21 #define REPORT { static ExeCounter ExeCount(__LINE__,19); ++ExeCount; } 26 static void cossin(
int n,
int d,
Real& c,
Real& s)
31 long n4 =
n * 4;
int sector = (int)std::floor( (
Real)n4 / (
Real)d + 0.5 );
33 if (sector < 0) {
REPORT sector = 3 - (3 - sector) % 4; }
34 else {
REPORT sector %= 4; }
39 case 0:
REPORT c = cos(ratio); s = sin(ratio);
break;
40 case 1:
REPORT c = -sin(ratio); s = cos(ratio);
break;
41 case 2:
REPORT c = -cos(ratio); s = -sin(ratio);
break;
42 case 3:
REPORT c = sin(ratio); s = -cos(ratio);
break;
52 const int gamma = after * before;
const int delta = now * after;
57 const int m =
A.Nrows() - gamma;
59 for (
int j = 0; j < now; j++)
63 for (
int ia = 0; ia < after; ia++)
67 cossin(-(j*after+ia), delta, r_arg, i_arg);
76 Real* a2 = m + a1;
Real* b2 = m + b1; a1 += after; b1 += after;
77 Real r_value = *a2;
Real i_value = *b2;
78 *x2 = r_value * r_arg - i_value * i_arg + *(a2-gamma);
79 *y2 = r_value * i_arg + i_value * r_arg + *(b2-gamma);
81 x2 += delta; y2 += delta;
90 Real* a2 = m + a1;
Real* b2 = m + b1; a1 += after; b1 += after;
91 Real r_value = *a2;
Real i_value = *b2;
92 int in = now-1;
while (in--)
97 a2 -= gamma; b2 -= gamma;
Real temp = r_value;
98 r_value = r_value * r_arg - i_value * i_arg + *a2;
99 i_value = temp * i_arg + i_value * r_arg + *b2;
101 *x2 = r_value; *y2 = i_value;
103 x2 += delta; y2 += delta;
132 const int n2 =
n / 2;
137 while (i--) { *a++ = *u++; *b++ = *u++; }
142 a =
A.Store(); b = B.
Store();
147 *
x++ = *a + *b; *
y++ = 0.0;
148 *xn-- = *a++ - *b++; *yn-- = 0.0;
150 int j = -1; i = n2/2;
153 Real c,s; cossin(j--,
n,c,s);
154 Real am = *a - *an;
Real ap = *a++ + *an--;
155 Real bm = *b - *bn;
Real bp = *b++ + *bn--;
156 Real samcbp = s * am + c * bp;
Real sbpcam = s * bp - c * am;
157 *
x++ = 0.5 * ( ap + samcbp); *
y++ = 0.5 * ( bm + sbpcam);
158 *xn-- = 0.5 * ( ap - samcbp); *yn-- = 0.5 * (-bm + sbpcam);
167 const int n21 =
A.Nrows();
168 if (n21 != B.
Nrows() || n21 == 0)
170 const int n2 = n21 - 1;
const int n = 2 * n2;
int i = n2 - 1;
174 Real* an = a + n2;
Real* bn = b + n2;
179 *
x++ = hn * (*a + *an); *
y++ = - hn * (*a - *an);
180 a++; an--; b++; bn--;
181 int j = -1; i = n2/2;
184 Real c,s; cossin(j--,
n,c,s);
185 Real am = *a - *an;
Real ap = *a++ + *an--;
186 Real bm = *b - *bn;
Real bp = *b++ + *bn--;
187 Real samcbp = s * am - c * bp;
Real sbpcam = s * bp + c * am;
188 *
x++ = hn * ( ap + samcbp); *
y++ = - hn * ( bm + sbpcam);
189 *xn-- = hn * ( ap - samcbp); *yn-- = - hn * (-bm + sbpcam);
194 while (i--) { *u++ = *
x++; *u++ = - *
y++; }
207 if (
n == 1) {
REPORT X = U; Y = V;
return; }
220 const int nextmx = 8;
221 int prime[8] = { 2,3,5,7,11,13,17,19 };
222 int after = 1;
int before =
n;
int next = 0;
bool inzee =
true;
229 if (next < nextmx) {
REPORT now = prime[next]; }
230 b1 = before / now;
if (b1 * now == before) {
REPORT break; }
235 if (inzee) {
REPORT fftstep(
A, B, X, Y, after, now, before); }
236 else {
REPORT fftstep(X, Y,
A, B, after, now, before); }
238 inzee = !inzee; after *= now;
255 const int n2 =
n / 2;
const int n4 =
n * 4;
261 while (i--) { *a++ = *u++; *(--b) = *u++; }
271 Real c, s; cossin(++k, n4, c, s);
273 *(++v) = xi * c + yi * s; *(--w) = xi * s - yi * c;
280 Tracer trace(
"DCT_II_inverse");
283 const int n2 =
n / 2;
const int n4 =
n * 4;
const int n21 = n2 + 1;
290 int i = n2;
int k = 0;
293 Real c, s; cossin(++k, n4, c, s);
295 *(++
x) = vi * c + wi * s; *(++
y) = vi * s - wi * c;
301 while (i--) { *u++ = *a++; *u++ = *(--b); }
310 const int n2 =
n / 2;
const int n4 =
n * 4;
316 while (i--) { *a++ = *u++; *(--b) = -(*u++); }
326 Real c, s; cossin(++k, n4, c, s);
328 *v++ = xi * s - yi * c; *(--w) = xi * c + yi * s;
335 Tracer trace(
"DST_II_inverse");
338 const int n2 =
n / 2;
const int n4 =
n * 4;
const int n21 = n2 + 1;
344 *
x = *(--w); *
y = 0.0;
345 int i = n2;
int k = 0;
348 Real c, s; cossin(++k, n4, c, s);
350 *(++
x) = vi * s + wi * c; *(++
y) = - vi * c + wi * s;
356 while (i--) { *u++ = *a++; *u++ = -(*(--b)); }
362 Tracer trace(
"DCT_inverse");
364 const int n = V.
Nrows()-1;
365 const int n2 =
n / 2;
const int n21 = n2 + 1;
370 Real vi = *v++; *
x++ = vi; *
y++ = 0.0;
371 Real sum1 = vi / 2.0;
Real sum2 = sum1; vi = *v++;
375 Real vi2 = *v++; sum1 += vi2 + vi; sum2 += vi2 - vi;
376 *
x++ = vi2; vi2 = *v++; *
y++ = vi - vi2; vi = vi2;
378 sum1 += vi; sum2 -= vi;
379 vi = *v; *
x = vi; *
y = 0.0; vi /= 2.0; sum1 += vi; sum2 += vi;
383 i = n2;
int k = 0; *u++ = sum1 / n2; *v-- = sum2 / n2;
386 Real s = sin(1.5707963267948966192 * (++k) / n2);
388 Real bz = (ai - bi) / 4 / s;
Real az = (ai + bi) / 2;
389 *u++ = az - bz; *v-- = az + bz;
399 V *= (V.
Nrows()-1)/2;
405 Tracer trace(
"DST_inverse");
407 const int n = V.
Nrows()-1;
408 const int n2 =
n / 2;
const int n21 = n2 + 1;
413 Real vi = *(++v); *
x++ = 2 * vi; *
y++ = 0.0;
415 while (i--) { *
y++ = *(++v);
Real vi2 = *(++v); *
x++ = vi2 - vi; vi = vi2; }
416 *
x = -2 * vi; *
y = 0.0;
420 i = n2;
int k = 0; *u++ = 0.0; *v-- = 0.0;
423 Real s = sin(1.5707963267948966192 * (++k) / n2);
425 Real az = (ai + bi) / 4 / s;
Real bz = (ai - bi) / 2;
426 *u++ = az - bz; *v-- = az + bz;
436 V *= (V.
Nrows()-1)/2;
445 if (m != V.
Nrows() ||
n != V.
Ncols() || m == 0 ||
n == 0)
449 for (i = 1; i <= m; ++i)
452 X.
Row(i) = CVR.
t(); Y.
Row(i) = CVI.
t();
454 for (i = 1; i <=
n; ++i)
GetSubMatrix Column(int) const
void DST_inverse(const ColumnVector &V, ColumnVector &U)
void DST_II(const ColumnVector &U, ColumnVector &V)
void RealFFT(const ColumnVector &U, ColumnVector &X, ColumnVector &Y)
void DCT_II(const ColumnVector &U, ColumnVector &V)
void FFT(const ColumnVector &U, const ColumnVector &V, ColumnVector &X, ColumnVector &Y)
void FFT2(const Matrix &U, const Matrix &V, Matrix &X, Matrix &Y)
void DCT_II_inverse(const ColumnVector &V, ColumnVector &U)
void FFT2I(const Matrix &U, const Matrix &V, Matrix &X, Matrix &Y)
os2<< "> n<< " > nendobj n
void FFTI(const ColumnVector &U, const ColumnVector &V, ColumnVector &X, ColumnVector &Y)
void DST(const ColumnVector &U, ColumnVector &V)
GetSubMatrix Row(int) const
static bool ar_1d_ft(int PTS, Real *X, Real *Y)
void RealFFTI(const ColumnVector &A, const ColumnVector &B, ColumnVector &U)
void DCT(const ColumnVector &U, ColumnVector &V)
void DCT_inverse(const ColumnVector &V, ColumnVector &U)
static bool CanFactor(int PTS)
TransposedMatrix t() const
void DST_II_inverse(const ColumnVector &V, ColumnVector &U)