From 314cde1b998de6a62aaed6104abdd73b068a5866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Sat, 21 Aug 2021 19:05:49 +0300 Subject: [PATCH] BaseSpec "constructor" from C pointer. --- qpms/cybspec.pxd | 2 ++ qpms/cybspec.pyx | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/qpms/cybspec.pxd b/qpms/cybspec.pxd index 853c372..4d080fc 100644 --- a/qpms/cybspec.pxd +++ b/qpms/cybspec.pxd @@ -6,4 +6,6 @@ cdef class BaseSpec: cdef qpms_vswf_set_spec_t s cdef np.ndarray __ilist + @staticmethod + cdef BaseSpec from_cpointer(const qpms_vswf_set_spec_t *orig) cdef qpms_vswf_set_spec_t *rawpointer(BaseSpec self) diff --git a/qpms/cybspec.pyx b/qpms/cybspec.pyx index e2813b8..9983272 100644 --- a/qpms/cybspec.pyx +++ b/qpms/cybspec.pyx @@ -27,6 +27,7 @@ try: except AttributeError: # For older Python versions, use IntEnum instead VSWFNorm = enum.IntEnum('VSWFNorm', names=__VSWF_norm_dict, module=__name__) + cdef class BaseSpec: '''Cython wrapper over qpms_vswf_set_spec_t. @@ -39,6 +40,16 @@ cdef class BaseSpec: #cdef np.ndarray __ilist # in pxd #cdef const qpms_uvswfi_t[:] __ilist + @staticmethod + cdef BaseSpec from_cpointer(const qpms_vswf_set_spec_t *orig): + '''Makes an instance of BaseSpec from an existing + C pointer, copying the contents + ''' + cdef const qpms_uvswfi_t[::1] ilist_orig = orig[0].ilist + cdef BaseSpec bs = BaseSpec(ilist_orig) + bs.s.norm = orig[0].norm + return bs + def __cinit__(self, *args, **kwargs): cdef const qpms_uvswfi_t[:] ilist_memview if len(args) == 0: