Eigen  5.0.1
 
Loading...
Searching...
No Matches
CholmodSupport.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_CHOLMODSUPPORT_H
12#define EIGEN_CHOLMODSUPPORT_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20
21template <typename Scalar>
22struct cholmod_configure_matrix;
23
24template <>
25struct cholmod_configure_matrix<double> {
26 template <typename CholmodType>
27 static void run(CholmodType& mat) {
28 mat.xtype = CHOLMOD_REAL;
29 mat.dtype = CHOLMOD_DOUBLE;
30 }
31};
32
33template <>
34struct cholmod_configure_matrix<std::complex<double> > {
35 template <typename CholmodType>
36 static void run(CholmodType& mat) {
37 mat.xtype = CHOLMOD_COMPLEX;
38 mat.dtype = CHOLMOD_DOUBLE;
39 }
40};
41
42// Other scalar types are not yet supported by Cholmod
43// template<> struct cholmod_configure_matrix<float> {
44// template<typename CholmodType>
45// static void run(CholmodType& mat) {
46// mat.xtype = CHOLMOD_REAL;
47// mat.dtype = CHOLMOD_SINGLE;
48// }
49// };
50//
51// template<> struct cholmod_configure_matrix<std::complex<float> > {
52// template<typename CholmodType>
53// static void run(CholmodType& mat) {
54// mat.xtype = CHOLMOD_COMPLEX;
55// mat.dtype = CHOLMOD_SINGLE;
56// }
57// };
58
59} // namespace internal
60
64template <typename Scalar_, int Options_, typename StorageIndex_>
65cholmod_sparse viewAsCholmod(Ref<SparseMatrix<Scalar_, Options_, StorageIndex_> > mat) {
66 cholmod_sparse res;
67 res.nzmax = mat.nonZeros();
68 res.nrow = mat.rows();
69 res.ncol = mat.cols();
70 res.p = mat.outerIndexPtr();
71 res.i = mat.innerIndexPtr();
72 res.x = mat.valuePtr();
73 res.z = 0;
74 res.sorted = 1;
75 if (mat.isCompressed()) {
76 res.packed = 1;
77 res.nz = 0;
78 } else {
79 res.packed = 0;
80 res.nz = mat.innerNonZeroPtr();
81 }
82
83 res.dtype = 0;
84 res.stype = -1;
85
86 EIGEN_IF_CONSTEXPR ((std::is_same<StorageIndex_, int>::value)) {
87 res.itype = CHOLMOD_INT;
88 } else EIGEN_IF_CONSTEXPR ((std::is_same<StorageIndex_, SuiteSparse_long>::value)) {
89 res.itype = CHOLMOD_LONG;
90 } else {
91 eigen_assert(false && "Index type not supported yet");
92 }
93
94 // setup res.xtype
95 internal::cholmod_configure_matrix<Scalar_>::run(res);
96
97 res.stype = 0;
98
99 return res;
100}
101
102template <typename Scalar_, int Options_, typename Index_>
103const cholmod_sparse viewAsCholmod(const SparseMatrix<Scalar_, Options_, Index_>& mat) {
104 cholmod_sparse res = viewAsCholmod(Ref<SparseMatrix<Scalar_, Options_, Index_> >(mat.const_cast_derived()));
105 return res;
106}
107
108template <typename Scalar_, int Options_, typename Index_>
109const cholmod_sparse viewAsCholmod(const SparseVector<Scalar_, Options_, Index_>& mat) {
110 cholmod_sparse res = viewAsCholmod(Ref<SparseMatrix<Scalar_, Options_, Index_> >(mat.const_cast_derived()));
111 return res;
112}
113
116template <typename Scalar_, int Options_, typename Index_, unsigned int UpLo>
117cholmod_sparse viewAsCholmod(const SparseSelfAdjointView<const SparseMatrix<Scalar_, Options_, Index_>, UpLo>& mat) {
118 cholmod_sparse res = viewAsCholmod(Ref<SparseMatrix<Scalar_, Options_, Index_> >(mat.matrix().const_cast_derived()));
119
120 EIGEN_IF_CONSTEXPR (UpLo == Upper) res.stype = 1;
121 EIGEN_IF_CONSTEXPR (UpLo == Lower) res.stype = -1;
122 // swap stype for rowmajor matrices (only works for real matrices)
123 EIGEN_STATIC_ASSERT((Options_ & RowMajorBit) == 0 || NumTraits<Scalar_>::IsComplex == 0,
124 THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
125 EIGEN_IF_CONSTEXPR (Options_ & RowMajorBit) res.stype *= -1;
126
127 return res;
128}
129
132template <typename Derived>
133cholmod_dense viewAsCholmod(MatrixBase<Derived>& mat) {
134 EIGEN_STATIC_ASSERT((internal::traits<Derived>::Flags & RowMajorBit) == 0,
135 THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
136 typedef typename Derived::Scalar Scalar;
137
138 cholmod_dense res;
139 res.nrow = mat.rows();
140 res.ncol = mat.cols();
141 res.nzmax = res.nrow * res.ncol;
142 res.d = Derived::IsVectorAtCompileTime ? mat.derived().size() : mat.derived().outerStride();
143 res.x = (void*)(mat.derived().data());
144 res.z = 0;
145
146 internal::cholmod_configure_matrix<Scalar>::run(res);
147
148 return res;
149}
150
153template <typename Scalar, typename StorageIndex>
154Map<const SparseMatrix<Scalar, ColMajor, StorageIndex> > viewAsEigen(cholmod_sparse& cm) {
156 cm.nrow, cm.ncol, static_cast<StorageIndex*>(cm.p)[cm.ncol], static_cast<StorageIndex*>(cm.p),
157 static_cast<StorageIndex*>(cm.i), static_cast<Scalar*>(cm.x));
158}
159
162template <typename Scalar, typename StorageIndex>
163Map<const SparseMatrix<Scalar, ColMajor, StorageIndex> > viewAsEigen(cholmod_factor& cm) {
165 cm.n, cm.n, static_cast<StorageIndex*>(cm.p)[cm.n], static_cast<StorageIndex*>(cm.p),
166 static_cast<StorageIndex*>(cm.i), static_cast<Scalar*>(cm.x));
167}
168
169namespace internal {
170
171// template specializations for int and long that call the correct cholmod method
172
173#define EIGEN_CHOLMOD_SPECIALIZE0(ret, name) \
174 template <typename StorageIndex_> \
175 inline ret cm_##name(cholmod_common& Common) { \
176 return cholmod_##name(&Common); \
177 } \
178 template <> \
179 inline ret cm_##name<SuiteSparse_long>(cholmod_common & Common) { \
180 return cholmod_l_##name(&Common); \
181 }
182
183#define EIGEN_CHOLMOD_SPECIALIZE1(ret, name, t1, a1) \
184 template <typename StorageIndex_> \
185 inline ret cm_##name(t1& a1, cholmod_common& Common) { \
186 return cholmod_##name(&a1, &Common); \
187 } \
188 template <> \
189 inline ret cm_##name<SuiteSparse_long>(t1 & a1, cholmod_common & Common) { \
190 return cholmod_l_##name(&a1, &Common); \
191 }
192
193EIGEN_CHOLMOD_SPECIALIZE0(int, start)
194EIGEN_CHOLMOD_SPECIALIZE0(int, finish)
195
196EIGEN_CHOLMOD_SPECIALIZE1(int, free_factor, cholmod_factor*, L)
197EIGEN_CHOLMOD_SPECIALIZE1(int, free_dense, cholmod_dense*, X)
198EIGEN_CHOLMOD_SPECIALIZE1(int, free_sparse, cholmod_sparse*, A)
199
200EIGEN_CHOLMOD_SPECIALIZE1(cholmod_factor*, analyze, cholmod_sparse, A)
201EIGEN_CHOLMOD_SPECIALIZE1(cholmod_sparse*, factor_to_sparse, cholmod_factor, L)
202
203template <typename StorageIndex_>
204inline cholmod_dense* cm_solve(int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common& Common) {
205 return cholmod_solve(sys, &L, &B, &Common);
206}
207template <>
208inline cholmod_dense* cm_solve<SuiteSparse_long>(int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common& Common) {
209 return cholmod_l_solve(sys, &L, &B, &Common);
210}
211
212template <typename StorageIndex_>
213inline cholmod_sparse* cm_spsolve(int sys, cholmod_factor& L, cholmod_sparse& B, cholmod_common& Common) {
214 return cholmod_spsolve(sys, &L, &B, &Common);
215}
216template <>
217inline cholmod_sparse* cm_spsolve<SuiteSparse_long>(int sys, cholmod_factor& L, cholmod_sparse& B,
218 cholmod_common& Common) {
219 return cholmod_l_spsolve(sys, &L, &B, &Common);
220}
221
222template <typename StorageIndex_>
223inline int cm_factorize_p(cholmod_sparse* A, double beta[2], StorageIndex_* fset, std::size_t fsize, cholmod_factor* L,
224 cholmod_common& Common) {
225 return cholmod_factorize_p(A, beta, fset, fsize, L, &Common);
226}
227template <>
228inline int cm_factorize_p<SuiteSparse_long>(cholmod_sparse* A, double beta[2], SuiteSparse_long* fset,
229 std::size_t fsize, cholmod_factor* L, cholmod_common& Common) {
230 return cholmod_l_factorize_p(A, beta, fset, fsize, L, &Common);
231}
232
233#undef EIGEN_CHOLMOD_SPECIALIZE0
234#undef EIGEN_CHOLMOD_SPECIALIZE1
235
236} // namespace internal
237
238enum CholmodMode { CholmodAuto, CholmodSimplicialLLt, CholmodSupernodalLLt, CholmodLDLt };
239
245template <typename MatrixType_, int UpLo_, typename Derived>
246class CholmodBase : public SparseSolverBase<Derived> {
247 protected:
248 typedef SparseSolverBase<Derived> Base;
249 using Base::derived;
250 using Base::m_isInitialized;
251
252 public:
253 typedef MatrixType_ MatrixType;
254 enum { UpLo = UpLo_ };
255 typedef typename MatrixType::Scalar Scalar;
256 typedef typename MatrixType::RealScalar RealScalar;
257 typedef MatrixType CholMatrixType;
258 typedef typename MatrixType::StorageIndex StorageIndex;
259 enum { ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime };
260
261 public:
262 CholmodBase() : m_cholmodFactor(0), m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false) {
263 EIGEN_STATIC_ASSERT((std::is_same<double, RealScalar>::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY);
264 m_shiftOffset[0] = m_shiftOffset[1] = 0.0;
265 internal::cm_start<StorageIndex>(m_cholmod);
266 }
267
268 explicit CholmodBase(const MatrixType& matrix)
269 : m_cholmodFactor(0), m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false) {
270 EIGEN_STATIC_ASSERT((std::is_same<double, RealScalar>::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY);
271 m_shiftOffset[0] = m_shiftOffset[1] = 0.0;
272 internal::cm_start<StorageIndex>(m_cholmod);
273 compute(matrix);
274 }
275
276 ~CholmodBase() {
277 if (m_cholmodFactor) internal::cm_free_factor<StorageIndex>(m_cholmodFactor, m_cholmod);
278 internal::cm_finish<StorageIndex>(m_cholmod);
279 }
280
281 inline StorageIndex cols() const { return internal::convert_index<StorageIndex, Index>(m_cholmodFactor->n); }
282 inline StorageIndex rows() const { return internal::convert_index<StorageIndex, Index>(m_cholmodFactor->n); }
283
290 eigen_assert(m_isInitialized && "Decomposition is not initialized.");
291 return m_info;
292 }
293
295 Derived& compute(const MatrixType& matrix) {
296 analyzePattern(matrix);
297 factorize(matrix);
298 return derived();
299 }
300
307 void analyzePattern(const MatrixType& matrix) {
308 if (m_cholmodFactor) {
309 internal::cm_free_factor<StorageIndex>(m_cholmodFactor, m_cholmod);
310 m_cholmodFactor = 0;
311 }
312 cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView<UpLo>());
313 m_cholmodFactor = internal::cm_analyze<StorageIndex>(A, m_cholmod);
314
315 this->m_isInitialized = true;
316 this->m_info = Success;
317 m_analysisIsOk = true;
318 m_factorizationIsOk = false;
319 }
320
328 void factorize(const MatrixType& matrix) {
329 eigen_assert(m_analysisIsOk && "You must first call analyzePattern()");
330 cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView<UpLo>());
331 internal::cm_factorize_p<StorageIndex>(&A, m_shiftOffset, 0, 0, m_cholmodFactor, m_cholmod);
332
333 // If the factorization failed, either the input matrix was zero (so m_cholmodFactor == nullptr), or minor is the
334 // column at which it failed. On success minor == n.
335 this->m_info =
336 (m_cholmodFactor != nullptr && m_cholmodFactor->minor == m_cholmodFactor->n ? Success : NumericalIssue);
337 m_factorizationIsOk = true;
338 }
339
342 cholmod_common& cholmod() { return m_cholmod; }
343
344#ifndef EIGEN_PARSED_BY_DOXYGEN
346 template <typename Rhs, typename Dest>
347 void _solve_impl(const MatrixBase<Rhs>& b, MatrixBase<Dest>& dest) const {
348 eigen_assert(m_factorizationIsOk &&
349 "The decomposition is not in a valid state for solving, you must first call either compute() or "
350 "symbolic()/numeric()");
351 const Index size = m_cholmodFactor->n;
352 EIGEN_UNUSED_VARIABLE(size);
353 eigen_assert(size == b.rows());
354
355 // Cholmod needs column-major storage without inner-stride, which corresponds to the default behavior of Ref.
357
358 cholmod_dense b_cd = viewAsCholmod(b_ref);
359 cholmod_dense* x_cd = internal::cm_solve<StorageIndex>(CHOLMOD_A, *m_cholmodFactor, b_cd, m_cholmod);
360 if (!x_cd) {
361 this->m_info = NumericalIssue;
362 return;
363 }
364 // TODO: optimize this copy by swapping when possible (be careful with alignment, etc.)
365 // NOTE Actually, the copy can be avoided by calling cholmod_solve2 instead of cholmod_solve
366 dest = Matrix<Scalar, Dest::RowsAtCompileTime, Dest::ColsAtCompileTime>::Map(reinterpret_cast<Scalar*>(x_cd->x),
367 b.rows(), b.cols());
368 internal::cm_free_dense<StorageIndex>(x_cd, m_cholmod);
369 }
370
372 template <typename RhsDerived, typename DestDerived>
373 void _solve_impl(const SparseMatrixBase<RhsDerived>& b, SparseMatrixBase<DestDerived>& dest) const {
374 eigen_assert(m_factorizationIsOk &&
375 "The decomposition is not in a valid state for solving, you must first call either compute() or "
376 "symbolic()/numeric()");
377 const Index size = m_cholmodFactor->n;
378 EIGEN_UNUSED_VARIABLE(size);
379 eigen_assert(size == b.rows());
380
381 // note: cs stands for Cholmod Sparse
382 Ref<SparseMatrix<typename RhsDerived::Scalar, ColMajor, typename RhsDerived::StorageIndex> > b_ref(
383 b.const_cast_derived());
384 cholmod_sparse b_cs = viewAsCholmod(b_ref);
385 cholmod_sparse* x_cs = internal::cm_spsolve<StorageIndex>(CHOLMOD_A, *m_cholmodFactor, b_cs, m_cholmod);
386 if (!x_cs) {
387 this->m_info = NumericalIssue;
388 return;
389 }
390 // TODO: optimize this copy by swapping when possible (be careful with alignment, etc.)
391 // NOTE cholmod_spsolve in fact just calls the dense solver for blocks of 4 columns at a time (similar to Eigen's
392 // sparse solver)
393 dest.derived() = viewAsEigen<typename DestDerived::Scalar, typename DestDerived::StorageIndex>(*x_cs);
394 internal::cm_free_sparse<StorageIndex>(x_cs, m_cholmod);
395 }
396#endif // EIGEN_PARSED_BY_DOXYGEN
397
407 Derived& setShift(const RealScalar& offset) {
408 m_shiftOffset[0] = double(offset);
409 return derived();
410 }
411
413 Scalar determinant() const {
414 using std::exp;
415 return exp(logDeterminant());
416 }
417
419 Scalar logDeterminant() const {
420 using numext::real;
421 using std::log;
422 eigen_assert(m_factorizationIsOk &&
423 "The decomposition is not in a valid state for solving, you must first call either compute() or "
424 "symbolic()/numeric()");
425
426 RealScalar logDet = 0;
427 Scalar* x = static_cast<Scalar*>(m_cholmodFactor->x);
428 if (m_cholmodFactor->is_super) {
429 // Supernodal factorization stored as a packed list of dense column-major blocks,
430 // as described by the following structure:
431
432 // super[k] == index of the first column of the k-th super node
433 StorageIndex* super = static_cast<StorageIndex*>(m_cholmodFactor->super);
434 // pi[k] == offset to the description of row indices
435 StorageIndex* pi = static_cast<StorageIndex*>(m_cholmodFactor->pi);
436 // px[k] == offset to the respective dense block
437 StorageIndex* px = static_cast<StorageIndex*>(m_cholmodFactor->px);
438
439 Index nb_super_nodes = m_cholmodFactor->nsuper;
440 for (Index k = 0; k < nb_super_nodes; ++k) {
441 StorageIndex ncols = super[k + 1] - super[k];
442 StorageIndex nrows = pi[k + 1] - pi[k];
443
444 Map<const Array<Scalar, 1, Dynamic>, 0, InnerStride<> > sk(x + px[k], ncols, InnerStride<>(nrows + 1));
445 logDet += sk.real().log().sum();
446 }
447 } else {
448 // Simplicial factorization stored as standard CSC matrix.
449 StorageIndex* p = static_cast<StorageIndex*>(m_cholmodFactor->p);
450 Index size = m_cholmodFactor->n;
451 for (Index k = 0; k < size; ++k) logDet += log(real(x[p[k]]));
452 }
453 if (m_cholmodFactor->is_ll) logDet *= 2.0;
454 return logDet;
455 }
456
457 template <typename Stream>
458 void dumpMemory(Stream& /*s*/) {}
459
460 protected:
461 mutable cholmod_common m_cholmod;
462 cholmod_factor* m_cholmodFactor;
463 double m_shiftOffset[2];
464 mutable ComputationInfo m_info;
465 int m_factorizationIsOk;
466 int m_analysisIsOk;
467};
468
492template <typename MatrixType_, int UpLo_ = Lower>
493class CholmodSimplicialLLT : public CholmodBase<MatrixType_, UpLo_, CholmodSimplicialLLT<MatrixType_, UpLo_> > {
494 typedef CholmodBase<MatrixType_, UpLo_, CholmodSimplicialLLT> Base;
495 using Base::m_cholmod;
496
497 public:
498 typedef MatrixType_ MatrixType;
499 typedef typename MatrixType::Scalar Scalar;
500 typedef typename MatrixType::RealScalar RealScalar;
501 typedef typename MatrixType::StorageIndex StorageIndex;
504
505 CholmodSimplicialLLT() : Base() { init(); }
506
507 CholmodSimplicialLLT(const MatrixType& matrix) : Base() {
508 init();
509 this->compute(matrix);
510 }
511
513 inline MatrixL matrixL() const { return viewAsEigen<Scalar, StorageIndex>(*Base::m_cholmodFactor); }
514
516 inline MatrixU matrixU() const { return matrixL().adjoint(); }
517
518 protected:
519 void init() {
520 m_cholmod.final_asis = 0;
521 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
522 m_cholmod.final_ll = 1;
523 }
524};
525
549template <typename MatrixType_, int UpLo_ = Lower>
550class CholmodSimplicialLDLT : public CholmodBase<MatrixType_, UpLo_, CholmodSimplicialLDLT<MatrixType_, UpLo_> > {
551 typedef CholmodBase<MatrixType_, UpLo_, CholmodSimplicialLDLT> Base;
552 using Base::m_cholmod;
553
554 public:
555 typedef MatrixType_ MatrixType;
556 typedef typename MatrixType::Scalar Scalar;
557 typedef typename MatrixType::RealScalar RealScalar;
558 typedef typename MatrixType::StorageIndex StorageIndex;
559 typedef Matrix<Scalar, Dynamic, 1> VectorType;
562
563 CholmodSimplicialLDLT() : Base() { init(); }
564
565 CholmodSimplicialLDLT(const MatrixType& matrix) : Base() {
566 init();
567 this->compute(matrix);
568 }
569
571 inline VectorType vectorD() const {
572 auto cholmodL = viewAsEigen<Scalar, StorageIndex>(*Base::m_cholmodFactor);
573
574 VectorType D{cholmodL.rows()};
575
576 for (Index k = 0; k < cholmodL.outerSize(); ++k) {
577 typename decltype(cholmodL)::InnerIterator it{cholmodL, k};
578 D(k) = it.value();
579 }
580
581 return D;
582 }
583
585 inline MatrixL matrixL() const { return viewAsEigen<Scalar, StorageIndex>(*Base::m_cholmodFactor); }
586
588 inline MatrixU matrixU() const { return matrixL().adjoint(); }
589
590 protected:
591 void init() {
592 m_cholmod.final_asis = 1;
593 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
594 }
595};
596
620template <typename MatrixType_, int UpLo_ = Lower>
621class CholmodSupernodalLLT : public CholmodBase<MatrixType_, UpLo_, CholmodSupernodalLLT<MatrixType_, UpLo_> > {
622 typedef CholmodBase<MatrixType_, UpLo_, CholmodSupernodalLLT> Base;
623 using Base::m_cholmod;
624
625 public:
626 typedef MatrixType_ MatrixType;
627 typedef typename MatrixType::Scalar Scalar;
628 typedef typename MatrixType::RealScalar RealScalar;
629 typedef typename MatrixType::StorageIndex StorageIndex;
630
631 CholmodSupernodalLLT() : Base() { init(); }
632
633 CholmodSupernodalLLT(const MatrixType& matrix) : Base() {
634 init();
635 this->compute(matrix);
636 }
637
639 inline MatrixType matrixL() const {
640 // Convert Cholmod factor's supernodal storage format to Eigen's CSC storage format
641 cholmod_sparse* cholmodL = internal::cm_factor_to_sparse(*Base::m_cholmodFactor, m_cholmod);
642 MatrixType L = viewAsEigen<Scalar, StorageIndex>(*cholmodL);
643 internal::cm_free_sparse<StorageIndex>(cholmodL, m_cholmod);
644
645 return L;
646 }
647
649 inline MatrixType matrixU() const { return matrixL().adjoint(); }
650
651 protected:
652 void init() {
653 m_cholmod.final_asis = 1;
654 m_cholmod.supernodal = CHOLMOD_SUPERNODAL;
655 }
656};
657
683template <typename MatrixType_, int UpLo_ = Lower>
684class CholmodDecomposition : public CholmodBase<MatrixType_, UpLo_, CholmodDecomposition<MatrixType_, UpLo_> > {
685 typedef CholmodBase<MatrixType_, UpLo_, CholmodDecomposition> Base;
686 using Base::m_cholmod;
687
688 public:
689 typedef MatrixType_ MatrixType;
690
691 CholmodDecomposition() : Base() { init(); }
692
693 CholmodDecomposition(const MatrixType& matrix) : Base() {
694 init();
695 this->compute(matrix);
696 }
697
698 void setMode(CholmodMode mode) {
699 switch (mode) {
700 case CholmodAuto:
701 m_cholmod.final_asis = 1;
702 m_cholmod.supernodal = CHOLMOD_AUTO;
703 break;
704 case CholmodSimplicialLLt:
705 m_cholmod.final_asis = 0;
706 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
707 m_cholmod.final_ll = 1;
708 break;
709 case CholmodSupernodalLLt:
710 m_cholmod.final_asis = 1;
711 m_cholmod.supernodal = CHOLMOD_SUPERNODAL;
712 break;
713 case CholmodLDLt:
714 m_cholmod.final_asis = 1;
715 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
716 break;
717 default:
718 break;
719 }
720 }
721
722 protected:
723 void init() {
724 m_cholmod.final_asis = 1;
725 m_cholmod.supernodal = CHOLMOD_AUTO;
726 }
727};
728
729} // end namespace Eigen
730
731#endif // EIGEN_CHOLMODSUPPORT_H
void factorize(const MatrixType &matrix)
Definition CholmodSupport.h:328
ComputationInfo info() const
Reports whether previous computation was successful.
Definition CholmodSupport.h:289
Scalar determinant() const
Definition CholmodSupport.h:413
Derived & setShift(const RealScalar &offset)
Definition CholmodSupport.h:407
Derived & compute(const MatrixType &matrix)
Definition CholmodSupport.h:295
Scalar logDeterminant() const
Definition CholmodSupport.h:419
cholmod_common & cholmod()
Definition CholmodSupport.h:342
void analyzePattern(const MatrixType &matrix)
Definition CholmodSupport.h:307
MatrixU matrixU() const
Definition CholmodSupport.h:588
VectorType vectorD() const
Definition CholmodSupport.h:571
MatrixL matrixL() const
Definition CholmodSupport.h:585
MatrixL matrixL() const
Definition CholmodSupport.h:513
MatrixU matrixU() const
Definition CholmodSupport.h:516
MatrixType matrixU() const
Definition CholmodSupport.h:649
MatrixType matrixL() const
Definition CholmodSupport.h:639
An InnerIterator allows to loop over the element of any matrix expression.
Definition CoreIterators.h:38
Scalar value() const
Definition CoreIterators.h:49
Convenience specialization of Stride to specify only an inner stride See class Map for some examples.
Definition Stride.h:93
A matrix or vector expression mapping an existing array of data.
Definition Map.h:97
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
A matrix or vector expression mapping an existing expression.
Definition Ref.h:262
A versatile sparse matrix representation.
Definition SparseMatrix.h:122
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition SparseSelfAdjointView.h:53
a sparse vector class
Definition SparseVector.h:63
Expression of a triangular part in a matrix.
Definition TriangularMatrix.h:426
ComputationInfo
Definition Constants.h:455
@ Lower
Definition Constants.h:212
@ Upper
Definition Constants.h:214
@ NumericalIssue
Definition Constants.h:459
@ Success
Definition Constants.h:457
constexpr unsigned int RowMajorBit
Definition Constants.h:71