@@ -464,7 +464,7 @@ def default_float_type(device=None, sycl_queue=None):
464
464
return map_dtype_to_device (float64 , _sycl_queue .sycl_device )
465
465
466
466
467
- def from_dlpack (obj , / ):
467
+ def from_dlpack (obj , / , * , device = None , copy = None ):
468
468
"""
469
469
Create a dpnp array from a Python object implementing the ``__dlpack__``
470
470
protocol.
@@ -476,17 +476,46 @@ def from_dlpack(obj, /):
476
476
obj : object
477
477
A Python object representing an array that implements the ``__dlpack__``
478
478
and ``__dlpack_device__`` methods.
479
+ device : {:class:`dpctl.SyclDevice`, :class:`dpctl.SyclQueue`,
480
+ :class:`dpctl.tensor.Device`, tuple, None}, optional
481
+ Array API concept of a device where the output array is to be placed.
482
+ ``device`` can be ``None``, an oneAPI filter selector string,
483
+ an instance of :class:`dpctl.SyclDevice` corresponding to
484
+ a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`,
485
+ a :class:`dpctl.tensor.Device` object returned by
486
+ :attr:`dpctl.tensor.usm_ndarray.device`, or a 2-tuple matching
487
+ the format of the output of the ``__dlpack_device__`` method,
488
+ an integer enumerator representing the device type followed by
489
+ an integer representing the index of the device.
490
+ Default: ``None``.
491
+ copy {bool, None}, optional
492
+ Boolean indicating whether or not to copy the input.
493
+
494
+ * If `copy``is ``True``, the input will always be copied.
495
+ * If ``False``, a ``BufferError`` will be raised if a copy is deemed
496
+ necessary.
497
+ * If ``None``, a copy will be made only if deemed necessary, otherwise,
498
+ the existing memory buffer will be reused.
499
+
500
+ Default: ``None``.
479
501
480
502
Returns
481
503
-------
482
504
out : dpnp_array
483
505
Returns a new dpnp array containing the data from another array
484
506
(obj) with the ``__dlpack__`` method on the same device as object.
485
507
508
+ Raises
509
+ ------
510
+ TypeError:
511
+ if `obj` does not implement ``__dlpack__`` method
512
+ ValueError:
513
+ if the input array resides on an unsupported device
514
+
486
515
"""
487
516
488
- usm_ary = dpt .from_dlpack (obj )
489
- return dpnp_array ._create_from_usm_ndarray (usm_ary )
517
+ usm_res = dpt .from_dlpack (obj , device = device , copy = copy )
518
+ return dpnp_array ._create_from_usm_ndarray (usm_res )
490
519
491
520
492
521
def get_dpnp_descriptor (
0 commit comments