forked from stack-of-tasks/eigenpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumpy.cpp
74 lines (57 loc) · 2.12 KB
/
numpy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright 2020-2022 INRIA
*/
#include "eigenpy/numpy.hpp"
namespace eigenpy {
void import_numpy() {
if (_import_array() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
}
}
int PyArray_TypeNum(PyTypeObject* type) {
return PyArray_TypeNumFromName(const_cast<char*>(type->tp_name));
}
#if defined _WIN32 || defined __CYGWIN__
bool call_PyArray_Check(PyObject* py_obj) { return PyArray_Check(py_obj); }
PyObject* call_PyArray_SimpleNew(int nd, npy_intp* shape, int np_type) {
return PyArray_SimpleNew(nd, shape, np_type);
}
PyObject* call_PyArray_New(PyTypeObject* py_type_ptr, int nd, npy_intp* shape,
int np_type, void* data_ptr, int options) {
return PyArray_New(py_type_ptr, nd, shape, np_type, NULL, data_ptr, 0,
options, NULL);
}
PyObject* call_PyArray_New(PyTypeObject* py_type_ptr, int nd, npy_intp* shape,
int np_type, npy_intp* strides, void* data_ptr,
int options) {
return PyArray_New(py_type_ptr, nd, shape, np_type, strides, data_ptr, 0,
options, NULL);
}
int call_PyArray_ObjectType(PyObject* obj, int val) {
return PyArray_ObjectType(obj, val);
}
PyTypeObject* getPyArrayType() { return &PyArray_Type; }
PyArray_Descr* call_PyArray_DescrFromType(int typenum) {
return PyArray_DescrFromType(typenum);
}
void call_PyArray_InitArrFuncs(PyArray_ArrFuncs* funcs) {
PyArray_InitArrFuncs(funcs);
}
int call_PyArray_RegisterDataType(PyArray_Descr* dtype) {
return PyArray_RegisterDataType(dtype);
}
PyArray_Descr* call_PyArray_MinScalarType(PyArrayObject* arr) {
return PyArray_MinScalarType(arr);
}
int call_PyArray_RegisterCanCast(PyArray_Descr* descr, int totype,
NPY_SCALARKIND scalar) {
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
} // namespace eigenpy