From bd3ab69d60a06bdf1c0d02fdf3c6b1a243481b60 Mon Sep 17 00:00:00 2001 From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be> Date: Thu, 11 Sep 2014 10:08:24 +0000 Subject: [PATCH] python : add typemap to convert returned fullVector to numpy array --- wrappers/gmshpy/gmshtypemaps.i | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wrappers/gmshpy/gmshtypemaps.i b/wrappers/gmshpy/gmshtypemaps.i index fa9ec33d24..5732a1b35e 100644 --- a/wrappers/gmshpy/gmshtypemaps.i +++ b/wrappers/gmshpy/gmshtypemaps.i @@ -123,6 +123,14 @@ } return array; } + PyObject *fullVector2PyArrayProxy(fullVector<double> &fv) + { + npy_intp dims[1] = {fv.size()}; + double *data = &fv.operator()(0); + PyObject *array = PyArray_New(&PyArray_Type, 1, dims, NPY_DOUBLE, NULL, (void*)data, 0, NPY_ARRAY_F_CONTIGUOUS, NULL); + PyArray_UpdateFlags((PyArrayObject*)array, NPY_ARRAY_ALIGNED | NPY_ARRAY_WRITEABLE); + return array; + } %#endif } @@ -176,6 +184,10 @@ %typemap(out, fragment="fullMatrixConversion") fullMatrix<double> { $result = fullMatrix2PyArray($1); } + +%typemap(out, fragment="fullMatrixConversion") fullVector<double>& { + $result = fullVector2PyArrayProxy(*$1); +} #endif -- GitLab