Skip to content

Commit 19c2deb

Browse files
committed
New fastpath for behaved output in slices_eval()
1 parent 9ea9f5b commit 19c2deb

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

blosc2/lazyexpr.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ def slices_eval(
553553
# Iterate over the operands and get the chunks
554554
chunks_idx, nchunks = get_chunks_idx(shape, chunks)
555555
lenout = 0
556+
behaved = False
556557
for nchunk in range(nchunks):
557558
coords = tuple(np.unravel_index(nchunk, chunks_idx))
558559
chunk_operands = {}
@@ -634,18 +635,22 @@ def slices_eval(
634635
out = blosc2.empty(shape_, dtype=result.dtype, **kwargs)
635636
else:
636637
out = blosc2.empty(shape_, dtype=result.dtype, **kwargs)
638+
# Check if the in out partitions are well-behaved (i.e. no padding)
639+
behaved = are_partitions_behaved(out.shape, out.chunks, out.blocks)
640+
print(f"Behaved: {behaved}")
637641

638-
if where is None:
639-
out[slice_] = result
640-
else:
641-
if len(where) == 2:
642-
out[slice_] = result
643-
elif len(where) == 1:
644-
lenres = len(result)
645-
out[lenout : lenout + lenres] = result
646-
lenout += lenres
642+
if where is None or len(where) == 2:
643+
if behaved:
644+
# Fast path
645+
out.schunk.update_data(nchunk, result, copy=False)
647646
else:
648-
raise ValueError("The where condition must be a tuple with one or two elements")
647+
out[slice_] = result
648+
elif len(where) == 1:
649+
lenres = len(result)
650+
out[lenout : lenout + lenres] = result
651+
lenout += lenres
652+
else:
653+
raise ValueError("The where condition must be a tuple with one or two elements")
649654

650655
if orig_slice is not None:
651656
if isinstance(out, np.ndarray):

0 commit comments

Comments
 (0)