Skip to content

Commit 9fa21c9

Browse files
authored
Merge pull request #3474 from yger/mf_sparse
Sparsify the weights
2 parents 0ae32e7 + b9f2cc8 commit 9fa21c9

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/spikeinterface/sortingcomponents/peak_detection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ def __init__(
631631
weight_method={},
632632
):
633633
PeakDetector.__init__(self, recording, return_output=True)
634+
from scipy.sparse import csr_matrix
634635

635636
if not HAVE_NUMBA:
636637
raise ModuleNotFoundError('matched_filtering" needs numba which is not installed')
@@ -664,7 +665,7 @@ def __init__(
664665
self.num_templates *= 2
665666

666667
self.weights = self.weights.reshape(self.num_templates * self.num_z_factors, -1)
667-
668+
self.weights = csr_matrix(self.weights)
668669
random_data = get_random_data_chunks(recording, return_scaled=False, **random_chunk_kwargs)
669670
conv_random_data = self.get_convolved_traces(random_data)
670671
medians = np.median(conv_random_data, axis=1)
@@ -734,10 +735,10 @@ def compute(self, traces, start_frame, end_frame, segment_index, max_margin):
734735
return (local_peaks,)
735736

736737
def get_convolved_traces(self, traces):
737-
import scipy.signal
738+
from scipy.signal import oaconvolve
738739

739-
tmp = scipy.signal.oaconvolve(self.prototype[None, :], traces.T, axes=1, mode="valid")
740-
scalar_products = np.dot(self.weights, tmp)
740+
tmp = oaconvolve(self.prototype[None, :], traces.T, axes=1, mode="valid")
741+
scalar_products = self.weights.dot(tmp)
741742
return scalar_products
742743

743744

0 commit comments

Comments
 (0)