22 enum SignMatrix { PositiveSemiDef, NegativeSemiDef, ZeroSign, Indefinite };
48 template<
typename _MatrixType,
int _UpLo>
class LDLT 51 typedef _MatrixType MatrixType;
53 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
54 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
56 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
57 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
62 typedef typename MatrixType::Index Index;
79 m_isInitialized(false)
89 : m_matrix(size, size),
90 m_transpositions(size),
93 m_isInitialized(false)
102 : m_matrix(matrix.rows(), matrix.cols()),
103 m_transpositions(matrix.rows()),
104 m_temporary(matrix.rows()),
106 m_isInitialized(false)
116 m_isInitialized =
false;
120 inline typename Traits::MatrixU
matrixU()
const 122 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
123 return Traits::getU(m_matrix);
127 inline typename Traits::MatrixL
matrixL()
const 129 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
130 return Traits::getL(m_matrix);
137 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
138 return m_transpositions;
144 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
145 return m_matrix.diagonal();
151 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
152 return m_sign == internal::PositiveSemiDef || m_sign == internal::ZeroSign;
155 #ifdef EIGEN2_SUPPORT 165 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
166 return m_sign == internal::NegativeSemiDef || m_sign == internal::ZeroSign;
184 template<
typename Rhs>
188 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
189 eigen_assert(m_matrix.rows()==b.rows()
190 &&
"LDLT::solve(): invalid number of rows of the right hand side matrix b");
194 #ifdef EIGEN2_SUPPORT 195 template<
typename OtherDerived,
typename ResultType>
198 *result = this->solve(b);
203 template<
typename Derived>
206 LDLT& compute(
const MatrixType& matrix);
208 template <
typename Derived>
217 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
221 MatrixType reconstructedMatrix()
const;
223 inline Index rows()
const {
return m_matrix.rows(); }
224 inline Index cols()
const {
return m_matrix.cols(); }
233 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
239 static void check_template_parameters()
241 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
251 TranspositionType m_transpositions;
252 TmpMatrixType m_temporary;
253 internal::SignMatrix m_sign;
254 bool m_isInitialized;
263 template<
typename MatrixType,
typename TranspositionType,
typename Workspace>
264 static bool unblocked(
MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign)
268 typedef typename MatrixType::RealScalar RealScalar;
269 typedef typename MatrixType::Index Index;
270 eigen_assert(mat.rows()==mat.cols());
271 const Index
size = mat.rows();
275 transpositions.setIdentity();
276 if (numext::real(mat.coeff(0,0)) > 0) sign = PositiveSemiDef;
277 else if (numext::real(mat.coeff(0,0)) < 0) sign = NegativeSemiDef;
278 else sign = ZeroSign;
282 for (Index k = 0; k <
size; ++k)
285 Index index_of_biggest_in_corner;
286 mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner);
287 index_of_biggest_in_corner += k;
289 transpositions.coeffRef(k) = index_of_biggest_in_corner;
290 if(k != index_of_biggest_in_corner)
294 Index s = size-index_of_biggest_in_corner-1;
295 mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k));
296 mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s));
297 std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner));
298 for(
int i=k+1;i<index_of_biggest_in_corner;++i)
300 Scalar tmp = mat.coeffRef(i,k);
301 mat.coeffRef(i,k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner,i));
302 mat.coeffRef(index_of_biggest_in_corner,i) = numext::conj(tmp);
305 mat.coeffRef(index_of_biggest_in_corner,k) = numext::conj(mat.coeff(index_of_biggest_in_corner,k));
312 Index rs = size - k - 1;
319 temp.head(k) = mat.diagonal().real().head(k).asDiagonal() * A10.adjoint();
320 mat.coeffRef(k,k) -= (A10 * temp.head(k)).value();
322 A21.noalias() -= A20 * temp.head(k);
329 RealScalar realAkk = numext::real(mat.coeffRef(k,k));
330 if((rs>0) && (abs(realAkk) > RealScalar(0)))
333 if (sign == PositiveSemiDef) {
334 if (realAkk < 0) sign = Indefinite;
335 }
else if (sign == NegativeSemiDef) {
336 if (realAkk > 0) sign = Indefinite;
337 }
else if (sign == ZeroSign) {
338 if (realAkk > 0) sign = PositiveSemiDef;
339 else if (realAkk < 0) sign = NegativeSemiDef;
353 template<
typename MatrixType,
typename WDerived>
356 using numext::isfinite;
358 typedef typename MatrixType::RealScalar RealScalar;
359 typedef typename MatrixType::Index Index;
361 const Index
size = mat.rows();
362 eigen_assert(mat.cols() == size && w.size()==
size);
364 RealScalar alpha = 1;
367 for (Index j = 0; j <
size; j++)
370 if (!(isfinite)(alpha))
374 RealScalar dj = numext::real(mat.coeff(j,j));
375 Scalar wj = w.coeff(j);
376 RealScalar swj2 = sigma*numext::abs2(wj);
377 RealScalar gamma = dj*alpha + swj2;
379 mat.coeffRef(j,j) += swj2/alpha;
385 w.
tail(rs) -= wj * mat.col(j).tail(rs);
387 mat.col(j).tail(rs) += (sigma*numext::conj(wj)/gamma)*w.
tail(rs);
392 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
393 static bool update(
MatrixType& mat,
const TranspositionType& transpositions, Workspace& tmp,
const WType& w,
const typename MatrixType::RealScalar& sigma=1)
396 tmp = transpositions * w;
404 template<
typename MatrixType,
typename TranspositionType,
typename Workspace>
405 static EIGEN_STRONG_INLINE
bool unblocked(
MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign)
411 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
412 static EIGEN_STRONG_INLINE
bool update(
MatrixType& mat, TranspositionType& transpositions, Workspace& tmp, WType& w,
const typename MatrixType::RealScalar& sigma=1)
423 static inline MatrixL getL(
const MatrixType& m) {
return m; }
424 static inline MatrixU getU(
const MatrixType& m) {
return m.adjoint(); }
431 static inline MatrixL getL(
const MatrixType& m) {
return m.adjoint(); }
432 static inline MatrixU getU(
const MatrixType& m) {
return m; }
439 template<
typename MatrixType,
int _UpLo>
442 check_template_parameters();
444 eigen_assert(a.rows()==a.cols());
445 const Index
size = a.rows();
449 m_transpositions.
resize(size);
450 m_isInitialized =
false;
451 m_temporary.resize(size);
452 m_sign = internal::ZeroSign;
456 m_isInitialized =
true;
465 template<
typename MatrixType,
int _UpLo>
466 template<
typename Derived>
469 const Index
size = w.rows();
472 eigen_assert(m_matrix.rows()==
size);
476 m_matrix.resize(size,size);
478 m_transpositions.resize(size);
479 for (Index i = 0; i <
size; i++)
480 m_transpositions.coeffRef(i) = i;
481 m_temporary.resize(size);
482 m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef;
483 m_isInitialized =
true;
492 template<
typename _MatrixType,
int _UpLo,
typename Rhs>
497 EIGEN_MAKE_SOLVE_HELPERS(LDLTType,Rhs)
499 template<
typename Dest>
void evalTo(Dest& dst)
const 501 eigen_assert(rhs().rows() == dec().matrixLDLT().rows());
503 dst = dec().transpositionsP() * rhs();
506 dec().matrixL().solveInPlace(dst);
512 typedef typename LDLTType::MatrixType
MatrixType;
513 typedef typename LDLTType::RealScalar RealScalar;
523 for (Index i = 0; i < vectorD.size(); ++i) {
524 if(abs(vectorD(i)) > tolerance)
525 dst.row(i) /= vectorD(i);
527 dst.row(i).setZero();
531 dec().matrixU().solveInPlace(dst);
534 dst = dec().transpositionsP().transpose() * dst;
552 template<
typename MatrixType,
int _UpLo>
553 template<
typename Derived>
556 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
557 eigen_assert(m_matrix.rows() == bAndX.rows());
559 bAndX = this->solve(bAndX);
567 template<
typename MatrixType,
int _UpLo>
570 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
571 const Index
size = m_matrix.rows();
576 res = transpositionsP() * res;
578 res = matrixU() * res;
580 res = vectorD().real().asDiagonal() * res;
582 res = matrixL() * res;
584 res = transpositionsP().transpose() * res;
592 template<
typename MatrixType,
unsigned int UpLo>
602 template<
typename Derived>
611 #endif // EIGEN_LDLT_H ComputationInfo info() const
Reports whether previous computation was successful.
Definition: LDLT.h:231
Robust Cholesky decomposition of a matrix with pivoting.
Definition: LDLT.h:48
const LDLT< PlainObject, UpLo > ldlt() const
Definition: LDLT.h:594
Definition: ForwardDeclarations.h:124
const TranspositionType & transpositionsP() const
Definition: LDLT.h:135
Traits::MatrixU matrixU() const
Definition: LDLT.h:120
Expression of the transpose of a matrix.
Definition: Transpose.h:57
LDLT(Index size)
Default Constructor with memory preallocation.
Definition: LDLT.h:88
const internal::solve_retval< LDLT, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: LDLT.h:186
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
void setZero()
Clear any existing decomposition.
Definition: LDLT.h:114
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
Traits::MatrixL matrixL() const
Definition: LDLT.h:127
bool isNegative(void) const
Definition: LDLT.h:163
Diagonal< const MatrixType > vectorD() const
Definition: LDLT.h:142
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
LDLT()
Default Constructor.
Definition: LDLT.h:75
View matrix as an upper triangular matrix.
Definition: Constants.h:169
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
Resizes *this to a rows x cols matrix.
Definition: PlainObjectBase.h:235
Computation was successful.
Definition: Constants.h:376
const LDLT< PlainObject > ldlt() const
Definition: LDLT.h:604
bool isPositive() const
Definition: LDLT.h:149
Definition: BandTriangularSolver.h:13
const MatrixType & matrixLDLT() const
Definition: LDLT.h:215
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
Base class for triangular part in a matrix.
Definition: TriangularMatrix.h:158
MatrixType reconstructedMatrix() const
Definition: LDLT.h:568
Definition: ForwardDeclarations.h:125
View matrix as a lower triangular matrix.
Definition: Constants.h:167
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:64
SegmentReturnType tail(Index n)
Definition: DenseBase.h:834
ComputationInfo
Enum for reporting the status of a computation.
Definition: Constants.h:374
bool isPositiveDefinite(MatrixBase< Derived > const &m)
Definition: TestIMU_UKF.cpp:37
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: osvr_print_tree.cpp:52
LDLT & compute(const MatrixType &matrix)
Compute / recompute the LDLT decomposition A = L D L^* = U^* D U of matrix.
Definition: LDLT.h:440
LDLT(const MatrixType &matrix)
Constructor with decomposition.
Definition: LDLT.h:101
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48