def test_fuse_slice(): assert fuse_slice(slice(10, 15), slice(0, 5, 2)) == slice(10, 15, 2) assert fuse_slice((slice(100, 200), ), (None, slice(10, 20))) == ( None, slice(110, 120), ) assert fuse_slice((slice(100, 200), ), (slice(10, 20), None)) == ( slice(110, 120), None, ) assert fuse_slice((1, ), (None, )) == (1, None) assert fuse_slice((1, slice(10, 20)), (None, None, 3, None)) == ( 1, None, None, 13, None, ) with pytest.raises(NotImplementedError): fuse_slice(slice(10, 15, 2), -1) # Regression test for #3076 with pytest.raises(NotImplementedError): fuse_slice(None, np.array([0, 0]))
def test_nonfusible_fancy_indexing(): nil = slice(None) cases = [# x[:, list, :][int, :, :] ((nil, [1, 2, 3], nil), (0, nil, nil)), # x[int, :, :][:, list, :] ((0, nil, nil), (nil, [1, 2, 3], nil)), # x[:, list, :, :][:, :, :, int] ((nil, [1, 2], nil, nil), (nil, nil, nil, 0))] for a, b in cases: with pytest.raises(NotImplementedError): fuse_slice(a, b)
def write_blocks(source, target, region: Optional[Tuple[slice, ...]]) -> da.Array: """ Return a dask array with where each chunk contains the result of writing each chunk of `source` to `target`. """ slices = slices_from_chunks(source.chunks) if region: slices = [fuse_slice(region, slc) for slc in slices] source_name = 'store-source-' + tokenize(source) store_name = 'store-' + tokenize(source) layers = {source_name: source.__dask_graph__()} deps = {source_name: set()} dsk = {} chunks = tuple((1,) * s for s in source.blocks.shape) for slice, key in zip(slices, flatten(source.__dask_keys__())): dsk[(store_name,) + key[1:]] = (ndwrapper, store_chunk, source.ndim, key, target, slice) layers[store_name] = dsk deps[store_name] = {source_name} store_dsk = HighLevelGraph(layers, deps) return da.Array(store_dsk, store_name, shape=source.blocks.shape, chunks=chunks, dtype=int)
def test_fuse_slice(): assert fuse_slice(slice(10, 15), slice(0, 5, 2)) == slice(10, 15, 2) assert (fuse_slice((slice(100, 200),), (None, slice(10, 20))) == (None, slice(110, 120))) assert (fuse_slice((slice(100, 200),), (slice(10, 20), None)) == (slice(110, 120), None)) assert (fuse_slice((1,), (None,)) == (1, None)) assert (fuse_slice((1, slice(10, 20)), (None, None, 3, None)) == (1, None, None, 13, None)) with pytest.raises(NotImplementedError): fuse_slice(slice(10, 15, 2), -1) # Regression test for #3076 with pytest.raises(NotImplementedError): fuse_slice(None, np.array([0, 0]))
def test_fuse_slice_with_lists(): assert fuse_slice(slice(10, 20, 2), [1, 2, 3]) == [12, 14, 16] assert fuse_slice([10, 20, 30, 40, 50], [3, 1, 2]) == [40, 20, 30] assert fuse_slice([10, 20, 30, 40, 50], 3) == 40 assert fuse_slice([10, 20, 30, 40, 50], -1) == 50 assert fuse_slice([10, 20, 30, 40, 50], slice(1, None, 2)) == [20, 40] assert fuse_slice((slice(None), slice(0, 10), [1, 2, 3]), (slice(None), slice(1, 5), slice(None))) == (slice(0, None), slice(1, 5), [1, 2, 3]) assert fuse_slice((slice(None), slice(None), [1, 2, 3]), (slice(None), slice(1, 5), 1)) == (slice(0, None), slice(1, 5), 2)
def test_fuse_slice(): assert fuse_slice(slice(10, 15), slice(0, 5, 2)) == slice(10, 15, 2) assert (fuse_slice((slice(100, 200), ), (None, slice(10, 20))) == (None, slice(110, 120))) assert (fuse_slice((slice(100, 200), ), (slice(10, 20), None)) == (slice(110, 120), None)) assert (fuse_slice((1, ), (None, )) == (1, None)) assert (fuse_slice((1, slice(10, 20)), (None, None, 3, None)) == (1, None, None, 13, None)) with pytest.raises(NotImplementedError): fuse_slice(slice(10, 15, 2), -1)
def test_fuse_slice(): assert fuse_slice(slice(10, 15), slice(0, 5, 2)) == slice(10, 15, 2) assert (fuse_slice((slice(100, 200),), (None, slice(10, 20))) == (None, slice(110, 120))) assert (fuse_slice((slice(100, 200),), (slice(10, 20), None)) == (slice(110, 120), None)) assert (fuse_slice((1,), (None,)) == (1, None)) assert (fuse_slice((1, slice(10, 20)), (None, None, 3, None)) == (1, None, None, 13, None)) with pytest.raises(NotImplementedError): fuse_slice(slice(10, 15, 2), -1)
def test_fuse_slice(): assert fuse_slice(slice(10, 15), slice(0, 5, 2)) == slice(10, 15, 2) assert fuse_slice((slice(100, 200),), (None, slice(10, 20))) == \ (None, slice(110, 120)) assert fuse_slice((slice(100, 200),), (slice(10, 20), None)) == \ (slice(110, 120), None) assert fuse_slice((1,), (None,)) == \ (1, None) assert fuse_slice((1, slice(10, 20)), (None, None, 3, None)) == \ (1, None, None, 13, None) assert (raises(NotImplementedError, lambda: fuse_slice(slice(10, 15, 2), -1)) or fuse_slice(slice(10, 15, 2), -1) == 14)