fix under- and overflow

This commit is contained in:
Gael Guennebaud 2011-02-06 08:23:10 +01:00
parent 9ce08b352f
commit ea99880760

View File

@ -400,7 +400,9 @@ SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>
RealVectorType& diag = m_eivalues;
MatrixType& mat = m_eivec;
mat = matrix;
// map the matrix coefficients to [-1:1] to avoid over- and underflow.
RealScalar scale = matrix.cwiseAbs().maxCoeff();
mat = matrix / scale;
m_subdiag.resize(n-1);
internal::tridiagonalization_inplace(mat, diag, m_subdiag, computeEigenvectors);
@ -457,6 +459,9 @@ SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>
}
}
// scale back the eigen values
m_eivalues *= scale;
m_isInitialized = true;
m_eigenvectorsOk = computeEigenvectors;
return *this;