Skip to content
Snippets Groups Projects
Unverified Commit 782371c8 authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #118 from jcarpent/devel

Expose getNumpyType
parents 54a9826b 97529bb1
No related branches found
No related tags found
No related merge requests found
...@@ -114,6 +114,11 @@ namespace eigenpy ...@@ -114,6 +114,11 @@ namespace eigenpy
static NP_TYPE np_type; static NP_TYPE np_type;
return np_type; return np_type;
} }
static bp::object getNumpyType()
{
return getInstance().CurrentNumpyType;
}
protected: protected:
NumpyType() NumpyType()
......
...@@ -16,7 +16,10 @@ namespace eigenpy ...@@ -16,7 +16,10 @@ namespace eigenpy
bp::def("setNumpyType",&NumpyType::setNumpyType, bp::def("setNumpyType",&NumpyType::setNumpyType,
bp::arg("Numpy type (np.ndarray or np.matrix)"), bp::arg("Numpy type (np.ndarray or np.matrix)"),
"Change the type returned by the converters from an Eigen object."); "Change the Numpy type returned by the converters from an Eigen object.");
bp::def("getNumpyType",&NumpyType::getNumpyType,
"Get the Numpy type returned by the converters from an Eigen object.");
bp::def("switchToNumpyArray",&NumpyType::switchToNumpyArray, bp::def("switchToNumpyArray",&NumpyType::switchToNumpyArray,
"Set the conversion from Eigen::Matrix to numpy.ndarray."); "Set the conversion from Eigen::Matrix to numpy.ndarray.");
......
from __future__ import print_function from __future__ import print_function
from eigenpy import *
from geometry import * from geometry import *
import numpy as np import numpy as np
from numpy import cos,sin from numpy import cos,sin
......
...@@ -3,12 +3,14 @@ from __future__ import print_function ...@@ -3,12 +3,14 @@ from __future__ import print_function
import eigenpy import eigenpy
import numpy as np import numpy as np
eigenpy.switchToNumpyMatrix()
quat = eigenpy.Quaternion() quat = eigenpy.Quaternion()
# By default, we convert as numpy.matrix # By default, we convert as numpy.matrix
coeffs_vector = quat.coeffs() coeffs_vector = quat.coeffs()
print(type(coeffs_vector)) print(type(coeffs_vector))
assert isinstance(coeffs_vector,np.matrixlib.defmatrix.matrix) assert isinstance(coeffs_vector,np.matrixlib.defmatrix.matrix)
assert eigenpy.getNumpyType() == np.matrix
# Switch to numpy.array # Switch to numpy.array
eigenpy.switchToNumpyArray() eigenpy.switchToNumpyArray()
...@@ -16,3 +18,4 @@ coeffs_array = quat.coeffs() ...@@ -16,3 +18,4 @@ coeffs_array = quat.coeffs()
print(type(coeffs_array)) print(type(coeffs_array))
assert isinstance(coeffs_vector,np.ndarray) assert isinstance(coeffs_vector,np.ndarray)
assert eigenpy.getNumpyType() == np.ndarray
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment