~ubuntu-branches/ubuntu/feisty/python-numpy/feisty

« back to all changes in this revision

Viewing changes to numpy/core/include/numpy/arrayobject.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-07-12 10:00:24 UTC
  • Revision ID: james.westby@ubuntu.com-20060712100024-5lw9q2yczlisqcrt
Tags: upstream-0.9.8
ImportĀ upstreamĀ versionĀ 0.9.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* This expects the following variables to be defined (besides
 
3
   the usual ones from pyconfig.h
 
4
 
 
5
   SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no
 
6
                         long double is present on platform.
 
7
   CHAR_BIT       --     number of bits in a char (usually 8)
 
8
                         (should be in limits.h)
 
9
*/
 
10
 
 
11
#ifndef Py_ARRAYOBJECT_H
 
12
#define Py_ARRAYOBJECT_H
 
13
#ifdef __cplusplus
 
14
#define CONFUSE_EMACS {
 
15
#define CONFUSE_EMACS2 }
 
16
extern "C" CONFUSE_EMACS
 
17
#undef CONFUSE_EMACS
 
18
#undef CONFUSE_EMACS2
 
19
/* ... otherwise a semi-smart idententer (like emacs) tries to indent
 
20
       everything when you're typing */
 
21
#endif
 
22
#include "config.h"
 
23
 
 
24
#ifdef PY_ARRAY_TYPES_PREFIX
 
25
#  define CAT2(x,y)   x ## y
 
26
#  define CAT(x,y)    CAT2(x,y)
 
27
#  define NS(name)    CAT(PY_ARRAY_TYPES_PREFIX, name)
 
28
#  define longlong    NS(longlong)
 
29
#  define ulonglong   NS(ulonglong)
 
30
#  define Bool        NS(Bool)
 
31
#  define longdouble  NS(longdouble)
 
32
#  define byte        NS(byte)
 
33
#  define ubyte       NS(ubyte)
 
34
#  define ushort      NS(ushort)
 
35
#  define uint        NS(uint)
 
36
#  define ulong       NS(ulong)
 
37
#  define cfloat      NS(cfloat)
 
38
#  define cdouble     NS(cdouble)
 
39
#  define clongdouble NS(clongdouble)
 
40
#  define Int8        NS(Int8)
 
41
#  define UInt8       NS(UInt8)
 
42
#  define Int16       NS(Int16)
 
43
#  define UInt16      NS(UInt16)
 
44
#  define Int32       NS(Int32)
 
45
#  define UInt32      NS(UInt32)
 
46
#  define Int64       NS(Int64)
 
47
#  define UInt64      NS(UInt64)
 
48
#  define Int128      NS(Int128)
 
49
#  define UInt128     NS(UInt128)
 
50
#  define Int256      NS(Int256)
 
51
#  define UInt256     NS(UInt256)
 
52
#  define Float16     NS(Float16)
 
53
#  define Complex32   NS(Complex32)
 
54
#  define Float32     NS(Float32)
 
55
#  define Complex64   NS(Complex64)
 
56
#  define Float64     NS(Float64)
 
57
#  define Complex128  NS(Complex128)
 
58
#  define Float80     NS(Float80)
 
59
#  define Complex160  NS(Complex160)
 
60
#  define Float96     NS(Float96)
 
61
#  define Complex192  NS(Complex192)
 
62
#  define Float128    NS(Float128)
 
63
#  define Complex256  NS(Complex256)
 
64
#  define intp        NS(intp)
 
65
#  define uintp       NS(uintp)
 
66
#endif
 
67
 
 
68
/* There are several places in the code where an array of dimensions is */
 
69
/* allocated statically.  This is the size of that static allocation. */
 
70
/*  The array creation itself could have arbitrary dimensions but
 
71
 *  all the places where static allocation is used would need to
 
72
 *  be changed to dynamic (including inside of structures)
 
73
 */
 
74
 
 
75
#define MAX_DIMS 32
 
76
 
 
77
/* Used for Converter Functions "O&" code in ParseTuple */
 
78
#define PY_FAIL 0
 
79
#define PY_SUCCEED 1
 
80
 
 
81
        /* Helpful to distinguish what is installed */
 
82
#define NDARRAY_VERSION 0x00090709
 
83
 
 
84
        /* Some platforms don't define bool, long long, or long double.
 
85
           Handle that here.
 
86
         */
 
87
 
 
88
#ifdef PY_LONG_LONG
 
89
typedef PY_LONG_LONG longlong;
 
90
typedef unsigned PY_LONG_LONG ulonglong;
 
91
#  ifdef _MSC_VER
 
92
#    define LONGLONG_FMT         "I64d"
 
93
#    define ULONGLONG_FMT        "I64u"
 
94
#    define LONGLONG_SUFFIX(x)   (x##i64)
 
95
#    define ULONGLONG_SUFFIX(x)  (x##Ui64)
 
96
#  else
 
97
        /* #define LONGLONG_FMT   "lld"      Another possible variant
 
98
           #define ULONGLONG_FMT  "llu"
 
99
 
 
100
           #define LONGLONG_FMT   "qd"   -- BSD perhaps?
 
101
           #define ULONGLONG_FMT   "qu"
 
102
        */
 
103
#    define LONGLONG_FMT         "Ld"
 
104
#    define ULONGLONG_FMT        "Lu"
 
105
#    define LONGLONG_SUFFIX(x)   (x##LL)
 
106
#    define ULONGLONG_SUFFIX(x)  (x##ULL)
 
107
#  endif
 
108
#else
 
109
typedef long longlong;
 
110
typedef unsigned long ulonglong;
 
111
#  define LONGLONG_SUFFIX(x)  (x##L)
 
112
#  define ULONGLONG_SUFFIX(x) (x##UL)
 
113
#endif
 
114
 
 
115
typedef unsigned char Bool;
 
116
#ifndef FALSE
 
117
#define FALSE 0
 
118
#endif
 
119
#ifndef TRUE
 
120
#define TRUE 1
 
121
#endif
 
122
 
 
123
#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE
 
124
        typedef double longdouble;
 
125
        #define LONGDOUBLE_FMT "g"
 
126
#else
 
127
        typedef long double longdouble;
 
128
        #define LONGDOUBLE_FMT "Lg"
 
129
#endif
 
130
 
 
131
#ifndef Py_USING_UNICODE
 
132
#error Must use Python with unicode enabled. 
 
133
#endif
 
134
 
 
135
 
 
136
typedef signed char byte;
 
137
typedef unsigned char ubyte;
 
138
#ifndef _BSD_SOURCE
 
139
typedef unsigned short ushort;
 
140
typedef unsigned int uint;
 
141
typedef unsigned long ulong;
 
142
#endif
 
143
 
 
144
typedef struct { float real, imag; } cfloat;
 
145
typedef struct { double real, imag; } cdouble;
 
146
typedef struct {longdouble real, imag;} clongdouble;
 
147
 
 
148
enum PyArray_TYPES {    PyArray_BOOL=0,
 
149
                        PyArray_BYTE, PyArray_UBYTE,
 
150
                        PyArray_SHORT, PyArray_USHORT,
 
151
                        PyArray_INT, PyArray_UINT,
 
152
                        PyArray_LONG, PyArray_ULONG,
 
153
                        PyArray_LONGLONG, PyArray_ULONGLONG,
 
154
                        PyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,
 
155
                        PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,
 
156
                        PyArray_OBJECT=17,
 
157
                        PyArray_STRING, PyArray_UNICODE,
 
158
                        PyArray_VOID,
 
159
                        PyArray_NTYPES,
 
160
                        PyArray_NOTYPE,
 
161
                        PyArray_CHAR,      /* special flag */
 
162
                        PyArray_USERDEF=256  /* leave room for characters */
 
163
};
 
164
 
 
165
        /* basetype array priority */
 
166
#define PyArray_PRIORITY 0.0
 
167
#define PyArray_BIG_PRIORITY 0.1
 
168
        /* default subtype priority */
 
169
#define PyArray_SUBTYPE_PRIORITY 1.0
 
170
 
 
171
        /* How many floating point types are there */
 
172
#define PyArray_NUM_FLOATTYPE 3
 
173
 
 
174
 
 
175
        /* We need to match intp to a signed integer of the same size as
 
176
           a pointer variable. uintp to the equivalent unsigned integer
 
177
        */
 
178
 
 
179
 
 
180
        /* These characters correspond to the array type and the
 
181
           struct module */
 
182
 
 
183
        /*  except 'p' -- signed integer for pointer type */
 
184
 
 
185
enum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',
 
186
                        PyArray_BYTELTR = 'b',
 
187
                        PyArray_UBYTELTR = 'B',
 
188
                        PyArray_SHORTLTR = 'h',
 
189
                        PyArray_USHORTLTR = 'H',
 
190
                        PyArray_INTLTR = 'i',
 
191
                        PyArray_UINTLTR = 'I',
 
192
                        PyArray_LONGLTR = 'l',
 
193
                        PyArray_ULONGLTR = 'L',
 
194
                        PyArray_LONGLONGLTR = 'q',
 
195
                        PyArray_ULONGLONGLTR = 'Q',
 
196
                        PyArray_FLOATLTR = 'f',
 
197
                        PyArray_DOUBLELTR = 'd',
 
198
                        PyArray_LONGDOUBLELTR = 'g',
 
199
                        PyArray_CFLOATLTR = 'F',
 
200
                        PyArray_CDOUBLELTR = 'D',
 
201
                        PyArray_CLONGDOUBLELTR = 'G',
 
202
                        PyArray_OBJECTLTR = 'O',
 
203
                        PyArray_STRINGLTR = 'S',
 
204
                        PyArray_STRINGLTR2 = 'a',
 
205
                        PyArray_UNICODELTR = 'U',
 
206
                        PyArray_VOIDLTR = 'V',
 
207
                        PyArray_CHARLTR = 'c',
 
208
 
 
209
                        /* No Descriptor, just a define -- this let's
 
210
                         Python users specify an array of integers
 
211
                         large enough to hold a pointer on the platform*/
 
212
                        PyArray_INTPLTR = 'p',
 
213
                        PyArray_UINTPLTR = 'P',
 
214
 
 
215
                        PyArray_GENBOOLLTR ='b',
 
216
                        PyArray_SIGNEDLTR = 'i',
 
217
                        PyArray_UNSIGNEDLTR = 'u',
 
218
                        PyArray_FLOATINGLTR = 'f',
 
219
                        PyArray_COMPLEXLTR = 'c'
 
220
};
 
