(flat)
| 233 | |
| 234 | @pytest.mark.parametrize("flat", [True, False]) |
| 235 | def 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 | |
| 268 | def test_len_does_not_materialize(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…