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

« back to all changes in this revision

Viewing changes to numpy/core/src/arraymethods.c

  • 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
/* Should only be used if x is known to be an nd-array */
 
3
#define _ARET(x) PyArray_Return((PyArrayObject *)(x))
 
4
 
 
5
static char doc_take[] = "a.take(indices, axis=None).  Selects the elements "\
 
6
        "in indices from array a along the given axis.";
 
7
 
 
8
static PyObject *
 
9
array_take(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
10
{
 
11
        int dimension=MAX_DIMS;
 
12
        PyObject *indices;
 
13
        static char *kwlist[] = {"indices", "axis", NULL};
 
14
        
 
15
        dimension=0;
 
16
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist, 
 
17
                                         &indices, PyArray_AxisConverter,
 
18
                                         &dimension))
 
19
                return NULL;
 
20
        
 
21
        return _ARET(PyArray_Take(self, indices, dimension));
 
22
}
 
23
 
 
24
static char doc_fill[] = "a.fill(value) places the scalar value at every "\
 
25
        "position in the array.";
 
26
 
 
27
static PyObject *
 
28
array_fill(PyArrayObject *self, PyObject *args)
 
29
{
 
30
        PyObject *obj;
 
31
        if (!PyArg_ParseTuple(args, "O", &obj))
 
32
                return NULL;
 
33
        if (PyArray_FillWithScalar(self, obj) < 0) return NULL;
 
34
        Py_INCREF(Py_None);
 
35
        return Py_None;
 
36
}
 
37
 
 
38
static char doc_put[] = "a.put(values, indices) sets a.flat[n] = v[n] "\
 
39
        "for each n in indices. v can be scalar or shorter than indices, "\
 
40
        "will repeat.";
 
41
 
 
42
static PyObject *
 
43
array_put(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
44
{
 
45
        PyObject *indices, *values;
 
46
        static char *kwlist[] = {"values", "indices", NULL};
 
47
        
 
48
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist,
 
49
                                         &values, &indices))
 
50
                return NULL;
 
51
        return PyArray_Put(self, values, indices);
 
52
}
 
53
 
 
54
static char doc_putmask[] = "a.putmask(values, mask) sets a.flat[n] = v[n] "\
 
55
        "for each n where mask.flat[n] is TRUE. v can be scalar.";
 
56
 
 
57
static PyObject *
 
58
array_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
59
{
 
60
        PyObject *mask, *values;
 
61
 
 
62
        static char *kwlist[] = {"values", "mask", NULL};
 
63
        
 
64
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist,
 
65
                                         &values, &mask))
 
66
                return NULL;
 
67
        return PyArray_PutMask(self, values, mask);
 
68
}
 
69
 
 
70
static char doc_reshape[] = \
 
71
        "self.reshape(d1, d2, ..., dn, order='C') \n"   
 
72
        "Return a new array from this one. \n"                          
 
73
        "\n  The new array must have the same number of elements as self. " 
 
74
        "Also\n always returns a view or raises a ValueError if that is \n"
 
75
        "impossible.";
 
76
 
 
77
static PyObject *
 
78
array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
79
{
 
80
        PyArray_Dims newshape;
 
81
        PyObject *ret;
 
82
        PyArray_ORDER order=PyArray_CORDER;
 
83
        int n;
 
84
        
 
85
        if (kwds != NULL) {
 
86
                PyObject *ref;
 
87
                ref = PyDict_GetItemString(kwds, "order");
 
88
                if (ref == NULL ||                                      \
 
89
                    (PyArray_OrderConverter(ref, &order) == PY_FAIL))
 
90
                        return NULL;
 
91
        }
 
92
 
 
93
        n = PyTuple_Size(args);
 
94
        if (n <= 1) {
 
95
                if (!PyArg_ParseTuple(args, "O&", PyArray_IntpConverter, 
 
96
                                      &newshape)) return NULL;
 
97
        }
 
98
        else {
 
99
                if (!PyArray_IntpConverter(args, &newshape)) {
 
100
                        if (!PyErr_Occurred()) {
 
101
                                PyErr_SetString(PyExc_TypeError, 
 
102
                                                "invalid shape");
 
103
                        } 
 
104
                        goto fail;
 
105
                }
 
106
        }
 
107
        ret = PyArray_Newshape(self, &newshape, order);
 
108
        PyDimMem_FREE(newshape.ptr);
 
109
        return ret;
 
110
 
 
111
 fail:
 
112
        PyDimMem_FREE(newshape.ptr);
 
113
        return NULL;
 
114
}
 
115
 
 
116
static char doc_squeeze[] = "m.squeeze() eliminate all length-1 dimensions";
 
117
 
 
118
static PyObject *
 
119
array_squeeze(PyArrayObject *self, PyObject *args)
 
120
{
 
121
        if (!PyArg_ParseTuple(args, "")) return NULL;
 
122
        return _ARET(PyArray_Squeeze(self));
 
123
}
 
124
 
 
125
static char doc_view[] = "a.view(<type>) return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object";
 
126
 
 
127
static PyObject *
 
128
array_view(PyArrayObject *self, PyObject *args)
 
129
{
 
130
        PyObject *otype=NULL;
 
131
        PyArray_Descr *type=NULL;
 
132
 
 
133
        if (!PyArg_ParseTuple(args, "|O", &otype)) return NULL;
 
134
 
 
135
        if (otype) {
 
136
                if (PyType_Check(otype) &&                      \
 
137
                    PyType_IsSubtype((PyTypeObject *)otype, 
 
138
                                     &PyArray_Type)) {
 
139
                        return PyArray_View(self, NULL, 
 
140
                                            (PyTypeObject *)otype);
 
141
                }
 
142
                else {
 
143
                        if (PyArray_DescrConverter(otype, &type) == PY_FAIL) 
 
144
                                return NULL;
 
145
                }
 
146
        }
 
147
        return PyArray_View(self, type, NULL);
 
148
}
 
149
 
 
150
static char doc_argmax[] = "a.argmax(axis=None)";
 
151
 
 
152
static PyObject *
 
153
array_argmax(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
154
{
 
155
        int axis=MAX_DIMS;
 
156
        static char *kwlist[] = {"axis", NULL};
 
157
        
 
158
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist, 
 
159
                                         PyArray_AxisConverter,
 
160
                                         &axis))
 
161
                return NULL;    
 
162
        
 
163
        return _ARET(PyArray_ArgMax(self, axis));
 
164
}
 
165
 
 
166
static char doc_argmin[] = "a.argmin(axis=None)";
 
167
 
 
168
static PyObject *
 
169
array_argmin(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
170
{
 
171
        int axis=MAX_DIMS;
 
172
        static char *kwlist[] = {"axis", NULL};
 
173
        
 
174
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist, 
 
175
                                         PyArray_AxisConverter,
 
176
                                         &axis))
 
177
                return NULL;    
 
178
        
 
179
        return _ARET(PyArray_ArgMin(self, axis));
 
180
}
 
181
 
 
182
static char doc_max[] = "a.max(axis=None)";
 
183
 
 
184
static PyObject *
 
185
array_max(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
186
{
 
187
        int axis=MAX_DIMS;
 
188
        static char *kwlist[] = {"axis", NULL};
 
189
        
 
190
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist, 
 
191
                                         PyArray_AxisConverter,
 
192
                                         &axis))
 
193
                return NULL;    
 
194
        
 
195
        return PyArray_Max(self, axis);
 
196
}
 
197
 
 
198
static char doc_ptp[] = "a.ptp(axis=None) a.max(axis)-a.min(axis)";
 
199
 
 
200
static PyObject *
 
201
array_ptp(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
202
{
 
203
        int axis=MAX_DIMS;
 
204
        static char *kwlist[] = {"axis", NULL};
 
205
        
 
206
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist, 
 
207
                                         PyArray_AxisConverter,
 
208
                                         &axis))
 
209
                return NULL;    
 
210
                
 
211
        return PyArray_Ptp(self, axis);
 
212
}
 
213
 
 
214
 
 
215
static char doc_min[] = "a.min(axis=None)";
 
216
 
 
217
static PyObject *
 
218
array_min(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
219
{
 
220
        int axis=MAX_DIMS;
 
221
        static char *kwlist[] = {"axis", NULL};
 
222
        
 
223
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist, 
 
224
                                         PyArray_AxisConverter,
 
225
                                         &axis))
 
226
                return NULL;    
 
227
        
 
228
        return PyArray_Min(self, axis);
 
229
}
 
230
 
 
231
static char doc_swapaxes[] = "a.swapaxes(axis1, axis2)  returns new view with axes swapped.";
 
232
 
 
233
static PyObject *
 
234
array_swapaxes(PyArrayObject *self, PyObject *args)
 
235
{
 
236
        int axis1, axis2;
 
237
 
 
238
        if (!PyArg_ParseTuple(args, "ii", &axis1, &axis2)) return NULL;
 
239
 
 
240
        return PyArray_SwapAxes(self, axis1, axis2);
 
241
}
 
242
 
 
243
static char doc_getfield[] = "m.getfield(dtype, offset) returns a field "\
 
244
        " of the given array as a certain type.  A field is a view of "\
 
