tensor4all_treetn/operator/identity.rs
1//! Identity tensor construction for operator composition.
2//!
3//! When composing exclusive operators, gap positions (nodes not covered by any operator)
4//! need identity tensors that pass information through unchanged.
5//!
6//! This module provides convenience wrappers around `TensorLike::delta()`.
7
8use anyhow::Result;
9
10use tensor4all_core::{DynIndex, TensorDynLen, TensorLike};
11
12/// Build an identity operator tensor for a gap node.
13///
14/// For a node with site indices `{s1, s2, ...}` and bond indices `{l1, l2, ...}`,
15/// this creates an identity tensor where:
16/// - Each site index `s` gets a primed version `s'` (output index)
17/// - The tensor is diagonal: `T[s1, s1', s2, s2', ...] = δ_{s1,s1'} × δ_{s2,s2'} × ...`
18///
19/// This is a convenience wrapper around `TensorDynLen::delta()`.
20///
21/// # Arguments
22///
23/// * `site_indices` - The site indices at this node
24/// * `output_site_indices` - The output (primed) site indices, must have same dimensions
25///
26/// # Returns
27///
28/// A tensor representing the identity operator on the given site space.
29///
30/// # Example
31///
32/// For a single site index of dimension 2:
33/// ```text
34/// T[s, s'] = δ_{s,s'} = [[1, 0], [0, 1]]
35/// ```
36pub fn build_identity_operator_tensor(
37 site_indices: &[DynIndex],
38 output_site_indices: &[DynIndex],
39) -> Result<TensorDynLen> {
40 TensorDynLen::delta(site_indices, output_site_indices)
41}
42
43#[cfg(test)]
44mod tests;