Expand description
Python bindings for the basic tensor algebra module.
Wraps ocas_atom::tensor — an independent Tensor type with index
slots, variance, and slot symmetry, plus explicit contraction and a
symmetrisation sign. Each Tensor owns a private leaked
arena pair (mirroring Expression).
from ocas import Tensor, contract_tensors, tensor_symmetrise_sign
# T^i_j · U^j_k = (TU)^i_k (partial contraction over j)
t = Tensor("T", [("i", "upper"), ("j", "lower")])
u = Tensor("U", [("j", "upper"), ("k", "lower")])
kind, payload = contract_tensors(t, u)
assert kind == "product"
# Antisymmetric ε_ab has a sign under slot swap.
eps = Tensor("eps", [("a", "lower"), ("b", "lower")], symmetry="antisymmetric")
assert tensor_symmetrise_sign(eps) in (1, -1)Structs§
- PyTensor
- A tensor: a named object with a list of index slots and an optional slot symmetry. Each tensor owns its own private arena; contraction rebuilds the operands into a fresh arena so lifetimes stay decoupled.
Functions§
- canonicalize_
tensors - Canonicalise a tensor expression using the graph-isomorphism engine.
- contract_
tensors - Contract two tensors by summing over shared dummy indices (equal label, opposite variance).
- refresh_
dummies - Refresh (rename) dummy indices in a tensor expression.
- tensor_
symmetrise_ sign - Return the symmetrisation sign of a tensor (+1 or -1).
- young_
project - Apply a Young projector to a tensor expression.