# NumPy static imports for Cython
#
# If any of the PyArray_* functions are called, import_array must be
# called first.
#
# This also defines backwards-compatibility buffer acquisition
# code for use in Python 2.x (or Python <= 2.5 when NumPy starts
# implementing PEP-3118 directly).
#
# Because of laziness, the format string of the buffer is statically
# allocated. Increase the size if this is not enough, or submit a
# patch to do this properly.
#
# Author: Dag Sverre Seljebotn
#
DEF _buffer_format_string_len = 255
cimport cpython.buffer as pybuf
from cpython.ref cimport Py_INCREF
from cpython.mem cimport PyObject_Malloc, PyObject_Free
from cpython.object cimport PyObject, PyTypeObject
from cpython.buffer cimport PyObject_GetBuffer
from cpython.type cimport type
cimport libc.stdio as stdio
cdef extern from "Python.h":
ctypedef int Py_intptr_t
cdef extern from "numpy/arrayobject.h":
ctypedef Py_intptr_t npy_intp
ctypedef size_t npy_uintp
cdef enum NPY_TYPES:
NPY_BOOL
NPY_BYTE
NPY_UBYTE
NPY_SHORT
NPY_USHORT
NPY_INT
NPY_UINT
NPY_LONG
NPY_ULONG
NPY_LONGLONG
NPY_ULONGLONG
NPY_FLOAT
NPY_DOUBLE
NPY_LONGDOUBLE
NPY_CFLOAT
NPY_CDOUBLE
NPY_CLONGDOUBLE
NPY_OBJECT
NPY_STRING
NPY_UNICODE
NPY_VOID
NPY_DATETIME
NPY_TIMEDELTA
NPY_NTYPES
NPY_NOTYPE
NPY_INT8
NPY_INT16
NPY_INT32
NPY_INT64
NPY_INT128
NPY_INT256
NPY_UINT8
NPY_UINT16
NPY_UINT32
NPY_UINT64
NPY_UINT128
NPY_UINT256
NPY_FLOAT16
NPY_FLOAT32
NPY_FLOAT64
NPY_FLOAT80
NPY_FLOAT96
NPY_FLOAT128
NPY_FLOAT256
NPY_COMPLEX32
NPY_COMPLEX64
NPY_COMPLEX128
NPY_COMPLEX160
NPY_COMPLEX192
NPY_COMPLEX256
NPY_COMPLEX512
NPY_INTP
ctypedef enum NPY_ORDER:
NPY_ANYORDER
NPY_CORDER
NPY_FORTRANORDER
NPY_KEEPORDER
ctypedef enum NPY_CASTING:
NPY_NO_CASTING
NPY_EQUIV_CASTING
NPY_SAFE_CASTING
NPY_SAME_KIND_CASTING
NPY_UNSAFE_CASTING
ctypedef enum NPY_CLIPMODE:
NPY_CLIP
NPY_WRAP
NPY_RAISE
ctypedef enum NPY_SCALARKIND:
NPY_NOSCALAR,
NPY_BOOL_SCALAR,
NPY_INTPOS_SCALAR,
NPY_INTNEG_SCALAR,
NPY_FLOAT_SCALAR,
NPY_COMPLEX_SCALAR,
NPY_OBJECT_SCALAR
ctypedef enum NPY_SORTKIND:
NPY_QUICKSORT
NPY_HEAPSORT
NPY_MERGESORT
ctypedef enum NPY_SEARCHSIDE:
NPY_SEARCHLEFT
NPY_SEARCHRIGHT
enum:
# DEPRECATED since NumPy 1.7 ! Do not use in new code!
NPY_C_CONTIGUOUS
NPY_F_CONTIGUOUS
NPY_CONTIGUOUS
NPY_FORTRAN
NPY_OWNDATA
NPY_FORCECAST
NPY_ENSURECOPY
NPY_ENSUREARRAY
NPY_ELEMENTSTRIDES
NPY_ALIGNED
NPY_NOTSWAPPED
NPY_WRITEABLE
NPY_UPDATEIFCOPY
NPY_ARR_HAS_DESCR
NPY_BEHAVED
NPY_BEHAVED_NS
NPY_CARRAY
NPY_CARRAY_RO
NPY_FARRAY
NPY_FARRAY_RO
NPY_DEFAULT
NPY_IN_ARRAY
NPY_OUT_ARRAY
NPY_INOUT_ARRAY
NPY_IN_FARRAY
NPY_OUT_FARRAY
NPY_INOUT_FARRAY
NPY_UPDATE_ALL
enum:
# Added in NumPy 1.7 to replace the deprecated enums above.
NPY_ARRAY_C_CONTIGUOUS
NPY_ARRAY_F_CONTIGUOUS
NPY_ARRAY_OWNDATA
NPY_ARRAY_FORCECAST
NPY_ARRAY_ENSURECOPY
NPY_ARRAY_ENSUREARRAY
NPY_ARRAY_ELEMENTSTRIDES
NPY_ARRAY_ALIGNED
NPY_ARRAY_NOTSWAPPED
NPY_ARRAY_WRITEABLE
NPY_ARRAY_UPDATEIFCOPY
NPY_ARRAY_BEHAVED
NPY_ARRAY_BEHAVED_NS
NPY_ARRAY_CARRAY
NPY_ARRAY_CARRAY_RO
NPY_ARRAY_FARRAY
NPY_ARRAY_FARRAY_RO
NPY_ARRAY_DEFAULT
NPY_ARRAY_IN_ARRAY
NPY_ARRAY_OUT_ARRAY
NPY_ARRAY_INOUT_ARRAY
NPY_ARRAY_IN_FARRAY
NPY_ARRAY_OUT_FARRAY
NPY_ARRAY_INOUT_FARRAY
NPY_ARRAY_UPDATE_ALL
cdef enum:
NPY_MAXDIMS
npy_intp NPY_MAX_ELSIZE
ctypedef void (*PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *, void *)
ctypedef struct PyArray_ArrayDescr:
# shape is a tuple, but Cython doesn't support "tuple shape"
# inside a non-PyObject declaration, so we have to declare it
# as just a PyObject*.
PyObject* shape
ctypedef struct PyArray_Descr:
pass
ctypedef class numpy.dtype [object PyArray_Descr, check_size ignore]:
# Use PyDataType_* macros when possible, however there are no macros
# for accessing some of the fields, so some are defined.
cdef PyTypeObject* typeobj
cdef char kind
cdef char type
# Numpy sometimes mutates this without warning (e.g. it'll
# sometimes change "|" to "<" in shared dtype objects on
# little-endian machines). If this matters to you, use
# PyArray_IsNativeByteOrder(dtype.byteorder) instead of
# directly accessing this field.
cdef char byteorder
cdef char flags
cdef int type_num
cdef int itemsize "elsize"
cdef int alignment
cdef dict fields
cdef tuple names
# Use PyDataType_HASSUBARRAY to test whether this field is
# valid (the pointer can be NULL). Most users should access
# this field via the inline helper method PyDataType_SHAPE.
cdef PyArray_ArrayDescr* subarray
ctypedef extern class numpy.flatiter [object PyArrayIterObject, check_size ignore]:
# Use through macros
pass
ctypedef extern class numpy.broadcast [object PyArrayMultiIterObject, check_size ignore]:
cdef int numiter
cdef npy_intp size, index
cdef int nd
cdef npy_intp *dimensions
cdef void **iters
ctypedef struct PyArrayObject:
# For use in situations where ndarray can't replace PyArrayObject*,
# like PyArrayObject**.
pass
ctypedef class numpy.ndarray [object PyArrayObject, check_size ignore]:
cdef __cythonbufferdefaults__ = {"mode": "strided"}
cdef:
# Only taking a few of the most commonly used and stable fields.
# One should use PyArray_* macros instead to access the C fields.
char *data
int ndim "nd"
npy_intp *shape "dimensions"
npy_intp *strides
dtype descr # deprecated since NumPy 1.7 !
PyObject* base # NOT PUBLIC, DO NOT USE !
ctypedef unsigned char npy_bool
ctypedef signed char npy_byte
ctypedef signed short npy_short
ctypedef signed int npy_int
ctypedef signed long npy_long
ctypedef signed long long npy_longlong
ctypedef unsigned char npy_ubyte
ctypedef unsigned short npy_ushort
ctypedef unsigned int npy_uint
ctypedef unsigned long npy_ulong
ctypedef unsigned long long npy_ulonglong
ctypedef float npy_float
ctypedef double npy_double
ctypedef long double npy_longdouble
ctypedef signed char npy_int8
ctypedef signed short npy_int16
ctypedef signed int npy_int32
ctypedef signed long long npy_int64
ctypedef signed long long npy_int96
ctypedef signed long long npy_int128
ctypedef unsigned char npy_uint8
ctypedef unsigned short npy_uint16
ctypedef unsigned int npy_uint32
ctypedef unsigned long long npy_uint64
ctypedef unsigned long long npy_uint96
ctypedef unsigned long long npy_uint128
ctypedef float npy_float32
ctypedef double npy_float64
ctypedef long double npy_float80
ctypedef long double npy_float96
ctypedef long double npy_float128
ctypedef struct npy_cfloat:
double real
double imag
ctypedef struct npy_cdouble:
double real
double imag
ctypedef struct npy_clongdouble:
long double real
long double imag
ctypedef struct npy_complex64:
float real
float imag
ctypedef struct npy_complex128:
double real
double imag
ctypedef struct npy_complex160:
long double real
long double imag
ctypedef struct npy_complex192:
long double real
long double imag
ctypedef struct npy_complex256:
long double real
long double imag
ctypedef struct PyArray_Dims:
npy_intp *ptr
int len
int _import_array() except -1
# A second definition so _import_array isn't marked as used when we use it here.
# Do not use - subject to change any time.
int __pyx_import_array "_import_array"() except -1
#
# Macros from ndarrayobject.h
#
bint PyArray_CHKFLAGS(ndarray m, int flags) nogil
bint PyArray_IS_C_CONTIGUOUS(ndarray arr) nogil
bint PyArray_IS_F_CONTIGUOUS(ndarray arr) nogil
Loading ...