NFFT  3.4.1
nfft_benchomp_createdataset.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 #include "config.h"
26 
27 #include "nfft3.h"
28 #include "infft.h"
29 
30 void nfft_benchomp_createdataset(unsigned int d, unsigned int trafo_adjoint, int *N, int M, double sigma)
31 {
32  int n[d];
33  int t, j;
34  R *x;
35  C *f, *f_hat;
36  int N_total = 1;
37 
38  for (t = 0; t < d; t++)
39  N_total *= N[t];
40 
41  x = (R*) NFFT(malloc)(d*M*sizeof(R));
42  f = (C*) NFFT(malloc)(M*sizeof(C));
43  f_hat = (C*) NFFT(malloc)(N_total*sizeof(C));
44 
45  for (t=0; t<d; t++)
46  n[t] = sigma*NFFT(next_power_of_2)(N[t]);
47 
49  NFFT(vrand_shifted_unit_double)(x,d*M);
50 
51  if (trafo_adjoint==0)
52  {
53  NFFT(vrand_unit_complex)(f_hat,N_total);
54  }
55  else
56  {
57  NFFT(vrand_unit_complex)(f,M);
58  }
59 
60  printf("%d %d ", d, trafo_adjoint);
61 
62  for (t=0; t<d; t++)
63  printf("%d ", N[t]);
64 
65  for (t=0; t<d; t++)
66  printf("%d ", n[t]);
67 
68  printf("%d\n", M);
69 
70  for (j=0; j < M; j++)
71  {
72  for (t=0; t < d; t++)
73  printf("%.16e ", x[d*j+t]);
74  printf("\n");
75  }
76 
77  if (trafo_adjoint==0)
78  {
79  for (j=0; j < N_total; j++)
80  printf("%.16e %.16e\n", creal(f_hat[j]), cimag(f_hat[j]));
81  }
82  else
83  {
84  for (j=0; j < M; j++)
85  printf("%.16e %.16e\n", creal(f[j]), cimag(f[j]));
86  }
87 
88  NFFT(free)(x);
89  NFFT(free)(f);
90  NFFT(free)(f_hat);
91 }
92 
93 int main(int argc, char **argv)
94 {
95  int d;
96  int *N;
97  int M;
98  int t;
99  int trafo_adjoint;
100  double sigma;
101 
102  if (argc < 6) {
103  fprintf(stderr, "usage: d tr_adj N_1 ... N_d M sigma\n");
104  return -1;
105  }
106 
107  d = atoi(argv[1]);
108 
109  fprintf(stderr, "d=%d", d);
110 
111  if (d < 1 || argc < 5+d) {
112  fprintf(stderr, "usage: d tr_adj N_1 ... N_d M sigma\n");
113  return -1;
114  }
115 
116  N = malloc(d*sizeof(int));
117 
118  trafo_adjoint = atoi(argv[2]);
119  if (trafo_adjoint < 0 && trafo_adjoint > 1)
120  trafo_adjoint = 1;
121 
122  fprintf(stderr, ", tr_adj=%d, N=", trafo_adjoint);
123 
124  for (t=0; t<d; t++)
125  N[t] = atoi(argv[3+t]);
126 
127  for (t=0; t<d; t++)
128  fprintf(stderr, "%d ",N[t]);
129 
130 
131  M = atoi(argv[3+d]);
132  sigma = atof(argv[4+d]);
133 
134  fprintf(stderr, ", M=%d, sigma=%.16g\n", M, sigma);
135 
136  nfft_benchomp_createdataset(d, trafo_adjoint, N, M, sigma);
137 
138  free(N);
139 
140  return 0;
141 }
Header file for the nfft3 library.