16 #define MAX(a,b) ((a) > (b) ? (a) : (b))
18 double maxerr_cplx(complex
double *a, complex
double *b,
int size)
22 for(i = 0; i<size; i++){
24 value =
MAX( cabs( a[i]-b[i] ), value );
29 double maxerr(
double *a,
double *b,
int size)
33 for(i = 0; i<size; i++){
34 value =
MAX( abs( a[i]-b[i] ), value );
41 int IM1=2147483563,IM2=2147483399,IMM1=IM1-1,
42 IA1=40014,IA2=40692,IQ1=53668,IQ2=52774,IR1=12211,IR2=3791,
43 NTAB=32,NDIV=1+IMM1/NTAB;
45 double AM=1./IM1,EPS=1.2e-7,RNMX=1.-EPS;
47 static int iv[32],iy,idum2 = 123456789;
51 idum= (-idum>1 ? -idum : 1);
53 for(j=NTAB+8;j>=1;j--) {
55 idum=IA1*(idum-k*IQ1)-k*IR1;
56 if (idum < 0) idum=idum+IM1;
57 if (j < NTAB) iv[j-1]=idum;
62 idum=IA1*(idum-k*IQ1)-k*IR1;
63 if (idum < 0) idum=idum+IM1;
65 idum2=IA2*(idum2-k*IQ2)-k*IR2;
66 if (idum2 < 0) idum2=idum2+IM2;
71 return (AM*iy < RNMX ? AM*iy : RNMX);
89 flmn[i] = (2.0*
ran2_dp(seed) - 1.0) + I * (2.0*
ran2_dp(seed) - 1.0);
95 int en, el, m, msign, i, i_op, offset;
98 for (en=0; en<N; en++) {
99 offset = en * flmsize;
100 for (el=0; el<L; el++) {
102 ssht_sampling_elm2ind(&i, el, m);
103 flmn[offset+i] = (2.0*
ran2_dp(seed) - 1.0);
104 for (m=1; m<=el; m++) {
105 ssht_sampling_elm2ind(&i, el, m);
106 flmn[offset+i] = (2.0*
ran2_dp(seed) - 1.0) + I * (2.0*
ran2_dp(seed) - 1.0);
107 ssht_sampling_elm2ind(&i_op, el, -m);
109 msign = 1 - msign - msign;
110 flmn[offset+i_op] = msign * conj(flmn[offset+i]);
116 void print_f(
const complex
double *f,
int L,
int N)
118 int mapsize = (2*L-1)*L;
121 printf(
"\n -- Layer %i -- \n", n);
122 for(j=0;j<mapsize;j++){
123 printf(
" (%f,%f) ",creal(f[n*mapsize+j]),cimag(f[n*mapsize+j]));
131 int mapsize = (2*L-1)*L;
134 printf(
"\n -- Layer %i -- \n", n);
135 for(j=0;j<mapsize;j++){
136 printf(
" %f ",(f[n*mapsize+j]));
147 printf(
"\n -- Layer %i -- \n", n);
148 for(j=0;j<mapsize;j++){
149 printf(
" (%f,%f) ",creal(flmn[n*mapsize+j]),cimag(flmn[n*mapsize+j]));
158 double *rs, *thetas, *phis, *laguweights;
172 double *roots = (
double*)calloc(N,
sizeof(
double));
173 double *weights = (
double*)calloc(N,
sizeof(
double));
174 const int alpha =
ALPHA;
185 const double R = 1.0;
187 const int alpha =
ALPHA;
189 double *roots = (
double*)calloc(N,
sizeof(
double));
190 double *weights = (
double*)calloc(N,
sizeof(
double));
192 double tau_bis = R / roots[N-1];
200 assert(cabs(tau_bis-tau) < 1e-14);
205 double *nodes = (
double*)calloc(N,
sizeof(
double));
206 double *weights = (
double*)calloc(N,
sizeof(
double));
209 assert(nodes != NULL);
210 assert(weights != NULL);
220 clock_t time_start, time_end;
221 complex
double *f, *fn, *fn_rec;
230 double *nodes = (
double*)calloc(N,
sizeof(
double));
231 double *weights = (
double*)calloc(N,
sizeof(
double));
235 time_start = clock();
238 printf(
" - Duration of mapped inverse synthesis : %4.4f seconds\n",
239 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
241 time_start = clock();
244 printf(
" - Duration of mapped forward analysis : %4.4f seconds\n",
245 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
247 printf(
" - Maximum abs error on reconstruction : %6.5e\n",
260 clock_t time_start, time_end;
261 double *f = (
double*)calloc(N,
sizeof(
double));
262 double *fn = (
double*)calloc(N,
sizeof(
double));
263 double *fnrec = (
double*)calloc(N,
sizeof(
double));
266 srand ( time(NULL) );
269 fn[n] = rand()/795079784.0;
272 double *nodes = (
double*)calloc(N,
sizeof(
double));
273 double *weights = (
double*)calloc(N,
sizeof(
double));
277 time_start = clock();
280 printf(
" - Duration of 1D inverse synthesis : %4.0e seconds\n",
281 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
283 time_start = clock();
286 printf(
" - Duration of 1D forward analysis : %4.0e seconds\n",
287 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
289 printf(
" - Maximum abs error on reconstruction : %6.5e\n",
315 complex
double *f, *flmn, *flmnrec;
316 clock_t time_start, time_end;
327 double *nodes = (
double*)calloc(N,
sizeof(
double));
328 double *weights = (
double*)calloc(N,
sizeof(
double));
332 time_start = clock();
335 printf(
" - Duration of full 3D synthesis : %4.4f seconds\n",
336 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
339 time_start = clock();
342 printf(
" - Duration of full 3D analysis : %4.4f seconds\n",
343 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
346 printf(
" - Maximum abs error on reconstruction : %6.5e\n",
362 clock_t time_start, time_end, t_for, t_back;
365 int n, offset_lm, offset_r;
366 ssht_dl_method_t dl_method = SSHT_DL_TRAPANI;
368 double *nodes = (
double*)calloc(N,
sizeof(
double));
369 double *weights = (
double*)calloc(N,
sizeof(
double));
370 printf(
"Sampling...");fflush(NULL);
372 printf(
"done\n");fflush(NULL);
374 complex
double *flmn, *flmr, *flmn_rec, *f, *flmr_rec;
384 printf(
"Starting synthesis\n");fflush(NULL);
385 time_start = clock();
388 printf(
" - Synthesis : SLAG 3D synthes duration : %4.4f seconds\n",
389 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
390 time_start = clock();
394 printf(
" - Synthesis : SLAG 3D analys duration : %4.4f seconds\n",
395 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
396 printf(
" - SLAG maximum absolute error : %6.5e\n",
404 for (n = 0; n < N; n++){
405 offset_lm = n * flmsize;
406 offset_r = n * frsize;
407 ssht_core_mw_inverse_sov_sym(f + offset_r, flmr + offset_lm, L, spin, dl_method, verbosity);
409 t_back += (time_end - time_start) / (N);
410 time_start = clock();
411 ssht_core_mw_forward_sov_conv_sym(flmr_rec + offset_lm, f + offset_r, L, spin, dl_method, verbosity);
413 t_for += (time_end - time_start) / (N);
414 time_start = clock();
420 printf(
" - Synthesis : SSHT forward av duration : %4.4f seconds\n",
421 t_for / (
double)CLOCKS_PER_SEC);
422 printf(
" - Analysis : SSHT backward av duration : %4.4f seconds\n",
423 t_back / (
double)CLOCKS_PER_SEC);
424 printf(
" - SSHT maximum absolute error : %6.5e\n",
432 time_start = clock();
435 printf(
" - Analysis : SLAG 3D analysis duration : %4.4f seconds\n",
436 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
437 time_start = clock();
440 printf(
" - Analysis : SLAG 3D synthesis duration: %4.4f seconds\n",
441 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
442 printf(
" - SLAG maximum absolute error : %6.5e\n",
444 printf(
" - Final FLAG maximum absolute error : %6.5e\n",
456 complex *flmn, *flmnrec;
457 clock_t time_start, time_end;
466 double *nodes = (
double*)calloc(N,
sizeof(
double));
467 double *weights = (
double*)calloc(N,
sizeof(
double));
471 time_start = clock();
474 printf(
" - Duration of full 3D synthesis : %4.4f seconds\n",
475 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
477 time_start = clock();
480 printf(
" - Duration of full 3D analysis : %4.4f seconds\n",
481 (time_end - time_start) / (
double)CLOCKS_PER_SEC);
484 printf(
" - Maximum abs error on reconstruction : %6.5e\n",
497 complex
double *f, *flmn, *flmnrec;
498 clock_t time_start, time_end;
500 double tottime_analysis = 0, tottime_synthesis = 0;
501 double accuracy = 0.0;
507 for (sc=0; sc<NSCALE; sc++) {
516 double *nodes = (
double*)calloc(N,
sizeof(
double));
517 double *weights = (
double*)calloc(N,
sizeof(
double));
523 printf(
"\n > tau = %4.4f -- L = %i N = %i \n", tau, L, N);
524 for (repeat=0; repeat<NREPEAT; repeat++){
532 time_start = clock();
535 tottime_synthesis += (time_end - time_start) / (
double)CLOCKS_PER_SEC;
539 time_start = clock();
542 tottime_analysis += (time_end - time_start) / (
double)CLOCKS_PER_SEC;
552 tottime_synthesis = tottime_synthesis / (double)NREPEAT;
553 tottime_analysis = tottime_analysis / (double)NREPEAT;
554 accuracy = accuracy / (double)NREPEAT;
557 printf(
" - Average duration for FLAG synthesis : %4.4f seconds\n", tottime_synthesis);
558 printf(
" - Average duration for FLAG analysis : %4.4f seconds\n", tottime_analysis);
559 printf(
" - Average max error on reconstruction : %6.5e\n", accuracy);
571 int main(
int argc,
char *argv[])
577 const double tau = 1.0;
578 const int seed = (int)(10000.0*(
double)clock()/(double)CLOCKS_PER_SEC);
581 double *roots = (
double*)calloc(N,
sizeof(
double));
582 double *weights = (
double*)calloc(N,
sizeof(
double));
588 printf(
"Root[%i] = %f with weight %5.5e\n",i,roots[i],weights[i]);
593 printf(
"==========================================================\n");
594 printf(
"PARAMETERS : ");
595 printf(
" L = %i N = %i tau = %4.1f seed = %i\n", L, N, tau, seed);
596 printf(
"----------------------------------------------------------\n");
597 printf(
"> Testing Laguerre quadrature...");
601 printf(
"> Testing Laguerre tau calculation...");
605 printf(
"> Testing Laguerre sampling scheme...");
609 printf(
"----------------------------------------------------------\n");
611 printf(
"> Testing 1D Laguerre transform...\n");
615 printf(
"----------------------------------------------------------\n");
617 printf(
"> Testing cmplx mapped Laguerre transform...\n");
621 printf(
"----------------------------------------------------------\n");
623 printf(
"> Testing FLAG sampling scheme...");
627 printf(
"> Testing FLAG transform...\n");
631 printf(
"> Testing REAL FLAG transform...\n");
635 printf(
"----------------------------------------------------------\n");
637 printf(
"> Testing FLAG in further details...\n");
641 printf(
"==========================================================\n");
void flag_core_synthesis(complex double *f, const complex double *flmn, const double *nodes, int Nnodes, int L, double tau, int N, int spin)
void flag_sampling(double *rs, double *thetas, double *phis, double *laguweights, double tau, int L, int N)
void flag_random_flmn(complex double *flmn, int L, int N, int seed)
void flag_sampling_allocate(double **rs, double **thetas, double **phis, double **laguweights, int L, int N)
void flag_core_allocate_f(complex double **f, int L, int N)
void flag_spherlaguerre_sampling_test(int N, double tau)
void flag_core_allocate_flmn(complex double **flmn, int L, int N)
void flag_transform_furter_test(int L, int N, double tau, int seed)
void flag_core_analysis(complex double *flmn, const complex double *f, int L, double tau, int N, int spin)
int flag_core_flmn_size(int L, int N)
void flag_core_synthesis_real(double *f, const complex double *flmn, const double *nodes, int Nnodes, int L, double tau, int N)
void flag_spherlaguerre_mapped_synthesis(complex double *f, const complex double *fn, const double *nodes, int Nnodes, double tau, int N, int mapsize)
void flag_transform_real_test(int L, int N, double tau, int seed)
double maxerr(double *a, double *b, int size)
void flag_spherlaguerre_transform_test(int N, double tau)
void flag_sampling_test(int L, int N, double tau)
void flag_spherlaguerre_cmplx_transform_test(int L, int N, double tau, int seed)
void flag_transform_test(int L, int N, double tau, int seed)
void print_f_real(const double *f, int L, int N)
void flag_core_allocate_f_real(double **f, int L, int N)
void flag_random_flmn_real(complex double *flmn, int L, int N, int seed)
double flag_spherlaguerre_tau(double R, int N)
void flag_spherlaguerre_mapped_analysis(complex double *fn, const complex double *f, const double *nodes, const double *weights, double tau, int N, int mapsize)
int ssht_fr_size_mw(int L)
void flag_spherlaguerre_tau_test(int N)
void flag_spherlaguerre_quadrature_test(int N)
double maxerr_cplx(complex double *a, complex double *b, int size)
void flag_spherlaguerre_sampling(double *nodes, double *weights, double tau, int N)
void flag_transform_performance_test(double tau, int NREPEAT, int NSCALE, int seed)
void flag_core_analysis_real(complex double *flmn, const double *f, int L, double tau, int N)
int flag_core_f_size_mw(int L, int N)
void flag_spherlaguerre_quadrature(double *roots, double *weights, int N, int alpha)
void print_flmn(const complex double *flmn, int L, int N)
int main(int argc, char *argv[])
void flag_spherlaguerre_synthesis(double *f, const double *fn, const double *nodes, int Nnodes, double tau, int N)
void flag_spherlaguerre_analysis(double *fn, const double *f, const double *nodes, const double *weights, double tau, int N)
void flag_random_f(complex double *f, int L, int N, int seed)
void print_f(const complex double *f, int L, int N)