@@ -90,6 +90,11 @@ def test_size(self):
9090
9191 def test_invalid_prob (self ):
9292 assert_raises (ValueError , random .multinomial , 100 , [1.1 , 0.2 ])
93+ assert_raises (ValueError , random .multinomial , 100 , [- .1 , 0.9 ])
94+
95+ def test_invalid_n (self ):
96+ assert_raises (ValueError , random .multinomial , - 1 , [0.8 , 0.2 ])
97+ assert_raises (ValueError , random .multinomial , [- 1 ] * 10 , [0.8 , 0.2 ])
9398
9499
95100class TestSetState (object ):
@@ -804,8 +809,7 @@ def test_geometric_exceptions(self):
804809 assert_raises (ValueError , random .geometric , [1.1 ] * 10 )
805810 assert_raises (ValueError , random .geometric , - 0.1 )
806811 assert_raises (ValueError , random .geometric , [- 0.1 ] * 10 )
807- with suppress_warnings () as sup :
808- sup .record (RuntimeWarning )
812+ with np .errstate (invalid = 'ignore' ):
809813 assert_raises (ValueError , random .geometric , np .nan )
810814 assert_raises (ValueError , random .geometric , [np .nan ] * 10 )
811815
@@ -888,8 +892,7 @@ def test_logseries(self):
888892 assert_array_equal (actual , desired )
889893
890894 def test_logseries_exceptions (self ):
891- with suppress_warnings () as sup :
892- sup .record (RuntimeWarning )
895+ with np .errstate (invalid = 'ignore' ):
893896 assert_raises (ValueError , random .logseries , np .nan )
894897 assert_raises (ValueError , random .logseries , [np .nan ] * 10 )
895898
@@ -964,8 +967,7 @@ def test_negative_binomial(self):
964967 assert_array_equal (actual , desired )
965968
966969 def test_negative_binomial_exceptions (self ):
967- with suppress_warnings () as sup :
968- sup .record (RuntimeWarning )
970+ with np .errstate (invalid = 'ignore' ):
969971 assert_raises (ValueError , random .negative_binomial , 100 , np .nan )
970972 assert_raises (ValueError , random .negative_binomial , 100 ,
971973 [np .nan ] * 10 )
@@ -1046,8 +1048,7 @@ def test_poisson_exceptions(self):
10461048 assert_raises (ValueError , random .poisson , [lamneg ] * 10 )
10471049 assert_raises (ValueError , random .poisson , lambig )
10481050 assert_raises (ValueError , random .poisson , [lambig ] * 10 )
1049- with suppress_warnings () as sup :
1050- sup .record (RuntimeWarning )
1051+ with np .errstate (invalid = 'ignore' ):
10511052 assert_raises (ValueError , random .poisson , np .nan )
10521053 assert_raises (ValueError , random .poisson , [np .nan ] * 10 )
10531054
@@ -1849,6 +1850,23 @@ def test_logseries(self):
18491850 assert_raises (ValueError , logseries , bad_p_one * 3 )
18501851 assert_raises (ValueError , logseries , bad_p_two * 3 )
18511852
1853+ def test_multinomial (self ):
1854+ random .brng .seed (self .seed )
1855+ actual = random .multinomial ([5 , 20 ], [1 / 6. ] * 6 , size = (3 , 2 ))
1856+ desired = np .array ([[[1 , 1 , 1 , 1 , 0 , 1 ],
1857+ [4 , 5 , 1 , 4 , 3 , 3 ]],
1858+ [[1 , 1 , 1 , 0 , 0 , 2 ],
1859+ [2 , 0 , 4 , 3 , 7 , 4 ]],
1860+ [[1 , 2 , 0 , 0 , 2 , 2 ],
1861+ [3 , 2 , 3 , 4 , 2 , 6 ]]], dtype = np .int64 )
1862+ assert_array_equal (actual , desired )
1863+
1864+ random .brng .seed (self .seed )
1865+ actual = random .multinomial ([5 , 20 ], [1 / 6. ] * 6 )
1866+ desired = np .array ([[1 , 1 , 1 , 1 , 0 , 1 ],
1867+ [4 , 5 , 1 , 4 , 3 , 3 ]], dtype = np .int64 )
1868+ assert_array_equal (actual , desired )
1869+
18521870
18531871class TestThread (object ):
18541872 # make sure each state produces the same sequence even in threads
0 commit comments