Skip to main content

Module tensor

Module tensor 

Source
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.