10 #ifndef EIGEN_BASIC_PRECONDITIONERS_H
11 #define EIGEN_BASIC_PRECONDITIONERS_H
33 template <
typename _Scalar>
36 typedef _Scalar Scalar;
39 typedef typename Vector::StorageIndex StorageIndex;
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);
84 template<
typename Rhs,
typename Dest>
85 void _solve_impl(
const Rhs& b, Dest& x)
const
87 x = m_invdiag.array() * b.array() ;
93 eigen_assert(m_isInitialized &&
"DiagonalPreconditioner is not initialized.");
94 eigen_assert(m_invdiag.size()==b.rows()
95 &&
"DiagonalPreconditioner::solve(): invalid number of rows of the right hand side matrix b");
103 bool m_isInitialized;
121 template <
typename _Scalar>
124 typedef _Scalar Scalar;
127 using Base::m_invdiag;
132 template<
typename MatType>
138 template<
typename MatType>
144 template<
typename MatType>
148 m_invdiag.
resize(mat.cols());
149 for(Index j=0; j<mat.outerSize(); ++j)
151 RealScalar sum = mat.innerVector(j).squaredNorm();
153 m_invdiag(j) = RealScalar(1)/sum;
155 m_invdiag(j) = RealScalar(1);
157 Base::m_isInitialized =
true;
161 template<
typename MatType>
164 return factorize(mat);
183 template<
typename MatrixType>
186 template<
typename MatrixType>
189 template<
typename MatrixType>
192 template<
typename MatrixType>
195 template<
typename Rhs>
196 inline const Rhs& solve(
const Rhs& b)
const {
return b; }
203 #endif // EIGEN_BASIC_PRECONDITIONERS_H
A preconditioner based on the digonal entries.
Definition: BasicPreconditioners.h:34
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:107
void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:252
Jacobi preconditioner for LeastSquaresConjugateGradient.
Definition: BasicPreconditioners.h:122
Definition: Constants.h:424
A naive preconditioner which approximates any matrix as the identity matrix.
Definition: BasicPreconditioners.h:177
Pseudo expression representing a solving operation.
Definition: Solve.h:63
ComputationInfo
Definition: Constants.h:422
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48