NFFT  3.3.1
nfsft_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 nfsft_benchomp_createdataset(unsigned int trafo_adjoint, int N, int M)
00031 {
00032   int t, j, k, n;
00033   R *x;
00034   C *f, *f_hat;
00035   int N_total = (2*N+2) * (2*N+2);
00036   nfsft_plan ptemp;
00037 
00038   nfsft_init_guru(&ptemp, N, M, NFSFT_MALLOC_X | NFSFT_MALLOC_F |
00039     NFSFT_MALLOC_F_HAT | NFSFT_NORMALIZED | NFSFT_PRESERVE_F_HAT,
00040     PRE_PHI_HUT | PRE_PSI | FFTW_INIT | FFT_OUT_OF_PLACE, 6);
00041 
00042   x = (R*) nfft_malloc(2*M*sizeof(R));
00043   f = (C*) nfft_malloc(M*sizeof(C));
00044   f_hat = (C*) nfft_malloc(N_total*sizeof(C));
00045 
00046   /* init pseudo-random nodes */
00047   for (j = 0; j < M; j++)
00048   {
00049     x[2*j]= X(drand48)() - K(0.5);
00050     x[2*j+1]= K(0.5) * X(drand48)();
00051   }
00052  
00053   if (trafo_adjoint==0)
00054   {
00055     for (k = 0; k <= N; k++)
00056       for (n = -k; n <= k; n++)
00057         nfft_vrand_unit_complex(f_hat+NFSFT_INDEX(k,n,&ptemp),1);
00058   }
00059   else
00060   {
00061     nfft_vrand_unit_complex(f,M);
00062   }
00063 
00064   printf("%d %d %d\n", trafo_adjoint, N, M);
00065 
00066   for (j=0; j < M; j++)
00067   {
00068     for (t=0; t < 2; t++)
00069       printf("%.16e ", x[2*j+t]);
00070     printf("\n");
00071   }
00072 
00073   if (trafo_adjoint==0)
00074   {
00075     for (k = 0; k <= N; k++)
00076       for (n = -k; n <= k; n++)
00077         printf("%.16e %.16e\n", creal(f_hat[NFSFT_INDEX(k,n,&ptemp)]), cimag(f_hat[NFSFT_INDEX(k,n,&ptemp)]));
00078   }
00079   else
00080   {
00081     for (j=0; j < M; j++)
00082       printf("%.16e %.16e\n", creal(f[j]), cimag(f[j]));
00083   }
00084 
00085   nfft_free(x);
00086   nfft_free(f);
00087   nfft_free(f_hat);
00088 }
00089 
00090 int main(int argc, char **argv)
00091 {
00092   int trafo_adjoint;
00093   int N;
00094   int M;
00095 
00096   if (argc < 4) {
00097     fprintf(stderr, "usage: tr_adj N M\n");
00098     return -1;
00099   }
00100 
00101   trafo_adjoint = atoi(argv[1]);
00102   if (trafo_adjoint < 0 && trafo_adjoint > 1)
00103     trafo_adjoint = 1;
00104 
00105   N = atoi(argv[2]);
00106   M = atoi(argv[3]);
00107   fprintf(stderr, "tr_adj=%d, N=%d, M=%d\n", trafo_adjoint, N, M);
00108 
00109   nfsft_benchomp_createdataset(trafo_adjoint, N, M);
00110 
00111   return 0;
00112 }