| 228 | assert_(vals.min() >= 0) |
| 229 | |
| 230 | def test_repeatability(self): |
| 231 | import hashlib |
| 232 | # We use a sha256 hash of generated sequences of 1000 samples |
| 233 | # in the range [0, 6) for all but bool, where the range |
| 234 | # is [0, 2). Hashes are for little endian numbers. |
| 235 | tgt = {'bool': '509aea74d792fb931784c4b0135392c65aec64beee12b0cc167548a2c3d31e71', # noqa: E501 |
| 236 | 'int16': '7b07f1a920e46f6d0fe02314155a2330bcfd7635e708da50e536c5ebb631a7d4', # noqa: E501 |
| 237 | 'int32': 'e577bfed6c935de944424667e3da285012e741892dcb7051a8f1ce68ab05c92f', # noqa: E501 |
| 238 | 'int64': '0fbead0b06759df2cfb55e43148822d4a1ff953c7eb19a5b08445a63bb64fa9e', # noqa: E501 |
| 239 | 'int8': '001aac3a5acb935a9b186cbe14a1ca064b8bb2dd0b045d48abeacf74d0203404', # noqa: E501 |
| 240 | 'uint16': '7b07f1a920e46f6d0fe02314155a2330bcfd7635e708da50e536c5ebb631a7d4', # noqa: E501 |
| 241 | 'uint32': 'e577bfed6c935de944424667e3da285012e741892dcb7051a8f1ce68ab05c92f', # noqa: E501 |
| 242 | 'uint64': '0fbead0b06759df2cfb55e43148822d4a1ff953c7eb19a5b08445a63bb64fa9e', # noqa: E501 |
| 243 | 'uint8': '001aac3a5acb935a9b186cbe14a1ca064b8bb2dd0b045d48abeacf74d0203404'} # noqa: E501 |
| 244 | |
| 245 | for dt in self.itype[1:]: |
| 246 | rng = random.RandomState(1234) |
| 247 | |
| 248 | # view as little endian for hash |
| 249 | if sys.byteorder == 'little': |
| 250 | val = rng.randint(0, 6, size=1000, dtype=dt) |
| 251 | else: |
| 252 | val = rng.randint(0, 6, size=1000, dtype=dt).byteswap() |
| 253 | |
| 254 | res = hashlib.sha256(val.view(np.int8)).hexdigest() |
| 255 | assert_(tgt[np.dtype(dt).name] == res) |
| 256 | |
| 257 | # bools do not depend on endianness |
| 258 | rng = random.RandomState(1234) |
| 259 | val = rng.randint(0, 2, size=1000, dtype=bool).view(np.int8) |
| 260 | res = hashlib.sha256(val).hexdigest() |
| 261 | assert_(tgt[np.dtype(bool).name] == res) |
| 262 | |
| 263 | def test_int64_uint64_corner_case(self): |
| 264 | # When stored in Numpy arrays, `lbnd` is casted |