NFFT  3.3.1
accuracy.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 
00019 #include <math.h>
00020 #include <stdlib.h>
00021 #include <complex.h>
00022 
00023 #include "nfft3.h"
00024 
00026 #define CSWAP(x,y) {double _Complex * NFFT_SWAP_temp__; \
00027   NFFT_SWAP_temp__=(x); (x)=(y); (y)=NFFT_SWAP_temp__;}
00028 
00029 void accuracy(int d)
00030 {
00031   int m,t;
00032   nnfft_plan my_plan;
00033   double _Complex *slow;
00034 
00035   int N[d],n[d];
00036   int M_total,N_total;
00037   M_total=10000;N_total=1;
00038 
00039   slow=(double _Complex*)nfft_malloc(M_total*sizeof(double _Complex));
00040 
00041   for(t=0; t<d; t++)
00042     {
00043       N[t]=(1<<(12/d));
00044       n[t]=2*N[t];
00045       N_total*=N[t];
00046     }
00047 
00049   for(m=0; m<10; m++)
00050     {
00051       nnfft_init_guru(&my_plan, d, N_total, M_total, N, n, m,
00052           PRE_PSI| PRE_PHI_HUT|
00053           MALLOC_X| MALLOC_V| MALLOC_F_HAT| MALLOC_F);
00054 
00055 
00057       nfft_vrand_shifted_unit_double(my_plan.x, d*my_plan.M_total);
00058       nfft_vrand_shifted_unit_double(my_plan.v, d*my_plan.N_total);
00059 
00061       if(my_plan.nnfft_flags & PRE_PSI)
00062         nnfft_precompute_psi(&my_plan);
00063 
00064       if(my_plan.nnfft_flags & PRE_LIN_PSI)
00065         nnfft_precompute_lin_psi(&my_plan);
00066 
00067       if(my_plan.nnfft_flags & PRE_FULL_PSI)
00068         nnfft_precompute_full_psi(&my_plan);
00069 
00071       if(my_plan.nnfft_flags & PRE_PHI_HUT)
00072         nnfft_precompute_phi_hut(&my_plan);
00073 
00075       nfft_vrand_unit_complex(my_plan.f_hat, my_plan.N_total);
00076 
00078       nnfft_trafo_direct(&my_plan);
00079 
00080       CSWAP(my_plan.f,slow);
00081 
00083       nnfft_trafo(&my_plan);
00084 
00085       printf("%e, %e\n",
00086        nfft_error_l_infty_complex(slow, my_plan.f, M_total),
00087        nfft_error_l_infty_1_complex(slow, my_plan.f, M_total, my_plan.f_hat,
00088              my_plan.N_total));
00089 
00091       nnfft_finalize(&my_plan);
00092     }
00093 }
00094 
00095 int main(void)
00096 {
00097   int d;
00098   for(d=1; d<4; d++)
00099     accuracy(d);
00100 
00101   return 1;
00102 }