You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spec/draft/migration_guide.md
+27-27Lines changed: 27 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ User group: Array Producers
72
72
compliance of your library with the Array API Standard. It includes tests
73
73
for array producers, covering a wide range of functionalities and use cases.
74
74
By running these tests, you can ensure that your library adheres to the
75
-
standard and can be used with compatible array consumers libraries.
75
+
standard and can be used with compatible array consumer libraries.
76
76
77
77
78
78
(array-api-extra)=
@@ -115,18 +115,18 @@ There are two main ways to test your API for compliance: either using
115
115
{ref}`array-api-tests` is a test suite which verifies that your API
116
116
adheres to the standard. For each function or method, it confirms
117
117
it's importable, verifies the signature, generates multiple test
118
-
cases with [hypothesis](https://hypothesis.readthedocs.io/en/latest/)
118
+
cases with the [hypothesis](https://hypothesis.readthedocs.io/en/latest/)
119
119
package, and runs assertions on the outputs.
120
120
121
121
The setup details are enclosed in the GitHub repository, so here we
122
122
cover only the minimal workflow:
123
123
124
-
1. Install your package, for example in editable mode.
125
-
2. Clone `array-api-tests`, and set `ARRAY_API_TESTS_MODULE` environment
124
+
1. Install your package (e.g., in editable mode).
125
+
2. Clone `array-api-tests`, and set the `ARRAY_API_TESTS_MODULE` environment
126
126
variable to your package import name.
127
-
3. Inside the `array-api-tests` directory run `pytest` command. There are
127
+
3. Inside the `array-api-tests` directory run the command for running pytest: `pytest`. There are
128
128
multiple useful options delivered by the test suite. A few worth mentioning:
129
-
-`--max-examples=1000` - maximal number of test cases to generate by the
129
+
-`--max-examples=1000` - maximal number of test cases to generate when using
130
130
hypothesis. This allows you to balance between execution time of the test
131
131
suite and thoroughness of the testing. It's advised to use as many examples
132
132
as the time buget can fit. Each test case is a random combination of
@@ -136,27 +136,27 @@ cover only the minimal workflow:
136
136
to fail. It's impossible to get the whole API perfectly implemented on a
137
137
first try, so tracking what still fails gives you more control over the
138
138
state of your API.
139
-
-`-o xfail_strict=<bool>` is often used with the previous one. If a test
139
+
-`-o xfail_strict=<bool>` is often used with the previous option. If a test
140
140
expected to fail actually passes (`XPASS`), then you can decide whether
141
141
to ignore that fact or raise it as an error.
142
142
-`--skips-file` for skipping tests. At times, some failing tests might stall
143
143
the execution time of the test suite. In that case, the most convenient
144
144
option is to skip these for the time being.
145
145
146
146
We strongly advise you to embed this setup in your CI as well. This will allow
147
-
you to monitor the coverage live, and make sure new changes don't break existing
148
-
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).
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).
149
149
150
150
151
151
#### Array API Strict
152
152
153
-
A simpler, and more manual, way of testing the Array API coverage is to
153
+
A simpler, and more manual, way of testing Array API coverage is to
154
154
run your API calls along with the {ref}`array-api-strict` Python implementation.
155
155
156
-
This way you can ensure the outputs coming from your API match the minimal
156
+
This way, you can ensure that the outputs coming from your API match the minimal
157
157
reference implementation. Bear in mind, however, that you need to write
158
-
the tests cases yourself, so you need to also take into account the edge
159
-
cases as well.
158
+
the tests cases yourself, so you need to also take into account any applicable edge
159
+
cases.
160
160
161
161
162
162
(array-consumers)=
@@ -177,12 +177,12 @@ c = np.mean(a, axis=0)
177
177
return np.dot(c, b)
178
178
```
179
179
180
-
The first step should be as simple as assigning `np` namespace to a dedicated
181
-
namespace variable. The convention in the ecosystem is to name it `xp`. Then
182
-
making sure that each method and function call is something that Array API
183
-
supports is vital.`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 - both NumPy and the
180
+
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
186
standard define it:
187
187
188
188
```python
@@ -196,8 +196,8 @@ c = xp.mean(a, axis=0)
196
196
return xp.tensordot(c, b, axes=1)
197
197
```
198
198
199
-
Then replacing one backend with another one should rely on providing a different
200
-
namespace, such as:`xp = torch`, e.g. via environment variable. This can be useful
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
201
if you're writing a script or in your custom software. The other alternatives are:
202
202
203
203
- If you are building a library where the backend is determined by input arrays,
@@ -211,26 +211,26 @@ if you're writing a script or in your custom software. The other alternatives ar
211
211
return xp.arange(scalar1, scalar2) @ array1
212
212
```
213
213
- For a function that accepts scalars and returns arrays, use namespace `xp` as
214
-
a parameter in the signature. Then enforcing objects to be of type by the
215
-
provided backend can be achieved with `arg1 = xp.asarray(arg1)` for each input:
214
+
a parameter in the signature. Enforcing objects to have the same type as the
215
+
provided backend can then be achieved with `arg1 = xp.asarray(arg1)` for each input:
216
216
```python
217
217
deffunc(s1, s2, xp):
218
218
return xp.arange(s1, s2)
219
219
```
220
220
221
221
If you're relying on NumPy, CuPy, PyTorch, Dask, or JAX then
222
222
{ref}`array-api-compat` can come in handy for the transition. The compat layer
223
-
allows you to still rely on your selection of array producing library, while
223
+
allows you to still rely on your preferred array producing library, while
224
224
making sure you're already using standard compatible API. Additionally, it
225
225
offers a set of useful utility functions, such as:
0 commit comments