From af4db1ad537d0a8d66e965fb15acee4c30366ec1 Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Thu, 23 Oct 2025 12:42:00 +0200 Subject: [PATCH 1/4] Update _array_api.py --- sklearnex/utils/_array_api.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sklearnex/utils/_array_api.py b/sklearnex/utils/_array_api.py index b2a241c786..e31f30db19 100644 --- a/sklearnex/utils/_array_api.py +++ b/sklearnex/utils/_array_api.py @@ -28,6 +28,7 @@ from onedal.utils._array_api import _get_sycl_namespace, _is_numpy_namespace from ..base import oneDALEstimator +from .._utils import get_config if sklearn_check_version("1.6"): from ..base import Tags @@ -83,11 +84,19 @@ def get_namespace(*arrays): True of the arrays are containers that implement the Array API spec. """ - sycl_type, xp, is_array_api_compliant = _get_sycl_namespace(*arrays) - - if sycl_type: - return xp, is_array_api_compliant - elif sklearn_check_version("1.2"): + # check required because _get_sycl_namespace only verifies that *arrays + # are of the same sycl namespace, not of the same array namespace. + # When array_api_dispatch is enabled, then sklearn's version is required + # for the additional array namespace check. This is now possible with + # dpnp and dpctl as they both support `__array_namespace__`. + if not get_config().get("array_api_dispatch", False): + sycl_type, xp, is_array_api_compliant = _get_sycl_namespace(*arrays) + if sycl_type: + return xp, is_array_api_compliant + + # sklearn contains a specially patched numpy wrapper that should be + # reused which is yielded from sklearn's get_namespace. + if sklearn_check_version("1.2"): return sklearn_get_namespace(*arrays) else: return np, False From daf6e5b027048f60f3b822a347e2bf41f6784c3a Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Thu, 23 Oct 2025 13:40:10 +0200 Subject: [PATCH 2/4] Update _array_api.py --- sklearnex/utils/_array_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/utils/_array_api.py b/sklearnex/utils/_array_api.py index e31f30db19..bcebd9c265 100644 --- a/sklearnex/utils/_array_api.py +++ b/sklearnex/utils/_array_api.py @@ -27,8 +27,8 @@ from daal4py.sklearn._utils import sklearn_check_version from onedal.utils._array_api import _get_sycl_namespace, _is_numpy_namespace -from ..base import oneDALEstimator from .._utils import get_config +from ..base import oneDALEstimator if sklearn_check_version("1.6"): from ..base import Tags From a7bd05974d659c4f8b943fba4e10bd0ee2ec21c2 Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Thu, 23 Oct 2025 13:51:09 +0200 Subject: [PATCH 3/4] Update _array_api.py --- sklearnex/utils/_array_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/utils/_array_api.py b/sklearnex/utils/_array_api.py index bcebd9c265..7d6aaf6e93 100644 --- a/sklearnex/utils/_array_api.py +++ b/sklearnex/utils/_array_api.py @@ -27,7 +27,7 @@ from daal4py.sklearn._utils import sklearn_check_version from onedal.utils._array_api import _get_sycl_namespace, _is_numpy_namespace -from .._utils import get_config +from .._config import get_config from ..base import oneDALEstimator if sklearn_check_version("1.6"): From 3322331b3cc462e1421dd4f075ed1e2cdc3d9895 Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Thu, 23 Oct 2025 13:51:23 +0200 Subject: [PATCH 4/4] Update _array_api.py --- sklearnex/utils/_array_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/utils/_array_api.py b/sklearnex/utils/_array_api.py index 7d6aaf6e93..d74e866e8a 100644 --- a/sklearnex/utils/_array_api.py +++ b/sklearnex/utils/_array_api.py @@ -14,7 +14,7 @@ # limitations under the License. # ============================================================================== -"""Tools to support array_api.""" +"""Tools to support array API.""" import math from collections.abc import Callable