Skip to content

Commit 7a56675

Browse files
authored
Update DLPack content to address unsupported use cases (#709)
Also extend the description of errors when DLPack cannot be supported
1 parent 8fe8b08 commit 7a56675

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: spec/draft/design_topics/data_interchange.rst

+19
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,22 @@ page gives a high-level specification for data exchange in Python using DLPack.
8484
are recommended to do so using the same syntax and semantics as outlined
8585
below. They are not required to return an array object from ``from_dlpack``
8686
which conforms to this standard.
87+
88+
Non-supported use cases
89+
-----------------------
90+
91+
Use of DLPack requires that the data can be represented by a strided, in-memory
92+
layout on a single device. This covers usage by a large range of, but not all,
93+
known and possible array libraries. Use cases that are not supported by DLPack
94+
include:
95+
96+
- Distributed arrays, i.e., the data residing on multiple nodes or devices,
97+
- Sparse arrays, i.e., sparse representations where a data value (typically
98+
zero) is implicit.
99+
100+
There may be other reasons why it is not possible or desirable for an
101+
implementation to materialize the array as strided data in memory. In such
102+
cases, the implementation may raise a `BufferError` in the `__dlpack__` or
103+
`__dlpack_device__` method. In case an implementation is never able to export
104+
its array data via DLPack, it may omit `__dlpack__` and `__dlpack_device__`
105+
completely, and hence `from_dlpack` may raise an `AttributeError`.

Diff for: src/array_api_stubs/_draft/creation_functions.py

+14
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ def from_dlpack(x: object, /) -> array:
232232
:class: note
233233
234234
The returned array may be either a copy or a view. See :ref:`data-interchange` for details.
235+
236+
Raises
237+
------
238+
BufferError
239+
The ``__dlpack__`` and ``__dlpack_device__`` methods on the input array
240+
may raise ``BufferError`` when the data cannot be exported as DLPack
241+
(e.g., incompatible dtype or strides). It may also raise other errors
242+
when export fails for other reasons (e.g., not enough memory available
243+
to materialize the data). ``from_dlpack`` must propagate such
244+
exceptions.
245+
AttributeError
246+
If the ``__dlpack__`` and ``__dlpack_device__`` methods are not present
247+
on the input array. This may happen for libraries that are never able
248+
to export their data with DLPack.
235249
"""
236250

237251

0 commit comments

Comments
 (0)