221
 
 
222
typedef enum {
 
223
        PyArray_QUICKSORT=0,
 
224
        PyArray_HEAPSORT=1,
 
225
        PyArray_MERGESORT=2,
 
226
        PyArray_TIMSORT=3         /* the sort Python uses -- specialized */
 
227
} PyArray_SORTKIND;
 
228
#define PyArray_NSORTS PyArray_TIMSORT + 1
 
229
 
 
230
 
 
231
typedef enum {
 
232
        PyArray_NOSCALAR=0,
 
233
        PyArray_BOOL_SCALAR=1,
 
234
        PyArray_INTPOS_SCALAR=2,
 
235
        PyArray_INTNEG_SCALAR=3,
 
236
        PyArray_FLOAT_SCALAR=4,
 
237
        PyArray_COMPLEX_SCALAR=5,
 
238
        PyArray_OBJECT_SCALAR=6
 
239
} PyArray_SCALARKIND;
 
240
 
 
241
typedef enum {
 
242
        PyArray_ANYORDER=-1,
 
243
        PyArray_CORDER=0,
 
244
        PyArray_FORTRANORDER=1
 
245
} PyArray_ORDER;
 
246
 
 
247
 
 
248
 
 
249
        /* Define bit-width array types and typedefs */
 
250
 
 
251
#define MAX_INT8 127
 
252
#define MIN_INT8 -128
 
253
#define MAX_UINT8 255
 
254
#define MAX_INT16 32767
 
255
#define MIN_INT16 -32768
 
256
#define MAX_UINT16 65535
 
257
#define MAX_INT32 2147483647
 
258
#define MIN_INT32 (-MAX_INT32 - 1)
 
259
#define MAX_UINT32 4294967295U
 
260
#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)
 
261
#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))
 
262
#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)
 
263
#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)
 
264
#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))
 
265
#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)
 
266
#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)
 
267
#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))
 
268
#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)
 
269
 
 
270
        /* Need to find the number of bits for each type and
 
271
           make definitions accordingly.
 
272
 
 
273
           C states that sizeof(char) == 1 by definition
 
274
 
 
275
           So, just using the sizeof keyword won't help.
 
276
 
 
277
           It also looks like Python itself uses sizeof(char) quite a
 
278
           bit, which by definition should be 1 all the time.
 
279
 
 
280
           Idea: Make Use of CHAR_BIT which should tell us how many
 
281
           BITS per CHARACTER
 
282
        */
 
283
 
 
284
        /* Include platform definitions -- These are in the C89/90 standard */
 
285
#include <limits.h>
 
286
#define MAX_BYTE SCHAR_MAX
 
287
#define MIN_BYTE SCHAR_MIN
 
288
#define MAX_UBYTE UCHAR_MAX
 
289
#define MAX_SHORT SHRT_MAX
 
290
#define MIN_SHORT SHRT_MIN
 
291
#define MAX_USHORT USHRT_MAX
 
292
#define MAX_INT   INT_MAX
 
293
#ifndef INT_MIN
 
294
#define INT_MIN (-INT_MAX - 1)
 
295
#endif
 
296
#define MIN_INT   INT_MIN
 
297
#define MAX_UINT  UINT_MAX
 
298
#define MAX_LONG  LONG_MAX
 
299
#define MIN_LONG  LONG_MIN
 
300
#define MAX_ULONG  ULONG_MAX
 
301
 
 
302
#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE
 
303
#define SIZEOF_LONGLONG SIZEOF_LONG_LONG
 
304
#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT
 
305
#define BITSOF_CHAR CHAR_BIT
 
306
#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)
 
307
#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)
 
308
#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)
 
309
#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)
 
310
#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)
 
311
#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)
 
312
#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)
 
313
 
 
314
 
 
315
#if BITSOF_LONG == 8
 
316
#define PyArray_INT8 PyArray_LONG
 
317
#define PyArray_UINT8 PyArray_ULONG
 
318
        typedef long Int8;
 
319
        typedef unsigned long UInt8;
 
320
#define STRBITSOF_LONG "8"
 
321
#elif BITSOF_LONG == 16
 
322
#define PyArray_INT16 PyArray_LONG
 
323
#define PyArray_UINT16 PyArray_ULONG
 
324
        typedef long Int16;
 
325
        typedef unsigned long UInt16;
 
326
#define STRBITSOF_LONG "16"
 
327
#elif BITSOF_LONG == 32
 
328
#define PyArray_INT32 PyArray_LONG
 
329
#define PyArray_UINT32 PyArray_ULONG
 
330
        typedef long Int32;
 
331
        typedef unsigned long UInt32;
 
332
        typedef unsigned long PyArray_UCS4;
 
333
#define STRBITSOF_LONG "32"
 
334
#elif BITSOF_LONG == 64
 
335
#define PyArray_INT64 PyArray_LONG
 
336
#define PyArray_UINT64 PyArray_ULONG
 
337
        typedef long Int64;
 
338
        typedef unsigned long UInt64;
 
339
#define STRBITSOF_LONG "64"
 
340
#elif BITSOF_LONG == 128
 
341
#define PyArray_INT128 PyArray_LONG
 
342
#define PyArray_UINT128 PyArray_ULONG
 
343
        typedef long Int128;
 
344
        typedef unsigned long UInt128;
 
345
#define STRBITSOF_LONG "128"
 
346
#endif
 
347
 
 
348
#if BITSOF_LONGLONG == 8
 
349
#  ifndef PyArray_INT8
 
350
#    define PyArray_INT8 PyArray_LONGLONG
 
351
#    define PyArray_UINT8 PyArray_ULONGLONG
 
352
        typedef longlong Int8;
 
353
        typedef ulonglong UInt8;
 
354
#  endif
 
355
#  define MAX_LONGLONG MAX_INT8
 
356
#  define MIN_LONGLONG MIN_INT8
 
357
#  define MAX_ULONGLONG MAX_UINT8
 
358
#define STRBITSOF_LONGLONG "8"
 
359
#elif BITSOF_LONGLONG == 16
 
360
#  ifndef PyArray_INT16
 
361
#    define PyArray_INT16 PyArray_LONGLONG
 
362
#    define PyArray_UINT16 PyArray_ULONGLONG
 
363
        typedef longlong Int16;
 
364
        typedef ulonglong UInt16;
 
365
#  endif
 
366
#  define MAX_LONGLONG MAX_INT16
 
367
#  define MIN_LONGLONG MIN_INT16
 
368
#  define MAX_ULONGLONG MAX_UINT16
 
369
#define STRBITSOF_LONGLONG "16"
 
370
#elif BITSOF_LONGLONG == 32
 
371
#  ifndef PyArray_INT32
 
372
#    define PyArray_INT32 PyArray_LONGLONG
 
373
#    define PyArray_UINT32 PyArray_ULONGLONG
 
374
        typedef longlong Int32;
 
375
        typedef ulonglong UInt32;
 
376
        typedef ulonglong PyArray_UCS4;
 
377
#  endif
 
378
#  define MAX_LONGLONG MAX_INT32
 
379
#  define MIN_LONGLONG MIN_INT32
 
380
#  define MAX_ULONGLONG MAX_UINT32
 
381
#define STRBITSOF_LONGLONG "32"
 
382
#elif BITSOF_LONGLONG == 64
 
383
#  ifndef PyArray_INT64
 
384
#    define PyArray_INT64 PyArray_LONGLONG
 
385
#    define PyArray_UINT64 PyArray_ULONGLONG
 
386
        typedef longlong Int64;
 
387
        typedef ulonglong UInt64;
 
388
#  endif
 
389
#  define MAX_LONGLONG MAX_INT64
 
390
#  define MIN_LONGLONG MIN_INT64
 
391
#  define MAX_ULONGLONG MAX_UINT64
 
392
#define STRBITSOF_LONGLONG "64"
 
