MCPcopy Create free account
hub / github.com/DedalusProject/dedalus / ChunkedRandomArray

Class ChunkedRandomArray

dedalus/tools/random_arrays.py:93–124  ·  view source on GitHub ↗

Random array with elements that are deterministically produced when indexed. This allows robustly constructing and selecting from a random array without requiring enough local memory to hold the entire array. Parameters ---------- shape : tuple of ints Shape of arra

Source from the content-addressed store, hash-verified

91
92
93class ChunkedRandomArray(IndexArray):
94 """
95 Random array with elements that are deterministically produced when indexed.
96 This allows robustly constructing and selecting from a random array without
97 requiring enough local memory to hold the entire array.
98
99 Parameters
100 ----------
101 shape : tuple of ints
102 Shape of array.
103 seed : int, optional
104 RNG seed. Default: None.
105 chunk_size : int, optional
106 Chunk size for drawing from distribution. Should be less than locally
107 available memory. Default: 2**20, corresponding to 8 MB of float64.
108 distribution : str, optional
109 Distribution name, corresponding to numpy random Generator method.
110 Default: 'uniform'.
111 **kw : dict
112 Other keywords passed to the distribution method.
113 """
114
115 def __init__(self, shape, seed=None, chunk_size=2**20, distribution='uniform', **kw):
116 super().__init__(shape)
117 self.seed = seed
118 self.chunk_size = chunk_size
119 self.distribution = distribution
120 self.kw = kw
121
122 def __getitem__(self, key):
123 indices = super().__getitem__(key)
124 return rng_elements(indices, self.seed, self.chunk_size, self.distribution, **self.kw)
125

Callers 1

fill_randomMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected