From bdee0c9baa6a6b48ea4dee803152d5568bcefb58 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 27 Dec 2011 16:38:05 +0100 Subject: [PATCH] set the default number of iteration to the size of the problem --- Eigen/src/IterativeLinearSolvers/BiCGSTAB.h | 6 +++--- Eigen/src/IterativeLinearSolvers/ConjugateGradient.h | 8 ++++---- .../src/IterativeLinearSolvers/IterativeSolverBase.h | 11 +++++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h b/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h index 574b47384..b8073915e 100644 --- a/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +++ b/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h @@ -125,8 +125,8 @@ struct traits > * \tparam _Preconditioner the type of the preconditioner. Default is DiagonalPreconditioner * * The maximal number of iterations and tolerance value can be controlled via the setMaxIterations() - * and setTolerance() methods. The default are 1000 max iterations and NumTraits::epsilon() - * for the tolerance. + * and setTolerance() methods. The defaults are the size of the problem for the maximal number of iterations + * and NumTraits::epsilon() for the tolerance. * * This class can be used as the direct solver classes. Here is a typical usage example: * \code @@ -218,7 +218,7 @@ public: { for(int j=0; j > * \tparam _Preconditioner the type of the preconditioner. Default is DiagonalPreconditioner * * The maximal number of iterations and tolerance value can be controlled via the setMaxIterations() - * and setTolerance() methods. The default are 1000 max iterations and NumTraits::epsilon() - * for the tolerance. + * and setTolerance() methods. The defaults are the size of the problem for the maximal number of iterations + * and NumTraits::epsilon() for the tolerance. * * This class can be used as the direct solver classes. Here is a typical usage example: * \code @@ -206,12 +206,12 @@ public: template void _solveWithGuess(const Rhs& b, Dest& x) const { - m_iterations = Base::m_maxIterations; + m_iterations = Base::maxIterations(); m_error = Base::m_tolerance; for(int j=0; jrows(); } + Index rows() const { return mp_matrix ? mp_matrix->rows() : 0; } /** \internal */ - Index cols() const { return mp_matrix->cols(); } + Index cols() const { return mp_matrix ? mp_matrix->cols() : 0; } /** \returns the tolerance threshold used by the stopping criteria */ RealScalar tolerance() const { return m_tolerance; } @@ -112,7 +112,10 @@ public: const Preconditioner& preconditioner() const { return m_preconditioner; } /** \returns the max number of iterations */ - int maxIterations() const { return m_maxIterations; } + int maxIterations() const + { + return (mp_matrix && m_maxIterations<0) ? mp_matrix->cols() : m_maxIterations; + } /** Sets the max number of iterations */ Derived& setMaxIterations(int maxIters) @@ -191,7 +194,7 @@ protected: void init() { m_isInitialized = false; - m_maxIterations = 1000; + m_maxIterations = -1; m_tolerance = NumTraits::epsilon(); } const MatrixType* mp_matrix;