245
        " the array's data with each itemsize determined by the given type"\
 
246
        " and the offset into the current array.";
 
247
 
 
248
/* steals typed reference */
 
249
/*OBJECT_API
 
250
 Get a subset of bytes from each element of the array
 
251
*/
 
252
static PyObject *
 
253
PyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)
 
254
{
 
255
        PyObject *ret=NULL;
 
256
 
 
257
        if (offset < 0 || (offset + typed->elsize) > self->descr->elsize) {
 
258
                PyErr_Format(PyExc_ValueError,
 
259
                             "Need 0 <= offset <= %d for requested type "  \
 
260
                             "but received offset = %d",
 
261
                             self->descr->elsize-typed->elsize, offset);
 
262
                Py_DECREF(typed);
 
263
                return NULL;
 
264
        }
 
265
        ret = PyArray_NewFromDescr(self->ob_type, 
 
266
                                   typed,
 
267
                                   self->nd, self->dimensions,
 
268
                                   self->strides, 
 
269
                                   self->data + offset,
 
270
                                   self->flags, (PyObject *)self);
 
271
        if (ret == NULL) return NULL;
 
272
        Py_INCREF(self);
 
273
        ((PyArrayObject *)ret)->base = (PyObject *)self; 
 
274
 
 
275
        PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);
 
276
        return ret;
 
277
}
 
278
 
 
279
static PyObject *
 
280
array_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)
 
281
{
 
282
 
 
283
        PyArray_Descr *dtype;
 
284
        int offset = 0;
 
285
        static char *kwlist[] = {"dtype", "offset", 0};
 
286
        
 
287
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|i", kwlist,
 
288
                                         PyArray_DescrConverter,
 
289
                                         &dtype, &offset)) return NULL;
 
290
        
 
291
        return _ARET(PyArray_GetField(self, dtype, offset));
 
292
}
 
293
 
 
294
 
 
295
static char doc_setfield[] = "m.setfield(value, dtype, offset) places val "\
 
296
        "into field of the given array defined by the data type and offset.";
 
297
 
 
298
/*OBJECT_API
 
299
 Set a subset of bytes from each element of the array
 
300
*/
 
301
static int
 
302
PyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,
 
303
                 int offset, PyObject *val)
 
304
{
 
305
        PyObject *ret=NULL;
 
306
        int retval = 0;
 
307
        
 
308
        if (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) {
 
309
                PyErr_Format(PyExc_ValueError,
 
310
                             "Need 0 <= offset <= %d for requested type "  \
 
311
                             "but received offset = %d",
 
312
                             self->descr->elsize-dtype->elsize, offset);
 
313
                Py_DECREF(dtype);
 
314
                return -1;
 
315
        }
 
316
        ret = PyArray_NewFromDescr(self->ob_type, 
 
317
                                   dtype, self->nd, self->dimensions,
 
318
                                   self->strides, self->data + offset,
 
319
                                   self->flags, (PyObject *)self);
 
320
        if (ret == NULL) return -1;
 
321
        Py_INCREF(self);
 
322
        ((PyArrayObject *)ret)->base = (PyObject *)self;
 
323
 
 
324
        PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);    
 
325
        retval = PyArray_CopyObject((PyArrayObject *)ret, val);
 
326
        Py_DECREF(ret);
 
327
        return retval;
 
328
}
 
329
 
 
330
static PyObject *
 
331
array_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)
 
332
{
 
333
        PyArray_Descr *dtype;
 
334
        int offset = 0;
 
335
        PyObject *value;
 
336
        static char *kwlist[] = {"value", "dtype", "offset", 0};
 
337
        
 
338
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|i", kwlist,
 
339
                                         &value, PyArray_DescrConverter,
 
340
                                         &dtype, &offset)) return NULL;
 
341
 
 
342
        if (PyArray_SetField(self, dtype, offset, value) < 0)
 
343
                return NULL;
 
344
        Py_INCREF(Py_None);
 
345
        return Py_None;
 
346
}
 
347
 
 
348
/* This doesn't change the descriptor just the actual data...
 
349
 */
 
350
 
 
351
/*OBJECT_API*/
 
352
static PyObject *
 
353
PyArray_Byteswap(PyArrayObject *self, Bool inplace)
 
354
{
 
355
        PyArrayObject *ret;
 
356
        intp size;
 
357
        PyArray_CopySwapNFunc *copyswapn;
 
358
        PyArray_CopySwapFunc *copyswap;
 
359
        PyArrayIterObject *it;
 
360
 
 
361
        if (inplace) {
 
362
                copyswapn = self->descr->f->copyswapn;
 
363
                
 
364
                size = PyArray_SIZE(self);
 
365
                if (PyArray_ISONESEGMENT(self)) {
 
366
                        copyswapn(self->data, NULL, size, 1, self);
 
367
                }
 
368
                else { /* Use iterator */
 
369
                        
 
370
                        it = (PyArrayIterObject *)\
 
371
                                PyArray_IterNew((PyObject *)self);
 
372
                        copyswap = self->descr->f->copyswap;
 
373
                        while (it->index < it->size) {
 
374
                                copyswap(it->dataptr, NULL, 1, self);
 
375
                                PyArray_ITER_NEXT(it);
 
376
                        }
 
377
                        Py_DECREF(it);
 
378
                }
 
379
                
 
380
                Py_INCREF(self);
 
381
                return (PyObject *)self;
 
382
        }
 
383
        else {
 
384
                if ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) 
 
385
                        return NULL;
 
386
                
 
387
                size = PyArray_SIZE(self);
 
388
 
 
389
                /* now ret has the same dtypedescr as self (including
 
390
                   byteorder)
 
391
                */
 
392
 
 
393
                ret->descr->f->copyswapn(ret->data, NULL, size, 1, ret);
 
394
 
 
395
                return (PyObject *)ret;
 
396
        }
 
397
}
 
398
 
 
399
static char doc_byteswap[] = "m.byteswap(False)  Swap the bytes in"\
 
400
        " the array.  Return the byteswapped array.  If the first argument"\
 
401
        " is TRUE, byteswap in-place and return a reference to self.";
 
402
 
 
403
static PyObject *
 
404
array_byteswap(PyArrayObject *self, PyObject *args) 
 
405
{
 
406
        Bool inplace=FALSE;
 
407
        
 
408
        if (!PyArg_ParseTuple(args, "|O&", PyArray_BoolConverter, &inplace))
 
409
                return NULL;
 
410
        
 
411
        return PyArray_Byteswap(self, inplace);
 
412
}
 
413
 
 
414
static char doc_tolist[] = "m.tolist().  Copy the data portion of the array"\
 
415
        " to a hierarchical python list and return that list.";
 
416
 
 
417
static PyObject *
 
418
array_tolist(PyArrayObject *self, PyObject *args) 
 
419
{
 
420
        if (!PyArg_ParseTuple(args, "")) return NULL;
 
421
        if (self->nd <= 0) {
 
422
                PyErr_SetString(PyExc_ValueError, 
 
423
                                "can't convert a 0-d array to a list");
 
424
                return NULL;
 
425
        }
 
426
        
 
427
        return PyArray_ToList(self);
 
428
}
 
429
 
 
430
static char doc_tostring[] = "m.tostring()  Construct a Python string "\
 
431
        "containing the raw bytes in the array";
 
432
 
 
433
static PyObject *
 
434
array_tostring(PyArrayObject *self, PyObject *args)
 
435
{
 
436
        if (!PyArg_ParseTuple(args, "")) return NULL;
 
437
        return PyArray_ToString(self);
 
438
}
 
439
 
 
440
static char doc_tofile[] = "m.tofile(fid, sep="") write the data to a file.";
 
441
 
 
442
static PyObject *
 
443
array_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)
 
444
{
 
445
        int ret;
 
446
        PyObject *file;
 
447
        FILE *fd;
 
448
        char *sep="";
 
449
        char *format="";
 
450
        char *mode="";
 
451
        static char *kwlist[] = {"file", "sep", "format", NULL};
 
452
        
 
453
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss", kwlist, 
 
454
                                         &file, &sep, &format)) return NULL;
 
455
 
 
456
        if (PyString_Check(file)) {
 
457
                if (sep == "") mode="wb";
 
458
                else mode="w";
 
459
                file = PyFile_FromString(PyString_AS_STRING(file), mode);
 
460
                if (file==NULL) return NULL;
 
461
        }
 
462
        else {
 
463
                Py_INCREF(file);
 
464
        }
 
465
        fd = PyFile_AsFile(file);
 
466
        if (fd == NULL) {
 
467
                PyErr_SetString(PyExc_IOError, "first argument must be a " \
 
468
                                "string or open file");
 
469
                Py_DECREF(file);
 
470
                return NULL;
 
471
        }
 
472
        ret = PyArray_ToFile(self, fd, sep, format);
 
473
        Py_DECREF(file);
 
474
        if (ret < 0) return NULL;
 
475
        Py_INCREF(Py_None);
 
476
        return Py_None;
 
477
}
 
478
 
 
479
static char doc_toscalar[] = "m.item().  Copy the first data point of "\
 
480
        "the array to a standard Python scalar and return it.";
 
481
 
 
482
static PyObject *
 
