Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/annbatch/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,11 @@ def __iter__(
in_memory_indices: None | np.ndarray = self._maybe_accumulate_indices(dataset_index_to_rows)
for split in splits:
sel = inv[split]

# Use basic slicing for contiguous selections to avoid costly fancy indexing on the loaded memory
if len(sel) > 0 and (sel[-1] - sel[0] == len(sel) - 1 and np.all(np.diff(sel) == 1)):
sel = slice(sel[0], sel[-1] + 1)

data = in_memory_data[sel]
yield {
"X": data if not self._to_torch else to_torch(data, self._preload_to_gpu),
Expand Down
Loading