mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 11:49:02 +08:00
formatting
This commit is contained in:
parent
04665ef9e1
commit
cacbc5679d
@ -78,7 +78,8 @@ bool gmres(const MatrixType & mat, const Rhs & rhs, Dest & x, const Precondition
|
|||||||
const RealScalar r0Norm = r0.norm();
|
const RealScalar r0Norm = r0.norm();
|
||||||
|
|
||||||
// is initial guess already good enough?
|
// is initial guess already good enough?
|
||||||
if(r0Norm == 0) {
|
if(r0Norm == 0)
|
||||||
|
{
|
||||||
tol_error = 0;
|
tol_error = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -95,10 +96,10 @@ bool gmres(const MatrixType & mat, const Rhs & rhs, Dest & x, const Precondition
|
|||||||
Ref<VectorType> H0_tail = H.col(0).tail(m - 1);
|
Ref<VectorType> H0_tail = H.col(0).tail(m - 1);
|
||||||
RealScalar beta;
|
RealScalar beta;
|
||||||
r0.makeHouseholder(H0_tail, tau.coeffRef(0), beta);
|
r0.makeHouseholder(H0_tail, tau.coeffRef(0), beta);
|
||||||
w(0)=(Scalar) beta;
|
w(0) = Scalar(beta);
|
||||||
|
|
||||||
for (Index k = 1; k <= restart; ++k) {
|
|
||||||
|
|
||||||
|
for (Index k = 1; k <= restart; ++k)
|
||||||
|
{
|
||||||
++iters;
|
++iters;
|
||||||
|
|
||||||
v = VectorType::Unit(m, k - 1);
|
v = VectorType::Unit(m, k - 1);
|
||||||
@ -117,29 +118,30 @@ bool gmres(const MatrixType & mat, const Rhs & rhs, Dest & x, const Precondition
|
|||||||
v.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data());
|
v.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v.tail(m - k).norm() != 0.0) {
|
if (v.tail(m - k).norm() != 0.0)
|
||||||
if (k <= restart) {
|
{
|
||||||
|
if (k <= restart)
|
||||||
|
{
|
||||||
// generate new Householder vector
|
// generate new Householder vector
|
||||||
Ref<VectorType> Hk_tail = H.col(k).tail(m - k - 1);
|
Ref<VectorType> Hk_tail = H.col(k).tail(m - k - 1);
|
||||||
|
|
||||||
v.tail(m - k).makeHouseholder(Hk_tail, tau.coeffRef(k), beta);
|
v.tail(m - k).makeHouseholder(Hk_tail, tau.coeffRef(k), beta);
|
||||||
|
|
||||||
// apply Householder reflection H_{k} to v
|
// apply Householder reflection H_{k} to v
|
||||||
v.tail(m - k).applyHouseholderOnTheLeft(Hk_tail, tau.coeffRef(k), workspace.data());
|
v.tail(m - k).applyHouseholderOnTheLeft(Hk_tail, tau.coeffRef(k), workspace.data());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k > 1) {
|
if (k > 1)
|
||||||
for (Index i = 0; i < k - 1; ++i) {
|
{
|
||||||
|
for (Index i = 0; i < k - 1; ++i)
|
||||||
|
{
|
||||||
// apply old Givens rotations to v
|
// apply old Givens rotations to v
|
||||||
v.applyOnTheLeft(i, i + 1, G[i].adjoint());
|
v.applyOnTheLeft(i, i + 1, G[i].adjoint());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k<m && v(k) != (Scalar) 0) {
|
if (k<m && v(k) != (Scalar) 0)
|
||||||
|
{
|
||||||
// determine next Givens rotation
|
// determine next Givens rotation
|
||||||
G[k - 1].makeGivens(v(k - 1), v(k));
|
G[k - 1].makeGivens(v(k - 1), v(k));
|
||||||
|
|
||||||
@ -153,11 +155,11 @@ bool gmres(const MatrixType & mat, const Rhs & rhs, Dest & x, const Precondition
|
|||||||
|
|
||||||
bool stop = (k==m || abs(w(k)) < tol * r0Norm || iters == maxIters);
|
bool stop = (k==m || abs(w(k)) < tol * r0Norm || iters == maxIters);
|
||||||
|
|
||||||
if (stop || k == restart) {
|
if (stop || k == restart)
|
||||||
|
{
|
||||||
// solve upper triangular system
|
// solve upper triangular system
|
||||||
VectorType y = w.head(k);
|
VectorType y = w.head(k);
|
||||||
H.topLeftCorner(k, k).template triangularView < Eigen::Upper > ().solveInPlace(y);
|
H.topLeftCorner(k, k).template triangularView <Upper>().solveInPlace(y);
|
||||||
|
|
||||||
// use Horner-like scheme to calculate solution vector
|
// use Horner-like scheme to calculate solution vector
|
||||||
VectorType x_new = y(k - 1) * VectorType::Unit(m, k - 1);
|
VectorType x_new = y(k - 1) * VectorType::Unit(m, k - 1);
|
||||||
@ -165,7 +167,8 @@ bool gmres(const MatrixType & mat, const Rhs & rhs, Dest & x, const Precondition
|
|||||||
// apply Householder reflection H_{k} to x_new
|
// apply Householder reflection H_{k} to x_new
|
||||||
x_new.tail(m - k + 1).applyHouseholderOnTheLeft(H.col(k - 1).tail(m - k), tau.coeffRef(k - 1), workspace.data());
|
x_new.tail(m - k + 1).applyHouseholderOnTheLeft(H.col(k - 1).tail(m - k), tau.coeffRef(k - 1), workspace.data());
|
||||||
|
|
||||||
for (Index i = k - 2; i >= 0; --i) {
|
for (Index i = k - 2; i >= 0; --i)
|
||||||
|
{
|
||||||
x_new += y(i) * VectorType::Unit(m, i);
|
x_new += y(i) * VectorType::Unit(m, i);
|
||||||
// apply Householder reflection H_{i} to x_new
|
// apply Householder reflection H_{i} to x_new
|
||||||
x_new.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data());
|
x_new.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data());
|
||||||
@ -173,9 +176,12 @@ bool gmres(const MatrixType & mat, const Rhs & rhs, Dest & x, const Precondition
|
|||||||
|
|
||||||
x += x_new;
|
x += x_new;
|
||||||
|
|
||||||
if (stop) {
|
if (stop)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
k=0;
|
k=0;
|
||||||
|
|
||||||
// reset data for restart
|
// reset data for restart
|
||||||
@ -190,12 +196,8 @@ bool gmres(const MatrixType & mat, const Rhs & rhs, Dest & x, const Precondition
|
|||||||
// generate first Householder vector
|
// generate first Householder vector
|
||||||
r0.makeHouseholder(H0_tail, tau.coeffRef(0), beta);
|
r0.makeHouseholder(H0_tail, tau.coeffRef(0), beta);
|
||||||
w(0)=(Scalar) beta;
|
w(0)=(Scalar) beta;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user