From 637b9bb928918a2f9ba5f48b5e96cb7506d4ec16 Mon Sep 17 00:00:00 2001 From: Justin Carpentier <justin.carpentier@inria.fr> Date: Thu, 18 Oct 2018 18:36:26 +0200 Subject: [PATCH] numpy: add helper for the switch --- include/eigenpy/details.hpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/include/eigenpy/details.hpp b/include/eigenpy/details.hpp index e7c60e89..fea17482 100644 --- a/include/eigenpy/details.hpp +++ b/include/eigenpy/details.hpp @@ -86,19 +86,30 @@ namespace eigenpy if(PyType_IsSubtype(obj_type,getInstance().NumpyMatrixType)) getInstance().CurrentNumpyType = getInstance().NumpyMatrixObject; else if(PyType_IsSubtype(obj_type,getInstance().NumpyArrayType)) - getInstance().CurrentNumpyType = getInstance().NumpyArrayObject;; + getInstance().CurrentNumpyType = getInstance().NumpyArrayObject; + } + + static void switchToNumpyArray() + { + getInstance().CurrentNumpyType = getInstance().NumpyArrayObject; + } + + static void switchToNumpyMatrix() + { + getInstance().CurrentNumpyType = getInstance().NumpyMatrixObject; } protected: PyMatrixType() { pyModule = bp::import("numpy"); - CurrentNumpyType = pyModule.attr("matrix"); // default conversion NumpyMatrixObject = pyModule.attr("matrix"); NumpyMatrixType = reinterpret_cast<PyTypeObject*>(NumpyMatrixObject.ptr()); NumpyArrayObject = pyModule.attr("ndarray"); NumpyArrayType = reinterpret_cast<PyTypeObject*>(NumpyArrayObject.ptr()); + + CurrentNumpyType = NumpyMatrixObject; // default conversion } bp::object CurrentNumpyType; @@ -107,9 +118,6 @@ namespace eigenpy // Numpy types bp::object NumpyMatrixObject; PyTypeObject * NumpyMatrixType; bp::object NumpyArrayObject; PyTypeObject * NumpyArrayType; - - -// PyTypeObject * NumpyArrayType; }; template<typename MatType> -- GitLab