void nfsft_benchomp_createdataset(unsigned int trafo_adjoint, int N, int M)
{
  int t, j, k, n;
  R *x;
  C *f, *f_hat;
  int N_total = (2*N+2) * (2*N+2);
  nfsft_plan ptemp;

  nfsft_init_guru(&ptemp, N, M, NFSFT_MALLOC_X | NFSFT_MALLOC_F |
    NFSFT_MALLOC_F_HAT | NFSFT_NORMALIZED | NFSFT_PRESERVE_F_HAT,
    PRE_PHI_HUT | PRE_PSI | FFTW_INIT | FFT_OUT_OF_PLACE, 6);

  x = (R*) nfft_malloc(2*M*sizeof(R));
  f = (C*) nfft_malloc(M*sizeof(C));
  f_hat = (C*) nfft_malloc(N_total*sizeof(C));

  /* init pseudo-random nodes */
  for (j = 0; j < M; j++)
  {
    x[2*j]= X(drand48)() - K(0.5);
    x[2*j+1]= K(0.5) * X(drand48)();
  }
 
  if (trafo_adjoint==0)
  {
    for (k = 0; k <= N; k++)
      for (n = -k; n <= k; n++)
        nfft_vrand_unit_complex(f_hat+NFSFT_INDEX(k,n,&ptemp),1);
  }
  else
  {
    nfft_vrand_unit_complex(f,M);
  }

  printf("%d %d %d\n", trafo_adjoint, N, M);

  for (j=0; j < M; j++)
  {
    for (t=0; t < 2; t++)
      printf("%.16e ", x[2*j+t]);
    printf("\n");
  }

  if (trafo_adjoint==0)
  {
    for (k = 0; k <= N; k++)
      for (n = -k; n <= k; n++)
        printf("%.16e %.16e\n", creal(f_hat[NFSFT_INDEX(k,n,&ptemp)]), cimag(f_hat[NFSFT_INDEX(k,n,&ptemp)]));
  }
  else
  {
    for (j=0; j < M; j++)
      printf("%.16e %.16e\n", creal(f[j]), cimag(f[j]));
  }

  nfft_free(x);
  nfft_free(f);
  nfft_free(f_hat);
}
Beispiel #2
0
static void simple_test_nfft_1d(void)
{
  nfft_plan p;
  double t;

  int N=14;
  int M=19;
  ticks t0, t1;

  /** init an one dimensional plan */
  nfft_init_1d(&p,N,M);

  /** init pseudo random nodes */
  nfft_vrand_shifted_unit_double(p.x,p.M_total);
 
  /** precompute psi, the entries of the matrix B */
  if(p.nfft_flags & PRE_ONE_PSI)
      nfft_precompute_one_psi(&p);

  /** init pseudo random Fourier coefficients and show them */
  nfft_vrand_unit_complex(p.f_hat,p.N_total);
  nfft_vpr_complex(p.f_hat,p.N_total,"given Fourier coefficients, vector f_hat");

  /** direct trafo and show the result */
  t0 = getticks();
  nfft_trafo_direct(&p);
  t1 = getticks();
  t = nfft_elapsed_seconds(t1,t0);
  nfft_vpr_complex(p.f,p.M_total,"ndft, vector f");
  printf(" took %e seconds.\n",t);

  /** approx. trafo and show the result */
  nfft_trafo(&p);
  nfft_vpr_complex(p.f,p.M_total,"nfft, vector f");

  /** approx. adjoint and show the result */
  nfft_adjoint_direct(&p);
  nfft_vpr_complex(p.f_hat,p.N_total,"adjoint ndft, vector f_hat");

  /** approx. adjoint and show the result */
  nfft_adjoint(&p);
  nfft_vpr_complex(p.f_hat,p.N_total,"adjoint nfft, vector f_hat");

  /** finalise the one dimensional plan */
  nfft_finalize(&p);
}
void fastsum_benchomp_createdataset(unsigned int d, int L, int M)
{
  int t, j, k;
  R *x;
  R *y;
  C *alpha;

  x = (R*) nfft_malloc(d*L*sizeof(R));
  y = (R*) nfft_malloc(d*L*sizeof(R));
  alpha = (C*) nfft_malloc(L*sizeof(C));

  /** init source knots in a d-ball with radius 1 */
  k = 0;
  while (k < L)
  {
    double r_max = 1.0;
    double r2 = 0.0;

    for (j=0; j<d; j++)
      x[k*d+j] = 2.0 * r_max * (double)rand()/(double)RAND_MAX - r_max;

    for (j=0; j<d; j++)
      r2 += x[k*d+j] * x[k*d+j];

    if (r2 >= r_max * r_max)
      continue;

    k++;
  }

  nfft_vrand_unit_complex(alpha,L);

  /** init target knots in a d-ball with radius 1 */
  k = 0;
  while (k < M)
  {
    double r_max = 1.0;
    double r2 = 0.0;

    for (j=0; j<d; j++)
      y[k*d+j] = 2.0 * r_max * (double)rand()/(double)RAND_MAX - r_max;

    for (j=0; j<d; j++)
      r2 += y[k*d+j] * y[k*d+j];

    if (r2 >= r_max * r_max)
      continue;

    k++;
  }

  printf("%d %d %d\n", d, L, M);

  for (j=0; j < L; j++)
  {
    for (t=0; t < d; t++)
      printf("%.16e ", x[d*j+t]);
    printf("\n");
  }

  for (j=0; j < L; j++)
    printf("%.16e %.16e\n", creal(alpha[j]), cimag(alpha[j]));

  for (j=0; j < M; j++)
  {
    for (t=0; t < d; t++)
      printf("%.16e ", y[d*j+t]);
    printf("\n");
  }

  nfft_free(x);
  nfft_free(y);
  nfft_free(alpha);
}
Beispiel #4
0
static void simple_test_nfft_2d(void)
{
  int K,N[2],n[2],M;
  double t;
  ticks t0, t1;

  nfft_plan p;

  N[0]=32; n[0]=64;
  N[1]=14; n[1]=32;
  M=N[0]*N[1];
  K=16;

  t0 = getticks();
  /** init a two dimensional plan */
  nfft_init_guru(&p, 2, N, M, n, 7,
		 PRE_PHI_HUT| PRE_FULL_PSI| MALLOC_F_HAT| MALLOC_X| MALLOC_F |
		 FFTW_INIT| FFT_OUT_OF_PLACE,
		 FFTW_ESTIMATE| FFTW_DESTROY_INPUT);

  /** init pseudo random nodes */
  nfft_vrand_shifted_unit_double(p.x,p.d*p.M_total);

  /** precompute psi, the entries of the matrix B */
  if(p.nfft_flags & PRE_ONE_PSI)
    nfft_precompute_one_psi(&p);

  /** init pseudo random Fourier coefficients and show them */
  nfft_vrand_unit_complex(p.f_hat,p.N_total);

  t1 = getticks();
  t = nfft_elapsed_seconds(t1,t0);
  nfft_vpr_complex(p.f_hat,K,
              "given Fourier coefficients, vector f_hat (first few entries)");
  printf(" ... initialisation took %e seconds.\n",t);

  /** direct trafo and show the result */
  t0 = getticks();
  nfft_trafo_direct(&p);
  t1 = getticks();
  t = nfft_elapsed_seconds(t1,t0);
  nfft_vpr_complex(p.f,K,"ndft, vector f (first few entries)");
  printf(" took %e seconds.\n",t);

  /** approx. trafo and show the result */
  t0 = getticks();
  nfft_trafo(&p);
  t1 = getticks();
  t = nfft_elapsed_seconds(t1,t0);
  nfft_vpr_complex(p.f,K,"nfft, vector f (first few entries)");
  printf(" took %e seconds.\n",t);

  /** direct adjoint and show the result */
  t0 = getticks();
  nfft_adjoint_direct(&p);
  t1 = getticks();
  t = nfft_elapsed_seconds(t1,t0);
  nfft_vpr_complex(p.f_hat,K,"adjoint ndft, vector f_hat (first few entries)");
  printf(" took %e seconds.\n",t);

  /** approx. adjoint and show the result */
  t0 = getticks();
  nfft_adjoint(&p);
  t1 = getticks();
  t = nfft_elapsed_seconds(t1,t0);
  nfft_vpr_complex(p.f_hat,K,"adjoint nfft, vector f_hat (first few entries)");
  printf(" took %e seconds.\n",t);

  /** finalise the two dimensional plan */
  nfft_finalize(&p);
}
Beispiel #5
0
void accuracy(int d)
{
  int m,t;                         
  nnfft_plan my_plan;                   
  double complex *slow;
  
  int N[d],n[d];
  int M_total,N_total;
  M_total=10000;N_total=1;
  
  slow=(double complex*)fftw_malloc(M_total*sizeof(double complex));
  
  for(t=0; t<d; t++)
    {
      N[t]=(1<<(12/d));
      n[t]=2*N[t];
      N_total*=N[t];
    }
  
  /** init a plan */
  for(m=0; m<10; m++)
    {
      nnfft_init_guru(&my_plan, d, N_total, M_total, N, n, m,
		      PRE_PSI| PRE_PHI_HUT|
		      MALLOC_X| MALLOC_V| MALLOC_F_HAT| MALLOC_F);
      
      
      /** init pseudo random nodes */
      nfft_vrand_shifted_unit_double(my_plan.x, d*my_plan.M_total);
      nfft_vrand_shifted_unit_double(my_plan.v, d*my_plan.N_total);
      
      /** precompute psi, the entries of the matrix B */
      if(my_plan.nnfft_flags & PRE_PSI)
      	nnfft_precompute_psi(&my_plan);
      
      if(my_plan.nnfft_flags & PRE_LIN_PSI)
        nnfft_precompute_lin_psi(&my_plan);
      
      if(my_plan.nnfft_flags & PRE_FULL_PSI)
        nnfft_precompute_full_psi(&my_plan);
      
      /** precompute psi, the entries of the matrix D */ 
      if(my_plan.nnfft_flags & PRE_PHI_HUT)
        nnfft_precompute_phi_hut(&my_plan);
      
      /** init pseudo random Fourier coefficients */
      nfft_vrand_unit_complex(my_plan.f_hat, my_plan.N_total);
      
      /** direct trafo and show the result */
      nndft_trafo(&my_plan);
      
      NFFT_SWAP_complex(my_plan.f,slow);
      
      /** approx. trafo and show the result */
      nnfft_trafo(&my_plan);
      
      printf("%e, %e\n",
	     nfft_error_l_infty_complex(slow, my_plan.f, M_total),
	     nfft_error_l_infty_1_complex(slow, my_plan.f, M_total, my_plan.f_hat,
				     my_plan.N_total));
      
      /** finalise the one dimensional plan */
      nnfft_finalize(&my_plan);
    }
}
void nfft_benchomp_createdataset(unsigned int d, unsigned int trafo_adjoint, int *N, int M, double sigma)
{
  int n[d];
  int t, j;
  R *x;
  C *f, *f_hat;
  int N_total = 1;

  for (t = 0; t < d; t++)
    N_total *= N[t];

  x = (R*) nfft_malloc(d*M*sizeof(R));
  f = (C*) nfft_malloc(M*sizeof(C));
  f_hat = (C*) nfft_malloc(N_total*sizeof(C));

  for (t=0; t<d; t++)
    n[t] = sigma*nfft_next_power_of_2(N[t]);

  /** init pseudo random nodes */
  nfft_vrand_shifted_unit_double(x,d*M);
 
  if (trafo_adjoint==0)
  {
    nfft_vrand_unit_complex(f_hat,N_total);
  }
  else
  {
    nfft_vrand_unit_complex(f,M);
  }

  printf("%d %d ", d, trafo_adjoint);

  for (t=0; t<d; t++)
    printf("%d ", N[t]);

  for (t=0; t<d; t++)
    printf("%d ", n[t]);

  printf("%d\n", M);

  for (j=0; j < M; j++)
  {
    for (t=0; t < d; t++)
      printf("%.16e ", x[d*j+t]);
    printf("\n");
  }

  if (trafo_adjoint==0)
  {
    for (j=0; j < N_total; j++)
      printf("%.16e %.16e\n", creal(f_hat[j]), cimag(f_hat[j]));
  }
  else
  {
    for (j=0; j < M; j++)
      printf("%.16e %.16e\n", creal(f[j]), cimag(f[j]));
  }

  nfft_free(x);
  nfft_free(f);
  nfft_free(f_hat);
}