xidulu commented on a change in pull request #17390: [Numpy]add op random.beta
URL: https://github.com/apache/incubator-mxnet/pull/17390#discussion_r368904233
 
 

 ##########
 File path: tests/python/unittest/test_numpy_op.py
 ##########
 @@ -3431,6 +3431,52 @@ def hybrid_forward(self, F, x):
                 assert out.shape == expected_shape
 
 
+@with_seed()
+@use_np
+def test_np_random_beta():
+    class TestRandomBeta(HybridBlock):
+        def __init__(self, size=None, dtype=None, ctx=None):
+            super(TestRandomBeta, self).__init__()
+            self._size = size
+            self._dtype = dtype
+            self._ctx = ctx
+
+        def hybrid_forward(self, F, a, b):
+            return F.np.random.beta(a, b, size=self._size, dtype=self._dtype, 
ctx=self._ctx)
+
+    def _test_random_beta_range(output):
+        bigger_than_zero = mx.np.all(output > 0)
+        smaller_than_one = mx.np.all(output < 1)
+        return (output.size == 0) or (bigger_than_zero and smaller_than_one)
+
+    shape_list = [(), (1,), (2, 3), (4, 0, 5), 6, (7, 8), None]
+    # since fp16 might incur precision issue, the corresponding test is skipped
+    dtype_list = [np.float32, np.float64]
+    hybridize_list = [False, True]
+    data = np.array([1])
+    for [param_shape, in_dtype, out_dtype, hybridize] in 
itertools.product(shape_list,
+            dtype_list, dtype_list, hybridize_list):
+        mx_data = data.astype(in_dtype)
+        np_data = mx_data.asnumpy()
+        test_random_beta = TestRandomBeta(size=param_shape, dtype=out_dtype)
+        if hybridize:
+            test_random_beta.hybridize()
+        np_out = _np.random.beta(np_data, np_data, size=param_shape)
+        mx_out = test_random_beta(mx_data, mx_data)
+        # print("param_shape, in_dtype, out_dtype, hybridize", param_shape, 
in_dtype, out_dtype, hybridize)
 
 Review comment:
   remove unused code.

----------------------------------------------------------------
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

Reply via email to