Function eigh

Source
pub fn eigh<F>(a: &ArrayView2<'_, F>) -> LinalgResult<(Array1<F>, Array2<F>)>
where F: Float + NumAssign + Sum + 'static,
Expand description

Compute the eigenvalues and eigenvectors of a Hermitian or symmetric matrix.

§Arguments

  • a - Input Hermitian or symmetric matrix

§Returns

  • Tuple (eigenvalues, eigenvectors) where eigenvalues is a real vector and eigenvectors is a real matrix whose columns are the eigenvectors

§Examples

use ndarray::array;
use scirs2_linalg::eigh;

let a = array![[1.0_f64, 0.0], [0.0, 2.0]];
let (w, v) = eigh(&a.view()).unwrap();

// Sort eigenvalues (they may be returned in different order)
let mut eigenvalues = vec![(w[0], 0), (w[1], 1)];
eigenvalues.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap());

assert!((eigenvalues[0].0 - 1.0).abs() < 1e-10);
assert!((eigenvalues[1].0 - 2.0).abs() < 1e-10);