NFFT Logo 3.2.3
nfft/simple_test.c
1 /*
2  * Copyright (c) 2002, 2012 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 3896 2012-10-10 12:19:26Z tovo $ */
20 #include "config.h"
21 
22 #include <stdio.h>
23 #include <math.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #ifdef HAVE_COMPLEX_H
27 #include <complex.h>
28 #endif
29 
30 #include "nfft3util.h"
31 #include "nfft3.h"
32 #include "infft.h"
33 
34 static void simple_test_nfft_1d(void)
35 {
36  nfft_plan p;
37  double t;
38 
39  int N=14;
40  int M=19;
41  ticks t0, t1;
42 
44  nfft_init_1d(&p,N,M);
45 
48 
50  if(p.nfft_flags & PRE_ONE_PSI)
51  nfft_precompute_one_psi(&p);
52 
55  nfft_vpr_complex(p.f_hat,p.N_total,"given Fourier coefficients, vector f_hat");
56 
58  t0 = getticks();
59  nfft_trafo_direct(&p);
60  t1 = getticks();
61  t = nfft_elapsed_seconds(t1,t0);
62  nfft_vpr_complex(p.f,p.M_total,"ndft, vector f");
63  printf(" took %e seconds.\n",t);
64 
66  nfft_trafo(&p);
67  nfft_vpr_complex(p.f,p.M_total,"nfft, vector f");
68 
70  nfft_adjoint_direct(&p);
71  nfft_vpr_complex(p.f_hat,p.N_total,"adjoint ndft, vector f_hat");
72 
74  nfft_adjoint(&p);
75  nfft_vpr_complex(p.f_hat,p.N_total,"adjoint nfft, vector f_hat");
76 
78  nfft_finalize(&p);
79 }
80 
81 static void simple_test_nfft_2d(void)
82 {
83  int K,N[2],n[2],M;
84  double t;
85  ticks t0, t1;
86 
87  nfft_plan p;
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 = getticks();
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 
103 
105  if(p.nfft_flags & PRE_ONE_PSI)
106  nfft_precompute_one_psi(&p);
107 
110 
111  t1 = getticks();
112  t = nfft_elapsed_seconds(t1,t0);
114  "given Fourier coefficients, vector f_hat (first few entries)");
115  printf(" ... initialisation took %e seconds.\n",t);
116 
118  t0 = getticks();
119  nfft_trafo_direct(&p);
120  t1 = getticks();
121  t = nfft_elapsed_seconds(t1,t0);
122  nfft_vpr_complex(p.f,K,"ndft, vector f (first few entries)");
123  printf(" took %e seconds.\n",t);
124 
126  t0 = getticks();
127  nfft_trafo(&p);
128  t1 = getticks();
129  t = nfft_elapsed_seconds(t1,t0);
130  nfft_vpr_complex(p.f,K,"nfft, vector f (first few entries)");
131  printf(" took %e seconds.\n",t);
132 
134  t0 = getticks();
135  nfft_adjoint_direct(&p);
136  t1 = getticks();
137  t = nfft_elapsed_seconds(t1,t0);
138  nfft_vpr_complex(p.f_hat,K,"adjoint ndft, vector f_hat (first few entries)");
139  printf(" took %e seconds.\n",t);
140 
142  t0 = getticks();
143  nfft_adjoint(&p);
144  t1 = getticks();
145  t = nfft_elapsed_seconds(t1,t0);
146  nfft_vpr_complex(p.f_hat,K,"adjoint nfft, vector f_hat (first few entries)");
147  printf(" took %e seconds.\n",t);
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 1;
164 }

Generated on Tue Apr 30 2013 by Doxygen 1.8.1