fortranobject.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef Py_FORTRANOBJECT_H
  2. #define Py_FORTRANOBJECT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "Python.h"
  7. #ifdef FORTRANOBJECT_C
  8. #define NO_IMPORT_ARRAY
  9. #endif
  10. #define PY_ARRAY_UNIQUE_SYMBOL _npy_f2py_ARRAY_API
  11. #include "numpy/arrayobject.h"
  12. #include "numpy/npy_3kcompat.h"
  13. #ifdef F2PY_REPORT_ATEXIT
  14. #include <sys/timeb.h>
  15. extern void f2py_start_clock(void);
  16. extern void f2py_stop_clock(void);
  17. extern void f2py_start_call_clock(void);
  18. extern void f2py_stop_call_clock(void);
  19. extern void f2py_cb_start_clock(void);
  20. extern void f2py_cb_stop_clock(void);
  21. extern void f2py_cb_start_call_clock(void);
  22. extern void f2py_cb_stop_call_clock(void);
  23. extern void f2py_report_on_exit(int,void*);
  24. #endif
  25. #ifdef DMALLOC
  26. #include "dmalloc.h"
  27. #endif
  28. /* Fortran object interface */
  29. /*
  30. 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
  31. PyFortranObject represents various Fortran objects:
  32. Fortran (module) routines, COMMON blocks, module data.
  33. Author: Pearu Peterson <pearu@cens.ioc.ee>
  34. */
  35. #define F2PY_MAX_DIMS 40
  36. typedef void (*f2py_set_data_func)(char*,npy_intp*);
  37. typedef void (*f2py_void_func)(void);
  38. typedef void (*f2py_init_func)(int*,npy_intp*,f2py_set_data_func,int*);
  39. /*typedef void* (*f2py_c_func)(void*,...);*/
  40. typedef void *(*f2pycfunc)(void);
  41. typedef struct {
  42. char *name; /* attribute (array||routine) name */
  43. int rank; /* array rank, 0 for scalar, max is F2PY_MAX_DIMS,
  44. || rank=-1 for Fortran routine */
  45. struct {npy_intp d[F2PY_MAX_DIMS];} dims; /* dimensions of the array, || not used */
  46. int type; /* PyArray_<type> || not used */
  47. char *data; /* pointer to array || Fortran routine */
  48. f2py_init_func func; /* initialization function for
  49. allocatable arrays:
  50. func(&rank,dims,set_ptr_func,name,len(name))
  51. || C/API wrapper for Fortran routine */
  52. char *doc; /* documentation string; only recommended
  53. for routines. */
  54. } FortranDataDef;
  55. typedef struct {
  56. PyObject_HEAD
  57. int len; /* Number of attributes */
  58. FortranDataDef *defs; /* An array of FortranDataDef's */
  59. PyObject *dict; /* Fortran object attribute dictionary */
  60. } PyFortranObject;
  61. #define PyFortran_Check(op) (Py_TYPE(op) == &PyFortran_Type)
  62. #define PyFortran_Check1(op) (0==strcmp(Py_TYPE(op)->tp_name,"fortran"))
  63. extern PyTypeObject PyFortran_Type;
  64. extern int F2PyDict_SetItemString(PyObject* dict, char *name, PyObject *obj);
  65. extern PyObject * PyFortranObject_New(FortranDataDef* defs, f2py_void_func init);
  66. extern PyObject * PyFortranObject_NewAsAttr(FortranDataDef* defs);
  67. PyObject * F2PyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *));
  68. void * F2PyCapsule_AsVoidPtr(PyObject *obj);
  69. int F2PyCapsule_Check(PyObject *ptr);
  70. extern void *F2PySwapThreadLocalCallbackPtr(char *key, void *ptr);
  71. extern void *F2PyGetThreadLocalCallbackPtr(char *key);
  72. #define ISCONTIGUOUS(m) (PyArray_FLAGS(m) & NPY_ARRAY_C_CONTIGUOUS)
  73. #define F2PY_INTENT_IN 1
  74. #define F2PY_INTENT_INOUT 2
  75. #define F2PY_INTENT_OUT 4
  76. #define F2PY_INTENT_HIDE 8
  77. #define F2PY_INTENT_CACHE 16
  78. #define F2PY_INTENT_COPY 32
  79. #define F2PY_INTENT_C 64
  80. #define F2PY_OPTIONAL 128
  81. #define F2PY_INTENT_INPLACE 256
  82. #define F2PY_INTENT_ALIGNED4 512
  83. #define F2PY_INTENT_ALIGNED8 1024
  84. #define F2PY_INTENT_ALIGNED16 2048
  85. #define ARRAY_ISALIGNED(ARR, SIZE) ((size_t)(PyArray_DATA(ARR)) % (SIZE) == 0)
  86. #define F2PY_ALIGN4(intent) (intent & F2PY_INTENT_ALIGNED4)
  87. #define F2PY_ALIGN8(intent) (intent & F2PY_INTENT_ALIGNED8)
  88. #define F2PY_ALIGN16(intent) (intent & F2PY_INTENT_ALIGNED16)
  89. #define F2PY_GET_ALIGNMENT(intent) \
  90. (F2PY_ALIGN4(intent) ? 4 : \
  91. (F2PY_ALIGN8(intent) ? 8 : \
  92. (F2PY_ALIGN16(intent) ? 16 : 1) ))
  93. #define F2PY_CHECK_ALIGNMENT(arr, intent) ARRAY_ISALIGNED(arr, F2PY_GET_ALIGNMENT(intent))
  94. extern PyArrayObject* array_from_pyobj(const int type_num,
  95. npy_intp *dims,
  96. const int rank,
  97. const int intent,
  98. PyObject *obj);
  99. extern int copy_ND_array(const PyArrayObject *in, PyArrayObject *out);
  100. #ifdef DEBUG_COPY_ND_ARRAY
  101. extern void dump_attrs(const PyArrayObject* arr);
  102. #endif
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif /* !Py_FORTRANOBJECT_H */