Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Add zero-dim and zero-size array tests for index_array
Browse files Browse the repository at this point in the history
  • Loading branch information
nickguletskii committed Apr 30, 2019
1 parent f628d78 commit aba94af
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/python/gpu/test_operator_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,30 @@ def test_index_array_default():
check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

@with_seed()
def test_index_array_default_zero_dim():
with mx.np_compat(active=True):
data = mx.symbol.Variable("data")
index_array = mx.sym.contrib.index_array(data)

input_array = np.ones(())
expected = np.zeros((0,))

check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

@with_seed()
def test_index_array_default_zero_size():
with mx.np_compat(active=True):
data = mx.symbol.Variable("data")
index_array = mx.sym.contrib.index_array(data)

input_array = np.ones((0, 0, 0))
expected = np.zeros((0, 0, 0, 3))

check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

@with_seed()
def test_index_array_select_axes():
shape = (5, 7, 11, 13, 17, 19)
Expand All @@ -2157,6 +2181,18 @@ def test_index_array_select_axes():
check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

@with_seed()
def test_index_array_select_axes_zero_size():
with mx.np_compat(active=True):
data = mx.symbol.Variable("data")
index_array = mx.sym.contrib.index_array(data, axes=(2, 1))

input_array = np.ones((0, 0, 0, 0))
expected = np.zeros((0, 0, 2))

check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

# isolated execution bulking test function to be invoked with different env var settings
def _test_bulking_in_process(seed, time_per_iteration):
data_shape = (10,)
Expand Down
36 changes: 36 additions & 0 deletions tests/python/unittest/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8067,6 +8067,30 @@ def test_index_array_default():
check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

@with_seed()
def test_index_array_default_zero_dim():
with mx.np_compat(active=True):
data = mx.symbol.Variable("data")
index_array = mx.sym.contrib.index_array(data)

input_array = np.ones(())
expected = np.zeros((0,))

check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

@with_seed()
def test_index_array_default_zero_size():
with mx.np_compat(active=True):
data = mx.symbol.Variable("data")
index_array = mx.sym.contrib.index_array(data)

input_array = np.ones((0, 0, 0))
expected = np.zeros((0, 0, 0, 3))

check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

@with_seed()
def test_index_array_select_axes():
shape = (5, 7, 11, 13, 17, 19)
Expand All @@ -8081,6 +8105,18 @@ def test_index_array_select_axes():
check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

@with_seed()
def test_index_array_select_axes_zero_size():
with mx.np_compat(active=True):
data = mx.symbol.Variable("data")
index_array = mx.sym.contrib.index_array(data, axes=(2, 1))

input_array = np.ones((0, 0, 0, 0))
expected = np.zeros((0, 0, 2))

check_symbolic_forward(index_array, [input_array], [expected])
check_symbolic_backward(index_array, [input_array], [np.ones(expected.shape)], [np.zeros_like(input_array)])

@with_seed()
def test_scalar_tensor_creation():
assertRaises(MXNetError, mx.nd.zeros, shape=())
Expand Down

0 comments on commit aba94af

Please sign in to comment.