Skip to content

Commit 52edb6d

Browse files
authored
Merge pull request #1781 from IntelPython/feature/dlpack-kdlcpu-support
Support `kDLCPU` DLDeviceType for `from_dlpack` and `__dlpack__`
2 parents 43f5aea + 9a17afc commit 52edb6d

File tree

7 files changed

+926
-278
lines changed

7 files changed

+926
-278
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. _dpctl_tensor_constants:
2+
3+
Constants
4+
========================
5+
6+
The following constants are defined in :py:mod:`dpctl.tensor`:
7+
8+
.. currentmodule:: dpctl.tensor
9+
10+
.. autodata:: DLDeviceType
11+
12+
.. data:: e
13+
14+
``float``:
15+
IEEE 754 floating-point representation of Euler's constant.
16+
17+
.. data:: inf
18+
19+
``float``:
20+
IEEE 754 floating-point representation of (positive) infinity.
21+
22+
.. data:: nan
23+
24+
``float``:
25+
IEEE 754 floating-point representation of Not a Number (NaN).
26+
27+
.. data:: newaxis
28+
29+
``NoneType``:
30+
Alias for ``None`` which is useful for indexing.
31+
32+
.. data:: pi
33+
34+
``float``:
35+
IEEE 754 floating-point representation of the mathematical constant π.

docs/doc_sources/api_reference/dpctl/tensor.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This module contains:
2929
* :ref:`sorting functions <dpctl_tensor_sorting_functions>`
3030
* :ref:`statistical functions <dpctl_tensor_statistical_functions>`
3131
* :ref:`utility functions <dpctl_tensor_utility_functions>`
32+
* :ref:`constants <dpctl_tensor_constants>`
3233

3334

3435
.. toctree::
@@ -48,3 +49,4 @@ This module contains:
4849
tensor.sorting_functions
4950
tensor.statistical_functions
5051
tensor.utility_functions
52+
tensor.constants

dpctl/tensor/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
from dpctl.tensor._reshape import reshape
101101
from dpctl.tensor._search_functions import where
102102
from dpctl.tensor._statistical_functions import mean, std, var
103-
from dpctl.tensor._usmarray import usm_ndarray
103+
from dpctl.tensor._usmarray import DLDeviceType, usm_ndarray
104104
from dpctl.tensor._utility_functions import all, any, diff
105105

106106
from ._accumulation import cumulative_logsumexp, cumulative_prod, cumulative_sum
@@ -383,5 +383,6 @@
383383
"nextafter",
384384
"diff",
385385
"count_nonzero",
386+
"DLDeviceType",
386387
"take_along_axis",
387388
]

dpctl/tensor/_dlpack.pxd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
# cython: language_level=3
1919
# cython: linetrace=True
2020

21+
cdef extern from "numpy/npy_no_deprecated_api.h":
22+
pass
23+
from numpy cimport ndarray
24+
2125
from .._sycl_device cimport SyclDevice
2226
from ._usmarray cimport usm_ndarray
2327

@@ -40,7 +44,8 @@ cdef extern from 'dlpack/dlpack.h' nogil:
4044

4145
cpdef object to_dlpack_capsule(usm_ndarray array) except +
4246
cpdef object to_dlpack_versioned_capsule(usm_ndarray array, bint copied) except +
43-
cpdef usm_ndarray from_dlpack_capsule(object dltensor) except +
47+
cpdef object numpy_to_dlpack_versioned_capsule(ndarray array, bint copied) except +
48+
cpdef object from_dlpack_capsule(object dltensor) except +
4449

4550
cdef int get_parent_device_ordinal_id(SyclDevice dev) except *
4651

0 commit comments

Comments
 (0)