Skip to content

Commit f903cdd

Browse files
Address review: drop unused batched reader, harden pick fast path
- Remove Raw._get_windows (unused in this changeset; will land with its first consumer). - _picks_to_idx integer fast path now rejects duplicate picks explicitly via np.unique (suggested in review), keeping semantics identical to the slow path. - Add changelog fragment.
1 parent 564a978 commit f903cdd

3 files changed

Lines changed: 14 additions & 40 deletions

File tree

doc/changes/dev/14212.bugfix.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sped up raw data access for workloads making many small reads:
2+
``Raw.get_data`` no longer materializes the full time axis when ``tmin`` and
3+
``tmax`` are unset, resolves ``picks=None`` without channel-name machinery,
4+
and ``_mult_cal_one`` applies gather/type-cast/calibration in a single pass.

mne/_fiff/pick.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,15 +1337,16 @@ def _picks_to_idx(
13371337
# Fast path: an integer ndarray with all values already in range needs no
13381338
# copy or further checks. This matters for callers resolving picks on
13391339
# every access (e.g., Raw.get_data in deep-learning training loops).
1340-
if (
1341-
picks.dtype.kind == "i"
1342-
and picks.size
1343-
and picks.min() >= 0
1344-
and picks.max() < n_chan
1345-
):
1346-
if return_kind:
1347-
return picks, picked_ch_type_or_generic
1348-
return picks
1340+
if picks.dtype.kind == "i" and len(picks):
1341+
sorted_picks = np.unique(picks)
1342+
if (
1343+
len(sorted_picks) == len(picks)
1344+
and sorted_picks[0] >= 0
1345+
and sorted_picks[-1] < n_chan
1346+
):
1347+
if return_kind:
1348+
return picks, picked_ch_type_or_generic
1349+
return picks
13491350
picks = picks.astype(int)
13501351

13511352
#

mne/io/base.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -877,37 +877,6 @@ def _parse_get_set_params(self, item):
877877

878878
return sel, start, stop
879879

880-
def _get_windows(self, starts, width, *, out=None, sel=None):
881-
"""Read many equal-width windows with setup shared across them."""
882-
starts = np.atleast_1d(np.asarray(starts, dtype=np.int64)).ravel()
883-
width = int(width)
884-
if width <= 0:
885-
raise ValueError(f"width must be positive, got {width}")
886-
n_times = self.n_times
887-
bad = (starts < 0) | (starts + width > n_times)
888-
if bad.any():
889-
raise ValueError(
890-
f"window out of bounds at index {int(np.flatnonzero(bad)[0])}"
891-
)
892-
n_out = self.info["nchan"] if sel is None else len(sel)
893-
if out is None:
894-
out = np.empty((len(starts), n_out, width), dtype=self._dtype)
895-
elif out.shape != (len(starts), n_out, width):
896-
raise ValueError(
897-
f"out has shape {out.shape}, need {(len(starts), n_out, width)}"
898-
)
899-
elif out.dtype not in (np.float64, np.float32):
900-
raise ValueError(
901-
f"out dtype must be float64 or float32, got {out.dtype}"
902-
)
903-
for j, s0 in enumerate(starts):
904-
self._read_segment(
905-
start=int(s0), stop=int(s0) + width,
906-
sel=sel,
907-
data_buffer=out[j],
908-
)
909-
return out
910-
911880
def __getitem__(self, item):
912881
"""Get raw data and times.
913882

0 commit comments

Comments
 (0)