Permalink
Browse files

ENH: core: More cleanups removing direct PyArrayObject field access

  • Loading branch information...
1 parent db90bf5 commit 57d6b5bebb039dc6b2b3c5a2cc7bfc8e2cc3fb98 Mark Wiebe committed Jul 18, 2011
@@ -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);
@@ -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) {
@@ -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 *
@@ -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;
@@ -61,7 +61,6 @@
/********************/
#define USE_USE_DEFAULTS 1
-#define USE_NEW_ITERATOR_GENFUNC 1
/********************/
/* ---------------------------------------------------------------- */
Oops, something went wrong.

0 comments on commit 57d6b5b

Please sign in to comment.