Axes bugfix

Former-commit-id: 8c58c30104d142779e698646a46ca950520307c0
This commit is contained in:
Marek Nečada 2017-05-03 08:08:58 +03:00
parent b6b701bd42
commit 2149a9ca71
2 changed files with 110 additions and 53 deletions

44
qpms/proftest.c Normal file
View File

@ -0,0 +1,44 @@
#include "translations.h"
#include <stdio.h>
//#include <math.h>
#include <complex.h>
typedef struct {
int m, n, mu, nu;
sph_t kdlj;
qpms_bessel_t J;
complex double result_A, result_B;
} testcase_single_trans_t;
testcase_single_trans_t testcases_Taylor[] = {
#include "testcases_taylor"
};
int main() {
int repete = 500;
int lMax = 3;
qpms_trans_calculator *c = qpms_trans_calculator_init(lMax, QPMS_NORMALIZATION_TAYLOR);
for( int rr = 0; rr < repete; rr++)
for(testcase_single_trans_t *tc = testcases_Taylor; tc->J != QPMS_BESSEL_UNDEF; tc++) {
//if (tc->n > 40 || tc->nu > 40 ) continue;
complex double A_array[c->nelem * c->nelem];
complex double B_array[c->nelem * c->nelem];
qpms_trans_calculator_get_AB_arrays(c, A_array, B_array, c->nelem, 1, tc->kdlj, true, tc->J);
#if 0
complex double A = qpms_trans_single_A_Taylor(tc->m, tc->n, tc->mu, tc->nu, tc->kdlj, true, tc->J);
complex double B = qpms_trans_single_B_Taylor(tc->m, tc->n, tc->mu, tc->nu, tc->kdlj, true, tc->J);
printf("A = %.16f+%.16fj, relerr=%.16f, J=%d\n",
creal(A), cimag(A), (0 == cabs(tc->result_A - A)) ? 0 :
cabs(tc->result_A - A)/((cabs(A) < cabs(tc->result_A)) ? cabs(A) : cabs(tc->result_A)),
tc->J);
printf("B = %.16f+%.16fj, relerr=%.16f, J=%d\n",
creal(B), cimag(B), (0 == cabs(tc->result_B - B)) ? 0 :
cabs(tc->result_B - B)/((cabs(B) < cabs(tc->result_B)) ? cabs(B) : cabs(tc->result_B)),
tc->J);
#endif
}
}

View File

@ -665,6 +665,10 @@ int qpms_trans_calculator_get_AB_arrays_ext(const qpms_trans_calculator *c,
#ifdef QPMS_COMPILE_PYTHON_EXTENSIONS
#include <string.h>
#ifdef QPMS_USE_OMP
#include <omp.h>
#endif
int qpms_cython_trans_calculator_get_AB_arrays_loop(
const qpms_trans_calculator *c, const qpms_bessel_t J, const int resnd,
const int daxis, const int saxis,
@ -677,13 +681,17 @@ int qpms_cython_trans_calculator_get_AB_arrays_loop(
assert(daxis != saxis);
assert(resnd >= 2);
int longest_axis = 0;
int longestshape = 1;
const npy_intp *resultshape = A_shape, *resultstrides = A_strides;
// TODO put some restrict's everywhere?
for (int ax = 0; ax < resnd; ++ax){
assert(A_shape[ax] == B_shape[ax]);
assert(A_strides[ax] == B_strides[ax]);
if (daxis == ax || saxis == ax) continue;
if (A_shape[ax] > A_shape[longest_axis]) longest_axis = ax;
if (A_shape[ax] > longestshape) {
longest_axis = ax;
longestshape = 1;
}
}
const npy_intp longlen = resultshape[longest_axis];
@ -704,12 +712,16 @@ int qpms_cython_trans_calculator_get_AB_arrays_loop(
const npy_intp dstride = resultstrides[daxis] / sizeof(complex double);
const npy_intp sstride = resultstrides[saxis] / sizeof(complex double);
int errval = 0;
// TODO here start parallelisation
//#pragma omp parallel
{
npy_intp local_indices[resnd];
memset(local_indices, 0, sizeof(local_indices));
int errval_local = 0;
for(npy_intp longi = 0; longi < longlen; ++longi) {
size_t longi;
//#pragma omp for
for(longi = 0; longi < longlen; ++longi) {
// this might be done also in the inverse order, but this is more
// 'c-contiguous' way of incrementing the indices
int ax = resnd - 1;
@ -758,8 +770,9 @@ int qpms_cython_trans_calculator_get_AB_arrays_loop(
ax = resnd - 1;
}
}
errval |= errval_local;
}
// FIXME when parallelizing
int errval = errval_local;
// TODO Here end parallelisation
return errval;
}