Expand description
Multi-tensor contraction with optimal contraction order.
This module provides functions to contract multiple tensors efficiently using hyperedge-aware einsum optimization via the tensorbackend (tenferro-backed implementation).
This module works with concrete types (DynIndex, TensorDynLen) only.
§Main Functions
contract_multi: Contracts tensors, handling disconnected components via outer productcontract_connected: Contracts tensors that must form a connected graph
§Diag Tensor Handling
When Diag tensors share indices, their diagonal axes are unified to create hyperedges in the einsum optimizer.
Example: Diag(i,j) * Diag(j,k):
- Diag(i,j) has diagonal axes i and j (same index)
- Diag(j,k) has diagonal axes j and k (same index)
- After union-find: i, j, k all map to the same representative ID
- This creates a hyperedge that the einsum optimizer handles correctly
Structs§
- Axis
Union Find - Union-Find data structure for grouping axis IDs.
Functions§
- build_
diag_ union - Build a union-find structure from a collection of tensors.
- collect_
sizes - Collect dimension sizes for remapped IDs.
- contract_
connected - Contract multiple tensors that form a connected graph.
- contract_
multi - Contract multiple tensors into a single tensor, handling disconnected components.
- print_
and_ reset_ contract_ profile - Print and clear the aggregated multi-tensor contraction profile.
- remap_
output_ ids - Remap output IDs using the union-find structure.
- remap_
tensor_ ids - Remap tensor indices using the union-find structure.
- reset_
contract_ profile - Reset the aggregated multi-tensor contraction profile.