393
#elif BITSOF_LONGLONG == 128
 
394
#  ifndef PyArray_INT128
 
395
#    define PyArray_INT128 PyArray_LONGLONG
 
396
#    define PyArray_UINT128 PyArray_ULONGLONG
 
397
        typedef longlong Int128;
 
398
        typedef ulonglong UInt128;
 
399
#  endif
 
400
#  define MAX_LONGLONG MAX_INT128
 
401
#  define MIN_LONGLONG MIN_INT128
 
402
#  define MAX_ULONGLONG MAX_UINT128
 
403
#define STRBITSOF_LONGLONG "128"
 
404
#elif BITSOF_LONGLONG == 256
 
405
#  define PyArray_INT256 PyArray_LONGLONG
 
406
#  define PyArray_UINT256 PyArray_ULONGLONG
 
407
        typedef longlong Int256;
 
408
        typedef ulonglong UInt256;
 
409
#  define MAX_LONGLONG MAX_INT256
 
410
#  define MIN_LONGLONG MIN_INT256
 
411
#  define MAX_ULONGLONG MAX_UINT256
 
412
#define STRBITSOF_LONGLONG "256"
 
413
#endif
 
414
 
 
415
#if BITSOF_INT == 8
 
416
#ifndef PyArray_INT8
 
417
#define PyArray_INT8 PyArray_INT
 
418
#define PyArray_UINT8 PyArray_UINT
 
419
        typedef int Int8;
 
420
        typedef unsigned int UInt8;
 
421
#endif
 
422
#define STRBITSOF_INT "8"
 
423
#elif BITSOF_INT == 16
 
424
#ifndef PyArray_INT16
 
425
#define PyArray_INT16 PyArray_INT
 
426
#define PyArray_UINT16 PyArray_UINT
 
427
        typedef int Int16;
 
428
        typedef unsigned int UInt16;
 
429
#endif
 
430
#define STRBITSOF_INT "16"
 
431
#elif BITSOF_INT == 32
 
432
#ifndef PyArray_INT32
 
433
#define PyArray_INT32 PyArray_INT
 
434
#define PyArray_UINT32 PyArray_UINT
 
435
        typedef int Int32;
 
436
        typedef unsigned int UInt32;
 
437
        typedef unsigned int PyArray_UCS4;
 
438
#endif
 
439
#define STRBITSOF_INT "32"
 
440
#elif BITSOF_INT == 64
 
441
#ifndef PyArray_INT64
 
442
#define PyArray_INT64 PyArray_INT
 
443
#define PyArray_UINT64 PyArray_UINT
 
444
        typedef int Int64;
 
445
        typedef unsigned int UInt64;
 
446
#endif
 
447
#define STRBITSOF_INT "64"
 
448
#elif BITSOF_INT == 128
 
449
#ifndef PyArray_INT128
 
450
#define PyArray_INT128 PyArray_INT
 
451
#define PyArray_UINT128 PyArray_UINT
 
452
        typedef int Int128;
 
453
        typedef unsigned int UInt128;
 
454
#endif
 
455
#define STRBITSOF_INT "128"
 
456
#endif
 
457
 
 
458
#if BITSOF_SHORT == 8
 
459
#ifndef PyArray_INT8
 
460
#define PyArray_INT8 PyArray_SHORT
 
461
#define PyArray_UINT8 PyArray_USHORT
 
462
        typedef short Int8;
 
463
        typedef unsigned short UInt8;
 
464
#endif
 
465
#define STRBITSOF_SHORT "8"
 
466
#elif BITSOF_SHORT == 16
 
467
#ifndef PyArray_INT16
 
468
#define PyArray_INT16 PyArray_SHORT
 
469
#define PyArray_UINT16 PyArray_USHORT
 
470
        typedef short Int16;
 
471
        typedef unsigned short UInt16;
 
472
#endif
 
473
#define STRBITSOF_SHORT "16"
 
474
#elif BITSOF_SHORT == 32
 
475
#ifndef PyArray_INT32
 
476
#define PyArray_INT32 PyArray_SHORT
 
477
#define PyArray_UINT32 PyArray_USHORT
 
478
        typedef short Int32;
 
479
        typedef unsigned short UInt32;
 
480
        typedef unsigned short PyArray_UCS4;
 
481
#endif
 
482
#define STRBITSOF_SHORT "32"
 
483
#elif BITSOF_SHORT == 64
 
484
#ifndef PyArray_INT64
 
485
#define PyArray_INT64 PyArray_SHORT
 
486
#define PyArray_UINT64 PyArray_USHORT
 
487
        typedef short Int64;
 
488
        typedef unsigned short UInt64;
 
489
#endif
 
490
#define STRBITSOF_SHORT "64"
 
491
#elif BITSOF_SHORT == 128
 
492
#ifndef PyArray_INT128
 
493
#define PyArray_INT128 PyArray_SHORT
 
494
#define PyArray_UINT128 PyArray_USHORT
 
495
        typedef short Int128;
 
496
        typedef unsigned short UInt128;
 
497
#endif
 
498
#define STRBITSOF_SHORT "128"
 
499
#endif
 
500
 
 
501
 
 
502
#if BITSOF_CHAR == 8
 
503
#ifndef PyArray_INT8
 
504
#define PyArray_INT8 PyArray_BYTE
 
505
#define PyArray_UINT8 PyArray_UBYTE
 
506
        typedef signed char Int8;
 
507
        typedef unsigned char UInt8;
 
508
#endif
 
509
#define STRBITSOF_CHAR "8"
 
510
#elif BITSOF_CHAR == 16
 
511
#ifndef PyArray_INT16
 
512
#define PyArray_INT16 PyArray_BYTE
 
513
#define PyArray_UINT16 PyArray_UBYTE
 
514
        typedef signed char Int16;
 
515
        typedef unsigned char UInt16;
 
516
#endif
 
517
#define STRBITSOF_CHAR "16"
 
518
#elif BITSOF_CHAR == 32
 
519
#ifndef PyArray_INT32
 
520
#define PyArray_INT32 PyArray_BYTE
 
521
#define PyArray_UINT32 PyArray_UBYTE
 
522
        typedef signed char Int32;
 
523
        typedef unsigned char UInt32;
 
524
        typedef unsigned char PyArray_UCS4;
 
525
#endif
 
526
#define STRBITSOF_CHAR "32"
 
527
#elif BITSOF_CHAR == 64
 
528
#ifndef PyArray_INT64
 
529
#define PyArray_INT64 PyArray_BYTE
 
530
#define PyArray_UINT64 PyArray_UBYTE
 
531
        typedef signed char Int64;
 
532
        typedef unsigned char UInt64;
 
533
#endif
 
534
#define STRBITSOF_CHAR "64"
 
535
#elif BITSOF_CHAR == 128
 
536
#ifndef PyArray_INT128
 
537
#define PyArray_INT128 PyArray_BYTE
 
538
#define PyArray_UINT128 PyArray_UBYTE
 
539
        typedef signed char Int128;
 
540
        typedef unsigned char UInt128;
 
541
#endif
 
542
#define STRBITSOF_CHAR "128"
 
543
#endif
 
544
 
 
545
 
 
546
 
 
547
#if BITSOF_DOUBLE == 16
 
548
#define STRBITSOF_DOUBLE "16"
 
549
#define STRBITSOF_CDOUBLE "32"
 
550
#ifndef PyArray_FLOAT16
 
551
#define PyArray_FLOAT16 PyArray_DOUBLE
 
552
#define PyArray_COMPLEX32 PyArray_CDOUBLE
 
553
        typedef  double Float16;
 
554
        typedef cdouble Complex32;
 
555
#endif
 
556
#elif BITSOF_DOUBLE == 32
 
557
#define STRBITSOF_DOUBLE "32"
 
558
#define STRBITSOF_CDOUBLE "64"
 
559
#ifndef PyArray_FLOAT32
 
560
#define PyArray_FLOAT32 PyArray_DOUBLE
 
561
#define PyArray_COMPLEX64 PyArray_CDOUBLE
 
562
        typedef double Float32;
 
563
        typedef cdouble Complex64;
 
564
#endif
 
565
#elif BITSOF_DOUBLE == 64
 
566
#define STRBITSOF_DOUBLE "64"
 
567
#define STRBITSOF_CDOUBLE "128"
 
568
#ifndef PyArray_FLOAT64
 
569
#define PyArray_FLOAT64 PyArray_DOUBLE
 
570
#define PyArray_COMPLEX128 PyArray_CDOUBLE
 
571
        typedef double Float64;
 
572
        typedef cdouble Complex128;
 
573
#endif
 
574
#elif BITSOF_DOUBLE == 80
 
575
#define STRBITSOF_DOUBLE "80"
 
576
#define STRBITSOF_CDOUBLE "160"
 
577
#ifndef PyArray_FLOAT80
 
578
#define PyArray_FLOAT80 PyArray_DOUBLE
 
579
#define PyArray_COMPLEX160 PyArray_CDOUBLE
 
580
        typedef double Float80;
 
581
        typedef cdouble Complex160;
 
582
#endif
 
583
#elif BITSOF_DOUBLE == 96
 
584
#define STRBITSOF_DOUBLE "96"
 
