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