10#ifndef EIGEN_ITERATIVE_SOLVER_BASE_H
11#define EIGEN_ITERATIVE_SOLVER_BASE_H
17template<
typename MatrixType>
21 template <
typename T0>
24 template <
typename T> any_conversion(
const volatile T&);
25 template <
typename T> any_conversion(T&);
27 struct yes {
int a[1];};
28 struct no {
int a[2];};
36 static MatrixType ms_from;
40template<
typename MatrixType>
50template<
typename MatrixType>
55 template<
int UpLo>
struct ConstSelfAdjointViewReturnType {
56 typedef typename ActualMatrixType::template ConstSelfAdjointViewReturnType<UpLo>::Type Type;
64 : m_dummy(0,0), m_matrix(m_dummy)
67 template<
typename InputType>
72 const ActualMatrixType& matrix()
const
77 template<
typename MatrixDerived>
78 void grab(
const EigenBase<MatrixDerived> &mat)
80 m_matrix.~Ref<
const MatrixType>();
81 ::new (&m_matrix) Ref<const MatrixType>(mat.derived());
84 void grab(
const Ref<const MatrixType> &mat)
86 if(&(mat.derived()) != &m_matrix)
88 m_matrix.~Ref<
const MatrixType>();
89 ::new (&m_matrix) Ref<const MatrixType>(mat);
95 ActualMatrixType m_matrix;
99template<
typename MatrixType>
103 typedef MatrixType ActualMatrixType;
104 template<
int UpLo>
struct ConstSelfAdjointViewReturnType
106 typedef ActualMatrixType Type;
117 generic_matrix_wrapper(
const MatrixType &
mat)
121 const ActualMatrixType& matrix()
const
126 void grab(
const MatrixType &mat)
132 const ActualMatrixType *mp_matrix;
142template<
typename Derived>
147 using Base::m_isInitialized;
152 typedef typename MatrixType::Scalar Scalar;
153 typedef typename MatrixType::StorageIndex StorageIndex;
154 typedef typename MatrixType::RealScalar RealScalar;
157 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
158 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
181 template<
typename MatrixDerived>
183 : m_matrixWrapper(A.derived())
196 template<
typename MatrixDerived>
200 m_preconditioner.analyzePattern(matrix());
201 m_isInitialized =
true;
202 m_analysisIsOk =
true;
203 m_info = m_preconditioner.info();
216 template<
typename MatrixDerived>
219 eigen_assert(m_analysisIsOk &&
"You must first call analyzePattern()");
221 m_preconditioner.factorize(matrix());
222 m_factorizationIsOk =
true;
223 m_info = m_preconditioner.info();
237 template<
typename MatrixDerived>
241 m_preconditioner.compute(matrix());
242 m_isInitialized =
true;
243 m_analysisIsOk =
true;
244 m_factorizationIsOk =
true;
245 m_info = m_preconditioner.info();
250 Index rows()
const {
return matrix().rows(); }
253 Index cols()
const {
return matrix().cols(); }
283 return (m_maxIterations<0) ? 2*matrix().cols() : m_maxIterations;
298 eigen_assert(m_isInitialized &&
"ConjugateGradient is not initialized.");
307 eigen_assert(m_isInitialized &&
"ConjugateGradient is not initialized.");
316 template<
typename Rhs,
typename Guess>
320 eigen_assert(m_isInitialized &&
"Solver is not initialized.");
321 eigen_assert(derived().rows()==b.rows() &&
"solve(): invalid number of rows of the right hand side matrix b");
328 eigen_assert(m_isInitialized &&
"IterativeSolverBase is not initialized.");
333 template<
typename Rhs,
typename DestScalar,
int DestOptions,
typename DestIndex>
336 eigen_assert(rows()==b.rows());
339 Index size = b.rows();
348 tx = derived().solve(
tb);
349 tmp.col(k) =
tx.sparseView(0);
357 m_isInitialized =
false;
358 m_analysisIsOk =
false;
359 m_factorizationIsOk =
false;
360 m_maxIterations = -1;
361 m_tolerance = NumTraits<Scalar>::epsilon();
364 typedef internal::generic_matrix_wrapper<MatrixType> MatrixWrapper;
365 typedef typename MatrixWrapper::ActualMatrixType ActualMatrixType;
367 const ActualMatrixType& matrix()
const
369 return m_matrixWrapper.matrix();
372 template<
typename InputType>
373 void grab(
const InputType &A)
375 m_matrixWrapper.grab(A);
378 MatrixWrapper m_matrixWrapper;
379 Preconditioner m_preconditioner;
381 Index m_maxIterations;
382 RealScalar m_tolerance;
384 mutable RealScalar m_error;
385 mutable Index m_iterations;
387 mutable bool m_analysisIsOk, m_factorizationIsOk;
Base class for linear iterative solvers.
Definition IterativeSolverBase.h:144
IterativeSolverBase()
Default constructor.
Definition IterativeSolverBase.h:166
ComputationInfo info() const
Definition IterativeSolverBase.h:326
RealScalar error() const
Definition IterativeSolverBase.h:305
Index maxIterations() const
Definition IterativeSolverBase.h:281
Derived & setMaxIterations(Index maxIters)
Sets the max number of iterations.
Definition IterativeSolverBase.h:289
Derived & compute(const EigenBase< MatrixDerived > &A)
Initializes the iterative solver with the matrix A for further solving Ax=b problems.
Definition IterativeSolverBase.h:238
IterativeSolverBase(const EigenBase< MatrixDerived > &A)
Initialize the solver with matrix A for further Ax=b solving.
Definition IterativeSolverBase.h:182
const Preconditioner & preconditioner() const
Definition IterativeSolverBase.h:275
Derived & analyzePattern(const EigenBase< MatrixDerived > &A)
Initializes the iterative solver for the sparsity pattern of the matrix A for further solving Ax=b pr...
Definition IterativeSolverBase.h:197
Derived & factorize(const EigenBase< MatrixDerived > &A)
Initializes the iterative solver with the numerical values of the matrix A for further solving Ax=b p...
Definition IterativeSolverBase.h:217
Preconditioner & preconditioner()
Definition IterativeSolverBase.h:272
Derived & setTolerance(const RealScalar &tolerance)
Sets the tolerance threshold used by the stopping criteria.
Definition IterativeSolverBase.h:265
RealScalar tolerance() const
Definition IterativeSolverBase.h:258
const SolveWithGuess< Derived, Rhs, Guess > solveWithGuess(const MatrixBase< Rhs > &b, const Guess &x0) const
Definition IterativeSolverBase.h:318
Index iterations() const
Definition IterativeSolverBase.h:296
Pseudo expression representing a solving operation.
Definition Solve.h:63
A base class for sparse solvers.
Definition SparseSolverBase.h:54
Definition IterativeSolverBase.h:47
ComputationInfo
Enum for reporting the status of a computation.
Definition Constants.h:430
Definition IterativeSolverBase.h:19
Definition IterativeSolverBase.h:42
Definition ForwardDeclarations.h:17