From a8488cf18a3c399de1dd5cdd9cc0e3caab3b53a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Thu, 28 Feb 2019 15:51:06 +0200 Subject: [PATCH] Working on the wrappers. Former-commit-id: b957673da9dfcff41c76212de92ee788d7ab844a --- qpms/qpms_c.pyx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/qpms/qpms_c.pyx b/qpms/qpms_c.pyx index f9a4400..5635d20 100644 --- a/qpms/qpms_c.pyx +++ b/qpms/qpms_c.pyx @@ -1037,7 +1037,17 @@ cdef class TMatrix: ''' Wrapper over the C qpms_tmatrix_t stucture. ''' - pass + cdef readonly np.ndarray m # Numpy array holding the matrix data + cdef readonly BaseSpec spec # Here we hold the base spec for the correct reference counting; TODO check if it gets copied + cdef qpms_tmatrix_t t + + def __cinit__(TMatrix self, BaseSpec spec, matrix): + self.t.spec = spec.rawpointer(); + # The following will raise an exception if shape is wrong + self.m = np.array(matrix, dtype=complex, copy=True, order='C').reshape((len(spec), len(spec))) + cdef cdouble[:,::1] m_memview = self.m + self.t.m = &(m_memview[0,0]) + self.t.owns_m = False # Memory in self.t.m is "owned" by self.m, not by self.t... cdef class FinitePointGroup: ''' @@ -1049,7 +1059,13 @@ cdef class Particle: ''' Wrapper over the qpms_particle_t structure. ''' - pass + cdef readonly qpms_particle_t p + cdef readonly TMatrix t # We hold the reference to the T-matrix to ensure correct reference counting + + def __cinit__(Particle self, position, TMatrix t): + pass + + cdef class ScatteringSystem: '''