From dedb698422b5869a3536cc3779a3304ce60776de Mon Sep 17 00:00:00 2001 From: Navaneet Villodi <11260095+nauaneed@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:47:44 +0530 Subject: [PATCH] fix(performance warnings): by adding noexcept --- cyarray/carray.pxd | 10 +++++----- cyarray/carray.pxd.mako | 10 +++++----- cyarray/carray.pyx | 20 ++++++++++---------- cyarray/carray.pyx.mako | 12 ++++++------ 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cyarray/carray.pxd b/cyarray/carray.pxd index 9706616..5d22577 100644 --- a/cyarray/carray.pxd +++ b/cyarray/carray.pxd @@ -12,10 +12,10 @@ Declaration File. # numpy import cimport numpy as np -cdef long aligned(long n, int item_size) nogil -cdef void* aligned_malloc(size_t bytes) nogil -cdef void* aligned_realloc(void* existing, size_t bytes, size_t old_size) nogil -cdef void aligned_free(void* p) nogil +cdef long aligned(long n, int item_size) noexcept nogil +cdef void* aligned_malloc(size_t bytes) noexcept nogil +cdef void* aligned_realloc(void* existing, size_t bytes, size_t old_size) noexcept nogil +cdef void aligned_free(void* p) noexcept nogil # forward declaration cdef class BaseArray @@ -31,7 +31,7 @@ cdef class BaseArray: cdef np.ndarray _npy_array cdef void c_align_array(self, LongArray new_indices, int stride=*) nogil - cdef void c_reserve(self, long size) nogil + cdef void c_reserve(self, long size) noexcept nogil cdef void c_reset(self) cdef void c_resize(self, long size) nogil cdef void c_squeeze(self) nogil diff --git a/cyarray/carray.pxd.mako b/cyarray/carray.pxd.mako index a9ca9d0..da52cb1 100644 --- a/cyarray/carray.pxd.mako +++ b/cyarray/carray.pxd.mako @@ -20,10 +20,10 @@ Declaration File. # numpy import cimport numpy as np -cdef long aligned(long n, int item_size) nogil -cdef void* aligned_malloc(size_t bytes) nogil -cdef void* aligned_realloc(void* existing, size_t bytes, size_t old_size) nogil -cdef void aligned_free(void* p) nogil +cdef long aligned(long n, int item_size) noexcept nogil +cdef void* aligned_malloc(size_t bytes) noexcept nogil +cdef void* aligned_realloc(void* existing, size_t bytes, size_t old_size) noexcept nogil +cdef void aligned_free(void* p) noexcept nogil # forward declaration cdef class BaseArray @@ -39,7 +39,7 @@ cdef class BaseArray: cdef np.ndarray _npy_array cdef void c_align_array(self, LongArray new_indices, int stride=*) nogil - cdef void c_reserve(self, long size) nogil + cdef void c_reserve(self, long size) noexcept nogil cdef void c_reset(self) cdef void c_resize(self, long size) nogil cdef void c_squeeze(self) nogil diff --git a/cyarray/carray.pyx b/cyarray/carray.pyx index 97e7d0f..4f90721 100644 --- a/cyarray/carray.pyx +++ b/cyarray/carray.pyx @@ -65,7 +65,7 @@ cdef extern from "stdlib.h": # numpy module initialization call _import_array() -cdef inline long aligned(long n, int item_size) nogil: +cdef inline long aligned(long n, int item_size) noexcept nogil: """Align `n` items each having size (in bytes) `item_size` to 64 bytes and return the appropriate number of items that would be aligned to 64 bytes. @@ -124,13 +124,13 @@ cdef void* _deref_base(void* ptr) nogil: raise MemoryError("Passed pointer is not aligned.") return base -cdef void* aligned_malloc(size_t bytes) nogil: +cdef void* aligned_malloc(size_t bytes) noexcept nogil: return _aligned_malloc(bytes) -cdef void* aligned_realloc(void* p, size_t bytes, size_t old_size) nogil: +cdef void* aligned_realloc(void* p, size_t bytes, size_t old_size) noexcept nogil: return _aligned_realloc(p, bytes, old_size) -cdef void aligned_free(void* p) nogil: +cdef void aligned_free(void* p) noexcept nogil: """Free block allocated by alligned_malloc. """ free(_deref_base(p)) @@ -146,7 +146,7 @@ cdef class BaseArray: """ pass - cdef void c_reserve(self, long size) nogil: + cdef void c_reserve(self, long size) noexcept nogil: pass cdef void c_reset(self): @@ -425,7 +425,7 @@ cdef class IntArray(BaseArray): # update the numpy arrays length arr.dimensions[0] = self.length - cdef void c_reserve(self, long size) nogil: + cdef void c_reserve(self, long size) noexcept nogil: cdef PyArrayObject* arr = self._npy_array cdef void* data = NULL if size > self.alloc: @@ -934,7 +934,7 @@ cdef class UIntArray(BaseArray): # update the numpy arrays length arr.dimensions[0] = self.length - cdef void c_reserve(self, long size) nogil: + cdef void c_reserve(self, long size) noexcept nogil: cdef PyArrayObject* arr = self._npy_array cdef void* data = NULL if size > self.alloc: @@ -1443,7 +1443,7 @@ cdef class LongArray(BaseArray): # update the numpy arrays length arr.dimensions[0] = self.length - cdef void c_reserve(self, long size) nogil: + cdef void c_reserve(self, long size) noexcept nogil: cdef PyArrayObject* arr = self._npy_array cdef void* data = NULL if size > self.alloc: @@ -1952,7 +1952,7 @@ cdef class FloatArray(BaseArray): # update the numpy arrays length arr.dimensions[0] = self.length - cdef void c_reserve(self, long size) nogil: + cdef void c_reserve(self, long size) noexcept nogil: cdef PyArrayObject* arr = self._npy_array cdef void* data = NULL if size > self.alloc: @@ -2461,7 +2461,7 @@ cdef class DoubleArray(BaseArray): # update the numpy arrays length arr.dimensions[0] = self.length - cdef void c_reserve(self, long size) nogil: + cdef void c_reserve(self, long size) noexcept nogil: cdef PyArrayObject* arr = self._npy_array cdef void* data = NULL if size > self.alloc: diff --git a/cyarray/carray.pyx.mako b/cyarray/carray.pyx.mako index b31f68f..d254a75 100644 --- a/cyarray/carray.pyx.mako +++ b/cyarray/carray.pyx.mako @@ -74,7 +74,7 @@ cdef extern from "stdlib.h": # numpy module initialization call _import_array() -cdef inline long aligned(long n, int item_size) nogil: +cdef inline long aligned(long n, int item_size) noexcept nogil: """Align `n` items each having size (in bytes) `item_size` to 64 bytes and return the appropriate number of items that would be aligned to 64 bytes. @@ -133,13 +133,13 @@ cdef void* _deref_base(void* ptr) nogil: raise MemoryError("Passed pointer is not aligned.") return base -cdef void* aligned_malloc(size_t bytes) nogil: +cdef void* aligned_malloc(size_t bytes) noexcept nogil: return _aligned_malloc(bytes) -cdef void* aligned_realloc(void* p, size_t bytes, size_t old_size) nogil: +cdef void* aligned_realloc(void* p, size_t bytes, size_t old_size) noexcept nogil: return _aligned_realloc(p, bytes, old_size) -cdef void aligned_free(void* p) nogil: +cdef void aligned_free(void* p) noexcept nogil: """Free block allocated by alligned_malloc. """ free(_deref_base(p)) @@ -156,7 +156,7 @@ cdef class BaseArray: """ pass - cdef void c_reserve(self, long size) nogil: + cdef void c_reserve(self, long size) noexcept nogil: pass cdef void c_reset(self): @@ -438,7 +438,7 @@ cdef class ${CLASSNAME}(BaseArray): # update the numpy arrays length arr.dimensions[0] = self.length - cdef void c_reserve(self, long size) nogil: + cdef void c_reserve(self, long size) noexcept nogil: cdef PyArrayObject* arr = self._npy_array cdef void* data = NULL if size > self.alloc: