~ubuntu-branches/ubuntu/trusty/cython/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/0001-Python-3-fix-NumPy-support.patch/Cython/Includes/numpy.pxd

  • Committer: Bazaar Package Importer
  • Author(s): Yaroslav Halchenko
  • Date: 2011-04-06 11:07:21 UTC
  • Revision ID: james.westby@ubuntu.com-20110406110721-ajmb22ewnl5ozuc0
Tags: 0.14.1-5
* Cherry-picked from upstream:
  - 0001-additional-fix-and-test-for-ticket-650.patch (Closes: #620859)
  - 0001-Python-3-fix-NumPy-support.patch to address some of the numpy 1.5
    compatibility issues
* Temporarily skipped 2 doctests triggered by numpy 1.5 incompatibility
  which is on upstream's TODO: patch deb_tempdisable_numpy_doctests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# NumPy static imports for Cython
 
2
#
 
3
# If any of the PyArray_* functions are called, import_array must be
 
4
# called first.
 
5
#
 
6
# This also defines backwards-compatability buffer acquisition
 
7
# code for use in Python 2.x (or Python <= 2.5 when NumPy starts
 
8
# implementing PEP-3118 directly).
 
9
#
 
10
# Because of laziness, the format string of the buffer is statically
 
11
# allocated. Increase the size if this is not enough, or submit a
 
12
# patch to do this properly.
 
13
#
 
14
# Author: Dag Sverre Seljebotn
 
15
#
 
16
 
 
17
DEF _buffer_format_string_len = 255
 
18
 
 
19
cimport cpython.buffer as pybuf
 
20
from cpython.ref cimport Py_INCREF, Py_XDECREF
 
21
from cpython.object cimport PyObject
 
22
cimport libc.stdlib as stdlib
 
23
cimport libc.stdio as stdio
 
24
 
 
25
cdef extern from "Python.h":
 
26
    ctypedef int Py_intptr_t
 
27
 
 
28
cdef extern from "numpy/arrayobject.h":
 
29
    ctypedef Py_intptr_t npy_intp
 
30
    ctypedef size_t npy_uintp
 
31
 
 
32
    cdef enum NPY_TYPES:
 
33
        NPY_BOOL
 
34
        NPY_BYTE
 
35
        NPY_UBYTE
 
36
        NPY_SHORT
 
37
        NPY_USHORT
 
38
        NPY_INT
 
39
        NPY_UINT
 
40
        NPY_LONG
 
41
        NPY_ULONG
 
42
        NPY_LONGLONG
 
43
        NPY_ULONGLONG
 
44
        NPY_FLOAT
 
45
        NPY_DOUBLE
 
46
        NPY_LONGDOUBLE
 
47
        NPY_CFLOAT
 
48
        NPY_CDOUBLE
 
49
        NPY_CLONGDOUBLE
 
50
        NPY_OBJECT
 
51
        NPY_STRING
 
52
        NPY_UNICODE
 
53
        NPY_VOID
 
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
    enum NPY_ORDER:
 
85
        NPY_ANYORDER
 
86
        NPY_CORDER
 
87
        NPY_FORTRANORDER
 
88
 
 
89
    enum NPY_CLIPMODE:
 
90
        NPY_CLIP
 
91
        NPY_WRAP
 
92
        NPY_RAISE
 
93
 
 
94
    enum NPY_SCALARKIND:
 
95
        NPY_NOSCALAR,
 
96
        NPY_BOOL_SCALAR,
 
97
        NPY_INTPOS_SCALAR,
 
98
        NPY_INTNEG_SCALAR,
 
99
        NPY_FLOAT_SCALAR,
 
100
        NPY_COMPLEX_SCALAR,
 
101
        NPY_OBJECT_SCALAR
 
102
 
 
103
 
 
104
    enum NPY_SORTKIND:
 
105
        NPY_QUICKSORT
 
106
        NPY_HEAPSORT
 
107
        NPY_MERGESORT
 
108
 
 
109
    cdef enum requirements:
 
110
        NPY_C_CONTIGUOUS
 
111
        NPY_F_CONTIGUOUS
 
112
        NPY_CONTIGUOUS
 
113
        NPY_FORTRAN
 
114
        NPY_OWNDATA
 
115
        NPY_FORCECAST
 
116
        NPY_ENSURECOPY
 
117
        NPY_ENSUREARRAY
 
118
        NPY_ELEMENTSTRIDES
 
119
        NPY_ALIGNED
 
120
        NPY_NOTSWAPPED
 
121
        NPY_WRITEABLE
 
122
        NPY_UPDATEIFCOPY
 
123
        NPY_ARR_HAS_DESCR
 
124
 
 
125
        NPY_BEHAVED
 
126
        NPY_BEHAVED_NS
 
127
        NPY_CARRAY
 
128
        NPY_CARRAY_RO
 
129
        NPY_FARRAY
 
130
        NPY_FARRAY_RO
 
131
        NPY_DEFAULT
 
132
 
 
133
        NPY_IN_ARRAY
 
134
        NPY_OUT_ARRAY
 
135
        NPY_INOUT_ARRAY
 
136
        NPY_IN_FARRAY
 
137
        NPY_OUT_FARRAY
 
138
        NPY_INOUT_FARRAY
 
139
 
 
140
        NPY_UPDATE_ALL
 
141
 
 
142
    cdef enum:
 
143
        NPY_MAXDIMS
 
144
 
 
145
    npy_intp NPY_MAX_ELSIZE
 
146
 
 
147
    ctypedef void (*PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *,  void *)
 
148
 
 
149
    ctypedef class numpy.dtype [object PyArray_Descr]:
 
150
        # Use PyDataType_* macros when possible, however there are no macros
 
151
        # for accessing some of the fields, so some are defined. Please
 
152
        # ask on cython-dev if you need more.
 
153
        cdef int type_num
 
154
        cdef int itemsize "elsize"
 
155
        cdef char byteorder
 
156
        cdef object fields
 
157
        cdef tuple names
 
158
 
 
159
    ctypedef extern class numpy.flatiter [object PyArrayIterObject]:
 
160
        # Use through macros
 
161
        pass
 
162
 
 
163
    ctypedef extern class numpy.broadcast [object PyArrayMultiIterObject]:
 
164
        # Use through macros
 
165
        pass
 
166
 
 
167
    ctypedef struct PyArrayObject:
 
168
        # For use in situations where ndarray can't replace PyArrayObject*,
 
169
        # like PyArrayObject**.
 
170
        pass
 
171
 
 
172
    ctypedef class numpy.ndarray [object PyArrayObject]:
 
173
        cdef __cythonbufferdefaults__ = {"mode": "strided"}
 
174
 
 
175
        cdef:
 
176
            # Only taking a few of the most commonly used and stable fields.
 
177
            # One should use PyArray_* macros instead to access the C fields.
 
178
            char *data
 
179
            int ndim "nd"
 
180
            npy_intp *shape "dimensions"
 
181
            npy_intp *strides
 
182
            dtype descr
 
183
            PyObject* base
 
184
 
 
185
        # Note: This syntax (function definition in pxd files) is an
 
186
        # experimental exception made for __getbuffer__ and __releasebuffer__
 
187
        # -- the details of this may change.
 
188
        def __getbuffer__(ndarray self, Py_buffer* info, int flags):
 
189
            # This implementation of getbuffer is geared towards Cython
 
190
            # requirements, and does not yet fullfill the PEP.
 
191
            # In particular strided access is always provided regardless
 
192
            # of flags
 
193
            cdef int copy_shape, i, ndim
 
194
            cdef int endian_detector = 1
 
195
            cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 
196
 
 
197
            ndim = PyArray_NDIM(self)
 
198
 
 
199
            if sizeof(npy_intp) != sizeof(Py_ssize_t):
 
200
                copy_shape = 1
 
201
            else:
 
202
                copy_shape = 0
 
203
 
 
204
            if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 
205
                and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 
206
                raise ValueError(u"ndarray is not C contiguous")
 
207
 
 
208
            if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 
209
                and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 
210
                raise ValueError(u"ndarray is not Fortran contiguous")
 
211
 
 
212
            info.buf = PyArray_DATA(self)
 
213
            info.ndim = ndim
 
214
            if copy_shape:
 
215
                # Allocate new buffer for strides and shape info. This is allocated
 
216
                # as one block, strides first.
 
217
                info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2)
 
