GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: np.einsum() fails with a 0-dimensional out argument and optimize='optimal' · Issue #31350 · numpy/numpy

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

New issue
Copy link
New issue
Copy link
Closed
#31354
Closed
BUG: np.einsum() fails with a 0-dimensional out argument and optimize='optimal'#31350
#31354
Copy link
Labels
00 - Bug

Description

@krivenko
krivenko
opened on Apr 28, 2026
Issue body actions

Describe the issue:

np.einsum() attempts to evaluate out[:] for a 0-dimensional output array out if optimize='optimal'.

Reproduce the code example:

import numpy as np

a = np.array([1.0, 2.0])
b = np.array([3.0, 4.0])
out = np.zeros(())  # 0-D output array

np.einsum('i,i->', a, b, out=out)  # works
np.einsum('i,i->', a, b, out=out, optimize='optimal')  # fails

Error message:

Traceback (most recent call last):
  File "<python-input-0>", line 8, in <module>
    np.einsum('i,i->', a, b, out=out, optimize='optimal')  # fails
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/numpy/_core/einsumfunc.py", line 1638, in einsum
    new_view = bmm_einsum(einsum_str, *tmp_operands, **kwargs)
  File "/usr/lib/python3.13/site-packages/numpy/_core/einsumfunc.py", line 1228, in bmm_einsum
    out[:] = ab
    ~~~^^^
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed

Python and NumPy Versions:

2.4.4
3.13.12 (main, Apr 24 2026, 21:23:57) [GCC 15.2.1 20260214]

Runtime Environment:

[{'numpy_version': '2.4.4',
'python': '3.13.12 (main, Apr 24 2026, 21:23:57) [GCC 15.2.1 20260214]',
'uname': uname_result(system='Linux', node='dijkstra', release='6.19.13-gentoo', version='#1 SMP PREEMPT_DYNAMIC Fri Apr 24 19:43:59 CEST 2026', machine='x86_64')},
{'simd_extensions': {'baseline': ['X86_V2', 'X86_V3'],
'found': [],
'not_found': ['X86_V4', 'AVX512_ICL', 'AVX512_SPR']}},
{'ignore_floating_point_errors_in_matmul': False},
{'available_backends': ['NETLIB', 'OPENBLAS'],
'current_backend': 'OPENBLAS',
'filepath': '/usr/lib64/libflexiblas.so.3.5',
'internal_api': 'flexiblas',
'loaded_backends': ['OPENBLAS'],
'num_threads': 22,
'prefix': 'libflexiblas',
'user_api': 'blas',
'version': '3.5.0'},
{'available_backends': ['NETLIB', 'OPENBLAS'],
'current_backend': 'OPENBLAS',
'filepath': '/usr/lib64/flexiblas/libflexiblas_fallback_lapack.so',
'internal_api': 'flexiblas',
'loaded_backends': ['OPENBLAS'],
'num_threads': 22,
'prefix': 'libflexiblas',
'user_api': 'blas',
'version': '3.5.0'},
{'architecture': 'HASWELL',
'filepath': '/usr/lib64/libopenblas_haswellp-r0.3.31.so',
'internal_api': 'openblas',
'num_threads': 22,
'prefix': 'libopenblas',
'threading_layer': 'openmp',
'user_api': 'blas',
'version': '0.3.31'},
{'filepath': '/usr/lib/gcc/x86_64-pc-linux-gnu/15/libgomp.so.1.0.0',
'internal_api': 'openmp',
'num_threads': 22,
'prefix': 'libgomp',
'user_api': 'openmp',
'version': None}]

How does this issue affect you or how did you find it:

I discovered this issue while working on a private computational physics project.

Activity

  1. krivenko
    added
    00 - Bug
    on Apr 28, 2026
  2. seberg commented on Apr 28, 2026

    @seberg
    seberg
    on Apr 28, 2026
    Member
    More actions

    Thanks, are you interested in a PR? I would guess all it needs is a test and changing the : to a ... which is more natural anyway.

  3. krivenko commented on Apr 28, 2026

    @krivenko
    krivenko
    on Apr 28, 2026
    ContributorAuthor
    More actions

    Thanks, are you interested in a PR? I would guess all it needs is a test and changing the : to a ... which is more natural anyway.

    I am not a NumPy expert, but if those really are the only necessary changes, then I could try to post a PR indeed.

    Reacted by Sebastian Berg
  4. seberg commented on Apr 28, 2026

    @seberg
    seberg
    on Apr 28, 2026
    Member
    More actions

    @krivenko yes, I suspect that is all. It may also be good to report it to opt_einsum which may have the same issue (or just fix it).

  5. krivenko commented on Apr 28, 2026

    @krivenko
    krivenko
    on Apr 28, 2026
    ContributorAuthor
    More actions

    It may also be good to report it to opt_einsum which may have the same issue (or just fix it).

    @seberg Turns out this issue has already been reported there, dgasmith/opt_einsum#255

    Reacted by Sebastian Berg
  6. krivenko
    added a commit that references this issue on Apr 28, 2026

    retime: Add a workaround for numpy/numpy#31350

    d03832f
  7. seberg
    closed this as completedin #31354on Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.