Skip to content

Fix array-api-tests job #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/array-api-tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: Array API Tests

on: [push, pull_request]

env:
PYTEST_ARGS: "-v -rxXfE --ci"
PYTEST_ARGS: "-v -rxXfE --ci --hypothesis-disable-deadline"

jobs:
tests:
array-api-tests:
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -37,13 +39,14 @@ jobs:
else
python -m pip install 'numpy>=1.26,<2.0';
fi
python -m pip install ${GITHUB_WORKSPACE}/array-api-strict
python -m pip install -r ${GITHUB_WORKSPACE}/array-api-tests/requirements.txt
- name: Run the array API testsuite
env:
ARRAY_API_TESTS_MODULE: array_api_strict
# This enables the NEP 50 type promotion behavior (without it a lot of
# tests fail in numpy 1.26 on bad scalar type promotion behavior)
NPY_PROMOTION_STATE: weak
run: |
export PYTHONPATH="${GITHUB_WORKSPACE}/array-api-compat"
cd ${GITHUB_WORKSPACE}/array-api-tests
pytest array_api_tests/ --xfails-file ${PYTEST_ARGS}
pytest array_api_tests/ --skips-file ${GITHUB_WORKSPACE}/array-api-strict/array-api-tests-xfails.txt ${PYTEST_ARGS}
25 changes: 25 additions & 0 deletions array-api-tests-xfails.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# copy=False is not yet implemented
# https://github.com/numpy/numpy/pull/25168
array_api_tests/test_creation_functions.py::test_asarray_arrays

# Some fft tests are currently wrong
# (https://github.com/data-apis/array-api-tests/issues/231)
array_api_tests/test_fft.py::test_fft
array_api_tests/test_fft.py::test_ifft
array_api_tests/test_fft.py::test_fftn
array_api_tests/test_fft.py::test_ifftn
array_api_tests/test_fft.py::test_rfft
array_api_tests/test_fft.py::test_irfft
array_api_tests/test_fft.py::test_rfftn
array_api_tests/test_fft.py::test_irfftn
array_api_tests/test_fft.py::test_hfft
array_api_tests/test_fft.py::test_ihfft

# Known special case issue in NumPy. Not worth working around here
# https://github.com/numpy/numpy/issues/21213
array_api_tests/test_special_cases.py::test_iop[__ipow__(x1_i is -infinity and x2_i > 0 and not (x2_i.is_integer() and x2_i % 2 == 1)) -> +infinity]
array_api_tests/test_special_cases.py::test_iop[__ipow__(x1_i is -0 and x2_i > 0 and not (x2_i.is_integer() and x2_i % 2 == 1)) -> +0]

# The test suite is incorrectly checking sums that have loss of significance
# (https://github.com/data-apis/array-api-tests/issues/168)
array_api_tests/test_statistical_functions.py::test_sum
20 changes: 10 additions & 10 deletions array_api_strict/_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
particular, type promotion rules are different (the standard has no
value-based casting). The standard also specifies a more limited subset of
array methods and functionalities than are implemented on ndarray. Since the
goal of the array_api namespace is to be a minimal implementation of the array
API standard, we need to define a separate wrapper class for the array_api
goal of the array_api_strict namespace is to be a minimal implementation of the array
API standard, we need to define a separate wrapper class for the array_api_strict
namespace.

The standard compliant class is only a wrapper class. It is *not* a subclass
Expand Down Expand Up @@ -73,7 +73,7 @@ def _new(cls, x, /):
This is a private method for initializing the array API Array
object.

Functions outside of the array_api submodule should not use this
Functions outside of the array_api_strict module should not use this
method. Use one of the creation functions instead, such as
``asarray``.

Expand All @@ -86,7 +86,7 @@ def _new(cls, x, /):
_dtype = _DType(x.dtype)
if _dtype not in _all_dtypes:
raise TypeError(
f"The array_api namespace does not support the dtype '{x.dtype}'"
f"The array_api_strict namespace does not support the dtype '{x.dtype}'"
)
obj._array = x
obj._dtype = _dtype
Expand All @@ -95,7 +95,7 @@ def _new(cls, x, /):
# Prevent Array() from working
def __new__(cls, *args, **kwargs):
raise TypeError(
"The array_api Array object should not be instantiated directly. Use an array creation function, such as asarray(), instead."
"The array_api_strict Array object should not be instantiated directly. Use an array creation function, such as asarray(), instead."
)

# These functions are not required by the spec, but are implemented for
Expand All @@ -121,7 +121,7 @@ def __repr__(self: Array, /) -> str:
return prefix + mid + suffix

# This function is not required by the spec, but we implement it here for
# convenience so that np.asarray(np.array_api.Array) will work.
# convenience so that np.asarray(array_api_strict.Array) will work.
def __array__(self, dtype: None | np.dtype[Any] = None) -> npt.NDArray[Any]:
"""
Warning: this method is NOT part of the array API spec. Implementers
Expand Down Expand Up @@ -338,7 +338,7 @@ def _validate_index(self, key):
if i is not None:
nonexpanding_key.append(i)
if isinstance(i, np.ndarray):
raise IndexError("Index arrays for np.array_api must be np.array_api arrays")
raise IndexError("Index arrays for array_api_strict must be array_api_strict arrays")
if isinstance(i, Array):
if i.dtype in _boolean_dtypes:
key_has_mask = True
Expand Down Expand Up @@ -471,7 +471,7 @@ def __array_namespace__(
if api_version is not None and not api_version.startswith("2021."):
raise ValueError(f"Unrecognized array API version: {api_version!r}")
import array_api_strict
return array_api
return array_api_strict

def __bool__(self: Array, /) -> bool:
"""
Expand Down Expand Up @@ -571,7 +571,7 @@ def __getitem__(
# docstring of _validate_index
self._validate_index(key)
if isinstance(key, Array):
# Indexing self._array with array_api arrays can be erroneous
# Indexing self._array with array_api_strict arrays can be erroneous
key = key._array
res = self._array.__getitem__(key)
return self._new(res)
Expand Down Expand Up @@ -761,7 +761,7 @@ def __setitem__(
# docstring of _validate_index
self._validate_index(key)
if isinstance(key, Array):
# Indexing self._array with array_api arrays can be erroneous
# Indexing self._array with array_api_strict arrays can be erroneous
key = key._array
self._array.__setitem__(key, asarray(value)._array)

Expand Down
2 changes: 1 addition & 1 deletion array_api_strict/_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, np_dtype):
self._np_dtype = np_dtype

def __repr__(self):
return f"np.array_api.{self._np_dtype.name}"
return f"array_api_strict.{self._np_dtype.name}"

def __eq__(self, other):
# See https://github.com/numpy/numpy/pull/25370/files#r1423259515.
Expand Down
10 changes: 8 additions & 2 deletions array_api_strict/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,16 @@ def slogdet(x: Array, /) -> SlogdetResult:
# To workaround this, the below is the code from np.linalg.solve except
# only calling solve1 in the exactly 1D case.
def _solve(a, b):
from numpy.linalg._linalg import (
try:
from numpy.linalg._linalg import (
_makearray, _assert_stacked_2d, _assert_stacked_square,
_commonType, isComplexType, _raise_linalgerror_singular
)
)
except ImportError:
from numpy.linalg.linalg import (
_makearray, _assert_stacked_2d, _assert_stacked_square,
_commonType, isComplexType, _raise_linalgerror_singular
)
from numpy.linalg import _umath_linalg

a, _ = _makearray(a)
Expand Down