From d01ab445fe1748ae1d128370fb4d65f6b7f4a19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Mon, 22 Jul 2019 10:08:09 +0300 Subject: [PATCH] Cython-wrap additional translations.h functions. Former-commit-id: 4b1ad54f40167f66b6788cb2976ca854b7971a5e --- TODO.md | 2 ++ qpms/qpms_c.pyx | 40 ++++++++++++++++++++++++++++++++++++++++ qpms/qpms_cdefs.pxd | 15 +++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/TODO.md b/TODO.md index de25fd1..8b83c0c 100644 --- a/TODO.md +++ b/TODO.md @@ -24,6 +24,8 @@ TODO list before public release * As a description of a T-matrix / particle metadata. - Nice CLI for all general enough utilities. - Remove legacy code. +- Split qpms_c.pyx. +- Reduce compiler warnings. - Prefix all identifiers. Maybe think about a different prefix than qpms? - Consistent indentation and style overall. - Rewrite the parallelized translation matrix, mode problem matrix generators diff --git a/qpms/qpms_c.pyx b/qpms/qpms_c.pyx index dc626f9..2907fb7 100644 --- a/qpms/qpms_c.pyx +++ b/qpms/qpms_c.pyx @@ -670,6 +670,46 @@ cdef class trans_calculator: r_ge_d_c.data, r_ge_d_c.shape, r_ge_d_c.strides ) return a, b + + def get_trans_array_bspec_sph(self, BaseSpec destspec, BaseSpec srcspec, + double k, kdlj, qpms_bessel_t J = QPMS_HANKEL_PLUS): + if kdlj.shape != (3,): + raise ValueError("Array of shape (3,) with spherical coordinates of the translation expected") + cdef size_t destn = len(destspec) + cdef size_t srcn = len(srcspec) + cdef np.ndarray[np.complex_t, ndim=2] target = np.empty( + (destn, srcn), dtype=complex, order='C') + cdef cdouble[:,::1] target_view = target + cdef sph_t kdlj_sph + kdlj_sph.r = kdlj[0] + kdlj_sph.theta = kdlj[1] + kdlj_sph.phi = kdlj[2] + qpms_trans_calculator_get_trans_array(self.c, &target_view[0][0], + destspec.rawpointer(), srcn, srcspec.rawpointer(), 1, + kdlj_sph, False, J) + return target + + def get_trans_array_bspec_c3pos(self, BaseSpec destspec, BaseSpec srcspec, + double k, destpos, srcpos, qpms_bessel_t J = QPMS_HANKEL_PLUS): + if destpos.shape != (3,) or srcpos.shape != (3,): + raise ValueError("Array of shape (3,) with cartesian coordinates of the particle position expected") + cdef size_t destn = len(destspec) + cdef size_t srcn = len(srcspec) + cdef np.ndarray[np.complex_t, ndim=2] target = np.empty( + (destn, srcn), dtype=complex, order='C') + cdef cdouble[:,::1] target_view = target + cdef cart3_t srcp, destp + srcp.x = srcpos[0] + srcp.y = srcpos[1] + srcp.z = srcpos[2] + destp.x = destpos[0] + destp.y = destpos[1] + destp.z = destpos[2] + qpms_trans_calculator_get_trans_array_lc3p(self.c, &target_view[0][0], + destspec.rawpointer(), srcn, srcspec.rawpointer(), 1, k, + destp, srcp, J) + return target + # TODO make possible to access the attributes (to show normalization etc) diff --git a/qpms/qpms_cdefs.pxd b/qpms/qpms_cdefs.pxd index f9d8914..16f8407 100644 --- a/qpms/qpms_cdefs.pxd +++ b/qpms/qpms_cdefs.pxd @@ -269,6 +269,21 @@ cdef extern from "translations.h": char *phi_data, np.npy_intp *phi_shape, np.npy_intp *phi_strides, char *r_ge_d_data, np.npy_intp *phi_shape, np.npy_intp *phi_strides) nogil + int qpms_trans_calculator_get_trans_array(const qpms_trans_calculator *c, + cdouble *target, + const qpms_vswf_set_spec_t *destspec, size_t deststride, + const qpms_vswf_set_spec_t *srcspec, size_t srcstride, + sph_t kdlj, bint r_ge_d, qpms_bessel_t J); + + int qpms_trans_calculator_get_trans_array_lc3p( + const qpms_trans_calculator *c, + cdouble *target, + const qpms_vswf_set_spec_t *destspec, size_t deststride, + const qpms_vswf_set_spec_t *srcspec, size_t srcstride, + double k, cart3_t destpos, cart3_t srcpos, + qpms_bessel_t J + ); + cdef extern from "gsl/gsl_interp.h": struct gsl_interp_type: pass