summaryrefslogtreecommitdiff
path: root/ot/utils.py
diff options
context:
space:
mode:
authorRémi Flamary <remi.flamary@gmail.com>2018-06-11 12:01:27 +0200
committerRémi Flamary <remi.flamary@gmail.com>2018-06-11 12:01:27 +0200
commitef17fcd2d5e85b986ff21d8039483bdaf03e37da (patch)
tree25cf5915a26273b3e0726494ed4a1405ce1e2786 /ot/utils.py
parent8046b8c424d7b80f520e212e2bf8de41cb624aab (diff)
parent530dc93a60e9b81fb8d1b44680deea77dacf660b (diff)
Merge branch 'master' into smooth_ot
Diffstat (limited to 'ot/utils.py')
-rw-r--r--ot/utils.py20
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.