218
                info.shape = info.strides + ndim
 
219
                for i in range(ndim):
 
220
                    info.strides[i] = PyArray_STRIDES(self)[i]
 
221
                    info.shape[i] = PyArray_DIMS(self)[i]
 
222
            else:
 
223
                info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 
224
                info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 
225
            info.suboffsets = NULL
 
226
            info.itemsize = PyArray_ITEMSIZE(self)
 
227
            info.readonly = not PyArray_ISWRITEABLE(self)
 
228
 
 
229
            cdef int t
 
230
            cdef char* f = NULL
 
231
            cdef dtype descr = self.descr
 
232
            cdef list stack
 
233
            cdef int offset
 
234
 
 
235
            cdef bint hasfields = PyDataType_HASFIELDS(descr)
 
236
 
 
237
            if not hasfields and not copy_shape:
 
238
                # do not call releasebuffer
 
239
                info.obj = None
 
240
            else:
 
241
                # need to call releasebuffer
 
242
                info.obj = self
 
243
 
 
244
            if not hasfields:
 
245
                t = descr.type_num
 
246
                if ((descr.byteorder == '>' and little_endian) or
 
247
                    (descr.byteorder == '<' and not little_endian)):
 
248
                    raise ValueError(u"Non-native byte order not supported")
 
249
                if   t == NPY_BYTE:        f = "b"
 
250
                elif t == NPY_UBYTE:       f = "B"
 
251
                elif t == NPY_SHORT:       f = "h"
 
252
                elif t == NPY_USHORT:      f = "H"
 
253
                elif t == NPY_INT:         f = "i"
 
254
                elif t == NPY_UINT:        f = "I"
 
255
                elif t == NPY_LONG:        f = "l"
 
256
                elif t == NPY_ULONG:       f = "L"
 
257
                elif t == NPY_LONGLONG:    f = "q"
 
258
                elif t == NPY_ULONGLONG:   f = "Q"
 
259
                elif t == NPY_FLOAT:       f = "f"
 
260
                elif t == NPY_DOUBLE:      f = "d"
 
261
                elif t == NPY_LONGDOUBLE:  f = "g"
 
262
                elif t == NPY_CFLOAT:      f = "Zf"
 
263
                elif t == NPY_CDOUBLE:     f = "Zd"
 
264
                elif t == NPY_CLONGDOUBLE: f = "Zg"
 
265
                elif t == NPY_OBJECT:      f = "O"
 
266
                else:
 
267
                    raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 
268
                info.format = f
 
269
                return
 
270
            else:
 
271
                info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 
272
                info.format[0] = '^' # Native data types, manual alignment
 
273
                offset = 0
 
274
                f = _util_dtypestring(descr, info.format + 1,
 
275
                                      info.format + _buffer_format_string_len,
 
276
                                      &offset)
 
277
                f[0] = 0 # Terminate format string
 
278
 
 
279
        def __releasebuffer__(ndarray self, Py_buffer* info):
 
280
            if PyArray_HASFIELDS(self):
 
281
                stdlib.free(info.format)
 
282
            if sizeof(npy_intp) != sizeof(Py_ssize_t):
 
283
                stdlib.free(info.strides)
 
284
                # info.shape was stored after info.strides in the same block
 
285
 
 
286
 
 
287
    ctypedef signed char      npy_bool
 
288
 
 
289
    ctypedef signed char      npy_byte
 
290
    ctypedef signed short     npy_short
 
291
    ctypedef signed int       npy_int
 
292
    ctypedef signed long      npy_long
 
293
    ctypedef signed long long npy_longlong
 
294
 
 
295
    ctypedef unsigned char      npy_ubyte
 
296
    ctypedef unsigned short     npy_ushort
 
297
    ctypedef unsigned int       npy_uint
 
298
    ctypedef unsigned long      npy_ulong
 
299
    ctypedef unsigned long long npy_ulonglong
 
300
 
 
301
    ctypedef float        npy_float
 
302
    ctypedef double       npy_double
 
303
    ctypedef long double  npy_longdouble
 
304
 
 
305
    ctypedef signed char        npy_int8
 
306
    ctypedef signed short       npy_int16
 
307
    ctypedef signed int         npy_int32
 
308
    ctypedef signed long long   npy_int64
 
309
    ctypedef signed long long   npy_int96
 
310
    ctypedef signed long long   npy_int128
 
311
 
 
312
    ctypedef unsigned char      npy_uint8
 
313
    ctypedef unsigned short     npy_uint16
 
314
    ctypedef unsigned int       npy_uint32
 
315
    ctypedef unsigned long long npy_uint64
 
316
    ctypedef unsigned long long npy_uint96
 
317
    ctypedef unsigned long long npy_uint128
 
318
 
 
319
    ctypedef float        npy_float32
 
320
    ctypedef double       npy_float64
 
321
    ctypedef long double  npy_float80
 
322
    ctypedef long double  npy_float96
 
323
    ctypedef long double  npy_float128
 
324
 
 
325
    ctypedef struct npy_cfloat:
 
326
        double real
 
327
        double imag
 
328
 
 
329
    ctypedef struct npy_cdouble:
 
330
        double real
 
331
        double imag
 
332
 
 
333
    ctypedef struct npy_clongdouble:
 
334
        double real
 
335
        double imag
 
336
 
 
337
    ctypedef struct npy_complex64:
 
338
        double real
 
339
        double imag
 
340
 
 
341
    ctypedef struct npy_complex128:
 
342
        double real
 
343
        double imag
 
344
 
 
345
    ctypedef struct npy_complex160:
 
346
        double real
 
347
        double imag
 
348
 
 
349
    ctypedef struct npy_complex192:
 
350
        double real
 
351
        double imag
 
352
 
 
353
    ctypedef struct npy_complex256:
 
354
        double real
 
355
        double imag
 
356
 
 
357
    ctypedef struct PyArray_Dims:
 
358
        npy_intp *ptr
 
359
        int len
 
360
 
 
361
    void import_array()
 
362
 
 
363
    #
 
364
    # Macros from ndarrayobject.h
 
365
    #
 
366
    bint PyArray_CHKFLAGS(ndarray m, int flags)
 
367
    bint PyArray_ISCONTIGUOUS(ndarray m)
 
368
    bint PyArray_ISWRITEABLE(ndarray m)
 
369
    bint PyArray_ISALIGNED(ndarray m)
 
370
 
 
371
    int PyArray_NDIM(ndarray)
 
372
    bint PyArray_ISONESEGMENT(ndarray)
 
373
    bint PyArray_ISFORTRAN(ndarray)
 
374
    int PyArray_FORTRANIF(ndarray)
 
375
 
 
376
    void* PyArray_DATA(ndarray)
 
377
    char* PyArray_BYTES(ndarray)
 
378
    npy_intp* PyArray_DIMS(ndarray)
 
379
    npy_intp* PyArray_STRIDES(ndarray)
 
380
    npy_intp PyArray_DIM(ndarray, size_t)
 
381
    npy_intp PyArray_STRIDE(ndarray, size_t)
 
382
 
 
383
    # object PyArray_BASE(ndarray) wrong refcount semantics
 
384
    # dtype PyArray_DESCR(ndarray) wrong refcount semantics
 
385
    int PyArray_FLAGS(ndarray)
 
386
    npy_intp PyArray_ITEMSIZE(ndarray)
 
387
    int PyArray_TYPE(ndarray arr)
 
388
 
 
389
    object PyArray_GETITEM(ndarray arr, void *itemptr)
 
390
    int PyArray_SETITEM(ndarray arr, void *itemptr, object obj)
 
391
 
 
392
    bint PyTypeNum_ISBOOL(int)
 
393
    bint PyTypeNum_ISUNSIGNED(int)
 
394
    bint PyTypeNum_ISSIGNED(int)
 
395
    bint PyTypeNum_ISINTEGER(int)
 
396
    bint PyTypeNum_ISFLOAT(int)
 
397
    bint PyTypeNum_ISNUMBER(int)
 
398
    bint PyTypeNum_ISSTRING(int)
 
399
    bint PyTypeNum_ISCOMPLEX(int)
 
400
    bint PyTypeNum_ISPYTHON(int)
 
401
    bint PyTypeNum_ISFLEXIBLE(int)
 
402
    bint PyTypeNum_ISUSERDEF(int)
 
403
    bint PyTypeNum_ISEXTENDED(int)
 
404
    bint PyTypeNum_ISOBJECT(int)
 
405
 
 
406
    bint PyDataType_ISBOOL(dtype)
 
407
    bint PyDataType_ISUNSIGNED(dtype)
 
408
    bint PyDataType_ISSIGNED(dtype)
 
409
    bint PyDataType_ISINTEGER(dtype)
 
410
    bint PyDataType_ISFLOAT(dtype)
 
411
    bint PyDataType_ISNUMBER(dtype)
 
412
    bint PyDataType_ISSTRING(dtype)
 
413
    bint PyDataType_ISCOMPLEX(dtype)
 
414
    bint PyDataType_ISPYTHON(dtype)
 
415
    bint PyDataType_ISFLEXIBLE(dtype)
 
416
    bint PyDataType_ISUSERDEF(dtype)
 
417
    bint PyDataType_ISEXTENDED(dtype)
 
418
    bint PyDataType_ISOBJECT(dtype)
 
419
    bint PyDataType_HASFIELDS(dtype)
 
420
 
 
421
    bint PyArray_ISBOOL(ndarray)
 
422
    bint PyArray_ISUNSIGNED(ndarray)
 
423
    bint PyArray_ISSIGNED(ndarray)
 
424
    bint PyArray_ISINTEGER(ndarray)
 
425
    bint PyArray_ISFLOAT(ndarray)
 
426
    bint PyArray_ISNUMBER(ndarray)
 
427
    bint PyArray_ISSTRING(ndarray)
 
428
    bint PyArray_ISCOMPLEX(ndarray)
 
429
    bint PyArray_ISPYTHON(ndarray)
 
