einops
4 memberslucid.einopslucid.einops — shape manipulation written in named axes.
Four entry points: rearrange (permute, reshape, split or merge axes),
reduce (the same, carrying a reduction), repeat (the same, carrying a
broadcast expansion) and einsum.
Patterns are strings of axis names, so the intent is stated in the call
rather than reconstructed from a run of anonymous transpose / reshape
steps:
lucid.einops.rearrange(x, "b c h w -> b (h w) c") # (2,3,4,5) → (2,20,3)
The grammar is the reference einops grammar: names, parenthesised groups
one level deep, ... for the axes the pattern does not name, 1 or
() for a unit axis and, in reduce and repeat, a number for an
unnamed axis of that length. A keyword length is also a check: an axis
the input already fixes must have the length given for it, and a keyword
naming no axis of the pattern is refused. A mismatch fails with a message
naming the axis that did not fit, instead of producing a silently wrong
shape that only surfaces layers later.
Reachable only as lucid.einops.*: there is no top-level lucid.einsum
and no Tensor.rearrange method, so each op has exactly one path.
Functions
rearrange→ TensorRearrange axes of tensor according to an einops pattern.
reduce→ TensorReduce tensor along axes implied by an einops pattern.
repeat→ TensorRepeat tensor along new or existing axes via an einops pattern.
einsum→ TensorEvaluate an Einstein-summation expression over the given tensors.