483
array_toscalar(PyArrayObject *self, PyObject *args) {
 
484
        if (!PyArg_ParseTuple(args, "")) return NULL;
 
485
        if (self->nd == 0 || PyArray_SIZE(self) == 1) 
 
486
                return self->descr->f->getitem(self->data, self);
 
487
        else {
 
488
                PyErr_SetString(PyExc_ValueError, "can only convert an" \
 
489
                                " array of size 1 to Python scalar.");
 
490
                return NULL;
 
491
        }
 
492
}
 
493
 
 
494
static char doc_cast[] = "m.astype(t).  Cast array m to type t.  \n\n"\
 
495
        "t can be either a string representing a typecode, or a python type"\
 
496
        " object of type int, float, or complex.";
 
497
 
 
498
static PyObject *
 
499
array_cast(PyArrayObject *self, PyObject *args) 
 
500
{
 
501
        PyArray_Descr *descr=NULL;
 
502
        PyObject *obj;
 
503
        
 
504
        if (!PyArg_ParseTuple(args, "O&", PyArray_DescrConverter,
 
505
                              &descr)) return NULL;
 
506
        
 
507
        if (descr == self->descr) {
 
508
                obj = _ARET(PyArray_NewCopy(self,0));
 
509
                Py_XDECREF(descr);
 
510
                return obj;
 
511
        }
 
512
        return _ARET(PyArray_CastToType(self, descr, 0));
 
513
}         
 
514
 
 
515
/* default sub-type implementation */
 
516
 
 
517
static char doc_wraparray[] = "m.__array_wrap__(obj) returns an object of "\
 
518
        "type m from the ndarray object obj";
 
519
 
 
520
static PyObject *
 
521
array_wraparray(PyArrayObject *self, PyObject *args)
 
522
{
 
523
        PyObject *arr;
 
524
        PyObject *ret;
 
525
        
 
526
        if (PyTuple_Size(args) < 1) {
 
527
                PyErr_SetString(PyExc_TypeError,
 
528
                                "only accepts 1 argument");
 
529
                return NULL;
 
530
        }
 
531
        arr = PyTuple_GET_ITEM(args, 0);
 
532
        if (!PyArray_Check(arr)) {
 
533
                PyErr_SetString(PyExc_TypeError,
 
534
                                "can only be called with ndarray object");
 
535
                return NULL;
 
536
        }       
 
537
 
 
538
        Py_INCREF(PyArray_DESCR(arr));
 
539
        ret = PyArray_NewFromDescr(self->ob_type, 
 
540
                                   PyArray_DESCR(arr),
 
541
                                   PyArray_NDIM(arr),
 
542
                                   PyArray_DIMS(arr), 
 
543
                                   PyArray_STRIDES(arr), PyArray_DATA(arr),
 
544
                                   PyArray_FLAGS(arr), (PyObject *)self);
 
545
        if (ret == NULL) return NULL;
 
546
        Py_INCREF(arr);
 
547
        PyArray_BASE(ret) = arr;
 
548
        return ret;
 
549
}
 
550
 
 
551
/* NO-OP --- just so all subclasses will have one by default. */
 
552
static PyObject *
 
553
array_finalize(PyArrayObject *self, PyObject *args)
 
554
{
 
555
        Py_INCREF(Py_None);
 
556
        return Py_None;
 
557
}
 
558
 
 
559
 
 
560
static char doc_array_getarray[] = "m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.";
 
561
 
 
562
static PyObject *
 
563
array_getarray(PyArrayObject *self, PyObject *args) 
 
564
{
 
565
        PyArray_Descr *newtype=NULL;
 
566
        PyObject *ret;
 
567
        
 
568
        if (!PyArg_ParseTuple(args, "|O&", PyArray_DescrConverter,
 
569
                              &newtype)) return NULL;
 
570
        
 
571
        /* convert to PyArray_Type */
 
572
        if (!PyArray_CheckExact(self)) {
 
573
                PyObject *new;
 
574
                PyTypeObject *subtype = &PyArray_Type;
 
575
 
 
576
                if (!PyType_IsSubtype(self->ob_type, &PyArray_Type)) {
 
577
                        subtype = &PyArray_Type;
 
578
                }
 
579
                
 
580
                Py_INCREF(PyArray_DESCR(self));
 
581
                new = PyArray_NewFromDescr(subtype, 
 
582
                                           PyArray_DESCR(self),
 
583
                                           PyArray_NDIM(self),
 
584
                                           PyArray_DIMS(self), 
 
585
                                           PyArray_STRIDES(self), 
 
586
                                           PyArray_DATA(self),
 
587
                                           PyArray_FLAGS(self), NULL);
 
588
                if (new == NULL) return NULL;
 
589
                Py_INCREF(self);
 
590
                PyArray_BASE(new) = (PyObject *)self;
 
591
                self = (PyArrayObject *)new;
 
592
        }
 
593
        else {
 
594
                Py_INCREF(self);
 
595
        }
 
596
                
 
597
        if ((newtype == NULL) || \
 
598
            PyArray_EquivTypes(self->descr, newtype)) {
 
599
                return (PyObject *)self;
 
600
        }
 
601
        else {
 
602
                ret = PyArray_CastToType(self, newtype, 0);
 
603
                Py_DECREF(self);
 
604
                return ret;
 
605
        }
 
606
}
 
607
 
 
608
static char doc_copy[] = "m.copy(|fortran). Return a copy of the array.\n"\
 
609
        "If fortran is false then the result is contiguous (default). \n"\
 
610
        "If fortran is true  then the result has fortran data order. \n"\
 
611
        "If fortran is None  then the result has fortran data order only if m\n"
 
612
        "   is already in fortran order.";
 
613
 
 
614
static PyObject *
 
615
array_copy(PyArrayObject *self, PyObject *args) 
 
616
{
 
617
        PyArray_ORDER fortran=PyArray_CORDER;
 
618
        if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter,
 
619
                              &fortran)) return NULL;
 
620
        
 
621
        return PyArray_NewCopy(self, fortran);
 
622
}
 
623
 
 
624
static char doc_resize[] = "self.resize(new_shape, refcheck=True, fortran=False).  "\
 
625
        "Change size and shape of self inplace.\n"\
 
626
        "\n    Array must own its own memory and not be referenced by other " \
 
627
        "arrays\n    Returns None.";
 
628
 
 
629
static PyObject *
 
630
array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
631
{
 
632
        PyArray_Dims newshape;
 
633
        PyObject *ret;
 
634
        int n;
 
635
        int refcheck = 1;
 
636
        PyArray_ORDER fortran=PyArray_ANYORDER;
 
637
        
 
638
        if (kwds != NULL) {
 
639
                PyObject *ref;
 
640
                ref = PyDict_GetItemString(kwds, "refcheck");
 
641
                if (ref) {
 
642
                        refcheck = PyInt_AsLong(ref);
 
643
                        if (refcheck==-1 && PyErr_Occurred()) {
 
644
                                return NULL;
 
645
                        }
 
646
                }
 
647
                ref = PyDict_GetItemString(kwds, "fortran");
 
648
                if (ref != NULL || 
 
649
                    (PyArray_OrderConverter(ref, &fortran) == PY_FAIL))
 
650
                        return NULL;
 
651
        }
 
652
        n = PyTuple_Size(args);
 
653
        if (n <= 1) {
 
654
                if (!PyArg_ParseTuple(args, "O&", PyArray_IntpConverter, 
 
655
                                      &newshape)) return NULL;
 
656
        }
 
657
        else {
 
658
                if (!PyArray_IntpConverter(args, &newshape)) {
 
659
                        if (!PyErr_Occurred()) {
 
660
                                PyErr_SetString(PyExc_TypeError, 
 
661
                                                "invalid shape");
 
662
                        } 
 
663
                        return NULL;                    
 
664
                }
 
665
        }       
 
666
        ret = PyArray_Resize(self, &newshape, refcheck, fortran);
 
667
        PyDimMem_FREE(newshape.ptr);
 
668
        if (ret == NULL) return NULL;
 
669
        Py_DECREF(ret);
 
670
        Py_INCREF(Py_None);
 
671
        return Py_None;
 
672
}
 
673
 
 
674
static char doc_repeat[] = "a.repeat(repeats=, axis=None)\n"\
 
675
        "\n"\
 
676
        " Copy elements of a, repeats times.  The repeats argument must\n"\
 
677
        "  be a sequence of length a.shape[axis] or a scalar.";
 
678
 
 
679
static PyObject *
 
680
array_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {
 
681
        PyObject *repeats;
 
682
        int axis=MAX_DIMS;
 
683
        static char *kwlist[] = {"repeats", "axis", NULL};
 
684
        
 
685
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist, 
 
686
                                         &repeats, PyArray_AxisConverter,
 
687
                                         &axis)) return NULL;
 
688
        
 
689
        return _ARET(PyArray_Repeat(self, repeats, axis));
 
690
}
 
691
 
 
692
static char doc_choose[] = "a.choose(b0, b1, ..., bn)\n"\
 
693
        "\n"\
 
694
        "Return an array with elements chosen from 'a' at the positions\n"\
 
695
        "of the given arrays b_i.  The array 'a' should be an integer array\n"\
 
