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

Bump cython #17

Closed
wants to merge 8 commits into from
Closed
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
13 changes: 11 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ jobs:
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements.txt
pip install .
python setup.py develop
- name: Run tests
run: pytest -v --pyargs cyarray
run: pytest -v --pyargs cyarray --benchmark-save benchmark-stats --benchmark-json benchmark-full.json --benchmark-histogram

- name: 'Upload Perf Data'
uses: actions/upload-artifact@v4
with:
name: perf-bench-result-${{ matrix.python-version }}-${{ matrix.os }}
path: |
benchmark_*.svg
.benchmarks/*
benchmark-full.json
12 changes: 6 additions & 6 deletions cyarray/carray.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,8 +31,8 @@ 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_reset(self) 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

Expand Down
12 changes: 6 additions & 6 deletions cyarray/carray.pxd.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,8 +39,8 @@ 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_reset(self) 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

Expand Down
69 changes: 43 additions & 26 deletions cyarray/carray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ The numpy array may however be copied and used in any manner.

# For malloc etc.
from libc.stdlib cimport *
IF UNAME_SYSNAME == "Windows":
cdef extern from "msstdint.h" nogil:
ctypedef unsigned int uintptr_t
ELSE:
from libc.stdint cimport uintptr_t

from libc.stdint cimport uintptr_t

cimport numpy as np

Expand Down Expand Up @@ -68,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.
Expand Down Expand Up @@ -127,13 +124,13 @@ cdef void* _deref_base(void* ptr) nogil:
raise MemoryError("Passed pointer is not aligned.")
return <void*>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(<void*>_deref_base(p))
Expand All @@ -149,10 +146,10 @@ 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) nogil:
cdef void c_reset(self):
cdef PyArrayObject* arr = <PyArrayObject*>self._npy_array
self.length = 0
arr.dimensions[0] = self.length
Expand Down Expand Up @@ -428,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 = <PyArrayObject*>self._npy_array
cdef void* data = NULL
if size > self.alloc:
Expand All @@ -446,12 +443,16 @@ cdef class IntArray(BaseArray):
self.alloc = size
arr.data = <char *>self.data

cdef void c_reset(self) nogil:
cdef void c_reset(self):
cdef np.npy_intp dims = self.length
BaseArray.c_reset(self)
if self._old_data != NULL:
self.data = self._old_data
self._old_data = NULL
self._npy_array.data = <char *>self.data

self._npy_array = PyArray_SimpleNewFromData(
1, &dims, NPY_INT, self.data
)

cdef void c_resize(self, long size) nogil:
cdef PyArrayObject* arr = <PyArrayObject*>self._npy_array
Expand Down Expand Up @@ -933,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 = <PyArrayObject*>self._npy_array
cdef void* data = NULL
if size > self.alloc:
Expand All @@ -951,12 +952,16 @@ cdef class UIntArray(BaseArray):
self.alloc = size
arr.data = <char *>self.data

cdef void c_reset(self) nogil:
cdef void c_reset(self):
cdef np.npy_intp dims = self.length
BaseArray.c_reset(self)
if self._old_data != NULL:
self.data = self._old_data
self._old_data = NULL
self._npy_array.data = <char *>self.data

self._npy_array = PyArray_SimpleNewFromData(
1, &dims, NPY_UINT, self.data
)

cdef void c_resize(self, long size) nogil:
cdef PyArrayObject* arr = <PyArrayObject*>self._npy_array
Expand Down Expand Up @@ -1438,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 = <PyArrayObject*>self._npy_array
cdef void* data = NULL
if size > self.alloc:
Expand All @@ -1456,12 +1461,16 @@ cdef class LongArray(BaseArray):
self.alloc = size
arr.data = <char *>self.data

cdef void c_reset(self) nogil:
cdef void c_reset(self):
cdef np.npy_intp dims = self.length
BaseArray.c_reset(self)
if self._old_data != NULL:
self.data = self._old_data
self._old_data = NULL
self._npy_array.data = <char *>self.data

self._npy_array = PyArray_SimpleNewFromData(
1, &dims, NPY_LONG, self.data
)

cdef void c_resize(self, long size) nogil:
cdef PyArrayObject* arr = <PyArrayObject*>self._npy_array
Expand Down Expand Up @@ -1943,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 = <PyArrayObject*>self._npy_array
cdef void* data = NULL
if size > self.alloc:
Expand All @@ -1961,12 +1970,16 @@ cdef class FloatArray(BaseArray):
self.alloc = size
arr.data = <char *>self.data

cdef void c_reset(self) nogil:
cdef void c_reset(self):
cdef np.npy_intp dims = self.length
BaseArray.c_reset(self)
if self._old_data != NULL:
self.data = self._old_data
self._old_data = NULL
self._npy_array.data = <char *>self.data

self._npy_array = PyArray_SimpleNewFromData(
1, &dims, NPY_FLOAT, self.data
)

cdef void c_resize(self, long size) nogil:
cdef PyArrayObject* arr = <PyArrayObject*>self._npy_array
Expand Down Expand Up @@ -2448,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 = <PyArrayObject*>self._npy_array
cdef void* data = NULL
if size > self.alloc:
Expand All @@ -2466,12 +2479,16 @@ cdef class DoubleArray(BaseArray):
self.alloc = size
arr.data = <char *>self.data

cdef void c_reset(self) nogil:
cdef void c_reset(self):
cdef np.npy_intp dims = self.length
BaseArray.c_reset(self)
if self._old_data != NULL:
self.data = self._old_data
self._old_data = NULL
self._npy_array.data = <char *>self.data

self._npy_array = PyArray_SimpleNewFromData(
1, &dims, NPY_DOUBLE, self.data
)

cdef void c_resize(self, long size) nogil:
cdef PyArrayObject* arr = <PyArrayObject*>self._npy_array
Expand Down
30 changes: 16 additions & 14 deletions cyarray/carray.pyx.mako
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%
import platform
type_info = [
('int', 'IntArray', 'NPY_INT'),
('unsigned int', 'UIntArray', 'NPY_UINT'),
Expand Down Expand Up @@ -37,11 +38,8 @@ The numpy array may however be copied and used in any manner.

# For malloc etc.
from libc.stdlib cimport *
IF UNAME_SYSNAME == "Windows":
cdef extern from "msstdint.h" nogil:
ctypedef unsigned int uintptr_t
ELSE:
from libc.stdint cimport uintptr_t

from libc.stdint cimport uintptr_t

cimport numpy as np

Expand Down Expand Up @@ -76,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.
Expand Down Expand Up @@ -135,13 +133,13 @@ cdef void* _deref_base(void* ptr) nogil:
raise MemoryError("Passed pointer is not aligned.")
return <void*>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(<void*>_deref_base(p))
Expand All @@ -158,10 +156,10 @@ 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) nogil:
cdef void c_reset(self):
cdef PyArrayObject* arr = <PyArrayObject*>self._npy_array
self.length = 0
arr.dimensions[0] = self.length
Expand Down Expand Up @@ -440,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 = <PyArrayObject*>self._npy_array
cdef void* data = NULL
if size > self.alloc:
Expand All @@ -458,12 +456,16 @@ cdef class ${CLASSNAME}(BaseArray):
self.alloc = size
arr.data = <char *>self.data

cdef void c_reset(self) nogil:
cdef void c_reset(self):
cdef np.npy_intp dims = self.length
BaseArray.c_reset(self)
if self._old_data != NULL:
self.data = self._old_data
self._old_data = NULL
self._npy_array.data = <char *>self.data

self._npy_array = PyArray_SimpleNewFromData(
1, &dims, ${NUMPY_TYPENAME}, self.data
)

cdef void c_resize(self, long size) nogil:
cdef PyArrayObject* arr = <PyArrayObject*>self._npy_array
Expand Down
Loading
Loading