common_ind_positions

Function common_ind_positions 

Source
pub fn common_ind_positions<I: IndexLike>(
    indices_a: &[I],
    indices_b: &[I],
) -> Vec<(usize, usize)>
Expand description

Find contractable indices between two slices and return their positions.

Returns a vector of (pos_a, pos_b) tuples where each tuple indicates that indices_a[pos_a] and indices_b[pos_b] are contractable (same ID, same dimension, and compatible ConjState).

ยงExample

use tensor4all_core::index::DefaultIndex as Index;
use tensor4all_core::index_ops::common_ind_positions;

let i = Index::new_dyn(2);
let j = Index::new_dyn(3);
let k = Index::new_dyn(4);

let indices_a = vec![i.clone(), j.clone()];
let indices_b = vec![j.clone(), k.clone()];

let positions = common_ind_positions(&indices_a, &indices_b);
assert_eq!(positions, vec![(1, 0)]); // j is at position 1 in a, position 0 in b