Skip to content

Commit

Permalink
Merge branch 'branch-0.41' into python-async-blocking-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pentschev authored Oct 22, 2024
2 parents 9e2d017 + cfe9008 commit 94d05e9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions python/ucxx/ucxx/_lib/arr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
# cython: language_level=3


from cpython.array cimport array, newarrayobject
from cpython.buffer cimport PyBuffer_IsContiguous
from cpython.mem cimport PyMem_Free, PyMem_Malloc
from cpython.memoryview cimport (
PyMemoryView_FromObject,
PyMemoryView_GET_BUFFER,
)
from cpython.object cimport PyObject
from cpython.ref cimport Py_INCREF
from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM
from cython cimport (
Expand All @@ -20,6 +19,7 @@ from cython cimport (
nonecheck,
wraparound,
)
from cython.view cimport array
from libc.stdint cimport uintptr_t
from libc.string cimport memcpy

Expand Down Expand Up @@ -62,13 +62,14 @@ cdef dict itemsize_mapping = {
}


cdef array array_Py_ssize_t = array("q")
cdef sizeof_Py_ssize_t = sizeof(Py_ssize_t)


cdef inline Py_ssize_t[::1] new_Py_ssize_t_array(Py_ssize_t n):
return newarrayobject(
(<PyObject*>array_Py_ssize_t).ob_type, n, array_Py_ssize_t.ob_descr
)
cdef Py_ssize_t[::1] new_Py_ssize_t_array(Py_ssize_t n):
cdef array a = array((n,), sizeof_Py_ssize_t, b"q", "c", False)
a.data = <char*>PyMem_Malloc(n * sizeof(Py_ssize_t))
a.callback_free_data = PyMem_Free
return a


@auto_pickle(False)
Expand Down Expand Up @@ -245,7 +246,7 @@ cdef class Array:
cdef inline bint _c_contiguous(Py_ssize_t itemsize,
Py_ssize_t ndim,
Py_ssize_t[::1] shape_mv,
Py_ssize_t[::1] strides_mv) nogil:
Py_ssize_t[::1] strides_mv) noexcept nogil:
cdef Py_ssize_t i, s
if strides_mv is not None:
s = itemsize
Expand All @@ -263,7 +264,7 @@ cdef inline bint _c_contiguous(Py_ssize_t itemsize,
cdef inline bint _f_contiguous(Py_ssize_t itemsize,
Py_ssize_t ndim,
Py_ssize_t[::1] shape_mv,
Py_ssize_t[::1] strides_mv) nogil:
Py_ssize_t[::1] strides_mv) noexcept nogil:
cdef Py_ssize_t i, s
if strides_mv is not None:
s = itemsize
Expand All @@ -279,7 +280,7 @@ cdef inline bint _f_contiguous(Py_ssize_t itemsize,
cdef inline bint _contiguous(Py_ssize_t itemsize,
Py_ssize_t ndim,
Py_ssize_t[::1] shape_mv,
Py_ssize_t[::1] strides_mv) nogil:
Py_ssize_t[::1] strides_mv) noexcept nogil:
cdef bint r = _c_contiguous(itemsize, ndim, shape_mv, strides_mv)
if not r:
r = _f_contiguous(itemsize, ndim, shape_mv, strides_mv)
Expand All @@ -292,7 +293,7 @@ cdef inline bint _contiguous(Py_ssize_t itemsize,
@wraparound(False)
cdef inline Py_ssize_t _nbytes(Py_ssize_t itemsize,
Py_ssize_t ndim,
Py_ssize_t[::1] shape_mv) nogil:
Py_ssize_t[::1] shape_mv) noexcept nogil:
cdef Py_ssize_t i, nbytes = itemsize
for i in range(ndim):
nbytes *= shape_mv[i]
Expand Down

0 comments on commit 94d05e9

Please sign in to comment.