Skip to content

Commit

Permalink
Remove special subdim=2 case from SymmetricEigen
Browse files Browse the repository at this point in the history
  • Loading branch information
CattleProdigy committed Mar 13, 2023
1 parent dc57668 commit b028297
Showing 1 changed file with 2 additions and 57 deletions.
59 changes: 2 additions & 57 deletions src/linalg/symmetric_eigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use approx::AbsDiffEq;
use num::Zero;

use crate::allocator::Allocator;
use crate::base::{DefaultAllocator, Matrix2, OMatrix, OVector, SquareMatrix, Vector2};
use crate::base::{DefaultAllocator, OMatrix, OVector, SquareMatrix, Vector2};
use crate::dimension::{Dim, DimDiff, DimSub, U1};
use crate::storage::Storage;
use simba::scalar::ComplexField;
Expand Down Expand Up @@ -131,10 +131,7 @@ where
Self::delimit_subproblem(&diag, &mut off_diag, dim - 1, eps.clone());

while end != start {
let subdim = end - start + 1;

#[allow(clippy::comparison_chain)]
if subdim > 2 {
{
let m = end - 1;
let n = end;

Expand Down Expand Up @@ -191,58 +188,6 @@ where
{
end -= 1;
}
} else if subdim == 2 {
let m = Matrix2::new(
diag[start].clone(),
off_diag[start].clone().conjugate(),
off_diag[start].clone(),
diag[start + 1].clone(),
);
let eigvals = m.eigenvalues().unwrap();

// A = [ a c ]
// [ c b ]
// v = [ v1; v2 ]
// (A-lI)v = 0
// (a-l1)v1 + c*v2 = 0
//
// let v1 = c
// (a-l1)c + c*v2 = 0
// (a-l1)c = -c*v2
// v2 = l1 - a
//
// c*v1 - b*v2 = 0
// c*v1 - (b-l1)*v2 = 0
// c*v1 = (l1-b)*v2
// let v2 = c
// v1 = (l1-b)
let basis = if (eigvals.x.clone() - diag[start + 1].clone()).abs()
> (eigvals.x.clone() - diag[start].clone()).abs()
{
Vector2::new(
eigvals.x.clone() - diag[start + 1].clone(),
off_diag[start].clone(),
)
} else {
Vector2::new(
off_diag[start].clone(),
eigvals.x.clone() - diag[start].clone(),
)
};

diag[start] = eigvals[0].clone();
diag[start + 1] = eigvals[1].clone();

if let Some(ref mut q) = q_mat {
if let Some((rot, _)) =
GivensRotation::try_new(basis.x.clone(), basis.y.clone(), eps.clone())
{
let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s()));
rot.rotate_rows(&mut q.fixed_columns_mut::<2>(start));
}
}

end -= 1;
}

// Re-delimit the subproblem in case some decoupling occurred.
Expand Down

0 comments on commit b028297

Please sign in to comment.