From fc4b9e567e9442f67fe79dff61205d7f831295af Mon Sep 17 00:00:00 2001 From: Justin Carpentier <justin.carpentier@inria.fr> Date: Mon, 24 Feb 2020 22:13:05 +0100 Subject: [PATCH] core: add helper eigen_from_py_construct --- include/eigenpy/eigen-from-python.hpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/include/eigenpy/eigen-from-python.hpp b/include/eigenpy/eigen-from-python.hpp index c9230791..91eeed3f 100644 --- a/include/eigenpy/eigen-from-python.hpp +++ b/include/eigenpy/eigen-from-python.hpp @@ -83,6 +83,22 @@ namespace boost { namespace python { namespace converter { namespace eigenpy { + + template<typename MatOrRefType> + void eigen_from_py_construct(PyObject* pyObj, + bp::converter::rvalue_from_python_stage1_data* memory) + { + PyArrayObject * pyArray = reinterpret_cast<PyArrayObject*>(pyObj); + assert((PyArray_DIMS(pyArray)[0]<INT_MAX) && (PyArray_DIMS(pyArray)[1]<INT_MAX)); + + bp::converter::rvalue_from_python_storage<MatOrRefType>* storage = reinterpret_cast<bp::converter::rvalue_from_python_storage<MatOrRefType>*> + (reinterpret_cast<void*>(memory)); + + EigenAllocator<MatOrRefType>::allocate(pyArray,storage); + + memory->convertible = storage->storage.bytes; + } + template<typename MatType> struct EigenFromPy { @@ -215,15 +231,7 @@ namespace eigenpy void EigenFromPy<MatType>::construct(PyObject* pyObj, bp::converter::rvalue_from_python_stage1_data* memory) { - PyArrayObject * pyArray = reinterpret_cast<PyArrayObject*>(pyObj); - assert((PyArray_DIMS(pyArray)[0]<INT_MAX) && (PyArray_DIMS(pyArray)[1]<INT_MAX)); - - void* storage = reinterpret_cast<bp::converter::rvalue_from_python_storage<MatType>*> - (reinterpret_cast<void*>(memory))->storage.bytes; - - EigenAllocator<MatType>::allocate(pyArray,storage); - - memory->convertible = storage; + eigen_from_py_construct<MatType>(pyObj,memory); } template<typename MatType> -- GitLab