Skip to content

Expanded docstring for method #994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions dpctl/tensor/_dlpack.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down