37 #ifndef GMM_LEAST_SQUARES_CG_H__
38 #define GMM_LEAST_SQUARES_CG_H__
46 template <
typename Matrix,
typename Vector1,
typename Vector2>
47 void least_squares_cg(
const Matrix& C, Vector1& x,
const Vector2& y,
50 typedef typename temporary_dense_vector<Vector1>::vector_type temp_vector;
51 typedef typename linalg_traits<Vector1>::value_type T;
54 temp_vector p(vect_size(x)), q(vect_size(y)), g(vect_size(x));
55 temp_vector r(vect_size(y));
56 iter.set_rhsnorm(gmm::sqrt(gmm::abs(
vect_hp(y, y))));
58 if (iter.get_rhsnorm() == 0.0)
61 mult(C, scaled(x, T(-1)), y, r);
66 while (!iter.finished_vect(g)) {
70 add(g, scaled(p, rho / rho_1), p);
77 add(scaled(q, -a), r);
87 template <
typename Matrix,
typename Precond,
88 typename Vector1,
typename Vector2>
inline
89 void least_squares_cg(
const Matrix& C,
const Vector1& x,
const Vector2& y,
91 { least_squares_cg(C, linalg_const_cast(x), y, iter); }
void copy(const L1 &l1, L2 &l2)
*/
strongest_value_type< V1, V2 >::value_type vect_hp(const V1 &v1, const V2 &v2)
*/
void clear(L &l)
clear (fill with zeros) a vector or matrix.
void mult(const L1 &l1, const L2 &l2, L3 &l3)
*/
void add(const L1 &l1, L2 &l2)
*/
handle conjugation of complex matrices/vectors.
conjugated_return< L >::return_type conjugated(const L &v)
return a conjugated view of the input matrix or vector.
Include the base gmm files.