diff options
author | Kevin Sheppard <kevin.k.sheppard@gmail.com> | 2022-07-19 15:22:01 +0100 |
---|---|---|
committer | Kevin Sheppard <kevin.k.sheppard@gmail.com> | 2022-07-19 15:23:53 +0100 |
commit | 95e3e7f445407e4f355b23d6a9991d8774f0eb0c (patch) | |
tree | b6926d5ba6c2afcaba95876f17ce747f8f6eb31a /numpy/random/tests/test_randomstate.py | |
parent | 5ba36b700284a8392af5be542f65ecd262fd2568 (diff) | |
download | numpy-95e3e7f445407e4f355b23d6a9991d8774f0eb0c.tar.gz |
BUG/ENH: ALlow bit generators to supply their own ctor
Allow bit generators to supply their own constructors to enable Generator
objects using arbitrary bit generators to be supported
closes #22012
Diffstat (limited to 'numpy/random/tests/test_randomstate.py')
-rw-r--r-- | numpy/random/tests/test_randomstate.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/numpy/random/tests/test_randomstate.py b/numpy/random/tests/test_randomstate.py index 861813a95..aadfe3d78 100644 --- a/numpy/random/tests/test_randomstate.py +++ b/numpy/random/tests/test_randomstate.py @@ -2020,3 +2020,21 @@ def test_broadcast_size_error(): random.binomial([1, 2], 0.3, size=(2, 1)) with pytest.raises(ValueError): random.binomial([1, 2], [0.3, 0.7], size=(2, 1)) + + +def test_randomstate_ctor_old_style_pickle(): + rs = np.random.RandomState(MT19937(0)) + rs.standard_normal(1) + # Directly call reduce which is used in pickline + ctor, args, state_a = rs.__reduce__() + # Simulate unpickling an old pickle that only has the name + assert args[:1] == ("MT19937",) + b = ctor(*args[:1]) + b.set_state(state_a) + state_b = b.get_state(legacy=False) + + assert_equal(state_a['bit_generator'], state_b['bit_generator']) + assert_array_equal(state_a['state']['key'], state_b['state']['key']) + assert_array_equal(state_a['state']['pos'], state_b['state']['pos']) + assert_equal(state_a['has_gauss'], state_b['has_gauss']) + assert_equal(state_a['gauss'], state_b['gauss']) |