55 template<
typename MatrixType,
typename Rhs,
typename Dest,
typename Preconditioner>
68 const Index maxIters = iters;
74 VectorType p0 = rhs -
mat*
x;
75 VectorType r0 = precond.solve(p0);
87 FMatrixType H = FMatrixType::Zero(m, restart + 1);
88 VectorType w = VectorType::Zero(restart + 1);
89 VectorType tau = VectorType::Zero(restart + 1);
92 std::vector < JacobiRotation < Scalar > > G(restart);
95 VectorType t(m), v(m), workspace(m), x_new(m);
100 r0.makeHouseholder(H0_tail, tau.coeffRef(0), beta);
103 for (
Index k = 1; k <= restart; ++k)
107 v = VectorType::Unit(m, k - 1);
111 for (
Index i = k - 1; i >= 0; --i) {
112 v.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data());
116 t.noalias() =
mat * v;
117 v = precond.solve(t);
121 for (
Index i = 0; i < k; ++i) {
122 v.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data());
125 if (v.tail(m - k).norm() != 0.0)
131 v.tail(m - k).makeHouseholder(Hk_tail, tau.coeffRef(k), beta);
134 v.tail(m - k).applyHouseholderOnTheLeft(Hk_tail, tau.coeffRef(k), workspace.data());
140 for (
Index i = 0; i < k - 1; ++i)
143 v.applyOnTheLeft(i, i + 1, G[i].adjoint());
147 if (k<m && v(k) != (
Scalar) 0)
150 G[k - 1].makeGivens(v(k - 1), v(k));
153 v.applyOnTheLeft(k - 1, k, G[k - 1].adjoint());
154 w.applyOnTheLeft(k - 1, k, G[k - 1].adjoint());
158 H.col(k-1).head(k) = v.head(k);
160 tol_error =
abs(w(k)) / r0Norm;
161 bool stop = (k==m || tol_error < tol || iters == maxIters);
163 if (stop || k == restart)
167 H.topLeftCorner(k, k).template triangularView <Upper>().solveInPlace(
y);
171 for (
Index i = k - 1; i >= 0; --i)
175 x_new.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data());
189 p0.noalias() = rhs -
mat*
x;
190 r0 = precond.solve(p0);
198 r0.makeHouseholder(H0_tail, tau.coeffRef(0), beta);
210 template<
typename _MatrixType,
211 typename _Preconditioner = DiagonalPreconditioner<typename _MatrixType::Scalar> >
216 template<
typename _MatrixType,
typename _Preconditioner>
259 template<
typename _MatrixType,
typename _Preconditioner>
294 template<
typename MatrixDerived>
309 template<
typename Rhs,
typename Dest>
313 for(
Index j=0; j<
b.cols(); ++j)
329 template<
typename Rhs,
typename Dest>
333 if(
x.squaredNorm() == 0)
return;
343 #endif // EIGEN_GMRES_H