| NFFT 3.5.0

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

nfft/simple_test.c
1 /*
2 * Copyright (c) 2002, 2017 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 #include <stdio.h>
19 #include <math.h>
20 #include <string.h>
21 #include <stdlib.h>
22
23 #define NFFT_PRECISION_DOUBLE
24
25 #include "nfft3mp.h"
26
27 static void simple_test_nfft_1d(void)
28 {
29 NFFT(plan) p;
30
31 int N = 14;
32 int M = 19;
33
34 const char *error_str;
35
37 NFFT(init_1d)(&p, N, M);
38
40 NFFT(vrand_shifted_unit_double)(p.x, p.M_total);
41
43 if (p.flags & PRE_ONE_PSI)
44 NFFT(precompute_one_psi)(&p);
45
47 NFFT(vrand_unit_complex)(p.f_hat,p.N_total);
48 NFFT(vpr_complex)(p.f_hat, p.N_total, "given Fourier coefficients, vector f_hat");
49
51 error_str = NFFT(check)(&p);
52 if (error_str != 0)
53 {
54 printf("Error in nfft module: %s\n", error_str);
55 return;
56 }
57
59 NFFT(trafo_direct)(&p);
60 NFFT(vpr_complex)(p.f,p.M_total,"ndft, vector f");
61
63 NFFT(trafo)(&p);
64 NFFT(vpr_complex)(p.f,p.M_total,"nfft, vector f");
65
67 NFFT(adjoint_direct)(&p);
68 NFFT(vpr_complex)(p.f_hat,p.N_total,"adjoint ndft, vector f_hat");
69
71 NFFT(adjoint)(&p);
72 NFFT(vpr_complex)(p.f_hat,p.N_total,"adjoint nfft, vector f_hat");
73
75 NFFT(finalize)(&p);
76 }
77
78 static void simple_test_nfft_2d(void)
79 {
80 int K, N[2], n[2], M;
81 NFFT_R t0, t1;
82
83 NFFT(plan) p;
84
85 const char *error_str;
86
87 N[0] = 32; n[0] = 64;
88 N[1] = 14; n[1] = 32;
89 M = N[0] * N[1];
90 K = 16;
91
92 t0 = NFFT(clock_gettime_seconds)();
94 NFFT(init_guru)(&p, 2, N, M, n, 7,
95 PRE_PHI_HUT| PRE_FULL_PSI| MALLOC_F_HAT| MALLOC_X| MALLOC_F |
96 FFTW_INIT| FFT_OUT_OF_PLACE,
97 FFTW_ESTIMATE| FFTW_DESTROY_INPUT);
98
100 NFFT(vrand_shifted_unit_double)(p.x, p.d * p.M_total);
101
103 if(p.flags & PRE_ONE_PSI)
104 NFFT(precompute_one_psi)(&p);
105
107 NFFT(vrand_unit_complex)(p.f_hat, p.N_total);
108
109 t1 = NFFT(clock_gettime_seconds)();
110 NFFT(vpr_complex)(p.f_hat,K, "given Fourier coefficients, vector f_hat (first few entries)");
111 printf(" ... initialisation took %.2" NFFT__FES__ " seconds.\n",t1-t0);
112
114 error_str = NFFT(check)(&p);
115 if (error_str != 0)
116 {
117 printf("Error in nfft module: %s\n", error_str);
118 return;
119 }
120
122 t0 = NFFT(clock_gettime_seconds)();
123 NFFT(trafo_direct)(&p);
124 t1 = NFFT(clock_gettime_seconds)();
125 NFFT(vpr_complex)(p.f, K, "ndft, vector f (first few entries)");
126 printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
127
129 t0 = NFFT(clock_gettime_seconds)();
130 NFFT(trafo)(&p);
131 t1 = NFFT(clock_gettime_seconds)();
132 NFFT(vpr_complex)(p.f, K, "nfft, vector f (first few entries)");
133 printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
134
136 t0 = NFFT(clock_gettime_seconds)();
137 NFFT(adjoint_direct)(&p);
138 t1 = NFFT(clock_gettime_seconds)();
139 NFFT(vpr_complex)(p.f_hat, K, "adjoint ndft, vector f_hat (first few entries)");
140 printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
141
143 t0 = NFFT(clock_gettime_seconds)();
144 NFFT(adjoint)(&p);
145 t1 = NFFT(clock_gettime_seconds)();
146 NFFT(vpr_complex)(p.f_hat, K, "adjoint nfft, vector f_hat (first few entries)");
147 printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
148
150 NFFT(finalize)(&p);
151 }
152
153 int main(void)
154 {
155 printf("1) computing a one dimensional ndft, nfft and an adjoint nfft\n\n");
156 simple_test_nfft_1d();
157
158 getc(stdin);
159
160 printf("2) computing a two dimensional ndft, nfft and an adjoint nfft\n\n");
161 simple_test_nfft_2d();
162
163 return EXIT_SUCCESS;
164 }
MALLOC_X
#define MALLOC_X
Definition: nfft3.h:199
MALLOC_F_HAT
#define MALLOC_F_HAT
Definition: nfft3.h:200
FFTW_INIT
#define FFTW_INIT
Definition: nfft3.h:203
MALLOC_F
#define MALLOC_F
Definition: nfft3.h:201
FFT_OUT_OF_PLACE
#define FFT_OUT_OF_PLACE
Definition: nfft3.h:202
PRE_FULL_PSI
#define PRE_FULL_PSI
Definition: nfft3.h:198
PRE_PHI_HUT
#define PRE_PHI_HUT
Definition: nfft3.h:193
PRE_ONE_PSI
#define PRE_ONE_PSI
Definition: nfft3.h:206