BUG/ENH: Allow bit generators to supply their own constructor#22014
BUG/ENH: Allow bit generators to supply their own constructor#22014mattip merged 2 commits intonumpy:mainfrom
Conversation
Allow bit generators to supply their own constructors to enable Generator objects using arbitrary bit generators to be supported closes numpy#22012
|
Simplest method I could find to work through #22012. Changes how |
| def test_generator_ctor_old_style_pickle(): | ||
| rg = np.random.Generator(np.random.PCG64DXSM(0)) | ||
| rg.standard_normal(1) | ||
| # Directly call reduce which is used in pickline |
There was a problem hiding this comment.
| # Directly call reduce which is used in pickline | |
| # Directly call reduce which is used in pickling |
| 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 |
There was a problem hiding this comment.
| # Directly call reduce which is used in pickline | |
| # Directly call reduce which is used in pickling |
| @@ -14,70 +14,67 @@ | |||
| } | |||
There was a problem hiding this comment.
It would be nice if we could refactor this to avoid the circular import _pickle -> _generator/mtrand -> _pickle
There was a problem hiding this comment.
well, not really circular since _generator/mtrand import _pickle in the __reduce__ method, but the pattern is convoluted.
There was a problem hiding this comment.
I think the only way to avoid would be to move these to be closed to the class definitions. There is always something circular required here since the main class needs its constructor, and the constructor needs the main class.
There was a problem hiding this comment.
That's very common in __reduce__ implementations, IME.
|
This LGTM. Any more thoughts? |
|
Thanks @bashtage |
|
Could you add a release note and mention this somewhere in the documentation? |
|
@mattip I was thinking of writing the release note, but I'm not sure there is really anything worth saying. This changes the pickling information in |
|
Maybe something like this in a release note? |
Allow bit generators to supply their own constructors to enable Generator
objects using arbitrary bit generators to be supported
closes #22012