diff --git a/unsupported/Eigen/src/IterativeSolvers/IncompleteCholesky.h b/unsupported/Eigen/src/IterativeSolvers/IncompleteCholesky.h index 2e2d9a851..388e6bfaa 100644 --- a/unsupported/Eigen/src/IterativeSolvers/IncompleteCholesky.h +++ b/unsupported/Eigen/src/IterativeSolvers/IncompleteCholesky.h @@ -24,6 +24,11 @@ namespace Eigen { * matrix. It is advised to give a row-oriented sparse matrix * \tparam _UpLo The triangular part of the matrix to reference. * \tparam _OrderingType + * + * It performs the following incomplete factorization: \f$ S P A P' S \approx L L' \f$ + * where L is a lower triangular factor, S if a diagonal scaling matrix, and P is a + * fill-in reducing permutation as computed of the ordering method. + * */ template > @@ -86,6 +91,7 @@ class IncompleteCholesky : public SparseSolverBase0) m_perm = pinv.inverse(); else m_perm.resize(0); m_analysisIsOk = true; + m_isInitialized = true; } template @@ -110,9 +116,17 @@ class IncompleteCholesky : public SparseSolverBase colPtr, Ref rowIdx, Ref vals, const Index& col, const Index& jk, VectorIx& firstElt, VectorList& listCol); }; @@ -176,13 +190,21 @@ void IncompleteCholesky::factorize(const _MatrixType } m_scale = m_scale.cwiseSqrt().cwiseSqrt(); + + for (Index j = 0; j < n; ++j) + if(m_scale(j)>(std::numeric_limits::min)()) + m_scale(j) = RealScalar(1)/m_scale(j); + else + m_scale(j) = 1; + + // FIXME disable scaling if not needed, i.e., if it is roughtly uniform? (this will make solve() faster) // Scale and compute the shift for the matrix RealScalar mindiag = NumTraits::highest(); for (Index j = 0; j < n; j++) { for (Index k = colPtr[j]; k < colPtr[j+1]; k++) - vals[k] /= (m_scale(j)*m_scale(rowIdx[k])); + vals[k] *= (m_scale(j)*m_scale(rowIdx[k])); eigen_internal_assert(rowIdx[colPtr[j]]==j && "IncompleteCholesky: only the lower triangular part must be stored"); mindiag = numext::mini(numext::real(vals[colPtr[j]]), mindiag); } @@ -240,7 +262,6 @@ void IncompleteCholesky::factorize(const _MatrixType // Scale the current column if(numext::real(diag) <= 0) { - std::cerr << "\nNegative diagonal during Incomplete factorization at position " << j << " (value = " << diag << ")\n"; m_info = NumericalIssue; return; } @@ -276,7 +297,6 @@ void IncompleteCholesky::factorize(const _MatrixType updateList(colPtr,rowIdx,vals,j,jk,firstElt,listCol); } m_factorizationIsOk = true; - m_isInitialized = true; m_info = Success; }