diff options
author | Julian Taylor <juliantaylor108@gmail.com> | 2014-06-02 21:35:09 +0200 |
---|---|---|
committer | Julian Taylor <juliantaylor108@gmail.com> | 2014-06-02 21:35:09 +0200 |
commit | dc5a148854476ece243205f05e09fd1218692205 (patch) | |
tree | 940bf2c9f216256aba6877e908f1682eef62be68 | |
parent | e9f27b9ad506a8e37565abf72c0e9f23254595de (diff) | |
parent | 41dc794935e6b01ab0427c054e930a23e4429e4a (diff) | |
download | numpy-dc5a148854476ece243205f05e09fd1218692205.tar.gz |
Merge pull request #4768 from depristo/master
ENH: Optimization for pickling random states
the constructor intended for pickling initializes its state via reading /dev/urandom which can be expensive on virtual machines. as the pickle constructor just needs to create any state which will later be initialized these urandom reads are unnecessary.
-rw-r--r-- | numpy/random/__init__.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/numpy/random/__init__.py b/numpy/random/__init__.py index 614b25a1c..388267c97 100644 --- a/numpy/random/__init__.py +++ b/numpy/random/__init__.py @@ -106,8 +106,16 @@ def __RandomState_ctor(): """Return a RandomState instance. This function exists solely to assist (un)pickling. + + Note that the state of the RandomState returned here is irrelevant, as this function's + entire purpose is to return a newly allocated RandomState whose state pickle can set. + Consequently the RandomState returned by this function is a freshly allocated copy + with a seed=0. + + See https://github.com/numpy/numpy/issues/4763 for a detailed discussion + """ - return RandomState() + return RandomState(seed=0) from numpy.testing import Tester test = Tester().test |