pub fn partial_contract<V>(
a: &TreeTN<TensorDynLen, V>,
b: &TreeTN<TensorDynLen, V>,
spec: &PartialContractionSpec<DynIndex>,
center: &V,
options: ContractionOptions,
) -> Result<TreeTN<TensorDynLen, V>>Expand description
Partially contract two TreeTNs according to the given specification.
§Arguments
a- First tensor networkb- Second tensor networkspec- Which site indices to contract versus link through diagonal structurecenter- Canonical center node for the resultoptions- Contraction algorithm options
§Index handling
- contract_pairs: Both indices are traced over (inner product). Neither appears in the result.
- diagonal_pairs: The two indices are linked through explicit diagonal structure so that only matching values contribute, while the left-hand site index remains in the result.
- Unmentioned indices: Pass through unchanged as external legs.
§Examples
use tensor4all_core::{DynIndex, TensorDynLen};
use tensor4all_treetn::{
contraction::ContractionOptions,
partial_contract,
PartialContractionSpec,
TreeTN,
};
let idx_a = DynIndex::new_dyn(2);
let idx_b = DynIndex::new_dyn(2);
let a = TreeTN::<TensorDynLen, usize>::from_tensors(
vec![TensorDynLen::from_dense(vec![idx_a.clone()], vec![1.0, 2.0]).unwrap()],
vec![0],
).unwrap();
let b = TreeTN::<TensorDynLen, usize>::from_tensors(
vec![TensorDynLen::from_dense(vec![idx_b.clone()], vec![3.0, 4.0]).unwrap()],
vec![0],
).unwrap();
let spec = PartialContractionSpec {
contract_pairs: vec![(idx_a.clone(), idx_b.clone())],
diagonal_pairs: vec![],
output_order: None,
};
let result = partial_contract(&a, &b, &spec, &0usize, ContractionOptions::default()).unwrap();
assert_eq!(result.node_count(), 1);