Skip to content

Commit b07236b

Browse files
committed
Update to property
1 parent 9f9cebf commit b07236b

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

src/array_api_stubs/_draft/array_object.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@
1717

1818

1919
class _array:
20-
"""
21-
Attributes
22-
----------
23-
__dlpack_c_exchange_api__: PyCapsule
24-
An optional static array type attribute stored in ``type(array_instance).__dlpack_c_exchange_api__``
25-
that can be used to retrieve the DLPack C-API exchange API struct in DLPack 1.3 or later to speed up
26-
exchange of array data at the C extension level without going through Python-level exchange.
27-
See :ref:`data-interchange` section for more details.
28-
"""
29-
30-
# use None for placeholder
31-
__dlpack_c_exchange_api__: PyCapsule = None
32-
3320
def __init__(self: array) -> None:
3421
"""Initialize the attributes for the array object class."""
3522

@@ -132,6 +119,26 @@ def T(self: array) -> array:
132119
Limiting the transpose to two-dimensional arrays (matrices) deviates from the NumPy et al practice of reversing all axes for arrays having more than two-dimensions. This is intentional, as reversing all axes was found to be problematic (e.g., conflicting with the mathematical definition of a transpose which is limited to matrices; not operating on batches of matrices; et cetera). In order to reverse all axes, one is recommended to use the functional ``permute_dims`` interface found in this specification.
133120
"""
134121

122+
123+
@property
124+
def __dlpack_c_exchange_api__(self: array) -> PyCapsule:
125+
"""
126+
127+
An optional static array type attribute stored in ``type(array_instance).__dlpack_c_exchange_api__``
128+
that can be used to retrieve the DLPack C-API exchange API struct in DLPack 1.3 or later to speed up
129+
exchange of array data at the C extension level without going through Python-level exchange.
130+
See :ref:`data-interchange` section for more details.
131+
132+
Returns
133+
-------
134+
out: PyCapsule
135+
The PyCapsule object containing the DLPack C-API exchange API struct.
136+
137+
.. note::
138+
This is a static global object shared across all the array instances of the same type.
139+
It can be queried through the ``type(array_instance).__dlpack_c_exchange_api__`` attribute.
140+
"""
141+
135142
def __abs__(self: array, /) -> array:
136143
"""
137144
Calculates the absolute value for each element of an array instance.

0 commit comments

Comments
 (0)