Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix crash in random.shuffle operator #15041

Merged
merged 7 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/operator/random/shuffle_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ namespace {
template<typename DType, typename Rand>
void Shuffle1D(DType* const out, const index_t size, Rand* const prnd) {
#ifdef USE_GNU_PARALLEL_SHUFFLE
auto rand_n = [prnd](index_t n) {
std::uniform_int_distribution<index_t> dist(0, n - 1);
/*
* See issue #15029: the data type of n needs to be compatible with
* the gcc library: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B\
* -v3/include/parallel/random_shuffle.h#L384
*/
auto rand_n = [prnd](uint32_t n) {
std::uniform_int_distribution<uint32_t> dist(0, n - 1);
return dist(*prnd);
};
__gnu_parallel::random_shuffle(out, out + size, rand_n);
Expand Down
2 changes: 2 additions & 0 deletions tests/python/unittest/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,8 @@ def testLarge(data, repeat):
# Test larger arrays
testLarge(mx.nd.arange(0, 100000).reshape((10, 10000)), 10)
testLarge(mx.nd.arange(0, 100000).reshape((10000, 10)), 10)
testLarge(mx.nd.arange(0, 100000), 10)


@with_seed()
def test_randint():
Expand Down