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

Commit

Permalink
[MXNET-1407] Added test to verify Large Tensor Support for pad operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit Kumar Srivastava committed Jun 3, 2019
1 parent 3ebd873 commit 00ec663
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/nightly/test_large_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,39 @@ def test_flip():
assert np.sum(t[-1, :].asnumpy() == 0) == b.shape[1]


def check_pad_with_shape(shape, pad_width, mode, dtype="float64"):
# bind with label
X = mx.symbol.Variable('X', dtype=dtype)
Y = mx.symbol.Pad(data=X, mode=mode, pad_width=pad_width)
x = mx.random.uniform(-1, 1, shape, dtype=dtype)
# numpy result
pad_grouped = list(zip(*[iter(list(pad_width))] * 2))
np_out = np.pad(x.asnumpy(), pad_grouped, mode)
# mxnet result
grad = mx.nd.empty(shape, dtype=dtype)
exec1 = Y.bind(args=[x], ctx=mx.cpu(), args_grad={'X': grad})
exec1.forward(is_train=True)
out = exec1.outputs[0].asnumpy()
# compare numpy + mxnet
assert_almost_equal(out, np_out)

def test_pad():
shape1 = (LARGE_X, 2, 2, 2)
pad1 = (0, 0, 0, 0, 1, 1, 1, 1)
shape2 = (LARGE_X, 2, 2, 1, 1)
pad2 = (0, 0, 0, 0, 1, 1, 0, 0, 0, 0)
# note: this op doesn't support ints yet. Add tests when supported
dtypes = ["float16", "float32", "float64"]
dtypes = ["float16"]
for dtype in dtypes:
check_pad_with_shape(shape1, pad1, 'constant', dtype)
check_pad_with_shape(shape1, pad1, 'edge', dtype)
check_pad_with_shape(shape2, pad2, 'constant', dtype)
check_pad_with_shape(shape2, pad2, 'edge', dtype)
check_pad_with_shape(shape1, pad1, 'reflect', dtype)
check_pad_with_shape(shape2, pad2, 'reflect', dtype)


if __name__ == '__main__':
import nose
nose.runmodule()

0 comments on commit 00ec663

Please sign in to comment.