Skip to content

Commit 5288076

Browse files
committed
Review comments
1 parent a4e274b commit 5288076

1 file changed

Lines changed: 44 additions & 42 deletions

File tree

spec/2025.12/migration_guide.md

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ This page is meant to help migrate your codebase to an Array API compliant
66
implementation. The guide is divided into two parts and, depending on your
77
exact use-case, you should look thoroughly into at least one of them.
88

9-
The first part is dedicated for {ref}`array-producers`. If your library
10-
mimics e.g. NumPy's or Dask's functionality, then you can find there an
11-
additional instructions and guidance on how to ensure downstream users can
12-
easily pick your solution as an array provider for their system/algorithm.
9+
The first part is dedicated for {ref}`array-producers`. If your library
10+
mimics, for example, NumPy's or Dask's functionality, then you can find in
11+
the first part additional instructions and guidance on how to ensure
12+
downstream users can easily pick your solution as an array provider for
13+
their system/algorithm.
1314

1415
The second part delves into details for Array API compatibility for
1516
{ref}`array-consumers`. This pertains to any software that performs
16-
multidimensional array manipulation in Python, such as: scikit-learn, SciPy,
17-
or statsmodels. If your software relies on a certain array producing library,
18-
such as NumPy or JAX, then here you can learn how to make it library agnostic
19-
and interchange them with way less friction.
17+
multidimensional array manipulation in Python, such as may be found in
18+
scikit-learn, SciPy, or statsmodels. If your software relies on a certain
19+
array producing library, such as NumPy or JAX, then you can use the second
20+
part to learn how to make it library agnostic and interchange array
21+
namespaces with significantly less friction.
2022

2123
## Ecosystem
2224

@@ -33,10 +35,10 @@ User group: Array Consumers
3335

3436
Although NumPy, Dask, CuPy, and PyTorch support the Array API Standard, there
3537
are still some corner cases where their behavior diverges from the standard.
36-
`array-api-compat` provides a compatibility layer to cover these cases as well.
38+
`array-api-compat` provides a compatibility layer to cover these cases.
3739
This is also accompanied by a few utility functions for easier introspection
38-
into array objects. As an array consumer you can still rely on the original API
39-
while having access to the standard compatible one.
40+
into array objects. As an array consumer, you can still rely on the original
41+
API while having access to the standard compatible one.
4042

4143

