Skip to content

Fix missing strides validation in dpnp.tensor.usm_ndarray#2927

Draft
vlad-perevezentsev wants to merge 3 commits into
masterfrom
extend_stride_validation
Draft

Fix missing strides validation in dpnp.tensor.usm_ndarray#2927
vlad-perevezentsev wants to merge 3 commits into
masterfrom
extend_stride_validation

Conversation

@vlad-perevezentsev
Copy link
Copy Markdown
Contributor

This PR proposes to fix #2881 issue.

The problem was that usm_ndarray constructor did not validate user-provided strides when allocating new memory.
This made it possible to create arrays with invalid stride patterns producing negative memory displacement or oversized memory footprints.

This PR adds validation for invalid stride configurations when allocating new memory and raises ValueError for unsupported strides.
It also adds a new test_ctor_invalid_strides in test_usm_ndarray_ctor.py to cover these cases

  • 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?

@github-actions
Copy link
Copy Markdown
Contributor

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

@github-actions
Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev0=py313h509198e_44 ran successfully.
Passed: 1352
Failed: 8
Skipped: 16

@vlad-perevezentsev vlad-perevezentsev marked this pull request as draft May 20, 2026 14:54
Comment thread dpnp/tensor/_usmarray.pyx
Comment on lines +384 to +386
"strides={} result in a negative memory displacement "
"and are not allowed when allocating new "
"memory".format(strides))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"strides={} result in a negative memory displacement "
"and are not allowed when allocating new "
"memory".format(strides))
f"strides={strides} result in a negative memory displacement "
"and are not allowed when allocating new "
"memory"

Comment thread dpnp/tensor/_usmarray.pyx
Comment on lines +392 to +394
"strides={} is incompatible with shape={} when "
"allocating new memory because the memory footprint "
"exceeds the number of elements".format(strides, shape))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"strides={} is incompatible with shape={} when "
"allocating new memory because the memory footprint "
"exceeds the number of elements".format(strides, shape))
f"strides={strides} is incompatible with shape={shape} when "
"allocating new memory because the memory footprint "
"exceeds the number of elements"

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.

Missing strides validation for usm_ndarray constructor

2 participants