From d1b68776640265bbcfb15083ec91557195728b7b Mon Sep 17 00:00:00 2001 From: Justin Carpentier <justin.carpentier@inria.fr> Date: Fri, 30 Jul 2021 15:33:59 +0200 Subject: [PATCH] core: export call_PyArray_RegisterCastFunc Needed by Windows --- include/eigenpy/numpy.hpp | 3 +++ include/eigenpy/user-type.hpp | 14 +++++++------- src/numpy.cpp | 9 +++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/eigenpy/numpy.hpp b/include/eigenpy/numpy.hpp index db64992..8abb4c9 100644 --- a/include/eigenpy/numpy.hpp +++ b/include/eigenpy/numpy.hpp @@ -83,6 +83,8 @@ namespace eigenpy EIGENPY_DLLAPI int call_PyArray_RegisterCanCast(PyArray_Descr *descr, int totype, NPY_SCALARKIND scalar); EIGENPY_DLLAPI PyArray_Descr * call_PyArray_MinScalarType(PyArrayObject *arr); + + EIGENPY_DLLAPI int call_PyArray_RegisterCastFunc(PyArray_Descr* descr, int totype, PyArray_VectorUnaryFunc* castfunc); } #else #define call_PyArray_Check(py_obj) PyArray_Check(py_obj) @@ -95,6 +97,7 @@ namespace eigenpy #define call_PyArray_InitArrFuncs(funcs) PyArray_InitArrFuncs(funcs) #define call_PyArray_RegisterDataType(dtype) PyArray_RegisterDataType(dtype) #define call_PyArray_RegisterCanCast(descr,totype,scalar) PyArray_RegisterCanCast(descr,totype,scalar) + #define call_PyArray_RegisterCastFunc(descr,totype,castfunc) PyArray_RegisterCastFunc(descr,totype,castfunc) #endif #endif // ifndef __eigenpy_numpy_hpp__ diff --git a/include/eigenpy/user-type.hpp b/include/eigenpy/user-type.hpp index 50fb676..bbd49c8 100644 --- a/include/eigenpy/user-type.hpp +++ b/include/eigenpy/user-type.hpp @@ -257,11 +257,11 @@ namespace eigenpy // PyTypeObject * to_py_type = Register::getPyType<To>(); int to_typenum = Register::getTypeCode<To>(); assert(to_typenum >= 0 && "to_typenum is not valid"); - assert(from_array_descr != NULL && "to_typenum is not valid"); + assert(from_array_descr != NULL && "from_array_descr is not valid"); - if(PyArray_RegisterCastFunc(from_array_descr, - to_typenum, - static_cast<PyArray_VectorUnaryFunc *>(&eigenpy::internal::cast<From,To>)) < 0) + if(call_PyArray_RegisterCastFunc(from_array_descr, + to_typenum, + static_cast<PyArray_VectorUnaryFunc *>(&eigenpy::internal::cast<From,To>)) < 0) { std::stringstream ss; ss @@ -274,9 +274,9 @@ namespace eigenpy return false; } - if (safe && PyArray_RegisterCanCast(from_array_descr, - to_typenum, - NPY_NOSCALAR) < 0) + if (safe && call_PyArray_RegisterCanCast(from_array_descr, + to_typenum, + NPY_NOSCALAR) < 0) { std::stringstream ss; ss diff --git a/src/numpy.cpp b/src/numpy.cpp index fc132c9..5cd2ef5 100644 --- a/src/numpy.cpp +++ b/src/numpy.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2020 INRIA + * Copyright 2020-2021 INRIA */ #include "eigenpy/numpy.hpp" @@ -68,6 +68,11 @@ namespace eigenpy { return PyArray_RegisterCanCast(descr,totype,scalar); } - + + int call_PyArray_RegisterCastFunc(PyArray_Descr* descr, int totype, PyArray_VectorUnaryFunc* castfunc) + { + return PyArray_RegisterCastFunc(descr,totype,castfunc); + } + #endif } -- GitLab