16template<
typename MatrixType,
int UpLo>
struct LLT_Traits;
50template<
typename _MatrixType,
int _UpLo>
class LLT
53 typedef _MatrixType MatrixType;
55 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
56 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
57 Options = MatrixType::Options,
58 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
60 typedef typename MatrixType::Scalar Scalar;
61 typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
63 typedef typename MatrixType::StorageIndex StorageIndex;
67 AlignmentMask = int(PacketSize)-1,
87 explicit LLT(
Index size) : m_matrix(size, size),
88 m_isInitialized(
false) {}
90 template<
typename InputType>
92 : m_matrix(matrix.rows(), matrix.cols()),
93 m_isInitialized(
false)
95 compute(matrix.derived());
99 inline typename Traits::MatrixU
matrixU()
const
101 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
102 return Traits::getU(m_matrix);
106 inline typename Traits::MatrixL
matrixL()
const
108 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
109 return Traits::getL(m_matrix);
122 template<
typename Rhs>
126 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
127 eigen_assert(m_matrix.rows()==b.rows()
128 &&
"LLT::solve(): invalid number of rows of the right hand side matrix b");
132 template<
typename Derived>
135 template<
typename InputType>
144 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
158 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
162 inline Index rows()
const {
return m_matrix.rows(); }
163 inline Index cols()
const {
return m_matrix.cols(); }
165 template<
typename VectorType>
166 LLT rankUpdate(
const VectorType& vec,
const RealScalar& sigma = 1);
168 #ifndef EIGEN_PARSED_BY_DOXYGEN
169 template<
typename RhsType,
typename DstType>
171 void _solve_impl(
const RhsType &rhs, DstType &dst)
const;
176 static void check_template_parameters()
178 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
186 bool m_isInitialized;
194template<
typename MatrixType,
typename VectorType>
195static Index llt_rank_update_lower(MatrixType&
mat,
const VectorType& vec,
const typename MatrixType::RealScalar& sigma)
198 typedef typename MatrixType::Scalar Scalar;
199 typedef typename MatrixType::RealScalar RealScalar;
200 typedef typename MatrixType::ColXpr ColXpr;
201 typedef typename internal::remove_all<ColXpr>::type
ColXprCleaned;
202 typedef typename ColXprCleaned::SegmentReturnType
ColXprSegment;
204 typedef typename TempVectorType::SegmentReturnType
TempVecSegment;
206 Index n =
mat.cols();
207 eigen_assert(
mat.rows()==n && vec.size()==n);
216 temp = sqrt(sigma) * vec;
218 for(Index i=0; i<n; ++i)
221 g.makeGivens(
mat(i,i), -temp(i), &
mat(i,i));
228 apply_rotation_in_the_plane(x, y,
g);
236 for(Index j=0; j<n; ++j)
238 RealScalar Ljj = numext::real(mat.coeff(j,j));
239 RealScalar dj = numext::abs2(Ljj);
240 Scalar wj = temp.coeff(j);
241 RealScalar swj2 = sigma*numext::abs2(wj);
242 RealScalar gamma = dj*beta + swj2;
244 RealScalar x = dj + swj2/beta;
245 if (x<=RealScalar(0))
247 RealScalar nLjj = sqrt(x);
248 mat.coeffRef(j,j) = nLjj;
255 temp.tail(rs) -= (wj/Ljj) * mat.col(j).tail(rs);
257 mat.col(j).tail(rs) = (nLjj/Ljj) * mat.col(j).tail(rs) + (nLjj * sigma*numext::conj(wj)/gamma)*temp.tail(rs);
266 typedef typename NumTraits<Scalar>::Real
RealScalar;
267 template<
typename MatrixType>
268 static Index unblocked(MatrixType&
mat)
272 eigen_assert(
mat.rows()==
mat.cols());
273 const Index size =
mat.rows();
274 for(Index k = 0; k < size; ++k)
283 if (k>0) x -=
A10.squaredNorm();
286 mat.coeffRef(k,k) = x = sqrt(x);
287 if (k>0 && rs>0)
A21.noalias() -=
A20 *
A10.adjoint();
293 template<
typename MatrixType>
294 static Index blocked(MatrixType& m)
296 eigen_assert(m.rows()==m.cols());
297 Index size = m.rows();
312 Index rs = size - k -
bs;
318 if((ret=unblocked(
A11))>=0)
return k+ret;
325 template<
typename MatrixType,
typename VectorType>
326 static Index rankUpdate(MatrixType&
mat,
const VectorType& vec,
const RealScalar& sigma)
328 return Eigen::internal::llt_rank_update_lower(
mat, vec, sigma);
334 typedef typename NumTraits<Scalar>::Real
RealScalar;
336 template<
typename MatrixType>
337 static EIGEN_STRONG_INLINE Index unblocked(MatrixType&
mat)
342 template<
typename MatrixType>
343 static EIGEN_STRONG_INLINE Index blocked(MatrixType&
mat)
348 template<
typename MatrixType,
typename VectorType>
349 static Index rankUpdate(MatrixType&
mat,
const VectorType& vec,
const RealScalar& sigma)
360 static inline MatrixL getL(
const MatrixType& m) {
return MatrixL(m); }
361 static inline MatrixU getU(
const MatrixType& m) {
return MatrixU(m.adjoint()); }
362 static bool inplace_decomposition(MatrixType& m)
363 {
return llt_inplace<typename MatrixType::Scalar, Lower>::blocked(m)==-1; }
370 static inline MatrixL getL(
const MatrixType& m) {
return MatrixL(m.adjoint()); }
371 static inline MatrixU getU(
const MatrixType& m) {
return MatrixU(m); }
372 static bool inplace_decomposition(MatrixType& m)
385template<
typename MatrixType,
int _UpLo>
386template<
typename InputType>
389 check_template_parameters();
391 eigen_assert(a.rows()==a.cols());
392 const Index size = a.rows();
393 m_matrix.resize(size, size);
394 m_matrix = a.derived();
396 m_isInitialized =
true;
397 bool ok = Traits::inplace_decomposition(m_matrix);
408template<
typename _MatrixType,
int _UpLo>
409template<
typename VectorType>
412 EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorType);
413 eigen_assert(v.size()==m_matrix.cols());
414 eigen_assert(m_isInitialized);
423#ifndef EIGEN_PARSED_BY_DOXYGEN
424template<
typename _MatrixType,
int _UpLo>
425template<
typename RhsType,
typename DstType>
446template<
typename MatrixType,
int _UpLo>
447template<
typename Derived>
448void LLT<MatrixType,_UpLo>::solveInPlace(MatrixBase<Derived> &bAndX)
const
450 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
451 eigen_assert(m_matrix.rows()==bAndX.rows());
452 matrixL().solveInPlace(bAndX);
453 matrixU().solveInPlace(bAndX);
459template<
typename MatrixType,
int _UpLo>
462 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
463 return matrixL() * matrixL().adjoint().toDenseMatrix();
471template<
typename Derived>
482template<
typename MatrixType,
unsigned int UpLo>
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
Definition LLT.h:51
LLT()
Default Constructor.
Definition LLT.h:79
Traits::MatrixU matrixU() const
Definition LLT.h:99
const Solve< LLT, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition LLT.h:124
const MatrixType & matrixLLT() const
Definition LLT.h:142
Traits::MatrixL matrixL() const
Definition LLT.h:106
MatrixType reconstructedMatrix() const
Definition LLT.h:460
LLT(Index size)
Default Constructor with memory preallocation.
Definition LLT.h:87
Eigen::Index Index
Definition LLT.h:62
ComputationInfo info() const
Reports whether previous computation was successful.
Definition LLT.h:156
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
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
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
@ NumericalIssue
The provided data did not satisfy the prerequisites.
Definition Constants.h:434
@ Success
Computation was successful.
Definition Constants.h:432
Definition GenericPacketMath.h:90