-
Notifications
You must be signed in to change notification settings - Fork 257
Vectorize per-channel PCA transform in run_for_all_spikes
#4488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
galenlynch
wants to merge
2
commits into
SpikeInterface:main
Choose a base branch
from
galenlynch:feat/vectorize-per-channel-pca
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+55
−17
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is me probably misreading but I'm super bad at parsing these type of > and < in general. If we have to be less than or = to the shape couldn't we run into an issue where we are = to the shape which is out of bounds?
ie an array of (4,5) the shape[0] = 4, but if I try to index on 4 it will be an out of bounds error. Again I don't work on the PC code at all so maybe I'm completely wrong here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean that the second <= should be just <?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I agree. It should be
to avoid any indexing error.
E,g. if nsamples = 90, traces shape is 300, and you have a spike at 210, then it would be valid, but L654 will fail because it'll try to access traces[300]...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we could get rid of the
valid_maskcompletely by extracting traces using amarginofmax(nbefore, nafter). @galenlynch do you mind if I give it a try in this PR?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's a bug here. This matches the original semantics (
if ... > traces.shape[0]: continue), and the original semantics were correct.The relevant code:
np.arange(nsamples)produces[0, 1, ..., nsamples-1]. So for a spike with offseto, the fancy indices accessed are[o, o+1, ..., o + nsamples - 1]. The maximum index accessed iso + nsamples - 1.For that to be in bounds, we need:
o + nsamples - 1 ≤ traces.shape[0] - 1⟺o + nsamples ≤ traces.shape[0]@alejoe91 your example is also not quite right:
With
offset = 210,nsamples = 90:offset + nsamples = 300 ≤ 300passes the masksample_indices = 210 + [0..89] = [210, 211, ..., 299]traces[[210, ..., 299]]: max index is 299, not 300.Changing the bound to
<would drop valid spikes at the end of the chunk.Using
get_chunk_with_marginis not the right fix because 1) I don't think there's a bug 2) would overfetch the data 3) would require other indexing logic changes.You're right that
valid_maskis leftover and unreachable logic replacing the original logic.Look at how
startandendare computed (lines 632–634):The traces array is tight-bracketed around exactly the spikes in
[i0, i1). Let's check the extremes:offset = spike_times[i0] - start - nbefore = 0→ accesses[0, nsamples-1](correct)offset = spike_times[i1-1] - spike_times[i0], sooffset + nsamples = spike_times[i1-1] - spike_times[i0] + nbefore + nafter = end - start = traces.shape[0]→ accesses up totraces.shape[0]-1(correct)So
valid_maskis always all-True on the happy path. The only time anything gets dropped is at absolute segment boundaries, and those are already handled by thei0 += 1 / i1 -= 1loop at lines 620–627 beforestart/endare even computed. Thevalid_maskis dead defensive code inherited from the original loop's continue checks.We could delete it entirely:
What do you think?