Skip to content

Commit

Permalink
Merge pull request #259 from honno/info-stub-fix
Browse files Browse the repository at this point in the history
Add missing `xp.__array_namespace_info__()` stub
  • Loading branch information
honno authored May 10, 2024
2 parents bc1e37e + 6ebe822 commit 82c3ec4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
45 changes: 15 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This is the test suite for array libraries adopting the [Python Array API
standard](https://data-apis.org/array-api/latest).

Note the suite is still a **work in progress**. Feedback and contributions are
welcome!
Keeping full coverage of the spec is an on-going priority as the Array API evolves.
Feedback and contributions are welcome!

## Quickstart

Expand Down Expand Up @@ -33,11 +33,23 @@ You need to specify the array library to test. It can be specified via the
`ARRAY_API_TESTS_MODULE` environment variable, e.g.

```bash
$ export ARRAY_API_TESTS_MODULE=numpy.array_api
$ export ARRAY_API_TESTS_MODULE=array_api_strict
```

Alternately, import/define the `xp` variable in `array_api_tests/__init__.py`.

### Specifying the API version

You can specify the API version to use when testing via the
`ARRAY_API_TESTS_VERSION` environment variable, e.g.

```bash
$ export ARRAY_API_TESTS_VERSION="2023.12"
```

Currently this defaults to the array module's `__array_api_version__` value, and
if that attribute doesn't exist then we fallback to `"2021.12"`.

### Run the suite

Simply run `pytest` against the `array_api_tests/` folder to run the full suite.
Expand Down Expand Up @@ -154,13 +166,6 @@ library to fail.

### Configuration

#### API version

You can specify the API version to use when testing via the
`ARRAY_API_TESTS_VERSION` environment variable. Currently this defaults to the
array module's `__array_api_version__` value, and if that attribute doesn't
exist then we fallback to `"2021.12"`.

#### Data-dependent shapes

Use the `--disable-data-dependent-shapes` flag to skip testing functions which have
Expand Down Expand Up @@ -349,26 +354,6 @@ into a release. If you want, you can add release notes, which GitHub can
generate for you.


## Future plans

Keeping full coverage of the spec is an on-going priority as the Array API
evolves.

Additionally, we have features and general improvements planned. Work on such
functionality is guided primarily by the concerete needs of developers
implementing and using the Array API—be sure to [let us
know](https://github.com/data-apis/array-api-tests/issues) any limitations you
come across.

* A dependency graph for every test case, which could be used to modify pytest's
collection so that low-dependency tests are run first, and tests with faulty
dependencies would skip/xfail.

* In some tests we've found it difficult to find appropaite assertion parameters
for output values (particularly epsilons for floating-point outputs), so we
need to review these and either implement assertions or properly note the lack
thereof.

---

<sup>1</sup>The only exceptions to having just one primary test per function are:
Expand Down
2 changes: 1 addition & 1 deletion array_api_tests/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

category_to_funcs: Dict[str, List[FunctionType]] = {}
for name, mod in name_to_mod.items():
if name.endswith("_functions"):
if name.endswith("_functions") or name == "info": # info functions file just named info.py
category = name.replace("_functions", "")
objects = [getattr(mod, name) for name in mod.__all__]
assert all(isinstance(o, FunctionType) for o in objects) # sanity check
Expand Down
3 changes: 2 additions & 1 deletion array_api_tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from . import dtype_helpers as dh
from . import pytest_helpers as ph
from . import shape_helpers as sh
from . import api_version
from .typing import Array

from . import _array_module
Expand Down Expand Up @@ -873,7 +874,7 @@ def test_trace(x, kw):
# See https://github.com/data-apis/array-api-tests/issues/160
if x.dtype in dh.uint_dtypes:
assert dh.is_int_dtype(res.dtype) # sanity check
else:
elif api_version < "2023.12": # TODO: update dtype assertion for >2023.12 - see #234
ph.assert_dtype("trace", in_dtype=x.dtype, out_dtype=res.dtype, expected=expected_dtype)

n, m = x.shape[-2:]
Expand Down
7 changes: 3 additions & 4 deletions array_api_tests/test_statistical_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from . import hypothesis_helpers as hh
from . import pytest_helpers as ph
from . import shape_helpers as sh
from . import xps
from . import api_version, xps
from ._array_module import _UndefinedStub
from .typing import DataType

Expand Down Expand Up @@ -148,7 +148,7 @@ def test_prod(x, data):
# See https://github.com/data-apis/array-api-tests/issues/106
if x.dtype in dh.uint_dtypes:
assert dh.is_int_dtype(out.dtype) # sanity check
else:
elif api_version < "2023.12": # TODO: update dtype assertion for >2023.12 - see #234
ph.assert_dtype("prod", in_dtype=x.dtype, out_dtype=out.dtype, expected=expected_dtype)
_axes = sh.normalise_axis(kw.get("axis", None), x.ndim)
ph.assert_keepdimable_shape(
Expand Down Expand Up @@ -207,7 +207,6 @@ def test_std(x, data):


@pytest.mark.unvectorized
@pytest.mark.skip("flaky") # TODO: fix!
@given(
x=hh.arrays(
dtype=xps.numeric_dtypes(),
Expand Down Expand Up @@ -238,7 +237,7 @@ def test_sum(x, data):
# See https://github.com/data-apis/array-api-tests/issues/160
if x.dtype in dh.uint_dtypes:
assert dh.is_int_dtype(out.dtype) # sanity check
else:
elif api_version < "2023.12": # TODO: update dtype assertion for >2023.12 - see #234
ph.assert_dtype("sum", in_dtype=x.dtype, out_dtype=out.dtype, expected=expected_dtype)
_axes = sh.normalise_axis(kw.get("axis", None), x.ndim)
ph.assert_keepdimable_shape(
Expand Down

0 comments on commit 82c3ec4

Please sign in to comment.