430
    bint PyArray_ISFLEXIBLE(ndarray)
 
431
    bint PyArray_ISUSERDEF(ndarray)
 
432
    bint PyArray_ISEXTENDED(ndarray)
 
433
    bint PyArray_ISOBJECT(ndarray)
 
434
    bint PyArray_HASFIELDS(ndarray)
 
435
 
 
436
    bint PyArray_ISVARIABLE(ndarray)
 
437
 
 
438
    bint PyArray_SAFEALIGNEDCOPY(ndarray)
 
439
    bint PyArray_ISNBO(ndarray)
 
440
    bint PyArray_IsNativeByteOrder(ndarray)
 
441
    bint PyArray_ISNOTSWAPPED(ndarray)
 
442
    bint PyArray_ISBYTESWAPPED(ndarray)
 
443
 
 
444
    bint PyArray_FLAGSWAP(ndarray, int)
 
445
 
 
446
    bint PyArray_ISCARRAY(ndarray)
 
447
    bint PyArray_ISCARRAY_RO(ndarray)
 
448
    bint PyArray_ISFARRAY(ndarray)
 
449
    bint PyArray_ISFARRAY_RO(ndarray)
 
450
    bint PyArray_ISBEHAVED(ndarray)
 
451
    bint PyArray_ISBEHAVED_RO(ndarray)
 
452
 
 
453
 
 
454
    bint PyDataType_ISNOTSWAPPED(dtype)
 
455
    bint PyDataType_ISBYTESWAPPED(dtype)
 
456
 
 
457
    bint PyArray_DescrCheck(object)
 
458
 
 
459
    bint PyArray_Check(object)
 
460
    bint PyArray_CheckExact(object)
 
461
 
 
462
    # Cannot be supported due to out arg:
 
463
    # bint PyArray_HasArrayInterfaceType(object, dtype, object, object&)
 
464
    # bint PyArray_HasArrayInterface(op, out)
 
465
 
 
466
 
 
467
    bint PyArray_IsZeroDim(object)
 
468
    # Cannot be supported due to ## ## in macro:
 
469
    # bint PyArray_IsScalar(object, verbatim work)
 
470
    bint PyArray_CheckScalar(object)
 
471
    bint PyArray_IsPythonNumber(object)
 
472
    bint PyArray_IsPythonScalar(object)
 
473
    bint PyArray_IsAnyScalar(object)
 
474
    bint PyArray_CheckAnyScalar(object)
 
475
    ndarray PyArray_GETCONTIGUOUS(ndarray)
 
476
    bint PyArray_SAMESHAPE(ndarray, ndarray)
 
477
    npy_intp PyArray_SIZE(ndarray)
 
478
    npy_intp PyArray_NBYTES(ndarray)
 
479
 
 
480
    object PyArray_FROM_O(object)
 
481
    object PyArray_FROM_OF(object m, int flags)
 
482
    bint PyArray_FROM_OT(object m, int type)
 
483
    bint PyArray_FROM_OTF(object m, int type, int flags)
 
484
    object PyArray_FROMANY(object m, int type, int min, int max, int flags)
 
485
    object PyArray_ZEROS(int nd, npy_intp* dims, int type, int fortran)
 
486
    object PyArray_EMPTY(int nd, npy_intp* dims, int type, int fortran)
 
487
    void PyArray_FILLWBYTE(object, int val)
 
488
    npy_intp PyArray_REFCOUNT(object)
 
489
    object PyArray_ContiguousFromAny(op, int, int min_depth, int max_depth)
 
490
    unsigned char PyArray_EquivArrTypes(ndarray a1, ndarray a2)
 
491
    bint PyArray_EquivByteorders(int b1, int b2)
 
492
    object PyArray_SimpleNew(int nd, npy_intp* dims, int typenum)
 
493
    object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int typenum, void* data)
 
494
    #object PyArray_SimpleNewFromDescr(int nd, npy_intp* dims, dtype descr)
 
495
    object PyArray_ToScalar(void* data, ndarray arr)
 
496
 
 
497
    void* PyArray_GETPTR1(ndarray m, npy_intp i)
 
498
    void* PyArray_GETPTR2(ndarray m, npy_intp i, npy_intp j)
 
499
    void* PyArray_GETPTR3(ndarray m, npy_intp i, npy_intp j, npy_intp k)
 
500
    void* PyArray_GETPTR4(ndarray m, npy_intp i, npy_intp j, npy_intp k, npy_intp l)
 
501
 
 
502
    void PyArray_XDECREF_ERR(ndarray)
 
503
    # Cannot be supported due to out arg
 
504
    # void PyArray_DESCR_REPLACE(descr)
 
505
 
 
506
 
 
507
    object PyArray_Copy(ndarray)
 
508
    object PyArray_FromObject(object op, int type, int min_depth, int max_depth)
 
509
    object PyArray_ContiguousFromObject(object op, int type, int min_depth, int max_depth)
 
510
    object PyArray_CopyFromObject(object op, int type, int min_depth, int max_depth)
 
511
 
 
512
    object PyArray_Cast(ndarray mp, int type_num)
 
513
    object PyArray_Take(ndarray ap, object items, int axis)
 
514
    object PyArray_Put(ndarray ap, object items, object values)
 
515
 
 
516
    void PyArray_ITER_RESET(flatiter it) nogil
 
517
    void PyArray_ITER_NEXT(flatiter it) nogil
 
518
    void PyArray_ITER_GOTO(flatiter it, npy_intp* destination) nogil
 
519
    void PyArray_ITER_GOTO1D(flatiter it, npy_intp ind) nogil
 
520
    void* PyArray_ITER_DATA(flatiter it) nogil
 
521
    bint PyArray_ITER_NOTDONE(flatiter it) nogil
 
522
 
 
523
    void PyArray_MultiIter_RESET(broadcast multi) nogil
 
524
    void PyArray_MultiIter_NEXT(broadcast multi) nogil
 
525
    void PyArray_MultiIter_GOTO(broadcast multi, npy_intp dest) nogil
 
526
    void PyArray_MultiIter_GOTO1D(broadcast multi, npy_intp ind) nogil
 
527
    void* PyArray_MultiIter_DATA(broadcast multi, npy_intp i) nogil
 
