Skip to content

Commit 2c5cf92

Browse files
authoredMar 23, 2024
fix hyperlinks in the python spec page (#142)
1 parent 695c8dd commit 2c5cf92

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed
 

‎docs/source/conf.py

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
exclude_patterns = []
4242

4343
intersphinx_mapping = {
44+
"python": ("https://docs.python.org/3/", None),
4445
"array_api": ("https://data-apis.org/array-api/latest", None),
4546
}
4647

@@ -68,6 +69,10 @@
6869
# -Dbreathe_projects.<breathe_default_project>=</path/to/xml/index/directory>
6970
breathe_default_project = "dlpack"
7071

72+
breathe_domain_by_extension = {
73+
"h" : "c",
74+
}
75+
7176

7277
# -- Options for HTML output -------------------------------------------------
7378

‎docs/source/python_spec.rst

+21-20
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Syntax for data interchange with DLPack
1313

1414
The array API will offer the following syntax for data interchange:
1515

16-
1. A ``from_dlpack(x, ...)`` function, which accepts any (array) object with
16+
1. A :func:`~array_api.from_dlpack` function, which accepts any (array) object with
1717
the two DLPack methods implemented (see below) and uses them to construct
18-
a new array containing the data from ``x``.
19-
2. ``__dlpack__`` and ``__dlpack_device__`` methods on the
20-
array object, which will be called from within ``from_dlpack``, to query
18+
a new array containing the data from the input array.
19+
2. :meth:`~array_api.array.__dlpack__` and :meth:`~array_api.array.__dlpack_device__` methods on the
20+
array object, which will be called from within :func:`~array_api.from_dlpack`, to query
2121
what device the array is on (may be needed to pass in the correct
2222
stream, e.g. in the case of multiple GPUs) and to access the data.
2323

@@ -39,7 +39,7 @@ may flag this and make a copy of the data. In both cases:
3939

4040
If an array that is accessed via the interchange protocol lives on a device that
4141
the requesting (consumer) library does not support, it is recommended to raise a
42-
``BufferError``, unless an explicit copy is requested (see below) and the producer
42+
:obj:`BufferError`, unless an explicit copy is requested (see below) and the producer
4343
can support the request.
4444

4545
Stream handling through the ``stream`` keyword applies to CUDA and ROCm (perhaps
@@ -51,9 +51,9 @@ unnecessary so asynchronous execution is enabled.
5151

5252
Starting Python array API standard v2023, a copy can be explicitly requested (or
5353
disabled) through the new ``copy`` argument of ``from_dlpack()``. When a copy is
54-
made, the producer must set the ``DLPACK_FLAG_BITMASK_IS_COPIED`` bit flag.
54+
made, the producer must set the :c:macro:`DLPACK_FLAG_BITMASK_IS_COPIED` bit flag.
5555
It is also possible to request cross-device copies through the new ``device``
56-
argument, though the v2023 standard only mandates the support of ``kDLCPU``.
56+
argument, though the v2023 standard only mandates the support of :c:enumerator:`kDLCPU`.
5757

5858
Implementation
5959
~~~~~~~~~~~~~~
@@ -72,24 +72,25 @@ types.*
7272

7373
Starting Python array API standard v2023, a new ``max_version`` argument
7474
is added to ``__dlpack__`` for the consumer to signal the producer the
75-
maximal supported DLPack version. Starting DLPack 1.0, the ``DLManagedTensorVersioned``
76-
struct should be used and the existing ``DLManagedTensor`` struct is considered
75+
maximal supported DLPack version. Starting DLPack 1.0, the :c:struct:`DLManagedTensorVersioned`
76+
struct should be used and the existing :c:struct:`DLManagedTensor` struct is considered
7777
deprecated, though a library should try to support both during the transition
7878
period if possible.
7979

80-
In the rest of this document, ``DLManagedTensorVersioned`` and ``DLManagedTensor``
81-
are treated as synonyms, assuming a proper handling of ``max_version`` has been
82-
done to choose the right struct. As far as the capsule name is concerned,
83-
when ``DLManagedTensorVersioned`` is in use the capsule names ``dltensor``
84-
and ``used_dltensor`` will need a ``_versioned`` suffix.
80+
.. note::
81+
In the rest of this document, ``DLManagedTensorVersioned`` and ``DLManagedTensor``
82+
are treated as synonyms, assuming a proper handling of ``max_version`` has been
83+
done to choose the right struct. As far as the capsule name is concerned,
84+
when ``DLManagedTensorVersioned`` is in use the capsule names ``dltensor``
85+
and ``used_dltensor`` will need a ``_versioned`` suffix.
8586

86-
The ``__dlpack__`` method will produce a ``PyCapsule`` containing a
87+
The ``__dlpack__`` method will produce a :c:type:`PyCapsule` containing a
8788
``DLManagedTensor``, which will be consumed immediately within
8889
``from_dlpack`` - therefore it is consumed exactly once, and it will not be
8990
visible to users of the Python API.
9091

9192
The producer must set the ``PyCapsule`` name to ``"dltensor"`` so that
92-
it can be inspected by name, and set ``PyCapsule_Destructor`` that calls
93+
it can be inspected by name, and set :c:type:`PyCapsule_Destructor` that calls
9394
the ``deleter`` of the ``DLManagedTensor`` when the ``"dltensor"``-named
9495
capsule is no longer needed.
9596

@@ -128,7 +129,7 @@ statically allocated.
128129
The ``DLManagedTensor`` deleter must ensure that sharing beyond Python
129130
boundaries is possible, this means that the GIL must be acquired explicitly
130131
if it uses Python objects or API.
131-
In Python, the deleter usually needs to ``Py_DECREF()`` the original owner
132+
In Python, the deleter usually needs to :c:func:`Py_DECREF` the original owner
132133
and free the ``DLManagedTensor`` allocation.
133134
For example, NumPy uses the following code to ensure sharing with arbitrary
134135
non-Python code is safe:
@@ -157,15 +158,15 @@ non-Python code is safe:
157158
PyGILState_Release(state);
158159
}
159160
160-
When the ``strides`` field in the ``DLTensor`` struct is ``NULL``, it indicates a
161+
When the :c:member:`~DLTensor.strides` field in the :c:struct:`DLTensor` struct is ``NULL``, it indicates a
161162
row-major compact array. If the array is of size zero, the data pointer in
162163
``DLTensor`` should be set to either ``NULL`` or ``0``.
163164

164165
For further details on DLPack design and how to implement support for it,
165166
refer to `github.com/dmlc/dlpack <https://github.com/dmlc/dlpack>`_.
166167

167168
.. warning::
168-
DLPack contains a ``device_id``, which will be the device
169+
DLPack contains a :c:member:`~DLDevice.device_id`, which will be the device
169170
ID (an integer, ``0, 1, ...``) which the producer library uses. In
170171
practice this will likely be the same numbering as that of the
171172
consumer, however that is not guaranteed. Depending on the hardware
@@ -174,7 +175,7 @@ refer to `github.com/dmlc/dlpack <https://github.com/dmlc/dlpack>`_.
174175
possible for example for CUDA device pointers.
175176

176177
It is recommended that implementers of this array API consider and document
177-
whether the ``.device`` attribute of the array returned from ``from_dlpack`` is
178+
whether the :attr:`~array_api.array.device` attribute of the array returned from ``from_dlpack`` is
178179
guaranteed to be in a certain order or not.
179180

180181

0 commit comments

Comments
 (0)