From fe58bcbeb816b2a2c221ea89bf7eba0c0294afb4 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 18 Nov 2022 15:15:03 -0600 Subject: [PATCH] Expanded docstring for method --- dpctl/tensor/_dlpack.pyx | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/dpctl/tensor/_dlpack.pyx b/dpctl/tensor/_dlpack.pyx index a58f4c29bb..f8ed9d8ae8 100644 --- a/dpctl/tensor/_dlpack.pyx +++ b/dpctl/tensor/_dlpack.pyx @@ -448,15 +448,37 @@ cpdef usm_ndarray from_dlpack_capsule(object py_caps) except +: cpdef from_dlpack(array): """ - dpctl.tensor.from_dlpack(obj) + dpctl.tensor.from_dlpack(obj) -> dpctl.tensor.usm_ndarray Constructs :class:`dpctl.tensor.usm_ndarray` instance from a Python object `obj` that implements `__dlpack__` protocol. The output array is always a zero-copy view of the input. + See https://dmlc.github.io/dlpack/latest/ for more details. + + :Example: + .. code-block:: python + + import dpctl + import dpctl.tensor as dpt + + class Container: + "Helper class implementing `__dlpack__` protocol" + def __init__(self, array): + self._array = array + + def __dlpack__(self, stream=None): + return self._array.__dlpack__(stream=stream) + + def __dlpack_device__(self): + return self._array.__dlpack_device__() + + C = Container(dpt.linspace(0, 100, num=20, dtype="int16")) + X = dpt.from_dlpack(C) + Args: - A Python object representing an array that supports `__dlpack__` - protocol. + obj: A Python object representing an array that supports `__dlpack__` + protocol. Raises: TypeError: if `obj` does not implement `__dlpack__` method. ValueError: if zero copy view can not be constructed because