358 temp.head(k) = mat.diagonal().real().head(k).asDiagonal() * A10.adjoint();
359 mat.coeffRef(k,k) -= (A10 * temp.head(k)).value();
361 A21.noalias() -= A20 * temp.head(k);
368 RealScalar realAkk = numext::real(mat.coeffRef(k,k));
369 bool pivot_is_valid = (
abs(realAkk) > RealScalar(0));
371 if(k==0 && !pivot_is_valid)
376 for(
Index j = 0; j<size; ++j)
378 transpositions.coeffRef(j) = IndexType(j);
379 ret = ret && (mat.col(j).tail(size-j-1).array()==
Scalar(0)).all();
384 if((rs>0) && pivot_is_valid)
387 ret = ret && (A21.array()==Scalar(0)).all();
389 if(found_zero_pivot && pivot_is_valid) ret =
false;
390 else if(!pivot_is_valid) found_zero_pivot =
true;
392 if (sign == PositiveSemiDef) {
393 if (realAkk <
static_cast<RealScalar
>(0))
sign = Indefinite;
394 }
else if (sign == NegativeSemiDef) {
395 if (realAkk >
static_cast<RealScalar
>(0))
sign = Indefinite;
396 }
else if (sign == ZeroSign) {
397 if (realAkk >
static_cast<RealScalar
>(0))
sign = PositiveSemiDef;
398 else if (realAkk <
static_cast<RealScalar
>(0))
sign = NegativeSemiDef;
412 template<
typename MatrixType,
typename WDerived>
413 static bool updateInPlace(MatrixType& mat, MatrixBase<WDerived>& w,
const typename MatrixType::RealScalar& sigma=1)
415 using numext::isfinite;
416 typedef typename MatrixType::Scalar Scalar;
417 typedef typename MatrixType::RealScalar RealScalar;
419 const Index size = mat.rows();
420 eigen_assert(mat.cols() == size && w.size()==size);
422 RealScalar alpha = 1;
425 for (
Index j = 0; j < size; j++)
432 RealScalar dj = numext::real(mat.coeff(j,j));
433 Scalar wj = w.coeff(j);
434 RealScalar swj2 = sigma*numext::abs2(wj);
435 RealScalar gamma = dj*alpha + swj2;
437 mat.coeffRef(j,j) += swj2/alpha;
443 w.tail(rs) -= wj * mat.col(j).tail(rs);
445 mat.col(j).tail(rs) += (sigma*numext::conj(wj)/gamma)*w.tail(rs);
450 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
451 static bool update(MatrixType& mat,
const TranspositionType& transpositions, Workspace& tmp,
const WType& w,
const typename MatrixType::RealScalar& sigma=1)
454 tmp = transpositions * w;
456 return ldlt_inplace<Lower>::updateInPlace(mat,tmp,sigma);
460template<>
struct ldlt_inplace<
Upper>
462 template<
typename MatrixType,
typename TranspositionType,
typename Workspace>
463 static EIGEN_STRONG_INLINE
bool unblocked(MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign)
465 Transpose<MatrixType> matt(mat);
466 return ldlt_inplace<Lower>::unblocked(matt, transpositions, temp, sign);
469 template<
typename MatrixType,
typename TranspositionType,
typename Workspace,
typename WType>
470 static EIGEN_STRONG_INLINE
bool update(MatrixType& mat, TranspositionType& transpositions, Workspace& tmp, WType& w,
const typename MatrixType::RealScalar& sigma=1)
472 Transpose<MatrixType> matt(mat);
473 return ldlt_inplace<Lower>::update(matt, transpositions, tmp, w.conjugate(), sigma);
477template<
typename MatrixType>
struct LDLT_Traits<MatrixType,
Lower>
479 typedef const TriangularView<const MatrixType, UnitLower> MatrixL;
480 typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitUpper> MatrixU;
481 static inline MatrixL getL(
const MatrixType& m) {
return MatrixL(m); }
482 static inline MatrixU getU(
const MatrixType& m) {
return MatrixU(m.adjoint()); }
485template<
typename MatrixType>
struct LDLT_Traits<MatrixType,
Upper>
487 typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitLower> MatrixL;
488 typedef const TriangularView<const MatrixType, UnitUpper> MatrixU;
489 static inline MatrixL getL(
const MatrixType& m) {
return MatrixL(m.adjoint()); }
490 static inline MatrixU getU(
const MatrixType& m) {
return MatrixU(m); }
497template<
typename MatrixType,
int _UpLo>
498template<
typename InputType>
501 check_template_parameters();
509 m_l1_norm = RealScalar(0);
512 RealScalar abs_col_sum;
514 abs_col_sum = m_matrix.col(col).tail(
size - col).template lpNorm<1>() + m_matrix.row(col).head(col).template lpNorm<1>();
516 abs_col_sum = m_matrix.col(col).head(col).template lpNorm<1>() + m_matrix.row(col).tail(
size - col).template lpNorm<1>();
517 if (abs_col_sum > m_l1_norm)
518 m_l1_norm = abs_col_sum;
521 m_transpositions.resize(
size);
522 m_isInitialized =
false;
523 m_temporary.resize(
size);
524 m_sign = internal::ZeroSign;
526 m_info = internal::ldlt_inplace<UpLo>::unblocked(m_matrix, m_transpositions, m_temporary, m_sign) ?
Success :
NumericalIssue;
528 m_isInitialized =
true;
537template<
typename MatrixType,
int _UpLo>
538template<
typename Derived>
541 typedef typename TranspositionType::StorageIndex IndexType;
545 eigen_assert(m_matrix.rows()==
size);
551 m_transpositions.resize(
size);
553 m_transpositions.coeffRef(i) = IndexType(i);
554 m_temporary.resize(
size);
555 m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef;
556 m_isInitialized =
true;
559 internal::ldlt_inplace<UpLo>::update(m_matrix, m_transpositions, m_temporary, w, sigma);
564#ifndef EIGEN_PARSED_BY_DOXYGEN
565template<
typename _MatrixType,
int _UpLo>
566template<
typename RhsType,
typename DstType>
569 _solve_impl_transposed<true>(rhs, dst);
572template<
typename _MatrixType,
int _UpLo>
573template<
bool Conjugate,
typename RhsType,
typename DstType>
574void LDLT<_MatrixType,_UpLo>::_solve_impl_transposed(
const RhsType &rhs, DstType &dst)
const
577 dst = m_transpositions * rhs;
581 matrixL().template conjugateIf<!Conjugate>().solveInPlace(dst);
587 const typename Diagonal<const MatrixType>::RealReturnType vecD(vectorD());
595 RealScalar tolerance = (std::numeric_limits<RealScalar>::min)();
596 for (Index i = 0; i < vecD.size(); ++i)
598 if(abs(vecD(i)) > tolerance)
599 dst.row(i) /= vecD(i);
601 dst.row(i).setZero();
606 matrixL().transpose().template conjugateIf<Conjugate>().solveInPlace(dst);
610 dst = m_transpositions.transpose() * dst;
627template<
typename MatrixType,
int _UpLo>
628template<
typename Derived>
631 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
632 eigen_assert(m_matrix.rows() == bAndX.rows());
634 bAndX = this->solve(bAndX);
642template<
typename MatrixType,
int _UpLo>
645 eigen_assert(m_isInitialized &&
"LDLT is not initialized.");
655 res =
vectorD().real().asDiagonal() * res;
668template<
typename MatrixType,
unsigned int UpLo>
679template<
typename Derived>