10 #ifndef EIGEN_BASIC_PRECONDITIONERS_H 11 #define EIGEN_BASIC_PRECONDITIONERS_H 14 #include "./InternalHeaderCheck.h" 38 template <
typename Scalar_>
40 typedef Scalar_ Scalar;
44 typedef typename Vector::StorageIndex StorageIndex;
45 enum { ColsAtCompileTime =
Dynamic, MaxColsAtCompileTime =
Dynamic };
49 template <
typename MatType>
54 constexpr
Index rows()
const noexcept {
return m_invdiag.size(); }
55 constexpr
Index cols()
const noexcept {
return m_invdiag.size(); }
57 template <
typename MatType>
62 template <
typename MatType>
64 m_invdiag.
resize(mat.cols());
65 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>
79 return factorize(mat);
83 template <
typename Rhs,
typename Dest>
84 void _solve_impl(
const Rhs& b, Dest& x)
const {
85 x = m_invdiag.array() * b.array();
88 template <
typename Rhs>
90 eigen_assert(m_isInitialized &&
"DiagonalPreconditioner is not initialized.");
91 eigen_assert(m_invdiag.size() == b.
rows() &&
92 "DiagonalPreconditioner::solve(): invalid number of rows of the right hand side matrix b");
100 bool m_isInitialized;
120 template <
typename Scalar_>
122 typedef Scalar_ Scalar;
125 using Base::m_invdiag;
130 template <
typename MatType>
135 template <
typename MatType>
140 template <
typename MatType>
143 m_invdiag.
resize(mat.cols());
144 if (MatType::IsRowMajor) {
146 for (
Index j = 0; j < mat.outerSize(); ++j) {
147 for (
typename MatType::InnerIterator it(mat, j); it; ++it) m_invdiag(it.index()) += numext::abs2(it.value());
149 for (
Index j = 0; j < mat.cols(); ++j)
150 if (numext::real(m_invdiag(j)) > RealScalar(0)) m_invdiag(j) = RealScalar(1) / numext::real(m_invdiag(j));
152 for (
Index j = 0; j < mat.outerSize(); ++j) {
153 RealScalar sum = mat.col(j).squaredNorm();
154 if (sum > RealScalar(0))
155 m_invdiag(j) = RealScalar(1) / sum;
157 m_invdiag(j) = RealScalar(1);
160 Base::m_isInitialized =
true;
164 template <
typename MatType>
166 return factorize(mat);
185 template <
typename MatrixType>
188 template <
typename MatrixType>
193 template <
typename MatrixType>
198 template <
typename MatrixType>
203 template <
typename Rhs>
204 inline const Rhs& solve(
const Rhs& b)
const {
213 #endif // EIGEN_BASIC_PRECONDITIONERS_H A preconditioner based on the digonal entries.
Definition: BasicPreconditioners.h:39
constexpr Derived & derived()
Definition: EigenBase.h:49
constexpr void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:268
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
Jacobi preconditioner for LeastSquaresConjugateGradient.
Definition: BasicPreconditioners.h:121
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:567
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
Definition: Constants.h:440
A naive preconditioner which approximates any matrix as the identity matrix.
Definition: BasicPreconditioners.h:181
const int Dynamic
Definition: Constants.h:25
Pseudo expression representing a solving operation.
Definition: Solve.h:62
constexpr Index rows() const noexcept
Definition: EigenBase.h:59
ComputationInfo
Definition: Constants.h:438
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52