nnfft/simple_test.c
/*
* Copyright (c) 2002, 2017 Jens Keiner, Stefan Kunis, Daniel Potts
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdlib.h>
#include <math.h>
#include <complex.h>
#include "nfft3.h"
#define CSWAP(x,y) {double _Complex * NFFT_SWAP_temp__; \
NFFT_SWAP_temp__=(x); (x)=(y); (y)=NFFT_SWAP_temp__;}
void simple_test_nnfft_1d(void)
{
int j,k;
nnfft_plan my_plan;
int N[1];
N[0]=10;
nnfft_init(&my_plan, 1, 3, 19, N);
for(j=0;j<my_plan.M_total;j++)
{
my_plan.x[j]=((double)rand())/((double)RAND_MAX)-0.5;
}
for(j=0;j<my_plan.N_total;j++)
{
my_plan.v[j]=((double)rand())/((double)RAND_MAX)-0.5;
}
/* 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);
/* if(my_plan.nnfft_flags & PRE_PHI_HUT)
nnfft_precompute_phi_hut(&my_plan);
*/
nnfft_precompute_one_psi(&my_plan);
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,my_plan.N_total,"given Fourier coefficients, vector f_hat");
nnfft_trafo_direct(&my_plan);
nfft_vpr_complex(my_plan.f,my_plan.M_total,"nndft, vector f");
nnfft_trafo(&my_plan);
nfft_vpr_complex(my_plan.f,my_plan.M_total,"nnfft, vector f");
nnfft_finalize(&my_plan);
}
static void simple_test_adjoint_nnfft_1d(void)
{
int j;
nnfft_plan my_plan;
int N[1];
N[0]=12;
nnfft_init(&my_plan, 1, 20, 33, N);
for(j=0;j<my_plan.M_total;j++)
{
my_plan.x[j]=((double)rand())/((double)RAND_MAX)-0.5;
}
for(j=0;j<my_plan.N_total;j++)
{
my_plan.v[j]=((double)rand())/((double)RAND_MAX)-0.5;
}
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);
if(my_plan.nnfft_flags & PRE_PHI_HUT)
nnfft_precompute_phi_hut(&my_plan);
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");
nnfft_adjoint_direct(&my_plan);
nfft_vpr_complex(my_plan.f_hat,my_plan.N_total,"adjoint nndft, vector f_hat");
nnfft_adjoint(&my_plan);
nfft_vpr_complex(my_plan.f_hat,my_plan.N_total,"adjoint nnfft, vector f_hat");
nnfft_finalize(&my_plan);
}
static void simple_test_nnfft_2d(void)
{
int j,k;
nnfft_plan my_plan;
int N[2];
N[0]=12;
N[1]=14;
nnfft_init(&my_plan, 2,12*14,19, N);
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;
}
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;
}
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);
if(my_plan.nnfft_flags & PRE_PHI_HUT)
nnfft_precompute_phi_hut(&my_plan);
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)");
nnfft_trafo_direct(&my_plan);
nfft_vpr_complex(my_plan.f,my_plan.M_total,"ndft, vector f");
nnfft_trafo(&my_plan);
nfft_vpr_complex(my_plan.f,my_plan.M_total,"nfft, vector f");
nnfft_finalize(&my_plan);
}
static void simple_test_innfft_1d(void)
{
int j,k,l,N=8;
nnfft_plan my_plan;
solver_plan_complex my_iplan;
nnfft_init(&my_plan,1 ,8 ,8 ,&N);
solver_init_advanced_complex(&my_iplan,(nfft_mv_plan_complex*)(&my_plan),CGNR);
for(j=0;j<my_plan.M_total;j++)
my_plan.x[j]=((double)rand())/((double)RAND_MAX)-0.5;
for(k=0;k<my_plan.N_total;k++)
my_plan.v[k]=((double)rand())/((double)RAND_MAX)-0.5;
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_PHI_HUT)
nnfft_precompute_phi_hut(&my_plan);
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");
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");
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);
}
static void measure_time_nnfft_1d(void)
{
int j,k;
nnfft_plan my_plan;
int my_N,N=4;
double t;
double t0, t1;
for(my_N=16; my_N<=16384; my_N*=2)
{
nnfft_init(&my_plan,1,my_N,my_N,&N);
for(j=0;j<my_plan.M_total;j++)
my_plan.x[j]=((double)rand())/((double)RAND_MAX)-0.5;
for(j=0;j<my_plan.N_total;j++)
my_plan.v[j]=((double)rand())/((double)RAND_MAX)-0.5;
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_PHI_HUT)
nnfft_precompute_phi_hut(&my_plan);
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);
t0 = nfft_clock_gettime_seconds();
nnfft_trafo_direct(&my_plan);
t1 = nfft_clock_gettime_seconds();
t = t1 - t0;
printf("t_nndft=%e,\t",t);
t0 = nfft_clock_gettime_seconds();
nnfft_trafo(&my_plan);
t1 = nfft_clock_gettime_seconds();
t = t1 - t0;
printf("t_nnfft=%e\t",t);
printf("(N=M=%d)\n",my_N);
nnfft_finalize(&my_plan);
}
}
int main(void)
{
system("clear");
printf("1) computing a one dimensional nndft, nnfft\n\n");
simple_test_nnfft_1d();
/*getc(stdin);
system("clear");
printf("1a) computing a one dimensional adjoint nndft, nnfft\n\n");
simple_test_adjoint_nnfft_1d();
getc(stdin);
system("clear");
printf("2) computing a two dimensional nndft, nnfft\n\n");
simple_test_nnfft_2d();
getc(stdin);
system("clear");
printf("3) computing a one dimensional innfft\n\n");
simple_test_innfft_1d();
getc(stdin);
system("clear");
printf("4) computing times for one dimensional nnfft\n\n");
measure_time_nnfft_1d();
*/
return 1;
}
PRE_FULL_PSI
#define PRE_FULL_PSI
Definition nfft3.h:186
PRE_PSI
#define PRE_PSI
Definition nfft3.h:185
PRE_LIN_PSI
#define PRE_LIN_PSI
Definition nfft3.h:183
PRE_PHI_HUT
#define PRE_PHI_HUT
Definition nfft3.h:181
CSWAP
#define CSWAP(x, y)
Swap two vectors.
Definition infft.h:139
nnfft_init
void nnfft_init(nnfft_plan *ths_plan, int d, int N_total, int M_total, int *N)
Definition nnfft.c:613
nnfft_precompute_lin_psi
void nnfft_precompute_lin_psi(nnfft_plan *ths_plan)
create a lookup table
Definition nnfft.c:367
nnfft_precompute_full_psi
void nnfft_precompute_full_psi(nnfft_plan *ths_plan)
computes all entries of B explicitly
Definition nnfft.c:424
nnfft_precompute_psi
void nnfft_precompute_psi(nnfft_plan *ths_plan)
Definition nnfft.c:385
nnfft_trafo
void nnfft_trafo(nnfft_plan *ths_plan)
user routines
Definition nnfft.c:291
nnfft_finalize
void nnfft_finalize(nnfft_plan *ths_plan)
Definition nnfft.c:657
nnfft_precompute_phi_hut
void nnfft_precompute_phi_hut(nnfft_plan *ths_plan)
initialisation of direct transform
Definition nnfft.c:347
nnfft_adjoint
void nnfft_adjoint(nnfft_plan *ths_plan)
Definition nnfft.c:319
CGNR
#define CGNR
Definition nfft3.h:802
nfft3.h
Header file for the nfft3 library.
nfft_vpr_complex
void nfft_vpr_complex(fftw_complex *x, const NFFT_INT n, const char *text)
Print complex vector to standard output.
nfft_mv_plan_complex
Definition nfft3.h:177
nnfft_plan
data structure for an NNFFT (nonequispaced in time and frequency fast Fourier transform) plan with do...
Definition nfft3.h:419
nnfft_plan::v
double * v
nodes (in fourier domain)
Definition nfft3.h:419
nnfft_plan::M_total
NFFT_INT M_total
Total number of samples.
Definition nfft3.h:419
nnfft_plan::nnfft_flags
unsigned nnfft_flags
flags for precomputation, malloc
Definition nfft3.h:419
nnfft_plan::N_total
NFFT_INT N_total
Total number of Fourier coefficients.
Definition nfft3.h:419
nnfft_plan::f
fftw_complex * f
Samples.
Definition nfft3.h:419
nnfft_plan::f_hat
fftw_complex * f_hat
Fourier coefficients.
Definition nfft3.h:419
nnfft_plan::x
double * x
nodes (in time/spatial domain)
Definition nfft3.h:419
solver_plan_complex
data structure for an inverse NFFT plan with double precision
Definition nfft3.h:796
solver_plan_complex::y
fftw_complex * y
right hand side, samples
Definition nfft3.h:796
solver_plan_complex::f_hat_iter
fftw_complex * f_hat_iter
iterative solution
Definition nfft3.h:796