xidulu commented on a change in pull request #17415: [numpy]add op
random.lognormal
URL: https://github.com/apache/incubator-mxnet/pull/17415#discussion_r369928236
##########
File path: tests/python/unittest/test_numpy_op.py
##########
@@ -3340,6 +3340,56 @@ def hybrid_forward(self, F, loc, scale):
assert_almost_equal(loc.grad.asnumpy().sum(),
_np.ones(out_shape).sum(), rtol=1e-3, atol=1e-5)
+@with_seed()
+@use_np
+def test_np_lognormal_grad():
+ class TestLognormalGrad(HybridBlock):
+ def __init__(self, shape):
+ super(TestLognormalGrad, self).__init__()
+ self._shape = shape
+
+ def hybrid_forward(self, F, mean, sigma):
+ return F.np.random.lognormal(mean, sigma, self._shape)
+
+ param_shape = [
+ [(3, 2), (3, 2)],
+ [(3, 2, 2), (3, 2, 2)],
+ [(3, 4, 5), (4, 1)],
+ ]
+ output_shapes = [
+ (3, 2),
+ (4, 3, 2, 2),
+ (3, 4, 5)
+ ]
+ for hybridize in [False, True]:
+ for ((shape1, shape2), out_shape) in zip(param_shape, output_shapes):
+ test_lognormal_grad = TestLognormalGrad(out_shape)
+ if hybridize:
+ test_lognormal_grad.hybridize()
+ mean = np.zeros(shape1)
+ mean.attach_grad()
+ sigma = np.ones(shape2)
+ sigma.attach_grad()
+ with mx.autograd.record():
+ mx_out = test_lognormal_grad(mean, sigma)
+ np_out = _np.random.lognormal(mean = mean.asnumpy(),
+ sigma = sigma.asnumpy(), size =
out_shape)
+ assert_almost_equal(np_out.shape, mx_out.shape)
Review comment:
You'd better use `assert np_out.shape == mx_out.shape`
----------------------------------------------------------------
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