Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: add matvec and vecmat gufuncs #27846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

charris
Copy link
Member

@charris charris commented Nov 25, 2024

Backport of #25675.

This PR adds new matvec and vecmat gufunc to calculate the matrix-vector and vector-matrix product, to add to plain matrix multiplication with matmul and the inner vector product with vecdot.

Fixes #12348

Note that for complex numbers, vecmat is defined as x†A, i.e., the complex conjugate of the vector is taken. This seems to be the standard and is what we used for vecdot too (x†x). However, it is not what matmul does for vector-matrix or indeed vector-vector products. I think this is a bug in matmul, which I'm happy to fix here. But I'll post to the mailing list to get feedback.

Separately, with these functions available, in principle these could be used in __matmul__ and the specializations in np.matmul removed. But that can be a separate PR (if it is wanted at all).

Summary of mailing list discussion

  • Behaviour of np.matmul for vector-matrix should not be adjusted. Some surprise that "matrix multiplcation" deals with vectors at all.
  • Less obvious consensus on what @ should do.
  • Moderate support for having special matvec and vecmat functions.

Internally, they mostly just call the relevant blas, or vecdot
routines.
@charris charris added this to the 2.2.0 release milestone Nov 25, 2024
@charris charris changed the title ENH: define matvec and vecmat gufuncs ENH: add matvec and vecmat gufuncs Nov 25, 2024
@charris charris merged commit 665208e into numpy:maintenance/2.2.x Nov 25, 2024
68 checks passed
@charris charris deleted the backport-25675 branch November 25, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.