Coerces input into a random number generator. If the input is None, then a global random state is returned. If the input is a numeric value, then that is used as a seed to construct a random state. Otherwise the input is returned as-is. Adapted from [1]_. Args: rng (i
(rng=None)
| 386 | |
| 387 | |
| 388 | def ensure_rng(rng=None): |
| 389 | """Coerces input into a random number generator. |
| 390 | |
| 391 | If the input is None, then a global random state is returned. |
| 392 | |
| 393 | If the input is a numeric value, then that is used as a seed to construct a |
| 394 | random state. Otherwise the input is returned as-is. |
| 395 | |
| 396 | Adapted from [1]_. |
| 397 | |
| 398 | Args: |
| 399 | rng (int | numpy.random.RandomState | None): |
| 400 | if None, then defaults to the global rng. Otherwise this can be an |
| 401 | integer or a RandomState class |
| 402 | Returns: |
| 403 | (numpy.random.RandomState) : rng - |
| 404 | a numpy random number generator |
| 405 | |
| 406 | References: |
| 407 | .. [1] https://gitlab.kitware.com/computer-vision/kwarray/blob/master/kwarray/util_random.py#L270 # noqa: E501 |
| 408 | """ |
| 409 | |
| 410 | if rng is None: |
| 411 | rng = np.random.mtrand._rand |
| 412 | elif isinstance(rng, int): |
| 413 | rng = np.random.RandomState(rng) |
| 414 | else: |
| 415 | rng = rng |
| 416 | return rng |
| 417 | |
| 418 | |
| 419 | def random_boxes(num=1, scale=1, rng=None): |
no outgoing calls
no test coverage detected