696
        "with entries from 0 to n+1, and the b_i arrays should have the same\n"\
 
697
        "shape as 'a'.";
 
698
 
 
699
static PyObject *
 
700
array_choose(PyArrayObject *self, PyObject *args) 
 
701
{
 
702
        PyObject *choices;
 
703
        int n;
 
704
        
 
705
        n = PyTuple_Size(args);
 
706
        if (n <= 1) {
 
707
                if (!PyArg_ParseTuple(args, "O", &choices))
 
708
                        return NULL;
 
709
        }
 
710
        else {
 
711
                choices = args;
 
712
        }
 
713
        
 
714
        return _ARET(PyArray_Choose(self, choices));
 
715
}
 
716
 
 
717
static char doc_sort[] = "a.sort(axis=-1,kind='quicksort') sorts in place along axis.  Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'";
 
718
 
 
719
static PyObject *
 
720
array_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
721
{
 
722
        int axis=-1;
 
723
        int val;
 
724
        PyArray_SORTKIND which=PyArray_QUICKSORT;
 
725
        static char *kwlist[] = {"axis", "kind", NULL};
 
726
        
 
727
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&", kwlist, &axis,
 
728
                                         PyArray_SortkindConverter, &which))
 
729
                return NULL;
 
730
        
 
731
        val = PyArray_Sort(self, axis, which);
 
732
        if (val < 0) return NULL;
 
733
        Py_INCREF(Py_None);
 
734
        return Py_None;
 
735
}
 
736
 
 
737
static char doc_argsort[] = "a.argsort(axis=-1,kind='quicksort')\n"\
 
738
        "  Return the indexes into a that would sort it along the"\
 
739
        " given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'";
 
740
 
 
741
static PyObject *
 
742
array_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
743
{
 
744
        int axis=-1;
 
745
        PyArray_SORTKIND which=PyArray_QUICKSORT;
 
746
        static char *kwlist[] = {"axis", "kind", NULL};
 
747
        
 
748
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&", kwlist, &axis,
 
749
                                         PyArray_SortkindConverter, &which))
 
750
                return NULL;
 
751
        
 
752
        return _ARET(PyArray_ArgSort(self, axis, which));
 
753
}
 
754
 
 
755
static char doc_searchsorted[] = "a.searchsorted(v)\n"\
 
756
        " Assuming that a is a 1-D array, in ascending order and\n"\
 
757
        " represents bin boundaries, then a.searchsorted(values) gives an\n"\
 
758
        " array of bin numbers, giving the bin into which each value would\n"\
 
759
        " be placed.  This method is helpful for histograming.  \n"\
 
760
        " Note: No warning is given if the boundaries, in a, are not \n"\
 
761
        " in ascending order.";
 
762
 
 
763
static PyObject *
 
764
array_searchsorted(PyArrayObject *self, PyObject *args) 
 
765
{
 
766
        PyObject *values;
 
767
        
 
768
        if (!PyArg_ParseTuple(args, "O", &values)) return NULL;
 
769
        
 
770
        return _ARET(PyArray_SearchSorted(self, values));
 
771
}
 
772
 
 
773
static char doc_deepcopy[] = "Used if copy.deepcopy is called on an array.";
 
774
 
 
775
static PyObject *
 
776
array_deepcopy(PyArrayObject *self, PyObject *args) 
 
777
{
 
778
        PyObject* visit;
 
779
        PyObject **optr;
 
780
        PyArrayIterObject *it;
 
781
        PyObject *copy, *ret, *deepcopy, *temp, *res;
 
782
 
 
783
        if (!PyArg_ParseTuple(args, "O", &visit)) return NULL;
 
784
        ret = PyArray_Copy(self);
 
785
        if (PyArray_ISOBJECT(self)) {
 
786
                copy = PyImport_ImportModule("copy");
 
787
                if (copy == NULL) return NULL;
 
788
                deepcopy = PyObject_GetAttrString(copy, "deepcopy");
 
789
                Py_DECREF(copy);
 
790
                if (deepcopy == NULL) return NULL;
 
791
                it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
 
792
                if (it == NULL) {Py_DECREF(deepcopy); return NULL;}
 
793
                optr = (PyObject **)PyArray_DATA(ret);
 
794
                while(it->index < it->size) {
 
795
                        temp = *((PyObject **)it->dataptr);
 
796
                        Py_INCREF(temp);
 
797
                        /* call deepcopy on this argument */
 
798
                        res = PyObject_CallFunctionObjArgs(deepcopy, 
 
799
                                                           temp, visit, NULL);
 
800
                        Py_DECREF(temp);
 
801
                        Py_DECREF(*optr);
 
802
                        *optr++ = res;
 
803
                        PyArray_ITER_NEXT(it);
 
804
                }
 
805
                Py_DECREF(deepcopy);
 
806
                Py_DECREF(it);
 
807
        }
 
808
        return _ARET(ret);
 
809
}
 
810
 
 
811
/* Convert Object Array to flat list and pickle the flat list string */
 
812
static PyObject *
 
813
_getobject_pkl(PyArrayObject *self)
 
814
{
 
815
        PyObject *theobject;
 
816
        PyArrayIterObject *iter=NULL;
 
817
        PyObject *list;
 
818
 
 
819
        
 
820
        iter = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
 
821
        if (iter == NULL) return NULL;
 
822
        list = PyList_New(iter->size);
 
823
        if (list == NULL) {Py_DECREF(iter); return NULL;}
 
824
        while (iter->index < iter->size) {
 
825
                theobject = *((PyObject **)iter->dataptr);
 
826
                Py_INCREF(theobject);
 
827
                PyList_SET_ITEM(list, (int) iter->index, theobject);
 
828
                PyArray_ITER_NEXT(iter);
 
829
        }
 
830
        Py_DECREF(iter);
 
831
        return list;
 
832
}
 
833
 
 
834
static int
 
835
_setobject_pkl(PyArrayObject *self, PyObject *list)
 
836
{
 
837
        PyObject *theobject;
 
838
        PyArrayIterObject *iter=NULL;
 
839
        int size;
 
840
 
 
841
        size = self->descr->elsize;
 
842
        
 
843
        iter = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
 
844
        if (iter == NULL) return -1;
 
845
        while(iter->index < iter->size) {
 
846
                theobject = PyList_GET_ITEM(list, (int) iter->index);
 
847
                Py_INCREF(theobject);
 
848
                *((PyObject **)iter->dataptr) = theobject;
 
849
                PyArray_ITER_NEXT(iter);
 
850
        }
 
851
        Py_XDECREF(iter);
 
852
        return 0;
 
853
}
 
854
 
 
855
static char doc_reduce[] = "a.__reduce__()  for pickling.";
 
856
 
 
857
static PyObject *
 
858
array_reduce(PyArrayObject *self, PyObject *args)
 
859
{
 
860
        PyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;
 
861
        PyObject *mybool, *thestr=NULL;
 
862
        PyArray_Descr *descr;
 
863
 
 
864
        /* Return a tuple of (callable object, arguments, object's state) */
 
865
        /*  We will put everything in the object's state, so that on UnPickle
 
866
            it can use the string object as memory without a copy */
 
867
 
 
868
        ret = PyTuple_New(3);
 
869
        if (ret == NULL) return NULL;
 
870
        mod = PyImport_ImportModule("numpy.core._internal");
 
871
        if (mod == NULL) {Py_DECREF(ret); return NULL;}
 
872
        obj = PyObject_GetAttrString(mod, "_reconstruct");
 
873
        Py_DECREF(mod);
 
874
        PyTuple_SET_ITEM(ret, 0, obj);
 
875
        PyTuple_SET_ITEM(ret, 1, 
 
876
                         Py_BuildValue("ONc",
 
877
                                       (PyObject *)self->ob_type,
 
878
                                       Py_BuildValue("(N)",
 
879
                                                     PyInt_FromLong(0)),
 
880
                                       /* dummy data-type */
 
881
                                       'b'));
 
882
        
 
883
        /* Now fill in object's state.  This is a tuple with 
 
884
           4 arguments
 
885
 
 
886
           1) a Tuple giving the shape
 
887
           2) a PyArray_Descr Object (with correct bytorder set)
 
888
           3) a Bool stating if Fortran or not
 
889
           4) a binary string with the data (or a list for Object arrays)
 
890
 
 
891
           Notice because Python does not describe a mechanism to write 
 
892
           raw data to the pickle, this performs a copy to a string first
 
893
        */
 
894
 
 
895
        state = PyTuple_New(4);
 
896
        if (state == NULL) {
 
897
                Py_DECREF(ret); return NULL;
 
898
        }
 
899
        PyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self, 
 
900
                                                          "shape"));
 
901
        descr = self->descr;
 
902
        Py_INCREF(descr);
 
903
        PyTuple_SET_ITEM(state, 1, (PyObject *)descr);
 
904
        mybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);
 
905
        Py_INCREF(mybool);
 
906
        PyTuple_SET_ITEM(state, 2, mybool);
 
907
        if (PyArray_ISOBJECT(self)) {
 
908
                thestr = _getobject_pkl(self);
 
909
        }
 
910
        else {
 
911
                thestr = PyArray_ToString(self);
 
912
        }
 
