sbodenstein commented on a change in pull request #12035: Pad Operator Type
Support
URL: https://github.com/apache/incubator-mxnet/pull/12035#discussion_r211077059
##########
File path: tests/python/unittest/test_operator.py
##########
@@ -2905,37 +2905,46 @@ def test_roipooling():
numeric_eps=1e-4, rtol=1e-1, atol=1E-4)
-def check_pad_with_shape(shape, xpu, pad_width, mode):
+def check_pad_with_shape(shape, xpu, pad_width, mode, dtype="float64"):
# bind with label
- X = mx.symbol.Variable('X')
+ real_types = ["float16", "float32", "float64"]
+ 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, ctx=mx.cpu()).copyto(xpu)
+ if dtype in real_types:
+ x = mx.random.uniform(-1, 1, shape, ctx=mx.cpu(),
dtype=dtype).copyto(xpu)
+ else:
+ x = mx.nd.ones(shape, ctx=mx.cpu(), dtype=dtype).copyto(xpu)
# 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, ctx = xpu)
+ grad = mx.nd.empty(shape, ctx = xpu, dtype=dtype)
exec1 = Y.bind(xpu, args = [x], args_grad = {'X': grad})
exec1.forward(is_train=True)
out = exec1.outputs[0].asnumpy()
# compare numpy + mxnet
assert_almost_equal(out, np_out)
# grad check
- check_numeric_gradient(Y, [x.asnumpy()], numeric_eps=1e-2, rtol=1e-2)
+ if dtype in real_types:
+ check_numeric_gradient(Y, [x.asnumpy()], numeric_eps=1e-2, rtol=1e-2)
@with_seed()
def test_pad():
+ ct = default_context()
shape1 = (2, 3, 3, 5)
pad1 = (0, 0, 0, 0, 1, 2, 3, 4)
shape2 = (2, 3, 3, 5, 4)
pad2 = (0, 0, 0, 0, 1, 2, 3, 4, 3, 1)
- check_pad_with_shape(shape1, default_context(), pad1, 'constant')
- check_pad_with_shape(shape1, default_context(), pad1, 'edge')
- check_pad_with_shape(shape2, default_context(), pad2, 'constant')
- check_pad_with_shape(shape2, default_context(), pad2, 'edge')
- check_pad_with_shape(shape1, default_context(), pad1, 'reflect')
- check_pad_with_shape(shape2, default_context(), pad2, 'reflect')
+ # note: this op doesn't support ints yet. Add tests when supported
+ test_types = ["float32", "float64", "float16"]
+ for d in test_types:
Review comment:
Changed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services