codekingpro/portable-devtools
115k
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.
5#
6# Author: Dag Sverre Seljebotn
7#
8
9DEF _buffer_format_string_len = 255
10
11cimport cpython.buffer as pybuf
12from cpython.ref cimport Py_INCREF
13from cpython.mem cimport PyObject_Malloc, PyObject_Free
14from cpython.object cimport PyObject, PyTypeObject
15from cpython.buffer cimport PyObject_GetBuffer
16from cpython.type cimport type
17cimport libc.stdio as stdio
18
19
20cdef extern from *:
21 # Leave a marker that the NumPy declarations came from NumPy itself and not from Cython.
22 # See https://github.com/cython/cython/issues/3573
23 """
24 /* Using NumPy API declarations from "numpy/__init__.pxd" */
25 """
26
27
28cdef extern from "Python.h":
29 ctypedef int Py_intptr_t
30 bint PyObject_TypeCheck(object obj, PyTypeObject* type)
31
32cdef extern from "numpy/arrayobject.h":
33 # It would be nice to use size_t and ssize_t, but ssize_t has special
34 # implicit conversion rules, so just use "long".
35 # Note: The actual type only matters for Cython promotion, so long
36 # is closer than int, but could lead to incorrect promotion.
37 # (Not to worrying, and always the status-quo.)
38 ctypedef signed long npy_intp
39 ctypedef unsigned long npy_uintp
40
41 ctypedef unsigned char npy_bool
42
43 ctypedef signed char npy_byte
44 ctypedef signed short npy_short
45 ctypedef signed int npy_int
46 ctypedef signed long npy_long
47 ctypedef signed long long npy_longlong
48
49 ctypedef unsigned char npy_ubyte
50 ctypedef unsigned short npy_ushort
51 ctypedef unsigned int npy_uint
52 ctypedef unsigned long npy_ulong
53 ctypedef unsigned long long npy_ulonglong
54
55 ctypedef float npy_float
56 ctypedef double npy_double
57 ctypedef long double npy_longdouble
58
59 ctypedef signed char npy_int8
60 ctypedef signed short npy_int16
61 ctypedef signed int npy_int32
62 ctypedef signed long long npy_int64
63
64 ctypedef unsigned char npy_uint8
65 ctypedef unsigned short npy_uint16
66 ctypedef unsigned int npy_uint32
67 ctypedef unsigned long long npy_uint64
68
69 ctypedef float npy_float32
70 ctypedef double npy_float64
71 ctypedef long double npy_float80
72 ctypedef long double npy_float96
73 ctypedef long double npy_float128
74
75 ctypedef struct npy_cfloat:
76 pass
77
78 ctypedef struct npy_cdouble:
79 pass
80
81 ctypedef struct npy_clongdouble:
82 pass
83
84 ctypedef struct npy_complex64:
85 pass
86
87 ctypedef struct npy_complex128:
88 pass
89
90 ctypedef struct npy_complex160:
91 pass
92
93 ctypedef struct npy_complex192:
94 pass
95
96 ctypedef struct npy_complex256:
97 pass
98
99 ctypedef struct PyArray_Dims:
100 npy_intp *ptr
101 int len
102
103
104 cdef enum NPY_TYPES:
105 NPY_BOOL
106 NPY_BYTE
107 NPY_UBYTE
108 NPY_SHORT
109 NPY_USHORT
110 NPY_INT
111 NPY_UINT
112 NPY_LONG
113 NPY_ULONG
114 NPY_LONGLONG
115 NPY_ULONGLONG
116 NPY_FLOAT
117 NPY_DOUBLE
118 NPY_LONGDOUBLE
119 NPY_CFLOAT
120 NPY_CDOUBLE
121 NPY_CLONGDOUBLE
122 NPY_OBJECT
123 NPY_STRING
124 NPY_UNICODE
125 NPY_VSTRING
126 NPY_VOID
127 NPY_DATETIME
128 NPY_TIMEDELTA
129 NPY_NTYPES_LEGACY
130 NPY_NOTYPE
131
132 NPY_INT8
133 NPY_INT16
134 NPY_INT32
135 NPY_INT64
136 NPY_UINT8
137 NPY_UINT16
138 NPY_UINT32
139 NPY_UINT64
140 NPY_FLOAT16
141 NPY_FLOAT32
142 NPY_FLOAT64
143 NPY_FLOAT80
144 NPY_FLOAT96
145 NPY_FLOAT128
146 NPY_COMPLEX64
147 NPY_COMPLEX128
148 NPY_COMPLEX160
149 NPY_COMPLEX192
150 NPY_COMPLEX256
151
152 NPY_INTP
153 NPY_UINTP
154 NPY_DEFAULT_INT # Not a compile time constant (normally)!
155
156 ctypedef enum NPY_ORDER:
157 NPY_ANYORDER
158 NPY_CORDER
159 NPY_FORTRANORDER
160 NPY_KEEPORDER
161
162 ctypedef enum NPY_CASTING:
163 NPY_NO_CASTING
164 NPY_EQUIV_CASTING
165 NPY_SAFE_CASTING
166 NPY_SAME_KIND_CASTING
167 NPY_UNSAFE_CASTING
168 NPY_SAME_VALUE_CASTING
169
170 ctypedef enum NPY_CLIPMODE:
171 NPY_CLIP
172 NPY_WRAP
173 NPY_RAISE
174
175 ctypedef enum NPY_SCALARKIND:
176 NPY_NOSCALAR,
177 NPY_BOOL_SCALAR,
178 NPY_INTPOS_SCALAR,
179 NPY_INTNEG_SCALAR,
180 NPY_FLOAT_SCALAR,
181 NPY_COMPLEX_SCALAR,
182 NPY_OBJECT_SCALAR
183
184 ctypedef enum NPY_SORTKIND:
185 NPY_QUICKSORT
186 NPY_HEAPSORT
187 NPY_MERGESORT
188
189 ctypedef enum NPY_SEARCHSIDE:
190 NPY_SEARCHLEFT
191 NPY_SEARCHRIGHT
192
193 enum:
194 NPY_ARRAY_C_CONTIGUOUS
195 NPY_ARRAY_F_CONTIGUOUS
196 NPY_ARRAY_OWNDATA
197 NPY_ARRAY_FORCECAST
198 NPY_ARRAY_ENSURECOPY
199 NPY_ARRAY_ENSUREARRAY
200 NPY_ARRAY_ELEMENTSTRIDES
201 NPY_ARRAY_ALIGNED
202 NPY_ARRAY_NOTSWAPPED
203 NPY_ARRAY_WRITEABLE
204 NPY_ARRAY_WRITEBACKIFCOPY
205
206 NPY_ARRAY_BEHAVED
207 NPY_ARRAY_BEHAVED_NS
208 NPY_ARRAY_CARRAY
209 NPY_ARRAY_CARRAY_RO
210 NPY_ARRAY_FARRAY
211 NPY_ARRAY_FARRAY_RO
212 NPY_ARRAY_DEFAULT
213
214 NPY_ARRAY_IN_ARRAY
215 NPY_ARRAY_OUT_ARRAY
216 NPY_ARRAY_INOUT_ARRAY
217 NPY_ARRAY_IN_FARRAY
218 NPY_ARRAY_OUT_FARRAY
219 NPY_ARRAY_INOUT_FARRAY
220
221 NPY_ARRAY_UPDATE_ALL
222
223 cdef enum:
224 NPY_MAXDIMS # 64 on NumPy 2.x and 32 on NumPy 1.x
225 NPY_RAVEL_AXIS # Used for functions like PyArray_Mean
226
227 ctypedef void (*PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *, void *)
228
229 ctypedef struct PyArray_ArrayDescr:
230 # shape is a tuple, but Cython doesn't support "tuple shape"
231 # inside a non-PyObject declaration, so we have to declare it
232 # as just a PyObject*.
233 PyObject* shape
234
235 ctypedef struct PyArray_Descr:
236 pass
237
238 ctypedef class numpy.dtype [object PyArray_Descr, check_size ignore]:
239 # Use PyDataType_* macros when possible, however there are no macros
240 # for accessing some of the fields, so some are defined.
241 cdef PyTypeObject* typeobj
242 cdef char kind
243 cdef char type
244 # Numpy sometimes mutates this without warning (e.g. it'll
245 # sometimes change "|" to "<" in shared dtype objects on
246 # little-endian machines). If this matters to you, use
247 # PyArray_IsNativeByteOrder(dtype.byteorder) instead of
248 # directly accessing this field.
249 cdef char byteorder
250 # Flags are not directly accessible on Cython <3. Use PyDataType_FLAGS.
251 # cdef char flags
252 cdef int type_num
253 # itemsize/elsize, alignment, fields, names, and subarray must
254 # use the `PyDataType_*` accessor macros. With Cython 3 you can
255 # still use getter attributes `dtype.itemsize`
256
257 ctypedef class numpy.flatiter [object PyArrayIterObject, check_size ignore]:
258 # Use through macros
259 pass
260
261 ctypedef class numpy.broadcast [object PyArrayMultiIterObject, check_size ignore]:
262 cdef int numiter
263 cdef npy_intp size, index
264 cdef int nd
265 cdef npy_intp *dimensions
266 cdef void **iters
267
268 ctypedef struct PyArrayObject:
269 # For use in situations where ndarray can't replace PyArrayObject*,
270 # like PyArrayObject**.
271 pass
272
273 ctypedef class numpy.ndarray [object PyArrayObject, check_size ignore]:
274 cdef __cythonbufferdefaults__ = {"mode": "strided"}
275
276 cdef:
277 # Only taking a few of the most commonly used and stable fields.
278 # One should use PyArray_* macros instead to access the C fields.
279 char *data
280 int ndim "nd"
281 npy_intp *shape "dimensions"
282 npy_intp *strides
283 dtype descr # deprecated since NumPy 1.7 !
284 PyObject* base # NOT PUBLIC, DO NOT USE !
285
286
287 int _import_array() except -1
288 # A second definition so _import_array isn't marked as used when we use it here.
289 # Do not use - subject to change any time.
290 int __pyx_import_array "_import_array"() except -1
291
292 #
293 # Macros from ndarrayobject.h
294 #
295 bint PyArray_CHKFLAGS(ndarray m, int flags) nogil
296 bint PyArray_IS_C_CONTIGUOUS(ndarray arr) nogil
297 bint PyArray_IS_F_CONTIGUOUS(ndarray arr) nogil
298 bint PyArray_ISCONTIGUOUS(ndarray m) nogil
299 bint PyArray_ISWRITEABLE(ndarray m) nogil
300 bint PyArray_ISALIGNED(ndarray m) nogil
301
302 int PyArray_NDIM(ndarray) nogil
303 bint PyArray_ISONESEGMENT(ndarray) nogil
304 bint PyArray_ISFORTRAN(ndarray) nogil
305 int PyArray_FORTRANIF(ndarray) nogil
306
307 void* PyArray_DATA(ndarray) nogil
308 char* PyArray_BYTES(ndarray) nogil
309
310 npy_intp* PyArray_DIMS(ndarray) nogil
311 npy_intp* PyArray_STRIDES(ndarray) nogil
312 npy_intp PyArray_DIM(ndarray, size_t) nogil
313 npy_intp PyArray_STRIDE(ndarray, size_t) nogil
314
315 PyObject *PyArray_BASE(ndarray) nogil # returns borrowed reference!
316 PyArray_Descr *PyArray_DESCR(ndarray) nogil # returns borrowed reference to dtype!
317 PyArray_Descr *PyArray_DTYPE(ndarray) nogil # returns borrowed reference to dtype! NP 1.7+ alias for descr.
318 int PyArray_FLAGS(ndarray) nogil
319 void PyArray_CLEARFLAGS(ndarray, int flags) nogil # Added in NumPy 1.7
320 void PyArray_ENABLEFLAGS(ndarray, int flags) nogil # Added in NumPy 1.7
321 npy_intp PyArray_ITEMSIZE(ndarray) nogil
322 int PyArray_TYPE(ndarray arr) nogil
323
324 object PyArray_GETITEM(ndarray arr, void *itemptr)
325 int PyArray_SETITEM(ndarray arr, void *itemptr, object obj) except -1
326
327 bint PyTypeNum_ISBOOL(int) nogil
328 bint PyTypeNum_ISUNSIGNED(int) nogil
329 bint PyTypeNum_ISSIGNED(int) nogil
330 bint PyTypeNum_ISINTEGER(int) nogil
331 bint PyTypeNum_ISFLOAT(int) nogil
332 bint PyTypeNum_ISNUMBER(int) nogil
333 bint PyTypeNum_ISSTRING(int) nogil
334 bint PyTypeNum_ISCOMPLEX(int) nogil
335 bint PyTypeNum_ISFLEXIBLE(int) nogil
336 bint PyTypeNum_ISUSERDEF(int) nogil
337 bint PyTypeNum_ISEXTENDED(int) nogil
338 bint PyTypeNum_ISOBJECT(int) nogil
339
340 npy_intp PyDataType_ELSIZE(dtype) nogil
341 npy_intp PyDataType_ALIGNMENT(dtype) nogil
342 PyObject* PyDataType_METADATA(dtype) nogil
343 PyArray_ArrayDescr* PyDataType_SUBARRAY(dtype) nogil
344 PyObject* PyDataType_NAMES(dtype) nogil
345 PyObject* PyDataType_FIELDS(dtype) nogil
346
347 bint PyDataType_ISBOOL(dtype) nogil
348 bint PyDataType_ISUNSIGNED(dtype) nogil
349 bint PyDataType_ISSIGNED(dtype) nogil
350 bint PyDataType_ISINTEGER(dtype) nogil
351 bint PyDataType_ISFLOAT(dtype) nogil
352 bint PyDataType_ISNUMBER(dtype) nogil
353 bint PyDataType_ISSTRING(dtype) nogil
354 bint PyDataType_ISCOMPLEX(dtype) nogil
355 bint PyDataType_ISFLEXIBLE(dtype) nogil
356 bint PyDataType_ISUSERDEF(dtype) nogil
357 bint PyDataType_ISEXTENDED(dtype) nogil
358 bint PyDataType_ISOBJECT(dtype) nogil
359 bint PyDataType_HASFIELDS(dtype) nogil
360 bint PyDataType_HASSUBARRAY(dtype) nogil
361 npy_uint64 PyDataType_FLAGS(dtype) nogil
362
363 bint PyArray_ISBOOL(ndarray) nogil
364 bint PyArray_ISUNSIGNED(ndarray) nogil
365 bint PyArray_ISSIGNED(ndarray) nogil
366 bint PyArray_ISINTEGER(ndarray) nogil
367 bint PyArray_ISFLOAT(ndarray) nogil
368 bint PyArray_ISNUMBER(ndarray) nogil
369 bint PyArray_ISSTRING(ndarray) nogil
370 bint PyArray_ISCOMPLEX(ndarray) nogil
371 bint PyArray_ISFLEXIBLE(ndarray) nogil
372 bint PyArray_ISUSERDEF(ndarray) nogil
373 bint PyArray_ISEXTENDED(ndarray) nogil
374 bint PyArray_ISOBJECT(ndarray) nogil
375 bint PyArray_HASFIELDS(ndarray) nogil
376
377 bint PyArray_ISVARIABLE(ndarray) nogil
378
379 bint PyArray_SAFEALIGNEDCOPY(ndarray) nogil
380 bint PyArray_ISNBO(char) nogil # works on ndarray.byteorder
381 bint PyArray_IsNativeByteOrder(char) nogil # works on ndarray.byteorder
382 bint PyArray_ISNOTSWAPPED(ndarray) nogil
383 bint PyArray_ISBYTESWAPPED(ndarray) nogil
384
385 bint PyArray_FLAGSWAP(ndarray, int) nogil
386
387 bint PyArray_ISCARRAY(ndarray) nogil
388 bint PyArray_ISCARRAY_RO(ndarray) nogil
389 bint PyArray_ISFARRAY(ndarray) nogil
390 bint PyArray_ISFARRAY_RO(ndarray) nogil
391 bint PyArray_ISBEHAVED(ndarray) nogil
392 bint PyArray_ISBEHAVED_RO(ndarray) nogil
393
394
395 bint PyDataType_ISNOTSWAPPED(dtype) nogil
396 bint PyDataType_ISBYTESWAPPED(dtype) nogil
397
398 bint PyArray_DescrCheck(object)
399
400 bint PyArray_Check(object)
401 bint PyArray_CheckExact(object)
402
403 # Cannot be supported due to out arg:
404 # bint PyArray_HasArrayInterfaceType(object, dtype, object, object&)
405 # bint PyArray_HasArrayInterface(op, out)
406
407
408 bint PyArray_IsZeroDim(object)
409 # Cannot be supported due to ## ## in macro:
410 # bint PyArray_IsScalar(object, verbatim work)
411 bint PyArray_CheckScalar(object)
412 bint PyArray_IsPythonNumber(object)
413 bint PyArray_IsPythonScalar(object)
414 bint PyArray_IsAnyScalar(object)
415 bint PyArray_CheckAnyScalar(object)
416
417 ndarray PyArray_GETCONTIGUOUS(ndarray)
418 bint PyArray_SAMESHAPE(ndarray, ndarray) nogil
419 npy_intp PyArray_SIZE(ndarray) nogil
420 npy_intp PyArray_NBYTES(ndarray) nogil
421
422 object PyArray_FROM_O(object)
423 object PyArray_FROM_OF(object m, int flags)
424 object PyArray_FROM_OT(object m, int type)
425 object PyArray_FROM_OTF(object m, int type, int flags)
426 object PyArray_FROMANY(object m, int type, int min, int max, int flags)
427 object PyArray_ZEROS(int nd, npy_intp* dims, int type, int fortran)
428 object PyArray_EMPTY(int nd, npy_intp* dims, int type, int fortran)
429 void PyArray_FILLWBYTE(ndarray, int val)
430 object PyArray_ContiguousFromAny(op, int, int min_depth, int max_depth)
431 unsigned char PyArray_EquivArrTypes(ndarray a1, ndarray a2)
432 bint PyArray_EquivByteorders(int b1, int b2) nogil
433 object PyArray_SimpleNew(int nd, npy_intp* dims, int typenum)
434 object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int typenum, void* data)
435 #object PyArray_SimpleNewFromDescr(int nd, npy_intp* dims, dtype descr)
436 object PyArray_ToScalar(void* data, ndarray arr)
437
438 void* PyArray_GETPTR1(ndarray m, npy_intp i) nogil
439 void* PyArray_GETPTR2(ndarray m, npy_intp i, npy_intp j) nogil
440 void* PyArray_GETPTR3(ndarray m, npy_intp i, npy_intp j, npy_intp k) nogil
441 void* PyArray_GETPTR4(ndarray m, npy_intp i, npy_intp j, npy_intp k, npy_intp l) nogil
442
443 # Cannot be supported due to out arg
444 # void PyArray_DESCR_REPLACE(descr)
445
446
447 object PyArray_Copy(ndarray)
448 object PyArray_FromObject(object op, int type, int min_depth, int max_depth)
449 object PyArray_ContiguousFromObject(object op, int type, int min_depth, int max_depth)
450 object PyArray_CopyFromObject(object op, int type, int min_depth, int max_depth)
451
452 object PyArray_Cast(ndarray mp, int type_num)
453 object PyArray_Take(ndarray ap, object items, int axis)
454 object PyArray_Put(ndarray ap, object items, object values)
455
456 void PyArray_ITER_RESET(flatiter it) nogil
457 void PyArray_ITER_NEXT(flatiter it) nogil
458 void PyArray_ITER_GOTO(flatiter it, npy_intp* destination) nogil
459 void PyArray_ITER_GOTO1D(flatiter it, npy_intp ind) nogil
460 void* PyArray_ITER_DATA(flatiter it) nogil
461 bint PyArray_ITER_NOTDONE(flatiter it) nogil
462
463 void PyArray_MultiIter_RESET(broadcast multi) nogil
464 void PyArray_MultiIter_NEXT(broadcast multi) nogil
465 void PyArray_MultiIter_GOTO(broadcast multi, npy_intp dest) nogil
466 void PyArray_MultiIter_GOTO1D(broadcast multi, npy_intp ind) nogil
467 void* PyArray_MultiIter_DATA(broadcast multi, npy_intp i) nogil
468 void PyArray_MultiIter_NEXTi(broadcast multi, npy_intp i) nogil
469 bint PyArray_MultiIter_NOTDONE(broadcast multi) nogil
470 npy_intp PyArray_MultiIter_SIZE(broadcast multi) nogil
471 int PyArray_MultiIter_NDIM(broadcast multi) nogil
472 npy_intp PyArray_MultiIter_INDEX(broadcast multi) nogil
473 int PyArray_MultiIter_NUMITER(broadcast multi) nogil
474 npy_intp* PyArray_MultiIter_DIMS(broadcast multi) nogil
475 void** PyArray_MultiIter_ITERS(broadcast multi) nogil
476
477 # Functions from __multiarray_api.h
478
479 # Functions taking dtype and returning object/ndarray are disabled
480 # for now as they steal dtype references. I'm conservative and disable
481 # more than is probably needed until it can be checked further.
482 int PyArray_INCREF (ndarray) except * # uses PyArray_Item_INCREF...
483 int PyArray_XDECREF (ndarray) except * # uses PyArray_Item_DECREF...
484 dtype PyArray_DescrFromType (int)
485 object PyArray_TypeObjectFromType (int)
486 char * PyArray_Zero (ndarray)
487 char * PyArray_One (ndarray)
488 #object PyArray_CastToType (ndarray, dtype, int)
489 int PyArray_CanCastSafely (int, int) # writes errors
490 npy_bool PyArray_CanCastTo (dtype, dtype) # writes errors
491 int PyArray_ObjectType (object, int) except 0
492 dtype PyArray_DescrFromObject (object, dtype)
493 #ndarray* PyArray_ConvertToCommonType (object, int *)
494 dtype PyArray_DescrFromScalar (object)
495 dtype PyArray_DescrFromTypeObject (object)
496 npy_intp PyArray_Size (object)
497 #object PyArray_Scalar (void *, dtype, object)
498 #object PyArray_FromScalar (object, dtype)
499 void PyArray_ScalarAsCtype (object, void *)
500 #int PyArray_CastScalarToCtype (object, void *, dtype)
501 #int PyArray_CastScalarDirect (object, dtype, void *, int)
502 #PyArray_VectorUnaryFunc * PyArray_GetCastFunc (dtype, int)
503 #object PyArray_FromAny (object, dtype, int, int, int, object)
504 object PyArray_EnsureArray (object)
505 object PyArray_EnsureAnyArray (object)
506 #object PyArray_FromFile (stdio.FILE *, dtype, npy_intp, char *)
507 #object PyArray_FromString (char *, npy_intp, dtype, npy_intp, char *)
508 #object PyArray_FromBuffer (object, dtype, npy_intp, npy_intp)
509 #object PyArray_FromIter (object, dtype, npy_intp)
510 object PyArray_Return (ndarray)
511 #object PyArray_GetField (ndarray, dtype, int)
512 #int PyArray_SetField (ndarray, dtype, int, object) except -1
513 object PyArray_Byteswap (ndarray, npy_bool)
514 object PyArray_Resize (ndarray, PyArray_Dims *, int, NPY_ORDER)
515 int PyArray_CopyInto (ndarray, ndarray) except -1
516 int PyArray_CopyAnyInto (ndarray, ndarray) except -1
517 int PyArray_CopyObject (ndarray, object) except -1
518 object PyArray_NewCopy (ndarray, NPY_ORDER)
519 object PyArray_ToList (ndarray)
520 object PyArray_ToString (ndarray, NPY_ORDER)
521 int PyArray_ToFile (ndarray, stdio.FILE *, char *, char *) except -1
522 int PyArray_Dump (object, object, int) except -1
523 object PyArray_Dumps (object, int)
524 int PyArray_ValidType (int) # Cannot error
525 void PyArray_UpdateFlags (ndarray, int)
526 object PyArray_New (type, int, npy_intp *, int, npy_intp *, void *, int, int, object)
527 #object PyArray_NewFromDescr (type, dtype, int, npy_intp *, npy_intp *, void *, int, object)
528 #dtype PyArray_DescrNew (dtype)
529 dtype PyArray_DescrNewFromType (int)
530 double PyArray_GetPriority (object, double) # clears errors as of 1.25
531 object PyArray_IterNew (object)
532 object PyArray_MultiIterNew (int, ...)
533
534 int PyArray_PyIntAsInt (object) except? -1
535 npy_intp PyArray_PyIntAsIntp (object)
536 int PyArray_Broadcast (broadcast) except -1
537 int PyArray_FillWithScalar (ndarray, object) except -1
538 npy_bool PyArray_CheckStrides (int, int, npy_intp, npy_intp, npy_intp *, npy_intp *)
539 dtype PyArray_DescrNewByteorder (dtype, char)
540 object PyArray_IterAllButAxis (object, int *)
541 #object PyArray_CheckFromAny (object, dtype, int, int, int, object)
542 #object PyArray_FromArray (ndarray, dtype, int)
543 object PyArray_FromInterface (object)
544 object PyArray_FromStructInterface (object)
545 #object PyArray_FromArrayAttr (object, dtype, object)
546 #NPY_SCALARKIND PyArray_ScalarKind (int, ndarray*)
547 int PyArray_CanCoerceScalar (int, int, NPY_SCALARKIND)
548 npy_bool PyArray_CanCastScalar (type, type)
549 int PyArray_RemoveSmallest (broadcast) except -1
550 int PyArray_ElementStrides (object)
551 void PyArray_Item_INCREF (char *, dtype) except *
552 void PyArray_Item_XDECREF (char *, dtype) except *
553 object PyArray_Transpose (ndarray, PyArray_Dims *)
554 object PyArray_TakeFrom (ndarray, object, int, ndarray, NPY_CLIPMODE)
555 object PyArray_PutTo (ndarray, object, object, NPY_CLIPMODE)
556 object PyArray_PutMask (ndarray, object, object)
557 object PyArray_Repeat (ndarray, object, int)
558 object PyArray_Choose (ndarray, object, ndarray, NPY_CLIPMODE)
559 int PyArray_Sort (ndarray, int, NPY_SORTKIND) except -1
560 object PyArray_ArgSort (ndarray, int, NPY_SORTKIND)
561 object PyArray_SearchSorted (ndarray, object, NPY_SEARCHSIDE, PyObject *)
562 object PyArray_ArgMax (ndarray, int, ndarray)
563 object PyArray_ArgMin (ndarray, int, ndarray)
564 object PyArray_Reshape (ndarray, object)
565 object PyArray_Newshape (ndarray, PyArray_Dims *, NPY_ORDER)
566 object PyArray_Squeeze (ndarray)
567 #object PyArray_View (ndarray, dtype, type)
568 object PyArray_SwapAxes (ndarray, int, int)
569 object PyArray_Max (ndarray, int, ndarray)
570 object PyArray_Min (ndarray, int, ndarray)
571 object PyArray_Ptp (ndarray, int, ndarray)
572 object PyArray_Mean (ndarray, int, int, ndarray)
573 object PyArray_Trace (ndarray, int, int, int, int, ndarray)
574 object PyArray_Diagonal (ndarray, int, int, int)
575 object PyArray_Clip (ndarray, object, object, ndarray)
576 object PyArray_Conjugate (ndarray, ndarray)
577 object PyArray_Nonzero (ndarray)
578 object PyArray_Std (ndarray, int, int, ndarray, int)
579 object PyArray_Sum (ndarray, int, int, ndarray)
580 object PyArray_CumSum (ndarray, int, int, ndarray)
581 object PyArray_Prod (ndarray, int, int, ndarray)
582 object PyArray_CumProd (ndarray, int, int, ndarray)
583 object PyArray_All (ndarray, int, ndarray)
584 object PyArray_Any (ndarray, int, ndarray)
585 object PyArray_Compress (ndarray, object, int, ndarray)
586 object PyArray_Flatten (ndarray, NPY_ORDER)
587 object PyArray_Ravel (ndarray, NPY_ORDER)
588 npy_intp PyArray_MultiplyList (npy_intp *, int)
589 int PyArray_MultiplyIntList (int *, int)
590 void * PyArray_GetPtr (ndarray, npy_intp*)
591 int PyArray_CompareLists (npy_intp *, npy_intp *, int)
592 #int PyArray_AsCArray (object*, void *, npy_intp *, int, dtype)
593 int PyArray_Free (object, void *)
594 #int PyArray_Converter (object, object*)
595 int PyArray_IntpFromSequence (object, npy_intp *, int) except -1
596 object PyArray_Concatenate (object, int)
597 object PyArray_InnerProduct (object, object)
598 object PyArray_MatrixProduct (object, object)
599 object PyArray_Correlate (object, object, int)
600 #int PyArray_DescrConverter (object, dtype*) except 0
601 #int PyArray_DescrConverter2 (object, dtype*) except 0
602 int PyArray_IntpConverter (object, PyArray_Dims *) except 0
603 #int PyArray_BufferConverter (object, chunk) except 0
604 int PyArray_AxisConverter (object, int *) except 0
605 int PyArray_BoolConverter (object, npy_bool *) except 0
606 int PyArray_ByteorderConverter (object, char *) except 0
607 int PyArray_OrderConverter (object, NPY_ORDER *) except 0
608 unsigned char PyArray_EquivTypes (dtype, dtype) # clears errors
609 #object PyArray_Zeros (int, npy_intp *, dtype, int)
610 #object PyArray_Empty (int, npy_intp *, dtype, int)
611 object PyArray_Where (object, object, object)
612 object PyArray_Arange (double, double, double, int)
613 #object PyArray_ArangeObj (object, object, object, dtype)
614 int PyArray_SortkindConverter (object, NPY_SORTKIND *) except 0
615 object PyArray_LexSort (object, int)
616 object PyArray_Round (ndarray, int, ndarray)
617 unsigned char PyArray_EquivTypenums (int, int)
618 int PyArray_RegisterDataType (dtype) except -1
619 int PyArray_RegisterCastFunc (dtype, int, PyArray_VectorUnaryFunc *) except -1
620 int PyArray_RegisterCanCast (dtype, int, NPY_SCALARKIND) except -1
621 #void PyArray_InitArrFuncs (PyArray_ArrFuncs *)
622 object PyArray_IntTupleFromIntp (int, npy_intp *)
623 int PyArray_ClipmodeConverter (object, NPY_CLIPMODE *) except 0
624 #int PyArray_OutputConverter (object, ndarray*) except 0
625 object PyArray_BroadcastToShape (object, npy_intp *, int)
626 #int PyArray_DescrAlignConverter (object, dtype*) except 0
627 #int PyArray_DescrAlignConverter2 (object, dtype*) except 0
628 int PyArray_SearchsideConverter (object, void *) except 0
629 object PyArray_CheckAxis (ndarray, int *, int)
630 npy_intp PyArray_OverflowMultiplyList (npy_intp *, int)
631 int PyArray_SetBaseObject(ndarray, base) except -1 # NOTE: steals a reference to base! Use "set_array_base()" instead.
632
633 # The memory handler functions require the NumPy 1.22 API
634 # and may require defining NPY_TARGET_VERSION
635 ctypedef struct PyDataMemAllocator:
636 void *ctx
637 void* (*malloc) (void *ctx, size_t size)
638 void* (*calloc) (void *ctx, size_t nelem, size_t elsize)
639 void* (*realloc) (void *ctx, void *ptr, size_t new_size)
640 void (*free) (void *ctx, void *ptr, size_t size)
641
642 ctypedef struct PyDataMem_Handler:
643 char* name
644 npy_uint8 version
645 PyDataMemAllocator allocator
646
647 object PyDataMem_SetHandler(object handler)
648 object PyDataMem_GetHandler()
649
650 # additional datetime related functions are defined below
651
652
653# Typedefs that matches the runtime dtype objects in
654# the numpy module.
655
656# The ones that are commented out needs an IFDEF function
657# in Cython to enable them only on the right systems.
658
659ctypedef npy_int8 int8_t
660ctypedef npy_int16 int16_t
661ctypedef npy_int32 int32_t
662ctypedef npy_int64 int64_t
663
664ctypedef npy_uint8 uint8_t
665ctypedef npy_uint16 uint16_t
666ctypedef npy_uint32 uint32_t
667ctypedef npy_uint64 uint64_t
668
669ctypedef npy_float32 float32_t
670ctypedef npy_float64 float64_t
671#ctypedef npy_float80 float80_t
672#ctypedef npy_float128 float128_t
673
674ctypedef float complex complex64_t
675ctypedef double complex complex128_t
676
677ctypedef npy_longlong longlong_t
678ctypedef npy_ulonglong ulonglong_t
679
680ctypedef npy_intp intp_t
681ctypedef npy_uintp uintp_t
682
683ctypedef npy_double float_t
684ctypedef npy_double double_t
685ctypedef npy_longdouble longdouble_t
686
687ctypedef float complex cfloat_t
688ctypedef double complex cdouble_t
689ctypedef double complex complex_t
690ctypedef long double complex clongdouble_t
691
692cdef inline object PyArray_MultiIterNew1(a):
693 return PyArray_MultiIterNew(1, <void*>a)
694
695cdef inline object PyArray_MultiIterNew2(a, b):
696 return PyArray_MultiIterNew(2, <void*>a, <void*>b)
697
698cdef inline object PyArray_MultiIterNew3(a, b, c):
699 return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
700
701cdef inline object PyArray_MultiIterNew4(a, b, c, d):
702 return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
703
704cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
705 return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
706
707cdef inline tuple PyDataType_SHAPE(dtype d):
708 if PyDataType_HASSUBARRAY(d):
709 return <tuple>d.subarray.shape
710 else:
711 return ()
712
713
714cdef extern from "numpy/ndarrayobject.h":
715 PyTypeObject PyTimedeltaArrType_Type
716 PyTypeObject PyDatetimeArrType_Type
717 ctypedef int64_t npy_timedelta
718 ctypedef int64_t npy_datetime
719
720cdef extern from "numpy/ndarraytypes.h":
721 ctypedef struct PyArray_DatetimeMetaData:
722 NPY_DATETIMEUNIT base
723 int64_t num
724
725 ctypedef struct npy_datetimestruct:
726 int64_t year
727 int32_t month, day, hour, min, sec, us, ps, as
728
729 # Iterator API added in v1.6
730 #
731 # These don't match the definition in the C API because Cython can't wrap
732 # function pointers that return functions.
733 # https://github.com/cython/cython/issues/6720
734 ctypedef int (*NpyIter_IterNextFunc "NpyIter_IterNextFunc *")(NpyIter* it) noexcept nogil
735 ctypedef void (*NpyIter_GetMultiIndexFunc "NpyIter_GetMultiIndexFunc *")(NpyIter* it, npy_intp* outcoords) noexcept nogil
736
737cdef extern from "numpy/arrayscalars.h":
738
739 # abstract types
740 ctypedef class numpy.generic [object PyObject]:
741 pass
742 ctypedef class numpy.number [object PyObject]:
743 pass
744 ctypedef class numpy.integer [object PyObject]:
745 pass
746 ctypedef class numpy.signedinteger [object PyObject]:
747 pass
748 ctypedef class numpy.unsignedinteger [object PyObject]:
749 pass
750 ctypedef class numpy.inexact [object PyObject]:
751 pass
752 ctypedef class numpy.floating [object PyObject]:
753 pass
754 ctypedef class numpy.complexfloating [object PyObject]:
755 pass
756 ctypedef class numpy.flexible [object PyObject]:
757 pass
758 ctypedef class numpy.character [object PyObject]:
759 pass
760
761 ctypedef struct PyDatetimeScalarObject:
762 # PyObject_HEAD
763 npy_datetime obval
764 PyArray_DatetimeMetaData obmeta
765
766 ctypedef struct PyTimedeltaScalarObject:
767 # PyObject_HEAD
768 npy_timedelta obval
769 PyArray_DatetimeMetaData obmeta
770
771 ctypedef enum NPY_DATETIMEUNIT:
772 NPY_FR_Y
773 NPY_FR_M
774 NPY_FR_W
775 NPY_FR_D
776 NPY_FR_B
777 NPY_FR_h
778 NPY_FR_m
779 NPY_FR_s
780 NPY_FR_ms
781 NPY_FR_us
782 NPY_FR_ns
783 NPY_FR_ps
784 NPY_FR_fs
785 NPY_FR_as
786 NPY_FR_GENERIC
787
788
789cdef extern from "numpy/arrayobject.h":
790 # These are part of the C-API defined in `__multiarray_api.h`
791
792 # NumPy internal definitions in datetime_strings.c:
793 int get_datetime_iso_8601_strlen "NpyDatetime_GetDatetimeISO8601StrLen" (
794 int local, NPY_DATETIMEUNIT base)
795 int make_iso_8601_datetime "NpyDatetime_MakeISO8601Datetime" (
796 npy_datetimestruct *dts, char *outstr, npy_intp outlen,
797 int local, int utc, NPY_DATETIMEUNIT base, int tzoffset,
798 NPY_CASTING casting) except -1
799
800 # NumPy internal definition in datetime.c:
801 # May return 1 to indicate that object does not appear to be a datetime
802 # (returns 0 on success).
803 int convert_pydatetime_to_datetimestruct "NpyDatetime_ConvertPyDateTimeToDatetimeStruct" (
804 PyObject *obj, npy_datetimestruct *out,
805 NPY_DATETIMEUNIT *out_bestunit, int apply_tzinfo) except -1
806 int convert_datetime64_to_datetimestruct "NpyDatetime_ConvertDatetime64ToDatetimeStruct" (
807 PyArray_DatetimeMetaData *meta, npy_datetime dt,
808 npy_datetimestruct *out) except -1
809 int convert_datetimestruct_to_datetime64 "NpyDatetime_ConvertDatetimeStructToDatetime64"(
810 PyArray_DatetimeMetaData *meta, const npy_datetimestruct *dts,
811 npy_datetime *out) except -1
812
813
814#
815# ufunc API
816#
817
818cdef extern from "numpy/ufuncobject.h":
819
820 ctypedef void (*PyUFuncGenericFunction) (char **, npy_intp *, npy_intp *, void *)
821
822 ctypedef class numpy.ufunc [object PyUFuncObject, check_size ignore]:
823 cdef:
824 int nin, nout, nargs
825 int identity
826 PyUFuncGenericFunction *functions
827 void **data
828 int ntypes
829 int check_return
830 char *name
831 char *types
832 char *doc
833 void *ptr
834 PyObject *obj
835 PyObject *userloops
836
837 cdef enum:
838 PyUFunc_Zero
839 PyUFunc_One
840 PyUFunc_None
841 # deprecated
842 UFUNC_FPE_DIVIDEBYZERO
843 UFUNC_FPE_OVERFLOW
844 UFUNC_FPE_UNDERFLOW
845 UFUNC_FPE_INVALID
846 # use these instead
847 NPY_FPE_DIVIDEBYZERO
848 NPY_FPE_OVERFLOW
849 NPY_FPE_UNDERFLOW
850 NPY_FPE_INVALID
851
852 object PyUFunc_FromFuncAndData(PyUFuncGenericFunction *,
853 void **, char *, int, int, int, int, char *, char *, int)
854 int PyUFunc_RegisterLoopForType(ufunc, int,
855 PyUFuncGenericFunction, int *, void *) except -1
856 void PyUFunc_f_f_As_d_d \
857 (char **, npy_intp *, npy_intp *, void *)
858 void PyUFunc_d_d \
859 (char **, npy_intp *, npy_intp *, void *)
860 void PyUFunc_f_f \
861 (char **, npy_intp *, npy_intp *, void *)
862 void PyUFunc_g_g \
863 (char **, npy_intp *, npy_intp *, void *)
864 void PyUFunc_F_F_As_D_D \
865 (char **, npy_intp *, npy_intp *, void *)
866 void PyUFunc_F_F \
867 (char **, npy_intp *, npy_intp *, void *)
868 void PyUFunc_D_D \
869 (char **, npy_intp *, npy_intp *, void *)
870 void PyUFunc_G_G \
871 (char **, npy_intp *, npy_intp *, void *)
872 void PyUFunc_O_O \
873 (char **, npy_intp *, npy_intp *, void *)
874 void PyUFunc_ff_f_As_dd_d \
875 (char **, npy_intp *, npy_intp *, void *)
876 void PyUFunc_ff_f \
877 (char **, npy_intp *, npy_intp *, void *)
878 void PyUFunc_dd_d \
879 (char **, npy_intp *, npy_intp *, void *)
880 void PyUFunc_gg_g \
881 (char **, npy_intp *, npy_intp *, void *)
882 void PyUFunc_FF_F_As_DD_D \
883 (char **, npy_intp *, npy_intp *, void *)
884 void PyUFunc_DD_D \
885 (char **, npy_intp *, npy_intp *, void *)
886 void PyUFunc_FF_F \
887 (char **, npy_intp *, npy_intp *, void *)
888 void PyUFunc_GG_G \
889 (char **, npy_intp *, npy_intp *, void *)
890 void PyUFunc_OO_O \
891 (char **, npy_intp *, npy_intp *, void *)
892 void PyUFunc_O_O_method \
893 (char **, npy_intp *, npy_intp *, void *)
894 void PyUFunc_OO_O_method \
895 (char **, npy_intp *, npy_intp *, void *)
896 void PyUFunc_On_Om \
897 (char **, npy_intp *, npy_intp *, void *)
898 void PyUFunc_clearfperr()
899 int PyUFunc_getfperr()
900 int PyUFunc_ReplaceLoopBySignature \
901 (ufunc, PyUFuncGenericFunction, int *, PyUFuncGenericFunction *)
902 object PyUFunc_FromFuncAndDataAndSignature \
903 (PyUFuncGenericFunction *, void **, char *, int, int, int,
904 int, char *, char *, int, char *)
905
906 int _import_umath() except -1
907
908cdef inline void set_array_base(ndarray arr, object base):
909 Py_INCREF(base) # important to do this before stealing the reference below!
910 PyArray_SetBaseObject(arr, base)
911
912cdef inline object get_array_base(ndarray arr):
913 base = PyArray_BASE(arr)
914 if base is NULL:
915 return None
916 return <object>base
917
918# Versions of the import_* functions which are more suitable for
919# Cython code.
920cdef inline int import_array() except -1:
921 try:
922 __pyx_import_array()
923 except Exception:
924 raise ImportError("numpy._core.multiarray failed to import")
925
926cdef inline int import_umath() except -1:
927 try:
928 _import_umath()
929 except Exception:
930 raise ImportError("numpy._core.umath failed to import")
931
932cdef inline int import_ufunc() except -1:
933 try:
934 _import_umath()
935 except Exception:
936 raise ImportError("numpy._core.umath failed to import")
937
938
939cdef inline bint is_timedelta64_object(object obj):
940 """
941 Cython equivalent of `isinstance(obj, np.timedelta64)`
942
943 Parameters
944 ----------
945 obj : object
946
947 Returns
948 -------
949 bool
950 """
951 return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type)
952
953
954cdef inline bint is_datetime64_object(object obj):
955 """
956 Cython equivalent of `isinstance(obj, np.datetime64)`
957
958 Parameters
959 ----------
960 obj : object
961
962 Returns
963 -------
964 bool
965 """
966 return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type)
967
968
969cdef inline npy_datetime get_datetime64_value(object obj) nogil:
970 """
971 returns the int64 value underlying scalar numpy datetime64 object
972
973 Note that to interpret this as a datetime, the corresponding unit is
974 also needed. That can be found using `get_datetime64_unit`.
975 """
976 return (<PyDatetimeScalarObject*>obj).obval
977
978
979cdef inline npy_timedelta get_timedelta64_value(object obj) nogil:
980 """
981 returns the int64 value underlying scalar numpy timedelta64 object
982 """
983 return (<PyTimedeltaScalarObject*>obj).obval
984
985
986cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil:
987 """
988 returns the unit part of the dtype for a numpy datetime64 object.
989 """
990 return <NPY_DATETIMEUNIT>(<PyDatetimeScalarObject*>obj).obmeta.base
991
992
993cdef extern from "numpy/arrayobject.h":
994
995 ctypedef struct NpyIter:
996 pass
997
998 cdef enum:
999 NPY_FAIL
1000 NPY_SUCCEED
1001
1002 cdef enum:
1003 # Track an index representing C order
1004 NPY_ITER_C_INDEX
1005 # Track an index representing Fortran order
1006 NPY_ITER_F_INDEX
1007 # Track a multi-index
1008 NPY_ITER_MULTI_INDEX
1009 # User code external to the iterator does the 1-dimensional innermost loop
1010 NPY_ITER_EXTERNAL_LOOP
1011 # Convert all the operands to a common data type
1012 NPY_ITER_COMMON_DTYPE
1013 # Operands may hold references, requiring API access during iteration
1014 NPY_ITER_REFS_OK
1015 # Zero-sized operands should be permitted, iteration checks IterSize for 0
1016 NPY_ITER_ZEROSIZE_OK
1017 # Permits reductions (size-0 stride with dimension size > 1)
1018 NPY_ITER_REDUCE_OK
1019 # Enables sub-range iteration
1020 NPY_ITER_RANGED
1021 # Enables buffering
1022 NPY_ITER_BUFFERED
1023 # When buffering is enabled, grows the inner loop if possible
1024 NPY_ITER_GROWINNER
1025 # Delay allocation of buffers until first Reset* call
1026 NPY_ITER_DELAY_BUFALLOC
1027 # When NPY_KEEPORDER is specified, disable reversing negative-stride axes
1028 NPY_ITER_DONT_NEGATE_STRIDES
1029 NPY_ITER_COPY_IF_OVERLAP
1030 # The operand will be read from and written to
1031 NPY_ITER_READWRITE
1032 # The operand will only be read from
1033 NPY_ITER_READONLY
1034 # The operand will only be written to
1035 NPY_ITER_WRITEONLY
1036 # The operand's data must be in native byte order
1037 NPY_ITER_NBO
1038 # The operand's data must be aligned
1039 NPY_ITER_ALIGNED
1040 # The operand's data must be contiguous (within the inner loop)
1041 NPY_ITER_CONTIG
1042 # The operand may be copied to satisfy requirements
1043 NPY_ITER_COPY
1044 # The operand may be copied with WRITEBACKIFCOPY to satisfy requirements
1045 NPY_ITER_UPDATEIFCOPY
1046 # Allocate the operand if it is NULL
1047 NPY_ITER_ALLOCATE
1048 # If an operand is allocated, don't use any subtype
1049 NPY_ITER_NO_SUBTYPE
1050 # This is a virtual array slot, operand is NULL but temporary data is there
1051 NPY_ITER_VIRTUAL
1052 # Require that the dimension match the iterator dimensions exactly
1053 NPY_ITER_NO_BROADCAST
1054 # A mask is being used on this array, affects buffer -> array copy
1055 NPY_ITER_WRITEMASKED
1056 # This array is the mask for all WRITEMASKED operands
1057 NPY_ITER_ARRAYMASK
1058 # Assume iterator order data access for COPY_IF_OVERLAP
1059 NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE
1060
1061 # construction and destruction functions
1062 NpyIter* NpyIter_New(ndarray arr, npy_uint32 flags, NPY_ORDER order,
1063 NPY_CASTING casting, dtype datatype) except NULL
1064 NpyIter* NpyIter_MultiNew(npy_intp nop, PyArrayObject** op, npy_uint32 flags,
1065 NPY_ORDER order, NPY_CASTING casting, npy_uint32*
1066 op_flags, PyArray_Descr** op_dtypes) except NULL
1067 NpyIter* NpyIter_AdvancedNew(npy_intp nop, PyArrayObject** op,
1068 npy_uint32 flags, NPY_ORDER order,
1069 NPY_CASTING casting, npy_uint32* op_flags,
1070 PyArray_Descr** op_dtypes, int oa_ndim,
1071 int** op_axes, const npy_intp* itershape,
1072 npy_intp buffersize) except NULL
1073 NpyIter* NpyIter_Copy(NpyIter* it) except NULL
1074 int NpyIter_RemoveAxis(NpyIter* it, int axis) except NPY_FAIL
1075 int NpyIter_RemoveMultiIndex(NpyIter* it) except NPY_FAIL
1076 int NpyIter_EnableExternalLoop(NpyIter* it) except NPY_FAIL
1077 int NpyIter_Deallocate(NpyIter* it) except NPY_FAIL
1078 int NpyIter_Reset(NpyIter* it, char** errmsg) except NPY_FAIL
1079 int NpyIter_ResetToIterIndexRange(NpyIter* it, npy_intp istart,
1080 npy_intp iend, char** errmsg) except NPY_FAIL
1081 int NpyIter_ResetBasePointers(NpyIter* it, char** baseptrs, char** errmsg) except NPY_FAIL
1082 int NpyIter_GotoMultiIndex(NpyIter* it, const npy_intp* multi_index) except NPY_FAIL
1083 int NpyIter_GotoIndex(NpyIter* it, npy_intp index) except NPY_FAIL
1084 npy_intp NpyIter_GetIterSize(NpyIter* it) nogil
1085 npy_intp NpyIter_GetIterIndex(NpyIter* it) nogil
1086 void NpyIter_GetIterIndexRange(NpyIter* it, npy_intp* istart,
1087 npy_intp* iend) nogil
1088 int NpyIter_GotoIterIndex(NpyIter* it, npy_intp iterindex) except NPY_FAIL
1089 npy_bool NpyIter_HasDelayedBufAlloc(NpyIter* it) nogil
1090 npy_bool NpyIter_HasExternalLoop(NpyIter* it) nogil
1091 npy_bool NpyIter_HasMultiIndex(NpyIter* it) nogil
1092 npy_bool NpyIter_HasIndex(NpyIter* it) nogil
1093 npy_bool NpyIter_RequiresBuffering(NpyIter* it) nogil
1094 npy_bool NpyIter_IsBuffered(NpyIter* it) nogil
1095 npy_bool NpyIter_IsGrowInner(NpyIter* it) nogil
1096 npy_intp NpyIter_GetBufferSize(NpyIter* it) nogil
1097 int NpyIter_GetNDim(NpyIter* it) nogil
1098 int NpyIter_GetNOp(NpyIter* it) nogil
1099 npy_intp* NpyIter_GetAxisStrideArray(NpyIter* it, int axis) except NULL
1100 int NpyIter_GetShape(NpyIter* it, npy_intp* outshape) nogil
1101 PyArray_Descr** NpyIter_GetDescrArray(NpyIter* it)
1102 PyArrayObject** NpyIter_GetOperandArray(NpyIter* it)
1103 ndarray NpyIter_GetIterView(NpyIter* it, npy_intp i)
1104 void NpyIter_GetReadFlags(NpyIter* it, char* outreadflags)
1105 void NpyIter_GetWriteFlags(NpyIter* it, char* outwriteflags)
1106 int NpyIter_CreateCompatibleStrides(NpyIter* it, npy_intp itemsize,
1107 npy_intp* outstrides) except NPY_FAIL
1108 npy_bool NpyIter_IsFirstVisit(NpyIter* it, int iop) nogil
1109 # functions for iterating an NpyIter object
1110 #
1111 # These don't match the definition in the C API because Cython can't wrap
1112 # function pointers that return functions.
1113 NpyIter_IterNextFunc* NpyIter_GetIterNext(NpyIter* it, char** errmsg) except NULL
1114 NpyIter_GetMultiIndexFunc* NpyIter_GetGetMultiIndex(NpyIter* it,
1115 char** errmsg) except NULL
1116 char** NpyIter_GetDataPtrArray(NpyIter* it) nogil
1117 char** NpyIter_GetInitialDataPtrArray(NpyIter* it) nogil
1118 npy_intp* NpyIter_GetIndexPtr(NpyIter* it)
1119 npy_intp* NpyIter_GetInnerStrideArray(NpyIter* it) nogil
1120 npy_intp* NpyIter_GetInnerLoopSizePtr(NpyIter* it) nogil
1121 void NpyIter_GetInnerFixedStrideArray(NpyIter* it, npy_intp* outstrides) nogil
1122 npy_bool NpyIter_IterationNeedsAPI(NpyIter* it) nogil
1123 void NpyIter_DebugPrint(NpyIter* it)
1124
1125# NpyString API
1126cdef extern from "numpy/ndarraytypes.h":
1127 ctypedef struct npy_string_allocator:
1128 pass
1129
1130 ctypedef struct npy_packed_static_string:
1131 pass
1132
1133 ctypedef struct npy_static_string:
1134 size_t size
1135 const char *buf
1136
1137 ctypedef struct PyArray_StringDTypeObject:
1138 PyArray_Descr base
1139 PyObject *na_object
1140 char coerce
1141 char has_nan_na
1142 char has_string_na
1143 char array_owned
1144 npy_static_string default_string
1145 npy_static_string na_name
1146 npy_string_allocator *allocator
1147
1148cdef extern from "numpy/arrayobject.h":
1149 npy_string_allocator *NpyString_acquire_allocator(const PyArray_StringDTypeObject *descr)
1150 void NpyString_acquire_allocators(size_t n_descriptors, PyArray_Descr *const descrs[], npy_string_allocator *allocators[])
1151 void NpyString_release_allocator(npy_string_allocator *allocator)
1152 void NpyString_release_allocators(size_t length, npy_string_allocator *allocators[])
1153 int NpyString_load(npy_string_allocator *allocator, const npy_packed_static_string *packed_string, npy_static_string *unpacked_string)
1154 int NpyString_pack_null(npy_string_allocator *allocator, npy_packed_static_string *packed_string)
1155 int NpyString_pack(npy_string_allocator *allocator, npy_packed_static_string *packed_string, const char *buf, size_t size)
1156 