NFFT Logo 3.2.2
fastsum_benchomp_createdataset.c
00001 /*
00002  * Copyright (c) 2002, 2012 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 /* $Id: simple_test.c 3372 2009-10-21 06:04:05Z skunis $ */
00020 
00021 #include <stdio.h>
00022 #include <math.h>
00023 #include <string.h>
00024 #include <stdlib.h>
00025 #include <complex.h>
00026 
00027 #include "config.h"
00028 
00029 #include "nfft3util.h"
00030 #include "nfft3.h"
00031 #include "infft.h"
00032 
00033 void fastsum_benchomp_createdataset(unsigned int d, int L, int M)
00034 {
00035   int t, j, k;
00036   R *x;
00037   R *y;
00038   C *alpha;
00039 
00040   x = (R*) nfft_malloc(d*L*sizeof(R));
00041   y = (R*) nfft_malloc(d*L*sizeof(R));
00042   alpha = (C*) nfft_malloc(L*sizeof(C));
00043 
00045   k = 0;
00046   while (k < L)
00047   {
00048     double r_max = 1.0;
00049     double r2 = 0.0;
00050 
00051     for (j=0; j<d; j++)
00052       x[k*d+j] = 2.0 * r_max * (double)rand()/(double)RAND_MAX - r_max;
00053 
00054     for (j=0; j<d; j++)
00055       r2 += x[k*d+j] * x[k*d+j];
00056 
00057     if (r2 >= r_max * r_max)
00058       continue;
00059 
00060     k++;
00061   }
00062 
00063   nfft_vrand_unit_complex(alpha,L);
00064 
00066   k = 0;
00067   while (k < M)
00068   {
00069     double r_max = 1.0;
00070     double r2 = 0.0;
00071 
00072     for (j=0; j<d; j++)
00073       y[k*d+j] = 2.0 * r_max * (double)rand()/(double)RAND_MAX - r_max;
00074 
00075     for (j=0; j<d; j++)
00076       r2 += y[k*d+j] * y[k*d+j];
00077 
00078     if (r2 >= r_max * r_max)
00079       continue;
00080 
00081     k++;
00082   }
00083 
00084   printf("%d %d %d\n", d, L, M);
00085 
00086   for (j=0; j < L; j++)
00087   {
00088     for (t=0; t < d; t++)
00089       printf("%.16e ", x[d*j+t]);
00090     printf("\n");
00091   }
00092 
00093   for (j=0; j < L; j++)
00094     printf("%.16e %.16e\n", creal(alpha[j]), cimag(alpha[j]));
00095 
00096   for (j=0; j < M; j++)
00097   {
00098     for (t=0; t < d; t++)
00099       printf("%.16e ", y[d*j+t]);
00100     printf("\n");
00101   }
00102 
00103   nfft_free(x);
00104   nfft_free(y);
00105   nfft_free(alpha);
00106 }
00107 
00108 int main(int argc, char **argv)
00109 {
00110   int d;
00111   int L;
00112   int M;
00113 
00114   if (argc < 4) {
00115     fprintf(stderr, "usage: d L M\n");
00116     return -1;
00117   }
00118 
00119   d = atoi(argv[1]);
00120   L = atoi(argv[2]);
00121   M = atoi(argv[3]);
00122 
00123   fprintf(stderr, "d=%d, L=%d, M=%d\n", d, L, M);
00124 
00125   fastsum_benchomp_createdataset(d, L, M);
00126 
00127   return 0;
00128 }
00129 

Generated on Fri Oct 12 2012 by Doxygen 1.8.0-20120409