From fb8310469f43f4dd572a444c8720b505c5ab88b0 Mon Sep 17 00:00:00 2001 From: Quoc-Tuan Truong Date: Tue, 5 Dec 2023 21:50:30 -0800 Subject: [PATCH] Fix exception check for Cython migration to 3.0 (#558) --- cornac/models/bpr/recom_bpr.pxd | 6 +++--- cornac/models/bpr/recom_bpr.pyx | 4 ++-- cornac/models/comparer/recom_comparer_obj.pyx | 2 +- cornac/models/efm/recom_efm.pyx | 2 +- cornac/models/lrppm/recom_lrppm.pyx | 4 ++-- cornac/models/mter/recom_mter.pxd | 4 ++-- cornac/models/mter/recom_mter.pyx | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cornac/models/bpr/recom_bpr.pxd b/cornac/models/bpr/recom_bpr.pxd index dace49d51..3002f1de7 100644 --- a/cornac/models/bpr/recom_bpr.pxd +++ b/cornac/models/bpr/recom_bpr.pxd @@ -20,7 +20,7 @@ from libcpp cimport bool from libcpp.vector cimport vector -cdef bool has_non_zero(integral[:], integral[:], integral, integral) nogil +cdef bool has_non_zero(integral[:], integral[:], integral, integral) noexcept nogil cdef extern from "" namespace "boost::random": @@ -29,7 +29,7 @@ cdef extern from "" namespace "boost::random": cdef cppclass uniform_int_distribution[T]: uniform_int_distribution(T, T) - T operator()(mt19937) nogil + T operator()(mt19937) noexcept nogil cdef class RNGVector(object): @@ -38,4 +38,4 @@ cdef class RNGVector(object): cdef vector[mt19937] rng cdef vector[uniform_int_distribution[long]] dist - cdef inline long generate(self, int thread_id) nogil + cdef inline long generate(self, int thread_id) noexcept nogil diff --git a/cornac/models/bpr/recom_bpr.pyx b/cornac/models/bpr/recom_bpr.pyx index 759e99636..2b72f228a 100644 --- a/cornac/models/bpr/recom_bpr.pyx +++ b/cornac/models/bpr/recom_bpr.pyx @@ -43,7 +43,7 @@ cdef extern from "recom_bpr.h" namespace "recom_bpr" nogil: @cython.boundscheck(False) cdef bool has_non_zero(integral[:] indptr, integral[:] indices, - integral rowid, integral colid) nogil: + integral rowid, integral colid) noexcept nogil: """Given a CSR matrix, returns whether the [rowid, colid] contains a non zero. Assumes the CSR matrix has sorted indices""" return binary_search(&indices[indptr[rowid]], &indices[indptr[rowid + 1]], colid) @@ -56,7 +56,7 @@ cdef class RNGVector(object): self.rng.push_back(mt19937(rng.randint(2 ** 31))) self.dist.push_back(uniform_int_distribution[long](0, rows)) - cdef inline long generate(self, int thread_id) nogil: + cdef inline long generate(self, int thread_id) noexcept nogil: return self.dist[thread_id](self.rng[thread_id]) diff --git a/cornac/models/comparer/recom_comparer_obj.pyx b/cornac/models/comparer/recom_comparer_obj.pyx index 63acc475c..1c522b6f9 100644 --- a/cornac/models/comparer/recom_comparer_obj.pyx +++ b/cornac/models/comparer/recom_comparer_obj.pyx @@ -35,7 +35,7 @@ MODEL_TYPES = {"Dominant": 0, "Finer": 1, "Around": 2} cdef floating _dot(int n, floating *x, int incx, - floating *y, int incy) nogil: + floating *y, int incy) noexcept nogil: if floating is float: return sdot(&n, x, &incx, y, &incy) else: diff --git a/cornac/models/efm/recom_efm.pyx b/cornac/models/efm/recom_efm.pyx index c4f8858da..5d6dd582c 100644 --- a/cornac/models/efm/recom_efm.pyx +++ b/cornac/models/efm/recom_efm.pyx @@ -36,7 +36,7 @@ from ...utils.init_utils import uniform cdef floating _dot(int n, floating *x, int incx, - floating *y, int incy) nogil: + floating *y, int incy) noexcept nogil: if floating is float: return sdot(&n, x, &incx, y, &incy) else: diff --git a/cornac/models/lrppm/recom_lrppm.pyx b/cornac/models/lrppm/recom_lrppm.pyx index 493f11a86..2c8ec5475 100644 --- a/cornac/models/lrppm/recom_lrppm.pyx +++ b/cornac/models/lrppm/recom_lrppm.pyx @@ -39,13 +39,13 @@ from ..mter.recom_mter cimport get_key cdef extern from "../bpr/recom_bpr.h" namespace "recom_bpr" nogil: cdef int get_thread_num() -cdef int get_key3(int i_id, int j_id, int k_id) nogil: +cdef int get_key3(int i_id, int j_id, int k_id) noexcept nogil: return get_key(get_key(i_id, j_id), k_id) @cython.boundscheck(False) @cython.wraparound(False) cdef floating get_score(floating[:, :] U, floating[:, :] I, floating[:, :] UA, floating[:, :] IA, - int n_factors, int u_idx, int i_idx, int a_idx) nogil: + int n_factors, int u_idx, int i_idx, int a_idx) noexcept nogil: cdef floating score = 0. cdef int k for k in range(n_factors): diff --git a/cornac/models/mter/recom_mter.pxd b/cornac/models/mter/recom_mter.pxd index cb0229c90..71c8355c3 100644 --- a/cornac/models/mter/recom_mter.pxd +++ b/cornac/models/mter/recom_mter.pxd @@ -19,8 +19,8 @@ from cython cimport floating, integral from libcpp.vector cimport vector -cdef int get_key(int i_id, int j_id) nogil +cdef int get_key(int i_id, int j_id) noexcept nogil cdef floating get_score(floating[:, :, :] G, int dim1, int dim2, int dim3, floating[:, :] U, floating[:, :] I, floating[:, :] A, - int u_idx, int i_idx, int a_idx) nogil + int u_idx, int i_idx, int a_idx) noexcept nogil diff --git a/cornac/models/mter/recom_mter.pyx b/cornac/models/mter/recom_mter.pyx index 254b2dfe5..0a1f4e2f4 100644 --- a/cornac/models/mter/recom_mter.pyx +++ b/cornac/models/mter/recom_mter.pyx @@ -39,7 +39,7 @@ cdef extern from "../bpr/recom_bpr.h" namespace "recom_bpr" nogil: cdef int get_thread_num() -cdef int get_key(int i_id, int j_id) nogil: +cdef int get_key(int i_id, int j_id) noexcept nogil: return (i_id + j_id) * (i_id + j_id + 1) // 2 + j_id @@ -47,7 +47,7 @@ cdef int get_key(int i_id, int j_id) nogil: @cython.wraparound(False) cdef floating get_score(floating[:, :, :] G, int dim1, int dim2, int dim3, floating[:, :] U, floating[:, :] I, floating[:, :] A, - int u_idx, int i_idx, int a_idx) nogil: + int u_idx, int i_idx, int a_idx) noexcept nogil: cdef floating score = 0. for i in range(dim1): for j in range(dim2):