MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / ensure_rng

Function ensure_rng

util/utils.py:388–416  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

386
387
388def 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
419def random_boxes(num=1, scale=1, rng=None):

Callers 2

randomMethod · 0.90
random_boxesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected