Validate the random state, r Check a random seed or existing numpy RandomState and get back an initialized RandomState. Parameters ---------- random_state : int, None, np.random.RandomState or np.random.Generator The existing RandomState. If None, or an int, will be use
(random_state)
| 235 | |
| 236 | |
| 237 | def check_random_state(random_state): |
| 238 | """Validate the random state, r |
| 239 | |
| 240 | Check a random seed or existing numpy RandomState |
| 241 | and get back an initialized RandomState. |
| 242 | |
| 243 | Parameters |
| 244 | ---------- |
| 245 | random_state : int, None, np.random.RandomState or np.random.Generator |
| 246 | The existing RandomState. If None, or an int, will be used |
| 247 | to seed a new curand RandomState generator |
| 248 | """ |
| 249 | if isinstance(random_state, np.random.RandomState): |
| 250 | # we need to convert from numpy random state our internal random state |
| 251 | return implicit.gpu.RandomState(random_state.randint(2**31)) |
| 252 | |
| 253 | if isinstance(random_state, np.random.Generator): |
| 254 | # we need to convert from numpy random state our internal random state |
| 255 | return implicit.gpu.RandomState(random_state.integers(2**31)) |
| 256 | |
| 257 | # otherwise try to initialize a new one, and let it fail through |
| 258 | # on the numpy side if it doesn't work |
| 259 | return implicit.gpu.RandomState(random_state or int(time.time())) |