mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-21 07:19:46 +08:00
Fix GMRES: Initialize essential Householder vector with correct dimension. Add check if initial guess is already a sufficient approximation.
(transplanted from e955725ff1
)
This commit is contained in:
parent
160034bba1
commit
6ff72f40cf
@ -2,7 +2,7 @@
|
|||||||
// for linear algebra.
|
// for linear algebra.
|
||||||
//
|
//
|
||||||
// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
|
// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||||
// Copyright (C) 2012 Kolja Brix <brix@igpm.rwth-aaachen.de>
|
// Copyright (C) 2012, 2014 Kolja Brix <brix@igpm.rwth-aaachen.de>
|
||||||
//
|
//
|
||||||
// This Source Code Form is subject to the terms of the Mozilla
|
// This Source Code Form is subject to the terms of the Mozilla
|
||||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||||
@ -72,16 +72,20 @@ bool gmres(const MatrixType & mat, const Rhs & rhs, Dest & x, const Precondition
|
|||||||
|
|
||||||
VectorType p0 = rhs - mat*x;
|
VectorType p0 = rhs - mat*x;
|
||||||
VectorType r0 = precond.solve(p0);
|
VectorType r0 = precond.solve(p0);
|
||||||
// RealScalar r0_sqnorm = r0.squaredNorm();
|
|
||||||
|
// is initial guess already good enough?
|
||||||
|
if(abs(r0.norm()) < tol) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
VectorType w = VectorType::Zero(restart + 1);
|
VectorType w = VectorType::Zero(restart + 1);
|
||||||
|
|
||||||
FMatrixType H = FMatrixType::Zero(m, restart + 1);
|
FMatrixType H = FMatrixType::Zero(m, restart + 1); // Hessenberg matrix
|
||||||
VectorType tau = VectorType::Zero(restart + 1);
|
VectorType tau = VectorType::Zero(restart + 1);
|
||||||
std::vector < JacobiRotation < Scalar > > G(restart);
|
std::vector < JacobiRotation < Scalar > > G(restart);
|
||||||
|
|
||||||
// generate first Householder vector
|
// generate first Householder vector
|
||||||
VectorType e;
|
VectorType e(m-1);
|
||||||
RealScalar beta;
|
RealScalar beta;
|
||||||
r0.makeHouseholder(e, tau.coeffRef(0), beta);
|
r0.makeHouseholder(e, tau.coeffRef(0), beta);
|
||||||
w(0)=(Scalar) beta;
|
w(0)=(Scalar) beta;
|
||||||
|
Loading…
Reference in New Issue
Block a user