585
#define STRBITSOF_CDOUBLE "192"
 
586
#ifndef PyArray_FLOAT96
 
587
#define PyArray_FLOAT96 PyArray_DOUBLE
 
588
#define PyArray_COMPLEX192 PyArray_CDOUBLE
 
589
        typedef double Float96;
 
590
        typedef cdouble Complex192;
 
591
#endif
 
592
#elif BITSOF_DOUBLE == 128
 
593
#define STRBITSOF_DOUBLE "128"
 
594
#define STRBITSOF_CDOUBLE "256"
 
595
#ifndef PyArray_FLOAT128
 
596
#define PyArray_FLOAT128 PyArray_DOUBLE
 
597
#define PyArray_COMPLEX256 PyArray_CDOUBLE
 
598
        typedef double Float128;
 
599
        typedef cdouble Complex256;
 
600
#endif
 
601
#endif
 
602
 
 
603
 
 
604
 
 
605
#if BITSOF_FLOAT == 16
 
606
#define STRBITSOF_FLOAT "16"
 
607
#define STRBITSOF_CFLOAT "32"
 
608
#ifndef PyArray_FLOAT16
 
609
#define PyArray_FLOAT16 PyArray_FLOAT
 
610
#define PyArray_COMPLEX32 PyArray_CFLOAT
 
611
        typedef float Float16;
 
612
        typedef cfloat Complex32;
 
613
#endif
 
614
#elif BITSOF_FLOAT == 32
 
615
#define STRBITSOF_FLOAT "32"
 
616
#define STRBITSOF_CFLOAT "64"
 
617
#ifndef PyArray_FLOAT32
 
618
#define PyArray_FLOAT32 PyArray_FLOAT
 
619
#define PyArray_COMPLEX64 PyArray_CFLOAT
 
620
        typedef float Float32;
 
621
        typedef cfloat Complex64;
 
622
#endif
 
623
#elif BITSOF_FLOAT == 64
 
624
#define STRBITSOF_FLOAT "64"
 
625
#define STRBITSOF_CFLOAT "128"
 
626
#ifndef PyArray_FLOAT64
 
627
#define PyArray_FLOAT64 PyArray_FLOAT
 
628
#define PyArray_COMPLEX128 PyArray_CFLOAT
 
629
        typedef float Float64;
 
630
        typedef cfloat Complex128;
 
631
#endif
 
632
#elif BITSOF_FLOAT == 80
 
633
#define STRBITSOF_FLOAT "80"
 
634
#define STRBITSOF_CFLOAT "160"
 
635
#ifndef PyArray_FLOAT80
 
636
#define PyArray_FLOAT80 PyArray_FLOAT
 
637
#define PyArray_COMPLEX160 PyArray_CFLOAT
 
638
        typedef float Float80;
 
639
        typedef cfloat Complex160;
 
640
#endif
 
641
#elif BITSOF_FLOAT == 96
 
642
#define STRBITSOF_FLOAT "96"
 
643
#define STRBITSOF_CFLOAT "192"
 
644
#ifndef PyArray_FLOAT96
 
645
#define PyArray_FLOAT96 PyArray_FLOAT
 
646
#define PyArray_COMPLEX192 PyArray_CFLOAT
 
647
        typedef float Float96;
 
648
        typedef cfloat Complex192;
 
649
#endif
 
650
#elif BITSOF_FLOAT == 128
 
651
#define STRBITSOF_FLOAT "128"
 
652
#define STRBITSOF_CFLOAT "256"
 
653
#ifndef PyArray_FLOAT128
 
654
#define PyArray_FLOAT128 PyArray_FLOAT
 
655
#define PyArray_COMPLEX256 PyArray_CFLOAT
 
656
        typedef float Float128;
 
657
        typedef cfloat Complex256;
 
658
#endif
 
659
#endif
 
660
 
 
661
 
 
662
#if BITSOF_LONGDOUBLE == 16
 
663
#define STRBITSOF_LONGDOUBLE "16"
 
664
#define STRBITSOF_CLONGDOUBLE "32"
 
665
#ifndef PyArray_FLOAT16
 
666
#define PyArray_FLOAT16 PyArray_LONGDOUBLE
 
667
#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE
 
668
        typedef  longdouble Float16;
 
669
        typedef clongdouble Complex32;
 
670
#endif
 
671
#elif BITSOF_LONGDOUBLE == 32
 
672
#define STRBITSOF_LONGDOUBLE "32"
 
673
#define STRBITSOF_CLONGDOUBLE "64"
 
674
#ifndef PyArray_FLOAT32
 
675
#define PyArray_FLOAT32 PyArray_LONGDOUBLE
 
676
#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE
 
677
        typedef longdouble Float32;
 
678
        typedef clongdouble Complex64;
 
679
#endif
 
680
#elif BITSOF_LONGDOUBLE == 64
 
681
#define STRBITSOF_LONGDOUBLE "64"
 
682
#define STRBITSOF_CLONGDOUBLE "128"
 
683
#ifndef PyArray_FLOAT64
 
684
#define PyArray_FLOAT64 PyArray_LONGDOUBLE
 
685
#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE
 
686
        typedef longdouble Float64;
 
687
        typedef clongdouble Complex128;
 
688
#endif
 
689
#elif BITSOF_LONGDOUBLE == 80
 
690
#define STRBITSOF_LONGDOUBLE "80"
 
691
#define STRBITSOF_CLONGDOUBLE "160"
 
692
#ifndef PyArray_FLOAT80
 
693
#define PyArray_FLOAT80 PyArray_LONGDOUBLE
 
694
#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE
 
695
        typedef longdouble Float80;
 
696
        typedef clongdouble Complex160;
 
697
#endif
 
698
#elif BITSOF_LONGDOUBLE == 96
 
699
#define STRBITSOF_LONGDOUBLE "96"
 
700
#define STRBITSOF_CLONGDOUBLE "192"
 
701
#ifndef PyArray_FLOAT96
 
702
#define PyArray_FLOAT96 PyArray_LONGDOUBLE
 
703
#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE
 
704
        typedef longdouble Float96;
 
705
        typedef clongdouble Complex192;
 
706
#endif
 
707
#elif BITSOF_LONGDOUBLE == 128
 
708
#define STRBITSOF_LONGDOUBLE "128"
 
709
#define STRBITSOF_CLONGDOUBLE "256"
 
710
#ifndef PyArray_FLOAT128
 
711
#define PyArray_FLOAT128 PyArray_LONGDOUBLE
 
712
#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE
 
713
        typedef longdouble Float128;
 
714
        typedef clongdouble Complex256;
 
715
#endif
 
716
#elif BITSOF_LONGDOUBLE == 256
 
717
#define STRBITSOF_LONGDOUBLE "256"
 
718
#define STRBITSOF_CLONGDOUBLE "512"
 
719
#define PyArray_FLOAT256 PyArray_LONGDOUBLE
 
720
#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE
 
721
        typedef longdouble Float256;
 
722
        typedef clongdouble Complex512;
 
723
#endif
 
724
 
 
725
        /* End of typedefs for numarray style bit-width names */
 
726
 
 
727
/* This is to typedef Intp to the appropriate pointer size for this platform.
 
728
 * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */
 
729
typedef Py_intptr_t intp;
 
730
typedef Py_uintptr_t uintp;
 
731
#define SIZEOF_INTP SIZEOF_PY_INTPTR_T
 
732
#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T
 
733
 
 
734
#if PY_VERSION_HEX >= 0x02050000
 
735
#define _int_or_ssize_t Py_ssize_t
 
736
#else
 
737
#define _int_or_ssize_t int
 
738
#endif
 
739
 
 
740
#define INTP_FMT "d"
 
741
 
 
742
#if SIZEOF_PY_INTPTR_T == SIZEOF_INT
 
743
        #define PyArray_INTP PyArray_INT
 
744
        #define PyArray_UINTP PyArray_UINT
 
745
        #define PyIntpArrType_Type PyIntArrType_Type
 
746
        #define PyUIntpArrType_Type PyUIntArrType_Type
 
747
        #define MAX_INTP MAX_INT
 
748
        #define MIN_INTP MIN_INT
 
749
        #define MAX_UINTP MAX_UINT
 
750
#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG
 
751
        #define PyArray_INTP PyArray_LONG
 
752
        #define PyArray_UINTP PyArray_ULONG
 
753
        #define PyIntpArrType_Type PyLongArrType_Type
 
754
        #define PyUIntpArrType_Type PyULongArrType_Type
 
755
        #define MAX_INTP MAX_LONG
 
756
        #define MIN_INTP MIN_LONG
 
757
        #define MAX_UINTP MAX_ULONG
 
758
        #undef INTP_FMT
 
759
        #define INTP_FMT "ld"
 
760
#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)
 
761
        #define PyArray_INTP PyArray_LONGLONG
 
762
        #define PyArray_UINTP PyArray_ULONGLONG
 
763
        #define PyIntpArrType_Type PyLongLongArrType_Type
 
764
        #define PyUIntpArrType_Type PyULongLongArrType_Type
 
765
        #define MAX_INTP MAX_LONGLONG
 
766
        #define MIN_INTP MIN_LONGLONG
 
