#ifndef Py_ARRAYOBJECT_H #define Py_ARRAYOBJECT_H #ifdef __cplusplus extern "C" { #endif #define MAX_ELSIZE 16 enum PyArray_TYPES { PyArray_CHAR, PyArray_UBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_INT, PyArray_LONG, PyArray_FLOAT, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_NTYPES, PyArray_NOTYPE}; typedef void (PyArray_VectorUnaryFunc) Py_FPROTO((char *, int, char *, int, int)); typedef PyObject * (PyArray_GetItemFunc) Py_FPROTO((char *)); typedef int (PyArray_SetItemFunc) Py_FPROTO((PyObject *, char *)); typedef struct { PyArray_VectorUnaryFunc *cast[PyArray_NTYPES]; /* Functions to cast to */ /* all other types */ PyArray_GetItemFunc *getitem; PyArray_SetItemFunc *setitem; int type_num, elsize; char *one, *zero; char type; } PyArray_Descr; #define CONTIGUOUS 1 #define OWN_DIMENSIONS 2 #define OWN_STRIDES 4 #define OWN_DATA 8 typedef struct { PyObject_HEAD char *data; int nd; int *dimensions, *strides; PyObject *base; PyArray_Descr *descr; int flags; #ifndef NUMPY_NOEXTRA PyObject* attributes; /* for user-defined information */ #endif } PyArrayObject; /* * C API */ /* Type definitions */ #define PyArray_Type_NUM 0 /* Function definitions */ /* The following are not intended for use in user code, only needed by umath. */ /* If you write your own match library, you might want this function. */ #define PyArray_SetNumericOps_RET int #define PyArray_SetNumericOps_PROTO Py_FPROTO((PyObject *)) #define PyArray_SetNumericOps_NUM 1 #define PyArray_INCREF_RET int #define PyArray_INCREF_PROTO Py_FPROTO((PyArrayObject *ap)) #define PyArray_INCREF_NUM 2 #define PyArray_XDECREF_RET int #define PyArray_XDECREF_PROTO Py_FPROTO((PyArrayObject *ap)) #define PyArray_XDECREF_NUM 3 /* Export the array error object. Is this a good idea? */ #define PyArrayError_RET PyObject * #define PyArrayError_PROTO Py_FPROTO(()) #define PyArrayError_NUM 4 /* Set the array print function to be a python function */ #define PyArray_SetStringFunction_RET void #define PyArray_SetStringFunction_PROTO Py_FPROTO((PyObject *op, int repr)) #define PyArray_SetStringFunction_NUM 5 /* Get the PyArray_Descr structure for a typecode */ #define PyArray_DescrFromType_RET PyArray_Descr * #define PyArray_DescrFromType_PROTO Py_FPROTO((int)) #define PyArray_DescrFromType_NUM 6 /* Cast an array to a different type */ #define PyArray_Cast_RET PyObject * #define PyArray_Cast_PROTO Py_FPROTO((PyArrayObject *, int)) #define PyArray_Cast_NUM 7 /* Check the type coercion rules */ #define PyArray_CanCastSafely_RET int #define PyArray_CanCastSafely_PROTO Py_FPROTO((int fromtype, int totype)) #define PyArray_CanCastSafely_NUM 8 /* Return the typecode to use for an object if it was an array */ #define PyArray_ObjectType_RET int #define PyArray_ObjectType_PROTO Py_FPROTO((PyObject *, int)) #define PyArray_ObjectType_NUM 9 #define _PyArray_multiply_list_RET int #define _PyArray_multiply_list_PROTO Py_FPROTO((int *lp, int n)) #define _PyArray_multiply_list_NUM 10 /* The following defines the C API for the array object for most users */ #define PyArray_SIZE(mp) (_PyArray_multiply_list((mp)->dimensions, (mp)->nd)) #define PyArray_NBYTES(mp) ((mp)->descr->elsize * PyArray_SIZE(mp)) /* Obviously this needs some work. */ #define PyArray_ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS) /* Return the size in number of items of an array */ #define PyArray_Size_RET int #define PyArray_Size_PROTO Py_FPROTO((PyObject *)) #define PyArray_Size_NUM 11 /* Array creation functions */ /* new_array = PyArray_FromDims(n_dimensions, dimensions[n_dimensions], item_type); */ #define PyArray_FromDims_RET PyObject * #define PyArray_FromDims_PROTO Py_PROTO((int, int *, int)) #define PyArray_FromDims_NUM 12 /* array_from_existing_data = PyArray_FromDimsAndData(n_dims, dims[n_dims], item_type, old_data); */ /* WARNING: using PyArray_FromDimsAndData is not reccommended! It should only be used to refer to */ /* global arrays that will never be freed (like FORTRAN common blocks). */ #define PyArray_FromDimsAndData_RET PyObject * #define PyArray_FromDimsAndData_PROTO Py_PROTO((int, int *, int, char *)) #define PyArray_FromDimsAndData_NUM 13 /* Initialize from a python object. */ /* PyArray_ContiguousFromObject(object, typecode, min_dimensions, max_dimensions) */ /* if max_dimensions = 0, then any number of dimensions are allowed. */ /* If you want an exact number of dimensions, you should use max_dimensions */ /* = min_dimensions. */ #define PyArray_ContiguousFromObject_RET PyObject * #define PyArray_ContiguousFromObject_PROTO Py_FPROTO((PyObject *, int, int, int)) #define PyArray_ContiguousFromObject_NUM 14 /* Same as contiguous, except guarantees a copy of the original data */ #define PyArray_CopyFromObject_RET PyObject * #define PyArray_CopyFromObject_PROTO Py_FPROTO((PyObject *, int, int, int)) #define PyArray_CopyFromObject_NUM 15 /* Shouldn't be used unless you know what you're doing and are not scared by discontiguous arrays */ #define PyArray_FromObject_RET PyObject * #define PyArray_FromObject_PROTO Py_FPROTO((PyObject *, int, int, int)) #define PyArray_FromObject_NUM 16 /* Return either an array, or if passed a 0d array return the appropriate python scalar */ #define PyArray_Return_RET PyObject * #define PyArray_Return_PROTO Py_FPROTO((PyArrayObject *)) #define PyArray_Return_NUM 17 #define PyArray_Reshape_RET PyObject * #define PyArray_Reshape_PROTO Py_FPROTO((PyArrayObject *ap, PyObject *shape)) #define PyArray_Reshape_NUM 18 #define PyArray_Copy_RET PyObject * #define PyArray_Copy_PROTO Py_FPROTO((PyArrayObject *ap)) #define PyArray_Copy_NUM 19 #define PyArray_Take_RET PyObject * #define PyArray_Take_PROTO Py_FPROTO((PyObject *ap, PyObject *items, int axis)) #define PyArray_Take_NUM 20 /*Getting arrays in various useful forms. */ #define PyArray_As1D_RET int #define PyArray_As1D_PROTO Py_FPROTO((PyObject **op, char **ptr, int *d1, int typecode)) #define PyArray_As1D_NUM 21 #define PyArray_As2D_RET int #define PyArray_As2D_PROTO Py_FPROTO((PyObject **op, char ***ptr, int *d1, int *d2, int typecode)) #define PyArray_As2D_NUM 22 #define PyArray_Free_RET int #define PyArray_Free_PROTO Py_FPROTO((PyObject *op, char *ptr)) #define PyArray_Free_NUM 23 /* Total number of C API pointers */ #define PyArray_API_pointers 24 #ifdef _ARRAY_MODULE extern PyTypeObject PyArray_Type; #define PyArray_Check(op) ((op)->ob_type == &PyArray_Type) extern PyArray_SetNumericOps_RET PyArray_SetNumericOps \ PyArray_SetNumericOps_PROTO; extern PyArray_INCREF_RET PyArray_INCREF PyArray_INCREF_PROTO; extern PyArray_XDECREF_RET PyArray_XDECREF PyArray_XDECREF_PROTO; extern PyArrayError_RET PyArrayError PyArrayError_PROTO; extern PyArray_SetStringFunction_RET PyArray_SetStringFunction \ PyArray_SetStringFunction_PROTO; extern PyArray_DescrFromType_RET PyArray_DescrFromType \ PyArray_DescrFromType_PROTO; extern PyArray_Cast_RET PyArray_Cast PyArray_Cast_PROTO; extern PyArray_CanCastSafely_RET PyArray_CanCastSafely \ PyArray_CanCastSafely_PROTO; extern PyArray_ObjectType_RET PyArray_ObjectType PyArray_ObjectType_PROTO; extern _PyArray_multiply_list_RET _PyArray_multiply_list \ _PyArray_multiply_list_PROTO; extern PyArray_Size_RET PyArray_Size PyArray_Size_PROTO; extern PyArray_FromDims_RET PyArray_FromDims PyArray_FromDims_PROTO; extern PyArray_FromDimsAndData_RET PyArray_FromDimsAndData \ PyArray_FromDimsAndData_PROTO; extern PyArray_ContiguousFromObject_RET PyArray_ContiguousFromObject \ PyArray_ContiguousFromObject_PROTO; extern PyArray_CopyFromObject_RET PyArray_CopyFromObject \ PyArray_CopyFromObject_PROTO; extern PyArray_FromObject_RET PyArray_FromObject PyArray_FromObject_PROTO; extern PyArray_Return_RET PyArray_Return PyArray_Return_PROTO; extern PyArray_Reshape_RET PyArray_Reshape PyArray_Reshape_PROTO; extern PyArray_Copy_RET PyArray_Copy PyArray_Copy_PROTO; extern PyArray_Take_RET PyArray_Take PyArray_Take_PROTO; extern PyArray_As1D_RET PyArray_As1D PyArray_As1D_PROTO; extern PyArray_As2D_RET PyArray_As2D PyArray_As2D_PROTO; extern PyArray_Free_RET PyArray_Free PyArray_Free_PROTO; #else /* C API address pointer */ #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY) extern void **PyArray_API; #else void **PyArray_API; #endif #define PyArray_Check(op) \ ((op)->ob_type == (PyTypeObject *)PyArray_API[PyArray_Type_NUM]) #define PyArray_Type *(PyTypeObject *)PyArray_API[PyArray_Type_NUM] #define PyArray_SetNumericOps \ (*(PyArray_SetNumericOps_RET (*)PyArray_SetNumericOps_PROTO) \ PyArray_API[PyArray_SetNumericOps_NUM]) #define PyArray_INCREF \ (*(PyArray_INCREF_RET (*)PyArray_INCREF_PROTO) \ PyArray_API[PyArray_INCREF_NUM]) #define PyArray_XDECREF \ (*(PyArray_XDECREF_RET (*)PyArray_XDECREF_PROTO) \ PyArray_API[PyArray_XDECREF_NUM]) #define PyArrayError \ (*(PyArrayError_RET (*)PyArrayError_PROTO) \ PyArray_API[PyArrayError_NUM]) #define PyArray_SetStringFunction \ (*(PyArray_SetStringFunction_RET (*)PyArray_SetStringFunction_PROTO) \ PyArray_API[PyArray_SetStringFunction_NUM]) #define PyArray_DescrFromType \ (*(PyArray_DescrFromType_RET (*)PyArray_DescrFromType_PROTO) \ PyArray_API[PyArray_DescrFromType_NUM]) #define PyArray_Cast \ (*(PyArray_Cast_RET (*)PyArray_Cast_PROTO) \ PyArray_API[PyArray_Cast_NUM]) #define PyArray_CanCastSafely \ (*(PyArray_CanCastSafely_RET (*)PyArray_CanCastSafely_PROTO) \ PyArray_API[PyArray_CanCastSafely_NUM]) #define PyArray_ObjectType \ (*(PyArray_ObjectType_RET (*)PyArray_ObjectType_PROTO) \ PyArray_API[PyArray_ObjectType_NUM]) #define _PyArray_multiply_list \ (*(_PyArray_multiply_list_RET (*)_PyArray_multiply_list_PROTO) \ PyArray_API[_PyArray_multiply_list_NUM]) #define PyArray_Size \ (*(PyArray_Size_RET (*)PyArray_Size_PROTO) \ PyArray_API[PyArray_Size_NUM]) #define PyArray_FromDims \ (*(PyArray_FromDims_RET (*)PyArray_FromDims_PROTO) \ PyArray_API[PyArray_FromDims_NUM]) #define PyArray_FromDimsAndData \ (*(PyArray_FromDimsAndData_RET (*)PyArray_FromDimsAndData_PROTO) \ PyArray_API[PyArray_FromDimsAndData_NUM]) #define PyArray_ContiguousFromObject \ (*(PyArray_ContiguousFromObject_RET (*)PyArray_ContiguousFromObject_PROTO) \ PyArray_API[PyArray_ContiguousFromObject_NUM]) #define PyArray_CopyFromObject \ (*(PyArray_CopyFromObject_RET (*)PyArray_CopyFromObject_PROTO) \ PyArray_API[PyArray_CopyFromObject_NUM]) #define PyArray_FromObject \ (*(PyArray_FromObject_RET (*)PyArray_FromObject_PROTO) \ PyArray_API[PyArray_FromObject_NUM]) #define PyArray_Return \ (*(PyArray_Return_RET (*)PyArray_Return_PROTO) \ PyArray_API[PyArray_Return_NUM]) #define PyArray_Reshape \ (*(PyArray_Reshape_RET (*)PyArray_Reshape_PROTO) \ PyArray_API[PyArray_Reshape_NUM]) #define PyArray_Copy \ (*(PyArray_Copy_RET (*)PyArray_Copy_PROTO) \ PyArray_API[PyArray_Copy_NUM]) #define PyArray_Take \ (*(PyArray_Take_RET (*)PyArray_Take_PROTO) \ PyArray_API[PyArray_Take_NUM]) #define PyArray_As1D \ (*(PyArray_As1D_RET (*)PyArray_As1D_PROTO) \ PyArray_API[PyArray_As1D_NUM]) #define PyArray_As2D \ (*(PyArray_As2D_RET (*)PyArray_As2D_PROTO) \ PyArray_API[PyArray_As2D_NUM]) #define PyArray_Free \ (*(PyArray_Free_RET (*)PyArray_Free_PROTO) \ PyArray_API[PyArray_Free_NUM]) #define import_array() \ { \ PyObject *numpy = PyImport_ImportModule("_numpy"); \ if (numpy != NULL) { \ PyObject *module_dict = PyModule_GetDict(numpy); \ PyObject *c_api_object = PyDict_GetItemString(module_dict, "_ARRAY_API"); \ if (PyCObject_Check(c_api_object)) { \ PyArray_API = (void **)PyCObject_AsVoidPtr(c_api_object); \ } \ } \ } #endif #ifdef __cplusplus } #endif #endif /* !Py_ARRAYOBJECT_H */