Skip to content

Commit 7ab1879

Browse files
authored
Merge pull request #79 from asmeurer/numpy-2.0
Add support for NumPy 2.0
2 parents 6f1610d + 165779a commit 7ab1879

File tree

4 files changed

+84
-9
lines changed

4 files changed

+84
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Array API Tests (NumPy dev)
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
array-api-tests-numpy-dev:
7+
uses: ./.github/workflows/array-api-tests.yml
8+
with:
9+
package-name: numpy
10+
extra-requires: '--pre --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple'
11+
xfails-file-extra: '-dev'

.github/workflows/array-api-tests.yml

+13-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ on:
66
package-name:
77
required: true
88
type: string
9+
module-name:
10+
required: false
11+
type: string
12+
extra-requires:
13+
required: false
14+
type: string
915
package-version:
1016
required: false
1117
type: string
@@ -49,17 +55,18 @@ jobs:
4955
with:
5056
python-version: ${{ matrix.python-version }}
5157
- name: Install dependencies
52-
# NumPy 1.21 doesn't support Python 3.11. There doesn't seem to be a way
53-
# to put this in the numpy 1.21 config file.
54-
if: "! (matrix.python-version == '3.11' && inputs.package-name == 'numpy' && contains(inputs.package-version, '1.21'))"
58+
# NumPy 1.21 doesn't support Python 3.11. NumPy 2.0 doesn't support
59+
# Python 3.8. There doesn't seem to be a way to put this in the numpy
60+
# 1.21 config file.
61+
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')))"
5562
run: |
5663
python -m pip install --upgrade pip
57-
python -m pip install '${{ inputs.package-name }} ${{ inputs.package-version }}'
64+
python -m pip install '${{ inputs.package-name }} ${{ inputs.package-version }}' ${{ inputs.extra-requires }}
5865
python -m pip install -r ${GITHUB_WORKSPACE}/array-api-tests/requirements.txt
5966
- name: Run the array API testsuite (${{ inputs.package-name }})
60-
if: "! (matrix.python-version == '3.11' && inputs.package-name == 'numpy' && contains(inputs.package-version, '1.21'))"
67+
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')))"
6168
env:
62-
ARRAY_API_TESTS_MODULE: array_api_compat.${{ inputs.package-name }}
69+
ARRAY_API_TESTS_MODULE: array_api_compat.${{ inputs.module-name || inputs.package-name }}
6370
# This enables the NEP 50 type promotion behavior (without it a lot of
6471
# tests fail on bad scalar type promotion behavior)
6572
NPY_PROMOTION_STATE: weak

array_api_compat/common/_helpers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def your_function(x, y):
7171
"""
7272
namespaces = set()
7373
for x in xs:
74-
if hasattr(x, '__array_namespace__'):
75-
namespaces.add(x.__array_namespace__(api_version=api_version))
76-
elif _is_numpy_array(x):
74+
if _is_numpy_array(x):
7775
_check_api_version(api_version)
7876
if _use_compat:
7977
from .. import numpy as numpy_namespace
@@ -97,6 +95,8 @@ def your_function(x, y):
9795
else:
9896
import torch
9997
namespaces.add(torch)
98+
elif hasattr(x, '__array_namespace__'):
99+
namespaces.add(x.__array_namespace__(api_version=api_version))
100100
else:
101101
# TODO: Support Python scalars?
102102
raise TypeError(f"{type(x).__name__} is not a supported array type")

numpy-dev-xfails.txt

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# asarray(copy=False) is not yet implemented
2+
array_api_tests/test_creation_functions.py::test_asarray_arrays
3+
4+
# finfo(float32).eps returns float32 but should return float
5+
array_api_tests/test_data_type_functions.py::test_finfo[float32]
6+
7+
# Array methods and attributes not already on np.ndarray cannot be wrapped
8+
array_api_tests/test_has_names.py::test_has_names[array_method-to_device]
9+
array_api_tests/test_has_names.py::test_has_names[array_attribute-device]
10+
11+
# linalg tests require cleanups
12+
# https://github.com/data-apis/array-api-tests/pull/101
13+
array_api_tests/test_linalg.py::test_solve
14+
15+
# NumPy deviates in some special cases for floordiv
16+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
17+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
18+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
19+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
20+
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
21+
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
22+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
23+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
24+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
25+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
26+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
27+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
28+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
29+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
30+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
31+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
32+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
33+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
34+
35+
# https://github.com/numpy/numpy/issues/21213
36+
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]
37+
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]
38+
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]
39+
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]
40+
array_api_tests/meta/test_hypothesis_helpers.py::test_symmetric_matrices
41+
42+
# The test suite is incorrectly checking sums that have loss of significance
43+
# (https://github.com/data-apis/array-api-tests/issues/168)
44+
array_api_tests/test_statistical_functions.py::test_sum
45+
46+
# fft functions are not yet supported
47+
# (https://github.com/data-apis/array-api-compat/issues/67)
48+
array_api_tests/test_fft.py::test_fft
49+
array_api_tests/test_fft.py::test_ifft
50+
array_api_tests/test_fft.py::test_fftn
51+
array_api_tests/test_fft.py::test_ifftn
52+
array_api_tests/test_fft.py::test_rfft
53+
array_api_tests/test_fft.py::test_irfft
54+
array_api_tests/test_fft.py::test_rfftn
55+
array_api_tests/test_fft.py::test_irfftn
56+
array_api_tests/test_fft.py::test_hfft
57+
array_api_tests/test_fft.py::test_ihfft

0 commit comments

Comments
 (0)