528
    void PyArray_MultiIter_NEXTi(broadcast multi, npy_intp i) nogil
 
529
    bint PyArray_MultiIter_NOTDONE(broadcast multi) nogil
 
530
 
 
531
    # Functions from __multiarray_api.h
 
532
 
 
533
    # Functions taking dtype and returning object/ndarray are disabled
 
534
    # for now as they steal dtype references. I'm conservative and disable
 
535
    # more than is probably needed until it can be checked further.
 
536
    int PyArray_SetNumericOps        (object)
 
537
    object PyArray_GetNumericOps ()
 
538
    int PyArray_INCREF (ndarray)
 
539
    int PyArray_XDECREF (ndarray)
 
540
    void PyArray_SetStringFunction (object, int)
 
541
    dtype PyArray_DescrFromType (int)
 
542
    object PyArray_TypeObjectFromType (int)
 
543
    char * PyArray_Zero (ndarray)
 
544
    char * PyArray_One (ndarray)
 
545
    #object PyArray_CastToType (ndarray, dtype, int)
 
546
    int PyArray_CastTo (ndarray, ndarray)
 
547
    int PyArray_CastAnyTo (ndarray, ndarray)
 
548
    int PyArray_CanCastSafely (int, int)
 
549
    npy_bool PyArray_CanCastTo (dtype, dtype)
 
550
    int PyArray_ObjectType (object, int)
 
551
    dtype PyArray_DescrFromObject (object, dtype)
 
552
    #ndarray* PyArray_ConvertToCommonType (object, int *)
 
553
    dtype PyArray_DescrFromScalar (object)
 
554
    dtype PyArray_DescrFromTypeObject (object)
 
555
    npy_intp PyArray_Size (object)
 
556
    #object PyArray_Scalar (void *, dtype, object)
 
557
    #object PyArray_FromScalar (object, dtype)
 
558
    void PyArray_ScalarAsCtype (object, void *)
 
559
    #int PyArray_CastScalarToCtype (object, void *, dtype)
 
560
    #int PyArray_CastScalarDirect (object, dtype, void *, int)
 
561
    object PyArray_ScalarFromObject (object)
 
562
    #PyArray_VectorUnaryFunc * PyArray_GetCastFunc (dtype, int)
 
563
    object PyArray_FromDims (int, int *, int)
 
564
    #object PyArray_FromDimsAndDataAndDescr (int, int *, dtype, char *)
 
565
    #object PyArray_FromAny (object, dtype, int, int, int, object)
 
566
    object PyArray_EnsureArray (object)
 
567
    object PyArray_EnsureAnyArray (object)
 
568
    #object PyArray_FromFile (stdio.FILE *, dtype, npy_intp, char *)
 
569
    #object PyArray_FromString (char *, npy_intp, dtype, npy_intp, char *)
 
570
    #object PyArray_FromBuffer (object, dtype, npy_intp, npy_intp)
 
571
    #object PyArray_FromIter (object, dtype, npy_intp)
 
572
    object PyArray_Return (ndarray)
 
573
    #object PyArray_GetField (ndarray, dtype, int)
 
574
    #int PyArray_SetField (ndarray, dtype, int, object)
 
575
    object PyArray_Byteswap (ndarray, npy_bool)
 
576
    object PyArray_Resize (ndarray, PyArray_Dims *, int, NPY_ORDER)
 
577
    int PyArray_MoveInto (ndarray, ndarray)
 
578
    int PyArray_CopyInto (ndarray, ndarray)
 
579
    int PyArray_CopyAnyInto (ndarray, ndarray)
 
580
    int PyArray_CopyObject (ndarray, object)
 
581
    object PyArray_NewCopy (ndarray, NPY_ORDER)
 
582
    object PyArray_ToList (ndarray)
 
583
    object PyArray_ToString (ndarray, NPY_ORDER)
 
584
    int PyArray_ToFile (ndarray, stdio.FILE *, char *, char *)
 
585
    int PyArray_Dump (object, object, int)
 
586
    object PyArray_Dumps (object, int)
 
587
    int PyArray_ValidType (int)
 
588
    void PyArray_UpdateFlags (ndarray, int)
 
589
    object PyArray_New (type, int, npy_intp *, int, npy_intp *, void *, int, int, object)
 
590
    #object PyArray_NewFromDescr (type, dtype, int, npy_intp *, npy_intp *, void *, int, object)
 
591
    #dtype PyArray_DescrNew (dtype)
 
592
    dtype PyArray_DescrNewFromType (int)
 
593
    double PyArray_GetPriority (object, double)
 
594
    object PyArray_IterNew (object)
 
595
    object PyArray_MultiIterNew (int, ...)
 
596
 
 
597
    int PyArray_PyIntAsInt (object)
 
598
    npy_intp PyArray_PyIntAsIntp (object)
 
599
    int PyArray_Broadcast (broadcast)
 
600
    void PyArray_FillObjectArray (ndarray, object)
 
601
    int PyArray_FillWithScalar (ndarray, object)
 
602
    npy_bool PyArray_CheckStrides (int, int, npy_intp, npy_intp, npy_intp *, npy_intp *)
 
603
    dtype PyArray_DescrNewByteorder (dtype, char)
 
604
    object PyArray_IterAllButAxis (object, int *)
 
605
    #object PyArray_CheckFromAny (object, dtype, int, int, int, object)
 
606
    #object PyArray_FromArray (ndarray, dtype, int)
 
607
    object PyArray_FromInterface (object)
 
608
    object PyArray_FromStructInterface (object)
 
609
    #object PyArray_FromArrayAttr (object, dtype, object)
 
610
    #NPY_SCALARKIND PyArray_ScalarKind (int, ndarray*)
 
611
    int PyArray_CanCoerceScalar (int, int, NPY_SCALARKIND)
 
612
    object PyArray_NewFlagsObject (object)
 
613
    npy_bool PyArray_CanCastScalar (type, type)
 
614
    #int PyArray_CompareUCS4 (npy_ucs4 *, npy_ucs4 *, register size_t)
 
615
    int PyArray_RemoveSmallest (broadcast)
 
616
    int PyArray_ElementStrides (object)
 
