Skip to content

Commit d4c398a

Browse files
authored
Merge pull request #66 from jcarpent/devel
core: make np_type static thhrough a Singleton
2 parents aacf998 + 070d223 commit d4c398a

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

include/eigenpy/details.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,19 @@ namespace eigenpy
8989
static void switchToNumpyArray()
9090
{
9191
getInstance().CurrentNumpyType = getInstance().NumpyArrayObject;
92-
getInstance().np_type = ARRAY_TYPE;
92+
getType() = ARRAY_TYPE;
9393
}
9494

9595
static void switchToNumpyMatrix()
9696
{
9797
getInstance().CurrentNumpyType = getInstance().NumpyMatrixObject;
98-
getInstance().np_type = MATRIX_TYPE;
98+
getType() = MATRIX_TYPE;
9999
}
100100

101-
static NP_TYPE getType()
101+
static NP_TYPE & getType()
102102
{
103-
return getInstance().np_type;
103+
static NP_TYPE np_type;
104+
return np_type;
104105
}
105106

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

123124
CurrentNumpyType = NumpyMatrixObject; // default conversion
125+
getType() = MATRIX_TYPE;
124126
}
125127

126128
bp::object CurrentNumpyType;
@@ -131,11 +133,8 @@ namespace eigenpy
131133
//bp::object NumpyAsMatrixObject; PyTypeObject * NumpyAsMatrixType;
132134
bp::object NumpyArrayObject; PyTypeObject * NumpyArrayType;
133135

134-
static NP_TYPE np_type;
135136
};
136137

137-
NP_TYPE NumpyType::np_type = MATRIX_TYPE;
138-
139138
template<typename MatType>
140139
struct EigenObjectAllocator
141140
{

unittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ ENDIF()
3636
ADD_PYTHON_UNIT_TEST("py-matrix" "unittest/python/test_matrix.py" "unittest")
3737
ADD_PYTHON_UNIT_TEST("py-geometry" "unittest/python/test_geometry.py" "unittest")
3838
ADD_PYTHON_UNIT_TEST("py-switch" "unittest/python/test_switch.py" "python/eigenpy")
39+
ADD_PYTHON_UNIT_TEST("py-dimensions" "unittest/python/test_dimensions.py" "python/eigenpy")

unittest/python/test_dimensions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from __future__ import print_function
2+
3+
import eigenpy
4+
import numpy as np
5+
6+
quat = eigenpy.Quaternion()
7+
# By default, we convert as numpy.matrix
8+
coeffs_vector = quat.coeffs()
9+
assert len(coeffs_vector.shape) == 2
10+
11+
# Switch to numpy.array
12+
eigenpy.switchToNumpyArray()
13+
coeffs_vector = quat.coeffs()
14+
assert len(coeffs_vector.shape) == 1

0 commit comments

Comments
 (0)