Skip to content

Commit

Permalink
chore(bump cython): fn c_reset fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nauaneed committed Aug 15, 2024
1 parent add5487 commit 40094ee
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cyarray/carray.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cdef class BaseArray:

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_reset(self)
cdef void c_resize(self, long size) nogil
cdef void c_squeeze(self) nogil

Expand Down
2 changes: 1 addition & 1 deletion cyarray/carray.pxd.mako
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cdef class BaseArray:

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_reset(self)
cdef void c_resize(self, long size) nogil
cdef void c_squeeze(self) nogil

Expand Down
42 changes: 31 additions & 11 deletions cyarray/carray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ cdef class BaseArray:
cdef void c_reserve(self, long size) 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 @@ -443,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 @@ -948,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 @@ -1453,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 @@ -1958,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 @@ -2463,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
10 changes: 7 additions & 3 deletions cyarray/carray.pyx.mako
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ cdef class BaseArray:
cdef void c_reserve(self, long size) 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 @@ -456,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

0 comments on commit 40094ee

Please sign in to comment.