reminisce commented on a change in pull request #15973: Numpy . implement numpy
op exp2 with tvm
URL: https://github.com/apache/incubator-mxnet/pull/15973#discussion_r317890686
##########
File path: tests/python/unittest/test_numpy_op.py
##########
@@ -931,6 +934,50 @@ def hybrid_forward(self, F, a, *args):
assert same(mx_out.asnumpy(), np_out)
+@with_seed()
+@use_np
+def test_np_exp2():
+ if _features.is_enabled("TVM_OP"):
+ class Testexp2(HybridBlock):
+ def __init__(self):
+ super(Testexp2, self).__init__()
+
+ def hybrid_forward(self, F, x, *args, **kwargs):
+ return F.np.exp2(x)
+
+ shapes = [
+ (),
+ (2,),
+ (2, 1, 2),
+ (2, 0, 2),
+ (1, 2, 3, 4, 5),
+ (6, 6, 6, 6, 6),
+ ]
+ dtypes = ['float32', 'float64']
+
+ for hybridize in [True, False]:
+ for shape in shapes:
+ for dtype in dtypes:
+ test_exp2 = Testexp2()
+ if hybridize:
+ test_exp2.hybridize()
+ x = rand_ndarray(shape=shape, dtype=dtype).as_np_ndarray()
+ x.attach_grad()
+ np_out = _np.exp2(x.asnumpy())
+ with mx.autograd.record():
+ mx_out = test_exp2(x)
+ mx_out.backward()
+ assert mx_out.shape == np_out.shape
+ assert_almost_equal(mx_out.asnumpy(), np_out, rtol = 1e-3,
atol = 1e-5)
+ assert_almost_equal(x.grad.asnumpy(), np_out * x.asnumpy()
/ 2,
Review comment:
Use `check_numeric_gradient`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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