913
        if (thestr == NULL) {
 
914
                Py_DECREF(ret);
 
915
                Py_DECREF(state);
 
916
                return NULL;
 
917
        }
 
918
        PyTuple_SET_ITEM(state, 3, thestr);
 
919
        PyTuple_SET_ITEM(ret, 2, state);
 
920
        return ret;
 
921
}
 
922
 
 
923
static char doc_setstate[] = "a.__setstate__(tuple) for unpickling.";
 
924
 
 
925
/*
 
926
           1) a Tuple giving the shape
 
927
           2) a PyArray_Descr Object
 
928
           3) a Bool stating if Fortran or not
 
929
           4) a binary string with the data (or a list if Object array) 
 
930
*/
 
931
 
 
932
static intp _array_fill_strides(intp *, intp *, int, intp, int, int *);
 
933
 
 
934
static int _IsAligned(PyArrayObject *); 
 
935
 
 
936
static PyArray_Descr * _array_typedescr_fromstr(char *);
 
937
 
 
938
static PyObject *
 
939
array_setstate(PyArrayObject *self, PyObject *args)
 
940
{
 
941
        PyObject *shape;
 
942
        PyArray_Descr *typecode;
 
943
        int fortran;
 
944
        PyObject *rawdata;
 
945
        char *datastr;
 
946
        int len;
 
947
        intp dimensions[MAX_DIMS];
 
948
        int nd;
 
949
        
 
950
        /* This will free any memory associated with a and
 
951
           use the string in setstate as the (writeable) memory.
 
952
        */
 
953
        if (!PyArg_ParseTuple(args, "(O!O!iO)", &PyTuple_Type,
 
954
                              &shape, &PyArrayDescr_Type, &typecode, 
 
955
                              &fortran, &rawdata))
 
956
                return NULL;
 
957
 
 
958
        Py_XDECREF(self->descr);
 
959
        self->descr = typecode;
 
960
        Py_INCREF(typecode);
 
961
        nd = PyArray_IntpFromSequence(shape, dimensions, MAX_DIMS);
 
962
        if (typecode->type_num == PyArray_OBJECT) {
 
963
                if (!PyList_Check(rawdata)) {
 
964
                        PyErr_SetString(PyExc_TypeError, 
 
965
                                        "object pickle not returning list");
 
966
                        return NULL;
 
967
                }
 
968
        }
 
969
        else {
 
970
                if (!PyString_Check(rawdata)) {
 
971
                        PyErr_SetString(PyExc_TypeError, 
 
972
                                        "pickle not returning string");
 
973
                        return NULL;
 
974
                }
 
975
 
 
976
                if (PyString_AsStringAndSize(rawdata, &datastr, &len))
 
977
                        return NULL;
 
978
 
 
979
                if ((len != (self->descr->elsize *                      \
 
980
                             (int) PyArray_MultiplyList(dimensions, nd)))) {
 
981
                        PyErr_SetString(PyExc_ValueError, 
 
982
                                        "buffer size does not"  \
 
983
                                        " match array size");
 
984
                        return NULL;
 
985
                }
 
986
        }
 
987
 
 
988
        if ((self->flags & OWN_DATA)) {
 
989
                if (self->data != NULL)
 
990
                        PyDataMem_FREE(self->data);
 
991
                self->flags &= ~OWN_DATA;
 
992
        }
 
993
        Py_XDECREF(self->base);
 
994
 
 
995
        self->flags &= ~UPDATEIFCOPY;
 
996
 
 
997
        if (self->dimensions != NULL) {
 
998
                PyDimMem_FREE(self->dimensions); 
 
999
                self->dimensions = NULL;
 
1000
        }
 
1001
 
 
1002
        self->flags = DEFAULT_FLAGS;
 
1003
 
 
1004
        self->nd = nd;
 
1005
 
 
1006
        if (nd > 0) {
 
1007
                self->dimensions = PyDimMem_NEW(nd * 2);
 
1008
                self->strides = self->dimensions + nd;
 
1009
                memcpy(self->dimensions, dimensions, sizeof(intp)*nd);
 
1010
                (void) _array_fill_strides(self->strides, dimensions, nd,
 
1011
                                           self->descr->elsize, 
 
1012
                                           (fortran ? FORTRAN : CONTIGUOUS),
 
1013
                                           &(self->flags));
 
1014
        }
 
1015
 
 
1016
        if (typecode->type_num != PyArray_OBJECT) {
 
1017
                int swap=!PyArray_ISNOTSWAPPED(self);
 
1018
                self->data = datastr;
 
1019
                if (!_IsAligned(self) || swap) {
 
1020
                        intp num = PyArray_NBYTES(self);
 
1021
                        self->data = PyDataMem_NEW(num);
 
1022
                        if (self->data == NULL) {
 
1023
                                self->nd = 0;
 
1024
                                PyDimMem_FREE(self->dimensions);
 
1025
                                return PyErr_NoMemory();
 
1026
                        }
 
1027
                        if (swap) { /* byte-swap on pickle-read */
 
1028
                                intp numels = num / self->descr->elsize;
 
1029
                                self->descr->f->copyswapn(self->data, datastr, 
 
1030
                                                          numels,
 
1031
                                                          1, self);
 
1032
                                if (!PyArray_ISEXTENDED(self)) {
 
1033
                                        self->descr = PyArray_DescrFromType(self->descr->type_num);
 
1034
                                }
 
1035
                                else {
 
1036
                                        self->descr = PyArray_DescrNew(typecode);
 
1037
                                        if (self->descr->byteorder == PyArray_BIG) 
 
1038
                                                self->descr->byteorder = PyArray_LITTLE;
 
1039
                                        else if (self->descr->byteorder == PyArray_LITTLE)
 
1040
                                                self->descr->byteorder = PyArray_BIG;
 
1041
                                }
 
1042
                                Py_DECREF(typecode);
 
1043
                        }
 
1044
                        else {
 
1045
                                memcpy(self->data, datastr, num);
 
1046
                        }
 
1047
                        self->flags |= OWN_DATA;
 
1048
                        self->base = NULL;
 
1049
                }
 
1050
                else {
 
1051
                        self->base = rawdata;
 
1052
                        Py_INCREF(self->base);
 
1053
                }
 
1054
        }
 
1055
        else {
 
1056
                self->data = PyDataMem_NEW(PyArray_NBYTES(self));
 
1057
                if (self->data == NULL) { 
 
1058
                        self->nd = 0;
 
1059
                        self->data = PyDataMem_NEW(self->descr->elsize);
 
1060
                        if (self->dimensions) PyDimMem_FREE(self->dimensions);
 
1061
                        return PyErr_NoMemory();
 
1062
                }
 
1063
                self->flags |= OWN_DATA;
 
1064
                self->base = NULL;
 
1065
                if (_setobject_pkl(self, rawdata) < 0) 
 
1066
                        return NULL;
 
1067
        }
 
1068
 
 
1069
        PyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);
 
1070
        
 
1071
        Py_INCREF(Py_None);
 
1072
        return Py_None; 
 
1073
}
 
1074
 
 
1075
/*OBJECT_API*/
 
1076
static int
 
1077
PyArray_Dump(PyObject *self, PyObject *file, int protocol)
 
1078
{
 
1079
        PyObject *cpick=NULL;
 
1080
        PyObject *ret;
 
1081
        if (protocol < 0) protocol = 2;
 
1082
 
 
1083
        cpick = PyImport_ImportModule("cPickle");
 
1084
        if (cpick==NULL) return -1;
 
1085
 
 
1086
        if PyString_Check(file) {
 
1087
                file = PyFile_FromString(PyString_AS_STRING(file), "wb");
 
1088
                if (file==NULL) return -1;
 
1089
        }
 
1090
        else Py_INCREF(file);
 
1091
        ret = PyObject_CallMethod(cpick, "dump", "OOi", self, 
 
1092
                                  file, protocol);
 
1093
        Py_XDECREF(ret);
 
1094
        Py_DECREF(file);
 
1095
        Py_DECREF(cpick);
 
1096
        if (PyErr_Occurred()) return -1;
 
1097
        return 0;
 
1098
}
 
1099
 
 
1100
/*OBJECT_API*/
 
1101
static PyObject *
 
1102
PyArray_Dumps(PyObject *self, int protocol)
 
1103
{
 
1104
        PyObject *cpick=NULL;
 
1105
        PyObject *ret;
 
1106
        if (protocol < 0) protocol = 2;
 
1107
 
 
1108
        cpick = PyImport_ImportModule("cPickle");
 
1109
        if (cpick==NULL) return NULL;
 
1110
        ret = PyObject_CallMethod(cpick, "dumps", "Oi", self, protocol);
 
1111
        Py_DECREF(cpick);
 
1112
        return ret;
 
1113
}
 
1114
 
 
1115
 
 
1116
static char doc_dump[] = "m.dump(file)";
 
1117
 
 
1118
static PyObject *
 
1119
array_dump(PyArrayObject *self, PyObject *args)
 
