10 #ifndef EIGEN_BASIC_PRECONDITIONERS_H
11 #define EIGEN_BASIC_PRECONDITIONERS_H
13 #include "./InternalHeaderCheck.h"
37 template <
typename Scalar_>
40 typedef Scalar_ Scalar;
51 template<
typename MatType>
57 EIGEN_CONSTEXPR
Index rows()
const EIGEN_NOEXCEPT {
return m_invdiag.size(); }
58 EIGEN_CONSTEXPR
Index cols()
const EIGEN_NOEXCEPT {
return m_invdiag.size(); }
60 template<
typename MatType>
66 template<
typename MatType>
69 m_invdiag.
resize(mat.cols());
70 for(
int j=0; j<mat.outerSize(); ++j)
72 typename MatType::InnerIterator it(mat,j);
73 while(it && it.index()!=j) ++it;
74 if(it && it.index()==j && it.value()!=Scalar(0))
75 m_invdiag(j) = Scalar(1)/it.value();
77 m_invdiag(j) = Scalar(1);
79 m_isInitialized =
true;
83 template<
typename MatType>
86 return factorize(mat);
90 template<
typename Rhs,
typename Dest>
91 void _solve_impl(
const Rhs& b, Dest& x)
const
93 x = m_invdiag.array() * b.array() ;
99 eigen_assert(m_isInitialized &&
"DiagonalPreconditioner is not initialized.");
100 eigen_assert(m_invdiag.size()==b.
rows()
101 &&
"DiagonalPreconditioner::solve(): invalid number of rows of the right hand side matrix b");
109 bool m_isInitialized;
129 template <
typename Scalar_>
132 typedef Scalar_ Scalar;
135 using Base::m_invdiag;
140 template<
typename MatType>
146 template<
typename MatType>
152 template<
typename MatType>
156 m_invdiag.
resize(mat.cols());
157 if(MatType::IsRowMajor)
160 for(
Index j=0; j<mat.outerSize(); ++j)
162 for(
typename MatType::InnerIterator it(mat,j); it; ++it)
163 m_invdiag(it.index()) += numext::abs2(it.value());
165 for(
Index j=0; j<mat.cols(); ++j)
166 if(numext::real(m_invdiag(j))>RealScalar(0))
167 m_invdiag(j) = RealScalar(1)/numext::real(m_invdiag(j));
171 for(
Index j=0; j<mat.outerSize(); ++j)
173 RealScalar sum = mat.col(j).squaredNorm();
174 if(sum>RealScalar(0))
175 m_invdiag(j) = RealScalar(1)/sum;
177 m_invdiag(j) = RealScalar(1);
180 Base::m_isInitialized =
true;
184 template<
typename MatType>
187 return factorize(mat);
208 template<
typename MatrixType>
211 template<
typename MatrixType>
214 template<
typename MatrixType>
217 template<
typename MatrixType>
220 template<
typename Rhs>
221 inline const Rhs& solve(
const Rhs& b)
const {
return b; }
internal::traits< Derived >::StorageIndex StorageIndex
The type used to store indices.
Definition: DenseBase.h:58
Derived & derived()
Definition: EigenBase.h:48
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:62
A preconditioner based on the digonal entries.
Definition: BasicPreconditioners.h:39
A naive preconditioner which approximates any matrix as the identity matrix.
Definition: BasicPreconditioners.h:203
Jacobi preconditioner for LeastSquaresConjugateGradient.
Definition: BasicPreconditioners.h:131
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:283
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:564
Pseudo expression representing a solving operation.
Definition: Solve.h:65
ComputationInfo
Definition: Constants.h:442
@ Success
Definition: Constants.h:444
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:231