diff options
author | Kilian <kilian.fatras@gmail.com> | 2018-06-26 11:10:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-26 11:10:40 -0700 |
commit | b4bc86176a5712fdd2f930fbf5d1968edd5efa5e (patch) | |
tree | 075c694496216f0a6db61e879ece5eb2e799fc07 /ot/utils.py | |
parent | 208ff4627ba28aa3f35328c5928324019c23ddac (diff) | |
parent | 327b0c6e0ccb0c9453179eb316021c34bcdffec4 (diff) |
Merge branch 'master' into stochastic_OT
Diffstat (limited to 'ot/utils.py')
-rw-r--r-- | ot/utils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ot/utils.py b/ot/utils.py index 17983f2..7dac283 100644 --- a/ot/utils.py +++ b/ot/utils.py @@ -225,6 +225,26 @@ def check_params(**kwargs): return check +def check_random_state(seed): + """Turn seed into a np.random.RandomState instance + Parameters + ---------- + seed : None | int | instance of RandomState + If seed is None, return the RandomState singleton used by np.random. + If seed is an int, return a new RandomState instance seeded with seed. + If seed is already a RandomState instance, return it. + Otherwise raise ValueError. + """ + if seed is None or seed is np.random: + return np.random.mtrand._rand + if isinstance(seed, (int, np.integer)): + return np.random.RandomState(seed) + if isinstance(seed, np.random.RandomState): + return seed + raise ValueError('{} cannot be used to seed a numpy.random.RandomState' + ' instance'.format(seed)) + + class deprecated(object): """Decorator to mark a function or class as deprecated. |