Skip to content

Commit

Permalink
Remove PyArrayMapIter_Type from user space.
Browse files Browse the repository at this point in the history
  • Loading branch information
teoliphant committed Nov 7, 2005
1 parent 12a01c1 commit 183f6fc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 70 deletions.
6 changes: 2 additions & 4 deletions scipy/base/code_generators/generate_array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@

# API fixes for __arrayobject_api.h

fixed = 5
fixed = 4
numtypes = len(types) + fixed
numobject = len(objectapi_list) + numtypes
nummulti = len(multiapi_list)
Expand Down Expand Up @@ -642,8 +642,7 @@
#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[0])
#define PyArray_Type (*(PyTypeObject *)PyArray_API[1])
#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[2])
#define PyArrayMapIter_Type (*(PyTypeObject *)PyArray_API[3])
#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[4])
#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[3])
%s
Expand Down Expand Up @@ -686,7 +685,6 @@
(void *) &PyBigArray_Type,
(void *) &PyArray_Type,
(void *) &PyArrayIter_Type,
(void *) &PyArrayMapIter_Type,
(int *) &PyArray_NUMUSERTYPES,
%s
};
Expand Down
4 changes: 0 additions & 4 deletions scipy/base/include/scipy/arrayobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -1079,10 +1079,6 @@ typedef struct {
} PyArrayMapIterObject;


/* Map Iterator API */
#define PyArrayMapIter_Check(op) PyObject_TypeCheck(op, &PyArrayMapIter_Type)


#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)
#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \
PyArray_CHKFLAGS(m, FORTRAN))
Expand Down
87 changes: 27 additions & 60 deletions scipy/base/src/arrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ PyArray_ToList(PyArrayObject *self)
PyErr_SetString(PyExc_RuntimeError,
"array_item not returning smaller-" \
"dimensional array");
Py_DECREF(v);
Py_DECREF(lp);
return NULL;
}
Expand Down Expand Up @@ -1709,27 +1710,16 @@ array_subscript(PyArrayObject *self, PyObject *op)
}
}

if (PyArrayMapIter_Check(op)) {
mit = (PyArrayMapIterObject *)op;
/* bind to current array */
PyArray_MapIterBind(mit, self);

/* If the mapiterator was created with standard indexing
behavior, fall through to view-based code */
if (!mit->view) return PyArray_GetMap(mit);
op = mit->indexobj;
}
else { /* wrap arguments into a mapiter object */
mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);
if (mit == NULL) return NULL;
if (!mit->view) { /* fancy indexing */
PyArray_MapIterBind(mit, self);
other = (PyArrayObject *)PyArray_GetMap(mit);
Py_DECREF(mit);
return (PyObject *)other;
}
Py_DECREF(mit);
}
/* wrap arguments into a mapiter object */
mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op);
if (mit == NULL) return NULL;
if (!mit->view) { /* fancy indexing */
PyArray_MapIterBind(mit, self);
other = (PyArrayObject *)PyArray_GetMap(mit);
Py_DECREF(mit);
return (PyObject *)other;
}
Py_DECREF(mit);

i = PyArray_PyIntAsIntp(op);
if (!error_converting(i)) {
Expand Down Expand Up @@ -1805,26 +1795,15 @@ array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)
}


if (PyArrayMapIter_Check(index)) {
mit = (PyArrayMapIterObject *)index;
/* bind behavior to current array */
PyArray_MapIterBind(mit, self);

/* fall through if standard view-based map iterator */
if (!mit->view) return PyArray_SetMap(mit, op);
index = mit->indexobj;
}
else {
mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);
if (mit == NULL) return -1;
if (!mit->view) {
PyArray_MapIterBind(mit, self);
ret = PyArray_SetMap(mit, op);
Py_DECREF(mit);
return ret;
}
Py_DECREF(mit);
}
mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index);
if (mit == NULL) return -1;
if (!mit->view) {
PyArray_MapIterBind(mit, self);
ret = PyArray_SetMap(mit, op);
Py_DECREF(mit);
return ret;
}
Py_DECREF(mit);

i = PyArray_PyIntAsIntp(index);
if (!error_converting(i)) {
Expand Down Expand Up @@ -2137,44 +2116,32 @@ PyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,
static PyObject *
PyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)
{
PyObject *args, *ret;
if (op == NULL) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
args = Py_BuildValue("(OO)", m1, m2);
ret = PyObject_Call(op, args, NULL);
Py_DECREF(args);
return ret;
return PyObject_CallFunction(op, "OO", m1, m2);
}

static PyObject *
PyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)
{
PyObject *args, *ret;
if (op == NULL) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
args = Py_BuildValue("(O)", m1);
ret = PyObject_Call(op, args, NULL);
Py_DECREF(args);
return ret;
return PyObject_CallFunction(op, "(O)", m1);
}

static PyObject *
PyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,
PyObject *m2, PyObject *op)
{
PyObject *args, *ret;
if (op == NULL) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
args = Py_BuildValue("(OOO)", m1, m2, m1);
ret = PyObject_Call(op, args, NULL);
Py_DECREF(args);
return ret;
return PyObject_CallFunction(op, "OOO", m1, m2, m1);
}

static PyObject *
Expand Down Expand Up @@ -5223,7 +5190,6 @@ array_fromarray(PyArrayObject *arr, PyArray_Typecode *typecode, int flags)
arr->flags,NULL);
if (ret == NULL) return NULL;
ret->base = (PyObject *)arr;
ret->flags &= ~UPDATEIFCOPY;
}
else {
ret = arr;
Expand Down Expand Up @@ -5749,7 +5715,7 @@ PyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth,
}
/* Ensure that type->fortran and flags & FORTRAN are the
same */
if (requires & FORTRAN) typecode->fortran = 1;
if (requires & FORTRAN) type->fortran = 1;
if (type->fortran == 1) {
requires |= FARRAY_FLAGS;
if (min_depth > 2) requires &= ~CONTIGUOUS;
Expand Down Expand Up @@ -6250,8 +6216,9 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
else if (PyArray_ISINTEGER(obj)) {
PyObject *new;
new = PyArray_FromAny(obj, &indtype, 0, 0,
FORCECAST | BEHAVED_FLAGS);
FORCECAST | BEHAVED_FLAGS_RO);
if (new==NULL) goto fail;
Py_DECREF(obj);
obj = new;
r = iter_subscript_int(self, (PyArrayObject *)obj);
}
Expand Down Expand Up @@ -7283,8 +7250,8 @@ arraymapiter_dealloc(PyArrayMapIterObject *mit)
{
int i;
PyObject_GC_UnTrack(mit);
Py_XDECREF(mit->ait);
Py_XDECREF(mit->indexobj);
Py_XDECREF(mit->ait);
Py_XDECREF(mit->subspace);
for (i=0; i<mit->numiter; i++)
Py_XDECREF(mit->iters[i]);
Expand Down
2 changes: 0 additions & 2 deletions scipy/base/src/scalartypes.inc.src
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,6 @@ static PyTypeObject Py@NAME@ArrType_Type = {
/**end repeat**/




static PyNumberMethods longdoubletype_as_number;
static PyNumberMethods clongdoubletype_as_number;

Expand Down

0 comments on commit 183f6fc

Please sign in to comment.