NFFT Logo 3.0 API Reference
Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

nsfft_test.c

00001 #include <stdio.h>
00002 #include <math.h>
00003 #include <string.h>
00004 #include <stdlib.h>
00005 
00006 #include "util.h"
00007 #include "nfft3.h"
00008 
00009 void accuracy_nsfft(int d, int J, int M, int m)
00010 {
00011   nsfft_plan p;
00012   double complex *swap_sndft_trafo, *swap_sndft_adjoint;
00013 
00014   nsfft_init(&p, d, J, M, m, NSDFT);
00015 
00016   swap_sndft_trafo=(double complex*) fftw_malloc(p.M_total*
00017              sizeof(double complex));
00018   swap_sndft_adjoint=(double complex*) fftw_malloc(p.N_total*
00019                sizeof(double complex));
00020 
00021   nsfft_init_random_nodes_coeffs(&p);
00022 
00024   nsdft_trafo(&p);
00025   
00026   NFFT_SWAP_complex(swap_sndft_trafo,p.f);
00027 
00029   nsfft_trafo(&p);
00030   
00031   printf("%5d\t %+.5E\t",J, 
00032          nfft_error_l_infty_1_complex(swap_sndft_trafo, p.f, p.M_total,
00033                                  p.f_hat, p.N_total));
00034   fflush(stdout);
00035 
00036   nfft_vrand_unit_complex(p.f, p.M_total);
00037 
00039   nsdft_adjoint(&p);
00040   
00041   NFFT_SWAP_complex(swap_sndft_adjoint,p.f_hat);
00042 
00044   nsfft_adjoint(&p);
00045   
00046   printf("%+.5E\n", 
00047          nfft_error_l_infty_1_complex(swap_sndft_adjoint, p.f_hat,
00048                                  p.N_total,
00049                                  p.f, p.M_total));
00050   fflush(stdout);
00051 
00052   fftw_free(swap_sndft_adjoint);
00053   fftw_free(swap_sndft_trafo);
00054 
00056   nsfft_finalize(&p);
00057 }
00058 
00059 void time_nsfft(int d, int J, int M, unsigned test_nsdft, unsigned test_nfft)
00060 {
00061   int r, N[d], n[d];
00062   int m, m_nfft, m_nsfft;
00063   double t, t_nsdft, t_nfft, t_nsfft;
00064 
00065   nsfft_plan p;
00066   nfft_plan np;
00067 
00068   for(r=0;r<d;r++)
00069   {
00070     N[r]=nfft_int_2_pow(J+2);
00071     n[r]=(3*N[r])/2;
00072     /*n[r]=2*N[r];*/
00073   }
00074 
00076   m=nfft_total_used_memory();
00077   nsfft_init(&p, d, J, M, 4, NSDFT);
00078   m_nsfft=nfft_total_used_memory()-m;
00079   nsfft_init_random_nodes_coeffs(&p);
00080 
00081   /* transforms */
00082   if(test_nsdft)
00083   {
00084     t_nsdft=0;
00085     r=0;
00086     while(t_nsdft<0.1)
00087     {
00088       r++;
00089       t=nfft_second();
00090       nsdft_trafo(&p);
00091       t=nfft_second()-t;
00092       t_nsdft+=t;
00093     }
00094     t_nsdft/=r;
00095   }
00096   else
00097     t_nsdft=nan("");   
00098 
00099   if(test_nfft)
00100   {
00101     m=nfft_total_used_memory();
00102     nfft_init_guru(&np,d,N,M,n,6, FG_PSI| MALLOC_F_HAT| MALLOC_F| FFTW_INIT,
00103        FFTW_MEASURE);
00104     m_nfft=nfft_total_used_memory()-m;
00105     np.x=p.act_nfft_plan->x;
00106     if(np.nfft_flags & PRE_ONE_PSI)
00107       nfft_precompute_one_psi(&np);
00108     nsfft_cp(&p, &np);
00109 
00110     t_nfft=0;
00111     r=0;
00112     while(t_nfft<0.1)
00113     {
00114       r++;
00115       t=nfft_second();
00116       nfft_trafo(&np);
00117       t=nfft_second()-t;
00118       t_nfft+=t;
00119     }
00120     t_nfft/=r;
00121 
00122     nfft_finalize(&np);
00123   }
00124   else
00125   {
00126     t_nfft=nan(""); 
00127     m_nfft=-1;
00128   }
00129 
00130   t_nsfft=0;
00131   r=0;
00132   while(t_nsfft<0.1)
00133     {
00134       r++;
00135       t=nfft_second();
00136       nsfft_trafo(&p);
00137       t=nfft_second()-t;
00138       t_nsfft+=t;
00139     }
00140   t_nsfft/=r;
00141 
00142   printf("%d\t%.2e\t%.2e\t%.2e\t%d\t%d\n",
00143    J,
00144          t_nsdft,
00145    t_nfft,
00146    t_nsfft,
00147          m_nfft,
00148    m_nsfft);
00149 
00150   fflush(stdout);
00151 
00153   nsfft_finalize(&p);
00154 }
00155 
00156 
00157 int main(int argc,char **argv)
00158 {
00159   int d, J, M;
00160     
00161   if(argc<=2)
00162   {
00163     fprintf(stderr,"nsfft_test type d [first last trials]\n");
00164     return -1;
00165   }
00166 
00167   d=atoi(argv[2]);
00168   fprintf(stderr,"Testing the nfft on the hyperbolic cross (nsfft).\n");
00169 
00170   if(atoi(argv[1])==1)
00171   {
00172     fprintf(stderr,"Testing the accuracy of the nsfft vs. nsdft\n");
00173     fprintf(stderr,"Columns: d, E_{1,\\infty}(trafo) E_{1,\\infty}(adjoint)\n\n");
00174     for(J=1; J<10; J++)
00175       accuracy_nsfft(d, J, 1000, 6);
00176   }
00177  
00178   if(atoi(argv[1])==2)
00179   {
00180     fprintf(stderr,"Testing the computation time of the nsdft, nfft, and nsfft\n");
00181     fprintf(stderr,"Columns: d, J, M, t_nsdft, t_nfft, t_nsfft\n\n");
00182     for(J=atoi(argv[3]); J<=atoi(argv[4]); J++)
00183     {
00184       if(d==2)
00185   M=(J+4)*nfft_int_2_pow(J+1);
00186       else
00187   M=6*nfft_int_2_pow(J)*(nfft_int_2_pow((J+1)/2+1)-1)+nfft_int_2_pow(3*(J/2+1));
00188       
00189       if(d*(J+2)<=24)
00190   time_nsfft(d, J, M, 1, 1);
00191       else
00192   if(d*(J+2)<=24)
00193     time_nsfft(d, J, M, 0, 1);
00194   else
00195     time_nsfft(d, J, M, 0, 0);  
00196     }
00197   }
00198 
00199   return 1;
00200 }

Generated on 1 Nov 2006 by Doxygen 1.4.4