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

Method test_shuffle

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

Source from the content-addressed store, hash-verified

678 assert_equal(actual, desired)
679
680 def test_shuffle(self):
681 # Test lists, arrays (of various dtypes), and multidimensional versions
682 # of both, c-contiguous or not:
683 for conv in [lambda x: np.array([]),
684 lambda x: x,
685 lambda x: np.asarray(x).astype(np.int8),
686 lambda x: np.asarray(x).astype(np.float32),
687 lambda x: np.asarray(x).astype(np.complex64),
688 lambda x: np.asarray(x).astype(object),
689 lambda x: [(i, i) for i in x],
690 lambda x: np.asarray([[i, i] for i in x]),
691 lambda x: np.vstack([x, x]).T,
692 # gh-11442
693 lambda x: (np.asarray([(i, i) for i in x],
694 [("a", int), ("b", int)])
695 .view(np.recarray)),
696 # gh-4270
697 lambda x: np.asarray([(i, i) for i in x],
698 [("a", object, (1,)),
699 ("b", np.int32, (1,))])]:
700 random.seed(self.seed)
701 alist = conv([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
702 random.shuffle(alist)
703 actual = alist
704 desired = conv([0, 1, 9, 6, 2, 4, 5, 8, 7, 3])
705 assert_array_equal(actual, desired)
706
707 def test_shuffle_masked(self):
708 # 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