pub fn replaceinds_in_place<I: IndexLike>(
indices: &mut [I],
replacements: &[(I, I)],
) -> Result<(), ReplaceIndsError>Expand description
Replace indices in-place based on ID matching.
This is an in-place variant of replaceinds that modifies the input slice directly.
Useful for performance-critical code where you want to avoid allocations.
§Arguments
indices- Mutable slice of indices to modifyreplacements- Pairs of(old_index, new_index)where indices matchingold_index.idare replaced withnew_index
§Returns
Ok(()) on success, or an error if any replacement has a dimension mismatch.
§Errors
Returns ReplaceIndsError::SpaceMismatch if any replacement index has a different dimension than the original.
§Example
use tensor4all_core::index::{DefaultIndex as Index, DynId};
use tensor4all_core::index_ops::replaceinds_in_place;
let i = Index::new_dyn(2);
let j = Index::new_dyn(3);
let k = Index::new_dyn(4);
let new_j = Index::new_dyn(3);
let mut indices = vec![i.clone(), j.clone(), k.clone()];
let replacements = vec![(j.clone(), new_j.clone())];
replaceinds_in_place(&mut indices, &replacements).unwrap();
assert_eq!(indices[1].id, new_j.id);