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

ndft_fast.c

Go to the documentation of this file.
00001 
00008 #include <stdio.h>
00009 #include <math.h>
00010 #include <string.h>
00011 #include <stdlib.h>
00012 #include <complex.h>
00013 
00014 #include "util.h"
00015 #include "nfft3.h"
00016 
00017 void ndft_horner_trafo(nfft_plan *ths)
00018 {
00019   int j,k;
00020   double complex *f_hat_k, *f_j;
00021   double complex exp_omega_0;
00022 
00023   for(j=0, f_j=ths->f; j<ths->M_total; j++, f_j++)
00024     (*f_j) =0;
00025 
00026   for(j=0, f_j=ths->f; j<ths->M_total; j++, f_j++)
00027     {
00028       exp_omega_0 = cexp(+2*PI*I*ths->x[j]);
00029       for(k=0, f_hat_k= ths->f_hat; k<ths->N[0]; k++, f_hat_k++)
00030         {
00031           (*f_j)+=(*f_hat_k);
00032           (*f_j)*=exp_omega_0;
00033   }
00034       (*f_j)*=cexp(-PI*I*ths->N[0]*ths->x[j]);
00035     }
00036 } /* ndft_horner_trafo */
00037 
00038 void ndft_pre_full_trafo(nfft_plan *ths, double complex *A)
00039 {
00040   int j,k;
00041   double complex *f_hat_k, *f_j;
00042   double complex *A_local;
00043 
00044   for(j=0, f_j=ths->f; j<ths->M_total; j++, f_j++)
00045     (*f_j) =0;
00046 
00047   for(j=0, f_j=ths->f, A_local=A; j<ths->M_total; j++, f_j++)
00048     for(k=0, f_hat_k= ths->f_hat; k<ths->N[0]; k++, f_hat_k++, A_local++)
00049       (*f_j) += (*f_hat_k)*(*A_local);
00050 } /* ndft_pre_full_trafo */
00051 
00052 void ndft_pre_full_init(nfft_plan *ths, double complex *A)
00053 {
00054   int j,k;
00055   double complex *f_hat_k, *f_j, *A_local;
00056 
00057   for(j=0, f_j=ths->f, A_local=A; j<ths->M_total; j++, f_j++)
00058     for(k=0, f_hat_k= ths->f_hat; k<ths->N[0]; k++, f_hat_k++, A_local++)
00059       (*A_local) = cexp(-2*PI*I*(k-ths->N[0]/2)*ths->x[j]);
00060 
00061 } /* ndft_pre_full_init */
00062 
00063 void ndft_time(int N, int M, unsigned test_ndft, unsigned test_pre_full)
00064 {
00065   int r;
00066   double t, t_ndft, t_horner, t_pre_full, t_nfft;
00067   double complex *A;
00068 
00069   nfft_plan np;
00070 
00071   printf("%d\t%d\t",N, M);
00072 
00073   nfft_init_1d(&np, N, M);
00074 
00076   nfft_vrand_shifted_unit_double(np.x, np.M_total);
00077 
00078   if(test_pre_full)
00079    {
00080      A=(double complex*)fftw_malloc(N*M*sizeof(double complex));
00081      ndft_pre_full_init(&np, A);
00082    }
00083 
00085   nfft_vrand_unit_complex(np.f_hat, np.N_total);
00086  
00088   if(test_ndft)
00089     {
00090       t_ndft=0;
00091       r=0;
00092       while(t_ndft<0.1)
00093         {
00094           r++;
00095           t=nfft_second();
00096           ndft_trafo(&np);
00097           t=nfft_second()-t;
00098           t_ndft+=t;
00099         }
00100       t_ndft/=r;
00101 
00102       printf("%.2e\t",t_ndft);
00103     }
00104   else
00105     printf("nan\t\t");
00106 
00108   t_horner=0;
00109   r=0;
00110   while(t_horner<0.1)
00111     {
00112       r++;
00113       t=nfft_second();
00114       ndft_horner_trafo(&np);
00115       t=nfft_second()-t;
00116       t_horner+=t;
00117     }
00118   t_horner/=r;
00119 
00120   printf("%.2e\t", t_horner);
00121 
00123   if(test_pre_full)
00124     {
00125       t_pre_full=0;
00126       r=0;
00127       while(t_pre_full<0.1)
00128         {
00129           r++;
00130           t=nfft_second();
00131           ndft_pre_full_trafo(&np,A);
00132           t=nfft_second()-t;
00133           t_pre_full+=t;
00134         }
00135       t_pre_full/=r;
00136 
00137       printf("%.2e\t", t_pre_full);
00138     }
00139   else
00140     printf("nan\t\t");
00141 
00142   t_nfft=0;
00143   r=0;
00144   while(t_nfft<0.1)
00145     {
00146       r++;
00147       t=nfft_second();
00148       nfft_trafo(&np);
00149       t=nfft_second()-t;
00150       t_nfft+=t;
00151     }
00152   t_nfft/=r;
00153 
00154   printf("%.2e\n", t_nfft);
00155 
00156   fflush(stdout);
00157 
00158   if(test_pre_full)
00159     fftw_free(A);
00160 
00161   nfft_finalize(&np);
00162 }
00163 
00164 int main(int argc,char **argv)
00165 {
00166   int l,trial;
00167 
00168   if(argc<=2)
00169     {
00170       fprintf(stderr,"ndft_fast type first last trials\n");
00171       return -1;
00172     }
00173   
00174   fprintf(stderr,"Testing ndft, Horner-like ndft, fully precomputed ndft.\n");
00175   fprintf(stderr,"Columns: N, M, t_ndft, t_horner, t_pre_full, t_nfft\n\n");
00176 
00177   /* time vs. N=M */
00178   if(atoi(argv[1])==0)
00179     {
00180       for(l=atoi(argv[2]); l<=atoi(argv[3]); l++)
00181         for(trial=0; trial<atoi(argv[4]); trial++)
00182           if(l<=13)
00183             ndft_time((1U<< l), (1U<< l), 1, 1);
00184           else
00185             if(l<=15)
00186               ndft_time((1U<< l), (1U<< l), 1, 0);
00187             else
00188               ndft_time((1U<< l), (1U<< l), 0, 0);
00189     }
00190 
00191   return 1;
00192 }

Generated on 1 Nov 2006 by Doxygen 1.4.4