diff --git a/wrappers/gmshpy/gmshtypemaps.i b/wrappers/gmshpy/gmshtypemaps.i index 5f91406d3ff7505f6c4b254c001ec1aa9b3db326..42a077fb8282755c8a929fce882b6a491784e659 100644 --- a/wrappers/gmshpy/gmshtypemaps.i +++ b/wrappers/gmshpy/gmshtypemaps.i @@ -124,6 +124,27 @@ } return array; } + PyObject *fullMatrix2PyArrayConst(const fullMatrix<double> &fm) + { + npy_intp dims[2] = {fm.size1(), fm.size2()}; + double *data = (double*)fm.getDataPtr(); + /*PyObject *array = PyArray_New(&PyArray_Type, 2, dims, NPY_DOUBLE, NULL, NULL, 0, NPY_ARRAY_F_CONTIGUOUS, NULL); + // copy data + memcpy((void*)PyArray_DATA(array), data, dims[0] * dims[1] * sizeof(double));*/ + // do not copy data + PyObject *array = PyArray_New(&PyArray_Type, 2, dims, NPY_DOUBLE, NULL, (void*)data, 0, NPY_ARRAY_F_CONTIGUOUS, NULL); + PyArray_UpdateFlags((PyArrayObject*)array, NPY_ARRAY_ALIGNED); + /*if (fm.getOwnData()) { + fm.setOwnData(false); + %#if PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==6 + PyObject *capsule = PyCObject_FromVoidPtr((void*)data, deleteCapsuleArray); + %#else + PyObject *capsule = PyCapsule_New((void*) data, NULL, deleteCapsuleArray); + %#endif + PyArray_SetBaseObject((PyArrayObject*)array, capsule); + }*/ + return array; + } PyObject *fullVector2PyArrayProxy(fullVector<double> &fv) { npy_intp dims[1] = {fv.size()}; @@ -186,6 +207,10 @@ $result = fullMatrix2PyArray($1); } +%typemap(out, fragment="fullMatrixConversion") const fullMatrix<double>& { + $result = fullMatrix2PyArrayConst(*$1); +} + %typemap(out, fragment="fullMatrixConversion") fullVector<double>& { $result = fullVector2PyArrayProxy(*$1); }