Skip to content
Get started Guides Reference

Extended Einsum

Extended Einsum is a small tensor language and compiler IR. It keeps contractions, intermediate results, layout operations, and nonlinearities visible long enough to optimize the whole program—then lowers it to PyTorch, JAX, or NumPy.

Beyond one einsum

Compose contractions with softmax, exponentials, arithmetic, stacking, slicing, selection, and routing.

Whole-program optimization

Replan contraction paths, fold matching operations, and arrange folded values for their consumers.

Automatic stability

Choose log-space or scaled evaluation without rewriting the expression that defines your model.

Backend independent

Use the included PyTorch, JAX, and NumPy backends or implement the compact backend protocol.

import torch
import extended_einsum.interface as xe
x = xe.array(torch.rand(32, 16) + 0.1)
w = xe.array(torch.rand(16, 8) + 0.1)
hidden = xe.softmax(x, axis=1)
result = xe.einsum("bi,io->bo", hidden, w)
output = result.materialize(stability_mode="scaled_sum")
print(output.backend_array.shape) # torch.Size([32, 8])
TensorExpression
↓ extract_program
Extended Einsum SSA program
↓ folding and contraction-path passes
Optimized program
↓ stability-aware translation
BackendProgram
↓ PyTorch / JAX / NumPy compiler
Native backend result

The frontend records what the tensor program computes. Optimization decides how to structure it. Stability translation chooses how positive values are represented. The backend finally supplies array primitives and optional compilation.