38 #ifndef GMM_LEAST_SQUARES_CG_H__
39 #define GMM_LEAST_SQUARES_CG_H__
47 template <
typename Matrix,
typename Vector1,
typename Vector2>
48 void least_squares_cg(
const Matrix& C, Vector1& x,
const Vector2& y,
51 typedef typename temporary_dense_vector<Vector1>::vector_type temp_vector;
52 typedef typename linalg_traits<Vector1>::value_type T;
55 temp_vector p(vect_size(x)), q(vect_size(y)), g(vect_size(x));
56 temp_vector r(vect_size(y));
57 iter.set_rhsnorm(gmm::sqrt(gmm::abs(
vect_hp(y, y))));
59 if (iter.get_rhsnorm() == 0.0)
62 mult(C, scaled(x, T(-1)), y, r);
67 while (!iter.finished_vect(g)) {
71 add(g, scaled(p, rho / rho_1), p);
78 add(scaled(q, -a), r);
88 template <
typename Matrix,
typename Precond,
89 typename Vector1,
typename Vector2>
inline
90 void least_squares_cg(
const Matrix& C,
const Vector1& x,
const Vector2& y,
92 { least_squares_cg(C, linalg_const_cast(x), y, iter); }
96 #endif // GMM_SOLVER_CG_H__