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
| 91 | |
| 92 | |
| 93 | class 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 |