From 5e10ca46cbbf9e6b5c68b26d4b3570669650db7b Mon Sep 17 00:00:00 2001 From: metric-space Date: Tue, 15 Feb 2022 01:45:33 -0500 Subject: [PATCH] Add another case for when eigenvalues should be mapped to zero. Make method private --- nalgebra-lapack/src/generalized_eigenvalues.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nalgebra-lapack/src/generalized_eigenvalues.rs b/nalgebra-lapack/src/generalized_eigenvalues.rs index aede9e07..dac8004c 100644 --- a/nalgebra-lapack/src/generalized_eigenvalues.rs +++ b/nalgebra-lapack/src/generalized_eigenvalues.rs @@ -253,17 +253,21 @@ where (l, r) } - /// computes the generalized eigenvalues i.e values of lambda that satisfy the following equation - /// determinant(A - lambda* B) = 0 - #[must_use] - pub fn eigenvalues(&self) -> OVector, D> + // only used for internal calculation for assembling eigenvectors based on realness of + // eigenvalues and complex-conjugate checks of subsequent non-real eigenvalues + fn eigenvalues(&self) -> OVector, D> where DefaultAllocator: Allocator, D>, { let mut out = Matrix::zeros_generic(self.vsl.shape_generic().0, Const::<1>); + let epsilon = T::RealField::default_epsilon(); + for i in 0..out.len() { - out[i] = if self.beta[i].clone().abs() < T::RealField::default_epsilon() { + out[i] = if self.beta[i].clone().abs() < epsilon + || (self.alphai[i].clone().abs() < epsilon + && self.alphar[i].clone().abs() < epsilon) + { Complex::zero() } else { Complex::new(self.alphar[i].clone(), self.alphai[i].clone())