diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2020-04-27 13:06:05 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2020-04-27 13:06:05 -0400 |
commit | ca5ade84d02801401d4833eec9d8a50ef04e46ce (patch) | |
tree | f3b7e255adc967239a9cb09f0eeb12c959d3a551 /numpy | |
parent | 1ded86d35efcc6516083840497b558247b263cfb (diff) | |
download | numpy-ca5ade84d02801401d4833eec9d8a50ef04e46ce.tar.gz |
TST: random: Add more repeatability tests for random integers.
Add repeatability tests for when the range of the integers is `2**32`
(and `2**32 +/- 1` for good measure) with broadcasting. The underlying
functions called by Generator.integers and random.randint when the
inputs are broadcast are different than when the inputs are scalars.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/random/tests/test_generator_mt19937.py | 23 | ||||
-rw-r--r-- | numpy/random/tests/test_randomstate.py | 22 |
2 files changed, 45 insertions, 0 deletions
diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py index aa7dd45e9..08b44e4db 100644 --- a/numpy/random/tests/test_generator_mt19937.py +++ b/numpy/random/tests/test_generator_mt19937.py @@ -535,6 +535,29 @@ class TestIntegers: x = random.integers(bound, size=size) assert_equal(x, expected if size is not None else expected[0]) + def test_repeatability_32bit_boundary_broadcasting(self): + desired = np.array([[[1622936284, 3620788691, 1659384060], + [1417365545, 760222891, 1909653332], + [3788118662, 660249498, 4092002593]], + [[3625610153, 2979601262, 3844162757], + [ 685800658, 120261497, 2694012896], + [1207779440, 1586594375, 3854335050]], + [[3004074748, 2310761796, 3012642217], + [2067714190, 2786677879, 1363865881], + [ 791663441, 1867303284, 2169727960]], + [[1939603804, 1250951100, 298950036], + [1040128489, 3791912209, 3317053765], + [3155528714, 61360675, 2305155588]], + [[ 817688762, 1335621943, 3288952434], + [1770890872, 1102951817, 1957607470], + [3099996017, 798043451, 48334215]]]) + for size in [None, (5, 3, 3)]: + random = Generator(MT19937(12345)) + x = random.integers([[-1], [0], [1]], + [2**32 - 1, 2**32, 2**32 + 1], + size=size) + assert_array_equal(x, desired if size is not None else desired[0]) + def test_int64_uint64_broadcast_exceptions(self, endpoint): configs = {np.uint64: ((0, 2**65), (-1, 2**62), (10, 9), (0, 0)), np.int64: ((0, 2**64), (-(2**64), 2**62), (10, 9), (0, 0), diff --git a/numpy/random/tests/test_randomstate.py b/numpy/random/tests/test_randomstate.py index ebe8558ba..9c2128529 100644 --- a/numpy/random/tests/test_randomstate.py +++ b/numpy/random/tests/test_randomstate.py @@ -350,6 +350,28 @@ class TestRandint: res = hashlib.md5(val).hexdigest() assert_(tgt[np.dtype(bool).name] == res) + def test_repeatability_32bit_boundary_broadcasting(self): + desired = np.array([[[3992670689, 2438360420, 2557845020], + [4107320065, 4142558326, 3216529513], + [1605979228, 2807061240, 665605495]], + [[3211410639, 4128781000, 457175120], + [1712592594, 1282922662, 3081439808], + [3997822960, 2008322436, 1563495165]], + [[1398375547, 4269260146, 115316740], + [3414372578, 3437564012, 2112038651], + [3572980305, 2260248732, 3908238631]], + [[2561372503, 223155946, 3127879445], + [ 441282060, 3514786552, 2148440361], + [1629275283, 3479737011, 3003195987]], + [[ 412181688, 940383289, 3047321305], + [2978368172, 764731833, 2282559898], + [ 105711276, 720447391, 3596512484]]]) + for size in [None, (5, 3, 3)]: + random.seed(12345) + x = self.rfunc([[-1], [0], [1]], [2**32 - 1, 2**32, 2**32 + 1], + size=size) + assert_array_equal(x, desired if size is not None else desired[0]) + def test_int64_uint64_corner_case(self): # When stored in Numpy arrays, `lbnd` is casted # as np.int64, and `ubnd` is casted as np.uint64. |