From a1e6bc63805896dafe93c89581b77eb537034cc8 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Wed, 5 May 2021 20:29:00 -0400 Subject: [PATCH 1/3] Fix LAPACK names in eigh_generalized docs --- lax/src/eigh.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lax/src/eigh.rs b/lax/src/eigh.rs index 46a3b131..ad8963dc 100644 --- a/lax/src/eigh.rs +++ b/lax/src/eigh.rs @@ -14,7 +14,7 @@ pub trait Eigh_: Scalar { a: &mut [Self], ) -> Result>; - /// Wraps `*syegv` for real and `*heegv` for complex + /// Wraps `*sygv` for real and `*hegv` for complex fn eigh_generalized( calc_eigenvec: bool, layout: MatrixLayout, From 3c4df7604f034826b8c6a502ccae2bebd8a63ecc Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Wed, 5 May 2021 20:29:54 -0400 Subject: [PATCH 2/3] Add basic documentation for eigh --- ndarray-linalg/src/eigh.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ndarray-linalg/src/eigh.rs b/ndarray-linalg/src/eigh.rs index 580c2b7e..850e6104 100644 --- a/ndarray-linalg/src/eigh.rs +++ b/ndarray-linalg/src/eigh.rs @@ -1,4 +1,15 @@ -//! Eigenvalue decomposition for Hermite matrices +//! Eigendecomposition for Hermitian matrices. +//! +//! For a Hermitian matrix `A`, this solves the eigenvalue problem `A V = V D` +//! for `D` and `V`, where `D` is the diagonal matrix of eigenvalues in +//! ascending order and `V` is the orthonormal matrix of corresponding +//! eigenvectors. +//! +//! For a pair of Hermitian matrices `A` and `B` where `B` is also positive +//! definite, this solves the generalized eigenvalue problem `A V = B V D`, +//! where `D` is the diagonal matrix of generalized eigenvalues in ascending +//! order and `V` is the matrix of corresponding generalized eigenvectors. The +//! matrix `V` is normalized such that `V^H B V = I`. use ndarray::*; From ab4cc024cc32087eecae21a3d614670085fa4f55 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Wed, 5 May 2021 23:42:43 -0400 Subject: [PATCH 3/3] Add example to eigh module --- ndarray-linalg/src/eigh.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ndarray-linalg/src/eigh.rs b/ndarray-linalg/src/eigh.rs index 850e6104..ec306ad6 100644 --- a/ndarray-linalg/src/eigh.rs +++ b/ndarray-linalg/src/eigh.rs @@ -10,6 +10,28 @@ //! where `D` is the diagonal matrix of generalized eigenvalues in ascending //! order and `V` is the matrix of corresponding generalized eigenvectors. The //! matrix `V` is normalized such that `V^H B V = I`. +//! +//! # Example +//! +//! Find the eigendecomposition of a Hermitian (or real symmetric) matrix. +//! +//! ``` +//! use approx::assert_abs_diff_eq; +//! use ndarray::{array, Array2}; +//! use ndarray_linalg::{Eigh, UPLO}; +//! +//! let a: Array2 = array![ +//! [2., 1.], +//! [1., 2.], +//! ]; +//! let (eigvals, eigvecs) = a.eigh(UPLO::Lower)?; +//! assert_abs_diff_eq!(eigvals, array![1., 3.]); +//! assert_abs_diff_eq!( +//! a.dot(&eigvecs), +//! eigvecs.dot(&Array2::from_diag(&eigvals)), +//! ); +//! # Ok::<(), Box>(()) +//! ``` use ndarray::*;