/ lib / numpy / __init__.cython-30.pxd
__init__.cython-30.pxd
   1  # NumPy static imports for Cython >= 3.0
   2  #
   3  # If any of the PyArray_* functions are called, import_array must be
   4  # called first.  This is done automatically by Cython 3.0+ if a call
   5  # is not detected inside of the module.
   6  #
   7  # Author: Dag Sverre Seljebotn
   8  #
   9  
  10  from cpython.ref cimport Py_INCREF
  11  from cpython.object cimport PyObject, PyTypeObject, PyObject_TypeCheck
  12  cimport libc.stdio as stdio
  13  
  14  
  15  cdef extern from *:
  16      # Leave a marker that the NumPy declarations came from NumPy itself and not from Cython.
  17      # See https://github.com/cython/cython/issues/3573
  18      """
  19      /* Using NumPy API declarations from "numpy/__init__.cython-30.pxd" */
  20      """
  21  
  22  
  23  cdef extern from "Python.h":
  24      ctypedef Py_ssize_t Py_intptr_t
  25  
  26  cdef extern from "numpy/arrayobject.h":
  27      ctypedef Py_intptr_t npy_intp
  28      ctypedef size_t npy_uintp
  29  
  30      cdef enum NPY_TYPES:
  31          NPY_BOOL
  32          NPY_BYTE
  33          NPY_UBYTE
  34          NPY_SHORT
  35          NPY_USHORT
  36          NPY_INT
  37          NPY_UINT
  38          NPY_LONG
  39          NPY_ULONG
  40          NPY_LONGLONG
  41          NPY_ULONGLONG
  42          NPY_FLOAT
  43          NPY_DOUBLE
  44          NPY_LONGDOUBLE
  45          NPY_CFLOAT
  46          NPY_CDOUBLE
  47          NPY_CLONGDOUBLE
  48          NPY_OBJECT
  49          NPY_STRING
  50          NPY_UNICODE
  51          NPY_VOID
  52          NPY_DATETIME
  53          NPY_TIMEDELTA
  54          NPY_NTYPES
  55          NPY_NOTYPE
  56  
  57          NPY_INT8
  58          NPY_INT16
  59          NPY_INT32
  60          NPY_INT64
  61          NPY_INT128
  62          NPY_INT256
  63          NPY_UINT8
  64          NPY_UINT16
  65          NPY_UINT32
  66          NPY_UINT64
  67          NPY_UINT128
  68          NPY_UINT256
  69          NPY_FLOAT16
  70          NPY_FLOAT32
  71          NPY_FLOAT64
  72          NPY_FLOAT80
  73          NPY_FLOAT96
  74          NPY_FLOAT128
  75          NPY_FLOAT256
  76          NPY_COMPLEX32
  77          NPY_COMPLEX64
  78          NPY_COMPLEX128
  79          NPY_COMPLEX160
  80          NPY_COMPLEX192
  81          NPY_COMPLEX256
  82          NPY_COMPLEX512
  83  
  84          NPY_INTP
  85  
  86      ctypedef enum NPY_ORDER:
  87          NPY_ANYORDER
  88          NPY_CORDER
  89          NPY_FORTRANORDER
  90          NPY_KEEPORDER
  91  
  92      ctypedef enum NPY_CASTING:
  93          NPY_NO_CASTING
  94          NPY_EQUIV_CASTING
  95          NPY_SAFE_CASTING
  96          NPY_SAME_KIND_CASTING
  97          NPY_UNSAFE_CASTING
  98  
  99      ctypedef enum NPY_CLIPMODE:
 100          NPY_CLIP
 101          NPY_WRAP
 102          NPY_RAISE
 103  
 104      ctypedef enum NPY_SCALARKIND:
 105          NPY_NOSCALAR,
 106          NPY_BOOL_SCALAR,
 107          NPY_INTPOS_SCALAR,
 108          NPY_INTNEG_SCALAR,
 109          NPY_FLOAT_SCALAR,
 110          NPY_COMPLEX_SCALAR,
 111          NPY_OBJECT_SCALAR
 112  
 113      ctypedef enum NPY_SORTKIND:
 114          NPY_QUICKSORT
 115          NPY_HEAPSORT
 116          NPY_MERGESORT
 117  
 118      ctypedef enum NPY_SEARCHSIDE:
 119          NPY_SEARCHLEFT
 120          NPY_SEARCHRIGHT
 121  
 122      enum:
 123          # DEPRECATED since NumPy 1.7 ! Do not use in new code!
 124          NPY_C_CONTIGUOUS
 125          NPY_F_CONTIGUOUS
 126          NPY_CONTIGUOUS
 127          NPY_FORTRAN
 128          NPY_OWNDATA
 129          NPY_FORCECAST
 130          NPY_ENSURECOPY
 131          NPY_ENSUREARRAY
 132          NPY_ELEMENTSTRIDES
 133          NPY_ALIGNED
 134          NPY_NOTSWAPPED
 135          NPY_WRITEABLE
 136          NPY_ARR_HAS_DESCR
 137  
 138          NPY_BEHAVED
 139          NPY_BEHAVED_NS
 140          NPY_CARRAY
 141          NPY_CARRAY_RO
 142          NPY_FARRAY
 143          NPY_FARRAY_RO
 144          NPY_DEFAULT
 145  
 146          NPY_IN_ARRAY
 147          NPY_OUT_ARRAY
 148          NPY_INOUT_ARRAY
 149          NPY_IN_FARRAY
 150          NPY_OUT_FARRAY
 151          NPY_INOUT_FARRAY
 152  
 153          NPY_UPDATE_ALL
 154  
 155      enum:
 156          # Added in NumPy 1.7 to replace the deprecated enums above.
 157          NPY_ARRAY_C_CONTIGUOUS
 158          NPY_ARRAY_F_CONTIGUOUS
 159          NPY_ARRAY_OWNDATA
 160          NPY_ARRAY_FORCECAST
 161          NPY_ARRAY_ENSURECOPY
 162          NPY_ARRAY_ENSUREARRAY
 163          NPY_ARRAY_ELEMENTSTRIDES
 164          NPY_ARRAY_ALIGNED
 165          NPY_ARRAY_NOTSWAPPED
 166          NPY_ARRAY_WRITEABLE
 167          NPY_ARRAY_WRITEBACKIFCOPY
 168  
 169          NPY_ARRAY_BEHAVED
 170          NPY_ARRAY_BEHAVED_NS
 171          NPY_ARRAY_CARRAY
 172          NPY_ARRAY_CARRAY_RO
 173          NPY_ARRAY_FARRAY
 174          NPY_ARRAY_FARRAY_RO
 175          NPY_ARRAY_DEFAULT
 176  
 177          NPY_ARRAY_IN_ARRAY
 178          NPY_ARRAY_OUT_ARRAY
 179          NPY_ARRAY_INOUT_ARRAY
 180          NPY_ARRAY_IN_FARRAY
 181          NPY_ARRAY_OUT_FARRAY
 182          NPY_ARRAY_INOUT_FARRAY
 183  
 184          NPY_ARRAY_UPDATE_ALL
 185  
 186      cdef enum:
 187          NPY_MAXDIMS
 188  
 189      npy_intp NPY_MAX_ELSIZE
 190  
 191      ctypedef void (*PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *,  void *)
 192  
 193      ctypedef struct PyArray_ArrayDescr:
 194          # shape is a tuple, but Cython doesn't support "tuple shape"
 195          # inside a non-PyObject declaration, so we have to declare it
 196          # as just a PyObject*.
 197          PyObject* shape
 198  
 199      ctypedef struct PyArray_Descr:
 200          pass
 201  
 202      ctypedef class numpy.dtype [object PyArray_Descr, check_size ignore]:
 203          # Use PyDataType_* macros when possible, however there are no macros
 204          # for accessing some of the fields, so some are defined.
 205          cdef PyTypeObject* typeobj
 206          cdef char kind
 207          cdef char type
 208          # Numpy sometimes mutates this without warning (e.g. it'll
 209          # sometimes change "|" to "<" in shared dtype objects on
 210          # little-endian machines). If this matters to you, use
 211          # PyArray_IsNativeByteOrder(dtype.byteorder) instead of
 212          # directly accessing this field.
 213          cdef char byteorder
 214          cdef char flags
 215          cdef int type_num
 216          cdef int itemsize "elsize"
 217          cdef int alignment
 218          cdef object fields
 219          cdef tuple names
 220          # Use PyDataType_HASSUBARRAY to test whether this field is
 221          # valid (the pointer can be NULL). Most users should access
 222          # this field via the inline helper method PyDataType_SHAPE.
 223          cdef PyArray_ArrayDescr* subarray
 224  
 225      ctypedef class numpy.flatiter [object PyArrayIterObject, check_size ignore]:
 226          # Use through macros
 227          pass
 228  
 229      ctypedef class numpy.broadcast [object PyArrayMultiIterObject, check_size ignore]:
 230          # Use through macros
 231          pass
 232  
 233      ctypedef struct PyArrayObject:
 234          # For use in situations where ndarray can't replace PyArrayObject*,
 235          # like PyArrayObject**.
 236          pass
 237  
 238      ctypedef class numpy.ndarray [object PyArrayObject, check_size ignore]:
 239          cdef __cythonbufferdefaults__ = {"mode": "strided"}
 240  
 241          # NOTE: no field declarations since direct access is deprecated since NumPy 1.7
 242          # Instead, we use properties that map to the corresponding C-API functions.
 243  
 244          @property
 245          cdef inline PyObject* base(self) nogil:
 246              """Returns a borrowed reference to the object owning the data/memory.
 247              """
 248              return PyArray_BASE(self)
 249  
 250          @property
 251          cdef inline dtype descr(self):
 252              """Returns an owned reference to the dtype of the array.
 253              """
 254              return <dtype>PyArray_DESCR(self)
 255  
 256          @property
 257          cdef inline int ndim(self) nogil:
 258              """Returns the number of dimensions in the array.
 259              """
 260              return PyArray_NDIM(self)
 261  
 262          @property
 263          cdef inline npy_intp *shape(self) nogil:
 264              """Returns a pointer to the dimensions/shape of the array.
 265              The number of elements matches the number of dimensions of the array (ndim).
 266              Can return NULL for 0-dimensional arrays.
 267              """
 268              return PyArray_DIMS(self)
 269  
 270          @property
 271          cdef inline npy_intp *strides(self) nogil:
 272              """Returns a pointer to the strides of the array.
 273              The number of elements matches the number of dimensions of the array (ndim).
 274              """
 275              return PyArray_STRIDES(self)
 276  
 277          @property
 278          cdef inline npy_intp size(self) nogil:
 279              """Returns the total size (in number of elements) of the array.
 280              """
 281              return PyArray_SIZE(self)
 282  
 283          @property
 284          cdef inline char* data(self) nogil:
 285              """The pointer to the data buffer as a char*.
 286              This is provided for legacy reasons to avoid direct struct field access.
 287              For new code that needs this access, you probably want to cast the result
 288              of `PyArray_DATA()` instead, which returns a 'void*'.
 289              """
 290              return PyArray_BYTES(self)
 291  
 292      ctypedef unsigned char      npy_bool
 293  
 294      ctypedef signed char      npy_byte
 295      ctypedef signed short     npy_short
 296      ctypedef signed int       npy_int
 297      ctypedef signed long      npy_long
 298      ctypedef signed long long npy_longlong
 299  
 300      ctypedef unsigned char      npy_ubyte
 301      ctypedef unsigned short     npy_ushort
 302      ctypedef unsigned int       npy_uint
 303      ctypedef unsigned long      npy_ulong
 304      ctypedef unsigned long long npy_ulonglong
 305  
 306      ctypedef float        npy_float
 307      ctypedef double       npy_double
 308      ctypedef long double  npy_longdouble
 309  
 310      ctypedef signed char        npy_int8
 311      ctypedef signed short       npy_int16
 312      ctypedef signed int         npy_int32
 313      ctypedef signed long long   npy_int64
 314      ctypedef signed long long   npy_int96
 315      ctypedef signed long long   npy_int128
 316  
 317      ctypedef unsigned char      npy_uint8
 318      ctypedef unsigned short     npy_uint16
 319      ctypedef unsigned int       npy_uint32
 320      ctypedef unsigned long long npy_uint64
 321      ctypedef unsigned long long npy_uint96
 322      ctypedef unsigned long long npy_uint128
 323  
 324      ctypedef float        npy_float32
 325      ctypedef double       npy_float64
 326      ctypedef long double  npy_float80
 327      ctypedef long double  npy_float96
 328      ctypedef long double  npy_float128
 329  
 330      ctypedef struct npy_cfloat:
 331          float real
 332          float imag
 333  
 334      ctypedef struct npy_cdouble:
 335          double real
 336          double imag
 337  
 338      ctypedef struct npy_clongdouble:
 339          long double real
 340          long double imag
 341  
 342      ctypedef struct npy_complex64:
 343          float real
 344          float imag
 345  
 346      ctypedef struct npy_complex128:
 347          double real
 348          double imag
 349  
 350      ctypedef struct npy_complex160:
 351          long double real
 352          long double imag
 353  
 354      ctypedef struct npy_complex192:
 355          long double real
 356          long double imag
 357  
 358      ctypedef struct npy_complex256:
 359          long double real
 360          long double imag
 361  
 362      ctypedef struct PyArray_Dims:
 363          npy_intp *ptr
 364          int len
 365  
 366      int _import_array() except -1
 367      # A second definition so _import_array isn't marked as used when we use it here.
 368      # Do not use - subject to change any time.
 369      int __pyx_import_array "_import_array"() except -1
 370  
 371      #
 372      # Macros from ndarrayobject.h
 373      #
 374      bint PyArray_CHKFLAGS(ndarray m, int flags) nogil
 375      bint PyArray_IS_C_CONTIGUOUS(ndarray arr) nogil
 376      bint PyArray_IS_F_CONTIGUOUS(ndarray arr) nogil
 377      bint PyArray_ISCONTIGUOUS(ndarray m) nogil
 378      bint PyArray_ISWRITEABLE(ndarray m) nogil
 379      bint PyArray_ISALIGNED(ndarray m) nogil
 380  
 381      int PyArray_NDIM(ndarray) nogil
 382      bint PyArray_ISONESEGMENT(ndarray) nogil
 383      bint PyArray_ISFORTRAN(ndarray) nogil
 384      int PyArray_FORTRANIF(ndarray) nogil
 385  
 386      void* PyArray_DATA(ndarray) nogil
 387      char* PyArray_BYTES(ndarray) nogil
 388  
 389      npy_intp* PyArray_DIMS(ndarray) nogil
 390      npy_intp* PyArray_STRIDES(ndarray) nogil
 391      npy_intp PyArray_DIM(ndarray, size_t) nogil
 392      npy_intp PyArray_STRIDE(ndarray, size_t) nogil
 393  
 394      PyObject *PyArray_BASE(ndarray) nogil  # returns borrowed reference!
 395      PyArray_Descr *PyArray_DESCR(ndarray) nogil  # returns borrowed reference to dtype!
 396      PyArray_Descr *PyArray_DTYPE(ndarray) nogil  # returns borrowed reference to dtype! NP 1.7+ alias for descr.
 397      int PyArray_FLAGS(ndarray) nogil
 398      void PyArray_CLEARFLAGS(ndarray, int flags) nogil  # Added in NumPy 1.7
 399      void PyArray_ENABLEFLAGS(ndarray, int flags) nogil  # Added in NumPy 1.7
 400      npy_intp PyArray_ITEMSIZE(ndarray) nogil
 401      int PyArray_TYPE(ndarray arr) nogil
 402  
 403      object PyArray_GETITEM(ndarray arr, void *itemptr)
 404      int PyArray_SETITEM(ndarray arr, void *itemptr, object obj)
 405  
 406      bint PyTypeNum_ISBOOL(int) nogil
 407      bint PyTypeNum_ISUNSIGNED(int) nogil
 408      bint PyTypeNum_ISSIGNED(int) nogil
 409      bint PyTypeNum_ISINTEGER(int) nogil
 410      bint PyTypeNum_ISFLOAT(int) nogil
 411      bint PyTypeNum_ISNUMBER(int) nogil
 412      bint PyTypeNum_ISSTRING(int) nogil
 413      bint PyTypeNum_ISCOMPLEX(int) nogil
 414      bint PyTypeNum_ISPYTHON(int) nogil
 415      bint PyTypeNum_ISFLEXIBLE(int) nogil
 416      bint PyTypeNum_ISUSERDEF(int) nogil
 417      bint PyTypeNum_ISEXTENDED(int) nogil
 418      bint PyTypeNum_ISOBJECT(int) nogil
 419  
 420      bint PyDataType_ISBOOL(dtype) nogil
 421      bint PyDataType_ISUNSIGNED(dtype) nogil
 422      bint PyDataType_ISSIGNED(dtype) nogil
 423      bint PyDataType_ISINTEGER(dtype) nogil
 424      bint PyDataType_ISFLOAT(dtype) nogil
 425      bint PyDataType_ISNUMBER(dtype) nogil
 426      bint PyDataType_ISSTRING(dtype) nogil
 427      bint PyDataType_ISCOMPLEX(dtype) nogil
 428      bint PyDataType_ISPYTHON(dtype) nogil
 429      bint PyDataType_ISFLEXIBLE(dtype) nogil
 430      bint PyDataType_ISUSERDEF(dtype) nogil
 431      bint PyDataType_ISEXTENDED(dtype) nogil
 432      bint PyDataType_ISOBJECT(dtype) nogil
 433      bint PyDataType_HASFIELDS(dtype) nogil
 434      bint PyDataType_HASSUBARRAY(dtype) nogil
 435  
 436      bint PyArray_ISBOOL(ndarray) nogil
 437      bint PyArray_ISUNSIGNED(ndarray) nogil
 438      bint PyArray_ISSIGNED(ndarray) nogil
 439      bint PyArray_ISINTEGER(ndarray) nogil
 440      bint PyArray_ISFLOAT(ndarray) nogil
 441      bint PyArray_ISNUMBER(ndarray) nogil
 442      bint PyArray_ISSTRING(ndarray) nogil
 443      bint PyArray_ISCOMPLEX(ndarray) nogil
 444      bint PyArray_ISPYTHON(ndarray) nogil
 445      bint PyArray_ISFLEXIBLE(ndarray) nogil
 446      bint PyArray_ISUSERDEF(ndarray) nogil
 447      bint PyArray_ISEXTENDED(ndarray) nogil
 448      bint PyArray_ISOBJECT(ndarray) nogil
 449      bint PyArray_HASFIELDS(ndarray) nogil
 450  
 451      bint PyArray_ISVARIABLE(ndarray) nogil
 452  
 453      bint PyArray_SAFEALIGNEDCOPY(ndarray) nogil
 454      bint PyArray_ISNBO(char) nogil              # works on ndarray.byteorder
 455      bint PyArray_IsNativeByteOrder(char) nogil  # works on ndarray.byteorder
 456      bint PyArray_ISNOTSWAPPED(ndarray) nogil
 457      bint PyArray_ISBYTESWAPPED(ndarray) nogil
 458  
 459      bint PyArray_FLAGSWAP(ndarray, int) nogil
 460  
 461      bint PyArray_ISCARRAY(ndarray) nogil
 462      bint PyArray_ISCARRAY_RO(ndarray) nogil
 463      bint PyArray_ISFARRAY(ndarray) nogil
 464      bint PyArray_ISFARRAY_RO(ndarray) nogil
 465      bint PyArray_ISBEHAVED(ndarray) nogil
 466      bint PyArray_ISBEHAVED_RO(ndarray) nogil
 467  
 468  
 469      bint PyDataType_ISNOTSWAPPED(dtype) nogil
 470      bint PyDataType_ISBYTESWAPPED(dtype) nogil
 471  
 472      bint PyArray_DescrCheck(object)
 473  
 474      bint PyArray_Check(object)
 475      bint PyArray_CheckExact(object)
 476  
 477      # Cannot be supported due to out arg:
 478      # bint PyArray_HasArrayInterfaceType(object, dtype, object, object&)
 479      # bint PyArray_HasArrayInterface(op, out)
 480  
 481  
 482      bint PyArray_IsZeroDim(object)
 483      # Cannot be supported due to ## ## in macro:
 484      # bint PyArray_IsScalar(object, verbatim work)
 485      bint PyArray_CheckScalar(object)
 486      bint PyArray_IsPythonNumber(object)
 487      bint PyArray_IsPythonScalar(object)
 488      bint PyArray_IsAnyScalar(object)
 489      bint PyArray_CheckAnyScalar(object)
 490  
 491      ndarray PyArray_GETCONTIGUOUS(ndarray)
 492      bint PyArray_SAMESHAPE(ndarray, ndarray) nogil
 493      npy_intp PyArray_SIZE(ndarray) nogil
 494      npy_intp PyArray_NBYTES(ndarray) nogil
 495  
 496      object PyArray_FROM_O(object)
 497      object PyArray_FROM_OF(object m, int flags)
 498      object PyArray_FROM_OT(object m, int type)
 499      object PyArray_FROM_OTF(object m, int type, int flags)
 500      object PyArray_FROMANY(object m, int type, int min, int max, int flags)
 501      object PyArray_ZEROS(int nd, npy_intp* dims, int type, int fortran)
 502      object PyArray_EMPTY(int nd, npy_intp* dims, int type, int fortran)
 503      void PyArray_FILLWBYTE(object, int val)
 504      npy_intp PyArray_REFCOUNT(object)
 505      object PyArray_ContiguousFromAny(op, int, int min_depth, int max_depth)
 506      unsigned char PyArray_EquivArrTypes(ndarray a1, ndarray a2)
 507      bint PyArray_EquivByteorders(int b1, int b2) nogil
 508      object PyArray_SimpleNew(int nd, npy_intp* dims, int typenum)
 509      object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int typenum, void* data)
 510      #object PyArray_SimpleNewFromDescr(int nd, npy_intp* dims, dtype descr)
 511      object PyArray_ToScalar(void* data, ndarray arr)
 512  
 513      void* PyArray_GETPTR1(ndarray m, npy_intp i) nogil
 514      void* PyArray_GETPTR2(ndarray m, npy_intp i, npy_intp j) nogil
 515      void* PyArray_GETPTR3(ndarray m, npy_intp i, npy_intp j, npy_intp k) nogil
 516      void* PyArray_GETPTR4(ndarray m, npy_intp i, npy_intp j, npy_intp k, npy_intp l) nogil
 517  
 518      void PyArray_XDECREF_ERR(ndarray)
 519      # Cannot be supported due to out arg
 520      # void PyArray_DESCR_REPLACE(descr)
 521  
 522  
 523      object PyArray_Copy(ndarray)
 524      object PyArray_FromObject(object op, int type, int min_depth, int max_depth)
 525      object PyArray_ContiguousFromObject(object op, int type, int min_depth, int max_depth)
 526      object PyArray_CopyFromObject(object op, int type, int min_depth, int max_depth)
 527  
 528      object PyArray_Cast(ndarray mp, int type_num)
 529      object PyArray_Take(ndarray ap, object items, int axis)
 530      object PyArray_Put(ndarray ap, object items, object values)
 531  
 532      void PyArray_ITER_RESET(flatiter it) nogil
 533      void PyArray_ITER_NEXT(flatiter it) nogil
 534      void PyArray_ITER_GOTO(flatiter it, npy_intp* destination) nogil
 535      void PyArray_ITER_GOTO1D(flatiter it, npy_intp ind) nogil
 536      void* PyArray_ITER_DATA(flatiter it) nogil
 537      bint PyArray_ITER_NOTDONE(flatiter it) nogil
 538  
 539      void PyArray_MultiIter_RESET(broadcast multi) nogil
 540      void PyArray_MultiIter_NEXT(broadcast multi) nogil
 541      void PyArray_MultiIter_GOTO(broadcast multi, npy_intp dest) nogil
 542      void PyArray_MultiIter_GOTO1D(broadcast multi, npy_intp ind) nogil
 543      void* PyArray_MultiIter_DATA(broadcast multi, npy_intp i) nogil
 544      void PyArray_MultiIter_NEXTi(broadcast multi, npy_intp i) nogil
 545      bint PyArray_MultiIter_NOTDONE(broadcast multi) nogil
 546  
 547      # Functions from __multiarray_api.h
 548  
 549      # Functions taking dtype and returning object/ndarray are disabled
 550      # for now as they steal dtype references. I'm conservative and disable
 551      # more than is probably needed until it can be checked further.
 552      int PyArray_SetNumericOps        (object)
 553      object PyArray_GetNumericOps ()
 554      int PyArray_INCREF (ndarray)
 555      int PyArray_XDECREF (ndarray)
 556      void PyArray_SetStringFunction (object, int)
 557      dtype PyArray_DescrFromType (int)
 558      object PyArray_TypeObjectFromType (int)
 559      char * PyArray_Zero (ndarray)
 560      char * PyArray_One (ndarray)
 561      #object PyArray_CastToType (ndarray, dtype, int)
 562      int PyArray_CastTo (ndarray, ndarray)
 563      int PyArray_CastAnyTo (ndarray, ndarray)
 564      int PyArray_CanCastSafely (int, int)
 565      npy_bool PyArray_CanCastTo (dtype, dtype)
 566      int PyArray_ObjectType (object, int)
 567      dtype PyArray_DescrFromObject (object, dtype)
 568      #ndarray* PyArray_ConvertToCommonType (object, int *)
 569      dtype PyArray_DescrFromScalar (object)
 570      dtype PyArray_DescrFromTypeObject (object)
 571      npy_intp PyArray_Size (object)
 572      #object PyArray_Scalar (void *, dtype, object)
 573      #object PyArray_FromScalar (object, dtype)
 574      void PyArray_ScalarAsCtype (object, void *)
 575      #int PyArray_CastScalarToCtype (object, void *, dtype)
 576      #int PyArray_CastScalarDirect (object, dtype, void *, int)
 577      object PyArray_ScalarFromObject (object)
 578      #PyArray_VectorUnaryFunc * PyArray_GetCastFunc (dtype, int)
 579      object PyArray_FromDims (int, int *, int)
 580      #object PyArray_FromDimsAndDataAndDescr (int, int *, dtype, char *)
 581      #object PyArray_FromAny (object, dtype, int, int, int, object)
 582      object PyArray_EnsureArray (object)
 583      object PyArray_EnsureAnyArray (object)
 584      #object PyArray_FromFile (stdio.FILE *, dtype, npy_intp, char *)
 585      #object PyArray_FromString (char *, npy_intp, dtype, npy_intp, char *)
 586      #object PyArray_FromBuffer (object, dtype, npy_intp, npy_intp)
 587      #object PyArray_FromIter (object, dtype, npy_intp)
 588      object PyArray_Return (ndarray)
 589      #object PyArray_GetField (ndarray, dtype, int)
 590      #int PyArray_SetField (ndarray, dtype, int, object)
 591      object PyArray_Byteswap (ndarray, npy_bool)
 592      object PyArray_Resize (ndarray, PyArray_Dims *, int, NPY_ORDER)
 593      int PyArray_MoveInto (ndarray, ndarray)
 594      int PyArray_CopyInto (ndarray, ndarray)
 595      int PyArray_CopyAnyInto (ndarray, ndarray)
 596      int PyArray_CopyObject (ndarray, object)
 597      object PyArray_NewCopy (ndarray, NPY_ORDER)
 598      object PyArray_ToList (ndarray)
 599      object PyArray_ToString (ndarray, NPY_ORDER)
 600      int PyArray_ToFile (ndarray, stdio.FILE *, char *, char *)
 601      int PyArray_Dump (object, object, int)
 602      object PyArray_Dumps (object, int)
 603      int PyArray_ValidType (int)
 604      void PyArray_UpdateFlags (ndarray, int)
 605      object PyArray_New (type, int, npy_intp *, int, npy_intp *, void *, int, int, object)
 606      #object PyArray_NewFromDescr (type, dtype, int, npy_intp *, npy_intp *, void *, int, object)
 607      #dtype PyArray_DescrNew (dtype)
 608      dtype PyArray_DescrNewFromType (int)
 609      double PyArray_GetPriority (object, double)
 610      object PyArray_IterNew (object)
 611      object PyArray_MultiIterNew (int, ...)
 612  
 613      int PyArray_PyIntAsInt (object)
 614      npy_intp PyArray_PyIntAsIntp (object)
 615      int PyArray_Broadcast (broadcast)
 616      void PyArray_FillObjectArray (ndarray, object)
 617      int PyArray_FillWithScalar (ndarray, object)
 618      npy_bool PyArray_CheckStrides (int, int, npy_intp, npy_intp, npy_intp *, npy_intp *)
 619      dtype PyArray_DescrNewByteorder (dtype, char)
 620      object PyArray_IterAllButAxis (object, int *)
 621      #object PyArray_CheckFromAny (object, dtype, int, int, int, object)
 622      #object PyArray_FromArray (ndarray, dtype, int)
 623      object PyArray_FromInterface (object)
 624      object PyArray_FromStructInterface (object)
 625      #object PyArray_FromArrayAttr (object, dtype, object)
 626      #NPY_SCALARKIND PyArray_ScalarKind (int, ndarray*)
 627      int PyArray_CanCoerceScalar (int, int, NPY_SCALARKIND)
 628      object PyArray_NewFlagsObject (object)
 629      npy_bool PyArray_CanCastScalar (type, type)
 630      #int PyArray_CompareUCS4 (npy_ucs4 *, npy_ucs4 *, register size_t)
 631      int PyArray_RemoveSmallest (broadcast)
 632      int PyArray_ElementStrides (object)
 633      void PyArray_Item_INCREF (char *, dtype)
 634      void PyArray_Item_XDECREF (char *, dtype)
 635      object PyArray_FieldNames (object)
 636      object PyArray_Transpose (ndarray, PyArray_Dims *)
 637      object PyArray_TakeFrom (ndarray, object, int, ndarray, NPY_CLIPMODE)
 638      object PyArray_PutTo (ndarray, object, object, NPY_CLIPMODE)
 639      object PyArray_PutMask (ndarray, object, object)
 640      object PyArray_Repeat (ndarray, object, int)
 641      object PyArray_Choose (ndarray, object, ndarray, NPY_CLIPMODE)
 642      int PyArray_Sort (ndarray, int, NPY_SORTKIND)
 643      object PyArray_ArgSort (ndarray, int, NPY_SORTKIND)
 644      object PyArray_SearchSorted (ndarray, object, NPY_SEARCHSIDE, PyObject *)
 645      object PyArray_ArgMax (ndarray, int, ndarray)
 646      object PyArray_ArgMin (ndarray, int, ndarray)
 647      object PyArray_Reshape (ndarray, object)
 648      object PyArray_Newshape (ndarray, PyArray_Dims *, NPY_ORDER)
 649      object PyArray_Squeeze (ndarray)
 650      #object PyArray_View (ndarray, dtype, type)
 651      object PyArray_SwapAxes (ndarray, int, int)
 652      object PyArray_Max (ndarray, int, ndarray)
 653      object PyArray_Min (ndarray, int, ndarray)
 654      object PyArray_Ptp (ndarray, int, ndarray)
 655      object PyArray_Mean (ndarray, int, int, ndarray)
 656      object PyArray_Trace (ndarray, int, int, int, int, ndarray)
 657      object PyArray_Diagonal (ndarray, int, int, int)
 658      object PyArray_Clip (ndarray, object, object, ndarray)
 659      object PyArray_Conjugate (ndarray, ndarray)
 660      object PyArray_Nonzero (ndarray)
 661      object PyArray_Std (ndarray, int, int, ndarray, int)
 662      object PyArray_Sum (ndarray, int, int, ndarray)
 663      object PyArray_CumSum (ndarray, int, int, ndarray)
 664      object PyArray_Prod (ndarray, int, int, ndarray)
 665      object PyArray_CumProd (ndarray, int, int, ndarray)
 666      object PyArray_All (ndarray, int, ndarray)
 667      object PyArray_Any (ndarray, int, ndarray)
 668      object PyArray_Compress (ndarray, object, int, ndarray)
 669      object PyArray_Flatten (ndarray, NPY_ORDER)
 670      object PyArray_Ravel (ndarray, NPY_ORDER)
 671      npy_intp PyArray_MultiplyList (npy_intp *, int)
 672      int PyArray_MultiplyIntList (int *, int)
 673      void * PyArray_GetPtr (ndarray, npy_intp*)
 674      int PyArray_CompareLists (npy_intp *, npy_intp *, int)
 675      #int PyArray_AsCArray (object*, void *, npy_intp *, int, dtype)
 676      #int PyArray_As1D (object*, char **, int *, int)
 677      #int PyArray_As2D (object*, char ***, int *, int *, int)
 678      int PyArray_Free (object, void *)
 679      #int PyArray_Converter (object, object*)
 680      int PyArray_IntpFromSequence (object, npy_intp *, int)
 681      object PyArray_Concatenate (object, int)
 682      object PyArray_InnerProduct (object, object)
 683      object PyArray_MatrixProduct (object, object)
 684      object PyArray_CopyAndTranspose (object)
 685      object PyArray_Correlate (object, object, int)
 686      int PyArray_TypestrConvert (int, int)
 687      #int PyArray_DescrConverter (object, dtype*)
 688      #int PyArray_DescrConverter2 (object, dtype*)
 689      int PyArray_IntpConverter (object, PyArray_Dims *)
 690      #int PyArray_BufferConverter (object, chunk)
 691      int PyArray_AxisConverter (object, int *)
 692      int PyArray_BoolConverter (object, npy_bool *)
 693      int PyArray_ByteorderConverter (object, char *)
 694      int PyArray_OrderConverter (object, NPY_ORDER *)
 695      unsigned char PyArray_EquivTypes (dtype, dtype)
 696      #object PyArray_Zeros (int, npy_intp *, dtype, int)
 697      #object PyArray_Empty (int, npy_intp *, dtype, int)
 698      object PyArray_Where (object, object, object)
 699      object PyArray_Arange (double, double, double, int)
 700      #object PyArray_ArangeObj (object, object, object, dtype)
 701      int PyArray_SortkindConverter (object, NPY_SORTKIND *)
 702      object PyArray_LexSort (object, int)
 703      object PyArray_Round (ndarray, int, ndarray)
 704      unsigned char PyArray_EquivTypenums (int, int)
 705      int PyArray_RegisterDataType (dtype)
 706      int PyArray_RegisterCastFunc (dtype, int, PyArray_VectorUnaryFunc *)
 707      int PyArray_RegisterCanCast (dtype, int, NPY_SCALARKIND)
 708      #void PyArray_InitArrFuncs (PyArray_ArrFuncs *)
 709      object PyArray_IntTupleFromIntp (int, npy_intp *)
 710      int PyArray_TypeNumFromName (char *)
 711      int PyArray_ClipmodeConverter (object, NPY_CLIPMODE *)
 712      #int PyArray_OutputConverter (object, ndarray*)
 713      object PyArray_BroadcastToShape (object, npy_intp *, int)
 714      void _PyArray_SigintHandler (int)
 715      void* _PyArray_GetSigintBuf ()
 716      #int PyArray_DescrAlignConverter (object, dtype*)
 717      #int PyArray_DescrAlignConverter2 (object, dtype*)
 718      int PyArray_SearchsideConverter (object, void *)
 719      object PyArray_CheckAxis (ndarray, int *, int)
 720      npy_intp PyArray_OverflowMultiplyList (npy_intp *, int)
 721      int PyArray_CompareString (char *, char *, size_t)
 722      int PyArray_SetBaseObject(ndarray, base)  # NOTE: steals a reference to base! Use "set_array_base()" instead.
 723  
 724  
 725  # Typedefs that matches the runtime dtype objects in
 726  # the numpy module.
 727  
 728  # The ones that are commented out needs an IFDEF function
 729  # in Cython to enable them only on the right systems.
 730  
 731  ctypedef npy_int8       int8_t
 732  ctypedef npy_int16      int16_t
 733  ctypedef npy_int32      int32_t
 734  ctypedef npy_int64      int64_t
 735  #ctypedef npy_int96      int96_t
 736  #ctypedef npy_int128     int128_t
 737  
 738  ctypedef npy_uint8      uint8_t
 739  ctypedef npy_uint16     uint16_t
 740  ctypedef npy_uint32     uint32_t
 741  ctypedef npy_uint64     uint64_t
 742  #ctypedef npy_uint96     uint96_t
 743  #ctypedef npy_uint128    uint128_t
 744  
 745  ctypedef npy_float32    float32_t
 746  ctypedef npy_float64    float64_t
 747  #ctypedef npy_float80    float80_t
 748  #ctypedef npy_float128   float128_t
 749  
 750  ctypedef float complex  complex64_t
 751  ctypedef double complex complex128_t
 752  
 753  # The int types are mapped a bit surprising --
 754  # numpy.int corresponds to 'l' and numpy.long to 'q'
 755  ctypedef npy_long       int_t
 756  ctypedef npy_longlong   long_t
 757  ctypedef npy_longlong   longlong_t
 758  
 759  ctypedef npy_ulong      uint_t
 760  ctypedef npy_ulonglong  ulong_t
 761  ctypedef npy_ulonglong  ulonglong_t
 762  
 763  ctypedef npy_intp       intp_t
 764  ctypedef npy_uintp      uintp_t
 765  
 766  ctypedef npy_double     float_t
 767  ctypedef npy_double     double_t
 768  ctypedef npy_longdouble longdouble_t
 769  
 770  ctypedef npy_cfloat      cfloat_t
 771  ctypedef npy_cdouble     cdouble_t
 772  ctypedef npy_clongdouble clongdouble_t
 773  
 774  ctypedef npy_cdouble     complex_t
 775  
 776  cdef inline object PyArray_MultiIterNew1(a):
 777      return PyArray_MultiIterNew(1, <void*>a)
 778  
 779  cdef inline object PyArray_MultiIterNew2(a, b):
 780      return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 781  
 782  cdef inline object PyArray_MultiIterNew3(a, b, c):
 783      return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 784  
 785  cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 786      return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 787  
 788  cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 789      return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 790  
 791  cdef inline tuple PyDataType_SHAPE(dtype d):
 792      if PyDataType_HASSUBARRAY(d):
 793          return <tuple>d.subarray.shape
 794      else:
 795          return ()
 796  
 797  
 798  cdef extern from "numpy/ndarrayobject.h":
 799      PyTypeObject PyTimedeltaArrType_Type
 800      PyTypeObject PyDatetimeArrType_Type
 801      ctypedef int64_t npy_timedelta
 802      ctypedef int64_t npy_datetime
 803  
 804  cdef extern from "numpy/ndarraytypes.h":
 805      ctypedef struct PyArray_DatetimeMetaData:
 806          NPY_DATETIMEUNIT base
 807          int64_t num
 808  
 809  cdef extern from "numpy/arrayscalars.h":
 810  
 811      # abstract types
 812      ctypedef class numpy.generic [object PyObject]:
 813          pass
 814      ctypedef class numpy.number [object PyObject]:
 815          pass
 816      ctypedef class numpy.integer [object PyObject]:
 817          pass
 818      ctypedef class numpy.signedinteger [object PyObject]:
 819          pass
 820      ctypedef class numpy.unsignedinteger [object PyObject]:
 821          pass
 822      ctypedef class numpy.inexact [object PyObject]:
 823          pass
 824      ctypedef class numpy.floating [object PyObject]:
 825          pass
 826      ctypedef class numpy.complexfloating [object PyObject]:
 827          pass
 828      ctypedef class numpy.flexible [object PyObject]:
 829          pass
 830      ctypedef class numpy.character [object PyObject]:
 831          pass
 832  
 833      ctypedef struct PyDatetimeScalarObject:
 834          # PyObject_HEAD
 835          npy_datetime obval
 836          PyArray_DatetimeMetaData obmeta
 837  
 838      ctypedef struct PyTimedeltaScalarObject:
 839          # PyObject_HEAD
 840          npy_timedelta obval
 841          PyArray_DatetimeMetaData obmeta
 842  
 843      ctypedef enum NPY_DATETIMEUNIT:
 844          NPY_FR_Y
 845          NPY_FR_M
 846          NPY_FR_W
 847          NPY_FR_D
 848          NPY_FR_B
 849          NPY_FR_h
 850          NPY_FR_m
 851          NPY_FR_s
 852          NPY_FR_ms
 853          NPY_FR_us
 854          NPY_FR_ns
 855          NPY_FR_ps
 856          NPY_FR_fs
 857          NPY_FR_as
 858  
 859  
 860  #
 861  # ufunc API
 862  #
 863  
 864  cdef extern from "numpy/ufuncobject.h":
 865  
 866      ctypedef void (*PyUFuncGenericFunction) (char **, npy_intp *, npy_intp *, void *)
 867  
 868      ctypedef class numpy.ufunc [object PyUFuncObject, check_size ignore]:
 869          cdef:
 870              int nin, nout, nargs
 871              int identity
 872              PyUFuncGenericFunction *functions
 873              void **data
 874              int ntypes
 875              int check_return
 876              char *name
 877              char *types
 878              char *doc
 879              void *ptr
 880              PyObject *obj
 881              PyObject *userloops
 882  
 883      cdef enum:
 884          PyUFunc_Zero
 885          PyUFunc_One
 886          PyUFunc_None
 887          UFUNC_ERR_IGNORE
 888          UFUNC_ERR_WARN
 889          UFUNC_ERR_RAISE
 890          UFUNC_ERR_CALL
 891          UFUNC_ERR_PRINT
 892          UFUNC_ERR_LOG
 893          UFUNC_MASK_DIVIDEBYZERO
 894          UFUNC_MASK_OVERFLOW
 895          UFUNC_MASK_UNDERFLOW
 896          UFUNC_MASK_INVALID
 897          UFUNC_SHIFT_DIVIDEBYZERO
 898          UFUNC_SHIFT_OVERFLOW
 899          UFUNC_SHIFT_UNDERFLOW
 900          UFUNC_SHIFT_INVALID
 901          UFUNC_FPE_DIVIDEBYZERO
 902          UFUNC_FPE_OVERFLOW
 903          UFUNC_FPE_UNDERFLOW
 904          UFUNC_FPE_INVALID
 905          UFUNC_ERR_DEFAULT
 906          UFUNC_ERR_DEFAULT2
 907  
 908      object PyUFunc_FromFuncAndData(PyUFuncGenericFunction *,
 909            void **, char *, int, int, int, int, char *, char *, int)
 910      int PyUFunc_RegisterLoopForType(ufunc, int,
 911                                      PyUFuncGenericFunction, int *, void *)
 912      void PyUFunc_f_f_As_d_d \
 913           (char **, npy_intp *, npy_intp *, void *)
 914      void PyUFunc_d_d \
 915           (char **, npy_intp *, npy_intp *, void *)
 916      void PyUFunc_f_f \
 917           (char **, npy_intp *, npy_intp *, void *)
 918      void PyUFunc_g_g \
 919           (char **, npy_intp *, npy_intp *, void *)
 920      void PyUFunc_F_F_As_D_D \
 921           (char **, npy_intp *, npy_intp *, void *)
 922      void PyUFunc_F_F \
 923           (char **, npy_intp *, npy_intp *, void *)
 924      void PyUFunc_D_D \
 925           (char **, npy_intp *, npy_intp *, void *)
 926      void PyUFunc_G_G \
 927           (char **, npy_intp *, npy_intp *, void *)
 928      void PyUFunc_O_O \
 929           (char **, npy_intp *, npy_intp *, void *)
 930      void PyUFunc_ff_f_As_dd_d \
 931           (char **, npy_intp *, npy_intp *, void *)
 932      void PyUFunc_ff_f \
 933           (char **, npy_intp *, npy_intp *, void *)
 934      void PyUFunc_dd_d \
 935           (char **, npy_intp *, npy_intp *, void *)
 936      void PyUFunc_gg_g \
 937           (char **, npy_intp *, npy_intp *, void *)
 938      void PyUFunc_FF_F_As_DD_D \
 939           (char **, npy_intp *, npy_intp *, void *)
 940      void PyUFunc_DD_D \
 941           (char **, npy_intp *, npy_intp *, void *)
 942      void PyUFunc_FF_F \
 943           (char **, npy_intp *, npy_intp *, void *)
 944      void PyUFunc_GG_G \
 945           (char **, npy_intp *, npy_intp *, void *)
 946      void PyUFunc_OO_O \
 947           (char **, npy_intp *, npy_intp *, void *)
 948      void PyUFunc_O_O_method \
 949           (char **, npy_intp *, npy_intp *, void *)
 950      void PyUFunc_OO_O_method \
 951           (char **, npy_intp *, npy_intp *, void *)
 952      void PyUFunc_On_Om \
 953           (char **, npy_intp *, npy_intp *, void *)
 954      int PyUFunc_GetPyValues \
 955          (char *, int *, int *, PyObject **)
 956      int PyUFunc_checkfperr \
 957             (int, PyObject *, int *)
 958      void PyUFunc_clearfperr()
 959      int PyUFunc_getfperr()
 960      int PyUFunc_handlefperr \
 961          (int, PyObject *, int, int *)
 962      int PyUFunc_ReplaceLoopBySignature \
 963          (ufunc, PyUFuncGenericFunction, int *, PyUFuncGenericFunction *)
 964      object PyUFunc_FromFuncAndDataAndSignature \
 965               (PyUFuncGenericFunction *, void **, char *, int, int, int,
 966                int, char *, char *, int, char *)
 967  
 968      int _import_umath() except -1
 969  
 970  cdef inline void set_array_base(ndarray arr, object base):
 971      Py_INCREF(base) # important to do this before stealing the reference below!
 972      PyArray_SetBaseObject(arr, base)
 973  
 974  cdef inline object get_array_base(ndarray arr):
 975      base = PyArray_BASE(arr)
 976      if base is NULL:
 977          return None
 978      return <object>base
 979  
 980  # Versions of the import_* functions which are more suitable for
 981  # Cython code.
 982  cdef inline int import_array() except -1:
 983      try:
 984          __pyx_import_array()
 985      except Exception:
 986          raise ImportError("numpy.core.multiarray failed to import")
 987  
 988  cdef inline int import_umath() except -1:
 989      try:
 990          _import_umath()
 991      except Exception:
 992          raise ImportError("numpy.core.umath failed to import")
 993  
 994  cdef inline int import_ufunc() except -1:
 995      try:
 996          _import_umath()
 997      except Exception:
 998          raise ImportError("numpy.core.umath failed to import")
 999  
