Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ENH: core: More cleanups removing direct PyArrayObject field access

  • Loading branch information...
commit 57d6b5bebb039dc6b2b3c5a2cc7bfc8e2cc3fb98 1 parent db90bf5
Mark Wiebe authored
View
2  numpy/core/src/multiarray/arrayobject.c
@@ -1149,7 +1149,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
* If not successful, then objects cannot be
* compared this way
*/
- if (array_other == NULL) {
+ if (array_other == NULL || (PyObject *)array_other == Py_None) {
Py_XDECREF(array_other);
PyErr_Clear();
Py_INCREF(Py_NotImplemented);
View
34 numpy/core/src/multiarray/multiarray_tests.c.src
@@ -29,15 +29,16 @@ static int copy_@type@(PyArrayIterObject *itx, PyArrayNeighborhoodIterObject *ni
for (i = 0; i < itx->size; ++i) {
PyArrayNeighborhoodIter_Reset(niterx);
- for (j = 0; j < itx->ao->nd; ++j) {
+ for (j = 0; j < PyArray_NDIM(itx->ao); ++j) {
odims[j] = bounds[2 * j + 1] - bounds[2 * j] + 1;
}
- aout = (PyArrayObject*)PyArray_SimpleNew(itx->ao->nd, odims, @typenum@);
+ aout = (PyArrayObject*)PyArray_SimpleNew(
+ PyArray_NDIM(itx->ao), odims, @typenum@);
if (aout == NULL) {
return -1;
}
- ptr = (@type@*)aout->data;
+ ptr = (@type@*)PyArray_DATA(aout);
for (j = 0; j < niterx->size; ++j) {
*ptr = *((@type@*)niterx->dataptr);
@@ -61,7 +62,7 @@ static int copy_object(PyArrayIterObject *itx, PyArrayNeighborhoodIterObject *ni
npy_intp i, j;
npy_intp odims[NPY_MAXDIMS];
PyArrayObject *aout;
- PyArray_CopySwapFunc *copyswap = itx->ao->descr->f->copyswap;
+ PyArray_CopySwapFunc *copyswap = PyArray_DESCR(itx->ao)->f->copyswap;
npy_int itemsize = PyArray_ITEMSIZE(itx->ao);
/*
@@ -71,16 +72,16 @@ static int copy_object(PyArrayIterObject *itx, PyArrayNeighborhoodIterObject *ni
for (i = 0; i < itx->size; ++i) {
PyArrayNeighborhoodIter_Reset(niterx);
- for (j = 0; j < itx->ao->nd; ++j) {
+ for (j = 0; j < PyArray_NDIM(itx->ao); ++j) {
odims[j] = bounds[2 * j + 1] - bounds[2 * j] + 1;
}
- aout = (PyArrayObject*)PyArray_SimpleNew(itx->ao->nd, odims, NPY_OBJECT);
+ aout = (PyArrayObject*)PyArray_SimpleNew(PyArray_NDIM(itx->ao), odims, NPY_OBJECT);
if (aout == NULL) {
return -1;
}
for (j = 0; j < niterx->size; ++j) {
- copyswap(aout->data + j * itemsize, niterx->dataptr, 0, NULL);
+ copyswap(PyArray_DATA(aout) + j * itemsize, niterx->dataptr, 0, NULL);
PyArrayNeighborhoodIter_Next(niterx);
}
@@ -117,7 +118,7 @@ test_neighborhood_iterator(PyObject* NPY_UNUSED(self), PyObject* args)
if (ax == NULL) {
return NULL;
}
- if (PySequence_Size(b) != 2 * ax->nd) {
+ if (PySequence_Size(b) != 2 * PyArray_NDIM(ax)) {
PyErr_SetString(PyExc_ValueError,
"bounds sequence size not compatible with x input");
goto clean_ax;
@@ -134,7 +135,7 @@ test_neighborhood_iterator(PyObject* NPY_UNUSED(self), PyObject* args)
}
/* Compute boundaries for the neighborhood iterator */
- for (i = 0; i < 2 * ax->nd; ++i) {
+ for (i = 0; i < 2 * PyArray_NDIM(ax); ++i) {
PyObject* bound;
bound = PySequence_GetItem(b, i);
if (bounds == NULL) {
@@ -221,15 +222,16 @@ copy_double_double(PyArrayNeighborhoodIterObject *itx,
*/
PyArrayNeighborhoodIter_Reset(itx);
for (i = 0; i < itx->size; ++i) {
- for (j = 0; j < itx->ao->nd; ++j) {
+ for (j = 0; j < PyArray_NDIM(itx->ao); ++j) {
odims[j] = bounds[2 * j + 1] - bounds[2 * j] + 1;
}
- aout = (PyArrayObject*)PyArray_SimpleNew(itx->ao->nd, odims, NPY_DOUBLE);
+ aout = (PyArrayObject*)PyArray_SimpleNew(
+ PyArray_NDIM(itx->ao), odims, NPY_DOUBLE);
if (aout == NULL) {
return -1;
}
- ptr = (double*)aout->data;
+ ptr = (double*)PyArray_DATA(aout);
PyArrayNeighborhoodIter_Reset(niterx);
for (j = 0; j < niterx->size; ++j) {
@@ -268,12 +270,12 @@ test_neighborhood_iterator_oob(PyObject* NPY_UNUSED(self), PyObject* args)
if (ax == NULL) {
return NULL;
}
- if (PySequence_Size(b1) != 2 * ax->nd) {
+ if (PySequence_Size(b1) != 2 * PyArray_NDIM(ax)) {
PyErr_SetString(PyExc_ValueError,
"bounds sequence 1 size not compatible with x input");
goto clean_ax;
}
- if (PySequence_Size(b2) != 2 * ax->nd) {
+ if (PySequence_Size(b2) != 2 * PyArray_NDIM(ax)) {
PyErr_SetString(PyExc_ValueError,
"bounds sequence 2 size not compatible with x input");
goto clean_ax;
@@ -290,7 +292,7 @@ test_neighborhood_iterator_oob(PyObject* NPY_UNUSED(self), PyObject* args)
}
/* Compute boundaries for the neighborhood iterator */
- for (i = 0; i < 2 * ax->nd; ++i) {
+ for (i = 0; i < 2 * PyArray_NDIM(ax); ++i) {
PyObject* bound;
bound = PySequence_GetItem(b1, i);
if (bounds == NULL) {
@@ -313,7 +315,7 @@ test_neighborhood_iterator_oob(PyObject* NPY_UNUSED(self), PyObject* args)
goto clean_out;
}
- for (i = 0; i < 2 * ax->nd; ++i) {
+ for (i = 0; i < 2 * PyArray_NDIM(ax); ++i) {
PyObject* bound;
bound = PySequence_GetItem(b2, i);
if (bounds == NULL) {
View
4 numpy/core/src/multiarray/nditer_pywrap.c
@@ -2011,7 +2011,7 @@ npyiter_seq_length(NewNpyArrayIterObject *self)
}
}
-NPY_NO_EXPORT PyArrayObject *
+NPY_NO_EXPORT PyObject *
npyiter_seq_item(NewNpyArrayIterObject *self, Py_ssize_t i)
{
PyArrayObject *ret;
@@ -2084,7 +2084,7 @@ npyiter_seq_item(NewNpyArrayIterObject *self, Py_ssize_t i)
PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL);
- return ret;
+ return (PyObject *)ret;
}
NPY_NO_EXPORT PyObject *
View
16 numpy/core/src/npysort/sort.c.src
@@ -469,7 +469,7 @@ mergesort0_@suff@(@type@ *pl, @type@ *pr, @type@ *pw, @type@ *vp, size_t len)
int
mergesort_@suff@(@type@ *start, npy_intp num, PyArrayObject *arr)
{
- const size_t elsize = arr->descr->elsize;
+ const size_t elsize = PyArray_DESCR(arr)->elsize;
const size_t len = elsize / sizeof(@type@);
@type@ *pl, *pr, *pw, *vp;
int err = 0;
@@ -500,8 +500,8 @@ fail_0:
int
quicksort_@suff@(@type@ *start, npy_intp num, PyArrayObject *arr)
{
- const size_t len = arr->descr->elsize/sizeof(@type@);
- @type@ *vp = malloc(arr->descr->elsize);
+ const size_t len = PyArray_DESCR(arr)->elsize/sizeof(@type@);
+ @type@ *vp = malloc(PyArray_DESCR(arr)->elsize);
@type@ *pl = start;
@type@ *pr = start + (num - 1)*len;
@type@ *stack[PYA_QS_STACK], **sptr = stack, *pm, *pi, *pj, *pk;
@@ -567,8 +567,8 @@ quicksort_@suff@(@type@ *start, npy_intp num, PyArrayObject *arr)
int
heapsort_@suff@(@type@ *start, npy_intp n, PyArrayObject *arr)
{
- size_t len = arr->descr->elsize/sizeof(@type@);
- @type@ *tmp = malloc(arr->descr->elsize);
+ size_t len = PyArray_DESCR(arr)->elsize/sizeof(@type@);
+ @type@ *tmp = malloc(PyArray_DESCR(arr)->elsize);
@type@ *a = start - len;
npy_intp i,j,l;
@@ -616,7 +616,7 @@ heapsort_@suff@(@type@ *start, npy_intp n, PyArrayObject *arr)
int
aheapsort_@suff@(@type@ *v, npy_intp *tosort, npy_intp n, PyArrayObject *arr)
{
- size_t len = arr->descr->elsize/sizeof(@type@);
+ size_t len = PyArray_DESCR(arr)->elsize/sizeof(@type@);
npy_intp *a, i,j,l, tmp;
/* The array needs to be offset by one for heapsort indexing */
@@ -665,7 +665,7 @@ aheapsort_@suff@(@type@ *v, npy_intp *tosort, npy_intp n, PyArrayObject *arr)
int
aquicksort_@suff@(@type@ *v, npy_intp* tosort, npy_intp num, PyArrayObject *arr)
{
- size_t len = arr->descr->elsize/sizeof(@type@);
+ size_t len = PyArray_DESCR(arr)->elsize/sizeof(@type@);
@type@ *vp;
npy_intp *pl = tosort;
npy_intp *pr = tosort + num - 1;
@@ -775,7 +775,7 @@ amergesort0_@suff@(npy_intp *pl, npy_intp *pr, @type@ *v, npy_intp *pw, int len)
int
amergesort_@suff@(@type@ *v, npy_intp *tosort, npy_intp num, PyArrayObject *arr)
{
- const size_t elsize = arr->descr->elsize;
+ const size_t elsize = PyArray_DESCR(arr)->elsize;
const size_t len = elsize / sizeof(@type@);
npy_intp *pl, *pr, *pw;
View
1  numpy/core/src/umath/ufunc_object.c
@@ -61,7 +61,6 @@
/********************/
#define USE_USE_DEFAULTS 1
-#define USE_NEW_ITERATOR_GENFUNC 1
/********************/
/* ---------------------------------------------------------------- */
View
163 numpy/lib/src/_compiled_base.c
@@ -1,12 +1,13 @@
+#define NPY_NO_DEPRECATED_API
#include "Python.h"
#include "structmember.h"
#include "numpy/noprefix.h"
#include "npy_config.h"
-static intp
-incr_slot_(double x, double *bins, intp lbins)
+static npy_intp
+incr_slot_(double x, double *bins, npy_intp lbins)
{
- intp i;
+ npy_intp i;
for ( i = 0; i < lbins; i ++ ) {
if ( x < bins [i] ) {
@@ -16,10 +17,10 @@ incr_slot_(double x, double *bins, intp lbins)
return lbins;
}
-static intp
-decr_slot_(double x, double * bins, intp lbins)
+static npy_intp
+decr_slot_(double x, double * bins, npy_intp lbins)
{
- intp i;
+ npy_intp i;
for ( i = lbins - 1; i >= 0; i -- ) {
if (x < bins [i]) {
@@ -57,11 +58,11 @@ monotonic_(double * a, int lena)
/* find the index of the maximum element of an integer array */
-static intp
-mxx (intp *i , intp len)
+static npy_intp
+mxx (npy_intp *i , npy_intp len)
{
- intp mx = 0, max = i[0];
- intp j;
+ npy_intp mx = 0, max = i[0];
+ npy_intp j;
for ( j = 1; j < len; j ++ ) {
if ( i [j] > max ) {
@@ -73,11 +74,11 @@ mxx (intp *i , intp len)
}
/* find the index of the minimum element of an integer array */
-static intp
-mnx (intp *i , intp len)
+static npy_intp
+mnx (npy_intp *i , npy_intp len)
{
- intp mn = 0, min = i [0];
- intp j;
+ npy_intp mn = 0, min = i [0];
+ npy_intp j;
for ( j = 1; j < len; j ++ )
if ( i [j] < min )
@@ -105,8 +106,8 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
{
PyArray_Descr *type;
PyObject *list = NULL, *weight=Py_None, *mlength=Py_None;
- PyObject *lst=NULL, *ans=NULL, *wts=NULL;
- intp *numbers, *ians, len , mxi, mni, ans_size, minlength;
+ PyArrayObject *lst=NULL, *ans=NULL, *wts=NULL;
+ npy_intp *numbers, *ians, len , mxi, mni, ans_size, minlength;
int i;
double *weights , *dans;
static char *kwlist[] = {"list", "weights", "minlength", NULL};
@@ -115,8 +116,9 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
kwlist, &list, &weight, &mlength)) {
goto fail;
}
- if (!(lst = PyArray_ContiguousFromAny(list, PyArray_INTP, 1, 1))) {
- goto fail;
+ lst = (PyArrayObject *)PyArray_ContiguousFromAny(list, NPY_INTP, 1, 1);
+ if (lst == NULL) {
+ goto fail;
}
len = PyArray_SIZE(lst);
if (len < 1) {
@@ -124,7 +126,7 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
"The first argument cannot be empty.");
goto fail;
}
- numbers = (intp *) PyArray_DATA(lst);
+ numbers = (npy_intp *) PyArray_DATA(lst);
mxi = mxx(numbers, len);
mni = mnx(numbers, len);
if (numbers[mni] < 0) {
@@ -147,18 +149,21 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
ans_size = minlength;
}
}
- type = PyArray_DescrFromType(PyArray_INTP);
+ type = PyArray_DescrFromType(NPY_INTP);
if (weight == Py_None) {
- if (!(ans = PyArray_Zeros(1, &ans_size, type, 0))) {
+ ans = (PyArrayObject *)PyArray_Zeros(1, &ans_size, type, 0);
+ if (ans == NULL) {
goto fail;
}
- ians = (intp *)(PyArray_DATA(ans));
+ ians = (npy_intp *)(PyArray_DATA(ans));
for (i = 0; i < len; i++)
ians [numbers [i]] += 1;
Py_DECREF(lst);
}
else {
- if (!(wts = PyArray_ContiguousFromAny(weight, PyArray_DOUBLE, 1, 1))) {
+ wts = (PyArrayObject *)PyArray_ContiguousFromAny(
+ weight, NPY_DOUBLE, 1, 1);
+ if (wts == NULL) {
goto fail;
}
weights = (double *)PyArray_DATA (wts);
@@ -167,18 +172,19 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
"The weights and list don't have the same length.");
goto fail;
}
- type = PyArray_DescrFromType(PyArray_DOUBLE);
- if (!(ans = PyArray_Zeros(1, &ans_size, type, 0))) {
+ type = PyArray_DescrFromType(NPY_DOUBLE);
+ ans = (PyArrayObject *)PyArray_Zeros(1, &ans_size, type, 0);
+ if (ans == NULL) {
goto fail;
}
- dans = (double *)PyArray_DATA (ans);
+ dans = (double *)PyArray_DATA(ans);
for (i = 0; i < len; i++) {
dans[numbers[i]] += weights[i];
}
Py_DECREF(lst);
Py_DECREF(wts);
}
- return ans;
+ return (PyObject *)ans;
fail:
Py_XDECREF(lst);
@@ -200,10 +206,10 @@ arr_digitize(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
{
/* self is not used */
PyObject *ox, *obins;
- PyObject *ax = NULL, *abins = NULL, *aret = NULL;
+ PyArrayObject *ax = NULL, *abins = NULL, *aret = NULL;
double *dx, *dbins;
- intp lbins, lx; /* lengths */
- intp *iret;
+ npy_intp lbins, lx; /* lengths */
+ npy_intp *iret;
int m, i;
static char *kwlist[] = {"x", "bins", NULL};
PyArray_Descr *type;
@@ -211,12 +217,16 @@ arr_digitize(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &ox, &obins)) {
goto fail;
}
- type = PyArray_DescrFromType(PyArray_DOUBLE);
- if (!(ax = PyArray_FromAny(ox, type, 1, 1, CARRAY, NULL))) {
+ type = PyArray_DescrFromType(NPY_DOUBLE);
+ ax = (PyArrayObject *)PyArray_FromAny(ox, type,
+ 1, 1, NPY_ARRAY_CARRAY, NULL);
+ if (ax == NULL) {
goto fail;
}
Py_INCREF(type);
- if (!(abins = PyArray_FromAny(obins, type, 1, 1, CARRAY, NULL))) {
+ abins = (PyArrayObject *)PyArray_FromAny(obins, type,
+ 1, 1, NPY_ARRAY_CARRAY, NULL);
+ if (abins == NULL) {
goto fail;
}
@@ -224,10 +234,11 @@ arr_digitize(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
dx = (double *)PyArray_DATA(ax);
lbins = PyArray_SIZE(abins);
dbins = (double *)PyArray_DATA(abins);
- if (!(aret = PyArray_SimpleNew(1, &lx, PyArray_INTP))) {
+ aret = (PyArrayObject *)PyArray_SimpleNew(1, &lx, NPY_INTP);
+ if (aret == NULL) {
goto fail;
}
- iret = (intp *)PyArray_DATA(aret);
+ iret = (npy_intp *)PyArray_DATA(aret);
if (lx <= 0 || lbins < 0) {
PyErr_SetString(PyExc_ValueError,
@@ -266,7 +277,7 @@ arr_digitize(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
Py_DECREF(ax);
Py_DECREF(abins);
- return aret;
+ return (PyObject *)aret;
fail:
Py_XDECREF(ax);
@@ -291,7 +302,7 @@ arr_insert(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict)
int numvals, totmask, sameshape;
char *input_data, *mptr, *vptr, *zero = NULL;
int melsize, delsize, copied, nd;
- intp *instrides, *inshape;
+ npy_intp *instrides, *inshape;
int mindx, rem_indx, indx, i, k, objarray;
static char *kwlist[] = {"input", "mask", "vals", NULL};
@@ -302,13 +313,13 @@ arr_insert(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict)
goto fail;
}
- amask = (PyArrayObject *) PyArray_FROM_OF(mask, CARRAY);
+ amask = (PyArrayObject *)PyArray_FROM_OF(mask, NPY_ARRAY_CARRAY);
if (amask == NULL) {
goto fail;
}
/* Cast an object array */
- if (amask->descr->type_num == PyArray_OBJECT) {
- tmp = (PyArrayObject *)PyArray_Cast(amask, PyArray_INTP);
+ if (PyArray_DESCR(amask)->type_num == NPY_OBJECT) {
+ tmp = (PyArrayObject *)PyArray_Cast(amask, NPY_INTP);
if (tmp == NULL) {
goto fail;
}
@@ -317,16 +328,16 @@ arr_insert(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict)
}
sameshape = 1;
- if (amask->nd == ainput->nd) {
- for (k = 0; k < amask->nd; k++) {
- if (amask->dimensions[k] != ainput->dimensions[k]) {
+ if (PyArray_NDIM(amask) == PyArray_NDIM(ainput)) {
+ for (k = 0; k < PyArray_NDIM(amask); k++) {
+ if (PyArray_DIMS(amask)[k] != PyArray_DIMS(ainput)[k]) {
sameshape = 0;
}
}
}
else {
/* Test to see if amask is 1d */
- if (amask->nd != 1) {
+ if (PyArray_NDIM(amask) != 1) {
sameshape = 0;
}
else if ((PyArray_SIZE(ainput)) != PyArray_SIZE(amask)) {
@@ -339,22 +350,23 @@ arr_insert(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict)
goto fail;
}
- avals = (PyArrayObject *)PyArray_FromObject(vals, ainput->descr->type_num, 0, 1);
+ avals = (PyArrayObject *)PyArray_FromObject(vals,
+ PyArray_DESCR(ainput)->type_num, 0, 1);
if (avals == NULL) {
goto fail;
}
numvals = PyArray_SIZE(avals);
- nd = ainput->nd;
- input_data = ainput->data;
- mptr = amask->data;
- melsize = amask->descr->elsize;
- vptr = avals->data;
- delsize = avals->descr->elsize;
+ nd = PyArray_NDIM(ainput);
+ input_data = PyArray_DATA(ainput);
+ mptr = PyArray_DATA(amask);
+ melsize = PyArray_DESCR(amask)->elsize;
+ vptr = PyArray_DATA(avals);
+ delsize = PyArray_DESCR(avals)->elsize;
zero = PyArray_Zero(amask);
if (zero == NULL) {
goto fail;
}
- objarray = (ainput->descr->type_num == PyArray_OBJECT);
+ objarray = (PyArray_DESCR(ainput)->type_num == NPY_OBJECT);
/* Handle zero-dimensional case separately */
if (nd == 0) {
@@ -380,8 +392,8 @@ arr_insert(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict)
*/
totmask = (int) PyArray_SIZE(amask);
copied = 0;
- instrides = ainput->strides;
- inshape = ainput->dimensions;
+ instrides = PyArray_STRIDES(ainput);
+ inshape = PyArray_DIMS(ainput);
for (mindx = 0; mindx < totmask; mindx++) {
if (memcmp(mptr,zero,melsize) != 0) {
/* compute indx into input array */
@@ -402,7 +414,7 @@ arr_insert(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict)
copied += 1;
/* If we move past value data. Reset */
if (copied >= numvals) {
- vptr = avals->data;
+ vptr = PyArray_DATA(avals);
}
}
mptr += melsize;
@@ -476,31 +488,32 @@ arr_interp(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict)
return NULL;
}
- afp = (NPY_AO*)PyArray_ContiguousFromAny(fp, NPY_DOUBLE, 1, 1);
+ afp = (PyArrayObject *)PyArray_ContiguousFromAny(fp, NPY_DOUBLE, 1, 1);
if (afp == NULL) {
return NULL;
}
- axp = (NPY_AO*)PyArray_ContiguousFromAny(xp, NPY_DOUBLE, 1, 1);
+ axp = (PyArrayObject *)PyArray_ContiguousFromAny(xp, NPY_DOUBLE, 1, 1);
if (axp == NULL) {
goto fail;
}
- ax = (NPY_AO*)PyArray_ContiguousFromAny(x, NPY_DOUBLE, 1, 0);
+ ax = (PyArrayObject *)PyArray_ContiguousFromAny(x, NPY_DOUBLE, 1, 0);
if (ax == NULL) {
goto fail;
}
- lenxp = axp->dimensions[0];
+ lenxp = PyArray_DIMS(axp)[0];
if (lenxp == 0) {
PyErr_SetString(PyExc_ValueError,
"array of sample points is empty");
goto fail;
}
- if (afp->dimensions[0] != lenxp) {
+ if (PyArray_DIMS(afp)[0] != lenxp) {
PyErr_SetString(PyExc_ValueError,
"fp and xp are not of the same length.");
goto fail;
}
- af = (NPY_AO*)PyArray_SimpleNew(ax->nd, ax->dimensions, NPY_DOUBLE);
+ af = (PyArrayObject *)PyArray_SimpleNew(PyArray_NDIM(ax),
+ PyArray_DIMS(ax), NPY_DOUBLE);
if (af == NULL) {
goto fail;
}
@@ -1038,7 +1051,10 @@ arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds)
goto fail;
}
Py_INCREF(ret_arr);
- view->base = (PyObject *)ret_arr;
+ if (PyArray_SetBase(view, (PyObject *)ret_arr) < 0) {
+ Py_DECREF(view);
+ goto fail;
+ }
PyTuple_SET_ITEM(ret_tuple, i, PyArray_Return(view));
}
@@ -1246,8 +1262,8 @@ static PyObject *
pack_or_unpack_bits(PyObject *input, int axis, int unpack)
{
PyArrayObject *inp;
- PyObject *new = NULL;
- PyObject *out = NULL;
+ PyArrayObject *new = NULL;
+ PyArrayObject *out = NULL;
npy_intp outdims[MAX_DIMS];
int i;
void (*thefunc)(void *, int, npy_intp, npy_intp, void *, npy_intp, npy_intp);
@@ -1271,25 +1287,25 @@ pack_or_unpack_bits(PyObject *input, int axis, int unpack)
goto fail;
}
- new = PyArray_CheckAxis(inp, &axis, 0);
+ new = (PyArrayObject *)PyArray_CheckAxis(inp, &axis, 0);
Py_DECREF(inp);
if (new == NULL) {
return NULL;
}
/* Handle zero-dim array separately */
if (PyArray_SIZE(new) == 0) {
- return PyArray_Copy((PyArrayObject *)new);
+ return PyArray_Copy(new);
}
if (PyArray_NDIM(new) == 0) {
if (unpack) {
/* Handle 0-d array by converting it to a 1-d array */
- PyObject *temp;
+ PyArrayObject *temp;
PyArray_Dims newdim = {NULL, 1};
npy_intp shape = 1;
newdim.ptr = &shape;
- temp = PyArray_Newshape((PyArrayObject *)new, &newdim, NPY_CORDER);
+ temp = (PyArrayObject *)PyArray_Newshape(new, &newdim, NPY_CORDER);
if (temp == NULL) {
goto fail;
}
@@ -1297,8 +1313,8 @@ pack_or_unpack_bits(PyObject *input, int axis, int unpack)
new = temp;
}
else {
- ubyte *optr, *iptr;
- out = PyArray_New(new->ob_type, 0, NULL, NPY_UBYTE,
+ char *optr, *iptr;
+ out = (PyArrayObject *)PyArray_New(new->ob_type, 0, NULL, NPY_UBYTE,
NULL, NULL, 0, 0, NULL);
if (out == NULL) {
goto fail;
@@ -1338,8 +1354,9 @@ pack_or_unpack_bits(PyObject *input, int axis, int unpack)
}
/* Create output array */
- out = PyArray_New(new->ob_type, PyArray_NDIM(new), outdims, PyArray_UBYTE,
- NULL, NULL, 0, PyArray_ISFORTRAN(new), NULL);
+ out = (PyArrayObject *)PyArray_New(new->ob_type,
+ PyArray_NDIM(new), outdims, NPY_UBYTE,
+ NULL, NULL, 0, PyArray_ISFORTRAN(new), NULL);
if (out == NULL) {
goto fail;
}
@@ -1365,7 +1382,7 @@ pack_or_unpack_bits(PyObject *input, int axis, int unpack)
finish:
Py_DECREF(new);
- return out;
+ return (PyObject *)out;
fail:
Py_XDECREF(new);
View
212 numpy/numarray/_capi.c
@@ -348,9 +348,9 @@ NA_NewAll(int ndim, maybelong *shape, NumarrayType type,
result = NULL;
} else {
if (buffer) {
- memcpy(result->data, buffer, NA_NBYTES(result));
+ memcpy(PyArray_DATA(result), buffer, NA_NBYTES(result));
} else {
- memset(result->data, 0, NA_NBYTES(result));
+ memset(PyArray_DATA(result), 0, NA_NBYTES(result));
}
}
}
@@ -367,7 +367,7 @@ NA_NewAllStrides(int ndim, maybelong *shape, maybelong *strides,
byteoffset, 0,
byteorder, aligned, writeable);
for(i=0; i<ndim; i++)
- result->strides[i] = strides[i];
+ PyArray_STRIDES(result)[i] = strides[i];
return result;
}
@@ -704,16 +704,16 @@ _NA_callStridingHelper(PyObject *aux, long dim,
{
int i, j, status=0;
dim -= 1;
- for(i=0; i<numarray[0]->dimensions[dim]; i++) {
+ for(i=0; i<PyArray_DIMS(numarray[0])[dim]; i++) {
for (j=0; j<nnumarray; j++)
- data[j] += numarray[j]->strides[dim]*i;
+ data[j] += PyArray_STRIDES(numarray[j])[dim]*i;
if (dim == 0)
status |= f(aux, nnumarray, numarray, data);
else
status |= _NA_callStridingHelper(
aux, dim, nnumarray, numarray, data, f);
for (j=0; j<nnumarray; j++)
- data[j] -= numarray[j]->strides[dim]*i;
+ data[j] -= PyArray_STRIDES(numarray[j])[dim]*i;
}
return status;
}
@@ -747,7 +747,7 @@ callStridingCFunc(PyObject *self, PyObject *args) {
"%s arg[%d] is not an array.",
me->descr.name, i);
numarray[i] = (PyArrayObject *) otemp;
- data[i] = numarray[i]->data;
+ data[i] = PyArray_DATA(numarray[i]);
Py_DECREF(otemp);
if (!NA_updateDataPtr(numarray[i]))
return NULL;
@@ -756,7 +756,7 @@ callStridingCFunc(PyObject *self, PyObject *args) {
/* Cast function pointer and perform stride operation */
f = (CFUNC_STRIDED_FUNC) me->descr.fptr;
- if (_NA_callStridingHelper(aux, numarray[0]->nd,
+ if (_NA_callStridingHelper(aux, PyArray_NDIM(numarray[0]),
nnumarray, numarray, data, f)) {
return NULL;
} else {
@@ -1053,7 +1053,7 @@ NA_InputArray(PyObject *a, NumarrayType t, int requires)
static int
satisfies(PyArrayObject *a, int requirements, NumarrayType t)
{
- int type_ok = (a->descr->type_num == t) || (t == tAny);
+ int type_ok = (PyArray_DESCR(a)->type_num == t) || (t == tAny);
if (PyArray_ISCARRAY(a))
return type_ok;
@@ -1165,7 +1165,7 @@ Complex64 NA_get_Complex64(PyArrayObject *a, long offset)
Complex32 v0;
Complex64 v;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tComplex32:
v0 = NA_GETP(a, Complex32, (NA_PTR(a)+offset));
v.r = v0.r;
@@ -1186,7 +1186,7 @@ void NA_set_Complex64(PyArrayObject *a, long offset, Complex64 v)
{
Complex32 v0;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tComplex32:
v0.r = v.r;
v0.i = v.i;
@@ -1203,7 +1203,7 @@ void NA_set_Complex64(PyArrayObject *a, long offset, Complex64 v)
Int64 NA_get_Int64(PyArrayObject *a, long offset)
{
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tBool:
return NA_GETP(a, Bool, (NA_PTR(a)+offset)) != 0;
case tInt8:
@@ -1233,7 +1233,7 @@ Int64 NA_get_Int64(PyArrayObject *a, long offset)
default:
PyErr_Format( PyExc_TypeError,
"Unknown type %d in NA_get_Int64",
- a->descr->type_num);
+ PyArray_DESCR(a)->type_num);
PyErr_Print();
}
return 0; /* suppress warning */
@@ -1243,7 +1243,7 @@ void NA_set_Int64(PyArrayObject *a, long offset, Int64 v)
{
Bool b;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tBool:
b = (v != 0);
NA_SETP(a, Bool, (NA_PTR(a)+offset), b);
@@ -1281,7 +1281,7 @@ void NA_set_Int64(PyArrayObject *a, long offset, Int64 v)
default:
PyErr_Format( PyExc_TypeError,
"Unknown type %d in NA_set_Int64",
- a->descr->type_num);
+ PyArray_DESCR(a)->type_num);
PyErr_Print();
}
}
@@ -1299,11 +1299,11 @@ long NA_get_offset(PyArrayObject *a, int N, ...)
va_start(ap, N);
if (N > 0) { /* compute offset of "outer" indices. */
for(i=0; i<N; i++)
- offset += va_arg(ap, long) * a->strides[i];
+ offset += va_arg(ap, long) * PyArray_STRIDES(a)[i];
} else { /* compute offset of "inner" indices. */
N = -N;
for(i=0; i<N; i++)
- offset += va_arg(ap, long) * a->strides[a->nd-N+i];
+ offset += va_arg(ap, long) * PyArray_STRIDES(a)[PyArray_NDIM(a)-N+i];
}
va_end(ap);
return offset;
@@ -1311,7 +1311,7 @@ long NA_get_offset(PyArrayObject *a, int N, ...)
Float64 NA_get_Float64(PyArrayObject *a, long offset)
{
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tBool:
return NA_GETP(a, Bool, (NA_PTR(a)+offset)) != 0;
case tInt8:
@@ -1343,7 +1343,7 @@ Float64 NA_get_Float64(PyArrayObject *a, long offset)
default:
PyErr_Format( PyExc_TypeError,
"Unknown type %d in NA_get_Float64",
- a->descr->type_num);
+ PyArray_DESCR(a)->type_num);
}
return 0; /* suppress warning */
}
@@ -1352,7 +1352,7 @@ void NA_set_Float64(PyArrayObject *a, long offset, Float64 v)
{
Bool b;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tBool:
b = (v != 0);
NA_SETP(a, Bool, (NA_PTR(a)+offset), b);
@@ -1394,7 +1394,7 @@ void NA_set_Float64(PyArrayObject *a, long offset, Float64 v)
default:
PyErr_Format( PyExc_TypeError,
"Unknown type %d in NA_set_Float64",
- a->descr->type_num );
+ PyArray_DESCR(a)->type_num );
PyErr_Print();
}
}
@@ -1402,127 +1402,127 @@ void NA_set_Float64(PyArrayObject *a, long offset, Float64 v)
Float64 NA_get1_Float64(PyArrayObject *a, long i)
{
- long offset = i * a->strides[0];
+ long offset = i * PyArray_STRIDES(a)[0];
return NA_get_Float64(a, offset);
}
Float64 NA_get2_Float64(PyArrayObject *a, long i, long j)
{
- long offset = i * a->strides[0]
- + j * a->strides[1];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1];
return NA_get_Float64(a, offset);
}
Float64 NA_get3_Float64(PyArrayObject *a, long i, long j, long k)
{
- long offset = i * a->strides[0]
- + j * a->strides[1]
- + k * a->strides[2];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1]
+ + k * PyArray_STRIDES(a)[2];
return NA_get_Float64(a, offset);
}
void NA_set1_Float64(PyArrayObject *a, long i, Float64 v)
{
- long offset = i * a->strides[0];
+ long offset = i * PyArray_STRIDES(a)[0];
NA_set_Float64(a, offset, v);
}
void NA_set2_Float64(PyArrayObject *a, long i, long j, Float64 v)
{
- long offset = i * a->strides[0]
- + j * a->strides[1];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1];
NA_set_Float64(a, offset, v);
}
void NA_set3_Float64(PyArrayObject *a, long i, long j, long k, Float64 v)
{
- long offset = i * a->strides[0]
- + j * a->strides[1]
- + k * a->strides[2];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1]
+ + k * PyArray_STRIDES(a)[2];
NA_set_Float64(a, offset, v);
}
Complex64 NA_get1_Complex64(PyArrayObject *a, long i)
{
- long offset = i * a->strides[0];
+ long offset = i * PyArray_STRIDES(a)[0];
return NA_get_Complex64(a, offset);
}
Complex64 NA_get2_Complex64(PyArrayObject *a, long i, long j)
{
- long offset = i * a->strides[0]
- + j * a->strides[1];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1];
return NA_get_Complex64(a, offset);
}
Complex64 NA_get3_Complex64(PyArrayObject *a, long i, long j, long k)
{
- long offset = i * a->strides[0]
- + j * a->strides[1]
- + k * a->strides[2];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1]
+ + k * PyArray_STRIDES(a)[2];
return NA_get_Complex64(a, offset);
}
void NA_set1_Complex64(PyArrayObject *a, long i, Complex64 v)
{
- long offset = i * a->strides[0];
+ long offset = i * PyArray_STRIDES(a)[0];
NA_set_Complex64(a, offset, v);
}
void NA_set2_Complex64(PyArrayObject *a, long i, long j, Complex64 v)
{
- long offset = i * a->strides[0]
- + j * a->strides[1];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1];
NA_set_Complex64(a, offset, v);
}
void NA_set3_Complex64(PyArrayObject *a, long i, long j, long k, Complex64 v)
{
- long offset = i * a->strides[0]
- + j * a->strides[1]
- + k * a->strides[2];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1]
+ + k * PyArray_STRIDES(a)[2];
NA_set_Complex64(a, offset, v);
}
Int64 NA_get1_Int64(PyArrayObject *a, long i)
{
- long offset = i * a->strides[0];
+ long offset = i * PyArray_STRIDES(a)[0];
return NA_get_Int64(a, offset);
}
Int64 NA_get2_Int64(PyArrayObject *a, long i, long j)
{
- long offset = i * a->strides[0]
- + j * a->strides[1];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1];
return NA_get_Int64(a, offset);
}
Int64 NA_get3_Int64(PyArrayObject *a, long i, long j, long k)
{
- long offset = i * a->strides[0]
- + j * a->strides[1]
- + k * a->strides[2];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1]
+ + k * PyArray_STRIDES(a)[2];
return NA_get_Int64(a, offset);
}
void NA_set1_Int64(PyArrayObject *a, long i, Int64 v)
{
- long offset = i * a->strides[0];
+ long offset = i * PyArray_STRIDES(a)[0];
NA_set_Int64(a, offset, v);
}
void NA_set2_Int64(PyArrayObject *a, long i, long j, Int64 v)
{
- long offset = i * a->strides[0]
- + j * a->strides[1];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1];
NA_set_Int64(a, offset, v);
}
void NA_set3_Int64(PyArrayObject *a, long i, long j, long k, Int64 v)
{
- long offset = i * a->strides[0]
- + j * a->strides[1]
- + k * a->strides[2];
+ long offset = i * PyArray_STRIDES(a)[0]
+ + j * PyArray_STRIDES(a)[1]
+ + k * PyArray_STRIDES(a)[2];
NA_set_Int64(a, offset, v);
}
@@ -1531,7 +1531,7 @@ void NA_set3_Int64(PyArrayObject *a, long i, long j, long k, Int64 v)
#define NA_SET_CMPLX(a, type, base, cnt, in) \
{ \
int i; \
- int stride = a->strides[ a->nd - 1]; \
+ int stride = PyArray_STRIDES(a)[ PyArray_NDIM(a) - 1]; \
NA_SET1D(a, type, base, cnt, in); \
base = NA_PTR(a) + offset + sizeof(type); \
for(i=0; i<cnt; i++) { \
@@ -1545,7 +1545,7 @@ NA_get1D_Float64(PyArrayObject *a, long offset, int cnt, Float64*out)
{
char *base = NA_PTR(a) + offset;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tBool:
NA_GET1D(a, Bool, base, cnt, out);
break;
@@ -1590,7 +1590,7 @@ NA_get1D_Float64(PyArrayObject *a, long offset, int cnt, Float64*out)
default:
PyErr_Format( PyExc_TypeError,
"Unknown type %d in NA_get1D_Float64",
- a->descr->type_num);
+ PyArray_DESCR(a)->type_num);
PyErr_Print();
return -1;
}
@@ -1614,7 +1614,7 @@ NA_set1D_Float64(PyArrayObject *a, long offset, int cnt, Float64*in)
{
char *base = NA_PTR(a) + offset;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tBool:
NA_SET1D(a, Bool, base, cnt, in);
break;
@@ -1659,7 +1659,7 @@ NA_set1D_Float64(PyArrayObject *a, long offset, int cnt, Float64*in)
default:
PyErr_Format( PyExc_TypeError,
"Unknown type %d in NA_set1D_Float64",
- a->descr->type_num);
+ PyArray_DESCR(a)->type_num);
PyErr_Print();
return -1;
}
@@ -1671,7 +1671,7 @@ NA_get1D_Int64(PyArrayObject *a, long offset, int cnt, Int64*out)
{
char *base = NA_PTR(a) + offset;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tBool:
NA_GET1D(a, Bool, base, cnt, out);
break;
@@ -1714,7 +1714,7 @@ NA_get1D_Int64(PyArrayObject *a, long offset, int cnt, Int64*out)
default:
PyErr_Format( PyExc_TypeError,
"Unknown type %d in NA_get1D_Int64",
- a->descr->type_num);
+ PyArray_DESCR(a)->type_num);
PyErr_Print();
return -1;
}
@@ -1738,7 +1738,7 @@ NA_set1D_Int64(PyArrayObject *a, long offset, int cnt, Int64*in)
{
char *base = NA_PTR(a) + offset;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tBool:
NA_SET1D(a, Bool, base, cnt, in);
break;
@@ -1781,7 +1781,7 @@ NA_set1D_Int64(PyArrayObject *a, long offset, int cnt, Int64*in)
default:
PyErr_Format( PyExc_TypeError,
"Unknown type %d in NA_set1D_Int64",
- a->descr->type_num);
+ PyArray_DESCR(a)->type_num);
PyErr_Print();
return -1;
}
@@ -1793,14 +1793,14 @@ NA_get1D_Complex64(PyArrayObject *a, long offset, int cnt, Complex64*out)
{
char *base = NA_PTR(a) + offset;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tComplex64:
NA_GET1D(a, Complex64, base, cnt, out);
break;
default:
PyErr_Format( PyExc_TypeError,
"Unsupported type %d in NA_get1D_Complex64",
- a->descr->type_num);
+ PyArray_DESCR(a)->type_num);
PyErr_Print();
return -1;
}
@@ -1812,14 +1812,14 @@ NA_set1D_Complex64(PyArrayObject *a, long offset, int cnt, Complex64*in)
{
char *base = NA_PTR(a) + offset;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tComplex64:
NA_SET1D(a, Complex64, base, cnt, in);
break;
default:
PyErr_Format( PyExc_TypeError,
"Unsupported type %d in NA_set1D_Complex64",
- a->descr->type_num);
+ PyArray_DESCR(a)->type_num);
PyErr_Print();
return -1;
}
@@ -1841,10 +1841,10 @@ NA_ShapeEqual(PyArrayObject *a, PyArrayObject *b)
"NA_ShapeEqual: non-array as parameter.");
return -1;
}
- if (a->nd != b->nd)
+ if (PyArray_NDIM(a) != PyArray_NDIM(b))
return 0;
- for(i=0; i<a->nd; i++)
- if (a->dimensions[i] != b->dimensions[i])
+ for(i=0; i<PyArray_NDIM(a); i++)
+ if (PyArray_DIMS(a)[i] != PyArray_DIMS(b)[i])
return 0;
return 1;
}
@@ -1864,11 +1864,11 @@ NA_ShapeLessThan(PyArrayObject *a, PyArrayObject *b)
"NA_ShapeLessThan: non-array as parameter.");
return -1;
}
- mindim = MIN(a->nd, b->nd);
- aoff = a->nd - mindim;
- boff = b->nd - mindim;
+ mindim = MIN(PyArray_NDIM(a), PyArray_NDIM(b));
+ aoff = PyArray_NDIM(a) - mindim;
+ boff = PyArray_NDIM(b) - mindim;
for(i=0; i<mindim; i++)
- if (a->dimensions[i+aoff] >= b->dimensions[i+boff])
+ if (PyArray_DIMS(a)[i+aoff] >= PyArray_DIMS(b)[i+boff])
return 0;
return 1;
}
@@ -2065,7 +2065,7 @@ getShape(PyObject *a, maybelong *shape, int dims)
}
if (!PySequence_Check(a) ||
- (NA_NDArrayCheck(a) && (PyArray(a)->nd == 0)))
+ (NA_NDArrayCheck(a) && (PyArray_NDIM(PyArray(a)) == 0)))
return dims;
slen = PySequence_Length(a);
if (slen < 0) {
@@ -2109,13 +2109,13 @@ setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, long offset)
SequenceConstraint mustbe = NOTHING;
int i, seqlen=-1, slen = PySequence_Length(s);
- if (dim > a->nd) {
+ if (dim > PyArray_NDIM(a)) {
PyErr_Format(PyExc_ValueError,
"setArrayFromSequence: sequence/array dimensions mismatch.");
return -1;
}
- if (slen != a->dimensions[dim]) {
+ if (slen != PyArray_DIMS(a)[dim]) {
PyErr_Format(PyExc_ValueError,
"setArrayFromSequence: sequence/array shape mismatch.");
return -1;
@@ -2128,7 +2128,7 @@ setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, long offset)
"setArrayFromSequence: Can't get a sequence item");
return -1;
} else if ((NA_isPythonScalar(o) ||
- (NA_NumArrayCheck(o) && PyArray(o)->nd == 0)) &&
+ (NA_NumArrayCheck(o) && PyArray_NDIM(PyArray(o)) == 0)) &&
((mustbe == NOTHING) || (mustbe == NUMBER))) {
if (NA_setFromPythonScalar(a, offset, o) < 0)
return -2;
@@ -2160,7 +2160,7 @@ setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, long offset)
return -6;
}
Py_DECREF(o);
- offset += a->strides[dim];
+ offset += PyArray_STRIDES(a)[dim];
}
return 0;
}
@@ -2205,7 +2205,7 @@ _NA_maxType(PyObject *seq, int limit)
return -1;
}
if (NA_NumArrayCheck(seq)) {
- switch(PyArray(seq)->descr->type_num) {
+ switch(PyArray_DESCR(PyArray(seq))->type_num) {
case tBool:
return BOOL_SCALAR;
case tInt8:
@@ -2308,7 +2308,7 @@ NA_isPythonScalar(PyObject *o)
static PyObject *
NA_getPythonScalar(PyArrayObject *a, long offset)
{
- int type = a->descr->type_num;
+ int type = PyArray_DESCR(a)->type_num;
PyObject *rval = NULL;
switch(type) {
@@ -2361,9 +2361,9 @@ NA_getPythonScalar(PyArrayObject *a, long offset)
static int
NA_overflow(PyArrayObject *a, Float64 v)
{
- if ((a->flags & CHECKOVERFLOW) == 0) return 0;
+ if ((PyArray_FLAGS(a) & CHECKOVERFLOW) == 0) return 0;
- switch(a->descr->type_num) {
+ switch(PyArray_DESCR(a)->type_num) {
case tBool:
return 0;
case tInt8:
@@ -2408,7 +2408,7 @@ NA_overflow(PyArrayObject *a, Float64 v)
default:
PyErr_Format( PyExc_TypeError,
"Unknown type %d in NA_overflow",
- a->descr->type_num );
+ PyArray_DESCR(a)->type_num );
PyErr_Print();
return -1;
}
@@ -2431,11 +2431,11 @@ _setFromPythonScalarCore(PyArrayObject *a, long offset, PyObject*value, int entr
return -1;
NA_set_Int64(a, offset, v);
} else if (PyLong_Check(value)) {
- if (a->descr->type_num == tInt64) {
+ if (PyArray_DESCR(a)->type_num == tInt64) {
v = (Int64) PyLong_AsLongLong( value );
- } else if (a->descr->type_num == tUInt64) {
+ } else if (PyArray_DESCR(a)->type_num == tUInt64) {
v = (UInt64) PyLong_AsUnsignedLongLong( value );
- } else if (a->descr->type_num == tUInt32) {
+ } else if (PyArray_DESCR(a)->type_num == tUInt32) {
v = PyLong_AsUnsignedLong(value);
} else {
v = PyLong_AsLongLong(value);
@@ -2461,7 +2461,7 @@ _setFromPythonScalarCore(PyArrayObject *a, long offset, PyObject*value, int entr
NA_set_Complex64(a, offset, vc);
} else if (PyObject_HasAttrString(value, "__tonumtype__")) {
int rval;
- PyObject *type = NA_typeNoToTypeObject(a->descr->type_num);
+ PyObject *type = NA_typeNoToTypeObject(PyArray_DESCR(a)->type_num);
if (!type) return -1;
value = PyObject_CallMethod(
value, "__tonumtype__", "(N)", type);
@@ -2514,7 +2514,7 @@ NA_ComplexArrayCheck(PyObject *a)
int rval = NA_NumArrayCheck(a);
if (rval > 0) {
PyArrayObject *arr = (PyArrayObject *) a;
- switch(arr->descr->type_num) {
+ switch(PyArray_DESCR(arr)->type_num) {
case tComplex64: case tComplex32:
return 1;
default:
@@ -2529,8 +2529,8 @@ NA_elements(PyArrayObject *a)
{
int i;
unsigned long n = 1;
- for(i = 0; i<a->nd; i++)
- n *= a->dimensions[i];
+ for(i = 0; i<PyArray_NDIM(a); i++)
+ n *= PyArray_DIMS(a)[i];
return n;
}
@@ -2731,25 +2731,25 @@ NA_swapAxes(PyArrayObject *array, int x, int y)
if (((PyObject *) array) == Py_None) return 0;
- if (array->nd < 2) return 0;
+ if (PyArray_NDIM(array) < 2) return 0;
- if (x < 0) x += array->nd;
- if (y < 0) y += array->nd;
+ if (x < 0) x += PyArray_NDIM(array);
+ if (y < 0) y += PyArray_NDIM(array);
- if ((x < 0) || (x >= array->nd) ||
- (y < 0) || (y >= array->nd)) {
+ if ((x < 0) || (x >= PyArray_NDIM(array)) ||
+ (y < 0) || (y >= PyArray_NDIM(array))) {
PyErr_Format(PyExc_ValueError,
"Specified dimension does not exist");
return -1;
}
- temp = array->dimensions[x];
- array->dimensions[x] = array->dimensions[y];
- array->dimensions[y] = temp;
+ temp = PyArray_DIMS(array)[x];
+ PyArray_DIMS(array)[x] = PyArray_DIMS(array)[y];
+ PyArray_DIMS(array)[y] = temp;
- temp = array->strides[x];
- array->strides[x] = array->strides[y];
- array->strides[y] = temp;
+ temp = PyArray_STRIDES(array)[x];
+ PyArray_STRIDES(array)[x] = PyArray_STRIDES(array)[y];
+ PyArray_STRIDES(array)[y] = temp;
PyArray_UpdateFlags(array, NPY_ARRAY_UPDATE_ALL);
@@ -2921,7 +2921,7 @@ NA_getArrayData(PyArrayObject *obj)
PyErr_Format(PyExc_TypeError,
"expected an NDArray");
}
- return obj->data;
+ return PyArray_DATA(obj);
}
/* Byteswap is not a flag of the array --- it is implicit in the data-type */
View
70 numpy/numarray/include/numpy/nummacro.h
@@ -87,15 +87,15 @@ typedef enum
/* from here down, type("ai") is NDInfo* */
#define NA_PTR(ai) ((char *) NA_OFFSETDATA((ai)))
-#define NA_PTR1(ai, i) (NA_PTR(ai) + \
- (i)*(ai)->strides[0])
-#define NA_PTR2(ai, i, j) (NA_PTR(ai) + \
- (i)*(ai)->strides[0] + \
- (j)*(ai)->strides[1])
-#define NA_PTR3(ai, i, j, k) (NA_PTR(ai) + \
- (i)*(ai)->strides[0] + \
- (j)*(ai)->strides[1] + \
- (k)*(ai)->strides[2])
+#define NA_PTR1(ai, i) (NA_PTR(ai) + \
+ (i)*PyArray_STRIDES(ai)[0])
+#define NA_PTR2(ai, i, j) (NA_PTR(ai) + \
+ (i)*PyArray_STRIDES(ai)[0] + \
+ (j)*PyArray_STRIDES(ai)[1])
+#define NA_PTR3(ai, i, j, k) (NA_PTR(ai) + \
+ (i)*PyArray_STRIDES(ai)[0] + \
+ (j)*PyArray_STRIDES(ai)[1] + \
+ (k)*PyArray_STRIDES(ai)[2])
#define NA_SET_TEMP(ai, type, v) (((type *) &__temp__)[0] = v)
@@ -238,10 +238,10 @@ _makeSetPa(Bool)
/* fast (aligned, !byteswapped) */
#define NA_GETPf(ai, type, ptr) (*((type *) (ptr)))
-#define NA_GETP(ai, type, ptr) \
- (PyArray_ISCARRAY(ai) ? NA_GETPf(ai, type, ptr) \
- : (PyArray_ISBYTESWAPPED(ai) ? \
- NA_GETPb(ai, type, ptr) \
+#define NA_GETP(ai, type, ptr) \
+ (PyArray_ISCARRAY(ai) ? NA_GETPf(ai, type, ptr) \
+ : (PyArray_ISBYTESWAPPED(ai) ? \
+ NA_GETPb(ai, type, ptr) \
: NA_GETPa(ai, type, ptr)))
/* NOTE: NA_SET* macros cannot be used as values. */
@@ -255,12 +255,12 @@ _makeSetPa(Bool)
/* fast (aligned, !byteswapped) */
#define NA_SETPf(ai, type, ptr, v) ((*((type *) ptr)) = (v))
-#define NA_SETP(ai, type, ptr, v) \
- if (PyArray_ISCARRAY(ai)) { \
- NA_SETPf((ai), type, (ptr), (v)); \
- } else if (PyArray_ISBYTESWAPPED(ai)) { \
- NA_SETPb((ai), type, (ptr), (v)); \
- } else \
+#define NA_SETP(ai, type, ptr, v) \
+ if (PyArray_ISCARRAY(ai)) { \
+ NA_SETPf((ai), type, (ptr), (v)); \
+ } else if (PyArray_ISBYTESWAPPED(ai)) { \
+ NA_SETPb((ai), type, (ptr), (v)); \
+ } else \
NA_SETPa((ai), type, (ptr), (v))
/* ========================== 1 index get/set ============================ */
@@ -315,29 +315,29 @@ _makeSetPa(Bool)
#define NA_GET3(ai, type, i, j, k) NA_GETP(ai, type, NA_PTR3(ai, i, j, k))
/* byteswapping */
-#define NA_SET3b(ai, type, i, j, k, v) \
+#define NA_SET3b(ai, type, i, j, k, v) \
NA_SETPb(ai, type, NA_PTR3(ai, i, j, k), v)
/* aligning */
-#define NA_SET3a(ai, type, i, j, k, v) \
+#define NA_SET3a(ai, type, i, j, k, v) \
NA_SETPa(ai, type, NA_PTR3(ai, i, j, k), v)
/* fast (aligned, !byteswapped) */
-#define NA_SET3f(ai, type, i, j, k, v) \
+#define NA_SET3f(ai, type, i, j, k, v) \
NA_SETPf(ai, type, NA_PTR3(ai, i, j, k), v)
-#define NA_SET3(ai, type, i, j, k, v) \
+#define NA_SET3(ai, type, i, j, k, v) \
NA_SETP(ai, type, NA_PTR3(ai, i, j, k), v)
/* ========================== 1D get/set ================================== */
-#define NA_GET1Db(ai, type, base, cnt, out) \
- { int i, stride = ai->strides[ai->nd-1]; \
- for(i=0; i<cnt; i++) { \
- out[i] = NA_GETPb(ai, type, base); \
- base += stride; \
- } \
+#define NA_GET1Db(ai, type, base, cnt, out) \
+ { int i, stride = PyArray_STRIDES(ai)[PyArray_NDIM(ai)-1]; \
+ for(i=0; i<cnt; i++) { \
+ out[i] = NA_GETPb(ai, type, base); \
+ base += stride; \
+ } \
}
#define NA_GET1Da(ai, type, base, cnt, out) \
- { int i, stride = ai->strides[ai->nd-1]; \
+ { int i, stride = PyArray_STRIDES(ai)[PyArray_NDIM(ai)-1]; \
for(i=0; i<cnt; i++) { \
out[i] = NA_GETPa(ai, type, base); \
base += stride; \
@@ -345,7 +345,7 @@ _makeSetPa(Bool)
}
#define NA_GET1Df(ai, type, base, cnt, out) \
- { int i, stride = ai->strides[ai->nd-1]; \
+ { int i, stride = PyArray_STRIDES(ai)[PyArray_NDIM(ai)-1]; \
for(i=0; i<cnt; i++) { \
out[i] = NA_GETPf(ai, type, base); \
base += stride; \
@@ -362,7 +362,7 @@ _makeSetPa(Bool)
}
#define NA_SET1Db(ai, type, base, cnt, in) \
- { int i, stride = ai->strides[ai->nd-1]; \
+ { int i, stride = PyArray_STRIDES(ai)[PyArray_NDIM(ai)-1]; \
for(i=0; i<cnt; i++) { \
NA_SETPb(ai, type, base, in[i]); \
base += stride; \
@@ -370,7 +370,7 @@ _makeSetPa(Bool)
}
#define NA_SET1Da(ai, type, base, cnt, in) \
- { int i, stride = ai->strides[ai->nd-1]; \
+ { int i, stride = PyArray_STRIDES(ai)[PyArray_NDIM(ai)-1]; \
for(i=0; i<cnt; i++) { \
NA_SETPa(ai, type, base, in[i]); \
base += stride; \
@@ -378,7 +378,7 @@ _makeSetPa(Bool)
}
#define NA_SET1Df(ai, type, base, cnt, in) \
- { int i, stride = ai->strides[ai->nd-1]; \
+ { int i, stride = PyArray_STRIDES(ai)[PyArray_NDIM(ai)-1]; \
for(i=0; i<cnt; i++) { \
NA_SETPf(ai, type, base, in[i]); \
base += stride; \
@@ -412,7 +412,7 @@ _makeSetPa(Bool)
#define BOOLEAN_BITWISE_NOT(x) ((x) ^ 1)
-#define NA_NBYTES(a) (a->descr->elsize * NA_elements(a))
+#define NA_NBYTES(a) (PyArray_DESCR(a)->elsize * NA_elements(a))
#if defined(NA_SMP)
#define BEGIN_THREADS Py_BEGIN_ALLOW_THREADS
Please sign in to comment.
Something went wrong with that request. Please try again.