anirudh2290 commented on a change in pull request #12749: [MXNET-1029] Feature
request: randint operator
URL: https://github.com/apache/incubator-mxnet/pull/12749#discussion_r235789783
##########
File path: tests/python/unittest/test_random.py
##########
@@ -844,6 +836,48 @@ def testLarge(data, repeat):
testLarge(mx.nd.arange(0, 100000).reshape((10, 10000)), 10)
testLarge(mx.nd.arange(0, 100000).reshape((10000, 10)), 10)
+@with_seed()
+def test_randint():
+ dtypes = ['int32', 'int64']
+ for dtype in dtypes:
+ params = {
+ 'low': -1,
+ 'high': 3,
+ 'shape' : (500, 500),
+ 'dtype' : dtype,
+ 'ctx' : mx.context.current_context()
+ }
+ mx.random.seed(128)
+ ret1 = mx.nd.random.randint(**params).asnumpy()
+ mx.random.seed(128)
+ ret2 = mx.nd.random.randint(**params).asnumpy()
+ assert same(ret1, ret2), \
+ "ndarray test: `%s` should give the same result with the same
seed"
+
+@with_seed()
+def test_randint_extremes():
+ a = mx.nd.random.randint(dtype='int64', low=50000000, high=50000010,
ctx=mx.context.current_context())
+ assert a>=50000000 and a<=50000010
+
+@with_seed()
+def test_randint_generator():
+ ctx = mx.context.current_context()
+ for dtype in ['int32', 'int64']:
+ for low, high in [(50000000,
50001000),(-50000000,-9900),(-500,199),(-2147483647,2147483647)]:
+ scale = high - low
+ buckets, probs = gen_buckets_probs_with_ppf(lambda x:
ss.uniform.ppf(x, loc=low, scale=scale), 5)
+ # Quantize bucket boundaries to reflect the actual dtype and
adjust probs accordingly
+ buckets = np.array(buckets, dtype=dtype).tolist()
+ probs = [(buckets[i][1] - buckets[i][0]) / float(scale) for i in
range(5)]
+ generator_mx = lambda x: mx.nd.random.randint(low, high, shape=x,
ctx=ctx, dtype=dtype).asnumpy()
Review comment:
please add a test without the dtype param.
----------------------------------------------------------------
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