File: accuracy.c

package info (click to toggle)
nfft 3.5.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,972 kB
  • sloc: ansic: 44,442; lisp: 1,697; makefile: 1,322; sh: 744; sed: 5
file content (102 lines) | stat: -rw-r--r-- 2,835 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Copyright (c) 2002, 2017 Jens Keiner, Stefan Kunis, Daniel Potts
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <math.h>
#include <stdlib.h>
#include <complex.h>

#include "nfft3.h"

/** Swap two vectors. */
#define CSWAP(x,y) {double _Complex * NFFT_SWAP_temp__; \
  NFFT_SWAP_temp__=(x); (x)=(y); (y)=NFFT_SWAP_temp__;}

void accuracy(int d)
{
  int m,t;
  nnfft_plan my_plan;
  double _Complex *slow;

  int N[d],n[d];
  int M_total,N_total;
  M_total=10000;N_total=1;

  slow=(double _Complex*)nfft_malloc(M_total*sizeof(double _Complex));

  for(t=0; t<d; t++)
    {
      N[t]=(1<<(12/d));
      n[t]=2*N[t];
      N_total*=N[t];
    }

  /** init a plan */
  for(m=0; m<10; m++)
    {
      nnfft_init_guru(&my_plan, d, N_total, M_total, N, n, m,
		      PRE_PSI| PRE_PHI_HUT|
		      MALLOC_X| MALLOC_V| MALLOC_F_HAT| MALLOC_F);


      /** init pseudo random nodes */
      nfft_vrand_shifted_unit_double(my_plan.x, d*my_plan.M_total);
      nfft_vrand_shifted_unit_double(my_plan.v, d*my_plan.N_total);

      /** precompute psi, the entries of the matrix B */
      if(my_plan.nnfft_flags & PRE_PSI)
      	nnfft_precompute_psi(&my_plan);

      if(my_plan.nnfft_flags & PRE_LIN_PSI)
        nnfft_precompute_lin_psi(&my_plan);

      if(my_plan.nnfft_flags & PRE_FULL_PSI)
        nnfft_precompute_full_psi(&my_plan);

      /** precompute psi, the entries of the matrix D */
      if(my_plan.nnfft_flags & PRE_PHI_HUT)
        nnfft_precompute_phi_hut(&my_plan);

      /** init pseudo random Fourier coefficients */
      nfft_vrand_unit_complex(my_plan.f_hat, my_plan.N_total);

      /** direct trafo and show the result */
      nnfft_trafo_direct(&my_plan);

      CSWAP(my_plan.f,slow);

      /** approx. trafo and show the result */
      nnfft_trafo(&my_plan);

      printf("%e, %e\n",
	     nfft_error_l_infty_complex(slow, my_plan.f, M_total),
	     nfft_error_l_infty_1_complex(slow, my_plan.f, M_total, my_plan.f_hat,
				     my_plan.N_total));

      /** finalise the one dimensional plan */
      nnfft_finalize(&my_plan);
    }
}

int main(void)
{
  int d;
  for(d=1; d<4; d++)
    accuracy(d);

  return 1;
}