10 #ifndef EIGEN_BASIC_PRECONDITIONERS_H
11 #define EIGEN_BASIC_PRECONDITIONERS_H
32 template <
typename _Scalar>
35 typedef _Scalar Scalar;
37 typedef typename Vector::Index Index;
45 template<
typename MatType>
51 Index rows()
const {
return m_invdiag.size(); }
52 Index cols()
const {
return m_invdiag.size(); }
54 template<
typename MatType>
60 template<
typename MatType>
63 m_invdiag.
resize(mat.cols());
64 for(
int j=0; j<mat.outerSize(); ++j)
66 typename MatType::InnerIterator it(mat,j);
67 while(it && it.index()!=j) ++it;
68 if(it && it.index()==j && it.value()!=Scalar(0))
69 m_invdiag(j) = Scalar(1)/it.value();
71 m_invdiag(j) = Scalar(1);
73 m_isInitialized =
true;
77 template<
typename MatType>
80 return factorize(mat);
83 template<
typename Rhs,
typename Dest>
84 void _solve(
const Rhs& b, Dest& x)
const
86 x = m_invdiag.array() * b.array() ;
89 template<
typename Rhs>
inline const internal::solve_retval<DiagonalPreconditioner, Rhs>
92 eigen_assert(m_isInitialized &&
"DiagonalPreconditioner is not initialized.");
93 eigen_assert(m_invdiag.size()==b.rows()
94 &&
"DiagonalPreconditioner::solve(): invalid number of rows of the right hand side matrix b");
95 return internal::solve_retval<DiagonalPreconditioner, Rhs>(*
this, b.derived());
100 bool m_isInitialized;
105 template<
typename _MatrixType,
typename Rhs>
107 : solve_retval_base<DiagonalPreconditioner<_MatrixType>, Rhs>
110 EIGEN_MAKE_SOLVE_HELPERS(Dec,Rhs)
112 template<typename Dest>
void evalTo(Dest& dst)
const
114 dec()._solve(rhs(),dst);
131 template<
typename MatrixType>
134 template<
typename MatrixType>
137 template<
typename MatrixType>
140 template<
typename MatrixType>
143 template<
typename Rhs>
144 inline const Rhs& solve(
const Rhs& b)
const {
return b; }
149 #endif // EIGEN_BASIC_PRECONDITIONERS_H
A preconditioner based on the digonal entries.
Definition: BasicPreconditioners.h:33
A naive preconditioner which approximates any matrix as the identity matrix.
Definition: BasicPreconditioners.h:125
void resize(Index nbRows, Index nbCols)
Definition: PlainObjectBase.h:235
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48