diff options
author | Travis Oliphant <oliphant@enthought.com> | 2005-10-07 18:28:56 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2005-10-07 18:28:56 +0000 |
commit | 3f0cd73d77fafad5a41748b288863ab0b37628d8 (patch) | |
tree | da853fd7c68e3c11578dc3fe6a145e3fcdfc6064 /scipy/base/src | |
parent | dfdb8689aaaed931bc8d9d42deec96d0c43a6a79 (diff) | |
download | numpy-3f0cd73d77fafad5a41748b288863ab0b37628d8.tar.gz |
Added some simple CAPI documentation.
Diffstat (limited to 'scipy/base/src')
-rw-r--r-- | scipy/base/src/arraymethods.c | 2 | ||||
-rw-r--r-- | scipy/base/src/arrayobject.c | 54 | ||||
-rw-r--r-- | scipy/base/src/multiarraymodule.c | 38 |
3 files changed, 54 insertions, 40 deletions
diff --git a/scipy/base/src/arraymethods.c b/scipy/base/src/arraymethods.c index aee19fd37..288d3a6d8 100644 --- a/scipy/base/src/arraymethods.c +++ b/scipy/base/src/arraymethods.c @@ -242,7 +242,7 @@ PyArray_GetField(PyArrayObject *self, PyArray_Typecode *type, ret = PyArray_New(self->ob_type, self->nd, self->dimensions, type->type_num, self->strides, self->data + offset, - type->itemsize, self->flags, self); + type->itemsize, self->flags, (PyObject *)self); if (ret == NULL) return NULL; Py_INCREF(self); ((PyArrayObject *)ret)->base = (PyObject *)self; diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c index 41414801a..47d9c5010 100644 --- a/scipy/base/src/arrayobject.c +++ b/scipy/base/src/arrayobject.c @@ -175,8 +175,10 @@ PyArray_GetPriority(PyObject *obj, double default_) PyObject *ret; double priority=PyArray_PRIORITY; - if (PyArray_CheckExact(obj) || PyBigArray_CheckExact(obj)) + if (PyArray_CheckExact(obj)) return priority; + if (PyBigArray_CheckExact(obj)) + return PyArray_BIG_PRIORITY; ret = PyObject_GetAttrString(obj, "__array_priority__"); if (ret != NULL) priority = PyFloat_AsDouble(ret); @@ -437,7 +439,7 @@ contiguous_data(PyArrayObject *src) static PyObject *PyArray_New(PyTypeObject *, int nd, intp *, - int, intp *, char *, int, int, PyArrayObject *); + int, intp *, char *, int, int, PyObject *); /* C-API functions */ @@ -748,7 +750,8 @@ PyArray_FromDimsAndData(int nd, int *d, int type, char *data) type, NULL, data, 0, CARRAY_FLAGS, NULL); #endif - if (type != PyArray_OBJECT) + if (type != PyArray_OBJECT && type != PyArray_OBJECTLTR) + /* already done*/ memset(PyArray_DATA(ret), 0, PyArray_SIZE(ret)); return ret; } @@ -769,7 +772,7 @@ PyArray_FromDims(int nd, int *d, int type) ret = PyArray_New(&PyArray_Type, nd, (intp *)d, type, NULL, NULL, 0, CARRAY_FLAGS, NULL); #endif - if (type != PyArray_OBJECT) + if (type != PyArray_OBJECT && type != PyArray_OBJECTLTR) memset(PyArray_DATA(ret), 0, PyArray_SIZE(ret)); return ret; } @@ -785,7 +788,7 @@ PyArray_Copy(PyArrayObject *m1) m1->dimensions, m1->descr->type_num, NULL, NULL, m1->itemsize, - 0, m1); + 0, (PyObject *)m1); if (PyArray_CopyInto(ret, m1) == -1) return NULL; @@ -921,6 +924,10 @@ PyArray_RegisterDataType(PyTypeObject *type) descr->typeobj = type; userdescrs = realloc(userdescrs, (PyArray_NUMUSERTYPES+1)*sizeof(void *)); + if (userdescrs == NULL) { + PyErr_SetString(PyExc_MemoryError, "RegisterDataType"); + return -1; + } userdescrs[PyArray_NUMUSERTYPES++] = descr; return typenum; } @@ -1221,7 +1228,7 @@ array_item(PyArrayObject *self, int i) self->descr->type_num, self->strides+1, item, self->itemsize, self->flags, - self); + (PyObject *)self); if (r == NULL) return NULL; Py_INCREF(self); r->base = (PyObject *)self; @@ -1550,7 +1557,7 @@ PyArray_GetMap(PyArrayMapIterObject *mit) temp->descr->type_num, NULL, NULL, temp->itemsize, PyArray_ISFORTRAN(temp), - temp); + (PyObject *)temp); if (ret == NULL) return NULL; /* Now just iterate through the new array filling it in @@ -1726,7 +1733,7 @@ array_subscript(PyArrayObject *self, PyObject *op) PyArray_New(self->ob_type, nd, dimensions, self->descr->type_num, strides, self->data+offset, self->itemsize, self->flags, - self)) == NULL) + (PyObject *)self)) == NULL) return NULL; @@ -2571,7 +2578,7 @@ array_slice(PyArrayObject *self, int ilow, int ihigh) r = (PyArrayObject *)\ PyArray_New(self->ob_type, self->nd, self->dimensions, self->descr->type_num, self->strides, data, - self->itemsize, self->flags, self); + self->itemsize, self->flags, (PyObject *)self); self->dimensions[0] = l; r->base = (PyObject *)self; @@ -3130,7 +3137,7 @@ _array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize, static PyObject * PyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num, intp *strides, char *data, int itemsize, int flags, - PyArrayObject *obj) + PyObject *obj) { PyArrayObject *self; PyArray_Descr *descr; @@ -3266,7 +3273,7 @@ PyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num, PyObject *res; res = PyObject_CallMethod((PyObject *)self, "__array_finalize__", - "O", (PyObject *)obj); + "O", obj); if (res == NULL) PyErr_Clear(); else Py_DECREF(res); } @@ -3980,7 +3987,7 @@ array_real_get(PyArrayObject *self) self->strides, self->data, 0, - self->flags, self); + self->flags, (PyObject *)self); if (ret == NULL) return NULL; ret->flags &= ~CONTIGUOUS; ret->flags &= ~FORTRAN; @@ -4014,7 +4021,7 @@ array_real_set(PyArrayObject *self, PyObject *val) self->strides, self->data, 0, - self->flags, self); + self->flags, (PyObject *)self); if (ret == NULL) return -1; ret->flags &= ~CONTIGUOUS; ret->flags &= ~FORTRAN; @@ -4050,7 +4057,7 @@ array_imag_get(PyArrayObject *self) self->strides, self->data + itemsize, 0, - self->flags, self); + self->flags, (PyObject *)self); if (ret == NULL) return NULL; ret->flags &= ~CONTIGUOUS; ret->flags &= ~FORTRAN; @@ -4085,7 +4092,7 @@ array_imag_set(PyArrayObject *self, PyObject *val) (self->itemsize >> 1) , self->data, 0, - self->flags, self); + self->flags, (PyObject *)self); if (ret == NULL) { Py_DECREF(new); return -1; @@ -4856,7 +4863,7 @@ PyArray_CastToType(PyArrayObject *mp, PyArray_Typecode *at) mp->dimensions, at->type_num, NULL, NULL, at->itemsize, - at->fortran, mp); + at->fortran, (PyObject *)mp); if (out == NULL) return NULL; ret = PyArray_CastTo((PyArrayObject *)out, mp); if (ret != -1) return out; @@ -4963,7 +4970,7 @@ array_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags) NULL, NULL, itemsize, flags & FORTRAN, - arr); + (PyObject *)arr); if (PyArray_CopyInto(ret, arr) == -1) return NULL; if (flags & UPDATEIFCOPY) { ret->flags |= UPDATEIFCOPY; @@ -5682,7 +5689,7 @@ iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind) itemsize = self->ao->itemsize; r = PyArray_New(self->ao->ob_type, 1, &count, self->ao->descr->type_num, NULL, NULL, - itemsize, 0, self->ao); + itemsize, 0, (PyObject *)self->ao); if (r==NULL) return NULL; /* Set up loop */ @@ -5729,7 +5736,7 @@ iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind) r = PyArray_New(self->ao->ob_type, ind->nd, ind->dimensions, self->ao->descr->type_num, NULL, NULL, self->ao->itemsize, - 0, self->ao); + 0, (PyObject *)self->ao); if (r==NULL) return NULL; optr = PyArray_DATA(r); @@ -5800,7 +5807,7 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind) r = PyArray_New(self->ao->ob_type, 1, &ii, self->ao->descr->type_num, NULL, NULL, self->ao->itemsize, 0, - self->ao); + (PyObject *)self->ao); return r; } } @@ -5827,7 +5834,7 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind) size = self->ao->itemsize; r = PyArray_New(self->ao->ob_type, 1, &n_steps, self->ao->descr->type_num, NULL, NULL, - size, 0, self->ao); + size, 0, (PyObject *)self->ao); if (r==NULL) goto fail; dptr = PyArray_DATA(r); swap = !PyArray_ISNOTSWAPPED(self->ao); @@ -6122,13 +6129,14 @@ iter_array(PyArrayIterObject *it, PyObject *op) it->ao->descr->type_num, NULL, it->ao->data, it->ao->itemsize, it->ao->flags, - it->ao); + (PyObject *)it->ao); if (r==NULL) return NULL; } else { r = PyArray_New(it->ao->ob_type, 1, &size, it->ao->descr->type_num, - NULL, NULL, it->ao->itemsize, 0, it->ao); + NULL, NULL, it->ao->itemsize, 0, + (PyObject *)it->ao); if (r==NULL) return NULL; if (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) { Py_DECREF(r); diff --git a/scipy/base/src/multiarraymodule.c b/scipy/base/src/multiarraymodule.c index 04b0ff6c6..752ccdd29 100644 --- a/scipy/base/src/multiarraymodule.c +++ b/scipy/base/src/multiarraymodule.c @@ -99,7 +99,7 @@ PyArray_View(PyArrayObject *self, PyArray_Typecode *type) self->strides, self->data, self->itemsize, - self->flags, self); + self->flags, (PyObject *)self); if (new==NULL) return NULL; @@ -163,7 +163,7 @@ PyArray_Flatten(PyArrayObject *a, int fortran) NULL, NULL, a->itemsize, - 0, a); + 0, (PyObject *)a); if (ret== NULL) return NULL; if (fortran) { @@ -275,7 +275,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims) NULL, self->data, self->itemsize, - self->flags, self); + self->flags, (PyObject *)self); if (ret== NULL) goto fail; @@ -322,7 +322,7 @@ PyArray_Squeeze(PyArrayObject *self) ret = PyArray_New(self->ob_type, newnd, dimensions, self->descr->type_num, strides, self->data, self->itemsize, self->flags, - self); + (PyObject *)self); self->flags &= ~OWN_DATA; self->base = (PyObject *)self; Py_INCREF(self); @@ -539,7 +539,7 @@ PyArray_Nonzero(PyArrayObject *self) PyArray_ITER_RESET(it); if (n==1) { ret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, - NULL, NULL, 0, 0, self); + NULL, NULL, 0, 0, (PyObject *)self); if (ret == NULL) goto fail; dptr[0] = (intp *)PyArray_DATA(ret); @@ -554,7 +554,7 @@ PyArray_Nonzero(PyArrayObject *self) for (j=0; j<n; j++) { item = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, NULL, NULL, 0, 0, - self); + (PyObject *)self); PyTuple_SET_ITEM(ret, j, item); if (item == NULL) goto fail; dptr[j] = (intp *)PyArray_DATA(item); @@ -1046,7 +1046,8 @@ PyArray_Concatenate(PyObject *op, int axis) mps[0]->dimensions[0] = new_dim; ret = (PyArrayObject *)PyArray_New(subtype, nd, mps[0]->dimensions, - type_num, NULL, NULL, 0, 0, ret); + type_num, NULL, NULL, 0, 0, + (PyObject *)ret); mps[0]->dimensions[0] = tmp; if (ret == NULL) goto fail; @@ -1149,7 +1150,7 @@ PyArray_Transpose(PyArrayObject *ap, PyObject *op) { ret = (PyArrayObject *)PyArray_New(ap->ob_type, n, permutation, ap->descr->type_num, NULL, ap->data, ap->itemsize, ap->flags, - ap); + (PyObject *)ap); if (ret == NULL) goto fail; /* point at true owner of memory: */ @@ -1231,7 +1232,7 @@ PyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis) { aop->dimensions, aop->descr->type_num, NULL, NULL, aop->itemsize, 0, - aop); + (PyObject *)aop); aop->dimensions[axis] = n; if (ret == NULL) goto fail; @@ -1348,7 +1349,7 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op) { */ ret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd, ap->dimensions, type_num, - NULL, NULL, 0, 0, ap); + NULL, NULL, 0, 0, (PyObject *)ap); if (ret == NULL) goto fail; elsize = ret->itemsize; @@ -1504,7 +1505,7 @@ PyArray_ArgSort(PyArrayObject *op, int axis) ret = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd, ap->dimensions, PyArray_INTP, - NULL, NULL, 0, 0, ap); + NULL, NULL, 0, 0, (PyObject *)ap); if (ret == NULL) goto fail; if (ap->descr->compare == NULL) { @@ -1608,7 +1609,7 @@ PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) ret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, ap2->dimensions, PyArray_INTP, - NULL, NULL, 0, 0, ap2); + NULL, NULL, 0, 0, (PyObject *)ap2); if (ret == NULL) goto fail; if (ap2->descr->compare == NULL) { @@ -1700,6 +1701,7 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, typenum, NULL, NULL, 0, 0, + (PyObject *) (prior2 > prior1 ? ap2 : ap1)); if (ret == NULL) goto fail; @@ -1822,6 +1824,7 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, typenum, NULL, NULL, 0, 0, + (PyObject *) (prior2 > prior1 ? ap2 : ap1)); if (ret == NULL) goto fail; @@ -1898,7 +1901,7 @@ PyArray_CopyAndTranspose(PyObject *op) elsize = PyArray_ITEMSIZE(arr); ret = PyArray_New(arr->ob_type, 2, dims, PyArray_TYPE(arr), - NULL, NULL, elsize, 0, (PyArrayObject *)arr); + NULL, NULL, elsize, 0, arr); if (ret == NULL) { Py_DECREF(arr); @@ -1973,7 +1976,8 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) ret = (PyArrayObject *)PyArray_New(ap1->ob_type, 1, &length, typenum, - NULL, NULL, 0, 0, ap1); + NULL, NULL, 0, 0, + (PyObject *)ap1); if (ret == NULL) goto fail; @@ -2130,7 +2134,8 @@ PyArray_ArgMax(PyArrayObject *op, int axis) rp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1, ap->dimensions, PyArray_INTP, - NULL, NULL, 0, 0, ap); + NULL, NULL, 0, 0, + (PyObject *)ap); if (rp == NULL) goto fail; @@ -2195,7 +2200,8 @@ PyArray_Take(PyArrayObject *self0, PyObject *indices0, int axis) { } ret = (PyArrayObject *)PyArray_New(self->ob_type, nd, shape, self->descr->type_num, - NULL, NULL, 0, 0, self); + NULL, NULL, 0, 0, + (PyObject *)self); if (ret == NULL) goto fail; |