Skip to content

Commit 38d415b

Browse files
committed
Migration guide post-merge review
1 parent 94bb5ba commit 38d415b

File tree

1 file changed

+60
-58
lines changed

1 file changed

+60
-58
lines changed

spec/draft/migration_guide.md

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,115 +2,115 @@
22

33
# Migration Guide
44

5-
This page is meant to help migrate your codebase to an Array API compliant
6-
implementation. The guide is divided into two parts and, depending on your
7-
exact use-case, you should look thoroughly into at least one of them.
5+
This page is meant to help migrate your codebase to an array API standard
6+
compliant implementation. The guide is divided into three parts.
7+
8+
The first part gives an overview of the {ref}`ecosystem` libraries, that
9+
are helpful in different contexts when working with the array API standard.
810

911
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
12+
mimics, for example, NumPy's or PyTorch's functionality, then you can find in
1113
the first part additional instructions and guidance on how to ensure
1214
downstream users can easily pick your solution as an array provider for
1315
their system/algorithm.
1416

15-
The second part delves into details for Array API compatibility for
17+
The second part delves into details for array API standard compatibility for
1618
{ref}`array-consumers`. This pertains to any software that performs
1719
multidimensional array manipulation in Python, such as may be found in
1820
scikit-learn, SciPy, or statsmodels. If your software relies on a certain
1921
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.
22+
part to learn how to make it library agnostic and, as a result, interchange
23+
array namespaces with significantly less friction.
24+
25+
26+
(ecosystem)=
2227

2328
## Ecosystem
2429

25-
Apart from the documented standard, the Array API ecosystem also provides
30+
Apart from the documented standard, the array API ecosystem also provides
2631
a set of tools and packages to help you with the migration process:
2732

2833

2934
(array-api-compat)=
3035

31-
### Array API Compat
36+
### array-api-compat
3237

