Skip to main content

normalize_eig_vectors

Function normalize_eig_vectors 

Source
pub fn normalize_eig_vectors<R>(
    vectors: &mut [Complex<R>],
    n: usize,
    batch_count: usize,
) -> Result<()>
where R: Float + NumAssign + AsPrimitive<f64> + 'static, f64: AsPrimitive<R>,
Expand description

Normalize the eigenvector columns of a batch of n x n column-major blocks in place.

vectors holds n * n complex elements per batch item, blocks back to back, and only the first batch_count blocks are read and written. Each block is normalized column by column to unit 2-norm, the gauge eig documents.

The arithmetic is the one eig uses: each column is scaled by its largest component before the squares are summed, so a finite column of large magnitude does not square to infinity and one of tiny magnitude does not square to zero. A column that cannot be normalized - every component zero, or a non-finite sum - is reported as Error::NonFinite with op: "eig" and role: "eigenvector column", the failure eig raises.

The whole slice is validated before anything is written, so an Err leaves vectors untouched.

§Errors

A tenferro_tensor::Error with a validation source when n is zero, when n * n * batch_count overflows usize, or when vectors is shorter than that product; and a numerical failure carrying Error::NonFinite for a column with no unit gauge.

§Examples

use num_complex::Complex64;
use tenferro_linalg::normalize_eig_vectors;

// One 2x2 column-major block: columns (2, 0) and (0, 3i).
let mut vectors = [
    Complex64::new(2.0, 0.0),
    Complex64::new(0.0, 0.0),
    Complex64::new(0.0, 0.0),
    Complex64::new(0.0, 3.0),
];
normalize_eig_vectors(&mut vectors, 2, 1)?;
assert_eq!(vectors[0], Complex64::new(1.0, 0.0));
assert_eq!(vectors[3], Complex64::new(0.0, 1.0));