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
16 #define NPY_API_SYMBOL_ATTRIBUTE EIGENPY_DLLAPI
27 #include <boost/python/detail/wrap_python.hpp>
29 #include <numpy/numpyconfig.h>
30 #ifdef NPY_1_8_API_VERSION
31 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
36 #if NPY_ABI_VERSION < 0x02000000
37 #define PyArray_DescrProto PyArray_Descr
40 #include <numpy/ndarrayobject.h>
41 #include <numpy/ufuncobject.h>
43 #if NPY_ABI_VERSION < 0x02000000
52 #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
56 #define Py_SET_TYPE(o, type) _Py_SET_TYPE((PyObject*)(o), type)
59 #if defined _WIN32 || defined __CYGWIN__
60 #define EIGENPY_GET_PY_ARRAY_TYPE(array) \
61 call_PyArray_MinScalarType(array)->type_num
63 #define EIGENPY_GET_PY_ARRAY_TYPE(array) PyArray_MinScalarType(array)->type_num
73 template <
typename Scalar,
typename Enable =
void>
116 #if defined _WIN32 || defined __CYGWIN__
119 struct NumpyEquivalentType<long> {
123 struct NumpyEquivalentType<unsigned long> {
140 #if defined __APPLE__
143 struct NumpyEquivalentType<long> {
147 struct NumpyEquivalentType<unsigned long> {
155 #if defined __linux__
157 #include <type_traits>
159 template <
typename Scalar>
160 struct NumpyEquivalentType<
162 typename std::enable_if<!std::is_same<int64_t, long long>::value &&
163 std::is_same<Scalar, long long>::value>::type> {
166 template <
typename Scalar>
167 struct NumpyEquivalentType<
168 Scalar, typename std::enable_if<
169 !std::is_same<uint64_t, unsigned long long>::value &&
170 std::is_same<Scalar, unsigned long long>::value>::type> {
202 template <
typename Scalar>
211 #if defined _WIN32 || defined __CYGWIN__
217 EIGENPY_DLLAPI PyObject*
call_PyArray_New(PyTypeObject* py_type_ptr,
int nd,
218 npy_intp* shape,
int np_type,
219 void* data_ptr,
int options);
221 EIGENPY_DLLAPI PyObject*
call_PyArray_New(PyTypeObject* py_type_ptr,
int nd,
222 npy_intp* shape,
int np_type,
223 npy_intp* strides,
void* data_ptr,
238 NPY_SCALARKIND scalar);
243 PyArray_Descr* descr,
int totype, PyArray_VectorUnaryFunc* castfunc);
246 return PyArray_Check(py_obj);
250 return PyArray_SimpleNew(nd, shape, np_type);
254 npy_intp* shape,
int np_type,
void* data_ptr,
256 return PyArray_New(py_type_ptr, nd, shape, np_type, NULL, data_ptr, 0,
261 npy_intp* shape,
int np_type,
262 npy_intp* strides,
void* data_ptr,
264 return PyArray_New(py_type_ptr, nd, shape, np_type, strides, data_ptr, 0,
269 return PyArray_ObjectType(obj,
val);
275 return PyArray_DescrFromType(typenum);
279 PyArray_InitArrFuncs(funcs);
283 return PyArray_RegisterDataType(dtype);
287 return PyArray_MinScalarType(arr);
291 NPY_SCALARKIND scalar) {
292 return PyArray_RegisterCanCast(descr, totype, scalar);
296 PyArray_VectorUnaryFunc* castfunc) {
297 return PyArray_RegisterCastFunc(descr, totype, castfunc);
302 #endif // ifndef __eigenpy_numpy_hpp__