2
/* Should only be used if x is known to be an nd-array */
3
#define _ARET(x) PyArray_Return((PyArrayObject *)(x))
5
static char doc_take[] = "a.take(indices, axis=None). Selects the elements "\
6
"in indices from array a along the given axis.";
9
array_take(PyArrayObject *self, PyObject *args, PyObject *kwds)
11
int dimension=MAX_DIMS;
13
static char *kwlist[] = {"indices", "axis", NULL};
16
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist,
17
&indices, PyArray_AxisConverter,
21
return _ARET(PyArray_Take(self, indices, dimension));
24
static char doc_fill[] = "a.fill(value) places the scalar value at every "\
25
"position in the array.";
28
array_fill(PyArrayObject *self, PyObject *args)
31
if (!PyArg_ParseTuple(args, "O", &obj))
33
if (PyArray_FillWithScalar(self, obj) < 0) return NULL;
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, "\
43
array_put(PyArrayObject *self, PyObject *args, PyObject *kwds)
45
PyObject *indices, *values;
46
static char *kwlist[] = {"values", "indices", NULL};
48
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist,
51
return PyArray_Put(self, values, indices);
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.";
58
array_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds)
60
PyObject *mask, *values;
62
static char *kwlist[] = {"values", "mask", NULL};
64
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist,
67
return PyArray_PutMask(self, values, mask);
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"
78
array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds)
80
PyArray_Dims newshape;
82
PyArray_ORDER order=PyArray_CORDER;
87
ref = PyDict_GetItemString(kwds, "order");
89
(PyArray_OrderConverter(ref, &order) == PY_FAIL))
93
n = PyTuple_Size(args);
95
if (!PyArg_ParseTuple(args, "O&", PyArray_IntpConverter,
96
&newshape)) return NULL;
99
if (!PyArray_IntpConverter(args, &newshape)) {
100
if (!PyErr_Occurred()) {
101
PyErr_SetString(PyExc_TypeError,
107
ret = PyArray_Newshape(self, &newshape, order);
108
PyDimMem_FREE(newshape.ptr);
112
PyDimMem_FREE(newshape.ptr);
116
static char doc_squeeze[] = "m.squeeze() eliminate all length-1 dimensions";
119
array_squeeze(PyArrayObject *self, PyObject *args)
121
if (!PyArg_ParseTuple(args, "")) return NULL;
122
return _ARET(PyArray_Squeeze(self));
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";
128
array_view(PyArrayObject *self, PyObject *args)
130
PyObject *otype=NULL;
131
PyArray_Descr *type=NULL;
133
if (!PyArg_ParseTuple(args, "|O", &otype)) return NULL;
136
if (PyType_Check(otype) && \
137
PyType_IsSubtype((PyTypeObject *)otype,
139
return PyArray_View(self, NULL,
140
(PyTypeObject *)otype);
143
if (PyArray_DescrConverter(otype, &type) == PY_FAIL)
147
return PyArray_View(self, type, NULL);
150
static char doc_argmax[] = "a.argmax(axis=None)";
153
array_argmax(PyArrayObject *self, PyObject *args, PyObject *kwds)
156
static char *kwlist[] = {"axis", NULL};
158
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
159
PyArray_AxisConverter,
163
return _ARET(PyArray_ArgMax(self, axis));
166
static char doc_argmin[] = "a.argmin(axis=None)";
169
array_argmin(PyArrayObject *self, PyObject *args, PyObject *kwds)
172
static char *kwlist[] = {"axis", NULL};
174
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
175
PyArray_AxisConverter,
179
return _ARET(PyArray_ArgMin(self, axis));
182
static char doc_max[] = "a.max(axis=None)";
185
array_max(PyArrayObject *self, PyObject *args, PyObject *kwds)
188
static char *kwlist[] = {"axis", NULL};
190
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
191
PyArray_AxisConverter,
195
return PyArray_Max(self, axis);
198
static char doc_ptp[] = "a.ptp(axis=None) a.max(axis)-a.min(axis)";
201
array_ptp(PyArrayObject *self, PyObject *args, PyObject *kwds)
204
static char *kwlist[] = {"axis", NULL};
206
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
207
PyArray_AxisConverter,
211
return PyArray_Ptp(self, axis);
215
static char doc_min[] = "a.min(axis=None)";
218
array_min(PyArrayObject *self, PyObject *args, PyObject *kwds)
221
static char *kwlist[] = {"axis", NULL};
223
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
224
PyArray_AxisConverter,
228
return PyArray_Min(self, axis);
231
static char doc_swapaxes[] = "a.swapaxes(axis1, axis2) returns new view with axes swapped.";
234
array_swapaxes(PyArrayObject *self, PyObject *args)
238
if (!PyArg_ParseTuple(args, "ii", &axis1, &axis2)) return NULL;
240
return PyArray_SwapAxes(self, axis1, axis2);
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.";
248
/* steals typed reference */
250
Get a subset of bytes from each element of the array
253
PyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)
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);
265
ret = PyArray_NewFromDescr(self->ob_type,
267
self->nd, self->dimensions,
270
self->flags, (PyObject *)self);
271
if (ret == NULL) return NULL;
273
((PyArrayObject *)ret)->base = (PyObject *)self;
275
PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);
280
array_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)
283
PyArray_Descr *dtype;
285
static char *kwlist[] = {"dtype", "offset", 0};
287
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|i", kwlist,
288
PyArray_DescrConverter,
289
&dtype, &offset)) return NULL;
291
return _ARET(PyArray_GetField(self, dtype, offset));
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.";
299
Set a subset of bytes from each element of the array
302
PyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,
303
int offset, PyObject *val)
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);
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;
322
((PyArrayObject *)ret)->base = (PyObject *)self;
324
PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);
325
retval = PyArray_CopyObject((PyArrayObject *)ret, val);
331
array_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)
333
PyArray_Descr *dtype;
336
static char *kwlist[] = {"value", "dtype", "offset", 0};
338
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|i", kwlist,
339
&value, PyArray_DescrConverter,
340
&dtype, &offset)) return NULL;
342
if (PyArray_SetField(self, dtype, offset, value) < 0)
348
/* This doesn't change the descriptor just the actual data...
353
PyArray_Byteswap(PyArrayObject *self, Bool inplace)
357
PyArray_CopySwapNFunc *copyswapn;
358
PyArray_CopySwapFunc *copyswap;
359
PyArrayIterObject *it;
362
copyswapn = self->descr->f->copyswapn;
364
size = PyArray_SIZE(self);
365
if (PyArray_ISONESEGMENT(self)) {
366
copyswapn(self->data, NULL, size, 1, self);
368
else { /* Use iterator */
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);
381
return (PyObject *)self;
384
if ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL)
387
size = PyArray_SIZE(self);
389
/* now ret has the same dtypedescr as self (including
393
ret->descr->f->copyswapn(ret->data, NULL, size, 1, ret);
395
return (PyObject *)ret;
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.";
404
array_byteswap(PyArrayObject *self, PyObject *args)
408
if (!PyArg_ParseTuple(args, "|O&", PyArray_BoolConverter, &inplace))
411
return PyArray_Byteswap(self, inplace);
414
static char doc_tolist[] = "m.tolist(). Copy the data portion of the array"\
415
" to a hierarchical python list and return that list.";
418
array_tolist(PyArrayObject *self, PyObject *args)
420
if (!PyArg_ParseTuple(args, "")) return NULL;
422
PyErr_SetString(PyExc_ValueError,
423
"can't convert a 0-d array to a list");
427
return PyArray_ToList(self);
430
static char doc_tostring[] = "m.tostring() Construct a Python string "\
431
"containing the raw bytes in the array";
434
array_tostring(PyArrayObject *self, PyObject *args)
436
if (!PyArg_ParseTuple(args, "")) return NULL;
437
return PyArray_ToString(self);
440
static char doc_tofile[] = "m.tofile(fid, sep="") write the data to a file.";
443
array_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)
451
static char *kwlist[] = {"file", "sep", "format", NULL};
453
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss", kwlist,
454
&file, &sep, &format)) return NULL;
456
if (PyString_Check(file)) {
457
if (sep == "") mode="wb";
459
file = PyFile_FromString(PyString_AS_STRING(file), mode);
460
if (file==NULL) return NULL;
465
fd = PyFile_AsFile(file);
467
PyErr_SetString(PyExc_IOError, "first argument must be a " \
468
"string or open file");
472
ret = PyArray_ToFile(self, fd, sep, format);
474
if (ret < 0) return NULL;
479
static char doc_toscalar[] = "m.item(). Copy the first data point of "\
480
"the array to a standard Python scalar and return it.";
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);
488
PyErr_SetString(PyExc_ValueError, "can only convert an" \
489
" array of size 1 to Python scalar.");
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.";
499
array_cast(PyArrayObject *self, PyObject *args)
501
PyArray_Descr *descr=NULL;
504
if (!PyArg_ParseTuple(args, "O&", PyArray_DescrConverter,
505
&descr)) return NULL;
507
if (descr == self->descr) {
508
obj = _ARET(PyArray_NewCopy(self,0));
512
return _ARET(PyArray_CastToType(self, descr, 0));
515
/* default sub-type implementation */
517
static char doc_wraparray[] = "m.__array_wrap__(obj) returns an object of "\
518
"type m from the ndarray object obj";
521
array_wraparray(PyArrayObject *self, PyObject *args)
526
if (PyTuple_Size(args) < 1) {
527
PyErr_SetString(PyExc_TypeError,
528
"only accepts 1 argument");
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");
538
Py_INCREF(PyArray_DESCR(arr));
539
ret = PyArray_NewFromDescr(self->ob_type,
543
PyArray_STRIDES(arr), PyArray_DATA(arr),
544
PyArray_FLAGS(arr), (PyObject *)self);
545
if (ret == NULL) return NULL;
547
PyArray_BASE(ret) = arr;
551
/* NO-OP --- just so all subclasses will have one by default. */
553
array_finalize(PyArrayObject *self, PyObject *args)
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.";
563
array_getarray(PyArrayObject *self, PyObject *args)
565
PyArray_Descr *newtype=NULL;
568
if (!PyArg_ParseTuple(args, "|O&", PyArray_DescrConverter,
569
&newtype)) return NULL;
571
/* convert to PyArray_Type */
572
if (!PyArray_CheckExact(self)) {
574
PyTypeObject *subtype = &PyArray_Type;
576
if (!PyType_IsSubtype(self->ob_type, &PyArray_Type)) {
577
subtype = &PyArray_Type;
580
Py_INCREF(PyArray_DESCR(self));
581
new = PyArray_NewFromDescr(subtype,
585
PyArray_STRIDES(self),
587
PyArray_FLAGS(self), NULL);
588
if (new == NULL) return NULL;
590
PyArray_BASE(new) = (PyObject *)self;
591
self = (PyArrayObject *)new;
597
if ((newtype == NULL) || \
598
PyArray_EquivTypes(self->descr, newtype)) {
599
return (PyObject *)self;
602
ret = PyArray_CastToType(self, newtype, 0);
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.";
615
array_copy(PyArrayObject *self, PyObject *args)
617
PyArray_ORDER fortran=PyArray_CORDER;
618
if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter,
619
&fortran)) return NULL;
621
return PyArray_NewCopy(self, fortran);
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.";
630
array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds)
632
PyArray_Dims newshape;
636
PyArray_ORDER fortran=PyArray_ANYORDER;
640
ref = PyDict_GetItemString(kwds, "refcheck");
642
refcheck = PyInt_AsLong(ref);
643
if (refcheck==-1 && PyErr_Occurred()) {
647
ref = PyDict_GetItemString(kwds, "fortran");
649
(PyArray_OrderConverter(ref, &fortran) == PY_FAIL))
652
n = PyTuple_Size(args);
654
if (!PyArg_ParseTuple(args, "O&", PyArray_IntpConverter,
655
&newshape)) return NULL;
658
if (!PyArray_IntpConverter(args, &newshape)) {
659
if (!PyErr_Occurred()) {
660
PyErr_SetString(PyExc_TypeError,
666
ret = PyArray_Resize(self, &newshape, refcheck, fortran);
667
PyDimMem_FREE(newshape.ptr);
668
if (ret == NULL) return NULL;
674
static char doc_repeat[] = "a.repeat(repeats=, axis=None)\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.";
680
array_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {
683
static char *kwlist[] = {"repeats", "axis", NULL};
685
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist,
686
&repeats, PyArray_AxisConverter,
689
return _ARET(PyArray_Repeat(self, repeats, axis));
692
static char doc_choose[] = "a.choose(b0, b1, ..., bn)\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"\
700
array_choose(PyArrayObject *self, PyObject *args)
705
n = PyTuple_Size(args);
707
if (!PyArg_ParseTuple(args, "O", &choices))
714
return _ARET(PyArray_Choose(self, choices));
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'";
720
array_sort(PyArrayObject *self, PyObject *args, PyObject *kwds)
724
PyArray_SORTKIND which=PyArray_QUICKSORT;
725
static char *kwlist[] = {"axis", "kind", NULL};
727
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&", kwlist, &axis,
728
PyArray_SortkindConverter, &which))
731
val = PyArray_Sort(self, axis, which);
732
if (val < 0) return NULL;
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'";
742
array_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds)
745
PyArray_SORTKIND which=PyArray_QUICKSORT;
746
static char *kwlist[] = {"axis", "kind", NULL};
748
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&", kwlist, &axis,
749
PyArray_SortkindConverter, &which))
752
return _ARET(PyArray_ArgSort(self, axis, which));
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.";
764
array_searchsorted(PyArrayObject *self, PyObject *args)
768
if (!PyArg_ParseTuple(args, "O", &values)) return NULL;
770
return _ARET(PyArray_SearchSorted(self, values));
773
static char doc_deepcopy[] = "Used if copy.deepcopy is called on an array.";
776
array_deepcopy(PyArrayObject *self, PyObject *args)
780
PyArrayIterObject *it;
781
PyObject *copy, *ret, *deepcopy, *temp, *res;
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");
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);
797
/* call deepcopy on this argument */
798
res = PyObject_CallFunctionObjArgs(deepcopy,
803
PyArray_ITER_NEXT(it);
811
/* Convert Object Array to flat list and pickle the flat list string */
813
_getobject_pkl(PyArrayObject *self)
816
PyArrayIterObject *iter=NULL;
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);
835
_setobject_pkl(PyArrayObject *self, PyObject *list)
838
PyArrayIterObject *iter=NULL;
841
size = self->descr->elsize;
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);
855
static char doc_reduce[] = "a.__reduce__() for pickling.";
858
array_reduce(PyArrayObject *self, PyObject *args)
860
PyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;
861
PyObject *mybool, *thestr=NULL;
862
PyArray_Descr *descr;
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 */
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");
874
PyTuple_SET_ITEM(ret, 0, obj);
875
PyTuple_SET_ITEM(ret, 1,
877
(PyObject *)self->ob_type,
880
/* dummy data-type */
883
/* Now fill in object's state. This is a tuple with
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)
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
895
state = PyTuple_New(4);
897
Py_DECREF(ret); return NULL;
899
PyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self,
903
PyTuple_SET_ITEM(state, 1, (PyObject *)descr);
904
mybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);
906
PyTuple_SET_ITEM(state, 2, mybool);
907
if (PyArray_ISOBJECT(self)) {
908
thestr = _getobject_pkl(self);
911
thestr = PyArray_ToString(self);
913
if (thestr == NULL) {
918
PyTuple_SET_ITEM(state, 3, thestr);
919
PyTuple_SET_ITEM(ret, 2, state);
923
static char doc_setstate[] = "a.__setstate__(tuple) for unpickling.";
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)
932
static intp _array_fill_strides(intp *, intp *, int, intp, int, int *);
934
static int _IsAligned(PyArrayObject *);
936
static PyArray_Descr * _array_typedescr_fromstr(char *);
939
array_setstate(PyArrayObject *self, PyObject *args)
942
PyArray_Descr *typecode;
947
intp dimensions[MAX_DIMS];
950
/* This will free any memory associated with a and
951
use the string in setstate as the (writeable) memory.
953
if (!PyArg_ParseTuple(args, "(O!O!iO)", &PyTuple_Type,
954
&shape, &PyArrayDescr_Type, &typecode,
958
Py_XDECREF(self->descr);
959
self->descr = 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");
970
if (!PyString_Check(rawdata)) {
971
PyErr_SetString(PyExc_TypeError,
972
"pickle not returning string");
976
if (PyString_AsStringAndSize(rawdata, &datastr, &len))
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");
988
if ((self->flags & OWN_DATA)) {
989
if (self->data != NULL)
990
PyDataMem_FREE(self->data);
991
self->flags &= ~OWN_DATA;
993
Py_XDECREF(self->base);
995
self->flags &= ~UPDATEIFCOPY;
997
if (self->dimensions != NULL) {
998
PyDimMem_FREE(self->dimensions);
999
self->dimensions = NULL;
1002
self->flags = DEFAULT_FLAGS;
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),
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) {
1024
PyDimMem_FREE(self->dimensions);
1025
return PyErr_NoMemory();
1027
if (swap) { /* byte-swap on pickle-read */
1028
intp numels = num / self->descr->elsize;
1029
self->descr->f->copyswapn(self->data, datastr,
1032
if (!PyArray_ISEXTENDED(self)) {
1033
self->descr = PyArray_DescrFromType(self->descr->type_num);
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;
1042
Py_DECREF(typecode);
1045
memcpy(self->data, datastr, num);
1047
self->flags |= OWN_DATA;
1051
self->base = rawdata;
1052
Py_INCREF(self->base);
1056
self->data = PyDataMem_NEW(PyArray_NBYTES(self));
1057
if (self->data == NULL) {
1059
self->data = PyDataMem_NEW(self->descr->elsize);
1060
if (self->dimensions) PyDimMem_FREE(self->dimensions);
1061
return PyErr_NoMemory();
1063
self->flags |= OWN_DATA;
1065
if (_setobject_pkl(self, rawdata) < 0)
1069
PyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);
1077
PyArray_Dump(PyObject *self, PyObject *file, int protocol)
1079
PyObject *cpick=NULL;
1081
if (protocol < 0) protocol = 2;
1083
cpick = PyImport_ImportModule("cPickle");
1084
if (cpick==NULL) return -1;
1086
if PyString_Check(file) {
1087
file = PyFile_FromString(PyString_AS_STRING(file), "wb");
1088
if (file==NULL) return -1;
1090
else Py_INCREF(file);
1091
ret = PyObject_CallMethod(cpick, "dump", "OOi", self,
1096
if (PyErr_Occurred()) return -1;
1102
PyArray_Dumps(PyObject *self, int protocol)
1104
PyObject *cpick=NULL;
1106
if (protocol < 0) protocol = 2;
1108
cpick = PyImport_ImportModule("cPickle");
1109
if (cpick==NULL) return NULL;
1110
ret = PyObject_CallMethod(cpick, "dumps", "Oi", self, protocol);
1116
static char doc_dump[] = "m.dump(file)";
1119
array_dump(PyArrayObject *self, PyObject *args)
1121
PyObject *file=NULL;
1124
if (!PyArg_ParseTuple(args, "O", &file))
1126
ret = PyArray_Dump((PyObject *)self, file, 2);
1127
if (ret < 0) return NULL;
1132
static char doc_dumps[] = "m.dumps()";
1135
array_dumps(PyArrayObject *self, PyObject *args)
1137
if (!PyArg_ParseTuple(args, ""))
1139
return PyArray_Dumps((PyObject *)self, 2);
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"
1149
">>> a = array([[1,2],[3,4]])\n"
1153
">>> a.transpose()\n"
1156
">>> a.transpose((1,0))\n"
1159
">>> a.transpose(1,0)\n"
1165
array_transpose(PyArrayObject *self, PyObject *args)
1167
PyObject *shape=Py_None;
1169
PyArray_Dims permute;
1172
n = PyTuple_Size(args);
1173
if (n > 1) shape = args;
1174
else if (n == 1) shape = PyTuple_GET_ITEM(args, 0);
1176
if (shape == Py_None)
1177
ret = PyArray_Transpose(self, NULL);
1179
if (!PyArray_IntpConverter(shape, &permute)) return NULL;
1180
ret = PyArray_Transpose(self, &permute);
1181
PyDimMem_FREE(permute.ptr);
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"\
1191
"If an integer axis is given, this equals:\n"\
1192
" a.sum(axis, dtype) * 1.0 / len(a)\n"\
1194
"If axis is None, this equals:\n"\
1195
" a.sum(axis, dtype) * 1.0 / product(a.shape)\n"\
1197
"The optional dtype argument is the data type for intermediate\n"\
1198
"calculations in the sum.";
1200
#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)
1203
array_mean(PyArrayObject *self, PyObject *args, PyObject *kwds)
1206
PyArray_Descr *dtype=NULL;
1207
static char *kwlist[] = {"axis", "dtype", NULL};
1209
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
1210
PyArray_AxisConverter,
1211
&axis, PyArray_DescrConverter2,
1212
&dtype)) return NULL;
1214
return PyArray_Mean(self, axis, _CHKTYPENUM(dtype));
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"\
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"\
1226
" a.dtype default sum() dtype\n"\
1227
" ---------------------------------------------------\n"\
1228
" bool, int8, int16, int32 int32\n"\
1232
">>> array([0.5, 1.5]).sum()\n"\
1234
">>> array([0.5, 1.5]).sum(dtype=int32)\n"\
1236
">>> array([[0, 1], [0, 5]]).sum(axis=0)\n"\
1238
">>> array([[0, 1], [0, 5]]).sum(axis=1)\n"\
1242
array_sum(PyArrayObject *self, PyObject *args, PyObject *kwds)
1245
PyArray_Descr *dtype=NULL;
1246
static char *kwlist[] = {"axis", "dtype", NULL};
1248
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
1249
PyArray_AxisConverter,
1250
&axis, PyArray_DescrConverter2,
1251
&dtype)) return NULL;
1253
return PyArray_Sum(self, axis, _CHKTYPENUM(dtype));
1257
static char doc_cumsum[] = "a.cumsum(axis=None, dtype=None)";
1260
array_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds)
1263
PyArray_Descr *dtype=NULL;
1264
static char *kwlist[] = {"axis", "dtype", NULL};
1266
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
1267
PyArray_AxisConverter,
1268
&axis, PyArray_DescrConverter2,
1269
&dtype)) return NULL;
1271
return PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));
1274
static char doc_prod[] = "a.prod(axis=None, dtype=None)";
1277
array_prod(PyArrayObject *self, PyObject *args, PyObject *kwds)
1280
PyArray_Descr *dtype=NULL;
1281
static char *kwlist[] = {"axis", "dtype", NULL};
1283
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
1284
PyArray_AxisConverter,
1285
&axis, PyArray_DescrConverter2,
1286
&dtype)) return NULL;
1288
return PyArray_Prod(self, axis, _CHKTYPENUM(dtype));
1292
static char doc_cumprod[] = "a.cumprod(axis=None, dtype=None)";
1295
array_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds)
1298
PyArray_Descr *dtype=NULL;
1299
static char *kwlist[] = {"axis", "dtype", NULL};
1301
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
1302
PyArray_AxisConverter,
1303
&axis, PyArray_DescrConverter2,
1304
&dtype)) return NULL;
1306
return PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));
1310
static char doc_any[] = "a.any(axis=None)";
1313
array_any(PyArrayObject *self, PyObject *args, PyObject *kwds)
1316
static char *kwlist[] = {"axis", NULL};
1318
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
1319
PyArray_AxisConverter,
1323
return PyArray_Any(self, axis);
1326
static char doc_all[] = "a.all(axis=None)";
1329
array_all(PyArrayObject *self, PyObject *args, PyObject *kwds)
1332
static char *kwlist[] = {"axis", NULL};
1334
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
1335
PyArray_AxisConverter,
1339
return PyArray_All(self, axis);
1342
static char doc_stddev[] = "a.std(axis=None, dtype=None)";
1345
array_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds)
1348
PyArray_Descr *dtype=NULL;
1349
static char *kwlist[] = {"axis", "dtype", NULL};
1351
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
1352
PyArray_AxisConverter,
1353
&axis, PyArray_DescrConverter2,
1354
&dtype)) return NULL;
1356
return PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);
1359
static char doc_variance[] = "a.var(axis=None, dtype=None)";
1362
array_variance(PyArrayObject *self, PyObject *args, PyObject *kwds)
1365
PyArray_Descr *dtype=NULL;
1366
static char *kwlist[] = {"axis", "dtype", NULL};
1368
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist,
1369
PyArray_AxisConverter,
1370
&axis, PyArray_DescrConverter2,
1371
&dtype)) return NULL;
1373
return PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);
1376
static char doc_compress[] = "a.compress(condition=, axis=None)";
1379
array_compress(PyArrayObject *self, PyObject *args, PyObject *kwds)
1382
PyObject *condition;
1383
static char *kwlist[] = {"condition", "axis", NULL};
1385
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist,
1386
&condition, PyArray_AxisConverter,
1387
&axis)) return NULL;
1389
return _ARET(PyArray_Compress(self, condition, axis));
1392
static char doc_nonzero[] = "a.nonzero() return a tuple of indices referencing "\
1393
"the elements of a that are nonzero.";
1396
array_nonzero(PyArrayObject *self, PyObject *args)
1398
if (!PyArg_ParseTuple(args, "")) return NULL;
1400
return PyArray_Nonzero(self);
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" \
1409
array_trace(PyArrayObject *self, PyObject *args, PyObject *kwds)
1411
int axis1=0, axis2=1, offset=0;
1412
PyArray_Descr *dtype=NULL;
1413
static char *kwlist[] = {"offset", "axis1", "axis2", "dtype", NULL};
1415
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iiiO&", kwlist,
1416
&offset, &axis1, &axis2,
1417
PyArray_DescrConverter2, &dtype))
1420
return _ARET(PyArray_Trace(self, offset, axis1, axis2,
1421
_CHKTYPENUM(dtype)));
1427
static char doc_clip[] = "a.clip(min=, max=)";
1430
array_clip(PyArrayObject *self, PyObject *args, PyObject *kwds)
1432
PyObject *min, *max;
1433
static char *kwlist[] = {"min", "max", NULL};
1435
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist,
1439
return _ARET(PyArray_Clip(self, min, max));
1442
static char doc_conj[] = "a.conj()";
1444
static char doc_conjugate[] = "a.conjugate()";
1447
array_conjugate(PyArrayObject *self, PyObject *args)
1450
if (!PyArg_ParseTuple(args, "")) return NULL;
1452
return PyArray_Conjugate(self);
1456
static char doc_diagonal[] = "a.diagonal(offset=0, axis1=0, axis2=1)";
1459
array_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds)
1461
int axis1=0, axis2=1, offset=0;
1462
static char *kwlist[] = {"offset", "axis1", "axis2", NULL};
1464
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iii", kwlist,
1465
&offset, &axis1, &axis2))
1468
return _ARET(PyArray_Diagonal(self, offset, axis1, axis2));
1471
static char doc_flatten[] = "a.flatten([fortran]) return a 1-d array (always copy)";
1474
array_flatten(PyArrayObject *self, PyObject *args)
1476
PyArray_ORDER fortran=PyArray_CORDER;
1478
if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter,
1479
&fortran)) return NULL;
1481
return PyArray_Flatten(self, fortran);
1484
static char doc_ravel[] = "a.ravel([fortran]) return a 1-d array (copy only if needed)";
1487
array_ravel(PyArrayObject *self, PyObject *args)
1489
PyArray_ORDER fortran=PyArray_CORDER;
1491
if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter,
1492
&fortran)) return NULL;
1494
return PyArray_Ravel(self, fortran);
1497
static char doc_round[] = "a.round(decimals=0)";
1500
array_round(PyArrayObject *self, PyObject *args, PyObject *kwds)
1503
static char *kwlist[] = {"decimals", NULL};
1505
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwlist,
1509
return _ARET(PyArray_Round(self, decimals));
1513
static char doc_setflags[] = "a.setflags(write=None, align=None, uic=None)";
1515
static int _IsAligned(PyArrayObject *);
1516
static Bool _IsWriteable(PyArrayObject *);
1519
array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
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;
1527
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", kwlist,
1528
&write, &align, &uic))
1531
if (align != Py_None) {
1532
if (PyObject_Not(align)) self->flags &= ~ALIGNED;
1533
else if (_IsAligned(self)) self->flags |= ALIGNED;
1535
PyErr_SetString(PyExc_ValueError,
1536
"cannot set aligned flag of mis-"\
1537
"aligned array to True");
1542
if (uic != Py_None) {
1543
if (PyObject_IsTrue(uic)) {
1544
self->flags = flagback;
1545
PyErr_SetString(PyExc_ValueError,
1546
"cannot set UPDATEIFCOPY" \
1551
self->flags &= ~UPDATEIFCOPY;
1552
Py_XDECREF(self->base);
1557
if (write != Py_None) {
1558
if (PyObject_IsTrue(write))
1559
if (_IsWriteable(self)) {
1560
self->flags |= WRITEABLE;
1563
self->flags = flagback;
1564
PyErr_SetString(PyExc_ValueError,
1565
"cannot set WRITEABLE " \
1566
"flag to True of this " \
1571
self->flags &= ~WRITEABLE;
1578
static char doc_newbyteorder[] = "a.newbyteorder(<byteorder>) is equivalent\n" \
1579
" to a.view(a.dtype.newbytorder(<byteorder>))\n";
1582
array_newbyteorder(PyArrayObject *self, PyObject *args)
1584
char endian = PyArray_SWAP;
1587
if (!PyArg_ParseTuple(args, "|O&", PyArray_ByteorderConverter,
1588
&endian)) return NULL;
1590
new = PyArray_DescrNewByteorder(self->descr, endian);
1591
if (!new) return NULL;
1592
return PyArray_View(self, new, NULL);
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},
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},
1619
/* for the copy module */
1620
{"__copy__", (PyCFunction)array_copy, 1, doc_copy},
1621
{"__deepcopy__", (PyCFunction)array_deepcopy, 1, doc_deepcopy},
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},
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 */