Skip to content

Commit 8a071e3

Browse files
Merge pull request #994 from IntelPython/improve-from_dlpack-docstring
Expanded docstring for method
2 parents 5f82196 + fe58bcb commit 8a071e3

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

dpctl/tensor/_dlpack.pyx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,37 @@ cpdef usm_ndarray from_dlpack_capsule(object py_caps) except +:
448448

449449
cpdef 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

0 commit comments

Comments
 (0)