Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Cython functions as noexcept #418

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sksurv/kernels/_clinical_kernel.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cnp.import_array()
@cython.wraparound(False)
@cython.cdivision(True)
@cython.boundscheck(False)
cdef void _get_min_and_max(cnp.npy_double[:] x, cnp.npy_double * min_out, cnp.npy_double * max_out) nogil:
cdef void _get_min_and_max(cnp.npy_double[:] x, cnp.npy_double * min_out, cnp.npy_double * max_out) noexcept nogil:
cdef cnp.npy_double amin = x[0]
cdef cnp.npy_double amax = x[0]
cdef int i
Expand Down
8 changes: 4 additions & 4 deletions sksurv/svm/_minlip.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def create_difference_matrix(cnp.npy_uint8[:] event,
cdef inline void set_entries(cnp.npy_intp[:] columns,
cnp.npy_int8[:] values,
cnp.npy_intp k,
cnp.npy_intp i, cnp.npy_intp j) nogil:
cnp.npy_intp i, cnp.npy_intp j) noexcept nogil:
"""Create sparse matrix with sorted indices"""
if i < j:
columns[k] = i
Expand All @@ -104,7 +104,7 @@ cdef inline void set_entries(cnp.npy_intp[:] columns,
cdef cnp.npy_intp create_difference_matrix_direct_neighbor(cnp.npy_uint8[:] event,
cnp.npy_intp[:] o,
cnp.npy_int8[:] values,
cnp.npy_intp[:] columns) nogil:
cnp.npy_intp[:] columns) noexcept nogil:
"""Only compare against direct nearest neighbor according to time"""
cdef cnp.npy_intp n_samples = event.shape[0]
cdef cnp.npy_intp i
Expand All @@ -129,7 +129,7 @@ cdef cnp.npy_intp create_difference_matrix_direct_neighbor(cnp.npy_uint8[:] even
cdef cnp.npy_intp create_difference_matrix_nearest_neighbor(cnp.npy_uint8[:] event,
cnp.npy_intp[:] o,
cnp.npy_int8[:] values,
cnp.npy_intp[:] columns) nogil:
cnp.npy_intp[:] columns) noexcept nogil:
"""Only considers comparable pairs (i, j) where j is uncensored sample
with highest survival time smaller than y_i"""
cdef cnp.npy_intp n_samples = event.shape[0]
Expand All @@ -154,7 +154,7 @@ cdef cnp.npy_intp create_difference_matrix_nearest_neighbor(cnp.npy_uint8[:] eve
cdef cnp.npy_intp create_difference_matrix_full(cnp.npy_uint8[:] event,
cnp.npy_intp[:] o,
cnp.npy_int8[:] values,
cnp.npy_intp[:] columns) nogil:
cnp.npy_intp[:] columns) noexcept nogil:
"""Considers all possible comparable pairs"""
cdef cnp.npy_intp n_samples = event.shape[0]
cdef cnp.npy_intp i, j
Expand Down
8 changes: 4 additions & 4 deletions sksurv/tree/_criterion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ cdef class RisksetCounter:
free(self.n_events)
free(self.n_at_risk)

cdef void reset(self) nogil:
cdef void reset(self) noexcept nogil:
memset(self.n_events, 0, self.nbytes)
memset(self.n_at_risk, 0, self.nbytes)

cdef void set_data(self, const DOUBLE_t[:, ::1] data) nogil:
cdef void set_data(self, const DOUBLE_t[:, ::1] data) noexcept nogil:
self.data = data

cdef void update(self, const SIZE_t[:] samples, SIZE_t start, SIZE_t end) nogil:
cdef void update(self, const SIZE_t[:] samples, SIZE_t start, SIZE_t end) noexcept nogil:
cdef:
SIZE_t i
SIZE_t idx
Expand Down Expand Up @@ -94,7 +94,7 @@ cdef class RisksetCounter:
if event != 0.0:
self.n_events[ti] += 1

cdef inline void at(self, SIZE_t index, DOUBLE_t * at_risk, DOUBLE_t * events) nogil:
cdef inline void at(self, SIZE_t index, DOUBLE_t * at_risk, DOUBLE_t * events) noexcept nogil:
if at_risk != NULL:
at_risk[0] = <DOUBLE_t> self.n_at_risk[index]
if events != NULL:
Expand Down