diff --git a/languages/c/SpectralEntropy.c b/languages/c/SpectralEntropy.c index f4f2453..a6005f6 100644 --- a/languages/c/SpectralEntropy.c +++ b/languages/c/SpectralEntropy.c @@ -57,7 +57,13 @@ float calculate_unweighted_entropy_similarity( b++; } } - return similarity / 2; + similarity = similarity / 2; + if (similarity < 0) { + similarity = 0; + }elif(similarity > 1) { + similarity = 1; + } + return similarity; } // Calculate entropy similarity diff --git a/ms_entropy/spectra/entropy_cython.pyx b/ms_entropy/spectra/entropy_cython.pyx index 8dc9cbd..08bb2d3 100644 --- a/ms_entropy/spectra/entropy_cython.pyx +++ b/ms_entropy/spectra/entropy_cython.pyx @@ -178,6 +178,8 @@ cpdef float cy_calculate_entropy_similarity( float The entropy similarity between the two spectra. """ + if len(peaks_a) == 0 or len(peaks_b) == 0: + return 0.0 cdef np.ndarray[float32, ndim=2] peaks_a_np = np.array(peaks_a, dtype=np.float32, copy=True, order="C") cdef np.ndarray[float32, ndim=2] peaks_b_np = np.array(peaks_b, dtype=np.float32, copy=True, order="C") @@ -248,6 +250,8 @@ cpdef float cy_calculate_unweighted_entropy_similarity( float The unweighted entropy similarity between the two spectra. """ + if len(peaks_a) == 0 or len(peaks_b) == 0: + return 0.0 cdef np.ndarray[float32, ndim=2] peaks_a_np cdef np.ndarray[float32, ndim=2] peaks_b_np if clean_spectra: diff --git a/ms_entropy/version.py b/ms_entropy/version.py index e398332..07f744c 100644 --- a/ms_entropy/version.py +++ b/ms_entropy/version.py @@ -1 +1 @@ -__version__ = '1.3.2' +__version__ = '1.3.3'