Skip to content

Commit 95395bc

Browse files
committed
Fix cross-references to helper functions and some RST issues
1 parent f66b8ac commit 95395bc

File tree

6 files changed

+32
-27
lines changed

6 files changed

+32
-27
lines changed

array_api_compat/common/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def to_device(x: Array, device: Device, /, *, stream: Optional[Union[int, Any]]
452452
<https://docs.cupy.dev/en/stable/reference/generated/cupy.cuda.Device.html>`_
453453
and `Stream
454454
<https://docs.cupy.dev/en/stable/reference/generated/cupy.cuda.Stream.html>`_
455-
objects. For PyTorch, this is the same as ``x.to(device)
455+
objects. For PyTorch, this is the same as `x.to(device)
456456
<https://pytorch.org/docs/stable/generated/torch.Tensor.to.html>`_ (the
457457
``stream`` argument is not supported in PyTorch).
458458

docs/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737

3838
# Make sphinx give errors for bad cross-references
3939
nitpicky = True
40+
# autodoc wants to make cross-references for every type hint. But a lot of
41+
# them don't actually refer to anything that we have a document for.
42+
nitpick_ignore = [
43+
("py:class", "Array"),
44+
("py:class", "Device"),
45+
]
4046

4147
# Lets us use single backticks for code in RST
4248
default_role = 'code'

docs/dev/implementation-notes.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ should be taken into account:
1414

1515
- *No Hard Dependencies.* Although array-api-compat "depends" on NumPy, CuPy,
1616
PyTorch, etc., it does not hard depend on them. These libraries are not
17-
imported unless either an array object is passed to `array_namespace()`, or
18-
the specific `array_api_compat.<namespace>` sub-namespace is explicitly
19-
imported.
17+
imported unless either an array object is passed to
18+
{func}`~.array_namespace()`, or the specific `array_api_compat.<namespace>`
19+
sub-namespace is explicitly imported.
2020

2121
- *Vendorability.* array-api-compat should be [vendorable](vendoring). This
2222
means that, for instance, all imports in the library are relative imports.
@@ -35,7 +35,7 @@ should be taken into account:
3535

3636
This also means that we do not at this point in time implement anything
3737
other than wrappers for functions in the standard, and basic [helper
38-
functions](../helper-functions.md) that would be useful for most users of
38+
functions](../helper-functions.rst) that would be useful for most users of
3939
array-api-compat. The addition of functions that are not part of the array
4040
API standard is currently out-of-scope for this package.
4141

