Allow ComplexEigenSolver and ComplexSchur to work with real matrices.

Add a test which covers this case.
This commit is contained in:
Jitse Niesen 2010-03-20 17:04:40 +00:00
parent d3e271c47e
commit d91ffffc37
3 changed files with 8 additions and 7 deletions

View File

@ -171,7 +171,7 @@ template<typename _MatrixType> class ComplexEigenSolver
void compute(const MatrixType& matrix);
protected:
MatrixType m_eivec;
EigenvectorType m_eivec;
EigenvalueType m_eivalues;
bool m_isInitialized;
};
@ -195,21 +195,21 @@ void ComplexEigenSolver<MatrixType>::compute(const MatrixType& matrix)
m_eivec.setZero();
Scalar d2, z;
Complex d2, z;
RealScalar norm = matrix.norm();
// compute the (normalized) eigenvectors
for(int k=n-1 ; k>=0 ; k--)
{
d2 = schur.matrixT().coeff(k,k);
m_eivec.coeffRef(k,k) = Scalar(1.0,0.0);
m_eivec.coeffRef(k,k) = Complex(1.0,0.0);
for(int i=k-1 ; i>=0 ; i--)
{
m_eivec.coeffRef(i,k) = -schur.matrixT().coeff(i,k);
if(k-i-1>0)
m_eivec.coeffRef(i,k) -= (schur.matrixT().row(i).segment(i+1,k-i-1) * m_eivec.col(k).segment(i+1,k-i-1)).value();
z = schur.matrixT().coeff(i,i) - d2;
if(z==Scalar(0))
if(z==Complex(0))
ei_real_ref(z) = eps * norm;
m_eivec.coeffRef(i,k) = m_eivec.coeff(i,k) / z;

View File

@ -158,8 +158,8 @@ void ComplexSchur<MatrixType>::compute(const MatrixType& matrix, bool skipU)
// TODO skip Q if skipU = true
HessenbergDecomposition<MatrixType> hess(matrix);
m_matT = hess.matrixH();
if(!skipU) m_matU = hess.matrixQ();
m_matT = hess.matrixH().template cast<Complex>();
if(!skipU) m_matU = hess.matrixQ().template cast<Complex>();
// Reduce the Hessenberg matrix m_matT to triangular form by QR iteration.
@ -221,7 +221,7 @@ void ComplexSchur<MatrixType>::compute(const MatrixType& matrix, bool skipU)
// compute the shift kappa as one of the eigenvalues of the 2x2
// diagonal block on the bottom of the active submatrix
Matrix<Scalar,2,2> t = m_matT.template block<2,2>(iu-1,iu-1);
Matrix<Complex,2,2> t = m_matT.template block<2,2>(iu-1,iu-1);
sf = t.cwiseAbs().sum();
t /= sf; // the normalization by sf is to avoid under/overflow

View File

@ -61,5 +61,6 @@ void test_eigensolver_complex()
CALL_SUBTEST_1( eigensolver(Matrix4cf()) );
CALL_SUBTEST_2( eigensolver(MatrixXcd(14,14)) );
CALL_SUBTEST_3( eigensolver(Matrix<std::complex<float>, 1, 1>()) );
CALL_SUBTEST_4( eigensolver(Matrix3f()) );
}
}