50 template<
typename _MatrixType,
int _UpLo>
class LDLT 55 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
56 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
57 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
58 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
61 typedef typename MatrixType::Scalar
Scalar;
81 m_isInitialized(false)
91 : m_matrix(size, size),
92 m_transpositions(size),
95 m_isInitialized(false)
104 template<
typename InputType>
106 : m_matrix(matrix.rows(), matrix.cols()),
107 m_transpositions(matrix.rows()),
108 m_temporary(matrix.rows()),
110 m_isInitialized(false)
121 template<
typename InputType>
123 : m_matrix(matrix.derived()),
124 m_transpositions(matrix.rows()),
125 m_temporary(matrix.rows()),
127 m_isInitialized(false)
137 m_isInitialized =
false;
141 inline typename Traits::MatrixU
matrixU()
const 143 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
144 return Traits::getU(m_matrix);
148 inline typename Traits::MatrixL
matrixL()
const 150 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
151 return Traits::getL(m_matrix);
158 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
159 return m_transpositions;
165 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
166 return m_matrix.diagonal();
172 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
179 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
198 template<
typename Rhs>
202 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
204 &&
"LDLT::solve(): invalid number of rows of the right hand side matrix b");
208 template<
typename Derived>
211 template<
typename InputType>
219 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
223 template <
typename Derived>
232 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
236 MatrixType reconstructedMatrix()
const;
245 inline Index
rows()
const {
return m_matrix.rows(); }
246 inline Index
cols()
const {
return m_matrix.cols(); }
255 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
259 #ifndef EIGEN_PARSED_BY_DOXYGEN 260 template<
typename RhsType,
typename DstType>
262 void _solve_impl(
const RhsType &rhs, DstType &dst)
const;
293 template<
typename MatrixType,
typename TranspositionType,
typename Workspace>
297 typedef typename MatrixType::Scalar Scalar;
298 typedef typename MatrixType::RealScalar RealScalar;
299 typedef typename TranspositionType::StorageIndex IndexType;
302 bool found_zero_pivot =
false;
307 transpositions.setIdentity();
317 Index index_of_biggest_in_corner;
318 mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner);
319 index_of_biggest_in_corner += k;
321 transpositions.coeffRef(k) = IndexType(index_of_biggest_in_corner);
322 if(k != index_of_biggest_in_corner)
326 Index s = size-index_of_biggest_in_corner-1;
327 mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k));
328 mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s));
329 std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner));
330 for(
Index i=k+1;i<index_of_biggest_in_corner;++i)
332 Scalar tmp = mat.coeffRef(i,k);
333 mat.coeffRef(i,k) =
numext::conj(mat.coeffRef(index_of_biggest_in_corner,i));
334 mat.coeffRef(index_of_biggest_in_corner,i) =
numext::conj(tmp);
337 mat.coeffRef(index_of_biggest_in_corner,k) =
numext::conj(mat.coeff(index_of_biggest_in_corner,k));
344 Index rs = size - k - 1;
351 temp.head(k) = mat.diagonal().real().head(k).asDiagonal() * A10.adjoint();
352 mat.coeffRef(k,k) -= (A10 * temp.head(k)).value();
354 A21.noalias() -= A20 * temp.head(k);
362 bool pivot_is_valid = (
abs(realAkk) > RealScalar(0));
364 if(k==0 && !pivot_is_valid)
371 transpositions.coeffRef(j) = IndexType(j);
372 ret = ret && (mat.col(j).tail(size-j-1).array()==Scalar(0)).all();
377 if((rs>0) && pivot_is_valid)
380 if(found_zero_pivot && pivot_is_valid) ret =
false;
381 else if(!pivot_is_valid) found_zero_pivot =
true;
384 if (realAkk < static_cast<RealScalar>(0)) sign =
Indefinite;
386 if (realAkk > static_cast<RealScalar>(0)) sign =
Indefinite;
403 template<
typename MatrixType,
typename WDerived>
407 typedef typename MatrixType::Scalar Scalar;
408 typedef typename MatrixType::RealScalar RealScalar;
413 RealScalar alpha = 1;
424 Scalar wj = w.coeff(j);
426 RealScalar
gamma = dj*alpha + swj2;
428 mat.coeffRef(j,j) += swj2/alpha;
434 w.
tail(rs) -= wj * mat.col(j).tail(rs);
441 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
442 static bool update(MatrixType& mat,
const TranspositionType& transpositions, Workspace& tmp,
const WType& w,
const typename MatrixType::RealScalar& sigma=1)
445 tmp = transpositions * w;
453 template<
typename MatrixType,
typename TranspositionType,
typename Workspace>
460 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
461 static EIGEN_STRONG_INLINE bool update(MatrixType& mat, TranspositionType& transpositions, Workspace& tmp, WType& w,
const typename MatrixType::RealScalar& sigma=1)
472 static inline MatrixL
getL(
const MatrixType& m) {
return MatrixL(m); }
473 static inline MatrixU
getU(
const MatrixType& m) {
return MatrixU(m.adjoint()); }
480 static inline MatrixL
getL(
const MatrixType& m) {
return MatrixL(m.adjoint()); }
481 static inline MatrixU
getU(
const MatrixType& m) {
return MatrixU(m); }
488 template<
typename MatrixType,
int _UpLo>
489 template<
typename InputType>
492 check_template_parameters();
505 abs_col_sum = m_matrix.col(
col).tail(size -
col).template lpNorm<1>() + m_matrix.row(
col).head(
col).template lpNorm<1>();
507 abs_col_sum = m_matrix.col(
col).head(
col).template lpNorm<1>() + m_matrix.row(
col).tail(size -
col).template lpNorm<1>();
508 if (abs_col_sum > m_l1_norm)
509 m_l1_norm = abs_col_sum;
512 m_transpositions.resize(size);
513 m_isInitialized =
false;
514 m_temporary.resize(size);
519 m_isInitialized =
true;
528 template<
typename MatrixType,
int _UpLo>
529 template<
typename Derived>
540 m_matrix.resize(size,size);
542 m_transpositions.resize(size);
544 m_transpositions.coeffRef(i) = IndexType(i);
545 m_temporary.resize(size);
547 m_isInitialized =
true;
555 #ifndef EIGEN_PARSED_BY_DOXYGEN 556 template<
typename _MatrixType,
int _UpLo>
557 template<
typename RhsType,
typename DstType>
562 dst = m_transpositions * rhs;
565 matrixL().solveInPlace(dst);
579 for (
Index i = 0; i < vecD.size(); ++i)
581 if(
abs(vecD(i)) > tolerance)
582 dst.row(i) /= vecD(i);
584 dst.row(i).setZero();
588 matrixU().solveInPlace(dst);
591 dst = m_transpositions.transpose() * dst;
608 template<
typename MatrixType,
int _UpLo>
609 template<
typename Derived>
612 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
615 bAndX = this->solve(bAndX);
623 template<
typename MatrixType,
int _UpLo>
626 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
632 res = transpositionsP() * res;
634 res = matrixU() * res;
636 res = vectorD().real().asDiagonal() * res;
638 res = matrixL() * res;
640 res = transpositionsP().transpose() * res;
649 template<
typename MatrixType,
unsigned int UpLo>
660 template<
typename Derived>
669 #endif // EIGEN_LDLT_H Robust Cholesky decomposition of a matrix with pivoting.
static void check_template_parameters()
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isfinite(const half &a)
#define EIGEN_STRONG_INLINE
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
TranspositionType m_transpositions
const LDLT< PlainObject > ldlt() const
NumTraits< typename MatrixType::Scalar >::Real RealScalar
static bool update(MatrixType &mat, const TranspositionType &transpositions, Workspace &tmp, const WType &w, const typename MatrixType::RealScalar &sigma=1)
EIGEN_DEVICE_FUNC RealReturnType real() const
LDLT & compute(const EigenBase< InputType > &matrix)
Expression of the transpose of a matrix.
LDLT(Index size)
Default Constructor with memory preallocation.
Matrix< Scalar, RowsAtCompileTime, 1, 0, MaxRowsAtCompileTime, 1 > TmpMatrixType
LDLT & rankUpdate(const MatrixBase< Derived > &w, const RealScalar &alpha=1)
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
static bool updateInPlace(MatrixType &mat, MatrixBase< WDerived > &w, const typename MatrixType::RealScalar &sigma=1)
Decomposition::RealScalar rcond_estimate_helper(typename Decomposition::RealScalar matrix_norm, const Decomposition &dec)
Reciprocal condition number estimator.
const MatrixType & matrixLDLT() const
internal::SignMatrix m_sign
static EIGEN_STRONG_INLINE bool update(MatrixType &mat, TranspositionType &transpositions, Workspace &tmp, WType &w, const typename MatrixType::RealScalar &sigma=1)
MatrixType::StorageIndex StorageIndex
LDLT()
Default Constructor.
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
EIGEN_DEVICE_FUNC const SignReturnType sign() const
const mpreal gamma(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
bool solveInPlace(MatrixBase< Derived > &bAndX) const
LDLT(const EigenBase< InputType > &matrix)
Constructor with decomposition.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_DEVICE_FUNC void _solve_impl(const RhsType &rhs, DstType &dst) const
bool isNegative(void) const
const TriangularView< const typename MatrixType::AdjointReturnType, UnitLower > MatrixL
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
const TriangularView< const MatrixType, UnitLower > MatrixL
Transpositions< RowsAtCompileTime, MaxRowsAtCompileTime > TranspositionType
MatrixType reconstructedMatrix() const
EIGEN_DEVICE_FUNC Index cols() const
static MatrixL getL(const MatrixType &m)
const LDLT & adjoint() const
internal::LDLT_Traits< MatrixType, UpLo > Traits
const TranspositionType & transpositionsP() const
static MatrixU getU(const MatrixType &m)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Abs2ReturnType abs2() const
Traits::MatrixU matrixU() const
static EIGEN_STRONG_INLINE bool unblocked(MatrixType &mat, TranspositionType &transpositions, Workspace &temp, SignMatrix &sign)
IndicesType::Scalar StorageIndex
TmpMatrixType m_temporary
const Solve< LDLT, Rhs > solve(const MatrixBase< Rhs > &b) const
EIGEN_DEVICE_FUNC SegmentReturnType tail(Index n)
TFSIMD_FORCE_INLINE const tfScalar & w() const
static MatrixU getU(const MatrixType &m)
ComputationInfo info() const
Reports whether previous computation was successful.
Expression of a fixed-size or dynamic-size block.
MatrixType::Scalar Scalar
Diagonal< const MatrixType > vectorD() const
Traits::MatrixL matrixL() const
Expression of a triangular part in a matrix.
EIGEN_DEVICE_FUNC Index rows() const
const TriangularView< const MatrixType, UnitUpper > MatrixU
const TriangularView< const typename MatrixType::AdjointReturnType, UnitUpper > MatrixU
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Pseudo expression representing a solving operation.
static bool unblocked(MatrixType &mat, TranspositionType &transpositions, Workspace &temp, SignMatrix &sign)
LDLT(EigenBase< InputType > &matrix)
Constructs a LDLT factorization from a given matrix.
EIGEN_DEVICE_FUNC const Scalar & b
EIGEN_DEVICE_FUNC Derived & derived()
Base class for all dense matrices, vectors, and expressions.
PermutationMatrix< RowsAtCompileTime, MaxRowsAtCompileTime > PermutationType
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
const LDLT< PlainObject, UpLo > ldlt() const
static MatrixL getL(const MatrixType &m)