MCPcopy
hub / github.com/dask/dask / random_state_data

Function random_state_data

dask/utils.py:542–563  ·  view source on GitHub ↗

Return a list of arrays that can initialize ``np.random.RandomState``. Parameters ---------- n : int Number of arrays to return. random_state : int or np.random.RandomState, optional If an int, is used to seed a new ``RandomState``.

(n: int, random_state=None)

Source from the content-addressed store, hash-verified

540
541
542def random_state_data(n: int, random_state=None) -> list:
543 """Return a list of arrays that can initialize
544 ``np.random.RandomState``.
545
546 Parameters
547 ----------
548 n : int
549 Number of arrays to return.
550 random_state : int or np.random.RandomState, optional
551 If an int, is used to seed a new ``RandomState``.
552 """
553 import numpy as np
554
555 if not all(
556 hasattr(random_state, attr) for attr in ["normal", "beta", "bytes", "uniform"]
557 ):
558 random_state = np.random.RandomState(random_state)
559
560 random_data = random_state.bytes(624 * n * 4) # `n * 624` 32-bit integers
561 l = list(np.frombuffer(random_data, dtype="<u4").reshape((n, -1)))
562 assert len(l) == n
563 return l
564
565
566def is_integer(i) -> bool:

Callers 9

random_state_dataMethod · 0.90
sampleMethod · 0.90
_layerMethod · 0.90
with_specFunction · 0.90
test_random_state_dataFunction · 0.90
choiceMethod · 0.90
_wrap_funcFunction · 0.90
_infoMethod · 0.90
state_dataMethod · 0.90

Calls 3

allFunction · 0.85
reshapeMethod · 0.80
RandomStateMethod · 0.45

Tested by 1

test_random_state_dataFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…