33This is the test suite for array libraries adopting the [ Python Array API
44standard] ( https://data-apis.org/array-api/latest ) .
55
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!
88
99## Quickstart
1010
@@ -33,11 +33,29 @@ You need to specify the array library to test. It can be specified via the
3333` ARRAY_API_TESTS_MODULE ` environment variable, e.g.
3434
3535``` 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)')"
3743```
3844
3945Alternately, import/define the ` xp ` variable in ` array_api_tests/__init__.py ` .
4046
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+
4159### Run the suite
4260
4361Simply 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.
138156
139157## Running on CI
140158
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 .
144162
145163### Releases
146164
@@ -154,19 +172,6 @@ library to fail.
154172
155173### Configuration
156174
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-
170175#### Data-dependent shapes
171176
172177Use the ` --disable-data-dependent-shapes ` flag to skip testing functions which have
@@ -260,7 +265,7 @@ jobs:
260265> There are several ways to avoid this problem:
261266>
262267> - 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
264269> make it more likely that the failing case will be found, but it will also
265270> make the tests take longer to run.
266271> - Don't use `-o xfail_strict=True`. This will make it so that if an XFAIL
@@ -281,11 +286,44 @@ jobs:
281286The tests make heavy use
282287[Hypothesis](https://hypothesis.readthedocs.io/en/latest/). You can configure
283288how 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
285290values should result in more rigorous runs. For example, `--max-examples
28629110_000` may find bugs where default runs don't but will take much longer to
287292run.
288293
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+
289327
290328## Contributing
291329
@@ -355,26 +393,6 @@ into a release. If you want, you can add release notes, which GitHub can
355393generate for you.
356394
357395
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-
378396---
379397
380398<sup>1</sup>The only exceptions to having just one primary test per function are:
0 commit comments