767
        #define MAX_UINTP MAX_ULONGLONG
 
768
        #undef INTP_FMT
 
769
        #define INTP_FMT "Ld"
 
770
#endif
 
771
 
 
772
#define ERR(str) fprintf(stderr, #str); fflush(stderr);
 
773
#define ERR2(str) fprintf(stderr, str); fflush(stderr);
 
774
 
 
775
  /* Macros to define how array, and dimension/strides data is
 
776
     allocated.
 
777
  */
 
778
 
 
779
  /* Data buffer */
 
780
#define PyDataMem_NEW(size) ((char *)malloc(size))
 
781
  /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/
 
782
#define PyDataMem_FREE(ptr)  free(ptr)
 
783
  /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */
 
784
#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))
 
785
 
 
786
#define PyArray_USE_PYMEM 0
 
787
 
 
788
#if PyArray_USE_PYMEM == 1
 
789
#define _pya_malloc PyObject_Malloc
 
790
#define _pya_free PyObject_Free
 
791
#define _pya_realloc PyObject_Realloc
 
792
#else
 
793
#define _pya_malloc malloc
 
794
#define _pya_free free
 
795
#define _pya_realloc realloc
 
796
#endif
 
797
 
 
798
/* Dimensions and strides */
 
799
#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))
 
800
#define PyDimMem_FREE(ptr) _pya_free(ptr)
 
801
#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))
 
802
 
 
803
 
 
804
  /* These must deal with unaligned and swapped data if necessary */
 
805
typedef PyObject * (PyArray_GetItemFunc) (void *, void *);
 
806
typedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);
 
807
 
 
808
typedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, void *);
 
809
typedef void (PyArray_CopySwapFunc)(void *, void *, int, void *);
 
810
typedef Bool (PyArray_NonzeroFunc)(void *, void *);
 
811
 
 
812
 
 
813
  /* These assume aligned and notswapped data -- a buffer will be
 
814
      used before or contiguous data will be obtained
 
815
  */
 
816
typedef int (PyArray_CompareFunc)(const void *, const void *, void *);
 
817
typedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);
 
818
typedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,
 
819
                               void *);
 
820
typedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);
 
821
typedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);
 
822
typedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);
 
823
 
 
824
typedef int (PyArray_FillFunc)(void *, intp, void *);
 
825
 
 
826
typedef int (PyArray_SortFunc)(void *, intp, void *);
 
827
typedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);
 
828
 
 
829
typedef int (PyArray_FillWithScalarFunc)(void *, intp, void *, void *);
 
830
 
 
831
typedef struct {
 
832
        intp *ptr;
 
833
        int len;
 
834
} PyArray_Dims;
 
835
 
 
836
typedef struct {
 
837
        /* Functions to cast to all other standard types*/
 
838
        PyArray_VectorUnaryFunc *cast[PyArray_NTYPES];
 
839
 
 
840
        /* Functions to get and set items with standard
 
841
           Python types -- not array scalars */
 
842
        PyArray_GetItemFunc *getitem;
 
843
        PyArray_SetItemFunc *setitem;
 
844
 
 
845
        /* Copy and/or swap data.  Memory areas may not overlap */
 
846
        /*  Use memmove first if they might */
 
847
        PyArray_CopySwapNFunc *copyswapn;
 
848
        PyArray_CopySwapFunc *copyswap;
 
849
 
 
850
        /* Function to compare items */
 
851
        PyArray_CompareFunc *compare;
 
852
 
 
853
        /* Function to select largest */
 
854
        PyArray_ArgFunc *argmax;
 
855
 
 
856
        /* Function to compute dot product */
 
857
        PyArray_DotFunc *dotfunc;
 
858
 
 
859
        /* Function to scan an ASCII file and
 
860
           place a single value plus possible separator */
 
861
        PyArray_ScanFunc *scanfunc;
 
862
 
 
863
        /* Function to read a single value from a string */
 
864
        /* and adjust the pointer */
 
865
        PyArray_FromStrFunc *fromstr;
 
866
 
 
867
        /* Function to determine if data is zero or not */
 
868
        PyArray_NonzeroFunc *nonzero;
 
869
 
 
870
        /* Used for arange */
 
871
        PyArray_FillFunc *fill;
 
872
 
 
873
        /* Function to fill arrays with scalar values */
 
874
        PyArray_FillWithScalarFunc *fillwithscalar;
 
875
 
 
876
        /* Sorting functions */
 
877
        PyArray_SortFunc *sort[PyArray_NSORTS];
 
878
        PyArray_ArgSortFunc *argsort[PyArray_NSORTS];
 
879
 
 
880
} PyArray_ArrFuncs;
 
881
 
 
882
 
 
883
typedef struct {
 
884
        PyObject_HEAD
 
885
        PyTypeObject *typeobj;  /* the type object representing an
 
886
                                   intance of this type */
 
887
        char kind;              /* kind for this type */
 
888
        char type;              /* unique-character representing this type */
 
889
        char byteorder;         /* '>' (big), '<' (little), '|'
 
890
                                   (not-applicable), or '=' (native). */
 
891
        char hasobject;         /* non-zero if it has object arrays in fields */
 
892
        int type_num;           /* number representing this type */
 
893
        int elsize;             /* element size for this type */
 
894
        int alignment;          /* alignment needed for this type */
 
895
        struct _arr_descr                                       \
 
896
        *subarray;              /* Non-NULL if this type is
 
897
                                   is an array (C-contiguous)
 
898
                                   of some other type
 
899
                                */
 
900
        PyObject *fields;       /* The fields dictionary for this type */
 
901
                                /* For statically defined descr this
 
902
                                   is always Py_None */
 
903
 
 
904
        PyArray_ArrFuncs *f;     /* a table of functions specific for each
 
905
                                    basic data descriptor */
 
906
} PyArray_Descr;
 
907
 
 
908
typedef struct _arr_descr {
 
909
        PyArray_Descr *base;
 
910
        PyObject *shape;       /* a tuple */
 
911
} PyArray_ArrayDescr;
 
912
 
 
913
 
 
914
/*
 
915
  The main array object structure. It is recommended to use the macros
 
916
  defined below (PyArray_DATA and friends) access fields here, instead
 
917
  of the members themselves.
 
918
 */
 
919
 
 
920
typedef struct PyArrayObject {
 
921
        PyObject_HEAD
 
922
        char *data;             /* pointer to raw data buffer */
 
923
        int nd;                 /* number of dimensions, also called ndim */
 
924
        intp *dimensions;       /* size in each dimension */
 
925
        intp *strides;          /* bytes to jump to get to the
 
926
                                   next element in each dimension */
 
927
        PyObject *base;         /* This object should be decref'd
 
928
                                   upon deletion of array */
 
929
                                /* For views it points to the original array */
 
930
                                /* For creation from buffer object it points
 
931
                                   to an object that shold be decref'd on
 
932
                                   deletion */
 
933
                                /* For UPDATEIFCOPY flag this is an array
 
934
                                   to-be-updated upon deletion of this one */
 
935
        PyArray_Descr *descr;   /* Pointer to type structure */
 
936
        int flags;              /* Flags describing array -- see below*/
 
937
        PyObject *weakreflist;  /* For weakreferences */
 
938
} PyArrayObject;
 
939
 
 
940
 
 
941
#define fortran fortran_        /* For some compilers */
 
942
 
 
943
/* Mirrors buffer object to ptr */
 
944
 
 
945
typedef struct {
 
946
        PyObject_HEAD
 
947
        PyObject *base;
 
948
        void *ptr;
 
949
        intp len;
 
950
        int flags;
 
951
} PyArray_Chunk;
 
952
 
 
953
/* Array flags */
 
954
 
 
955
/* Means c-style contiguous (last index varies the fastest). The
 
956
   data elements right after each other. */
 
957
#define CONTIGUOUS    0x0001
 
958
/* set if array is a contiguous Fortran array: the first index
 
959
   varies the fastest in memory (strides array is reverse of
 
960
   C-contiguous array)*/
 
961
#define FORTRAN       0x0002
 
962
 
 
963
/*
 
964
  Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a
 
965
   1-d array is CONTIGUOUS it is also FORTRAN contiguous
 
966
*/
 
967
 
 
968
/* If set, the array owns the data: it will be free'd when the array
 
969
   is deleted. */
 
970
#define OWNDATA       0x0004
 
971
#define OWN_DATA      OWNDATA
 
972
 
 
973
/* An array never has the next four set; they're only used as parameter
 
974
   flags to the the various FromAny functions */
 
975
 
 
976
/* Cause a cast to occur regardless of whether or not it is safe. */
 
977
#define FORCECAST     0x0010
 
978
 
 
979
/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,
 
980
   and WRITEABLE. */
 
981
#define ENSURECOPY    0x0020
 
982
 
 
983
/* Make sure the returned array is an ndarray or a bigndarray */
 
984
#define ENSUREARRAY   0x0040
 
985
 
 
986
/* Make sure that the strides are in units of the element size
 
987
   Needed for some operations with record-arrays.
 
988
*/
 
989
#define ELEMENTSTRIDES 0x0080
 
