35 template<
typename Vector,
typename RealScalar>
42 const Scalar ts = t.dot(s);
53 return angle * (ns / nt) * (ts /
abs(ts));
55 return ts / (nt * nt);
58 template <
typename MatrixType,
typename Rhs,
typename Dest,
typename Preconditioner>
68 S = S < x.rows() ?
S : x.rows();
69 const RealScalar
tol = relres;
72 Index replacements = 0;
80 P = (qr.
householderQ() * DenseMatrixType::Identity(N, S));
83 const RealScalar normb = b.norm();
109 const RealScalar tolb = tol * normb;
110 VectorType r = b - A *
x;
120 RealScalar normr = r.norm();
126 relres = normr / normb;
130 DenseMatrixType
G = DenseMatrixType::Zero(N, S);
131 DenseMatrixType
U = DenseMatrixType::Zero(N, S);
132 DenseMatrixType
M = DenseMatrixType::Identity(S, S);
133 VectorType
t(N),
v(N);
139 while (normr > tolb && iter < maxit)
142 VectorType
f = (r.adjoint() *
P).
adjoint();
144 for (
Index k = 0; k <
S; ++k)
148 lu_solver.
compute(M.block(k , k , S -k, S - k ));
149 VectorType
c = lu_solver.
solve(f.segment(k , S - k ));
151 v = r - G.rightCols(S - k ) *
c;
153 v = precond.solve(v);
156 U.col(k) = U.rightCols(S - k ) * c + om *
v;
157 G.col(k) = A * U.col(k );
163 Scalar
alpha = P.col(
i ).dot(G.col(k )) /
M(
i,
i );
164 G.col(k ) = G.col(k ) - alpha * G.col(
i );
165 U.col(k ) = U.col(k ) - alpha * U.col(
i );
170 M.block(k , k , S - k , 1) = (G.col(k ).adjoint() * P.rightCols(S - k )).
adjoint();
178 Scalar beta =
f(k ) /
M(k , k );
179 r = r - beta * G.col(k );
180 x = x + beta * U.col(k );
183 if (replacement && normr > tolb / mp)
193 Scalar gamma =
t.dot(r_s) /
t.norm();
194 r_s = r_s - gamma *
t;
195 x_s = x_s - gamma * (x_s -
x);
199 if (normr < tolb || iter == maxit)
207 f.segment(k + 1, S - (k + 1) ) = f.segment(k + 1 , S - (k + 1)) - beta * M.block(k + 1 , k , S - (k + 1), 1);
211 if (normr < tolb || iter == maxit)
220 v = precond.solve(v);
237 if (replacement && normr > tolb / mp)
243 if (trueres && normr < normb)
254 Scalar gamma = t.dot(r_s) /t.norm();
255 r_s = r_s - gamma *
t;
256 x_s = x_s - gamma * (x_s -
x);
274 template <
typename _MatrixType,
typename _Preconditioner = DiagonalPreconditioner<
typename _MatrixType::Scalar> >
280 template <
typename _MatrixType,
typename _Preconditioner>
330 template <
typename _MatrixType,
typename _Preconditioner>
344 using Base::m_isInitialized;
345 using Base::m_iterations;
354 IDRS(): m_S(4), m_smoothing(false), m_angle(RealScalar(0.7)), m_residual(false) {}
366 template <
typename MatrixDerived>
368 m_angle(RealScalar(0.7)), m_residual(false) {}
376 template <
typename Rhs,
typename Dest>
379 m_iterations = Base::maxIterations();
380 m_error = Base::m_tolerance;
382 bool ret =
internal::idrs(
matrix(), b, x, Base::m_preconditioner, m_iterations, m_error, m_S,m_smoothing,m_angle,m_residual);
406 m_smoothing=smoothing;
const Solve< FullPivLU< _MatrixType >, Rhs > solve(const MatrixBase< Rhs > &b) const
MatrixType::RealScalar RealScalar
Matrix< RealScalar, Dynamic, Dynamic > M
void setSmoothing(bool smoothing)
void adjoint(const MatrixType &m)
JacobiRotation< float > G
FullPivLU & compute(const EigenBase< InputType > &matrix)
Namespace containing all symbols from the Eigen library.
iterator iter(handle obj)
The Induced Dimension Reduction method (IDR(s)) is a short-recurrences Krylov method for sparse squar...
_Preconditioner Preconditioner
HouseholderQR< MatrixXf > qr(A)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE internal::enable_if< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real >::type abs(const T &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Array< int, Dynamic, 1 > v
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Vector::Scalar omega(const Vector &t, const Vector &s, RealScalar angle)
IterativeSolverBase< IDRS > Base
HouseholderSequenceType householderQ() const
NumTraits< Scalar >::Real RealScalar
void _solve_vector_with_guess_impl(const Rhs &b, Dest &x) const
MatrixType::Scalar Scalar
LU decomposition of a matrix with complete pivoting, and related features.
void setResidualUpdate(bool update)
Householder QR decomposition of a matrix.
IDRS(const EigenBase< MatrixDerived > &A)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Base class for linear iterative solvers.
void setAngle(RealScalar angle)
_Preconditioner Preconditioner
bool idrs(const MatrixType &A, const Rhs &b, Dest &x, const Preconditioner &precond, Index &iter, typename Dest::RealScalar &relres, Index S, bool smoothing, typename Dest::RealScalar angle, bool replacement)