From 8ef7c4232824c1b74e43a391dc14302a1d931669 Mon Sep 17 00:00:00 2001 From: metric-space Date: Sat, 5 Feb 2022 23:44:05 -0500 Subject: [PATCH] Removed extra memory allocation for buffer (now redundant) --- .../src/generalized_eigenvalues.rs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/nalgebra-lapack/src/generalized_eigenvalues.rs b/nalgebra-lapack/src/generalized_eigenvalues.rs index c9fb0e57..f60f9df2 100644 --- a/nalgebra-lapack/src/generalized_eigenvalues.rs +++ b/nalgebra-lapack/src/generalized_eigenvalues.rs @@ -205,10 +205,12 @@ where Allocator, D, D> + Allocator, D> + Allocator<(Complex, T), D>, { let n = self.vsl.shape().0; + let mut l = self .vsl .clone() .map(|x| Complex::new(x, T::RealField::zero())); + let mut r = self .vsr .clone() @@ -216,8 +218,8 @@ where let eigenvalues = &self.eigenvalues(); - let mut ll; let mut c = 0; + while c < n { if eigenvalues[c].im.abs() > T::RealField::default_epsilon() && c + 1 < n && { let e_conj = eigenvalues[c].conj(); @@ -225,22 +227,20 @@ where ((e_conj.re - e.re).abs() < T::RealField::default_epsilon()) && ((e_conj.im - e.im).abs() < T::RealField::default_epsilon()) } { - ll = l.column(c + 1).into_owned(); - l.column_mut(c).zip_apply(&ll, |r, i| { - *r = Complex::new(r.re.clone(), i.re); + // taking care of the left eigenvector matrix + l.column_mut(c).zip_apply(&self.vsl.column(c + 1), |r, i| { + *r = Complex::new(r.re.clone(), i.clone()); }); - ll.copy_from(&l.column(c)); - l.column_mut(c + 1).zip_apply(&ll, |r, i| { - *r = i.conj(); + l.column_mut(c + 1).zip_apply(&self.vsl.column(c), |i, r| { + *i = Complex::new(r.clone(), -i.re.clone()); }); - ll.copy_from(&r.column(c + 1)); - r.column_mut(c).zip_apply(&ll, |r, i| { - *r = Complex::new(r.re, i.re); + // taking care of the right eigenvector matrix + r.column_mut(c).zip_apply(&self.vsr.column(c + 1), |r, i| { + *r = Complex::new(r.re.clone(), i.clone()); }); - ll.copy_from(&r.column(c)); - r.column_mut(c + 1).zip_apply(&ll, |r, i| { - *r = i.conj(); + r.column_mut(c + 1).zip_apply(&self.vsr.column(c), |i, r| { + *i = Complex::new(r.clone(), -i.re.clone()); }); c += 2;