Skip to content

Commit a082543

Browse files
committed
remove joint calculation of dot product and norms
1 parent c07f466 commit a082543

1 file changed

Lines changed: 0 additions & 84 deletions

File tree

src/spikeinterface/comparison/comparisontools.py

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -108,90 +108,6 @@ def do_count_event(sorting):
108108
return event_counts
109109

110110

111-
def get_optimized_compute_dot_product_all():
112-
"""
113-
This function wraps around the compute_dot_product function,
114-
which uses numba for JIT compilation. It caches the compiled function
115-
for improved performance on subsequent calls.
116-
"""
117-
118-
if hasattr(get_optimized_compute_dot_product_all, "_cached_function"):
119-
return get_optimized_compute_dot_product_all._cached_function
120-
121-
import numba
122-
123-
@numba.jit(nopython=True, nogil=True)
124-
def compute_dot_product(sample_frames, unit_indices, num_units_sorting1, num_units_sorting2, delta_frames):
125-
"""
126-
Compute the dot product matrix for two spike trains.
127-
128-
Note that the sample frames and unit indices must be sorted by sample frames.
129-
Also note that the unit_indices corresponding to the second spike train must be
130-
shifted by num_units_sorting1.
131-
132-
This creates a matrix that can be divided in four quadrants. Clokwise from top left:
133-
1. The dot product of spikes in the first spike train with themselves.
134-
2. The dot product of spikes in the first spike train with spikes in the second spike train.
135-
3. The dot product of spikes in the second spike train with spikes in the first spike train.
136-
4. The dot product of spikes in the second spike train with themselves.
137-
138-
Note that the norms of of the spike trains are the diagonals of the 1 and 4 quadrants.
139-
That is the only part of those quadrants that we need to calculate.
140-
141-
Parameters
142-
----------
143-
sample_frames : ndarray
144-
An array of integer frame numbers corresponding to spike times.
145-
unit_indices : ndarray
146-
An array of integers where unit_indices[i] gives the unit index associated with
147-
the spike at sample_frames[i]. Note that the unit_indices of the second spike train
148-
need to be shifted by num_units_sorting1.
149-
num_units_sorting1 : int
150-
The total count of unique units in the first spike train.
151-
num_units_sorting2 : int
152-
The total count of unique units in the second spike train.
153-
delta_frames : int
154-
The inclusive upper limit on the frame difference for which two spikes are considered in proximity.
155-
156-
Returns
157-
-------
158-
dot_product_matrix : ndarray
159-
A 2D numpy array of shape (num_units_sorting1 + num_units_sorting2, num_units_sorting1 + num_units_sorting2).
160-
Each element [i, j] represents the accumulated proximity score between unit i and unit j.
161-
"""
162-
163-
dot_product_matrix = np.zeros(
164-
(num_units_sorting1 + num_units_sorting2, num_units_sorting1 + num_units_sorting2),
165-
dtype=np.uint32,
166-
)
167-
168-
minimal_search = 0
169-
num_samples = len(sample_frames)
170-
for index1 in range(num_samples):
171-
frame1 = sample_frames[index1]
172-
173-
for index2 in range(minimal_search, num_samples):
174-
frame2 = sample_frames[index2]
175-
176-
frame2 - frame1
177-
if frame2 < frame1 - delta_frames:
178-
minimal_search += 1
179-
continue
180-
elif frame2 > frame1 + delta_frames:
181-
break
182-
else:
183-
unit_index1 = unit_indices[index1]
184-
unit_index2 = unit_indices[index2]
185-
dot_product_matrix[unit_index1, unit_index2] += delta_frames - abs(frame1 - frame2)
186-
187-
return dot_product_matrix
188-
189-
# Cache the compiled function
190-
get_optimized_compute_dot_product_all._cached_function = compute_dot_product
191-
192-
return compute_dot_product
193-
194-
195111
def get_optimized_dot_product_function():
196112
"""
197113
This function is to avoid the bare try-except pattern when importing the compute_dot_product function

0 commit comments

Comments
 (0)