Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Replaced `.pxi` includes in `dpnp.tensor` with modular `.pxd`/`.pyx` Cython imports[#2913](https://github.com/IntelPython/dpnp/pull/2913)

### Deprecated

### Removed
Expand Down
42 changes: 42 additions & 0 deletions dpnp/tensor/_slicing.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# *****************************************************************************
# Copyright (c) 2026, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# - Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

# distutils: language = c++
# cython: language_level=3

cdef bint _is_buffer(object o)

cdef Py_ssize_t _slice_len(
Py_ssize_t sl_start,
Py_ssize_t sl_stop,
Py_ssize_t sl_step
)

cdef bint _is_integral(object x) except *

cdef bint _is_boolean(object x) except *
5 changes: 5 additions & 0 deletions dpnp/tensor/_slicing.pxi → dpnp/tensor/_slicing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

# distutils: language = c++
# cython: language_level=3

import numbers
from operator import index
from cpython.buffer cimport PyObject_CheckBuffer
from numpy import ndarray

from ._usmarray cimport usm_ndarray


cdef bint _is_buffer(object o):
return PyObject_CheckBuffer(o)
Expand Down
58 changes: 58 additions & 0 deletions dpnp/tensor/_stride_utils.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# *****************************************************************************
# Copyright (c) 2026, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# - Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

# distutils: language = c++
# cython: language_level=3

cdef int ERROR_MALLOC
cdef int ERROR_INTERNAL
cdef int ERROR_INCORRECT_ORDER
cdef int ERROR_UNEXPECTED_STRIDES

cdef int USM_ARRAY_C_CONTIGUOUS
cdef int USM_ARRAY_F_CONTIGUOUS
cdef int USM_ARRAY_WRITABLE

cdef Py_ssize_t shape_to_elem_count(int nd, Py_ssize_t *shape_arr)

cdef int _from_input_shape_strides(
int nd, object shape, object strides, int itemsize, char order,
Py_ssize_t **shape_ptr, Py_ssize_t **strides_ptr,
Py_ssize_t *nelems, Py_ssize_t *min_disp, Py_ssize_t *max_disp,
int *contig
)

cdef object _make_int_tuple(int nd, const Py_ssize_t *ary)

cdef object _make_reversed_int_tuple(int nd, const Py_ssize_t *ary)

cdef object _c_contig_strides(int nd, Py_ssize_t *shape)

cdef object _f_contig_strides(int nd, Py_ssize_t *shape)

cdef object _swap_last_two(tuple t)
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# distutils: language = c++
# cython: language_level=3

from cpython.mem cimport PyMem_Malloc
from cpython.mem cimport PyMem_Free, PyMem_Malloc
from cpython.ref cimport Py_INCREF
from cpython.tuple cimport PyTuple_New, PyTuple_SetItem

Expand Down
58 changes: 58 additions & 0 deletions dpnp/tensor/_types.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# *****************************************************************************
# Copyright (c) 2026, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# - Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

# distutils: language = c++
# cython: language_level=3

cdef int UAR_BOOL
cdef int UAR_BYTE
cdef int UAR_UBYTE
cdef int UAR_SHORT
cdef int UAR_USHORT
cdef int UAR_INT
cdef int UAR_UINT
cdef int UAR_LONG
cdef int UAR_ULONG
cdef int UAR_LONGLONG
cdef int UAR_ULONGLONG
cdef int UAR_FLOAT
cdef int UAR_DOUBLE
cdef int UAR_CFLOAT
cdef int UAR_CDOUBLE
cdef int UAR_TYPE_SENTINEL
cdef int UAR_HALF

cdef int type_bytesize(int typenum)

cdef str _make_typestr(int typenum)

cdef int typenum_from_format(str s)

cdef int descr_to_typenum(object dtype)

cdef int dtype_to_typenum(dtype)
5 changes: 5 additions & 0 deletions dpnp/tensor/_types.pxi → dpnp/tensor/_types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

# distutils: language = c++
# cython: language_level=3

import numpy as np

# these typenum values are aligned to values in NumPy
cdef:
int UAR_BOOL = 0 # pragma: no cover
Expand Down
53 changes: 49 additions & 4 deletions dpnp/tensor/_usmarray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ from ._print import usm_ndarray_repr, usm_ndarray_str
cimport dpctl as c_dpctl
cimport dpctl.memory as c_dpmem
from cpython.mem cimport PyMem_Free
from cpython.tuple cimport PyTuple_New, PyTuple_SetItem

from . cimport _dlpack as c_dlpack

Expand All @@ -56,9 +55,55 @@ from . import _flags
from ._dlpack import get_build_dlpack_version
from ._tensor_impl import default_device_fp_type

include "_stride_utils.pxi"
include "_types.pxi"
include "_slicing.pxi"
from ._slicing cimport *
from ._stride_utils cimport (
ERROR_INCORRECT_ORDER,
ERROR_INTERNAL,
ERROR_MALLOC,
ERROR_UNEXPECTED_STRIDES,
_c_contig_strides,
_f_contig_strides,
_from_input_shape_strides,
_make_int_tuple,
_make_reversed_int_tuple,
_swap_last_two,
shape_to_elem_count,
)
from ._types cimport (
_make_typestr,
descr_to_typenum,
dtype_to_typenum,
type_bytesize,
typenum_from_format,
)

from ._slicing import _basic_slice_meta


# Local storage for `cdef public api` constants
# declared in _usmarray.pxd
cdef int USM_ARRAY_C_CONTIGUOUS = 1
cdef int USM_ARRAY_F_CONTIGUOUS = 2
cdef int USM_ARRAY_WRITABLE = 4

cdef:
int UAR_BOOL = 0
int UAR_BYTE = 1
int UAR_UBYTE = 2
int UAR_SHORT = 3
int UAR_USHORT = 4
int UAR_INT = 5
int UAR_UINT = 6
int UAR_LONG = 7
int UAR_ULONG = 8
int UAR_LONGLONG = 9
int UAR_ULONGLONG = 10
int UAR_FLOAT = 11
int UAR_DOUBLE = 12
int UAR_CFLOAT = 14
int UAR_CDOUBLE = 15
int UAR_TYPE_SENTINEL = 17
int UAR_HALF = 23


class DLDeviceType(IntEnum):
Expand Down
Loading