Vectorize _find_duplicated_spikes_keep_first/last_iterative kernels.#4614
Open
grahamfindlay wants to merge 1 commit into
Open
Vectorize _find_duplicated_spikes_keep_first/last_iterative kernels.#4614grahamfindlay wants to merge 1 commit into
grahamfindlay wants to merge 1 commit into
Conversation
Let `N` be the number of spikes in the train, and `D` be the number of spikes flagged as duplicates (i.e. the fall within the censored period of an earlier kept spike). The old kernels were using `if i in indices_of_duplicates` for each of `N` spikes to check if the spike was a duplicate, which is `O(N*D)`. But for heavily contaminated units, `D` can be quite large. On long (48h) recordings, this was blowing up, and taking 56min to compute `sd_ratio` for 232 units. One unit took nearly 5min by itself. This approach is constant-time lookup, so `O(N)` total. New time on the 48h dataset is 10.6s total to compute `sd_ratio` for all units. Tested equivalence with the old method on both the real data and synthetic bursty trains, plus the existing test still passes (note for the future: the existing test should probably check the exact indices).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Let
Nbe the number of spikes in the train, andDbe the number of spikes flagged as duplicates (i.e. the fall within the censored period of an earlier kept spike).The old kernels were using
if i in indices_of_duplicatesfor each ofNspikes to check if the spike was a duplicate, which isO(N*D). But for heavily contaminated units,Dcan be quite large. On long (48h) recordings, this was blowing up, and taking 56min to computesd_ratiofor 232 units. One unit took nearly 5min by itself.This approach is constant-time lookup, so
O(N)total. New time on the 48h dataset is 10.6s total to computesd_ratiofor all units. Tested equivalence with the old method on both the real data and synthetic bursty trains, plus the existing test still passes (note for the future: the existing test should probably check the exact indices).Also switched
cache=Truetocache=Falseon thekeep_lastvariant to match its twin and conform with the rest of the codebase.