MCPcopy Create free account
hub / github.com/dask/dask / test_store_regions

Function test_store_regions

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

Source from the content-addressed store, hash-verified

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