617
    void PyArray_Item_INCREF (char *, dtype)
 
618
    void PyArray_Item_XDECREF (char *, dtype)
 
619
    object PyArray_FieldNames (object)
 
620
    object PyArray_Transpose (ndarray, PyArray_Dims *)
 
621
    object PyArray_TakeFrom (ndarray, object, int, ndarray, NPY_CLIPMODE)
 
622
    object PyArray_PutTo (ndarray, object, object, NPY_CLIPMODE)
 
623
    object PyArray_PutMask (ndarray, object, object)
 
624
    object PyArray_Repeat (ndarray, object, int)
 
625
    object PyArray_Choose (ndarray, object, ndarray, NPY_CLIPMODE)
 
626
    int PyArray_Sort (ndarray, int, NPY_SORTKIND)
 
627
    object PyArray_ArgSort (ndarray, int, NPY_SORTKIND)
 
628
    object PyArray_SearchSorted (ndarray, object, NPY_SEARCHSIDE)
 
629
    object PyArray_ArgMax (ndarray, int, ndarray)
 
630
    object PyArray_ArgMin (ndarray, int, ndarray)
 
631
    object PyArray_Reshape (ndarray, object)
 
632
    object PyArray_Newshape (ndarray, PyArray_Dims *, NPY_ORDER)
 
633
    object PyArray_Squeeze (ndarray)
 
634
    #object PyArray_View (ndarray, dtype, type)
 
635
    object PyArray_SwapAxes (ndarray, int, int)
 
636
    object PyArray_Max (ndarray, int, ndarray)
 
637
    object PyArray_Min (ndarray, int, ndarray)
 
638
    object PyArray_Ptp (ndarray, int, ndarray)
 
639
    object PyArray_Mean (ndarray, int, int, ndarray)
 
640
    object PyArray_Trace (ndarray, int, int, int, int, ndarray)
 
641
    object PyArray_Diagonal (ndarray, int, int, int)
 
642
    object PyArray_Clip (ndarray, object, object, ndarray)
 
643
    object PyArray_Conjugate (ndarray, ndarray)
 
644
    object PyArray_Nonzero (ndarray)
 
645
    object PyArray_Std (ndarray, int, int, ndarray, int)
 
646
    object PyArray_Sum (ndarray, int, int, ndarray)
 
647
    object PyArray_CumSum (ndarray, int, int, ndarray)
 
648
    object PyArray_Prod (ndarray, int, int, ndarray)
 
649
    object PyArray_CumProd (ndarray, int, int, ndarray)
 
650
    object PyArray_All (ndarray, int, ndarray)
 
651
    object PyArray_Any (ndarray, int, ndarray)
 
652
    object PyArray_Compress (ndarray, object, int, ndarray)
 
653
    object PyArray_Flatten (ndarray, NPY_ORDER)
 
654
    object PyArray_Ravel (ndarray, NPY_ORDER)
 
655
    npy_intp PyArray_MultiplyList (npy_intp *, int)
 
656
    int PyArray_MultiplyIntList (int *, int)
 
657
    void * PyArray_GetPtr (ndarray, npy_intp*)
 
658
    int PyArray_CompareLists (npy_intp *, npy_intp *, int)
 
659
    #int PyArray_AsCArray (object*, void *, npy_intp *, int, dtype)
 
660
    #int PyArray_As1D (object*, char **, int *, int)
 
661
    #int PyArray_As2D (object*, char ***, int *, int *, int)
 
662
    int PyArray_Free (object, void *)
 
663
    #int PyArray_Converter (object, object*)
 
664
    int PyArray_IntpFromSequence (object, npy_intp *, int)
 
665
    object PyArray_Concatenate (object, int)
 
666
    object PyArray_InnerProduct (object, object)
 
667
    object PyArray_MatrixProduct (object, object)
 
668
    object PyArray_CopyAndTranspose (object)
 
669
    object PyArray_Correlate (object, object, int)
 
670
    int PyArray_TypestrConvert (int, int)
 
671
    #int PyArray_DescrConverter (object, dtype*)
 
672
    #int PyArray_DescrConverter2 (object, dtype*)
 
673
    int PyArray_IntpConverter (object, PyArray_Dims *)
 
674
    #int PyArray_BufferConverter (object, chunk)
 
675
    int PyArray_AxisConverter (object, int *)
 
676
    int PyArray_BoolConverter (object, npy_bool *)
 
677
    int PyArray_ByteorderConverter (object, char *)
 
678
    int PyArray_OrderConverter (object, NPY_ORDER *)
 
679
    unsigned char PyArray_EquivTypes (dtype, dtype)
 
680
    #object PyArray_Zeros (int, npy_intp *, dtype, int)
 
681
    #object PyArray_Empty (int, npy_intp *, dtype, int)
 
682
    object PyArray_Where (object, object, object)
 
683
    object PyArray_Arange (double, double, double, int)
 
684
    #object PyArray_ArangeObj (object, object, object, dtype)
 
685
    int PyArray_SortkindConverter (object, NPY_SORTKIND *)
 
686
    object PyArray_LexSort (object, int)
 
687
    object PyArray_Round (ndarray, int, ndarray)
 
688
    unsigned char PyArray_EquivTypenums (int, int)
 
689
    int PyArray_RegisterDataType (dtype)
 
690
    int PyArray_RegisterCastFunc (dtype, int, PyArray_VectorUnaryFunc *)
 
691
    int PyArray_RegisterCanCast (dtype, int, NPY_SCALARKIND)
 
692
    #void PyArray_InitArrFuncs (PyArray_ArrFuncs *)
 
693
    object PyArray_IntTupleFromIntp (int, npy_intp *)
 
694
    int PyArray_TypeNumFromName (char *)
 
695
    int PyArray_ClipmodeConverter (object, NPY_CLIPMODE *)
 
696
    #int PyArray_OutputConverter (object, ndarray*)
 
697
    object PyArray_BroadcastToShape (object, npy_intp *, int)
 
698
    void _PyArray_SigintHandler (int)
 
699
    void* _PyArray_GetSigintBuf ()
 
700
    #int PyArray_DescrAlignConverter (object, dtype*)
 
