mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
This reverts commit7abeb92796. Reverted https://github.com/pytorch/pytorch/pull/108762 on behalf of https://github.com/clee2000 due to sorry but I think the asan test_scalarmath failure is real7abeb92796https://github.com/pytorch/pytorch/actions/runs/6132913963/job/16645381921 ([comment](https://github.com/pytorch/pytorch/pull/108762#issuecomment-1714214523))
51 lines
1.1 KiB
Python
51 lines
1.1 KiB
Python
# Owner(s): ["module: dynamo"]
|
|
|
|
"""Light smoke test switching between numpy to pytorch random streams.
|
|
"""
|
|
import pytest
|
|
|
|
import torch._numpy as tnp
|
|
from torch._numpy.testing import assert_equal
|
|
|
|
|
|
def test_uniform():
|
|
r = tnp.random.uniform(0, 1, size=10)
|
|
|
|
|
|
def test_shuffle():
|
|
x = tnp.arange(10)
|
|
tnp.random.shuffle(x)
|
|
|
|
|
|
def test_numpy_global():
|
|
tnp.random.USE_NUMPY_RANDOM = True
|
|
tnp.random.seed(12345)
|
|
x = tnp.random.uniform(0, 1, size=11)
|
|
|
|
# check that the stream is identical to numpy's
|
|
import numpy as _np
|
|
|
|
_np.random.seed(12345)
|
|
x_np = _np.random.uniform(0, 1, size=11)
|
|
|
|
assert_equal(x, tnp.asarray(x_np))
|
|
|
|
# switch to the pytorch stream, variates differ
|
|
tnp.random.USE_NUMPY_RANDOM = False
|
|
tnp.random.seed(12345)
|
|
|
|
x_1 = tnp.random.uniform(0, 1, size=11)
|
|
assert not (x_1 == x).all()
|
|
|
|
|
|
def test_wrong_global():
|
|
try:
|
|
oldstate = tnp.random.USE_NUMPY_RANDOM
|
|
|
|
tnp.random.USE_NUMPY_RANDOM = "oops"
|
|
with pytest.raises(ValueError):
|
|
tnp.random.rand()
|
|
|
|
finally:
|
|
tnp.random.USE_NUMPY_RANDOM = oldstate
|