diff --git a/include/eigenpy/numpy-type.hpp b/include/eigenpy/numpy-type.hpp index c9bccd774380df3364016b57ecbd3660af7d5100..ecc24046bf4d839789b8aa968d12ddae138b18c3 100644 --- a/include/eigenpy/numpy-type.hpp +++ b/include/eigenpy/numpy-type.hpp @@ -7,6 +7,7 @@ #include "eigenpy/fwd.hpp" #include "eigenpy/scalar-conversion.hpp" +#include "eigenpy/register.hpp" #include <stdexcept> #include <typeinfo> @@ -16,27 +17,6 @@ namespace eigenpy { namespace bp = boost::python; - // By default, the Scalar is considered as a Python object - template <typename Scalar> struct NumpyEquivalentType { enum { type_code = NPY_USERDEF };}; - - template <> struct NumpyEquivalentType<float> { enum { type_code = NPY_FLOAT };}; - template <> struct NumpyEquivalentType< std::complex<float> > { enum { type_code = NPY_CFLOAT };}; - template <> struct NumpyEquivalentType<double> { enum { type_code = NPY_DOUBLE };}; - template <> struct NumpyEquivalentType< std::complex<double> > { enum { type_code = NPY_CDOUBLE };}; - template <> struct NumpyEquivalentType<long double> { enum { type_code = NPY_LONGDOUBLE };}; - template <> struct NumpyEquivalentType< std::complex<long double> > { enum { type_code = NPY_CLONGDOUBLE };}; - template <> struct NumpyEquivalentType<bool> { enum { type_code = NPY_BOOL };}; - template <> struct NumpyEquivalentType<int> { enum { type_code = NPY_INT };}; - template <> struct NumpyEquivalentType<long> { enum { type_code = NPY_LONG };}; - - template<typename Scalar> - bool isNumpyNativeType() - { - if((int)NumpyEquivalentType<Scalar>::type_code == NPY_USERDEF) - return false; - return true; - } - template<typename Scalar> bool np_type_is_convertible_into_scalar(const int np_type) { diff --git a/include/eigenpy/numpy.hpp b/include/eigenpy/numpy.hpp index 1631a79752cf1153589f0886fb3e4b25cf0fac38..bd68b7c04fded250a0a71075810a55d632517e45 100644 --- a/include/eigenpy/numpy.hpp +++ b/include/eigenpy/numpy.hpp @@ -31,6 +31,28 @@ namespace eigenpy { void EIGENPY_DLLAPI import_numpy(); int EIGENPY_DLLAPI PyArray_TypeNum(PyTypeObject * type); + + // By default, the Scalar is considered as a Python object + template <typename Scalar> struct NumpyEquivalentType { enum { type_code = NPY_USERDEF };}; + + template <> struct NumpyEquivalentType<float> { enum { type_code = NPY_FLOAT };}; + template <> struct NumpyEquivalentType< std::complex<float> > { enum { type_code = NPY_CFLOAT };}; + template <> struct NumpyEquivalentType<double> { enum { type_code = NPY_DOUBLE };}; + template <> struct NumpyEquivalentType< std::complex<double> > { enum { type_code = NPY_CDOUBLE };}; + template <> struct NumpyEquivalentType<long double> { enum { type_code = NPY_LONGDOUBLE };}; + template <> struct NumpyEquivalentType< std::complex<long double> > { enum { type_code = NPY_CLONGDOUBLE };}; + template <> struct NumpyEquivalentType<bool> { enum { type_code = NPY_BOOL };}; + template <> struct NumpyEquivalentType<int> { enum { type_code = NPY_INT };}; + template <> struct NumpyEquivalentType<long> { enum { type_code = NPY_LONG };}; + + template<typename Scalar> + bool isNumpyNativeType() + { + if((int)NumpyEquivalentType<Scalar>::type_code == NPY_USERDEF) + return false; + return true; + } + } #if defined _WIN32 || defined __CYGWIN__ diff --git a/include/eigenpy/register.hpp b/include/eigenpy/register.hpp index 58bb770a835e32fe732f83a2231c444e9241926b..2164449357dfff90a177066fe6ce7e746bbbd284 100644 --- a/include/eigenpy/register.hpp +++ b/include/eigenpy/register.hpp @@ -6,7 +6,7 @@ #define __eigenpy_register_hpp__ #include "eigenpy/fwd.hpp" -#include "eigenpy/numpy-type.hpp" +#include "eigenpy/numpy.hpp" #include "eigenpy/exception.hpp" #include <algorithm> @@ -36,6 +36,7 @@ namespace eigenpy template<typename Scalar> static PyTypeObject * getPyType() { + namespace bp = boost::python; if(!isNumpyNativeType<Scalar>()) { const PyTypeObject * const_py_type_ptr = bp::converter::registered_pytype<Scalar>::get_pytype();