Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ChunkSize apply no indices on empty arrays #134

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ndindex/chunking.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ def num_chunks(self, shape):
"""
shape = asshape(shape)
d = [ceiling(i, c) for i, c in zip(shape, self)]
if 0 in d:
return 1
return prod(d)

def indices(self, shape):
Expand Down Expand Up @@ -134,7 +132,7 @@ def indices(self, shape):
raise ValueError("chunks dimensions must equal the array dimensions")
d = [ceiling(i, c) for i, c in zip(shape, self)]
if 0 in d:
yield Tuple(*[Slice(0, bool(i)*chunk_size, 1) for i, chunk_size in zip(d, self)]).expand(shape)
return
for p in product(*[range(i) for i in d]):
# p = (0, 0, 0), (0, 0, 1), ...
yield Tuple(*[Slice(chunk_size*i, min(chunk_size*(i + 1), n), 1)
Expand Down
2 changes: 2 additions & 0 deletions ndindex/tests/test_chunking.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def test_indices_error():
def test_num_chunks(chunk_size, shape):
chunk_size = ChunkSize(chunk_size)
assert chunk_size.num_chunks(shape) == len(list(chunk_size.indices(shape)))
if 0 in shape:
assert chunk_size.num_chunks(shape) == 0

@given(chunk_sizes(), chunk_shapes)
def test_indices(chunk_size, shape):
Expand Down
Loading