Skip to content
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

contract_expression inconsistent with contract #218

Open
SebastianSemper opened this issue Jul 11, 2023 · 0 comments
Open

contract_expression inconsistent with contract #218

SebastianSemper opened this issue Jul 11, 2023 · 0 comments

Comments

@SebastianSemper
Copy link

I am using numpy 1.25.1 and opt_einsum 3.3.0.

Python 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:41) [Clang 15.0.7 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import opt_einsum as oe
>>> x = np.random.randn(2,3,4)
>>> y = np.random.randn(2,3)
>>> np.einsum(x, [0,1,Ellipsis], y, [0,1], [0, Ellipsis])
array([[ 0.50400543,  1.60218127, -2.32967585,  2.806769  ],
       [-1.86581498,  1.98371577, -3.15319885, -1.78047722]])
>>> oe.contract(x, [0,1,Ellipsis], y, [0,1], [0, Ellipsis])
array([[ 0.50400543,  1.60218127, -2.32967585,  2.806769  ],
       [-1.86581498,  1.98371577, -3.15319885, -1.78047722]])
>>> oe.contract_expression(x.shape, [0,1,Ellipsis], y.shape, [0,1], [0, Ellipsis])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Caskroom/miniconda/base/envs/finest/lib/python3.11/site-packages/opt_einsum/contract.py", line 882, in contract_expression
    return contract(subscripts, *dummy_arrays, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/finest/lib/python3.11/site-packages/opt_einsum/contract.py", line 497, in contract
    operands, contraction_list = contract_path(*operands,
                                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/finest/lib/python3.11/site-packages/opt_einsum/contract.py", line 210, in contract_path
    input_subscripts, output_subscript, operands = parser.parse_einsum_input(operands)
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/finest/lib/python3.11/site-packages/opt_einsum/parser.py", line 309, in parse_einsum_input
    if operands[num].shape == ():
       ^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: operands could not be broadcast together with shapes (3,) (0,)

I get the above error, which I assume must be some bug, since both oe.contract and np.einsum seem to be working. As a hint, this error does not occur, when using numpy 1.23.5.

Let me know, if you need any more input form me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant