Skip to content

Commit 872d6a4

Browse files
committed
data: Skip the O(n) np.delete in index_handle_oob for numeric indices
index_handle_oob dropped out-of-bounds (None) entries with np.delete(idx, where(idx == None)) on every 1-D array index. Only an object array can hold those sentinels; a plain numeric index has none, so the call was a wasted O(n) copy (plus an elementwise '== None'). Return the index unchanged in that case. A 65536-point assignment drops from ~1.6 ms to ~0.17 ms; the object-array path (real OOB drops) is unchanged.
1 parent ad8366a commit 872d6a4

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

devito/data/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ def index_handle_oob(idx):
124124
# A boolean mask, nothing to do
125125
return idx
126126
elif idx.ndim == 1:
127+
# Only an object array can carry the None sentinels; a plain numeric
128+
# index has no out-of-bounds entries to drop, so skip the O(n) copy.
129+
if idx.dtype != object:
130+
return idx
127131
return np.delete(idx, np.where(idx == None)) # noqa
128132
else:
129133
raise ValueError("Cannot identify OOB accesses when using "

0 commit comments

Comments
 (0)