mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add field m_maxIterations; break loop when this limit is exceeded.
This commit is contained in:
@@ -360,6 +360,11 @@ template<typename _MatrixType> class SelfAdjointEigenSolver
|
||||
return m_eivec * m_eivalues.cwiseInverse().cwiseSqrt().asDiagonal() * m_eivec.adjoint();
|
||||
}
|
||||
|
||||
/** \brief Maximum number of iterations.
|
||||
*
|
||||
* Maximum number of iterations allowed for an eigenvalue to converge.
|
||||
*/
|
||||
static const int m_maxIterations = 30;
|
||||
|
||||
protected:
|
||||
MatrixType m_eivec;
|
||||
@@ -419,6 +424,8 @@ SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>::compute(
|
||||
|
||||
Index end = n-1;
|
||||
Index start = 0;
|
||||
Index iter = 0; // number of iterations we are working on one element
|
||||
|
||||
while (end>0)
|
||||
{
|
||||
for (Index i = start; i<end; ++i)
|
||||
@@ -427,9 +434,17 @@ SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>::compute(
|
||||
|
||||
// find the largest unreduced block
|
||||
while (end>0 && m_subdiag[end-1]==0)
|
||||
{
|
||||
iter = 0;
|
||||
end--;
|
||||
}
|
||||
if (end<=0)
|
||||
break;
|
||||
|
||||
// if we spent too many iterations on the current element, we give up
|
||||
iter++;
|
||||
if(iter >= m_maxIterations) break;
|
||||
|
||||
start = end - 1;
|
||||
while (start>0 && m_subdiag[start-1]!=0)
|
||||
start--;
|
||||
@@ -437,6 +452,11 @@ SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>::compute(
|
||||
ei_tridiagonal_qr_step(diag.data(), m_subdiag.data(), start, end, computeEigenvectors ? m_eivec.data() : (Scalar*)0, n);
|
||||
}
|
||||
|
||||
if(iter >= m_maxIterations)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Sort eigenvalues and corresponding vectors.
|
||||
// TODO make the sort optional ?
|
||||
// TODO use a better sort algorithm !!
|
||||
|
||||
Reference in New Issue
Block a user