-
Notifications
You must be signed in to change notification settings - Fork 226
Speedup template_similarity #4211
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1ce0aa5
Caching the norms
yger 254b7a3
Use sparsity internaly while getting templates in analyzer
yger 13679f6
WIP
yger 30138cf
Patch for numba
yger e790205
syntax
yger 4628f1d
Patch for numba
yger 8c1b54b
Patch for numba
yger c60c7f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d5e7f43
Cleaning
yger 1e1d3aa
Cleaning
yger 3031d9e
Speedup merging
yger b53a9f0
Message
yger d3a6fee
Merge branch 'main' into speedup_similarity
samuelgarcia 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,16 +110,16 @@ def _merge_extension_data( | |
| n = all_new_unit_ids.size | ||
| similarity = np.zeros((n, n), dtype=old_similarity.dtype) | ||
|
|
||
| local_mask = ~np.isin(all_new_unit_ids, new_unit_ids) | ||
| sub_units_ids = all_new_unit_ids[local_mask] | ||
| sub_units_inds = np.flatnonzero(local_mask) | ||
| old_units_inds = self.sorting_analyzer.sorting.ids_to_indices(sub_units_ids) | ||
|
|
||
| # copy old similarity | ||
| for unit_ind1, unit_id1 in enumerate(all_new_unit_ids): | ||
| if unit_id1 not in new_unit_ids: | ||
| old_ind1 = self.sorting_analyzer.sorting.id_to_index(unit_id1) | ||
| for unit_ind2, unit_id2 in enumerate(all_new_unit_ids): | ||
| if unit_id2 not in new_unit_ids: | ||
| old_ind2 = self.sorting_analyzer.sorting.id_to_index(unit_id2) | ||
| s = self.data["similarity"][old_ind1, old_ind2] | ||
| similarity[unit_ind1, unit_ind2] = s | ||
| similarity[unit_ind1, unit_ind2] = s | ||
| for old_ind1, unit_ind1 in zip(old_units_inds, sub_units_inds): | ||
| s = self.data["similarity"][old_ind1, old_units_inds] | ||
| similarity[unit_ind1, sub_units_inds] = s | ||
| similarity[sub_units_inds, unit_ind1] = s | ||
|
|
||
| # insert new similarity both way | ||
| for unit_ind, unit_id in enumerate(all_new_unit_ids): | ||
|
|
@@ -319,9 +319,14 @@ def _compute_similarity_matrix_numba( | |
| sparsity_mask[i, :], other_sparsity_mask | ||
| ) # shape (other_num_templates, num_channels) | ||
| elif support == "union": | ||
| connected_mask = np.logical_and(sparsity_mask[i, :], other_sparsity_mask) | ||
| not_connected_mask = np.sum(connected_mask, axis=1) == 0 | ||
| local_mask = np.logical_or( | ||
| sparsity_mask[i, :], other_sparsity_mask | ||
| ) # shape (other_num_templates, num_channels) | ||
| for local_i in np.flatnonzero(not_connected_mask): | ||
| local_mask[local_i] = False | ||
|
|
||
|
Comment on lines
+322
to
+329
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course! |
||
| elif support == "dense": | ||
| local_mask = np.ones((other_num_templates, num_channels), dtype=np.bool_) | ||
|
|
||
|
|
@@ -386,7 +391,11 @@ def get_overlapping_mask_for_one_template(template_index, sparsity, other_sparsi | |
| if support == "intersection": | ||
| mask = np.logical_and(sparsity[template_index, :], other_sparsity) # shape (other_num_templates, num_channels) | ||
| elif support == "union": | ||
| connected_mask = np.logical_and(sparsity[template_index, :], other_sparsity) | ||
| not_connected_mask = np.sum(connected_mask, axis=1) == 0 | ||
| mask = np.logical_or(sparsity[template_index, :], other_sparsity) # shape (other_num_templates, num_channels) | ||
| for i in np.flatnonzero(not_connected_mask): | ||
| mask[i] = False | ||
| elif support == "dense": | ||
| mask = np.ones(other_sparsity.shape, dtype=bool) | ||
| return mask | ||
|
|
||
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.
Cool. Smater