990
 
 
991
/* Array data is aligned on the appropiate memory address for the
 
992
   type stored according to how the compiler would align things
 
993
   (e.g., an array of integers (4 bytes each) starts on
 
994
   a memory address that's a multiple of 4) */
 
995
#define ALIGNED       0x0100
 
996
/* Array data has the native endianness */
 
997
#define NOTSWAPPED    0x0200
 
998
/* Array data is writeable */
 
999
#define WRITEABLE     0x0400
 
1000
/* If this flag is set, then base contains a pointer to an array of
 
1001
   the same size that should be updated with the current contents of
 
1002
   this array when this array is deallocated
 
1003
*/
 
1004
#define UPDATEIFCOPY  0x1000
 
1005
 
 
1006
 
 
1007
#define BEHAVED_FLAGS ALIGNED | WRITEABLE
 
1008
#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED
 
1009
#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS
 
1010
#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED
 
1011
#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS
 
1012
#define FARRAY_FLAGS_RO FORTRAN | ALIGNED
 
1013
#define DEFAULT_FLAGS CARRAY_FLAGS
 
1014
#define IN_ARRAY CARRAY_FLAGS_RO
 
1015
#define OUT_ARRAY CARRAY_FLAGS 
 
1016
#define INOUT_ARRAY CARRAY_FLAGS | UPDATEIFCOPY
 
1017
#define IN_FARRAY FARRAY_FLAGS_RO
 
1018
#define OUT_FARRAY FARRAY_FLAGS
 
1019
#define INOUT_FARRAY FARRAY_FLAGS | UPDATEIFCOPY
 
1020
 
 
1021
#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED
 
1022
 
 
1023
 
 
1024
/* Size of internal buffers used for alignment */
 
1025
#define PyArray_BUFSIZE 10000
 
1026
#define PyArray_MIN_BUFSIZE 5
 
1027
#define PyArray_MAX_BUFSIZE 100000000
 
1028
 
 
1029
/*
 
1030
 * C API:  consists of Macros and functions.  The MACROS are defined here.
 
1031
 */
 
1032
 
 
1033
 
 
1034
#define PyArray_CHKFLAGS(m, FLAGS) \
 
1035
        ((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))
 
1036
#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)
 
1037
#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)
 
1038
#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)
 
1039
 
 
1040
#ifndef MAX
 
1041
#define MAX(a,b) (((a)>(b))?(a):(b))
 
1042
#endif
 
1043
#ifndef MIN
 
1044
#define MIN(a,b) (((a)<(b))?(a):(b))
 
1045
#endif
 
1046
 
 
1047
/* Useful if a and b have to be evaluated.  */
 
1048
 
 
1049
#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}
 
1050
#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}
 
1051
 
 
1052
#if defined(ALLOW_THREADS)
 
1053
#define BEGIN_THREADS_DEF PyThreadState *_save;
 
1054
#define BEGIN_THREADS _save = PyEval_SaveThread();
 
1055
#define END_THREADS   PyEval_RestoreThread(_save);
 
1056
#define ALLOW_C_API_DEF  PyGILState_STATE __save__;
 
1057
#define ALLOW_C_API      __save__ = PyGILState_Ensure();
 
1058
#define DISABLE_C_API    PyGILState_Release(__save__);
 
1059
#else
 
1060
#define BEGIN_THREADS_DEF
 
1061
#define BEGIN_THREADS
 
1062
#define END_THREADS
 
1063
#define ALLOW_C_API_DEF
 
1064
#define ALLOW_C_API
 
1065
#define DISABLE_C_API
 
1066
#endif
 
1067
 
 
1068
 
 
1069
 
 
1070
 
 
1071
typedef struct {
 
1072
        PyObject_HEAD
 
1073
        int               nd_m1;            /* number of dimensions - 1 */
 
1074
        intp              index, size;
 
1075
        intp              coordinates[MAX_DIMS];/* N-dimensional loop */
 
1076
        intp              dims_m1[MAX_DIMS];    /* ao->dimensions - 1 */
 
1077
        intp              strides[MAX_DIMS];    /* ao->strides or fake */
 
1078
        intp              backstrides[MAX_DIMS];/* how far to jump back */
 
1079
        intp              factors[MAX_DIMS];     /* shape factors */
 
1080
        PyArrayObject     *ao;
 
1081
        char              *dataptr;        /* pointer to current item*/
 
1082
        Bool              contiguous;
 
1083
} PyArrayIterObject;
 
1084
 
 
1085
 
 
1086
/* Iterator API */
 
1087
#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)
 
1088
 
 
1089
#define PyArray_ITER_RESET(it) {                                        \
 
1090
        it->index = 0;                                                  \
 
1091
        it->dataptr = it->ao->data;                                     \
 
1092
        memset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));         \
 
1093
}
 
1094
 
 
1095
#define _PyArray_ITER_NEXT1(it) {               \
 
1096
                it->dataptr += it->strides[0];  \
 
1097
                it->coordinates[0]++;           \
 
1098
        }
 
1099
 
 
1100
#define _PyArray_ITER_NEXT2(it) {                                       \
 
1101
                if (it->coordinates[1] < it->dims_m1[1]) {              \
 
1102
                        it->coordinates[1]++;                           \
 
1103
                        it->dataptr += it->strides[1];                  \
 
1104
                }                                                       \
 
1105
                else {                                                  \
 
1106
                        it->coordinates[1] = 0;                         \
 
1107
                        it->coordinates[0]++;                           \
 
1108
                        it->dataptr += it->strides[0] -                 \
 
1109
                                it->backstrides[1];                     \
 
1110
                }                                                       \
 
1111
        }
 
1112
 
 
1113
#define PyArray_ITER_NEXT(it) {                                         \
 
1114
        it->index++;                                                    \
 
1115
        if (it->nd_m1 == 0) {                                           \
 
1116
                _PyArray_ITER_NEXT1(it);                                \
 
1117
        }                                                               \
 
1118
        else if (it->contiguous)  it->dataptr += it->ao->descr->elsize; \
 
1119
        else if (it->nd_m1 == 1) {                                      \
 
1120
                _PyArray_ITER_NEXT2(it);                                \
 
1121
        }                                                               \
 
1122
        else {                                                          \
 
1123
                int _i_;                                                \
 
1124
                for (_i_ = it->nd_m1; _i_ >= 0; _i_--) {                \
 
1125
                        if (it->coordinates[_i_] <                      \
 
1126
                            it->dims_m1[_i_]) {                         \
 
1127
                                it->coordinates[_i_]++;                 \
 
1128
                                it->dataptr += it->strides[_i_];        \
 
1129
                                break;                                  \
 
1130
                        }                                               \
 
1131
                        else {                                          \
 
1132
                                it->coordinates[_i_] = 0;               \
 
1133
                                it->dataptr -= it->backstrides[_i_];    \
 
1134
                        }                                               \
 
1135
                }                                                       \
 
1136
        }                                                               \
 
1137
}
 
1138
 
 
1139
#define PyArray_ITER_GOTO(it, destination) {                            \
 
1140
                int _i_;                                                \
 
1141
                it->index = 0;                                          \
 
1142
                it->dataptr = it->ao->data;                             \
 
1143
                for (_i_ = it->nd_m1; _i_>=0; _i_--) {                  \
 
1144
                        if (destination[_i_] < 0) {                     \
 
1145
                                destination[_i_] += it->dims_m1[_i_]+1; \
 
1146
                        }                                               \
 
1147
                        it->dataptr += destination[_i_] *               \
 
1148
                                it->strides[_i_];                       \
 
1149
                        it->coordinates[_i_] = destination[_i_];        \
 
1150
                        it->index += destination[_i_] *                 \
 
1151
                                ( _i_==it->nd_m1 ? 1 :                  \
 
1152
                                  it->dims_m1[_i_+1]+1) ;                       \
 
1153
                }                                                       \
 
1154
        }
 
1155
 
 
1156
#define PyArray_ITER_GOTO1D(it, ind) {                                  \
 
1157
                int _i_;                                                \
 
1158
                intp _lind_ = (intp) (ind);                             \
 
1159
                if (_lind_ < 0) _lind_ += it->size;                     \
 
1160
                it->index = _lind_;                                     \
 
1161
                if (it->nd_m1 == 0) {                                   \
 
1162
                        it->dataptr = it->ao->data + _lind_ *           \
 
1163
                                it->strides[0];                         \
 
1164
                }                                                       \
 
1165
                else if (it->contiguous)                                \
 
1166
                        it->dataptr = it->ao->data + _lind_ *           \
 
1167
                                it->ao->descr->elsize;                  \
 
1168
                else {                                                  \
 
1169
                        it->dataptr = it->ao->data;                     \
 
1170
                        for (_i_ = 0; _i_<=it->nd_m1; _i_++) {          \
 
1171
                                it->dataptr += (_lind_ / it->factors[_i_]) \
 
1172
                                        * it->strides[_i_];             \
 
1173
                                _lind_ %= it->factors[_i_];             \
 
1174
                        }                                               \
 
1175
                }                                                       \
 
1176
}
 
1177
 
 
1178
#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr
 
1179
 
 
1180
 
 
1181
/*
 
1182
   Any object passed to PyArray_Broadcast must be binary compatible with
 
1183
   this structure.
 
1184
*/
 
