eric-haibin-lin commented on a change in pull request #12749: [MXNET-1029]
Feature request: randint operator
URL: https://github.com/apache/incubator-mxnet/pull/12749#discussion_r230846141
##########
File path: python/mxnet/ndarray/random.py
##########
@@ -518,3 +518,52 @@ def shuffle(data, **kwargs):
<NDArray 2x3 @cpu(0)>
"""
return _internal._shuffle(data, **kwargs)
+
+
+def randint(low=0, high=1, shape=_Null, dtype=_Null, ctx=None, out=None,
**kwargs):
+ """Draw random samples from a discrete uniform distribution.
+
+ Samples are uniformly distributed over the half-open interval *[low, high)*
+ (includes *low*, but excludes *high*).
+
+ Parameters
+ ----------
+ low : int, optional
+ Lower boundary of the output interval. All values generated will be
+ greater than or equal to low. The default value is 0.
+ high : int, optional
+ Upper boundary of the output interval. All values generated will be
+ less than high. The default value is 1.
+ shape : int or tuple of ints, optional
+ The number of samples to draw. If shape is, e.g., `(m, n)` and `low`
and
+ `high` are scalars, output shape will be `(m, n)`.
+ dtype : {'int32', 'int64'}, optional
+ Data type of output samples. Default is 'int32'
+ ctx : Context, optional
+ Device context of output. Default is current context. Overridden by
+ `low.context` when `low` is an NDArray.
+ out : NDArray, optional
+ Store output to an existing NDArray.
+
+
+ Examples
+ --------
+ >>> mx.nd.random.randint()
+ [ 190]
+ <NDArray 1 @cpu(0)
+ >>> mx.nd.random.randint(-10, 2, ctx=mx.gpu(0))
+ [ -8]
+ <NDArray 1 @gpu(0)>
+ >>> mx.nd.random.randint(-10, 10, shape=(2,))
+ [ -5 4]
+ <NDArray 2 @cpu(0)>
+ >>> low = mx.nd.array([1,2,3])
+ >>> high = mx.nd.array([2,3,4])
+ >>> mx.nd.random.randint(low, high, shape=2)
+ [[ 1 1]
+ [ 2 2]
+ [ 3 3]]
+ <NDArray 3x2 @cpu(0)>
+ """
+ return _random_helper(_internal._random_randint, _internal._sample_uniform,
Review comment:
This part looks strange. Why use `_internal._sample_uniform`? Does it work
correctly if inputs are large int64 numbers? If you plan to only support
high/low with int types then you should not use `_random_helper` this way
----------------------------------------------------------------
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