opt_einsum
opt_einsum copied to clipboard
`contract_path` with ellipsis fails when `shapes=True`
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.