Adopt a NumPy RandomState in NumpyBackend.seed - #881
Open
shaneraphel wants to merge 2 commits into
Open
shaneraphel wants to merge 2 commits into
shaneraphel wants to merge 2 commits into
Conversation
RandomState.seed rejects another RandomState, so callers can pass the generator itself and later draws use it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #881 +/- ##
=======================================
Coverage 96.86% 96.87%
=======================================
Files 128 128
Lines 26304 26330 +26
=======================================
+ Hits 25480 25506 +26
Misses 824 824 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Types of changes
Motivation and context / Related issue
NumpyBackend.seedforwards its argument toRandomState.seed. That method accepts an integer, and it rejects anumpy.random.RandomStatewithTypeError.TorchBackend.seedalready adopts atorch.Generator, andTensorflowBackend.seedalready adopts atf.random.Generator. Issue #848 asks for the same on the NumPy backend.An integer still seeds the current generator. A
RandomStatereplacesrng_on that instance, so laterrand,randn, andrandpermdraws come from the object the caller passed.Nonestill leaves the generator unchanged. Adopting the object does not reseed the class-level generator shared by other instances.How has this been tested (if it applies)
test_numpy_backend_adopts_random_statechecks four things: aRandomState(42)produces the same first four uniform draws as a freshRandomState(42); those draws do not advance the class-level generator;randncontinues that generator; an integer seed is still repeatable;seed(None)does not change the state.I ran that scenario by loading
ot/backend.pydirectly. I did not build the package extension and I did not run the full test suite.PR checklist