| NFFT 3.5.0

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

solver/simple_test.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 <stdio.h>
20 #include <math.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <complex.h>
24
25 #define NFFT_PRECISION_DOUBLE
26
27 #include "nfft3mp.h"
28
29 /* void simple_test_infft_1d(int N, int M, int iter) */
30 /* { */
31 /* int k,l; /\**< index for nodes, freqencies,iter*\/ */
32 /* nfft_plan p; /\**< plan for the nfft *\/ */
33 /* infft_plan ip; /\**< plan for the inverse nfft *\/ */
34
35 /* /\** initialise an one dimensional plan *\/ */
36 /* nfft_init_1d(&p, N, M); */
37
38 /* /\** init pseudo random nodes *\/ */
39 /* nfft_vrand_shifted_unit_double(p.x,p.M_total); */
40
41 /* /\** precompute psi, the entries of the matrix B *\/ */
42 /* if(p.flags & PRE_ONE_PSI) */
43 /* nfft_precompute_one_psi(&p); */
44
45 /* /\** initialise inverse plan *\/ */
46 /* infft_init(&ip,&p); */
47
48 /* /\** init pseudo random samples and show them *\/ */
49 /* nfft_vrand_unit_complex(ip.y,p.M_total); */
50 /* nfft_vpr_complex(ip.y,p.M_total,"Given data, vector y"); */
51
52 /* /\** initialise some guess f_hat_0 and solve *\/ */
53 /* for(k=0;k<p.N_total;k++) */
54 /* ip.f_hat_iter[k]=0; */
55
56 /* nfft_vpr_complex(ip.f_hat_iter,p.N_total,"Initial guess, vector f_hat_iter"); */
57
58 /* CSWAP(ip.f_hat_iter,p.f_hat); */
59 /* nfft_trafo(&p); */
60 /* nfft_vpr_complex(p.f,p.M_total,"Data fit, vector f"); */
61 /* CSWAP(ip.f_hat_iter,p.f_hat); */
62
63 /* infft_before_loop(&ip); */
64 /* printf("\n Residual r=%e\n",ip.dot_r_iter); */
65
66 /* for(l=0;l<iter;l++) */
67 /* { */
68 /* printf("\n********** Iteration l=%d **********\n",l); */
69 /* infft_loop_one_step(&ip); */
70 /* nfft_vpr_complex(ip.f_hat_iter,p.N_total, */
71 /* "Approximate solution, vector f_hat_iter"); */
72
73 /* CSWAP(ip.f_hat_iter,p.f_hat); */
74 /* nfft_trafo(&p); */
75 /* nfft_vpr_complex(p.f,p.M_total,"Data fit, vector f"); */
76 /* CSWAP(ip.f_hat_iter,p.f_hat); */
77
78 /* printf("\n Residual r=%e\n",ip.dot_r_iter); */
79 /* } */
80
81 /* infft_finalize(&ip); */
82 /* nfft_finalize(&p); */
83 /* } */
84
86 static void simple_test_solver_nfft_1d(int N, int M, int iter)
87 {
88 int k, l;
89 NFFT(plan) p;
90 SOLVER(plan_complex) ip;
91 const char *error_str;
92
94 NFFT(init_1d)(&p, N, M);
95
97 NFFT(vrand_shifted_unit_double)(p.x, p.M_total);
98
100 if (p.flags & PRE_ONE_PSI)
101 NFFT(precompute_one_psi)(&p);
102
104 SOLVER(init_complex)(&ip, (NFFT(mv_plan_complex)*) (&p));
105
107 NFFT(vrand_unit_complex)(ip.y, p.M_total);
108 NFFT(vpr_complex)(ip.y, p.M_total, "Given data, vector y");
109
111 for (k = 0; k < p.N_total; k++)
112 ip.f_hat_iter[k] = NFFT_K(0.0);
113
114 NFFT(vpr_complex)(ip.f_hat_iter, p.N_total,
115 "Initial guess, vector f_hat_iter");
116
118 error_str = NFFT(check)(&p);
119 if (error_str != 0)
120 {
121 printf("Error in nfft module: %s\n", error_str);
122 return;
123 }
124
125 NFFT_CSWAP(ip.f_hat_iter, p.f_hat);
126 NFFT(trafo)(&p);
127 NFFT(vpr_complex)(p.f, p.M_total, "Data fit, vector f");
128 NFFT_CSWAP(ip.f_hat_iter, p.f_hat);
129
130 SOLVER(before_loop_complex)(&ip);
131 printf("\n Residual r=%" NFFT__FES__ "\n", ip.dot_r_iter);
132
133 for (l = 0; l < iter; l++)
134 {
135 printf("\n********** Iteration l=%d **********\n", l);
136 SOLVER(loop_one_step_complex)(&ip);
137 NFFT(vpr_complex)(ip.f_hat_iter, p.N_total,
138 "Approximate solution, vector f_hat_iter");
139
140 NFFT_CSWAP(ip.f_hat_iter, p.f_hat);
141 NFFT(trafo)(&p);
142 NFFT(vpr_complex)(p.f, p.M_total, "Data fit, vector f");
143 NFFT_CSWAP(ip.f_hat_iter, p.f_hat);
144
145 printf("\n Residual r=%" NFFT__FES__ "\n", ip.dot_r_iter);
146 }
147
148 SOLVER(finalize_complex)(&ip);
149 NFFT(finalize)(&p);
150 }
151
153 int main(void)
154 {
155 printf("\n Computing a one dimensional inverse nfft\n");
156
157 simple_test_solver_nfft_1d(16, 8, 9);
158
159 return EXIT_SUCCESS;
160 }
161 /* \} */
PRE_ONE_PSI
#define PRE_ONE_PSI
Definition: nfft3.h:206