Repository navigation
Speed up common median reference on channel-sized axes - #4836
JESUSROYETH wants to merge 2 commits into
Conversation
np.sort vectorises 32- and 64-bit sorts, and on the default chain's float32 output it beats the counting kernel (29 vs 39 ms per 1 s of 384 channels) and np.median (100 ms). This is the approach of SpikeInterface#4836. It also covers float64 and needs no numba. The int16 histogram kernel stays, since np.sort is 2.6x slower than np.median there.
Sorting float rows for the median, in beec896, follows @JESUSROYETH's approach in SpikeInterface#4836. Co-authored-by: JESUSROYETH <[email protected]>
|
Partly: float32 traces are ~55% faster (384 ch 3.29 s to 1.46 s, 32 ch 0.39 s to 0.18 s; the author reported 3.9x on 384 ch), outputs identical, but int16 traces, which is what raw Neuropixels data is, are slower: +165% on 384 ch (2.5 s to 6.6 s) and +32% on 32 ch. A micro-benchmark on this machine (Ryzen 9 5950X, numpy 2.5.5) shows why: A/B vs
Outputs identical to @JESUSROYETH did you use float or ints in your tests? System
|
|
Hi @alejoe91, thanks for checking this. The reported timings were for float32 at the common-reference stage. The public 384-channel snippet was bandpass-filtered with dtype="float32", and the full tridesclous2 run also uses float32 before common referencing through its default preprocessing. |
Or use the |
|
To wrap this up, let's use the new function for |
|
@JESUSROYETH maybe we could simply go with #4854 , since it's basically the same implementation for float and a numba version for ints. Is it ok for you? |
|
Yes @alejoe91, that's fine with me |
Summary
Common median reference currently calls
np.medianfor each trace chunk. For the short channel axis used here, NumPy's full sort path turns out faster than its partition-based median path.This adds a private reduction helper: one or two numeric channels use their equivalent mean, finite numeric arrays with at least four channels sort and average the middle value(s), and three-channel, NaN, empty, or non-numeric inputs keep
np.median. No public API changes.Benchmark
I ran a complete cold-process
run_sorter("tridesclous2"), 20-minute/32-channel recording,n_jobs=1, on an Intel Sapphire Rapids box, five alternating pairs:Each of the five paired runs improved, 10.02–18.97%. On SpikeInterface's public 384-channel NHP snippet, the CMR reduction itself comes out 3.89× faster, with identical output hashes.
I ran the common-reference tests too:
16 passed, 1 skipped, Black/style clean. This is complementary to #4564 — it cuts default single-thread work without adding threading.