NFFT Logo 3.2.3
fastsum_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 fastsum_benchomp_createdataset(unsigned int d, int L, int M)
34 {
35  int t, j, k;
36  R *x;
37  R *y;
38  C *alpha;
39 
40  x = (R*) nfft_malloc(d*L*sizeof(R));
41  y = (R*) nfft_malloc(d*L*sizeof(R));
42  alpha = (C*) nfft_malloc(L*sizeof(C));
43 
45  k = 0;
46  while (k < L)
47  {
48  double r_max = 1.0;
49  double r2 = 0.0;
50 
51  for (j=0; j<d; j++)
52  x[k*d+j] = 2.0 * r_max * (double)rand()/(double)RAND_MAX - r_max;
53 
54  for (j=0; j<d; j++)
55  r2 += x[k*d+j] * x[k*d+j];
56 
57  if (r2 >= r_max * r_max)
58  continue;
59 
60  k++;
61  }
62 
63  nfft_vrand_unit_complex(alpha,L);
64 
66  k = 0;
67  while (k < M)
68  {
69  double r_max = 1.0;
70  double r2 = 0.0;
71 
72  for (j=0; j<d; j++)
73  y[k*d+j] = 2.0 * r_max * (double)rand()/(double)RAND_MAX - r_max;
74 
75  for (j=0; j<d; j++)
76  r2 += y[k*d+j] * y[k*d+j];
77 
78  if (r2 >= r_max * r_max)
79  continue;
80 
81  k++;
82  }
83 
84  printf("%d %d %d\n", d, L, M);
85 
86  for (j=0; j < L; j++)
87  {
88  for (t=0; t < d; t++)
89  printf("%.16e ", x[d*j+t]);
90  printf("\n");
91  }
92 
93  for (j=0; j < L; j++)
94  printf("%.16e %.16e\n", creal(alpha[j]), cimag(alpha[j]));
95 
96  for (j=0; j < M; j++)
97  {
98  for (t=0; t < d; t++)
99  printf("%.16e ", y[d*j+t]);
100  printf("\n");
101  }
102 
103  nfft_free(x);
104  nfft_free(y);
105  nfft_free(alpha);
106 }
107 
108 int main(int argc, char **argv)
109 {
110  int d;
111  int L;
112  int M;
113 
114  if (argc < 4) {
115  fprintf(stderr, "usage: d L M\n");
116  return -1;
117  }
118 
119  d = atoi(argv[1]);
120  L = atoi(argv[2]);
121  M = atoi(argv[3]);
122 
123  fprintf(stderr, "d=%d, L=%d, M=%d\n", d, L, M);
124 
125  fastsum_benchomp_createdataset(d, L, M);
126 
127  return 0;
128 }
129 

Generated on Tue Apr 30 2013 by Doxygen 1.8.1