@@ -2050,8 +2050,8 @@ def fromstring(
2050
2050
2051
2051
def from_dlpack (x , / , * , device = None , copy = None ):
2052
2052
"""
2053
- Create a dpnp array from a Python object implementing the ``__dlpack__``
2054
- protocol.
2053
+ Constructs :class:` dpnp.ndarray` or :class:`numpy.ndarray` instance from
2054
+ a Python object `x` that implements ``__dlpack__`` protocol.
2055
2055
2056
2056
For full documentation refer to :obj:`numpy.from_dlpack`.
2057
2057
@@ -2060,16 +2060,27 @@ def from_dlpack(x, /, *, device=None, copy=None):
2060
2060
x : object
2061
2061
A Python object representing an array that implements the ``__dlpack__``
2062
2062
and ``__dlpack_device__`` methods.
2063
- device : {None, tuple, SyclDevice, SyclQueue, Device}, optional
2064
- Array API concept of a device where the output array is to be placed.
2065
- ``device`` can be ``None``, an oneAPI filter selector string,
2066
- an instance of :class:`dpctl.SyclDevice` corresponding to
2067
- a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`,
2068
- a :class:`dpctl.tensor.Device` object returned by
2069
- :attr:`dpctl.tensor.usm_ndarray.device`, or a 2-tuple matching
2070
- the format of the output of the ``__dlpack_device__`` method,
2071
- an integer enumerator representing the device type followed by
2072
- an integer representing the index of the device.
2063
+ device : {None, string, tuple, device}, optional
2064
+ Device where the output array is to be placed. `device` keyword values
2065
+ can be:
2066
+
2067
+ * ``None`` : The data remains on the same device.
2068
+ * oneAPI filter selector string : SYCL device selected by filter
2069
+ selector string.
2070
+ * :class:`dpctl.SyclDevice` : Explicit SYCL device that must correspond
2071
+ to a non-partitioned SYCL device.
2072
+ * :class:`dpctl.SyclQueue` : Implies SYCL device targeted by the SYCL
2073
+ queue.
2074
+ * :class:`dpctl.tensor.Device` : Implies SYCL device
2075
+ ``device.sycl_queue``. The `device` object is obtained via
2076
+ :attr:`dpctl.tensor.usm_ndarray.device`.
2077
+ * ``(device_type, device_id)`` : 2-tuple matching the format of the
2078
+ output of the ``__dlpack_device__`` method: an integer enumerator
2079
+ representing the device type followed by an integer representing
2080
+ the index of the device. The only supported
2081
+ :class:`dpctl.tensor.DLDeviceType` device types are ``"kDLCPU"``
2082
+ and ``"kDLOneAPI"``.
2083
+
2073
2084
Default: ``None``.
2074
2085
copy : {bool, None}, optional
2075
2086
Boolean indicating whether or not to copy the input.
@@ -2084,16 +2095,30 @@ def from_dlpack(x, /, *, device=None, copy=None):
2084
2095
2085
2096
Returns
2086
2097
-------
2087
- out : dpnp.ndarray
2088
- Returns a new dpnp array containing the data from another array `obj`
2089
- with the ``__dlpack__`` method on the same device as object.
2098
+ out : {dpnp.ndarray, numpy.ndarray}
2099
+ An array containing the data in `x`. When `copy` is ``None`` or
2100
+ ``False``, this may be a view into the original memory.
2101
+ The type of the returned object depends on where the data backing up
2102
+ input object `x` resides. If it resides in a USM allocation on a SYCL
2103
+ device, the type :class:`dpnp.ndarray` is returned, otherwise if it
2104
+ resides on ``"kDLCPU"`` device the type is :class:`numpy.ndarray`, and
2105
+ otherwise an exception is raised.
2090
2106
2091
2107
Raises
2092
2108
------
2093
- TypeError:
2109
+ TypeError
2094
2110
if `obj` does not implement ``__dlpack__`` method
2095
- ValueError:
2096
- if the input array resides on an unsupported device
2111
+ ValueError
2112
+ if data of the input object resides on an unsupported device
2113
+
2114
+ Notes
2115
+ -----
2116
+ If the return type is :class:`dpnp.ndarray`, the associated SYCL queue is
2117
+ derived from the `device` keyword. When `device` keyword value has type
2118
+ :class:`dpctl.SyclQueue`, the explicit queue instance is used, when `device`
2119
+ keyword value has type :class:`dpctl.tensor.Device`, the
2120
+ ``device.sycl_queue`` is used. In all other cases, the cached SYCL queue
2121
+ corresponding to the implied SYCL device is used.
2097
2122
2098
2123
Examples
2099
2124
--------
@@ -2105,8 +2130,10 @@ def from_dlpack(x, /, *, device=None, copy=None):
2105
2130
2106
2131
"""
2107
2132
2108
- usm_res = dpt .from_dlpack (x , device = device , copy = copy )
2109
- return dpnp_array ._create_from_usm_ndarray (usm_res )
2133
+ result = dpt .from_dlpack (x , device = device , copy = copy )
2134
+ if isinstance (result , dpt .usm_ndarray ):
2135
+ return dpnp_array ._create_from_usm_ndarray (result )
2136
+ return result
2110
2137
2111
2138
2112
2139
def full (
0 commit comments