File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -448,15 +448,37 @@ cpdef usm_ndarray from_dlpack_capsule(object py_caps) except +:
448448
449449cpdef from_dlpack(array):
450450 """
451- dpctl.tensor.from_dlpack(obj)
451+ dpctl.tensor.from_dlpack(obj) -> dpctl.tensor.usm_ndarray
452452
453453 Constructs :class:`dpctl.tensor.usm_ndarray` instance from a Python
454454 object `obj` that implements `__dlpack__` protocol. The output
455455 array is always a zero-copy view of the input.
456456
457+ See https://dmlc.github.io/dlpack/latest/ for more details.
458+
459+ :Example:
460+ .. code-block:: python
461+
462+ import dpctl
463+ import dpctl.tensor as dpt
464+
465+ class Container:
466+ "Helper class implementing `__dlpack__` protocol"
467+ def __init__(self, array):
468+ self._array = array
469+
470+ def __dlpack__(self, stream=None):
471+ return self._array.__dlpack__(stream=stream)
472+
473+ def __dlpack_device__(self):
474+ return self._array.__dlpack_device__()
475+
476+ C = Container(dpt.linspace(0, 100, num=20, dtype="int16"))
477+ X = dpt.from_dlpack(C)
478+
457479 Args:
458- A Python object representing an array that supports `__dlpack__`
459- protocol.
480+ obj: A Python object representing an array that supports `__dlpack__`
481+ protocol.
460482 Raises:
461483 TypeError: if `obj` does not implement `__dlpack__` method.
462484 ValueError: if zero copy view can not be constructed because
You can’t perform that action at this time.
0 commit comments