summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMark Wiebe <mwwiebe@gmail.com>2011-07-15 01:35:39 -0500
committerMark Wiebe <mwiebe@enthought.com>2011-07-19 14:00:27 -0500
commit2bb06a5cc043943ba4147b3ddeb5fd8835310200 (patch)
treeab4b0e2d4f6c77cff1a543da69e4a69271d4cda8 /numpy
parent4dce9c07eaa7756c9a6d552ac316137c83e92809 (diff)
downloadnumpy-2bb06a5cc043943ba4147b3ddeb5fd8835310200.tar.gz
ENH: core: Progress getting NumPy building without direct field access
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h20
-rw-r--r--numpy/core/include/numpy/npy_deprecated_api.h6
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src12
-rw-r--r--numpy/core/src/multiarray/ctors.c86
-rw-r--r--numpy/core/src/multiarray/iterators.c185
-rw-r--r--numpy/core/src/multiarray/multiarray_tests.c.src1
-rw-r--r--numpy/core/src/multiarray/nditer_api.c6
-rw-r--r--numpy/core/src/multiarray/shape.c7
-rw-r--r--numpy/core/src/umath/ufunc_object.c26
-rw-r--r--numpy/numarray/_capi.c32
10 files changed, 218 insertions, 163 deletions
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index 0e83e2d14..3ac3954e4 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -620,6 +620,7 @@ typedef struct tagPyArrayObject {
PyObject_HEAD
} PyArrayObject;
#else
+/* Can't put this in npy_deprecated_api.h like the others */
typedef PyArrayObject_fieldaccess PyArrayObject;
#endif
@@ -1328,6 +1329,25 @@ PyArray_CHKFLAGS(PyArrayObject *arr, int flags)
return (PyArray_FLAGS(arr) & flags) == flags;
}
+/*
+ * Enables the specified array flags. Does no checking,
+ * assumes you know what you're doing.
+ */
+static NPY_INLINE void
+PyArray_ENABLEFLAGS(PyArrayObject *arr, int flags)
+{
+ ((PyArrayObject_fieldaccess *)arr)->flags |= ~flags;
+}
+
+/*
+ * Clears the specified array flags. Does no checking,
+ * assumes you know what you're doing.
+ */
+static NPY_INLINE void
+PyArray_CLEARFLAGS(PyArrayObject *arr, int flags)
+{
+ ((PyArrayObject_fieldaccess *)arr)->flags &= ~flags;
+}
static NPY_INLINE npy_intp
PyArray_ITEMSIZE(PyArrayObject *arr)
diff --git a/numpy/core/include/numpy/npy_deprecated_api.h b/numpy/core/include/numpy/npy_deprecated_api.h
index 6002181d6..413d24d4e 100644
--- a/numpy/core/include/numpy/npy_deprecated_api.h
+++ b/numpy/core/include/numpy/npy_deprecated_api.h
@@ -89,10 +89,4 @@
*/
#define fortran fortran_
-/*
- * Direct access to PyArrayObject fields is deprecated as of NumPy 1.7,
- * but enabled here through this typedef.
- */
-typedef PyArrayObject_fieldaccess PyArrayObject;
-
#endif
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index db1c5516f..2ce16b01a 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -578,10 +578,10 @@ VOID_getitem(char *ip, PyArrayObject *ap)
/* update alignment based on offset */
if ((new->alignment > 1)
&& ((((intp)(ip+offset)) % new->alignment) != 0)) {
- ((PyArrayObject_fieldaccess *)ap)->flags &= ~NPY_ARRAY_ALIGNED;
+ PyArray_CLEARFLAGS(ap, NPY_ARRAY_ALIGNED);
}
else {
- ((PyArrayObject_fieldaccess *)ap)->flags |= NPY_ARRAY_ALIGNED;
+ PyArray_ENABLEFLAGS(ap, NPY_ARRAY_ALIGNED);
}
PyTuple_SET_ITEM(ret, i, new->f->getitem(ip+offset, ap));
((PyArrayObject_fieldaccess *)ap)->flags = savedflags;
@@ -708,10 +708,10 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)
/* remember to update alignment flags */
if ((new->alignment > 1)
&& ((((intp)(ip+offset)) % new->alignment) != 0)) {
- ((PyArrayObject_fieldaccess *)ap)->flags &= ~NPY_ARRAY_ALIGNED;
+ PyArray_CLEARFLAGS(ap, NPY_ARRAY_ALIGNED);
}
else {
- ((PyArrayObject_fieldaccess *)ap)->flags |= NPY_ARRAY_ALIGNED;
+ PyArray_ENABLEFLAGS(ap, NPY_ARRAY_ALIGNED);
}
res = new->f->setitem(PyTuple_GET_ITEM(op, i), ip+offset, ap);
((PyArrayObject_fieldaccess *)ap)->flags = savedflags;
@@ -2222,10 +2222,10 @@ VOID_nonzero (char *ip, PyArrayObject *ap)
((PyArrayObject_fieldaccess *)ap)->descr = descr;
((PyArrayObject_fieldaccess *)ap)->flags = savedflags;
if ((new->alignment > 1) && !__ALIGNED(ip+offset, new->alignment)) {
- ((PyArrayObject_fieldaccess *)ap)->flags &= ~NPY_ARRAY_ALIGNED;
+ PyArray_CLEARFLAGS(ap, NPY_ARRAY_ALIGNED);
}
else {
- ((PyArrayObject_fieldaccess *)ap)->flags |= NPY_ARRAY_ALIGNED;
+ PyArray_ENABLEFLAGS(ap, NPY_ARRAY_ALIGNED);
}
if (new->f->nonzero(ip+offset, ap)) {
nonz = TRUE;
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 944d8125e..bcfa19ca9 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1030,7 +1030,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
npy_intp *dims, npy_intp *strides, void *data,
int flags, PyObject *obj)
{
- PyArrayObject *self;
+ PyArrayObject_fieldaccess *self;
int i;
size_t sd;
npy_intp largest;
@@ -1118,7 +1118,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
largest /= dim;
}
- self = (PyArrayObject *) subtype->tp_alloc(subtype, 0);
+ self = (PyArrayObject_fieldaccess *) subtype->tp_alloc(subtype, 0);
if (self == NULL) {
Py_DECREF(descr);
return NULL;
@@ -2063,15 +2063,13 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
return NULL;
}
if (flags & NPY_ARRAY_UPDATEIFCOPY) {
- ((PyArrayObject_fieldaccess *)ret)->flags |=
- NPY_ARRAY_UPDATEIFCOPY;
+ Py_INCREF(arr);
if (PyArray_SetBase(ret, (PyObject *)arr) < 0) {
Py_DECREF(ret);
return NULL;
}
- ((PyArrayObject_fieldaccess *)ret->base)->flags &=
- ~NPY_ARRAY_WRITEABLE;
- Py_INCREF(arr);
+ PyArray_ENABLEFLAGS(ret, NPY_ARRAY_UPDATEIFCOPY);
+ PyArray_CLEARFLAGS(arr, NPY_ARRAY_WRITEABLE);
}
}
/*
@@ -2136,11 +2134,13 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
return NULL;
}
if (flags & NPY_ARRAY_UPDATEIFCOPY) {
- ret->flags |= NPY_ARRAY_UPDATEIFCOPY;
- ret->base = (PyObject *)arr;
- ((PyArrayObject_fieldaccess *)ret->base)->flags &=
- ~NPY_ARRAY_WRITEABLE;
Py_INCREF(arr);
+ if (PyArray_SetBase(ret, (PyObject *)arr) < 0) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ PyArray_ENABLEFLAGS(ret, NPY_ARRAY_UPDATEIFCOPY);
+ PyArray_CLEARFLAGS(arr, NPY_ARRAY_WRITEABLE);
}
}
return (PyObject *)ret;
@@ -2153,7 +2153,8 @@ PyArray_FromStructInterface(PyObject *input)
PyArray_Descr *thetype = NULL;
char buf[40];
PyArrayInterface *inter;
- PyObject *attr, *r;
+ PyObject *attr;
+ PyArrayObject *ret;
char endian = PyArray_NATBYTE;
attr = PyObject_GetAttrString(input, "__array_struct__");
@@ -2189,18 +2190,18 @@ PyArray_FromStructInterface(PyObject *input)
}
}
- r = PyArray_NewFromDescr(&PyArray_Type, thetype,
+ ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, thetype,
inter->nd, inter->shape,
inter->strides, inter->data,
inter->flags, NULL);
Py_INCREF(input);
- if (PyArray_SetBase(r, input) < 0) {
- Py_DECREF(r);
+ if (PyArray_SetBase(ret, input) < 0) {
+ Py_DECREF(ret);
return NULL;
}
Py_DECREF(attr);
- PyArray_UpdateFlags((PyArrayObject *)r, NPY_ARRAY_UPDATE_ALL);
- return r;
+ PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL);
+ return (PyObject *)ret;
fail:
PyErr_SetString(PyExc_ValueError, "invalid __array_struct__");
@@ -2497,13 +2498,13 @@ PyArray_FromDimsAndDataAndDescr(int nd, int *d,
NPY_NO_EXPORT PyObject *
PyArray_FromDims(int nd, int *d, int type)
{
- PyObject *ret;
+ PyArrayObject *ret;
char msg[] = "PyArray_FromDims: use PyArray_SimpleNew.";
if (DEPRECATE(msg) < 0) {
return NULL;
}
- ret = PyArray_FromDimsAndDataAndDescr(nd, d,
+ ret = (PyArrayObject *)PyArray_FromDimsAndDataAndDescr(nd, d,
PyArray_DescrFromType(type),
NULL);
/*
@@ -2511,10 +2512,10 @@ PyArray_FromDims(int nd, int *d, int type)
* relied on that. Better keep it the same. If
* Object type, then it's already been set to zero, though.
*/
- if (ret && (PyArray_DESCR(ret)->type_num != PyArray_OBJECT)) {
+ if (ret && (PyArray_DESCR(ret)->type_num != NPY_OBJECT)) {
memset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));
}
- return ret;
+ return (PyObject *)ret;
}
/* end old calls */
@@ -3286,7 +3287,7 @@ NPY_NO_EXPORT PyObject *
PyArray_Arange(double start, double stop, double step, int type_num)
{
npy_intp length;
- PyObject *range;
+ PyArrayObject *range;
PyArray_ArrFuncs *funcs;
PyObject *obj;
int ret;
@@ -3301,7 +3302,7 @@ PyArray_Arange(double start, double stop, double step, int type_num)
return PyArray_New(&PyArray_Type, 1, &length, type_num,
NULL, NULL, 0, 0, NULL);
}
- range = PyArray_New(&PyArray_Type, 1, &length, type_num,
+ range = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &length, type_num,
NULL, NULL, 0, 0, NULL);
if (range == NULL) {
return NULL;
@@ -3313,34 +3314,34 @@ PyArray_Arange(double start, double stop, double step, int type_num)
* if length > 2, then call the inner loop, otherwise stop
*/
obj = PyFloat_FromDouble(start);
- ret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);
+ ret = funcs->setitem(obj, PyArray_DATA(range), range);
Py_DECREF(obj);
if (ret < 0) {
goto fail;
}
if (length == 1) {
- return range;
+ return (PyObject *)range;
}
obj = PyFloat_FromDouble(start + step);
ret = funcs->setitem(obj, PyArray_BYTES(range)+PyArray_ITEMSIZE(range),
- (PyArrayObject *)range);
+ range);
Py_DECREF(obj);
if (ret < 0) {
goto fail;
}
if (length == 2) {
- return range;
+ return (PyObject *)range;
}
if (!funcs->fill) {
PyErr_SetString(PyExc_ValueError, "no fill-function for data-type.");
Py_DECREF(range);
return NULL;
}
- funcs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);
+ funcs->fill(PyArray_DATA(range), length, range);
if (PyErr_Occurred()) {
goto fail;
}
- return range;
+ return (PyObject *)range;
fail:
Py_DECREF(range);
@@ -3427,7 +3428,7 @@ _calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, i
NPY_NO_EXPORT PyObject *
PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype)
{
- PyObject *range;
+ PyArrayObject *range;
PyArray_ArrFuncs *funcs;
PyObject *next, *err;
npy_intp length;
@@ -3492,10 +3493,10 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr
}
if (length <= 0) {
length = 0;
- range = PyArray_SimpleNewFromDescr(1, &length, dtype);
+ range = (PyArrayObject *)PyArray_SimpleNewFromDescr(1, &length, dtype);
Py_DECREF(step);
Py_DECREF(start);
- return range;
+ return (PyObject *)range;
}
/*
@@ -3511,7 +3512,7 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr
swap = 0;
}
- range = PyArray_SimpleNewFromDescr(1, &length, native);
+ range = (PyArrayObject *)PyArray_SimpleNewFromDescr(1, &length, native);
if (range == NULL) {
goto fail;
}
@@ -3521,15 +3522,14 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr
* if length > 2, then call the inner loop, otherwise stop
*/
funcs = PyArray_DESCR(range)->f;
- if (funcs->setitem(
- start, PyArray_DATA(range), (PyArrayObject *)range) < 0) {
+ if (funcs->setitem(start, PyArray_DATA(range), range) < 0) {
goto fail;
}
if (length == 1) {
goto finish;
}
if (funcs->setitem(next, PyArray_BYTES(range)+PyArray_ITEMSIZE(range),
- (PyArrayObject *)range) < 0) {
+ range) < 0) {
goto fail;
}
if (length == 2) {
@@ -3540,22 +3540,24 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr
Py_DECREF(range);
goto fail;
}
- funcs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);
+ funcs->fill(PyArray_DATA(range), length, range);
if (PyErr_Occurred()) {
goto fail;
}
finish:
+ /* TODO: This swapping could be handled on the fly by the nditer */
if (swap) {
PyObject *new;
- new = PyArray_Byteswap((PyArrayObject *)range, 1);
+ new = PyArray_Byteswap(range, 1);
Py_DECREF(new);
Py_DECREF(PyArray_DESCR(range));
- PyArray_DESCR(range) = dtype; /* steals the reference */
+ /* steals the reference */
+ ((PyArrayObject_fieldaccess *)range)->descr = dtype;
}
Py_DECREF(start);
Py_DECREF(step);
Py_DECREF(next);
- return range;
+ return (PyObject *)range;
fail:
Py_DECREF(start);
@@ -3689,7 +3691,7 @@ array_from_text(PyArray_Descr *dtype, npy_intp num, char *sep, size_t *nread,
err = 1;
}
else {
- PyArray_DIM(r,0) = *nread;
+ PyArray_DIMS(r)[0] = *nread;
r->data = tmp;
}
}
@@ -3771,7 +3773,7 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, npy_intp num, char *sep)
return PyErr_NoMemory();
}
ret->data = tmp;
- PyArray_DIM(ret,0) = nread;
+ PyArray_DIMS(ret)[0] = nread;
}
return (PyObject *)ret;
}
diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c
index 3618febf2..1f237640f 100644
--- a/numpy/core/src/multiarray/iterators.c
+++ b/numpy/core/src/multiarray/iterators.c
@@ -441,28 +441,37 @@ PyArray_BroadcastToShape(PyObject *obj, npy_intp *dims, int nd)
NPY_NO_EXPORT PyObject *
PyArray_IterAllButAxis(PyObject *obj, int *inaxis)
{
+ PyArrayObject *arr;
PyArrayIterObject *it;
int axis;
- it = (PyArrayIterObject *)PyArray_IterNew(obj);
+
+ if (!PyArray_Check(obj)) {
+ PyErr_SetString(PyExc_ValueError,
+ "Numpy IterAllButAxis requires an ndarray");
+ return NULL;
+ }
+ arr = (PyArrayObject *)obj;
+
+ it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);
if (it == NULL) {
return NULL;
}
- if (PyArray_NDIM(obj)==0) {
+ if (PyArray_NDIM(arr)==0) {
return (PyObject *)it;
}
if (*inaxis < 0) {
int i, minaxis = 0;
npy_intp minstride = 0;
i = 0;
- while (minstride == 0 && i < PyArray_NDIM(obj)) {
- minstride = PyArray_STRIDE(obj,i);
+ while (minstride == 0 && i < PyArray_NDIM(arr)) {
+ minstride = PyArray_STRIDE(arr,i);
i++;
}
- for (i = 1; i < PyArray_NDIM(obj); i++) {
- if (PyArray_STRIDE(obj,i) > 0 &&
- PyArray_STRIDE(obj, i) < minstride) {
+ for (i = 1; i < PyArray_NDIM(arr); i++) {
+ if (PyArray_STRIDE(arr,i) > 0 &&
+ PyArray_STRIDE(arr, i) < minstride) {
minaxis = i;
- minstride = PyArray_STRIDE(obj,i);
+ minstride = PyArray_STRIDE(arr,i);
}
}
*inaxis = minaxis;
@@ -471,7 +480,7 @@ PyArray_IterAllButAxis(PyObject *obj, int *inaxis)
/* adjust so that will not iterate over axis */
it->contiguous = 0;
if (it->size != 0) {
- it->size /= PyArray_DIM(obj,axis);
+ it->size /= PyArray_DIM(arr,axis);
}
it->dims_m1[axis] = 0;
it->backstrides[axis] = 0;
@@ -560,14 +569,14 @@ iter_length(PyArrayIterObject *self)
}
-static PyObject *
+static PyArrayObject *
iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)
{
npy_intp index, strides;
int itemsize;
npy_intp count = 0;
char *dptr, *optr;
- PyObject *r;
+ PyArrayObject *ret;
int swap;
PyArray_CopySwapFunc *copyswap;
@@ -593,22 +602,22 @@ iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)
}
dptr += strides;
}
- itemsize = self->ao->descr->elsize;
- Py_INCREF(self->ao->descr);
- r = PyArray_NewFromDescr(Py_TYPE(self->ao),
- self->ao->descr, 1, &count,
+ itemsize = PyArray_DESCR(self->ao)->elsize;
+ Py_INCREF(PyArray_DESCR(self->ao));
+ ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self->ao),
+ PyArray_DESCR(self->ao), 1, &count,
NULL, NULL,
0, (PyObject *)self->ao);
- if (r == NULL) {
+ if (ret == NULL) {
return NULL;
}
/* Set up loop */
- optr = PyArray_DATA(r);
+ optr = PyArray_DATA(ret);
index = ind->dimensions[0];
dptr = ind->data;
- copyswap = self->ao->descr->f->copyswap;
+ copyswap = PyArray_DESCR(self->ao)->f->copyswap;
/* Loop over Boolean array */
- swap = (PyArray_ISNOTSWAPPED(self->ao) != PyArray_ISNOTSWAPPED(r));
+ swap = (PyArray_ISNOTSWAPPED(self->ao) != PyArray_ISNOTSWAPPED(ret));
while (index--) {
if (*((Bool *)dptr) != 0) {
copyswap(optr, self->dataptr, swap, self->ao);
@@ -618,14 +627,14 @@ iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)
PyArray_ITER_NEXT(self);
}
PyArray_ITER_RESET(self);
- return r;
+ return ret;
}
static PyObject *
iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
{
npy_intp num;
- PyObject *r;
+ PyArrayObject *ret;
PyArrayIterObject *ind_it;
int itemsize;
int swap;
@@ -633,7 +642,7 @@ iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
npy_intp index;
PyArray_CopySwapFunc *copyswap;
- itemsize = self->ao->descr->elsize;
+ itemsize = PyArray_DESCR(self->ao)->elsize;
if (ind->nd == 0) {
num = *((npy_intp *)ind->data);
if (num < 0) {
@@ -644,33 +653,37 @@ iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
"index %"INTP_FMT" out of bounds" \
" 0<=index<%"INTP_FMT,
num, self->size);
- r = NULL;
+ PyArray_ITER_RESET(self);
+ return NULL;
}
else {
+ PyObject *tmp;
PyArray_ITER_GOTO1D(self, num);
- r = PyArray_ToScalar(self->dataptr, self->ao);
+ tmp = PyArray_ToScalar(self->dataptr, self->ao);
+ PyArray_ITER_RESET(self);
+ return tmp;
}
- PyArray_ITER_RESET(self);
- return r;
}
- Py_INCREF(self->ao->descr);
- r = PyArray_NewFromDescr(Py_TYPE(self->ao), self->ao->descr,
- ind->nd, ind->dimensions,
+ Py_INCREF(PyArray_DESCR(self->ao));
+ ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self->ao),
+ PyArray_DESCR(self->ao),
+ ind->nd,
+ ind->dimensions,
NULL, NULL,
0, (PyObject *)self->ao);
- if (r == NULL) {
+ if (ret == NULL) {
return NULL;
}
- optr = PyArray_DATA(r);
+ optr = PyArray_DATA(ret);
ind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);
if (ind_it == NULL) {
- Py_DECREF(r);
+ Py_DECREF(ret);
return NULL;
}
index = ind_it->size;
- copyswap = PyArray_DESCR(r)->f->copyswap;
- swap = (PyArray_ISNOTSWAPPED(r) != PyArray_ISNOTSWAPPED(self->ao));
+ copyswap = PyArray_DESCR(ret)->f->copyswap;
+ swap = (PyArray_ISNOTSWAPPED(ret) != PyArray_ISNOTSWAPPED(self->ao));
while (index--) {
num = *((npy_intp *)(ind_it->dataptr));
if (num < 0) {
@@ -682,18 +695,18 @@ iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
" 0<=index<%"INTP_FMT,
num, self->size);
Py_DECREF(ind_it);
- Py_DECREF(r);
+ Py_DECREF(ret);
PyArray_ITER_RESET(self);
return NULL;
}
PyArray_ITER_GOTO1D(self, num);
- copyswap(optr, self->dataptr, swap, r);
+ copyswap(optr, self->dataptr, swap, ret);
optr += itemsize;
PyArray_ITER_NEXT(ind_it);
}
Py_DECREF(ind_it);
PyArray_ITER_RESET(self);
- return r;
+ return (PyObject *)ret;
}
/* Always returns arrays */
@@ -701,9 +714,10 @@ NPY_NO_EXPORT PyObject *
iter_subscript(PyArrayIterObject *self, PyObject *ind)
{
PyArray_Descr *indtype = NULL;
+ PyArray_Descr *dtype;
npy_intp start, step_size;
npy_intp n_steps;
- PyObject *r;
+ PyArrayObject *ret;
char *dptr;
int size;
PyObject *obj = NULL;
@@ -731,7 +745,7 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
/*
* Tuples >1d not accepted --- i.e. no newaxis
* Could implement this with adjusted strides and dimensions in iterator
- * Check for Boolean -- this is first becasue Bool is a subclass of Int
+ * Check for Boolean -- this is first because Bool is a subclass of Int
*/
PyArray_ITER_RESET(self);
@@ -741,13 +755,14 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
}
else { /* empty array */
npy_intp ii = 0;
- Py_INCREF(self->ao->descr);
- r = PyArray_NewFromDescr(Py_TYPE(self->ao),
- self->ao->descr,
+ dtype = PyArray_DESCR(self->ao);
+ Py_INCREF(dtype);
+ ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self->ao),
+ dtype,
1, &ii,
NULL, NULL, 0,
(PyObject *)self->ao);
- return r;
+ return (PyObject *)ret;
}
}
@@ -765,30 +780,32 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
}
PyArray_ITER_GOTO1D(self, start)
if (n_steps == SingleIndex) { /* Integer */
- r = PyArray_ToScalar(self->dataptr, self->ao);
+ PyObject *tmp;
+ tmp = PyArray_ToScalar(self->dataptr, self->ao);
PyArray_ITER_RESET(self);
- return r;
+ return tmp;
}
size = self->ao->descr->elsize;
- Py_INCREF(self->ao->descr);
- r = PyArray_NewFromDescr(Py_TYPE(self->ao),
- self->ao->descr,
+ dtype = PyArray_DESCR(self->ao);
+ Py_INCREF(dtype);
+ ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self->ao),
+ dtype,
1, &n_steps,
NULL, NULL,
0, (PyObject *)self->ao);
- if (r == NULL) {
+ if (ret == NULL) {
goto fail;
}
- dptr = PyArray_DATA(r);
- copyswap = PyArray_DESCR(r)->f->copyswap;
+ dptr = PyArray_DATA(ret);
+ copyswap = PyArray_DESCR(ret)->f->copyswap;
while (n_steps--) {
- copyswap(dptr, self->dataptr, 0, r);
+ copyswap(dptr, self->dataptr, 0, ret);
start += step_size;
PyArray_ITER_GOTO1D(self, start)
dptr += size;
}
PyArray_ITER_RESET(self);
- return r;
+ return (PyObject *)ret;
}
/* convert to INTP array if Integer array scalar or List */
@@ -807,12 +824,12 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
if (PyArray_Check(obj)) {
/* Check for Boolean object */
- if (PyArray_TYPE(obj)==PyArray_BOOL) {
- r = iter_subscript_Bool(self, (PyArrayObject *)obj);
+ if (PyArray_TYPE((PyArrayObject *)obj) == NPY_BOOL) {
+ ret = iter_subscript_Bool(self, (PyArrayObject *)obj);
Py_DECREF(indtype);
}
/* Check for integer array */
- else if (PyArray_ISINTEGER(obj)) {
+ else if (PyArray_ISINTEGER((PyArrayObject *)obj)) {
PyObject *new;
new = PyArray_FromAny(obj, indtype, 0, 0,
NPY_ARRAY_FORCECAST | NPY_ARRAY_ALIGNED, NULL);
@@ -821,13 +838,15 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
}
Py_DECREF(obj);
obj = new;
- r = iter_subscript_int(self, (PyArrayObject *)obj);
+ new = iter_subscript_int(self, (PyArrayObject *)obj);
+ Py_DECREF(obj);
+ return new;
}
else {
goto fail;
}
Py_DECREF(obj);
- return r;
+ return (PyObject *)ret;
}
else {
Py_DECREF(indtype);
@@ -935,7 +954,7 @@ iter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,
NPY_NO_EXPORT int
iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)
{
- PyObject *arrval = NULL;
+ PyArrayObject *arrval = NULL;
PyArrayIterObject *val_it = NULL;
PyArray_Descr *type;
PyArray_Descr *indtype = NULL;
@@ -1003,11 +1022,11 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)
skip:
Py_INCREF(type);
- arrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);
+ arrval = (PyArrayObject *)PyArray_FromAny(val, type, 0, 0, 0, NULL);
if (arrval == NULL) {
return -1;
}
- val_it = (PyArrayIterObject *)PyArray_IterNew(arrval);
+ val_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arrval);
if (val_it == NULL) {
goto finish;
}
@@ -1065,7 +1084,7 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)
if (obj != NULL && PyArray_Check(obj)) {
/* Check for Boolean object */
- if (PyArray_TYPE(obj)==PyArray_BOOL) {
+ if (PyArray_TYPE((PyArrayObject *)obj)==PyArray_BOOL) {
if (iter_ass_sub_Bool(self, (PyArrayObject *)obj,
val_it, swap) < 0) {
goto finish;
@@ -1073,7 +1092,7 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)
retval=0;
}
/* Check for integer array */
- else if (PyArray_ISINTEGER(obj)) {
+ else if (PyArray_ISINTEGER((PyArrayObject *)obj)) {
PyObject *new;
Py_INCREF(indtype);
new = PyArray_CheckFromAny(obj, indtype, 0, 0,
@@ -1116,11 +1135,11 @@ static PyMappingMethods iter_as_mapping = {
-static PyObject *
+static PyArrayObject *
iter_array(PyArrayIterObject *it, PyObject *NPY_UNUSED(op))
{
- PyObject *r;
+ PyArrayObject *ret;
npy_intp size;
/* Any argument ignored */
@@ -1135,35 +1154,43 @@ iter_array(PyArrayIterObject *it, PyObject *NPY_UNUSED(op))
size = PyArray_SIZE(it->ao);
Py_INCREF(it->ao->descr);
if (PyArray_ISCONTIGUOUS(it->ao)) {
- r = PyArray_NewFromDescr(&PyArray_Type,
- it->ao->descr,
+ ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type,
+ PyArray_DESCR(it->ao),
1, &size,
- NULL, it->ao->data,
- it->ao->flags,
+ NULL, PyArray_DATA(it->ao),
+ PyArray_FLAGS(it->ao),
(PyObject *)it->ao);
- if (r == NULL) {
+ if (ret == NULL) {
+ return NULL;
+ }
+ Py_INCREF(it->ao);
+ if (PyArray_SetBase(ret, (PyObject *)it->ao) < 0) {
+ Py_DECREF(ret);
return NULL;
}
}
else {
- r = PyArray_NewFromDescr(&PyArray_Type,
+ ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type,
it->ao->descr,
1, &size,
NULL, NULL,
0, (PyObject *)it->ao);
- if (r == NULL) {
+ if (ret == NULL) {
return NULL;
}
- if (PyArray_CopyAnyInto((PyArrayObject *)r, it->ao) < 0) {
- Py_DECREF(r);
+ if (PyArray_CopyAnyInto(ret, it->ao) < 0) {
+ Py_DECREF(ret);
return NULL;
}
- PyArray_FLAGS(r) |= NPY_ARRAY_UPDATEIFCOPY;
- it->ao->flags &= ~NPY_ARRAY_WRITEABLE;
+ Py_INCREF(it->ao);
+ if (PyArray_SetBase(ret, (PyObject *)it->ao) < 0) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ PyArray_ENABLEFLAGS(ret, NPY_ARRAY_UPDATEIFCOPY);
+ PyArray_CLEARFLAGS(it->ao, NPY_ARRAY_WRITEABLE);
}
- Py_INCREF(it->ao);
- PyArray_BASE(r) = (PyObject *)it->ao;
- return r;
+ return ret;
}
diff --git a/numpy/core/src/multiarray/multiarray_tests.c.src b/numpy/core/src/multiarray/multiarray_tests.c.src
index d6340025c..aeb57f63a 100644
--- a/numpy/core/src/multiarray/multiarray_tests.c.src
+++ b/numpy/core/src/multiarray/multiarray_tests.c.src
@@ -1,3 +1,4 @@
+#define NPY_NO_DEPRECATED_API
#include <Python.h>
#include "numpy/ndarrayobject.h"
diff --git a/numpy/core/src/multiarray/nditer_api.c b/numpy/core/src/multiarray/nditer_api.c
index 4eda968db..0518e4379 100644
--- a/numpy/core/src/multiarray/nditer_api.c
+++ b/numpy/core/src/multiarray/nditer_api.c
@@ -1864,7 +1864,7 @@ npyiter_copy_from_buffers(NpyIter *iter)
(int)iop, (int)op_transfersize);
if (op_itflags[iop] & NPY_OP_ITFLAG_WRITEMASKED) {
- npy_uint8 *maskptr;
+ npy_mask *maskptr;
/*
* The mask pointer may be in the buffer or in
@@ -1873,10 +1873,10 @@ npyiter_copy_from_buffers(NpyIter *iter)
delta = (ptrs[maskop] - buffers[maskop]);
if (0 <= delta &&
delta <= buffersize*dtypes[maskop]->elsize) {
- maskptr = buffers[maskop];
+ maskptr = (npy_mask *)buffers[maskop];
}
else {
- maskptr = ad_ptrs[maskop];
+ maskptr = (npy_mask *)ad_ptrs[maskop];
}
PyArray_TransferMaskedStridedToNDim(ndim_transfer,
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c
index 14d345d5a..1462bcbef 100644
--- a/numpy/core/src/multiarray/shape.c
+++ b/numpy/core/src/multiarray/shape.c
@@ -623,9 +623,12 @@ PyArray_Squeeze(PyArrayObject *self)
if (ret == NULL) {
return NULL;
}
- ((PyArrayObject_fieldaccess *)ret)->flags &= ~NPY_ARRAY_OWNDATA;
+ PyArray_CLEARFLAGS(ret, NPY_ARRAY_OWNDATA);
Py_INCREF(self);
- PyArray_SetBase(ret, (PyObject *)self);
+ if (PyArray_SetBase(ret, (PyObject *)self) < 0) {
+ Py_DECREF(ret);
+ return NULL;
+ }
return (PyObject *)ret;
}
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 2ffca63d2..570f45b88 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -798,7 +798,7 @@ static int get_ufunc_arguments(PyUFuncObject *self,
}
/* If it's an array, can use it */
if (PyArray_Check(obj)) {
- if (!PyArray_ISWRITEABLE(obj)) {
+ if (!PyArray_ISWRITEABLE((PyArrayObject *)obj)) {
PyErr_SetString(PyExc_ValueError,
"return array is not writeable");
return -1;
@@ -890,7 +890,7 @@ static int get_ufunc_arguments(PyUFuncObject *self,
}
if (PyArray_Check(value)) {
- if (!PyArray_ISWRITEABLE(value)) {
+ if (!PyArray_ISWRITEABLE((PyArrayObject *)value)) {
PyErr_SetString(PyExc_ValueError,
"return array is not writeable");
goto fail;
@@ -1116,6 +1116,7 @@ prepare_ufunc_output(PyUFuncObject *self,
{
if (arr_prep != NULL && arr_prep != Py_None) {
PyObject *res;
+ PyArrayObject *arr;
res = PyObject_CallFunction(arr_prep, "O(OOi)",
*op, self, arr_prep_args, i);
@@ -1128,32 +1129,33 @@ prepare_ufunc_output(PyUFuncObject *self,
Py_XDECREF(res);
return -1;
}
+ arr = (PyArrayObject *)res;
/* If the same object was returned, nothing to do */
- if (res == (PyObject *)*op) {
- Py_DECREF(res);
+ if (arr == *op) {
+ Py_DECREF(arr);
}
/* If the result doesn't match, throw an error */
- else if (PyArray_NDIM(res) != PyArray_NDIM(*op) ||
- !PyArray_CompareLists(PyArray_DIMS(res),
+ else if (PyArray_NDIM(arr) != PyArray_NDIM(*op) ||
+ !PyArray_CompareLists(PyArray_DIMS(arr),
PyArray_DIMS(*op),
- PyArray_NDIM(res)) ||
- !PyArray_CompareLists(PyArray_STRIDES(res),
+ PyArray_NDIM(arr)) ||
+ !PyArray_CompareLists(PyArray_STRIDES(arr),
PyArray_STRIDES(*op),
- PyArray_NDIM(res)) ||
- !PyArray_EquivTypes(PyArray_DESCR(res),
+ PyArray_NDIM(arr)) ||
+ !PyArray_EquivTypes(PyArray_DESCR(arr),
PyArray_DESCR(*op))) {
PyErr_SetString(PyExc_TypeError,
"__array_prepare__ must return an "
"ndarray or subclass thereof which is "
"otherwise identical to its input");
- Py_DECREF(res);
+ Py_DECREF(arr);
return -1;
}
/* Replace the op value */
else {
Py_DECREF(*op);
- *op = (PyArrayObject *)res;
+ *op = arr;
}
}
diff --git a/numpy/numarray/_capi.c b/numpy/numarray/_capi.c
index 446594d99..f6094426e 100644
--- a/numpy/numarray/_capi.c
+++ b/numpy/numarray/_capi.c
@@ -1,5 +1,6 @@
#include <Python.h>
+#define NPY_NO_DEPRECATED_API
#define _libnumarray_MODULE
#include "include/numpy/libnumarray.h"
#include "numpy/npy_3kcompat.h"
@@ -1076,7 +1077,7 @@ NA_OutputArray(PyObject *a, NumarrayType t, int requires)
PyArray_Descr *dtype;
PyArrayObject *ret;
- if (!PyArray_Check(a) || !PyArray_ISWRITEABLE(a)) {
+ if (!PyArray_Check(a) || !PyArray_ISWRITEABLE((PyArrayObject *)a)) {
PyErr_Format(PyExc_TypeError,
"NA_OutputArray: only writeable arrays work for output.");
return NULL;
@@ -1087,18 +1088,22 @@ NA_OutputArray(PyObject *a, NumarrayType t, int requires)
return (PyArrayObject *)a;
}
if (t == tAny) {
- dtype = PyArray_DESCR(a);
+ dtype = PyArray_DESCR((PyArrayObject *)a);
Py_INCREF(dtype);
}
else {
dtype = PyArray_DescrFromType(t);
}
- ret = (PyArrayObject *)PyArray_Empty(PyArray_NDIM(a), PyArray_DIMS(a),
- dtype, 0);
- ret->flags |= NPY_UPDATEIFCOPY;
- ret->base = a;
- PyArray_FLAGS(a) &= ~NPY_WRITEABLE;
+ ret = (PyArrayObject *)PyArray_Empty(PyArray_NDIM((PyArrayObject *)a),
+ PyArray_DIMS((PyArrayObject *)a),
+ dtype, 0);
Py_INCREF(a);
+ if (PyArray_SetBase(ret, a) < 0) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ PyArray_ENABLEFLAGS(ret, NPY_ARRAY_UPDATEIFCOPY);
+ PyArray_CLEARFLAGS((PyArrayObject *)a, NPY_ARRAY_WRITEABLE);
return ret;
}
@@ -1114,7 +1119,8 @@ NA_OutputArray(PyObject *a, NumarrayType t, int requires)
static PyArrayObject *
NA_IoArray(PyObject *a, NumarrayType t, int requires)
{
- PyArrayObject *shadow = NA_InputArray(a, t, requires | NPY_UPDATEIFCOPY );
+ PyArrayObject *shadow = NA_InputArray(a, t,
+ requires | NPY_ARRAY_UPDATEIFCOPY );
if (!shadow) return NULL;
@@ -2482,7 +2488,7 @@ _setFromPythonScalarCore(PyArrayObject *a, long offset, PyObject*value, int entr
static int
NA_setFromPythonScalar(PyArrayObject *a, long offset, PyObject *value)
{
- if (a->flags & WRITABLE)
+ if (PyArray_FLAGS(a) & NPY_ARRAY_WRITEABLE)
return _setFromPythonScalarCore(a, offset, value, 0);
else {
PyErr_Format(
@@ -2745,7 +2751,7 @@ NA_swapAxes(PyArrayObject *array, int x, int y)
array->strides[x] = array->strides[y];
array->strides[y] = temp;
- PyArray_UpdateFlags(array, NPY_UPDATE_ALL);
+ PyArray_UpdateFlags(array, NPY_ARRAY_UPDATE_ALL);
return 0;
}
@@ -2861,20 +2867,20 @@ NA_NewAllFromBuffer(int ndim, maybelong *shape, NumarrayType type,
static void
NA_updateAlignment(PyArrayObject *self)
{
- PyArray_UpdateFlags(self, NPY_ALIGNED);
+ PyArray_UpdateFlags(self, NPY_ARRAY_ALIGNED);
}
static void
NA_updateContiguous(PyArrayObject *self)
{
- PyArray_UpdateFlags(self, NPY_CONTIGUOUS | NPY_FORTRAN);
+ PyArray_UpdateFlags(self, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
}
static void
NA_updateStatus(PyArrayObject *self)
{
- PyArray_UpdateFlags(self, NPY_UPDATE_ALL);
+ PyArray_UpdateFlags(self, NPY_ARRAY_UPDATE_ALL);
}
static int