Skip to content

Vectorized EDF/BDF window decode fast path - #14214

Closed
bruAristimunha wants to merge 9 commits into
mne-tools:mainfrom
bruAristimunha:pr/3-edf-fastpath
Closed

Vectorized EDF/BDF window decode fast path#14214
bruAristimunha wants to merge 9 commits into
mne-tools:mainfrom
bruAristimunha:pr/3-edf-fastpath

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Reference issue (if any)

None. Part 3/5 of the IO-speedup series. Depends on #14213 (→ #14212).

What does this implement/fix?

Uniform-sampling-rate EDF/BDF windows decode through a strided gather plus an
optional-numba kernel writing calibrated samples straight into the output
buffer, replacing the per-channel Python loop. Big-endian chunks are
byteswapped to native order first; uniform stim channels apply the legacy
truncating bitmask on the fast path; projector reads keep the legacy route.
EDF/BDF/GDF file handles persist per process.

Random 2 s windows via public API vs main + earlier parts:
EDF 1472 → ~300 µs, BDF 2484 → ~406 µs.

Mixed-sampling-rate files intentionally keep the existing engine.

Additional information

AI disclosure: same as #14212.
CI note: held until the parent PR merges.

get_data resolves picks=None to arange directly instead of going through
string-based channel-name machinery on every call; _picks_to_idx gets an
early return for integer arrays already unique and in range (duplicate
picks keep taking the validating path); _mult_cal_one fuses gather,
type-cast, and calibration into a single elementwise pass.
FIF raw segments are read as byte-offset views into a PID-keyed memory
map of the file instead of open/seek/read per call; buffer entries are
selected with searchsorted on the sorted bounds. gzip, file-like objects,
and non-simple tag types keep the legacy path. The generic memory-map
cache in _read_segments_file also serves the other binary readers.
Uniform-sampling-rate EDF/BDF windows decode through a strided gather
plus an optional-numba kernel writing calibrated samples directly into
the caller's output buffer, replacing the per-channel Python loop.
Big-endian chunks are byteswapped to native order first; uniform stim
channels apply the legacy truncating bitmask on the fast path;
projector/compensation reads keep the exact legacy route. EDF/BDF/GDF
file handles persist per process (PID-keyed LRU).
cal_v/off_v/gain_v -> channel_calibration/channel_offset/channel_gain,
the uniform-row subsets get the uniform_ prefix, one_flat ->
decoded_block, arr3 -> record_grid, and the strided gather is named
digital_view. No behavior change.
@larsoner

Copy link
Copy Markdown
Member

Do we need the memmap code here given we can get it already (once we fix it) from preload=<str>? Maybe this can be a read-speed improvement involving strides, etc.?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants