Skip to content

BUG: Fix matvec/vecmat in-place aliasing (out=input produces zeros) (#31150)#31208

Merged
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
charris:backport-31150
Apr 11, 2026
Merged

BUG: Fix matvec/vecmat in-place aliasing (out=input produces zeros) (#31150)#31208
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
charris:backport-31150

Conversation

@charris
Copy link
Copy Markdown
Member

@charris charris commented Apr 10, 2026

Backport of #31150.

PR summary

Fixes #31144.

np.matvec(A, b, out=b) returns all zeros because matvec and vecmat are missing the ~NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE output flag that matmul already has. Without it the iterator ends up skipping the overlap check when out is the same array as an input so no temporary copy is made and BLAS gemv clobbers the input buffer.

This PR adds the same fix to matvec and vecmat and adds regression testing for both.

First time committer introduction

Hi, I'm Ijtihed Kilani (ijtihed.com); I'm an early-career software engineer based in Helsinki, Finland. I work mainly on physics-informed simulations for robotics and autonomy, currently at Supercell working on new games. I've used NumPy heavily for linear algebra in simulation code/studies.

AI Disclosure

This fix was made with help from Claude in Cursor. I used it to look over any assumptions I might have missed and draft the basic code changes which I then looked over, then rewrote and verified. All changes were reviewed and verified by me before submission.

Made with Cursor

…umpy#31150)

`np.matvec(A, b, out=b)` returns all zeros because matvec and vecmat are missing the ~NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE output flag that matmul already has. Without it the iterator ends up skipping the overlap check when out is the same array as an input so no temporary copy is made and BLAS gemv clobbers the input buffer.

This PR adds the same fix to matvec and vecmat and adds regression testing for both.
@charris charris added this to the 2.4.5 release milestone Apr 10, 2026
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Apr 10, 2026
@charris charris merged commit 367faef into numpy:maintenance/2.4.x Apr 11, 2026
73 of 74 checks passed
@charris charris deleted the backport-31150 branch April 11, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants