Skip to content

BUG: np.einsum() fails with a 0-dimensional out argument and optimize='optimal'#31354

Merged
seberg merged 3 commits into
numpy:mainfrom
krivenko:einsum-0d-out-optimize
Apr 28, 2026
Merged

BUG: np.einsum() fails with a 0-dimensional out argument and optimize='optimal'#31354
seberg merged 3 commits into
numpy:mainfrom
krivenko:einsum-0d-out-optimize

Conversation

@krivenko

Copy link
Copy Markdown
Contributor

PR summary

This PR fixes #31350.

It replaces the expression out[:] found in bmm_einsum() with the more universal out[...], which is also valid for a 0-dimensional out.

TestEinsum.test_einsum_misc() in numpy/_core/tests/test_einsum.py has been extended to cover #31350.

First time committer introduction

I am a researcher who uses NumPy in a multitude of scientific computing projects, mostly simulation codes for computational condensed matter theory. I discovered the issue #31350 while working on one of such (private) projects.

AI Disclosure

No AI has been used in preparation of this PR.

@seberg seberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, small nit, but I think it is also good as is.

Comment thread numpy/_core/tests/test_einsum.py
@seberg seberg added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels Apr 28, 2026
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
@krivenko krivenko force-pushed the einsum-0d-out-optimize branch from d108479 to 5ea7e7c Compare April 28, 2026 14:15
@krivenko

Copy link
Copy Markdown
Contributor Author

@seberg There was a missing : in the change you suggested, so I had to amend that commit...

Comment thread numpy/_core/tests/test_einsum.py Outdated
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
@seberg

seberg commented Apr 28, 2026

Copy link
Copy Markdown
Member

Thanks @krivenko, nice little fix!

@seberg seberg merged commit 425f631 into numpy:main Apr 28, 2026
85 of 86 checks passed
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Apr 28, 2026
@krivenko krivenko deleted the einsum-0d-out-optimize branch April 28, 2026 19:09
charris pushed a commit that referenced this pull request Apr 28, 2026
…='optimal' (#31354)

It replaces the expression out[:] found in bmm_einsum() with the more universal out[...], which is also valid for a 0-dimensional out.
TestEinsum.test_einsum_misc() in numpy/_core/tests/test_einsum.py has been extended.

Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
charris added a commit that referenced this pull request Apr 28, 2026
BUG: np.einsum() fails with a 0-dimensional out argument and optimize='optimal' (#31354)
MaanasArora pushed a commit to MaanasArora/numpy that referenced this pull request May 7, 2026
…='optimal' (numpy#31354)

It replaces the expression out[:] found in bmm_einsum() with the more universal out[...], which is also valid for a 0-dimensional out.
TestEinsum.test_einsum_misc() in numpy/_core/tests/test_einsum.py has been extended.

Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: np.einsum() fails with a 0-dimensional out argument and optimize='optimal'

3 participants