question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: `np.einsum` accepts some subscripts only when optimize=True

See original GitHub issue

It seems that the acceptable syntax of np.einsum subscripts are different when optimize option is set or not.

>>> import numpy as np

>>> x = np.ones((2, 2, 2))

>>> np.einsum('...->', x, optimize=True)
8.0

>>> np.einsum('...->', x, optimize=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kenichi/.pyenv/versions/local-3.6.3/lib/python3.6/site-packages/numpy/core/einsumfunc.py", line 948, in einsum
    return c_einsum(*operands, **kwargs)
ValueError: output had too few broadcast dimensions

>>> np.einsum('i...j->ij', x, optimize=True)
array([[ 2.,  2.],
       [ 2.,  2.]])

>>> np.einsum('i...j->ij', x, optimize=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kenichi/.pyenv/versions/local-3.6.3/lib/python3.6/site-packages/numpy/core/einsumfunc.py", line 948, in einsum
    return c_einsum(*operands, **kwargs)
ValueError: output has more dimensions than subscripts given in einstein sum, but no '...' ellipsis provided to broadcast the extra dimensions.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
jaimefriocommented, May 14, 2018

I have started looking into einsum’s parsing, see #11095. If that gets merged I’ll look into making the parsing a standalone function, and adding a Python wrapper so that ‘einsum_path’ can call it and we can get rid of the duplicate parsers.

1reaction
toslunarcommented, May 29, 2018

Found by @asi1024:

>>> numpy.einsum('a- >a', numpy.array([3,4]), optimize=True)
array([3, 4])
>>> numpy.einsum('. ..->...', numpy.array([3,4]), optimize=True)
array([3, 4])
Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy.einsum — NumPy v1.24 Manual
Specifies the subscripts for summation as comma separated list of subscript labels. An implicit (classical Einstein summation) calculation is performed unless ...
Read more >
Einsum optimize fails for basic operation - Stack Overflow
So it's summing on d . Note the error - with optimization, it uses tensordot (transpose plus dot ), rather than the original...
Read more >
Source code for opt_einsum.contract
Source code for opt_einsum.contract. """ Contains the primary optimization and contraction routines. """ from collections import ...
Read more >
Numpy Einsum Gives Error: Dimensions In Operand 0 for ... - ADocLib
The exception is if a subscript is repeated for the same input operand in which case the ... BUG: np.einsum accepts some subscripts...
Read more >
test_einsum.py - import itertools import numpy as np from numpy ...
[0, 0], optimize=do_opt)assert_raises(ValueError, np.einsum, ".i. ... subscripts may only be specified onceassert_raises(ValueError, np.einsum, "ij->jij", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found