1 #ifndef __GfxTL_JACOBI_HEADER__
2 #define __GfxTL_JACOBI_HEADER__
15 #define __GfxTL_JACOBI_ROTATE(a, i, j, k, l) \
18 (a)[j][i] = g - s * (h + g * tau); \
19 (a)[l][k] = h + s *(g - h * tau);
21 template<
unsigned int N,
class T >
28 T tresh, theta, tau, t, sm,
s, h, g,
c;
29 T volatile temp1, temp2;
31 for (ip = 0; ip < N; ip++)
33 for (iq = 0; iq < N; iq++)
39 for (ip = 0; ip < N; ip++)
41 b[ip] = (*d)[ip] =
a[ip][ip];
48 for (i = 1; i <= 200; i++)
51 for (ip = 0; ip < N - 1; ip++)
53 for (iq = ip + 1; iq < N; iq++)
64 tresh =
T(0.2) * sm / (N * N);
70 for (ip = 0; ip < N - 1; ip++)
72 for (iq = ip + 1; iq < N; iq++)
74 g =
T(100) *
abs(
a[iq][ip]);
75 temp1 =
abs((*d)[ip]) + g;
76 temp2 =
abs((*d)[iq]) + g;
78 temp1 ==
abs((*d)[ip]) &&
79 temp2 ==
abs((*d)[iq]))
83 else if (
abs(
a[iq][ip]) > tresh)
85 h = (*d)[iq] - (*d)[ip];
93 theta =
T(0.5) * h /
a[iq][ip];
94 t =
T(1) / (
abs(theta) +
95 sqrt(
T(1) + theta * theta));
103 tau =
s / (
T(1) +
c);
110 for (j = 0; j <= ip - 1; j++)
114 for (j = ip + 1; j <= iq - 1; j++)
118 for (j = iq + 1; j < N; j++)
122 for (j = 0; j < N; j++)
133 for (ip = 0; ip < N; ip++)
143 template<
unsigned int N,
class T >
148 for (i = 0; i < N; ++i)
151 for (j = i + 1 ; j < N; ++j)
160 for (j = 0; j < N; ++j)
163 (*v)[i][j] = (*v)[k][j];
174 template<
class IteratorT,
class VectorT >
180 intptr_t N = (*a).Extent(0);
181 intptr_t j, iq, ip, i;
182 T tresh, theta, tau, t, sm,
s, h, g,
c;
183 T volatile temp1, temp2;
184 auto_ptr< T > ab(
new T[N]), az(
new T[N]);
185 T* b = ab.get(), *z = az.get();
186 for (ip = 0; ip < N; ip++)
188 for (iq = 0; iq < N; iq++)
194 for (ip = 0; ip < N; ip++)
196 b[ip] = (*d)[ip] = (*a)[ip][ip];
203 for (i = 1; i <= 200; i++)
206 for (ip = 0; ip < N - 1; ip++)
208 for (iq = ip + 1; iq < N; iq++)
210 sm +=
abs((*
a)[iq][ip]);
219 tresh =
T(0.2) * sm / (N * N);
225 for (ip = 0; ip < N - 1; ip++)
227 for (iq = ip + 1; iq < N; iq++)
229 g =
T(100) *
abs((*
a)[iq][ip]);
230 temp1 =
abs((*d)[ip]) + g;
231 temp2 =
abs((*d)[iq]) + g;
233 temp1 ==
abs((*d)[ip]) &&
234 temp2 ==
abs((*d)[iq]))
238 else if (
abs((*
a)[iq][ip]) > tresh)
240 h = (*d)[iq] - (*d)[ip];
241 temp1 = (
abs(h) + g);
244 t = (*a)[iq][ip] / h;
248 theta =
T(0.5) * h / (*a)[iq][ip];
249 t =
T(1) / (
abs(theta) +
250 sqrt(
T(1) + theta * theta));
258 tau =
s / (
T(1) +
c);
259 h = t * (*a)[iq][ip];
265 for (j = 0; j <= ip - 1; j++)
269 for (j = ip + 1; j <= iq - 1; j++)
273 for (j = iq + 1; j < N; j++)
277 for (j = 0; j < N; j++)
288 for (ip = 0; ip < N; ip++)
298 template<
class IteratorT,
class VectorT >
302 size_t N =
v->Extent(0);
305 for (i = 0; i < N; ++i)
308 for (j = i + 1 ; j < N; ++j)
317 for (j = 0; j < N; ++j)
320 (*v)[i][j] = (*v)[k][j];
327 #undef __GfxTL_JACOBI_ROTATE