@@ -133,10 +133,8 @@ def _merge_extension_data(
133133 new_data = dict (ccgs = new_ccgs , bins = new_bins )
134134 else :
135135
136- # First, we make a transformation matrix, which tells us how unit_indices from the
137- # old to the new sorter are mapped. The i-th original unit_index gets mapped to the
138- # j-th new unit_index; where j is the only non-zero element of the matrix. To help
139- # construct the matrix we first make a dictionary of the form {old_index: new_index}
136+ # Make a transformation dict, which tells us how unit_indices from the
137+ # old to the new sorter are mapped.
140138 old_to_new_unit_index_map = {}
141139 for old_unit in self .sorting_analyzer .unit_ids :
142140 old_unit_index = self .sorting_analyzer .sorting .id_to_index (old_unit )
@@ -156,12 +154,6 @@ def _merge_extension_data(
156154 if unit_involved_in_merge is False :
157155 old_to_new_unit_index_map [old_unit_index ] = new_sorting_analyzer .sorting .id_to_index (old_unit )
158156
159- transformation_matrix = np .zeros (
160- (len (new_sorting_analyzer .unit_ids ), len (self .sorting_analyzer .unit_ids )), dtype = "int"
161- )
162- for col , row in old_to_new_unit_index_map .items ():
163- transformation_matrix [row ][col ] = 1
164-
165157 need_to_append = False
166158 delete_from = 1
167159
@@ -185,9 +177,13 @@ def _merge_extension_data(
185177 for merge_unit_group_index in merge_unit_group_indices :
186178 correlograms [:, merge_unit_group_index , :] = new_row
187179
188- # The new correlograms are in the old unit_id order. Hence we must transform
189- # to the new unit_id order using a change of basis operation: C -> TCT^T
190- new_correlograms = np .einsum ("ij,jkz,lk->ilz" , transformation_matrix , correlograms , transformation_matrix )
180+ new_correlograms = np .zeros (
181+ (len (new_sorting_analyzer .unit_ids ), len (new_sorting_analyzer .unit_ids ), correlograms .shape [2 ])
182+ )
183+ for old_index_1 , new_index_1 in old_to_new_unit_index_map .items ():
184+ for old_index_2 , new_index_2 in old_to_new_unit_index_map .items ():
185+ new_correlograms [new_index_1 , new_index_2 , :] = correlograms [old_index_1 , old_index_2 , :]
186+ new_correlograms [new_index_2 , new_index_1 , :] = correlograms [old_index_2 , old_index_1 , :]
191187
192188 new_data = dict (ccgs = new_correlograms , bins = new_bins )
193189 return new_data
0 commit comments