NFFT Logo 3.2.3
nfsoft/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 
21 #include "config.h"
22 
23 /* Include standard C headers. */
24 #include <stdio.h>
25 #include <math.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #ifdef HAVE_COMPLEX_H
29 #include <complex.h>
30 #endif
31 
32 /* Include NFFT 3 utilities headers. */
33 #include "nfft3util.h"
34 /* Include NFFT3 library header. */
35 #include "nfft3.h"
36 #include "infft.h"
37 
38 static void simple_test_nfsoft(int bw, int M)
39 {
40  nfsoft_plan plan_nfsoft;
41  nfsoft_plan plan_ndsoft;
43  ticks t0, t1;
44  int j;
45  int k, m;
46  double d1, d2, d3;
47  double time, error;
48  unsigned int flags = NFSOFT_MALLOC_X | NFSOFT_MALLOC_F | NFSOFT_MALLOC_F_HAT;
51  k = 1000;
52  m = 5;
61  nfsoft_init_guru(&plan_ndsoft, bw, M, flags | NFSOFT_USE_NDFT
62  | NFSOFT_USE_DPT, PRE_PHI_HUT | PRE_PSI | MALLOC_X | MALLOC_F_HAT
63  | MALLOC_F | FFTW_INIT | FFT_OUT_OF_PLACE, m, k);
64 
65  nfsoft_init_guru(&plan_nfsoft, bw, M, flags, PRE_PHI_HUT | PRE_PSI | MALLOC_X
66  | MALLOC_F_HAT | MALLOC_F | FFTW_INIT | FFT_OUT_OF_PLACE, m, k);
67 
69  for (j = 0; j < plan_nfsoft.M_total; j++)
70  {
71  d1 = ((R) rand()) / RAND_MAX - 0.5;
72  d2 = 0.5 * ((R) rand()) / RAND_MAX;
73  d3 = ((R) rand()) / RAND_MAX - 0.5;
74 
75  plan_nfsoft.x[3* j ] = d1;
76  plan_nfsoft.x[3* j + 1] = d2;
77  plan_nfsoft.x[3* j + 2] = d3;
79  plan_ndsoft.x[3* j ] = d1;
80  plan_ndsoft.x[3* j + 1] = d2;
81  plan_ndsoft.x[3* j + 2] = d3;
82  }
83 
85  for (j = 0; j < (bw + 1) * (4* (bw +1)*(bw+1)-1)/3;j++)
86  {
87  d1=((R)rand())/RAND_MAX - 0.5;
88  d2=((R)rand())/RAND_MAX - 0.5;
89  plan_nfsoft.f_hat[j]=d1 + I*d2;
90  plan_ndsoft.f_hat[j]=d1 + I*d2;
91  }
92 
93  if ((bw+1)*(4*(bw+1)*(bw+1)-1)/3<=20)
94  nfft_vpr_complex(plan_nfsoft.f_hat,(bw+1)*(4*(bw+1)*(bw+1)-1)/3,"randomly generated SO(3) Fourier coefficients");
95  else
96  nfft_vpr_complex(plan_ndsoft.f_hat,20,"1st-20th randomly generated SO(3) Fourier coefficient");
97 
98  printf("\n---------------------------------------------\n");
99 
101  nfsoft_precompute(&plan_nfsoft);
102  nfsoft_precompute(&plan_ndsoft);
103 
104 
106  t0 = getticks();
107  nfsoft_trafo(&plan_nfsoft);
108  t1 = getticks();
109  time = nfft_elapsed_seconds(t1,t0);
110  if (plan_nfsoft.M_total<=20)
111  nfft_vpr_complex(plan_nfsoft.f,plan_nfsoft.M_total,"NFSOFT, function samples");
112  else
113  nfft_vpr_complex(plan_nfsoft.f,20,"NFSOFT, 1st-20th function sample");
114  printf(" computed in %11le seconds\n",time);
115 
117  t0 = getticks();
118  nfsoft_trafo(&plan_ndsoft);
119  t1 = getticks();
120 time = nfft_elapsed_seconds(t1,t0);
121  if (plan_ndsoft.M_total<=20)
122  nfft_vpr_complex(plan_ndsoft.f,plan_ndsoft.M_total,"NDSOFT, function samples");
123  else
124  nfft_vpr_complex(plan_ndsoft.f,20,"NDSOFT, 1st-20th function sample");
125  printf(" computed in %11le seconds\n",time);
126 
128  error= X(error_l_infty_complex)(plan_ndsoft.f,plan_nfsoft.f, plan_nfsoft.M_total);
129  printf("\n The NFSOFT of bandwidth=%d for %d rotations has infty-error %11le \n",bw, M,error);
130 
131  printf("\n---------------------------------------------\n");
132 
133  plan_nfsoft.f[0]=1.0;
134  plan_ndsoft.f[0]=1.0;
135  nfft_vpr_complex(plan_ndsoft.f,plan_ndsoft.M_total, "function samples to start adjoint trafo");
136 
138  t0 = getticks();
139  nfsoft_adjoint(&plan_nfsoft);
140  t1 = getticks();
141 time = nfft_elapsed_seconds(t1,t0);
142  if ((bw+1)*(4*(bw+1)*(bw+1)-1)/3<=20)
143  nfft_vpr_complex(plan_nfsoft.f_hat,(bw+1)*(4*(bw+1)*(bw+1)-1)/3,"SO(3) Fourier coefficients");
144  else
145  nfft_vpr_complex(plan_nfsoft.f_hat,20,"adjoint NFSOFT, 1st-20th Fourier coefficient");
146  printf(" computed in %11le seconds\n",time);
147 
149  t0 = getticks();
150  nfsoft_adjoint(&plan_ndsoft);
151  t1 = getticks();
152 time = nfft_elapsed_seconds(t1,t0);
153  if ((bw+1)*(4*(bw+1)*(bw+1)-1)/3<=20)
154  nfft_vpr_complex(plan_ndsoft.f_hat,(bw+1)*(4*(bw+1)*(bw+1)-1)/3,"SO(3) Fourier coefficients");
155  else
156  nfft_vpr_complex(plan_ndsoft.f_hat,20,"adjoint NDSOFT, 1st-20th Fourier coefficient");
157  printf(" computed in %11le seconds\n",time);
158 
159 
161  error=X(error_l_infty_complex)(plan_ndsoft.f_hat,plan_nfsoft.f_hat, (bw+1)*(4*(bw+1)*(bw+1)-1)/3);
162  printf("\n The adjoint NFSOFT of bandwidth=%d for %d rotations has infty-error %11le \n",bw, M,error);
163 
164  printf("\n---------------------------------------------\n");
165 
167  nfsoft_finalize(&plan_ndsoft);
168  nfsoft_finalize(&plan_nfsoft);
169 }
170 
187 int main(int argc, char **argv)
188 {
189  int N;
190  int M;
192  if (argc < 2)
193  {
194  printf(
195  "This test programm computes the NFSOFT with maximum polynomial degree N at M input rotations\n");
196  printf("Usage: simple_test N M \n");
197  printf("e.g.: simple_test 8 64\n");
198  exit(0);
199  }
200 
202  N = atoi(argv[1]);
203  M = atoi(argv[2]);
204 
205  printf(
206  "computing an NDSOFT, an NFSOFT, an adjoint NDSOFT, and an adjoint NFSOFT\n\n");
207 
208  simple_test_nfsoft(N, M);
209 
210 
211 
212  /* Exit the program. */
213  return EXIT_SUCCESS;
214 
215 }

Generated on Tue Apr 30 2013 by Doxygen 1.8.1