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

Method test_shuffle

numpy/random/tests/test_random.py:480–504  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

478 assert_equal(actual, desired)
479
480 def test_shuffle(self):
481 # Test lists, arrays (of various dtypes), and multidimensional versions
482 # of both, c-contiguous or not:
483 for conv in [lambda x: np.array([]),
484 lambda x: x,
485 lambda x: np.asarray(x).astype(np.int8),
486 lambda x: np.asarray(x).astype(np.float32),
487 lambda x: np.asarray(x).astype(np.complex64),
488 lambda x: np.asarray(x).astype(object),
489 lambda x: [(i, i) for i in x],
490 lambda x: np.asarray([[i, i] for i in x]),
491 lambda x: np.vstack([x, x]).T,
492 # gh-11442
493 lambda x: (np.asarray([(i, i) for i in x],
494 [("a", int), ("b", int)])
495 .view(np.recarray)),
496 # gh-4270
497 lambda x: np.asarray([(i, i) for i in x],
498 [("a", object), ("b", np.int32)])]:
499 np.random.seed(self.seed)
500 alist = conv([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
501 np.random.shuffle(alist)
502 actual = alist
503 desired = conv([0, 1, 9, 6, 2, 4, 5, 8, 7, 3])
504 assert_array_equal(actual, desired)
505
506 def test_shuffle_masked(self):
507 # gh-3263

Callers

nothing calls this directly

Calls 4

assert_array_equalFunction · 0.90
astypeMethod · 0.80
convFunction · 0.50
viewMethod · 0.45

Tested by

no test coverage detected