pub fn contract_multi_owned(
tensors: Vec<TensorDynLen>,
options: ContractionOptions<'_>,
) -> Result<TensorDynLen>Expand description
Contract multiple owned tensors into a single tensor.
This is the consuming counterpart to contract_multi_with_options. It
preserves the same contraction semantics while allowing eligible non-AD
dense inputs to use tenferro’s owned eager einsum executor. When any input
tracks gradients, or when compact structured metadata needs the borrowed
path, this function falls back to the shared borrowed execution so semantics
and reverse-mode AD remain intact.
§Arguments
tensors- Owned tensors to contract.options- Pair-selection policy and retained indices.
§Returns
The contracted tensor, with retained shared indices preserved in the output.
§Errors
Returns an error for the same conditions as
contract_multi_with_options, including empty input, invalid retained
indices, and incompatible contraction pairs.
§Examples
use tensor4all_core::{contract_multi_owned, contract_multi_with_options, AllowedPairs, ContractionOptions, DynIndex, TensorDynLen};
let i = DynIndex::new_dyn(2);
let j = DynIndex::new_dyn(3);
let k = DynIndex::new_dyn(4);
let a = TensorDynLen::from_dense(vec![i.clone(), j.clone()], vec![1.0_f64; 6]).unwrap();
let b = TensorDynLen::from_dense(vec![j.clone(), k.clone()], vec![1.0_f64; 12]).unwrap();
let options = ContractionOptions::new(AllowedPairs::All);
let owned = contract_multi_owned(vec![a.clone(), b.clone()], options).unwrap();
let borrowed = contract_multi_with_options(&[&a, &b], options).unwrap();
assert_eq!(owned.indices(), borrowed.indices());
assert_eq!(owned.to_vec::<f64>().unwrap(), borrowed.to_vec::<f64>().unwrap());