home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / include / python2.4 / Numeric / arrayobject.h next >
Encoding:
C/C++ Source or Header  |  2005-11-04  |  15.0 KB  |  431 lines

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