From 0510351c0e56febcbb1c69df155df03f1e1275f2 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Tue, 19 May 2026 19:37:54 +0530 Subject: [PATCH 1/3] Adding dlpack conversion support Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- src/array_api_extra/_lib/_testing.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/array_api_extra/_lib/_testing.py b/src/array_api_extra/_lib/_testing.py index c5b1a307..5ec3bf04 100644 --- a/src/array_api_extra/_lib/_testing.py +++ b/src/array_api_extra/_lib/_testing.py @@ -136,6 +136,13 @@ def as_numpy_array(array: Array, *, xp: ModuleType) -> np.typing.NDArray[Any]: cpu = cast(Device, jax.devices("cpu")[0]) array = to_device(array, cpu) + # Try DLPack (works for JAX and other backends) + if hasattr(array, "__dlpack__"): + try: + return np.from_dlpack(array) + except (TypeError, BufferError): + pass + return np.asarray(array) From 890a6e6ed581db89b88ca8b3f29573a09b2cb5c7 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Tue, 19 May 2026 21:11:22 +0530 Subject: [PATCH 2/3] precommit error fix Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- src/array_api_extra/_lib/_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_extra/_lib/_testing.py b/src/array_api_extra/_lib/_testing.py index 5ec3bf04..d7735e8d 100644 --- a/src/array_api_extra/_lib/_testing.py +++ b/src/array_api_extra/_lib/_testing.py @@ -139,7 +139,7 @@ def as_numpy_array(array: Array, *, xp: ModuleType) -> np.typing.NDArray[Any]: # Try DLPack (works for JAX and other backends) if hasattr(array, "__dlpack__"): try: - return np.from_dlpack(array) + return np.from_dlpack(array) # ignore[reportArgumentType] except (TypeError, BufferError): pass From 32982110de9ab03b940efc5bdf4f8736e1d3110b Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Tue, 19 May 2026 22:40:16 +0530 Subject: [PATCH 3/3] precommit error fix Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- src/array_api_extra/_lib/_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_extra/_lib/_testing.py b/src/array_api_extra/_lib/_testing.py index d7735e8d..60fd8fc8 100644 --- a/src/array_api_extra/_lib/_testing.py +++ b/src/array_api_extra/_lib/_testing.py @@ -139,7 +139,7 @@ def as_numpy_array(array: Array, *, xp: ModuleType) -> np.typing.NDArray[Any]: # Try DLPack (works for JAX and other backends) if hasattr(array, "__dlpack__"): try: - return np.from_dlpack(array) # ignore[reportArgumentType] + return np.from_dlpack(array) # pyright: ignore[reportArgumentType] except (TypeError, BufferError): pass