@@ -59,7 +59,7 @@ should be taken into account:
5959
functions](https://data-apis.org/array-api/latest/API_specification/elementwise_functions.html)
6060
instead of
6161
[operators](https://data-apis.org/array-api/latest/API_specification/array_object.html#operators),
62-
and by using the [helper functions](../helper-functions.md) provided by
62+
and by using the [helper functions](../helper-functions.rst) provided by
6363
array-api-compat instead of attributes or methods like `x.to_device()`.
6464

6565
- *Avoid Restricting Behavior that is Outside the Scope of the Standard.* All
@@ -145,7 +145,7 @@ The majority of the behavior for array-api-compat is tested by the
145145
the array API standard. There are also array-api-compat specific tests in
146146
[`tests/`](https://github.com/data-apis/array-api-compat/tree/main/tests).
147147
These tests should be limited to things that are not tested by the test suite,
148-
e.g., tests for [helper functions](../helper-functions.md) or for behavior
148+
e.g., tests for [helper functions](../helper-functions.rst) or for behavior
149149
that is not strictly required by the standard.
150150

151151
array-api-tests is run against all supported libraries are tested on CI

docs/helper-functions.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ array_namespace
1313
The `array_namespace()` function is the primary entry-point for array API
1414
consuming libraries.
1515

16+
1617
.. autofunction:: array_namespace
17-
:canonical: array_api_compat.array_namespace
18+
.. autofunction:: is_array_api_obj
1819

1920
Array Method Helpers
2021
--------------------
2122

2223
array-api-compat does not attempt to wrap or monkey patch the array object for
2324
any library. Consequently, any API differences for the [array
24-
object](https://data-apis.org/array-api/latest/API_specification/array_object.htmlK
25+
object](https://data-apis.org/array-api/latest/API_specification/array_object.html)
2526
cannot be directly wrapped. Some libraries do not define some of these methods
2627
or define them differently. For these, helper functions are provided which can
2728
be used instead.
@@ -35,14 +36,13 @@ instead, which would be wrapped.
3536
.. autofunction:: to_device
3637
.. autofunction:: size
3738

38-
Inspect Helpers
39-
---------------
39+
Inspection Helpers
40+
------------------
4041

4142
These convenience functions can be used to test if an array comes from a
4243
specific library without importing that library if it hasn't been imported
4344
yet.
4445

45-
.. autofunction:: is_array_api_obj
4646
.. autofunction:: is_numpy_array
4747
.. autofunction:: is_cupy_array
4848
.. autofunction:: is_torch_array

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ version](https://data-apis.org/array-api/2022.12/) of the standard.
2323
python -m pip install array-api-compat
2424
```
2525

26-
and [Conda-forge](https://anaconda.org/conda-forge/array-api-compat)
26+
and [conda-forge](https://anaconda.org/conda-forge/array-api-compat)
2727

2828
```
2929
conda install --channel conda-forge array-api-compat
@@ -32,7 +32,7 @@ conda install --channel conda-forge array-api-compat
3232
## Usage
3333

3434
The typical usage of this library will be to get the corresponding array API
35-
compliant namespace from the input arrays using {func}`array_namespace()`, like
35+
compliant namespace from the input arrays using {func}`~.array_namespace()`, like
3636

3737
```py
3838
def your_function(x, y):

docs/supported-array-libraries.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ The following array libraries are supported. This page outlines the known
44
differences between this library and the array API specification for the
55
supported packages.
66

7-
Note that the [`array_namespace()`](helper-functions.md) helper will also
8-
support any array library that explicitly supports the array API by defining
7+
Note that the {func}`~.array_namespace()` helper will also support any array
8+
library that explicitly supports the array API by defining
99
[`__array_namespace__`](https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.__array_namespace__.html).
1010

1111
Any reasonably popular array library is in-scope for array-api-compat,
@@ -17,18 +17,18 @@ complexity. If your favorite library is not supported, feel free to open an
1717

1818
NumPy 2.0 has full array API compatibility. This package is not strictly
1919
necessary for NumPy 2.0 support, but may still be useful for the support of
20-
other libraries, as well as for the [helper functions](helper-functions.md).
20+
other libraries, as well as for the [helper functions](helper-functions.rst).
2121

2222
For NumPy 1.26, as well as corresponding versions of CuPy, the following
2323
deviations from the standard should be noted:
2424

2525
- The array methods `__array_namespace__`, `device` (for NumPy), `to_device`,
2626
and `mT` are not defined. This reuses `np.ndarray` and `cp.ndarray` and we
2727
don't want to monkey patch or wrap it. The [helper
28-
functions](helper-functions.md) `device()` and `to_device()` are provided to
29-
work around these missing methods. `x.mT` can be replaced with
30-
`xp.linalg.matrix_transpose(x)`. `array_namespace(x)` should be used instead
31-
of `x.__array_namespace__`.
28+
functions](helper-functions.rst) {func}`~.device()` and {func}`~.to_device()`
29+
are provided to work around these missing methods. `x.mT` can be replaced
30+
with `xp.linalg.matrix_transpose(x)`. {func}`~.array_namespace()` should be
31+
used instead of `x.__array_namespace__`.
3232

3333
- Value-based casting for scalars will be in effect unless explicitly disabled
3434
with the environment variable `NPY_PROMOTION_STATE=weak` or
@@ -63,14 +63,14 @@ version.
6363

6464
- Like NumPy/CuPy, we do not wrap the `torch.Tensor` object. It is missing the
6565
`__array_namespace__` and `to_device` methods, so the corresponding helper
66-
functions `array_namespace()` and `to_device()` in this library should be
67-
used instead (see above).
66+
functions {func}`~.array_namespace()` and {func}`~.to_device()` in this
67+
library should be used instead.
6868

6969
- The `x.size` attribute on `torch.Tensor` is a function that behaves
7070
differently from
7171
[`x.size`](https://data-apis.org/array-api/draft/API_specification/generated/array_api.array.size.html)
72-
in the spec. Use the `size(x)` helper function as a portable workaround (see
73-
above).
72+
in the spec. Use the {func}`~.size()` helper function as a portable
73+
workaround.
7474

7575
- PyTorch does not have unsigned integer types other than `uint8`, and no
7676
attempt is made to implement them here.
@@ -95,8 +95,7 @@ version.
9595
[`var()`](https://data-apis.org/array-api/latest/API_specification/generated/array_api.var.html#array_api.var)
9696
do not support floating-point `correction`.
9797

98-
- The `stream` argument of the `to_device()` helper (see above) is not
99-
supported.
98+
- The `stream` argument of the {func}`~.to_device()` helper is not supported.
10099

101100
- As with NumPy, type annotations and positional-only arguments may not
102101
exactly match the spec for functions that are not wrapped at all.

0 commit comments

Comments
 (0)