BUG: `np.einsum` accepts some subscripts only when optimize=True
See original GitHub issueIt 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:
- Created 5 years ago
- Reactions:2
- Comments:12 (12 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Found by @asi1024: