diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2019-09-16 08:51:29 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2019-09-16 20:58:04 -0400 |
commit | ff11e2f0b7d06451860022564f0b173794860149 (patch) | |
tree | 6bcab48995db3a9c4c8e882fb9083ea59393b2fa /numpy/random/tests/test_randomstate_regression.py | |
parent | 6e75b9ab7888e2d807893a8237811f97f605547e (diff) | |
download | numpy-ff11e2f0b7d06451860022564f0b173794860149.tar.gz |
BUG: random: Create a legacy implementation of random.binomial.
Create a legacy implementation of the random_binomial method of
RandomState that does not include the "short-circuit" check for
n == 0 or p == 0. This ensures that the stream of variates
is consistent with the behavior in 1.16.
Closes gh-14522.
Diffstat (limited to 'numpy/random/tests/test_randomstate_regression.py')
-rw-r--r-- | numpy/random/tests/test_randomstate_regression.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/numpy/random/tests/test_randomstate_regression.py b/numpy/random/tests/test_randomstate_regression.py index ae92319c4..edf32ea97 100644 --- a/numpy/random/tests/test_randomstate_regression.py +++ b/numpy/random/tests/test_randomstate_regression.py @@ -191,4 +191,20 @@ class TestRegression(object): 2588848963, 3684848379, 2340255427, 3638918503, 1819583497, 2678185683], dtype='int64') actual = random.randint(2**32, size=10) - assert_array_equal(actual, expected)
\ No newline at end of file + assert_array_equal(actual, expected) + + def test_p_zero_stream(self): + # Regression test for gh-14522. Ensure that future versions + # generate the same variates as version 1.16. + np.random.seed(12345) + assert_array_equal(random.binomial(1, [0, 0.25, 0.5, 0.75, 1]), + [0, 0, 0, 1, 1]) + + def test_n_zero_stream(self): + # Regression test for gh-14522. Ensure that future versions + # generate the same variates as version 1.16. + np.random.seed(8675309) + expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [3, 4, 2, 3, 3, 1, 5, 3, 1, 3]]) + assert_array_equal(random.binomial([[0], [10]], 0.25, size=(2, 10)), + expected) |