Skip to content

Avoid copying uninitialized float64 buffers to the device in tests - #3110

Open
antonwolfy wants to merge 1 commit into
masterfrom
fix-uninit-out-arrays-in-tests
Open

antonwolfy wants to merge 1 commit into
masterfrom
fix-uninit-out-arrays-in-tests

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Four tests built an output array with numpy.empty in float64 and copied it to the device with dpnp.array:

  • TestDot::test_out_scalar in test_product.py (numpy.result_type(int, float32_array) is float64)
  • TestMatmul::test_syrk_out_order in test_product.py (generate_random_numpy_array defaults to float64)
  • TestVecdot::test_out_0D in test_product.py
  • TestNanProdSum::test_out in test_nanfunctions.py

On a device without fp64 support the copy casts the buffer to float32. If the uninitialized memory happens to hold a value beyond the float32 range, NumPy raises RuntimeWarning: overflow encountered in cast, so the warning appears at random in test runs on such devices (it was seen for TestDot::test_out_scalar[float32] on a Windows GPU).

The buffers are now created with numpy.zeros. In TestNanProdSum::test_out, where only a wrongly shaped out array is needed, it is allocated on the device with dpnp.empty instead. Only test files are changed.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

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.
@antonwolfy antonwolfy added this to the 0.21.0 release milestone Oct 15, 2026
@antonwolfy antonwolfy self-assigned this Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3110/index.html

@github-actions

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev14=np2py314h8d9cdd5_6 ran successfully.
Passed: 1376
Failed: 0
Skipped: 6

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 82.61%. remained the same — fix-uninit-out-arrays-in-tests into master

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants