Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions include/eigenpy/details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you solved the issue ?
I think you should move the definition of this function to a non-installed cc file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are working of course.

}

protected:
Expand All @@ -121,6 +122,7 @@ namespace eigenpy
//NumpyAsMatrixType = reinterpret_cast<PyTypeObject*>(NumpyAsMatrixObject.ptr());

CurrentNumpyType = NumpyMatrixObject; // default conversion
getType() = MATRIX_TYPE;
}

bp::object CurrentNumpyType;
Expand All @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
14 changes: 14 additions & 0 deletions unittest/python/test_dimensions.py
Original file line number Diff line number Diff line change
@@ -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