numpy
2.0.0
|
00001 #ifndef NDARRAYTYPES_H 00002 #define NDARRAYTYPES_H 00003 00004 #include "npy_common.h" 00005 #include "npy_endian.h" 00006 #include "npy_cpu.h" 00007 #include "utils.h" 00008 00009 #define NPY_NO_EXPORT NPY_VISIBILITY_HIDDEN 00010 00011 /* Only use thread if configured in config and python supports it */ 00012 #if defined WITH_THREAD && !NPY_NO_SMP 00013 #define NPY_ALLOW_THREADS 1 00014 #else 00015 #define NPY_ALLOW_THREADS 0 00016 #endif 00017 00018 00019 00020 /* 00021 * There are several places in the code where an array of dimensions 00022 * is allocated statically. This is the size of that static 00023 * allocation. 00024 * 00025 * The array creation itself could have arbitrary dimensions but all 00026 * the places where static allocation is used would need to be changed 00027 * to dynamic (including inside of several structures) 00028 */ 00029 00030 #define NPY_MAXDIMS 32 00031 #define NPY_MAXARGS 32 00032 00033 /* Used for Converter Functions "O&" code in ParseTuple */ 00034 #define NPY_FAIL 0 00035 #define NPY_SUCCEED 1 00036 00037 /* 00038 * Binary compatibility version number. This number is increased 00039 * whenever the C-API is changed such that binary compatibility is 00040 * broken, i.e. whenever a recompile of extension modules is needed. 00041 */ 00042 #define NPY_VERSION NPY_ABI_VERSION 00043 00044 /* 00045 * Minor API version. This number is increased whenever a change is 00046 * made to the C-API -- whether it breaks binary compatibility or not. 00047 * Some changes, such as adding a function pointer to the end of the 00048 * function table, can be made without breaking binary compatibility. 00049 * In this case, only the NPY_FEATURE_VERSION (*not* NPY_VERSION) 00050 * would be increased. Whenever binary compatibility is broken, both 00051 * NPY_VERSION and NPY_FEATURE_VERSION should be increased. 00052 */ 00053 #define NPY_FEATURE_VERSION NPY_API_VERSION 00054 00055 enum NPY_TYPES { NPY_BOOL=0, 00056 NPY_BYTE, NPY_UBYTE, 00057 NPY_SHORT, NPY_USHORT, 00058 NPY_INT, NPY_UINT, 00059 NPY_LONG, NPY_ULONG, 00060 NPY_LONGLONG, NPY_ULONGLONG, 00061 NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE, 00062 NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE, 00063 NPY_OBJECT=17, 00064 NPY_STRING, NPY_UNICODE, 00065 NPY_VOID, 00066 /* 00067 * New 1.6 types appended, may be integrated 00068 * into the above in 2.0. 00069 */ 00070 NPY_DATETIME, NPY_TIMEDELTA, NPY_HALF, 00071 00072 NPY_NTYPES, 00073 NPY_NOTYPE, 00074 NPY_CHAR, /* special flag */ 00075 NPY_USERDEF=256, /* leave room for characters */ 00076 00077 /* The number of types not including the new 1.6 types */ 00078 NPY_NTYPES_ABI_COMPATIBLE=21 00079 }; 00080 00081 /* basetype array priority */ 00082 #define NPY_PRIORITY 0.0 00083 00084 /* default subtype priority */ 00085 #define NPY_SUBTYPE_PRIORITY 1.0 00086 00087 /* default scalar priority */ 00088 #define NPY_SCALAR_PRIORITY -1000000.0 00089 00090 /* How many floating point types are there (excluding half) */ 00091 #define NPY_NUM_FLOATTYPE 3 00092 00093 /* 00094 * These characters correspond to the array type and the struct 00095 * module 00096 */ 00097 00098 enum NPY_TYPECHAR { 00099 NPY_BOOLLTR = '?', 00100 NPY_BYTELTR = 'b', 00101 NPY_UBYTELTR = 'B', 00102 NPY_SHORTLTR = 'h', 00103 NPY_USHORTLTR = 'H', 00104 NPY_INTLTR = 'i', 00105 NPY_UINTLTR = 'I', 00106 NPY_LONGLTR = 'l', 00107 NPY_ULONGLTR = 'L', 00108 NPY_LONGLONGLTR = 'q', 00109 NPY_ULONGLONGLTR = 'Q', 00110 NPY_HALFLTR = 'e', 00111 NPY_FLOATLTR = 'f', 00112 NPY_DOUBLELTR = 'd', 00113 NPY_LONGDOUBLELTR = 'g', 00114 NPY_CFLOATLTR = 'F', 00115 NPY_CDOUBLELTR = 'D', 00116 NPY_CLONGDOUBLELTR = 'G', 00117 NPY_OBJECTLTR = 'O', 00118 NPY_STRINGLTR = 'S', 00119 NPY_STRINGLTR2 = 'a', 00120 NPY_UNICODELTR = 'U', 00121 NPY_VOIDLTR = 'V', 00122 NPY_DATETIMELTR = 'M', 00123 NPY_TIMEDELTALTR = 'm', 00124 NPY_CHARLTR = 'c', 00125 00126 /* 00127 * No Descriptor, just a define -- this let's 00128 * Python users specify an array of integers 00129 * large enough to hold a pointer on the 00130 * platform 00131 */ 00132 NPY_INTPLTR = 'p', 00133 NPY_UINTPLTR = 'P', 00134 00135 /* 00136 * These are for dtype 'kinds', not dtype 'typecodes' 00137 * as the above are for. 00138 */ 00139 NPY_GENBOOLLTR ='b', 00140 NPY_SIGNEDLTR = 'i', 00141 NPY_UNSIGNEDLTR = 'u', 00142 NPY_FLOATINGLTR = 'f', 00143 NPY_COMPLEXLTR = 'c' 00144 }; 00145 00146 typedef enum { 00147 NPY_QUICKSORT=0, 00148 NPY_HEAPSORT=1, 00149 NPY_MERGESORT=2 00150 } NPY_SORTKIND; 00151 #define NPY_NSORTS (NPY_MERGESORT + 1) 00152 00153 00154 typedef enum { 00155 NPY_INTROSELECT=0 00156 } NPY_SELECTKIND; 00157 #define NPY_NSELECTS (NPY_INTROSELECT + 1) 00158 00159 00160 typedef enum { 00161 NPY_SEARCHLEFT=0, 00162 NPY_SEARCHRIGHT=1 00163 } NPY_SEARCHSIDE; 00164 #define NPY_NSEARCHSIDES (NPY_SEARCHRIGHT + 1) 00165 00166 00167 typedef enum { 00168 NPY_NOSCALAR=-1, 00169 NPY_BOOL_SCALAR, 00170 NPY_INTPOS_SCALAR, 00171 NPY_INTNEG_SCALAR, 00172 NPY_FLOAT_SCALAR, 00173 NPY_COMPLEX_SCALAR, 00174 NPY_OBJECT_SCALAR 00175 } NPY_SCALARKIND; 00176 #define NPY_NSCALARKINDS (NPY_OBJECT_SCALAR + 1) 00177 00178 /* For specifying array memory layout or iteration order */ 00179 typedef enum { 00180 /* Fortran order if inputs are all Fortran, C otherwise */ 00181 NPY_ANYORDER=-1, 00182 /* C order */ 00183 NPY_CORDER=0, 00184 /* Fortran order */ 00185 NPY_FORTRANORDER=1, 00186 /* An order as close to the inputs as possible */ 00187 NPY_KEEPORDER=2 00188 } NPY_ORDER; 00189 00190 /* For specifying allowed casting in operations which support it */ 00191 typedef enum { 00192 /* Only allow identical types */ 00193 NPY_NO_CASTING=0, 00194 /* Allow identical and byte swapped types */ 00195 NPY_EQUIV_CASTING=1, 00196 /* Only allow safe casts */ 00197 NPY_SAFE_CASTING=2, 00198 /* Allow safe casts or casts within the same kind */ 00199 NPY_SAME_KIND_CASTING=3, 00200 /* Allow any casts */ 00201 NPY_UNSAFE_CASTING=4 00202 } NPY_CASTING; 00203 00204 typedef enum { 00205 NPY_CLIP=0, 00206 NPY_WRAP=1, 00207 NPY_RAISE=2 00208 } NPY_CLIPMODE; 00209 00210 /* The special not-a-time (NaT) value */ 00211 #define NPY_DATETIME_NAT NPY_MIN_INT64 00212 00213 /* 00214 * Upper bound on the length of a DATETIME ISO 8601 string 00215 * YEAR: 21 (64-bit year) 00216 * MONTH: 3 00217 * DAY: 3 00218 * HOURS: 3 00219 * MINUTES: 3 00220 * SECONDS: 3 00221 * ATTOSECONDS: 1 + 3*6 00222 * TIMEZONE: 5 00223 * NULL TERMINATOR: 1 00224 */ 00225 #define NPY_DATETIME_MAX_ISO8601_STRLEN (21+3*5+1+3*6+6+1) 00226 00227 typedef enum { 00228 NPY_FR_Y = 0, /* Years */ 00229 NPY_FR_M = 1, /* Months */ 00230 NPY_FR_W = 2, /* Weeks */ 00231 /* Gap where 1.6 NPY_FR_B (value 3) was */ 00232 NPY_FR_D = 4, /* Days */ 00233 NPY_FR_h = 5, /* hours */ 00234 NPY_FR_m = 6, /* minutes */ 00235 NPY_FR_s = 7, /* seconds */ 00236 NPY_FR_ms = 8, /* milliseconds */ 00237 NPY_FR_us = 9, /* microseconds */ 00238 NPY_FR_ns = 10,/* nanoseconds */ 00239 NPY_FR_ps = 11,/* picoseconds */ 00240 NPY_FR_fs = 12,/* femtoseconds */ 00241 NPY_FR_as = 13,/* attoseconds */ 00242 NPY_FR_GENERIC = 14 /* Generic, unbound units, can convert to anything */ 00243 } NPY_DATETIMEUNIT; 00244 00245 /* 00246 * NOTE: With the NPY_FR_B gap for 1.6 ABI compatibility, NPY_DATETIME_NUMUNITS 00247 * is technically one more than the actual number of units. 00248 */ 00249 #define NPY_DATETIME_NUMUNITS (NPY_FR_GENERIC + 1) 00250 #define NPY_DATETIME_DEFAULTUNIT NPY_FR_GENERIC 00251 00252 /* 00253 * Business day conventions for mapping invalid business 00254 * days to valid business days. 00255 */ 00256 typedef enum { 00257 /* Go forward in time to the following business day. */ 00258 NPY_BUSDAY_FORWARD, 00259 NPY_BUSDAY_FOLLOWING = NPY_BUSDAY_FORWARD, 00260 /* Go backward in time to the preceding business day. */ 00261 NPY_BUSDAY_BACKWARD, 00262 NPY_BUSDAY_PRECEDING = NPY_BUSDAY_BACKWARD, 00263 /* 00264 * Go forward in time to the following business day, unless it 00265 * crosses a month boundary, in which case go backward 00266 */ 00267 NPY_BUSDAY_MODIFIEDFOLLOWING, 00268 /* 00269 * Go backward in time to the preceding business day, unless it 00270 * crosses a month boundary, in which case go forward. 00271 */ 00272 NPY_BUSDAY_MODIFIEDPRECEDING, 00273 /* Produce a NaT for non-business days. */ 00274 NPY_BUSDAY_NAT, 00275 /* Raise an exception for non-business days. */ 00276 NPY_BUSDAY_RAISE 00277 } NPY_BUSDAY_ROLL; 00278 00279 /************************************************************ 00280 * NumPy Auxiliary Data for inner loops, sort functions, etc. 00281 ************************************************************/ 00282 00283 /* 00284 * When creating an auxiliary data struct, this should always appear 00285 * as the first member, like this: 00286 * 00287 * typedef struct { 00288 * NpyAuxData base; 00289 * double constant; 00290 * } constant_multiplier_aux_data; 00291 */ 00292 typedef struct NpyAuxData_tag NpyAuxData; 00293 00294 /* Function pointers for freeing or cloning auxiliary data */ 00295 typedef void (NpyAuxData_FreeFunc) (NpyAuxData *); 00296 typedef NpyAuxData *(NpyAuxData_CloneFunc) (NpyAuxData *); 00297 00298 struct NpyAuxData_tag { 00299 NpyAuxData_FreeFunc *free; 00300 NpyAuxData_CloneFunc *clone; 00301 /* To allow for a bit of expansion without breaking the ABI */ 00302 void *reserved[2]; 00303 }; 00304 00305 /* Macros to use for freeing and cloning auxiliary data */ 00306 #define NPY_AUXDATA_FREE(auxdata) \ 00307 do { \ 00308 if ((auxdata) != NULL) { \ 00309 (auxdata)->free(auxdata); \ 00310 } \ 00311 } while(0) 00312 #define NPY_AUXDATA_CLONE(auxdata) \ 00313 ((auxdata)->clone(auxdata)) 00314 00315 #define NPY_ERR(str) fprintf(stderr, #str); fflush(stderr); 00316 #define NPY_ERR2(str) fprintf(stderr, str); fflush(stderr); 00317 00318 #define NPY_STRINGIFY(x) #x 00319 #define NPY_TOSTRING(x) NPY_STRINGIFY(x) 00320 00321 /* 00322 * Macros to define how array, and dimension/strides data is 00323 * allocated. 00324 */ 00325 00326 /* Data buffer - PyDataMem_NEW/FREE/RENEW are in multiarraymodule.c */ 00327 00328 #define NPY_USE_PYMEM 1 00329 00330 #if NPY_USE_PYMEM == 1 00331 /* numpy sometimes calls PyArray_malloc() with the GIL released. On Python 00332 3.3 and older, it was safe to call PyMem_Malloc() with the GIL released. 00333 On Python 3.4 and newer, it's better to use PyMem_RawMalloc() to be able 00334 to use tracemalloc. On Python 3.6, calling PyMem_Malloc() with the GIL 00335 released is now a fatal error in debug mode. */ 00336 # if PY_VERSION_HEX >= 0x03040000 00337 # define PyArray_malloc PyMem_RawMalloc 00338 # define PyArray_free PyMem_RawFree 00339 # define PyArray_realloc PyMem_RawRealloc 00340 # else 00341 # define PyArray_malloc PyMem_Malloc 00342 # define PyArray_free PyMem_Free 00343 # define PyArray_realloc PyMem_Realloc 00344 # endif 00345 #else 00346 #define PyArray_malloc malloc 00347 #define PyArray_free free 00348 #define PyArray_realloc realloc 00349 #endif 00350 00351 /* Dimensions and strides */ 00352 #define PyDimMem_NEW(size) \ 00353 ((npy_intp *)PyArray_malloc(size*sizeof(npy_intp))) 00354 00355 #define PyDimMem_FREE(ptr) PyArray_free(ptr) 00356 00357 #define PyDimMem_RENEW(ptr,size) \ 00358 ((npy_intp *)PyArray_realloc(ptr,size*sizeof(npy_intp))) 00359 00360 /* forward declaration */ 00361 struct _PyArray_Descr; 00362 00363 /* These must deal with unaligned and swapped data if necessary */ 00364 typedef PyObject * (PyArray_GetItemFunc) (void *, void *); 00365 typedef int (PyArray_SetItemFunc)(PyObject *, void *, void *); 00366 00367 typedef void (PyArray_CopySwapNFunc)(void *, npy_intp, void *, npy_intp, 00368 npy_intp, int, void *); 00369 00370 typedef void (PyArray_CopySwapFunc)(void *, void *, int, void *); 00371 typedef npy_bool (PyArray_NonzeroFunc)(void *, void *); 00372 00373 00374 /* 00375 * These assume aligned and notswapped data -- a buffer will be used 00376 * before or contiguous data will be obtained 00377 */ 00378 00379 typedef int (PyArray_CompareFunc)(const void *, const void *, void *); 00380 typedef int (PyArray_ArgFunc)(void*, npy_intp, npy_intp*, void *); 00381 00382 typedef void (PyArray_DotFunc)(void *, npy_intp, void *, npy_intp, void *, 00383 npy_intp, void *); 00384 00385 typedef void (PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *, 00386 void *); 00387 00388 /* 00389 * XXX the ignore argument should be removed next time the API version 00390 * is bumped. It used to be the separator. 00391 */ 00392 typedef int (PyArray_ScanFunc)(FILE *fp, void *dptr, 00393 char *ignore, struct _PyArray_Descr *); 00394 typedef int (PyArray_FromStrFunc)(char *s, void *dptr, char **endptr, 00395 struct _PyArray_Descr *); 00396 00397 typedef int (PyArray_FillFunc)(void *, npy_intp, void *); 00398 00399 typedef int (PyArray_SortFunc)(void *, npy_intp, void *); 00400 typedef int (PyArray_ArgSortFunc)(void *, npy_intp *, npy_intp, void *); 00401 typedef int (PyArray_PartitionFunc)(void *, npy_intp, npy_intp, 00402 npy_intp *, npy_intp *, 00403 void *); 00404 typedef int (PyArray_ArgPartitionFunc)(void *, npy_intp *, npy_intp, npy_intp, 00405 npy_intp *, npy_intp *, 00406 void *); 00407 00408 typedef int (PyArray_FillWithScalarFunc)(void *, npy_intp, void *, void *); 00409 00410 typedef int (PyArray_ScalarKindFunc)(void *); 00411 00412 typedef void (PyArray_FastClipFunc)(void *in, npy_intp n_in, void *min, 00413 void *max, void *out); 00414 typedef void (PyArray_FastPutmaskFunc)(void *in, void *mask, npy_intp n_in, 00415 void *values, npy_intp nv); 00416 typedef int (PyArray_FastTakeFunc)(void *dest, void *src, npy_intp *indarray, 00417 npy_intp nindarray, npy_intp n_outer, 00418 npy_intp m_middle, npy_intp nelem, 00419 NPY_CLIPMODE clipmode); 00420 00421 typedef struct { 00422 npy_intp *ptr; 00423 int len; 00424 } PyArray_Dims; 00425 00426 typedef struct { 00427 /* 00428 * Functions to cast to most other standard types 00429 * Can have some NULL entries. The types 00430 * DATETIME, TIMEDELTA, and HALF go into the castdict 00431 * even though they are built-in. 00432 */ 00433 PyArray_VectorUnaryFunc *cast[NPY_NTYPES_ABI_COMPATIBLE]; 00434 00435 /* The next four functions *cannot* be NULL */ 00436 00437 /* 00438 * Functions to get and set items with standard Python types 00439 * -- not array scalars 00440 */ 00441 PyArray_GetItemFunc *getitem; 00442 PyArray_SetItemFunc *setitem; 00443 00444 /* 00445 * Copy and/or swap data. Memory areas may not overlap 00446 * Use memmove first if they might 00447 */ 00448 PyArray_CopySwapNFunc *copyswapn; 00449 PyArray_CopySwapFunc *copyswap; 00450 00451 /* 00452 * Function to compare items 00453 * Can be NULL 00454 */ 00455 PyArray_CompareFunc *compare; 00456 00457 /* 00458 * Function to select largest 00459 * Can be NULL 00460 */ 00461 PyArray_ArgFunc *argmax; 00462 00463 /* 00464 * Function to compute dot product 00465 * Can be NULL 00466 */ 00467 PyArray_DotFunc *dotfunc; 00468 00469 /* 00470 * Function to scan an ASCII file and 00471 * place a single value plus possible separator 00472 * Can be NULL 00473 */ 00474 PyArray_ScanFunc *scanfunc; 00475 00476 /* 00477 * Function to read a single value from a string 00478 * and adjust the pointer; Can be NULL 00479 */ 00480 PyArray_FromStrFunc *fromstr; 00481 00482 /* 00483 * Function to determine if data is zero or not 00484 * If NULL a default version is 00485 * used at Registration time. 00486 */ 00487 PyArray_NonzeroFunc *nonzero; 00488 00489 /* 00490 * Used for arange. 00491 * Can be NULL. 00492 */ 00493 PyArray_FillFunc *fill; 00494 00495 /* 00496 * Function to fill arrays with scalar values 00497 * Can be NULL 00498 */ 00499 PyArray_FillWithScalarFunc *fillwithscalar; 00500 00501 /* 00502 * Sorting functions 00503 * Can be NULL 00504 */ 00505 PyArray_SortFunc *sort[NPY_NSORTS]; 00506 PyArray_ArgSortFunc *argsort[NPY_NSORTS]; 00507 00508 /* 00509 * Dictionary of additional casting functions 00510 * PyArray_VectorUnaryFuncs 00511 * which can be populated to support casting 00512 * to other registered types. Can be NULL 00513 */ 00514 PyObject *castdict; 00515 00516 /* 00517 * Functions useful for generalizing 00518 * the casting rules. 00519 * Can be NULL; 00520 */ 00521 PyArray_ScalarKindFunc *scalarkind; 00522 int **cancastscalarkindto; 00523 int *cancastto; 00524 00525 PyArray_FastClipFunc *fastclip; 00526 PyArray_FastPutmaskFunc *fastputmask; 00527 PyArray_FastTakeFunc *fasttake; 00528 00529 /* 00530 * Function to select smallest 00531 * Can be NULL 00532 */ 00533 PyArray_ArgFunc *argmin; 00534 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 /* A sticky flag specifically for structured arrays */ 00554 #define NPY_ALIGNED_STRUCT 0x80 00555 00556 /* 00557 *These are inherited for global data-type if any data-types in the 00558 * field have them 00559 */ 00560 #define NPY_FROM_FIELDS (NPY_NEEDS_INIT | NPY_LIST_PICKLE | \ 00561 NPY_ITEM_REFCOUNT | NPY_NEEDS_PYAPI) 00562 00563 #define NPY_OBJECT_DTYPE_FLAGS (NPY_LIST_PICKLE | NPY_USE_GETITEM | \ 00564 NPY_ITEM_IS_POINTER | NPY_ITEM_REFCOUNT | \ 00565 NPY_NEEDS_INIT | NPY_NEEDS_PYAPI) 00566 00567 #define PyDataType_FLAGCHK(dtype, flag) \ 00568 (((dtype)->flags & (flag)) == (flag)) 00569 00570 #define PyDataType_REFCHK(dtype) \ 00571 PyDataType_FLAGCHK(dtype, NPY_ITEM_REFCOUNT) 00572 00573 typedef struct _PyArray_Descr { 00574 PyObject_HEAD 00575 /* 00576 * the type object representing an 00577 * instance of this type -- should not 00578 * be two type_numbers with the same type 00579 * object. 00580 */ 00581 PyTypeObject *typeobj; 00582 /* kind for this type */ 00583 char kind; 00584 /* unique-character representing this type */ 00585 char type; 00586 /* 00587 * '>' (big), '<' (little), '|' 00588 * (not-applicable), or '=' (native). 00589 */ 00590 char byteorder; 00591 /* flags describing data type */ 00592 char flags; 00593 /* number representing this type */ 00594 int type_num; 00595 /* element size (itemsize) for this type */ 00596 int elsize; 00597 /* alignment needed for this type */ 00598 int alignment; 00599 /* 00600 * Non-NULL if this type is 00601 * is an array (C-contiguous) 00602 * of some other type 00603 */ 00604 struct _arr_descr *subarray; 00605 /* 00606 * The fields dictionary for this type 00607 * For statically defined descr this 00608 * is always Py_None 00609 */ 00610 PyObject *fields; 00611 /* 00612 * An ordered tuple of field names or NULL 00613 * if no fields are defined 00614 */ 00615 PyObject *names; 00616 /* 00617 * a table of functions specific for each 00618 * basic data descriptor 00619 */ 00620 PyArray_ArrFuncs *f; 00621 /* Metadata about this dtype */ 00622 PyObject *metadata; 00623 /* 00624 * Metadata specific to the C implementation 00625 * of the particular dtype. This was added 00626 * for NumPy 1.7.0. 00627 */ 00628 NpyAuxData *c_metadata; 00629 /* Cached hash value (-1 if not yet computed). 00630 * This was added for NumPy 2.0.0. 00631 */ 00632 npy_hash_t hash; 00633 } PyArray_Descr; 00634 00635 typedef struct _arr_descr { 00636 PyArray_Descr *base; 00637 PyObject *shape; /* a tuple */ 00638 } PyArray_ArrayDescr; 00639 00640 /* 00641 * The main array object structure. 00642 * 00643 * It has been recommended to use the inline functions defined below 00644 * (PyArray_DATA and friends) to access fields here for a number of 00645 * releases. Direct access to the members themselves is deprecated. 00646 * To ensure that your code does not use deprecated access, 00647 * #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 00648 * (or NPY_1_8_API_VERSION or higher as required). 00649 */ 00650 /* This struct will be moved to a private header in a future release */ 00651 typedef struct tagPyArrayObject_fields { 00652 PyObject_HEAD 00653 /* Pointer to the raw data buffer */ 00654 char *data; 00655 /* The number of dimensions, also called 'ndim' */ 00656 int nd; 00657 /* The size in each dimension, also called 'shape' */ 00658 npy_intp *dimensions; 00659 /* 00660 * Number of bytes to jump to get to the 00661 * next element in each dimension 00662 */ 00663 npy_intp *strides; 00664 /* 00665 * This object is decref'd upon 00666 * deletion of array. Except in the 00667 * case of UPDATEIFCOPY which has 00668 * special handling. 00669 * 00670 * For views it points to the original 00671 * array, collapsed so no chains of 00672 * views occur. 00673 * 00674 * For creation from buffer object it 00675 * points to an object that should be 00676 * decref'd on deletion 00677 * 00678 * For UPDATEIFCOPY flag this is an 00679 * array to-be-updated upon deletion 00680 * of this one 00681 */ 00682 PyObject *base; 00683 /* Pointer to type structure */ 00684 PyArray_Descr *descr; 00685 /* Flags describing array -- see below */ 00686 int flags; 00687 /* For weak references */ 00688 PyObject *weakreflist; 00689 } PyArrayObject_fields; 00690 00691 /* 00692 * To hide the implementation details, we only expose 00693 * the Python struct HEAD. 00694 */ 00695 #if !defined(NPY_NO_DEPRECATED_API) || \ 00696 (NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION) 00697 /* 00698 * Can't put this in npy_deprecated_api.h like the others. 00699 * PyArrayObject field access is deprecated as of NumPy 1.7. 00700 */ 00701 typedef PyArrayObject_fields PyArrayObject; 00702 #else 00703 typedef struct tagPyArrayObject { 00704 PyObject_HEAD 00705 } PyArrayObject; 00706 #endif 00707 00708 #define NPY_SIZEOF_PYARRAYOBJECT (sizeof(PyArrayObject_fields)) 00709 00710 /* Array Flags Object */ 00711 typedef struct PyArrayFlagsObject { 00712 PyObject_HEAD 00713 PyObject *arr; 00714 int flags; 00715 } PyArrayFlagsObject; 00716 00717 /* Mirrors buffer object to ptr */ 00718 00719 typedef struct { 00720 PyObject_HEAD 00721 PyObject *base; 00722 void *ptr; 00723 npy_intp len; 00724 int flags; 00725 } PyArray_Chunk; 00726 00727 typedef struct { 00728 NPY_DATETIMEUNIT base; 00729 int num; 00730 } PyArray_DatetimeMetaData; 00731 00732 typedef struct { 00733 NpyAuxData base; 00734 PyArray_DatetimeMetaData meta; 00735 } PyArray_DatetimeDTypeMetaData; 00736 00737 /* 00738 * This structure contains an exploded view of a date-time value. 00739 * NaT is represented by year == NPY_DATETIME_NAT. 00740 */ 00741 typedef struct { 00742 npy_int64 year; 00743 npy_int32 month, day, hour, min, sec, us, ps, as; 00744 } npy_datetimestruct; 00745 00746 /* This is not used internally. */ 00747 typedef struct { 00748 npy_int64 day; 00749 npy_int32 sec, us, ps, as; 00750 } npy_timedeltastruct; 00751 00752 typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *); 00753 00754 /* 00755 * Means c-style contiguous (last index varies the fastest). The data 00756 * elements right after each other. 00757 * 00758 * This flag may be requested in constructor functions. 00759 * This flag may be tested for in PyArray_FLAGS(arr). 00760 */ 00761 #define NPY_ARRAY_C_CONTIGUOUS 0x0001 00762 00763 /* 00764 * Set if array is a contiguous Fortran array: the first index varies 00765 * the fastest in memory (strides array is reverse of C-contiguous 00766 * array) 00767 * 00768 * This flag may be requested in constructor functions. 00769 * This flag may be tested for in PyArray_FLAGS(arr). 00770 */ 00771 #define NPY_ARRAY_F_CONTIGUOUS 0x0002 00772 00773 /* 00774 * Note: all 0-d arrays are C_CONTIGUOUS and F_CONTIGUOUS. If a 00775 * 1-d array is C_CONTIGUOUS it is also F_CONTIGUOUS. Arrays with 00776 * more then one dimension can be C_CONTIGUOUS and F_CONTIGUOUS 00777 * at the same time if they have either zero or one element. 00778 * If NPY_RELAXED_STRIDES_CHECKING is set, a higher dimensional 00779 * array is always C_CONTIGUOUS and F_CONTIGUOUS if it has zero elements 00780 * and the array is contiguous if ndarray.squeeze() is contiguous. 00781 * I.e. dimensions for which `ndarray.shape[dimension] == 1` are 00782 * ignored. 00783 */ 00784 00785 /* 00786 * If set, the array owns the data: it will be free'd when the array 00787 * is deleted. 00788 * 00789 * This flag may be tested for in PyArray_FLAGS(arr). 00790 */ 00791 #define NPY_ARRAY_OWNDATA 0x0004 00792 00793 /* 00794 * An array never has the next four set; they're only used as parameter 00795 * flags to the various FromAny functions 00796 * 00797 * This flag may be requested in constructor functions. 00798 */ 00799 00800 /* Cause a cast to occur regardless of whether or not it is safe. */ 00801 #define NPY_ARRAY_FORCECAST 0x0010 00802 00803 /* 00804 * Always copy the array. Returned arrays are always CONTIGUOUS, 00805 * ALIGNED, and WRITEABLE. 00806 * 00807 * This flag may be requested in constructor functions. 00808 */ 00809 #define NPY_ARRAY_ENSURECOPY 0x0020 00810 00811 /* 00812 * Make sure the returned array is a base-class ndarray 00813 * 00814 * This flag may be requested in constructor functions. 00815 */ 00816 #define NPY_ARRAY_ENSUREARRAY 0x0040 00817 00818 /* 00819 * Make sure that the strides are in units of the element size Needed 00820 * for some operations with record-arrays. 00821 * 00822 * This flag may be requested in constructor functions. 00823 */ 00824 #define NPY_ARRAY_ELEMENTSTRIDES 0x0080 00825 00826 /* 00827 * Array data is aligned on the appropriate memory address for the type 00828 * stored according to how the compiler would align things (e.g., an 00829 * array of integers (4 bytes each) starts on a memory address that's 00830 * a multiple of 4) 00831 * 00832 * This flag may be requested in constructor functions. 00833 * This flag may be tested for in PyArray_FLAGS(arr). 00834 */ 00835 #define NPY_ARRAY_ALIGNED 0x0100 00836 00837 /* 00838 * Array data has the native endianness 00839 * 00840 * This flag may be requested in constructor functions. 00841 */ 00842 #define NPY_ARRAY_NOTSWAPPED 0x0200 00843 00844 /* 00845 * Array data is writeable 00846 * 00847 * This flag may be requested in constructor functions. 00848 * This flag may be tested for in PyArray_FLAGS(arr). 00849 */ 00850 #define NPY_ARRAY_WRITEABLE 0x0400 00851 00852 /* 00853 * If this flag is set, then base contains a pointer to an array of 00854 * the same size that should be updated with the current contents of 00855 * this array when this array is deallocated 00856 * 00857 * This flag may be requested in constructor functions. 00858 * This flag may be tested for in PyArray_FLAGS(arr). 00859 */ 00860 #define NPY_ARRAY_UPDATEIFCOPY 0x1000 00861 00862 /* 00863 * NOTE: there are also internal flags defined in multiarray/arrayobject.h, 00864 * which start at bit 31 and work down. 00865 */ 00866 00867 #define NPY_ARRAY_BEHAVED (NPY_ARRAY_ALIGNED | \ 00868 NPY_ARRAY_WRITEABLE) 00869 #define NPY_ARRAY_BEHAVED_NS (NPY_ARRAY_ALIGNED | \ 00870 NPY_ARRAY_WRITEABLE | \ 00871 NPY_ARRAY_NOTSWAPPED) 00872 #define NPY_ARRAY_CARRAY (NPY_ARRAY_C_CONTIGUOUS | \ 00873 NPY_ARRAY_BEHAVED) 00874 #define NPY_ARRAY_CARRAY_RO (NPY_ARRAY_C_CONTIGUOUS | \ 00875 NPY_ARRAY_ALIGNED) 00876 #define NPY_ARRAY_FARRAY (NPY_ARRAY_F_CONTIGUOUS | \ 00877 NPY_ARRAY_BEHAVED) 00878 #define NPY_ARRAY_FARRAY_RO (NPY_ARRAY_F_CONTIGUOUS | \ 00879 NPY_ARRAY_ALIGNED) 00880 #define NPY_ARRAY_DEFAULT (NPY_ARRAY_CARRAY) 00881 #define NPY_ARRAY_IN_ARRAY (NPY_ARRAY_CARRAY_RO) 00882 #define NPY_ARRAY_OUT_ARRAY (NPY_ARRAY_CARRAY) 00883 #define NPY_ARRAY_INOUT_ARRAY (NPY_ARRAY_CARRAY | \ 00884 NPY_ARRAY_UPDATEIFCOPY) 00885 #define NPY_ARRAY_IN_FARRAY (NPY_ARRAY_FARRAY_RO) 00886 #define NPY_ARRAY_OUT_FARRAY (NPY_ARRAY_FARRAY) 00887 #define NPY_ARRAY_INOUT_FARRAY (NPY_ARRAY_FARRAY | \ 00888 NPY_ARRAY_UPDATEIFCOPY) 00889 00890 #define NPY_ARRAY_UPDATE_ALL (NPY_ARRAY_C_CONTIGUOUS | \ 00891 NPY_ARRAY_F_CONTIGUOUS | \ 00892 NPY_ARRAY_ALIGNED) 00893 00894 /* This flag is for the array interface, not PyArrayObject */ 00895 #define NPY_ARR_HAS_DESCR 0x0800 00896 00897 00898 00899 00900 /* 00901 * Size of internal buffers used for alignment Make BUFSIZE a multiple 00902 * of sizeof(npy_cdouble) -- usually 16 so that ufunc buffers are aligned 00903 */ 00904 #define NPY_MIN_BUFSIZE ((int)sizeof(npy_cdouble)) 00905 #define NPY_MAX_BUFSIZE (((int)sizeof(npy_cdouble))*1000000) 00906 #define NPY_BUFSIZE 8192 00907 /* buffer stress test size: */ 00908 /*#define NPY_BUFSIZE 17*/ 00909 00910 #define PyArray_MAX(a,b) (((a)>(b))?(a):(b)) 00911 #define PyArray_MIN(a,b) (((a)<(b))?(a):(b)) 00912 #define PyArray_CLT(p,q) ((((p).real==(q).real) ? ((p).imag < (q).imag) : \ 00913 ((p).real < (q).real))) 00914 #define PyArray_CGT(p,q) ((((p).real==(q).real) ? ((p).imag > (q).imag) : \ 00915 ((p).real > (q).real))) 00916 #define PyArray_CLE(p,q) ((((p).real==(q).real) ? ((p).imag <= (q).imag) : \ 00917 ((p).real <= (q).real))) 00918 #define PyArray_CGE(p,q) ((((p).real==(q).real) ? ((p).imag >= (q).imag) : \ 00919 ((p).real >= (q).real))) 00920 #define PyArray_CEQ(p,q) (((p).real==(q).real) && ((p).imag == (q).imag)) 00921 #define PyArray_CNE(p,q) (((p).real!=(q).real) || ((p).imag != (q).imag)) 00922 00923 /* 00924 * C API: consists of Macros and functions. The MACROS are defined 00925 * here. 00926 */ 00927 00928 00929 #define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS) 00930 #define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, NPY_ARRAY_WRITEABLE) 00931 #define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, NPY_ARRAY_ALIGNED) 00932 00933 #define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS) 00934 #define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) 00935 00936 /* the variable is used in some places, so always define it */ 00937 #define NPY_BEGIN_THREADS_DEF PyThreadState *_save=NULL; 00938 #if NPY_ALLOW_THREADS 00939 #define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS 00940 #define NPY_END_ALLOW_THREADS Py_END_ALLOW_THREADS 00941 #define NPY_BEGIN_THREADS do {_save = PyEval_SaveThread();} while (0); 00942 #define NPY_END_THREADS do { if (_save) \ 00943 { PyEval_RestoreThread(_save); _save = NULL;} } while (0); 00944 #define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) do { if (loop_size > 500) \ 00945 { _save = PyEval_SaveThread();} } while (0); 00946 00947 #define NPY_BEGIN_THREADS_DESCR(dtype) \ 00948 do {if (!(PyDataType_FLAGCHK(dtype, NPY_NEEDS_PYAPI))) \ 00949 NPY_BEGIN_THREADS;} while (0); 00950 00951 #define NPY_END_THREADS_DESCR(dtype) \ 00952 do {if (!(PyDataType_FLAGCHK(dtype, NPY_NEEDS_PYAPI))) \ 00953 NPY_END_THREADS; } while (0); 00954 00955 #define NPY_ALLOW_C_API_DEF PyGILState_STATE __save__; 00956 #define NPY_ALLOW_C_API do {__save__ = PyGILState_Ensure();} while (0); 00957 #define NPY_DISABLE_C_API do {PyGILState_Release(__save__);} while (0); 00958 #else 00959 #define NPY_BEGIN_ALLOW_THREADS 00960 #define NPY_END_ALLOW_THREADS 00961 #define NPY_BEGIN_THREADS 00962 #define NPY_END_THREADS 00963 #define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) 00964 #define NPY_BEGIN_THREADS_DESCR(dtype) 00965 #define NPY_END_THREADS_DESCR(dtype) 00966 #define NPY_ALLOW_C_API_DEF 00967 #define NPY_ALLOW_C_API 00968 #define NPY_DISABLE_C_API 00969 #endif 00970 00971 /********************************** 00972 * The nditer object, added in 1.6 00973 **********************************/ 00974 00975 /* The actual structure of the iterator is an internal detail */ 00976 typedef struct NpyIter_InternalOnly NpyIter; 00977 00978 /* Iterator function pointers that may be specialized */ 00979 typedef int (NpyIter_IterNextFunc)(NpyIter *iter); 00980 typedef void (NpyIter_GetMultiIndexFunc)(NpyIter *iter, 00981 npy_intp *outcoords); 00982 00983 /*** Global flags that may be passed to the iterator constructors ***/ 00984 00985 /* Track an index representing C order */ 00986 #define NPY_ITER_C_INDEX 0x00000001 00987 /* Track an index representing Fortran order */ 00988 #define NPY_ITER_F_INDEX 0x00000002 00989 /* Track a multi-index */ 00990 #define NPY_ITER_MULTI_INDEX 0x00000004 00991 /* User code external to the iterator does the 1-dimensional innermost loop */ 00992 #define NPY_ITER_EXTERNAL_LOOP 0x00000008 00993 /* Convert all the operands to a common data type */ 00994 #define NPY_ITER_COMMON_DTYPE 0x00000010 00995 /* Operands may hold references, requiring API access during iteration */ 00996 #define NPY_ITER_REFS_OK 0x00000020 00997 /* Zero-sized operands should be permitted, iteration checks IterSize for 0 */ 00998 #define NPY_ITER_ZEROSIZE_OK 0x00000040 00999 /* Permits reductions (size-0 stride with dimension size > 1) */ 01000 #define NPY_ITER_REDUCE_OK 0x00000080 01001 /* Enables sub-range iteration */ 01002 #define NPY_ITER_RANGED 0x00000100 01003 /* Enables buffering */ 01004 #define NPY_ITER_BUFFERED 0x00000200 01005 /* When buffering is enabled, grows the inner loop if possible */ 01006 #define NPY_ITER_GROWINNER 0x00000400 01007 /* Delay allocation of buffers until first Reset* call */ 01008 #define NPY_ITER_DELAY_BUFALLOC 0x00000800 01009 /* When NPY_KEEPORDER is specified, disable reversing negative-stride axes */ 01010 #define NPY_ITER_DONT_NEGATE_STRIDES 0x00001000 01011 01012 /*** Per-operand flags that may be passed to the iterator constructors ***/ 01013 01014 /* The operand will be read from and written to */ 01015 #define NPY_ITER_READWRITE 0x00010000 01016 /* The operand will only be read from */ 01017 #define NPY_ITER_READONLY 0x00020000 01018 /* The operand will only be written to */ 01019 #define NPY_ITER_WRITEONLY 0x00040000 01020 /* The operand's data must be in native byte order */ 01021 #define NPY_ITER_NBO 0x00080000 01022 /* The operand's data must be aligned */ 01023 #define NPY_ITER_ALIGNED 0x00100000 01024 /* The operand's data must be contiguous (within the inner loop) */ 01025 #define NPY_ITER_CONTIG 0x00200000 01026 /* The operand may be copied to satisfy requirements */ 01027 #define NPY_ITER_COPY 0x00400000 01028 /* The operand may be copied with UPDATEIFCOPY to satisfy requirements */ 01029 #define NPY_ITER_UPDATEIFCOPY 0x00800000 01030 /* Allocate the operand if it is NULL */ 01031 #define NPY_ITER_ALLOCATE 0x01000000 01032 /* If an operand is allocated, don't use any subtype */ 01033 #define NPY_ITER_NO_SUBTYPE 0x02000000 01034 /* This is a virtual array slot, operand is NULL but temporary data is there */ 01035 #define NPY_ITER_VIRTUAL 0x04000000 01036 /* Require that the dimension match the iterator dimensions exactly */ 01037 #define NPY_ITER_NO_BROADCAST 0x08000000 01038 /* A mask is being used on this array, affects buffer -> array copy */ 01039 #define NPY_ITER_WRITEMASKED 0x10000000 01040 /* This array is the mask for all WRITEMASKED operands */ 01041 #define NPY_ITER_ARRAYMASK 0x20000000 01042 01043 #define NPY_ITER_GLOBAL_FLAGS 0x0000ffff 01044 #define NPY_ITER_PER_OP_FLAGS 0xffff0000 01045 01046 01047 /***************************** 01048 * Basic iterator object 01049 *****************************/ 01050 01051 /* FWD declaration */ 01052 typedef struct PyArrayIterObject_tag PyArrayIterObject; 01053 01054 /* 01055 * type of the function which translates a set of coordinates to a 01056 * pointer to the data 01057 */ 01058 typedef char* (*npy_iter_get_dataptr_t)(PyArrayIterObject* iter, npy_intp*); 01059 01060 struct PyArrayIterObject_tag { 01061 PyObject_HEAD 01062 int nd_m1; /* number of dimensions - 1 */ 01063 npy_intp index, size; 01064 npy_intp coordinates[NPY_MAXDIMS];/* N-dimensional loop */ 01065 npy_intp dims_m1[NPY_MAXDIMS]; /* ao->dimensions - 1 */ 01066 npy_intp strides[NPY_MAXDIMS]; /* ao->strides or fake */ 01067 npy_intp backstrides[NPY_MAXDIMS];/* how far to jump back */ 01068 npy_intp factors[NPY_MAXDIMS]; /* shape factors */ 01069 PyArrayObject *ao; 01070 char *dataptr; /* pointer to current item*/ 01071 npy_bool contiguous; 01072 01073 npy_intp bounds[NPY_MAXDIMS][2]; 01074 npy_intp limits[NPY_MAXDIMS][2]; 01075 npy_intp limits_sizes[NPY_MAXDIMS]; 01076 npy_iter_get_dataptr_t translate; 01077 } ; 01078 01079 01080 /* Iterator API */ 01081 #define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type) 01082 01083 #define _PyAIT(it) ((PyArrayIterObject *)(it)) 01084 #define PyArray_ITER_RESET(it) do { \ 01085 _PyAIT(it)->index = 0; \ 01086 _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \ 01087 memset(_PyAIT(it)->coordinates, 0, \ 01088 (_PyAIT(it)->nd_m1+1)*sizeof(npy_intp)); \ 01089 } while (0) 01090 01091 #define _PyArray_ITER_NEXT1(it) do { \ 01092 (it)->dataptr += _PyAIT(it)->strides[0]; \ 01093 (it)->coordinates[0]++; \ 01094 } while (0) 01095 01096 #define _PyArray_ITER_NEXT2(it) do { \ 01097 if ((it)->coordinates[1] < (it)->dims_m1[1]) { \ 01098 (it)->coordinates[1]++; \ 01099 (it)->dataptr += (it)->strides[1]; \ 01100 } \ 01101 else { \ 01102 (it)->coordinates[1] = 0; \ 01103 (it)->coordinates[0]++; \ 01104 (it)->dataptr += (it)->strides[0] - \ 01105 (it)->backstrides[1]; \ 01106 } \ 01107 } while (0) 01108 01109 #define PyArray_ITER_NEXT(it) do { \ 01110 _PyAIT(it)->index++; \ 01111 if (_PyAIT(it)->nd_m1 == 0) { \ 01112 _PyArray_ITER_NEXT1(_PyAIT(it)); \ 01113 } \ 01114 else if (_PyAIT(it)->contiguous) \ 01115 _PyAIT(it)->dataptr += PyArray_DESCR(_PyAIT(it)->ao)->elsize; \ 01116 else if (_PyAIT(it)->nd_m1 == 1) { \ 01117 _PyArray_ITER_NEXT2(_PyAIT(it)); \ 01118 } \ 01119 else { \ 01120 int __npy_i; \ 01121 for (__npy_i=_PyAIT(it)->nd_m1; __npy_i >= 0; __npy_i--) { \ 01122 if (_PyAIT(it)->coordinates[__npy_i] < \ 01123 _PyAIT(it)->dims_m1[__npy_i]) { \ 01124 _PyAIT(it)->coordinates[__npy_i]++; \ 01125 _PyAIT(it)->dataptr += \ 01126 _PyAIT(it)->strides[__npy_i]; \ 01127 break; \ 01128 } \ 01129 else { \ 01130 _PyAIT(it)->coordinates[__npy_i] = 0; \ 01131 _PyAIT(it)->dataptr -= \ 01132 _PyAIT(it)->backstrides[__npy_i]; \ 01133 } \ 01134 } \ 01135 } \ 01136 } while (0) 01137 01138 #define PyArray_ITER_GOTO(it, destination) do { \ 01139 int __npy_i; \ 01140 _PyAIT(it)->index = 0; \ 01141 _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \ 01142 for (__npy_i = _PyAIT(it)->nd_m1; __npy_i>=0; __npy_i--) { \ 01143 if (destination[__npy_i] < 0) { \ 01144 destination[__npy_i] += \ 01145 _PyAIT(it)->dims_m1[__npy_i]+1; \ 01146 } \ 01147 _PyAIT(it)->dataptr += destination[__npy_i] * \ 01148 _PyAIT(it)->strides[__npy_i]; \ 01149 _PyAIT(it)->coordinates[__npy_i] = \ 01150 destination[__npy_i]; \ 01151 _PyAIT(it)->index += destination[__npy_i] * \ 01152 ( __npy_i==_PyAIT(it)->nd_m1 ? 1 : \ 01153 _PyAIT(it)->dims_m1[__npy_i+1]+1) ; \ 01154 } \ 01155 } while (0) 01156 01157 #define PyArray_ITER_GOTO1D(it, ind) do { \ 01158 int __npy_i; \ 01159 npy_intp __npy_ind = (npy_intp) (ind); \ 01160 if (__npy_ind < 0) __npy_ind += _PyAIT(it)->size; \ 01161 _PyAIT(it)->index = __npy_ind; \ 01162 if (_PyAIT(it)->nd_m1 == 0) { \ 01163 _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \ 01164 __npy_ind * _PyAIT(it)->strides[0]; \ 01165 } \ 01166 else if (_PyAIT(it)->contiguous) \ 01167 _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \ 01168 __npy_ind * PyArray_DESCR(_PyAIT(it)->ao)->elsize; \ 01169 else { \ 01170 _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \ 01171 for (__npy_i = 0; __npy_i<=_PyAIT(it)->nd_m1; \ 01172 __npy_i++) { \ 01173 _PyAIT(it)->dataptr += \ 01174 (__npy_ind / _PyAIT(it)->factors[__npy_i]) \ 01175 * _PyAIT(it)->strides[__npy_i]; \ 01176 __npy_ind %= _PyAIT(it)->factors[__npy_i]; \ 01177 } \ 01178 } \ 01179 } while (0) 01180 01181 #define PyArray_ITER_DATA(it) ((void *)(_PyAIT(it)->dataptr)) 01182 01183 #define PyArray_ITER_NOTDONE(it) (_PyAIT(it)->index < _PyAIT(it)->size) 01184 01185 01186 /* 01187 * Any object passed to PyArray_Broadcast must be binary compatible 01188 * with this structure. 01189 */ 01190 01191 typedef struct { 01192 PyObject_HEAD 01193 int numiter; /* number of iters */ 01194 npy_intp size; /* broadcasted size */ 01195 npy_intp index; /* current index */ 01196 int nd; /* number of dims */ 01197 npy_intp dimensions[NPY_MAXDIMS]; /* dimensions */ 01198 PyArrayIterObject *iters[NPY_MAXARGS]; /* iterators */ 01199 } PyArrayMultiIterObject; 01200 01201 #define _PyMIT(m) ((PyArrayMultiIterObject *)(m)) 01202 #define PyArray_MultiIter_RESET(multi) do { \ 01203 int __npy_mi; \ 01204 _PyMIT(multi)->index = 0; \ 01205 for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \ 01206 PyArray_ITER_RESET(_PyMIT(multi)->iters[__npy_mi]); \ 01207 } \ 01208 } while (0) 01209 01210 #define PyArray_MultiIter_NEXT(multi) do { \ 01211 int __npy_mi; \ 01212 _PyMIT(multi)->index++; \ 01213 for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \ 01214 PyArray_ITER_NEXT(_PyMIT(multi)->iters[__npy_mi]); \ 01215 } \ 01216 } while (0) 01217 01218 #define PyArray_MultiIter_GOTO(multi, dest) do { \ 01219 int __npy_mi; \ 01220 for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \ 01221 PyArray_ITER_GOTO(_PyMIT(multi)->iters[__npy_mi], dest); \ 01222 } \ 01223 _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \ 01224 } while (0) 01225 01226 #define PyArray_MultiIter_GOTO1D(multi, ind) do { \ 01227 int __npy_mi; \ 01228 for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \ 01229 PyArray_ITER_GOTO1D(_PyMIT(multi)->iters[__npy_mi], ind); \ 01230 } \ 01231 _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \ 01232 } while (0) 01233 01234 #define PyArray_MultiIter_DATA(multi, i) \ 01235 ((void *)(_PyMIT(multi)->iters[i]->dataptr)) 01236 01237 #define PyArray_MultiIter_NEXTi(multi, i) \ 01238 PyArray_ITER_NEXT(_PyMIT(multi)->iters[i]) 01239 01240 #define PyArray_MultiIter_NOTDONE(multi) \ 01241 (_PyMIT(multi)->index < _PyMIT(multi)->size) 01242 01243 01244 /* 01245 * Store the information needed for fancy-indexing over an array. The 01246 * fields are slightly unordered to keep consec, dataptr and subspace 01247 * where they were originally. 01248 */ 01249 typedef struct { 01250 PyObject_HEAD 01251 /* 01252 * Multi-iterator portion --- needs to be present in this 01253 * order to work with PyArray_Broadcast 01254 */ 01255 01256 int numiter; /* number of index-array 01257 iterators */ 01258 npy_intp size; /* size of broadcasted 01259 result */ 01260 npy_intp index; /* current index */ 01261 int nd; /* number of dims */ 01262 npy_intp dimensions[NPY_MAXDIMS]; /* dimensions */ 01263 NpyIter *outer; /* index objects 01264 iterator */ 01265 void *unused[NPY_MAXDIMS - 2]; 01266 PyArrayObject *array; 01267 /* Flat iterator for the indexed array. For compatibility solely. */ 01268 PyArrayIterObject *ait; 01269 01270 /* 01271 * Subspace array. For binary compatibility (was an iterator, 01272 * but only the check for NULL should be used). 01273 */ 01274 PyArrayObject *subspace; 01275 01276 /* 01277 * if subspace iteration, then this is the array of axes in 01278 * the underlying array represented by the index objects 01279 */ 01280 int iteraxes[NPY_MAXDIMS]; 01281 npy_intp fancy_strides[NPY_MAXDIMS]; 01282 01283 /* pointer when all fancy indices are 0 */ 01284 char *baseoffset; 01285 01286 /* 01287 * after binding consec denotes at which axis the fancy axes 01288 * are inserted. 01289 */ 01290 int consec; 01291 char *dataptr; 01292 01293 int nd_fancy; 01294 npy_intp fancy_dims[NPY_MAXDIMS]; 01295 01296 /* Whether the iterator (any of the iterators) requires API */ 01297 int needs_api; 01298 01299 /* 01300 * Extra op information. 01301 */ 01302 PyArrayObject *extra_op; 01303 PyArray_Descr *extra_op_dtype; /* desired dtype */ 01304 npy_uint32 *extra_op_flags; /* Iterator flags */ 01305 01306 NpyIter *extra_op_iter; 01307 NpyIter_IterNextFunc *extra_op_next; 01308 char **extra_op_ptrs; 01309 01310 /* 01311 * Information about the iteration state. 01312 */ 01313 NpyIter_IterNextFunc *outer_next; 01314 char **outer_ptrs; 01315 npy_intp *outer_strides; 01316 01317 /* 01318 * Information about the subspace iterator. 01319 */ 01320 NpyIter *subspace_iter; 01321 NpyIter_IterNextFunc *subspace_next; 01322 char **subspace_ptrs; 01323 npy_intp *subspace_strides; 01324 01325 /* Count for the external loop (which ever it is) for API iteration */ 01326 npy_intp iter_count; 01327 01328 } PyArrayMapIterObject; 01329 01330 enum { 01331 NPY_NEIGHBORHOOD_ITER_ZERO_PADDING, 01332 NPY_NEIGHBORHOOD_ITER_ONE_PADDING, 01333 NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING, 01334 NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING, 01335 NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING 01336 }; 01337 01338 typedef struct { 01339 PyObject_HEAD 01340 01341 /* 01342 * PyArrayIterObject part: keep this in this exact order 01343 */ 01344 int nd_m1; /* number of dimensions - 1 */ 01345 npy_intp index, size; 01346 npy_intp coordinates[NPY_MAXDIMS];/* N-dimensional loop */ 01347 npy_intp dims_m1[NPY_MAXDIMS]; /* ao->dimensions - 1 */ 01348 npy_intp strides[NPY_MAXDIMS]; /* ao->strides or fake */ 01349 npy_intp backstrides[NPY_MAXDIMS];/* how far to jump back */ 01350 npy_intp factors[NPY_MAXDIMS]; /* shape factors */ 01351 PyArrayObject *ao; 01352 char *dataptr; /* pointer to current item*/ 01353 npy_bool contiguous; 01354 01355 npy_intp bounds[NPY_MAXDIMS][2]; 01356 npy_intp limits[NPY_MAXDIMS][2]; 01357 npy_intp limits_sizes[NPY_MAXDIMS]; 01358 npy_iter_get_dataptr_t translate; 01359 01360 /* 01361 * New members 01362 */ 01363 npy_intp nd; 01364 01365 /* Dimensions is the dimension of the array */ 01366 npy_intp dimensions[NPY_MAXDIMS]; 01367 01368 /* 01369 * Neighborhood points coordinates are computed relatively to the 01370 * point pointed by _internal_iter 01371 */ 01372 PyArrayIterObject* _internal_iter; 01373 /* 01374 * To keep a reference to the representation of the constant value 01375 * for constant padding 01376 */ 01377 char* constant; 01378 01379 int mode; 01380 } PyArrayNeighborhoodIterObject; 01381 01382 /* 01383 * Neighborhood iterator API 01384 */ 01385 01386 /* General: those work for any mode */ 01387 static NPY_INLINE int 01388 PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter); 01389 static NPY_INLINE int 01390 PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter); 01391 #if 0 01392 static NPY_INLINE int 01393 PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter); 01394 #endif 01395 01396 /* 01397 * Include inline implementations - functions defined there are not 01398 * considered public API 01399 */ 01400 #define _NPY_INCLUDE_NEIGHBORHOOD_IMP 01401 #include "_neighborhood_iterator_imp.h" 01402 #undef _NPY_INCLUDE_NEIGHBORHOOD_IMP 01403 01404 /* The default array type */ 01405 #define NPY_DEFAULT_TYPE NPY_DOUBLE 01406 01407 /* 01408 * All sorts of useful ways to look into a PyArrayObject. It is recommended 01409 * to use PyArrayObject * objects instead of always casting from PyObject *, 01410 * for improved type checking. 01411 * 01412 * In many cases here the macro versions of the accessors are deprecated, 01413 * but can't be immediately changed to inline functions because the 01414 * preexisting macros accept PyObject * and do automatic casts. Inline 01415 * functions accepting PyArrayObject * provides for some compile-time 01416 * checking of correctness when working with these objects in C. 01417 */ 01418 01419 #define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || \ 01420 PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS) || \ 01421 PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS)) 01422 01423 #define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) && \ 01424 (!PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS))) 01425 01426 #define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) ? \ 01427 NPY_ARRAY_F_CONTIGUOUS : 0)) 01428 01429 #if (defined(NPY_NO_DEPRECATED_API) && (NPY_1_7_API_VERSION <= NPY_NO_DEPRECATED_API)) 01430 /* 01431 * Changing access macros into functions, to allow for future hiding 01432 * of the internal memory layout. This later hiding will allow the 2.x series 01433 * to change the internal representation of arrays without affecting 01434 * ABI compatibility. 01435 */ 01436 01437 static NPY_INLINE int 01438 PyArray_NDIM(const PyArrayObject *arr) 01439 { 01440 return ((PyArrayObject_fields *)arr)->nd; 01441 } 01442 01443 static NPY_INLINE void * 01444 PyArray_DATA(PyArrayObject *arr) 01445 { 01446 return ((PyArrayObject_fields *)arr)->data; 01447 } 01448 01449 static NPY_INLINE char * 01450 PyArray_BYTES(PyArrayObject *arr) 01451 { 01452 return ((PyArrayObject_fields *)arr)->data; 01453 } 01454 01455 static NPY_INLINE npy_intp * 01456 PyArray_DIMS(PyArrayObject *arr) 01457 { 01458 return ((PyArrayObject_fields *)arr)->dimensions; 01459 } 01460 01461 static NPY_INLINE npy_intp * 01462 PyArray_STRIDES(PyArrayObject *arr) 01463 { 01464 return ((PyArrayObject_fields *)arr)->strides; 01465 } 01466 01467 static NPY_INLINE npy_intp 01468 PyArray_DIM(const PyArrayObject *arr, int idim) 01469 { 01470 return ((PyArrayObject_fields *)arr)->dimensions[idim]; 01471 } 01472 01473 static NPY_INLINE npy_intp 01474 PyArray_STRIDE(const PyArrayObject *arr, int istride) 01475 { 01476 return ((PyArrayObject_fields *)arr)->strides[istride]; 01477 } 01478 01479 static NPY_INLINE NPY_RETURNS_BORROWED_REF PyObject * 01480 PyArray_BASE(PyArrayObject *arr) 01481 { 01482 return ((PyArrayObject_fields *)arr)->base; 01483 } 01484 01485 static NPY_INLINE NPY_RETURNS_BORROWED_REF PyArray_Descr * 01486 PyArray_DESCR(PyArrayObject *arr) 01487 { 01488 return ((PyArrayObject_fields *)arr)->descr; 01489 } 01490 01491 static NPY_INLINE int 01492 PyArray_FLAGS(const PyArrayObject *arr) 01493 { 01494 return ((PyArrayObject_fields *)arr)->flags; 01495 } 01496 01497 static NPY_INLINE npy_intp 01498 PyArray_ITEMSIZE(const PyArrayObject *arr) 01499 { 01500 return ((PyArrayObject_fields *)arr)->descr->elsize; 01501 } 01502 01503 static NPY_INLINE int 01504 PyArray_TYPE(const PyArrayObject *arr) 01505 { 01506 return ((PyArrayObject_fields *)arr)->descr->type_num; 01507 } 01508 01509 static NPY_INLINE int 01510 PyArray_CHKFLAGS(const PyArrayObject *arr, int flags) 01511 { 01512 return (PyArray_FLAGS(arr) & flags) == flags; 01513 } 01514 01515 static NPY_INLINE PyObject * 01516 PyArray_GETITEM(const PyArrayObject *arr, const char *itemptr) 01517 { 01518 return ((PyArrayObject_fields *)arr)->descr->f->getitem( 01519 (void *)itemptr, (PyArrayObject *)arr); 01520 } 01521 01522 static NPY_INLINE int 01523 PyArray_SETITEM(PyArrayObject *arr, char *itemptr, PyObject *v) 01524 { 01525 return ((PyArrayObject_fields *)arr)->descr->f->setitem( 01526 v, itemptr, arr); 01527 } 01528 01529 #else 01530 01531 /* These macros are deprecated as of NumPy 1.7. */ 01532 #define PyArray_NDIM(obj) (((PyArrayObject_fields *)(obj))->nd) 01533 #define PyArray_BYTES(obj) (((PyArrayObject_fields *)(obj))->data) 01534 #define PyArray_DATA(obj) ((void *)((PyArrayObject_fields *)(obj))->data) 01535 #define PyArray_DIMS(obj) (((PyArrayObject_fields *)(obj))->dimensions) 01536 #define PyArray_STRIDES(obj) (((PyArrayObject_fields *)(obj))->strides) 01537 #define PyArray_DIM(obj,n) (PyArray_DIMS(obj)[n]) 01538 #define PyArray_STRIDE(obj,n) (PyArray_STRIDES(obj)[n]) 01539 #define PyArray_BASE(obj) (((PyArrayObject_fields *)(obj))->base) 01540 #define PyArray_DESCR(obj) (((PyArrayObject_fields *)(obj))->descr) 01541 #define PyArray_FLAGS(obj) (((PyArrayObject_fields *)(obj))->flags) 01542 #define PyArray_CHKFLAGS(m, FLAGS) \ 01543 ((((PyArrayObject_fields *)(m))->flags & (FLAGS)) == (FLAGS)) 01544 #define PyArray_ITEMSIZE(obj) \ 01545 (((PyArrayObject_fields *)(obj))->descr->elsize) 01546 #define PyArray_TYPE(obj) \ 01547 (((PyArrayObject_fields *)(obj))->descr->type_num) 01548 #define PyArray_GETITEM(obj,itemptr) \ 01549 PyArray_DESCR(obj)->f->getitem((char *)(itemptr), \ 01550 (PyArrayObject *)(obj)) 01551 01552 #define PyArray_SETITEM(obj,itemptr,v) \ 01553 PyArray_DESCR(obj)->f->setitem((PyObject *)(v), \ 01554 (char *)(itemptr), \ 01555 (PyArrayObject *)(obj)) 01556 #endif 01557 01558 static NPY_INLINE PyArray_Descr * 01559 PyArray_DTYPE(PyArrayObject *arr) 01560 { 01561 return ((PyArrayObject_fields *)arr)->descr; 01562 } 01563 01564 static NPY_INLINE npy_intp * 01565 PyArray_SHAPE(PyArrayObject *arr) 01566 { 01567 return ((PyArrayObject_fields *)arr)->dimensions; 01568 } 01569 01570 /* 01571 * Enables the specified array flags. Does no checking, 01572 * assumes you know what you're doing. 01573 */ 01574 static NPY_INLINE void 01575 PyArray_ENABLEFLAGS(PyArrayObject *arr, int flags) 01576 { 01577 ((PyArrayObject_fields *)arr)->flags |= flags; 01578 } 01579 01580 /* 01581 * Clears the specified array flags. Does no checking, 01582 * assumes you know what you're doing. 01583 */ 01584 static NPY_INLINE void 01585 PyArray_CLEARFLAGS(PyArrayObject *arr, int flags) 01586 { 01587 ((PyArrayObject_fields *)arr)->flags &= ~flags; 01588 } 01589 01590 #define PyTypeNum_ISBOOL(type) ((type) == NPY_BOOL) 01591 01592 #define PyTypeNum_ISUNSIGNED(type) (((type) == NPY_UBYTE) || \ 01593 ((type) == NPY_USHORT) || \ 01594 ((type) == NPY_UINT) || \ 01595 ((type) == NPY_ULONG) || \ 01596 ((type) == NPY_ULONGLONG)) 01597 01598 #define PyTypeNum_ISSIGNED(type) (((type) == NPY_BYTE) || \ 01599 ((type) == NPY_SHORT) || \ 01600 ((type) == NPY_INT) || \ 01601 ((type) == NPY_LONG) || \ 01602 ((type) == NPY_LONGLONG)) 01603 01604 #define PyTypeNum_ISINTEGER(type) (((type) >= NPY_BYTE) && \ 01605 ((type) <= NPY_ULONGLONG)) 01606 01607 #define PyTypeNum_ISFLOAT(type) ((((type) >= NPY_FLOAT) && \ 01608 ((type) <= NPY_LONGDOUBLE)) || \ 01609 ((type) == NPY_HALF)) 01610 01611 #define PyTypeNum_ISNUMBER(type) (((type) <= NPY_CLONGDOUBLE) || \ 01612 ((type) == NPY_HALF)) 01613 01614 #define PyTypeNum_ISSTRING(type) (((type) == NPY_STRING) || \ 01615 ((type) == NPY_UNICODE)) 01616 01617 #define PyTypeNum_ISCOMPLEX(type) (((type) >= NPY_CFLOAT) && \ 01618 ((type) <= NPY_CLONGDOUBLE)) 01619 01620 #define PyTypeNum_ISPYTHON(type) (((type) == NPY_LONG) || \ 01621 ((type) == NPY_DOUBLE) || \ 01622 ((type) == NPY_CDOUBLE) || \ 01623 ((type) == NPY_BOOL) || \ 01624 ((type) == NPY_OBJECT )) 01625 01626 #define PyTypeNum_ISFLEXIBLE(type) (((type) >=NPY_STRING) && \ 01627 ((type) <=NPY_VOID)) 01628 01629 #define PyTypeNum_ISDATETIME(type) (((type) >=NPY_DATETIME) && \ 01630 ((type) <=NPY_TIMEDELTA)) 01631 01632 #define PyTypeNum_ISUSERDEF(type) (((type) >= NPY_USERDEF) && \ 01633 ((type) < NPY_USERDEF+ \ 01634 NPY_NUMUSERTYPES)) 01635 01636 #define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \ 01637 PyTypeNum_ISUSERDEF(type)) 01638 01639 #define PyTypeNum_ISOBJECT(type) ((type) == NPY_OBJECT) 01640 01641 01642 #define PyDataType_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj)) 01643 #define PyDataType_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(((PyArray_Descr*)(obj))->type_num) 01644 #define PyDataType_ISSIGNED(obj) PyTypeNum_ISSIGNED(((PyArray_Descr*)(obj))->type_num) 01645 #define PyDataType_ISINTEGER(obj) PyTypeNum_ISINTEGER(((PyArray_Descr*)(obj))->type_num ) 01646 #define PyDataType_ISFLOAT(obj) PyTypeNum_ISFLOAT(((PyArray_Descr*)(obj))->type_num) 01647 #define PyDataType_ISNUMBER(obj) PyTypeNum_ISNUMBER(((PyArray_Descr*)(obj))->type_num) 01648 #define PyDataType_ISSTRING(obj) PyTypeNum_ISSTRING(((PyArray_Descr*)(obj))->type_num) 01649 #define PyDataType_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(((PyArray_Descr*)(obj))->type_num) 01650 #define PyDataType_ISPYTHON(obj) PyTypeNum_ISPYTHON(((PyArray_Descr*)(obj))->type_num) 01651 #define PyDataType_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(((PyArray_Descr*)(obj))->type_num) 01652 #define PyDataType_ISDATETIME(obj) PyTypeNum_ISDATETIME(((PyArray_Descr*)(obj))->type_num) 01653 #define PyDataType_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(((PyArray_Descr*)(obj))->type_num) 01654 #define PyDataType_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(((PyArray_Descr*)(obj))->type_num) 01655 #define PyDataType_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)(obj))->type_num) 01656 #define PyDataType_HASFIELDS(obj) (((PyArray_Descr *)(obj))->names != NULL) 01657 #define PyDataType_HASSUBARRAY(dtype) ((dtype)->subarray != NULL) 01658 01659 #define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj)) 01660 #define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj)) 01661 #define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj)) 01662 #define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj)) 01663 #define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj)) 01664 #define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj)) 01665 #define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj)) 01666 #define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj)) 01667 #define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj)) 01668 #define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj)) 01669 #define PyArray_ISDATETIME(obj) PyTypeNum_ISDATETIME(PyArray_TYPE(obj)) 01670 #define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj)) 01671 #define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj)) 01672 #define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj)) 01673 #define PyArray_HASFIELDS(obj) PyDataType_HASFIELDS(PyArray_DESCR(obj)) 01674 01675 /* 01676 * FIXME: This should check for a flag on the data-type that 01677 * states whether or not it is variable length. Because the 01678 * ISFLEXIBLE check is hard-coded to the built-in data-types. 01679 */ 01680 #define PyArray_ISVARIABLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj)) 01681 01682 #define PyArray_SAFEALIGNEDCOPY(obj) (PyArray_ISALIGNED(obj) && !PyArray_ISVARIABLE(obj)) 01683 01684 01685 #define NPY_LITTLE '<' 01686 #define NPY_BIG '>' 01687 #define NPY_NATIVE '=' 01688 #define NPY_SWAP 's' 01689 #define NPY_IGNORE '|' 01690 01691 #if NPY_BYTE_ORDER == NPY_BIG_ENDIAN 01692 #define NPY_NATBYTE NPY_BIG 01693 #define NPY_OPPBYTE NPY_LITTLE 01694 #else 01695 #define NPY_NATBYTE NPY_LITTLE 01696 #define NPY_OPPBYTE NPY_BIG 01697 #endif 01698 01699 #define PyArray_ISNBO(arg) ((arg) != NPY_OPPBYTE) 01700 #define PyArray_IsNativeByteOrder PyArray_ISNBO 01701 #define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder) 01702 #define PyArray_ISBYTESWAPPED(m) (!PyArray_ISNOTSWAPPED(m)) 01703 01704 #define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) && \ 01705 PyArray_ISNOTSWAPPED(m)) 01706 01707 #define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY) 01708 #define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY_RO) 01709 #define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY) 01710 #define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY_RO) 01711 #define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, NPY_ARRAY_BEHAVED) 01712 #define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_ALIGNED) 01713 01714 01715 #define PyDataType_ISNOTSWAPPED(d) PyArray_ISNBO(((PyArray_Descr *)(d))->byteorder) 01716 #define PyDataType_ISBYTESWAPPED(d) (!PyDataType_ISNOTSWAPPED(d)) 01717 01718 /************************************************************ 01719 * A struct used by PyArray_CreateSortedStridePerm, new in 1.7. 01720 ************************************************************/ 01721 01722 typedef struct { 01723 npy_intp perm, stride; 01724 } npy_stride_sort_item; 01725 01726 /************************************************************ 01727 * This is the form of the struct that's returned pointed by the 01728 * PyCObject attribute of an array __array_struct__. See 01729 * http://docs.scipy.org/doc/numpy/reference/arrays.interface.html for the full 01730 * documentation. 01731 ************************************************************/ 01732 typedef struct { 01733 int two; /* 01734 * contains the integer 2 as a sanity 01735 * check 01736 */ 01737 01738 int nd; /* number of dimensions */ 01739 01740 char typekind; /* 01741 * kind in array --- character code of 01742 * typestr 01743 */ 01744 01745 int itemsize; /* size of each element */ 01746 01747 int flags; /* 01748 * how should be data interpreted. Valid 01749 * flags are CONTIGUOUS (1), F_CONTIGUOUS (2), 01750 * ALIGNED (0x100), NOTSWAPPED (0x200), and 01751 * WRITEABLE (0x400). ARR_HAS_DESCR (0x800) 01752 * states that arrdescr field is present in 01753 * structure 01754 */ 01755 01756 npy_intp *shape; /* 01757 * A length-nd array of shape 01758 * information 01759 */ 01760 01761 npy_intp *strides; /* A length-nd array of stride information */ 01762 01763 void *data; /* A pointer to the first element of the array */ 01764 01765 PyObject *descr; /* 01766 * A list of fields or NULL (ignored if flags 01767 * does not have ARR_HAS_DESCR flag set) 01768 */ 01769 } PyArrayInterface; 01770 01771 /* 01772 * This is a function for hooking into the PyDataMem_NEW/FREE/RENEW functions. 01773 * See the documentation for PyDataMem_SetEventHook. 01774 */ 01775 typedef void (PyDataMem_EventHookFunc)(void *inp, void *outp, size_t size, 01776 void *user_data); 01777 01778 /* 01779 * Use the keyword NPY_DEPRECATED_INCLUDES to ensure that the header files 01780 * npy_*_*_deprecated_api.h are only included from here and nowhere else. 01781 */ 01782 #ifdef NPY_DEPRECATED_INCLUDES 01783 #error "Do not use the reserved keyword NPY_DEPRECATED_INCLUDES." 01784 #endif 01785 #define NPY_DEPRECATED_INCLUDES 01786 #if !defined(NPY_NO_DEPRECATED_API) || \ 01787 (NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION) 01788 #include "npy_1_7_deprecated_api.h" 01789 #endif 01790 /* 01791 * There is no file npy_1_8_deprecated_api.h since there are no additional 01792 * deprecated API features in NumPy 1.8. 01793 * 01794 * Note to maintainers: insert code like the following in future NumPy 01795 * versions. 01796 * 01797 * #if !defined(NPY_NO_DEPRECATED_API) || \ 01798 * (NPY_NO_DEPRECATED_API < NPY_1_9_API_VERSION) 01799 * #include "npy_1_9_deprecated_api.h" 01800 * #endif 01801 */ 01802 #undef NPY_DEPRECATED_INCLUDES 01803 01804 #endif /* NPY_ARRAYTYPES_H */