50 template<
typename _MatrixType,
int _UpLo>
class LDLT 55 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
56 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
57 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
58 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
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>
299 typedef typename TranspositionType::StorageIndex IndexType;
302 bool found_zero_pivot =
false;
307 transpositions.setIdentity();
318 Index index_of_biggest_in_corner;
319 mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner);
320 index_of_biggest_in_corner += k;
322 transpositions.coeffRef(k) = IndexType(index_of_biggest_in_corner);
323 if(k != index_of_biggest_in_corner)
327 Index s = size-index_of_biggest_in_corner-1;
328 mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k));
329 mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s));
330 std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner));
331 for(
Index i=k+1;
i<index_of_biggest_in_corner;++
i)
333 Scalar tmp = mat.coeffRef(
i,k);
334 mat.coeffRef(
i,k) =
numext::conj(mat.coeffRef(index_of_biggest_in_corner,
i));
335 mat.coeffRef(index_of_biggest_in_corner,
i) =
numext::conj(tmp);
338 mat.coeffRef(index_of_biggest_in_corner,k) =
numext::conj(mat.coeff(index_of_biggest_in_corner,k));
345 Index rs = size - k - 1;
352 temp.head(k) = mat.diagonal().real().head(k).asDiagonal() * A10.adjoint();
353 mat.coeffRef(k,k) -= (A10 * temp.head(k)).
value();
355 A21.noalias() -= A20 * temp.head(k);
365 if(k==0 && !pivot_is_valid)
372 transpositions.coeffRef(
j) = IndexType(
j);
373 ret = ret && (mat.col(
j).tail(size-
j-1).array()==
Scalar(0)).all();
378 if((rs>0) && pivot_is_valid)
381 ret = ret && (A21.array()==
Scalar(0)).all();
383 if(found_zero_pivot && pivot_is_valid) ret =
false;
384 else if(!pivot_is_valid) found_zero_pivot =
true;
387 if (realAkk < static_cast<RealScalar>(0)) sign =
Indefinite;
389 if (realAkk > static_cast<RealScalar>(0)) sign =
Indefinite;
406 template<
typename MatrixType,
typename WDerived>
416 RealScalar
alpha = 1;
427 Scalar wj = w.coeff(
j);
429 RealScalar
gamma = dj*alpha + swj2;
431 mat.coeffRef(
j,
j) += swj2/
alpha;
437 w.
tail(rs) -= wj * mat.col(j).tail(rs);
444 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
448 tmp = transpositions *
w;
456 template<
typename MatrixType,
typename TranspositionType,
typename Workspace>
463 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
491 template<
typename MatrixType,
int _UpLo>
492 template<
typename InputType>
495 check_template_parameters();
508 abs_col_sum = m_matrix.col(
col).tail(size -
col).template lpNorm<1>() + m_matrix.row(
col).head(
col).template lpNorm<1>();
510 abs_col_sum = m_matrix.col(
col).head(
col).template lpNorm<1>() + m_matrix.row(
col).tail(size -
col).template lpNorm<1>();
511 if (abs_col_sum > m_l1_norm)
512 m_l1_norm = abs_col_sum;
515 m_transpositions.resize(size);
516 m_isInitialized =
false;
517 m_temporary.resize(size);
522 m_isInitialized =
true;
531 template<
typename MatrixType,
int _UpLo>
532 template<
typename Derived>
543 m_matrix.resize(size,size);
545 m_transpositions.resize(size);
547 m_transpositions.coeffRef(
i) = IndexType(
i);
548 m_temporary.resize(size);
550 m_isInitialized =
true;
558 #ifndef EIGEN_PARSED_BY_DOXYGEN 559 template<
typename _MatrixType,
int _UpLo>
560 template<
typename RhsType,
typename DstType>
565 dst = m_transpositions * rhs;
568 matrixL().solveInPlace(dst);
583 for (
Index i = 0;
i < vecD.size(); ++
i)
585 if(
abs(vecD(
i)) > tolerance)
586 dst.row(
i) /= vecD(
i);
588 dst.row(
i).setZero();
592 matrixU().solveInPlace(dst);
595 dst = m_transpositions.transpose() * dst;
612 template<
typename MatrixType,
int _UpLo>
613 template<
typename Derived>
616 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
619 bAndX = this->solve(bAndX);
627 template<
typename MatrixType,
int _UpLo>
630 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
636 res = transpositionsP() *
res;
638 res = matrixU() *
res;
640 res = vectorD().real().asDiagonal() *
res;
642 res = matrixL() *
res;
644 res = transpositionsP().transpose() *
res;
653 template<
typename MatrixType,
unsigned int UpLo>
664 template<
typename Derived>
673 #endif // EIGEN_LDLT_H
Robust Cholesky decomposition of a matrix with pivoting.
static void check_template_parameters()
#define EIGEN_STRONG_INLINE
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)
LDLT & compute(const EigenBase< InputType > &matrix)
EIGEN_DEVICE_FUNC bool() isfinite(const T &x)
Expression of the transpose of a matrix.
LDLT(Index size)
Default Constructor with memory preallocation.
Matrix< Scalar, RowsAtCompileTime, 1, 0, MaxRowsAtCompileTime, 1 > TmpMatrixType
static const double sigma
Namespace containing all symbols from the Eigen library.
LDLT & rankUpdate(const MatrixBase< Derived > &w, const RealScalar &alpha=1)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
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
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
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 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
NumTraits< Scalar >::Real RealScalar
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)
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.
EIGEN_DONT_INLINE void compute(Solver &solver, const MatrixType &A)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
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 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)
ScalarWithExceptions conj(const ScalarWithExceptions &x)