MCPcopy
hub / github.com/numpy/numpy / test_repeatability

Method test_repeatability

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

Source from the content-addressed store, hash-verified

518 assert_array_equal(scalar, array)
519
520 def test_repeatability(self, endpoint):
521 # We use a sha256 hash of generated sequences of 1000 samples
522 # in the range [0, 6) for all but bool, where the range
523 # is [0, 2). Hashes are for little endian numbers.
524 tgt = {'bool': '053594a9b82d656f967c54869bc6970aa0358cf94ad469c81478459c6a90eee3', # noqa: E501
525 'int16': '54de9072b6ee9ff7f20b58329556a46a447a8a29d67db51201bf88baa6e4e5d4', # noqa: E501
526 'int32': 'd3a0d5efb04542b25ac712e50d21f39ac30f312a5052e9bbb1ad3baa791ac84b', # noqa: E501
527 'int64': '14e224389ac4580bfbdccb5697d6190b496f91227cf67df60989de3d546389b1', # noqa: E501
528 'int8': '0e203226ff3fbbd1580f15da4621e5f7164d0d8d6b51696dd42d004ece2cbec1', # noqa: E501
529 'uint16': '54de9072b6ee9ff7f20b58329556a46a447a8a29d67db51201bf88baa6e4e5d4', # noqa: E501
530 'uint32': 'd3a0d5efb04542b25ac712e50d21f39ac30f312a5052e9bbb1ad3baa791ac84b', # noqa: E501
531 'uint64': '14e224389ac4580bfbdccb5697d6190b496f91227cf67df60989de3d546389b1', # noqa: E501
532 'uint8': '0e203226ff3fbbd1580f15da4621e5f7164d0d8d6b51696dd42d004ece2cbec1'} # noqa: E501
533
534 for dt in self.itype[1:]:
535 random = Generator(MT19937(1234))
536
537 # view as little endian for hash
538 if sys.byteorder == 'little':
539 val = random.integers(0, 6 - endpoint, size=1000, endpoint=endpoint,
540 dtype=dt)
541 else:
542 val = random.integers(0, 6 - endpoint, size=1000, endpoint=endpoint,
543 dtype=dt).byteswap()
544
545 res = hashlib.sha256(val).hexdigest()
546 assert_(tgt[np.dtype(dt).name] == res)
547
548 # bools do not depend on endianness
549 random = Generator(MT19937(1234))
550 val = random.integers(0, 2 - endpoint, size=1000, endpoint=endpoint,
551 dtype=bool).view(np.int8)
552 res = hashlib.sha256(val).hexdigest()
553 assert_(tgt[np.dtype(bool).name] == res)
554
555 def test_repeatability_broadcasting(self, endpoint):
556 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