5 #ifndef __eigenpy_numpy_hpp__
6 #define __eigenpy_numpy_hpp__
8 #include "eigenpy/config.hpp"
10 #ifndef PY_ARRAY_UNIQUE_SYMBOL
11 #define PY_ARRAY_UNIQUE_SYMBOL EIGENPY_ARRAY_API
17 #define NPY_API_SYMBOL_ATTRIBUTE EIGENPY_DLLAPI
19 #include <numpy/numpyconfig.h>
20 #ifdef NPY_1_8_API_VERSION
21 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
28 #if NPY_ABI_VERSION < 0x02000000
29 #define PyArray_DescrProto PyArray_Descr
32 #include <numpy/ndarrayobject.h>
33 #include <numpy/ufuncobject.h>
35 #if NPY_ABI_VERSION < 0x02000000
44 #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
48 #define Py_SET_TYPE(o, type) _Py_SET_TYPE((PyObject*)(o), type)
51 #if defined _WIN32 || defined __CYGWIN__
52 #define EIGENPY_GET_PY_ARRAY_TYPE(array) \
53 call_PyArray_MinScalarType(array)->type_num
55 #define EIGENPY_GET_PY_ARRAY_TYPE(array) PyArray_MinScalarType(array)->type_num
65 template <
typename Scalar,
typename Enable =
void>
108 #if defined _WIN32 || defined __CYGWIN__
111 struct NumpyEquivalentType<long> {
115 struct NumpyEquivalentType<unsigned long> {
132 #if defined __APPLE__
135 struct NumpyEquivalentType<long> {
139 struct NumpyEquivalentType<unsigned long> {
147 #if defined __linux__
149 #include <type_traits>
151 template <
typename Scalar>
152 struct NumpyEquivalentType<
154 typename std::enable_if<!std::is_same<int64_t, long long>::value &&
155 std::is_same<Scalar, long long>::value>::type> {
158 template <
typename Scalar>
159 struct NumpyEquivalentType<
160 Scalar, typename std::enable_if<
161 !std::is_same<uint64_t, unsigned long long>::value &&
162 std::is_same<Scalar, unsigned long long>::value>::type> {
194 template <
typename Scalar>
203 #if defined _WIN32 || defined __CYGWIN__
209 EIGENPY_DLLAPI PyObject*
call_PyArray_New(PyTypeObject* py_type_ptr,
int nd,
210 npy_intp* shape,
int np_type,
211 void* data_ptr,
int options);
213 EIGENPY_DLLAPI PyObject*
call_PyArray_New(PyTypeObject* py_type_ptr,
int nd,
214 npy_intp* shape,
int np_type,
215 npy_intp* strides,
void* data_ptr,
230 NPY_SCALARKIND scalar);
235 PyArray_Descr* descr,
int totype, PyArray_VectorUnaryFunc* castfunc);
238 return PyArray_Check(py_obj);
242 return PyArray_SimpleNew(nd, shape, np_type);
246 npy_intp* shape,
int np_type,
void* data_ptr,
248 return PyArray_New(py_type_ptr, nd, shape, np_type, NULL, data_ptr, 0,
253 npy_intp* shape,
int np_type,
254 npy_intp* strides,
void* data_ptr,
256 return PyArray_New(py_type_ptr, nd, shape, np_type, strides, data_ptr, 0,
261 return PyArray_ObjectType(obj,
val);
267 return PyArray_DescrFromType(typenum);
271 PyArray_InitArrFuncs(funcs);
275 return PyArray_RegisterDataType(dtype);
279 return PyArray_MinScalarType(arr);
283 NPY_SCALARKIND scalar) {
284 return PyArray_RegisterCanCast(descr, totype, scalar);
288 PyArray_VectorUnaryFunc* castfunc) {
289 return PyArray_RegisterCastFunc(descr, totype, castfunc);
294 #endif // ifndef __eigenpy_numpy_hpp__