NFFT  3.4.1
accuracy.c
1 /*
2  * Copyright (c) 2002, 2017 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include <math.h>
20 #include <stdlib.h>
21 #include <complex.h>
22 
23 #include "nfft3.h"
24 
26 #define CSWAP(x,y) {double _Complex * NFFT_SWAP_temp__; \
27  NFFT_SWAP_temp__=(x); (x)=(y); (y)=NFFT_SWAP_temp__;}
28 
29 void accuracy(int d)
30 {
31  int m,t;
32  nnfft_plan my_plan;
33  double _Complex *slow;
34 
35  int N[d],n[d];
36  int M_total,N_total;
37  M_total=10000;N_total=1;
38 
39  slow=(double _Complex*)nfft_malloc(M_total*sizeof(double _Complex));
40 
41  for(t=0; t<d; t++)
42  {
43  N[t]=(1<<(12/d));
44  n[t]=2*N[t];
45  N_total*=N[t];
46  }
47 
49  for(m=0; m<10; m++)
50  {
51  nnfft_init_guru(&my_plan, d, N_total, M_total, N, n, m,
54 
55 
57  nfft_vrand_shifted_unit_double(my_plan.x, d*my_plan.M_total);
58  nfft_vrand_shifted_unit_double(my_plan.v, d*my_plan.N_total);
59 
61  if(my_plan.nnfft_flags & PRE_PSI)
62  nnfft_precompute_psi(&my_plan);
63 
64  if(my_plan.nnfft_flags & PRE_LIN_PSI)
65  nnfft_precompute_lin_psi(&my_plan);
66 
67  if(my_plan.nnfft_flags & PRE_FULL_PSI)
68  nnfft_precompute_full_psi(&my_plan);
69 
71  if(my_plan.nnfft_flags & PRE_PHI_HUT)
72  nnfft_precompute_phi_hut(&my_plan);
73 
75  nfft_vrand_unit_complex(my_plan.f_hat, my_plan.N_total);
76 
78  nnfft_trafo_direct(&my_plan);
79 
80  CSWAP(my_plan.f,slow);
81 
83  nnfft_trafo(&my_plan);
84 
85  printf("%e, %e\n",
86  nfft_error_l_infty_complex(slow, my_plan.f, M_total),
87  nfft_error_l_infty_1_complex(slow, my_plan.f, M_total, my_plan.f_hat,
88  my_plan.N_total));
89 
91  nnfft_finalize(&my_plan);
92  }
93 }
94 
95 int main(void)
96 {
97  int d;
98  for(d=1; d<4; d++)
99  accuracy(d);
100 
101  return 1;
102 }
void nnfft_precompute_psi(nnfft_plan *ths_plan)
Definition: nnfft.c:385
fftw_complex * f_hat
Fourier coefficients.
Definition: nfft3.h:424
unsigned nnfft_flags
flags for precomputation, malloc
Definition: nfft3.h:424
fftw_complex * f
Samples.
Definition: nfft3.h:424
#define MALLOC_X
Definition: nfft3.h:199
#define MALLOC_F_HAT
Definition: nfft3.h:200
double * v
nodes (in fourier domain)
Definition: nfft3.h:424
void nnfft_trafo(nnfft_plan *ths_plan)
user routines
Definition: nnfft.c:291
void nfft_vrand_shifted_unit_double(double *x, const NFFT_INT n)
Inits a vector of random double numbers in .
void nnfft_precompute_phi_hut(nnfft_plan *ths_plan)
initialisation of direct transform
Definition: nnfft.c:347
void nnfft_precompute_full_psi(nnfft_plan *ths_plan)
computes all entries of B explicitly
Definition: nnfft.c:424
#define MALLOC_V
Definition: nfft3.h:425
void nnfft_precompute_lin_psi(nnfft_plan *ths_plan)
create a lookup table
Definition: nnfft.c:367
void nfft_vrand_unit_complex(fftw_complex *x, const NFFT_INT n)
Inits a vector of random complex numbers in .
NFFT_INT M_total
Total number of samples.
Definition: nfft3.h:424
#define MALLOC_F
Definition: nfft3.h:201
data structure for an NNFFT (nonequispaced in time and frequency fast Fourier transform) plan with do...
Definition: nfft3.h:424
double * x
nodes (in time/spatial domain)
Definition: nfft3.h:424
#define PRE_LIN_PSI
Definition: nfft3.h:195
#define PRE_PSI
Definition: nfft3.h:197
void * nfft_malloc(size_t n)
NFFT_INT N_total
Total number of Fourier coefficients.
Definition: nfft3.h:424
#define PRE_FULL_PSI
Definition: nfft3.h:198
Header file for the nfft3 library.
#define PRE_PHI_HUT
Definition: nfft3.h:193
void nnfft_init_guru(nnfft_plan *ths_plan, int d, int N_total, int M_total, int *N, int *N1, int m, unsigned nnfft_flags)
Definition: nnfft.c:577
void nnfft_finalize(nnfft_plan *ths_plan)
Definition: nnfft.c:655
#define CSWAP(x, y)
Swap two vectors.
Definition: infft.h:139