Turn seed into a numpy.random.mtrand.RandomState instance. If seed is None, return the RandomState singleton used by np.random.mtrand. If seed is an int, return a new RandomState instance seeded with seed. If seed is already a RandomState instance, return it. Otherwise raise ValueEr
(seed)
| 205 | |
| 206 | # adapted from scikit-learn utils/validation.py |
| 207 | def check_random_state(seed): |
| 208 | """Turn seed into a numpy.random.mtrand.RandomState instance. |
| 209 | |
| 210 | If seed is None, return the RandomState singleton used by np.random.mtrand. |
| 211 | If seed is an int, return a new RandomState instance seeded with seed. |
| 212 | If seed is already a RandomState instance, return it. |
| 213 | Otherwise raise ValueError. |
| 214 | """ |
| 215 | if seed is None or seed is np.random: |
| 216 | return np.random.mtrand._rand |
| 217 | if isinstance(seed, int | np.integer): |
| 218 | return np.random.mtrand.RandomState(seed) |
| 219 | if isinstance(seed, np.random.mtrand.RandomState): |
| 220 | return seed |
| 221 | if isinstance(seed, np.random.Generator): |
| 222 | return seed |
| 223 | raise ValueError( |
| 224 | f"{seed!r} cannot be used to seed a numpy.random.mtrand.RandomState instance" |
| 225 | ) |
| 226 | |
| 227 | |
| 228 | def _check_event_id(event_id, events): |
no outgoing calls