-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-1029] Feature request: randint operator #12749
Conversation
@mxnet-label-bot [pr-awaiting-review] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create unit test (refer to test_random.py). Also please explicitly check edge cases like randint(dtype='int64', low=50000000, high=50000010)
0b08216
to
bc40a8e
Compare
9272bf6
to
05d696b
Compare
9a3b7fd
to
7341c9b
Compare
@@ -63,6 +63,10 @@ class RandGenerator<cpu, DType> { | |||
|
|||
MSHADOW_XINLINE int rand() { return engine_->operator()(); } | |||
|
|||
MSHADOW_XINLINE int64_t rand_int64() { | |||
return static_cast<int64_t>(engine_->operator()() << 31) + engine_->operator()(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leezu over here I use rand_int64() by using mt19937.rand() for 2 32bits
According to the video : https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful
is this a right way of doing it truly uniform random integer distribution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because you're concatenating 2 32bit numbers, where every bit is uniformly random. Thus the resulting 64bits are uniformly random.
Description
Incorporates the feature request to support randint operator, includes optional tag across all random functions.
Fixes #11218
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Comments
This function tries to ensure the discrete uniform distribution is truly uniform.
It uses the already defined
verify_generator
function but with default values, it failed the CI for certain config (specifically Python2 GPU.Ensured that I check in the above environment and verified the function works as mentioned in feedback.