|
docc 0.8.3 (0d44999b)
C++ API Reference
|
Directories | |
| passes | |
| replacers | |
| transformations | |
Files | |
| einsum.h | |
| einsum_detection.h | |
| einsum_node.h | |
| einsum_replacer.h | |
Einsum (short for Einstein summation) is a compact notation for describing operations on tensors (multi-dimensional arrays). Instead of writing explicit loops, you label each dimension of every operand with an index and let the notation describe how those indices relate.
A matrix multiplication C = A · B is written as:
Read this as: for every output element C[i,j], multiply the matching elements of A and B and sum the products over the shared index k.
The core rules are:
With this handful of rules a single expression can express matrix multiplication, dot products, outer products, transposition, trace, batched contractions, and more.
Numerical code usually expresses tensor math as explicit, hand-written loop nests:
At the loop level, a compiler only sees scalar loads, a multiply, an add, and stores. The fact that this is a matrix multiplication — and that a highly tuned gemm kernel exists for it — is lost.
The purpose of this module is to raise the level of abstraction: detect the tensor-algebra pattern buried in the loops and replace it with a single EinsumNode. Once the computation is expressed as an einsum, the compiler can: