10 #ifndef EIGEN_CHOLMODSUPPORT_H
11 #define EIGEN_CHOLMODSUPPORT_H
20 template<
typename CholmodType>
21 static void run(CholmodType& mat) {
22 mat.xtype = CHOLMOD_REAL;
23 mat.dtype = CHOLMOD_DOUBLE;
28 template<
typename CholmodType>
29 static void run(CholmodType& mat) {
30 mat.xtype = CHOLMOD_COMPLEX;
31 mat.dtype = CHOLMOD_DOUBLE;
57 template<
typename _Scalar,
int _Options,
typename _StorageIndex>
61 res.nzmax = mat.nonZeros();
62 res.nrow = mat.rows();
63 res.ncol = mat.cols();
64 res.p = mat.outerIndexPtr();
65 res.i = mat.innerIndexPtr();
66 res.x = mat.valuePtr();
69 if(mat.isCompressed())
77 res.nz = mat.innerNonZeroPtr();
85 res.itype = CHOLMOD_INT;
89 res.itype = CHOLMOD_LONG;
104 template<
typename _Scalar,
int _Options,
typename _Index>
111 template<
typename _Scalar,
int _Options,
typename _Index>
120 template<
typename _Scalar,
int _Options,
typename _Index,
unsigned int UpLo>
125 if(UpLo==
Upper) res.stype = 1;
126 if(UpLo==
Lower) res.stype = -1;
136 template<
typename Derived>
140 typedef typename Derived::Scalar Scalar;
143 res.nrow = mat.rows();
144 res.ncol = mat.cols();
145 res.nzmax = res.nrow * res.ncol;
146 res.d = Derived::IsVectorAtCompileTime ? mat.derived().size() : mat.derived().outerStride();
147 res.x = (
void*)(mat.derived().data());
157 template<
typename Scalar,
int Flags,
typename StorageIndex>
161 (cm.nrow, cm.ncol,
static_cast<StorageIndex*
>(cm.p)[cm.ncol],
162 static_cast<StorageIndex*
>(cm.p),
static_cast<StorageIndex*
>(cm.i),
static_cast<Scalar*
>(cm.x) );
169 #define EIGEN_CHOLMOD_SPECIALIZE0(ret, name) \
170 template<typename _StorageIndex> inline ret cm_ ## name (cholmod_common &Common) { return cholmod_ ## name (&Common); } \
171 template<> inline ret cm_ ## name<SuiteSparse_long> (cholmod_common &Common) { return cholmod_l_ ## name (&Common); }
173 #define EIGEN_CHOLMOD_SPECIALIZE1(ret, name, t1, a1) \
174 template<typename _StorageIndex> inline ret cm_ ## name (t1& a1, cholmod_common &Common) { return cholmod_ ## name (&a1, &Common); } \
175 template<> inline ret cm_ ## name<SuiteSparse_long> (t1& a1, cholmod_common &Common) { return cholmod_l_ ## name (&a1, &Common); }
186 template<typename _StorageIndex> inline cholmod_dense*
cm_solve (
int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common &Common) {
return cholmod_solve (sys, &L, &B, &Common); }
187 template<>
inline cholmod_dense*
cm_solve<SuiteSparse_long> (
int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common &Common) {
return cholmod_l_solve (sys, &L, &B, &Common); }
189 template<
typename _StorageIndex>
inline cholmod_sparse*
cm_spsolve (
int sys, cholmod_factor& L, cholmod_sparse& B, cholmod_common &Common) {
return cholmod_spsolve (sys, &L, &B, &Common); }
190 template<>
inline cholmod_sparse*
cm_spsolve<SuiteSparse_long> (
int sys, cholmod_factor& L, cholmod_sparse& B, cholmod_common &Common) {
return cholmod_l_spsolve (sys, &L, &B, &Common); }
192 template<
typename _StorageIndex>
193 inline int cm_factorize_p (cholmod_sparse* A,
double beta[2], _StorageIndex* fset, std::size_t fsize, cholmod_factor* L, cholmod_common &Common) {
return cholmod_factorize_p (A, beta, fset, fsize, L, &Common); }
195 inline int cm_factorize_p<SuiteSparse_long> (cholmod_sparse* A,
double beta[2], SuiteSparse_long* fset, std::size_t fsize, cholmod_factor* L, cholmod_common &Common) {
return cholmod_l_factorize_p (A, beta, fset, fsize, L, &Common); }
197 #undef EIGEN_CHOLMOD_SPECIALIZE0
198 #undef EIGEN_CHOLMOD_SPECIALIZE1
213 template<
typename _MatrixType,
int _UpLo,
typename Derived>
223 typedef typename MatrixType::Scalar
Scalar;
239 internal::cm_start<StorageIndex>(
m_cholmod);
247 internal::cm_start<StorageIndex>(
m_cholmod);
255 internal::cm_finish<StorageIndex>(
m_cholmod);
293 cholmod_sparse A =
viewAsCholmod(matrix.template selfadjointView<UpLo>());
311 cholmod_sparse A =
viewAsCholmod(matrix.template selfadjointView<UpLo>());
323 #ifndef EIGEN_PARSED_BY_DOXYGEN
325 template<
typename Rhs,
typename Dest>
328 eigen_assert(
m_factorizationIsOk &&
"The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()");
346 internal::cm_free_dense<StorageIndex>(x_cd,
m_cholmod);
350 template<
typename RhsDerived,
typename DestDerived>
353 eigen_assert(
m_factorizationIsOk &&
"The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()");
369 dest.
derived() = viewAsEigen<typename DestDerived::Scalar,ColMajor,typename DestDerived::StorageIndex>(*x_cs);
370 internal::cm_free_sparse<StorageIndex>(x_cs,
m_cholmod);
402 eigen_assert(
m_factorizationIsOk &&
"The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()");
419 for (
Index k=0; k < nb_super_nodes; ++k)
425 logDet += sk.real().log().sum();
434 logDet +=
log(
real( x[p[k]] ));
441 template<
typename Stream>
476 template<
typename _MatrixType,
int _UpLo = Lower>
499 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
527 template<
typename _MatrixType,
int _UpLo = Lower>
550 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
576 template<
typename _MatrixType,
int _UpLo = Lower>
599 m_cholmod.supernodal = CHOLMOD_SUPERNODAL;
627 template<
typename _MatrixType,
int _UpLo = Lower>
657 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
662 m_cholmod.supernodal = CHOLMOD_SUPERNODAL;
666 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
Definition: ArrayCwiseUnaryOps.h:97
EIGEN_DEVICE_FUNC const LogReturnType log() const
Definition: ArrayCwiseUnaryOps.h:128
#define EIGEN_CHOLMOD_SPECIALIZE1(ret, name, t1, a1)
Definition: CholmodSupport.h:173
#define EIGEN_CHOLMOD_SPECIALIZE0(ret, name)
Definition: CholmodSupport.h:169
EIGEN_DEVICE_FUNC RealReturnType real() const
Definition: CommonCwiseUnaryOps.h:100
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:1076
#define eigen_assert(x)
Definition: Macros.h:1037
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
The base class for the direct Cholesky factorization of Cholmod.
Definition: CholmodSupport.h:215
cholmod_factor * m_cholmodFactor
Definition: CholmodSupport.h:447
cholmod_common m_cholmod
Definition: CholmodSupport.h:446
CholmodBase(const MatrixType &matrix)
Definition: CholmodSupport.h:242
void dumpMemory(Stream &)
Definition: CholmodSupport.h:442
ComputationInfo m_info
Definition: CholmodSupport.h:449
int m_factorizationIsOk
Definition: CholmodSupport.h:450
double m_shiftOffset[2]
Definition: CholmodSupport.h:448
Scalar logDeterminant() const
Definition: CholmodSupport.h:398
void analyzePattern(const MatrixType &matrix)
Definition: CholmodSupport.h:286
void factorize(const MatrixType &matrix)
Definition: CholmodSupport.h:308
cholmod_common & cholmod()
Definition: CholmodSupport.h:321
MatrixType::RealScalar RealScalar
Definition: CholmodSupport.h:224
MatrixType CholMatrixType
Definition: CholmodSupport.h:225
StorageIndex rows() const
Definition: CholmodSupport.h:259
~CholmodBase()
Definition: CholmodSupport.h:251
Derived & setShift(const RealScalar &offset)
Definition: CholmodSupport.h:384
StorageIndex cols() const
Definition: CholmodSupport.h:258
@ MaxColsAtCompileTime
Definition: CholmodSupport.h:229
@ ColsAtCompileTime
Definition: CholmodSupport.h:228
@ UpLo
Definition: CholmodSupport.h:222
Scalar determinant() const
Definition: CholmodSupport.h:391
Derived & compute(const MatrixType &matrix)
Definition: CholmodSupport.h:273
int m_analysisIsOk
Definition: CholmodSupport.h:451
CholmodBase()
Definition: CholmodSupport.h:234
bool m_isInitialized
Definition: SparseSolverBase.h:119
MatrixType::StorageIndex StorageIndex
Definition: CholmodSupport.h:226
Derived & derived()
Definition: SparseSolverBase.h:79
MatrixType::Scalar Scalar
Definition: CholmodSupport.h:223
void _solve_impl(const MatrixBase< Rhs > &b, MatrixBase< Dest > &dest) const
Definition: CholmodSupport.h:326
void _solve_impl(const SparseMatrixBase< RhsDerived > &b, SparseMatrixBase< DestDerived > &dest) const
Definition: CholmodSupport.h:351
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: CholmodSupport.h:266
SparseSolverBase< Derived > Base
Definition: CholmodSupport.h:217
_MatrixType MatrixType
Definition: CholmodSupport.h:221
A general Cholesky factorization and solver based on Cholmod.
Definition: CholmodSupport.h:629
cholmod_common m_cholmod
Definition: CholmodSupport.h:446
~CholmodDecomposition()
Definition: CholmodSupport.h:645
CholmodDecomposition()
Definition: CholmodSupport.h:637
void init()
Definition: CholmodSupport.h:673
CholmodDecomposition(const MatrixType &matrix)
Definition: CholmodSupport.h:639
CholmodBase< _MatrixType, _UpLo, CholmodDecomposition > Base
Definition: CholmodSupport.h:630
_MatrixType MatrixType
Definition: CholmodSupport.h:635
void setMode(CholmodMode mode)
Definition: CholmodSupport.h:647
A simplicial direct Cholesky (LDLT) factorization and solver based on Cholmod.
Definition: CholmodSupport.h:529
cholmod_common m_cholmod
Definition: CholmodSupport.h:446
_MatrixType MatrixType
Definition: CholmodSupport.h:535
void init()
Definition: CholmodSupport.h:547
CholmodSimplicialLDLT(const MatrixType &matrix)
Definition: CholmodSupport.h:539
CholmodSimplicialLDLT()
Definition: CholmodSupport.h:537
CholmodBase< _MatrixType, _UpLo, CholmodSimplicialLDLT > Base
Definition: CholmodSupport.h:530
~CholmodSimplicialLDLT()
Definition: CholmodSupport.h:545
A simplicial direct Cholesky (LLT) factorization and solver based on Cholmod.
Definition: CholmodSupport.h:478
cholmod_common m_cholmod
Definition: CholmodSupport.h:446
CholmodSimplicialLLT(const MatrixType &matrix)
Definition: CholmodSupport.h:488
void init()
Definition: CholmodSupport.h:496
_MatrixType MatrixType
Definition: CholmodSupport.h:484
CholmodBase< _MatrixType, _UpLo, CholmodSimplicialLLT > Base
Definition: CholmodSupport.h:479
~CholmodSimplicialLLT()
Definition: CholmodSupport.h:494
CholmodSimplicialLLT()
Definition: CholmodSupport.h:486
A supernodal Cholesky (LLT) factorization and solver based on Cholmod.
Definition: CholmodSupport.h:578
void init()
Definition: CholmodSupport.h:596
CholmodSupernodalLLT()
Definition: CholmodSupport.h:586
cholmod_common m_cholmod
Definition: CholmodSupport.h:446
CholmodBase< _MatrixType, _UpLo, CholmodSupernodalLLT > Base
Definition: CholmodSupport.h:579
_MatrixType MatrixType
Definition: CholmodSupport.h:584
~CholmodSupernodalLLT()
Definition: CholmodSupport.h:594
CholmodSupernodalLLT(const MatrixType &matrix)
Definition: CholmodSupport.h:588
Convenience specialization of Stride to specify only an inner stride See class Map for some examples.
Definition: Stride.h:96
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
Sparse matrix.
Definition: MappedSparseMatrix.h:34
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:50
static ConstMapType Map(const Scalar *data)
Definition: PlainObjectBase.h:644
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:283
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:28
Index rows() const
Definition: SparseMatrixBase.h:176
Derived & const_cast_derived() const
Definition: SparseMatrixBase.h:145
const Derived & derived() const
Definition: SparseMatrixBase.h:143
A versatible sparse matrix representation.
Definition: SparseMatrix.h:98
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition: SparseSelfAdjointView.h:45
A base class for sparse solvers.
Definition: SparseSolverBase.h:68
bool m_isInitialized
Definition: SparseSolverBase.h:119
Derived & derived()
Definition: SparseSolverBase.h:79
a sparse vector class
Definition: SparseVector.h:66
Concept for reading and writing characters.
ComputationInfo
Definition: Constants.h:440
@ Lower
Definition: Constants.h:209
@ Upper
Definition: Constants.h:211
@ NumericalIssue
Definition: Constants.h:444
@ Success
Definition: Constants.h:442
const unsigned int RowMajorBit
Definition: Constants.h:66
cholmod_sparse * cm_spsolve(int sys, cholmod_factor &L, cholmod_sparse &B, cholmod_common &Common)
Definition: CholmodSupport.h:189
int cm_factorize_p(cholmod_sparse *A, double beta[2], _StorageIndex *fset, std::size_t fsize, cholmod_factor *L, cholmod_common &Common)
Definition: CholmodSupport.h:193
cholmod_sparse * cm_spsolve< SuiteSparse_long >(int sys, cholmod_factor &L, cholmod_sparse &B, cholmod_common &Common)
Definition: CholmodSupport.h:190
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
cholmod_dense * cm_solve< SuiteSparse_long >(int sys, cholmod_factor &L, cholmod_dense &B, cholmod_common &Common)
Definition: CholmodSupport.h:187
int cm_factorize_p< SuiteSparse_long >(cholmod_sparse *A, double beta[2], SuiteSparse_long *fset, std::size_t fsize, cholmod_factor *L, cholmod_common &Common)
Definition: CholmodSupport.h:195
cholmod_dense * cm_solve(int sys, cholmod_factor &L, cholmod_dense &B, cholmod_common &Common)
Definition: CholmodSupport.h:186
Namespace containing all symbols from the Eigen library.
Definition: LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
CholmodMode
Definition: CholmodSupport.h:203
@ CholmodSimplicialLLt
Definition: CholmodSupport.h:204
@ CholmodAuto
Definition: CholmodSupport.h:204
@ CholmodLDLt
Definition: CholmodSupport.h:204
@ CholmodSupernodalLLt
Definition: CholmodSupport.h:204
MappedSparseMatrix< Scalar, Flags, StorageIndex > viewAsEigen(cholmod_sparse &cm)
Definition: CholmodSupport.h:158
cholmod_sparse viewAsCholmod(Ref< SparseMatrix< _Scalar, _Options, _StorageIndex > > mat)
Definition: CholmodSupport.h:58
Definition: document.h:416
Definition: json.hpp:5678
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:233
Definition: ForwardDeclarations.h:17