Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
SimplicialCholesky.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2012 Gael Guennebaud <[email protected]>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_SIMPLICIAL_CHOLESKY_H
11#define EIGEN_SIMPLICIAL_CHOLESKY_H
12
13// IWYU pragma: private
14#include "./InternalHeaderCheck.h"
15
16namespace Eigen {
17
18enum SimplicialCholeskyMode { SimplicialCholeskyLLT, SimplicialCholeskyLDLT };
19
20namespace internal {
21template <typename CholMatrixType, typename InputMatrixType>
22struct simplicial_cholesky_grab_input {
23 typedef CholMatrixType const* ConstCholMatrixPtr;
24 static void run(const InputMatrixType& input, ConstCholMatrixPtr& pmat, CholMatrixType& tmp) {
25 tmp = input;
26 pmat = &tmp;
27 }
28};
29
30template <typename MatrixType>
31struct simplicial_cholesky_grab_input<MatrixType, MatrixType> {
32 typedef MatrixType const* ConstMatrixPtr;
33 static void run(const MatrixType& input, ConstMatrixPtr& pmat, MatrixType& /*tmp*/) { pmat = &input; }
34};
35} // end namespace internal
36
50template <typename Derived>
53 using Base::m_isInitialized;
54
55 public:
56 typedef typename internal::traits<Derived>::MatrixType MatrixType;
57 typedef typename internal::traits<Derived>::OrderingType OrderingType;
58 enum { UpLo = internal::traits<Derived>::UpLo };
59 typedef typename MatrixType::Scalar Scalar;
60 typedef typename MatrixType::RealScalar RealScalar;
61 typedef typename internal::traits<Derived>::DiagonalScalar DiagonalScalar;
62 typedef typename MatrixType::StorageIndex StorageIndex;
64 typedef CholMatrixType const* ConstCholMatrixPtr;
67
68 enum { ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime };
69
70 public:
71 using Base::derived;
72
75 : m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false), m_shiftOffset(0), m_shiftScale(1) {}
76
77 explicit SimplicialCholeskyBase(const MatrixType& matrix)
78 : m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false), m_shiftOffset(0), m_shiftScale(1) {
79 derived().compute(matrix);
80 }
81
82 ~SimplicialCholeskyBase() {}
83
84 Derived& derived() { return *static_cast<Derived*>(this); }
85 const Derived& derived() const { return *static_cast<const Derived*>(this); }
86
87 inline Index cols() const { return m_matrix.cols(); }
88 inline Index rows() const { return m_matrix.rows(); }
89
96 eigen_assert(m_isInitialized && "Decomposition is not initialized.");
97 return m_info;
98 }
99
103
107
118 Derived& setShift(const DiagonalScalar& offset, const DiagonalScalar& scale = 1) {
119 m_shiftOffset = offset;
120 m_shiftScale = scale;
121 return derived();
122 }
123
124#ifndef EIGEN_PARSED_BY_DOXYGEN
126 template <typename Stream>
127 void dumpMemory(Stream& s) {
128 int total = 0;
129 s << " L: "
130 << ((total += (m_matrix.cols() + 1) * sizeof(int) + m_matrix.nonZeros() * (sizeof(int) + sizeof(Scalar))) >> 20)
131 << "Mb"
132 << "\n";
133 s << " diag: " << ((total += m_diag.size() * sizeof(Scalar)) >> 20) << "Mb"
134 << "\n";
135 s << " tree: " << ((total += m_parent.size() * sizeof(int)) >> 20) << "Mb"
136 << "\n";
137 s << " nonzeros: " << ((total += m_nonZerosPerCol.size() * sizeof(int)) >> 20) << "Mb"
138 << "\n";
139 s << " perm: " << ((total += m_P.size() * sizeof(int)) >> 20) << "Mb"
140 << "\n";
141 s << " perm^-1: " << ((total += m_Pinv.size() * sizeof(int)) >> 20) << "Mb"
142 << "\n";
143 s << " TOTAL: " << (total >> 20) << "Mb"
144 << "\n";
145 }
146
148 template <typename Rhs, typename Dest>
149 void _solve_impl(const MatrixBase<Rhs>& b, MatrixBase<Dest>& dest) const {
150 eigen_assert(m_factorizationIsOk &&
151 "The decomposition is not in a valid state for solving, you must first call either compute() or "
152 "symbolic()/numeric()");
153 eigen_assert(m_matrix.rows() == b.rows());
154
155 if (m_info != Success) return;
156
157 if (m_P.size() > 0)
158 dest = m_P * b;
159 else
160 dest = b;
161
162 if (m_matrix.nonZeros() > 0) // otherwise L==I
163 derived().matrixL().solveInPlace(dest);
164
165 if (m_diag.size() > 0) dest = m_diag.asDiagonal().inverse() * dest;
166
167 if (m_matrix.nonZeros() > 0) // otherwise U==I
168 derived().matrixU().solveInPlace(dest);
169
170 if (m_P.size() > 0) dest = m_Pinv * dest;
171 }
172
173 template <typename Rhs, typename Dest>
174 void _solve_impl(const SparseMatrixBase<Rhs>& b, SparseMatrixBase<Dest>& dest) const {
175 internal::solve_sparse_through_dense_panels(derived(), b, dest);
176 }
177
178#endif // EIGEN_PARSED_BY_DOXYGEN
179
180 protected:
182 template <bool DoLDLT, bool NonHermitian>
183 void compute(const MatrixType& matrix) {
184 eigen_assert(matrix.rows() == matrix.cols());
185 Index size = matrix.cols();
186 CholMatrixType tmp(size, size);
187 ConstCholMatrixPtr pmat;
188 ordering<NonHermitian>(matrix, pmat, tmp);
189 analyzePattern_preordered(*pmat, DoLDLT);
190 factorize_preordered<DoLDLT, NonHermitian>(*pmat);
191 }
192
193 template <bool DoLDLT, bool NonHermitian>
194 void factorize(const MatrixType& a) {
195 eigen_assert(a.rows() == a.cols());
196 Index size = a.cols();
197 CholMatrixType tmp(size, size);
198 ConstCholMatrixPtr pmat;
199
200 if (m_P.size() == 0 && (int(UpLo) & int(Upper)) == Upper) {
201 // If there is no ordering, try to directly use the input matrix without any copy
202 internal::simplicial_cholesky_grab_input<CholMatrixType, MatrixType>::run(a, pmat, tmp);
203 } else {
204 internal::permute_symm_to_symm<UpLo, Upper, NonHermitian>(a, tmp, m_P.indices().data());
205 pmat = &tmp;
206 }
207
208 factorize_preordered<DoLDLT, NonHermitian>(*pmat);
209 }
210
211 template <bool DoLDLT, bool NonHermitian>
212 void factorize_preordered(const CholMatrixType& a);
213
214 template <bool DoLDLT, bool NonHermitian>
215 void analyzePattern(const MatrixType& a) {
216 eigen_assert(a.rows() == a.cols());
217 Index size = a.cols();
218 CholMatrixType tmp(size, size);
219 ConstCholMatrixPtr pmat;
220 ordering<NonHermitian>(a, pmat, tmp);
221 analyzePattern_preordered(*pmat, DoLDLT);
222 }
223 void analyzePattern_preordered(const CholMatrixType& a, bool doLDLT);
224
225 template <bool NonHermitian>
226 void ordering(const MatrixType& a, ConstCholMatrixPtr& pmat, CholMatrixType& ap);
227
228 inline DiagonalScalar getDiag(Scalar x) { return internal::traits<Derived>::getDiag(x); }
229 inline Scalar getSymm(Scalar x) { return internal::traits<Derived>::getSymm(x); }
230
232 struct keep_diag {
233 inline bool operator()(const Index& row, const Index& col, const Scalar&) const { return row != col; }
234 };
235
236 mutable ComputationInfo m_info;
237 bool m_factorizationIsOk;
238 bool m_analysisIsOk;
239
240 CholMatrixType m_matrix;
241 VectorType m_diag; // the diagonal coefficients (LDLT mode)
242 VectorI m_parent; // elimination tree
243 VectorI m_nonZerosPerCol;
245 PermutationMatrix<Dynamic, Dynamic, StorageIndex> m_Pinv; // the inverse permutation
246
247 DiagonalScalar m_shiftOffset;
248 DiagonalScalar m_shiftScale;
249};
250
251template <typename MatrixType_, int UpLo_ = Lower,
253class SimplicialLLT;
254template <typename MatrixType_, int UpLo_ = Lower,
256class SimplicialLDLT;
257template <typename MatrixType_, int UpLo_ = Lower,
260template <typename MatrixType_, int UpLo_ = Lower,
263template <typename MatrixType_, int UpLo_ = Lower,
266
267namespace internal {
268
269template <typename MatrixType_, int UpLo_, typename Ordering_>
270struct traits<SimplicialLLT<MatrixType_, UpLo_, Ordering_> > {
271 typedef MatrixType_ MatrixType;
272 typedef Ordering_ OrderingType;
273 enum { UpLo = UpLo_ };
274 typedef typename MatrixType::Scalar Scalar;
275 typedef typename MatrixType::RealScalar DiagonalScalar;
276 typedef typename MatrixType::StorageIndex StorageIndex;
277 typedef SparseMatrix<Scalar, ColMajor, StorageIndex> CholMatrixType;
278 typedef TriangularView<const CholMatrixType, Eigen::Lower> MatrixL;
279 typedef TriangularView<const typename CholMatrixType::AdjointReturnType, Eigen::Upper> MatrixU;
280 static inline MatrixL getL(const CholMatrixType& m) { return MatrixL(m); }
281 static inline MatrixU getU(const CholMatrixType& m) { return MatrixU(m.adjoint()); }
282 static inline DiagonalScalar getDiag(Scalar x) { return numext::real(x); }
283 static inline Scalar getSymm(Scalar x) { return numext::conj(x); }
284};
285
286template <typename MatrixType_, int UpLo_, typename Ordering_>
287struct traits<SimplicialLDLT<MatrixType_, UpLo_, Ordering_> > {
288 typedef MatrixType_ MatrixType;
289 typedef Ordering_ OrderingType;
290 enum { UpLo = UpLo_ };
291 typedef typename MatrixType::Scalar Scalar;
292 typedef typename MatrixType::RealScalar DiagonalScalar;
293 typedef typename MatrixType::StorageIndex StorageIndex;
294 typedef SparseMatrix<Scalar, ColMajor, StorageIndex> CholMatrixType;
295 typedef TriangularView<const CholMatrixType, Eigen::UnitLower> MatrixL;
296 typedef TriangularView<const typename CholMatrixType::AdjointReturnType, Eigen::UnitUpper> MatrixU;
297 static inline MatrixL getL(const CholMatrixType& m) { return MatrixL(m); }
298 static inline MatrixU getU(const CholMatrixType& m) { return MatrixU(m.adjoint()); }
299 static inline DiagonalScalar getDiag(Scalar x) { return numext::real(x); }
300 static inline Scalar getSymm(Scalar x) { return numext::conj(x); }
301};
302
303template <typename MatrixType_, int UpLo_, typename Ordering_>
304struct traits<SimplicialNonHermitianLLT<MatrixType_, UpLo_, Ordering_> > {
305 typedef MatrixType_ MatrixType;
306 typedef Ordering_ OrderingType;
307 enum { UpLo = UpLo_ };
308 typedef typename MatrixType::Scalar Scalar;
309 typedef typename MatrixType::Scalar DiagonalScalar;
310 typedef typename MatrixType::StorageIndex StorageIndex;
311 typedef SparseMatrix<Scalar, ColMajor, StorageIndex> CholMatrixType;
312 typedef TriangularView<const CholMatrixType, Eigen::Lower> MatrixL;
313 typedef TriangularView<const typename CholMatrixType::ConstTransposeReturnType, Eigen::Upper> MatrixU;
314 static inline MatrixL getL(const CholMatrixType& m) { return MatrixL(m); }
315 static inline MatrixU getU(const CholMatrixType& m) { return MatrixU(m.transpose()); }
316 static inline DiagonalScalar getDiag(Scalar x) { return x; }
317 static inline Scalar getSymm(Scalar x) { return x; }
318};
319
320template <typename MatrixType_, int UpLo_, typename Ordering_>
321struct traits<SimplicialNonHermitianLDLT<MatrixType_, UpLo_, Ordering_> > {
322 typedef MatrixType_ MatrixType;
323 typedef Ordering_ OrderingType;
324 enum { UpLo = UpLo_ };
325 typedef typename MatrixType::Scalar Scalar;
326 typedef typename MatrixType::Scalar DiagonalScalar;
327 typedef typename MatrixType::StorageIndex StorageIndex;
328 typedef SparseMatrix<Scalar, ColMajor, StorageIndex> CholMatrixType;
329 typedef TriangularView<const CholMatrixType, Eigen::UnitLower> MatrixL;
330 typedef TriangularView<const typename CholMatrixType::ConstTransposeReturnType, Eigen::UnitUpper> MatrixU;
331 static inline MatrixL getL(const CholMatrixType& m) { return MatrixL(m); }
332 static inline MatrixU getU(const CholMatrixType& m) { return MatrixU(m.transpose()); }
333 static inline DiagonalScalar getDiag(Scalar x) { return x; }
334 static inline Scalar getSymm(Scalar x) { return x; }
335};
336
337template <typename MatrixType_, int UpLo_, typename Ordering_>
338struct traits<SimplicialCholesky<MatrixType_, UpLo_, Ordering_> > {
339 typedef MatrixType_ MatrixType;
340 typedef Ordering_ OrderingType;
341 enum { UpLo = UpLo_ };
342 typedef typename MatrixType::Scalar Scalar;
343 typedef typename MatrixType::RealScalar DiagonalScalar;
344 static inline DiagonalScalar getDiag(Scalar x) { return numext::real(x); }
345 static inline Scalar getSymm(Scalar x) { return numext::conj(x); }
346};
347
348} // namespace internal
349
370template <typename MatrixType_, int UpLo_, typename Ordering_>
371class SimplicialLLT : public SimplicialCholeskyBase<SimplicialLLT<MatrixType_, UpLo_, Ordering_> > {
372 public:
373 typedef MatrixType_ MatrixType;
374 enum { UpLo = UpLo_ };
376 typedef typename MatrixType::Scalar Scalar;
377 typedef typename MatrixType::RealScalar RealScalar;
378 typedef typename MatrixType::StorageIndex StorageIndex;
381 typedef internal::traits<SimplicialLLT> Traits;
382 typedef typename Traits::MatrixL MatrixL;
383 typedef typename Traits::MatrixU MatrixU;
384
385 public:
389 explicit SimplicialLLT(const MatrixType& matrix) : Base(matrix) {}
390
392 inline const MatrixL matrixL() const {
393 eigen_assert(Base::m_factorizationIsOk && "Simplicial LLT not factorized");
394 return Traits::getL(Base::m_matrix);
395 }
396
398 inline const MatrixU matrixU() const {
399 eigen_assert(Base::m_factorizationIsOk && "Simplicial LLT not factorized");
400 return Traits::getU(Base::m_matrix);
401 }
402
404 SimplicialLLT& compute(const MatrixType& matrix) {
405 Base::template compute<false, false>(matrix);
406 return *this;
407 }
408
415 void analyzePattern(const MatrixType& a) { Base::template analyzePattern<false, false>(a); }
416
423 void factorize(const MatrixType& a) { Base::template factorize<false, false>(a); }
424
426 Scalar determinant() const {
427 Scalar detL = Base::m_matrix.diagonal().prod();
428 return numext::abs2(detL);
429 }
430};
431
452template <typename MatrixType_, int UpLo_, typename Ordering_>
453class SimplicialLDLT : public SimplicialCholeskyBase<SimplicialLDLT<MatrixType_, UpLo_, Ordering_> > {
454 public:
455 typedef MatrixType_ MatrixType;
456 enum { UpLo = UpLo_ };
458 typedef typename MatrixType::Scalar Scalar;
459 typedef typename MatrixType::RealScalar RealScalar;
460 typedef typename MatrixType::StorageIndex StorageIndex;
463 typedef internal::traits<SimplicialLDLT> Traits;
464 typedef typename Traits::MatrixL MatrixL;
465 typedef typename Traits::MatrixU MatrixU;
466
467 public:
470
472 explicit SimplicialLDLT(const MatrixType& matrix) : Base(matrix) {}
473
475 inline const VectorType vectorD() const {
476 eigen_assert(Base::m_factorizationIsOk && "Simplicial LDLT not factorized");
477 return Base::m_diag;
478 }
480 inline const MatrixL matrixL() const {
481 eigen_assert(Base::m_factorizationIsOk && "Simplicial LDLT not factorized");
482 return Traits::getL(Base::m_matrix);
483 }
484
486 inline const MatrixU matrixU() const {
487 eigen_assert(Base::m_factorizationIsOk && "Simplicial LDLT not factorized");
488 return Traits::getU(Base::m_matrix);
489 }
490
492 SimplicialLDLT& compute(const MatrixType& matrix) {
493 Base::template compute<true, false>(matrix);
494 return *this;
495 }
496
503 void analyzePattern(const MatrixType& a) { Base::template analyzePattern<true, false>(a); }
504
511 void factorize(const MatrixType& a) { Base::template factorize<true, false>(a); }
512
514 Scalar determinant() const { return Base::m_diag.prod(); }
515};
516
537template <typename MatrixType_, int UpLo_, typename Ordering_>
539 : public SimplicialCholeskyBase<SimplicialNonHermitianLLT<MatrixType_, UpLo_, Ordering_> > {
540 public:
541 typedef MatrixType_ MatrixType;
542 enum { UpLo = UpLo_ };
544 typedef typename MatrixType::Scalar Scalar;
545 typedef typename MatrixType::RealScalar RealScalar;
546 typedef typename MatrixType::StorageIndex StorageIndex;
549 typedef internal::traits<SimplicialNonHermitianLLT> Traits;
550 typedef typename Traits::MatrixL MatrixL;
551 typedef typename Traits::MatrixU MatrixU;
552
553 public:
556
558 explicit SimplicialNonHermitianLLT(const MatrixType& matrix) : Base(matrix) {}
559
561 inline const MatrixL matrixL() const {
562 eigen_assert(Base::m_factorizationIsOk && "Simplicial LLT not factorized");
563 return Traits::getL(Base::m_matrix);
564 }
565
567 inline const MatrixU matrixU() const {
568 eigen_assert(Base::m_factorizationIsOk && "Simplicial LLT not factorized");
569 return Traits::getU(Base::m_matrix);
570 }
571
573 SimplicialNonHermitianLLT& compute(const MatrixType& matrix) {
574 Base::template compute<false, true>(matrix);
575 return *this;
576 }
577
584 void analyzePattern(const MatrixType& a) { Base::template analyzePattern<false, true>(a); }
585
592 void factorize(const MatrixType& a) { Base::template factorize<false, true>(a); }
593
595 Scalar determinant() const {
596 Scalar detL = Base::m_matrix.diagonal().prod();
597 return detL * detL;
598 }
599};
600
621template <typename MatrixType_, int UpLo_, typename Ordering_>
623 : public SimplicialCholeskyBase<SimplicialNonHermitianLDLT<MatrixType_, UpLo_, Ordering_> > {
624 public:
625 typedef MatrixType_ MatrixType;
626 enum { UpLo = UpLo_ };
628 typedef typename MatrixType::Scalar Scalar;
629 typedef typename MatrixType::RealScalar RealScalar;
630 typedef typename MatrixType::StorageIndex StorageIndex;
633 typedef internal::traits<SimplicialNonHermitianLDLT> Traits;
634 typedef typename Traits::MatrixL MatrixL;
635 typedef typename Traits::MatrixU MatrixU;
636
637 public:
640
642 explicit SimplicialNonHermitianLDLT(const MatrixType& matrix) : Base(matrix) {}
643
645 inline const VectorType vectorD() const {
646 eigen_assert(Base::m_factorizationIsOk && "Simplicial LDLT not factorized");
647 return Base::m_diag;
648 }
650 inline const MatrixL matrixL() const {
651 eigen_assert(Base::m_factorizationIsOk && "Simplicial LDLT not factorized");
652 return Traits::getL(Base::m_matrix);
653 }
654
656 inline const MatrixU matrixU() const {
657 eigen_assert(Base::m_factorizationIsOk && "Simplicial LDLT not factorized");
658 return Traits::getU(Base::m_matrix);
659 }
660
662 SimplicialNonHermitianLDLT& compute(const MatrixType& matrix) {
663 Base::template compute<true, true>(matrix);
664 return *this;
665 }
666
673 void analyzePattern(const MatrixType& a) { Base::template analyzePattern<true, true>(a); }
674
681 void factorize(const MatrixType& a) { Base::template factorize<true, true>(a); }
682
684 Scalar determinant() const { return Base::m_diag.prod(); }
685};
686
693template <typename MatrixType_, int UpLo_, typename Ordering_>
694class SimplicialCholesky : public SimplicialCholeskyBase<SimplicialCholesky<MatrixType_, UpLo_, Ordering_> > {
695 public:
696 typedef MatrixType_ MatrixType;
697 enum { UpLo = UpLo_ };
699 typedef typename MatrixType::Scalar Scalar;
700 typedef typename MatrixType::RealScalar RealScalar;
701 typedef typename MatrixType::StorageIndex StorageIndex;
704 typedef internal::traits<SimplicialLDLT<MatrixType, UpLo> > LDLTTraits;
705 typedef internal::traits<SimplicialLLT<MatrixType, UpLo> > LLTTraits;
706
707 public:
708 SimplicialCholesky() : Base(), m_LDLT(true) {}
709
710 explicit SimplicialCholesky(const MatrixType& matrix) : Base(), m_LDLT(true) { compute(matrix); }
711
712 SimplicialCholesky& setMode(SimplicialCholeskyMode mode) {
713 switch (mode) {
714 case SimplicialCholeskyLLT:
715 m_LDLT = false;
716 break;
717 case SimplicialCholeskyLDLT:
718 m_LDLT = true;
719 break;
720 default:
721 break;
722 }
723
724 return *this;
725 }
726
727 inline const VectorType vectorD() const {
728 eigen_assert(Base::m_factorizationIsOk && "Simplicial Cholesky not factorized");
729 return Base::m_diag;
730 }
731 inline const CholMatrixType rawMatrix() const {
732 eigen_assert(Base::m_factorizationIsOk && "Simplicial Cholesky not factorized");
733 return Base::m_matrix;
734 }
735
737 SimplicialCholesky& compute(const MatrixType& matrix) {
738 if (m_LDLT)
739 Base::template compute<true, false>(matrix);
740 else
741 Base::template compute<false, false>(matrix);
742 return *this;
743 }
744
751 void analyzePattern(const MatrixType& a) {
752 if (m_LDLT)
753 Base::template analyzePattern<true, false>(a);
754 else
755 Base::template analyzePattern<false, false>(a);
756 }
757
764 void factorize(const MatrixType& a) {
765 if (m_LDLT)
766 Base::template factorize<true, false>(a);
767 else
768 Base::template factorize<false, false>(a);
769 }
770
772 template <typename Rhs, typename Dest>
773 void _solve_impl(const MatrixBase<Rhs>& b, MatrixBase<Dest>& dest) const {
774 eigen_assert(Base::m_factorizationIsOk &&
775 "The decomposition is not in a valid state for solving, you must first call either compute() or "
776 "symbolic()/numeric()");
777 eigen_assert(Base::m_matrix.rows() == b.rows());
778
779 if (Base::m_info != Success) return;
780
781 if (Base::m_P.size() > 0)
782 dest = Base::m_P * b;
783 else
784 dest = b;
785
786 if (Base::m_matrix.nonZeros() > 0) // otherwise L==I
787 {
788 if (m_LDLT)
789 LDLTTraits::getL(Base::m_matrix).solveInPlace(dest);
790 else
791 LLTTraits::getL(Base::m_matrix).solveInPlace(dest);
792 }
793
794 if (Base::m_diag.size() > 0) dest = Base::m_diag.real().asDiagonal().inverse() * dest;
795
796 if (Base::m_matrix.nonZeros() > 0) // otherwise I==I
797 {
798 if (m_LDLT)
799 LDLTTraits::getU(Base::m_matrix).solveInPlace(dest);
800 else
801 LLTTraits::getU(Base::m_matrix).solveInPlace(dest);
802 }
803
804 if (Base::m_P.size() > 0) dest = Base::m_Pinv * dest;
805 }
806
808 template <typename Rhs, typename Dest>
809 void _solve_impl(const SparseMatrixBase<Rhs>& b, SparseMatrixBase<Dest>& dest) const {
810 internal::solve_sparse_through_dense_panels(*this, b, dest);
811 }
812
813 Scalar determinant() const {
814 if (m_LDLT) {
815 return Base::m_diag.prod();
816 } else {
817 Scalar detL = Diagonal<const CholMatrixType>(Base::m_matrix).prod();
818 return numext::abs2(detL);
819 }
820 }
821
822 protected:
823 bool m_LDLT;
824};
825
826template <typename Derived>
827template <bool NonHermitian>
828void SimplicialCholeskyBase<Derived>::ordering(const MatrixType& a, ConstCholMatrixPtr& pmat, CholMatrixType& ap) {
829 eigen_assert(a.rows() == a.cols());
830 const Index size = a.rows();
831 pmat = &ap;
832 // Note that ordering methods compute the inverse permutation
833 if (!internal::is_same<OrderingType, NaturalOrdering<Index> >::value) {
834 {
835 CholMatrixType C;
836 internal::permute_symm_to_fullsymm<UpLo, NonHermitian>(a, C, NULL);
837
838 OrderingType ordering;
839 ordering(C, m_Pinv);
840 }
841
842 if (m_Pinv.size() > 0)
843 m_P = m_Pinv.inverse();
844 else
845 m_P.resize(0);
846
847 ap.resize(size, size);
848 internal::permute_symm_to_symm<UpLo, Upper, NonHermitian>(a, ap, m_P.indices().data());
849 } else {
850 m_Pinv.resize(0);
851 m_P.resize(0);
852 if (int(UpLo) == int(Lower) || MatrixType::IsRowMajor) {
853 // we have to transpose the lower part to to the upper one
854 ap.resize(size, size);
855 internal::permute_symm_to_symm<UpLo, Upper, NonHermitian>(a, ap, NULL);
856 } else
857 internal::simplicial_cholesky_grab_input<CholMatrixType, MatrixType>::run(a, pmat, ap);
858 }
859}
860
861} // end namespace Eigen
862
863#endif // EIGEN_SIMPLICIAL_CHOLESKY_H
Definition Ordering.h:50
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition EigenBase.h:59
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
const DiagonalWrapper< const Derived > asDiagonal() const
Definition DiagonalMatrix.h:344
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
Index size() const
Definition PermutationMatrix.h:96
Permutation matrix.
Definition PermutationMatrix.h:280
const IndicesType & indices() const
Definition PermutationMatrix.h:334
A base class for direct sparse Cholesky factorizations.
Definition SimplicialCholesky.h:51
SimplicialCholeskyBase()
Definition SimplicialCholesky.h:74
void compute(const MatrixType &matrix)
Definition SimplicialCholesky.h:183
ComputationInfo info() const
Reports whether previous computation was successful.
Definition SimplicialCholesky.h:95
const PermutationMatrix< Dynamic, Dynamic, StorageIndex > & permutationP() const
Definition SimplicialCholesky.h:102
Derived & setShift(const DiagonalScalar &offset, const DiagonalScalar &scale=1)
Definition SimplicialCholesky.h:118
const PermutationMatrix< Dynamic, Dynamic, StorageIndex > & permutationPinv() const
Definition SimplicialCholesky.h:106
Definition SimplicialCholesky.h:694
void factorize(const MatrixType &a)
Definition SimplicialCholesky.h:764
void analyzePattern(const MatrixType &a)
Definition SimplicialCholesky.h:751
SimplicialCholesky & compute(const MatrixType &matrix)
Definition SimplicialCholesky.h:737
A direct sparse LDLT Cholesky factorizations without square root.
Definition SimplicialCholesky.h:453
Scalar determinant() const
Definition SimplicialCholesky.h:514
const MatrixL matrixL() const
Definition SimplicialCholesky.h:480
SimplicialLDLT(const MatrixType &matrix)
Definition SimplicialCholesky.h:472
const MatrixU matrixU() const
Definition SimplicialCholesky.h:486
void analyzePattern(const MatrixType &a)
Definition SimplicialCholesky.h:503
void factorize(const MatrixType &a)
Definition SimplicialCholesky.h:511
const VectorType vectorD() const
Definition SimplicialCholesky.h:475
SimplicialLDLT & compute(const MatrixType &matrix)
Definition SimplicialCholesky.h:492
SimplicialLDLT()
Definition SimplicialCholesky.h:469
A direct sparse LLT Cholesky factorizations.
Definition SimplicialCholesky.h:371
const MatrixL matrixL() const
Definition SimplicialCholesky.h:392
SimplicialLLT & compute(const MatrixType &matrix)
Definition SimplicialCholesky.h:404
Scalar determinant() const
Definition SimplicialCholesky.h:426
const MatrixU matrixU() const
Definition SimplicialCholesky.h:398
SimplicialLLT()
Definition SimplicialCholesky.h:387
void analyzePattern(const MatrixType &a)
Definition SimplicialCholesky.h:415
void factorize(const MatrixType &a)
Definition SimplicialCholesky.h:423
SimplicialLLT(const MatrixType &matrix)
Definition SimplicialCholesky.h:389
A direct sparse LDLT Cholesky factorizations without square root, for symmetric non-hermitian matrice...
Definition SimplicialCholesky.h:623
SimplicialNonHermitianLDLT()
Definition SimplicialCholesky.h:639
Scalar determinant() const
Definition SimplicialCholesky.h:684
SimplicialNonHermitianLDLT & compute(const MatrixType &matrix)
Definition SimplicialCholesky.h:662
const MatrixU matrixU() const
Definition SimplicialCholesky.h:656
const MatrixL matrixL() const
Definition SimplicialCholesky.h:650
const VectorType vectorD() const
Definition SimplicialCholesky.h:645
SimplicialNonHermitianLDLT(const MatrixType &matrix)
Definition SimplicialCholesky.h:642
void factorize(const MatrixType &a)
Definition SimplicialCholesky.h:681
void analyzePattern(const MatrixType &a)
Definition SimplicialCholesky.h:673
A direct sparse LLT Cholesky factorizations, for symmetric non-hermitian matrices.
Definition SimplicialCholesky.h:539
void factorize(const MatrixType &a)
Definition SimplicialCholesky.h:592
const MatrixU matrixU() const
Definition SimplicialCholesky.h:567
SimplicialNonHermitianLLT()
Definition SimplicialCholesky.h:555
SimplicialNonHermitianLLT & compute(const MatrixType &matrix)
Definition SimplicialCholesky.h:573
Scalar determinant() const
Definition SimplicialCholesky.h:595
const MatrixL matrixL() const
Definition SimplicialCholesky.h:561
void analyzePattern(const MatrixType &a)
Definition SimplicialCholesky.h:584
SimplicialNonHermitianLLT(const MatrixType &matrix)
Definition SimplicialCholesky.h:558
A versatible sparse matrix representation.
Definition SparseUtil.h:47
Index nonZeros() const
Definition SparseCompressedBase.h:64
Index cols() const
Definition SparseMatrix.h:161
Index rows() const
Definition SparseMatrix.h:159
A base class for sparse solvers.
Definition SparseSolverBase.h:67
ComputationInfo
Definition Constants.h:438
@ Lower
Definition Constants.h:211
@ Upper
Definition Constants.h:213
@ Success
Definition Constants.h:440
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83
Definition SimplicialCholesky.h:232