Skip to content

Commit 8bdba69

Browse files
committed
Fix indexing bug
1 parent b521069 commit 8bdba69

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/blosc2/ndarray.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6319,6 +6319,18 @@ def take_along_axis(x: blosc2.Array, indices: blosc2.Array, axis: int = -1) -> N
63196319
return blosc2.asarray(x[key])
63206320

63216321

6322+
class MyChunkRange:
6323+
def __init__(self, start, stop, step=1, n=1):
6324+
self.start = start
6325+
self.stop = stop
6326+
self.step = step
6327+
self.n = n
6328+
6329+
def __iter__(self):
6330+
for k in range(math.ceil((self.stop - self.start) / self.step)):
6331+
yield (self.start + k * self.step) // self.n
6332+
6333+
63226334
def slice_to_chunktuple(s, n):
63236335
# Adapted from _slice_iter in ndindex.ChunkSize.as_subchunks.
63246336
start, stop, step = s.start, s.stop, s.step
@@ -6328,7 +6340,7 @@ def slice_to_chunktuple(s, n):
63286340
start = temp + 1
63296341
step = -step # get positive steps
63306342
if step > n:
6331-
return ((start + k * step) // n for k in range(ceiling(stop - start, step)))
6343+
return MyChunkRange(start, stop, step, n)
63326344
else:
63336345
return range(start // n, ceiling(stop, n))
63346346

tests/ndarray/test_ndarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def test_fancy_index(c):
361361
b = arr[row, d // 2 :: -1]
362362
n = nparr[row, d // 2 :: -1]
363363
np.testing.assert_allclose(b, n)
364-
b = arr[M // 2 :: -4, row, d // 2 :: -3]
364+
b = arr[M // 2 :: -4, row, d // 2 :: -3] # test stepsize > chunk_shape
365365
n = nparr[M // 2 :: -4, row, d // 2 :: -3]
366366
np.testing.assert_allclose(b, n)
367367

0 commit comments

Comments
 (0)