Skip to content

Commit c3e322e

Browse files
committed
core: fix user declaration according to new NumPy API 1.20
1 parent 4879a79 commit c3e322e

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

include/eigenpy/numpy.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
#if defined _WIN32 || defined __CYGWIN__
2323
#define EIGENPY_GET_PY_ARRAY_TYPE(array) \
24-
call_PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0)
24+
call_PyArray_MinScalarType(array)->type_num
2525
#else
2626
#define EIGENPY_GET_PY_ARRAY_TYPE(array) \
27-
PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0)
27+
PyArray_MinScalarType(array)->type_num
2828
#endif
2929

3030
namespace eigenpy
@@ -51,6 +51,10 @@ namespace eigenpy
5151
EIGENPY_DLLAPI void call_PyArray_InitArrFuncs(PyArray_ArrFuncs * funcs);
5252

5353
EIGENPY_DLLAPI int call_PyArray_RegisterDataType(PyArray_Descr * dtype);
54+
55+
EIGENPY_DLLAPI int call_PyArray_RegisterCanCast(PyArray_Descr *descr, int totype, NPY_SCALARKIND scalar);
56+
57+
EIGENPY_DLLAPI PyArray_Descr * call_PyArray_MinScalarType(PyArrayObject *arr);
5458
}
5559
#else
5660
#define call_PyArray_Check(py_obj) PyArray_Check(py_obj)
@@ -59,8 +63,10 @@ namespace eigenpy
5963
PyArray_New(py_type_ptr,nd,shape,np_type,NULL,data_ptr,0,options,NULL)
6064
#define getPyArrayType() &PyArray_Type
6165
#define call_PyArray_DescrFromType(typenum) PyArray_DescrFromType(typenum)
66+
#define call_PyArray_MinScalarType(py_arr) PyArray_MinScalarType(py_arr)
6267
#define call_PyArray_InitArrFuncs(funcs) PyArray_InitArrFuncs(funcs)
63-
#define call_PyArray_RegisterDataType(dtype) PyArray_RegisterDataType(dtype)
68+
#define call_PyArray_RegisterDataType(dtype) PyArray_RegisterDataType(dtype)
69+
#define call_PyArray_RegisterCanCast(descr,totype,scalar) PyArray_RegisterCanCast(descr,totype,scalar)
6470
#endif
6571

6672
#endif // ifndef __eigenpy_numpy_hpp__

include/eigenpy/user-type.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ namespace eigenpy
198198
copyswap, copyswapn,
199199
dotfunc);
200200

201+
call_PyArray_RegisterCanCast(call_PyArray_DescrFromType(NPY_OBJECT),
202+
code, NPY_NOSCALAR);
203+
201204
return code;
202205
}
203206

src/numpy.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ namespace eigenpy
5858
{
5959
return PyArray_RegisterDataType(dtype);
6060
}
61+
62+
PyArray_Descr * call_PyArray_MinScalarType(PyArrayObject * arr)
63+
{
64+
return PyArray_MinScalarType(arr);
65+
}
66+
67+
int call_PyArray_RegisterCanCast(PyArray_Descr *descr, int totype, NPY_SCALARKIND scalar)
68+
{
69+
return PyArray_RegisterCanCast(descr,totype,scalar);
70+
}
6171

6272
#endif
6373
}

0 commit comments

Comments
 (0)