16 template<
typename MatrixType,
int UpLo>
struct LLT_Traits;
50 template<
typename _MatrixType,
int _UpLo>
class LLT 55 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
56 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
57 Options = MatrixType::Options,
58 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
60 typedef typename MatrixType::Scalar
Scalar;
62 typedef typename MatrixType::Index
Index;
66 AlignmentMask = int(PacketSize)-1,
78 LLT() : m_matrix(), m_isInitialized(false) {}
86 LLT(Index size) : m_matrix(size, size),
87 m_isInitialized(false) {}
89 LLT(
const MatrixType& matrix)
90 : m_matrix(matrix.rows(), matrix.cols()),
91 m_isInitialized(false)
97 inline typename Traits::MatrixU
matrixU()
const 99 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
100 return Traits::getU(m_matrix);
104 inline typename Traits::MatrixL
matrixL()
const 106 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
107 return Traits::getL(m_matrix);
120 template<
typename Rhs>
124 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
126 &&
"LLT::solve(): invalid number of rows of the right hand side matrix b");
130 #ifdef EIGEN2_SUPPORT 131 template<
typename OtherDerived,
typename ResultType>
134 *result = this->solve(b);
138 bool isPositiveDefinite()
const {
return true; }
141 template<
typename Derived>
144 LLT& compute(
const MatrixType& matrix);
152 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
156 MatrixType reconstructedMatrix()
const;
166 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
170 inline Index
rows()
const {
return m_matrix.rows(); }
171 inline Index
cols()
const {
return m_matrix.cols(); }
173 template<
typename VectorType>
174 LLT rankUpdate(
const VectorType& vec,
const RealScalar& sigma = 1);
190 template<
typename MatrixType,
typename VectorType>
191 static typename MatrixType::Index
llt_rank_update_lower(MatrixType& mat,
const VectorType& vec,
const typename MatrixType::RealScalar& sigma)
194 typedef typename MatrixType::Scalar Scalar;
195 typedef typename MatrixType::RealScalar RealScalar;
196 typedef typename MatrixType::Index Index;
203 Index n = mat.cols();
213 temp =
sqrt(sigma) * vec;
215 for(Index i=0; i<n; ++i)
223 ColXprSegment
x(mat.col(i).tail(rs));
224 TempVecSegment
y(temp.tail(rs));
233 for(Index j=0; j<n; ++j)
237 Scalar wj = temp.coeff(j);
239 RealScalar gamma = dj*beta + swj2;
241 RealScalar
x = dj + swj2/beta;
242 if (x<=RealScalar(0))
244 RealScalar nLjj =
sqrt(x);
245 mat.coeffRef(j,j) = nLjj;
252 temp.tail(rs) -= (wj/Ljj) * mat.col(j).tail(rs);
254 mat.col(j).tail(rs) = (nLjj/Ljj) * mat.col(j).tail(rs) + (nLjj * sigma*numext::conj(wj)/gamma)*temp.tail(rs);
264 template<
typename MatrixType>
265 static typename MatrixType::Index
unblocked(MatrixType& mat)
268 typedef typename MatrixType::Index Index;
271 const Index size = mat.rows();
272 for(Index k = 0; k < size; ++k)
281 if (k>0) x -= A10.squaredNorm();
282 if (x<=RealScalar(0))
284 mat.coeffRef(k,k) = x =
sqrt(x);
285 if (k>0 && rs>0) A21.noalias() -= A20 * A10.adjoint();
286 if (rs>0) A21 *= RealScalar(1)/x;
291 template<
typename MatrixType>
292 static typename MatrixType::Index
blocked(MatrixType& m)
294 typedef typename MatrixType::Index Index;
296 Index size = m.rows();
300 Index blockSize = size/8;
301 blockSize = (blockSize/16)*16;
302 blockSize = (std::min)((std::max)(blockSize,Index(8)), Index(128));
304 for (Index k=0; k<size; k+=blockSize)
310 Index bs = (std::min)(blockSize, size-k);
311 Index rs = size - k - bs;
317 if((ret=unblocked(A11))>=0)
return k+ret;
318 if(rs>0) A11.adjoint().template triangularView<Upper>().
template solveInPlace<OnTheRight>(A21);
319 if(rs>0) A22.template selfadjointView<Lower>().rankUpdate(A21,-1);
324 template<
typename MatrixType,
typename VectorType>
325 static typename MatrixType::Index
rankUpdate(MatrixType& mat,
const VectorType& vec,
const RealScalar& sigma)
335 template<
typename MatrixType>
341 template<
typename MatrixType>
347 template<
typename MatrixType,
typename VectorType>
348 static typename MatrixType::Index
rankUpdate(MatrixType& mat,
const VectorType& vec,
const RealScalar& sigma)
359 static inline MatrixL
getL(
const MatrixType& m) {
return m; }
360 static inline MatrixU
getU(
const MatrixType& m) {
return m.
adjoint(); }
369 static inline MatrixL
getL(
const MatrixType& m) {
return m.
adjoint(); }
370 static inline MatrixU
getU(
const MatrixType& m) {
return m; }
384 template<
typename MatrixType,
int _UpLo>
388 const Index size = a.rows();
389 m_matrix.resize(size, size);
392 m_isInitialized =
true;
393 bool ok = Traits::inplace_decomposition(m_matrix);
404 template<
typename _MatrixType,
int _UpLo>
405 template<
typename VectorType>
420 template<
typename _MatrixType,
int UpLo,
typename Rhs>
427 template<typename Dest>
void evalTo(Dest& dst)
const 430 dec().solveInPlace(dst);
448 template<
typename MatrixType,
int _UpLo>
449 template<
typename Derived>
452 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
454 matrixL().solveInPlace(bAndX);
455 matrixU().solveInPlace(bAndX);
461 template<
typename MatrixType,
int _UpLo>
464 eigen_assert(m_isInitialized &&
"LLT is not initialized.");
465 return matrixL() * matrixL().adjoint().toDenseMatrix();
471 template<
typename Derived>
481 template<
typename MatrixType,
unsigned int UpLo>
490 #endif // EIGEN_LLT_H const LLT< PlainObject, UpLo > llt() const
MatrixType reconstructedMatrix() const
VectorBlock< Derived > SegmentReturnType
#define EIGEN_STRONG_INLINE
const TriangularView< const typename MatrixType::AdjointReturnType, TransposeMode > adjoint() const
const TriangularView< const MatrixType, Lower > MatrixL
void makeGivens(const Scalar &p, const Scalar &q, Scalar *z=0)
Expression of the transpose of a matrix.
Traits::MatrixU matrixU() const
MatrixType::Scalar Scalar
LLT(Index size)
Default Constructor with memory preallocation.
Block< Derived, internal::traits< Derived >::RowsAtCompileTime, 1,!IsRowMajor > ColXpr
const MatrixType & matrixLLT() const
Rotation given by a cosine-sine pair.
static bool inplace_decomposition(MatrixType &m)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
const TriangularView< const typename MatrixType::AdjointReturnType, Upper > MatrixU
static MatrixType::Index rankUpdate(MatrixType &mat, const VectorType &vec, const RealScalar &sigma)
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs2_op< Scalar >, const Derived > abs2() const
ComputationInfo info() const
Reports whether previous computation was successful.
void solveInPlace(MatrixBase< Derived > &bAndX) const
LLT< _MatrixType, UpLo > LLTType
LLT rankUpdate(const VectorType &vec, const RealScalar &sigma=1)
RealReturnType real() const
LLT(const MatrixType &matrix)
static MatrixType::Index rankUpdate(MatrixType &mat, const VectorType &vec, const RealScalar &sigma)
internal::LLT_Traits< MatrixType, UpLo > Traits
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
NumTraits< Scalar >::Real RealScalar
static MatrixType::Index blocked(MatrixType &m)
TFSIMD_FORCE_INLINE const tfScalar & x() const
static EIGEN_STRONG_INLINE MatrixType::Index blocked(MatrixType &mat)
static bool inplace_decomposition(MatrixType &m)
Expression of a fixed-size or dynamic-size block.
void apply_rotation_in_the_plane(VectorX &_x, VectorY &_y, const JacobiRotation< OtherScalar > &j)
static MatrixU getU(const MatrixType &m)
const internal::solve_retval< LLT, Rhs > solve(const MatrixBase< Rhs > &b) const
static MatrixU getU(const MatrixType &m)
static MatrixType::Index unblocked(MatrixType &mat)
Base class for triangular part in a matrix.
const TriangularView< const MatrixType, Upper > MatrixU
LLT & compute(const MatrixType &matrix)
const TriangularView< const typename MatrixType::AdjointReturnType, Lower > MatrixL
#define EIGEN_MAKE_SOLVE_HELPERS(DecompositionType, Rhs)
const LLT< PlainObject > llt() const
LLT()
Default Constructor.
const CwiseUnaryOp< internal::scalar_sqrt_op< Scalar >, const Derived > sqrt() const
Traits::MatrixL matrixL() const
static MatrixL getL(const MatrixType &m)
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Base class for all dense matrices, vectors, and expressions.
static EIGEN_STRONG_INLINE MatrixType::Index unblocked(MatrixType &mat)
static MatrixL getL(const MatrixType &m)
NumTraits< typename MatrixType::Scalar >::Real RealScalar
static MatrixType::Index llt_rank_update_lower(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma)
NumTraits< Scalar >::Real RealScalar