From a09cc5d4c014e517ef766b3ff0e535ad8d9a6dc9 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 3 Dec 2011 18:26:08 +0100 Subject: [PATCH] fix bug #282: add the possibiliry to shift the diagonal coefficients via a linear function. --- Eigen/src/SparseCholesky/SimplicialCholesky.h | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Eigen/src/SparseCholesky/SimplicialCholesky.h b/Eigen/src/SparseCholesky/SimplicialCholesky.h index 3206dd0ab..808be2855 100644 --- a/Eigen/src/SparseCholesky/SimplicialCholesky.h +++ b/Eigen/src/SparseCholesky/SimplicialCholesky.h @@ -96,11 +96,11 @@ class SimplicialCholeskyBase /** Default constructor */ SimplicialCholeskyBase() - : m_info(Success), m_isInitialized(false) + : m_info(Success), m_isInitialized(false), m_shiftOffset(0), m_shiftScale(1) {} SimplicialCholeskyBase(const MatrixType& matrix) - : m_info(Success), m_isInitialized(false) + : m_info(Success), m_isInitialized(false), m_shiftOffset(0), m_shiftScale(1) { compute(matrix); } @@ -172,6 +172,22 @@ class SimplicialCholeskyBase const PermutationMatrix& permutationPinv() const { return m_Pinv; } + /** Sets the shift parameters that will be used to adjust the diagonal coefficients during the numerical factorization. + * + * During the numerical factorization, the diagonal coefficients are transformed by the following linear model:\n + * \c d_ii = \a offset + \a scale * \c d_ii + * + * The default is the identity transformation with \a offset=0, and \a scale=1. + * + * \returns a reference to \c *this. + */ + Derived& setShift(const Scalar& offset, const RealScalar& scale = 1) + { + m_shiftOffset = offset; + m_shiftScale = scale; + return derived(); + } + #ifndef EIGEN_PARSED_BY_DOXYGEN /** \internal */ template @@ -264,6 +280,9 @@ class SimplicialCholeskyBase VectorXi m_nonZerosPerCol; PermutationMatrix m_P; // the permutation PermutationMatrix m_Pinv; // the inverse permutation + + Scalar m_shiftOffset; + RealScalar m_shiftScale; }; template class SimplicialLLt; @@ -719,7 +738,8 @@ void SimplicialCholeskyBase::factorize(const MatrixType& a) } /* compute numerical values kth row of L (a sparse triangular solve) */ - Scalar d = y[k]; // get D(k,k) and clear Y(k) + + Scalar d = y[k] * m_shiftScale + m_shiftOffset; // get D(k,k), apply the shift function, and clear Y(k) y[k] = 0.0; for(; top < size; ++top) {