NFFT Logo 3.2.2
nfft/simple_test.c
00001 /*
00002  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
00003  *
00004  * This program is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU General Public License along with
00015  * this program; if not, write to the Free Software Foundation, Inc., 51
00016  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 /* $Id: simple_test.c 3896 2012-10-10 12:19:26Z tovo $ */
00020 #include "config.h"
00021 
00022 #include <stdio.h>
00023 #include <math.h>
00024 #include <string.h>
00025 #include <stdlib.h>
00026 #ifdef HAVE_COMPLEX_H
00027 #include <complex.h>
00028 #endif
00029 
00030 #include "nfft3util.h"
00031 #include "nfft3.h"
00032 #include "infft.h"
00033 
00034 static void simple_test_nfft_1d(void)
00035 {
00036   nfft_plan p;
00037   double t;
00038 
00039   int N=14;
00040   int M=19;
00041   ticks t0, t1;
00042 
00044   nfft_init_1d(&p,N,M);
00045 
00047   nfft_vrand_shifted_unit_double(p.x,p.M_total);
00048  
00050   if(p.nfft_flags & PRE_ONE_PSI)
00051       nfft_precompute_one_psi(&p);
00052 
00054   nfft_vrand_unit_complex(p.f_hat,p.N_total);
00055   nfft_vpr_complex(p.f_hat,p.N_total,"given Fourier coefficients, vector f_hat");
00056 
00058   t0 = getticks();
00059   nfft_trafo_direct(&p);
00060   t1 = getticks();
00061   t = nfft_elapsed_seconds(t1,t0);
00062   nfft_vpr_complex(p.f,p.M_total,"ndft, vector f");
00063   printf(" took %e seconds.\n",t);
00064 
00066   nfft_trafo(&p);
00067   nfft_vpr_complex(p.f,p.M_total,"nfft, vector f");
00068 
00070   nfft_adjoint_direct(&p);
00071   nfft_vpr_complex(p.f_hat,p.N_total,"adjoint ndft, vector f_hat");
00072 
00074   nfft_adjoint(&p);
00075   nfft_vpr_complex(p.f_hat,p.N_total,"adjoint nfft, vector f_hat");
00076 
00078   nfft_finalize(&p);
00079 }
00080 
00081 static void simple_test_nfft_2d(void)
00082 {
00083   int K,N[2],n[2],M;
00084   double t;
00085   ticks t0, t1;
00086 
00087   nfft_plan p;
00088 
00089   N[0]=32; n[0]=64;
00090   N[1]=14; n[1]=32;
00091   M=N[0]*N[1];
00092   K=16;
00093 
00094   t0 = getticks();
00096   nfft_init_guru(&p, 2, N, M, n, 7,
00097      PRE_PHI_HUT| PRE_FULL_PSI| MALLOC_F_HAT| MALLOC_X| MALLOC_F |
00098      FFTW_INIT| FFT_OUT_OF_PLACE,
00099      FFTW_ESTIMATE| FFTW_DESTROY_INPUT);
00100 
00102   nfft_vrand_shifted_unit_double(p.x,p.d*p.M_total);
00103 
00105   if(p.nfft_flags & PRE_ONE_PSI)
00106     nfft_precompute_one_psi(&p);
00107 
00109   nfft_vrand_unit_complex(p.f_hat,p.N_total);
00110 
00111   t1 = getticks();
00112   t = nfft_elapsed_seconds(t1,t0);
00113   nfft_vpr_complex(p.f_hat,K,
00114               "given Fourier coefficients, vector f_hat (first few entries)");
00115   printf(" ... initialisation took %e seconds.\n",t);
00116 
00118   t0 = getticks();
00119   nfft_trafo_direct(&p);
00120   t1 = getticks();
00121   t = nfft_elapsed_seconds(t1,t0);
00122   nfft_vpr_complex(p.f,K,"ndft, vector f (first few entries)");
00123   printf(" took %e seconds.\n",t);
00124 
00126   t0 = getticks();
00127   nfft_trafo(&p);
00128   t1 = getticks();
00129   t = nfft_elapsed_seconds(t1,t0);
00130   nfft_vpr_complex(p.f,K,"nfft, vector f (first few entries)");
00131   printf(" took %e seconds.\n",t);
00132 
00134   t0 = getticks();
00135   nfft_adjoint_direct(&p);
00136   t1 = getticks();
00137   t = nfft_elapsed_seconds(t1,t0);
00138   nfft_vpr_complex(p.f_hat,K,"adjoint ndft, vector f_hat (first few entries)");
00139   printf(" took %e seconds.\n",t);
00140 
00142   t0 = getticks();
00143   nfft_adjoint(&p);
00144   t1 = getticks();
00145   t = nfft_elapsed_seconds(t1,t0);
00146   nfft_vpr_complex(p.f_hat,K,"adjoint nfft, vector f_hat (first few entries)");
00147   printf(" took %e seconds.\n",t);
00148 
00150   nfft_finalize(&p);
00151 }
00152 
00153 int main(void)
00154 {
00155   printf("1) computing a one dimensional ndft, nfft and an adjoint nfft\n\n");
00156   simple_test_nfft_1d();
00157 
00158   getc(stdin);
00159 
00160   printf("2) computing a two dimensional ndft, nfft and an adjoint nfft\n\n");
00161   simple_test_nfft_2d();
00162 
00163   return 1;
00164 }

Generated on Fri Oct 12 2012 by Doxygen 1.8.0-20120409