bdusell / semiring-einsum

Generic PyTorch implementation of einsum that supports different semirings
https://bdusell.github.io/semiring-einsum/
MIT License
45 stars 7 forks source link

Allow repeated and unmatched output indices? #9

Open davidweichiang opened 2 years ago

davidweichiang commented 2 years ago

Although the original einsum doesn't allow it, it would be convenient if:

I can imagine that the second proposal is more controversial than the first one.

bdusell commented 2 years ago

I think the first one is a reasonable extension of the syntax. Are there any other possible interpretations of the i->ii syntax, like being equivalent to input[:, None] * input[None, :]? What would be the result of einsum('ijk->iik', x)?

I think the second one can be worked around easily with an unsqueeze on the return value of einsum. I think most people would consider it an error to use a variable on the RHS that isn't declared on the LHS, but I suppose it's a matter of taste.

davidweichiang commented 2 years ago

Hm, I suppose an argument against i->ii is that it's not the inverse of ii->i (trace).