New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG/ENH: Allow bit generators to supply their own constructor #22014
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Directly call reduce which is used in pickline | |
# Directly call reduce which is used in pickling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Directly call reduce which is used in pickline | |
# Directly call reduce which is used in pickling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.
@@ -14,70 +14,67 @@ | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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