Skip to content

Commit 5b2ee1a

Browse files
updated tests
1 parent c977ec5 commit 5b2ee1a

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

mkl_random/tests/test_random.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def test_invalid_array(self):
8080
assert_raises(ValueError, rnd.RandomState, [1, 2, 4294967296])
8181
assert_raises(ValueError, rnd.RandomState, [1, -2, 4294967296])
8282

83+
def test_non_deterministic(self):
84+
rs = rnd.RandomState(brng='nondeterministic')
85+
rs.rand(10)
86+
rs.randint(0, 10)
87+
8388
class TestBinomial_Intel(TestCase):
8489
def test_n_zero(self):
8590
# Tests the corner case of n == 0 for the binomial distribution.
@@ -447,8 +452,8 @@ def test_shuffle(self):
447452
lambda x: np.vstack([x, x]).T,
448453
# gh-4270
449454
lambda x: np.asarray([(i, i) for i in x],
450-
[("a", object, 1),
451-
("b", np.int32, 1)])]:
455+
[("a", object, (1,)),
456+
("b", np.int32, (1,))])]:
452457
rnd.seed(self.seed, self.brng)
453458
alist = conv([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
454459
rnd.shuffle(alist)
@@ -633,13 +638,15 @@ def test_logseries(self):
633638

634639

635640
def test_multinomial(self):
636-
rnd.seed(self.seed, self.brng)
637-
actual = rnd.multinomial(20, [1/6.]*6, size=(3, 2))
638-
desired = np.array([[[7, 0, 2, 4, 4, 3], [7, 1, 2, 6, 4, 0]],
639-
[[2, 2, 3, 4, 6, 3], [1, 2, 5, 5, 6, 1]],
640-
[[2, 7, 4, 1, 2, 4], [3, 5, 2, 5, 4, 1]]])
641-
np.testing.assert_array_equal(actual, desired)
642-
641+
rs = rnd.RandomState(self.seed, brng=self.brng)
642+
actual = rs.multinomial(20, [1/6.]*6, size=(3, 2))
643+
desired = np.full((3, 2), 20, dtype=actual.dtype)
644+
np.testing.assert_array_equal(actual.sum(axis=-1), desired)
645+
expected = np.array([
646+
[[6, 2, 1, 3, 2, 6], [7, 5, 1, 2, 3, 2]],
647+
[[5, 1, 8, 3, 2, 1], [4, 6, 0, 4, 4, 2]],
648+
[[6, 3, 1, 4, 4, 2], [3, 2, 4, 2, 1, 8]]], actual.dtype)
649+
np.testing.assert_array_equal(actual, expected)
643650

644651
def test_multivariate_normal(self):
645652
rnd.seed(self.seed, self.brng)

0 commit comments

Comments
 (0)