MCPcopy Create free account
hub / github.com/numpy/numpy / test_repeatability

Method test_repeatability

numpy/random/tests/test_randomstate.py:340–370  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

338 assert_(vals.min() >= 0)
339
340 def test_repeatability(self):
341 # We use a sha256 hash of generated sequences of 1000 samples
342 # in the range [0, 6) for all but bool, where the range
343 # is [0, 2). Hashes are for little endian numbers.
344 tgt = {'bool': '509aea74d792fb931784c4b0135392c65aec64beee12b0cc167548a2c3d31e71',
345 'int16': '7b07f1a920e46f6d0fe02314155a2330bcfd7635e708da50e536c5ebb631a7d4',
346 'int32': 'e577bfed6c935de944424667e3da285012e741892dcb7051a8f1ce68ab05c92f',
347 'int64': '0fbead0b06759df2cfb55e43148822d4a1ff953c7eb19a5b08445a63bb64fa9e',
348 'int8': '001aac3a5acb935a9b186cbe14a1ca064b8bb2dd0b045d48abeacf74d0203404',
349 'uint16': '7b07f1a920e46f6d0fe02314155a2330bcfd7635e708da50e536c5ebb631a7d4',
350 'uint32': 'e577bfed6c935de944424667e3da285012e741892dcb7051a8f1ce68ab05c92f',
351 'uint64': '0fbead0b06759df2cfb55e43148822d4a1ff953c7eb19a5b08445a63bb64fa9e',
352 'uint8': '001aac3a5acb935a9b186cbe14a1ca064b8bb2dd0b045d48abeacf74d0203404'}
353
354 for dt in self.itype[1:]:
355 random.seed(1234)
356
357 # view as little endian for hash
358 if sys.byteorder == 'little':
359 val = self.rfunc(0, 6, size=1000, dtype=dt)
360 else:
361 val = self.rfunc(0, 6, size=1000, dtype=dt).byteswap()
362
363 res = hashlib.sha256(val.view(np.int8)).hexdigest()
364 assert_(tgt[np.dtype(dt).name] == res)
365
366 # bools do not depend on endianness
367 random.seed(1234)
368 val = self.rfunc(0, 2, size=1000, dtype=bool).view(np.int8)
369 res = hashlib.sha256(val).hexdigest()
370 assert_(tgt[np.dtype(bool).name] == res)
371
372 @pytest.mark.skipif(np.iinfo('l').max < 2**32,
373 reason='Cannot test with 32-bit C long')

Callers

nothing calls this directly

Calls 4

assert_Function · 0.90
byteswapMethod · 0.80
viewMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected