diff --git a/include/eigenpy/details.hpp b/include/eigenpy/details.hpp index e6dfc50a98c53b6a24eb57e68023d4dbf2d9b778..f0d32adee2fa2d5e7aafc5c5ab70603b269c3b0a 100644 --- a/include/eigenpy/details.hpp +++ b/include/eigenpy/details.hpp @@ -89,18 +89,19 @@ namespace eigenpy static void switchToNumpyArray() { getInstance().CurrentNumpyType = getInstance().NumpyArrayObject; - getInstance().np_type = ARRAY_TYPE; + getType() = ARRAY_TYPE; } static void switchToNumpyMatrix() { getInstance().CurrentNumpyType = getInstance().NumpyMatrixObject; - getInstance().np_type = MATRIX_TYPE; + getType() = MATRIX_TYPE; } - static NP_TYPE getType() + static NP_TYPE & getType() { - return getInstance().np_type; + static NP_TYPE np_type; + return np_type; } protected: @@ -121,6 +122,7 @@ namespace eigenpy //NumpyAsMatrixType = reinterpret_cast<PyTypeObject*>(NumpyAsMatrixObject.ptr()); CurrentNumpyType = NumpyMatrixObject; // default conversion + getType() = MATRIX_TYPE; } bp::object CurrentNumpyType; @@ -131,11 +133,8 @@ namespace eigenpy //bp::object NumpyAsMatrixObject; PyTypeObject * NumpyAsMatrixType; bp::object NumpyArrayObject; PyTypeObject * NumpyArrayType; - static NP_TYPE np_type; }; - NP_TYPE NumpyType::np_type = MATRIX_TYPE; - template<typename MatType> struct EigenObjectAllocator { diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 723247bf7a77aac91be4a9de6465a372c81359fc..84ce752b838889f7c58c8e2db848645e9e9be5ad 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -36,3 +36,4 @@ ENDIF() ADD_PYTHON_UNIT_TEST("py-matrix" "unittest/python/test_matrix.py" "unittest") ADD_PYTHON_UNIT_TEST("py-geometry" "unittest/python/test_geometry.py" "unittest") ADD_PYTHON_UNIT_TEST("py-switch" "unittest/python/test_switch.py" "python/eigenpy") +ADD_PYTHON_UNIT_TEST("py-dimensions" "unittest/python/test_dimensions.py" "python/eigenpy") diff --git a/unittest/python/test_dimensions.py b/unittest/python/test_dimensions.py new file mode 100644 index 0000000000000000000000000000000000000000..3ccc354b7f323cca24099d7e919dd7c220333b70 --- /dev/null +++ b/unittest/python/test_dimensions.py @@ -0,0 +1,14 @@ +from __future__ import print_function + +import eigenpy +import numpy as np + +quat = eigenpy.Quaternion() +# By default, we convert as numpy.matrix +coeffs_vector = quat.coeffs() +assert len(coeffs_vector.shape) == 2 + +# Switch to numpy.array +eigenpy.switchToNumpyArray() +coeffs_vector = quat.coeffs() +assert len(coeffs_vector.shape) == 1