3
3
This is the test suite for array libraries adopting the [ Python Array API
4
4
standard] ( https://data-apis.org/array-api/latest ) .
5
5
6
- Note the suite is still a ** work in progress ** . Feedback and contributions are
7
- welcome!
6
+ Keeping full coverage of the spec is an on-going priority as the Array API evolves.
7
+ Feedback and contributions are welcome!
8
8
9
9
## Quickstart
10
10
@@ -33,11 +33,29 @@ You need to specify the array library to test. It can be specified via the
33
33
` ARRAY_API_TESTS_MODULE ` environment variable, e.g.
34
34
35
35
``` bash
36
- $ export ARRAY_API_TESTS_MODULE=numpy.array_api
36
+ $ export ARRAY_API_TESTS_MODULE=array_api_strict
37
+ ```
38
+
39
+ To specify a runtime-defined module, define ` xp ` using the ` exec('...') ` syntax:
40
+
41
+ ``` bash
42
+ $ export ARRAY_API_TESTS_MODULE=" exec('import quantity_array, numpy; xp = quantity_array.quantity_namespace(numpy)')"
37
43
```
38
44
39
45
Alternately, import/define the ` xp ` variable in ` array_api_tests/__init__.py ` .
40
46
47
+ ### Specifying the API version
48
+
49
+ You can specify the API version to use when testing via the
50
+ ` ARRAY_API_TESTS_VERSION ` environment variable, e.g.
51
+
52
+ ``` bash
53
+ $ export ARRAY_API_TESTS_VERSION=" 2023.12"
54
+ ```
55
+
56
+ Currently this defaults to the array module's ` __array_api_version__ ` value, and
57
+ if that attribute doesn't exist then we fallback to ` "2021.12" ` .
58
+
41
59
### Run the suite
42
60
43
61
Simply run ` pytest ` against the ` array_api_tests/ ` folder to run the full suite.
@@ -138,9 +156,9 @@ issues](https://github.com/data-apis/array-api-tests/issues/) to us.
138
156
139
157
## Running on CI
140
158
141
- See our existing [ GitHub Actions workflow for
142
- Numpy ] ( https://github.com/data-apis/array-api-tests/blob/master/.github/workflows/numpy.yml )
143
- for an example of using the test suite on CI .
159
+ See our existing [ GitHub Actions workflow for ` array-api-strict ` ] ( https://github.com/data-apis/array-api-tests/blob/master/.github/workflows/test.yml )
160
+ for an example of using the test suite on CI. Note [ ` array-api-strict ` ] ( https://github.com/data-apis/array-api-strict )
161
+ is an implementation of the array API that uses NumPy under the hood .
144
162
145
163
### Releases
146
164
@@ -154,19 +172,6 @@ library to fail.
154
172
155
173
### Configuration
156
174
157
- #### API version
158
-
159
- You can specify the API version to use when testing via the
160
- ` ARRAY_API_TESTS_VERSION ` environment variable. Currently this defaults to the
161
- array module's ` __array_api_version__ ` value, and if that attribute doesn't
162
- exist then we fallback to ` "2021.12" ` .
163
-
164
- #### CI flag
165
-
166
- Use the ` --ci ` flag to run only the primary and special cases tests. You can
167
- ignore the other test cases as they are redundant for the purposes of checking
168
- compliance.
169
-
170
175
#### Data-dependent shapes
171
176
172
177
Use the ` --disable-data-dependent-shapes ` flag to skip testing functions which have
@@ -260,7 +265,7 @@ jobs:
260
265
> There are several ways to avoid this problem:
261
266
>
262
267
> - Increase the maximum number of examples, e.g., by adding ` --max-examples
263
- > 200` to the test command (the default is `100 `, see below). This will
268
+ > 200` to the test command (the default is `20 `, see below). This will
264
269
> make it more likely that the failing case will be found, but it will also
265
270
> make the tests take longer to run.
266
271
> - Don't use `-o xfail_strict=True`. This will make it so that if an XFAIL
@@ -281,11 +286,44 @@ jobs:
281
286
The tests make heavy use
282
287
[Hypothesis](https://hypothesis.readthedocs.io/en/latest/). You can configure
283
288
how many examples are generated using the `--max-examples` flag, which
284
- defaults to `100 `. Lower values can be useful for quick checks, and larger
289
+ defaults to `20 `. Lower values can be useful for quick checks, and larger
285
290
values should result in more rigorous runs. For example, `--max-examples
286
291
10_000` may find bugs where default runs don't but will take much longer to
287
292
run.
288
293
294
+ # ### Skipping Dtypes
295
+
296
+ The test suite will automatically skip testing of inessential dtypes if they
297
+ are not present on the array module namespace, but dtypes can also be skipped
298
+ manually by setting the environment variable `ARRAY_API_TESTS_SKIP_DTYPES` to
299
+ a comma separated list of dtypes to skip. For example
300
+
301
+ ```
302
+ ARRAY_API_TESTS_SKIP_DTYPES=uint16,uint32,uint64 pytest array_api_tests/
303
+ ```
304
+
305
+ Note that skipping certain essential dtypes such as `bool` and the default
306
+ floating-point dtype is not supported.
307
+
308
+ #### Turning xfails into skips
309
+
310
+ Keeping a large number of ``xfails`` can have drastic effects on the run time. This is due
311
+ to the way `hypothesis` works: when it detects a failure, it does a large amount
312
+ of work to simplify the failing example.
313
+ If the run time of the test suite becomes a problem, you can use the
314
+ ``ARRAY_API_TESTS_XFAIL_MARK`` environment variable: setting it to ``skip`` skips the
315
+ entries from the ``xfail.txt`` file instead of xfailing them. Anecdotally, we saw
316
+ speed-ups by a factor of 4-5---which allowed us to use 4-5 larger values of
317
+ ``--max-examples`` within the same time budget.
318
+
319
+ #### Limiting the array sizes
320
+
321
+ The test suite generates random arrays as inputs to functions it tests. "unvectorized"
322
+ tests iterate over elements of arrays, which might be slow. If the run time becomes
323
+ a problem, you can limit the maximum number of elements in generated arrays by
324
+ setting the environment variable ``ARRAY_API_TESTS_MAX_ARRAY_SIZE`` to the
325
+ desired value. By default, it is set to 1024.
326
+
289
327
290
328
## Contributing
291
329
@@ -355,26 +393,6 @@ into a release. If you want, you can add release notes, which GitHub can
355
393
generate for you.
356
394
357
395
358
- # # Future plans
359
-
360
- Keeping full coverage of the spec is an on-going priority as the Array API
361
- evolves.
362
-
363
- Additionally, we have features and general improvements planned. Work on such
364
- functionality is guided primarily by the concerete needs of developers
365
- implementing and using the Array API—be sure to [let us
366
- know](https://github.com/data-apis/array-api-tests/issues) any limitations you
367
- come across.
368
-
369
- * A dependency graph for every test case, which could be used to modify pytest's
370
- collection so that low-dependency tests are run first, and tests with faulty
371
- dependencies would skip/xfail.
372
-
373
- * In some tests we've found it difficult to find appropaite assertion parameters
374
- for output values (particularly epsilons for floating-point outputs), so we
375
- need to review these and either implement assertions or properly note the lack
376
- thereof.
377
-
378
396
---
379
397
380
398
<sup>1</sup>The only exceptions to having just one primary test per function are:
0 commit comments