NFFT  3.3.0
nfft/simple_test.c
1 /*
2  * Copyright (c) 2002, 2015 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /* $Id: simple_test.c.in 4298 2015-01-15 10:24:37Z tovo $ */
20 #include <stdio.h>
21 #include <math.h>
22 #include <string.h>
23 #include <stdlib.h>
24 
25 #define NFFT_PRECISION_DOUBLE
26 
27 #include "nfft3mp.h"
28 
29 static void simple_test_nfft_1d(void)
30 {
31  NFFT(plan) p;
32 
33  int N = 14;
34  int M = 19;
35 
36  const char *error_str;
37 
39  NFFT(init_1d)(&p, N, M);
40 
42  NFFT(vrand_shifted_unit_double)(p.x, p.M_total);
43 
45  if (p.flags & PRE_ONE_PSI)
46  NFFT(precompute_one_psi)(&p);
47 
49  NFFT(vrand_unit_complex)(p.f_hat,p.N_total);
50  NFFT(vpr_complex)(p.f_hat, p.N_total, "given Fourier coefficients, vector f_hat");
51 
53  error_str = NFFT(check)(&p);
54  if (error_str != 0)
55  {
56  printf("Error in nfft module: %s\n", error_str);
57  return;
58  }
59 
61  NFFT(trafo_direct)(&p);
62  NFFT(vpr_complex)(p.f,p.M_total,"ndft, vector f");
63 
65  NFFT(trafo)(&p);
66  NFFT(vpr_complex)(p.f,p.M_total,"nfft, vector f");
67 
69  NFFT(adjoint_direct)(&p);
70  NFFT(vpr_complex)(p.f_hat,p.N_total,"adjoint ndft, vector f_hat");
71 
73  NFFT(adjoint)(&p);
74  NFFT(vpr_complex)(p.f_hat,p.N_total,"adjoint nfft, vector f_hat");
75 
77  NFFT(finalize)(&p);
78 }
79 
80 static void simple_test_nfft_2d(void)
81 {
82  int K, N[2], n[2], M;
83  NFFT_R t0, t1;
84 
85  NFFT(plan) p;
86 
87  const char *error_str;
88 
89  N[0] = 32; n[0] = 64;
90  N[1] = 14; n[1] = 32;
91  M = N[0] * N[1];
92  K = 16;
93 
94  t0 = NFFT(clock_gettime_seconds)();
96  NFFT(init_guru)(&p, 2, N, M, n, 7,
97  PRE_PHI_HUT| PRE_FULL_PSI| MALLOC_F_HAT| MALLOC_X| MALLOC_F |
98  FFTW_INIT| FFT_OUT_OF_PLACE,
99  FFTW_ESTIMATE| FFTW_DESTROY_INPUT);
100 
102  NFFT(vrand_shifted_unit_double)(p.x, p.d * p.M_total);
103 
105  if(p.flags & PRE_ONE_PSI)
106  NFFT(precompute_one_psi)(&p);
107 
109  NFFT(vrand_unit_complex)(p.f_hat, p.N_total);
110 
111  t1 = NFFT(clock_gettime_seconds)();
112  NFFT(vpr_complex)(p.f_hat,K, "given Fourier coefficients, vector f_hat (first few entries)");
113  printf(" ... initialisation took %.2" NFFT__FES__ " seconds.\n",t1-t0);
114 
116  error_str = NFFT(check)(&p);
117  if (error_str != 0)
118  {
119  printf("Error in nfft module: %s\n", error_str);
120  return;
121  }
122 
124  t0 = NFFT(clock_gettime_seconds)();
125  NFFT(trafo_direct)(&p);
126  t1 = NFFT(clock_gettime_seconds)();
127  NFFT(vpr_complex)(p.f, K, "ndft, vector f (first few entries)");
128  printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
129 
131  t0 = NFFT(clock_gettime_seconds)();
132  NFFT(trafo)(&p);
133  t1 = NFFT(clock_gettime_seconds)();
134  NFFT(vpr_complex)(p.f, K, "nfft, vector f (first few entries)");
135  printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
136 
138  t0 = NFFT(clock_gettime_seconds)();
139  NFFT(adjoint_direct)(&p);
140  t1 = NFFT(clock_gettime_seconds)();
141  NFFT(vpr_complex)(p.f_hat, K, "adjoint ndft, vector f_hat (first few entries)");
142  printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
143 
145  t0 = NFFT(clock_gettime_seconds)();
146  NFFT(adjoint)(&p);
147  t1 = NFFT(clock_gettime_seconds)();
148  NFFT(vpr_complex)(p.f_hat, K, "adjoint nfft, vector f_hat (first few entries)");
149  printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
150 
152  NFFT(finalize)(&p);
153 }
154 
155 int main(void)
156 {
157  printf("1) computing a one dimensional ndft, nfft and an adjoint nfft\n\n");
158  simple_test_nfft_1d();
159 
160  getc(stdin);
161 
162  printf("2) computing a two dimensional ndft, nfft and an adjoint nfft\n\n");
163  simple_test_nfft_2d();
164 
165  return EXIT_SUCCESS;
166 }