1000  
1001  cdef inline bint is_timedelta64_object(object obj):
1002      """
1003      Cython equivalent of `isinstance(obj, np.timedelta64)`
1004  
1005      Parameters
1006      ----------
1007      obj : object
1008  
1009      Returns
1010      -------
1011      bool
1012      """
1013      return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type)
1014  
1015  
1016  cdef inline bint is_datetime64_object(object obj):
1017      """
1018      Cython equivalent of `isinstance(obj, np.datetime64)`
1019  
1020      Parameters
1021      ----------
1022      obj : object
1023  
1024      Returns
1025      -------
1026      bool
1027      """
1028      return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type)
1029  
1030  
1031  cdef inline npy_datetime get_datetime64_value(object obj) nogil:
1032      """
1033      returns the int64 value underlying scalar numpy datetime64 object
1034  
1035      Note that to interpret this as a datetime, the corresponding unit is
1036      also needed.  That can be found using `get_datetime64_unit`.
1037      """
1038      return (<PyDatetimeScalarObject*>obj).obval
1039  
1040  
1041  cdef inline npy_timedelta get_timedelta64_value(object obj) nogil:
1042      """
1043      returns the int64 value underlying scalar numpy timedelta64 object
1044      """
1045      return (<PyTimedeltaScalarObject*>obj).obval
1046  
1047  
1048  cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil:
1049      """
1050      returns the unit part of the dtype for a numpy datetime64 object.
1051      """
1052      return <NPY_DATETIMEUNIT>(<PyDatetimeScalarObject*>obj).obmeta.base