Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
fortranobject.h174 linesDownload Raw Back to src
1#ifndef Py_FORTRANOBJECT_H
2#define Py_FORTRANOBJECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#include <Python.h>
8
9#ifndef NPY_NO_DEPRECATED_API
10#define NPY_NO_DEPRECATED_API NPY_API_VERSION
11#endif
12#ifdef FORTRANOBJECT_C
13#define NO_IMPORT_ARRAY
14#endif
15#define PY_ARRAY_UNIQUE_SYMBOL _npy_f2py_ARRAY_API
16#include "numpy/arrayobject.h"
17#include "numpy/npy_3kcompat.h"
18
19#ifdef F2PY_REPORT_ATEXIT
20#include <sys/timeb.h>
21// clang-format off
22extern void f2py_start_clock(void);
23extern void f2py_stop_clock(void);
24extern void f2py_start_call_clock(void);
25extern void f2py_stop_call_clock(void);
26extern void f2py_cb_start_clock(void);
27extern void f2py_cb_stop_clock(void);
28extern void f2py_cb_start_call_clock(void);
29extern void f2py_cb_stop_call_clock(void);
30extern void f2py_report_on_exit(int, void *);
31// clang-format on
32#endif
33
34#ifdef DMALLOC
35#include "dmalloc.h"
36#endif
37
38/* Fortran object interface */
39
40/*
41123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
42
43PyFortranObject represents various Fortran objects:
44Fortran (module) routines, COMMON blocks, module data.
45
46Author: Pearu Peterson <pearu@cens.ioc.ee>
47*/
48
49#define F2PY_MAX_DIMS 40
50#define F2PY_MESSAGE_BUFFER_SIZE 300  // Increase on "stack smashing detected"
51
52typedef void (*f2py_set_data_func)(char *, npy_intp *);
53typedef void (*f2py_void_func)(void);
54typedef void (*f2py_init_func)(int *, npy_intp *, f2py_set_data_func, int *);
55
56/*typedef void* (*f2py_c_func)(void*,...);*/
57
58typedef void *(*f2pycfunc)(void);
59
60typedef struct {
61    char *name; /* attribute (array||routine) name */
62    int rank;   /* array rank, 0 for scalar, max is F2PY_MAX_DIMS,
63                   || rank=-1 for Fortran routine */
64    struct {
65        npy_intp d[F2PY_MAX_DIMS];
66    } dims;              /* dimensions of the array, || not used */
67    int type;            /* PyArray_<type> || not used */
68    int elsize;                /* Element size || not used */
69    char *data;          /* pointer to array || Fortran routine */
70    f2py_init_func func; /* initialization function for
71                            allocatable arrays:
72                            func(&rank,dims,set_ptr_func,name,len(name))
73                            || C/API wrapper for Fortran routine */
74    char *doc;           /* documentation string; only recommended
75                            for routines. */
76} FortranDataDef;
77
78typedef struct {
79    PyObject_HEAD
80    int len;              /* Number of attributes */
81    FortranDataDef *defs; /* An array of FortranDataDef's */
82    PyObject *dict;       /* Fortran object attribute dictionary */
83} PyFortranObject;
84
85#define PyFortran_Check(op) (Py_TYPE(op) == &PyFortran_Type)
86#define PyFortran_Check1(op) (0 == strcmp(Py_TYPE(op)->tp_name, "fortran"))
87
88extern PyTypeObject PyFortran_Type;
89extern int
90F2PyDict_SetItemString(PyObject *dict, char *name, PyObject *obj);
91extern PyObject *
92PyFortranObject_New(FortranDataDef *defs, f2py_void_func init);
93extern PyObject *
94PyFortranObject_NewAsAttr(FortranDataDef *defs);
95
96PyObject *
97F2PyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *));
98void *
99F2PyCapsule_AsVoidPtr(PyObject *obj);
100int
101F2PyCapsule_Check(PyObject *ptr);
102
103extern void *
104F2PySwapThreadLocalCallbackPtr(char *key, void *ptr);
105extern void *
106F2PyGetThreadLocalCallbackPtr(char *key);
107
108#define ISCONTIGUOUS(m) (PyArray_FLAGS(m) & NPY_ARRAY_C_CONTIGUOUS)
109#define F2PY_INTENT_IN 1
110#define F2PY_INTENT_INOUT 2
111#define F2PY_INTENT_OUT 4
112#define F2PY_INTENT_HIDE 8
113#define F2PY_INTENT_CACHE 16
114#define F2PY_INTENT_COPY 32
115#define F2PY_INTENT_C 64
116#define F2PY_OPTIONAL 128
117#define F2PY_INTENT_INPLACE 256
118#define F2PY_INTENT_ALIGNED4 512
119#define F2PY_INTENT_ALIGNED8 1024
120#define F2PY_INTENT_ALIGNED16 2048
121
122#define ARRAY_ISALIGNED(ARR, SIZE) ((size_t)(PyArray_DATA(ARR)) % (SIZE) == 0)
123#define F2PY_ALIGN4(intent) (intent & F2PY_INTENT_ALIGNED4)
124#define F2PY_ALIGN8(intent) (intent & F2PY_INTENT_ALIGNED8)
125#define F2PY_ALIGN16(intent) (intent & F2PY_INTENT_ALIGNED16)
126
127#define F2PY_GET_ALIGNMENT(intent) \
128    (F2PY_ALIGN4(intent)           \
129             ? 4                   \
130             : (F2PY_ALIGN8(intent) ? 8 : (F2PY_ALIGN16(intent) ? 16 : 1)))
131#define F2PY_CHECK_ALIGNMENT(arr, intent) \
132    ARRAY_ISALIGNED(arr, F2PY_GET_ALIGNMENT(intent))
133#define F2PY_ARRAY_IS_CHARACTER_COMPATIBLE(arr) ((PyArray_DESCR(arr)->type_num == NPY_STRING && PyArray_ITEMSIZE(arr) >= 1) \
134                                                 || PyArray_DESCR(arr)->type_num == NPY_UINT8)
135#define F2PY_IS_UNICODE_ARRAY(arr) (PyArray_DESCR(arr)->type_num == NPY_UNICODE)
136
137extern PyArrayObject *
138ndarray_from_pyobj(const int type_num, const int elsize_, npy_intp *dims,
139                   const int rank, const int intent, PyObject *obj,
140                   const char *errmess);
141
142extern PyArrayObject *
143array_from_pyobj(const int type_num, npy_intp *dims, const int rank,
144                 const int intent, PyObject *obj);
145extern int
146copy_ND_array(const PyArrayObject *in, PyArrayObject *out);
147
148#ifdef DEBUG_COPY_ND_ARRAY
149extern void
150dump_attrs(const PyArrayObject *arr);
151#endif
152
153  extern int f2py_describe(PyObject *obj, char *buf);
154
155  /* Utility CPP macros and functions that can be used in signature file
156     expressions. See signature-file.rst for documentation.
157  */
158
159#define f2py_itemsize(var) (PyArray_ITEMSIZE(capi_ ## var ## _as_array))
160#define f2py_size(var, ...) f2py_size_impl((PyArrayObject *)(capi_ ## var ## _as_array), ## __VA_ARGS__, -1)
161#define f2py_rank(var) var ## _Rank
162#define f2py_shape(var,dim) var ## _Dims[dim]
163#define f2py_len(var) f2py_shape(var,0)
164#define f2py_fshape(var,dim) f2py_shape(var,rank(var)-dim-1)
165#define f2py_flen(var) f2py_fshape(var,0)
166#define f2py_slen(var) capi_ ## var ## _len
167
168  extern npy_intp f2py_size_impl(PyArrayObject* var, ...);
169
170#ifdef __cplusplus
171}
172#endif
173#endif /* !Py_FORTRANOBJECT_H */
174 
codekingpro/portable-devtools · Team Ai