47 #define MIN(a,b) ((a < b) ? (a) : (b))
48 #define MAX(a,b) ((a > b) ? (a) : (b))
50 double get_max_error(complex
double *expected, complex
double *actual,
int n);
55 int main(
int argc,
char **argv)
57 so3_parameters_t parameters = {};
58 int Lmax, L, useLasN, N, L0;
59 complex
double *flmn_orig, *flmn_syn;
63 clock_t time_start, time_end;
67 const char *n_order_str[SO3_N_ORDER_SIZE];
68 const char *storage_mode_str[SO3_STORAGE_SIZE];
69 const char *n_mode_str[SO3_N_MODE_SIZE];
70 const char *reality_str[2];
71 const char *sampling_str[2];
73 double min_duration_inverse;
74 double min_duration_forward;
75 double avg_duration_inverse;
76 double avg_duration_forward;
79 n_order_str[SO3_N_ORDER_ZERO_FIRST] =
"n = 0 first";
80 n_order_str[SO3_N_ORDER_NEGATIVE_FIRST] =
"n = -N+1 first";
82 storage_mode_str[SO3_STORAGE_PADDED] =
"padded storage";
83 storage_mode_str[SO3_STORAGE_COMPACT] =
"compact storage";
85 n_mode_str[SO3_N_MODE_ALL] =
"all n";
86 n_mode_str[SO3_N_MODE_EVEN] =
"only even n";
87 n_mode_str[SO3_N_MODE_ODD] =
"only odd n";
88 n_mode_str[SO3_N_MODE_MAXIMUM] =
"only |n| = N-1";
90 reality_str[0] =
"complex";
91 reality_str[1] =
"real";
93 sampling_str[0] =
"MW";
94 sampling_str[1] =
"MWSS";
102 Lmax = atoi(argv[1]);
113 parameters.verbosity = 0;
117 flmn_orig = malloc((2*N-1)*Lmax*Lmax *
sizeof *flmn_orig);
118 SO3_ERROR_MEM_ALLOC_CHECK(flmn_orig);
119 flmn_syn = malloc((2*N-1)*Lmax*Lmax *
sizeof *flmn_syn);
120 SO3_ERROR_MEM_ALLOC_CHECK(flmn_syn);
124 f = malloc((2*Lmax)*(Lmax+1)*(2*N-1) *
sizeof *f);
125 SO3_ERROR_MEM_ALLOC_CHECK(f);
126 f_real = malloc((2*Lmax)*(Lmax+1)*(2*N-1) *
sizeof *f_real);
127 SO3_ERROR_MEM_ALLOC_CHECK(f_real);
130 printf(
"reality;L;N;avg_duration_inverse;avg_duration_forward;min_duration_inverse;min_duration_forward;avg_error\n");
132 parameters.sampling_scheme = SO3_SAMPLING_MW;
133 parameters.n_order = SO3_N_ORDER_ZERO_FIRST;
134 parameters.storage = SO3_STORAGE_PADDED;
135 parameters.n_mode = SO3_N_MODE_ALL;
139 for (real = 0; real < 2; ++real)
141 parameters.reality = real;
146 if (L <= L0 || (!useLasN && L < N))
159 min_duration_inverse = 0.0;
160 min_duration_forward = 0.0;
161 avg_duration_inverse = 0.0;
162 avg_duration_forward = 0.0;
171 for (j = 0; j < (2*N-1)*L*L; ++j)
177 time_start = clock();
182 duration = (time_end - time_start) / (
double)CLOCKS_PER_SEC;
183 avg_duration_inverse = avg_duration_inverse + duration /
NREPEAT;
184 if (!i || duration < min_duration_inverse)
185 min_duration_inverse = duration;
187 time_start = clock();
192 duration = (time_end - time_start) / (
double)CLOCKS_PER_SEC;
193 avg_duration_forward = avg_duration_forward + duration /
NREPEAT;
194 if (!i || duration < min_duration_forward)
195 min_duration_forward = duration;
201 printf(
"%d;%d;%d;%f;%f;%f;%f;%e\n",
205 avg_duration_inverse,
206 avg_duration_forward,
207 min_duration_inverse,
208 min_duration_forward,
223 double get_max_error(complex
double *expected, complex
double *actual,
int n)
226 double error, maxError = 0;
228 for (i = 0; i < n; ++i)
230 error = cabs(expected[i] - actual[i]);
231 maxError =
MAX(error, maxError);
254 complex
double *flmn,
255 const so3_parameters_t *parameters,
259 int i, el, m, n, n_start, n_stop, n_inc, ind;
265 for (i = 0; i < (2*N-1)*L*L; ++i)
268 switch (parameters->n_mode)
275 case SO3_N_MODE_EVEN:
276 n_start = ((N-1) % 2 == 0) ? -N+1 : -N+2;
277 n_stop = ((N-1) % 2 == 0) ? N-1 : N-2;
281 n_start = ((N-1) % 2 != 0) ? -N+1 : -N+2;
282 n_stop = ((N-1) % 2 != 0) ? N-1 : N-2;
285 case SO3_N_MODE_MAXIMUM:
291 SO3_ERROR_GENERIC(
"Invalid n-mode.");
294 for (n = n_start; n <= n_stop; n += n_inc)
296 for (el =
MAX(L0, abs(n)); el < L; ++el)
298 for (m = -el; m <= el; ++m)
301 flmn[ind] = (2.0*
ran2_dp(seed) - 1.0) + I * (2.0*
ran2_dp(seed) - 1.0);
327 complex
double *flmn,
328 const so3_parameters_t *parameters,
332 int i, el, m, n, n_start, n_stop, n_inc, ind;
339 for (i = 0; i < (2*N-1)*L*L; ++i)
342 switch (parameters->n_mode)
349 case SO3_N_MODE_EVEN:
351 n_stop = ((N-1) % 2 == 0) ? N-1 : N-2;
356 n_stop = ((N-1) % 2 != 0) ? N-1 : N-2;
359 case SO3_N_MODE_MAXIMUM:
365 SO3_ERROR_GENERIC(
"Invalid n-mode.");
368 for (n = n_start; n <= n_stop; n += n_inc)
373 for (el = L0; el < L; ++el)
376 flmn[ind] = (2.0*
ran2_dp(seed) - 1.0);
381 for (el = L0; el < L; ++el)
383 for (m = 1; m <= el; ++m)
385 real = (2.0*
ran2_dp(seed) - 1.0);
386 imag = (2.0*
ran2_dp(seed) - 1.0);
388 flmn[ind] = real + imag * I;
390 flmn[ind] = real - imag * I;
392 flmn[ind] = - real + imag * I;
394 flmn[ind] = real - imag * I;
400 for (el =
MAX(L0, n); el < L; ++el)
402 for (m = -el; m <= el; ++m)
406 flmn[ind] = (2.0*
ran2_dp(seed) - 1.0) + I * (2.0*
ran2_dp(seed) - 1.0);
428 int IM1=2147483563,IM2=2147483399,IMM1=IM1-1,
429 IA1=40014,IA2=40692,IQ1=53668,IQ2=52774,IR1=12211,IR2=3791,
430 NTAB=32,NDIV=1+IMM1/NTAB;
432 double AM=1./IM1,EPS=1.2e-7,RNMX=1.-EPS;
434 static int iv[32],iy,idum2 = 123456789;
438 idum= (-idum>1 ? -idum : 1);
440 for(j=NTAB+8;j>=1;j--) {
442 idum=IA1*(idum-k*IQ1)-k*IR1;
443 if (idum < 0) idum=idum+IM1;
444 if (j < NTAB) iv[j-1]=idum;
449 idum=IA1*(idum-k*IQ1)-k*IR1;
450 if (idum < 0) idum=idum+IM1;
452 idum2=IA2*(idum2-k*IQ2)-k*IR2;
453 if (idum2 < 0) idum2=idum2+IM2;
457 if(iy < 1)iy=iy+IMM1;
458 return (AM*iy < RNMX ? AM*iy : RNMX);