1120
{
 
1121
        PyObject *file=NULL;
 
1122
        int ret;
 
1123
 
 
1124
        if (!PyArg_ParseTuple(args, "O", &file))
 
1125
                return NULL;
 
1126
        ret = PyArray_Dump((PyObject *)self, file, 2);
 
1127
        if (ret < 0) return NULL;
 
1128
        Py_INCREF(Py_None);
 
1129
        return Py_None;
 
1130
}
 
1131
 
 
1132
static char doc_dumps[] = "m.dumps()";
 
1133
 
 
1134
static PyObject *
 
1135
array_dumps(PyArrayObject *self, PyObject *args)
 
1136
{
 
1137
        if (!PyArg_ParseTuple(args, ""))
 
1138
                return NULL;
 
1139
        return PyArray_Dumps((PyObject *)self, 2);
 
1140
}
 
1141
 
 
1142
 
 
1143
static char doc_transpose[] = "a.transpose(*axes)\n\n"
 
1144
"Returns a view of `a` with axes transposed. If no axes are given,\n"
 
1145
"or None is passed, switches the order of the axes (for a 2-d array,\n"
 
1146
"this is the usual matrix transpose). If axes are given, they\n"
 
1147
"describe how the axes are permuted.\n\n"
 
1148
"Example:\n"
 
1149
">>> a = array([[1,2],[3,4]])\n"
 
1150
">>> a\n"
 
1151
"array([[1, 2],\n"
 
1152
"       [3, 4]])\n"
 
1153
">>> a.transpose()\n"
 
1154
"array([[1, 3],\n"
 
1155
"       [3, 4]])\n"
 
1156
">>> a.transpose((1,0))\n"
 
1157
"array([[1, 3],\n"
 
1158
"       [3, 4]])\n"
 
1159
">>> a.transpose(1,0)\n"
 
1160
"array([[1, 3],\n"
 
1161
"       [3, 4]])\n"
 
1162
;
 
1163
 
 
1164
static PyObject *
 
1165
array_transpose(PyArrayObject *self, PyObject *args) 
 
1166
{
 
1167
        PyObject *shape=Py_None;
 
1168
        int n;
 
1169
        PyArray_Dims permute;
 
1170
        PyObject *ret;
 
1171
 
 
1172
        n = PyTuple_Size(args);
 
1173
        if (n > 1) shape = args;
 
1174
        else if (n == 1) shape = PyTuple_GET_ITEM(args, 0);
 
1175
        
 
1176
        if (shape == Py_None)
 
1177
                ret = PyArray_Transpose(self, NULL);
 
1178
        else {
 
1179
                if (!PyArray_IntpConverter(shape, &permute)) return NULL;
 
1180
                ret = PyArray_Transpose(self, &permute);
 
1181
                PyDimMem_FREE(permute.ptr);
 
1182
        }
 
1183
        
 
1184
        return _ARET(ret);
 
1185
}
 
1186
 
 
1187
static char doc_mean[] = "a.mean(axis=None, dtype=None)\n\n"\
 
1188
  "Average the array over the given axis.  If the axis is None, average\n"\
 
1189
  "over all dimensions of the array.\n"\
 
1190
  "\n"\
 
1191
  "If an integer axis is given, this equals:\n"\
 
1192
  "    a.sum(axis, dtype) * 1.0 / len(a)\n"\
 
1193
  "\n"\
 
1194
  "If axis is None, this equals:\n"\
 
1195
  "     a.sum(axis, dtype) * 1.0 / product(a.shape)\n"\
 
1196
  "\n"\
 
1197
  "The optional dtype argument is the data type for intermediate\n"\
 
1198
  "calculations in the sum.";
 
1199
 
 
1200
#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)
 
1201
 
 
1202
static PyObject *
 
1203
array_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1204
{
 
1205
        int axis=MAX_DIMS;
 
1206
        PyArray_Descr *dtype=NULL;
 
1207
        static char *kwlist[] = {"axis", "dtype", NULL};
 
1208
        
 
1209
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
 
1210
                                         PyArray_AxisConverter, 
 
1211
                                         &axis, PyArray_DescrConverter2,
 
1212
                                         &dtype)) return NULL;
 
1213
 
 
1214
        return PyArray_Mean(self, axis, _CHKTYPENUM(dtype));
 
1215
}
 
1216
 
 
1217
static char doc_sum[] = "a.sum(axis=None, dtype=None)\n\n"\
 
1218
  "Sum the array over the given axis.  If the axis is None, sum over all\n"\
 
1219
  "dimensions of the array.\n"\
 
1220
  "\n"\
 
1221
  "The optional dtype argument is the data type for the returned value\n"\
 
1222
  "and intermediate calculations.  The default is to upcast (promote)\n"\
 
1223
  "smaller integer types to the platform-dependent int.  For example, on\n"\
 
1224
  "32-bit platforms:\n"\
 
1225
  "\n"\
 
1226
  "    a.dtype                         default sum() dtype\n"\
 
1227
  "    ---------------------------------------------------\n"\
 
1228
  "    bool, int8, int16, int32        int32\n"\
 
1229
  "\n"\
 
1230
  "Examples:\n"\
 
1231
  "\n"\
 
1232
  ">>> array([0.5, 1.5]).sum()\n"\
 
1233
  "2.0\n"\
 
1234
  ">>> array([0.5, 1.5]).sum(dtype=int32)\n"\
 
1235
  "1\n"\
 
1236
  ">>> array([[0, 1], [0, 5]]).sum(axis=0)\n"\
 
1237
  "array([0, 6])\n"\
 
1238
  ">>> array([[0, 1], [0, 5]]).sum(axis=1)\n"\
 
1239
  "array([1, 5])";
 
1240
 
 
1241
static PyObject *
 
1242
array_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1243
{
 
1244
        int axis=MAX_DIMS;
 
1245
        PyArray_Descr *dtype=NULL;
 
1246
        static char *kwlist[] = {"axis", "dtype", NULL};
 
1247
 
 
1248
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, 
 
1249
                                         PyArray_AxisConverter, 
 
1250
                                         &axis, PyArray_DescrConverter2,
 
1251
                                         &dtype)) return NULL;
 
1252
        
 
1253
        return PyArray_Sum(self, axis, _CHKTYPENUM(dtype));
 
1254
}
 
1255
 
 
1256
 
 
1257
static char doc_cumsum[] = "a.cumsum(axis=None, dtype=None)";
 
1258
 
 
1259
static PyObject *
 
1260
array_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1261
{
 
1262
        int axis=MAX_DIMS;
 
1263
        PyArray_Descr *dtype=NULL;
 
1264
        static char *kwlist[] = {"axis", "dtype", NULL};
 
1265
        
 
1266
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, 
 
1267
                                         PyArray_AxisConverter, 
 
1268
                                         &axis, PyArray_DescrConverter2,
 
1269
                                         &dtype)) return NULL;
 
1270
        
 
1271
        return PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));
 
1272
}
 
1273
 
 
1274
static char doc_prod[] = "a.prod(axis=None, dtype=None)";
 
1275
 
 
1276
static PyObject *
 
1277
array_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1278
{
 
1279
        int axis=MAX_DIMS;
 
1280
        PyArray_Descr *dtype=NULL;
 
1281
        static char *kwlist[] = {"axis", "dtype", NULL};
 
1282
        
 
1283
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, 
 
1284
                                         PyArray_AxisConverter, 
 
1285
                                         &axis, PyArray_DescrConverter2,
 
1286
                                         &dtype)) return NULL;
 
1287
        
 
1288
        return PyArray_Prod(self, axis, _CHKTYPENUM(dtype));
 
1289
}
 
1290
 
 
1291
 
 
1292
static char doc_cumprod[] = "a.cumprod(axis=None, dtype=None)";
 
1293
 
 
1294
static PyObject *
 
1295
array_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1296
{
 
1297
        int axis=MAX_DIMS;
 
1298
        PyArray_Descr *dtype=NULL;
 
1299
        static char *kwlist[] = {"axis", "dtype", NULL};
 
1300
        
 
1301
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, 
 
1302
                                         PyArray_AxisConverter, 
 
1303
                                         &axis, PyArray_DescrConverter2,
 
1304
                                         &dtype)) return NULL;
 
1305
        
 
1306
        return PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));
 
1307
}
 
1308
 
 
1309
 
 
1310
static char doc_any[] = "a.any(axis=None)";
 
1311
 
 
1312
static PyObject *
 
1313
array_any(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1314
{
 
1315
        int axis=MAX_DIMS;
 
1316
        static char *kwlist[] = {"axis", NULL};
 
1317
        
 
1318
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist, 
 
1319
                                         PyArray_AxisConverter,
 
1320
                                         &axis))
 
1321
                return NULL;    
 
1322
        
 
1323
        return PyArray_Any(self, axis);
 
1324
}
 
1325
 
 
1326
static char doc_all[] = "a.all(axis=None)";
 
1327
 
 
1328
static PyObject *
 
1329
array_all(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1330
{
 
1331
        int axis=MAX_DIMS;
 
1332
        static char *kwlist[] = {"axis", NULL};
 
1333
        
 
1334
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist, 
 
1335
                                         PyArray_AxisConverter,
 
1336
                                         &axis))
 
1337
                return NULL;    
 
1338
 
 
1339
        return PyArray_All(self, axis);
 
1340
}
 
1341
 
 
1342
static char doc_stddev[] = "a.std(axis=None, dtype=None)";
 
1343
 
 
1344
static PyObject *
 
1345
array_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1346
{
 
1347
        int axis=MAX_DIMS;
 
1348
        PyArray_Descr *dtype=NULL;
 
1349
        static char *kwlist[] = {"axis", "dtype", NULL};
 
1350
        
 
1351
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, 
 
1352
                                         PyArray_AxisConverter, 
 
1353
                                         &axis, PyArray_DescrConverter2,
 
1354
                                         &dtype)) return NULL;
 
1355
        
 
1356
        return PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);
 
1357
}
 
1358
 
 
1359
static char doc_variance[] = "a.var(axis=None, dtype=None)";
 
1360
 
 
1361
static PyObject *
 
1362
array_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1363
{
 
1364
        int axis=MAX_DIMS;
 
1365
        PyArray_Descr *dtype=NULL;
 
1366
        static char *kwlist[] = {"axis", "dtype", NULL};
 
1367
        
 
1368
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, 
 
1369
                                         PyArray_AxisConverter, 
 
1370
                                         &axis, PyArray_DescrConverter2,
 
1371
                                         &dtype)) return NULL;
 
1372
        
 
1373
        return PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);
 
1374
}
 
1375
 
 
1376
static char doc_compress[] = "a.compress(condition=, axis=None)";
 
1377
 
 
1378
static PyObject *
 
1379
array_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1380
{
 
1381
        int axis=MAX_DIMS;
 
1382
        PyObject *condition;    
 
1383
        static char *kwlist[] = {"condition", "axis", NULL};
 
1384
        
 
1385
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist, 
 
1386
                                         &condition, PyArray_AxisConverter,
 
1387
                                         &axis)) return NULL;
 
1388
 
 
1389
        return _ARET(PyArray_Compress(self, condition, axis));
 
1390
}
 
1391
 
 
1392
static char doc_nonzero[] = "a.nonzero() return a tuple of indices referencing "\
 
1393
        "the elements of a that are nonzero.";
 
1394
 
 
1395
static PyObject *
 
1396
array_nonzero(PyArrayObject *self, PyObject *args)
 
1397
{
 
1398
        if (!PyArg_ParseTuple(args, "")) return NULL;
 
1399
 
 
1400
        return PyArray_Nonzero(self);
 
1401
}
 
1402
 
 
1403
 
 
1404
static char doc_trace[] = "a.trace(offset=0, axis1=0, axis2=1, dtype=None)\n"\
 
1405
        "return the sum along the offset diagonal of the arrays indicated\n" \
 
1406
        "axis1 and axis2.";
 
1407
 
 
1408
static PyObject *
 
1409
array_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1410
{
 
1411
        int axis1=0, axis2=1, offset=0;
 
1412
        PyArray_Descr *dtype=NULL;
 
1413
        static char *kwlist[] = {"offset", "axis1", "axis2", "dtype", NULL};
 
1414
        
 
1415
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iiiO&", kwlist, 
 
1416
                                         &offset, &axis1, &axis2,
 
1417
                                         PyArray_DescrConverter2, &dtype))
 
1418
                return NULL;
 
1419
        
 
1420
        return _ARET(PyArray_Trace(self, offset, axis1, axis2, 
 
1421
                                   _CHKTYPENUM(dtype)));
 
1422
}
 
1423
 
 
1424
#undef _CHKTYPENUM
 
1425
 
 
1426
 
 
1427
static char doc_clip[] = "a.clip(min=, max=)";
 
1428
 
 
1429
static PyObject *
 
1430
array_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1431
{
 
1432
        PyObject *min, *max;
 
1433
        static char *kwlist[] = {"min", "max", NULL};
 
1434
 
 
1435
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist,
 
1436
                                         &min, &max)) 
 
1437
                return NULL;
 
1438
        
 
1439
        return _ARET(PyArray_Clip(self, min, max));
 
1440
}
 
1441
 
 
1442
static char doc_conj[] = "a.conj()";
 
1443
 
 
1444
static char doc_conjugate[] = "a.conjugate()";
 
1445
 
 
1446
static PyObject *
 
1447
array_conjugate(PyArrayObject *self, PyObject *args) 
 
1448
{
 
1449
 
 
1450
        if (!PyArg_ParseTuple(args, "")) return NULL;
 
1451
        
 
1452
        return PyArray_Conjugate(self);
 
1453
}
 
1454
 
 
1455
 
 
1456
static char doc_diagonal[] = "a.diagonal(offset=0, axis1=0, axis2=1)";
 
1457
 
 
1458
static PyObject *
 
1459
array_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1460
{
 
1461
        int axis1=0, axis2=1, offset=0;
 
1462
        static char *kwlist[] = {"offset", "axis1", "axis2", NULL};
 
1463
        
 
1464
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iii", kwlist, 
 
1465
                                         &offset, &axis1, &axis2))
 
1466
                return NULL;
 
1467
        
 
1468
        return _ARET(PyArray_Diagonal(self, offset, axis1, axis2));
 
1469
}
 
1470
 
 
1471
static char doc_flatten[] = "a.flatten([fortran]) return a 1-d array (always copy)";
 
1472
 
 
1473
static PyObject *
 
1474
array_flatten(PyArrayObject *self, PyObject *args)
 
1475
{
 
1476
        PyArray_ORDER fortran=PyArray_CORDER;
 
1477
 
 
1478
        if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, 
 
1479
                              &fortran)) return NULL;
 
1480
        
 
1481
        return PyArray_Flatten(self, fortran);
 
1482
}
 
1483
 
 
1484
static char doc_ravel[] = "a.ravel([fortran]) return a 1-d array (copy only if needed)";
 
1485
 
 
1486
static PyObject *
 
1487
array_ravel(PyArrayObject *self, PyObject *args)
 
1488
{
 
1489
        PyArray_ORDER fortran=PyArray_CORDER;
 
1490
        
 
1491
        if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, 
 
1492
                              &fortran)) return NULL;
 
1493
 
 
1494
        return PyArray_Ravel(self, fortran);
 
1495
}
 
1496
 
 
1497
static char doc_round[] = "a.round(decimals=0)";
 
1498
 
 
1499
static PyObject *
 
1500
array_round(PyArrayObject *self, PyObject *args, PyObject *kwds) 
 
1501
{
 
1502
        int decimals = 0;
 
1503
        static char *kwlist[] = {"decimals", NULL};
 
1504
 
 
1505
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwlist,
 
1506
                                         &decimals)) 
 
1507
                return NULL;
 
1508
        
 
1509
        return _ARET(PyArray_Round(self, decimals));
 
1510
}
 
1511
 
 
1512
 
 
1513
static char doc_setflags[] = "a.setflags(write=None, align=None, uic=None)";
 
1514
 
 
1515
static int _IsAligned(PyArrayObject *);
 
1516
static Bool _IsWriteable(PyArrayObject *);
 
1517
 
 
1518
static PyObject *
 
1519
array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
 
1520
{
 
1521
        static char *kwlist[] = {"write", "align", "uic", NULL};
 
1522
        PyObject *write=Py_None;
 
1523
        PyObject *align=Py_None;
 
1524
        PyObject *uic=Py_None;
 
1525
        int flagback = self->flags;
 
1526
                
 
1527
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", kwlist,
 
1528
                                         &write, &align, &uic))
 
1529
                return NULL;
 
1530
 
 
1531
        if (align != Py_None) {
 
1532
                if (PyObject_Not(align)) self->flags &= ~ALIGNED;
 
1533
                else if (_IsAligned(self)) self->flags |= ALIGNED;
 
1534
                else {
 
1535
                        PyErr_SetString(PyExc_ValueError, 
 
1536
                                        "cannot set aligned flag of mis-"\
 
1537
                                        "aligned array to True");
 
1538
                        return NULL;
 
1539
                }
 
1540
        }
 
1541
        
 
1542
        if (uic != Py_None) {
 
1543
                if (PyObject_IsTrue(uic)) {
 
1544
                        self->flags = flagback;
 
1545
                        PyErr_SetString(PyExc_ValueError, 
 
1546
                                        "cannot set UPDATEIFCOPY"       \
 
1547
                                        "flag to True");
 
1548
                        return NULL;
 
1549
                }
 
1550
                else {
 
1551
                        self->flags &= ~UPDATEIFCOPY;
 
1552
                        Py_XDECREF(self->base);
 
1553
                        self->base = NULL;
 
1554
                }
 
1555
        }
 
1556
        
 
1557
        if (write != Py_None) {
 
1558
                if (PyObject_IsTrue(write)) 
 
1559
                        if (_IsWriteable(self)) {
 
1560
                                self->flags |= WRITEABLE;
 
1561
                        }
 
1562
                        else {
 
1563
                                self->flags = flagback;
 
1564
                                PyErr_SetString(PyExc_ValueError, 
 
1565
                                                "cannot set WRITEABLE " \
 
1566
                                                "flag to True of this " \
 
1567
                                                "array");               \
 
1568
                                return NULL;
 
1569
                        }
 
1570
                else
 
1571
                        self->flags &= ~WRITEABLE;
 
1572
        }
 
