-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
29 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
import numpy as np | ||
from funlib.persistence.arrays.slices import chain_slices | ||
from dask.array.optimization import fuse_slice | ||
from functools import reduce | ||
import pytest | ||
|
||
|
||
def test_slice_chaining(): | ||
|
||
base = np.s_[::2, 0, :4] | ||
def combine_slices(*slices): | ||
return reduce(fuse_slice, slices) | ||
|
||
base = np.s_[::2, :, :4] | ||
|
||
# chain with index expressions | ||
|
||
s1 = chain_slices(base, np.s_[0]) | ||
assert s1 == np.s_[0, 0, :4] | ||
s1 = combine_slices(base, np.s_[0]) | ||
assert s1 == np.s_[0, :, :4] | ||
|
||
s2 = chain_slices(s1, np.s_[1]) | ||
assert s2 == np.s_[0, 0, 1] | ||
s2 = combine_slices(s1, np.s_[1]) | ||
assert s2 == np.s_[0, 1, :4] | ||
|
||
# chain with index arrays | ||
|
||
s1 = chain_slices(base, np.s_[[0, 1, 1, 2, 3, 5], :]) | ||
assert s1 == np.s_[[0, 2, 2, 4, 6, 10], 0, :4] | ||
s1 = combine_slices(base, np.s_[[0, 1, 1, 2, 3, 5], :]) | ||
assert s1 == np.s_[[0, 2, 2, 4, 6, 10], 0:, :4] | ||
|
||
# ...and another index array | ||
s21 = chain_slices(s1, np.s_[[0, 3], :]) | ||
assert s21 == np.s_[[0, 4], 0, :4] | ||
with pytest.raises(NotImplementedError): | ||
# this is not supported because the combined indexing | ||
# operation would not behave the same as the individual | ||
# indexing operations performed in sequence | ||
combine_slices(s1, np.s_[[0, 3], 2]) | ||
|
||
# ...and a slice() expression | ||
s22 = chain_slices(s1, np.s_[1:4]) | ||
assert s22 == np.s_[[2, 2, 4], 0, :4] | ||
s22 = combine_slices(s1, np.s_[1:4]) | ||
assert s22 == np.s_[[2, 2, 4], 0:, :4] | ||
|
||
# chain with slice expressions | ||
|
||
s1 = chain_slices(base, np.s_[10:20, ::2]) | ||
assert s1 == np.s_[20:40:2, 0, :4:2] | ||
s1 = combine_slices(base, np.s_[10:20, ::2, 0]) | ||
assert s1 == np.s_[20:40:2, 0::2, 0] |