numpy.hpp 2.33 KB
Newer Older
1
2
3
4
5
6
7
/*
 * Copyright 2020 INRIA
 */

#ifndef __eigenpy_numpy_hpp__
#define __eigenpy_numpy_hpp__

8
#include "eigenpy/fwd.hpp"
9

10
11
12
13
14
15
16
17
18
19
#ifndef PY_ARRAY_UNIQUE_SYMBOL
  #define PY_ARRAY_UNIQUE_SYMBOL EIGENPY_ARRAY_API
#endif

#include <numpy/numpyconfig.h>
#ifdef NPY_1_8_API_VERSION
  #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif

#include <numpy/noprefix.h>
Justin Carpentier's avatar
Justin Carpentier committed
20
#include <numpy/ufuncobject.h>
21

Justin Carpentier's avatar
Justin Carpentier committed
22
23
#if defined _WIN32 || defined __CYGWIN__
  #define EIGENPY_GET_PY_ARRAY_TYPE(array) \
24
    call_PyArray_MinScalarType(array)->type_num
Justin Carpentier's avatar
Justin Carpentier committed
25
26
#else
  #define EIGENPY_GET_PY_ARRAY_TYPE(array) \
27
    PyArray_MinScalarType(array)->type_num
Justin Carpentier's avatar
Justin Carpentier committed
28
#endif
29

30
31
namespace eigenpy
{
32
33
  void EIGENPY_DLLAPI import_numpy();
  int EIGENPY_DLLAPI PyArray_TypeNum(PyTypeObject * type);
34
35
}

Justin Carpentier's avatar
Justin Carpentier committed
36
37
38
#if defined _WIN32 || defined __CYGWIN__
namespace eigenpy
{
39
  EIGENPY_DLLAPI bool call_PyArray_Check(PyObject *);
40

41
  EIGENPY_DLLAPI PyObject* call_PyArray_SimpleNew(int nd, npy_intp * shape, int np_type);
Justin Carpentier's avatar
Justin Carpentier committed
42

43
  EIGENPY_DLLAPI PyObject* call_PyArray_New(PyTypeObject * py_type_ptr, int nd, npy_intp * shape, int np_type, void * data_ptr, int options);
Justin Carpentier's avatar
Justin Carpentier committed
44

45
  EIGENPY_DLLAPI int call_PyArray_ObjectType(PyObject *, int);
46

47
  EIGENPY_DLLAPI PyTypeObject * getPyArrayType();
48

49
  EIGENPY_DLLAPI PyArray_Descr * call_PyArray_DescrFromType(int typenum);
50

51
  EIGENPY_DLLAPI void call_PyArray_InitArrFuncs(PyArray_ArrFuncs * funcs);
52

53
  EIGENPY_DLLAPI int call_PyArray_RegisterDataType(PyArray_Descr * dtype);
54
55
56
57

  EIGENPY_DLLAPI int call_PyArray_RegisterCanCast(PyArray_Descr *descr, int totype, NPY_SCALARKIND scalar);

  EIGENPY_DLLAPI PyArray_Descr * call_PyArray_MinScalarType(PyArrayObject *arr);
Justin Carpentier's avatar
Justin Carpentier committed
58
59
}
#else
60
  #define call_PyArray_Check(py_obj) PyArray_Check(py_obj)
Justin Carpentier's avatar
Justin Carpentier committed
61
  #define call_PyArray_SimpleNew PyArray_SimpleNew
62
63
  #define call_PyArray_New(py_type_ptr,nd,shape,np_type,data_ptr,options) \
    PyArray_New(py_type_ptr,nd,shape,np_type,NULL,data_ptr,0,options,NULL)
64
  #define getPyArrayType() &PyArray_Type
65
  #define call_PyArray_DescrFromType(typenum) PyArray_DescrFromType(typenum)
66
  #define call_PyArray_MinScalarType(py_arr) PyArray_MinScalarType(py_arr)
67
  #define call_PyArray_InitArrFuncs(funcs) PyArray_InitArrFuncs(funcs)
68
69
  #define call_PyArray_RegisterDataType(dtype) PyArray_RegisterDataType(dtype)
  #define call_PyArray_RegisterCanCast(descr,totype,scalar) PyArray_RegisterCanCast(descr,totype,scalar)
Justin Carpentier's avatar
Justin Carpentier committed
70
71
#endif

72
#endif // ifndef __eigenpy_numpy_hpp__