-
Notifications
You must be signed in to change notification settings - Fork 139
/
acb_dft.h
331 lines (268 loc) · 8.42 KB
/
acb_dft.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
Copyright (C) 2016 Pascal Molin
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#ifndef ACB_DFT_H
#define ACB_DFT_H
#ifdef ACB_DFT_INLINES_C
#define ACB_DFT_INLINE
#else
#define ACB_DFT_INLINE static __inline__
#endif
#include "acb.h"
#include "dlog.h"
#ifdef __cplusplus
extern "C" {
#endif
void _acb_dft_naive(acb_ptr w, acb_srcptr v, slong dv, acb_srcptr z, slong dz, slong len, slong prec);
void acb_dft_naive(acb_ptr w, acb_srcptr v, slong len, slong prec);
void acb_dft_crt(acb_ptr w, acb_srcptr v, slong len, slong prec);
void acb_dft_cyc(acb_ptr w, acb_srcptr v, slong len, slong prec);
void acb_dft_rad2_inplace(acb_ptr v, int e, slong prec);
void acb_dft_rad2(acb_ptr w, acb_srcptr v, int e, slong prec);
void acb_dft_bluestein(acb_ptr w, acb_srcptr v, slong len, slong prec);
void acb_dft_prod(acb_ptr w, acb_srcptr v, slong * cyc, slong num, slong prec);
void acb_dft_rad2_inplace_threaded(acb_ptr v, int e, slong prec);
void acb_dft_convol_naive(acb_ptr w, acb_srcptr f, acb_srcptr g, slong len, slong prec);
void acb_dft_convol_dft(acb_ptr w, acb_srcptr f, acb_srcptr g, slong len, slong prec);
void acb_dft_convol_rad2(acb_ptr w, acb_srcptr f, acb_srcptr g, slong len, slong prec);
void acb_dft_convol_mullow(acb_ptr w, acb_srcptr f, acb_srcptr g, slong len, slong prec);
void acb_dft_convol(acb_ptr w, acb_srcptr f, acb_srcptr g, slong len, slong prec);
#define CRT_MAX 15
typedef struct
{
int num;
nmod_t n;
slong m[CRT_MAX];
ulong M[CRT_MAX];
ulong vM[CRT_MAX];
}
crt_struct;
typedef crt_struct crt_t[1];
void crt_init(crt_t c, ulong n);
void crt_decomp(acb_ptr y, acb_srcptr x, slong dx, const crt_t c, ulong len);
void crt_recomp(acb_ptr y, acb_srcptr x, const crt_t c, ulong len);
typedef struct acb_dft_step_struct acb_dft_step_struct;
typedef acb_dft_step_struct * acb_dft_step_ptr;
typedef struct
{
slong n;
acb_ptr z;
int zclear;
slong num;
acb_dft_step_ptr cyc;
}
acb_dft_cyc_struct;
typedef acb_dft_cyc_struct acb_dft_cyc_t[1];
typedef struct
{
int e;
slong n; /* = 1 << e */
slong dv;
slong nz; /* = n but could be bigger */
acb_ptr z;
}
acb_dft_rad2_struct;
typedef acb_dft_rad2_struct acb_dft_rad2_t[1];
typedef struct
{
slong n;
slong dv;
acb_ptr z; /* z[k] = e(k^2/2n) */
acb_ptr g; /* g[k] = dft( z ) */
acb_dft_rad2_t rad2;
}
acb_dft_bluestein_struct;
typedef acb_dft_bluestein_struct acb_dft_bluestein_t[1];
typedef struct
{
slong n;
slong num;
acb_dft_step_ptr cyc;
}
acb_dft_prod_struct;
typedef acb_dft_prod_struct acb_dft_prod_t[1];
typedef struct
{
slong n;
crt_t c;
slong dv;
/* then a product */
acb_dft_step_ptr cyc;
}
acb_dft_crt_struct;
typedef acb_dft_crt_struct acb_dft_crt_t[1];
typedef struct
{
slong n;
slong dv;
int zclear;
acb_ptr z;
slong dz;
}
acb_dft_naive_struct;
typedef acb_dft_naive_struct acb_dft_naive_t[1];
typedef struct
{
slong n;
int type;
union
{
acb_dft_rad2_t rad2;
acb_dft_cyc_t cyc;
acb_dft_prod_t prod;
acb_dft_crt_t crt;
acb_dft_naive_t naive;
acb_dft_bluestein_t bluestein;
} t;
}
acb_dft_pre_struct;
typedef acb_dft_pre_struct acb_dft_pre_t[1];
/* covers both product and cyclic case */
struct
acb_dft_step_struct
{
/* [G:H] */
slong m;
/* card H */
slong M;
slong dv; /* = M for prod, also = M if cyc is reordered */
/* pointer on some roots of unity, if needed */
acb_srcptr z;
/* index of mM in z */
slong dz;
/* dft to call on H */
acb_dft_pre_t pre;
/* dft to call on G/H ? */
};
/*typedef acb_dft_pre_struct acb_dft_pre_t[1];*/
#define DFT_VERB 0
enum
{
DFT_NAIVE, DFT_CYC, DFT_PROD, DFT_CRT , DFT_RAD2 , DFT_CONV
};
void acb_dft_step(acb_ptr w, acb_srcptr v, acb_dft_step_ptr cyc, slong num, slong prec);
void acb_dft_precomp(acb_ptr w, acb_srcptr v, const acb_dft_pre_t pre, slong prec);
void acb_dft_inverse_precomp(acb_ptr w, acb_srcptr v, const acb_dft_pre_t pre, slong prec);
void acb_dft_naive_precomp(acb_ptr w, acb_srcptr v, const acb_dft_naive_t pol, slong prec);
void acb_dft_cyc_precomp(acb_ptr w, acb_srcptr v, const acb_dft_cyc_t cyc, slong prec);
void acb_dft_rad2_precomp_inplace(acb_ptr v, const acb_dft_rad2_t rad2, slong prec);
void acb_dft_rad2_precomp(acb_ptr w, acb_srcptr v, const acb_dft_rad2_t rad2, slong prec);
void acb_dft_crt_precomp(acb_ptr w, acb_srcptr v, const acb_dft_crt_t crt, slong prec);
void acb_dft_prod_precomp(acb_ptr w, acb_srcptr v, const acb_dft_prod_t prod, slong prec);
void acb_dft_bluestein_precomp(acb_ptr w, acb_srcptr v, const acb_dft_bluestein_t t, slong prec);
void acb_dft_rad2_precomp_inplace_threaded(acb_ptr v, const acb_dft_rad2_t rad2, slong prec);
void acb_dft_inverse_rad2_precomp_inplace(acb_ptr v, const acb_dft_rad2_t rad2, slong prec);
void acb_dft_inverse_rad2_precomp(acb_ptr w, acb_srcptr v, const acb_dft_rad2_t rad2, slong prec);
void acb_dft_convol_rad2_precomp(acb_ptr w, acb_srcptr f, acb_srcptr g, slong len, const acb_dft_rad2_t, slong prec);
void _acb_dft_precomp_init(acb_dft_pre_t pre, slong dv, acb_ptr z, slong dz, slong len, slong prec);
void acb_dft_precomp_init(acb_dft_pre_t pre, slong len, slong prec);
void acb_dft_precomp_clear(acb_dft_pre_t pre);
void acb_dft(acb_ptr w, acb_srcptr v, slong len, slong prec);
void acb_dft_inverse(acb_ptr w, acb_srcptr v, slong len, slong prec);
acb_dft_step_ptr _acb_dft_steps_prod(slong * m, slong num, slong prec);
ACB_DFT_INLINE void
acb_dft_prod_init(acb_dft_prod_t t, slong * cyc, slong num, slong prec)
{
t->num = num;
t->cyc = _acb_dft_steps_prod(cyc, num, prec);
}
void acb_dft_prod_clear(acb_dft_prod_t t);
void _acb_dft_cyc_init_z_fac(acb_dft_cyc_t t, n_factor_t fac, slong dv, acb_ptr z, slong dz, slong len, slong prec);
void _acb_dft_cyc_init(acb_dft_cyc_t t, slong dv, slong len, slong prec);
ACB_DFT_INLINE void
acb_dft_cyc_init(acb_dft_cyc_t t, slong len, slong prec)
{
_acb_dft_cyc_init(t, 1, len, prec);
}
void acb_dft_cyc_clear(acb_dft_cyc_t t);
void _acb_dft_naive_init(acb_dft_naive_t pol, slong dv, acb_ptr z, slong dz, slong len, slong prec);
ACB_DFT_INLINE void
acb_dft_naive_init(acb_dft_naive_t pol, slong len, slong prec)
{
_acb_dft_naive_init(pol, 1, NULL, 0, len, prec);
}
ACB_DFT_INLINE void
acb_dft_naive_clear(acb_dft_naive_t pol)
{
if (pol->zclear)
_acb_vec_clear(pol->z, pol->n);
}
void _acb_dft_rad2_init(acb_dft_rad2_t t, slong dv, int e, slong prec);
ACB_DFT_INLINE void
acb_dft_rad2_init(acb_dft_rad2_t t, int e, slong prec)
{
_acb_dft_rad2_init(t, 1, e, prec);
}
ACB_DFT_INLINE void
acb_dft_rad2_clear(acb_dft_rad2_t t)
{
_acb_vec_clear(t->z, t->nz);
}
void _acb_dft_bluestein_init(acb_dft_bluestein_t t, slong dv, slong n, slong prec);
ACB_DFT_INLINE void
acb_dft_bluestein_init(acb_dft_bluestein_t t, slong n, slong prec)
{
_acb_dft_bluestein_init(t, 1, n, prec);
}
ACB_DFT_INLINE void
acb_dft_bluestein_clear(acb_dft_bluestein_t t)
{
if (t->n != 0)
{
_acb_vec_clear(t->z, t->n);
_acb_vec_clear(t->g, t->rad2->n);
acb_dft_rad2_clear(t->rad2);
}
}
void _acb_dft_crt_init(acb_dft_crt_t crt, slong dv, slong len, slong prec);
void acb_dft_crt_init(acb_dft_crt_t crt, slong len, slong prec);
void acb_dft_crt_clear(acb_dft_crt_t crt);
/* utils, could be moved elsewhere */
ACB_DFT_INLINE void
acb_swap_ri(acb_t x)
{
arb_swap(acb_realref(x), acb_imagref(x));
}
ACB_DFT_INLINE void
acb_vec_swap_ri(acb_ptr v, slong len)
{
slong k;
for (k = 0; k < len; k++)
acb_swap_ri(v + k);
}
ACB_DFT_INLINE void
_acb_vec_kronecker_mul(acb_ptr z, acb_srcptr x, acb_srcptr y, slong len, slong prec)
{
slong k;
for (k = 0; k < len; k++)
acb_mul(z + k, x + k, y + k, prec);
}
ACB_DFT_INLINE void
_acb_vec_kronecker_mul_step(acb_ptr z, acb_srcptr x, acb_srcptr y, slong step, slong len, slong prec)
{
slong k;
for (k = 0; k < len; k++)
{
acb_mul(z + k, x + k, y + k * step, prec);
}
}
ACB_DFT_INLINE void
acb_vec_printd_index(acb_srcptr vec, slong len, slong digits)
{
slong i;
for (i = 0; i < len; i++)
{
flint_printf("[%wd] ", i);
acb_printd(vec + i, digits);
flint_printf("\n");
}
}
#ifdef __cplusplus
}
#endif
#endif