Skip to content

Commit

Permalink
Add explicit noexcept in nogil function declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
n-elie committed Nov 27, 2023
1 parent bb1aad4 commit 569dceb
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion libmetgem/_cosine.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ cpdef enum SpectraMatchState:

cdef double cosine_score_nogil(double, peak_t*, np.npy_intp,
double, peak_t*, np.npy_intp,
double, int) nogil
double, int) noexcept nogil
8 changes: 4 additions & 4 deletions libmetgem/_cosine.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ from ._common cimport (score_t, np_arr_pointer,
arr_from_score_vector,
arr_from_1d_vector)

cdef double addScore(double sum, const score_t &b) nogil:
cdef double addScore(double sum, const score_t &b) noexcept nogil:
return sum + b.value

cdef bool compareByScore(const score_t &a, const score_t &b) nogil:
cdef bool compareByScore(const score_t &a, const score_t &b) noexcept nogil:
return a.value > b.value


Expand All @@ -37,7 +37,7 @@ cdef vector[score_t] compare_spectra_nogil(double spectrum1_mz,
double spectrum2_mz,
peak_t *spectrum2_data,
np.npy_intp spectrum2_size,
double mz_tolerance) nogil:
double mz_tolerance) noexcept nogil:
cdef:
double dm
vector[score_t] scores
Expand Down Expand Up @@ -117,7 +117,7 @@ cdef double cosine_score_nogil(double spectrum1_mz,
peak_t *spectrum2_data,
np.npy_intp spectrum2_size,
double mz_tolerance,
int min_matched_peaks) nogil:
int min_matched_peaks) noexcept nogil:
cdef:
vector[score_t] matches = compare_spectra_nogil(spectrum1_mz,
spectrum1_data,
Expand Down
2 changes: 1 addition & 1 deletion libmetgem/_database.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ cdef query_result_t query_nogil(char *fname, vector[int] indices,
double analog_mz_tolerance=0.,
bool positive_polarity=True,
double mz_min = 50.,
object callback=None) nogil:
object callback=None) noexcept nogil:
cdef:
sqlite3 *db
sqlite3_stmt *stmt
Expand Down
2 changes: 1 addition & 1 deletion libmetgem/_filter.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ from libcpp.vector cimport vector
cimport numpy as np
from ._common cimport peak_t

cdef vector[peak_t] filter_data_nogil(double, const peak_t *, np.npy_intp, int, int, int, int, double) nogil
cdef vector[peak_t] filter_data_nogil(double, const peak_t *, np.npy_intp, int, int, int, int, double) noexcept nogil
10 changes: 5 additions & 5 deletions libmetgem/_filter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cdef bool compareByMz(const peak_t &a, const peak_t &b) nogil:
cdef vector[peak_t] parent_filter_nogil(double mz_parent, vector[peak_t] data,
int min_intensity,
int parent_filter_tolerance,
double mz_min = 50.) nogil:
double mz_min = 50.) noexcept nogil:
cdef:
int i
float mz, intensity
Expand Down Expand Up @@ -64,7 +64,7 @@ cdef vector[peak_t] parent_filter_nogil(double mz_parent, vector[peak_t] data,
@cython.cdivision(True)
cdef vector[peak_t] window_rank_filter_nogil(vector[peak_t] data,
int matched_peaks_window,
int min_matched_peaks_search) nogil:
int min_matched_peaks_search) noexcept nogil:
cdef:
int i, j, count=0
float mz
Expand Down Expand Up @@ -93,7 +93,7 @@ cdef vector[peak_t] window_rank_filter_nogil(vector[peak_t] data,
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
cdef vector[peak_t] square_root_and_normalize_data_nogil(vector[peak_t] data) nogil:
cdef vector[peak_t] square_root_and_normalize_data_nogil(vector[peak_t] data) noexcept nogil:
cdef:
int i
double dot_product = 0.
Expand Down Expand Up @@ -123,7 +123,7 @@ cdef vector[peak_t] filter_data_nogil(double mz_parent, const peak_t *data,
int parent_filter_tolerance,
int matched_peaks_window,
int min_matched_peaks_search,
double mz_min) nogil:
double mz_min) noexcept nogil:
cdef vector[peak_t] peaks

if data_size == 0:
Expand Down Expand Up @@ -156,7 +156,7 @@ cdef vector[vector[peak_t]] filter_data_multi_nogil(vector[double] mzvec,
int matched_peaks_window,
int min_matched_peaks_search,
double mz_min,
object callback=None) nogil:
object callback=None) noexcept nogil:
cdef:
vector[vector[peak_t]] spectra
int i
Expand Down
4 changes: 2 additions & 2 deletions libmetgem/_mgf.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ cdef extern from *:
extern const char* CHARSET


cdef inline double strtof(char* string, char **endptr) nogil:
cdef inline double strtof(char* string, char **endptr) noexcept nogil:
cdef char *ptr = NULL

# Allow comma as decimal separator
Expand All @@ -56,7 +56,7 @@ cdef inline double strtof(char* string, char **endptr) nogil:
return std_strtof(string, endptr)


cdef void read_data(char line[MAX_LINE_SIZE], vector[peak_t] *peaklist, FILE *fp) nogil:
cdef void read_data(char line[MAX_LINE_SIZE], vector[peak_t] *peaklist, FILE *fp) noexcept nogil:
"""Read peak list from file.
First line has already been read and has to be passed as first argument.
peak list is read into `peaklist`, which is cleared as first step."""
Expand Down
6 changes: 3 additions & 3 deletions libmetgem/_msp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ cdef extern from *:
extern const char* CHARSET


cdef inline bool isdelim(char s) nogil:
cdef inline bool isdelim(char s) noexcept nogil:
return strchr(b'()[]{},;:', s) != NULL


cdef inline void trim(char* string) nogil:
cdef inline void trim(char* string) noexcept nogil:
cdef:
int i = 0
int index = 0
Expand Down Expand Up @@ -91,7 +91,7 @@ cdef inline void trim(char* string) nogil:


cdef void read_data(char line[MAX_LINE_SIZE], vector[peak_t] *peaklist,
FILE *fp, int num_peaks) nogil:
FILE *fp, int num_peaks) noexcept nogil:
"""Read peak list from file.
First line has already been read and has to be passed as first argument.
peak list is read into `peaklist`, which is cleared as first step."""
Expand Down
8 changes: 4 additions & 4 deletions libmetgem/_network.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ ctypedef struct element_t:
int index
double cosine

cdef bool compareElementsByCosine(const element_t &a, const element_t &b) nogil:
cdef bool compareElementsByCosine(const element_t &a, const element_t &b) noexcept nogil:
return a.cosine > b.cosine

cdef bool compareInteractionsByCosine(const interaction_t &a, const interaction_t &b) nogil:
cdef bool compareInteractionsByCosine(const interaction_t &a, const interaction_t &b) noexcept nogil:
if a.cosine > b.cosine:
return True
elif a.cosine < b.cosine:
Expand All @@ -41,14 +41,14 @@ cdef bool compareInteractionsByCosine(const interaction_t &a, const interaction_
return False
else:
return False

@cython.boundscheck(False)
@cython.wraparound(False)
cdef vector[interaction_t] generate_network_nogil(const float[:,:] scores_matrix,
vector[double] mzvec,
double pairs_min_cosine,
size_t top_k,
object callback=None) nogil:
object callback=None) noexcept nogil:
cdef:
vector[interaction_t] interactions, interactions2
interaction_t inter
Expand Down

0 comments on commit 569dceb

Please sign in to comment.