Refactoring of sparse solvers through a SparseSolverBase class and usage of the Solve<> expression. Introduce a SolveWithGuess expression on top of Solve.

This commit is contained in:
Gael Guennebaud
2014-09-01 15:00:19 +02:00
parent bc065c75d2
commit 85c7659574
20 changed files with 565 additions and 131 deletions

View File

@@ -1,7 +1,7 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
@@ -181,7 +181,8 @@ public:
BiCGSTAB(const MatrixType& A) : Base(A) {}
~BiCGSTAB() {}
#ifndef EIGEN_TEST_EVALUATORS
/** \returns the solution x of \f$ A x = b \f$ using the current decomposition of A
* \a x0 as an initial solution.
*
@@ -197,10 +198,26 @@ public:
return internal::solve_retval_with_guess
<BiCGSTAB, Rhs, Guess>(*this, b.derived(), x0);
}
#else
/** \returns the solution x of \f$ A x = b \f$ using the current decomposition of A
* \a x0 as an initial solution.
*
* \sa compute()
*/
template<typename Rhs,typename Guess>
inline const SolveWithGuess<BiCGSTAB, Rhs, Guess>
solveWithGuess(const MatrixBase<Rhs>& b, const Guess& x0) const
{
eigen_assert(m_isInitialized && "BiCGSTAB is not initialized.");
eigen_assert(Base::rows()==b.rows()
&& "BiCGSTAB::solve(): invalid number of rows of the right hand side matrix b");
return SolveWithGuess<BiCGSTAB, Rhs, Guess>(*this, b.derived(), x0);
}
#endif
/** \internal */
template<typename Rhs,typename Dest>
void _solveWithGuess(const Rhs& b, Dest& x) const
void _solve_with_guess_impl(const Rhs& b, Dest& x) const
{
bool failed = false;
for(int j=0; j<b.cols(); ++j)
@@ -219,22 +236,23 @@ public:
}
/** \internal */
using Base::_solve_impl;
template<typename Rhs,typename Dest>
void _solve(const Rhs& b, Dest& x) const
void _solve_impl(const MatrixBase<Rhs>& b, Dest& x) const
{
// x.setZero();
x = b;
_solveWithGuess(b,x);
// x.setZero();
x = b;
_solve_with_guess_impl(b,x);
}
protected:
};
#ifndef EIGEN_TEST_EVALUATORS
namespace internal {
template<typename _MatrixType, typename _Preconditioner, typename Rhs>
template<typename _MatrixType, typename _Preconditioner, typename Rhs>
struct solve_retval<BiCGSTAB<_MatrixType, _Preconditioner>, Rhs>
: solve_retval_base<BiCGSTAB<_MatrixType, _Preconditioner>, Rhs>
{
@@ -243,11 +261,12 @@ struct solve_retval<BiCGSTAB<_MatrixType, _Preconditioner>, Rhs>
template<typename Dest> void evalTo(Dest& dst) const
{
dec()._solve(rhs(),dst);
dec()._solve_impl(rhs(),dst);
}
};
} // end namespace internal
#endif
} // end namespace Eigen