NFFT Logo 3.2.3
nsfft_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: nsfft_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 accuracy_nsfft(int d, int J, int M, int m)
35 {
36  nsfft_plan p;
37  double _Complex *swap_sndft_trafo, *swap_sndft_adjoint;
38 
39  nsfft_init(&p, d, J, M, m, NSDFT);
40 
41  swap_sndft_trafo=(double _Complex*) nfft_malloc(p.M_total*
42  sizeof(double _Complex));
43  swap_sndft_adjoint=(double _Complex*) nfft_malloc(p.N_total*
44  sizeof(double _Complex));
45 
46  nsfft_init_random_nodes_coeffs(&p);
47 
49  nsfft_trafo_direct(&p);
50 
51  NFFT_SWAP_complex(swap_sndft_trafo,p.f);
52 
54  nsfft_trafo(&p);
55 
56  printf("%5d\t %+.5E\t",J,
57  X(error_l_infty_1_complex)(swap_sndft_trafo, p.f, p.M_total,
58  p.f_hat, p.N_total));
59  fflush(stdout);
60 
62 
64  nsfft_adjoint_direct(&p);
65 
66  NFFT_SWAP_complex(swap_sndft_adjoint,p.f_hat);
67 
69  nsfft_adjoint(&p);
70 
71  printf("%+.5E\n",
72  X(error_l_infty_1_complex)(swap_sndft_adjoint, p.f_hat,
73  p.N_total,
74  p.f, p.M_total));
75  fflush(stdout);
76 
77  nfft_free(swap_sndft_adjoint);
78  nfft_free(swap_sndft_trafo);
79 
81  nsfft_finalize(&p);
82 }
83 
84 static void time_nsfft(int d, int J, int M, unsigned test_nsdft, unsigned test_nfft)
85 {
86  int r, N[d], n[d];
87  double t, t_nsdft, t_nfft, t_nsfft;
88  ticks t0, t1;
89 
90  nsfft_plan p;
91  nfft_plan np;
92 
93  for(r=0;r<d;r++)
94  {
95  N[r]= X(exp2i)(J+2);
96  n[r]=(3*N[r])/2;
97  /*n[r]=2*N[r];*/
98  }
99 
101  nsfft_init(&p, d, J, M, 4, NSDFT);
102  nsfft_init_random_nodes_coeffs(&p);
103 
104  /* transforms */
105  if(test_nsdft)
106  {
107  t_nsdft=0;
108  r=0;
109  while(t_nsdft<0.1)
110  {
111  r++;
112  t0 = getticks();
113  nsfft_trafo_direct(&p);
114  t1 = getticks();
115  t = nfft_elapsed_seconds(t1,t0);
116  t_nsdft+=t;
117  }
118  t_nsdft/=r;
119  }
120  else
121  t_nsdft=nan("");
122 
123  if(test_nfft)
124  {
125  nfft_init_guru(&np,d,N,M,n,6, FG_PSI| MALLOC_F_HAT| MALLOC_F| FFTW_INIT,
126  FFTW_MEASURE);
127  np.x=p.act_nfft_plan->x;
128  if(np.nfft_flags & PRE_ONE_PSI)
129  nfft_precompute_one_psi(&np);
130  nsfft_cp(&p, &np);
131 
132  t_nfft=0;
133  r=0;
134  while(t_nfft<0.1)
135  {
136  r++;
137  t0 = getticks();
138  nfft_trafo(&np);
139  t1 = getticks();
140  t = nfft_elapsed_seconds(t1,t0);
141  t_nfft+=t;
142  }
143  t_nfft/=r;
144 
145  nfft_finalize(&np);
146  }
147  else
148  {
149  t_nfft=nan("");
150  }
151 
152  t_nsfft=0;
153  r=0;
154  while(t_nsfft<0.1)
155  {
156  r++;
157  t0 = getticks();
158  nsfft_trafo(&p);
159  t1 = getticks();
160  t = nfft_elapsed_seconds(t1,t0);
161  t_nsfft+=t;
162  }
163  t_nsfft/=r;
164 
165  printf("%d\t%.2e\t%.2e\t%.2e\n", J, t_nsdft, t_nfft, t_nsfft);
166 
167  fflush(stdout);
168 
170  nsfft_finalize(&p);
171 }
172 
173 
174 int main(int argc,char **argv)
175 {
176  int d, J, M;
177 
178  if(argc<=2)
179  {
180  fprintf(stderr,"nsfft_test type d [first last trials]\n");
181  return -1;
182  }
183 
184  d=atoi(argv[2]);
185  fprintf(stderr,"Testing the nfft on the hyperbolic cross (nsfft).\n");
186 
187  if(atoi(argv[1])==1)
188  {
189  fprintf(stderr,"Testing the accuracy of the nsfft vs. nsdft\n");
190  fprintf(stderr,"Columns: d, E_{1,\\infty}(trafo) E_{1,\\infty}(adjoint)\n\n");
191  for(J=1; J<10; J++)
192  accuracy_nsfft(d, J, 1000, 6);
193  }
194 
195  if(atoi(argv[1])==2)
196  {
197  fprintf(stderr,"Testing the computation time of the nsdft, nfft, and nsfft\n");
198  fprintf(stderr,"Columns: d, J, M, t_nsdft, t_nfft, t_nsfft\n\n");
199  for(J=atoi(argv[3]); J<=atoi(argv[4]); J++)
200  {
201  if(d==2)
202  M=(J+4)*X(exp2i)(J+1);
203  else
204  M=6*X(exp2i)(J)*(X(exp2i)((J+1)/2+1)-1)+X(exp2i)(3*(J/2+1));
205 
206  if(d*(J+2)<=24)
207  time_nsfft(d, J, M, 1, 1);
208  else
209  if(d*(J+2)<=24)
210  time_nsfft(d, J, M, 0, 1);
211  else
212  time_nsfft(d, J, M, 0, 0);
213  }
214  }
215 
216  return 1;
217 }

Generated on Tue Apr 30 2013 by Doxygen 1.8.1