25 #ifndef EIGEN_CHOLMODSUPPORT_H
26 #define EIGEN_CHOLMODSUPPORT_H
32 template<
typename Scalar,
typename CholmodType>
35 if (internal::is_same<Scalar,float>::value)
37 mat.xtype = CHOLMOD_REAL;
38 mat.dtype = CHOLMOD_SINGLE;
40 else if (internal::is_same<Scalar,double>::value)
42 mat.xtype = CHOLMOD_REAL;
43 mat.dtype = CHOLMOD_DOUBLE;
45 else if (internal::is_same<Scalar,std::complex<float> >::value)
47 mat.xtype = CHOLMOD_COMPLEX;
48 mat.dtype = CHOLMOD_SINGLE;
50 else if (internal::is_same<Scalar,std::complex<double> >::value)
52 mat.xtype = CHOLMOD_COMPLEX;
53 mat.dtype = CHOLMOD_DOUBLE;
57 eigen_assert(
false &&
"Scalar type not supported by CHOLMOD");
66 template<
typename _Scalar,
int _Options,
typename _Index>
72 res.nrow = mat.
rows();;
73 res.ncol = mat.
cols();
91 if (internal::is_same<_Index,int>::value)
93 res.itype = CHOLMOD_INT;
97 eigen_assert(
false &&
"Index type different than int is not supported yet");
101 internal::cholmod_configure_matrix<_Scalar>(res);
108 template<
typename _Scalar,
int _Options,
typename _Index>
117 template<
typename _Scalar,
int _Options,
typename _Index,
unsigned int UpLo>
120 cholmod_sparse res =
viewAsCholmod(mat.matrix().const_cast_derived());
122 if(UpLo==
Upper) res.stype = 1;
123 if(UpLo==
Lower) res.stype = -1;
130 template<
typename Derived>
134 typedef typename Derived::Scalar Scalar;
137 res.nrow = mat.rows();
138 res.ncol = mat.cols();
139 res.nzmax = res.nrow * res.ncol;
140 res.d = Derived::IsVectorAtCompileTime ? mat.derived().size() : mat.derived().outerStride();
141 res.x = mat.derived().data();
144 internal::cholmod_configure_matrix<Scalar>(res);
151 template<
typename Scalar,
int Flags,
typename Index>
155 (cm.nrow, cm.ncol,
reinterpret_cast<Index*
>(cm.p)[cm.ncol],
156 reinterpret_cast<Index*>(cm.p),
reinterpret_cast<Index*
>(cm.i),reinterpret_cast<Scalar*>(cm.x) );
169 template<
typename _MatrixType,
int _UpLo,
typename Derived>
175 typedef typename MatrixType::Scalar
Scalar;
178 typedef typename MatrixType::Index
Index;
205 Derived&
derived() {
return *
static_cast<Derived*
>(
this); }
206 const Derived&
derived()
const {
return *
static_cast<const Derived*
>(
this); }
231 template<
typename Rhs>
232 inline const internal::solve_retval<CholmodBase, Rhs>
237 &&
"CholmodDecomposition::solve(): invalid number of rows of the right hand side matrix b");
238 return internal::solve_retval<CholmodBase, Rhs>(*
this, b.derived());
245 template<
typename Rhs>
246 inline const internal::sparse_solve_retval<CholmodBase, Rhs>
251 &&
"CholmodDecomposition::solve(): invalid number of rows of the right hand side matrix b");
252 return internal::sparse_solve_retval<CholmodBase, Rhs>(*
this, b.
derived());
268 cholmod_sparse A =
viewAsCholmod(matrix.template selfadjointView<UpLo>());
286 cholmod_sparse A =
viewAsCholmod(matrix.template selfadjointView<UpLo>());
297 #ifndef EIGEN_PARSED_BY_DOXYGEN
299 template<
typename Rhs,
typename Dest>
302 eigen_assert(
m_factorizationIsOk &&
"The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()");
314 dest = Matrix<Scalar,Dest::RowsAtCompileTime,Dest::ColsAtCompileTime>::Map(reinterpret_cast<Scalar*>(x_cd->x),b.rows(),b.cols());
319 template<
typename RhsScalar,
int RhsOptions,
typename RhsIndex,
typename DestScalar,
int DestOptions,
typename DestIndex>
320 void _solve(
const SparseMatrix<RhsScalar,RhsOptions,RhsIndex> &b, SparseMatrix<DestScalar,DestOptions,DestIndex> &dest)
const
322 eigen_assert(
m_factorizationIsOk &&
"The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()");
334 dest = viewAsEigen<DestScalar,DestOptions,DestIndex>(*x_cs);
337 #endif // EIGEN_PARSED_BY_DOXYGEN
339 template<
typename Stream>
370 template<
typename _MatrixType,
int _UpLo = Lower>
393 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
417 template<
typename _MatrixType,
int _UpLo = Lower>
440 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
462 template<
typename _MatrixType,
int _UpLo = Lower>
485 m_cholmod.supernodal = CHOLMOD_SUPERNODAL;
509 template<
typename _MatrixType,
int _UpLo = Lower>
539 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
544 m_cholmod.supernodal = CHOLMOD_SUPERNODAL;
548 m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
564 template<
typename _MatrixType,
int _UpLo,
typename Derived,
typename Rhs>
565 struct solve_retval<CholmodBase<_MatrixType,_UpLo,Derived>, Rhs>
566 : solve_retval_base<CholmodBase<_MatrixType,_UpLo,Derived>, Rhs>
568 typedef CholmodBase<_MatrixType,_UpLo,Derived> Dec;
571 template<typename Dest>
void evalTo(Dest& dst)
const
573 dec()._solve(rhs(),dst);
577 template<
typename _MatrixType,
int _UpLo,
typename Derived,
typename Rhs>
578 struct sparse_solve_retval<CholmodBase<_MatrixType,_UpLo,Derived>, Rhs>
579 : sparse_solve_retval_base<CholmodBase<_MatrixType,_UpLo,Derived>, Rhs>
581 typedef CholmodBase<_MatrixType,_UpLo,Derived> Dec;
584 template<typename Dest>
void evalTo(Dest& dst)
const
586 dec()._solve(rhs(),dst);
594 #endif // EIGEN_CHOLMODSUPPORT_H