From 0d1fe1bf661fb03be9730f651267e2d6d55ef146 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Thu, 20 Aug 2026 15:45:52 +0530 Subject: [PATCH 1/5] Fix test failure if no device parameter Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- array_api_tests/dtype_helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/array_api_tests/dtype_helpers.py b/array_api_tests/dtype_helpers.py index 9fe2c7b1..d9cbccb7 100644 --- a/array_api_tests/dtype_helpers.py +++ b/array_api_tests/dtype_helpers.py @@ -203,12 +203,13 @@ def is_device_dlpack_compatible(device): """If device is dlpack compatible, return True, else False""" # XXX: there seems to be no better way than try-catch for __dlpack_device__() - x = xp.empty(2, device=device) try: + x = xp.empty(2, device=device) x.__dlpack_device__() except: # case in point: torch.device(type="meta") raises # ValueError: Unknown device type meta for Dlpack + # also covers libraries whose creation functions don't accept device return False else: # no exception => device is compatible (or a cuda device) From e7b55994bc5ff7a1c856316c804642244f7874b6 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Thu, 20 Aug 2026 17:15:31 +0530 Subject: [PATCH 2/5] use another try block Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- array_api_tests/dtype_helpers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/array_api_tests/dtype_helpers.py b/array_api_tests/dtype_helpers.py index d9cbccb7..e4499678 100644 --- a/array_api_tests/dtype_helpers.py +++ b/array_api_tests/dtype_helpers.py @@ -205,6 +205,9 @@ def is_device_dlpack_compatible(device): try: x = xp.empty(2, device=device) + except: + x = xp.empty(2) + try: x.__dlpack_device__() except: # case in point: torch.device(type="meta") raises From 104d104f1f54c5b1170e249325737c81e361c0e1 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Thu, 20 Aug 2026 18:00:35 +0530 Subject: [PATCH 3/5] better comment Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- array_api_tests/dtype_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/array_api_tests/dtype_helpers.py b/array_api_tests/dtype_helpers.py index e4499678..bffefa8b 100644 --- a/array_api_tests/dtype_helpers.py +++ b/array_api_tests/dtype_helpers.py @@ -206,13 +206,13 @@ def is_device_dlpack_compatible(device): try: x = xp.empty(2, device=device) except: + # also covers libraries that does not support device parameter x = xp.empty(2) try: x.__dlpack_device__() except: # case in point: torch.device(type="meta") raises # ValueError: Unknown device type meta for Dlpack - # also covers libraries whose creation functions don't accept device return False else: # no exception => device is compatible (or a cuda device) From 86603d86eb489229fd4d14850525ce893497770c Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+prady0t@users.noreply.github.com> Date: Wed, 26 Aug 2026 00:00:22 +0530 Subject: [PATCH 4/5] Update array_api_tests/dtype_helpers.py Co-authored-by: Tim Head --- array_api_tests/dtype_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/array_api_tests/dtype_helpers.py b/array_api_tests/dtype_helpers.py index bffefa8b..3a158e67 100644 --- a/array_api_tests/dtype_helpers.py +++ b/array_api_tests/dtype_helpers.py @@ -206,7 +206,7 @@ def is_device_dlpack_compatible(device): try: x = xp.empty(2, device=device) except: - # also covers libraries that does not support device parameter + # also covers libraries that do not support device parameter x = xp.empty(2) try: x.__dlpack_device__() From bc5e8d85133e285524ce484cc2f5f141938e0681 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Wed, 26 Aug 2026 01:06:50 +0530 Subject: [PATCH 5/5] apply suggestions Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- array_api_tests/dtype_helpers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/array_api_tests/dtype_helpers.py b/array_api_tests/dtype_helpers.py index bffefa8b..9d59e715 100644 --- a/array_api_tests/dtype_helpers.py +++ b/array_api_tests/dtype_helpers.py @@ -5,6 +5,7 @@ from functools import lru_cache from typing import Any, DefaultDict, Dict, List, NamedTuple, Sequence, Tuple, Union from warnings import warn +import inspect from . import api_version from . import xp @@ -204,9 +205,13 @@ def is_device_dlpack_compatible(device): # XXX: there seems to be no better way than try-catch for __dlpack_device__() try: + has_device = "device" in inspect.signature(xp.empty).parameters + except (TypeError, ValueError): + has_device = False + if has_device: x = xp.empty(2, device=device) - except: - # also covers libraries that does not support device parameter + else: + # also covers libraries that do not support device parameter x = xp.empty(2) try: x.__dlpack_device__()