NFFT  3.3.2
fastsum_benchomp_createdataset.c
00001 /*
00002  * Copyright (c) 2002, 2016 Jens Keiner, Stefan Kunis, Daniel Potts
00003  *
00004  * This program is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU General Public License along with
00015  * this program; if not, write to the Free Software Foundation, Inc., 51
00016  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include <stdio.h>
00020 #include <math.h>
00021 #include <string.h>
00022 #include <stdlib.h>
00023 #include <complex.h>
00024 
00025 #include "config.h"
00026 
00027 #include "nfft3.h"
00028 #include "infft.h"
00029 
00030 void fastsum_benchomp_createdataset(unsigned int d, int L, int M)
00031 {
00032   int t, j, k;
00033   R *x;
00034   R *y;
00035   C *alpha;
00036 
00037   x = (R*) NFFT(malloc)((size_t)(d * L) * sizeof(R));
00038   y = (R*) NFFT(malloc)((size_t)(d * L) * sizeof(R));
00039   alpha = (C*) NFFT(malloc)((size_t)(L) * sizeof(C));
00040 
00042   k = 0;
00043   while (k < L)
00044   {
00045     R r_max = K(1.0);
00046     R r2 = K(0.0);
00047 
00048     for (j = 0; j < d; j++)
00049       x[k * d + j] = K(2.0) * r_max * NFFT(drand48)() - r_max;
00050 
00051     for (j = 0; j < d; j++)
00052       r2 += x[k * d + j] * x[k * d + j];
00053 
00054     if (r2 >= r_max * r_max)
00055       continue;
00056 
00057     k++;
00058   }
00059 
00060   NFFT(vrand_unit_complex)(alpha, L);
00061 
00063   k = 0;
00064   while (k < M)
00065   {
00066     R r_max = K(1.0);
00067     R r2 = K(0.0);
00068 
00069     for (j = 0; j < d; j++)
00070       y[k * d + j] = K(2.0) * r_max * NFFT(drand48)() - r_max;
00071 
00072     for (j = 0; j < d; j++)
00073       r2 += y[k * d + j] * y[k * d + j];
00074 
00075     if (r2 >= r_max * r_max)
00076       continue;
00077 
00078     k++;
00079   }
00080 
00081   printf("%d %d %d\n", d, L, M);
00082 
00083   for (j = 0; j < L; j++)
00084   {
00085     for (t = 0; t < d; t++)
00086       printf("%.16" __FES__ " ", x[d * j + t]);
00087     printf("\n");
00088   }
00089 
00090   for (j = 0; j < L; j++)
00091     printf("%.16" __FES__ " %.16" __FES__ "\n", CREAL(alpha[j]), CIMAG(alpha[j]));
00092 
00093   for (j = 0; j < M; j++)
00094   {
00095     for (t = 0; t < d; t++)
00096       printf("%.16" __FES__ " ", y[d * j + t]);
00097     printf("\n");
00098   }
00099 
00100   NFFT(free)(x);
00101   NFFT(free)(y);
00102   NFFT(free)(alpha);
00103 }
00104 
00105 int main(int argc, char **argv)
00106 {
00107   int d;
00108   int L;
00109   int M;
00110 
00111   if (argc < 4)
00112   {
00113     fprintf(stderr, "usage: d L M\n");
00114     return -1;
00115   }
00116 
00117   d = atoi(argv[1]);
00118   L = atoi(argv[2]);
00119   M = atoi(argv[3]);
00120 
00121   fprintf(stderr, "d=%d, L=%d, M=%d\n", d, L, M);
00122 
00123   fastsum_benchomp_createdataset(d, L, M);
00124 
00125   return 0;
00126 }
00127