Skip to content

Fix diagonal() strides calculation for empty results#2814

Open
antonwolfy wants to merge 5 commits intomasterfrom
resolve-gh-2761
Open

Fix diagonal() strides calculation for empty results#2814
antonwolfy wants to merge 5 commits intomasterfrom
resolve-gh-2761

Conversation

@antonwolfy
Copy link
Contributor

@antonwolfy antonwolfy commented Mar 11, 2026

Previously dpnp.diagonal() returned incorrect strides when the diagonal was empty (e.g., when offset >= array width). The stride was set to itemsize instead of the correct st_n + st_m.

This PR:

  • fixes stride calculation to consistently use (st_n + st_m)
  • simplifies implementation using unified formula to calculate resulting shape, strides, and offset
  • extends tests coverage including scenarios with empty diagonals, views, and non-contiguous arrays

The PR closes #2761.

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

@antonwolfy antonwolfy added this to the 0.20.0 release milestone Mar 11, 2026
@antonwolfy antonwolfy self-assigned this Mar 11, 2026
@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

Array API standard conformance tests for dpnp=0.20.0dev4=py313h509198e_6 ran successfully.
Passed: 1355
Failed: 2
Skipped: 16

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 81.165% (-0.005%) from 81.17%
when pulling b3d712d on resolve-gh-2761
into 4b64466 on master.

@antonwolfy antonwolfy marked this pull request as ready for review March 11, 2026 16:04
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.

dpnp.diagonal returns incorrect strides for empty result

2 participants