22 enum SignMatrix { PositiveSemiDef, NegativeSemiDef, ZeroSign, Indefinite };
48template<
typename _MatrixType,
int _UpLo>
class LDLT
51 typedef _MatrixType MatrixType;
53 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
54 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
55 Options = MatrixType::Options & ~RowMajorBit,
56 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
57 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
60 typedef typename MatrixType::Scalar Scalar;
61 typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
63 typedef typename MatrixType::StorageIndex StorageIndex;
79 m_sign(internal::ZeroSign),
80 m_isInitialized(false)
90 : m_matrix(size, size),
91 m_transpositions(size),
93 m_sign(internal::ZeroSign),
94 m_isInitialized(false)
102 template<
typename InputType>
104 : m_matrix(matrix.rows(), matrix.cols()),
105 m_transpositions(matrix.rows()),
106 m_temporary(matrix.rows()),
107 m_sign(internal::ZeroSign),
108 m_isInitialized(false)
110 compute(matrix.derived());
118 m_isInitialized =
false;
122 inline typename Traits::MatrixU
matrixU()
const
124 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
125 return Traits::getU(m_matrix);
129 inline typename Traits::MatrixL
matrixL()
const
131 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
132 return Traits::getL(m_matrix);
139 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
140 return m_transpositions;
146 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
147 return m_matrix.diagonal();
153 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
154 return m_sign == internal::PositiveSemiDef || m_sign == internal::ZeroSign;
160 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
161 return m_sign == internal::NegativeSemiDef || m_sign == internal::ZeroSign;
179 template<
typename Rhs>
183 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
184 eigen_assert(m_matrix.rows()==b.rows()
185 &&
"LDLT::solve(): invalid number of rows of the right hand side matrix b");
189 template<
typename Derived>
192 template<
typename InputType>
195 template <
typename Derived>
204 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
210 inline Index rows()
const {
return m_matrix.rows(); }
211 inline Index cols()
const {
return m_matrix.cols(); }
220 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
224 #ifndef EIGEN_PARSED_BY_DOXYGEN
225 template<
typename RhsType,
typename DstType>
232 static void check_template_parameters()
234 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
244 TranspositionType m_transpositions;
245 TmpMatrixType m_temporary;
246 internal::SignMatrix m_sign;
247 bool m_isInitialized;
256 template<
typename MatrixType,
typename TranspositionType,
typename Workspace>
260 typedef typename MatrixType::Scalar Scalar;
261 typedef typename MatrixType::RealScalar RealScalar;
262 typedef typename TranspositionType::StorageIndex IndexType;
263 eigen_assert(
mat.rows()==
mat.cols());
264 const Index size =
mat.rows();
269 if (numext::real(
mat.coeff(0,0)) > 0) sign = PositiveSemiDef;
270 else if (numext::real(
mat.coeff(0,0)) < 0) sign = NegativeSemiDef;
271 else sign = ZeroSign;
275 for (Index k = 0; k < size; ++k)
293 Scalar tmp =
mat.coeffRef(i,k);
305 Index rs = size - k - 1;
312 temp.head(k) =
mat.diagonal().real().head(k).asDiagonal() *
A10.adjoint();
313 mat.coeffRef(k,k) -= (
A10 * temp.head(k)).value();
315 A21.noalias() -=
A20 * temp.head(k);
322 RealScalar
realAkk = numext::real(
mat.coeffRef(k,k));
323 if((rs>0) && (abs(
realAkk) > RealScalar(0)))
326 if (sign == PositiveSemiDef) {
327 if (
realAkk < 0) sign = Indefinite;
328 }
else if (sign == NegativeSemiDef) {
329 if (
realAkk > 0) sign = Indefinite;
330 }
else if (sign == ZeroSign) {
331 if (
realAkk > 0) sign = PositiveSemiDef;
332 else if (
realAkk < 0) sign = NegativeSemiDef;
346 template<
typename MatrixType,
typename WDerived>
347 static bool updateInPlace(MatrixType&
mat,
MatrixBase<WDerived>& w,
const typename MatrixType::RealScalar& sigma=1)
349 using numext::isfinite;
350 typedef typename MatrixType::Scalar Scalar;
351 typedef typename MatrixType::RealScalar RealScalar;
353 const Index size =
mat.rows();
354 eigen_assert(
mat.cols() == size && w.size()==size);
356 RealScalar alpha = 1;
359 for (Index
j = 0;
j < size;
j++)
362 if (!(isfinite)(alpha))
367 Scalar
wj = w.coeff(
j);
377 w.tail(rs) -=
wj *
mat.col(
j).tail(rs);
379 mat.col(
j).tail(rs) += (sigma*numext::conj(
wj)/gamma)*w.tail(rs);
384 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
385 static bool update(MatrixType& mat,
const TranspositionType& transpositions, Workspace& tmp,
const WType& w,
const typename MatrixType::RealScalar& sigma=1)
388 tmp = transpositions * w;
390 return ldlt_inplace<Lower>::updateInPlace(mat,tmp,sigma);
396 template<
typename MatrixType,
typename TranspositionType,
typename Workspace>
397 static EIGEN_STRONG_INLINE
bool unblocked(MatrixType&
mat, TranspositionType&
transpositions,
Workspace& temp, SignMatrix& sign)
403 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
404 static EIGEN_STRONG_INLINE
bool update(MatrixType&
mat, TranspositionType&
transpositions,
Workspace& tmp,
WType& w,
const typename MatrixType::RealScalar& sigma=1)
415 static inline MatrixL getL(
const MatrixType& m) {
return MatrixL(m); }
416 static inline MatrixU getU(
const MatrixType& m) {
return MatrixU(m.adjoint()); }
423 static inline MatrixL getL(
const MatrixType& m) {
return MatrixL(m.adjoint()); }
424 static inline MatrixU getU(
const MatrixType& m) {
return MatrixU(m); }
431template<
typename MatrixType,
int _UpLo>
432template<
typename InputType>
435 check_template_parameters();
437 eigen_assert(a.rows()==a.cols());
438 const Index size = a.rows();
440 m_matrix = a.derived();
442 m_transpositions.resize(size);
443 m_isInitialized =
false;
444 m_temporary.resize(size);
445 m_sign = internal::ZeroSign;
449 m_isInitialized =
true;
458template<
typename MatrixType,
int _UpLo>
459template<
typename Derived>
462 typedef typename TranspositionType::StorageIndex IndexType;
463 const Index size = w.rows();
466 eigen_assert(m_matrix.rows()==size);
470 m_matrix.resize(size,size);
472 m_transpositions.resize(size);
473 for (
Index i = 0; i < size; i++)
474 m_transpositions.coeffRef(i) = IndexType(i);
475 m_temporary.resize(size);
476 m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef;
477 m_isInitialized =
true;
485#ifndef EIGEN_PARSED_BY_DOXYGEN
486template<
typename _MatrixType,
int _UpLo>
487template<
typename RhsType,
typename DstType>
490 eigen_assert(rhs.rows() == rows());
492 dst = m_transpositions * rhs;
495 matrixL().solveInPlace(
dst);
509 for (Index i = 0; i <
vecD.size(); ++i)
511 if(abs(
vecD(i)) > tolerance)
514 dst.row(i).setZero();
518 matrixU().solveInPlace(dst);
521 dst = m_transpositions.transpose() * dst;
538template<
typename MatrixType,
int _UpLo>
539template<
typename Derived>
540bool LDLT<MatrixType,_UpLo>::solveInPlace(MatrixBase<Derived> &bAndX)
const
542 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
543 eigen_assert(m_matrix.rows() == bAndX.rows());
545 bAndX = this->solve(bAndX);
553template<
typename MatrixType,
int _UpLo>
556 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
557 const Index size = m_matrix.rows();
558 MatrixType res(size,size);
562 res = transpositionsP() * res;
564 res = matrixU() * res;
566 res = vectorD().real().asDiagonal() * res;
568 res = matrixL() * res;
570 res = transpositionsP().transpose() * res;
580template<
typename MatrixType,
unsigned int UpLo>
591template<
typename Derived>
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition Diagonal.h:65
Robust Cholesky decomposition of a matrix with pivoting.
Definition LDLT.h:49
const Solve< LDLT, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition LDLT.h:181
LDLT(Index size)
Default Constructor with memory preallocation.
Definition LDLT.h:89
LDLT()
Default Constructor.
Definition LDLT.h:76
Traits::MatrixU matrixU() const
Definition LDLT.h:122
bool isPositive() const
Definition LDLT.h:151
ComputationInfo info() const
Reports whether previous computation was successful.
Definition LDLT.h:218
void setZero()
Clear any existing decomposition.
Definition LDLT.h:116
const MatrixType & matrixLDLT() const
Definition LDLT.h:202
bool isNegative(void) const
Definition LDLT.h:158
Diagonal< const MatrixType > vectorD() const
Definition LDLT.h:144
LDLT(const EigenBase< InputType > &matrix)
Constructor with decomposition.
Definition LDLT.h:103
Eigen::Index Index
Definition LDLT.h:62
MatrixType reconstructedMatrix() const
Definition LDLT.h:554
Traits::MatrixL matrixL() const
Definition LDLT.h:129
const TranspositionType & transpositionsP() const
Definition LDLT.h:137
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
Permutation matrix.
Definition PermutationMatrix.h:311
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
Definition SelfAdjointView.h:51
Pseudo expression representing a solving operation.
Definition Solve.h:63
Represents a sequence of transpositions (row/column interchange)
Definition Transpositions.h:159
ComputationInfo
Enum for reporting the status of a computation.
Definition Constants.h:430
@ Lower
View matrix as a lower triangular matrix.
Definition Constants.h:204
@ Upper
View matrix as an upper triangular matrix.
Definition Constants.h:206
@ Success
Computation was successful.
Definition Constants.h:432
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.hpp:24418
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition EigenBase.h:29
Holds information about the various numeric (i.e.
Definition NumTraits.h:108