4244
(array-api-strict)=
@@ -47,12 +49,12 @@ GitHub: [array-api-strict](https://github.com/data-apis/array-api-strict)
4749
User group: Array Consumers, Array Producers (for testing)
4850

4951
`array-api-strict` is a library that provides a strict and minimal
50-
implementation of the Array API Standard. For array producers it is designed
52+
implementation of the Array API Standard. For array producers, it is designed
5153
to be used as a reference implementation for testing and development purposes.
52-
You can compare your API calls with `array-api-strict` counterparts,
53-
and ensure that your library is fully compliant with the standard and can
54+
You can compare your API calls with `array-api-strict` counterparts and
55+
ensure that your library is fully compliant with the standard and can
5456
serve as a reliable reference for other developers in the ecosystem.
55-
For consumers you can use `array-api-strict` during the development as an
57+
For consumers, you can use `array-api-strict` during the development as an
5658
array provider to ensure your code uses API compliant with the standard.
5759

5860

@@ -90,28 +92,27 @@ The sections below mention when and how to use them.
9092
## Array Producers
9193

9294
For array producers, the central task during the development/migration process
93-
is adhering user-facing API to the Array API Standard.
95+
is ensuring that the user-facing API adheres to the Array API Standard.
9496

95-
The complete API of the standard is documented on the
96-
[API specification](https://data-apis.org/array-api/latest/API_specification/index.html)
97-
page.
97+
The complete API of the standard is documented in the
98+
[API specification](https://data-apis.org/array-api/latest/API_specification/index.html).
9899

99100
There, each function, constant, and object is described with details
100101
on parameters, return values, and special cases.
101102

102103
### Testing against Array API
103104

104-
There are two main ways to test your API for compliance: Either using
105-
`array-api-tests` suite or testing your API manually against `array-api-strict`
106-
reference implementation.
105+
There are two main ways to test your API for compliance: either using
106+
`array-api-tests` suite or testing your API manually against the
107+
`array-api-strict` reference implementation.
107108

108109
#### Array API Test suite (Recommended)
109110

110111
{ref}`array-api-tests` is a test suite which verifies that your API
111-
for adhering to the standard. For each function or method it confirms
112-
it's importable, verifies the signature, and generates multiple test
112+
adheres to the standard. For each function or method, it confirms
113+
it's importable, verifies the signature, generates multiple test
113114
cases with [hypothesis](https://hypothesis.readthedocs.io/en/latest/)
114-
package and runs asserts for the outputs.
115+
package, and runs assertions on the outputs.
115116

116117
The setup details are enclosed in the GitHub repository, so here we
117118
cover only the minimal workflow:
@@ -120,44 +121,45 @@ cover only the minimal workflow:
120121
2. Clone `array-api-tests`, and set `ARRAY_API_TESTS_MODULE` environment
121122
variable to your package import name.
122123
3. Inside the `array-api-tests` directory run `pytest` command. There are
123-
multiple useful options delivered by the test suite, a few worth mentioning:
124+
multiple useful options delivered by the test suite. A few worth mentioning:
124125
- `--max-examples=1000` - maximal number of test cases to generate by the
125126
hypothesis. This allows you to balance between execution time of the test
126127
suite and thoroughness of the testing. It's advised to use as many examples
127128
as the time buget can fit. Each test case is a random combination of
128-
possible inputs: the more cases, the higher chance of finding an unsupported
129-
edge case.
130-
- With `--xfails-file` option you can describe which tests are expected to
131-
fail - it's impossible to get the whole API perfectly implemented on a
129+
possible inputs: the more cases, the higher chance of finding an
130+
unsupported edge case.
131+
- With the `--xfails-file` option, you can describe which tests are expected
132+
to fail. It's impossible to get the whole API perfectly implemented on a
132133
first try, so tracking what still fails gives you more control over the
133134
state of your API.
134135
- `-o xfail_strict=<bool>` is often used with the previous one. If a test
135-
expected to fail actually passes (`XPASS`) then you can decide whether
136+
expected to fail actually passes (`XPASS`), then you can decide whether
136137
to ignore that fact or raise it as an error.
137-
- `--skips-file` for skipping tests. At times some failing tests might stall
138-
the execution time of the test suite - in that case the most convenient
138+
- `--skips-file` for skipping tests. At times, some failing tests might stall
139+
the execution time of the test suite. In that case, the most convenient
139140
option is to skip these for the time being.
140141

141142
We strongly advise you to embed this setup in your CI as well. This will allow
142143
you to monitor the coverage live, and make sure new changes don't break existing
143-
API. For a reference here's a [NumPy Array API Tests CI setup](https://github.com/numpy/numpy/blob/581d10f43b539a189a2d37856e5130464de9e5f6/.github/workflows/linux.yml#L296).
144+
APIs. For a reference, here's a [NumPy Array API Tests CI setup](https://github.com/numpy/numpy/blob/581d10f43b539a189a2d37856e5130464de9e5f6/.github/workflows/linux.yml#L296).
144145

145146

146147
#### Array API Strict
147148

148149
A simpler, and more manual, way of testing the Array API coverage is to
149-
run your API calls along with {ref}`array-api-strict` Python implementation.
150+
run your API calls along with the {ref}`array-api-strict` Python implementation.
150151

151152
This way you can ensure the outputs coming from your API match the minimal
152-
reference implementation, but bear in mind you need to write the tests cases
153-
yourself, so you need to also take into account the edge cases as well.
153+
reference implementation. Bear in mind, however, that you need to write
154+
the tests cases yourself, so you need to also take into account the edge
155+
cases as well.
154156

155157

156158
(array-consumers)=
157159

158160
## Array Consumers
159161

160-
For array consumers the main premise is to keep in mind that your **array
162+
For array consumers, the main premise is to keep in mind that your **array
161163
manipulation operations should not lock in for a particular array producing
162164
library**. For instance, if you use NumPy for arrays, then your code could
163165
contain:
@@ -172,7 +174,7 @@ return np.dot(c, b)
172174
```
173175

174176
The first step should be as simple as assigning `np` namespace to a dedicated
175-
namespace variable - the convention in the ecosystem is to name it `xp`. Then
177+
namespace variable. The convention in the ecosystem is to name it `xp`. Then
176178
making sure that each method and function call is something that Array API
177179
supports is vital. `dot` is present in the NumPy's API but the standard doesn't
178180
support it. Let's use `tensordot` instead - both NumPy and the standard define it:
@@ -223,6 +225,6 @@ offers a set of useful utility functions, such as:
223225
- [device()](https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.device)
224226
to get a device the array resides on.
225227

226-
For now the migration from a specific library (e.g. NumPy) to a standard compatible
227-
setup requires a manual intervention for each failing API call but in the future
228-
we plan to provide some automation tools for it.
228+
For now, the migration from a specific library (e.g., NumPy) to a standard
229+
compatible setup requires a manual intervention for each failing API call,
230+
but, in the future, we plan to provide some automation tools for it.

0 commit comments

Comments
 (0)