46 enum boolean {NO = 0, YES = 1};
58 int main (
int argc,
char **argv)
84 double _Complex *temp2;
91 double *alpha, *beta, *gamma;
94 fscanf(stdin,
"testcases=%d\n",&T);
95 fprintf(stderr,
"%d\n",T);
98 for (t = 0; t < T; t++)
101 fscanf(stdin,
"nfsft=%d\n",&use_nfsft);
102 fprintf(stderr,
"%d\n",use_nfsft);
106 fscanf(stdin,
"nfft=%d\n",&use_nfft);
107 fprintf(stderr,
"%d\n",use_nfsft);
111 fscanf(stdin,
"cutoff=%d\n",&cutoff);
112 fprintf(stderr,
"%d\n",cutoff);
121 fscanf(stdin,
"fpt=%d\n",&use_fpt);
122 fprintf(stderr,
"%d\n",use_fpt);
126 fscanf(stdin,
"threshold=%lf\n",&threshold);
127 fprintf(stderr,
"%lf\n",threshold);
147 fscanf(stdin,
"bandwidth=%d\n",&N);
148 fprintf(stderr,
"%d\n",N);
151 nfsft_precompute(N,threshold,
152 ((use_nfsft==NO)?(NFSFT_NO_FAST_ALGORITHM):(0U)), 0U);
155 fscanf(stdin,
"nodes=%d\n",&M);
156 fprintf(stderr,
"%d\n",M);
161 X(next_power_of_2_exp)(N, &npt, &npt_exp);
162 fprintf(stderr,
"npt = %d, npt_exp = %d\n", npt, npt_exp);
163 fprintf(stderr,
"Optimal interpolation!\n");
166 temp = (
double*)
nfft_malloc((2*N+1)*
sizeof(double));
167 temp2 = (
double _Complex*)
nfft_malloc((N+1)*
sizeof(
double _Complex));
170 for (j = 0; j <= N; j++)
172 xs = 2.0 + (2.0*j)/(N+1);
173 ys[j] = (2.0-((j == 0)?(1.0):(0.0)))*4.0*
nfft_bspline(4,xs,scratch);
178 for (j = 0; j <= N; j++)
184 qweights = (
double*)
nfft_malloc(qlength*
sizeof(
double));
186 fplan = fftw_plan_r2r_1d(N+1, qweights, qweights, FFTW_REDFT00, 0U);
187 for (j = 0; j < N+1; j++)
189 qweights[j] = -2.0/(4*j*j-1);
194 for (j = 0; j < N+1; j++)
196 qweights[j] *= 1.0/(2.0*N+1.0);
197 qweights[2*N+1-1-j] = qweights[j];
200 fplan = fftw_plan_r2r_1d(2*N+1, temp, temp, FFTW_REDFT00, 0U);
201 for (j = 0; j <= N; j++)
203 temp[j] = ((j==0 || j == 2*N)?(1.0):(0.5))*ys[j];
205 for (j = N+1; j < 2*N+1; j++)
211 for (j = 0; j < 2*N+1; j++)
213 temp[j] *= qweights[j];
218 for (j = 0; j < 2*N+1; j++)
220 temp[j] *= ((j==0 || j == 2*N)?(1.0):(0.5));
227 set = fpt_init(1, npt_exp, 0U);
229 alpha = (
double*)
nfft_malloc((N+2)*
sizeof(double));
230 beta = (
double*)
nfft_malloc((N+2)*
sizeof(double));
231 gamma = (
double*)
nfft_malloc((N+2)*
sizeof(double));
233 alpha_al_row(alpha, N, 0);
234 beta_al_row(beta, N, 0);
235 gamma_al_row(gamma, N, 0);
237 fpt_precompute(
set, 0, alpha, beta, gamma, 0, 1000.0);
239 fpt_transposed(
set,0, temp2, temp2, N, 0U);
247 fftw_destroy_plan(fplan);
256 nfsft_init_guru(&plan, N, M,
257 ((use_nfft!=0)?(0U):(NFSFT_USE_NDFT)) |
258 ((use_fpt!=0)?(0U):(NFSFT_USE_DPT)) | NFSFT_MALLOC_F | NFSFT_MALLOC_X |
259 NFSFT_MALLOC_F_HAT | NFSFT_NORMALIZED | NFSFT_ZERO_F_HAT,
260 PRE_PHI_HUT | PRE_PSI | FFTW_INIT |
270 solver_init_advanced_complex(&iplan, (
nfft_mv_plan_complex*)(&plan), CGNR | PRECOMPUTE_WEIGHT | PRECOMPUTE_DAMP);
274 for (j = 0; j < M; j++)
276 fscanf(stdin,
"%le %le %le %le\n",&plan.
x[2*j+1],&plan.
x[2*j],&re,&im);
277 plan.
x[2*j+1] = plan.
x[2*j+1]/(2.0*
PI);
278 plan.
x[2*j] = plan.
x[2*j]/(2.0*
PI);
279 if (plan.
x[2*j] >= 0.5)
281 plan.
x[2*j] = plan.
x[2*j] - 1;
283 iplan.
y[j] = re + _Complex_I * im;
284 fprintf(stderr,
"%le %le %le %le\n",plan.
x[2*j+1],plan.
x[2*j],
285 creal(iplan.
y[j]),cimag(iplan.
y[j]));
289 fscanf(stdin,
"nodes_eval=%d\n",&M2);
290 fprintf(stderr,
"%d\n",M2);
293 nfsft_init_guru(&plan2, N, M2,
294 ((use_nfft!=0)?(0U):(NFSFT_USE_NDFT)) |
295 ((use_fpt!=0)?(0U):(NFSFT_USE_DPT)) | NFSFT_MALLOC_F | NFSFT_MALLOC_X |
296 NFSFT_MALLOC_F_HAT | NFSFT_NORMALIZED | NFSFT_ZERO_F_HAT,
297 PRE_PHI_HUT | PRE_PSI | FFTW_INIT |
302 for (j = 0; j < M2; j++)
304 fscanf(stdin,
"%le %le\n",&plan2.
x[2*j+1],&plan2.
x[2*j]);
305 plan2.
x[2*j+1] = plan2.
x[2*j+1]/(2.0*
PI);
306 plan2.
x[2*j] = plan2.
x[2*j]/(2.0*
PI);
307 if (plan2.
x[2*j] >= 0.5)
309 plan2.
x[2*j] = plan2.
x[2*j] - 1;
311 fprintf(stderr,
"%le %le\n",plan2.
x[2*j+1],plan2.
x[2*j]);
314 nfsft_precompute_x(&plan);
316 nfsft_precompute_x(&plan2);
333 for (j = 0; j < plan.
N_total; j++)
335 iplan.
w_hat[j] = 0.0;
338 for (k = 0; k <= N; k++)
340 for (j = -k; j <= k; j++)
342 iplan.
w_hat[NFSFT_INDEX(k,j,&plan)] = 1.0/(pow(k+1.0,2.0)); ;
348 for (j = 0; j < plan.
N_total; j++)
350 iplan.
w_hat[j] = 0.0;
353 for (k = 0; k <= N; k++)
355 for (j = -k; j <= k; j++)
357 iplan.
w_hat[NFSFT_INDEX(k,j,&plan)] = 1/(pow(k+1.0,2.5));
366 for (j = 0; j < plan.
M_total; j++)
368 fprintf(stderr,
"%le\n",iplan.
w[j]);
371 fprintf(stderr,
"sum = %le\n",a);
374 fprintf(stderr,
"N_total = %d\n", plan.
N_total);
375 fprintf(stderr,
"M_total = %d\n", plan.
M_total);
378 for (k = 0; k < plan.
N_total; k++)
384 solver_before_loop_complex(&iplan);
391 for (m = 0; m < 29; m++)
393 fprintf(stderr,
"Residual ||r||=%e,\n",sqrt(iplan.
dot_r_iter));
416 for (k = 0; k < plan2.
M_total; k++)
418 fprintf(stdout,
"%le\n",cabs(plan2.
f[k]));
423 nfsft_finalize(&plan);
425 nfsft_finalize(&plan2);