From 184d3971ecb89f62d377269b04d6d7850432ffc5 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 30 Jul 2024 12:44:45 -0600 Subject: [PATCH 1/4] Add NumPy 2.0 as a separate run in the tests CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e51c635..fcd4336 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,7 +6,7 @@ jobs: strategy: matrix: python-version: ['3.9', '3.10', '3.11', '3.12'] - numpy-version: ['1.21', '1.26', 'dev'] + numpy-version: ['1.21', '1.26', '2.0', 'dev'] exclude: - python-version: '3.11' numpy-version: '1.21' From 850ef722b54a5b19b09b95b09a85843ec926cd05 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 30 Jul 2024 12:45:04 -0600 Subject: [PATCH 2/4] Re-enable wrapping unconditionally for NumPy NumPy 2.0 and 2.1 both have some incompatibilities with the array API (see #167 and #164). Closes #168. --- array_api_compat/common/_helpers.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/array_api_compat/common/_helpers.py b/array_api_compat/common/_helpers.py index 93a50d8..9975219 100644 --- a/array_api_compat/common/_helpers.py +++ b/array_api_compat/common/_helpers.py @@ -145,7 +145,7 @@ def is_ndonnx_array(x): import ndonnx as ndx - return isinstance(x, ndx.Array) + return isinstance(x, ndx.Array) def is_dask_array(x): """ @@ -340,12 +340,9 @@ def your_function(x, y): elif use_compat is False: namespaces.add(np) else: - # numpy 2.0 has __array_namespace__ and is fully array API + # numpy 2.0+ have __array_namespace__, however, they are not yet fully array API # compatible. - if hasattr(np.empty(0), '__array_namespace__'): - namespaces.add(np.empty(0).__array_namespace__(api_version=api_version)) - else: - namespaces.add(numpy_namespace) + namespaces.add(numpy_namespace) elif is_cupy_array(x): if _use_compat: _check_api_version(api_version) From b1d9d1e515a40e006340074deae653da74291f97 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 2 Aug 2024 12:59:38 -0600 Subject: [PATCH 3/4] Fix tests for NumPy 2.0 --- tests/_helpers.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/_helpers.py b/tests/_helpers.py index e52c205..26cf398 100644 --- a/tests/_helpers.py +++ b/tests/_helpers.py @@ -3,11 +3,8 @@ import pytest -wrapped_libraries = ["cupy", "torch", "dask.array"] -all_libraries = wrapped_libraries + ["numpy", "jax.numpy", "sparse"] -import numpy as np -if np.__version__[0] == '1': - wrapped_libraries.append("numpy") +wrapped_libraries = ["numpy", "cupy", "torch", "dask.array"] +all_libraries = wrapped_libraries + ["jax.numpy", "sparse"] # `sparse` added array API support as of Python 3.10. if sys.version_info >= (3, 10): From 29afe3ad82566832ffed0357499962123cff50d7 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 2 Aug 2024 12:59:49 -0600 Subject: [PATCH 4/4] Fix sparse only being tested in 3.10 logic --- tests/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_helpers.py b/tests/_helpers.py index 26cf398..4e34ec0 100644 --- a/tests/_helpers.py +++ b/tests/_helpers.py @@ -4,7 +4,7 @@ import pytest wrapped_libraries = ["numpy", "cupy", "torch", "dask.array"] -all_libraries = wrapped_libraries + ["jax.numpy", "sparse"] +all_libraries = wrapped_libraries + ["jax.numpy"] # `sparse` added array API support as of Python 3.10. if sys.version_info >= (3, 10):