3338
GitHub: [array-api-compat](https://github.com/data-apis/array-api-compat)
3439

3540
User group: Array Consumers
3641

37-
Although NumPy, Dask, CuPy, and PyTorch support the Array API Standard, there
42+
Although NumPy, Dask, CuPy, and PyTorch support the array API standard, there
3843
are still some corner cases where their behavior diverges from the standard.
39-
`array-api-compat` provides a compatibility layer to cover these cases.
40-
This is also accompanied by a few utility functions for easier introspection
41-
into array objects. As an array consumer, you can still rely on the original
42-
API while having access to the standard compatible one.
44+
`array-api-compat` provides a compatibility layer to cover an additional subset
45+
of these corner cases. This is also accompanied by a few utility functions fo
46+
easier introspection into array objects. As an array consumer, you can still
47+
rely on the original API while having access to the standard compatible one.
4348

4449

4550
(array-api-strict)=
4651

47-
### Array API Strict
52+
### array-api-strict
4853

4954
GitHub: [array-api-strict](https://github.com/data-apis/array-api-strict)
5055

51-
User group: Array Consumers, Array Producers (for testing)
56+
User group: Array Consumers
5257

5358
`array-api-strict` is a library that provides a strict and minimal
54-
implementation of the Array API Standard. For array producers, it is designed
55-
to be used as a reference implementation for testing and development purposes.
56-
You can compare your API calls with `array-api-strict` counterparts and
57-
ensure that your library is fully compliant with the standard and can
58-
serve as a reliable reference for other developers in the ecosystem.
59-
For consumers, you can use `array-api-strict` during the development as an
60-
array provider to ensure your code uses APIs compliant with the standard.
59+
implementation of the array API standard. As a consumer, you can use
60+
`array-api-strict` for parametrising tests with it as an array namespace
61+
to ensure your code uses APIs compliant with the standard.
6162

6263

6364
(array-api-tests)=
6465

65-
### Array API Test
66+
### array-api-tests
6667

6768
GitHub: [array-api-tests](https://github.com/data-apis/array-api-tests)
6869

6970
User group: Array Producers
7071

7172
`array-api-tests` is a collection of tests that can be used to verify the
72-
compliance of your library with the Array API Standard. It includes tests
73+
compliance of your library with the array API standard. It includes tests
7374
for array producers, covering a wide range of functionalities and use cases.
7475
By running these tests, you can ensure that your library adheres to the
7576
standard and can be used with compatible array consumer libraries.
7677

7778

7879
(array-api-extra)=
7980

80-
### Array API Extra
81+
### array-api-extra
8182

8283
GitHub: [array-api-extra](https://github.com/data-apis/array-api-extra)
8384

8485
User group: Array Consumers
8586

8687
`array-api-extra` is a collection of additional utilities and tools that are
87-
missing from the Array API Standard but can be useful for compliant array
88-
consumers. It includes additional array manipulation and statistical functions.
89-
It is already used by SciPy and scikit-learn.
90-
91-
The sections below mention when and how to use them.
88+
not present in the array API standard but can be useful for compliant array
89+
consumers. It includes additional array manipulation and statistical
90+
functions, support for lazy backends, and useful testing utilities. It is
91+
already used by SciPy and scikit-learn.
9292

9393

9494
(array-producers)=
9595

9696
## Array Producers
9797

9898
For array producers, the central task during the development/migration process
99-
is ensuring that the user-facing API adheres to the Array API Standard.
99+
is ensuring that the user-facing API adheres to the array API standard.
100100

101101
The complete API of the standard is documented in the
102102
[API specification](https://data-apis.org/array-api/latest/API_specification/index.html).
103103

104104
There, each function, constant, and object is described with details
105105
on parameters, return values, and special cases.
106106

107-
### Testing against Array API
107+
### Testing against array API
108108

109109
There are two main ways to test your API for compliance: either using
110110
`array-api-tests` suite or testing your API manually against the
111111
`array-api-strict` reference implementation.
112112

113-
#### Array API Test suite (Recommended)
113+
#### array-api-tests suite (Recommended)
114114

115115
{ref}`array-api-tests` is a test suite which verifies that your API
116116
adheres to the standard. For each function or method, it confirms
@@ -144,13 +144,15 @@ cover only the minimal workflow:
144144
option is to skip these for the time being.
145145

146146
We strongly advise you to embed this setup in your CI as well. This will allow
147-
you to continuously monitor Array API coverage, and make sure new changes don't break existing
148-
APIs. As a reference, see [NumPy's Array API Tests CI setup](https://github.com/numpy/numpy/blob/581d10f43b539a189a2d37856e5130464de9e5f6/.github/workflows/linux.yml#L296).
147+
you to continuously monitor array API standard coverage, and make sure new
148+
changes don't break existing APIs. As a reference, see
149+
[NumPy's array-api-tests CI setup](https://github.com/numpy/numpy/blob/581d10f43b539a189a2d37856e5130464de9e5f6/.github/workflows/linux.yml#L296)
150+
and [a Pixi workspace setup](https://github.com/mdhaber/mparray/blob/0ef47e008fef92c605f73907436d4c6617419161/pixi.toml#L119-L179).
149151

150152

151-
#### Array API Strict
153+
#### array-api-strict
152154

153-
A simpler, and more manual, way of testing Array API coverage is to
155+
A simpler, and more manual, way of testing array API standard coverage is to
154156
run your API calls along with the {ref}`array-api-strict` Python implementation.
155157

156158
This way, you can ensure that the outputs coming from your API match the minimal
@@ -163,10 +165,9 @@ cases.
163165

164166
## Array Consumers
165167

166-
For array consumers, the main premise is to keep in mind that your **array
167-
manipulation operations should not lock in for a particular array producing
168-
library**. For instance, if you use NumPy for arrays, then your code could
169-
contain:
168+
For array consumers, the main premise is that your **array manipulation operations
169+
should not be specific to one particular array producing library**. For instance,
170+
if your code is specific to NumPy, it might contain:
170171

171172
```python
172173
import numpy as np
@@ -178,12 +179,12 @@ return np.dot(c, b)
178179
```
179180

180181
The first step should be as simple as assigning the `np` namespace to a dedicated
181-
namespace variable. The convention used in the ecosystem is to name it `xp`. Then,
182-
it is vital to ensure that each method and function call is something that the Array API
183-
supports. For example, `dot` is present in the NumPy's API, but the standard
184-
doesn't support it. For the sake of simplicity, let's assume both `c` and `b`
185-
are `ndim=2`; therefore, we select `tensordot` instead, as both NumPy and the
186-
standard define it:
182+
namespace variable. The convention used in the ecosystem is to name it `xp`.
183+
Then, it is vital to ensure that each method and function call is something that
184+
the array API standard supports. For example, `dot` is present in the NumPy's
185+
API, but the standard doesn't support it. For the sake of simplicity, let's
186+
assume both `c` and `b` are `ndim=2`; therefore, we select `tensordot` instead,
187+
as both NumPy and the standard define it:
187188

188189
```python
189190
import numpy as np
@@ -196,18 +197,19 @@ c = xp.mean(a, axis=0)
196197
return xp.tensordot(c, b, axes=1)
197198
```
198199

199-
At this point, replacing one backend with another one should only require providing a different
200-
namespace, such as `xp = torch` (e.g., via an environment variable). This can be useful
201-
if you're writing a script or in your custom software. The other alternatives are:
200+
At this point, replacing one backend with another one should only require
201+
providing a different namespace, such as `xp = torch` (e.g., via an environment
202+
variable). This can be useful if you're writing a script or in your custom
203+
software. The other alternatives are:
202204

203-
- If you are building a library where the backend is determined by input arrays,
204-
and your function accepts array arguments, then a recommended way is to ask
205-
your input arrays for a namespace to use: `xp = arr.__array_namespace__()`.
206-
If the given library doesn't have it, then [`array_api_compat.array_namespace()`](https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.array_namespace)
207-
should be used instead:
205+
- If you are building a library where the backend is determined by input
206+
arrays, and your function accepts array arguments, then a recommended way to
207+
fetch the namespace is to use [`array_api_compat.array_namespace()`](https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.array_namespace).
208+
In case you don't want to introduce a new package dependency, you can rely
209+
on a plain `xp = arr.__array_namespace__()`:
208210
```python
209211
def func(array1, scalar1, scalar2):
210-
xp = array1.__array_namespace__() # or array_namespace(array1)
212+
xp = array_namespace(array1) # or array1.__array_namespace__()
211213
return xp.arange(scalar1, scalar2) @ array1
212214
```
213215
- For a function that accepts scalars and returns arrays, use namespace `xp` as
@@ -227,7 +229,7 @@ offers a set of useful utility functions, such as:
227229
- [array_namespace()](https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.array_namespace)
228230
for fetching the namespace based on input arrays.
229231
- [is_array_api_obj()](https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.is_array_api_obj)
230-
for inspecting whether a given object is Array API compatible.
232+
for inspecting whether a given object is array API compatible.
231233
- [device()](https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.device)
232234
for retrieving the device on which an array resides.
233235

0 commit comments

Comments
 (0)