From 2d309019b5e9dd3298961b5f1841710ade32993b Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 17 Jan 2024 14:28:14 -0700 Subject: [PATCH 1/8] Don't bypass numpy compat just because it has __array_namespace__ https://github.com/data-apis/array-api-compat/issues/77#issuecomment-1894095240 --- array_api_compat/common/_helpers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/array_api_compat/common/_helpers.py b/array_api_compat/common/_helpers.py index 5cb029dc..c1b0aef3 100644 --- a/array_api_compat/common/_helpers.py +++ b/array_api_compat/common/_helpers.py @@ -71,9 +71,7 @@ def your_function(x, y): """ namespaces = set() for x in xs: - if hasattr(x, '__array_namespace__'): - namespaces.add(x.__array_namespace__(api_version=api_version)) - elif _is_numpy_array(x): + if _is_numpy_array(x): _check_api_version(api_version) if _use_compat: from .. import numpy as numpy_namespace @@ -97,6 +95,8 @@ def your_function(x, y): else: import torch namespaces.add(torch) + elif hasattr(x, '__array_namespace__'): + namespaces.add(x.__array_namespace__(api_version=api_version)) else: # TODO: Support Python scalars? raise TypeError(f"{type(x).__name__} is not a supported array type") From ae488ccd2fc81060673811976a8e361da53757d2 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 17 Jan 2024 14:39:17 -0700 Subject: [PATCH 2/8] Allow specifying extra-requires in the GitHub Actions config This is a change from #76. --- .github/workflows/array-api-tests.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/array-api-tests.yml b/.github/workflows/array-api-tests.yml index 0a7050f7..446e24e9 100644 --- a/.github/workflows/array-api-tests.yml +++ b/.github/workflows/array-api-tests.yml @@ -6,6 +6,12 @@ on: package-name: required: true type: string + module-name: + required: false + type: string + extra-requires: + required: false + type: string package-version: required: false type: string @@ -54,12 +60,12 @@ jobs: if: "! (matrix.python-version == '3.11' && inputs.package-name == 'numpy' && contains(inputs.package-version, '1.21'))" run: | python -m pip install --upgrade pip - python -m pip install '${{ inputs.package-name }} ${{ inputs.package-version }}' + python -m pip install '${{ inputs.package-name }} ${{ inputs.package-version }}' ${{ inputs.extra-requires }} python -m pip install -r ${GITHUB_WORKSPACE}/array-api-tests/requirements.txt - name: Run the array API testsuite (${{ inputs.package-name }}) if: "! (matrix.python-version == '3.11' && inputs.package-name == 'numpy' && contains(inputs.package-version, '1.21'))" env: - ARRAY_API_TESTS_MODULE: array_api_compat.${{ inputs.package-name }} + ARRAY_API_TESTS_MODULE: array_api_compat.${{ inputs.module-name || inputs.package-name }} # This enables the NEP 50 type promotion behavior (without it a lot of # tests fail on bad scalar type promotion behavior) NPY_PROMOTION_STATE: weak From 14c8506528a579e03a3ed32d5dcf9aeb0d59f1e6 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 17 Jan 2024 14:41:50 -0700 Subject: [PATCH 3/8] Add GitHub Actions workflow for NumPy dev --- .../workflows/array-api-tests-numpy-dev.yml | 11 ++++ numpy-dev-xfails.txt | 56 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .github/workflows/array-api-tests-numpy-dev.yml create mode 100644 numpy-dev-xfails.txt diff --git a/.github/workflows/array-api-tests-numpy-dev.yml b/.github/workflows/array-api-tests-numpy-dev.yml new file mode 100644 index 00000000..eef4269d --- /dev/null +++ b/.github/workflows/array-api-tests-numpy-dev.yml @@ -0,0 +1,11 @@ +name: Array API Tests (NumPy dev) + +on: [push, pull_request] + +jobs: + array-api-tests-numpy-dev: + uses: ./.github/workflows/array-api-tests.yml + with: + package-name: numpy + extra-requires: '--pre --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple' + xfails-file-extra: '-dev' diff --git a/numpy-dev-xfails.txt b/numpy-dev-xfails.txt new file mode 100644 index 00000000..5c8467d1 --- /dev/null +++ b/numpy-dev-xfails.txt @@ -0,0 +1,56 @@ +# asarray(copy=False) is not yet implemented +array_api_tests/test_creation_functions.py::test_asarray_arrays + +# finfo(float32).eps returns float32 but should return float +array_api_tests/test_data_type_functions.py::test_finfo[float32] + +# Array methods and attributes not already on np.ndarray cannot be wrapped +array_api_tests/test_has_names.py::test_has_names[array_method-__array_namespace__] +array_api_tests/test_has_names.py::test_has_names[array_method-to_device] +array_api_tests/test_has_names.py::test_has_names[array_attribute-device] +array_api_tests/test_has_names.py::test_has_names[array_attribute-mT] + +# linalg tests require https://github.com/data-apis/array-api-tests/pull/101 +# cleanups. Also some tests are using .mT +array_api_tests/test_linalg.py::test_eigvalsh +array_api_tests/test_linalg.py::test_solve +array_api_tests/test_linalg.py::test_trace + +# Array methods and attributes not already on np.ndarray cannot be wrapped +array_api_tests/test_signatures.py::test_array_method_signature[__array_namespace__] +array_api_tests/test_signatures.py::test_array_method_signature[to_device] + +# NumPy deviates in some special cases for floordiv +array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity] +array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity] +array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity] +array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity] +array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0] +array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0] +array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity] +array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity] +array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity] +array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity] +array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0] +array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0] +array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity] +array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity] +array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity] +array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity] +array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0] +array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0] + +# testsuite issue with test_square +# https://github.com/data-apis/array-api-tests/issues/190 +array_api_tests/test_operators_and_elementwise_functions.py::test_square + +# https://github.com/numpy/numpy/issues/21213 +array_api_tests/test_special_cases.py::test_binary[__pow__(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_binary[__pow__(x1_i is -0 and x2_i > 0 and not (x2_i.is_integer() and x2_i % 2 == 1)) -> +0] +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] +array_api_tests/meta/test_hypothesis_helpers.py::test_symmetric_matrices + +# 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 From 6021c554b9c09a19f575b61aaaf0ae0bed8ee1ea Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 17 Jan 2024 19:44:51 -0700 Subject: [PATCH 4/8] Add fft xfails to the numpy 2.0 xfails file --- numpy-dev-xfails.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/numpy-dev-xfails.txt b/numpy-dev-xfails.txt index 5c8467d1..1de2f755 100644 --- a/numpy-dev-xfails.txt +++ b/numpy-dev-xfails.txt @@ -54,3 +54,16 @@ array_api_tests/meta/test_hypothesis_helpers.py::test_symmetric_matrices # 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 + +# fft functions are not yet supported +# (https://github.com/data-apis/array-api-compat/issues/67) +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 From 8cd95361a1e572d1999292167b4db502dee2c882 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 18 Jan 2024 02:35:10 -0700 Subject: [PATCH 5/8] Remove some XPASS tests from the numpy 2.0 xfails file --- numpy-dev-xfails.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/numpy-dev-xfails.txt b/numpy-dev-xfails.txt index 1de2f755..f8de2c30 100644 --- a/numpy-dev-xfails.txt +++ b/numpy-dev-xfails.txt @@ -5,16 +5,12 @@ array_api_tests/test_creation_functions.py::test_asarray_arrays array_api_tests/test_data_type_functions.py::test_finfo[float32] # Array methods and attributes not already on np.ndarray cannot be wrapped -array_api_tests/test_has_names.py::test_has_names[array_method-__array_namespace__] array_api_tests/test_has_names.py::test_has_names[array_method-to_device] array_api_tests/test_has_names.py::test_has_names[array_attribute-device] -array_api_tests/test_has_names.py::test_has_names[array_attribute-mT] # linalg tests require https://github.com/data-apis/array-api-tests/pull/101 # cleanups. Also some tests are using .mT -array_api_tests/test_linalg.py::test_eigvalsh array_api_tests/test_linalg.py::test_solve -array_api_tests/test_linalg.py::test_trace # Array methods and attributes not already on np.ndarray cannot be wrapped array_api_tests/test_signatures.py::test_array_method_signature[__array_namespace__] @@ -40,10 +36,6 @@ array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0] array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0] -# testsuite issue with test_square -# https://github.com/data-apis/array-api-tests/issues/190 -array_api_tests/test_operators_and_elementwise_functions.py::test_square - # https://github.com/numpy/numpy/issues/21213 array_api_tests/test_special_cases.py::test_binary[__pow__(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_binary[__pow__(x1_i is -0 and x2_i > 0 and not (x2_i.is_integer() and x2_i % 2 == 1)) -> +0] From f1d1dd44196e135c52bca232cf55ea73a23d0c97 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 18 Jan 2024 14:53:44 -0700 Subject: [PATCH 6/8] Remove some numpy dev xfails --- numpy-dev-xfails.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/numpy-dev-xfails.txt b/numpy-dev-xfails.txt index f8de2c30..5e270a95 100644 --- a/numpy-dev-xfails.txt +++ b/numpy-dev-xfails.txt @@ -8,14 +8,10 @@ array_api_tests/test_data_type_functions.py::test_finfo[float32] array_api_tests/test_has_names.py::test_has_names[array_method-to_device] array_api_tests/test_has_names.py::test_has_names[array_attribute-device] -# linalg tests require https://github.com/data-apis/array-api-tests/pull/101 -# cleanups. Also some tests are using .mT +# linalg tests require cleanups +# https://github.com/data-apis/array-api-tests/pull/101 array_api_tests/test_linalg.py::test_solve -# Array methods and attributes not already on np.ndarray cannot be wrapped -array_api_tests/test_signatures.py::test_array_method_signature[__array_namespace__] -array_api_tests/test_signatures.py::test_array_method_signature[to_device] - # NumPy deviates in some special cases for floordiv array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity] array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity] From b9d8a9bc0571004dce6973592f609da13909c9ea Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 18 Jan 2024 14:58:11 -0700 Subject: [PATCH 7/8] Don't run numpy dev tests in Python 3.8 --- .github/workflows/array-api-tests.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/array-api-tests.yml b/.github/workflows/array-api-tests.yml index 04e0812c..d09b71bc 100644 --- a/.github/workflows/array-api-tests.yml +++ b/.github/workflows/array-api-tests.yml @@ -55,9 +55,10 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install dependencies - # NumPy 1.21 doesn't support Python 3.11. There doesn't seem to be a way - # to put this in the numpy 1.21 config file. - if: "! (matrix.python-version == '3.11' && inputs.package-name == 'numpy' && contains(inputs.package-version, '1.21'))" + # NumPy 1.21 doesn't support Python 3.11. NumPy 2.0 doesn't support + # Python 3.8. There doesn't seem to be a way to put this in the numpy + # 1.21 config file. + if: "! ((matrix.python-version == '3.11' && inputs.package-name == 'numpy' && contains(inputs.package-version, '1.21')) || (matrix.python-version == '3.8' && inputs.package-name == 'numpy' && contains(inputs.xfails-file-extra, 'dev')))" run: | python -m pip install --upgrade pip python -m pip install '${{ inputs.package-name }} ${{ inputs.package-version }}' ${{ inputs.extra-requires }} From 165779a88b9bed06a29ce2272517fd61caa392db Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 18 Jan 2024 14:59:34 -0700 Subject: [PATCH 8/8] Fix missing skip condition --- .github/workflows/array-api-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/array-api-tests.yml b/.github/workflows/array-api-tests.yml index d09b71bc..c7e2af5c 100644 --- a/.github/workflows/array-api-tests.yml +++ b/.github/workflows/array-api-tests.yml @@ -64,7 +64,7 @@ jobs: python -m pip install '${{ inputs.package-name }} ${{ inputs.package-version }}' ${{ inputs.extra-requires }} python -m pip install -r ${GITHUB_WORKSPACE}/array-api-tests/requirements.txt - name: Run the array API testsuite (${{ inputs.package-name }}) - if: "! (matrix.python-version == '3.11' && inputs.package-name == 'numpy' && contains(inputs.package-version, '1.21'))" + if: "! ((matrix.python-version == '3.11' && inputs.package-name == 'numpy' && contains(inputs.package-version, '1.21')) || (matrix.python-version == '3.8' && inputs.package-name == 'numpy' && contains(inputs.xfails-file-extra, 'dev')))" env: ARRAY_API_TESTS_MODULE: array_api_compat.${{ inputs.module-name || inputs.package-name }} # This enables the NEP 50 type promotion behavior (without it a lot of