pub fn prepare_contraction_pairs<I: IndexLike>(
indices_a: &[I],
dims_a: &[usize],
indices_b: &[I],
dims_b: &[usize],
pairs: &[(I, I)],
) -> Result<ContractionSpec<I>, ContractionError>Expand description
Prepare contraction data for explicit index pairs (like tensordot).
Unlike prepare_contraction, this function takes explicit pairs of indices
to contract, allowing contraction of indices with different IDs.
ยงExample
use tensor4all_core::index::DefaultIndex as Index;
use tensor4all_core::index_ops::prepare_contraction_pairs;
let i = Index::new_dyn(2);
let j = Index::new_dyn(3);
let k = Index::new_dyn(3); // Same dim as j but different ID
let l = Index::new_dyn(4);
let indices_a = vec![i.clone(), j.clone()];
let dims_a = vec![2, 3];
let indices_b = vec![k.clone(), l.clone()];
let dims_b = vec![3, 4];
// Contract j with k
let spec = prepare_contraction_pairs(
&indices_a, &dims_a,
&indices_b, &dims_b,
&[(j.clone(), k.clone())]
).unwrap();
assert_eq!(spec.axes_a, vec![1]);
assert_eq!(spec.axes_b, vec![0]);
assert_eq!(spec.result_dims, vec![2, 4]);