numpy.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020-2022 INRIA
3  */
4 
5 #ifndef __eigenpy_numpy_hpp__
6 #define __eigenpy_numpy_hpp__
7 
8 #include "eigenpy/fwd.hpp"
9 
10 #ifndef PY_ARRAY_UNIQUE_SYMBOL
11 #define PY_ARRAY_UNIQUE_SYMBOL EIGENPY_ARRAY_API
12 #endif
13 
14 #include <numpy/numpyconfig.h>
15 #ifdef NPY_1_8_API_VERSION
16 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
17 #endif
18 
19 #include <numpy/ndarrayobject.h>
20 #include <numpy/ufuncobject.h>
21 
22 #if defined _WIN32 || defined __CYGWIN__
23 #define EIGENPY_GET_PY_ARRAY_TYPE(array) \
24  call_PyArray_MinScalarType(array)->type_num
25 #else
26 #define EIGENPY_GET_PY_ARRAY_TYPE(array) PyArray_MinScalarType(array)->type_num
27 #endif
28 
29 namespace eigenpy {
30 void EIGENPY_DLLAPI import_numpy();
31 int EIGENPY_DLLAPI PyArray_TypeNum(PyTypeObject* type);
32 
33 // By default, the Scalar is considered as a Python object
34 template <typename Scalar>
36  enum { type_code = NPY_USERDEF };
37 };
38 
39 template <>
40 struct NumpyEquivalentType<float> {
41  enum { type_code = NPY_FLOAT };
42 };
43 template <>
44 struct NumpyEquivalentType<std::complex<float> > {
45  enum { type_code = NPY_CFLOAT };
46 };
47 template <>
48 struct NumpyEquivalentType<double> {
49  enum { type_code = NPY_DOUBLE };
50 };
51 template <>
52 struct NumpyEquivalentType<std::complex<double> > {
53  enum { type_code = NPY_CDOUBLE };
54 };
55 template <>
56 struct NumpyEquivalentType<long double> {
57  enum { type_code = NPY_LONGDOUBLE };
58 };
59 template <>
60 struct NumpyEquivalentType<std::complex<long double> > {
61  enum { type_code = NPY_CLONGDOUBLE };
62 };
63 template <>
64 struct NumpyEquivalentType<bool> {
65  enum { type_code = NPY_BOOL };
66 };
67 template <>
68 struct NumpyEquivalentType<int> {
69  enum { type_code = NPY_INT };
70 };
71 template <>
72 struct NumpyEquivalentType<unsigned int> {
73  enum { type_code = NPY_UINT };
74 };
75 template <>
76 struct NumpyEquivalentType<long> {
77  enum { type_code = NPY_LONG };
78 };
79 // #if defined _WIN32 || defined __CYGWIN__
80 template <>
81 struct NumpyEquivalentType<long long> {
82  enum { type_code = NPY_LONGLONG };
83 };
84 // #else
85 // template <> struct NumpyEquivalentType<long long> { enum { type_code =
86 // NPY_LONGLONG };};
87 // #endif
88 template <>
89 struct NumpyEquivalentType<unsigned long> {
90  enum { type_code = NPY_ULONG };
91 };
92 
93 template <typename Scalar>
95  if ((int)NumpyEquivalentType<Scalar>::type_code == NPY_USERDEF) return false;
96  return true;
97 }
98 
99 } // namespace eigenpy
100 
101 namespace eigenpy {
102 #if defined _WIN32 || defined __CYGWIN__
103 EIGENPY_DLLAPI bool call_PyArray_Check(PyObject*);
104 
105 EIGENPY_DLLAPI PyObject* call_PyArray_SimpleNew(int nd, npy_intp* shape,
106  int np_type);
107 
108 EIGENPY_DLLAPI PyObject* call_PyArray_New(PyTypeObject* py_type_ptr, int nd,
109  npy_intp* shape, int np_type,
110  void* data_ptr, int options);
111 
112 EIGENPY_DLLAPI PyObject* call_PyArray_New(PyTypeObject* py_type_ptr, int nd,
113  npy_intp* shape, int np_type,
114  npy_intp* strides, void* data_ptr,
115  int options);
116 
117 EIGENPY_DLLAPI int call_PyArray_ObjectType(PyObject*, int);
118 
119 EIGENPY_DLLAPI PyTypeObject* getPyArrayType();
120 
121 EIGENPY_DLLAPI PyArray_Descr* call_PyArray_DescrFromType(int typenum);
122 
123 EIGENPY_DLLAPI void call_PyArray_InitArrFuncs(PyArray_ArrFuncs* funcs);
124 
125 EIGENPY_DLLAPI int call_PyArray_RegisterDataType(PyArray_Descr* dtype);
126 
127 EIGENPY_DLLAPI int call_PyArray_RegisterCanCast(PyArray_Descr* descr,
128  int totype,
129  NPY_SCALARKIND scalar);
130 
131 EIGENPY_DLLAPI PyArray_Descr* call_PyArray_MinScalarType(PyArrayObject* arr);
132 
133 EIGENPY_DLLAPI int call_PyArray_RegisterCastFunc(
134  PyArray_Descr* descr, int totype, PyArray_VectorUnaryFunc* castfunc);
135 #else
136 inline bool call_PyArray_Check(PyObject* py_obj) {
137  return PyArray_Check(py_obj);
138 }
139 
140 inline PyObject* call_PyArray_SimpleNew(int nd, npy_intp* shape, int np_type) {
141  return PyArray_SimpleNew(nd, shape, np_type);
142 }
143 
144 inline PyObject* call_PyArray_New(PyTypeObject* py_type_ptr, int nd,
145  npy_intp* shape, int np_type, void* data_ptr,
146  int options) {
147  return PyArray_New(py_type_ptr, nd, shape, np_type, NULL, data_ptr, 0,
148  options, NULL);
149 }
150 
151 inline PyObject* call_PyArray_New(PyTypeObject* py_type_ptr, int nd,
152  npy_intp* shape, int np_type,
153  npy_intp* strides, void* data_ptr,
154  int options) {
155  return PyArray_New(py_type_ptr, nd, shape, np_type, strides, data_ptr, 0,
156  options, NULL);
157 }
158 
159 inline int call_PyArray_ObjectType(PyObject* obj, int val) {
160  return PyArray_ObjectType(obj, val);
161 }
162 
163 inline PyTypeObject* getPyArrayType() { return &PyArray_Type; }
164 
165 inline PyArray_Descr* call_PyArray_DescrFromType(int typenum) {
166  return PyArray_DescrFromType(typenum);
167 }
168 
169 inline void call_PyArray_InitArrFuncs(PyArray_ArrFuncs* funcs) {
170  PyArray_InitArrFuncs(funcs);
171 }
172 
173 inline int call_PyArray_RegisterDataType(PyArray_Descr* dtype) {
174  return PyArray_RegisterDataType(dtype);
175 }
176 
177 inline PyArray_Descr* call_PyArray_MinScalarType(PyArrayObject* arr) {
178  return PyArray_MinScalarType(arr);
179 }
180 
181 inline int call_PyArray_RegisterCanCast(PyArray_Descr* descr, int totype,
182  NPY_SCALARKIND scalar) {
183  return PyArray_RegisterCanCast(descr, totype, scalar);
184 }
185 
186 inline int call_PyArray_RegisterCastFunc(PyArray_Descr* descr, int totype,
187  PyArray_VectorUnaryFunc* castfunc) {
188  return PyArray_RegisterCastFunc(descr, totype, castfunc);
189 }
190 #endif
191 } // namespace eigenpy
192 
193 #endif // ifndef __eigenpy_numpy_hpp__
bool call_PyArray_Check(PyObject *py_obj)
Definition: numpy.hpp:136
bool isNumpyNativeType()
Definition: numpy.hpp:94
void EIGENPY_DLLAPI import_numpy()
Definition: numpy.cpp:8
PyObject * call_PyArray_SimpleNew(int nd, npy_intp *shape, int np_type)
Definition: numpy.hpp:140
PyObject * call_PyArray_New(PyTypeObject *py_type_ptr, int nd, npy_intp *shape, int np_type, void *data_ptr, int options)
Definition: numpy.hpp:144
int call_PyArray_RegisterCastFunc(PyArray_Descr *descr, int totype, PyArray_VectorUnaryFunc *castfunc)
Definition: numpy.hpp:186
int call_PyArray_RegisterCanCast(PyArray_Descr *descr, int totype, NPY_SCALARKIND scalar)
Definition: numpy.hpp:181
PyArray_Descr * call_PyArray_MinScalarType(PyArrayObject *arr)
Definition: numpy.hpp:177
int call_PyArray_ObjectType(PyObject *obj, int val)
Definition: numpy.hpp:159
int call_PyArray_RegisterDataType(PyArray_Descr *dtype)
Definition: numpy.hpp:173
PyTypeObject * getPyArrayType()
Definition: numpy.hpp:163
PyArray_Descr * call_PyArray_DescrFromType(int typenum)
Definition: numpy.hpp:165
void call_PyArray_InitArrFuncs(PyArray_ArrFuncs *funcs)
Definition: numpy.hpp:169
int EIGENPY_DLLAPI PyArray_TypeNum(PyTypeObject *type)
Definition: numpy.cpp:16


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Fri Jun 2 2023 02:10:26