701
    #int PyArray_DescrAlignConverter2 (object, dtype*)
 
702
    int PyArray_SearchsideConverter (object, void *)
 
703
    object PyArray_CheckAxis (ndarray, int *, int)
 
704
    npy_intp PyArray_OverflowMultiplyList (npy_intp *, int)
 
705
    int PyArray_CompareString (char *, char *, size_t)
 
706
 
 
707
 
 
708
# Typedefs that matches the runtime dtype objects in
 
709
# the numpy module.
 
710
 
 
711
# The ones that are commented out needs an IFDEF function
 
712
# in Cython to enable them only on the right systems.
 
713
 
 
714
ctypedef npy_int8       int8_t
 
715
ctypedef npy_int16      int16_t
 
716
ctypedef npy_int32      int32_t
 
717
ctypedef npy_int64      int64_t
 
718
#ctypedef npy_int96      int96_t
 
719
#ctypedef npy_int128     int128_t
 
720
 
 
721
ctypedef npy_uint8      uint8_t
 
722
ctypedef npy_uint16     uint16_t
 
723
ctypedef npy_uint32     uint32_t
 
724
ctypedef npy_uint64     uint64_t
 
725
#ctypedef npy_uint96     uint96_t
 
726
#ctypedef npy_uint128    uint128_t
 
727
 
 
728
ctypedef npy_float32    float32_t
 
729
ctypedef npy_float64    float64_t
 
730
#ctypedef npy_float80    float80_t
 
731
#ctypedef npy_float128   float128_t
 
732
 
 
733
ctypedef float complex  complex64_t
 
734
ctypedef double complex complex128_t
 
735
 
 
736
# The int types are mapped a bit surprising --
 
737
# numpy.int corresponds to 'l' and numpy.long to 'q'
 
738
ctypedef npy_long       int_t
 
739
ctypedef npy_longlong   long_t
 
740
ctypedef npy_intp       intp_t
 
741
ctypedef npy_uintp      uintp_t
 
742
 
 
743
ctypedef npy_ulong      uint_t
 
744
ctypedef npy_ulonglong  ulong_t
 
745
 
 
746
ctypedef npy_double     float_t
 
747
ctypedef npy_double     double_t
 
748
ctypedef npy_longdouble longdouble_t
 
749
 
 
750
ctypedef npy_cfloat      cfloat_t
 
751
ctypedef npy_cdouble     cdouble_t
 
752
ctypedef npy_clongdouble clongdouble_t
 
753
 
 
754
ctypedef npy_cdouble     complex_t
 
755
 
 
756
cdef inline object PyArray_MultiIterNew1(a):
 
757
    return PyArray_MultiIterNew(1, <void*>a)
 
758
 
 
759
cdef inline object PyArray_MultiIterNew2(a, b):
 
760
    return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 
761
 
 
762
cdef inline object PyArray_MultiIterNew3(a, b, c):
 
763
    return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 
764
 
 
765
cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 
766
    return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 
767
 
 
768
cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 
769
    return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 
770
 
 
771
cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:
 
772
    # Recursive utility function used in __getbuffer__ to get format
 
773
    # string. The new location in the format string is returned.
 
774
 
 
775
    cdef dtype child
 
776
    cdef int delta_offset
 
777
    cdef tuple i
 
778
    cdef int endian_detector = 1
 
779
    cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 
780
    cdef tuple fields
 
781
 
 
782
    for childname in descr.names:
 
783
        fields = descr.fields[childname]
 
784
        child, new_offset = fields
 
785
 
 
786
        if (end - f) - (new_offset - offset[0]) < 15:
 
787
            raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 
788
 
 
789
        if ((child.byteorder == '>' and little_endian) or
 
790
            (child.byteorder == '<' and not little_endian)):
 
791
            raise ValueError(u"Non-native byte order not supported")
 
792
            # One could encode it in the format string and have Cython
 
793
            # complain instead, BUT: < and > in format strings also imply
 
794
            # standardized sizes for datatypes, and we rely on native in
 
795
            # order to avoid reencoding data types based on their size.
 
796
            #
 
797
            # A proper PEP 3118 exporter for other clients than Cython
 
798
            # must deal properly with this!
 
799
 
 
800
        # Output padding bytes
 
801
        while offset[0] < new_offset:
 
802
            f[0] = 120 # "x"; pad byte
 
803
            f += 1
 
804
            offset[0] += 1
 
805
 
 
806
        offset[0] += child.itemsize
 
807
 
 
808
        if not PyDataType_HASFIELDS(child):
 
809
            t = child.type_num
 
810
            if end - f < 5:
 
811
                raise RuntimeError(u"Format string allocated too short.")
 
812
 
 
813
            # Until ticket #99 is fixed, use integers to avoid warnings
 
814
            if   t == NPY_BYTE:        f[0] =  98 #"b"
 
815
            elif t == NPY_UBYTE:       f[0] =  66 #"B"
 
816
            elif t == NPY_SHORT:       f[0] = 104 #"h"
 
817
            elif t == NPY_USHORT:      f[0] =  72 #"H"
 
818
            elif t == NPY_INT:         f[0] = 105 #"i"
 
819
            elif t == NPY_UINT:        f[0] =  73 #"I"
 
820
            elif t == NPY_LONG:        f[0] = 108 #"l"
 
821
            elif t == NPY_ULONG:       f[0] = 76  #"L"
 
822
            elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 
823
            elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 
824
            elif t == NPY_FLOAT:       f[0] = 102 #"f"
 
825
            elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 
826
            elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 
827
            elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 
828
            elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 
829
            elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 
830
            elif t == NPY_OBJECT:      f[0] = 79 #"O"
 
831
            else:
 
832
                raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 
833
            f += 1
 
834
        else:
 
835
            # Cython ignores struct boundary information ("T{...}"),
 
836
            # so don't output it
 
837
            f = _util_dtypestring(child, f, end, offset)
 
838
    return f
 
839
 
 
840
 
 
841
#
 
842
# ufunc API
 
843
#
 
844
 
 
845
cdef extern from "numpy/ufuncobject.h":
 
846
 
 
847
    ctypedef void (*PyUFuncGenericFunction) (char **, npy_intp *, npy_intp *, void *)
 
