einops
fdpyutils.einops.einsum.einsum
Same as einops.einsum
but supports index un-grouping notation.
For example, the following operation does not work (yet) in einops.einsum
, but
works with this version: einsum(A, B, '(a b) c, a b c -> (a b) c', a=a, b=b)
.
(More information here) # noqa: B950
Parameters:
-
tensors_and_pattern
(Union[Tensor, str]
, default:()
) –tensors: tensors of any supported library (numpy, tensorflow, pytorch, jax). pattern: string, einsum pattern, with commas separating specifications for each tensor. Pattern should be provided after all tensors.
-
axes_lengths
(int
, default:{}
) –Length of axes that cannot be inferred.
Returns:
-
Tensor
–Tensor of the same type as input, after processing with einsum.
Raises:
-
NotImplementedError
–If the pattern contains unsupported features.
Examples:
>>> from fdpyutils.einops.einsum import einsum
>>> from torch import rand, allclose
>>> a, b, c = 3, 4, 5 # dimensions
>>> A, B = rand(a, b, c), rand(a * b, c) # operands
>>> C = einsum(A, B, 'a b c, (a b) c -> (a b) c', a=a, b=b)
>>> allclose(C, A.reshape(a * b, c) * B)
True