MCPcopy
hub / github.com/dask/dask / test_blockwise_cull

Function test_blockwise_cull

dask/tests/test_highgraph.py:235–265  ·  view source on GitHub ↗
(flat)

Source from the content-addressed store, hash-verified

233
234@pytest.mark.parametrize("flat", [True, False])
235def test_blockwise_cull(flat):
236 np = pytest.importorskip("numpy")
237 da = pytest.importorskip("dask.array")
238 if flat:
239 # Simple "flat" mapping between input and
240 # output indices
241 x = da.from_array(np.arange(40).reshape((4, 10)), (2, 4)) + 100
242 else:
243 # Complex mapping between input and output
244 # indices (outer product and transpose)
245 x = da.from_array(np.arange(10).reshape((10,)), (4,))
246 y = da.from_array(np.arange(10).reshape((10,)), (4,))
247 x = da.outer(x, y).transpose()
248
249 # Check that blockwise culling results in correct
250 # output keys and that full graph is not materialized
251 dsk = x.__dask_graph__()
252 select = (1, 1) # Select a single chunk
253 keys = {(x._name, *select)}
254 dsk_cull = dsk.cull(keys)
255 for name, layer in dsk_cull.layers.items():
256 old_name = name.rsplit("-", 1)[0]
257 if not isinstance(layer, dask.blockwise.Blockwise):
258 # The original layer shouldn't be Blockwise if the new one isn't
259 assert not isinstance(dsk.layers[old_name], dask.blockwise.Blockwise)
260 continue
261 assert isinstance(dsk.layers[old_name], dask.blockwise.Blockwise)
262 assert not layer.is_materialized()
263 out_keys = layer.get_output_keys()
264 assert out_keys == {(layer.output, *select)}
265 assert not layer.is_materialized()
266
267
268def test_len_does_not_materialize():

Callers

nothing calls this directly

Calls 10

reshapeMethod · 0.80
rsplitMethod · 0.80
arangeMethod · 0.45
transposeMethod · 0.45
outerMethod · 0.45
__dask_graph__Method · 0.45
cullMethod · 0.45
itemsMethod · 0.45
is_materializedMethod · 0.45
get_output_keysMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…