848
 
 
849
    ctypedef extern class numpy.ufunc [object PyUFuncObject]:
 
850
        cdef:
 
851
            int nin, nout, nargs
 
852
            int identity
 
853
            PyUFuncGenericFunction *functions
 
854
            void **data
 
855
            int ntypes
 
856
            int check_return
 
857
            char *name, *types
 
858
            char *doc
 
859
            void *ptr
 
860
            PyObject *obj
 
861
            PyObject *userloops
 
862
 
 
863
    cdef enum:
 
864
        PyUFunc_Zero
 
865
        PyUFunc_One
 
866
        PyUFunc_None
 
867
        UFUNC_ERR_IGNORE
 
868
        UFUNC_ERR_WARN
 
869
        UFUNC_ERR_RAISE
 
870
        UFUNC_ERR_CALL
 
871
        UFUNC_ERR_PRINT
 
872
        UFUNC_ERR_LOG
 
873
        UFUNC_MASK_DIVIDEBYZERO
 
874
        UFUNC_MASK_OVERFLOW
 
875
        UFUNC_MASK_UNDERFLOW
 
876
        UFUNC_MASK_INVALID
 
877
        UFUNC_SHIFT_DIVIDEBYZERO
 
878
        UFUNC_SHIFT_OVERFLOW
 
879
        UFUNC_SHIFT_UNDERFLOW
 
880
        UFUNC_SHIFT_INVALID
 
881
        UFUNC_FPE_DIVIDEBYZERO
 
882
        UFUNC_FPE_OVERFLOW
 
883
        UFUNC_FPE_UNDERFLOW
 
884
        UFUNC_FPE_INVALID
 
885
        UFUNC_ERR_DEFAULT
 
886
        UFUNC_ERR_DEFAULT2
 
887
 
 
888
    object PyUFunc_FromFuncAndData(PyUFuncGenericFunction *,
 
889
          void **, char *, int, int, int, int, char *, char *, int)
 
890
    int PyUFunc_RegisterLoopForType(ufunc, int,
 
891
                                    PyUFuncGenericFunction, int *, void *)
 
892
    int PyUFunc_GenericFunction \
 
893
        (ufunc, PyObject *, PyObject *, PyArrayObject **)
 
894
    void PyUFunc_f_f_As_d_d \
 
895
         (char **, npy_intp *, npy_intp *, void *)
 
896
    void PyUFunc_d_d \
 
897
         (char **, npy_intp *, npy_intp *, void *)
 
898
    void PyUFunc_f_f \
 
899
         (char **, npy_intp *, npy_intp *, void *)
 
900
    void PyUFunc_g_g \
 
901
         (char **, npy_intp *, npy_intp *, void *)
 
902
    void PyUFunc_F_F_As_D_D \
 
903
         (char **, npy_intp *, npy_intp *, void *)
 
904
    void PyUFunc_F_F \
 
905
         (char **, npy_intp *, npy_intp *, void *)
 
906
    void PyUFunc_D_D \
 
907
         (char **, npy_intp *, npy_intp *, void *)
 
908
    void PyUFunc_G_G \
 
909
         (char **, npy_intp *, npy_intp *, void *)
 
910
    void PyUFunc_O_O \
 
911
         (char **, npy_intp *, npy_intp *, void *)
 
912
    void PyUFunc_ff_f_As_dd_d \
 
913
         (char **, npy_intp *, npy_intp *, void *)
 
914
    void PyUFunc_ff_f \
 
915
         (char **, npy_intp *, npy_intp *, void *)
 
916
    void PyUFunc_dd_d \
 
917
         (char **, npy_intp *, npy_intp *, void *)
 
918
    void PyUFunc_gg_g \
 
919
         (char **, npy_intp *, npy_intp *, void *)
 
920
    void PyUFunc_FF_F_As_DD_D \
 
921
         (char **, npy_intp *, npy_intp *, void *)
 
922
    void PyUFunc_DD_D \
 
923
         (char **, npy_intp *, npy_intp *, void *)
 
924
    void PyUFunc_FF_F \
 
925
         (char **, npy_intp *, npy_intp *, void *)
 
926
    void PyUFunc_GG_G \
 
927
         (char **, npy_intp *, npy_intp *, void *)
 
928
    void PyUFunc_OO_O \
 
929
         (char **, npy_intp *, npy_intp *, void *)
 
930
    void PyUFunc_O_O_method \
 
931
         (char **, npy_intp *, npy_intp *, void *)
 
932
    void PyUFunc_OO_O_method \
 
933
         (char **, npy_intp *, npy_intp *, void *)
 
934
    void PyUFunc_On_Om \
 
935
         (char **, npy_intp *, npy_intp *, void *)
 
936
    int PyUFunc_GetPyValues \
 
937
        (char *, int *, int *, PyObject **)
 
938
    int PyUFunc_checkfperr \
 
939
           (int, PyObject *, int *)
 
940
    void PyUFunc_clearfperr()
 
941
    int PyUFunc_getfperr()
 
942
    int PyUFunc_handlefperr \
 
943
        (int, PyObject *, int, int *)
 
944
    int PyUFunc_ReplaceLoopBySignature \
 
945
        (ufunc, PyUFuncGenericFunction, int *, PyUFuncGenericFunction *)
 
946
    object PyUFunc_FromFuncAndDataAndSignature \
 
947
             (PyUFuncGenericFunction *, void **, char *, int, int, int,
 
948
              int, char *, char *, int, char *)
 
949
 
 
950
    void import_ufunc()
 
951
 
 
952
 
 
953
cdef inline void set_array_base(ndarray arr, object base):
 
954
     cdef PyObject* baseptr
 
955
     if base is None:
 
956
         baseptr = NULL
 
957
     else:
 
958
         Py_INCREF(base) # important to do this before decref below!
 
959
         baseptr = <PyObject*>base
 
960
     Py_XDECREF(arr.base)
 
961
     arr.base = baseptr
 
962
 
 
963
cdef inline object get_array_base(ndarray arr):
 
964
    if arr.base is NULL:
 
965
        return None
 
966
    else:
 
967
        return <object>arr.base