How einx notation works
mastereinx provides a universal interface for tensor operations across frameworks like Numpy, PyTorch, Jax, and Tensorflow using a specific string notation. Every operation follows this pattern:
outputs... = einx.{elementary_operation}("{vectorization}", inputs...)
The vectorization string serves three purposes:
Full Operation Signature: Defines the relationship between all input and output dimensions. Inputs and outputs are separated by
->, and tensors are separated by,.- Example:
"[c d] a, b -> a [e] b"accepts shapes(c, d, a)and(b), returning(a, e, b).
- Example:
Elementary Operation Signature: Sub-expressions in brackets
[]define the dimensions that the core operation (e.g.,sum,dot,add) actually operates on. Axes outside brackets are treated as vectorized (loop) axes.- Example: In
"[c d] a, b -> a [e] b", the elementary operation acts on shapes(c, d)and()and returns(e).
- Example: In
Vectorization: Axes not in brackets are handled via vectorization (analogous to nested loops).
- Example:
"[c d] a, b -> a [e] b"is equivalent to:for a in range(...): for b in range(...): z[a, :, b] = elementary_operation(x[:, :, a], y[b])
- Example:
Note: einx uses backend-optimized functions rather than literal Python loops.
outputs... = einx.{elementary_operation}("{vectorization}", inputs...)