added a function to get all the real elements

This commit is contained in:
Marc Haubenstock 2022-10-26 16:26:06 +02:00
parent 14394b7e67
commit 9c8b5f0f38
2 changed files with 37 additions and 4 deletions

View File

@ -27,7 +27,5 @@ fn main() {
assert_relative_eq!(eigenvectors[0][1].re, -9.0/32.7871926215100059134410999); 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][1].im, 12.0/32.7871926215100059134410999);
assert_relative_eq!(eigenvectors[0][2].re, 25.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);
} }

View File

@ -168,10 +168,45 @@ where
det 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<T>, Option<Vec<OVector<T, D>>>, Option<Vec<OVector<T, D>>>) where DefaultAllocator: Allocator<T, D> {
let (number_of_elements, _) = self.eigenvalues_re.shape_generic();
let number_of_elements_value = number_of_elements.value();
let mut eigenvalues = Vec::<T>::with_capacity(number_of_elements_value);
let mut eigenvectors = match self.eigenvectors.is_some() {
true => Some(Vec::<OVector<T, D>>::with_capacity(number_of_elements_value)),
false => None
};
let mut left_eigenvectors = match self.left_eigenvectors.is_some() {
true => Some(Vec::<OVector<T, D>>::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. /// 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. /// 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<Vec<Complex<T>>>, Option<Vec<OVector<Complex<T>, D>>>, Option<Vec<OVector<Complex<T>, D>>>) where DefaultAllocator: Allocator<Complex<T>, D> { pub fn get_complex_elements(&self) -> (Option<Vec<Complex<T>>>, Option<Vec<OVector<Complex<T>, D>>>, Option<Vec<OVector<Complex<T>, D>>>) where DefaultAllocator: Allocator<Complex<T>, D> {
match self.eigenvalues_are_real() { match self.eigenvalues_are_real() {
true => (None, None, None), true => (None, None, None),
false => { false => {