pub fn common_inds<I: IndexLike>(indices_a: &[I], indices_b: &[I]) -> Vec<I>Expand description
Find common indices between two index collections.
Returns a vector of indices that appear in both indices_a and indices_b
(set intersection). This is similar to ITensors.jl’s commoninds function.
Time complexity: O(n + m) where n = len(indices_a), m = len(indices_b).
§Arguments
indices_a- First collection of indicesindices_b- Second collection of indices
§Returns
A vector containing indices that are common to both collections (matched by ID).
§Example
use tensor4all_core::index::{DefaultIndex as Index, DynId};
use tensor4all_core::index_ops::common_inds;
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 common = common_inds(&indices_a, &indices_b);
assert_eq!(common.len(), 1);
assert_eq!(common[0].id, j.id);