MCPcopy Index your code
hub / github.com/numpy/numpy / test_shuffle

Method test_shuffle

numpy/random/tests/test_generator_mt19937.py:976–1001  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

974 assert_equal(actual, desired)
975
976 def test_shuffle(self):
977 # Test lists, arrays (of various dtypes), and multidimensional versions
978 # of both, c-contiguous or not:
979 for conv in [lambda x: np.array([]),
980 lambda x: x,
981 lambda x: np.asarray(x).astype(np.int8),
982 lambda x: np.asarray(x).astype(np.float32),
983 lambda x: np.asarray(x).astype(np.complex64),
984 lambda x: np.asarray(x).astype(object),
985 lambda x: [(i, i) for i in x],
986 lambda x: np.asarray([[i, i] for i in x]),
987 lambda x: np.vstack([x, x]).T,
988 # gh-11442
989 lambda x: (np.asarray([(i, i) for i in x],
990 [("a", int), ("b", int)])
991 .view(np.recarray)),
992 # gh-4270
993 lambda x: np.asarray([(i, i) for i in x],
994 [("a", object, (1,)),
995 ("b", np.int32, (1,))])]:
996 random = Generator(MT19937(self.seed))
997 alist = conv([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
998 random.shuffle(alist)
999 actual = alist
1000 desired = conv([4, 1, 9, 8, 0, 5, 3, 6, 2, 7])
1001 assert_array_equal(actual, desired)
1002
1003 def test_shuffle_custom_axis(self):
1004 random = Generator(MT19937(self.seed))

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