Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / fft / hc_pass_3.c
1 /* fft/hc_pass_3.c
2  * 
3  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or (at
8  * your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 static void
21 FUNCTION(fft_halfcomplex,pass_3) (const BASE in[],
22                                   const size_t istride,
23                                   BASE out[],
24                                   const size_t ostride,
25                                   const size_t product,
26                                   const size_t n,
27                                   const TYPE(gsl_complex) twiddle1[],
28                                   const TYPE(gsl_complex) twiddle2[])
29 {
30   size_t i, j, k, k1, jump;
31   size_t factor, q, m, product_1;
32
33   ATOMIC tau = sqrt (3.0) / 2.0;
34
35   i = 0;
36   j = 0;
37
38   factor = 3;
39   m = n / factor;
40   q = n / product;
41   product_1 = product / factor;
42   jump = (factor - 1) * q;
43
44   for (k1 = 0; k1 < product_1; k1++)
45     {
46       const size_t from0 = 3 * k1 * q;
47       const size_t from1 = from0 + 2 * q - 1;
48
49       const ATOMIC z0_real = VECTOR(in,istride,from0);
50       const ATOMIC z1_real = VECTOR(in,istride,from1);
51       const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
52
53       const ATOMIC t1_real = 2 * z1_real;
54       const ATOMIC t2_real = z0_real - z1_real;
55       const ATOMIC t3_imag = 2 * tau * z1_imag;
56
57       const size_t to0 = q * k1;
58       const size_t to1 = to0 + m;
59       const size_t to2 = to1 + m;
60
61       VECTOR(out,ostride,to0) = z0_real + t1_real;
62       VECTOR(out,ostride,to1) = t2_real - t3_imag;
63       VECTOR(out,ostride,to2) = t2_real + t3_imag;
64
65     }
66
67   if (q == 1)
68     return;
69
70   for (k = 1; k < (q + 1) / 2; k++)
71     {
72       const ATOMIC w1_real = GSL_REAL(twiddle1[k - 1]);
73       const ATOMIC w1_imag = GSL_IMAG(twiddle1[k - 1]);
74       const ATOMIC w2_real = GSL_REAL(twiddle2[k - 1]);
75       const ATOMIC w2_imag = GSL_IMAG(twiddle2[k - 1]);
76
77       for (k1 = 0; k1 < product_1; k1++)
78         {
79           const size_t from0 = 3 * k1 * q + 2 * k - 1;
80           const size_t from1 = from0 + 2 * q;
81           const size_t from2 = 3 * k1 * q - 2 * k + 2 * q - 1;
82
83           const ATOMIC z0_real = VECTOR(in,istride,from0);
84           const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
85
86           const ATOMIC z1_real = VECTOR(in,istride,from1);
87           const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
88
89           const ATOMIC z2_real = VECTOR(in,istride,from2);
90           const ATOMIC z2_imag = -VECTOR(in,istride,from2 + 1);
91
92           /* compute x = W(3) z */
93
94           /* t1 = z1 + z2 */
95           const ATOMIC t1_real = z1_real + z2_real;
96           const ATOMIC t1_imag = z1_imag + z2_imag;
97
98           /* t2 = z0 - t1/2 */
99           const ATOMIC t2_real = z0_real - t1_real / 2.0;
100           const ATOMIC t2_imag = z0_imag - t1_imag / 2.0;
101
102           /* t3 = sin(pi/3)*(z1 - z2) */
103           const ATOMIC t3_real = tau * (z1_real - z2_real);
104           const ATOMIC t3_imag = tau * (z1_imag - z2_imag);
105
106           /* x0 = z0 + t1 */
107           const ATOMIC x0_real = z0_real + t1_real;
108           const ATOMIC x0_imag = z0_imag + t1_imag;
109
110           /* x1 = t2 + i t3 */
111           const ATOMIC x1_real = t2_real - t3_imag;
112           const ATOMIC x1_imag = t2_imag + t3_real;
113
114           /* x2 = t2 - i t3 */
115           const ATOMIC x2_real = t2_real + t3_imag;
116           const ATOMIC x2_imag = t2_imag - t3_real;
117
118           const size_t to0 = k1 * q + 2 * k - 1;
119           const size_t to1 = to0 + m;
120           const size_t to2 = to1 + m;
121
122           VECTOR(out,ostride,to0) = x0_real;
123           VECTOR(out,ostride,to0 + 1) = x0_imag;
124
125           VECTOR(out,ostride,to1) = w1_real * x1_real - w1_imag * x1_imag;
126           VECTOR(out,ostride,to1 + 1) = w1_imag * x1_real + w1_real * x1_imag;
127
128           VECTOR(out,ostride,to2) = w2_real * x2_real - w2_imag * x2_imag;
129           VECTOR(out,ostride,to2 + 1) = w2_imag * x2_real + w2_real * x2_imag;
130
131         }
132     }
133
134   if (q % 2 == 1)
135     return;
136
137   for (k1 = 0; k1 < product_1; k1++)
138     {
139       const size_t from0 = 3 * k1 * q + q - 1;
140       const size_t from1 = from0 + 2 * q;
141
142       const ATOMIC z0_real = VECTOR(in,istride,from0);
143       const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
144       const ATOMIC z1_real = VECTOR(in,istride,from1);
145
146       const ATOMIC t1_real = z0_real - z1_real;
147       const ATOMIC t2_real = 2 * tau * z0_imag;
148
149       const ATOMIC x0_real = 2 * z0_real + z1_real;
150       const ATOMIC x1_real = t1_real - t2_real;
151       const ATOMIC x2_real = -t1_real - t2_real;
152
153       const size_t to0 = k1 * q + q - 1;
154       const size_t to1 = to0 + m;
155       const size_t to2 = to1 + m;
156
157       VECTOR(out,ostride,to0) = x0_real;
158       VECTOR(out,ostride,to1) = x1_real;
159       VECTOR(out,ostride,to2) = x2_real;
160     }
161   return;
162 }