Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions spec/draft/API_specification/array_object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ Attributes
array.shape
array.size
array.T
array.__dlpack_c_exchange_api__

-------------------------------------------------

Expand Down
13 changes: 13 additions & 0 deletions spec/draft/design_topics/data_interchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ page gives a high-level specification for data exchange in Python using DLPack.
below. They are not required to return an array object from ``from_dlpack``
which conforms to this standard.


DLPack C Exchange API
---------------------

DLPack 1.3 introduces a C-level exchange API that can be used to speed up
data exchange between arrays at the C-extension level. This API is available via
the ``type(array_instance).__dlpack_c_exchange_api__`` attribute on the array type object.
This is a static global object shared across all the array instances of the same type.
For more details, see the `Python specification of DLPack <https://dmlc.github.io/dlpack/latest/python_spec.html>`__
We recommend consumer libraries to start first using the Python-level ``__dlpack__`` first which will covers
most cases, then start to use the C-level ``__dlpack_c_exchange_api__`` for performance critical cases.


Non-supported use cases
-----------------------

Expand Down
13 changes: 13 additions & 0 deletions src/array_api_stubs/_draft/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@


class _array:
"""
Attributes
----------
__dlpack_c_exchange_api__: PyCapsule
An optional static array type attribute stored in ``type(array_instance).__dlpack_c_exchange_api__``
that can be used to retrieve the DLPack C-API exchange API struct in DLPack 1.3 or later to speed up
exchange of array data at the C extension level without going through Python-level exchange.
See :ref:`data-interchange` section for more details.
"""

# use None for placeholder
__dlpack_c_exchange_api__: PyCapsule = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rendering this locally shows the one-line description goes missing:

Image

I think the correct fix is to make it an @property just like dtype, device and other properties. These are only stubs that are primarily used for generating documentation, so I don't see a problem with this being a type-specific rather than an instance-specific property.


def __init__(self: array) -> None:
"""Initialize the attributes for the array object class."""

Expand Down