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

support long for mx.random.seed #14314

Merged
merged 7 commits into from
Mar 5, 2019
Merged
Changes from 1 commit
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
18 changes: 15 additions & 3 deletions tests/python/unittest/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,12 +717,24 @@ def test_random_seed():
shape = (5, 5)
seed = rnd.randint(-(1 << 31), (1 << 31))
mx.random.seed(seed)
v1 = mx.nd.random_uniform(shape=shape)

def _assert_same_mx_arrays(a, b):
assert len(a) == len(b)
for a_i, b_i in zip(a, b):
assert (a_i.asnumpy() == b_i.asnumpy()).all()

N = 100
v1 = [mx.nd.random_uniform(shape=shape) for _ in range(N)]
wkcn marked this conversation as resolved.
Show resolved Hide resolved

mx.random.seed(seed)
v2 = [mx.nd.random_uniform(shape=shape) for _ in range(N)]
_assert_same_mx_arrays(v1, v2)

try:
long
mx.random.seed(long(seed))
v2 = mx.nd.random_uniform(shape=shape)
assert (v1.asnumpy() == v2.asnumpy()).all()
v3 = [mx.nd.random_uniform(shape=shape) for _ in range(N)]
_assert_same_mx_arrays(v1, v3)
except NameError:
pass

Expand Down