12 #ifndef BOGUS_EIGEN_SPARSE_LINEAR_SOLVERS_HPP
13 #define BOGUS_EIGEN_SPARSE_LINEAR_SOLVERS_HPP
19 #include "SparseHeader.hpp"
21 #ifdef BOGUS_WITH_EIGEN_STABLE_SPARSE_API
23 #include "EigenLinearSolvers.hpp"
24 #include "../Utils/LinearSolverBase.hpp"
25 #include "../Utils/NaiveSharedPtr.hpp"
27 #include <Eigen/OrderingMethods>
30 #ifndef EIGEN_MPL2_ONLY
32 #include <Eigen/SparseCholesky>
33 #define BOGUS_WITH_EIGEN_SPARSE_LDLT
37 #if ! EIGEN_VERSION_AT_LEAST(3,2,90)
38 template <
typename MatrixType,
typename RhsType >
39 struct EigenSolveResult< Eigen::SimplicialLDLT< MatrixType >, RhsType >
41 typedef Eigen::SimplicialLDLT< MatrixType > FactType ;
42 typedef Eigen::internal::solve_retval< Eigen::SimplicialCholeskyBase< FactType >, RhsType > Type ;
46 template <
typename Derived >
47 struct LinearSolverTraits< LDLT< Eigen::SparseMatrixBase< Derived > > >
49 typedef typename Derived::PlainObject MatrixType ;
50 typedef Eigen::SimplicialLDLT< MatrixType > FactType ;
52 template <
typename RhsT >
struct Result {
53 typedef typename EigenSolveResult< FactType, RhsT >::Type Type ;
55 template <
typename RhsT >
56 struct Result< Eigen::MatrixBase< RhsT > > {
57 typedef typename Result< RhsT >::Type Type ;
62 template <
typename Derived >
63 struct LDLT< Eigen::SparseMatrixBase< Derived > >
64 :
public LinearSolverBase< LDLT< Eigen::SparseMatrixBase< Derived > > >
66 typedef Eigen::SparseMatrixBase< Derived > MatrixType ;
67 typedef LinearSolverTraits< LDLT< MatrixType > > Traits ;
70 template<
typename OtherDerived >
71 explicit LDLT (
const Eigen::SparseMatrixBase< OtherDerived >& mat )
72 : m_fact( new typename Traits::FactType( mat ) )
75 template<
typename OtherDerived >
76 LDLT& compute (
const Eigen::SparseMatrixBase< OtherDerived >& mat )
78 m_fact.reset(
new typename Traits::FactType( mat ) ) ;
82 template <
typename RhsT,
typename ResT >
83 void solve(
const Eigen::MatrixBase< RhsT >& rhs, ResT& res )
const
86 res = m_fact->solve( rhs ) ;
89 template <
typename RhsT >
90 typename Traits::template Result< Eigen::MatrixBase< RhsT > >::Type
91 solve(
const Eigen::MatrixBase< RhsT >& rhs )
const
94 return m_fact->solve( rhs ) ;
97 const typename Traits::FactType& factorization()
const {
102 BOGUS_SHARED_PTR(
typename Traits::FactType, m_fact ) ;
105 template <
typename Scalar,
int _Options = 0,
typename _Index =
int >
106 struct SparseLDLT :
public LDLT< Eigen::SparseMatrixBase< Eigen::SparseMatrix< Scalar, _Options, _Index > > >
109 template<
typename OtherDerived >
110 explicit SparseLDLT (
const Eigen::SparseMatrixBase< OtherDerived >& mat )
111 : LDLT< Eigen::SparseMatrixBase< Eigen::SparseMatrix< Scalar, _Options, _Index > > >( mat )
120 #if EIGEN_VERSION_AT_LEAST(3,1,92)
122 #include <Eigen/SparseLU>
124 #define BOGUS_WITH_EIGEN_SPARSE_LU
128 template <
typename Derived >
129 struct LinearSolverTraits< LU< Eigen::SparseMatrixBase< Derived > > >
131 typedef typename Derived::PlainObject MatrixType ;
132 typedef Eigen::SparseLU< MatrixType, Eigen::COLAMDOrdering<int> > FactType ;
134 template <
typename RhsT >
struct Result {
135 typedef typename EigenSolveResult< FactType, RhsT >::Type Type ;
137 template <
typename RhsT >
138 struct Result< Eigen::MatrixBase< RhsT > > {
139 typedef typename Result< RhsT >::Type Type ;
144 template <
typename Derived >
145 struct LU< Eigen::SparseMatrixBase< Derived > >
146 :
public LinearSolverBase< LU< Eigen::SparseMatrixBase< Derived > > >
148 typedef Eigen::SparseMatrixBase< Derived > MatrixType ;
149 typedef LinearSolverTraits< LU< MatrixType > > Traits ;
152 template<
typename OtherDerived >
153 explicit LU (
const Eigen::SparseMatrixBase< OtherDerived >& mat )
154 : m_fact( new typename Traits::FactType( mat ) )
157 template<
typename OtherDerived >
158 LU& compute (
const Eigen::SparseMatrixBase< OtherDerived >& mat )
160 m_fact.reset(
new typename Traits::FactType( mat ) ) ;
164 template <
typename RhsT,
typename ResT >
165 void solve(
const Eigen::MatrixBase< RhsT >& rhs, ResT& res )
const
168 res = m_fact->solve( rhs ) ;
171 template <
typename RhsT >
172 typename Traits::template Result< Eigen::MatrixBase< RhsT > >::Type
173 solve(
const Eigen::MatrixBase< RhsT >& rhs )
const
176 return m_fact->solve( rhs ) ;
179 const typename Traits::FactType& factorization()
const {
184 BOGUS_SHARED_PTR(
typename Traits::FactType, m_fact ) ;
187 template <
typename Scalar,
int _Options = 0,
typename _Index =
int >
188 struct SparseLU :
public LU< Eigen::SparseMatrixBase< Eigen::SparseMatrix< Scalar, _Options, _Index > > >
191 template<
typename OtherDerived >
192 explicit SparseLU (
const Eigen::SparseMatrixBase< OtherDerived >& mat )
193 : LU< Eigen::SparseMatrixBase< Eigen::SparseMatrix< Scalar, _Options, _Index > > >( mat )
201 #endif // EIGEN_STABLE_API
LinearSolverTraits< LDLT< MatrixType > >::template Result< RhsT >::Type solve(const RhsT &rhs) const
Returns the solution x of the linear system M * x = rhs.
Definition: LinearSolverBase.hpp:32