29template<
typename MatrixType,
32 typename FilterMatrixType,
37 const FilterMatrixType &filter,
40 typename Dest::RealScalar &tol_error)
44 typedef typename Dest::RealScalar RealScalar;
45 typedef typename Dest::Scalar
Scalar;
46 typedef Matrix<Scalar, Dynamic, 1> VectorType;
48 RealScalar tol = tol_error;
53 VectorType residual = filter * (
rhs - mat *
x);
55 RealScalar rhsNorm2 = (filter *
rhs).squaredNorm();
63 RealScalar threshold = tol * tol * rhsNorm2;
64 RealScalar residualNorm2 = residual.squaredNorm();
65 if (residualNorm2 < threshold) {
67 tol_error =
sqrt(residualNorm2 / rhsNorm2);
72 p = filter * precond.solve(residual);
74 VectorType
z(n), tmp(n);
75 RealScalar absNew = numext::real(
78 while (i < maxIters) {
79 tmp.noalias() = filter * (mat * p);
81 Scalar alpha = absNew / p.dot(tmp);
83 residual -= alpha * tmp;
85 residualNorm2 = residual.squaredNorm();
86 if (residualNorm2 < threshold) {
90 z = precond.solve(residual);
92 RealScalar absOld = absNew;
93 absNew = numext::real(residual.dot(
z));
96 RealScalar
beta = absNew / absOld;
98 p = filter * (
z +
beta * p);
101 tol_error =
sqrt(residualNorm2 / rhsNorm2);
108template<
typename MatrixType>
struct MatrixFilter {
109 MatrixFilter() : m_cmat(
NULL) {}
111 MatrixFilter(
const MatrixType &cmat) : m_cmat(&cmat) {}
113 void setMatrix(
const MatrixType &cmat)
118 template<
typename VectorType>
void apply(VectorType
v)
const
124 const MatrixType *m_cmat;
128template<
typename _MatrixType,
130 typename _FilterMatrixType = _MatrixType,
131 typename _Preconditioner = DiagonalPreconditioner<typename _MatrixType::Scalar>>
132class ConstrainedConjugateGradient;
136template<
typename _MatrixType,
int _UpLo,
typename _FilterMatrixType,
typename _Preconditioner>
195template<
typename _MatrixType,
int _UpLo,
typename _FilterMatrixType,
typename _Preconditioner>
197 :
public IterativeSolverBase<
198 ConstrainedConjugateGradient<_MatrixType, _UpLo, _FilterMatrixType, _Preconditioner>> {
199 typedef IterativeSolverBase<ConstrainedConjugateGradient> Base;
202 using Base::m_isInitialized;
203 using Base::m_iterations;
204 using Base::mp_matrix;
208 typedef typename MatrixType::Scalar
Scalar;
209 typedef typename MatrixType::Index
Index;
250 template<
typename Rhs,
typename Guess>
251 inline const internal::solve_retval_with_guess<ConstrainedConjugateGradient, Rhs, Guess>
254 eigen_assert(m_isInitialized &&
"ConjugateGradient is not initialized.");
256 Base::rows() ==
b.rows() &&
257 "ConjugateGradient::solve(): invalid number of rows of the right hand side matrix b");
258 return internal::solve_retval_with_guess<ConstrainedConjugateGradient, Rhs, Guess>(
259 *
this,
b.derived(), x0);
265 m_iterations = Base::maxIterations();
266 m_error = Base::m_tolerance;
268 for (
int j = 0; j <
b.cols(); j++) {
269 m_iterations = Base::maxIterations();
270 m_error = Base::m_tolerance;
272 typename Dest::ColXpr xj(x, j);
277 Base::m_preconditioner,
282 m_isInitialized =
true;
283 m_info = m_error <= Base::m_tolerance ? Success : NoConvergence;
287 template<
typename Rhs,
typename Dest>
void _solve(
const Rhs &
b, Dest &x)
const
299template<
typename _MatrixType,
int _UpLo,
typename _Filter,
typename _Preconditioner,
typename Rhs>
302 : solve_retval_base<ConstrainedConjugateGradient<_MatrixType, _UpLo, _Filter, _Preconditioner>,
305 EIGEN_MAKE_SOLVE_HELPERS(
Dec, Rhs)
307 template<typename Dest>
void evalTo(Dest &dst)
const
309 dec()._solve(
rhs(), dst);
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
A conjugate gradient solver for sparse self-adjoint problems with additional constraints.
ConstrainedConjugateGradient()
void _solve(const Rhs &b, Dest &x) const
FilterMatrixType & filter()
_FilterMatrixType FilterMatrixType
const internal::solve_retval_with_guess< ConstrainedConjugateGradient, Rhs, Guess > solveWithGuess(const MatrixBase< Rhs > &b, const Guess &x0) const
void _solveWithGuess(const Rhs &b, Dest &x) const
ConstrainedConjugateGradient(const MatrixType &A)
~ConstrainedConjugateGradient()
_Preconditioner Preconditioner
MatrixType::Scalar Scalar
MatrixType::RealScalar RealScalar
FilterMatrixType m_filter
const FilterMatrixType & filter() const
local_group_size(16, 16) .push_constant(Type b
local_group_size(16, 16) .push_constant(Type rhs
EIGEN_DONT_INLINE void constrained_conjugate_gradient(const MatrixType &mat, const Rhs &rhs, Dest &x, const FilterMatrixType &filter, const Preconditioner &precond, int &iters, typename Dest::RealScalar &tol_error)
ConstrainedConjugateGradient< _MatrixType, _UpLo, _Filter, _Preconditioner > Dec
_Preconditioner Preconditioner
_FilterMatrixType FilterMatrixType
ccl_device_inline float beta(float x, float y)