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_path with ellipsis fails when shapes=True #235

Closed
nova77 opened this issue Jun 13, 2024 · 1 comment
Closed

contract_path with ellipsis fails when shapes=True #235

nova77 opened this issue Jun 13, 2024 · 1 comment

Comments

@nova77
Copy link

nova77 commented Jun 13, 2024

Easy way to reproduce:

input = np.random.rand(1,3,5,2,)
a = np.random.rand(2)
b = np.random.rand(7)

# ValueError: operands could not be broadcast together with shapes (4,) (0,) 
oe.contract_path('...D,D,k->...k', input.shape, a.shape, b.shape, shapes=True)

While if we do not pass the shapes, the function works:

oe.contract_path('...D,D,k->...k', input, a, b)  # all good!

The source of error is in in parser.py where operands (i.e. the shapes) are converted into arrays:

operands = [possibly_convert_to_numpy(x) for x in operands[1:]]

The fix should be simple: just skip the conversion when shapes is True.

@nova77 nova77 changed the title contract_path with ellipses fails when shapes=True contract_path with ellipsis fails when shapes=True Jun 13, 2024
@nova77
Copy link
Author

nova77 commented Jun 13, 2024

The smallest change would be:

    if shapes:
        operand_shapes = [list(s) for s in operands]  # from operand_shapes = operands
    else:
        operand_shapes = [o.shape for o in operands]

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