File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -225,6 +225,26 @@ def check_params(**kwargs):
225225 return check
226226
227227
228+ def check_random_state (seed ):
229+ """Turn seed into a np.random.RandomState instance
230+ Parameters
231+ ----------
232+ seed : None | int | instance of RandomState
233+ If seed is None, return the RandomState singleton used by np.random.
234+ If seed is an int, return a new RandomState instance seeded with seed.
235+ If seed is already a RandomState instance, return it.
236+ Otherwise raise ValueError.
237+ """
238+ if seed is None or seed is np .random :
239+ return np .random .mtrand ._rand
240+ if isinstance (seed , (int , np .integer )):
241+ return np .random .RandomState (seed )
242+ if isinstance (seed , np .random .RandomState ):
243+ return seed
244+ raise ValueError ('{} cannot be used to seed a numpy.random.RandomState'
245+ ' instance' .format (seed ))
246+
247+
228248class deprecated (object ):
229249
230250 """Decorator to mark a function or class as deprecated.
You can’t perform that action at this time.
0 commit comments