NFFT  3.3.2
simple_test.c
00001 /*
00002  * Copyright (c) 2002, 2016 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 #include <stdio.h>
00019 #include <math.h>
00020 #include <string.h>
00021 #include <stdlib.h>
00022 
00023 #define NFFT_PRECISION_DOUBLE
00024 
00025 #include "nfft3mp.h"
00026 
00027 static void simple_test_nfft_1d(void)
00028 {
00029   NFFT(plan) p;
00030 
00031   int N = 14;
00032   int M = 19;
00033 
00034   const char *error_str;
00035 
00037   NFFT(init_1d)(&p, N, M);
00038 
00040   NFFT(vrand_shifted_unit_double)(p.x, p.M_total);
00041  
00043   if (p.flags & PRE_ONE_PSI)
00044       NFFT(precompute_one_psi)(&p);
00045 
00047   NFFT(vrand_unit_complex)(p.f_hat,p.N_total);
00048   NFFT(vpr_complex)(p.f_hat, p.N_total, "given Fourier coefficients, vector f_hat");
00049 
00051   error_str = NFFT(check)(&p);
00052   if (error_str != 0)
00053   {
00054     printf("Error in nfft module: %s\n", error_str);
00055     return;
00056   }
00057 
00059   NFFT(trafo_direct)(&p);
00060   NFFT(vpr_complex)(p.f,p.M_total,"ndft, vector f");
00061 
00063   NFFT(trafo)(&p);
00064   NFFT(vpr_complex)(p.f,p.M_total,"nfft, vector f");
00065 
00067   NFFT(adjoint_direct)(&p);
00068   NFFT(vpr_complex)(p.f_hat,p.N_total,"adjoint ndft, vector f_hat");
00069 
00071   NFFT(adjoint)(&p);
00072   NFFT(vpr_complex)(p.f_hat,p.N_total,"adjoint nfft, vector f_hat");
00073 
00075   NFFT(finalize)(&p);
00076 }
00077 
00078 static void simple_test_nfft_2d(void)
00079 {
00080   int K, N[2], n[2], M;
00081   NFFT_R t0, t1;
00082 
00083   NFFT(plan) p;
00084 
00085   const char *error_str;
00086 
00087   N[0] = 32; n[0] = 64;
00088   N[1] = 14; n[1] = 32;
00089   M = N[0] * N[1];
00090   K = 16;
00091 
00092   t0 = NFFT(clock_gettime_seconds)();
00094   NFFT(init_guru)(&p, 2, N, M, n, 7,
00095      PRE_PHI_HUT| PRE_FULL_PSI| MALLOC_F_HAT| MALLOC_X| MALLOC_F |
00096      FFTW_INIT| FFT_OUT_OF_PLACE,
00097      FFTW_ESTIMATE| FFTW_DESTROY_INPUT);
00098 
00100   NFFT(vrand_shifted_unit_double)(p.x, p.d * p.M_total);
00101 
00103   if(p.flags & PRE_ONE_PSI)
00104     NFFT(precompute_one_psi)(&p);
00105 
00107   NFFT(vrand_unit_complex)(p.f_hat, p.N_total);
00108 
00109   t1 = NFFT(clock_gettime_seconds)();
00110   NFFT(vpr_complex)(p.f_hat,K, "given Fourier coefficients, vector f_hat (first few entries)");
00111   printf(" ... initialisation took %.2" NFFT__FES__ " seconds.\n",t1-t0);
00112 
00114   error_str = NFFT(check)(&p);
00115   if (error_str != 0)
00116   {
00117     printf("Error in nfft module: %s\n", error_str);
00118     return;
00119   }
00120 
00122   t0 = NFFT(clock_gettime_seconds)();
00123   NFFT(trafo_direct)(&p);
00124   t1 = NFFT(clock_gettime_seconds)();
00125   NFFT(vpr_complex)(p.f, K, "ndft, vector f (first few entries)");
00126   printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
00127 
00129   t0 = NFFT(clock_gettime_seconds)();
00130   NFFT(trafo)(&p);
00131   t1 = NFFT(clock_gettime_seconds)();
00132   NFFT(vpr_complex)(p.f, K, "nfft, vector f (first few entries)");
00133   printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
00134 
00136   t0 = NFFT(clock_gettime_seconds)();
00137   NFFT(adjoint_direct)(&p);
00138   t1 = NFFT(clock_gettime_seconds)();
00139   NFFT(vpr_complex)(p.f_hat, K, "adjoint ndft, vector f_hat (first few entries)");
00140   printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
00141 
00143   t0 = NFFT(clock_gettime_seconds)();
00144   NFFT(adjoint)(&p);
00145   t1 = NFFT(clock_gettime_seconds)();
00146   NFFT(vpr_complex)(p.f_hat, K, "adjoint nfft, vector f_hat (first few entries)");
00147   printf(" took %.2" NFFT__FES__ " seconds.\n",t1-t0);
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 EXIT_SUCCESS;
00164 }