Skip to content

Commit e382094

Browse files
authored
Apply suggestions from code review
Co-authored-by: Athan <kgryte@gmail.com>
1 parent feea3f9 commit e382094

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

spec/draft/migration_guide.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ User group: Array Producers
7272
compliance of your library with the Array API Standard. It includes tests
7373
for array producers, covering a wide range of functionalities and use cases.
7474
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.
7676

7777

7878
(array-api-extra)=
@@ -115,18 +115,18 @@ There are two main ways to test your API for compliance: either using
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
117117
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/)
119119
package, and runs assertions on the outputs.
120120

121121
The setup details are enclosed in the GitHub repository, so here we
122122
cover only the minimal workflow:
123123

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
126126
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
128128
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
130130
hypothesis. This allows you to balance between execution time of the test
131131
suite and thoroughness of the testing. It's advised to use as many examples
132132
as the time buget can fit. Each test case is a random combination of
@@ -136,27 +136,27 @@ cover only the minimal workflow:
136136
to fail. It's impossible to get the whole API perfectly implemented on a
137137
first try, so tracking what still fails gives you more control over the
138138
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
140140
expected to fail actually passes (`XPASS`), then you can decide whether
141141
to ignore that fact or raise it as an error.
142142
- `--skips-file` for skipping tests. At times, some failing tests might stall
143143
the execution time of the test suite. In that case, the most convenient
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 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).
149149

150150

151151
#### Array API Strict
152152

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
154154
run your API calls along with the {ref}`array-api-strict` Python implementation.
155155

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
157157
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.
160160

161161

162162
(array-consumers)=
@@ -177,12 +177,12 @@ c = np.mean(a, axis=0)
177177
return np.dot(c, b)
178178
```
179179

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
186186
standard define it:
187187

188188
```python
@@ -196,8 +196,8 @@ c = xp.mean(a, axis=0)
196196
return xp.tensordot(c, b, axes=1)
197197
```
198198

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
201201
if you're writing a script or in your custom software. The other alternatives are:
202202

203203
- 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
211211
return xp.arange(scalar1, scalar2) @ array1
212212
```
213213
- 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:
216216
```python
217217
def func(s1, s2, xp):
218218
return xp.arange(s1, s2)
219219
```
220220

221221
If you're relying on NumPy, CuPy, PyTorch, Dask, or JAX then
222222
{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
224224
making sure you're already using standard compatible API. Additionally, it
225225
offers a set of useful utility functions, such as:
226226

227227
- [array_namespace()](https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.array_namespace)
228228
for fetching the namespace based on input arrays.
229229
- [is_array_api_obj()](https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.is_array_api_obj)
230-
for the introspection whether a given object is Array API compatible.
230+
for inspecting whether a given object is Array API compatible.
231231
- [device()](https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.device)
232-
to get a device the array resides on.
232+
for retrieving the device on which an array resides.
233233

234234
For now, the migration from a specific library (e.g., NumPy) to a standard
235235
compatible setup requires a manual intervention for each failing API call,
236-
but, in the future, we plan to provide some automation tools for it.
236+
but, in the future, we're hoping to provide tools for automating the migration process.

0 commit comments

Comments
 (0)