diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e4d855bf70..81badeda4a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ This release is compatible with NumPy 2.5. * Fixed `icx`/`icpx` warning during `conda build` by stripping the GCC-only `-fno-merge-constants` flag injected by conda-forge into `CFLAGS`/`CXXFLAGS` [#2978](https://github.com/IntelPython/dpnp/pull/2978) * Fixed `dpnp.asnumpy` and `dpnp.ndarray.asnumpy` ignoring the `order` keyword, which caused a non-contiguous source array to be returned with a non-contiguous layout even when `order="C"` was requested [#2980](https://github.com/IntelPython/dpnp/pull/2980) * Fixed `dpnp.tensor.acosh` and `dpnp.tensor.acos` returning infinity for complex numbers with large negative real parts [#2928](https://github.com/IntelPython/dpnp/pull/2928) +* Fixed `__array_namespace_info__().devices()` and `.default_device()` to return Python array API compatible device objects [#2979](https://github.com/IntelPython/dpnp/pull/2979) ### Security diff --git a/dpnp/tensor/_array_api.py b/dpnp/tensor/_array_api.py index 8b44e4b52ee..8915123932e 100644 --- a/dpnp/tensor/_array_api.py +++ b/dpnp/tensor/_array_api.py @@ -132,9 +132,9 @@ def default_device(self): """ default_device() - Returns the default SYCL device. + Returns the default device. """ - return dpctl.select_default_device() + return dpt.Device.create_device(dpctl.select_default_device()) def default_dtypes(self, *, device=None): """ @@ -239,9 +239,9 @@ def devices(self): """ devices() - Returns a list of supported devices. + Returns a tuple of supported devices. """ - return dpctl.get_devices() + return tuple(dpt.Device.create_device(d) for d in dpctl.get_devices()) def __array_namespace_info__(): diff --git a/dpnp/tests/tensor/test_tensor_array_api_inspection.py b/dpnp/tests/tensor/test_tensor_array_api_inspection.py index 2eb19894465..a04bccaf5db 100644 --- a/dpnp/tests/tensor/test_tensor_array_api_inspection.py +++ b/dpnp/tests/tensor/test_tensor_array_api_inspection.py @@ -69,7 +69,7 @@ def test_array_api_inspection_default_device(): dev = dpctl.select_default_device() except dpctl.SyclDeviceCreationError: pytest.skip("No default device available") - assert dpt.__array_namespace_info__().default_device() == dev + assert dpt.__array_namespace_info__().default_device().sycl_device == dev def test_array_api_inspection_devices(): @@ -79,7 +79,7 @@ def test_array_api_inspection_devices(): pytest.skip("No default device available") devices1 = dpt.__array_namespace_info__().devices() assert len(devices1) == len(devices2) - assert devices1 == devices2 + assert tuple(dev.sycl_device for dev in devices1) == devices2 def test_array_api_inspection_capabilities(): @@ -142,7 +142,7 @@ def test_array_api_inspection_device_dtypes(): except dpctl.SyclDeviceCreationError: pytest.skip("No default device available") dtypes = _dtypes_no_fp16_fp64.copy() - if dev.has_aspect_fp64: + if dev.sycl_device.has_aspect_fp64: dtypes["float64"] = dpt.float64 dtypes["complex128"] = dpt.complex128 @@ -210,7 +210,7 @@ def test_array_api_inspection_dtype_kind_errors(): def test_array_api_inspection_device_types(): info = dpt.__array_namespace_info__() try: - dev = info.default_device() + dev = info.default_device().sycl_device except dpctl.SyclDeviceCreationError: pytest.skip("No default device available") diff --git a/dpnp/tests/test_array_api_info.py b/dpnp/tests/test_array_api_info.py index 9b1f0cc2010..60f81c0eddd 100644 --- a/dpnp/tests/test_array_api_info.py +++ b/dpnp/tests/test_array_api_info.py @@ -22,7 +22,7 @@ def test_capabilities(): def test_default_device(): - assert info.default_device() == default_device + assert info.default_device().sycl_device == default_device def test_default_dtypes(): @@ -130,4 +130,6 @@ def test_dtypes_invalid_device(): def test_devices(): - assert info.devices() == get_devices() + devices = info.devices() + assert isinstance(devices, tuple) + assert tuple(dev.sycl_device for dev in devices) == get_devices()