1185
 
 
1186
typedef struct {
 
1187
        PyObject_HEAD
 
1188
 
 
1189
        int                     numiter;               /* number of iters */
 
1190
        intp                    size;                  /* broadcasted size */
 
1191
        intp                    index;                 /* current index */
 
1192
        int                     nd;                    /* number of dims */
 
1193
        intp                    dimensions[MAX_DIMS];  /* dimensions */
 
1194
        PyArrayIterObject       *iters[MAX_DIMS];      /* iterators */
 
1195
} PyArrayMultiIterObject;
 
1196
 
 
1197
#define PyArray_MultiIter_RESET(multi) {                          \
 
1198
                int _mi_;                                         \
 
1199
                PyArrayMultiIterObject *_mul_ = (multi);          \
 
1200
                _mul_->index = 0;                                 \
 
1201
                for (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {   \
 
1202
                        PyArray_ITER_RESET(_mul_->iters[_mi_]);   \
 
1203
                }                                                 \
 
1204
        }
 
1205
 
 
1206
#define PyArray_MultiIter_NEXT(multi) {                          \
 
1207
                int _mi_;                                        \
 
1208
                PyArrayMultiIterObject *_mul_ = (multi);          \
 
1209
                _mul_->index += 1;                               \
 
1210
                for (_mi_=0; _mi_<_mul_->numiter; _mi_++) {      \
 
1211
                        PyArray_ITER_NEXT(_mul_->iters[_mi_]);   \
 
1212
                }                                                \
 
1213
        }
 
1214
 
 
1215
#define PyArray_MultiIter_GOTO(multi, dest) {                           \
 
1216
                int _mi_;                                               \
 
1217
                PyArrayMultiIterObject *_mul_ = (multi);                \
 
1218
                for (_mi_=0; _mi_<_mul_->numiter; _mi_++) {             \
 
1219
                        PyArray_ITER_GOTO(_mul_->iters[_mi_], dest);    \
 
1220
                }                                                       \
 
1221
                _mul_->index = _mul_->iters[0]->index;                  \
 
1222
        }
 
1223
 
 
1224
#define PyArray_MultiIter_GOTO1D(multi, ind) {                          \
 
1225
                int _mi_;                                               \
 
1226
                PyArrayMultiIterObject *_mul_ = (multi);                \
 
1227
                for (_mi_=0; _mi_<_mul_->numiter; _mi_++) {             \
 
1228
                        PyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);   \
 
1229
                }                                                       \
 
1230
                _mul_->index = _mul_->iters[0]->index;                  \
 
1231
        }
 
1232
 
 
1233
#define PyArray_MultiIter_DATA(multi, i) \
 
1234
        ((PyArrayMultiIterObject *)multi)->iters[i]->dataptr
 
1235
 
 
1236
#define PyArray_MultiIter_SIZE(multi) \
 
1237
        ((PyArrayMultiIterObject *)multi)->size;
 
1238
 
 
1239
 
 
1240
/* Store the information needed for fancy-indexing over an array */
 
1241
 
 
1242
typedef struct {
 
1243
        PyObject_HEAD
 
1244
        /* Multi-iterator portion --- needs to be present in this order to
 
1245
           work with PyArray_Broadcast */
 
1246
 
 
1247
        int                     numiter;               /* number of index-array
 
1248
                                                          iterators */
 
1249
        intp                    size;                  /* size of broadcasted
 
1250
                                                          result */
 
1251
        intp                    index;                 /* current index */
 
1252
        int                     nd;                    /* number of dims */
 
1253
        intp                    dimensions[MAX_DIMS];  /* dimensions */
 
1254
        PyArrayIterObject       *iters[MAX_DIMS];      /* index object
 
1255
                                                          iterators */
 
1256
        PyArrayIterObject       *ait;                   /* flat Iterator for
 
1257
                                                          underlying array */
 
1258
 
 
1259
        /* flat iterator for subspace (when numiter < nd) */
 
1260
        PyArrayIterObject       *subspace;
 
1261
 
 
1262
        /* if subspace iteration, then this is the array of
 
1263
           axes in the underlying array represented by the
 
1264
           index objects */
 
1265
        int                     iteraxes[MAX_DIMS];
 
1266
        /* if subspace iteration, the these are the coordinates
 
1267
           to the start of the subspace.
 
1268
        */
 
1269
        intp                    bscoord[MAX_DIMS];
 
1270
 
 
1271
        PyObject                *indexobj;             /* reference to
 
1272
                                                          creating obj */
 
1273
        int                     view;
 
1274
        int                     consec;
 
1275
        char                    *dataptr;
 
1276
 
 
1277
} PyArrayMapIterObject;
 
1278
 
 
1279
/* All sorts of useful ways to look into a PyArrayObject.
 
1280
   These are the recommended over casting to PyArrayObject and accessing
 
1281
   the members directly.
 
1282
 */
 
1283
 
 
1284
#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)
 
1285
#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \
 
1286
                                 PyArray_CHKFLAGS(m, FORTRAN))
 
1287
#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))
 
1288
#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))
 
1289
#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))
 
1290
#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)
 
1291
#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)
 
1292
#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)
 
1293
#define PyArray_DIM(obj,n) (PyArray_DIMS(obj)[n])
 
1294
#define PyArray_STRIDE(obj,n) (PyArray_STRIDES(obj)[n])
 
1295
#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)
 
1296
#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)
 
1297
#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)
 
1298
#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)
 
1299
#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)
 
1300
#define PyArray_GETITEM(obj,itemptr)                    \
 
1301
        ((PyArrayObject *)(obj))->descr->f->getitem((char *)itemptr,    \
 
1302
                                                 (PyArrayObject *)obj);
 
1303
#define PyArray_SETITEM(obj,itemptr,v)                                  \
 
1304
        (obj)->descr->f->setitem((PyObject *)v,(char *)(itemptr),               \
 
1305
                              (PyArrayObject *)(obj));
 
1306
 
 
1307
 
 
1308
#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)
 
1309
#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \
 
1310
                                 (type == PyArray_USHORT) || \
 
1311
                                 (type == PyArray_UINT) ||      \
 
1312
                                 (type == PyArray_ULONG) || \
 
1313
                                 (type == PyArray_ULONGLONG))
 
1314
 
 
1315
#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||     \
 
1316
                               (type == PyArray_SHORT) ||       \
 
1317
                               (type == PyArray_INT) || \
 
1318
                               (type == PyArray_LONG) ||        \
 
1319
                               (type == PyArray_LONGLONG))
 
1320
 
 
1321
#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&    \
 
1322
                                (type <= PyArray_ULONGLONG))
 
1323
 
 
1324
#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) &&  \
 
1325
                              (type <= PyArray_LONGDOUBLE))
 
1326
 
 
1327
#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)
 
1328
 
 
1329
#define PyTypeNum_ISSTRING(type) ((type == PyArray_STRING) || \
 
1330
                               (type == PyArray_UNICODE))
 
1331
 
 
1332
#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \
 
1333
                                (type <= PyArray_CLONGDOUBLE))
 
1334
 
 
1335
#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \
 
1336
                                  (type == PyArray_DOUBLE) ||   \
 
1337
                                  (type == PyArray_CDOUBLE) ||  \
 
1338
                                  (type == PyArray_BOOL) || \
 
1339
                                  (type == PyArray_OBJECT ))
 
1340
 
 
1341
#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \
 
1342
                                    (type<=PyArray_VOID))
 
1343
 
 
1344
#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \
 
1345
                                   (type < PyArray_USERDEF+\
 
1346
                                    PyArray_NUMUSERTYPES))
 
1347
 
 
1348
#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) ||  \
 
1349
                                    PyTypeNum_ISUSERDEF(type))
 
1350
 
 
1351
#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)
 
1352
 
 
1353
#define _PyADt(o) ((PyArray_Descr *)o)->type_num
 
1354
#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))
 
1355
#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))
 
1356
#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))
 
1357
#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))
 
1358
#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))
 
1359
#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))
 
1360
#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))
 
1361
#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))
 
1362
#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))
 
1363
#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))
 
1364
#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))
 
1365
#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))
 
1366
#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))
 
1367
#undef _PyAD
 
1368
 
 
1369
#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))
 
1370
#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))
 
1371
#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))
 
1372
#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))
 
1373
#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))
 
1374
#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))
 
1375
#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))
 
1376
#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))
 
1377
#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))
 
1378
#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))
 
1379
#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))
 
1380
#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))
 
1381
#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))
 
1382
 
 
1383
#define PyArray_LITTLE '<'
 
1384
#define PyArray_BIG '>'
 
1385
#define PyArray_NATIVE '='
 
1386
#define PyArray_SWAP 's'
 
1387
#define PyArray_IGNORE '|'
 
1388
 
 
1389
#ifdef WORDS_BIGENDIAN
 
1390
#define PyArray_NATBYTE PyArray_BIG
 
1391
#define PyArray_OPPBYTE PyArray_LITTLE
 
1392
#else
 
1393
#define PyArray_NATBYTE PyArray_LITTLE
 
1394
#define PyArray_OPPBYTE PyArray_BIG
 
1395
#endif
 
