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

Generated on Tue Apr 30 2013 by Doxygen 1.8.1