MCPcopy
hub / github.com/dask/dask / test_store_regions

Function test_store_regions

dask/array/tests/test_array_core.py:2160–2252  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2158
2159
2160def test_store_regions():
2161 d = da.ones((4, 4, 4), dtype=int, chunks=(2, 2, 2))
2162 a, b = d + 1, d + 2
2163 a = a[:, 1:, :].astype(float)
2164
2165 region = (slice(None, None, 2), slice(None), [1, 2, 4, 5])
2166
2167 # Single region:
2168 at = np.zeros(shape=(8, 3, 6))
2169 bt = np.zeros(shape=(8, 4, 6))
2170 v = store([a, b], [at, bt], regions=region, compute=False)
2171 assert all([isinstance(a, Array) for a in v])
2172 assert (at == 0).all() and (bt[region] == 0).all()
2173 results = dask.compute(*v)
2174 assert all([ev.size == 0 for ev in results])
2175 assert (at[region] == 2).all() and (bt[region] == 3).all()
2176 assert not (bt == 3).all() and not (bt == 0).all()
2177 assert not (at == 2).all() and not (at == 0).all()
2178
2179 # Multiple regions:
2180 at = np.zeros(shape=(8, 3, 6))
2181 bt = np.zeros(shape=(8, 4, 6))
2182 v = store([a, b], [at, bt], regions=[region, region], compute=False)
2183 assert (at == 0).all() and (bt[region] == 0).all()
2184 results = dask.compute(*v)
2185 assert all([ev.size == 0 for ev in results])
2186 assert (at[region] == 2).all() and (bt[region] == 3).all()
2187 assert not (bt == 3).all() and not (bt == 0).all()
2188 assert not (at == 2).all() and not (at == 0).all()
2189
2190 # Single region (keep result):
2191 for st_compute in [False, True]:
2192 at = np.zeros(shape=(8, 3, 6))
2193 bt = np.zeros(shape=(8, 4, 6))
2194 v = store(
2195 [a, b], [at, bt], regions=region, compute=st_compute, return_stored=True
2196 )
2197 assert isinstance(v, tuple)
2198 assert all([isinstance(e, da.Array) for e in v])
2199 if st_compute:
2200 for arr in v:
2201 assert_has_persisted_data(arr)
2202 else:
2203 assert (at == 0).all() and (bt[region] == 0).all()
2204
2205 ar, br = v
2206 assert ar.dtype == a.dtype
2207 assert br.dtype == b.dtype
2208 assert ar.shape == a.shape
2209 assert br.shape == b.shape
2210 assert ar.chunks == a.chunks
2211 assert br.chunks == b.chunks
2212
2213 ar, br = da.compute(ar, br)
2214 assert (at[region] == 2).all() and (bt[region] == 3).all()
2215 assert not (bt == 3).all() and not (bt == 0).all()
2216 assert not (at == 2).all() and not (at == 0).all()
2217 assert (br == 3).all()

Callers

nothing calls this directly

Calls 8

storeFunction · 0.90
allFunction · 0.85
onesMethod · 0.45
astypeMethod · 0.45
zerosMethod · 0.45
allMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…