Attachment 'arrayobject.h'

Download

   1 #ifndef Py_ARRAYOBJECT_H
   2 #define Py_ARRAYOBJECT_H
   3 #ifdef __cplusplus
   4 extern "C" {
   5 #endif
   6 
   7 #define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
   8 #define MAX_ELSIZE 16
   9 
  10 #define PyArray_UNSIGNED_TYPES
  11 
  12 enum PyArray_TYPES {    PyArray_CHAR, PyArray_UBYTE, PyArray_SBYTE,
  13 		        PyArray_SHORT, PyArray_USHORT, 
  14 		        PyArray_INT, PyArray_UINT, 
  15 			PyArray_LONG,
  16 			PyArray_FLOAT, PyArray_DOUBLE, 
  17 			PyArray_CFLOAT, PyArray_CDOUBLE,
  18 			PyArray_OBJECT,
  19 			PyArray_NTYPES, PyArray_NOTYPE};
  20 
  21 typedef void (PyArray_VectorUnaryFunc) (char *, int, char *, int, int);
  22 
  23 typedef PyObject * (PyArray_GetItemFunc) (char *);
  24 typedef int (PyArray_SetItemFunc) (PyObject *, char *);
  25 
  26 typedef struct {
  27   PyArray_VectorUnaryFunc *cast[PyArray_NTYPES]; /* Functions to cast to */
  28 					           /* all other types */
  29   PyArray_GetItemFunc *getitem;
  30   PyArray_SetItemFunc *setitem;
  31 
  32   int type_num, elsize;
  33   char *one, *zero;
  34   char type;
  35 
  36 } PyArray_Descr;
  37 
  38 /* Array flags */
  39 #define CONTIGUOUS 1
  40 #define OWN_DIMENSIONS 2
  41 #define OWN_STRIDES 4
  42 #define OWN_DATA 8
  43 #define SAVESPACE 16
  44 
  45 /* type bit */
  46 #define SAVESPACEBIT 128 
  47 
  48 typedef struct {
  49   PyObject_HEAD
  50   char *data;
  51   int nd;
  52   int *dimensions, *strides;
  53   PyObject *base;
  54   PyArray_Descr *descr;
  55   int flags;
  56 } PyArrayObject;
  57 
  58 
  59 /*
  60  * C API
  61  */
  62 
  63 /* Type definitions */
  64 
  65 #define PyArray_Type_NUM 0
  66 
  67 /* Function definitions */
  68 
  69 /* The following are not intended for use in user code, only needed by umath. */
  70 /* If you write your own match library, you might want this function. */
  71 #define PyArray_SetNumericOps_RET int
  72 #define PyArray_SetNumericOps_PROTO (PyObject *)
  73 #define PyArray_SetNumericOps_NUM 1
  74 
  75 #define PyArray_INCREF_RET int
  76 #define PyArray_INCREF_PROTO (PyArrayObject *ap)
  77 #define PyArray_INCREF_NUM 2
  78 
  79 #define PyArray_XDECREF_RET int
  80 #define PyArray_XDECREF_PROTO (PyArrayObject *ap)
  81 #define PyArray_XDECREF_NUM 3
  82 
  83 /* Export the array error object.  Is this a good idea?  */
  84 #define PyArrayError_RET PyObject *
  85 #define PyArrayError_PROTO (void)
  86 #define PyArrayError_NUM 4
  87 
  88 /* Set the array print function to be a python function */
  89 #define PyArray_SetStringFunction_RET void
  90 #define PyArray_SetStringFunction_PROTO (PyObject *op, int repr)
  91 #define PyArray_SetStringFunction_NUM 5
  92 
  93 /* Get the PyArray_Descr structure for a typecode */
  94 #define PyArray_DescrFromType_RET PyArray_Descr *
  95 #define PyArray_DescrFromType_PROTO (int)
  96 #define PyArray_DescrFromType_NUM 6
  97 
  98 /* Cast an array to a different type */
  99 #define PyArray_Cast_RET PyObject *
 100 #define PyArray_Cast_PROTO (PyArrayObject *, int)
 101 #define PyArray_Cast_NUM 7
 102 
 103 /* Check the type coercion rules */
 104 #define PyArray_CanCastSafely_RET int
 105 #define PyArray_CanCastSafely_PROTO (int fromtype, int totype)
 106 #define PyArray_CanCastSafely_NUM 8
 107 
 108 /* Return the typecode to use for an object if it was an array */
 109 #define PyArray_ObjectType_RET int
 110 #define PyArray_ObjectType_PROTO (PyObject *, int)
 111 #define PyArray_ObjectType_NUM 9
 112 
 113 #define _PyArray_multiply_list_RET int
 114 #define _PyArray_multiply_list_PROTO (int *lp, int n)
 115 #define _PyArray_multiply_list_NUM 10
 116 
 117 
 118 /* The following defines the C API for the array object for most users */
 119 
 120 #define PyArray_SIZE(mp) (_PyArray_multiply_list((mp)->dimensions, (mp)->nd))
 121 #define PyArray_NBYTES(mp) ((mp)->descr->elsize * PyArray_SIZE(mp))
 122 /* Obviously this needs some work. */
 123 #define PyArray_ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)
 124 #define PyArray_ISSPACESAVER(m) (((PyArrayObject *)m)->flags & SAVESPACE)
 125 #define PyScalarArray_Check(m) (PyArray_Check((m)) && (((PyArrayObject *)(m))->nd == 0))
 126 
 127 /* Return the size in number of items of an array */
 128 #define PyArray_Size_RET int
 129 #define PyArray_Size_PROTO (PyObject *)
 130 #define PyArray_Size_NUM 11
 131 
 132 
 133 /* Array creation functions */
 134 /* new_array = PyArray_FromDims(n_dimensions, dimensions[n_dimensions], item_type); */
 135 #define PyArray_FromDims_RET PyObject *
 136 #define PyArray_FromDims_PROTO (int, int *, int)
 137 #define PyArray_FromDims_NUM 12
 138 
 139 /* array_from_existing_data = PyArray_FromDimsAndData(n_dims, dims[n_dims], item_type, old_data); */
 140 /* WARNING: using PyArray_FromDimsAndData is not reccommended!  It should only be used to refer to */
 141 /* global arrays that will never be freed (like FORTRAN common blocks). */
 142 #define PyArray_FromDimsAndData_RET PyObject *
 143 #define PyArray_FromDimsAndData_PROTO (int, int *, int, char *)
 144 #define PyArray_FromDimsAndData_NUM 13
 145 
 146 /* Initialize from a python object. */
 147 
 148 /* PyArray_ContiguousFromObject(object, typecode, min_dimensions, max_dimensions) */
 149 /* if max_dimensions = 0, then any number of dimensions are allowed. */
 150 /* If you want an exact number of dimensions, you should use max_dimensions */
 151 /* = min_dimensions. */
 152 
 153 #define PyArray_ContiguousFromObject_RET PyObject *
 154 #define PyArray_ContiguousFromObject_PROTO (PyObject *, int, int, int)
 155 #define PyArray_ContiguousFromObject_NUM 14
 156 
 157 /* Same as contiguous, except guarantees a copy of the original data */
 158 #define PyArray_CopyFromObject_RET PyObject *
 159 #define PyArray_CopyFromObject_PROTO (PyObject *, int, int, int)
 160 #define PyArray_CopyFromObject_NUM 15
 161 
 162 /* Shouldn't be used unless you know what you're doing and are not scared by discontiguous arrays */
 163 #define PyArray_FromObject_RET PyObject *
 164 #define PyArray_FromObject_PROTO (PyObject *, int, int, int)
 165 #define PyArray_FromObject_NUM 16
 166 
 167 /* Return either an array, or if passed a 0d array return the appropriate python scalar */
 168 #define PyArray_Return_RET PyObject *
 169 #define PyArray_Return_PROTO (PyArrayObject *)
 170 #define PyArray_Return_NUM 17
 171 
 172 #define PyArray_Reshape_RET PyObject *
 173 #define PyArray_Reshape_PROTO (PyArrayObject *ap, PyObject *shape)
 174 #define PyArray_Reshape_NUM 18
 175 
 176 #define PyArray_Copy_RET PyObject *
 177 #define PyArray_Copy_PROTO (PyArrayObject *ap)
 178 #define PyArray_Copy_NUM 19
 179 
 180 #define PyArray_Take_RET PyObject *
 181 #define PyArray_Take_PROTO (PyObject *ap, PyObject *items, int axis)
 182 #define PyArray_Take_NUM 20
 183 
 184 /*Getting arrays in various useful forms. */
 185 #define PyArray_As1D_RET int
 186 #define PyArray_As1D_PROTO (PyObject **op, char **ptr, int *d1, int typecode)
 187 #define PyArray_As1D_NUM 21
 188 
 189 #define PyArray_As2D_RET int
 190 #define PyArray_As2D_PROTO (PyObject **op, char ***ptr, int *d1, int *d2, int typecode)
 191 #define PyArray_As2D_NUM 22
 192 
 193 #define PyArray_Free_RET int
 194 #define PyArray_Free_PROTO (PyObject *op, char *ptr)
 195 #define PyArray_Free_NUM 23
 196 
 197 /* array_from_existing_data = PyArray_FromDimsAndDataAndDescr(n_dims, dims[n_dims], descr, old_data); */
 198 /* WARNING: using PyArray_FromDimsAndDataAndDescr is not reccommended!  It should only be used to refer to */
 199 /* global arrays that will never be freed (like FORTRAN common blocks). */
 200 #define PyArray_FromDimsAndDataAndDescr_RET PyObject *
 201 #define PyArray_FromDimsAndDataAndDescr_PROTO (int, int *, PyArray_Descr *, char *)
 202 #define PyArray_FromDimsAndDataAndDescr_NUM 24
 203 
 204 #define PyArray_Converter_RET int
 205 #define PyArray_Converter_PROTO (PyObject *, PyObject **)
 206 #define PyArray_Converter_NUM 25
 207 
 208 #define PyArray_Put_RET PyObject *
 209 #define PyArray_Put_PROTO (PyObject *ap, PyObject *items, PyObject* values)
 210 #define PyArray_Put_NUM 26
 211 
 212 #define PyArray_PutMask_RET PyObject *
 213 #define PyArray_PutMask_PROTO (PyObject *ap, PyObject *mask, PyObject* values)
 214 #define PyArray_PutMask_NUM 27
 215 
 216 #define PyArray_CopyArray_RET int
 217 #define PyArray_CopyArray_PROTO (PyArrayObject *dest, PyArrayObject *src)
 218 #define PyArray_CopyArray_NUM 28
 219 
 220 #define PyArray_ValidType_RET int
 221 #define PyArray_ValidType_PROTO (int type)
 222 #define PyArray_ValidType_NUM 29
 223 
 224 /* Total number of C API pointers */
 225 #define PyArray_API_pointers 30
 226 
 227 
 228 #ifdef _ARRAY_MODULE
 229 
 230 extern PyTypeObject PyArray_Type;
 231 #define PyArray_Check(op) ((op)->ob_type == &PyArray_Type)
 232 
 233 extern PyArray_SetNumericOps_RET PyArray_SetNumericOps \
 234        PyArray_SetNumericOps_PROTO;
 235 extern PyArray_INCREF_RET PyArray_INCREF PyArray_INCREF_PROTO;
 236 extern PyArray_XDECREF_RET PyArray_XDECREF PyArray_XDECREF_PROTO;
 237 extern PyArrayError_RET PyArrayError PyArrayError_PROTO;
 238 extern PyArray_SetStringFunction_RET PyArray_SetStringFunction \
 239        PyArray_SetStringFunction_PROTO;
 240 extern PyArray_DescrFromType_RET PyArray_DescrFromType \
 241        PyArray_DescrFromType_PROTO;
 242 extern PyArray_Cast_RET PyArray_Cast PyArray_Cast_PROTO;
 243 extern PyArray_CanCastSafely_RET PyArray_CanCastSafely \
 244        PyArray_CanCastSafely_PROTO;
 245 extern PyArray_ObjectType_RET PyArray_ObjectType PyArray_ObjectType_PROTO;
 246 extern _PyArray_multiply_list_RET _PyArray_multiply_list \
 247        _PyArray_multiply_list_PROTO;
 248 extern PyArray_Size_RET PyArray_Size PyArray_Size_PROTO;
 249 extern PyArray_FromDims_RET PyArray_FromDims PyArray_FromDims_PROTO;
 250 extern PyArray_FromDimsAndData_RET PyArray_FromDimsAndData \
 251        PyArray_FromDimsAndData_PROTO;
 252 extern PyArray_FromDimsAndDataAndDescr_RET PyArray_FromDimsAndDataAndDescr \
 253        PyArray_FromDimsAndDataAndDescr_PROTO;
 254 extern PyArray_ContiguousFromObject_RET PyArray_ContiguousFromObject \
 255        PyArray_ContiguousFromObject_PROTO;
 256 extern PyArray_CopyFromObject_RET PyArray_CopyFromObject \
 257        PyArray_CopyFromObject_PROTO;
 258 extern PyArray_FromObject_RET PyArray_FromObject PyArray_FromObject_PROTO;
 259 extern PyArray_Return_RET PyArray_Return PyArray_Return_PROTO;
 260 extern PyArray_Reshape_RET PyArray_Reshape PyArray_Reshape_PROTO;
 261 extern PyArray_Copy_RET PyArray_Copy PyArray_Copy_PROTO;
 262 extern PyArray_Take_RET PyArray_Take PyArray_Take_PROTO;
 263 extern PyArray_As1D_RET PyArray_As1D PyArray_As1D_PROTO;
 264 extern PyArray_As2D_RET PyArray_As2D PyArray_As2D_PROTO;
 265 extern PyArray_Free_RET PyArray_Free PyArray_Free_PROTO;
 266 extern PyArray_Converter_RET PyArray_Converter PyArray_Converter_PROTO;
 267 extern PyArray_Put_RET PyArray_Put PyArray_Put_PROTO;
 268 extern PyArray_PutMask_RET PyArray_PutMask PyArray_PutMask_PROTO;
 269 extern PyArray_CopyArray_RET PyArray_CopyArray PyArray_CopyArray_PROTO;
 270 extern PyArray_ValidType_RET PyArray_ValidType PyArray_ValidType_PROTO;
 271 
 272 #else
 273 
 274 #if defined(PY_ARRAY_UNIQUE_SYMBOL)
 275 #define PyArray_API PY_ARRAY_UNIQUE_SYMBOL
 276 #endif
 277 
 278 /* C API address pointer */ 
 279 #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
 280 extern void **PyArray_API;
 281 #else
 282 #if defined(PY_ARRAY_UNIQUE_SYMBOL)
 283 void **PyArray_API;
 284 #else
 285 static void **PyArray_API;
 286 #endif
 287 #endif
 288 
 289 #define PyArray_Check(op) \
 290    ((op)->ob_type == (PyTypeObject *)PyArray_API[PyArray_Type_NUM])
 291 #define PyArray_Type *(PyTypeObject *)PyArray_API[PyArray_Type_NUM]
 292 
 293 #define PyArray_SetNumericOps \
 294   (*(PyArray_SetNumericOps_RET (*)PyArray_SetNumericOps_PROTO) \
 295    PyArray_API[PyArray_SetNumericOps_NUM])
 296 #define PyArray_INCREF \
 297   (*(PyArray_INCREF_RET (*)PyArray_INCREF_PROTO) \
 298    PyArray_API[PyArray_INCREF_NUM])
 299 #define PyArray_XDECREF \
 300   (*(PyArray_XDECREF_RET (*)PyArray_XDECREF_PROTO) \
 301    PyArray_API[PyArray_XDECREF_NUM])
 302 #define PyArrayError \
 303   (*(PyArrayError_RET (*)PyArrayError_PROTO) \
 304    PyArray_API[PyArrayError_NUM])
 305 #define PyArray_SetStringFunction \
 306   (*(PyArray_SetStringFunction_RET (*)PyArray_SetStringFunction_PROTO) \
 307    PyArray_API[PyArray_SetStringFunction_NUM])
 308 #define PyArray_DescrFromType \
 309   (*(PyArray_DescrFromType_RET (*)PyArray_DescrFromType_PROTO) \
 310    PyArray_API[PyArray_DescrFromType_NUM])
 311 #define PyArray_Cast \
 312   (*(PyArray_Cast_RET (*)PyArray_Cast_PROTO) \
 313    PyArray_API[PyArray_Cast_NUM])
 314 #define PyArray_CanCastSafely \
 315   (*(PyArray_CanCastSafely_RET (*)PyArray_CanCastSafely_PROTO) \
 316    PyArray_API[PyArray_CanCastSafely_NUM])
 317 #define PyArray_ObjectType \
 318   (*(PyArray_ObjectType_RET (*)PyArray_ObjectType_PROTO) \
 319    PyArray_API[PyArray_ObjectType_NUM])
 320 #define _PyArray_multiply_list \
 321   (*(_PyArray_multiply_list_RET (*)_PyArray_multiply_list_PROTO) \
 322    PyArray_API[_PyArray_multiply_list_NUM])
 323 #define PyArray_Size \
 324   (*(PyArray_Size_RET (*)PyArray_Size_PROTO) \
 325    PyArray_API[PyArray_Size_NUM])
 326 #define PyArray_FromDims \
 327   (*(PyArray_FromDims_RET (*)PyArray_FromDims_PROTO) \
 328    PyArray_API[PyArray_FromDims_NUM])
 329 #define PyArray_FromDimsAndData \
 330   (*(PyArray_FromDimsAndData_RET (*)PyArray_FromDimsAndData_PROTO) \
 331    PyArray_API[PyArray_FromDimsAndData_NUM])
 332 #define PyArray_FromDimsAndDataAndDescr \
 333   (*(PyArray_FromDimsAndDataAndDescr_RET (*)PyArray_FromDimsAndDataAndDescr_PROTO) \
 334    PyArray_API[PyArray_FromDimsAndDataAndDescr_NUM])
 335 #define PyArray_ContiguousFromObject \
 336   (*(PyArray_ContiguousFromObject_RET (*)PyArray_ContiguousFromObject_PROTO) \
 337    PyArray_API[PyArray_ContiguousFromObject_NUM])
 338 #define PyArray_CopyFromObject \
 339   (*(PyArray_CopyFromObject_RET (*)PyArray_CopyFromObject_PROTO) \
 340    PyArray_API[PyArray_CopyFromObject_NUM])
 341 #define PyArray_FromObject \
 342   (*(PyArray_FromObject_RET (*)PyArray_FromObject_PROTO) \
 343    PyArray_API[PyArray_FromObject_NUM])
 344 #define PyArray_Return \
 345   (*(PyArray_Return_RET (*)PyArray_Return_PROTO) \
 346    PyArray_API[PyArray_Return_NUM])
 347 #define PyArray_Reshape \
 348   (*(PyArray_Reshape_RET (*)PyArray_Reshape_PROTO) \
 349    PyArray_API[PyArray_Reshape_NUM])
 350 #define PyArray_Copy \
 351   (*(PyArray_Copy_RET (*)PyArray_Copy_PROTO) \
 352    PyArray_API[PyArray_Copy_NUM])
 353 #define PyArray_Take \
 354   (*(PyArray_Take_RET (*)PyArray_Take_PROTO) \
 355    PyArray_API[PyArray_Take_NUM])
 356 #define PyArray_As1D \
 357   (*(PyArray_As1D_RET (*)PyArray_As1D_PROTO) \
 358    PyArray_API[PyArray_As1D_NUM])
 359 #define PyArray_As2D \
 360   (*(PyArray_As2D_RET (*)PyArray_As2D_PROTO) \
 361    PyArray_API[PyArray_As2D_NUM])
 362 #define PyArray_Free \
 363   (*(PyArray_Free_RET (*)PyArray_Free_PROTO) \
 364    PyArray_API[PyArray_Free_NUM])
 365 #define PyArray_Converter \
 366   (*(PyArray_Converter_RET (*)PyArray_Converter_PROTO) \
 367    PyArray_API[PyArray_Converter_NUM])
 368 #define PyArray_Put \
 369   (*(PyArray_Put_RET (*)PyArray_Put_PROTO) \
 370    PyArray_API[PyArray_Put_NUM])
 371 #define PyArray_PutMask \
 372   (*(PyArray_PutMask_RET (*)PyArray_PutMask_PROTO) \
 373    PyArray_API[PyArray_PutMask_NUM])
 374 #define PyArray_CopyArray \
 375   (*(PyArray_CopyArray_RET (*)PyArray_CopyArray_PROTO) \
 376    PyArray_API[PyArray_CopyArray_NUM])
 377 #define PyArray_ValidType \
 378   (*(PyArray_ValidType_RET (*)PyArray_ValidType_PROTO) \
 379    PyArray_API[PyArray_ValidType_NUM])
 380 
 381 #define import_array() \
 382 { \
 383   PyObject *numpy = PyImport_ImportModule("_numpy"); \
 384   if (numpy != NULL) { \
 385     PyObject *module_dict = PyModule_GetDict(numpy); \
 386     PyObject *c_api_object = PyDict_GetItemString(module_dict, "_ARRAY_API"); \
 387     if (PyCObject_Check(c_api_object)) { \
 388       PyArray_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
 389     } \
 390   } \
 391 }
 392 
 393 #endif
 394 
 395 
 396 #ifdef __cplusplus
 397 }
 398 #endif
 399 #endif /* !Py_ARRAYOBJECT_H */
 400 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.