From 366a55dce667f07354f242db4a13f2fda98fef82 Mon Sep 17 00:00:00 2001 From: Manu Seth Date: Tue, 12 Mar 2019 01:33:38 +0000 Subject: [PATCH] adding test for end=-1 step<0 case --- tests/python/unittest/test_operator.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/python/unittest/test_operator.py b/tests/python/unittest/test_operator.py index 7169395205e0..b16cb5200dea 100644 --- a/tests/python/unittest/test_operator.py +++ b/tests/python/unittest/test_operator.py @@ -6606,6 +6606,21 @@ def test_slice_forward_backward(a, index): for index in index_list: test_slice_forward_backward(arr, index) + # check for end=-1 and negative step + shape = (4, 3) + begin = (1, 2) + end = (-1, -1) + step = (-1, -2) + in_arr = mx.nd.arange(np.prod(shape)).reshape(shape=shape) + out_arr = mx.nd.slice(in_arr, begin=begin, end=end, step=step) + out_exp = np.array([[5., 3.],[2., 0.]]) + assert same(out_arr.asnumpy(), out_exp) + data = mx.sym.Variable('data') + slice_sym = mx.sym.slice(data, begin=begin, end=end, step=step) + grad_exp = np.zeros(shape) + grad_exp[(slice(None, 2, 1),slice(None, None, 2))] = np.array([[0., 2.],[3., 5.]]) + check_symbolic_backward(slice_sym, [in_arr.asnumpy()], [out_exp], [grad_exp]) + # check numeric gradient in_data = np.arange(36).reshape(2, 2, 3, 3) data = mx.sym.Variable('data')