Skip to content

Commit 782371c

Browse files
authored
Merge pull request #118 from jcarpent/devel
Expose getNumpyType
2 parents 54a9826 + 97529bb commit 782371c

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

include/eigenpy/details.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ namespace eigenpy
114114
static NP_TYPE np_type;
115115
return np_type;
116116
}
117+
118+
static bp::object getNumpyType()
119+
{
120+
return getInstance().CurrentNumpyType;
121+
}
117122

118123
protected:
119124
NumpyType()

src/eigenpy.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ namespace eigenpy
1616

1717
bp::def("setNumpyType",&NumpyType::setNumpyType,
1818
bp::arg("Numpy type (np.ndarray or np.matrix)"),
19-
"Change the type returned by the converters from an Eigen object.");
19+
"Change the Numpy type returned by the converters from an Eigen object.");
20+
21+
bp::def("getNumpyType",&NumpyType::getNumpyType,
22+
"Get the Numpy type returned by the converters from an Eigen object.");
2023

2124
bp::def("switchToNumpyArray",&NumpyType::switchToNumpyArray,
2225
"Set the conversion from Eigen::Matrix to numpy.ndarray.");

unittest/python/test_geometry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import print_function
22

3-
from eigenpy import *
43
from geometry import *
54
import numpy as np
65
from numpy import cos,sin

unittest/python/test_switch.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
import eigenpy
44
import numpy as np
55

6+
eigenpy.switchToNumpyMatrix()
67
quat = eigenpy.Quaternion()
78
# By default, we convert as numpy.matrix
89
coeffs_vector = quat.coeffs()
910
print(type(coeffs_vector))
1011

1112
assert isinstance(coeffs_vector,np.matrixlib.defmatrix.matrix)
13+
assert eigenpy.getNumpyType() == np.matrix
1214

1315
# Switch to numpy.array
1416
eigenpy.switchToNumpyArray()
1517
coeffs_array = quat.coeffs()
1618
print(type(coeffs_array))
1719

1820
assert isinstance(coeffs_vector,np.ndarray)
21+
assert eigenpy.getNumpyType() == np.ndarray

0 commit comments

Comments
 (0)