LCOV - code coverage report
Current view: top level - usr/lib64/python3.8/site-packages/numpy/core/include/numpy - ndarraytypes.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 8 10 80.0 %
Date: 2021-10-13 02:24:04 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef NDARRAYTYPES_H
       2             : #define NDARRAYTYPES_H
       3             : 
       4             : #include "npy_common.h"
       5             : #include "npy_endian.h"
       6             : #include "npy_cpu.h"
       7             : #include "utils.h"
       8             : 
       9             : #define NPY_NO_EXPORT NPY_VISIBILITY_HIDDEN
      10             : 
      11             : /* Only use thread if configured in config and python supports it */
      12             : #if defined WITH_THREAD && !NPY_NO_SMP
      13             :         #define NPY_ALLOW_THREADS 1
      14             : #else
      15             :         #define NPY_ALLOW_THREADS 0
      16             : #endif
      17             : 
      18             : #ifndef __has_extension
      19             : #define __has_extension(x) 0
      20             : #endif
      21             : 
      22             : #if !defined(_NPY_NO_DEPRECATIONS) && \
      23             :     ((defined(__GNUC__)&& __GNUC__ >= 6) || \
      24             :      __has_extension(attribute_deprecated_with_message))
      25             : #define NPY_ATTR_DEPRECATE(text) __attribute__ ((deprecated (text)))
      26             : #else
      27             : #define NPY_ATTR_DEPRECATE(text)
      28             : #endif
      29             : 
      30             : /*
      31             :  * There are several places in the code where an array of dimensions
      32             :  * is allocated statically.  This is the size of that static
      33             :  * allocation.
      34             :  *
      35             :  * The array creation itself could have arbitrary dimensions but all
      36             :  * the places where static allocation is used would need to be changed
      37             :  * to dynamic (including inside of several structures)
      38             :  */
      39             : 
      40             : #define NPY_MAXDIMS 32
      41             : #define NPY_MAXARGS 32
      42             : 
      43             : /* Used for Converter Functions "O&" code in ParseTuple */
      44             : #define NPY_FAIL 0
      45             : #define NPY_SUCCEED 1
      46             : 
      47             : /*
      48             :  * Binary compatibility version number.  This number is increased
      49             :  * whenever the C-API is changed such that binary compatibility is
      50             :  * broken, i.e. whenever a recompile of extension modules is needed.
      51             :  */
      52             : #define NPY_VERSION NPY_ABI_VERSION
      53             : 
      54             : /*
      55             :  * Minor API version.  This number is increased whenever a change is
      56             :  * made to the C-API -- whether it breaks binary compatibility or not.
      57             :  * Some changes, such as adding a function pointer to the end of the
      58             :  * function table, can be made without breaking binary compatibility.
      59             :  * In this case, only the NPY_FEATURE_VERSION (*not* NPY_VERSION)
      60             :  * would be increased.  Whenever binary compatibility is broken, both
      61             :  * NPY_VERSION and NPY_FEATURE_VERSION should be increased.
      62             :  */
      63             : #define NPY_FEATURE_VERSION NPY_API_VERSION
      64             : 
      65             : enum NPY_TYPES {    NPY_BOOL=0,
      66             :                     NPY_BYTE, NPY_UBYTE,
      67             :                     NPY_SHORT, NPY_USHORT,
      68             :                     NPY_INT, NPY_UINT,
      69             :                     NPY_LONG, NPY_ULONG,
      70             :                     NPY_LONGLONG, NPY_ULONGLONG,
      71             :                     NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE,
      72             :                     NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE,
      73             :                     NPY_OBJECT=17,
      74             :                     NPY_STRING, NPY_UNICODE,
      75             :                     NPY_VOID,
      76             :                     /*
      77             :                      * New 1.6 types appended, may be integrated
      78             :                      * into the above in 2.0.
      79             :                      */
      80             :                     NPY_DATETIME, NPY_TIMEDELTA, NPY_HALF,
      81             : 
      82             :                     NPY_NTYPES,
      83             :                     NPY_NOTYPE,
      84             :                     NPY_CHAR NPY_ATTR_DEPRECATE("Use NPY_STRING"),
      85             :                     NPY_USERDEF=256,  /* leave room for characters */
      86             : 
      87             :                     /* The number of types not including the new 1.6 types */
      88             :                     NPY_NTYPES_ABI_COMPATIBLE=21
      89             : };
      90             : #ifdef _MSC_VER
      91             : #pragma deprecated(NPY_CHAR)
      92             : #endif
      93             : 
      94             : /* basetype array priority */
      95             : #define NPY_PRIORITY 0.0
      96             : 
      97             : /* default subtype priority */
      98             : #define NPY_SUBTYPE_PRIORITY 1.0
      99             : 
     100             : /* default scalar priority */
     101             : #define NPY_SCALAR_PRIORITY -1000000.0
     102             : 
     103             : /* How many floating point types are there (excluding half) */
     104             : #define NPY_NUM_FLOATTYPE 3
     105             : 
     106             : /*
     107             :  * These characters correspond to the array type and the struct
     108             :  * module
     109             :  */
     110             : 
     111             : enum NPY_TYPECHAR {
     112             :         NPY_BOOLLTR = '?',
     113             :         NPY_BYTELTR = 'b',
     114             :         NPY_UBYTELTR = 'B',
     115             :         NPY_SHORTLTR = 'h',
     116             :         NPY_USHORTLTR = 'H',
     117             :         NPY_INTLTR = 'i',
     118             :         NPY_UINTLTR = 'I',
     119             :         NPY_LONGLTR = 'l',
     120             :         NPY_ULONGLTR = 'L',
     121             :         NPY_LONGLONGLTR = 'q',
     122             :         NPY_ULONGLONGLTR = 'Q',
     123             :         NPY_HALFLTR = 'e',
     124             :         NPY_FLOATLTR = 'f',
     125             :         NPY_DOUBLELTR = 'd',
     126             :         NPY_LONGDOUBLELTR = 'g',
     127             :         NPY_CFLOATLTR = 'F',
     128             :         NPY_CDOUBLELTR = 'D',
     129             :         NPY_CLONGDOUBLELTR = 'G',
     130             :         NPY_OBJECTLTR = 'O',
     131             :         NPY_STRINGLTR = 'S',
     132             :         NPY_STRINGLTR2 = 'a',
     133             :         NPY_UNICODELTR = 'U',
     134             :         NPY_VOIDLTR = 'V',
     135             :         NPY_DATETIMELTR = 'M',
     136             :         NPY_TIMEDELTALTR = 'm',
     137             :         NPY_CHARLTR = 'c',
     138             : 
     139             :         /*
     140             :          * No Descriptor, just a define -- this let's
     141             :          * Python users specify an array of integers
     142             :          * large enough to hold a pointer on the
     143             :          * platform
     144             :          */
     145             :         NPY_INTPLTR = 'p',
     146             :         NPY_UINTPLTR = 'P',
     147             : 
     148             :         /*
     149             :          * These are for dtype 'kinds', not dtype 'typecodes'
     150             :          * as the above are for.
     151             :          */
     152             :         NPY_GENBOOLLTR ='b',
     153             :         NPY_SIGNEDLTR = 'i',
     154             :         NPY_UNSIGNEDLTR = 'u',
     155             :         NPY_FLOATINGLTR = 'f',
     156             :         NPY_COMPLEXLTR = 'c'
     157             : };
     158             : 
     159             : /*
     160             :  * Changing this may break Numpy API compatibility
     161             :  * due to changing offsets in PyArray_ArrFuncs, so be
     162             :  * careful. Here we have reused the mergesort slot for
     163             :  * any kind of stable sort, the actual implementation will
     164             :  * depend on the data type.
     165             :  */
     166             : typedef enum {
     167             :         NPY_QUICKSORT=0,
     168             :         NPY_HEAPSORT=1,
     169             :         NPY_MERGESORT=2,
     170             :         NPY_STABLESORT=2,
     171             : } NPY_SORTKIND;
     172             : #define NPY_NSORTS (NPY_STABLESORT + 1)
     173             : 
     174             : 
     175             : typedef enum {
     176             :         NPY_INTROSELECT=0
     177             : } NPY_SELECTKIND;
     178             : #define NPY_NSELECTS (NPY_INTROSELECT + 1)
     179             : 
     180             : 
     181             : typedef enum {
     182             :         NPY_SEARCHLEFT=0,
     183             :         NPY_SEARCHRIGHT=1
     184             : } NPY_SEARCHSIDE;
     185             : #define NPY_NSEARCHSIDES (NPY_SEARCHRIGHT + 1)
     186             : 
     187             : 
     188             : typedef enum {
     189             :         NPY_NOSCALAR=-1,
     190             :         NPY_BOOL_SCALAR,
     191             :         NPY_INTPOS_SCALAR,
     192             :         NPY_INTNEG_SCALAR,
     193             :         NPY_FLOAT_SCALAR,
     194             :         NPY_COMPLEX_SCALAR,
     195             :         NPY_OBJECT_SCALAR
     196             : } NPY_SCALARKIND;
     197             : #define NPY_NSCALARKINDS (NPY_OBJECT_SCALAR + 1)
     198             : 
     199             : /* For specifying array memory layout or iteration order */
     200             : typedef enum {
     201             :         /* Fortran order if inputs are all Fortran, C otherwise */
     202             :         NPY_ANYORDER=-1,
     203             :         /* C order */
     204             :         NPY_CORDER=0,
     205             :         /* Fortran order */
     206             :         NPY_FORTRANORDER=1,
     207             :         /* An order as close to the inputs as possible */
     208             :         NPY_KEEPORDER=2
     209             : } NPY_ORDER;
     210             : 
     211             : /* For specifying allowed casting in operations which support it */
     212             : typedef enum {
     213             :         /* Only allow identical types */
     214             :         NPY_NO_CASTING=0,
     215             :         /* Allow identical and byte swapped types */
     216             :         NPY_EQUIV_CASTING=1,
     217             :         /* Only allow safe casts */
     218             :         NPY_SAFE_CASTING=2,
     219             :         /* Allow safe casts or casts within the same kind */
     220             :         NPY_SAME_KIND_CASTING=3,
     221             :         /* Allow any casts */
     222             :         NPY_UNSAFE_CASTING=4
     223             : } NPY_CASTING;
     224             : 
     225             : typedef enum {
     226             :         NPY_CLIP=0,
     227             :         NPY_WRAP=1,
     228             :         NPY_RAISE=2
     229             : } NPY_CLIPMODE;
     230             : 
     231             : /* The special not-a-time (NaT) value */
     232             : #define NPY_DATETIME_NAT NPY_MIN_INT64
     233             : 
     234             : /*
     235             :  * Upper bound on the length of a DATETIME ISO 8601 string
     236             :  *   YEAR: 21 (64-bit year)
     237             :  *   MONTH: 3
     238             :  *   DAY: 3
     239             :  *   HOURS: 3
     240             :  *   MINUTES: 3
     241             :  *   SECONDS: 3
     242             :  *   ATTOSECONDS: 1 + 3*6
     243             :  *   TIMEZONE: 5
     244             :  *   NULL TERMINATOR: 1
     245             :  */
     246             : #define NPY_DATETIME_MAX_ISO8601_STRLEN (21 + 3*5 + 1 + 3*6 + 6 + 1)
     247             : 
     248             : /* The FR in the unit names stands for frequency */
     249             : typedef enum {
     250             :         /* Force signed enum type, must be -1 for code compatibility */
     251             :         NPY_FR_ERROR = -1,      /* error or undetermined */
     252             : 
     253             :         /* Start of valid units */
     254             :         NPY_FR_Y = 0,           /* Years */
     255             :         NPY_FR_M = 1,           /* Months */
     256             :         NPY_FR_W = 2,           /* Weeks */
     257             :         /* Gap where 1.6 NPY_FR_B (value 3) was */
     258             :         NPY_FR_D = 4,           /* Days */
     259             :         NPY_FR_h = 5,           /* hours */
     260             :         NPY_FR_m = 6,           /* minutes */
     261             :         NPY_FR_s = 7,           /* seconds */
     262             :         NPY_FR_ms = 8,          /* milliseconds */
     263             :         NPY_FR_us = 9,          /* microseconds */
     264             :         NPY_FR_ns = 10,         /* nanoseconds */
     265             :         NPY_FR_ps = 11,         /* picoseconds */
     266             :         NPY_FR_fs = 12,         /* femtoseconds */
     267             :         NPY_FR_as = 13,         /* attoseconds */
     268             :         NPY_FR_GENERIC = 14     /* unbound units, can convert to anything */
     269             : } NPY_DATETIMEUNIT;
     270             : 
     271             : /*
     272             :  * NOTE: With the NPY_FR_B gap for 1.6 ABI compatibility, NPY_DATETIME_NUMUNITS
     273             :  * is technically one more than the actual number of units.
     274             :  */
     275             : #define NPY_DATETIME_NUMUNITS (NPY_FR_GENERIC + 1)
     276             : #define NPY_DATETIME_DEFAULTUNIT NPY_FR_GENERIC
     277             : 
     278             : /*
     279             :  * Business day conventions for mapping invalid business
     280             :  * days to valid business days.
     281             :  */
     282             : typedef enum {
     283             :     /* Go forward in time to the following business day. */
     284             :     NPY_BUSDAY_FORWARD,
     285             :     NPY_BUSDAY_FOLLOWING = NPY_BUSDAY_FORWARD,
     286             :     /* Go backward in time to the preceding business day. */
     287             :     NPY_BUSDAY_BACKWARD,
     288             :     NPY_BUSDAY_PRECEDING = NPY_BUSDAY_BACKWARD,
     289             :     /*
     290             :      * Go forward in time to the following business day, unless it
     291             :      * crosses a month boundary, in which case go backward
     292             :      */
     293             :     NPY_BUSDAY_MODIFIEDFOLLOWING,
     294             :     /*
     295             :      * Go backward in time to the preceding business day, unless it
     296             :      * crosses a month boundary, in which case go forward.
     297             :      */
     298             :     NPY_BUSDAY_MODIFIEDPRECEDING,
     299             :     /* Produce a NaT for non-business days. */
     300             :     NPY_BUSDAY_NAT,
     301             :     /* Raise an exception for non-business days. */
     302             :     NPY_BUSDAY_RAISE
     303             : } NPY_BUSDAY_ROLL;
     304             : 
     305             : /************************************************************
     306             :  * NumPy Auxiliary Data for inner loops, sort functions, etc.
     307             :  ************************************************************/
     308             : 
     309             : /*
     310             :  * When creating an auxiliary data struct, this should always appear
     311             :  * as the first member, like this:
     312             :  *
     313             :  * typedef struct {
     314             :  *     NpyAuxData base;
     315             :  *     double constant;
     316             :  * } constant_multiplier_aux_data;
     317             :  */
     318             : typedef struct NpyAuxData_tag NpyAuxData;
     319             : 
     320             : /* Function pointers for freeing or cloning auxiliary data */
     321             : typedef void (NpyAuxData_FreeFunc) (NpyAuxData *);
     322             : typedef NpyAuxData *(NpyAuxData_CloneFunc) (NpyAuxData *);
     323             : 
     324             : struct NpyAuxData_tag {
     325             :     NpyAuxData_FreeFunc *free;
     326             :     NpyAuxData_CloneFunc *clone;
     327             :     /* To allow for a bit of expansion without breaking the ABI */
     328             :     void *reserved[2];
     329             : };
     330             : 
     331             : /* Macros to use for freeing and cloning auxiliary data */
     332             : #define NPY_AUXDATA_FREE(auxdata) \
     333             :     do { \
     334             :         if ((auxdata) != NULL) { \
     335             :             (auxdata)->free(auxdata); \
     336             :         } \
     337             :     } while(0)
     338             : #define NPY_AUXDATA_CLONE(auxdata) \
     339             :     ((auxdata)->clone(auxdata))
     340             : 
     341             : #define NPY_ERR(str) fprintf(stderr, #str); fflush(stderr);
     342             : #define NPY_ERR2(str) fprintf(stderr, str); fflush(stderr);
     343             : 
     344             : #define NPY_STRINGIFY(x) #x
     345             : #define NPY_TOSTRING(x) NPY_STRINGIFY(x)
     346             : 
     347             :   /*
     348             :    * Macros to define how array, and dimension/strides data is
     349             :    * allocated.
     350             :    */
     351             : 
     352             :   /* Data buffer - PyDataMem_NEW/FREE/RENEW are in multiarraymodule.c */
     353             : 
     354             : #define NPY_USE_PYMEM 1
     355             : 
     356             : #if NPY_USE_PYMEM == 1
     357             :    /* numpy sometimes calls PyArray_malloc() with the GIL released. On Python
     358             :       3.3 and older, it was safe to call PyMem_Malloc() with the GIL released.
     359             :       On Python 3.4 and newer, it's better to use PyMem_RawMalloc() to be able
     360             :       to use tracemalloc. On Python 3.6, calling PyMem_Malloc() with the GIL
     361             :       released is now a fatal error in debug mode. */
     362             : #  if PY_VERSION_HEX >= 0x03040000
     363             : #    define PyArray_malloc PyMem_RawMalloc
     364             : #    define PyArray_free PyMem_RawFree
     365             : #    define PyArray_realloc PyMem_RawRealloc
     366             : #  else
     367             : #    define PyArray_malloc PyMem_Malloc
     368             : #    define PyArray_free PyMem_Free
     369             : #    define PyArray_realloc PyMem_Realloc
     370             : #  endif
     371             : #else
     372             : #define PyArray_malloc malloc
     373             : #define PyArray_free free
     374             : #define PyArray_realloc realloc
     375             : #endif
     376             : 
     377             : /* Dimensions and strides */
     378             : #define PyDimMem_NEW(size)                                         \
     379             :     ((npy_intp *)PyArray_malloc(size*sizeof(npy_intp)))
     380             : 
     381             : #define PyDimMem_FREE(ptr) PyArray_free(ptr)
     382             : 
     383             : #define PyDimMem_RENEW(ptr,size)                                   \
     384             :         ((npy_intp *)PyArray_realloc(ptr,size*sizeof(npy_intp)))
     385             : 
     386             : /* forward declaration */
     387             : struct _PyArray_Descr;
     388             : 
     389             : /* These must deal with unaligned and swapped data if necessary */
     390             : typedef PyObject * (PyArray_GetItemFunc) (void *, void *);
     391             : typedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);
     392             : 
     393             : typedef void (PyArray_CopySwapNFunc)(void *, npy_intp, void *, npy_intp,
     394             :                                      npy_intp, int, void *);
     395             : 
     396             : typedef void (PyArray_CopySwapFunc)(void *, void *, int, void *);
     397             : typedef npy_bool (PyArray_NonzeroFunc)(void *, void *);
     398             : 
     399             : 
     400             : /*
     401             :  * These assume aligned and notswapped data -- a buffer will be used
     402             :  * before or contiguous data will be obtained
     403             :  */
     404             : 
     405             : typedef int (PyArray_CompareFunc)(const void *, const void *, void *);
     406             : typedef int (PyArray_ArgFunc)(void*, npy_intp, npy_intp*, void *);
     407             : 
     408             : typedef void (PyArray_DotFunc)(void *, npy_intp, void *, npy_intp, void *,
     409             :                                npy_intp, void *);
     410             : 
     411             : typedef void (PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *,
     412             :                                        void *);
     413             : 
     414             : /*
     415             :  * XXX the ignore argument should be removed next time the API version
     416             :  * is bumped. It used to be the separator.
     417             :  */
     418             : typedef int (PyArray_ScanFunc)(FILE *fp, void *dptr,
     419             :                                char *ignore, struct _PyArray_Descr *);
     420             : typedef int (PyArray_FromStrFunc)(char *s, void *dptr, char **endptr,
     421             :                                   struct _PyArray_Descr *);
     422             : 
     423             : typedef int (PyArray_FillFunc)(void *, npy_intp, void *);
     424             : 
     425             : typedef int (PyArray_SortFunc)(void *, npy_intp, void *);
     426             : typedef int (PyArray_ArgSortFunc)(void *, npy_intp *, npy_intp, void *);
     427             : typedef int (PyArray_PartitionFunc)(void *, npy_intp, npy_intp,
     428             :                                     npy_intp *, npy_intp *,
     429             :                                     void *);
     430             : typedef int (PyArray_ArgPartitionFunc)(void *, npy_intp *, npy_intp, npy_intp,
     431             :                                        npy_intp *, npy_intp *,
     432             :                                        void *);
     433             : 
     434             : typedef int (PyArray_FillWithScalarFunc)(void *, npy_intp, void *, void *);
     435             : 
     436             : typedef int (PyArray_ScalarKindFunc)(void *);
     437             : 
     438             : typedef void (PyArray_FastClipFunc)(void *in, npy_intp n_in, void *min,
     439             :                                     void *max, void *out);
     440             : typedef void (PyArray_FastPutmaskFunc)(void *in, void *mask, npy_intp n_in,
     441             :                                        void *values, npy_intp nv);
     442             : typedef int  (PyArray_FastTakeFunc)(void *dest, void *src, npy_intp *indarray,
     443             :                                        npy_intp nindarray, npy_intp n_outer,
     444             :                                        npy_intp m_middle, npy_intp nelem,
     445             :                                        NPY_CLIPMODE clipmode);
     446             : 
     447             : typedef struct {
     448             :         npy_intp *ptr;
     449             :         int len;
     450             : } PyArray_Dims;
     451             : 
     452             : typedef struct {
     453             :         /*
     454             :          * Functions to cast to most other standard types
     455             :          * Can have some NULL entries. The types
     456             :          * DATETIME, TIMEDELTA, and HALF go into the castdict
     457             :          * even though they are built-in.
     458             :          */
     459             :         PyArray_VectorUnaryFunc *cast[NPY_NTYPES_ABI_COMPATIBLE];
     460             : 
     461             :         /* The next four functions *cannot* be NULL */
     462             : 
     463             :         /*
     464             :          * Functions to get and set items with standard Python types
     465             :          * -- not array scalars
     466             :          */
     467             :         PyArray_GetItemFunc *getitem;
     468             :         PyArray_SetItemFunc *setitem;
     469             : 
     470             :         /*
     471             :          * Copy and/or swap data.  Memory areas may not overlap
     472             :          * Use memmove first if they might
     473             :          */
     474             :         PyArray_CopySwapNFunc *copyswapn;
     475             :         PyArray_CopySwapFunc *copyswap;
     476             : 
     477             :         /*
     478             :          * Function to compare items
     479             :          * Can be NULL
     480             :          */
     481             :         PyArray_CompareFunc *compare;
     482             : 
     483             :         /*
     484             :          * Function to select largest
     485             :          * Can be NULL
     486             :          */
     487             :         PyArray_ArgFunc *argmax;
     488             : 
     489             :         /*
     490             :          * Function to compute dot product
     491             :          * Can be NULL
     492             :          */
     493             :         PyArray_DotFunc *dotfunc;
     494             : 
     495             :         /*
     496             :          * Function to scan an ASCII file and
     497             :          * place a single value plus possible separator
     498             :          * Can be NULL
     499             :          */
     500             :         PyArray_ScanFunc *scanfunc;
     501             : 
     502             :         /*
     503             :          * Function to read a single value from a string
     504             :          * and adjust the pointer; Can be NULL
     505             :          */
     506             :         PyArray_FromStrFunc *fromstr;
     507             : 
     508             :         /*
     509             :          * Function to determine if data is zero or not
     510             :          * If NULL a default version is
     511             :          * used at Registration time.
     512             :          */
     513             :         PyArray_NonzeroFunc *nonzero;
     514             : 
     515             :         /*
     516             :          * Used for arange. Should return 0 on success
     517             :          * and -1 on failure.
     518             :          * Can be NULL.
     519             :          */
     520             :         PyArray_FillFunc *fill;
     521             : 
     522             :         /*
     523             :          * Function to fill arrays with scalar values
     524             :          * Can be NULL
     525             :          */
     526             :         PyArray_FillWithScalarFunc *fillwithscalar;
     527             : 
     528             :         /*
     529             :          * Sorting functions
     530             :          * Can be NULL
     531             :          */
     532             :         PyArray_SortFunc *sort[NPY_NSORTS];
     533             :         PyArray_ArgSortFunc *argsort[NPY_NSORTS];
     534             : 
     535             :         /*
     536             :          * Dictionary of additional casting functions
     537             :          * PyArray_VectorUnaryFuncs
     538             :          * which can be populated to support casting
     539             :          * to other registered types. Can be NULL
     540             :          */
     541             :         PyObject *castdict;
     542             : 
     543             :         /*
     544             :          * Functions useful for generalizing
     545             :          * the casting rules.
     546             :          * Can be NULL;
     547             :          */
     548             :         PyArray_ScalarKindFunc *scalarkind;
     549             :         int **cancastscalarkindto;
     550             :         int *cancastto;
     551             : 
     552             :         PyArray_FastClipFunc *fastclip;
     553             :         PyArray_FastPutmaskFunc *fastputmask;
     554             :         PyArray_FastTakeFunc *fasttake;
     555             : 
     556             :         /*
     557             :          * Function to select smallest
     558             :          * Can be NULL
     559             :          */
     560             :         PyArray_ArgFunc *argmin;
     561             : 
     562             : } PyArray_ArrFuncs;
     563             : 
     564             : /* The item must be reference counted when it is inserted or extracted. */
     565             : #define NPY_ITEM_REFCOUNT   0x01
     566             : /* Same as needing REFCOUNT */
     567             : #define NPY_ITEM_HASOBJECT  0x01
     568             : /* Convert to list for pickling */
     569             : #define NPY_LIST_PICKLE     0x02
     570             : /* The item is a POINTER  */
     571             : #define NPY_ITEM_IS_POINTER 0x04
     572             : /* memory needs to be initialized for this data-type */
     573             : #define NPY_NEEDS_INIT      0x08
     574             : /* operations need Python C-API so don't give-up thread. */
     575             : #define NPY_NEEDS_PYAPI     0x10
     576             : /* Use f.getitem when extracting elements of this data-type */
     577             : #define NPY_USE_GETITEM     0x20
     578             : /* Use f.setitem when setting creating 0-d array from this data-type.*/
     579             : #define NPY_USE_SETITEM     0x40
     580             : /* A sticky flag specifically for structured arrays */
     581             : #define NPY_ALIGNED_STRUCT  0x80
     582             : 
     583             : /*
     584             :  *These are inherited for global data-type if any data-types in the
     585             :  * field have them
     586             :  */
     587             : #define NPY_FROM_FIELDS    (NPY_NEEDS_INIT | NPY_LIST_PICKLE | \
     588             :                             NPY_ITEM_REFCOUNT | NPY_NEEDS_PYAPI)
     589             : 
     590             : #define NPY_OBJECT_DTYPE_FLAGS (NPY_LIST_PICKLE | NPY_USE_GETITEM | \
     591             :                                 NPY_ITEM_IS_POINTER | NPY_ITEM_REFCOUNT | \
     592             :                                 NPY_NEEDS_INIT | NPY_NEEDS_PYAPI)
     593             : 
     594             : #define PyDataType_FLAGCHK(dtype, flag) \
     595             :         (((dtype)->flags & (flag)) == (flag))
     596             : 
     597             : #define PyDataType_REFCHK(dtype) \
     598             :         PyDataType_FLAGCHK(dtype, NPY_ITEM_REFCOUNT)
     599             : 
     600             : typedef struct _PyArray_Descr {
     601             :         PyObject_HEAD
     602             :         /*
     603             :          * the type object representing an
     604             :          * instance of this type -- should not
     605             :          * be two type_numbers with the same type
     606             :          * object.
     607             :          */
     608             :         PyTypeObject *typeobj;
     609             :         /* kind for this type */
     610             :         char kind;
     611             :         /* unique-character representing this type */
     612             :         char type;
     613             :         /*
     614             :          * '>' (big), '<' (little), '|'
     615             :          * (not-applicable), or '=' (native).
     616             :          */
     617             :         char byteorder;
     618             :         /* flags describing data type */
     619             :         char flags;
     620             :         /* number representing this type */
     621             :         int type_num;
     622             :         /* element size (itemsize) for this type */
     623             :         int elsize;
     624             :         /* alignment needed for this type */
     625             :         int alignment;
     626             :         /*
     627             :          * Non-NULL if this type is
     628             :          * is an array (C-contiguous)
     629             :          * of some other type
     630             :          */
     631             :         struct _arr_descr *subarray;
     632             :         /*
     633             :          * The fields dictionary for this type
     634             :          * For statically defined descr this
     635             :          * is always Py_None
     636             :          */
     637             :         PyObject *fields;
     638             :         /*
     639             :          * An ordered tuple of field names or NULL
     640             :          * if no fields are defined
     641             :          */
     642             :         PyObject *names;
     643             :         /*
     644             :          * a table of functions specific for each
     645             :          * basic data descriptor
     646             :          */
     647             :         PyArray_ArrFuncs *f;
     648             :         /* Metadata about this dtype */
     649             :         PyObject *metadata;
     650             :         /*
     651             :          * Metadata specific to the C implementation
     652             :          * of the particular dtype. This was added
     653             :          * for NumPy 1.7.0.
     654             :          */
     655             :         NpyAuxData *c_metadata;
     656             :         /* Cached hash value (-1 if not yet computed).
     657             :          * This was added for NumPy 2.0.0.
     658             :          */
     659             :         npy_hash_t hash;
     660             : } PyArray_Descr;
     661             : 
     662             : typedef struct _arr_descr {
     663             :         PyArray_Descr *base;
     664             :         PyObject *shape;       /* a tuple */
     665             : } PyArray_ArrayDescr;
     666             : 
     667             : /*
     668             :  * The main array object structure.
     669             :  *
     670             :  * It has been recommended to use the inline functions defined below
     671             :  * (PyArray_DATA and friends) to access fields here for a number of
     672             :  * releases. Direct access to the members themselves is deprecated.
     673             :  * To ensure that your code does not use deprecated access,
     674             :  * #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
     675             :  * (or NPY_1_8_API_VERSION or higher as required).
     676             :  */
     677             : /* This struct will be moved to a private header in a future release */
     678             : typedef struct tagPyArrayObject_fields {
     679             :     PyObject_HEAD
     680             :     /* Pointer to the raw data buffer */
     681             :     char *data;
     682             :     /* The number of dimensions, also called 'ndim' */
     683             :     int nd;
     684             :     /* The size in each dimension, also called 'shape' */
     685             :     npy_intp *dimensions;
     686             :     /*
     687             :      * Number of bytes to jump to get to the
     688             :      * next element in each dimension
     689             :      */
     690             :     npy_intp *strides;
     691             :     /*
     692             :      * This object is decref'd upon
     693             :      * deletion of array. Except in the
     694             :      * case of WRITEBACKIFCOPY which has
     695             :      * special handling.
     696             :      *
     697             :      * For views it points to the original
     698             :      * array, collapsed so no chains of
     699             :      * views occur.
     700             :      *
     701             :      * For creation from buffer object it
     702             :      * points to an object that should be
     703             :      * decref'd on deletion
     704             :      *
     705             :      * For WRITEBACKIFCOPY flag this is an
     706             :      * array to-be-updated upon calling
     707             :      * PyArray_ResolveWritebackIfCopy
     708             :      */
     709             :     PyObject *base;
     710             :     /* Pointer to type structure */
     711             :     PyArray_Descr *descr;
     712             :     /* Flags describing array -- see below */
     713             :     int flags;
     714             :     /* For weak references */
     715             :     PyObject *weakreflist;
     716             : } PyArrayObject_fields;
     717             : 
     718             : /*
     719             :  * To hide the implementation details, we only expose
     720             :  * the Python struct HEAD.
     721             :  */
     722             : #if !defined(NPY_NO_DEPRECATED_API) || \
     723             :     (NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
     724             : /*
     725             :  * Can't put this in npy_deprecated_api.h like the others.
     726             :  * PyArrayObject field access is deprecated as of NumPy 1.7.
     727             :  */
     728             : typedef PyArrayObject_fields PyArrayObject;
     729             : #else
     730             : typedef struct tagPyArrayObject {
     731             :         PyObject_HEAD
     732             : } PyArrayObject;
     733             : #endif
     734             : 
     735             : #define NPY_SIZEOF_PYARRAYOBJECT (sizeof(PyArrayObject_fields))
     736             : 
     737             : /* Array Flags Object */
     738             : typedef struct PyArrayFlagsObject {
     739             :         PyObject_HEAD
     740             :         PyObject *arr;
     741             :         int flags;
     742             : } PyArrayFlagsObject;
     743             : 
     744             : /* Mirrors buffer object to ptr */
     745             : 
     746             : typedef struct {
     747             :         PyObject_HEAD
     748             :         PyObject *base;
     749             :         void *ptr;
     750             :         npy_intp len;
     751             :         int flags;
     752             : } PyArray_Chunk;
     753             : 
     754             : typedef struct {
     755             :     NPY_DATETIMEUNIT base;
     756             :     int num;
     757             : } PyArray_DatetimeMetaData;
     758             : 
     759             : typedef struct {
     760             :     NpyAuxData base;
     761             :     PyArray_DatetimeMetaData meta;
     762             : } PyArray_DatetimeDTypeMetaData;
     763             : 
     764             : /*
     765             :  * This structure contains an exploded view of a date-time value.
     766             :  * NaT is represented by year == NPY_DATETIME_NAT.
     767             :  */
     768             : typedef struct {
     769             :         npy_int64 year;
     770             :         npy_int32 month, day, hour, min, sec, us, ps, as;
     771             : } npy_datetimestruct;
     772             : 
     773             : /* This is not used internally. */
     774             : typedef struct {
     775             :         npy_int64 day;
     776             :         npy_int32 sec, us, ps, as;
     777             : } npy_timedeltastruct;
     778             : 
     779             : typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
     780             : 
     781             : /*
     782             :  * Means c-style contiguous (last index varies the fastest). The data
     783             :  * elements right after each other.
     784             :  *
     785             :  * This flag may be requested in constructor functions.
     786             :  * This flag may be tested for in PyArray_FLAGS(arr).
     787             :  */
     788             : #define NPY_ARRAY_C_CONTIGUOUS    0x0001
     789             : 
     790             : /*
     791             :  * Set if array is a contiguous Fortran array: the first index varies
     792             :  * the fastest in memory (strides array is reverse of C-contiguous
     793             :  * array)
     794             :  *
     795             :  * This flag may be requested in constructor functions.
     796             :  * This flag may be tested for in PyArray_FLAGS(arr).
     797             :  */
     798             : #define NPY_ARRAY_F_CONTIGUOUS    0x0002
     799             : 
     800             : /*
     801             :  * Note: all 0-d arrays are C_CONTIGUOUS and F_CONTIGUOUS. If a
     802             :  * 1-d array is C_CONTIGUOUS it is also F_CONTIGUOUS. Arrays with
     803             :  * more then one dimension can be C_CONTIGUOUS and F_CONTIGUOUS
     804             :  * at the same time if they have either zero or one element.
     805             :  * If NPY_RELAXED_STRIDES_CHECKING is set, a higher dimensional
     806             :  * array is always C_CONTIGUOUS and F_CONTIGUOUS if it has zero elements
     807             :  * and the array is contiguous if ndarray.squeeze() is contiguous.
     808             :  * I.e. dimensions for which `ndarray.shape[dimension] == 1` are
     809             :  * ignored.
     810             :  */
     811             : 
     812             : /*
     813             :  * If set, the array owns the data: it will be free'd when the array
     814             :  * is deleted.
     815             :  *
     816             :  * This flag may be tested for in PyArray_FLAGS(arr).
     817             :  */
     818             : #define NPY_ARRAY_OWNDATA         0x0004
     819             : 
     820             : /*
     821             :  * An array never has the next four set; they're only used as parameter
     822             :  * flags to the various FromAny functions
     823             :  *
     824             :  * This flag may be requested in constructor functions.
     825             :  */
     826             : 
     827             : /* Cause a cast to occur regardless of whether or not it is safe. */
     828             : #define NPY_ARRAY_FORCECAST       0x0010
     829             : 
     830             : /*
     831             :  * Always copy the array. Returned arrays are always CONTIGUOUS,
     832             :  * ALIGNED, and WRITEABLE.
     833             :  *
     834             :  * This flag may be requested in constructor functions.
     835             :  */
     836             : #define NPY_ARRAY_ENSURECOPY      0x0020
     837             : 
     838             : /*
     839             :  * Make sure the returned array is a base-class ndarray
     840             :  *
     841             :  * This flag may be requested in constructor functions.
     842             :  */
     843             : #define NPY_ARRAY_ENSUREARRAY     0x0040
     844             : 
     845             : /*
     846             :  * Make sure that the strides are in units of the element size Needed
     847             :  * for some operations with record-arrays.
     848             :  *
     849             :  * This flag may be requested in constructor functions.
     850             :  */
     851             : #define NPY_ARRAY_ELEMENTSTRIDES  0x0080
     852             : 
     853             : /*
     854             :  * Array data is aligned on the appropriate memory address for the type
     855             :  * stored according to how the compiler would align things (e.g., an
     856             :  * array of integers (4 bytes each) starts on a memory address that's
     857             :  * a multiple of 4)
     858             :  *
     859             :  * This flag may be requested in constructor functions.
     860             :  * This flag may be tested for in PyArray_FLAGS(arr).
     861             :  */
     862             : #define NPY_ARRAY_ALIGNED         0x0100
     863             : 
     864             : /*
     865             :  * Array data has the native endianness
     866             :  *
     867             :  * This flag may be requested in constructor functions.
     868             :  */
     869             : #define NPY_ARRAY_NOTSWAPPED      0x0200
     870             : 
     871             : /*
     872             :  * Array data is writeable
     873             :  *
     874             :  * This flag may be requested in constructor functions.
     875             :  * This flag may be tested for in PyArray_FLAGS(arr).
     876             :  */
     877             : #define NPY_ARRAY_WRITEABLE       0x0400
     878             : 
     879             : /*
     880             :  * If this flag is set, then base contains a pointer to an array of
     881             :  * the same size that should be updated with the current contents of
     882             :  * this array when PyArray_ResolveWritebackIfCopy is called.
     883             :  *
     884             :  * This flag may be requested in constructor functions.
     885             :  * This flag may be tested for in PyArray_FLAGS(arr).
     886             :  */
     887             : #define NPY_ARRAY_UPDATEIFCOPY    0x1000 /* Deprecated in 1.14 */
     888             : #define NPY_ARRAY_WRITEBACKIFCOPY 0x2000
     889             : 
     890             : /*
     891             :  * NOTE: there are also internal flags defined in multiarray/arrayobject.h,
     892             :  * which start at bit 31 and work down.
     893             :  */
     894             : 
     895             : #define NPY_ARRAY_BEHAVED      (NPY_ARRAY_ALIGNED | \
     896             :                                 NPY_ARRAY_WRITEABLE)
     897             : #define NPY_ARRAY_BEHAVED_NS   (NPY_ARRAY_ALIGNED | \
     898             :                                 NPY_ARRAY_WRITEABLE | \
     899             :                                 NPY_ARRAY_NOTSWAPPED)
     900             : #define NPY_ARRAY_CARRAY       (NPY_ARRAY_C_CONTIGUOUS | \
     901             :                                 NPY_ARRAY_BEHAVED)
     902             : #define NPY_ARRAY_CARRAY_RO    (NPY_ARRAY_C_CONTIGUOUS | \
     903             :                                 NPY_ARRAY_ALIGNED)
     904             : #define NPY_ARRAY_FARRAY       (NPY_ARRAY_F_CONTIGUOUS | \
     905             :                                 NPY_ARRAY_BEHAVED)
     906             : #define NPY_ARRAY_FARRAY_RO    (NPY_ARRAY_F_CONTIGUOUS | \
     907             :                                 NPY_ARRAY_ALIGNED)
     908             : #define NPY_ARRAY_DEFAULT      (NPY_ARRAY_CARRAY)
     909             : #define NPY_ARRAY_IN_ARRAY     (NPY_ARRAY_CARRAY_RO)
     910             : #define NPY_ARRAY_OUT_ARRAY    (NPY_ARRAY_CARRAY)
     911             : #define NPY_ARRAY_INOUT_ARRAY  (NPY_ARRAY_CARRAY | \
     912             :                                 NPY_ARRAY_UPDATEIFCOPY)
     913             : #define NPY_ARRAY_INOUT_ARRAY2 (NPY_ARRAY_CARRAY | \
     914             :                                 NPY_ARRAY_WRITEBACKIFCOPY)
     915             : #define NPY_ARRAY_IN_FARRAY    (NPY_ARRAY_FARRAY_RO)
     916             : #define NPY_ARRAY_OUT_FARRAY   (NPY_ARRAY_FARRAY)
     917             : #define NPY_ARRAY_INOUT_FARRAY (NPY_ARRAY_FARRAY | \
     918             :                                 NPY_ARRAY_UPDATEIFCOPY)
     919             : #define NPY_ARRAY_INOUT_FARRAY2 (NPY_ARRAY_FARRAY | \
     920             :                                 NPY_ARRAY_WRITEBACKIFCOPY)
     921             : 
     922             : #define NPY_ARRAY_UPDATE_ALL   (NPY_ARRAY_C_CONTIGUOUS | \
     923             :                                 NPY_ARRAY_F_CONTIGUOUS | \
     924             :                                 NPY_ARRAY_ALIGNED)
     925             : 
     926             : /* This flag is for the array interface, not PyArrayObject */
     927             : #define NPY_ARR_HAS_DESCR  0x0800
     928             : 
     929             : 
     930             : 
     931             : 
     932             : /*
     933             :  * Size of internal buffers used for alignment Make BUFSIZE a multiple
     934             :  * of sizeof(npy_cdouble) -- usually 16 so that ufunc buffers are aligned
     935             :  */
     936             : #define NPY_MIN_BUFSIZE ((int)sizeof(npy_cdouble))
     937             : #define NPY_MAX_BUFSIZE (((int)sizeof(npy_cdouble))*1000000)
     938             : #define NPY_BUFSIZE 8192
     939             : /* buffer stress test size: */
     940             : /*#define NPY_BUFSIZE 17*/
     941             : 
     942             : #define PyArray_MAX(a,b) (((a)>(b))?(a):(b))
     943             : #define PyArray_MIN(a,b) (((a)<(b))?(a):(b))
     944             : #define PyArray_CLT(p,q) ((((p).real==(q).real) ? ((p).imag < (q).imag) : \
     945             :                                ((p).real < (q).real)))
     946             : #define PyArray_CGT(p,q) ((((p).real==(q).real) ? ((p).imag > (q).imag) : \
     947             :                                ((p).real > (q).real)))
     948             : #define PyArray_CLE(p,q) ((((p).real==(q).real) ? ((p).imag <= (q).imag) : \
     949             :                                ((p).real <= (q).real)))
     950             : #define PyArray_CGE(p,q) ((((p).real==(q).real) ? ((p).imag >= (q).imag) : \
     951             :                                ((p).real >= (q).real)))
     952             : #define PyArray_CEQ(p,q) (((p).real==(q).real) && ((p).imag == (q).imag))
     953             : #define PyArray_CNE(p,q) (((p).real!=(q).real) || ((p).imag != (q).imag))
     954             : 
     955             : /*
     956             :  * C API: consists of Macros and functions.  The MACROS are defined
     957             :  * here.
     958             :  */
     959             : 
     960             : 
     961             : #define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_C_CONTIGUOUS)
     962             : #define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS((m), NPY_ARRAY_WRITEABLE)
     963             : #define PyArray_ISALIGNED(m) PyArray_CHKFLAGS((m), NPY_ARRAY_ALIGNED)
     964             : 
     965             : #define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_C_CONTIGUOUS)
     966             : #define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_F_CONTIGUOUS)
     967             : 
     968             : /* the variable is used in some places, so always define it */
     969             : #define NPY_BEGIN_THREADS_DEF PyThreadState *_save=NULL;
     970             : #if NPY_ALLOW_THREADS
     971             : #define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
     972             : #define NPY_END_ALLOW_THREADS Py_END_ALLOW_THREADS
     973             : #define NPY_BEGIN_THREADS do {_save = PyEval_SaveThread();} while (0);
     974             : #define NPY_END_THREADS   do { if (_save) \
     975             :                 { PyEval_RestoreThread(_save); _save = NULL;} } while (0);
     976             : #define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) do { if ((loop_size) > 500) \
     977             :                 { _save = PyEval_SaveThread();} } while (0);
     978             : 
     979             : #define NPY_BEGIN_THREADS_DESCR(dtype) \
     980             :         do {if (!(PyDataType_FLAGCHK((dtype), NPY_NEEDS_PYAPI))) \
     981             :                 NPY_BEGIN_THREADS;} while (0);
     982             : 
     983             : #define NPY_END_THREADS_DESCR(dtype) \
     984             :         do {if (!(PyDataType_FLAGCHK((dtype), NPY_NEEDS_PYAPI))) \
     985             :                 NPY_END_THREADS; } while (0);
     986             : 
     987             : #define NPY_ALLOW_C_API_DEF  PyGILState_STATE __save__;
     988             : #define NPY_ALLOW_C_API      do {__save__ = PyGILState_Ensure();} while (0);
     989             : #define NPY_DISABLE_C_API    do {PyGILState_Release(__save__);} while (0);
     990             : #else
     991             : #define NPY_BEGIN_ALLOW_THREADS
     992             : #define NPY_END_ALLOW_THREADS
     993             : #define NPY_BEGIN_THREADS
     994             : #define NPY_END_THREADS
     995             : #define NPY_BEGIN_THREADS_THRESHOLDED(loop_size)
     996             : #define NPY_BEGIN_THREADS_DESCR(dtype)
     997             : #define NPY_END_THREADS_DESCR(dtype)
     998             : #define NPY_ALLOW_C_API_DEF
     999             : #define NPY_ALLOW_C_API
    1000             : #define NPY_DISABLE_C_API
    1001             : #endif
    1002             : 
    1003             : /**********************************
    1004             :  * The nditer object, added in 1.6
    1005             :  **********************************/
    1006             : 
    1007             : /* The actual structure of the iterator is an internal detail */
    1008             : typedef struct NpyIter_InternalOnly NpyIter;
    1009             : 
    1010             : /* Iterator function pointers that may be specialized */
    1011             : typedef int (NpyIter_IterNextFunc)(NpyIter *iter);
    1012             : typedef void (NpyIter_GetMultiIndexFunc)(NpyIter *iter,
    1013             :                                       npy_intp *outcoords);
    1014             : 
    1015             : /*** Global flags that may be passed to the iterator constructors ***/
    1016             : 
    1017             : /* Track an index representing C order */
    1018             : #define NPY_ITER_C_INDEX                    0x00000001
    1019             : /* Track an index representing Fortran order */
    1020             : #define NPY_ITER_F_INDEX                    0x00000002
    1021             : /* Track a multi-index */
    1022             : #define NPY_ITER_MULTI_INDEX                0x00000004
    1023             : /* User code external to the iterator does the 1-dimensional innermost loop */
    1024             : #define NPY_ITER_EXTERNAL_LOOP              0x00000008
    1025             : /* Convert all the operands to a common data type */
    1026             : #define NPY_ITER_COMMON_DTYPE               0x00000010
    1027             : /* Operands may hold references, requiring API access during iteration */
    1028             : #define NPY_ITER_REFS_OK                    0x00000020
    1029             : /* Zero-sized operands should be permitted, iteration checks IterSize for 0 */
    1030             : #define NPY_ITER_ZEROSIZE_OK                0x00000040
    1031             : /* Permits reductions (size-0 stride with dimension size > 1) */
    1032             : #define NPY_ITER_REDUCE_OK                  0x00000080
    1033             : /* Enables sub-range iteration */
    1034             : #define NPY_ITER_RANGED                     0x00000100
    1035             : /* Enables buffering */
    1036             : #define NPY_ITER_BUFFERED                   0x00000200
    1037             : /* When buffering is enabled, grows the inner loop if possible */
    1038             : #define NPY_ITER_GROWINNER                  0x00000400
    1039             : /* Delay allocation of buffers until first Reset* call */
    1040             : #define NPY_ITER_DELAY_BUFALLOC             0x00000800
    1041             : /* When NPY_KEEPORDER is specified, disable reversing negative-stride axes */
    1042             : #define NPY_ITER_DONT_NEGATE_STRIDES        0x00001000
    1043             : /*
    1044             :  * If output operands overlap with other operands (based on heuristics that
    1045             :  * has false positives but no false negatives), make temporary copies to
    1046             :  * eliminate overlap.
    1047             :  */
    1048             : #define NPY_ITER_COPY_IF_OVERLAP            0x00002000
    1049             : 
    1050             : /*** Per-operand flags that may be passed to the iterator constructors ***/
    1051             : 
    1052             : /* The operand will be read from and written to */
    1053             : #define NPY_ITER_READWRITE                  0x00010000
    1054             : /* The operand will only be read from */
    1055             : #define NPY_ITER_READONLY                   0x00020000
    1056             : /* The operand will only be written to */
    1057             : #define NPY_ITER_WRITEONLY                  0x00040000
    1058             : /* The operand's data must be in native byte order */
    1059             : #define NPY_ITER_NBO                        0x00080000
    1060             : /* The operand's data must be aligned */
    1061             : #define NPY_ITER_ALIGNED                    0x00100000
    1062             : /* The operand's data must be contiguous (within the inner loop) */
    1063             : #define NPY_ITER_CONTIG                     0x00200000
    1064             : /* The operand may be copied to satisfy requirements */
    1065             : #define NPY_ITER_COPY                       0x00400000
    1066             : /* The operand may be copied with WRITEBACKIFCOPY to satisfy requirements */
    1067             : #define NPY_ITER_UPDATEIFCOPY               0x00800000
    1068             : /* Allocate the operand if it is NULL */
    1069             : #define NPY_ITER_ALLOCATE                   0x01000000
    1070             : /* If an operand is allocated, don't use any subtype */
    1071             : #define NPY_ITER_NO_SUBTYPE                 0x02000000
    1072             : /* This is a virtual array slot, operand is NULL but temporary data is there */
    1073             : #define NPY_ITER_VIRTUAL                    0x04000000
    1074             : /* Require that the dimension match the iterator dimensions exactly */
    1075             : #define NPY_ITER_NO_BROADCAST               0x08000000
    1076             : /* A mask is being used on this array, affects buffer -> array copy */
    1077             : #define NPY_ITER_WRITEMASKED                0x10000000
    1078             : /* This array is the mask for all WRITEMASKED operands */
    1079             : #define NPY_ITER_ARRAYMASK                  0x20000000
    1080             : /* Assume iterator order data access for COPY_IF_OVERLAP */
    1081             : #define NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE 0x40000000
    1082             : 
    1083             : #define NPY_ITER_GLOBAL_FLAGS               0x0000ffff
    1084             : #define NPY_ITER_PER_OP_FLAGS               0xffff0000
    1085             : 
    1086             : 
    1087             : /*****************************
    1088             :  * Basic iterator object
    1089             :  *****************************/
    1090             : 
    1091             : /* FWD declaration */
    1092             : typedef struct PyArrayIterObject_tag PyArrayIterObject;
    1093             : 
    1094             : /*
    1095             :  * type of the function which translates a set of coordinates to a
    1096             :  * pointer to the data
    1097             :  */
    1098             : typedef char* (*npy_iter_get_dataptr_t)(
    1099             :         PyArrayIterObject* iter, const npy_intp*);
    1100             : 
    1101             : struct PyArrayIterObject_tag {
    1102             :         PyObject_HEAD
    1103             :         int               nd_m1;            /* number of dimensions - 1 */
    1104             :         npy_intp          index, size;
    1105             :         npy_intp          coordinates[NPY_MAXDIMS];/* N-dimensional loop */
    1106             :         npy_intp          dims_m1[NPY_MAXDIMS];    /* ao->dimensions - 1 */
    1107             :         npy_intp          strides[NPY_MAXDIMS];    /* ao->strides or fake */
    1108             :         npy_intp          backstrides[NPY_MAXDIMS];/* how far to jump back */
    1109             :         npy_intp          factors[NPY_MAXDIMS];     /* shape factors */
    1110             :         PyArrayObject     *ao;
    1111             :         char              *dataptr;        /* pointer to current item*/
    1112             :         npy_bool          contiguous;
    1113             : 
    1114             :         npy_intp          bounds[NPY_MAXDIMS][2];
    1115             :         npy_intp          limits[NPY_MAXDIMS][2];
    1116             :         npy_intp          limits_sizes[NPY_MAXDIMS];
    1117             :         npy_iter_get_dataptr_t translate;
    1118             : } ;
    1119             : 
    1120             : 
    1121             : /* Iterator API */
    1122             : #define PyArrayIter_Check(op) PyObject_TypeCheck((op), &PyArrayIter_Type)
    1123             : 
    1124             : #define _PyAIT(it) ((PyArrayIterObject *)(it))
    1125             : #define PyArray_ITER_RESET(it) do { \
    1126             :         _PyAIT(it)->index = 0; \
    1127             :         _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
    1128             :         memset(_PyAIT(it)->coordinates, 0, \
    1129             :                (_PyAIT(it)->nd_m1+1)*sizeof(npy_intp)); \
    1130             : } while (0)
    1131             : 
    1132             : #define _PyArray_ITER_NEXT1(it) do { \
    1133             :         (it)->dataptr += _PyAIT(it)->strides[0]; \
    1134             :         (it)->coordinates[0]++; \
    1135             : } while (0)
    1136             : 
    1137             : #define _PyArray_ITER_NEXT2(it) do { \
    1138             :         if ((it)->coordinates[1] < (it)->dims_m1[1]) { \
    1139             :                 (it)->coordinates[1]++; \
    1140             :                 (it)->dataptr += (it)->strides[1]; \
    1141             :         } \
    1142             :         else { \
    1143             :                 (it)->coordinates[1] = 0; \
    1144             :                 (it)->coordinates[0]++; \
    1145             :                 (it)->dataptr += (it)->strides[0] - \
    1146             :                         (it)->backstrides[1]; \
    1147             :         } \
    1148             : } while (0)
    1149             : 
    1150             : #define PyArray_ITER_NEXT(it) do { \
    1151             :         _PyAIT(it)->index++; \
    1152             :         if (_PyAIT(it)->nd_m1 == 0) { \
    1153             :                 _PyArray_ITER_NEXT1(_PyAIT(it)); \
    1154             :         } \
    1155             :         else if (_PyAIT(it)->contiguous) \
    1156             :                 _PyAIT(it)->dataptr += PyArray_DESCR(_PyAIT(it)->ao)->elsize; \
    1157             :         else if (_PyAIT(it)->nd_m1 == 1) { \
    1158             :                 _PyArray_ITER_NEXT2(_PyAIT(it)); \
    1159             :         } \
    1160             :         else { \
    1161             :                 int __npy_i; \
    1162             :                 for (__npy_i=_PyAIT(it)->nd_m1; __npy_i >= 0; __npy_i--) { \
    1163             :                         if (_PyAIT(it)->coordinates[__npy_i] < \
    1164             :                             _PyAIT(it)->dims_m1[__npy_i]) { \
    1165             :                                 _PyAIT(it)->coordinates[__npy_i]++; \
    1166             :                                 _PyAIT(it)->dataptr += \
    1167             :                                         _PyAIT(it)->strides[__npy_i]; \
    1168             :                                 break; \
    1169             :                         } \
    1170             :                         else { \
    1171             :                                 _PyAIT(it)->coordinates[__npy_i] = 0; \
    1172             :                                 _PyAIT(it)->dataptr -= \
    1173             :                                         _PyAIT(it)->backstrides[__npy_i]; \
    1174             :                         } \
    1175             :                 } \
    1176             :         } \
    1177             : } while (0)
    1178             : 
    1179             : #define PyArray_ITER_GOTO(it, destination) do { \
    1180             :         int __npy_i; \
    1181             :         _PyAIT(it)->index = 0; \
    1182             :         _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
    1183             :         for (__npy_i = _PyAIT(it)->nd_m1; __npy_i>=0; __npy_i--) { \
    1184             :                 if (destination[__npy_i] < 0) { \
    1185             :                         destination[__npy_i] += \
    1186             :                                 _PyAIT(it)->dims_m1[__npy_i]+1; \
    1187             :                 } \
    1188             :                 _PyAIT(it)->dataptr += destination[__npy_i] * \
    1189             :                         _PyAIT(it)->strides[__npy_i]; \
    1190             :                 _PyAIT(it)->coordinates[__npy_i] = \
    1191             :                         destination[__npy_i]; \
    1192             :                 _PyAIT(it)->index += destination[__npy_i] * \
    1193             :                         ( __npy_i==_PyAIT(it)->nd_m1 ? 1 : \
    1194             :                           _PyAIT(it)->dims_m1[__npy_i+1]+1) ; \
    1195             :         } \
    1196             : } while (0)
    1197             : 
    1198             : #define PyArray_ITER_GOTO1D(it, ind) do { \
    1199             :         int __npy_i; \
    1200             :         npy_intp __npy_ind = (npy_intp)(ind); \
    1201             :         if (__npy_ind < 0) __npy_ind += _PyAIT(it)->size; \
    1202             :         _PyAIT(it)->index = __npy_ind; \
    1203             :         if (_PyAIT(it)->nd_m1 == 0) { \
    1204             :                 _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \
    1205             :                         __npy_ind * _PyAIT(it)->strides[0]; \
    1206             :         } \
    1207             :         else if (_PyAIT(it)->contiguous) \
    1208             :                 _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \
    1209             :                         __npy_ind * PyArray_DESCR(_PyAIT(it)->ao)->elsize; \
    1210             :         else { \
    1211             :                 _PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
    1212             :                 for (__npy_i = 0; __npy_i<=_PyAIT(it)->nd_m1; \
    1213             :                      __npy_i++) { \
    1214             :                         _PyAIT(it)->dataptr += \
    1215             :                                 (__npy_ind / _PyAIT(it)->factors[__npy_i]) \
    1216             :                                 * _PyAIT(it)->strides[__npy_i]; \
    1217             :                         __npy_ind %= _PyAIT(it)->factors[__npy_i]; \
    1218             :                 } \
    1219             :         } \
    1220             : } while (0)
    1221             : 
    1222             : #define PyArray_ITER_DATA(it) ((void *)(_PyAIT(it)->dataptr))
    1223             : 
    1224             : #define PyArray_ITER_NOTDONE(it) (_PyAIT(it)->index < _PyAIT(it)->size)
    1225             : 
    1226             : 
    1227             : /*
    1228             :  * Any object passed to PyArray_Broadcast must be binary compatible
    1229             :  * with this structure.
    1230             :  */
    1231             : 
    1232             : typedef struct {
    1233             :         PyObject_HEAD
    1234             :         int                  numiter;                 /* number of iters */
    1235             :         npy_intp             size;                    /* broadcasted size */
    1236             :         npy_intp             index;                   /* current index */
    1237             :         int                  nd;                      /* number of dims */
    1238             :         npy_intp             dimensions[NPY_MAXDIMS]; /* dimensions */
    1239             :         PyArrayIterObject    *iters[NPY_MAXARGS];     /* iterators */
    1240             : } PyArrayMultiIterObject;
    1241             : 
    1242             : #define _PyMIT(m) ((PyArrayMultiIterObject *)(m))
    1243             : #define PyArray_MultiIter_RESET(multi) do {                                   \
    1244             :         int __npy_mi;                                                         \
    1245             :         _PyMIT(multi)->index = 0;                                             \
    1246             :         for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter;  __npy_mi++) {    \
    1247             :                 PyArray_ITER_RESET(_PyMIT(multi)->iters[__npy_mi]);           \
    1248             :         }                                                                     \
    1249             : } while (0)
    1250             : 
    1251             : #define PyArray_MultiIter_NEXT(multi) do {                                    \
    1252             :         int __npy_mi;                                                         \
    1253             :         _PyMIT(multi)->index++;                                               \
    1254             :         for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter;   __npy_mi++) {   \
    1255             :                 PyArray_ITER_NEXT(_PyMIT(multi)->iters[__npy_mi]);            \
    1256             :         }                                                                     \
    1257             : } while (0)
    1258             : 
    1259             : #define PyArray_MultiIter_GOTO(multi, dest) do {                            \
    1260             :         int __npy_mi;                                                       \
    1261             :         for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) {   \
    1262             :                 PyArray_ITER_GOTO(_PyMIT(multi)->iters[__npy_mi], dest);    \
    1263             :         }                                                                   \
    1264             :         _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index;              \
    1265             : } while (0)
    1266             : 
    1267             : #define PyArray_MultiIter_GOTO1D(multi, ind) do {                          \
    1268             :         int __npy_mi;                                                      \
    1269             :         for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) {  \
    1270             :                 PyArray_ITER_GOTO1D(_PyMIT(multi)->iters[__npy_mi], ind);  \
    1271             :         }                                                                  \
    1272             :         _PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index;             \
    1273             : } while (0)
    1274             : 
    1275             : #define PyArray_MultiIter_DATA(multi, i)                \
    1276             :         ((void *)(_PyMIT(multi)->iters[i]->dataptr))
    1277             : 
    1278             : #define PyArray_MultiIter_NEXTi(multi, i)               \
    1279             :         PyArray_ITER_NEXT(_PyMIT(multi)->iters[i])
    1280             : 
    1281             : #define PyArray_MultiIter_NOTDONE(multi)                \
    1282             :         (_PyMIT(multi)->index < _PyMIT(multi)->size)
    1283             : 
    1284             : 
    1285             : /*
    1286             :  * Store the information needed for fancy-indexing over an array. The
    1287             :  * fields are slightly unordered to keep consec, dataptr and subspace
    1288             :  * where they were originally.
    1289             :  */
    1290             : typedef struct {
    1291             :         PyObject_HEAD
    1292             :         /*
    1293             :          * Multi-iterator portion --- needs to be present in this
    1294             :          * order to work with PyArray_Broadcast
    1295             :          */
    1296             : 
    1297             :         int                   numiter;                 /* number of index-array
    1298             :                                                           iterators */
    1299             :         npy_intp              size;                    /* size of broadcasted
    1300             :                                                           result */
    1301             :         npy_intp              index;                   /* current index */
    1302             :         int                   nd;                      /* number of dims */
    1303             :         npy_intp              dimensions[NPY_MAXDIMS]; /* dimensions */
    1304             :         NpyIter               *outer;                  /* index objects
    1305             :                                                           iterator */
    1306             :         void                  *unused[NPY_MAXDIMS - 2];
    1307             :         PyArrayObject         *array;
    1308             :         /* Flat iterator for the indexed array. For compatibility solely. */
    1309             :         PyArrayIterObject     *ait;
    1310             : 
    1311             :         /*
    1312             :          * Subspace array. For binary compatibility (was an iterator,
    1313             :          * but only the check for NULL should be used).
    1314             :          */
    1315             :         PyArrayObject         *subspace;
    1316             : 
    1317             :         /*
    1318             :          * if subspace iteration, then this is the array of axes in
    1319             :          * the underlying array represented by the index objects
    1320             :          */
    1321             :         int                   iteraxes[NPY_MAXDIMS];
    1322             :         npy_intp              fancy_strides[NPY_MAXDIMS];
    1323             : 
    1324             :         /* pointer when all fancy indices are 0 */
    1325             :         char                  *baseoffset;
    1326             : 
    1327             :         /*
    1328             :          * after binding consec denotes at which axis the fancy axes
    1329             :          * are inserted.
    1330             :          */
    1331             :         int                   consec;
    1332             :         char                  *dataptr;
    1333             : 
    1334             :         int                   nd_fancy;
    1335             :         npy_intp              fancy_dims[NPY_MAXDIMS];
    1336             : 
    1337             :         /* Whether the iterator (any of the iterators) requires API */
    1338             :         int                   needs_api;
    1339             : 
    1340             :         /*
    1341             :          * Extra op information.
    1342             :          */
    1343             :         PyArrayObject         *extra_op;
    1344             :         PyArray_Descr         *extra_op_dtype;         /* desired dtype */
    1345             :         npy_uint32            *extra_op_flags;         /* Iterator flags */
    1346             : 
    1347             :         NpyIter               *extra_op_iter;
    1348             :         NpyIter_IterNextFunc  *extra_op_next;
    1349             :         char                  **extra_op_ptrs;
    1350             : 
    1351             :         /*
    1352             :          * Information about the iteration state.
    1353             :          */
    1354             :         NpyIter_IterNextFunc  *outer_next;
    1355             :         char                  **outer_ptrs;
    1356             :         npy_intp              *outer_strides;
    1357             : 
    1358             :         /*
    1359             :          * Information about the subspace iterator.
    1360             :          */
    1361             :         NpyIter               *subspace_iter;
    1362             :         NpyIter_IterNextFunc  *subspace_next;
    1363             :         char                  **subspace_ptrs;
    1364             :         npy_intp              *subspace_strides;
    1365             : 
    1366             :         /* Count for the external loop (which ever it is) for API iteration */
    1367             :         npy_intp              iter_count;
    1368             : 
    1369             : } PyArrayMapIterObject;
    1370             : 
    1371             : enum {
    1372             :     NPY_NEIGHBORHOOD_ITER_ZERO_PADDING,
    1373             :     NPY_NEIGHBORHOOD_ITER_ONE_PADDING,
    1374             :     NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING,
    1375             :     NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING,
    1376             :     NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING
    1377             : };
    1378             : 
    1379             : typedef struct {
    1380             :     PyObject_HEAD
    1381             : 
    1382             :     /*
    1383             :      * PyArrayIterObject part: keep this in this exact order
    1384             :      */
    1385             :     int               nd_m1;            /* number of dimensions - 1 */
    1386             :     npy_intp          index, size;
    1387             :     npy_intp          coordinates[NPY_MAXDIMS];/* N-dimensional loop */
    1388             :     npy_intp          dims_m1[NPY_MAXDIMS];    /* ao->dimensions - 1 */
    1389             :     npy_intp          strides[NPY_MAXDIMS];    /* ao->strides or fake */
    1390             :     npy_intp          backstrides[NPY_MAXDIMS];/* how far to jump back */
    1391             :     npy_intp          factors[NPY_MAXDIMS];     /* shape factors */
    1392             :     PyArrayObject     *ao;
    1393             :     char              *dataptr;        /* pointer to current item*/
    1394             :     npy_bool          contiguous;
    1395             : 
    1396             :     npy_intp          bounds[NPY_MAXDIMS][2];
    1397             :     npy_intp          limits[NPY_MAXDIMS][2];
    1398             :     npy_intp          limits_sizes[NPY_MAXDIMS];
    1399             :     npy_iter_get_dataptr_t translate;
    1400             : 
    1401             :     /*
    1402             :      * New members
    1403             :      */
    1404             :     npy_intp nd;
    1405             : 
    1406             :     /* Dimensions is the dimension of the array */
    1407             :     npy_intp dimensions[NPY_MAXDIMS];
    1408             : 
    1409             :     /*
    1410             :      * Neighborhood points coordinates are computed relatively to the
    1411             :      * point pointed by _internal_iter
    1412             :      */
    1413             :     PyArrayIterObject* _internal_iter;
    1414             :     /*
    1415             :      * To keep a reference to the representation of the constant value
    1416             :      * for constant padding
    1417             :      */
    1418             :     char* constant;
    1419             : 
    1420             :     int mode;
    1421             : } PyArrayNeighborhoodIterObject;
    1422             : 
    1423             : /*
    1424             :  * Neighborhood iterator API
    1425             :  */
    1426             : 
    1427             : /* General: those work for any mode */
    1428             : static NPY_INLINE int
    1429             : PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter);
    1430             : static NPY_INLINE int
    1431             : PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter);
    1432             : #if 0
    1433             : static NPY_INLINE int
    1434             : PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
    1435             : #endif
    1436             : 
    1437             : /*
    1438             :  * Include inline implementations - functions defined there are not
    1439             :  * considered public API
    1440             :  */
    1441             : #define _NPY_INCLUDE_NEIGHBORHOOD_IMP
    1442             : #include "_neighborhood_iterator_imp.h"
    1443             : #undef _NPY_INCLUDE_NEIGHBORHOOD_IMP
    1444             : 
    1445             : /* The default array type */
    1446             : #define NPY_DEFAULT_TYPE NPY_DOUBLE
    1447             : 
    1448             : /*
    1449             :  * All sorts of useful ways to look into a PyArrayObject. It is recommended
    1450             :  * to use PyArrayObject * objects instead of always casting from PyObject *,
    1451             :  * for improved type checking.
    1452             :  *
    1453             :  * In many cases here the macro versions of the accessors are deprecated,
    1454             :  * but can't be immediately changed to inline functions because the
    1455             :  * preexisting macros accept PyObject * and do automatic casts. Inline
    1456             :  * functions accepting PyArrayObject * provides for some compile-time
    1457             :  * checking of correctness when working with these objects in C.
    1458             :  */
    1459             : 
    1460             : #define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || \
    1461             :                              PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS) || \
    1462             :                              PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS))
    1463             : 
    1464             : #define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) && \
    1465             :                              (!PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS)))
    1466             : 
    1467             : #define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) ? \
    1468             :                                NPY_ARRAY_F_CONTIGUOUS : 0))
    1469             : 
    1470             : #if (defined(NPY_NO_DEPRECATED_API) && (NPY_1_7_API_VERSION <= NPY_NO_DEPRECATED_API))
    1471             : /*
    1472             :  * Changing access macros into functions, to allow for future hiding
    1473             :  * of the internal memory layout. This later hiding will allow the 2.x series
    1474             :  * to change the internal representation of arrays without affecting
    1475             :  * ABI compatibility.
    1476             :  */
    1477             : 
    1478             : static NPY_INLINE int
    1479             : PyArray_NDIM(const PyArrayObject *arr)
    1480             : {
    1481         261 :     return ((PyArrayObject_fields *)arr)->nd;
    1482             : }
    1483             : 
    1484             : static NPY_INLINE void *
    1485             : PyArray_DATA(PyArrayObject *arr)
    1486             : {
    1487         541 :     return ((PyArrayObject_fields *)arr)->data;
    1488             : }
    1489             : 
    1490             : static NPY_INLINE char *
    1491             : PyArray_BYTES(PyArrayObject *arr)
    1492             : {
    1493           0 :     return ((PyArrayObject_fields *)arr)->data;
    1494             : }
    1495             : 
    1496             : static NPY_INLINE npy_intp *
    1497             : PyArray_DIMS(PyArrayObject *arr)
    1498             : {
    1499         247 :     return ((PyArrayObject_fields *)arr)->dimensions;
    1500             : }
    1501             : 
    1502             : static NPY_INLINE npy_intp *
    1503             : PyArray_STRIDES(PyArrayObject *arr)
    1504             : {
    1505           0 :     return ((PyArrayObject_fields *)arr)->strides;
    1506             : }
    1507             : 
    1508             : static NPY_INLINE npy_intp
    1509             : PyArray_DIM(const PyArrayObject *arr, int idim)
    1510             : {
    1511             :     return ((PyArrayObject_fields *)arr)->dimensions[idim];
    1512             : }
    1513             : 
    1514             : static NPY_INLINE npy_intp
    1515             : PyArray_STRIDE(const PyArrayObject *arr, int istride)
    1516             : {
    1517             :     return ((PyArrayObject_fields *)arr)->strides[istride];
    1518             : }
    1519             : 
    1520             : static NPY_INLINE NPY_RETURNS_BORROWED_REF PyObject *
    1521             : PyArray_BASE(PyArrayObject *arr)
    1522             : {
    1523             :     return ((PyArrayObject_fields *)arr)->base;
    1524             : }
    1525             : 
    1526             : static NPY_INLINE NPY_RETURNS_BORROWED_REF PyArray_Descr *
    1527             : PyArray_DESCR(PyArrayObject *arr)
    1528             : {
    1529         219 :     return ((PyArrayObject_fields *)arr)->descr;
    1530             : }
    1531             : 
    1532             : static NPY_INLINE int
    1533             : PyArray_FLAGS(const PyArrayObject *arr)
    1534             : {
    1535          44 :     return ((PyArrayObject_fields *)arr)->flags;
    1536             : }
    1537             : 
    1538             : static NPY_INLINE npy_intp
    1539             : PyArray_ITEMSIZE(const PyArrayObject *arr)
    1540             : {
    1541             :     return ((PyArrayObject_fields *)arr)->descr->elsize;
    1542             : }
    1543             : 
    1544             : static NPY_INLINE int
    1545             : PyArray_TYPE(const PyArrayObject *arr)
    1546             : {
    1547             :     return ((PyArrayObject_fields *)arr)->descr->type_num;
    1548             : }
    1549             : 
    1550             : static NPY_INLINE int
    1551             : PyArray_CHKFLAGS(const PyArrayObject *arr, int flags)
    1552             : {
    1553             :     return (PyArray_FLAGS(arr) & flags) == flags;
    1554             : }
    1555             : 
    1556             : static NPY_INLINE PyObject *
    1557             : PyArray_GETITEM(const PyArrayObject *arr, const char *itemptr)
    1558             : {
    1559          84 :     return ((PyArrayObject_fields *)arr)->descr->f->getitem(
    1560             :                                         (void *)itemptr, (PyArrayObject *)arr);
    1561             : }
    1562             : 
    1563             : static NPY_INLINE int
    1564             : PyArray_SETITEM(PyArrayObject *arr, char *itemptr, PyObject *v)
    1565             : {
    1566             :     return ((PyArrayObject_fields *)arr)->descr->f->setitem(
    1567             :                                                         v, itemptr, arr);
    1568             : }
    1569             : 
    1570             : #else
    1571             : 
    1572             : /* These macros are deprecated as of NumPy 1.7. */
    1573             : #define PyArray_NDIM(obj) (((PyArrayObject_fields *)(obj))->nd)
    1574             : #define PyArray_BYTES(obj) (((PyArrayObject_fields *)(obj))->data)
    1575             : #define PyArray_DATA(obj) ((void *)((PyArrayObject_fields *)(obj))->data)
    1576             : #define PyArray_DIMS(obj) (((PyArrayObject_fields *)(obj))->dimensions)
    1577             : #define PyArray_STRIDES(obj) (((PyArrayObject_fields *)(obj))->strides)
    1578             : #define PyArray_DIM(obj,n) (PyArray_DIMS(obj)[n])
    1579             : #define PyArray_STRIDE(obj,n) (PyArray_STRIDES(obj)[n])
    1580             : #define PyArray_BASE(obj) (((PyArrayObject_fields *)(obj))->base)
    1581             : #define PyArray_DESCR(obj) (((PyArrayObject_fields *)(obj))->descr)
    1582             : #define PyArray_FLAGS(obj) (((PyArrayObject_fields *)(obj))->flags)
    1583             : #define PyArray_CHKFLAGS(m, FLAGS) \
    1584             :         ((((PyArrayObject_fields *)(m))->flags & (FLAGS)) == (FLAGS))
    1585             : #define PyArray_ITEMSIZE(obj) \
    1586             :                     (((PyArrayObject_fields *)(obj))->descr->elsize)
    1587             : #define PyArray_TYPE(obj) \
    1588             :                     (((PyArrayObject_fields *)(obj))->descr->type_num)
    1589             : #define PyArray_GETITEM(obj,itemptr) \
    1590             :         PyArray_DESCR(obj)->f->getitem((char *)(itemptr), \
    1591             :                                      (PyArrayObject *)(obj))
    1592             : 
    1593             : #define PyArray_SETITEM(obj,itemptr,v) \
    1594             :         PyArray_DESCR(obj)->f->setitem((PyObject *)(v), \
    1595             :                                      (char *)(itemptr), \
    1596             :                                      (PyArrayObject *)(obj))
    1597             : #endif
    1598             : 
    1599             : static NPY_INLINE PyArray_Descr *
    1600             : PyArray_DTYPE(PyArrayObject *arr)
    1601             : {
    1602             :     return ((PyArrayObject_fields *)arr)->descr;
    1603             : }
    1604             : 
    1605             : static NPY_INLINE npy_intp *
    1606             : PyArray_SHAPE(PyArrayObject *arr)
    1607             : {
    1608             :     return ((PyArrayObject_fields *)arr)->dimensions;
    1609             : }
    1610             : 
    1611             : /*
    1612             :  * Enables the specified array flags. Does no checking,
    1613             :  * assumes you know what you're doing.
    1614             :  */
    1615             : static NPY_INLINE void
    1616             : PyArray_ENABLEFLAGS(PyArrayObject *arr, int flags)
    1617             : {
    1618             :     ((PyArrayObject_fields *)arr)->flags |= flags;
    1619             : }
    1620             : 
    1621             : /*
    1622             :  * Clears the specified array flags. Does no checking,
    1623             :  * assumes you know what you're doing.
    1624             :  */
    1625             : static NPY_INLINE void
    1626             : PyArray_CLEARFLAGS(PyArrayObject *arr, int flags)
    1627             : {
    1628          36 :     ((PyArrayObject_fields *)arr)->flags &= ~flags;
    1629          36 : }
    1630             : 
    1631             : #define PyTypeNum_ISBOOL(type) ((type) == NPY_BOOL)
    1632             : 
    1633             : #define PyTypeNum_ISUNSIGNED(type) (((type) == NPY_UBYTE) ||   \
    1634             :                                  ((type) == NPY_USHORT) ||     \
    1635             :                                  ((type) == NPY_UINT) ||       \
    1636             :                                  ((type) == NPY_ULONG) ||      \
    1637             :                                  ((type) == NPY_ULONGLONG))
    1638             : 
    1639             : #define PyTypeNum_ISSIGNED(type) (((type) == NPY_BYTE) ||      \
    1640             :                                ((type) == NPY_SHORT) ||        \
    1641             :                                ((type) == NPY_INT) ||          \
    1642             :                                ((type) == NPY_LONG) ||         \
    1643             :                                ((type) == NPY_LONGLONG))
    1644             : 
    1645             : #define PyTypeNum_ISINTEGER(type) (((type) >= NPY_BYTE) &&     \
    1646             :                                 ((type) <= NPY_ULONGLONG))
    1647             : 
    1648             : #define PyTypeNum_ISFLOAT(type) ((((type) >= NPY_FLOAT) && \
    1649             :                               ((type) <= NPY_LONGDOUBLE)) || \
    1650             :                               ((type) == NPY_HALF))
    1651             : 
    1652             : #define PyTypeNum_ISNUMBER(type) (((type) <= NPY_CLONGDOUBLE) || \
    1653             :                                   ((type) == NPY_HALF))
    1654             : 
    1655             : #define PyTypeNum_ISSTRING(type) (((type) == NPY_STRING) ||    \
    1656             :                                   ((type) == NPY_UNICODE))
    1657             : 
    1658             : #define PyTypeNum_ISCOMPLEX(type) (((type) >= NPY_CFLOAT) &&   \
    1659             :                                 ((type) <= NPY_CLONGDOUBLE))
    1660             : 
    1661             : #define PyTypeNum_ISPYTHON(type) (((type) == NPY_LONG) ||      \
    1662             :                                   ((type) == NPY_DOUBLE) ||    \
    1663             :                                   ((type) == NPY_CDOUBLE) ||   \
    1664             :                                   ((type) == NPY_BOOL) ||      \
    1665             :                                   ((type) == NPY_OBJECT ))
    1666             : 
    1667             : #define PyTypeNum_ISFLEXIBLE(type) (((type) >=NPY_STRING) &&  \
    1668             :                                     ((type) <=NPY_VOID))
    1669             : 
    1670             : #define PyTypeNum_ISDATETIME(type) (((type) >=NPY_DATETIME) &&  \
    1671             :                                     ((type) <=NPY_TIMEDELTA))
    1672             : 
    1673             : #define PyTypeNum_ISUSERDEF(type) (((type) >= NPY_USERDEF) && \
    1674             :                                    ((type) < NPY_USERDEF+     \
    1675             :                                     NPY_NUMUSERTYPES))
    1676             : 
    1677             : #define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) ||  \
    1678             :                                     PyTypeNum_ISUSERDEF(type))
    1679             : 
    1680             : #define PyTypeNum_ISOBJECT(type) ((type) == NPY_OBJECT)
    1681             : 
    1682             : 
    1683             : #define PyDataType_ISBOOL(obj) PyTypeNum_ISBOOL(((PyArray_Descr*)(obj))->type_num)
    1684             : #define PyDataType_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(((PyArray_Descr*)(obj))->type_num)
    1685             : #define PyDataType_ISSIGNED(obj) PyTypeNum_ISSIGNED(((PyArray_Descr*)(obj))->type_num)
    1686             : #define PyDataType_ISINTEGER(obj) PyTypeNum_ISINTEGER(((PyArray_Descr*)(obj))->type_num )
    1687             : #define PyDataType_ISFLOAT(obj) PyTypeNum_ISFLOAT(((PyArray_Descr*)(obj))->type_num)
    1688             : #define PyDataType_ISNUMBER(obj) PyTypeNum_ISNUMBER(((PyArray_Descr*)(obj))->type_num)
    1689             : #define PyDataType_ISSTRING(obj) PyTypeNum_ISSTRING(((PyArray_Descr*)(obj))->type_num)
    1690             : #define PyDataType_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(((PyArray_Descr*)(obj))->type_num)
    1691             : #define PyDataType_ISPYTHON(obj) PyTypeNum_ISPYTHON(((PyArray_Descr*)(obj))->type_num)
    1692             : #define PyDataType_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(((PyArray_Descr*)(obj))->type_num)
    1693             : #define PyDataType_ISDATETIME(obj) PyTypeNum_ISDATETIME(((PyArray_Descr*)(obj))->type_num)
    1694             : #define PyDataType_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(((PyArray_Descr*)(obj))->type_num)
    1695             : #define PyDataType_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(((PyArray_Descr*)(obj))->type_num)
    1696             : #define PyDataType_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)(obj))->type_num)
    1697             : #define PyDataType_HASFIELDS(obj) (((PyArray_Descr *)(obj))->names != NULL)
    1698             : #define PyDataType_HASSUBARRAY(dtype) ((dtype)->subarray != NULL)
    1699             : #define PyDataType_ISUNSIZED(dtype) ((dtype)->elsize == 0 && \
    1700             :                                       !PyDataType_HASFIELDS(dtype))
    1701             : #define PyDataType_MAKEUNSIZED(dtype) ((dtype)->elsize = 0)
    1702             : 
    1703             : #define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))
    1704             : #define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))
    1705             : #define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))
    1706             : #define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))
    1707             : #define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))
    1708             : #define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))
    1709             : #define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))
    1710             : #define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))
    1711             : #define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))
    1712             : #define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))
    1713             : #define PyArray_ISDATETIME(obj) PyTypeNum_ISDATETIME(PyArray_TYPE(obj))
    1714             : #define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))
    1715             : #define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))
    1716             : #define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))
    1717             : #define PyArray_HASFIELDS(obj) PyDataType_HASFIELDS(PyArray_DESCR(obj))
    1718             : 
    1719             :     /*
    1720             :      * FIXME: This should check for a flag on the data-type that
    1721             :      * states whether or not it is variable length.  Because the
    1722             :      * ISFLEXIBLE check is hard-coded to the built-in data-types.
    1723             :      */
    1724             : #define PyArray_ISVARIABLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))
    1725             : 
    1726             : #define PyArray_SAFEALIGNEDCOPY(obj) (PyArray_ISALIGNED(obj) && !PyArray_ISVARIABLE(obj))
    1727             : 
    1728             : 
    1729             : #define NPY_LITTLE '<'
    1730             : #define NPY_BIG '>'
    1731             : #define NPY_NATIVE '='
    1732             : #define NPY_SWAP 's'
    1733             : #define NPY_IGNORE '|'
    1734             : 
    1735             : #if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
    1736             : #define NPY_NATBYTE NPY_BIG
    1737             : #define NPY_OPPBYTE NPY_LITTLE
    1738             : #else
    1739             : #define NPY_NATBYTE NPY_LITTLE
    1740             : #define NPY_OPPBYTE NPY_BIG
    1741             : #endif
    1742             : 
    1743             : #define PyArray_ISNBO(arg) ((arg) != NPY_OPPBYTE)
    1744             : #define PyArray_IsNativeByteOrder PyArray_ISNBO
    1745             : #define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)
    1746             : #define PyArray_ISBYTESWAPPED(m) (!PyArray_ISNOTSWAPPED(m))
    1747             : 
    1748             : #define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&       \
    1749             :                                     PyArray_ISNOTSWAPPED(m))
    1750             : 
    1751             : #define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY)
    1752             : #define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY_RO)
    1753             : #define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY)
    1754             : #define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY_RO)
    1755             : #define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, NPY_ARRAY_BEHAVED)
    1756             : #define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_ALIGNED)
    1757             : 
    1758             : 
    1759             : #define PyDataType_ISNOTSWAPPED(d) PyArray_ISNBO(((PyArray_Descr *)(d))->byteorder)
    1760             : #define PyDataType_ISBYTESWAPPED(d) (!PyDataType_ISNOTSWAPPED(d))
    1761             : 
    1762             : /************************************************************
    1763             :  * A struct used by PyArray_CreateSortedStridePerm, new in 1.7.
    1764             :  ************************************************************/
    1765             : 
    1766             : typedef struct {
    1767             :     npy_intp perm, stride;
    1768             : } npy_stride_sort_item;
    1769             : 
    1770             : /************************************************************
    1771             :  * This is the form of the struct that's returned pointed by the
    1772             :  * PyCObject attribute of an array __array_struct__. See
    1773             :  * https://docs.scipy.org/doc/numpy/reference/arrays.interface.html for the full
    1774             :  * documentation.
    1775             :  ************************************************************/
    1776             : typedef struct {
    1777             :     int two;              /*
    1778             :                            * contains the integer 2 as a sanity
    1779             :                            * check
    1780             :                            */
    1781             : 
    1782             :     int nd;               /* number of dimensions */
    1783             : 
    1784             :     char typekind;        /*
    1785             :                            * kind in array --- character code of
    1786             :                            * typestr
    1787             :                            */
    1788             : 
    1789             :     int itemsize;         /* size of each element */
    1790             : 
    1791             :     int flags;            /*
    1792             :                            * how should be data interpreted. Valid
    1793             :                            * flags are CONTIGUOUS (1), F_CONTIGUOUS (2),
    1794             :                            * ALIGNED (0x100), NOTSWAPPED (0x200), and
    1795             :                            * WRITEABLE (0x400).  ARR_HAS_DESCR (0x800)
    1796             :                            * states that arrdescr field is present in
    1797             :                            * structure
    1798             :                            */
    1799             : 
    1800             :     npy_intp *shape;       /*
    1801             :                             * A length-nd array of shape
    1802             :                             * information
    1803             :                             */
    1804             : 
    1805             :     npy_intp *strides;    /* A length-nd array of stride information */
    1806             : 
    1807             :     void *data;           /* A pointer to the first element of the array */
    1808             : 
    1809             :     PyObject *descr;      /*
    1810             :                            * A list of fields or NULL (ignored if flags
    1811             :                            * does not have ARR_HAS_DESCR flag set)
    1812             :                            */
    1813             : } PyArrayInterface;
    1814             : 
    1815             : /*
    1816             :  * This is a function for hooking into the PyDataMem_NEW/FREE/RENEW functions.
    1817             :  * See the documentation for PyDataMem_SetEventHook.
    1818             :  */
    1819             : typedef void (PyDataMem_EventHookFunc)(void *inp, void *outp, size_t size,
    1820             :                                        void *user_data);
    1821             : 
    1822             : /*
    1823             :  * Use the keyword NPY_DEPRECATED_INCLUDES to ensure that the header files
    1824             :  * npy_*_*_deprecated_api.h are only included from here and nowhere else.
    1825             :  */
    1826             : #ifdef NPY_DEPRECATED_INCLUDES
    1827             : #error "Do not use the reserved keyword NPY_DEPRECATED_INCLUDES."
    1828             : #endif
    1829             : #define NPY_DEPRECATED_INCLUDES
    1830             : #if !defined(NPY_NO_DEPRECATED_API) || \
    1831             :     (NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
    1832             : #include "npy_1_7_deprecated_api.h"
    1833             : #endif
    1834             : /*
    1835             :  * There is no file npy_1_8_deprecated_api.h since there are no additional
    1836             :  * deprecated API features in NumPy 1.8.
    1837             :  *
    1838             :  * Note to maintainers: insert code like the following in future NumPy
    1839             :  * versions.
    1840             :  *
    1841             :  * #if !defined(NPY_NO_DEPRECATED_API) || \
    1842             :  *     (NPY_NO_DEPRECATED_API < NPY_1_9_API_VERSION)
    1843             :  * #include "npy_1_9_deprecated_api.h"
    1844             :  * #endif
    1845             :  */
    1846             : #undef NPY_DEPRECATED_INCLUDES
    1847             : 
    1848             : #endif /* NPY_ARRAYTYPES_H */

Generated by: LCOV version 1.14