From 3400dba62cf21b8de76821c378a0853ba31deef2 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Thu, 15 Oct 2026 19:16:53 +0200 Subject: [PATCH] Avoid copying uninitialized float64 buffers to the device in tests Four tests built an output array with `numpy.empty` in float64 and copied it to the device with `dpnp.array`. On a device without fp64 support the copy casts to float32, and if the uninitialized memory holds a value beyond the float32 range, NumPy raises `RuntimeWarning: overflow encountered in cast`. Initialize the buffers with `numpy.zeros`, or allocate on the device with `dpnp.empty` where the numpy array isn't needed. --- dpnp/tests/test_nanfunctions.py | 2 +- dpnp/tests/test_product.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dpnp/tests/test_nanfunctions.py b/dpnp/tests/test_nanfunctions.py index 810ac9b61afa..5563f81045e5 100644 --- a/dpnp/tests/test_nanfunctions.py +++ b/dpnp/tests/test_nanfunctions.py @@ -581,7 +581,7 @@ def test_out(self, func): getattr(dpnp, func)(ia, axis=0, out=iout) # incorrect shape for out - iout = dpnp.array(numpy.empty((2, 3))) + iout = dpnp.empty((2, 3)) with pytest.raises(ValueError): getattr(dpnp, func)(ia, axis=0, out=iout) diff --git a/dpnp/tests/test_product.py b/dpnp/tests/test_product.py index 7e55e967ec68..9670fd73ee68 100644 --- a/dpnp/tests/test_product.py +++ b/dpnp/tests/test_product.py @@ -285,7 +285,7 @@ def test_out_scalar(self, dtype): ib = dpnp.array(b) np_res_dtype = numpy.result_type(type(a), b) - out = numpy.empty(10, dtype=np_res_dtype) + out = numpy.zeros(10, dtype=np_res_dtype) dp_res_dtype = map_dtype_to_device(np_res_dtype, ib.sycl_device) dp_out = dpnp.array(out, dtype=dp_res_dtype) result = dpnp.dot(a, ib, out=dp_out) @@ -1225,7 +1225,7 @@ def test_syrk_strided(self, dt): ) def test_syrk_out_order(self, order, out_order): a = generate_random_numpy_array((5, 4), order=order, low=-5, high=5) - out = numpy.empty((5, 5), dtype=a.dtype, order=out_order) + out = numpy.zeros((5, 5), dtype=a.dtype, order=out_order) ia, iout = dpnp.array(a), dpnp.array(out) expected = numpy.matmul(a, a.T, out=out) @@ -2185,7 +2185,7 @@ def test_out_0D(self, out_shape): a = numpy.arange(3) ia = dpnp.array(a) - out = numpy.empty(out_shape) + out = numpy.zeros(out_shape) iout = dpnp.array(out) result = dpnp.vecdot(ia, ia, out=iout) expected = numpy.vecdot(a, a, out=out)