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