@@ -459,3 +459,29 @@ def generalized_tanimoto_similarity_matrix_weighted(references: np.ndarray, quer
459459 for j in range (size2 ):
460460 scores [i , j ] = generalized_tanimoto_similarity_weighted (references [i , :], queries [j , :], weights )
461461 return scores
462+
463+
464+ def compute_cosine_greedy (cosine_obj , spectra ):
465+ # This is only a replacement of the matchme method until that will allow disabling tqdm
466+ n_rows = n_cols = len (spectra )
467+
468+ idx_row = []
469+ idx_col = []
470+ scores = []
471+ # Wrap the outer loop with tqdm to track progress
472+ for i_ref , reference in enumerate (spectra [:n_rows ]):
473+ for i_query , query in enumerate (spectra [i_ref :n_cols ], start = i_ref ):
474+ score = cosine_obj .pair (reference , query )
475+ if cosine_obj .keep_score (score ):
476+ idx_row += [i_ref , i_query ]
477+ idx_col += [i_query , i_ref ]
478+ scores += [score , score ]
479+
480+ idx_row = np .array (idx_row , dtype = np .int_ )
481+ idx_col = np .array (idx_col , dtype = np .int_ )
482+ scores_data = np .array (scores , dtype = cosine_obj .score_datatype )
483+ # TODO: make StackedSparseArray the default and add fixed function to output different formats (with code below)
484+
485+ scores_array = np .zeros (shape = (n_rows , n_cols ), dtype = self .score_datatype )
486+ scores_array [idx_row , idx_col ] = scores_data .reshape (- 1 )
487+ return scores_array
0 commit comments