1396
 
 
1397
#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)
 
1398
#define PyArray_IsNativeByteOrder PyArray_ISNBO
 
1399
#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)
 
1400
 
 
1401
#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&       \
 
1402
                                    PyArray_ISNOTSWAPPED(m))
 
1403
#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)
 
1404
#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)
 
1405
#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)
 
1406
#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)
 
1407
#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)
 
1408
#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)
 
1409
 
 
1410
 
 
1411
 
 
1412
/* This is the form of the struct that's returned pointed by the
 
1413
   PyCObject attribute of an array __array_struct__. See
 
1414
   http://numeric.scipy.org/array_interface.html for the full
 
1415
   documentation. */
 
1416
typedef struct {
 
1417
    int version;          /* contains the integer 2 as a sanity check */
 
1418
    int nd;               /* number of dimensions */
 
1419
    char typekind;        /* kind in array --- character code of typestr */
 
1420
    int itemsize;         /* size of each element */
 
1421
    int flags;            /* how should be data interpreted. Valid
 
1422
                             flags are CONTIGUOUS (1), FORTRAN (2),
 
1423
                             ALIGNED (0x100), NOTSWAPPED (0x200), and
 
1424
                             WRITEABLE (0x400)*/
 
1425
    intp *shape;          /* A length-nd array of shape information */
 
1426
    intp *strides;        /* A length-nd array of stride information */
 
1427
    void *data;           /* A pointer to the first element of the array */
 
1428
} PyArrayInterface;
 
1429
 
 
1430
/* Includes the "function" C-API -- these are all stored in a
 
1431
   list of pointers --- one for each file
 
1432
   The two lists are concatenated into one in multiarray.
 
1433
 
 
1434
   They are available as import_array()
 
1435
*/
 
1436
 
 
1437
 
 
1438
#include "__multiarray_api.h"
 
1439
 
 
1440
 
 
1441
/* C-API that requries previous API to be defined */
 
1442
 
 
1443
#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)
 
1444
 
 
1445
#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type ||            \
 
1446
                           PyObject_TypeCheck((op), &PyArray_Type))
 
1447
#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)
 
1448
 
 
1449
#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))
 
1450
#define PyArray_IsScalar(obj, cls)                              \
 
1451
        (PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))
 
1452
#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \
 
1453
                                PyArray_IsZeroDim(m))
 
1454
#define PyArray_IsPythonNumber(obj) \
 
1455
        (PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \
 
1456
         PyLong_Check(obj) || PyBool_Check(obj))
 
1457
#define PyArray_IsPythonScalar(obj) \
 
1458
        (PyArray_IsPythonNumber(obj) || PyString_Check(obj) ||  \
 
1459
         PyUnicode_Check(obj))
 
1460
#define PyArray_IsAnyScalar(obj)                                        \
 
1461
        (PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))
 
1462
#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \
 
1463
                                     PyArray_CheckScalar(obj))
 
1464
 
 
1465
#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \
 
1466
                                  (PyArrayObject *)(PyArray_Copy(m)))
 
1467
 
 
1468
#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))
 
1469
#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))
 
1470
#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)
 
1471
#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)
 
1472
#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \
 
1473
                                                      0, 0, 0, NULL);
 
1474
#define PyArray_FROM_OTF(m, type, flags)                                \
 
1475
        PyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0,           \
 
1476
                        (((flags) & ENSURECOPY) ?                       \
 
1477
                         ((flags) | DEFAULT_FLAGS) : (flags)), NULL)
 
1478
#define PyArray_FROMANY(m, type, min, max, flags)                       \
 
1479
        PyArray_FromAny(m, PyArray_DescrFromType(type), min, max,       \
 
1480
                        (((flags) & ENSURECOPY) ?                       \
 
1481
                         (flags) | DEFAULT_FLAGS : (flags)), NULL)
 
1482
 
 
1483
#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))
 
1484
 
 
1485
#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
 
1486
#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE
 
1487
 
 
1488
#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth)   \
 
1489
        PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
 
1490
                              max_depth, DEFAULT_FLAGS, NULL)
 
1491
 
 
1492
#define PyArray_EquivArrTypes(a1, a2)                                   \
 
1493
        PyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))
 
1494
 
 
1495
#define PyArray_EquivByteorders(b1, b2) \
 
1496
        (((b1) == (b2)) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))
 
1497
 
 
1498
#define PyArray_SimpleNew(nd, dims, typenum) \
 
1499
        PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)
 
1500
#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \
 
1501
        PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)
 
1502
#define PyArray_SimpleNewFromDescr(nd, dims, descr) \
 
1503
        PyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)
 
1504
 
 
1505
#define PyArray_ToScalar(data, arr) \
 
1506
        PyArray_Scalar(data, PyArray_DESCR(arr), (PyObject *)arr)
 
1507
 
 
1508
/* These might be faster without the dereferencing of obj
 
1509
   going on inside -- of course an optimizing compiler should
 
1510
   inline the constants inside a for loop making it a moot point
 
1511
*/
 
1512
 
 
1513
#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +           \
 
1514
                                         i*PyArray_STRIDES(obj)[0])
 
1515
 
 
1516
#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +        \
 
1517
                                            i*PyArray_STRIDES(obj)[0] + \
 
1518
                                            j*PyArray_STRIDES(obj)[1])
 
1519
 
 
1520
#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +     \
 
1521
                                               i*PyArray_STRIDES(obj)[0] + \
 
1522
                                               j*PyArray_STRIDES(obj)[1] + \
 
1523
                                               k*PyArray_STRIDES(obj)[2]) \
 
1524
 
 
1525
#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +  \
 
1526
                                                  i*PyArray_STRIDES(obj)[0] + \
 
1527
                                                  j*PyArray_STRIDES(obj)[1] + \
 
1528
                                                  k*PyArray_STRIDES(obj)[2] + \
 
1529
                                                  l*PyArray_STRIDES(obj)[3])
 
1530
 
 
1531
#define PyArray_DESCR_REPLACE(descr) do {       \
 
1532
                PyArray_Descr *_new_;                   \
 
1533
                _new_ = PyArray_DescrNew(descr);        \
 
1534
                Py_XDECREF(descr);                      \
 
1535
                descr = _new_;                          \
 
1536
        } while(0)
 
1537
 
 
1538
/* Copy should always return contiguous array */
 
1539
#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)
 
1540
 
 
1541
#define PyArray_FromObject(op, type, min_depth, max_depth)              \
 
1542
        PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,     \
 
1543
                              max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)
 
1544
 
 
1545
#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)    \
 
1546
        PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,     \
 
1547
                              max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)
 
1548
 
 
1549
#define PyArray_CopyFromObject(op, type, min_depth, max_depth)          \
 
1550
        PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,     \
 
1551
                        max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)
 
1552
 
 
1553
#define PyArray_Cast(mp, type_num) \
 
1554
        PyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)
 
1555
 
 
1556
/* Compatibility with old Numeric stuff -- don't use in new code */
 
1557
 
 
1558
#define PyArray_FromDimsAndData(nd, d, type, data) \
 
1559
        PyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \
 
1560
                                        data)
 
1561
 
 
1562
#define PyArray_UNSIGNED_TYPES
 
1563
#define PyArray_SBYTE PyArray_BYTE
 
1564
#define PyArray_CopyArray PyArray_CopyInto
 
1565
#define _PyArray_multiply_list PyArray_MultiplyIntList
 
1566
#define PyArray_ISSPACESAVER(m) FALSE
 
1567
#define PyScalarArray_Check PyArray_CheckScalar
 
1568
 
 
1569
#ifdef PY_ARRAY_TYPES_PREFIX
 
1570
#  undef CAT
 
1571
#  undef CAT2
 
1572
#  undef NS
 
1573
#  undef longlong
 
1574
#  undef ulonglong
 
1575
#  undef Bool
 
1576
#  undef longdouble
 
1577
#  undef byte
 
1578
#  undef ubyte
 
1579
#  undef ushort
 
1580
#  undef uint
 
1581
#  undef ulong
 
1582
#  undef cfloat
 
1583
#  undef cdouble
 
1584
#  undef clongdouble
 
1585
#  undef Int8
 
1586
#  undef UInt8
 
1587
#  undef Int16
 
1588
#  undef UInt16
 
1589
#  undef Int32
 
1590
#  undef UInt32
 
1591
#  undef Int64
 
1592
#  undef UInt64
 
1593
#  undef Int128
 
1594
#  undef UInt128
 
1595
#  undef Int256
 
1596
#  undef UInt256
 
1597
#  undef Float16
 
1598
#  undef Complex32
 
1599
#  undef Float32
 
1600
#  undef Complex64
 
1601
#  undef Float64
 
1602
#  undef Complex128
 
1603
#  undef Float80
 
1604
#  undef Complex160
 
1605
#  undef Float96
 
1606
#  undef Complex192
 
1607
#  undef Float128
 
1608
#  undef Complex256
 
1609
#  undef intp
 
1610
#  undef uintp
 
1611
#endif
 
1612
 
 
1613
#ifdef __cplusplus
 
1614
}
 
1615
#endif
 
1616
 
 
1617
#endif /* !Py_ARRAYOBJECT_H */