28 #include "sirf/common/Operator.h" 36 template<
class value_type>
41 void set_num_iterations(
int nit)
47 template<
class vector_type>
49 vector_type& x ,
int verb=0)
52 value_type a[] = { 0, 0, 0, 0 };
59 std::unique_ptr<vector_type> uptr_y = x.clone();
60 vector_type& y = *uptr_y;
61 std::unique_ptr<vector_type> uptr_z = x.clone();
62 vector_type& z = *uptr_z;
63 std::unique_ptr<vector_type> uptr_w = x.clone();
64 vector_type& w = *uptr_w;
65 std::unique_ptr<vector_type> uptr_Az = x.clone();
66 vector_type& Az = *uptr_Az;
68 float s = sqrt(abs(x.dot(x)));
70 std::shared_ptr<vector_type> sptr_Ax = A(x);
71 vector_type& Ax = *sptr_Ax;
73 for (
int it = 0; it < nit_; it++) {
75 y.axpby(1.0, Ax, -lmd, x);
77 std::cout <<
"CG iteration " << it
78 <<
": largest eigenvalue " << std::real(lmd) <<
'\n';
81 w.axpby(1.0, Az, -t, z);
82 t = w.dot(y) / (lmd - t);
83 y.axpby(1.0, y, t, z);
86 s = sqrt(abs(y.dot(y)));
92 y.axpby(1.0, y, -t, x);
94 s = sqrt(abs(y.dot(y)));
99 std::shared_ptr<vector_type> sptr_Ay = A(y);
100 vector_type& Ay = *sptr_Ay;
107 z.axpby(u[0], x, u[1], y);
108 x.axpby(v[0], x, v[1], y);
112 Az.axpby(u[0], Ax, u[1], Ay);
113 Ax.axpby(v[0], Ax, v[1], Ay);
115 s = sqrt(abs(x.dot(x)));
119 return std::real(lmd);
126 void eigh2_(
const value_type a[4], value_type lmd[2], value_type x[2],
127 value_type y[2])
const 131 value_type c = abs(a[1]);
132 value_type d = abs(a[0] - a[3]);
133 d = d * d + (c + c) * (c + c);
134 value_type s = sqrt(d);
135 value_type t = a[0] + a[3];
136 if (s == zero && t == zero) {
145 lmd[0] = (t - s) / (one + one);
146 lmd[1] = (t + s) / (one + one);
148 value_type q = lmd[0] - a[0];
149 value_type pc = (p == zero ? 0 : abs(p*p) / p);
150 value_type qc = (q == zero ? 0 : abs(q*q) / q);
153 s = sqrt(abs(pc*x[0] + qc*x[1]));
Definition: JacobiCG.h:37
Abstract data container.
Definition: GeometricalInfo.cpp:141