/** * Simple example that computes fast and discrete Gauss transforms. * * \arg ths The pointer to the fgt plan * \arg sigma The parameter of the Gaussian * \arg eps The target accuracy * * \author Stefan Kunis */ void fgt_test_simple(int N, int M, double _Complex sigma, double eps) { fgt_plan my_plan; double _Complex *swap_dgt; fgt_init(&my_plan, N, M, sigma, eps); swap_dgt = (double _Complex*)nfft_malloc(my_plan.M*sizeof(double _Complex)); fgt_test_init_rand(&my_plan); fgt_init_node_dependent(&my_plan); NFFT_SWAP_complex(swap_dgt,my_plan.f); dgt_trafo(&my_plan); nfft_vpr_complex(my_plan.f,my_plan.M,"discrete gauss transform"); NFFT_SWAP_complex(swap_dgt,my_plan.f); fgt_trafo(&my_plan); nfft_vpr_complex(my_plan.f,my_plan.M,"fast gauss transform"); printf("\n relative error: %1.3e\n", X(error_l_infty_1_complex)(swap_dgt, my_plan.f, my_plan.M, my_plan.alpha, my_plan.N)); nfft_free(swap_dgt); fgt_finalize(&my_plan); }
static void simple_test_nsfft(int d, int J, int M) { int K=12; nsfft_plan p; nsfft_init(&p, d, J, M, 6, NSDFT); nsfft_init_random_nodes_coeffs(&p); nfft_vpr_complex(p.f_hat, K, "frequencies, vector f_hat (first few entries)"); /** direct trafo and show the result */ nsfft_trafo_direct(&p); nfft_vpr_complex(p.f, K, "nsdft, vector f (first few entries)"); /** approx. trafo and show the result */ nsfft_trafo(&p); nfft_vpr_complex(p.f, K, "nsfft, vector f (first few entries)"); /** direct adjoint and show the result */ nsfft_adjoint_direct(&p); nfft_vpr_complex(p.f_hat, K, "adjoint nsdft, vector f_hat, (first few entries)"); /** approx. adjoint and show the result */ nsfft_adjoint(&p); nfft_vpr_complex(p.f_hat, K, "adjoint nsfft, vector f_hat, (first few entries)"); /** finalise the one dimensional plan */ nsfft_finalize(&p); }
static void simple_test_nnfft_2d(void) { int j,k; /**< index for nodes and freqencies */ nnfft_plan my_plan; /**< plan for the nfft */ int N[2]; N[0]=12; N[1]=14; /** init an one dimensional plan */ nnfft_init(&my_plan, 2,12*14,19, N); /** init pseudo random nodes */ for(j=0;j<my_plan.M_total;j++) { my_plan.x[2*j]=((double)rand())/((double)RAND_MAX)-0.5; my_plan.x[2*j+1]=((double)rand())/((double)RAND_MAX)-0.5; } /** init pseudo random nodes */ for(j=0;j<my_plan.N_total;j++) { my_plan.v[2*j]=((double)rand())/((double)RAND_MAX)-0.5; my_plan.v[2*j+1]=((double)rand())/((double)RAND_MAX)-0.5; } /** 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_FULL_PSI) nnfft_precompute_full_psi(&my_plan); if(my_plan.nnfft_flags & PRE_LIN_PSI) nnfft_precompute_lin_psi(&my_plan); /** precompute phi_hut, 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 and show them */ for(k=0;k<my_plan.N_total;k++) my_plan.f_hat[k] = ((double)rand())/((double)RAND_MAX) + _Complex_I*((double)rand())/((double)RAND_MAX); nfft_vpr_complex(my_plan.f_hat,12, "given Fourier coefficients, vector f_hat (first 12 entries)"); /** direct trafo and show the result */ nnfft_trafo_direct(&my_plan); nfft_vpr_complex(my_plan.f,my_plan.M_total,"ndft, vector f"); /** approx. trafo and show the result */ nnfft_trafo(&my_plan); nfft_vpr_complex(my_plan.f,my_plan.M_total,"nfft, vector f"); /** finalise the one dimensional plan */ nnfft_finalize(&my_plan); }
static void simple_test_adjoint_nnfft_1d(void) { int j; /**< index for nodes and freqencies */ nnfft_plan my_plan; /**< plan for the nfft */ int N[1]; N[0]=12; /** init an one dimensional plan */ nnfft_init(&my_plan, 1, 20, 33, N); /** init pseudo random nodes */ for(j=0;j<my_plan.M_total;j++) { my_plan.x[j]=((double)rand())/((double)RAND_MAX)-0.5; } /** init pseudo random nodes */ for(j=0;j<my_plan.N_total;j++) { my_plan.v[j]=((double)rand())/((double)RAND_MAX)-0.5; } /** 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_FULL_PSI) nnfft_precompute_full_psi(&my_plan); if(my_plan.nnfft_flags & PRE_LIN_PSI) nnfft_precompute_lin_psi(&my_plan); /** precompute phi_hut, 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 and show them */ for(j=0;j<my_plan.M_total;j++) my_plan.f[j] = ((double)rand())/((double)RAND_MAX) + _Complex_I*((double)rand())/((double)RAND_MAX); nfft_vpr_complex(my_plan.f,my_plan.M_total,"given Samples, vector f"); /** direct trafo and show the result */ nnfft_adjoint_direct(&my_plan); nfft_vpr_complex(my_plan.f_hat,my_plan.N_total,"adjoint nndft, vector f_hat"); /** approx. trafo and show the result */ nnfft_adjoint(&my_plan); nfft_vpr_complex(my_plan.f_hat,my_plan.N_total,"adjoint nnfft, vector f_hat"); /** finalise the one dimensional plan */ nnfft_finalize(&my_plan); }
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); }
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); }
static void simple_test_innfft_1d(void) { int j,k,l,N=8; /**< index for nodes, freqencies, iter*/ nnfft_plan my_plan; /**< plan for the nnfft */ solver_plan_complex my_iplan; /**< plan for the inverse nnfft */ /** initialise an one dimensional plan */ nnfft_init(&my_plan,1 ,8 ,8 ,&N); /** initialise my_iplan */ solver_init_advanced_complex(&my_iplan,(nfft_mv_plan_complex*)(&my_plan),CGNR); /** init pseudo random nodes */ for(j=0;j<my_plan.M_total;j++) my_plan.x[j]=((double)rand())/((double)RAND_MAX)-0.5; /** init pseudo random nodes */ for(k=0;k<my_plan.N_total;k++) my_plan.v[k]=((double)rand())/((double)RAND_MAX)-0.5; /** 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_FULL_PSI) nnfft_precompute_full_psi(&my_plan); /** precompute phi_hut, the entries of the matrix D */ if(my_plan.nnfft_flags & PRE_PHI_HUT) nnfft_precompute_phi_hut(&my_plan); /** init pseudo random samples (real) and show them */ for(j=0;j<my_plan.M_total;j++) my_iplan.y[j] = ((double)rand())/((double)RAND_MAX); nfft_vpr_complex(my_iplan.y,my_plan.M_total,"given data, vector given_f"); /** initialise some guess f_hat_0 */ for(k=0;k<my_plan.N_total;k++) my_iplan.f_hat_iter[k] = 0.0; nfft_vpr_complex(my_iplan.f_hat_iter,my_plan.N_total, "approximate solution, vector f_hat_iter"); /** solve the system */ solver_before_loop_complex(&my_iplan); for(l=0;l<8;l++) { printf("iteration l=%d\n",l); solver_loop_one_step_complex(&my_iplan); nfft_vpr_complex(my_iplan.f_hat_iter,my_plan.N_total, "approximate solution, vector f_hat_iter"); CSWAP(my_iplan.f_hat_iter,my_plan.f_hat); nnfft_trafo(&my_plan); nfft_vpr_complex(my_plan.f,my_plan.M_total,"fitting the data, vector f"); CSWAP(my_iplan.f_hat_iter,my_plan.f_hat); } solver_finalize_complex(&my_iplan); nnfft_finalize(&my_plan); }