numpy 2.0.0
|
00001 #ifndef NDARRAYTYPES_H 00002 #define NDARRAYTYPES_H 00003 00004 /* This is auto-generated by the installer */ 00005 #include "numpyconfig.h" 00006 00007 #include "npy_common.h" 00008 #include "npy_endian.h" 00009 #include "npy_cpu.h" 00010 #include "utils.h" 00011 00012 #ifdef NPY_ENABLE_SEPARATE_COMPILATION 00013 #define NPY_NO_EXPORT NPY_VISIBILITY_HIDDEN 00014 #else 00015 #define NPY_NO_EXPORT static 00016 #endif 00017 00018 /* Only use thread if configured in config and python supports it */ 00019 #if defined WITH_THREAD && !NPY_NO_SMP 00020 #define NPY_ALLOW_THREADS 1 00021 #else 00022 #define NPY_ALLOW_THREADS 0 00023 #endif 00024 00025 00026 00027 /* 00028 * There are several places in the code where an array of dimensions 00029 * is allocated statically. This is the size of that static 00030 * allocation. 00031 * 00032 * The array creation itself could have arbitrary dimensions but all 00033 * the places where static allocation is used would need to be changed 00034 * to dynamic (including inside of several structures) 00035 */ 00036 00037 #define NPY_MAXDIMS 32 00038 #define NPY_MAXARGS 32 00039 00040 /* Used for Converter Functions "O&" code in ParseTuple */ 00041 #define NPY_FAIL 0 00042 #define NPY_SUCCEED 1 00043 00044 /* 00045 * Binary compatibility version number. This number is increased 00046 * whenever the C-API is changed such that binary compatibility is 00047 * broken, i.e. whenever a recompile of extension modules is needed. 00048 */ 00049 #define NPY_VERSION NPY_ABI_VERSION 00050 00051 /* 00052 * Minor API version. This number is increased whenever a change is 00053 * made to the C-API -- whether it breaks binary compatibility or not. 00054 * Some changes, such as adding a function pointer to the end of the 00055 * function table, can be made without breaking binary compatibility. 00056 * In this case, only the NPY_FEATURE_VERSION (*not* NPY_VERSION) 00057 * would be increased. Whenever binary compatibility is broken, both 00058 * NPY_VERSION and NPY_FEATURE_VERSION should be increased. 00059 */ 00060 #define NPY_FEATURE_VERSION NPY_API_VERSION 00061 00062 enum NPY_TYPES { NPY_BOOL=0, 00063 NPY_BYTE, NPY_UBYTE, 00064 NPY_SHORT, NPY_USHORT, 00065 NPY_INT, NPY_UINT, 00066 NPY_LONG, NPY_ULONG, 00067 NPY_LONGLONG, NPY_ULONGLONG, 00068 NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE, 00069 NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE, 00070 NPY_OBJECT=17, 00071 NPY_STRING, NPY_UNICODE, 00072 NPY_VOID, 00073 /* 00074 * New 1.6 types appended, may be integrated 00075 * into the above in 2.0. 00076 */ 00077 NPY_DATETIME, NPY_TIMEDELTA, NPY_HALF, 00078 00079 NPY_NTYPES, 00080 NPY_NOTYPE, 00081 NPY_CHAR, /* special flag */ 00082 NPY_USERDEF=256, /* leave room for characters */ 00083 00084 /* The number of types not including the new 1.6 types */ 00085 NPY_NTYPES_ABI_COMPATIBLE=21 00086 }; 00087 00088 #define NPY_METADATA_DTSTR "__frequency__" 00089 00090 /* basetype array priority */ 00091 #define NPY_PRIORITY 0.0 00092 00093 /* default subtype priority */ 00094 #define NPY_SUBTYPE_PRIORITY 1.0 00095 00096 /* default scalar priority */ 00097 #define NPY_SCALAR_PRIORITY -1000000.0 00098 00099 /* How many floating point types are there (excluding half) */ 00100 #define NPY_NUM_FLOATTYPE 3 00101 00102 /* 00103 * We need to match npy_intp to a signed integer of the same size as a 00104 * pointer variable. npy_uintp to the equivalent unsigned integer 00105 */ 00106 00107 00108 /* 00109 * These characters correspond to the array type and the struct 00110 * module 00111 */ 00112 00113 /* except 'p' -- signed integer for pointer type */ 00114 00115 enum NPY_TYPECHAR { NPY_BOOLLTR = '?', 00116 NPY_BYTELTR = 'b', 00117 NPY_UBYTELTR = 'B', 00118 NPY_SHORTLTR = 'h', 00119 NPY_USHORTLTR = 'H', 00120 NPY_INTLTR = 'i', 00121 NPY_UINTLTR = 'I', 00122 NPY_LONGLTR = 'l', 00123 NPY_ULONGLTR = 'L', 00124 NPY_LONGLONGLTR = 'q', 00125 NPY_ULONGLONGLTR = 'Q', 00126 NPY_HALFLTR = 'e', 00127 NPY_FLOATLTR = 'f', 00128 NPY_DOUBLELTR = 'd', 00129 NPY_LONGDOUBLELTR = 'g', 00130 NPY_CFLOATLTR = 'F', 00131 NPY_CDOUBLELTR = 'D', 00132 NPY_CLONGDOUBLELTR = 'G', 00133 NPY_OBJECTLTR = 'O', 00134 NPY_STRINGLTR = 'S', 00135 NPY_STRINGLTR2 = 'a', 00136 NPY_UNICODELTR = 'U', 00137 NPY_VOIDLTR = 'V', 00138 NPY_DATETIMELTR = 'M', 00139 NPY_TIMEDELTALTR = 'm', 00140 NPY_CHARLTR = 'c', 00141 00142 /* 00143 * No Descriptor, just a define -- this let's 00144 * Python users specify an array of integers 00145 * large enough to hold a pointer on the 00146 * platform 00147 */ 00148 NPY_INTPLTR = 'p', 00149 NPY_UINTPLTR = 'P', 00150 00151 NPY_GENBOOLLTR ='b', 00152 NPY_SIGNEDLTR = 'i', 00153 NPY_UNSIGNEDLTR = 'u', 00154 NPY_FLOATINGLTR = 'f', 00155 NPY_COMPLEXLTR = 'c' 00156 }; 00157 00158 typedef enum { 00159 NPY_QUICKSORT=0, 00160 NPY_HEAPSORT=1, 00161 NPY_MERGESORT=2 00162 } NPY_SORTKIND; 00163 #define NPY_NSORTS (NPY_MERGESORT + 1) 00164 00165 00166 typedef enum { 00167 NPY_SEARCHLEFT=0, 00168 NPY_SEARCHRIGHT=1 00169 } NPY_SEARCHSIDE; 00170 #define NPY_NSEARCHSIDES (NPY_SEARCHRIGHT + 1) 00171 00172 00173 typedef enum { 00174 NPY_NOSCALAR=-1, 00175 NPY_BOOL_SCALAR, 00176 NPY_INTPOS_SCALAR, 00177 NPY_INTNEG_SCALAR, 00178 NPY_FLOAT_SCALAR, 00179 NPY_COMPLEX_SCALAR, 00180 NPY_OBJECT_SCALAR 00181 } NPY_SCALARKIND; 00182 #define NPY_NSCALARKINDS (NPY_OBJECT_SCALAR + 1) 00183 00184 /* For specifying array memory layout or iteration order */ 00185 typedef enum { 00186 /* Fortran order if inputs are all Fortran, C otherwise */ 00187 NPY_ANYORDER=-1, 00188 /* C order */ 00189 NPY_CORDER=0, 00190 /* Fortran order */ 00191 NPY_FORTRANORDER=1, 00192 /* An order as close to the inputs as possible */ 00193 NPY_KEEPORDER=2 00194 } NPY_ORDER; 00195 00196 /* For specifying allowed casting in operations which support it */ 00197 typedef enum { 00198 /* Only allow identical types */ 00199 NPY_NO_CASTING=0, 00200 /* Allow identical and byte swapped types */ 00201 NPY_EQUIV_CASTING=1, 00202 /* Only allow safe casts */ 00203 NPY_SAFE_CASTING=2, 00204 /* Allow safe casts or casts within the same kind */ 00205 NPY_SAME_KIND_CASTING=3, 00206 /* Allow any casts */ 00207 NPY_UNSAFE_CASTING=4 00208 } NPY_CASTING; 00209 00210 typedef enum { 00211 NPY_CLIP=0, 00212 NPY_WRAP=1, 00213 NPY_RAISE=2 00214 } NPY_CLIPMODE; 00215 00216 typedef enum { 00217 NPY_FR_Y, 00218 NPY_FR_M, 00219 NPY_FR_W, 00220 NPY_FR_B, 00221 NPY_FR_D, 00222 NPY_FR_h, 00223 NPY_FR_m, 00224 NPY_FR_s, 00225 NPY_FR_ms, 00226 NPY_FR_us, 00227 NPY_FR_ns, 00228 NPY_FR_ps, 00229 NPY_FR_fs, 00230 NPY_FR_as 00231 } NPY_DATETIMEUNIT; 00232 00233 #define NPY_DATETIME_NUMUNITS (NPY_FR_as + 1) 00234 #define NPY_DATETIME_DEFAULTUNIT NPY_FR_us 00235 00236 #define NPY_STR_Y "Y" 00237 #define NPY_STR_M "M" 00238 #define NPY_STR_W "W" 00239 #define NPY_STR_B "B" 00240 #define NPY_STR_D "D" 00241 #define NPY_STR_h "h" 00242 #define NPY_STR_m "m" 00243 #define NPY_STR_s "s" 00244 #define NPY_STR_ms "ms" 00245 #define NPY_STR_us "us" 00246 #define NPY_STR_ns "ns" 00247 #define NPY_STR_ps "ps" 00248 #define NPY_STR_fs "fs" 00249 #define NPY_STR_as "as" 00250 00251 00252 /* 00253 * This is to typedef npy_intp to the appropriate pointer size for 00254 * this platform. Py_intptr_t, Py_uintptr_t are defined in pyport.h. 00255 */ 00256 typedef Py_intptr_t npy_intp; 00257 typedef Py_uintptr_t npy_uintp; 00258 #define NPY_SIZEOF_INTP NPY_SIZEOF_PY_INTPTR_T 00259 #define NPY_SIZEOF_UINTP NPY_SIZEOF_PY_INTPTR_T 00260 00261 #ifdef constchar 00262 #undef constchar 00263 #endif 00264 00265 #if (PY_VERSION_HEX < 0x02050000) 00266 #ifndef PY_SSIZE_T_MIN 00267 typedef int Py_ssize_t; 00268 #define PY_SSIZE_T_MAX INT_MAX 00269 #define PY_SSIZE_T_MIN INT_MIN 00270 #endif 00271 #define NPY_SSIZE_T_PYFMT "i" 00272 #undef PyIndex_Check 00273 #define constchar const char 00274 #define PyIndex_Check(op) 0 00275 #else 00276 #define NPY_SSIZE_T_PYFMT "n" 00277 #define constchar char 00278 #endif 00279 00280 /* NPY_INTP_FMT Note: 00281 * Unlike the other NPY_*_FMT macros which are used with 00282 * PyOS_snprintf, NPY_INTP_FMT is used with PyErr_Format and 00283 * PyString_Format. These functions use different formatting 00284 * codes which are portably specified according to the Python 00285 * documentation. See ticket #1795. 00286 * 00287 * On Windows x64, the LONGLONG formatter should be used, but 00288 * in Python 2.6 the %lld formatter is not supported. In this 00289 * case we work around the problem by using the %zd formatter. 00290 */ 00291 #if NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_INT 00292 #define NPY_INTP NPY_INT 00293 #define NPY_UINTP NPY_UINT 00294 #define PyIntpArrType_Type PyIntArrType_Type 00295 #define PyUIntpArrType_Type PyUIntArrType_Type 00296 #define NPY_MAX_INTP NPY_MAX_INT 00297 #define NPY_MIN_INTP NPY_MIN_INT 00298 #define NPY_MAX_UINTP NPY_MAX_UINT 00299 #define NPY_INTP_FMT "d" 00300 #elif NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_LONG 00301 #define NPY_INTP NPY_LONG 00302 #define NPY_UINTP NPY_ULONG 00303 #define PyIntpArrType_Type PyLongArrType_Type 00304 #define PyUIntpArrType_Type PyULongArrType_Type 00305 #define NPY_MAX_INTP NPY_MAX_LONG 00306 #define NPY_MIN_INTP MIN_LONG 00307 #define NPY_MAX_UINTP NPY_MAX_ULONG 00308 #define NPY_INTP_FMT "ld" 00309 #elif defined(PY_LONG_LONG) && (NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_LONGLONG) 00310 #define NPY_INTP NPY_LONGLONG 00311 #define NPY_UINTP NPY_ULONGLONG 00312 #define PyIntpArrType_Type PyLongLongArrType_Type 00313 #define PyUIntpArrType_Type PyULongLongArrType_Type 00314 #define NPY_MAX_INTP NPY_MAX_LONGLONG 00315 #define NPY_MIN_INTP NPY_MIN_LONGLONG 00316 #define NPY_MAX_UINTP NPY_MAX_ULONGLONG 00317 #if (PY_VERSION_HEX >= 0x02070000) 00318 #define NPY_INTP_FMT "lld" 00319 #else 00320 #define NPY_INTP_FMT "zd" 00321 #endif 00322 #endif 00323 00324 /* 00325 * We can only use C99 formats for npy_int_p if it is the same as 00326 * intp_t, hence the condition on HAVE_UNITPTR_T 00327 */ 00328 #if (NPY_USE_C99_FORMATS) == 1 \ 00329 && (defined HAVE_UINTPTR_T) \ 00330 && (defined HAVE_INTTYPES_H) 00331 #include <inttypes.h> 00332 #undef NPY_INTP_FMT 00333 #define NPY_INTP_FMT PRIdPTR 00334 #endif 00335 00336 #define NPY_ERR(str) fprintf(stderr, #str); fflush(stderr); 00337 #define NPY_ERR2(str) fprintf(stderr, str); fflush(stderr); 00338 00339 #define NPY_STRINGIFY(x) #x 00340 #define NPY_TOSTRING(x) NPY_STRINGIFY(x) 00341 00342 /* 00343 * Macros to define how array, and dimension/strides data is 00344 * allocated. 00345 */ 00346 00347 /* Data buffer */ 00348 #define PyDataMem_NEW(size) ((char *)malloc(size)) 00349 #define PyDataMem_FREE(ptr) free(ptr) 00350 #define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size)) 00351 00352 #define NPY_USE_PYMEM 1 00353 00354 #if NPY_USE_PYMEM == 1 00355 #define PyArray_malloc PyMem_Malloc 00356 #define PyArray_free PyMem_Free 00357 #define PyArray_realloc PyMem_Realloc 00358 #else 00359 #define PyArray_malloc malloc 00360 #define PyArray_free free 00361 #define PyArray_realloc realloc 00362 #endif 00363 00364 /* Dimensions and strides */ 00365 #define PyDimMem_NEW(size) \ 00366 ((npy_intp *)PyArray_malloc(size*sizeof(npy_intp))) 00367 00368 #define PyDimMem_FREE(ptr) PyArray_free(ptr) 00369 00370 #define PyDimMem_RENEW(ptr,size) \ 00371 ((npy_intp *)PyArray_realloc(ptr,size*sizeof(npy_intp))) 00372 00373 /* forward declaration */ 00374 struct _PyArray_Descr; 00375 00376 /* These must deal with unaligned and swapped data if necessary */ 00377 typedef PyObject * (PyArray_GetItemFunc) (void *, void *); 00378 typedef int (PyArray_SetItemFunc)(PyObject *, void *, void *); 00379 00380 typedef void (PyArray_CopySwapNFunc)(void *, npy_intp, void *, npy_intp, 00381 npy_intp, int, void *); 00382 00383 typedef void (PyArray_CopySwapFunc)(void *, void *, int, void *); 00384 typedef npy_bool (PyArray_NonzeroFunc)(void *, void *); 00385 00386 00387 /* 00388 * These assume aligned and notswapped data -- a buffer will be used 00389 * before or contiguous data will be obtained 00390 */ 00391 00392 typedef int (PyArray_CompareFunc)(const void *, const void *, void *); 00393 typedef int (PyArray_ArgFunc)(void*, npy_intp, npy_intp*, void *); 00394 00395 typedef void (PyArray_DotFunc)(void *, npy_intp, void *, npy_intp, void *, 00396 npy_intp, void *); 00397 00398 typedef void (PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *, 00399 void *); 00400 00401 /* 00402 * XXX the ignore argument should be removed next time the API version 00403 * is bumped. It used to be the separator. 00404 */ 00405 typedef int (PyArray_ScanFunc)(FILE *fp, void *dptr, 00406 char *ignore, struct _PyArray_Descr *); 00407 typedef int (PyArray_FromStrFunc)(char *s, void *dptr, char **endptr, 00408 struct _PyArray_Descr *); 00409 00410 typedef int (PyArray_FillFunc)(void *, npy_intp, void *); 00411 00412 typedef int (PyArray_SortFunc)(void *, npy_intp, void *); 00413 typedef int (PyArray_ArgSortFunc)(void *, npy_intp *, npy_intp, void *); 00414 00415 typedef int (PyArray_FillWithScalarFunc)(void *, npy_intp, void *, void *); 00416 00417 typedef int (PyArray_ScalarKindFunc)(void *); 00418 00419 typedef void (PyArray_FastClipFunc)(void *in, npy_intp n_in, void *min, 00420 void *max, void *out); 00421 typedef void (PyArray_FastPutmaskFunc)(void *in, void *mask, npy_intp n_in, 00422 void *values, npy_intp nv); 00423 typedef int (PyArray_FastTakeFunc)(void *dest, void *src, npy_intp *indarray, 00424 npy_intp nindarray, npy_intp n_outer, 00425 npy_intp m_middle, npy_intp nelem, 00426 NPY_CLIPMODE clipmode); 00427 00428 typedef struct { 00429 npy_intp *ptr; 00430 int len; 00431 } PyArray_Dims; 00432 00433 typedef struct { 00434 /* 00435 * Functions to cast to most other standard types 00436 * Can have some NULL entries. The types 00437 * DATETIME, TIMEDELTA, and HALF go into the castdict 00438 * even though they are built-in. 00439 */ 00440 PyArray_VectorUnaryFunc *cast[NPY_NTYPES_ABI_COMPATIBLE]; 00441 00442 /* The next four functions *cannot* be NULL */ 00443 00444 /* 00445 * Functions to get and set items with standard Python types 00446 * -- not array scalars 00447 */ 00448 PyArray_GetItemFunc *getitem; 00449 PyArray_SetItemFunc *setitem; 00450 00451 /* 00452 * Copy and/or swap data. Memory areas may not overlap 00453 * Use memmove first if they might 00454 */ 00455 PyArray_CopySwapNFunc *copyswapn; 00456 PyArray_CopySwapFunc *copyswap; 00457 00458 /* 00459 * Function to compare items 00460 * Can be NULL 00461 */ 00462 PyArray_CompareFunc *compare; 00463 00464 /* 00465 * Function to select largest 00466 * Can be NULL 00467 */ 00468 PyArray_ArgFunc *argmax; 00469 00470 /* 00471 * Function to compute dot product 00472 * Can be NULL 00473 */ 00474 PyArray_DotFunc *dotfunc; 00475 00476 /* 00477 * Function to scan an ASCII file and 00478 * place a single value plus possible separator 00479 * Can be NULL 00480 */ 00481 PyArray_ScanFunc *scanfunc; 00482 00483 /* 00484 * Function to read a single value from a string 00485 * and adjust the pointer; Can be NULL 00486 */ 00487 PyArray_FromStrFunc *fromstr; 00488 00489 /* 00490 * Function to determine if data is zero or not 00491 * If NULL a default version is 00492 * used at Registration time. 00493 */ 00494 PyArray_NonzeroFunc *nonzero; 00495 00496 /* 00497 * Used for arange. 00498 * Can be NULL. 00499 */ 00500 PyArray_FillFunc *fill; 00501 00502 /* 00503 * Function to fill arrays with scalar values 00504 * Can be NULL 00505 */ 00506 PyArray_FillWithScalarFunc *fillwithscalar; 00507 00508 /* 00509 * Sorting functions 00510 * Can be NULL 00511 */ 00512 PyArray_SortFunc *sort[NPY_NSORTS]; 00513 PyArray_ArgSortFunc *argsort[NPY_NSORTS]; 00514 00515 /* 00516 * Dictionary of additional casting functions 00517 * PyArray_VectorUnaryFuncs 00518 * which can be populated to support casting 00519 * to other registered types. Can be NULL 00520 */ 00521 PyObject *castdict; 00522 00523 /* 00524 * Functions useful for generalizing 00525 * the casting rules. 00526 * Can be NULL; 00527 */ 00528 PyArray_ScalarKindFunc *scalarkind; 00529 int **cancastscalarkindto; 00530 int *cancastto; 00531 00532 PyArray_FastClipFunc *fastclip; 00533 PyArray_FastPutmaskFunc *fastputmask; 00534 PyArray_FastTakeFunc *fasttake; 00535 } PyArray_ArrFuncs; 00536 00537 /* The item must be reference counted when it is inserted or extracted. */ 00538 #define NPY_ITEM_REFCOUNT 0x01 00539 /* Same as needing REFCOUNT */ 00540 #define NPY_ITEM_HASOBJECT 0x01 00541 /* Convert to list for pickling */ 00542 #define NPY_LIST_PICKLE 0x02 00543 /* The item is a POINTER */ 00544 #define NPY_ITEM_IS_POINTER 0x04 00545 /* memory needs to be initialized for this data-type */ 00546 #define NPY_NEEDS_INIT 0x08 00547 /* operations need Python C-API so don't give-up thread. */ 00548 #define NPY_NEEDS_PYAPI 0x10 00549 /* Use f.getitem when extracting elements of this data-type */ 00550 #define NPY_USE_GETITEM 0x20 00551 /* Use f.setitem when setting creating 0-d array from this data-type.*/ 00552 #define NPY_USE_SETITEM 0x40 00553 /* define NPY_IS_COMPLEX */ 00554 00555 /* 00556 *These are inherited for global data-type if any data-types in the 00557 * field have them 00558 */ 00559 #define NPY_FROM_FIELDS (NPY_NEEDS_INIT | NPY_LIST_PICKLE | \ 00560 NPY_ITEM_REFCOUNT | NPY_NEEDS_PYAPI) 00561 00562 #define NPY_OBJECT_DTYPE_FLAGS (NPY_LIST_PICKLE | NPY_USE_GETITEM | \ 00563 NPY_ITEM_IS_POINTER | NPY_ITEM_REFCOUNT | \ 00564 NPY_NEEDS_INIT | NPY_NEEDS_PYAPI) 00565 00566 #define PyDataType_FLAGCHK(dtype, flag) \ 00567 (((dtype)->flags & (flag)) == (flag)) 00568 00569 #define PyDataType_REFCHK(dtype) \ 00570 PyDataType_FLAGCHK(dtype, NPY_ITEM_REFCOUNT) 00571 00572 typedef struct _PyArray_Descr { 00573 PyObject_HEAD 00574 PyTypeObject *typeobj; /* 00575 * the type object representing an 00576 * instance of this type -- should not 00577 * be two type_numbers with the same type 00578 * object. 00579 */ 00580 char kind; /* kind for this type */ 00581 char type; /* unique-character representing this type */ 00582 char byteorder; /* 00583 * '>' (big), '<' (little), '|' 00584 * (not-applicable), or '=' (native). 00585 */ 00586 char flags; /* flags describing data type */ 00587 int type_num; /* number representing this type */ 00588 int elsize; /* element size for this type */ 00589 int alignment; /* alignment needed for this type */ 00590 struct _arr_descr \ 00591 *subarray; /* 00592 * Non-NULL if this type is 00593 * is an array (C-contiguous) 00594 * of some other type 00595 */ 00596 PyObject *fields; /* The fields dictionary for this type 00597 * For statically defined descr this 00598 * is always Py_None 00599 */ 00600 00601 PyObject *names; /* 00602 * An ordered tuple of field names or NULL 00603 * if no fields are defined 00604 */ 00605 00606 PyArray_ArrFuncs *f; /* 00607 * a table of functions specific for each 00608 * basic data descriptor 00609 */ 00610 00611 PyObject *metadata; /* Metadata about this dtype */ 00612 } PyArray_Descr; 00613 00614 typedef struct _arr_descr { 00615 PyArray_Descr *base; 00616 PyObject *shape; /* a tuple */ 00617 } PyArray_ArrayDescr; 00618 00619 /* 00620 * The main array object structure. It is recommended to use the macros 00621 * defined below (PyArray_DATA and friends) access fields here, instead 00622 * of the members themselves. 00623 */ 00624 00625 typedef struct PyArrayObject { 00626 PyObject_HEAD 00627 char *data; /* pointer to raw data buffer */ 00628 int nd; /* number of dimensions, also called ndim */ 00629 npy_intp *dimensions; /* size in each dimension */ 00630 npy_intp *strides; /* 00631 * bytes to jump to get to the 00632 * next element in each dimension 00633 */ 00634 PyObject *base; /* 00635 * This object should be decref'd upon 00636 * deletion of array 00637 * 00638 * For views it points to the original 00639 * array 00640 * 00641 * For creation from buffer object it 00642 * points to an object that shold be 00643 * decref'd on deletion 00644 * 00645 * For UPDATEIFCOPY flag this is an 00646 * array to-be-updated upon deletion 00647 * of this one 00648 */ 00649 PyArray_Descr *descr; /* Pointer to type structure */ 00650 int flags; /* Flags describing array -- see below */ 00651 PyObject *weakreflist; /* For weakreferences */ 00652 } PyArrayObject; 00653 00654 #define NPY_AO PyArrayObject 00655 00656 #define fortran fortran_ /* For some compilers */ 00657 00658 /* Array Flags Object */ 00659 typedef struct PyArrayFlagsObject { 00660 PyObject_HEAD 00661 PyObject *arr; 00662 int flags; 00663 } PyArrayFlagsObject; 00664 00665 /* Mirrors buffer object to ptr */ 00666 00667 typedef struct { 00668 PyObject_HEAD 00669 PyObject *base; 00670 void *ptr; 00671 npy_intp len; 00672 int flags; 00673 } PyArray_Chunk; 00674 00675 00676 typedef struct { 00677 NPY_DATETIMEUNIT base; 00678 int num; 00679 int den; /* 00680 * Converted to 1 on input for now -- an 00681 * input-only mechanism 00682 */ 00683 int events; 00684 } PyArray_DatetimeMetaData; 00685 00686 typedef struct { 00687 npy_longlong year; 00688 int month, day, hour, min, sec, us, ps, as; 00689 } npy_datetimestruct; 00690 00691 typedef struct { 00692 npy_longlong day; 00693 int sec, us, ps, as; 00694 } npy_timedeltastruct; 00695 00696 #if PY_VERSION_HEX >= 0x03000000 00697 #define PyDataType_GetDatetimeMetaData(descr) \ 00698 ((descr->metadata == NULL) ? NULL : \ 00699 ((PyArray_DatetimeMetaData *)(PyCapsule_GetPointer( \ 00700 PyDict_GetItemString( \ 00701 descr->metadata, NPY_METADATA_DTSTR), NULL)))) 00702 #else 00703 #define PyDataType_GetDatetimeMetaData(descr) \ 00704 ((descr->metadata == NULL) ? NULL : \ 00705 ((PyArray_DatetimeMetaData *)(PyCObject_AsVoidPtr( \ 00706 PyDict_GetItemString(descr->metadata, NPY_METADATA_DTSTR))))) 00707 #endif 00708 00709 typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *); 00710 00711 /* 00712 * Means c-style contiguous (last index varies the fastest). The data 00713 * elements right after each other. 00714 */ 00715 #define NPY_CONTIGUOUS 0x0001 00716 00717 /* 00718 * set if array is a contiguous Fortran array: the first index varies 00719 * the fastest in memory (strides array is reverse of C-contiguous 00720 * array) 00721 */ 00722 #define NPY_FORTRAN 0x0002 00723 00724 #define NPY_C_CONTIGUOUS NPY_CONTIGUOUS 00725 #define NPY_F_CONTIGUOUS NPY_FORTRAN 00726 00727 /* 00728 * Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a 00729 * 1-d array is CONTIGUOUS it is also FORTRAN contiguous 00730 */ 00731 00732 /* 00733 * If set, the array owns the data: it will be free'd when the array 00734 * is deleted. 00735 */ 00736 #define NPY_OWNDATA 0x0004 00737 00738 /* 00739 * An array never has the next four set; they're only used as parameter 00740 * flags to the the various FromAny functions 00741 */ 00742 00743 /* Cause a cast to occur regardless of whether or not it is safe. */ 00744 #define NPY_FORCECAST 0x0010 00745 00746 /* 00747 * Always copy the array. Returned arrays are always CONTIGUOUS, 00748 * ALIGNED, and WRITEABLE. 00749 */ 00750 #define NPY_ENSURECOPY 0x0020 00751 00752 /* Make sure the returned array is a base-class ndarray */ 00753 #define NPY_ENSUREARRAY 0x0040 00754 00755 /* 00756 * Make sure that the strides are in units of the element size Needed 00757 * for some operations with record-arrays. 00758 */ 00759 #define NPY_ELEMENTSTRIDES 0x0080 00760 00761 /* 00762 * Array data is aligned on the appropiate memory address for the type 00763 * stored according to how the compiler would align things (e.g., an 00764 * array of integers (4 bytes each) starts on a memory address that's 00765 * a multiple of 4) 00766 */ 00767 #define NPY_ALIGNED 0x0100 00768 00769 /* Array data has the native endianness */ 00770 #define NPY_NOTSWAPPED 0x0200 00771 00772 /* Array data is writeable */ 00773 #define NPY_WRITEABLE 0x0400 00774 00775 /* 00776 * If this flag is set, then base contains a pointer to an array of 00777 * the same size that should be updated with the current contents of 00778 * this array when this array is deallocated 00779 */ 00780 #define NPY_UPDATEIFCOPY 0x1000 00781 00782 /* This flag is for the array interface */ 00783 #define NPY_ARR_HAS_DESCR 0x0800 00784 00785 00786 #define NPY_BEHAVED (NPY_ALIGNED | NPY_WRITEABLE) 00787 #define NPY_BEHAVED_NS (NPY_ALIGNED | NPY_WRITEABLE | NPY_NOTSWAPPED) 00788 #define NPY_CARRAY (NPY_CONTIGUOUS | NPY_BEHAVED) 00789 #define NPY_CARRAY_RO (NPY_CONTIGUOUS | NPY_ALIGNED) 00790 #define NPY_FARRAY (NPY_FORTRAN | NPY_BEHAVED) 00791 #define NPY_FARRAY_RO (NPY_FORTRAN | NPY_ALIGNED) 00792 #define NPY_DEFAULT NPY_CARRAY 00793 #define NPY_IN_ARRAY NPY_CARRAY_RO 00794 #define NPY_OUT_ARRAY NPY_CARRAY 00795 #define NPY_INOUT_ARRAY (NPY_CARRAY | NPY_UPDATEIFCOPY) 00796 #define NPY_IN_FARRAY NPY_FARRAY_RO 00797 #define NPY_OUT_FARRAY NPY_FARRAY 00798 #define NPY_INOUT_FARRAY (NPY_FARRAY | NPY_UPDATEIFCOPY) 00799 00800 #define NPY_UPDATE_ALL (NPY_CONTIGUOUS | NPY_FORTRAN | NPY_ALIGNED) 00801 00802 00803 /* 00804 * Size of internal buffers used for alignment Make BUFSIZE a multiple 00805 * of sizeof(cdouble) -- ususally 16 so that ufunc buffers are aligned 00806 */ 00807 #define NPY_MIN_BUFSIZE ((int)sizeof(cdouble)) 00808 #define NPY_MAX_BUFSIZE (((int)sizeof(cdouble))*1000000) 00809 #define NPY_BUFSIZE 8192 00810 /* buffer stress test size: */ 00811 /*#define NPY_BUFSIZE 17*/ 00812 00813 #define PyArray_MAX(a,b) (((a)>(b))?(a):(b)) 00814 #define PyArray_MIN(a,b) (((a)<(b))?(a):(b)) 00815 #define PyArray_CLT(p,q) ((((p).real==(q).real) ? ((p).imag < (q).imag) : \ 00816 ((p).real < (q).real))) 00817 #define PyArray_CGT(p,q) ((((p).real==(q).real) ? ((p).imag > (q).imag) : \ 00818 ((p).real > (q).real))) 00819 #define PyArray_CLE(p,q) ((((p).real==(q).real) ? ((p).imag <= (q).imag) : \ 00820 ((p).real <= (q).real))) 00821 #define PyArray_CGE(p,q) ((((p).real==(q).real) ? ((p).imag >= (q).imag) : \ 00822 ((p).real >= (q).real))) 00823 #define PyArray_CEQ(p,q) (((p).real==(q).real) && ((p).imag == (q).imag)) 00824 #define PyArray_CNE(p,q) (((p).real!=(q).real) || ((p).imag != (q).imag)) 00825 00826 /* 00827 * C API: consists of Macros and functions. The MACROS are defined 00828 * here. 00829 */ 00830 00831 00832 #define PyArray_CHKFLAGS(m, FLAGS) \ 00833 ((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS)) 00834 00835 #define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_CONTIGUOUS) 00836 #define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, NPY_WRITEABLE) 00837 #define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, NPY_ALIGNED) 00838 00839 #define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_C_CONTIGUOUS) 00840 #define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_F_CONTIGUOUS) 00841 00842 #if NPY_ALLOW_THREADS 00843 #define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS 00844 #define NPY_END_ALLOW_THREADS Py_END_ALLOW_THREADS 00845 #define NPY_BEGIN_THREADS_DEF PyThreadState *_save=NULL; 00846 #define NPY_BEGIN_THREADS _save = PyEval_SaveThread(); 00847 #define NPY_END_THREADS do {if (_save) PyEval_RestoreThread(_save);} while (0); 00848 00849 #define NPY_BEGIN_THREADS_DESCR(dtype) \ 00850 do {if (!(PyDataType_FLAGCHK(dtype, NPY_NEEDS_PYAPI))) \ 00851 NPY_BEGIN_THREADS;} while (0); 00852 00853 #define NPY_END_THREADS_DESCR(dtype) \ 00854 do {if (!(PyDataType_FLAGCHK(dtype, NPY_NEEDS_PYAPI))) \ 00855 NPY_END_THREADS; } while (0); 00856 00857 #define NPY_ALLOW_C_API_DEF PyGILState_STATE __save__; 00858 #define NPY_ALLOW_C_API __save__ = PyGILState_Ensure(); 00859 #define NPY_DISABLE_C_API PyGILState_Release(__save__); 00860 #else 00861 #define NPY_BEGIN_ALLOW_THREADS 00862 #define NPY_END_ALLOW_THREADS 00863 #define NPY_BEGIN_THREADS_DEF 00864 #define NPY_BEGIN_THREADS 00865 #define NPY_END_THREADS 00866 #define NPY_BEGIN_THREADS_DESCR(dtype) 00867 #define NPY_END_THREADS_DESCR(dtype) 00868 #define NPY_ALLOW_C_API_DEF 00869 #define NPY_ALLOW_C_API 00870 #define NPY_DISABLE_C_API 00871 #endif 00872 00873 /***************************** 00874 * New iterator object 00875 *****************************/ 00876 00877 /* The actual structure of the iterator is an internal detail */ 00878 typedef struct NpyIter_InternalOnly NpyIter; 00879 00880 /* Iterator function pointers that may be specialized */ 00881 typedef int (NpyIter_IterNextFunc)(NpyIter *iter); 00882 typedef void (NpyIter_GetMultiIndexFunc)(NpyIter *iter, 00883 npy_intp *outcoords); 00884 00885 /*** Global flags that may be passed to the iterator constructors ***/ 00886 00887 /* Track an index representing C order */ 00888 #define NPY_ITER_C_INDEX 0x00000001 00889 /* Track an index representing Fortran order */ 00890 #define NPY_ITER_F_INDEX 0x00000002 00891 /* Track a multi-index */ 00892 #define NPY_ITER_MULTI_INDEX 0x00000004 00893 /* User code external to the iterator does the 1-dimensional innermost loop */ 00894 #define NPY_ITER_EXTERNAL_LOOP 0x00000008 00895 /* Convert all the operands to a common data type */ 00896 #define NPY_ITER_COMMON_DTYPE 0x00000010 00897 /* Operands may hold references, requiring API access during iteration */ 00898 #define NPY_ITER_REFS_OK 0x00000020 00899 /* Zero-sized operands should be permitted, iteration checks IterSize for 0 */ 00900 #define NPY_ITER_ZEROSIZE_OK 0x00000040 00901 /* Permits reductions (size-0 stride with dimension size > 1) */ 00902 #define NPY_ITER_REDUCE_OK 0x00000080 00903 /* Enables sub-range iteration */ 00904 #define NPY_ITER_RANGED 0x00000100 00905 /* Enables buffering */ 00906 #define NPY_ITER_BUFFERED 0x00000200 00907 /* When buffering is enabled, grows the inner loop if possible */ 00908 #define NPY_ITER_GROWINNER 0x00000400 00909 /* Delay allocation of buffers until first Reset* call */ 00910 #define NPY_ITER_DELAY_BUFALLOC 0x00000800 00911 /* When NPY_KEEPORDER is specified, disable reversing negative-stride axes */ 00912 #define NPY_ITER_DONT_NEGATE_STRIDES 0x00001000 00913 00914 /*** Per-operand flags that may be passed to the iterator constructors ***/ 00915 00916 /* The operand will be read from and written to */ 00917 #define NPY_ITER_READWRITE 0x00010000 00918 /* The operand will only be read from */ 00919 #define NPY_ITER_READONLY 0x00020000 00920 /* The operand will only be written to */ 00921 #define NPY_ITER_WRITEONLY 0x00040000 00922 /* The operand's data must be in native byte order */ 00923 #define NPY_ITER_NBO 0x00080000 00924 /* The operand's data must be aligned */ 00925 #define NPY_ITER_ALIGNED 0x00100000 00926 /* The operand's data must be contiguous (within the inner loop) */ 00927 #define NPY_ITER_CONTIG 0x00200000 00928 /* The operand may be copied to satisfy requirements */ 00929 #define NPY_ITER_COPY 0x00400000 00930 /* The operand may be copied with UPDATEIFCOPY to satisfy requirements */ 00931 #define NPY_ITER_UPDATEIFCOPY 0x00800000 00932 /* Allocate the operand if it is NULL */ 00933 #define NPY_ITER_ALLOCATE 0x01000000 00934 /* If an operand is allocated, don't use any subtype */ 00935 #define NPY_ITER_NO_SUBTYPE 0x02000000 00936 /* Require that the dimension match the iterator dimensions exactly */ 00937 #define NPY_ITER_NO_BROADCAST 0x08000000 00938 00939 #define NPY_ITER_GLOBAL_FLAGS 0x0000ffff 00940 #define NPY_ITER_PER_OP_FLAGS 0xffff0000 00941 00942 00943 /***************************** 00944 * Basic iterator object 00945 *****************************/ 00946 00947 /* FWD declaration */ 00948 typedef struct PyArrayIterObject_tag PyArrayIterObject; 00949 00950 /* 00951 * type of the function which translates a set of coordinates to a 00952 * pointer to the data 00953 */ 00954 typedef char* (*npy_iter_get_dataptr_t)(PyArrayIterObject* iter, npy_intp*); 00955 00956 struct PyArrayIterObject_tag { 00957 PyObject_HEAD 00958 int nd_m1; /* number of dimensions - 1 */ 00959 npy_intp index, size; 00960 npy_intp coordinates[NPY_MAXDIMS];/* N-dimensional loop */ 00961 npy_intp dims_m1[NPY_MAXDIMS]; /* ao->dimensions - 1 */ 00962 npy_intp strides[NPY_MAXDIMS]; /* ao->strides or fake */ 00963 npy_intp backstrides[NPY_MAXDIMS];/* how far to jump back */ 00964 npy_intp factors[NPY_MAXDIMS]; /* shape factors */ 00965 PyArrayObject *ao; 00966 char *dataptr; /* pointer to current item*/ 00967 npy_bool contiguous; 00968 00969 npy_intp bounds[NPY_MAXDIMS][2]; 00970 npy_intp limits[NPY_MAXDIMS][2]; 00971 npy_intp limits_sizes[NPY_MAXDIMS]; 00972 npy_iter_get_dataptr_t translate; 00973 } ; 00974 00975 00976 /* Iterator API */ 00977 #define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type) 00978 00979 #define _PyAIT(it) ((PyArrayIterObject *)(it)) 00980 #define PyArray_ITER_RESET(it) { \ 00981 _PyAIT(it)->index = 0; \ 00982 _PyAIT(it)->dataptr = _PyAIT(it)->ao->data; \ 00983 memset(_PyAIT(it)->coordinates, 0, \ 00984 (_PyAIT(it)->nd_m1+1)*sizeof(npy_intp)); \ 00985 } 00986 00987 #define _PyArray_ITER_NEXT1(it) { \ 00988 (it)->dataptr += _PyAIT(it)->strides[0]; \ 00989 (it)->coordinates[0]++; \ 00990 } 00991 00992 #define _PyArray_ITER_NEXT2(it) { \ 00993 if ((it)->coordinates[1] < (it)->dims_m1[1]) { \ 00994 (it)->coordinates[1]++; \ 00995 (it)->dataptr += (it)->strides[1]; \ 00996 } \ 00997 else { \ 00998 (it)->coordinates[1] = 0; \ 00999 (it)->coordinates[0]++; \ 01000 (it)->dataptr += (it)->strides[0] - \ 01001 (it)->backstrides[1]; \ 01002 } \ 01003 } 01004 01005 #define _PyArray_ITER_NEXT3(it) { \ 01006 if ((it)->coordinates[2] < (it)->dims_m1[2]) { \ 01007 (it)->coordinates[2]++; \ 01008 (it)->dataptr += (it)->strides[2]; \ 01009 } \ 01010 else { \ 01011 (it)->coordinates[2] = 0; \ 01012 (it)->dataptr -= (it)->backstrides[2]; \ 01013 if ((it)->coordinates[1] < (it)->dims_m1[1]) { \ 01014 (it)->coordinates[1]++; \ 01015 (it)->dataptr += (it)->strides[1]; \ 01016 } \ 01017 else { \ 01018 (it)->coordinates[1] = 0; \ 01019 (it)->coordinates[0]++; \ 01020 (it)->dataptr += (it)->strides[0] - \ 01021 (it)->backstrides[1]; \ 01022 } \ 01023 } \ 01024 } 01025 01026 #define PyArray_ITER_NEXT(it) { \ 01027 _PyAIT(it)->index++; \ 01028 if (_PyAIT(it)->nd_m1 == 0) { \ 01029 _PyArray_ITER_NEXT1(_PyAIT(it)); \ 01030 } \ 01031 else if (_PyAIT(it)->contiguous) \ 01032 _PyAIT(it)->dataptr += _PyAIT(it)->ao->descr->elsize; \ 01033 else if (_PyAIT(it)->nd_m1 == 1) { \ 01034 _PyArray_ITER_NEXT2(_PyAIT(it)); \ 01035 } \ 01036 else { \ 01037 int __npy_i; \ 01038 for (__npy_i=_PyAIT(it)->nd_m1; __npy_i >= 0; __npy_i--) { \ 01039 if (_PyAIT(it)->coordinates[__npy_i] < \ 01040 _PyAIT(it)->dims_m1[__npy_i]) { \ 01041 _PyAIT(it)->coordinates[__npy_i]++; \ 01042 _PyAIT(it)->dataptr += \ 01043 _PyAIT(it)->strides[__npy_i]; \ 01044 break; \ 01045 } \ 01046 else { \ 01047 _PyAIT(it)->coordinates[__npy_i] = 0; \ 01048 _PyAIT(it)->dataptr -= \ 01049 _PyAIT(it)->backstrides[__npy_i]; \ 01050 } \ 01051 } \ 01052 } \ 01053 } 01054 01055 #define PyArray_ITER_GOTO(it, destination) { \ 01056 int __npy_i; \ 01057 _PyAIT(it)->index = 0; \ 01058 _PyAIT(it)->dataptr = _PyAIT(it)->ao->data; \ 01059 for (__npy_i = _PyAIT(it)->nd_m1; __npy_i>=0; __npy_i--) { \ 01060 if (destination[__npy_i] < 0) { \ 01061 destination[__npy_i] += \ 01062 _PyAIT(it)->dims_m1[__npy_i]+1; \ 01063 } \ 01064 _PyAIT(it)->dataptr += destination[__npy_i] * \ 01065 _PyAIT(it)->strides[__npy_i]; \ 01066 _PyAIT(it)->coordinates[__npy_i] = \ 01067 destination[__npy_i]; \ 01068 _PyAIT(it)->index += destination[__npy_i] * \ 01069 ( __npy_i==_PyAIT(it)->nd_m1 ? 1 : \ 01070 _PyAIT(it)->dims_m1[__npy_i+1]+1) ; \ 01071 } \ 01072 } 01073 01074 #define PyArray_ITER_GOTO1D(it, ind) { \ 01075 int __npy_i; \ 01076 npy_intp __npy_ind = (npy_intp) (ind); \ 01077 if (__npy_ind < 0) __npy_ind += _PyAIT(it)->size; \ 01078 _PyAIT(it)->index = __npy_ind; \ 01079 if (_PyAIT(it)->nd_m1 == 0) { \ 01080 _PyAIT(it)->dataptr = _PyAIT(it)->ao->data + \ 01081 __npy_ind * _PyAIT(it)->strides[0]; \ 01082 } \ 01083 else if (_PyAIT(it)->contiguous) \ 01084 _PyAIT(it)->dataptr = _PyAIT(it)->ao->data + \ 01085 __npy_ind * _PyAIT(it)->ao->descr->elsize; \ 01086 else { \ 01087 _PyAIT(it)->dataptr = _PyAIT(it)->ao->data; \ 01088 for (__npy_i = 0; __npy_i<=_PyAIT(it)->nd_m1; \ 01089 __npy_i++) { \ 01090 _PyAIT(it)->dataptr += \ 01091 (__npy_ind / _PyAIT(it)->factors[__npy_i]) \ 01092 * _PyAIT(it)->strides[__npy_i]; \ 01093 __npy_ind %= _PyAIT(it)->factors[__npy_i]; \ 01094 } \ 01095 } \ 01096 } 01097 01098 #define PyArray_ITER_DATA(it) ((void *)(_PyAIT(it)->dataptr)) 01099 01100 #define PyArray_ITER_NOTDONE(it) (_PyAIT(it)->index < _PyAIT(it)->size) 01101 01102 01103 /* 01104 * Any object passed to PyArray_Broadcast must be binary compatible 01105 * with this structure. 01106 */ 01107 01108 typedef struct { 01109 PyObject_HEAD 01110 int numiter; /* number of iters */ 01111 npy_intp size; /* broadcasted size */ 01112 npy_intp index; /* current index */ 01113 int nd; /* number of dims */ 01114 npy_intp dimensions[NPY_MAXDIMS]; /* dimensions */ 01115 PyArrayIterObject *iters[NPY_MAXARGS]; /* iterators */ 01116 } PyArrayMultiIterObject; 01117 01118 #define _PyMIT(m) ((PyArrayMultiIterObject *)(m)) 01119 #define PyArray_MultiIter_RESET(multi) { \ 01120 int __npy_mi; \ 01121 _PyMIT(multi)->index = 0; \ 01122 for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \ 01123 PyArray_ITER_RESET(_PyMIT(multi)->iters[__npy_mi]); \ 01124 } \ 01125 } 01126 01127 #define PyArray_MultiIter_NEXT(multi) { \ 01128 int __npy_mi; \ 01129 _PyMIT(multi)->index++; \ 01130 for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \ 01131 PyArray_ITER_NEXT(_PyMIT(multi)->iters[__npy_mi]); \ 01132 } \ 01133 } 01134 01135 #define PyArray_MultiIter_GOTO(multi, dest) { \ 01136 int __npy_mi; \ 01137 for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \ 01138 PyArray_ITER_GOTO(_PyMIT(multi)->iters[__npy_mi], dest); \ 01139 } \ 01140 _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \ 01141 } 01142 01143 #define PyArray_MultiIter_GOTO1D(multi, ind) { \ 01144 int __npy_mi; \ 01145 for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \ 01146 PyArray_ITER_GOTO1D(_PyMIT(multi)->iters[__npy_mi], ind); \ 01147 } \ 01148 _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \ 01149 } 01150 01151 #define PyArray_MultiIter_DATA(multi, i) \ 01152 ((void *)(_PyMIT(multi)->iters[i]->dataptr)) 01153 01154 #define PyArray_MultiIter_NEXTi(multi, i) \ 01155 PyArray_ITER_NEXT(_PyMIT(multi)->iters[i]) 01156 01157 #define PyArray_MultiIter_NOTDONE(multi) \ 01158 (_PyMIT(multi)->index < _PyMIT(multi)->size) 01159 01160 /* Store the information needed for fancy-indexing over an array */ 01161 01162 typedef struct { 01163 PyObject_HEAD 01164 /* 01165 * Multi-iterator portion --- needs to be present in this 01166 * order to work with PyArray_Broadcast 01167 */ 01168 01169 int numiter; /* number of index-array 01170 iterators */ 01171 npy_intp size; /* size of broadcasted 01172 result */ 01173 npy_intp index; /* current index */ 01174 int nd; /* number of dims */ 01175 npy_intp dimensions[NPY_MAXDIMS]; /* dimensions */ 01176 PyArrayIterObject *iters[NPY_MAXDIMS]; /* index object 01177 iterators */ 01178 PyArrayIterObject *ait; /* flat Iterator for 01179 underlying array */ 01180 01181 /* flat iterator for subspace (when numiter < nd) */ 01182 PyArrayIterObject *subspace; 01183 01184 /* 01185 * if subspace iteration, then this is the array of axes in 01186 * the underlying array represented by the index objects 01187 */ 01188 int iteraxes[NPY_MAXDIMS]; 01189 /* 01190 * if subspace iteration, the these are the coordinates to the 01191 * start of the subspace. 01192 */ 01193 npy_intp bscoord[NPY_MAXDIMS]; 01194 01195 PyObject *indexobj; /* creating obj */ 01196 int consec; 01197 char *dataptr; 01198 01199 } PyArrayMapIterObject; 01200 01201 enum { 01202 NPY_NEIGHBORHOOD_ITER_ZERO_PADDING, 01203 NPY_NEIGHBORHOOD_ITER_ONE_PADDING, 01204 NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING, 01205 NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING, 01206 NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING 01207 }; 01208 01209 typedef struct { 01210 PyObject_HEAD 01211 01212 /* 01213 * PyArrayIterObject part: keep this in this exact order 01214 */ 01215 int nd_m1; /* number of dimensions - 1 */ 01216 npy_intp index, size; 01217 npy_intp coordinates[NPY_MAXDIMS];/* N-dimensional loop */ 01218 npy_intp dims_m1[NPY_MAXDIMS]; /* ao->dimensions - 1 */ 01219 npy_intp strides[NPY_MAXDIMS]; /* ao->strides or fake */ 01220 npy_intp backstrides[NPY_MAXDIMS];/* how far to jump back */ 01221 npy_intp factors[NPY_MAXDIMS]; /* shape factors */ 01222 PyArrayObject *ao; 01223 char *dataptr; /* pointer to current item*/ 01224 npy_bool contiguous; 01225 01226 npy_intp bounds[NPY_MAXDIMS][2]; 01227 npy_intp limits[NPY_MAXDIMS][2]; 01228 npy_intp limits_sizes[NPY_MAXDIMS]; 01229 npy_iter_get_dataptr_t translate; 01230 01231 /* 01232 * New members 01233 */ 01234 npy_intp nd; 01235 01236 /* Dimensions is the dimension of the array */ 01237 npy_intp dimensions[NPY_MAXDIMS]; 01238 01239 /* 01240 * Neighborhood points coordinates are computed relatively to the 01241 * point pointed by _internal_iter 01242 */ 01243 PyArrayIterObject* _internal_iter; 01244 /* 01245 * To keep a reference to the representation of the constant value 01246 * for constant padding 01247 */ 01248 char* constant; 01249 01250 int mode; 01251 } PyArrayNeighborhoodIterObject; 01252 01253 /* 01254 * Neighborhood iterator API 01255 */ 01256 01257 /* General: those work for any mode */ 01258 static NPY_INLINE int 01259 PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter); 01260 static NPY_INLINE int 01261 PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter); 01262 #if 0 01263 static NPY_INLINE int 01264 PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter); 01265 #endif 01266 01267 /* 01268 * Include inline implementations - functions defined there are not 01269 * considered public API 01270 */ 01271 #define _NPY_INCLUDE_NEIGHBORHOOD_IMP 01272 #include "_neighborhood_iterator_imp.h" 01273 #undef _NPY_INCLUDE_NEIGHBORHOOD_IMP 01274 01275 /* The default array type */ 01276 #define NPY_DEFAULT_TYPE NPY_DOUBLE 01277 #define PyArray_DEFAULT NPY_DEFAULT_TYPE 01278 01279 /* 01280 * All sorts of useful ways to look into a PyArrayObject. These are 01281 * the recommended over casting to PyArrayObject and accessing the 01282 * members directly. 01283 */ 01284 01285 #define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd) 01286 #define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || \ 01287 PyArray_CHKFLAGS(m, NPY_CONTIGUOUS) || \ 01288 PyArray_CHKFLAGS(m, NPY_FORTRAN)) 01289 01290 #define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_FORTRAN) && \ 01291 (PyArray_NDIM(m) > 1)) 01292 01293 #define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_FORTRAN) ? \ 01294 NPY_FORTRAN : 0)) 01295 01296 #define FORTRAN_IF PyArray_FORTRAN_IF 01297 #define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data)) 01298 #define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data) 01299 #define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions) 01300 #define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides) 01301 #define PyArray_DIM(obj,n) (PyArray_DIMS(obj)[n]) 01302 #define PyArray_STRIDE(obj,n) (PyArray_STRIDES(obj)[n]) 01303 #define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base) 01304 #define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr) 01305 #define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags) 01306 #define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize) 01307 #define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num) 01308 01309 #define PyArray_GETITEM(obj,itemptr) \ 01310 ((PyArrayObject *)(obj))->descr->f->getitem((char *)(itemptr), \ 01311 (PyArrayObject *)(obj)) 01312 01313 #define PyArray_SETITEM(obj,itemptr,v) \ 01314 ((PyArrayObject *)(obj))->descr->f->setitem((PyObject *)(v), \ 01315 (char *)(itemptr), \ 01316 (PyArrayObject *)(obj)) 01317 01318 01319 #define PyTypeNum_ISBOOL(type) ((type) == NPY_BOOL) 01320 01321 #define PyTypeNum_ISUNSIGNED(type) (((type) == NPY_UBYTE) || \ 01322 ((type) == NPY_USHORT) || \ 01323 ((type) == NPY_UINT) || \ 01324 ((type) == NPY_ULONG) || \ 01325 ((type) == NPY_ULONGLONG)) 01326 01327 #define PyTypeNum_ISSIGNED(type) (((type) == NPY_BYTE) || \ 01328 ((type) == NPY_SHORT) || \ 01329 ((type) == NPY_INT) || \ 01330 ((type) == NPY_LONG) || \ 01331 ((type) == NPY_LONGLONG)) 01332 01333 #define PyTypeNum_ISINTEGER(type) (((type) >= NPY_BYTE) && \ 01334 ((type) <= NPY_ULONGLONG)) 01335 01336 #define PyTypeNum_ISFLOAT(type) ((((type) >= NPY_FLOAT) && \ 01337 ((type) <= NPY_LONGDOUBLE)) || \ 01338 ((type) == NPY_HALF)) 01339 01340 #define PyTypeNum_ISNUMBER(type) (((type) <= NPY_CLONGDOUBLE) || \ 01341 ((type) == NPY_HALF)) 01342 01343 #define PyTypeNum_ISSTRING(type) (((type) == NPY_STRING) || \ 01344 ((type) == NPY_UNICODE)) 01345 01346 #define PyTypeNum_ISCOMPLEX(type) (((type) >= NPY_CFLOAT) && \ 01347 ((type) <= NPY_CLONGDOUBLE)) 01348 01349 #define PyTypeNum_ISPYTHON(type) (((type) == NPY_LONG) || \ 01350 ((type) == NPY_DOUBLE) || \ 01351 ((type) == NPY_CDOUBLE) || \ 01352 ((type) == NPY_BOOL) || \ 01353 ((type) == NPY_OBJECT )) 01354 01355 #define PyTypeNum_ISFLEXIBLE(type) (((type) >=NPY_STRING) && \ 01356 ((type) <=NPY_VOID)) 01357 01358 #define PyTypeNum_ISDATETIME(type) (((type) >=NPY_DATETIME) && \ 01359 ((type) <=NPY_TIMEDELTA)) 01360 01361 #define PyTypeNum_ISUSERDEF(type) (((type) >= NPY_USERDEF) && \ 01362 ((type) < NPY_USERDEF+ \ 01363 NPY_NUMUSERTYPES)) 01364 01365 #define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \ 01366 PyTypeNum_ISUSERDEF(type)) 01367 01368 #define PyTypeNum_ISOBJECT(type) ((type) == NPY_OBJECT) 01369 01370 01371 #define PyDataType_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj)) 01372 #define PyDataType_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(((PyArray_Descr*)(obj))->type_num) 01373 #define PyDataType_ISSIGNED(obj) PyTypeNum_ISSIGNED(((PyArray_Descr*)(obj))->type_num) 01374 #define PyDataType_ISINTEGER(obj) PyTypeNum_ISINTEGER(((PyArray_Descr*)(obj))->type_num ) 01375 #define PyDataType_ISFLOAT(obj) PyTypeNum_ISFLOAT(((PyArray_Descr*)(obj))->type_num) 01376 #define PyDataType_ISNUMBER(obj) PyTypeNum_ISNUMBER(((PyArray_Descr*)(obj))->type_num) 01377 #define PyDataType_ISSTRING(obj) PyTypeNum_ISSTRING(((PyArray_Descr*)(obj))->type_num) 01378 #define PyDataType_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(((PyArray_Descr*)(obj))->type_num) 01379 #define PyDataType_ISPYTHON(obj) PyTypeNum_ISPYTHON(((PyArray_Descr*)(obj))->type_num) 01380 #define PyDataType_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(((PyArray_Descr*)(obj))->type_num) 01381 #define PyDataType_ISDATETIME(obj) PyTypeNum_ISDATETIME(((PyArray_Descr*)(obj))->type_num) 01382 #define PyDataType_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(((PyArray_Descr*)(obj))->type_num) 01383 #define PyDataType_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(((PyArray_Descr*)(obj))->type_num) 01384 #define PyDataType_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)(obj))->type_num) 01385 #define PyDataType_HASFIELDS(obj) (((PyArray_Descr *)(obj))->names != NULL) 01386 01387 #define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj)) 01388 #define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj)) 01389 #define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj)) 01390 #define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj)) 01391 #define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj)) 01392 #define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj)) 01393 #define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj)) 01394 #define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj)) 01395 #define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj)) 01396 #define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj)) 01397 #define PyArray_ISDATETIME(obj) PyTypeNum_ISDATETIME(PyArray_TYPE(obj)) 01398 #define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj)) 01399 #define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj)) 01400 #define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj)) 01401 #define PyArray_HASFIELDS(obj) PyDataType_HASFIELDS(PyArray_DESCR(obj)) 01402 01403 /* 01404 * FIXME: This should check for a flag on the data-type that 01405 * states whether or not it is variable length. Because the 01406 * ISFLEXIBLE check is hard-coded to the built-in data-types. 01407 */ 01408 #define PyArray_ISVARIABLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj)) 01409 01410 #define PyArray_SAFEALIGNEDCOPY(obj) (PyArray_ISALIGNED(obj) && !PyArray_ISVARIABLE(obj)) 01411 01412 01413 #define NPY_LITTLE '<' 01414 #define NPY_BIG '>' 01415 #define NPY_NATIVE '=' 01416 #define NPY_SWAP 's' 01417 #define NPY_IGNORE '|' 01418 01419 #if NPY_BYTE_ORDER == NPY_BIG_ENDIAN 01420 #define NPY_NATBYTE NPY_BIG 01421 #define NPY_OPPBYTE NPY_LITTLE 01422 #else 01423 #define NPY_NATBYTE NPY_LITTLE 01424 #define NPY_OPPBYTE NPY_BIG 01425 #endif 01426 01427 #define PyArray_ISNBO(arg) ((arg) != NPY_OPPBYTE) 01428 #define PyArray_IsNativeByteOrder PyArray_ISNBO 01429 #define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder) 01430 #define PyArray_ISBYTESWAPPED(m) (!PyArray_ISNOTSWAPPED(m)) 01431 01432 #define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) && \ 01433 PyArray_ISNOTSWAPPED(m)) 01434 01435 #define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, NPY_CARRAY) 01436 #define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_CARRAY_RO) 01437 #define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, NPY_FARRAY) 01438 #define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_FARRAY_RO) 01439 #define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, NPY_BEHAVED) 01440 #define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, NPY_ALIGNED) 01441 01442 01443 #define PyDataType_ISNOTSWAPPED(d) PyArray_ISNBO(((PyArray_Descr *)(d))->byteorder) 01444 #define PyDataType_ISBYTESWAPPED(d) (!PyDataType_ISNOTSWAPPED(d)) 01445 01446 01447 /* 01448 * This is the form of the struct that's returned pointed by the 01449 * PyCObject attribute of an array __array_struct__. See 01450 * http://numpy.scipy.org/array_interface.shtml for the full 01451 * documentation. 01452 */ 01453 typedef struct { 01454 int two; /* 01455 * contains the integer 2 as a sanity 01456 * check 01457 */ 01458 01459 int nd; /* number of dimensions */ 01460 01461 char typekind; /* 01462 * kind in array --- character code of 01463 * typestr 01464 */ 01465 01466 int itemsize; /* size of each element */ 01467 01468 int flags; /* 01469 * how should be data interpreted. Valid 01470 * flags are CONTIGUOUS (1), FORTRAN (2), 01471 * ALIGNED (0x100), NOTSWAPPED (0x200), and 01472 * WRITEABLE (0x400). ARR_HAS_DESCR (0x800) 01473 * states that arrdescr field is present in 01474 * structure 01475 */ 01476 01477 npy_intp *shape; /* 01478 * A length-nd array of shape 01479 * information 01480 */ 01481 01482 npy_intp *strides; /* A length-nd array of stride information */ 01483 01484 void *data; /* A pointer to the first element of the array */ 01485 01486 PyObject *descr; /* 01487 * A list of fields or NULL (ignored if flags 01488 * does not have ARR_HAS_DESCR flag set) 01489 */ 01490 } PyArrayInterface; 01491 01492 #endif /* NPY_ARRAYTYPES_H */