Repository navigation
Extract margin tapering and make chunk ownership explicit - #4887
galenlynch wants to merge 4 commits into
Conversation
Keep the taper private and accept a precomputed window so phase_shift can reuse it across chunks. Add an explicit copy option to the margin helpers so in-place tapering cannot modify parent data when no cast is needed. Preserve the existing window_on_margin behavior and verify exact FFT output and parent isolation for interior and boundary chunks.
|
Thanks @galenlynch this is very nice, will review next week (and the cool FIR phase shift implementation) but wanted to ask here because I was thinking about it recently - do you think how the e.g. this can happen: (this mostly effects It would be nice to enforce a copy at the root |
I agree! We should make the This will also fix #4563 |
|
Thanks @JoeZiminski! Agreed: the mix of views and copies is a trap, as your
I'd avoid always copying because most nodes already return a fresh array, so a copy in every Code that writes into Happy to do it in a follow-up. |
The conflict resolution in 97a1f73 took the older side for the taper changes. That brought back the public apply_raised_cosine_taper, the FFT path that tapers the chunk itself, and the phase-shift benchmark script. The taper now lives in SpikeInterface#4887, so the FFT path goes back to get_chunk_with_margin(window_on_margin=True), which tapers a buffer it owns rather than one that may be a view of the parent's traces. HAVE_NUMBA keeps its find_spec check but imports importlib.util, which importing importlib alone does not guarantee.
With round=True, astype rounded the array returned by its parent in place. When the parent returns a view of stored data, as NumpyRecording does, that rounded the source recording too.
NumpyRecording returned writable views of its stored arrays, so writing into get_traces() output silently changed the recording. It now keeps a read-only view, as binary and shared-memory recordings already are, so such writes raise. The caller's own array stays writable.
get_chunk_with_margincan return a view of parent data when no padding or casting is needed. Moving tapering outside that helper therefore requires an explicit way to obtain a buffer that callers can safely modify.This extracts a private
_taper_margins(traces, window)helper and addscopy=Trueto both margin helpers.phase_shiftrequests an owned buffer and builds its raised-cosine window once per segment, reusing it across chunks. Existingwindow_on_margin=Truebehavior remains supported.Split out from #4563 because the FIR implementation no longer depends on this refactor.
Validation: six focused tests pass, including exact agreement with the legacy FFT path for int16, float32, and float64 inputs, and checks that read-only parent arrays remain untouched at interior and boundary chunks.