diff --git a/nalgebra-lapack/examples/complex_eigen.rs b/nalgebra-lapack/examples/complex_eigen.rs index ebf5e48c..6c452d66 100644 --- a/nalgebra-lapack/examples/complex_eigen.rs +++ b/nalgebra-lapack/examples/complex_eigen.rs @@ -27,7 +27,5 @@ fn main() { assert_relative_eq!(eigenvectors[0][1].re, -9.0/32.7871926215100059134410999); assert_relative_eq!(eigenvectors[0][1].im, 12.0/32.7871926215100059134410999); assert_relative_eq!(eigenvectors[0][2].re, 25.0/32.7871926215100059134410999); - assert_relative_eq!(eigenvectors[0][2].im, 0.0); - - + assert_relative_eq!(eigenvectors[0][2].im, 0.0); } \ No newline at end of file diff --git a/nalgebra-lapack/src/eigen.rs b/nalgebra-lapack/src/eigen.rs index d98c500d..e76b8ef4 100644 --- a/nalgebra-lapack/src/eigen.rs +++ b/nalgebra-lapack/src/eigen.rs @@ -168,10 +168,45 @@ where det } + /// Returns a tuple of vectors. The elements of the tuple are the real parts of the eigenvalues, left eigenvectors and right eigenvectors respectively. + pub fn get_real_elements(&self) -> (Vec, Option>>, Option>>) where DefaultAllocator: Allocator { + let (number_of_elements, _) = self.eigenvalues_re.shape_generic(); + let number_of_elements_value = number_of_elements.value(); + let mut eigenvalues = Vec::::with_capacity(number_of_elements_value); + let mut eigenvectors = match self.eigenvectors.is_some() { + true => Some(Vec::>::with_capacity(number_of_elements_value)), + false => None + }; + let mut left_eigenvectors = match self.left_eigenvectors.is_some() { + true => Some(Vec::>::with_capacity(number_of_elements_value)), + false => None + }; + + let mut c = 0; + while c < number_of_elements_value { + eigenvalues.push(self.eigenvalues_re[c].clone()); + + if eigenvectors.is_some() { + eigenvectors.as_mut().unwrap().push((&self.eigenvectors.as_ref()).unwrap().column(c).into_owned()); + } + + if left_eigenvectors.is_some() { + left_eigenvectors.as_mut().unwrap().push((&self.left_eigenvectors.as_ref()).unwrap().column(c).into_owned()); + } + if self.eigenvalues_im[c] != T::zero() { + //skip next entry + c += 1; + } + c+=1; + } + (eigenvalues, left_eigenvectors, eigenvectors) + + + } + /// Returns a tuple of vectors. The elements of the tuple are the complex eigenvalues, complex left eigenvectors and complex right eigenvectors respectively. /// The elements appear as conjugate pairs within each vector, with the positive of the pair always being first. pub fn get_complex_elements(&self) -> (Option>>, Option, D>>>, Option, D>>>) where DefaultAllocator: Allocator, D> { - match self.eigenvalues_are_real() { true => (None, None, None), false => {