@@ -89,6 +89,33 @@ def cosine_kernel(
8989 --------
9090 callable
9191 CUDA kernel function for calculating cosine similarity scores.
92+
93+ For example:
94+
95+ >>> from simms.similarity.spectrum_similarity_functions import cosine_kernel
96+ >>> from numba import cuda
97+ >>> import numpy as np
98+ >>> batch_size, n_max_peaks = 2, 4
99+ >>> kernel = cosine_kernel(tolerance=0.1, n_max_peaks=n_max_peaks, batch_size=batch_size)
100+ >>> rspec = cuda.to_device(np.array([
101+ ... [ [1., 10., 100., 200.,], # mz values
102+ ... [2., 20., 200., 400.,], ],
103+ ... [ [1., 1., 1., 1.,], # Intensities
104+ ... [1., 1., 1., 1.,], ]
105+ ... ], dtype=np.float32))
106+ >>> qspec = rspec # symmetric
107+ >>> metadata = cuda.to_device(np.array([
108+ ... [ 4., 4., ], # lengths of reference spectra
109+ ... [ 4., 4., ], # lengths of query spectra
110+ ... [ 2., 2., ], # norms of reference spectra
111+ ... [ 2., 2., ], # norms of query spectra
112+ ... ], dtype=np.float32))
113+ >>> out = cuda.to_device(np.zeros((3, batch_size, batch_size), dtype=np.float32))
114+ >>> kernel(rspec, qspec, metadata, out)
115+ >>> scores, matches, overflows = out.copy_to_host()
116+ >>> print(scores)
117+ [[1. 0.25]
118+ [0.25 1. ]]
92119 """
93120
94121 if is_symmetric :
0 commit comments