mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-06 03:57:01 +08:00
Fix IterativeSolverBase for expressions as input
This commit is contained in:
parent
47592d31ea
commit
a92681e0d2
@ -49,10 +49,11 @@ public:
|
|||||||
* this class becomes invalid. Call compute() to update it with the new
|
* this class becomes invalid. Call compute() to update it with the new
|
||||||
* matrix A, or modify a copy of A.
|
* matrix A, or modify a copy of A.
|
||||||
*/
|
*/
|
||||||
IterativeSolverBase(const MatrixType& A)
|
template<typename InputDerived>
|
||||||
|
IterativeSolverBase(const EigenBase<InputDerived>& A)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
compute(A);
|
compute(A.derived());
|
||||||
}
|
}
|
||||||
|
|
||||||
~IterativeSolverBase() {}
|
~IterativeSolverBase() {}
|
||||||
@ -62,9 +63,11 @@ public:
|
|||||||
* Currently, this function mostly call analyzePattern on the preconditioner. In the future
|
* Currently, this function mostly call analyzePattern on the preconditioner. In the future
|
||||||
* we might, for instance, implement column reodering for faster matrix vector products.
|
* we might, for instance, implement column reodering for faster matrix vector products.
|
||||||
*/
|
*/
|
||||||
Derived& analyzePattern(const MatrixType& A)
|
template<typename InputDerived>
|
||||||
|
Derived& analyzePattern(const EigenBase<InputDerived>& A)
|
||||||
{
|
{
|
||||||
m_preconditioner.analyzePattern(A);
|
grabInput(A.derived());
|
||||||
|
m_preconditioner.analyzePattern(*mp_matrix);
|
||||||
m_isInitialized = true;
|
m_isInitialized = true;
|
||||||
m_analysisIsOk = true;
|
m_analysisIsOk = true;
|
||||||
m_info = Success;
|
m_info = Success;
|
||||||
@ -80,11 +83,12 @@ public:
|
|||||||
* this class becomes invalid. Call compute() to update it with the new
|
* this class becomes invalid. Call compute() to update it with the new
|
||||||
* matrix A, or modify a copy of A.
|
* matrix A, or modify a copy of A.
|
||||||
*/
|
*/
|
||||||
Derived& factorize(const MatrixType& A)
|
template<typename InputDerived>
|
||||||
|
Derived& factorize(const EigenBase<InputDerived>& A)
|
||||||
{
|
{
|
||||||
|
grabInput(A.derived());
|
||||||
eigen_assert(m_analysisIsOk && "You must first call analyzePattern()");
|
eigen_assert(m_analysisIsOk && "You must first call analyzePattern()");
|
||||||
mp_matrix = &A;
|
m_preconditioner.factorize(*mp_matrix);
|
||||||
m_preconditioner.factorize(A);
|
|
||||||
m_factorizationIsOk = true;
|
m_factorizationIsOk = true;
|
||||||
m_info = Success;
|
m_info = Success;
|
||||||
return derived();
|
return derived();
|
||||||
@ -100,10 +104,11 @@ public:
|
|||||||
* this class becomes invalid. Call compute() to update it with the new
|
* this class becomes invalid. Call compute() to update it with the new
|
||||||
* matrix A, or modify a copy of A.
|
* matrix A, or modify a copy of A.
|
||||||
*/
|
*/
|
||||||
Derived& compute(const MatrixType& A)
|
template<typename InputDerived>
|
||||||
|
Derived& compute(const EigenBase<InputDerived>& A)
|
||||||
{
|
{
|
||||||
mp_matrix = &A;
|
grabInput(A.derived());
|
||||||
m_preconditioner.compute(A);
|
m_preconditioner.compute(*mp_matrix);
|
||||||
m_isInitialized = true;
|
m_isInitialized = true;
|
||||||
m_analysisIsOk = true;
|
m_analysisIsOk = true;
|
||||||
m_factorizationIsOk = true;
|
m_factorizationIsOk = true;
|
||||||
@ -212,6 +217,28 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
template<typename InputDerived>
|
||||||
|
void grabInput(const EigenBase<InputDerived>& A)
|
||||||
|
{
|
||||||
|
// we const cast to prevent the creation of a MatrixType temporary by the compiler.
|
||||||
|
grabInput_impl(A.const_cast_derived());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename InputDerived>
|
||||||
|
void grabInput_impl(const EigenBase<InputDerived>& A)
|
||||||
|
{
|
||||||
|
m_copyMatrix = A;
|
||||||
|
mp_matrix = &m_copyMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void grabInput_impl(MatrixType& A)
|
||||||
|
{
|
||||||
|
if(MatrixType::RowsAtCompileTime==Dynamic && MatrixType::ColsAtCompileTime==Dynamic)
|
||||||
|
m_copyMatrix.resize(0,0);
|
||||||
|
mp_matrix = &A;
|
||||||
|
}
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
m_isInitialized = false;
|
m_isInitialized = false;
|
||||||
@ -220,6 +247,7 @@ protected:
|
|||||||
m_maxIterations = -1;
|
m_maxIterations = -1;
|
||||||
m_tolerance = NumTraits<Scalar>::epsilon();
|
m_tolerance = NumTraits<Scalar>::epsilon();
|
||||||
}
|
}
|
||||||
|
MatrixType m_copyMatrix;
|
||||||
const MatrixType* mp_matrix;
|
const MatrixType* mp_matrix;
|
||||||
Preconditioner m_preconditioner;
|
Preconditioner m_preconditioner;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user