1573
        
 
1574
        Py_INCREF(Py_None);
 
1575
        return Py_None;
 
1576
}
 
1577
 
 
1578
static char doc_newbyteorder[] = "a.newbyteorder(<byteorder>) is equivalent\n" \
 
1579
        " to a.view(a.dtype.newbytorder(<byteorder>))\n";
 
1580
 
 
1581
static PyObject *
 
1582
array_newbyteorder(PyArrayObject *self, PyObject *args) 
 
1583
{
 
1584
        char endian = PyArray_SWAP;
 
1585
        PyArray_Descr *new;
 
1586
        
 
1587
        if (!PyArg_ParseTuple(args, "|O&", PyArray_ByteorderConverter,
 
1588
                              &endian)) return NULL;
 
1589
 
 
1590
        new = PyArray_DescrNewByteorder(self->descr, endian);
 
1591
        if (!new) return NULL;
 
1592
        return PyArray_View(self, new, NULL);
 
1593
 
 
1594
}
 
1595
 
 
1596
static PyMethodDef array_methods[] = {
 
1597
        {"tolist",       (PyCFunction)array_tolist,     1, doc_tolist},
 
1598
        {"item", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar},
 
1599
        {"tofile", (PyCFunction)array_tofile, 
 
1600
         METH_VARARGS | METH_KEYWORDS, doc_tofile},
 
1601
        {"tostring", (PyCFunction)array_tostring, METH_VARARGS, doc_tostring},
 
1602
        {"byteswap",   (PyCFunction)array_byteswap,     1, doc_byteswap},
 
1603
        {"astype", (PyCFunction)array_cast, 1, doc_cast},
 
1604
        {"getfield", (PyCFunction)array_getfield, 
 
1605
         METH_VARARGS | METH_KEYWORDS, doc_getfield},
 
1606
        {"setfield", (PyCFunction)array_setfield, 
 
1607
         METH_VARARGS | METH_KEYWORDS, doc_setfield},
 
1608
        {"copy", (PyCFunction)array_copy, 1, doc_copy},  
 
1609
        {"resize", (PyCFunction)array_resize, 
 
1610
         METH_VARARGS | METH_KEYWORDS, doc_resize}, 
 
1611
 
 
1612
        /* for subtypes */
 
1613
        {"__array__", (PyCFunction)array_getarray, 1, doc_array_getarray},
 
1614
        {"__array_wrap__", (PyCFunction)array_wraparray, 1, doc_wraparray},
 
1615
        /* default version so it is found... -- only used for subclasses */
 
1616
        {"__array_finalize__", (PyCFunction)array_finalize, 1, NULL},
 
1617
        
 
1618
        
 
1619
        /* for the copy module */
 
1620
        {"__copy__", (PyCFunction)array_copy, 1, doc_copy},      
 
1621
        {"__deepcopy__", (PyCFunction)array_deepcopy, 1, doc_deepcopy},  
 
1622
        
 
1623
        /* for Pickling */
 
1624
        {"__reduce__", (PyCFunction) array_reduce, 1, doc_reduce},      
 
1625
        {"__setstate__", (PyCFunction) array_setstate, 1, doc_setstate},
 
1626
        {"dumps", (PyCFunction) array_dumps, 1, doc_dumps},
 
1627
        {"dump", (PyCFunction) array_dump, 1, doc_dump},
 
1628
 
 
1629
        /* Extended methods added 2005 */
 
1630
        {"fill", (PyCFunction)array_fill,
 
1631
         METH_VARARGS, doc_fill},
 
1632
        {"transpose",   (PyCFunction)array_transpose, 
 
1633
         METH_VARARGS, doc_transpose},
 
1634
        {"take",        (PyCFunction)array_take, 
 
1635
         METH_VARARGS|METH_KEYWORDS, doc_take},
 
1636
        {"put", (PyCFunction)array_put, 
 
1637
         METH_VARARGS|METH_KEYWORDS, doc_put},
 
1638
        {"putmask",     (PyCFunction)array_putmask, 
 
1639
         METH_VARARGS|METH_KEYWORDS, doc_putmask},
 
1640
        {"repeat",      (PyCFunction)array_repeat, 
 
1641
         METH_VARARGS|METH_KEYWORDS, doc_repeat},
 
1642
        {"choose",      (PyCFunction)array_choose, 
 
1643
         METH_VARARGS, doc_choose},     
 
1644
        {"sort",        (PyCFunction)array_sort, 
 
1645
         METH_VARARGS|METH_KEYWORDS, doc_sort},
 
1646
        {"argsort",     (PyCFunction)array_argsort, 
 
1647
         METH_VARARGS|METH_KEYWORDS, doc_argsort},
 
1648
        {"searchsorted",  (PyCFunction)array_searchsorted, 
 
1649
         METH_VARARGS, doc_searchsorted},       
 
1650
        {"argmax",      (PyCFunction)array_argmax, 
 
1651
         METH_VARARGS|METH_KEYWORDS, doc_argmax},
 
1652
        {"argmin",  (PyCFunction)array_argmin,
 
1653
         METH_VARARGS|METH_KEYWORDS, doc_argmin},
 
1654
        {"reshape",     (PyCFunction)array_reshape, 
 
1655
         METH_VARARGS|METH_KEYWORDS, doc_reshape},
 
1656
        {"squeeze",     (PyCFunction)array_squeeze,
 
1657
         METH_VARARGS, doc_squeeze},
 
1658
        {"view",  (PyCFunction)array_view, 
 
1659
         METH_VARARGS, doc_view},
 
1660
        {"swapaxes", (PyCFunction)array_swapaxes,
 
1661
         METH_VARARGS, doc_swapaxes},
 
1662
        {"max", (PyCFunction)array_max,
 
1663
         METH_VARARGS|METH_KEYWORDS, doc_max},
 
1664
        {"min", (PyCFunction)array_min,
 
1665
         METH_VARARGS|METH_KEYWORDS, doc_min},
 
1666
        {"ptp", (PyCFunction)array_ptp,
 
1667
         METH_VARARGS|METH_KEYWORDS, doc_ptp},
 
1668
        {"mean", (PyCFunction)array_mean,
 
1669
         METH_VARARGS|METH_KEYWORDS, doc_mean},
 
1670
        {"trace", (PyCFunction)array_trace,
 
1671
         METH_VARARGS|METH_KEYWORDS, doc_trace},
 
1672
        {"diagonal", (PyCFunction)array_diagonal,
 
1673
         METH_VARARGS|METH_KEYWORDS, doc_diagonal},
 
1674
        {"clip", (PyCFunction)array_clip,
 
1675
         METH_VARARGS|METH_KEYWORDS, doc_clip},
 
1676
        {"conj", (PyCFunction)array_conjugate,
 
1677
         METH_VARARGS, doc_conj},
 
1678
        {"conjugate", (PyCFunction)array_conjugate,
 
1679
         METH_VARARGS, doc_conjugate},
 
1680
        {"nonzero", (PyCFunction)array_nonzero,
 
1681
         METH_VARARGS, doc_nonzero},
 
1682
        {"std", (PyCFunction)array_stddev,
 
1683
         METH_VARARGS|METH_KEYWORDS, doc_stddev},
 
1684
        {"var", (PyCFunction)array_variance,
 
1685
         METH_VARARGS|METH_KEYWORDS, doc_variance},
 
1686
        {"sum", (PyCFunction)array_sum,
 
1687
         METH_VARARGS|METH_KEYWORDS, doc_sum},
 
1688
        {"cumsum", (PyCFunction)array_cumsum,
 
1689
         METH_VARARGS|METH_KEYWORDS, doc_cumsum},
 
1690
        {"prod", (PyCFunction)array_prod,
 
1691
         METH_VARARGS|METH_KEYWORDS, doc_prod},
 
1692
        {"cumprod", (PyCFunction)array_cumprod,
 
1693
         METH_VARARGS|METH_KEYWORDS, doc_cumprod},
 
1694
        {"all", (PyCFunction)array_all,
 
1695
         METH_VARARGS|METH_KEYWORDS, doc_all},
 
1696
        {"any", (PyCFunction)array_any,
 
1697
         METH_VARARGS|METH_KEYWORDS, doc_any},
 
1698
        {"compress", (PyCFunction)array_compress,
 
1699
         METH_VARARGS|METH_KEYWORDS, doc_compress},
 
1700
        {"flatten", (PyCFunction)array_flatten,
 
1701
         METH_VARARGS, doc_flatten},
 
1702
        {"ravel", (PyCFunction)array_ravel,
 
1703
         METH_VARARGS, doc_ravel},
 
1704
        {"round", (PyCFunction)array_round,
 
1705
         METH_VARARGS|METH_KEYWORDS, doc_round},
 
1706
        {"setflags", (PyCFunction)array_setflags,
 
1707
         METH_VARARGS|METH_KEYWORDS, doc_setflags},
 
1708
        {"newbyteorder", (PyCFunction)array_newbyteorder,
 
1709
         METH_VARARGS, doc_newbyteorder},
 
1710
        {NULL,          NULL}           /* sentinel */
 
1711
};
 
1712
 
 
1713
#undef _ARET
 
1714
 
 
1715