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