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

Method test_repeatability

numpy/random/tests/test_generator_mt19937.py:491–524  ·  view source on GitHub ↗
(self, endpoint)

Source from the content-addressed store, hash-verified

489 assert_array_equal(scalar, array)
490
491 def test_repeatability(self, endpoint):
492 # We use a sha256 hash of generated sequences of 1000 samples
493 # in the range [0, 6) for all but bool, where the range
494 # is [0, 2). Hashes are for little endian numbers.
495 tgt = {'bool': '053594a9b82d656f967c54869bc6970aa0358cf94ad469c81478459c6a90eee3',
496 'int16': '54de9072b6ee9ff7f20b58329556a46a447a8a29d67db51201bf88baa6e4e5d4',
497 'int32': 'd3a0d5efb04542b25ac712e50d21f39ac30f312a5052e9bbb1ad3baa791ac84b',
498 'int64': '14e224389ac4580bfbdccb5697d6190b496f91227cf67df60989de3d546389b1',
499 'int8': '0e203226ff3fbbd1580f15da4621e5f7164d0d8d6b51696dd42d004ece2cbec1',
500 'uint16': '54de9072b6ee9ff7f20b58329556a46a447a8a29d67db51201bf88baa6e4e5d4',
501 'uint32': 'd3a0d5efb04542b25ac712e50d21f39ac30f312a5052e9bbb1ad3baa791ac84b',
502 'uint64': '14e224389ac4580bfbdccb5697d6190b496f91227cf67df60989de3d546389b1',
503 'uint8': '0e203226ff3fbbd1580f15da4621e5f7164d0d8d6b51696dd42d004ece2cbec1'}
504
505 for dt in self.itype[1:]:
506 random = Generator(MT19937(1234))
507
508 # view as little endian for hash
509 if sys.byteorder == 'little':
510 val = random.integers(0, 6 - endpoint, size=1000, endpoint=endpoint,
511 dtype=dt)
512 else:
513 val = random.integers(0, 6 - endpoint, size=1000, endpoint=endpoint,
514 dtype=dt).byteswap()
515
516 res = hashlib.sha256(val).hexdigest()
517 assert_(tgt[np.dtype(dt).name] == res)
518
519 # bools do not depend on endianness
520 random = Generator(MT19937(1234))
521 val = random.integers(0, 2 - endpoint, size=1000, endpoint=endpoint,
522 dtype=bool).view(np.int8)
523 res = hashlib.sha256(val).hexdigest()
524 assert_(tgt[np.dtype(bool).name] == res)
525
526 def test_repeatability_broadcasting(self, endpoint):
527 for dt in self.itype:

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected