[Numpy-svn] r2898 - in branches/ver1.0/numpy/core: . src
numpy-svn at scipy.org
numpy-svn at scipy.org
Wed Jul 26 12:25:25 EDT 2006
Author: oliphant
Date: 2006-07-26 11:25:14 -0500 (Wed, 26 Jul 2006)
New Revision: 2898
Modified:
branches/ver1.0/numpy/core/ma.py
branches/ver1.0/numpy/core/src/arrayobject.c
branches/ver1.0/numpy/core/src/arraytypes.inc.src
branches/ver1.0/numpy/core/src/scalartypes.inc.src
Log:
Fix unnecessary use of NULL in scalar_value and remove tabs.
Modified: branches/ver1.0/numpy/core/ma.py
===================================================================
--- branches/ver1.0/numpy/core/ma.py 2006-07-26 12:29:49 UTC (rev 2897)
+++ branches/ver1.0/numpy/core/ma.py 2006-07-26 16:25:14 UTC (rev 2898)
@@ -512,7 +512,7 @@
then the candidate data is data.data and the
mask used is data.mask. If data is a numeric array,
it is used as the candidate raw data.
- If dtype.char is not None and
+ If dtype is not None and
is != data.dtype.char then a data copy is required.
Otherwise, the candidate is used.
Modified: branches/ver1.0/numpy/core/src/arrayobject.c
===================================================================
--- branches/ver1.0/numpy/core/src/arrayobject.c 2006-07-26 12:29:49 UTC (rev 2897)
+++ branches/ver1.0/numpy/core/src/arrayobject.c 2006-07-26 16:25:14 UTC (rev 2898)
@@ -29,8 +29,8 @@
PyObject *ret;
double priority=PyArray_PRIORITY;
- if (PyArray_CheckExact(obj))
- return priority;
+ if (PyArray_CheckExact(obj))
+ return priority;
ret = PyObject_GetAttrString(obj, "__array_priority__");
if (ret != NULL) priority = PyFloat_AsDouble(ret);
@@ -45,11 +45,11 @@
static int
_check_object_rec(PyArray_Descr *descr)
{
- if (descr->hasobject && !PyDescr_ISOBJECT(descr)) {
- PyErr_SetString(PyExc_TypeError, "Not supported for this data-type.");
- return -1;
- }
- return 0;
+ if (descr->hasobject && !PyDescr_ISOBJECT(descr)) {
+ PyErr_SetString(PyExc_TypeError, "Not supported for this data-type.");
+ return -1;
+ }
+ return 0;
}
/* Backward compatibility only */
@@ -77,28 +77,28 @@
int ret, storeflags;
PyObject *obj;
- if (_check_object_rec(arr->descr) < 0) return NULL;
+ if (_check_object_rec(arr->descr) < 0) return NULL;
zeroval = PyDataMem_NEW(arr->descr->elsize);
if (zeroval == NULL) {
PyErr_SetNone(PyExc_MemoryError);
return NULL;
}
- obj=PyInt_FromLong((long) 0);
+ obj=PyInt_FromLong((long) 0);
if (PyArray_ISOBJECT(arr)) {
memcpy(zeroval, &obj, sizeof(PyObject *));
Py_DECREF(obj);
return zeroval;
}
- storeflags = arr->flags;
- arr->flags |= BEHAVED;
+ storeflags = arr->flags;
+ arr->flags |= BEHAVED;
ret = arr->descr->f->setitem(obj, zeroval, arr);
- arr->flags = storeflags;
- Py_DECREF(obj);
- if (ret < 0) {
- PyDataMem_FREE(zeroval);
- return NULL;
- }
+ arr->flags = storeflags;
+ Py_DECREF(obj);
+ if (ret < 0) {
+ PyDataMem_FREE(zeroval);
+ return NULL;
+ }
return zeroval;
}
@@ -112,7 +112,7 @@
int ret, storeflags;
PyObject *obj;
- if (_check_object_rec(arr->descr) < 0) return NULL;
+ if (_check_object_rec(arr->descr) < 0) return NULL;
oneval = PyDataMem_NEW(arr->descr->elsize);
if (oneval == NULL) {
PyErr_SetNone(PyExc_MemoryError);
@@ -126,10 +126,10 @@
return oneval;
}
- storeflags = arr->flags;
- arr->flags |= BEHAVED;
+ storeflags = arr->flags;
+ arr->flags |= BEHAVED;
ret = arr->descr->f->setitem(obj, oneval, arr);
- arr->flags = storeflags;
+ arr->flags = storeflags;
Py_DECREF(obj);
if (ret < 0) {
PyDataMem_FREE(oneval);
@@ -164,8 +164,8 @@
PyArray_Descr *new;
int offset, pos=0;
while (PyDict_Next(descr->fields, &pos, &key, &value)) {
- if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
- &title)) return;
+ if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
+ &title)) return;
PyArray_Item_INCREF(data + offset, new);
}
}
@@ -191,8 +191,8 @@
PyArray_Descr *new;
int offset, pos=0;
while (PyDict_Next(descr->fields, &pos, &key, &value)) {
- if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
- &title)) return;
+ if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
+ &title)) return;
PyArray_Item_XDECREF(data + offset, new);
}
}
@@ -209,7 +209,7 @@
static int
PyArray_INCREF(PyArrayObject *mp)
{
- intp i, n;
+ intp i, n;
PyObject **data, **temp;
PyArrayIterObject *it;
@@ -305,37 +305,37 @@
static void
_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides,
- intp N, int elsize)
+ intp N, int elsize)
{
intp i, j;
char *tout = dst;
char *tin = src;
-#define _FAST_MOVE(_type_) \
- for (i=0; i<N; i++) { \
- ((_type_ *)tout)[0] = ((_type_ *)tin)[0]; \
- tin += instrides; \
- tout += outstrides; \
- } \
- return
-
+#define _FAST_MOVE(_type_) \
+ for (i=0; i<N; i++) { \
+ ((_type_ *)tout)[0] = ((_type_ *)tin)[0]; \
+ tin += instrides; \
+ tout += outstrides; \
+ } \
+ return
+
switch(elsize) {
case 8:
- _FAST_MOVE(Float64);
+ _FAST_MOVE(Float64);
case 4:
- _FAST_MOVE(Int32);
- case 1:
- _FAST_MOVE(Int8);
+ _FAST_MOVE(Int32);
+ case 1:
+ _FAST_MOVE(Int8);
case 2:
- _FAST_MOVE(Int16);
- case 16:
+ _FAST_MOVE(Int16);
+ case 16:
for (i=0; i<N; i++) {
((Float64 *)tout)[0] = ((Float64 *)tin)[0];
((Float64 *)tout)[1] = ((Float64 *)tin)[1];
tin += instrides;
tout += outstrides;
}
- return;
+ return;
default:
for (i=0; i<N; i++) {
for (j=0; j<elsize; j++) {
@@ -348,38 +348,38 @@
#undef _FAST_MOVE
}
-
+
static void
_unaligned_strided_byte_move(char *dst, intp outstrides, char *src,
- intp instrides, intp N, int elsize)
+ intp instrides, intp N, int elsize)
{
intp i;
char *tout = dst;
char *tin = src;
-#define _MOVE_N_SIZE(size) \
- for (i=0; i<N; i++) { \
- memmove(tout, tin, size); \
- tin += instrides; \
- tout += outstrides; \
- } \
- return
-
+#define _MOVE_N_SIZE(size) \
+ for (i=0; i<N; i++) { \
+ memmove(tout, tin, size); \
+ tin += instrides; \
+ tout += outstrides; \
+ } \
+ return
+
switch(elsize) {
case 8:
- _MOVE_N_SIZE(8);
+ _MOVE_N_SIZE(8);
case 4:
- _MOVE_N_SIZE(4);
- case 1:
- _MOVE_N_SIZE(1);
+ _MOVE_N_SIZE(4);
+ case 1:
+ _MOVE_N_SIZE(1);
case 2:
- _MOVE_N_SIZE(2);
- case 16:
- _MOVE_N_SIZE(16);
+ _MOVE_N_SIZE(2);
+ case 16:
+ _MOVE_N_SIZE(16);
default:
- _MOVE_N_SIZE(elsize);
+ _MOVE_N_SIZE(elsize);
}
#undef _MOVE_N_SIZE
@@ -387,33 +387,33 @@
static void
_unaligned_strided_byte_copy(char *dst, intp outstrides, char *src,
- intp instrides, intp N, int elsize)
+ intp instrides, intp N, int elsize)
{
intp i;
char *tout = dst;
char *tin = src;
-#define _COPY_N_SIZE(size) \
- for (i=0; i<N; i++) { \
- memcpy(tout, tin, size); \
- tin += instrides; \
- tout += outstrides; \
- } \
- return
+#define _COPY_N_SIZE(size) \
+ for (i=0; i<N; i++) { \
+ memcpy(tout, tin, size); \
+ tin += instrides; \
+ tout += outstrides; \
+ } \
+ return
switch(elsize) {
case 8:
- _COPY_N_SIZE(8);
+ _COPY_N_SIZE(8);
case 4:
- _COPY_N_SIZE(4);
- case 1:
- _COPY_N_SIZE(1);
+ _COPY_N_SIZE(4);
+ case 1:
+ _COPY_N_SIZE(1);
case 2:
- _COPY_N_SIZE(2);
- case 16:
- _COPY_N_SIZE(16);
+ _COPY_N_SIZE(2);
+ case 16:
+ _COPY_N_SIZE(16);
default:
- _COPY_N_SIZE(elsize);
+ _COPY_N_SIZE(elsize);
}
#undef _COPY_N_SIZE
@@ -422,9 +422,9 @@
static void
_strided_byte_swap(void *p, intp stride, intp n, int size)
{
- char *a, *b, c=0;
+ char *a, *b, c=0;
int j,m;
-
+
switch(size) {
case 1: /* no byteswap necessary */
break;
@@ -456,7 +456,7 @@
b = a + (size-1);
for (j=0; j<m; j++) {
c=*a; *a++ = *b; *b-- = c;
- }
+ }
}
break;
}
@@ -465,8 +465,8 @@
static void
byte_swap_vector(void *p, intp n, int size)
{
- _strided_byte_swap(p, (intp) size, n, size);
- return;
+ _strided_byte_swap(p, (intp) size, n, size);
+ return;
}
/* If numitems > 1, then dst must be contiguous */
@@ -501,7 +501,7 @@
static PyArray_Descr **userdescrs=NULL;
#define error_converting(x) (((x) == -1) && PyErr_Occurred())
-
+
/* Computer-generated arraytype and scalartype code */
#include "scalartypes.inc"
@@ -514,86 +514,86 @@
static intp
PyArray_PyIntAsIntp(PyObject *o)
{
- longlong long_value = -1;
- PyObject *obj;
- static char *msg = "an integer is required";
- PyObject *arr;
- PyArray_Descr *descr;
- intp ret;
+ longlong long_value = -1;
+ PyObject *obj;
+ static char *msg = "an integer is required";
+ PyObject *arr;
+ PyArray_Descr *descr;
+ intp ret;
- if (!o) {
- PyErr_SetString(PyExc_TypeError, msg);
- return -1;
- }
+ if (!o) {
+ PyErr_SetString(PyExc_TypeError, msg);
+ return -1;
+ }
- if (PyInt_Check(o)) {
- long_value = (longlong) PyInt_AS_LONG(o);
- goto finish;
- } else if (PyLong_Check(o)) {
- long_value = (longlong) PyLong_AsLongLong(o);
- goto finish;
- }
+ if (PyInt_Check(o)) {
+ long_value = (longlong) PyInt_AS_LONG(o);
+ goto finish;
+ } else if (PyLong_Check(o)) {
+ long_value = (longlong) PyLong_AsLongLong(o);
+ goto finish;
+ }
#if SIZEOF_INTP == SIZEOF_LONG
- descr = &LONG_Descr;
+ descr = &LONG_Descr;
#elif SIZEOF_INTP == SIZEOF_INT
- descr = &INT_Descr;
+ descr = &INT_Descr;
#else
- descr = &LONGLONG_Descr;
+ descr = &LONGLONG_Descr;
#endif
- arr = NULL;
+ arr = NULL;
- if (PyArray_Check(o)) {
- if (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {
- PyErr_SetString(PyExc_TypeError, msg);
- return -1;
- }
- Py_INCREF(descr);
- arr = PyArray_CastToType((PyArrayObject *)o, descr, 0);
- }
- else if (PyArray_IsScalar(o, Integer)) {
- Py_INCREF(descr);
- arr = PyArray_FromScalar(o, descr);
- }
- if (arr != NULL) {
- ret = *((intp *)PyArray_DATA(arr));
- Py_DECREF(arr);
- return ret;
- }
- if (o->ob_type->tp_as_number != NULL && \
- o->ob_type->tp_as_number->nb_long != NULL) {
- obj = o->ob_type->tp_as_number->nb_long(o);
- if (obj != NULL) {
- long_value = (longlong) PyLong_AsLongLong(obj);
- Py_DECREF(obj);
- }
- }
- else if (o->ob_type->tp_as_number != NULL && \
- o->ob_type->tp_as_number->nb_int != NULL) {
- obj = o->ob_type->tp_as_number->nb_int(o);
- if (obj != NULL) {
- long_value = (longlong) PyLong_AsLongLong(obj);
- Py_DECREF(obj);
- }
- }
- else {
- PyErr_SetString(PyExc_NotImplementedError,"");
- }
+ if (PyArray_Check(o)) {
+ if (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {
+ PyErr_SetString(PyExc_TypeError, msg);
+ return -1;
+ }
+ Py_INCREF(descr);
+ arr = PyArray_CastToType((PyArrayObject *)o, descr, 0);
+ }
+ else if (PyArray_IsScalar(o, Integer)) {
+ Py_INCREF(descr);
+ arr = PyArray_FromScalar(o, descr);
+ }
+ if (arr != NULL) {
+ ret = *((intp *)PyArray_DATA(arr));
+ Py_DECREF(arr);
+ return ret;
+ }
+ if (o->ob_type->tp_as_number != NULL && \
+ o->ob_type->tp_as_number->nb_long != NULL) {
+ obj = o->ob_type->tp_as_number->nb_long(o);
+ if (obj != NULL) {
+ long_value = (longlong) PyLong_AsLongLong(obj);
+ Py_DECREF(obj);
+ }
+ }
+ else if (o->ob_type->tp_as_number != NULL && \
+ o->ob_type->tp_as_number->nb_int != NULL) {
+ obj = o->ob_type->tp_as_number->nb_int(o);
+ if (obj != NULL) {
+ long_value = (longlong) PyLong_AsLongLong(obj);
+ Py_DECREF(obj);
+ }
+ }
+ else {
+ PyErr_SetString(PyExc_NotImplementedError,"");
+ }
finish:
- if error_converting(long_value) {
- PyErr_SetString(PyExc_TypeError, msg);
- return -1;
- }
+ if error_converting(long_value) {
+ PyErr_SetString(PyExc_TypeError, msg);
+ return -1;
+ }
#if (SIZEOF_LONGLONG > SIZEOF_INTP)
- if ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {
- PyErr_SetString(PyExc_ValueError,
- "integer won't fit into a C intp");
- return -1;
- }
+ if ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {
+ PyErr_SetString(PyExc_ValueError,
+ "integer won't fit into a C intp");
+ return -1;
+ }
#endif
- return (intp) long_value;
+ return (intp) long_value;
}
@@ -603,94 +603,94 @@
static int
PyArray_PyIntAsInt(PyObject *o)
{
- long long_value = -1;
- PyObject *obj;
- static char *msg = "an integer is required";
- PyObject *arr;
- PyArray_Descr *descr;
- int ret;
+ long long_value = -1;
+ PyObject *obj;
+ static char *msg = "an integer is required";
+ PyObject *arr;
+ PyArray_Descr *descr;
+ int ret;
- if (!o) {
- PyErr_SetString(PyExc_TypeError, msg);
- return -1;
- }
+ if (!o) {
+ PyErr_SetString(PyExc_TypeError, msg);
+ return -1;
+ }
- if (PyInt_Check(o)) {
- long_value = (long) PyInt_AS_LONG(o);
- goto finish;
- } else if (PyLong_Check(o)) {
- long_value = (long) PyLong_AsLong(o);
- goto finish;
- }
+ if (PyInt_Check(o)) {
+ long_value = (long) PyInt_AS_LONG(o);
+ goto finish;
+ } else if (PyLong_Check(o)) {
+ long_value = (long) PyLong_AsLong(o);
+ goto finish;
+ }
- descr = &INT_Descr;
- arr=NULL;
- if (PyArray_Check(o)) {
- if (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {
- PyErr_SetString(PyExc_TypeError, msg);
- return -1;
- }
- Py_INCREF(descr);
- arr = PyArray_CastToType((PyArrayObject *)o, descr, 0);
- }
- if (PyArray_IsScalar(o, Integer)) {
- Py_INCREF(descr);
- arr = PyArray_FromScalar(o, descr);
- }
- if (arr != NULL) {
- ret = *((int *)PyArray_DATA(arr));
- Py_DECREF(arr);
- return ret;
- }
- if (o->ob_type->tp_as_number != NULL && \
- o->ob_type->tp_as_number->nb_int != NULL) {
- obj = o->ob_type->tp_as_number->nb_int(o);
- if (obj == NULL) return -1;
- long_value = (long) PyLong_AsLong(obj);
- Py_DECREF(obj);
- }
- else if (o->ob_type->tp_as_number != NULL && \
- o->ob_type->tp_as_number->nb_long != NULL) {
- obj = o->ob_type->tp_as_number->nb_long(o);
- if (obj == NULL) return -1;
- long_value = (long) PyLong_AsLong(obj);
- Py_DECREF(obj);
- }
- else {
- PyErr_SetString(PyExc_NotImplementedError,"");
- }
+ descr = &INT_Descr;
+ arr=NULL;
+ if (PyArray_Check(o)) {
+ if (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {
+ PyErr_SetString(PyExc_TypeError, msg);
+ return -1;
+ }
+ Py_INCREF(descr);
+ arr = PyArray_CastToType((PyArrayObject *)o, descr, 0);
+ }
+ if (PyArray_IsScalar(o, Integer)) {
+ Py_INCREF(descr);
+ arr = PyArray_FromScalar(o, descr);
+ }
+ if (arr != NULL) {
+ ret = *((int *)PyArray_DATA(arr));
+ Py_DECREF(arr);
+ return ret;
+ }
+ if (o->ob_type->tp_as_number != NULL && \
+ o->ob_type->tp_as_number->nb_int != NULL) {
+ obj = o->ob_type->tp_as_number->nb_int(o);
+ if (obj == NULL) return -1;
+ long_value = (long) PyLong_AsLong(obj);
+ Py_DECREF(obj);
+ }
+ else if (o->ob_type->tp_as_number != NULL && \
+ o->ob_type->tp_as_number->nb_long != NULL) {
+ obj = o->ob_type->tp_as_number->nb_long(o);
+ if (obj == NULL) return -1;
+ long_value = (long) PyLong_AsLong(obj);
+ Py_DECREF(obj);
+ }
+ else {
+ PyErr_SetString(PyExc_NotImplementedError,"");
+ }
finish:
- if error_converting(long_value) {
- PyErr_SetString(PyExc_TypeError, msg);
- return -1;
- }
+ if error_converting(long_value) {
+ PyErr_SetString(PyExc_TypeError, msg);
+ return -1;
+ }
#if (SIZEOF_LONG > SIZEOF_INT)
- if ((long_value < INT_MIN) || (long_value > INT_MAX)) {
- PyErr_SetString(PyExc_ValueError,
- "integer won't fit into a C int");
- return -1;
- }
+ if ((long_value < INT_MIN) || (long_value > INT_MAX)) {
+ PyErr_SetString(PyExc_ValueError,
+ "integer won't fit into a C int");
+ return -1;
+ }
#endif
- return (int) long_value;
+ return (int) long_value;
}
static char *
index2ptr(PyArrayObject *mp, intp i)
{
- intp dim0;
- if(mp->nd == 0) {
- PyErr_SetString(PyExc_IndexError,
- "0-d arrays can't be indexed");
- return NULL;
- }
- dim0 = mp->dimensions[0];
- if (i<0) i += dim0;
- if (i==0 && dim0 > 0)
- return mp->data;
-
+ intp dim0;
+ if(mp->nd == 0) {
+ PyErr_SetString(PyExc_IndexError,
+ "0-d arrays can't be indexed");
+ return NULL;
+ }
+ dim0 = mp->dimensions[0];
+ if (i<0) i += dim0;
+ if (i==0 && dim0 > 0)
+ return mp->data;
+
if (i>0 && i < dim0) {
return mp->data+i*mp->strides[0];
}
@@ -707,7 +707,7 @@
if (PyArray_Check(op)) {
return PyArray_SIZE((PyArrayObject *)op);
}
- else {
+ else {
return 0;
}
}
@@ -715,86 +715,86 @@
static int
_copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap)
{
- char *aligned=NULL;
- char *sptr;
- int numcopies, nbytes;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
- int retval=-1;
+ char *aligned=NULL;
+ char *sptr;
+ int numcopies, nbytes;
+ void (*myfunc)(char *, intp, char *, intp, intp, int);
+ int retval=-1;
NPY_BEGIN_THREADS_DEF
- numcopies = PyArray_SIZE(dest);
- if (numcopies < 1) return 0;
- nbytes = PyArray_ITEMSIZE(src);
+ numcopies = PyArray_SIZE(dest);
+ if (numcopies < 1) return 0;
+ nbytes = PyArray_ITEMSIZE(src);
- if (!PyArray_ISALIGNED(src)) {
- aligned = malloc((size_t)nbytes);
- if (aligned == NULL) {
- PyErr_NoMemory();
- return -1;
- }
- memcpy(aligned, src->data, (size_t) nbytes);
- usecopy = 1;
- sptr = aligned;
- }
- else sptr = src->data;
- if (PyArray_ISALIGNED(dest)) {
- myfunc = _strided_byte_copy;
- }
- else if (usecopy) {
- myfunc = _unaligned_strided_byte_copy;
- }
- else {
- myfunc = _unaligned_strided_byte_move;
- }
+ if (!PyArray_ISALIGNED(src)) {
+ aligned = malloc((size_t)nbytes);
+ if (aligned == NULL) {
+ PyErr_NoMemory();
+ return -1;
+ }
+ memcpy(aligned, src->data, (size_t) nbytes);
+ usecopy = 1;
+ sptr = aligned;
+ }
+ else sptr = src->data;
+ if (PyArray_ISALIGNED(dest)) {
+ myfunc = _strided_byte_copy;
+ }
+ else if (usecopy) {
+ myfunc = _unaligned_strided_byte_copy;
+ }
+ else {
+ myfunc = _unaligned_strided_byte_move;
+ }
- if ((dest->nd < 2) || PyArray_ISONESEGMENT(dest)) {
- char *dptr;
- intp dstride;
+ if ((dest->nd < 2) || PyArray_ISONESEGMENT(dest)) {
+ char *dptr;
+ intp dstride;
- dptr = dest->data;
- if (dest->nd == 1)
- dstride = dest->strides[0];
- else
- dstride = nbytes;
- PyArray_XDECREF(dest);
+ dptr = dest->data;
+ if (dest->nd == 1)
+ dstride = dest->strides[0];
+ else
+ dstride = nbytes;
+ PyArray_XDECREF(dest);
NPY_BEGIN_THREADS
- myfunc(dptr, dstride, sptr, 0, numcopies, (int) nbytes);
- if (swap)
- _strided_byte_swap(dptr, dstride, numcopies, (int) nbytes);
+ myfunc(dptr, dstride, sptr, 0, numcopies, (int) nbytes);
+ if (swap)
+ _strided_byte_swap(dptr, dstride, numcopies, (int) nbytes);
NPY_END_THREADS
- PyArray_INCREF(dest);
- }
- else {
- PyArrayIterObject *dit;
- int axis=-1;
- dit = (PyArrayIterObject *)\
- PyArray_IterAllButAxis((PyObject *)dest, &axis);
- if (dit == NULL) goto finish;
- PyArray_XDECREF(dest);
+ PyArray_INCREF(dest);
+ }
+ else {
+ PyArrayIterObject *dit;
+ int axis=-1;
+ dit = (PyArrayIterObject *)\
+ PyArray_IterAllButAxis((PyObject *)dest, &axis);
+ if (dit == NULL) goto finish;
+ PyArray_XDECREF(dest);
NPY_BEGIN_THREADS
- while(dit->index < dit->size) {
- myfunc(dit->dataptr, PyArray_STRIDE(dest, axis),
- sptr, 0,
- PyArray_DIM(dest, axis), nbytes);
- if (swap)
- _strided_byte_swap(dit->dataptr,
- PyArray_STRIDE(dest, axis),
- PyArray_DIM(dest, axis), nbytes);
- PyArray_ITER_NEXT(dit);
- }
+ while(dit->index < dit->size) {
+ myfunc(dit->dataptr, PyArray_STRIDE(dest, axis),
+ sptr, 0,
+ PyArray_DIM(dest, axis), nbytes);
+ if (swap)
+ _strided_byte_swap(dit->dataptr,
+ PyArray_STRIDE(dest, axis),
+ PyArray_DIM(dest, axis), nbytes);
+ PyArray_ITER_NEXT(dit);
+ }
NPY_END_THREADS
- PyArray_INCREF(dest);
- Py_DECREF(dit);
- }
- retval = 0;
+ PyArray_INCREF(dest);
+ Py_DECREF(dit);
+ }
+ retval = 0;
finish:
- if (aligned != NULL) free(aligned);
- return retval;
+ if (aligned != NULL) free(aligned);
+ return retval;
}
/* Special-case of PyArray_CopyInto when dst is 1-d
@@ -803,164 +803,164 @@
this one is a flattening operation...
*/
int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) {
- PyArrayIterObject *it;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
- char *dptr;
- int axis;
- int elsize;
- intp nbytes;
+ PyArrayIterObject *it;
+ void (*myfunc)(char *, intp, char *, intp, intp, int);
+ char *dptr;
+ int axis;
+ int elsize;
+ intp nbytes;
NPY_BEGIN_THREADS_DEF
- if (PyArray_NDIM(src) == 0) {
- PyArray_XDECREF((PyArrayObject *)dst);
+ if (PyArray_NDIM(src) == 0) {
+ PyArray_XDECREF((PyArrayObject *)dst);
NPY_BEGIN_THREADS
- memcpy(PyArray_BYTES(dst), PyArray_BYTES(src),
- PyArray_ITEMSIZE(src));
- NPY_END_THREADS
- PyArray_INCREF((PyArrayObject *)dst);
- return 0;
- }
+ memcpy(PyArray_BYTES(dst), PyArray_BYTES(src),
+ PyArray_ITEMSIZE(src));
+ NPY_END_THREADS
+ PyArray_INCREF((PyArrayObject *)dst);
+ return 0;
+ }
- if (order == PyArray_FORTRANORDER) {
- axis = 0;
- }
- else {
- axis = PyArray_NDIM(src)-1;
- }
+ if (order == PyArray_FORTRANORDER) {
+ axis = 0;
+ }
+ else {
+ axis = PyArray_NDIM(src)-1;
+ }
- it = (PyArrayIterObject *)PyArray_IterAllButAxis(src, &axis);
- if (it == NULL) return -1;
+ it = (PyArrayIterObject *)PyArray_IterAllButAxis(src, &axis);
+ if (it == NULL) return -1;
- if (PyArray_ISALIGNED(src)) {
- myfunc = _strided_byte_copy;
- }
- else {
- myfunc = _unaligned_strided_byte_copy;
- }
+ if (PyArray_ISALIGNED(src)) {
+ myfunc = _strided_byte_copy;
+ }
+ else {
+ myfunc = _unaligned_strided_byte_copy;
+ }
- dptr = PyArray_BYTES(dst);
- elsize = PyArray_ITEMSIZE(dst);
- nbytes = elsize * PyArray_DIM(src, axis);
- PyArray_XDECREF((PyArrayObject *)dst);
+ dptr = PyArray_BYTES(dst);
+ elsize = PyArray_ITEMSIZE(dst);
+ nbytes = elsize * PyArray_DIM(src, axis);
+ PyArray_XDECREF((PyArrayObject *)dst);
NPY_BEGIN_THREADS
- while(it->index < it->size) {
- myfunc(dptr, elsize, it->dataptr,
- PyArray_STRIDE(src,axis),
- PyArray_DIM(src,axis), elsize);
- dptr += nbytes;
- PyArray_ITER_NEXT(it);
- }
- NPY_END_THREADS
- PyArray_INCREF((PyArrayObject *)dst);
+ while(it->index < it->size) {
+ myfunc(dptr, elsize, it->dataptr,
+ PyArray_STRIDE(src,axis),
+ PyArray_DIM(src,axis), elsize);
+ dptr += nbytes;
+ PyArray_ITER_NEXT(it);
+ }
+ NPY_END_THREADS
+ PyArray_INCREF((PyArrayObject *)dst);
- Py_DECREF(it);
- return 0;
+ Py_DECREF(it);
+ return 0;
}
static int
_copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src,
- void (*myfunc)(char *, intp, char *, intp, intp, int),
- int swap)
+ void (*myfunc)(char *, intp, char *, intp, intp, int),
+ int swap)
{
- int maxaxis=-1, elsize;
- intp maxdim;
- PyArrayIterObject *dit, *sit;
+ int maxaxis=-1, elsize;
+ intp maxdim;
+ PyArrayIterObject *dit, *sit;
NPY_BEGIN_THREADS_DEF
- dit = (PyArrayIterObject *) \
- PyArray_IterAllButAxis((PyObject *)dest, &maxaxis);
- sit = (PyArrayIterObject *) \
- PyArray_IterAllButAxis((PyObject *)src, &maxaxis);
-
- maxdim = dest->dimensions[maxaxis];
-
- if ((dit == NULL) || (sit == NULL)) {
- Py_XDECREF(dit);
- Py_XDECREF(sit);
- return -1;
- }
- elsize = PyArray_ITEMSIZE(dest);
+ dit = (PyArrayIterObject *) \
+ PyArray_IterAllButAxis((PyObject *)dest, &maxaxis);
+ sit = (PyArrayIterObject *) \
+ PyArray_IterAllButAxis((PyObject *)src, &maxaxis);
+
+ maxdim = dest->dimensions[maxaxis];
+
+ if ((dit == NULL) || (sit == NULL)) {
+ Py_XDECREF(dit);
+ Py_XDECREF(sit);
+ return -1;
+ }
+ elsize = PyArray_ITEMSIZE(dest);
- PyArray_XDECREF(dest);
+ PyArray_XDECREF(dest);
NPY_BEGIN_THREADS
- while(dit->index < dit->size) {
- /* strided copy of elsize bytes */
- myfunc(dit->dataptr, dest->strides[maxaxis],
- sit->dataptr, src->strides[maxaxis],
- maxdim, elsize);
- if (swap) {
- _strided_byte_swap(dit->dataptr,
- dest->strides[maxaxis],
- dest->dimensions[maxaxis],
- elsize);
- }
- PyArray_ITER_NEXT(dit);
- PyArray_ITER_NEXT(sit);
- }
- NPY_END_THREADS
+ while(dit->index < dit->size) {
+ /* strided copy of elsize bytes */
+ myfunc(dit->dataptr, dest->strides[maxaxis],
+ sit->dataptr, src->strides[maxaxis],
+ maxdim, elsize);
+ if (swap) {
+ _strided_byte_swap(dit->dataptr,
+ dest->strides[maxaxis],
+ dest->dimensions[maxaxis],
+ elsize);
+ }
+ PyArray_ITER_NEXT(dit);
+ PyArray_ITER_NEXT(sit);
+ }
+ NPY_END_THREADS
- Py_DECREF(sit);
- Py_DECREF(dit);
- PyArray_INCREF(dest);
- return 0;
+ Py_DECREF(sit);
+ Py_DECREF(dit);
+ PyArray_INCREF(dest);
+ return 0;
}
static int
_broadcast_copy(PyArrayObject *dest, PyArrayObject *src,
- void (*myfunc)(char *, intp, char *, intp, intp, int),
- int swap)
+ void (*myfunc)(char *, intp, char *, intp, intp, int),
+ int swap)
{
- int elsize;
- PyArrayMultiIterObject *multi;
- int maxaxis; intp maxdim;
+ int elsize;
+ PyArrayMultiIterObject *multi;
+ int maxaxis; intp maxdim;
NPY_BEGIN_THREADS_DEF
- elsize = PyArray_ITEMSIZE(dest);
- multi = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, dest, src);
- if (multi == NULL) return -1;
+ elsize = PyArray_ITEMSIZE(dest);
+ multi = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, dest, src);
+ if (multi == NULL) return -1;
- if (multi->size != PyArray_SIZE(dest)) {
- PyErr_SetString(PyExc_ValueError,
- "array dimensions are not "\
- "compatible for copy");
- Py_DECREF(multi);
- return -1;
- }
+ if (multi->size != PyArray_SIZE(dest)) {
+ PyErr_SetString(PyExc_ValueError,
+ "array dimensions are not "\
+ "compatible for copy");
+ Py_DECREF(multi);
+ return -1;
+ }
- maxaxis = PyArray_RemoveLargest(multi);
- if (maxaxis < 0) { /* copy 1 0-d array to another */
- PyArray_XDECREF(dest);
- memcpy(dest->data, src->data, elsize);
- if (swap) byte_swap_vector(dest->data, 1, elsize);
- PyArray_INCREF(dest);
- return 0;
- }
- maxdim = multi->dimensions[maxaxis];
+ maxaxis = PyArray_RemoveLargest(multi);
+ if (maxaxis < 0) { /* copy 1 0-d array to another */
+ PyArray_XDECREF(dest);
+ memcpy(dest->data, src->data, elsize);
+ if (swap) byte_swap_vector(dest->data, 1, elsize);
+ PyArray_INCREF(dest);
+ return 0;
+ }
+ maxdim = multi->dimensions[maxaxis];
- PyArray_XDECREF(dest);
+ PyArray_XDECREF(dest);
NPY_BEGIN_THREADS
- while(multi->index < multi->size) {
- myfunc(multi->iters[0]->dataptr,
- multi->iters[0]->strides[maxaxis],
- multi->iters[1]->dataptr,
- multi->iters[1]->strides[maxaxis],
- maxdim, elsize);
- if (swap) {
- _strided_byte_swap(multi->iters[0]->dataptr,
- multi->iters[0]->strides[maxaxis],
- maxdim, elsize);
- }
- PyArray_MultiIter_NEXT(multi);
- }
+ while(multi->index < multi->size) {
+ myfunc(multi->iters[0]->dataptr,
+ multi->iters[0]->strides[maxaxis],
+ multi->iters[1]->dataptr,
+ multi->iters[1]->strides[maxaxis],
+ maxdim, elsize);
+ if (swap) {
+ _strided_byte_swap(multi->iters[0]->dataptr,
+ multi->iters[0]->strides[maxaxis],
+ maxdim, elsize);
+ }
+ PyArray_MultiIter_NEXT(multi);
+ }
NPY_END_THREADS
- Py_DECREF(multi);
- PyArray_INCREF(dest);
- return 0;
+ Py_DECREF(multi);
+ PyArray_INCREF(dest);
+ return 0;
}
/* If destination is not the right type, then src
@@ -977,10 +977,10 @@
static int
_array_copy_into(PyArrayObject *dest, PyArrayObject *src, int usecopy)
{
- int swap;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
- int simple;
- int same;
+ int swap;
+ void (*myfunc)(char *, intp, char *, intp, intp, int);
+ int simple;
+ int same;
NPY_BEGIN_THREADS_DEF
@@ -994,47 +994,47 @@
return -1;
}
- same = PyArray_SAMESHAPE(dest, src);
- simple = same && ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) ||
- (PyArray_ISFARRAY_RO(src) && PyArray_ISFARRAY(dest)));
-
- if (simple) {
- PyArray_XDECREF(dest);
+ same = PyArray_SAMESHAPE(dest, src);
+ simple = same && ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) ||
+ (PyArray_ISFARRAY_RO(src) && PyArray_ISFARRAY(dest)));
+
+ if (simple) {
+ PyArray_XDECREF(dest);
NPY_BEGIN_THREADS
- if (usecopy)
- memcpy(dest->data, src->data, PyArray_NBYTES(dest));
- else
- memmove(dest->data, src->data, PyArray_NBYTES(dest));
+ if (usecopy)
+ memcpy(dest->data, src->data, PyArray_NBYTES(dest));
+ else
+ memmove(dest->data, src->data, PyArray_NBYTES(dest));
NPY_END_THREADS
- PyArray_INCREF(dest);
- return 0;
- }
+ PyArray_INCREF(dest);
+ return 0;
+ }
- swap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);
+ swap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);
- if (src->nd == 0) {
- return _copy_from0d(dest, src, usecopy, swap);
- }
+ if (src->nd == 0) {
+ return _copy_from0d(dest, src, usecopy, swap);
+ }
- if (PyArray_ISALIGNED(dest) && PyArray_ISALIGNED(src)) {
- myfunc = _strided_byte_copy;
- }
- else if (usecopy) {
- myfunc = _unaligned_strided_byte_copy;
- }
- else {
- myfunc = _unaligned_strided_byte_move;
- }
-
- /* Could combine these because _broadcasted_copy would work as well.
- But, same-shape copying is so common we want to speed it up.
- */
- if (same) {
- return _copy_from_same_shape(dest, src, myfunc, swap);
- }
- else {
- return _broadcast_copy(dest, src, myfunc, swap);
- }
+ if (PyArray_ISALIGNED(dest) && PyArray_ISALIGNED(src)) {
+ myfunc = _strided_byte_copy;
+ }
+ else if (usecopy) {
+ myfunc = _unaligned_strided_byte_copy;
+ }
+ else {
+ myfunc = _unaligned_strided_byte_move;
+ }
+
+ /* Could combine these because _broadcasted_copy would work as well.
+ But, same-shape copying is so common we want to speed it up.
+ */
+ if (same) {
+ return _copy_from_same_shape(dest, src, myfunc, swap);
+ }
+ else {
+ return _broadcast_copy(dest, src, myfunc, swap);
+ }
}
/*OBJECT_API
@@ -1049,7 +1049,7 @@
intp size;
int elsize, simple;
PyArrayIterObject *idest, *isrc;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
+ void (*myfunc)(char *, intp, char *, intp, intp, int);
NPY_BEGIN_THREADS_DEF
if (!PyArray_EquivArrTypes(dest, src)) {
@@ -1062,35 +1062,35 @@
return -1;
}
- if ((size=PyArray_SIZE(dest)) != PyArray_SIZE(src)) {
+ if ((size=PyArray_SIZE(dest)) != PyArray_SIZE(src)) {
PyErr_SetString(PyExc_ValueError,
"arrays must have the same number of elements"
" for copy");
return -1;
}
- simple = ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) ||
+ simple = ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) ||
(PyArray_ISFARRAY_RO(src) && PyArray_ISFARRAY(dest)));
-
- if (simple) {
- PyArray_XDECREF(dest);
+
+ if (simple) {
+ PyArray_XDECREF(dest);
NPY_BEGIN_THREADS
memcpy(dest->data, src->data, PyArray_NBYTES(dest));
NPY_END_THREADS
- PyArray_INCREF(dest);
- return 0;
- }
+ PyArray_INCREF(dest);
+ return 0;
+ }
if (PyArray_SAMESHAPE(dest, src)) {
int swap;
if (PyArray_ISALIGNED(dest) && PyArray_ISALIGNED(src)) {
myfunc = _strided_byte_copy;
}
- else {
+ else {
myfunc = _unaligned_strided_byte_copy;
}
swap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);
- return _copy_from_same_shape(dest, src, myfunc, swap);
+ return _copy_from_same_shape(dest, src, myfunc, swap);
}
/* Otherwise we have to do an iterator-based copy */
@@ -1119,7 +1119,7 @@
static int
PyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)
{
- return _array_copy_into(dest, src, 1);
+ return _array_copy_into(dest, src, 1);
}
@@ -1129,7 +1129,7 @@
static int
PyArray_MoveInto(PyArrayObject *dest, PyArrayObject *src)
{
- return _array_copy_into(dest, src, 0);
+ return _array_copy_into(dest, src, 0);
}
@@ -1138,43 +1138,43 @@
PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)
{
PyArrayObject *src;
- PyArray_Descr* dtype;
+ PyArray_Descr* dtype;
int ret;
- /* Special code to mimic Numeric behavior for
- character arrays.
- */
- if (dest->descr->type == PyArray_CHARLTR && dest->nd > 0 \
- && PyString_Check(src_object)) {
- int n_new, n_old;
- char *new_string;
- PyObject *tmp;
- n_new = dest->dimensions[dest->nd-1];
- n_old = PyString_Size(src_object);
- if (n_new > n_old) {
- new_string = (char *)malloc(n_new);
- memmove(new_string,
- PyString_AS_STRING(src_object),
- n_old);
- memset(new_string+n_old, ' ', n_new-n_old);
- tmp = PyString_FromStringAndSize(new_string, n_new);
- free(new_string);
- src_object = tmp;
- }
- }
-
- if (PyArray_Check(src_object)) {
- dtype = NULL;
- }
- else {
- dtype = dest->descr;
- Py_INCREF(dtype);
- }
- src = (PyArrayObject *)PyArray_FromAny(src_object, dtype, 0,
- dest->nd,
- FORTRAN_IF(dest), NULL);
+ /* Special code to mimic Numeric behavior for
+ character arrays.
+ */
+ if (dest->descr->type == PyArray_CHARLTR && dest->nd > 0 \
+ && PyString_Check(src_object)) {
+ int n_new, n_old;
+ char *new_string;
+ PyObject *tmp;
+ n_new = dest->dimensions[dest->nd-1];
+ n_old = PyString_Size(src_object);
+ if (n_new > n_old) {
+ new_string = (char *)malloc(n_new);
+ memmove(new_string,
+ PyString_AS_STRING(src_object),
+ n_old);
+ memset(new_string+n_old, ' ', n_new-n_old);
+ tmp = PyString_FromStringAndSize(new_string, n_new);
+ free(new_string);
+ src_object = tmp;
+ }
+ }
+
+ if (PyArray_Check(src_object)) {
+ dtype = NULL;
+ }
+ else {
+ dtype = dest->descr;
+ Py_INCREF(dtype);
+ }
+ src = (PyArrayObject *)PyArray_FromAny(src_object, dtype, 0,
+ dest->nd,
+ FORTRAN_IF(dest), NULL);
if (src == NULL) return -1;
-
+
ret = PyArray_MoveInto(dest, src);
Py_DECREF(src);
return ret;
@@ -1195,28 +1195,28 @@
PyArray_Descr *descr,
char *data)
{
- PyObject *ret;
+ PyObject *ret;
#if SIZEOF_INTP != SIZEOF_INT
- int i;
- intp newd[MAX_DIMS];
+ int i;
+ intp newd[MAX_DIMS];
#endif
- if (!PyArray_ISNBO(descr->byteorder))
- descr->byteorder = '=';
+ if (!PyArray_ISNBO(descr->byteorder))
+ descr->byteorder = '=';
#if SIZEOF_INTP != SIZEOF_INT
- for (i=0; i<nd; i++) newd[i] = (intp) d[i];
+ for (i=0; i<nd; i++) newd[i] = (intp) d[i];
ret = PyArray_NewFromDescr(&PyArray_Type, descr,
- nd, newd,
- NULL, data,
- (data ? CARRAY : 0), NULL);
+ nd, newd,
+ NULL, data,
+ (data ? CARRAY : 0), NULL);
#else
- ret = PyArray_NewFromDescr(&PyArray_Type, descr,
- nd, (intp *)d,
- NULL, data,
- (data ? CARRAY : 0), NULL);
+ ret = PyArray_NewFromDescr(&PyArray_Type, descr,
+ nd, (intp *)d,
+ NULL, data,
+ (data ? CARRAY : 0), NULL);
#endif
- return ret;
+ return ret;
}
/*OBJECT_API
@@ -1225,18 +1225,18 @@
static PyObject *
PyArray_FromDims(int nd, int *d, int type)
{
- PyObject *ret;
- ret = PyArray_FromDimsAndDataAndDescr(nd, d,
- PyArray_DescrFromType(type),
- NULL);
- /* Old FromDims set memory to zero --- some algorithms
- 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)) {
- memset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));
- }
- return ret;
+ PyObject *ret;
+ ret = PyArray_FromDimsAndDataAndDescr(nd, d,
+ PyArray_DescrFromType(type),
+ NULL);
+ /* Old FromDims set memory to zero --- some algorithms
+ 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)) {
+ memset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));
+ }
+ return ret;
}
/* end old calls */
@@ -1248,19 +1248,19 @@
static PyObject *
PyArray_NewCopy(PyArrayObject *m1, NPY_ORDER fortran)
{
- PyArrayObject *ret;
- if (fortran == PyArray_ANYORDER)
- fortran = PyArray_ISFORTRAN(m1);
+ PyArrayObject *ret;
+ if (fortran == PyArray_ANYORDER)
+ fortran = PyArray_ISFORTRAN(m1);
- Py_INCREF(m1->descr);
- ret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,
- m1->descr,
- m1->nd,
- m1->dimensions,
- NULL, NULL,
- fortran,
- (PyObject *)m1);
- if (ret == NULL) return NULL;
+ Py_INCREF(m1->descr);
+ ret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,
+ m1->descr,
+ m1->nd,
+ m1->dimensions,
+ NULL, NULL,
+ fortran,
+ (PyObject *)m1);
+ if (ret == NULL) return NULL;
if (PyArray_CopyInto(ret, m1) == -1) {
Py_DECREF(ret);
return NULL;
@@ -1278,137 +1278,137 @@
static PyObject *
PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
{
- PyTypeObject *type;
- PyObject *obj;
+ PyTypeObject *type;
+ PyObject *obj;
void *destptr;
PyArray_CopySwapFunc *copyswap;
- int type_num;
- int itemsize;
- int swap;
+ int type_num;
+ int itemsize;
+ int swap;
- type_num = descr->type_num;
- if (type_num == PyArray_BOOL)
- PyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);
- else if (type_num == PyArray_OBJECT) {
- return descr->f->getitem(data, base);
- }
- itemsize = descr->elsize;
+ type_num = descr->type_num;
+ if (type_num == PyArray_BOOL)
+ PyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);
+ else if (type_num == PyArray_OBJECT) {
+ return descr->f->getitem(data, base);
+ }
+ itemsize = descr->elsize;
type = descr->typeobj;
copyswap = descr->f->copyswap;
- swap = !PyArray_ISNBO(descr->byteorder);
- if PyTypeNum_ISSTRING(type_num) { /* Eliminate NULL bytes */
- char *dptr = data;
- dptr += itemsize-1;
- while(itemsize && *dptr-- == 0) itemsize--;
- if (type_num == PyArray_UNICODE && itemsize) {
- /* make sure itemsize is a multiple of 4 */
- /* so round up to nearest multiple */
- itemsize = (((itemsize-1) >> 2) + 1) << 2;
- }
- }
- if (type->tp_itemsize != 0) /* String type */
- obj = type->tp_alloc(type, itemsize);
- else
- obj = type->tp_alloc(type, 0);
- if (obj == NULL) return NULL;
- if PyTypeNum_ISFLEXIBLE(type_num) {
- if (type_num == PyArray_STRING) {
- destptr = PyString_AS_STRING(obj);
- ((PyStringObject *)obj)->ob_shash = -1;
- ((PyStringObject *)obj)->ob_sstate = \
- SSTATE_NOT_INTERNED;
- memcpy(destptr, data, itemsize);
- return obj;
- }
- else if (type_num == PyArray_UNICODE) {
- PyUnicodeObject *uni = (PyUnicodeObject*)obj;
- int length = itemsize >> 2;
+ swap = !PyArray_ISNBO(descr->byteorder);
+ if PyTypeNum_ISSTRING(type_num) { /* Eliminate NULL bytes */
+ char *dptr = data;
+ dptr += itemsize-1;
+ while(itemsize && *dptr-- == 0) itemsize--;
+ if (type_num == PyArray_UNICODE && itemsize) {
+ /* make sure itemsize is a multiple of 4 */
+ /* so round up to nearest multiple */
+ itemsize = (((itemsize-1) >> 2) + 1) << 2;
+ }
+ }
+ if (type->tp_itemsize != 0) /* String type */
+ obj = type->tp_alloc(type, itemsize);
+ else
+ obj = type->tp_alloc(type, 0);
+ if (obj == NULL) return NULL;
+ if PyTypeNum_ISFLEXIBLE(type_num) {
+ if (type_num == PyArray_STRING) {
+ destptr = PyString_AS_STRING(obj);
+ ((PyStringObject *)obj)->ob_shash = -1;
+ ((PyStringObject *)obj)->ob_sstate = \
+ SSTATE_NOT_INTERNED;
+ memcpy(destptr, data, itemsize);
+ return obj;
+ }
+ else if (type_num == PyArray_UNICODE) {
+ PyUnicodeObject *uni = (PyUnicodeObject*)obj;
+ int length = itemsize >> 2;
#ifndef Py_UNICODE_WIDE
- char *buffer;
- int alloc=0;
- length *= 2;
+ char *buffer;
+ int alloc=0;
+ length *= 2;
#endif
- /* Need an extra slot and need to use
- Python memory manager */
- uni->str = NULL;
- destptr = PyMem_NEW(Py_UNICODE,length+1);
- if (destptr == NULL) {
+ /* Need an extra slot and need to use
+ Python memory manager */
+ uni->str = NULL;
+ destptr = PyMem_NEW(Py_UNICODE,length+1);
+ if (destptr == NULL) {
Py_DECREF(obj);
- return PyErr_NoMemory();
- }
- uni->str = (Py_UNICODE *)destptr;
- uni->str[0] = 0;
- uni->str[length] = 0;
- uni->length = length;
- uni->hash = -1;
- uni->defenc = NULL;
+ return PyErr_NoMemory();
+ }
+ uni->str = (Py_UNICODE *)destptr;
+ uni->str[0] = 0;
+ uni->str[length] = 0;
+ uni->length = length;
+ uni->hash = -1;
+ uni->defenc = NULL;
#ifdef Py_UNICODE_WIDE
- memcpy(destptr, data, itemsize);
- if (swap)
- byte_swap_vector(destptr, length, 4);
+ memcpy(destptr, data, itemsize);
+ if (swap)
+ byte_swap_vector(destptr, length, 4);
#else
- /* need aligned data buffer */
- if (!PyArray_ISBEHAVED(base)) {
- buffer = _pya_malloc(itemsize);
- if (buffer == NULL)
- return PyErr_NoMemory();
- alloc = 1;
- memcpy(buffer, data, itemsize);
- if (!PyArray_ISNOTSWAPPED(base)) {
- byte_swap_vector(buffer,
- itemsize >> 2, 4);
- }
- }
- else buffer = data;
+ /* need aligned data buffer */
+ if (!PyArray_ISBEHAVED(base)) {
+ buffer = _pya_malloc(itemsize);
+ if (buffer == NULL)
+ return PyErr_NoMemory();
+ alloc = 1;
+ memcpy(buffer, data, itemsize);
+ if (!PyArray_ISNOTSWAPPED(base)) {
+ byte_swap_vector(buffer,
+ itemsize >> 2, 4);
+ }
+ }
+ else buffer = data;
/* Allocated enough for 2-characters per itemsize.
- Now convert from the data-buffer
+ Now convert from the data-buffer
*/
- length = PyUCS2Buffer_FromUCS4(uni->str,
- (PyArray_UCS4 *)buffer,
- itemsize >> 2);
- if (alloc) _pya_free(buffer);
- /* Resize the unicode result */
- if (MyPyUnicode_Resize(uni, length) < 0) {
- Py_DECREF(obj);
- return NULL;
- }
+ length = PyUCS2Buffer_FromUCS4(uni->str,
+ (PyArray_UCS4 *)buffer,
+ itemsize >> 2);
+ if (alloc) _pya_free(buffer);
+ /* Resize the unicode result */
+ if (MyPyUnicode_Resize(uni, length) < 0) {
+ Py_DECREF(obj);
+ return NULL;
+ }
#endif
- return obj;
- }
- else {
- PyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;
- vobj->base = NULL;
- vobj->descr = descr;
- Py_INCREF(descr);
- vobj->obval = NULL;
- vobj->ob_size = itemsize;
- vobj->flags = BEHAVED | OWNDATA;
- swap = 0;
- if (descr->names) {
- if (base) {
- Py_INCREF(base);
- vobj->base = base;
- vobj->flags = PyArray_FLAGS(base);
- vobj->flags &= ~OWNDATA;
- vobj->obval = data;
- return obj;
- }
- }
- destptr = PyDataMem_NEW(itemsize);
- if (destptr == NULL) {
+ return obj;
+ }
+ else {
+ PyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;
+ vobj->base = NULL;
+ vobj->descr = descr;
+ Py_INCREF(descr);
+ vobj->obval = NULL;
+ vobj->ob_size = itemsize;
+ vobj->flags = BEHAVED | OWNDATA;
+ swap = 0;
+ if (descr->names) {
+ if (base) {
+ Py_INCREF(base);
+ vobj->base = base;
+ vobj->flags = PyArray_FLAGS(base);
+ vobj->flags &= ~OWNDATA;
+ vobj->obval = data;
+ return obj;
+ }
+ }
+ destptr = PyDataMem_NEW(itemsize);
+ if (destptr == NULL) {
Py_DECREF(obj);
- return PyErr_NoMemory();
- }
- vobj->obval = destptr;
- }
- }
- else {
- destptr = scalar_value(obj, NULL);
- }
- /* copyswap for OBJECT increments the reference count */
+ return PyErr_NoMemory();
+ }
+ vobj->obval = destptr;
+ }
+ }
+ else {
+ destptr = scalar_value(obj, descr);
+ }
+ /* copyswap for OBJECT increments the reference count */
copyswap(destptr, data, swap, base);
- return obj;
+ return obj;
}
/* returns an Array-Scalar Object of the type of arr
@@ -1432,24 +1432,24 @@
PyArray_Return(PyArrayObject *mp)
{
- if (mp == NULL) return NULL;
+ if (mp == NULL) return NULL;
if (PyErr_Occurred()) {
Py_XDECREF(mp);
return NULL;
}
- if (!PyArray_Check(mp)) return (PyObject *)mp;
+ if (!PyArray_Check(mp)) return (PyObject *)mp;
- if (mp->nd == 0) {
- PyObject *ret;
- ret = PyArray_ToScalar(mp->data, mp);
- Py_DECREF(mp);
- return ret;
- }
- else {
- return (PyObject *)mp;
- }
+ if (mp->nd == 0) {
+ PyObject *ret;
+ ret = PyArray_ToScalar(mp->data, mp);
+ Py_DECREF(mp);
+ return ret;
+ }
+ else {
+ return (PyObject *)mp;
+ }
}
@@ -1459,41 +1459,41 @@
static void
PyArray_InitArrFuncs(PyArray_ArrFuncs *f)
{
- int i;
- for (i=0; i<PyArray_NTYPES; i++) {
- f->cast[i] = NULL;
- }
- f->getitem = NULL;
- f->setitem = NULL;
- f->copyswapn = NULL;
+ int i;
+ for (i=0; i<PyArray_NTYPES; i++) {
+ f->cast[i] = NULL;
+ }
+ f->getitem = NULL;
+ f->setitem = NULL;
+ f->copyswapn = NULL;
f->copyswap = NULL;
- f->compare = NULL;
- f->argmax = NULL;
- f->dotfunc = NULL;
- f->scanfunc = NULL;
- f->fromstr = NULL;
- f->nonzero = NULL;
- f->fill = NULL;
- f->fillwithscalar = NULL;
- for (i=0; i<PyArray_NSORTS; i++) {
- f->sort[i] = NULL;
- f->argsort[i] = NULL;
- }
- f->castdict = NULL;
- f->scalarkind = NULL;
- f->cancastscalarkindto = NULL;
- f->cancastto = NULL;
+ f->compare = NULL;
+ f->argmax = NULL;
+ f->dotfunc = NULL;
+ f->scanfunc = NULL;
+ f->fromstr = NULL;
+ f->nonzero = NULL;
+ f->fill = NULL;
+ f->fillwithscalar = NULL;
+ for (i=0; i<PyArray_NSORTS; i++) {
+ f->sort[i] = NULL;
+ f->argsort[i] = NULL;
+ }
+ f->castdict = NULL;
+ f->scalarkind = NULL;
+ f->cancastscalarkindto = NULL;
+ f->cancastto = NULL;
}
static Bool
_default_nonzero(void *ip, void *arr)
{
- int elsize = PyArray_ITEMSIZE(arr);
- char *ptr = ip;
- while (elsize--) {
- if (*ptr++ != 0) return TRUE;
- }
- return FALSE;
+ int elsize = PyArray_ITEMSIZE(arr);
+ char *ptr = ip;
+ while (elsize--) {
+ if (*ptr++ != 0) return TRUE;
+ }
+ return FALSE;
}
/*
@@ -1508,16 +1508,16 @@
static int
PyArray_TypeNumFromName(char *str)
{
- int i;
- PyArray_Descr *descr;
+ int i;
+ PyArray_Descr *descr;
- for (i=0; i<NPY_NUMUSERTYPES; i++) {
- descr = userdescrs[i];
- if (strcmp(descr->typeobj->tp_name, str) == 0)
- return descr->type_num;
- }
-
- return PyArray_NOTYPE;
+ for (i=0; i<NPY_NUMUSERTYPES; i++) {
+ descr = userdescrs[i];
+ if (strcmp(descr->typeobj->tp_name, str) == 0)
+ return descr->type_num;
+ }
+
+ return PyArray_NOTYPE;
}
/*
@@ -1532,46 +1532,46 @@
static int
PyArray_RegisterDataType(PyArray_Descr *descr)
{
- PyArray_Descr *descr2;
- int typenum;
- int i;
- PyArray_ArrFuncs *f;
+ PyArray_Descr *descr2;
+ int typenum;
+ int i;
+ PyArray_ArrFuncs *f;
- /* See if this type is already registered */
- for (i=0; i<NPY_NUMUSERTYPES; i++) {
- descr2 = userdescrs[i];
- if (descr2 == descr)
- return descr->type_num;
- }
- typenum = PyArray_USERDEF + NPY_NUMUSERTYPES;
- descr->type_num = typenum;
- if (descr->elsize == 0) {
- PyErr_SetString(PyExc_ValueError, "cannot register a" \
- "flexible data-type");
- return -1;
- }
- f = descr->f;
- if (f->nonzero == NULL) {
- f->nonzero = _default_nonzero;
- }
- if (f->copyswap == NULL || f->getitem == NULL ||
- f->copyswapn == NULL || f->setitem == NULL) {
- PyErr_SetString(PyExc_ValueError, "a required array function" \
- " is missing.");
- return -1;
- }
- if (descr->typeobj == NULL) {
- PyErr_SetString(PyExc_ValueError, "missing typeobject");
- return -1;
- }
- userdescrs = realloc(userdescrs,
- (NPY_NUMUSERTYPES+1)*sizeof(void *));
+ /* See if this type is already registered */
+ for (i=0; i<NPY_NUMUSERTYPES; i++) {
+ descr2 = userdescrs[i];
+ if (descr2 == descr)
+ return descr->type_num;
+ }
+ typenum = PyArray_USERDEF + NPY_NUMUSERTYPES;
+ descr->type_num = typenum;
+ if (descr->elsize == 0) {
+ PyErr_SetString(PyExc_ValueError, "cannot register a" \
+ "flexible data-type");
+ return -1;
+ }
+ f = descr->f;
+ if (f->nonzero == NULL) {
+ f->nonzero = _default_nonzero;
+ }
+ if (f->copyswap == NULL || f->getitem == NULL ||
+ f->copyswapn == NULL || f->setitem == NULL) {
+ PyErr_SetString(PyExc_ValueError, "a required array function" \
+ " is missing.");
+ return -1;
+ }
+ if (descr->typeobj == NULL) {
+ PyErr_SetString(PyExc_ValueError, "missing typeobject");
+ return -1;
+ }
+ userdescrs = realloc(userdescrs,
+ (NPY_NUMUSERTYPES+1)*sizeof(void *));
if (userdescrs == NULL) {
PyErr_SetString(PyExc_MemoryError, "RegisterDataType");
return -1;
}
- userdescrs[NPY_NUMUSERTYPES++] = descr;
- return typenum;
+ userdescrs[NPY_NUMUSERTYPES++] = descr;
+ return typenum;
}
/*MULTIARRAY_API
@@ -1580,43 +1580,43 @@
*/
static int
PyArray_RegisterCastFunc(PyArray_Descr *descr, int totype,
- PyArray_VectorUnaryFunc *castfunc)
+ PyArray_VectorUnaryFunc *castfunc)
{
- PyObject *cobj, *key;
- int ret;
- if (totype < PyArray_NTYPES) {
- descr->f->cast[totype] = castfunc;
- return 0;
- }
- if (!PyTypeNum_ISUSERDEF(totype)) {
- PyErr_SetString(PyExc_TypeError, "invalid type number.");
- return -1;
- }
- if (descr->f->castdict == NULL) {
- descr->f->castdict = PyDict_New();
- if (descr->f->castdict == NULL) return -1;
- }
- key = PyInt_FromLong(totype);
- if (PyErr_Occurred()) return -1;
- cobj = PyCObject_FromVoidPtr((void *)castfunc, NULL);
- if (cobj == NULL) {Py_DECREF(key); return -1;}
- ret = PyDict_SetItem(descr->f->castdict, key, cobj);
- Py_DECREF(key);
- Py_DECREF(cobj);
- return ret;
+ PyObject *cobj, *key;
+ int ret;
+ if (totype < PyArray_NTYPES) {
+ descr->f->cast[totype] = castfunc;
+ return 0;
+ }
+ if (!PyTypeNum_ISUSERDEF(totype)) {
+ PyErr_SetString(PyExc_TypeError, "invalid type number.");
+ return -1;
+ }
+ if (descr->f->castdict == NULL) {
+ descr->f->castdict = PyDict_New();
+ if (descr->f->castdict == NULL) return -1;
+ }
+ key = PyInt_FromLong(totype);
+ if (PyErr_Occurred()) return -1;
+ cobj = PyCObject_FromVoidPtr((void *)castfunc, NULL);
+ if (cobj == NULL) {Py_DECREF(key); return -1;}
+ ret = PyDict_SetItem(descr->f->castdict, key, cobj);
+ Py_DECREF(key);
+ Py_DECREF(cobj);
+ return ret;
}
static int *
_append_new(int *types, int insert)
{
- int n=0;
- int *newtypes;
+ int n=0;
+ int *newtypes;
- while (types[n] != PyArray_NOTYPE) n++;
- newtypes = (int *)realloc(types, (n+2)*sizeof(int));
- newtypes[n] = insert;
- newtypes[n+1] = PyArray_NOTYPE;
- return newtypes;
+ while (types[n] != PyArray_NOTYPE) n++;
+ newtypes = (int *)realloc(types, (n+2)*sizeof(int));
+ newtypes[n] = insert;
+ newtypes[n+1] = PyArray_NOTYPE;
+ return newtypes;
}
/*MULTIARRAY_API
@@ -1625,41 +1625,41 @@
*/
static int
PyArray_RegisterCanCast(PyArray_Descr *descr, int totype,
- NPY_SCALARKIND scalar)
+ NPY_SCALARKIND scalar)
{
- if (scalar == PyArray_NOSCALAR) {
- /* register with cancastto */
- /* These lists won't be freed once created
- -- they become part of the data-type */
- if (descr->f->cancastto == NULL) {
- descr->f->cancastto = (int *)malloc(1*sizeof(int));
- descr->f->cancastto[0] = PyArray_NOTYPE;
- }
- descr->f->cancastto = _append_new(descr->f->cancastto,
- totype);
- }
- else {
- /* register with cancastscalarkindto */
- if (descr->f->cancastscalarkindto == NULL) {
- int i;
- descr->f->cancastscalarkindto = \
- (int **)malloc(PyArray_NSCALARKINDS* \
- sizeof(int*));
- for (i=0; i<PyArray_NSCALARKINDS; i++) {
- descr->f->cancastscalarkindto[i] = NULL;
- }
- }
- if (descr->f->cancastscalarkindto[scalar] == NULL) {
- descr->f->cancastscalarkindto[scalar] = \
- (int *)malloc(1*sizeof(int));
- descr->f->cancastscalarkindto[scalar][0] = \
- PyArray_NOTYPE;
- }
- descr->f->cancastscalarkindto[scalar] = \
- _append_new(descr->f->cancastscalarkindto[scalar],
- totype);
- }
- return 0;
+ if (scalar == PyArray_NOSCALAR) {
+ /* register with cancastto */
+ /* These lists won't be freed once created
+ -- they become part of the data-type */
+ if (descr->f->cancastto == NULL) {
+ descr->f->cancastto = (int *)malloc(1*sizeof(int));
+ descr->f->cancastto[0] = PyArray_NOTYPE;
+ }
+ descr->f->cancastto = _append_new(descr->f->cancastto,
+ totype);
+ }
+ else {
+ /* register with cancastscalarkindto */
+ if (descr->f->cancastscalarkindto == NULL) {
+ int i;
+ descr->f->cancastscalarkindto = \
+ (int **)malloc(PyArray_NSCALARKINDS* \
+ sizeof(int*));
+ for (i=0; i<PyArray_NSCALARKINDS; i++) {
+ descr->f->cancastscalarkindto[i] = NULL;
+ }
+ }
+ if (descr->f->cancastscalarkindto[scalar] == NULL) {
+ descr->f->cancastscalarkindto[scalar] = \
+ (int *)malloc(1*sizeof(int));
+ descr->f->cancastscalarkindto[scalar][0] = \
+ PyArray_NOTYPE;
+ }
+ descr->f->cancastscalarkindto[scalar] = \
+ _append_new(descr->f->cancastscalarkindto[scalar],
+ totype);
+ }
+ return 0;
}
/*OBJECT_API
@@ -1674,23 +1674,23 @@
PyArrayIterObject *it;
PyObject *obj, *strobj, *tupobj;
- n3 = (sep ? strlen((const char *)sep) : 0);
- if (n3 == 0) { /* binary data */
+ n3 = (sep ? strlen((const char *)sep) : 0);
+ if (n3 == 0) { /* binary data */
if (self->descr->hasobject) {
PyErr_SetString(PyExc_ValueError, "cannot write "\
- "object arrays to a file in " \
- "binary mode");
+ "object arrays to a file in " \
+ "binary mode");
return -1;
}
if (PyArray_ISCONTIGUOUS(self)) {
size = PyArray_SIZE(self);
- NPY_BEGIN_ALLOW_THREADS
- n=fwrite((const void *)self->data,
- (size_t) self->descr->elsize,
- (size_t) size, fp);
- NPY_END_ALLOW_THREADS
- if (n < size) {
+ NPY_BEGIN_ALLOW_THREADS
+ n=fwrite((const void *)self->data,
+ (size_t) self->descr->elsize,
+ (size_t) size, fp);
+ NPY_END_ALLOW_THREADS
+ if (n < size) {
PyErr_Format(PyExc_ValueError,
"%ld requested and %ld written",
(long) size, (long) n);
@@ -1698,26 +1698,26 @@
}
}
else {
- NPY_BEGIN_THREADS_DEF
+ NPY_BEGIN_THREADS_DEF
it=(PyArrayIterObject *) \
PyArray_IterNew((PyObject *)self);
- NPY_BEGIN_THREADS
+ NPY_BEGIN_THREADS
while(it->index < it->size) {
if (fwrite((const void *)it->dataptr,
(size_t) self->descr->elsize,
1, fp) < 1) {
- NPY_END_THREADS
+ NPY_END_THREADS
PyErr_Format(PyExc_IOError,
"problem writing element"\
" %d to file",
- (int)it->index);
+ (int)it->index);
Py_DECREF(it);
return -1;
}
PyArray_ITER_NEXT(it);
}
- NPY_END_THREADS
+ NPY_END_THREADS
Py_DECREF(it);
}
}
@@ -1725,36 +1725,36 @@
it=(PyArrayIterObject *) \
PyArray_IterNew((PyObject *)self);
- n4 = (format ? strlen((const char *)format) : 0);
+ n4 = (format ? strlen((const char *)format) : 0);
while(it->index < it->size) {
obj = self->descr->f->getitem(it->dataptr, self);
if (obj == NULL) {Py_DECREF(it); return -1;}
- if (n4 == 0) { /* standard writing */
- strobj = PyObject_Str(obj);
- Py_DECREF(obj);
- if (strobj == NULL) {Py_DECREF(it); return -1;}
- }
- else { /* use format string */
- tupobj = PyTuple_New(1);
- if (tupobj == NULL) {Py_DECREF(it); return -1;}
- PyTuple_SET_ITEM(tupobj,0,obj);
- obj = PyString_FromString((const char *)format);
- if (obj == NULL) {Py_DECREF(tupobj);
- Py_DECREF(it); return -1;}
- strobj = PyString_Format(obj, tupobj);
- Py_DECREF(obj);
- Py_DECREF(tupobj);
- if (strobj == NULL) {Py_DECREF(it); return -1;}
- }
- NPY_BEGIN_ALLOW_THREADS
- n=fwrite(PyString_AS_STRING(strobj), 1,
- n2=PyString_GET_SIZE(strobj), fp);
- NPY_END_ALLOW_THREADS
+ if (n4 == 0) { /* standard writing */
+ strobj = PyObject_Str(obj);
+ Py_DECREF(obj);
+ if (strobj == NULL) {Py_DECREF(it); return -1;}
+ }
+ else { /* use format string */
+ tupobj = PyTuple_New(1);
+ if (tupobj == NULL) {Py_DECREF(it); return -1;}
+ PyTuple_SET_ITEM(tupobj,0,obj);
+ obj = PyString_FromString((const char *)format);
+ if (obj == NULL) {Py_DECREF(tupobj);
+ Py_DECREF(it); return -1;}
+ strobj = PyString_Format(obj, tupobj);
+ Py_DECREF(obj);
+ Py_DECREF(tupobj);
+ if (strobj == NULL) {Py_DECREF(it); return -1;}
+ }
+ NPY_BEGIN_ALLOW_THREADS
+ n=fwrite(PyString_AS_STRING(strobj), 1,
+ n2=PyString_GET_SIZE(strobj), fp);
+ NPY_END_ALLOW_THREADS
if (n < n2) {
PyErr_Format(PyExc_IOError,
"problem writing element %d"\
" to file",
- (int) it->index);
+ (int) it->index);
Py_DECREF(strobj);
Py_DECREF(it);
return -1;
@@ -1762,13 +1762,13 @@
/* write separator for all but last one */
if (it->index != it->size-1)
if (fwrite(sep, 1, n3, fp) < n3) {
- PyErr_Format(PyExc_IOError,
- "problem writing "\
- "separator to file");
- Py_DECREF(strobj);
- Py_DECREF(it);
- return -1;
- }
+ PyErr_Format(PyExc_IOError,
+ "problem writing "\
+ "separator to file");
+ Py_DECREF(strobj);
+ Py_DECREF(it);
+ return -1;
+ }
Py_DECREF(strobj);
PyArray_ITER_NEXT(it);
}
@@ -1790,23 +1790,23 @@
if (!PyArray_Check(self)) return (PyObject *)self;
if (self->nd == 0)
- return self->descr->f->getitem(self->data,self);
+ return self->descr->f->getitem(self->data,self);
sz = self->dimensions[0];
lp = PyList_New(sz);
for (i=0; i<sz; i++) {
v=(PyArrayObject *)array_big_item(self, i);
- if (v->nd >= self->nd) {
- PyErr_SetString(PyExc_RuntimeError,
- "array_item not returning smaller-" \
- "dimensional array");
+ if (v->nd >= self->nd) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "array_item not returning smaller-" \
+ "dimensional array");
Py_DECREF(v);
- Py_DECREF(lp);
- return NULL;
- }
+ Py_DECREF(lp);
+ return NULL;
+ }
PyList_SetItem(lp, i, PyArray_ToList(v));
- Py_DECREF(v);
+ Py_DECREF(v);
}
return lp;
@@ -1823,34 +1823,34 @@
PyObject *ret;
PyArrayIterObject *it;
- if (order == NPY_ANYORDER)
- order = PyArray_ISFORTRAN(self);
+ if (order == NPY_ANYORDER)
+ order = PyArray_ISFORTRAN(self);
- /* if (PyArray_TYPE(self) == PyArray_OBJECT) {
- PyErr_SetString(PyExc_ValueError, "a string for the data" \
- "in an object array is not appropriate");
- return NULL;
- }
- */
+ /* if (PyArray_TYPE(self) == PyArray_OBJECT) {
+ PyErr_SetString(PyExc_ValueError, "a string for the data" \
+ "in an object array is not appropriate");
+ return NULL;
+ }
+ */
numbytes = PyArray_NBYTES(self);
- if ((PyArray_ISCONTIGUOUS(self) && (order == NPY_CORDER)) || \
- (PyArray_ISFORTRAN(self) && (order == NPY_FORTRANORDER))) {
+ if ((PyArray_ISCONTIGUOUS(self) && (order == NPY_CORDER)) || \
+ (PyArray_ISFORTRAN(self) && (order == NPY_FORTRANORDER))) {
ret = PyString_FromStringAndSize(self->data, (int) numbytes);
}
else {
- PyObject *new;
- if (order == NPY_FORTRANORDER) {
- /* iterators are always in C-order */
- new = PyArray_Transpose(self, NULL);
- if (new == NULL) return NULL;
- }
- else {
- Py_INCREF(self);
- new = (PyObject *)self;
- }
+ PyObject *new;
+ if (order == NPY_FORTRANORDER) {
+ /* iterators are always in C-order */
+ new = PyArray_Transpose(self, NULL);
+ if (new == NULL) return NULL;
+ }
+ else {
+ Py_INCREF(self);
+ new = (PyObject *)self;
+ }
it = (PyArrayIterObject *)PyArray_IterNew(new);
- Py_DECREF(new);
+ Py_DECREF(new);
if (it==NULL) return NULL;
ret = PyString_FromStringAndSize(NULL, (int) numbytes);
if (ret == NULL) {Py_DECREF(it); return NULL;}
@@ -1864,7 +1864,7 @@
}
Py_DECREF(it);
}
- return ret;
+ return ret;
}
@@ -1880,43 +1880,43 @@
PyObject_ClearWeakRefs((PyObject *)self);
if(self->base) {
- /* UPDATEIFCOPY means that base points to an
- array that should be updated with the contents
- of this array upon destruction.
+ /* UPDATEIFCOPY means that base points to an
+ array that should be updated with the contents
+ of this array upon destruction.
self->base->flags must have been WRITEABLE
(checked previously) and it was locked here
thus, unlock it.
- */
- if (self->flags & UPDATEIFCOPY) {
+ */
+ if (self->flags & UPDATEIFCOPY) {
((PyArrayObject *)self->base)->flags |= WRITEABLE;
- Py_INCREF(self); /* hold on to self in next call */
+ Py_INCREF(self); /* hold on to self in next call */
if (PyArray_CopyAnyInto((PyArrayObject *)self->base,
self) < 0) {
PyErr_Print();
PyErr_Clear();
}
- /* Don't need to DECREF -- because we are deleting
- self already... */
- }
- /* In any case base is pointing to something that we need
- to DECREF -- either a view or a buffer object */
+ /* Don't need to DECREF -- because we are deleting
+ self already... */
+ }
+ /* In any case base is pointing to something that we need
+ to DECREF -- either a view or a buffer object */
Py_DECREF(self->base);
}
if ((self->flags & OWNDATA) && self->data) {
- /* Free internal references if an Object array */
- if (self->descr->hasobject) {
- Py_INCREF(self); /*hold on to self */
- PyArray_XDECREF(self);
- /* Don't need to DECREF -- because we are deleting
- self already... */
- }
+ /* Free internal references if an Object array */
+ if (self->descr->hasobject) {
+ Py_INCREF(self); /*hold on to self */
+ PyArray_XDECREF(self);
+ /* Don't need to DECREF -- because we are deleting
+ self already... */
+ }
PyDataMem_FREE(self->data);
}
- PyDimMem_FREE(self->dimensions);
+ PyDimMem_FREE(self->dimensions);
- Py_DECREF(self->descr);
+ Py_DECREF(self->descr);
self->ob_type->tp_free((PyObject *)self);
}
@@ -1931,52 +1931,52 @@
if (self->nd != 0) {
return self->dimensions[0];
} else {
- PyErr_SetString(PyExc_TypeError, "len() of unsized object");
- return -1;
+ PyErr_SetString(PyExc_TypeError, "len() of unsized object");
+ return -1;
}
}
static PyObject *
array_big_item(PyArrayObject *self, intp i)
{
- char *item;
- PyArrayObject *r;
+ char *item;
+ PyArrayObject *r;
- if(self->nd == 0) {
- PyErr_SetString(PyExc_IndexError,
- "0-d arrays can't be indexed");
- return NULL;
- }
+ if(self->nd == 0) {
+ PyErr_SetString(PyExc_IndexError,
+ "0-d arrays can't be indexed");
+ return NULL;
+ }
if ((item = index2ptr(self, i)) == NULL) return NULL;
- Py_INCREF(self->descr);
- r = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,
- self->descr,
- self->nd-1,
- self->dimensions+1,
- self->strides+1, item,
- self->flags,
- (PyObject *)self);
- if (r == NULL) return NULL;
- Py_INCREF(self);
- r->base = (PyObject *)self;
+ Py_INCREF(self->descr);
+ r = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,
+ self->descr,
+ self->nd-1,
+ self->dimensions+1,
+ self->strides+1, item,
+ self->flags,
+ (PyObject *)self);
+ if (r == NULL) return NULL;
+ Py_INCREF(self);
+ r->base = (PyObject *)self;
PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);
- return (PyObject *)r;
+ return (PyObject *)r;
}
/* contains optimization for 1-d arrays */
static PyObject *
array_item_nice(PyArrayObject *self, Py_ssize_t i)
{
- if (self->nd == 1) {
- char *item;
- if ((item = index2ptr(self, i)) == NULL) return NULL;
- return PyArray_Scalar(item, self->descr, (PyObject *)self);
- }
- else {
- return PyArray_Return((PyArrayObject *)\
- array_big_item(self, (intp) i));
- }
+ if (self->nd == 1) {
+ char *item;
+ if ((item = index2ptr(self, i)) == NULL) return NULL;
+ return PyArray_Scalar(item, self->descr, (PyObject *)self);
+ }
+ else {
+ return PyArray_Return((PyArrayObject *)\
+ array_big_item(self, (intp) i));
+ }
}
static int
@@ -1991,11 +1991,11 @@
"can't delete array elements");
return -1;
}
- if (!PyArray_ISWRITEABLE(self)) {
- PyErr_SetString(PyExc_RuntimeError,
- "array is not writeable");
- return -1;
- }
+ if (!PyArray_ISWRITEABLE(self)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "array is not writeable");
+ return -1;
+ }
if (self->nd == 0) {
PyErr_SetString(PyExc_IndexError,
"0-d arrays can't be indexed.");
@@ -2029,7 +2029,7 @@
static int
array_ass_item(PyArrayObject *self, Py_ssize_t i, PyObject *v)
{
- return array_ass_big_item(self, (intp) i, v);
+ return array_ass_big_item(self, (intp) i, v);
}
#endif
@@ -2038,12 +2038,12 @@
static int
slice_coerce_index(PyObject *o, intp *v)
{
- *v = PyArray_PyIntAsIntp(o);
- if (error_converting(*v)) {
- PyErr_Clear();
- return 0;
- }
- return 1;
+ *v = PyArray_PyIntAsIntp(o);
+ if (error_converting(*v)) {
+ PyErr_Clear();
+ return 0;
+ }
+ return 1;
}
@@ -2054,52 +2054,52 @@
intp *start, intp *stop, intp *step,
intp *slicelength)
{
- intp defstart, defstop;
+ intp defstart, defstop;
- if (r->step == Py_None) {
- *step = 1;
- } else {
- if (!slice_coerce_index(r->step, step)) return -1;
- if (*step == 0) {
- PyErr_SetString(PyExc_ValueError,
- "slice step cannot be zero");
- return -1;
- }
- }
+ if (r->step == Py_None) {
+ *step = 1;
+ } else {
+ if (!slice_coerce_index(r->step, step)) return -1;
+ if (*step == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "slice step cannot be zero");
+ return -1;
+ }
+ }
- defstart = *step < 0 ? length - 1 : 0;
- defstop = *step < 0 ? -1 : length;
+ defstart = *step < 0 ? length - 1 : 0;
+ defstop = *step < 0 ? -1 : length;
- if (r->start == Py_None) {
- *start = *step < 0 ? length-1 : 0;
- } else {
- if (!slice_coerce_index(r->start, start)) return -1;
- if (*start < 0) *start += length;
- if (*start < 0) *start = (*step < 0) ? -1 : 0;
- if (*start >= length) {
- *start = (*step < 0) ? length - 1 : length;
- }
- }
+ if (r->start == Py_None) {
+ *start = *step < 0 ? length-1 : 0;
+ } else {
+ if (!slice_coerce_index(r->start, start)) return -1;
+ if (*start < 0) *start += length;
+ if (*start < 0) *start = (*step < 0) ? -1 : 0;
+ if (*start >= length) {
+ *start = (*step < 0) ? length - 1 : length;
+ }
+ }
- if (r->stop == Py_None) {
- *stop = defstop;
- } else {
- if (!slice_coerce_index(r->stop, stop)) return -1;
- if (*stop < 0) *stop += length;
+ if (r->stop == Py_None) {
+ *stop = defstop;
+ } else {
+ if (!slice_coerce_index(r->stop, stop)) return -1;
+ if (*stop < 0) *stop += length;
if (*stop < 0) *stop = -1;
if (*stop > length) *stop = length;
- }
+ }
- if ((*step < 0 && *stop >= *start) || \
- (*step > 0 && *start >= *stop)) {
- *slicelength = 0;
- } else if (*step < 0) {
- *slicelength = (*stop - *start + 1) / (*step) + 1;
- } else {
- *slicelength = (*stop - *start - 1) / (*step) + 1;
- }
+ if ((*step < 0 && *stop >= *start) || \
+ (*step > 0 && *start >= *stop)) {
+ *slicelength = 0;
+ } else if (*step < 0) {
+ *slicelength = (*stop - *start + 1) / (*step) + 1;
+ } else {
+ *slicelength = (*stop - *start - 1) / (*step) + 1;
+ }
- return 0;
+ return 0;
}
#define PseudoIndex -1
@@ -2109,49 +2109,49 @@
static intp
parse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)
{
- intp index;
+ intp index;
- if (op == Py_None) {
- *n_steps = PseudoIndex;
- index = 0;
- } else if (op == Py_Ellipsis) {
- *n_steps = RubberIndex;
- index = 0;
- } else if (PySlice_Check(op)) {
- intp stop;
- if (slice_GetIndices((PySliceObject *)op, max,
- &index, &stop, step_size, n_steps) < 0) {
- if (!PyErr_Occurred()) {
- PyErr_SetString(PyExc_IndexError,
- "invalid slice");
- }
- goto fail;
- }
- if (*n_steps <= 0) {
- *n_steps = 0;
- *step_size = 1;
- index = 0;
- }
- } else {
- index = PyArray_PyIntAsIntp(op);
- if (error_converting(index)) {
- PyErr_SetString(PyExc_IndexError,
- "each subindex must be either a "\
- "slice, an integer, Ellipsis, or "\
- "newaxis");
- goto fail;
- }
- *n_steps = SingleIndex;
- *step_size = 0;
- if (index < 0) index += max;
- if (index >= max || index < 0) {
- PyErr_SetString(PyExc_IndexError, "invalid index");
- goto fail;
- }
- }
- return index;
+ if (op == Py_None) {
+ *n_steps = PseudoIndex;
+ index = 0;
+ } else if (op == Py_Ellipsis) {
+ *n_steps = RubberIndex;
+ index = 0;
+ } else if (PySlice_Check(op)) {
+ intp stop;
+ if (slice_GetIndices((PySliceObject *)op, max,
+ &index, &stop, step_size, n_steps) < 0) {
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_IndexError,
+ "invalid slice");
+ }
+ goto fail;
+ }
+ if (*n_steps <= 0) {
+ *n_steps = 0;
+ *step_size = 1;
+ index = 0;
+ }
+ } else {
+ index = PyArray_PyIntAsIntp(op);
+ if (error_converting(index)) {
+ PyErr_SetString(PyExc_IndexError,
+ "each subindex must be either a "\
+ "slice, an integer, Ellipsis, or "\
+ "newaxis");
+ goto fail;
+ }
+ *n_steps = SingleIndex;
+ *step_size = 0;
+ if (index < 0) index += max;
+ if (index >= max || index < 0) {
+ PyErr_SetString(PyExc_IndexError, "invalid index");
+ goto fail;
+ }
+ }
+ return index;
fail:
- return -1;
+ return -1;
}
@@ -2161,7 +2161,7 @@
{
int i, j, n;
int nd_old, nd_new, n_add, n_pseudo;
- intp n_steps, start, offset, step_size;
+ intp n_steps, start, offset, step_size;
PyObject *op1=NULL;
int is_slice;
@@ -2203,7 +2203,7 @@
if (n_steps == PseudoIndex) {
dimensions[nd_new] = 1; strides[nd_new] = 0;
- nd_new++;
+ nd_new++;
} else {
if (n_steps == RubberIndex) {
for(j=i+1, n_pseudo=0; j<n; j++) {
@@ -2255,15 +2255,15 @@
static void
_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)
{
- PyObject *new;
- int n1, n2, n3, val;
- int i;
- PyArray_Dims permute;
- intp d[MAX_DIMS];
+ PyObject *new;
+ int n1, n2, n3, val;
+ int i;
+ PyArray_Dims permute;
+ intp d[MAX_DIMS];
PyArrayObject *arr;
- permute.ptr = d;
- permute.len = mit->nd;
+ permute.ptr = d;
+ permute.len = mit->nd;
/* arr might not have the right number of dimensions
and need to be reshaped first by pre-pending ones */
@@ -2281,32 +2281,32 @@
if (new == NULL) return;
}
- /* tuple for transpose is
- (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)
- n1 is the number of dimensions of
- the broadcasted index array
- n2 is the number of dimensions skipped at the
- start
- n3 is the number of dimensions of the
- result
- */
- n1 = mit->iters[0]->nd_m1 + 1;
- n2 = mit->iteraxes[0];
- n3 = mit->nd;
- val = n1;
- i = 0;
- while(val < n1+n2)
- permute.ptr[i++] = val++;
- val = 0;
- while(val < n1)
- permute.ptr[i++] = val++;
- val = n1+n2;
- while(val < n3)
- permute.ptr[i++] = val++;
+ /* tuple for transpose is
+ (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)
+ n1 is the number of dimensions of
+ the broadcasted index array
+ n2 is the number of dimensions skipped at the
+ start
+ n3 is the number of dimensions of the
+ result
+ */
+ n1 = mit->iters[0]->nd_m1 + 1;
+ n2 = mit->iteraxes[0];
+ n3 = mit->nd;
+ val = n1;
+ i = 0;
+ while(val < n1+n2)
+ permute.ptr[i++] = val++;
+ val = 0;
+ while(val < n1)
+ permute.ptr[i++] = val++;
+ val = n1+n2;
+ while(val < n3)
+ permute.ptr[i++] = val++;
- new = PyArray_Transpose(*ret, &permute);
- Py_DECREF(*ret);
- *ret = (PyArrayObject *)new;
+ new = PyArray_Transpose(*ret, &permute);
+ Py_DECREF(*ret);
+ *ret = (PyArrayObject *)new;
}
/* Prototypes for Mapping calls --- not part of the C-API
@@ -2322,176 +2322,176 @@
PyArray_GetMap(PyArrayMapIterObject *mit)
{
- PyArrayObject *ret, *temp;
- PyArrayIterObject *it;
- int index;
- int swap;
+ PyArrayObject *ret, *temp;
+ PyArrayIterObject *it;
+ int index;
+ int swap;
PyArray_CopySwapFunc *copyswap;
- /* Unbound map iterator --- Bind should have been called */
- if (mit->ait == NULL) return NULL;
+ /* Unbound map iterator --- Bind should have been called */
+ if (mit->ait == NULL) return NULL;
- /* This relies on the map iterator object telling us the shape
- of the new array in nd and dimensions.
- */
- temp = mit->ait->ao;
- Py_INCREF(temp->descr);
- ret = (PyArrayObject *)\
- PyArray_NewFromDescr(temp->ob_type,
- temp->descr,
- mit->nd, mit->dimensions,
- NULL, NULL,
- PyArray_ISFORTRAN(temp),
- (PyObject *)temp);
- if (ret == NULL) return NULL;
+ /* This relies on the map iterator object telling us the shape
+ of the new array in nd and dimensions.
+ */
+ temp = mit->ait->ao;
+ Py_INCREF(temp->descr);
+ ret = (PyArrayObject *)\
+ PyArray_NewFromDescr(temp->ob_type,
+ temp->descr,
+ mit->nd, mit->dimensions,
+ NULL, NULL,
+ PyArray_ISFORTRAN(temp),
+ (PyObject *)temp);
+ if (ret == NULL) return NULL;
- /* Now just iterate through the new array filling it in
- with the next object from the original array as
- defined by the mapping iterator */
+ /* Now just iterate through the new array filling it in
+ with the next object from the original array as
+ defined by the mapping iterator */
- if ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))
- == NULL) {
- Py_DECREF(ret);
- return NULL;
- }
- index = it->size;
- swap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));
+ if ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))
+ == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ index = it->size;
+ swap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));
copyswap = ret->descr->f->copyswap;
- PyArray_MapIterReset(mit);
- while (index--) {
+ PyArray_MapIterReset(mit);
+ while (index--) {
copyswap(it->dataptr, mit->dataptr, swap, ret);
- PyArray_MapIterNext(mit);
- PyArray_ITER_NEXT(it);
- }
- Py_DECREF(it);
+ PyArray_MapIterNext(mit);
+ PyArray_ITER_NEXT(it);
+ }
+ Py_DECREF(it);
- /* check for consecutive axes */
- if ((mit->subspace != NULL) && (mit->consec)) {
- if (mit->iteraxes[0] > 0) { /* then we need to swap */
- _swap_axes(mit, &ret);
- }
- }
- return (PyObject *)ret;
+ /* check for consecutive axes */
+ if ((mit->subspace != NULL) && (mit->consec)) {
+ if (mit->iteraxes[0] > 0) { /* then we need to swap */
+ _swap_axes(mit, &ret);
+ }
+ }
+ return (PyObject *)ret;
}
static int
PyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)
{
- PyObject *arr=NULL;
- PyArrayIterObject *it;
- int index;
- int swap;
+ PyObject *arr=NULL;
+ PyArrayIterObject *it;
+ int index;
+ int swap;
PyArray_CopySwapFunc *copyswap;
- PyArray_Descr *descr;
+ PyArray_Descr *descr;
- /* Unbound Map Iterator */
- if (mit->ait == NULL) return -1;
+ /* Unbound Map Iterator */
+ if (mit->ait == NULL) return -1;
- descr = mit->ait->ao->descr;
- Py_INCREF(descr);
- arr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);
- if (arr == NULL) return -1;
+ descr = mit->ait->ao->descr;
+ Py_INCREF(descr);
+ arr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);
+ if (arr == NULL) return -1;
- if ((mit->subspace != NULL) && (mit->consec)) {
- if (mit->iteraxes[0] > 0) { /* then we need to swap */
- _swap_axes(mit, (PyArrayObject **)&arr);
- if (arr == NULL) return -1;
- }
- }
-
+ if ((mit->subspace != NULL) && (mit->consec)) {
+ if (mit->iteraxes[0] > 0) { /* then we need to swap */
+ _swap_axes(mit, (PyArrayObject **)&arr);
+ if (arr == NULL) return -1;
+ }
+ }
+
- if ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {
- Py_DECREF(arr);
- return -1;
- }
+ if ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {
+ Py_DECREF(arr);
+ return -1;
+ }
- index = mit->size;
- swap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \
- (PyArray_ISNOTSWAPPED(arr)));
+ index = mit->size;
+ swap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \
+ (PyArray_ISNOTSWAPPED(arr)));
copyswap = PyArray_DESCR(arr)->f->copyswap;
- PyArray_MapIterReset(mit);
+ PyArray_MapIterReset(mit);
/* Need to decref hasobject arrays */
if (descr->hasobject) {
while (index--) {
- PyArray_Item_XDECREF(mit->dataptr, PyArray_DESCR(arr));
- PyArray_Item_INCREF(it->dataptr, PyArray_DESCR(arr));
+ PyArray_Item_XDECREF(mit->dataptr, PyArray_DESCR(arr));
+ PyArray_Item_INCREF(it->dataptr, PyArray_DESCR(arr));
memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));
- /* ignored unless VOID array with object's */
- copyswap(mit->dataptr, NULL, swap, arr);
+ /* ignored unless VOID array with object's */
+ copyswap(mit->dataptr, NULL, swap, arr);
PyArray_MapIterNext(mit);
PyArray_ITER_NEXT(it);
if (it->index == it->size)
PyArray_ITER_RESET(it);
}
- Py_DECREF(arr);
- Py_DECREF(it);
+ Py_DECREF(arr);
+ Py_DECREF(it);
return 0;
}
- while(index--) {
- memmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));
- if (swap)
- copyswap(mit->dataptr, NULL, swap, arr);
- PyArray_MapIterNext(mit);
- PyArray_ITER_NEXT(it);
- if (it->index == it->size)
- PyArray_ITER_RESET(it);
- }
- Py_DECREF(arr);
- Py_DECREF(it);
- return 0;
+ while(index--) {
+ memmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));
+ if (swap)
+ copyswap(mit->dataptr, NULL, swap, arr);
+ PyArray_MapIterNext(mit);
+ PyArray_ITER_NEXT(it);
+ if (it->index == it->size)
+ PyArray_ITER_RESET(it);
+ }
+ Py_DECREF(arr);
+ Py_DECREF(it);
+ return 0;
}
int
count_new_axes_0d(PyObject *tuple)
{
- int i, argument_count;
- int ellipsis_count = 0;
- int newaxis_count = 0;
+ int i, argument_count;
+ int ellipsis_count = 0;
+ int newaxis_count = 0;
- argument_count = PyTuple_GET_SIZE(tuple);
+ argument_count = PyTuple_GET_SIZE(tuple);
- for (i = 0; i < argument_count; ++i) {
- PyObject *arg = PyTuple_GET_ITEM(tuple, i);
- if (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;
- else if (arg == Py_None) newaxis_count++;
- else break;
- }
- if (i < argument_count) {
- PyErr_SetString(PyExc_IndexError,
- "0-d arrays can only use a single ()"
- " or a list of newaxes (and a single ...)"
- " as an index");
- return -1;
- }
- if (newaxis_count > MAX_DIMS) {
- PyErr_SetString(PyExc_IndexError,
- "too many dimensions");
- return -1;
- }
- return newaxis_count;
+ for (i = 0; i < argument_count; ++i) {
+ PyObject *arg = PyTuple_GET_ITEM(tuple, i);
+ if (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;
+ else if (arg == Py_None) newaxis_count++;
+ else break;
+ }
+ if (i < argument_count) {
+ PyErr_SetString(PyExc_IndexError,
+ "0-d arrays can only use a single ()"
+ " or a list of newaxes (and a single ...)"
+ " as an index");
+ return -1;
+ }
+ if (newaxis_count > MAX_DIMS) {
+ PyErr_SetString(PyExc_IndexError,
+ "too many dimensions");
+ return -1;
+ }
+ return newaxis_count;
}
static PyObject *
add_new_axes_0d(PyArrayObject *arr, int newaxis_count)
{
- PyArrayObject *other;
- intp dimensions[MAX_DIMS];
- int i;
- for (i = 0; i < newaxis_count; ++i) {
- dimensions[i] = 1;
- }
- Py_INCREF(arr->descr);
- if ((other = (PyArrayObject *)
- PyArray_NewFromDescr(arr->ob_type, arr->descr,
- newaxis_count, dimensions,
- NULL, arr->data,
- arr->flags,
- (PyObject *)arr)) == NULL)
- return NULL;
- other->base = (PyObject *)arr;
- Py_INCREF(arr);
- return (PyObject *)other;
+ PyArrayObject *other;
+ intp dimensions[MAX_DIMS];
+ int i;
+ for (i = 0; i < newaxis_count; ++i) {
+ dimensions[i] = 1;
+ }
+ Py_INCREF(arr->descr);
+ if ((other = (PyArrayObject *)
+ PyArray_NewFromDescr(arr->ob_type, arr->descr,
+ newaxis_count, dimensions,
+ NULL, arr->data,
+ arr->flags,
+ (PyObject *)arr)) == NULL)
+ return NULL;
+ other->base = (PyObject *)arr;
+ Py_INCREF(arr);
+ return (PyObject *)other;
}
@@ -2506,65 +2506,65 @@
static int
fancy_indexing_check(PyObject *args)
{
- int i, n;
- PyObject *obj;
- int retval = SOBJ_NOTFANCY;
+ int i, n;
+ PyObject *obj;
+ int retval = SOBJ_NOTFANCY;
- if (PyTuple_Check(args)) {
- n = PyTuple_GET_SIZE(args);
- if (n >= MAX_DIMS) return SOBJ_TOOMANY;
- for (i=0; i<n; i++) {
- obj = PyTuple_GET_ITEM(args,i);
- if (PyArray_Check(obj)) {
- if (PyArray_ISINTEGER(obj) || PyArray_ISBOOL(obj))
- retval = SOBJ_ISFANCY;
- else {
- retval = SOBJ_BADARRAY;
- break;
- }
- }
- else if (PySequence_Check(obj)) {
+ if (PyTuple_Check(args)) {
+ n = PyTuple_GET_SIZE(args);
+ if (n >= MAX_DIMS) return SOBJ_TOOMANY;
+ for (i=0; i<n; i++) {
+ obj = PyTuple_GET_ITEM(args,i);
+ if (PyArray_Check(obj)) {
+ if (PyArray_ISINTEGER(obj) || PyArray_ISBOOL(obj))
+ retval = SOBJ_ISFANCY;
+ else {
+ retval = SOBJ_BADARRAY;
+ break;
+ }
+ }
+ else if (PySequence_Check(obj)) {
retval = SOBJ_ISFANCY;
- }
- }
- }
- else if (PyArray_Check(args)) {
- if ((PyArray_TYPE(args)==PyArray_BOOL) ||
- (PyArray_ISINTEGER(args)))
- return SOBJ_ISFANCY;
- else
- return SOBJ_BADARRAY;
- }
- else if (PySequence_Check(args)) {
- /* Sequences < MAX_DIMS with any slice objects
- or newaxis, or Ellipsis is considered standard
- as long as there are also no Arrays and or additional
- sequences embedded.
- */
- retval = SOBJ_ISFANCY;
- n = PySequence_Size(args);
- if (n<0 || n>=MAX_DIMS) return SOBJ_ISFANCY;
- for (i=0; i<n; i++) {
- obj = PySequence_GetItem(args, i);
- if (obj == NULL) return SOBJ_ISFANCY;
- if (PyArray_Check(obj)) {
- if (PyArray_ISINTEGER(obj))
- retval = SOBJ_LISTTUP;
- else
- retval = SOBJ_BADARRAY;
- }
- else if (PySequence_Check(obj)) {
+ }
+ }
+ }
+ else if (PyArray_Check(args)) {
+ if ((PyArray_TYPE(args)==PyArray_BOOL) ||
+ (PyArray_ISINTEGER(args)))
+ return SOBJ_ISFANCY;
+ else
+ return SOBJ_BADARRAY;
+ }
+ else if (PySequence_Check(args)) {
+ /* Sequences < MAX_DIMS with any slice objects
+ or newaxis, or Ellipsis is considered standard
+ as long as there are also no Arrays and or additional
+ sequences embedded.
+ */
+ retval = SOBJ_ISFANCY;
+ n = PySequence_Size(args);
+ if (n<0 || n>=MAX_DIMS) return SOBJ_ISFANCY;
+ for (i=0; i<n; i++) {
+ obj = PySequence_GetItem(args, i);
+ if (obj == NULL) return SOBJ_ISFANCY;
+ if (PyArray_Check(obj)) {
+ if (PyArray_ISINTEGER(obj))
+ retval = SOBJ_LISTTUP;
+ else
+ retval = SOBJ_BADARRAY;
+ }
+ else if (PySequence_Check(obj)) {
retval = SOBJ_LISTTUP;
- }
- else if (PySlice_Check(obj) || obj == Py_Ellipsis || \
- obj == Py_None) {
- retval = SOBJ_NOTFANCY;
- }
- Py_DECREF(obj);
- if (retval > SOBJ_ISFANCY) return retval;
- }
- }
- return retval;
+ }
+ else if (PySlice_Check(obj) || obj == Py_Ellipsis || \
+ obj == Py_None) {
+ retval = SOBJ_NOTFANCY;
+ }
+ Py_DECREF(obj);
+ if (retval > SOBJ_ISFANCY) return retval;
+ }
+ }
+ return retval;
}
/* Called when treating array object like a mapping -- called first from
@@ -2592,37 +2592,37 @@
array_subscript_simple(PyArrayObject *self, PyObject *op)
{
intp dimensions[MAX_DIMS], strides[MAX_DIMS];
- intp offset;
+ intp offset;
int nd;
PyArrayObject *other;
- intp value;
+ intp value;
- value = PyArray_PyIntAsIntp(op);
- if (!PyErr_Occurred()) {
- return array_big_item(self, value);
- }
- PyErr_Clear();
-
- /* Standard (view-based) Indexing */
+ value = PyArray_PyIntAsIntp(op);
+ if (!PyErr_Occurred()) {
+ return array_big_item(self, value);
+ }
+ PyErr_Clear();
+
+ /* Standard (view-based) Indexing */
if ((nd = parse_index(self, op, dimensions, strides, &offset))
== -1) return NULL;
- /* This will only work if new array will be a view */
- Py_INCREF(self->descr);
- if ((other = (PyArrayObject *) \
- PyArray_NewFromDescr(self->ob_type, self->descr,
- nd, dimensions,
- strides, self->data+offset,
- self->flags,
- (PyObject *)self)) == NULL)
- return NULL;
-
- other->base = (PyObject *)self;
- Py_INCREF(self);
-
- PyArray_UpdateFlags(other, UPDATE_ALL);
-
- return (PyObject *)other;
+ /* This will only work if new array will be a view */
+ Py_INCREF(self->descr);
+ if ((other = (PyArrayObject *) \
+ PyArray_NewFromDescr(self->ob_type, self->descr,
+ nd, dimensions,
+ strides, self->data+offset,
+ self->flags,
+ (PyObject *)self)) == NULL)
+ return NULL;
+
+ other->base = (PyObject *)self;
+ Py_INCREF(self);
+
+ PyArray_UpdateFlags(other, UPDATE_ALL);
+
+ return (PyObject *)other;
}
static PyObject *
@@ -2630,93 +2630,93 @@
{
int nd, oned, fancy;
PyArrayObject *other;
- PyArrayMapIterObject *mit;
+ PyArrayMapIterObject *mit;
- if (PyString_Check(op) || PyUnicode_Check(op)) {
- if (self->descr->names) {
- PyObject *obj;
- obj = PyDict_GetItem(self->descr->fields, op);
- if (obj != NULL) {
- PyArray_Descr *descr;
- int offset;
- PyObject *title;
+ if (PyString_Check(op) || PyUnicode_Check(op)) {
+ if (self->descr->names) {
+ PyObject *obj;
+ obj = PyDict_GetItem(self->descr->fields, op);
+ if (obj != NULL) {
+ PyArray_Descr *descr;
+ int offset;
+ PyObject *title;
- if (PyArg_ParseTuple(obj, "Oi|O",
- &descr, &offset, &title)) {
- Py_INCREF(descr);
- return PyArray_GetField(self, descr,
- offset);
- }
- }
- }
+ if (PyArg_ParseTuple(obj, "Oi|O",
+ &descr, &offset, &title)) {
+ Py_INCREF(descr);
+ return PyArray_GetField(self, descr,
+ offset);
+ }
+ }
+ }
- PyErr_Format(PyExc_ValueError,
- "field named %s not found.",
- PyString_AsString(op));
- return NULL;
- }
+ PyErr_Format(PyExc_ValueError,
+ "field named %s not found.",
+ PyString_AsString(op));
+ return NULL;
+ }
if (self->nd == 0) {
- if (op == Py_Ellipsis) {
- /* XXX: This leads to a small inconsistency
- XXX: with the nd>0 case where (x[...] is x)
- XXX: is false for nd>0 case. */
- Py_INCREF(self);
- return (PyObject *)self;
- }
- if (op == Py_None)
- return add_new_axes_0d(self, 1);
- if (PyTuple_Check(op)) {
- if (0 == PyTuple_GET_SIZE(op)) {
- Py_INCREF(self);
- return (PyObject *)self;
- }
- if ((nd = count_new_axes_0d(op)) == -1)
- return NULL;
- return add_new_axes_0d(self, nd);
- }
+ if (op == Py_Ellipsis) {
+ /* XXX: This leads to a small inconsistency
+ XXX: with the nd>0 case where (x[...] is x)
+ XXX: is false for nd>0 case. */
+ Py_INCREF(self);
+ return (PyObject *)self;
+ }
+ if (op == Py_None)
+ return add_new_axes_0d(self, 1);
+ if (PyTuple_Check(op)) {
+ if (0 == PyTuple_GET_SIZE(op)) {
+ Py_INCREF(self);
+ return (PyObject *)self;
+ }
+ if ((nd = count_new_axes_0d(op)) == -1)
+ return NULL;
+ return add_new_axes_0d(self, nd);
+ }
PyErr_SetString(PyExc_IndexError,
"0-d arrays can't be indexed.");
return NULL;
}
- if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) ||
- PyLong_Check(op)) {
- intp value;
- value = PyArray_PyIntAsIntp(op);
- if (!PyErr_Occurred()) {
- return array_big_item(self, value);
- }
- PyErr_Clear();
- }
+ if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) ||
+ PyLong_Check(op)) {
+ intp value;
+ value = PyArray_PyIntAsIntp(op);
+ if (!PyErr_Occurred()) {
+ return array_big_item(self, value);
+ }
+ PyErr_Clear();
+ }
- fancy = fancy_indexing_check(op);
+ fancy = fancy_indexing_check(op);
- if (fancy != SOBJ_NOTFANCY) {
- oned = ((self->nd == 1) && !(PyTuple_Check(op) && \
- PyTuple_GET_SIZE(op) > 1));
+ if (fancy != SOBJ_NOTFANCY) {
+ oned = ((self->nd == 1) && !(PyTuple_Check(op) && \
+ PyTuple_GET_SIZE(op) > 1));
- /* wrap arguments into a mapiter object */
- mit = (PyArrayMapIterObject *)\
- PyArray_MapIterNew(op, oned, fancy);
- if (mit == NULL) return NULL;
- if (oned) {
- PyArrayIterObject *it;
- PyObject *rval;
- it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
- if (it == NULL) {Py_DECREF(mit); return NULL;}
- rval = iter_subscript(it, mit->indexobj);
- Py_DECREF(it);
- Py_DECREF(mit);
- return rval;
- }
+ /* wrap arguments into a mapiter object */
+ mit = (PyArrayMapIterObject *)\
+ PyArray_MapIterNew(op, oned, fancy);
+ if (mit == NULL) return NULL;
+ if (oned) {
+ PyArrayIterObject *it;
+ PyObject *rval;
+ it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
+ if (it == NULL) {Py_DECREF(mit); return NULL;}
+ rval = iter_subscript(it, mit->indexobj);
+ Py_DECREF(it);
+ Py_DECREF(mit);
+ return rval;
+ }
PyArray_MapIterBind(mit, self);
other = (PyArrayObject *)PyArray_GetMap(mit);
Py_DECREF(mit);
return (PyObject *)other;
}
- return array_subscript_simple(self, op);
+ return array_subscript_simple(self, op);
}
@@ -2736,41 +2736,41 @@
{
int ret;
PyArrayObject *tmp;
- intp value;
+ intp value;
- value = PyArray_PyIntAsIntp(index);
- if (!error_converting(value)) {
- return array_ass_big_item(self, value, op);
- }
- PyErr_Clear();
-
- /* Rest of standard (view-based) indexing */
+ value = PyArray_PyIntAsIntp(index);
+ if (!error_converting(value)) {
+ return array_ass_big_item(self, value, op);
+ }
+ PyErr_Clear();
+
+ /* Rest of standard (view-based) indexing */
- if (PyArray_CheckExact(self)) {
- tmp = (PyArrayObject *)array_subscript_simple(self, index);
- if (tmp == NULL) return -1;
- }
- else {
- PyObject *tmp0;
- tmp0 = PyObject_GetItem((PyObject *)self, index);
- if (tmp0 == NULL) return -1;
- if (!PyArray_Check(tmp0)) {
- PyErr_SetString(PyExc_RuntimeError,
- "Getitem not returning array.");
- Py_DECREF(tmp0);
- return -1;
- }
- tmp = (PyArrayObject *)tmp0;
- }
-
- if (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {
- ret = tmp->descr->f->setitem(op, tmp->data, tmp);
- }
- else {
- ret = PyArray_CopyObject(tmp, op);
- }
- Py_DECREF(tmp);
- return ret;
+ if (PyArray_CheckExact(self)) {
+ tmp = (PyArrayObject *)array_subscript_simple(self, index);
+ if (tmp == NULL) return -1;
+ }
+ else {
+ PyObject *tmp0;
+ tmp0 = PyObject_GetItem((PyObject *)self, index);
+ if (tmp0 == NULL) return -1;
+ if (!PyArray_Check(tmp0)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Getitem not returning array.");
+ Py_DECREF(tmp0);
+ return -1;
+ }
+ tmp = (PyArrayObject *)tmp0;
+ }
+
+ if (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {
+ ret = tmp->descr->f->setitem(op, tmp->data, tmp);
+ }
+ else {
+ ret = PyArray_CopyObject(tmp, op);
+ }
+ Py_DECREF(tmp);
+ return ret;
}
@@ -2778,111 +2778,111 @@
array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)
{
int ret, oned, fancy;
- PyArrayMapIterObject *mit;
- intp vals[MAX_DIMS];
+ PyArrayMapIterObject *mit;
+ intp vals[MAX_DIMS];
if (op == NULL) {
PyErr_SetString(PyExc_ValueError,
"cannot delete array elements");
return -1;
}
- if (!PyArray_ISWRITEABLE(self)) {
- PyErr_SetString(PyExc_RuntimeError,
- "array is not writeable");
- return -1;
- }
+ if (!PyArray_ISWRITEABLE(self)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "array is not writeable");
+ return -1;
+ }
- if (PyInt_Check(index) || PyArray_IsScalar(index, Integer) ||
- PyLong_Check(index)) {
- intp value;
- value = PyArray_PyIntAsIntp(index);
- if (PyErr_Occurred())
- PyErr_Clear();
- else
- return array_ass_big_item(self, value, op);
- }
+ if (PyInt_Check(index) || PyArray_IsScalar(index, Integer) ||
+ PyLong_Check(index)) {
+ intp value;
+ value = PyArray_PyIntAsIntp(index);
+ if (PyErr_Occurred())
+ PyErr_Clear();
+ else
+ return array_ass_big_item(self, value, op);
+ }
- if (PyString_Check(index) || PyUnicode_Check(index)) {
+ if (PyString_Check(index) || PyUnicode_Check(index)) {
if (self->descr->names) {
- PyObject *obj;
- obj = PyDict_GetItem(self->descr->fields, index);
- if (obj != NULL) {
- PyArray_Descr *descr;
- int offset;
- PyObject *title;
+ PyObject *obj;
+ obj = PyDict_GetItem(self->descr->fields, index);
+ if (obj != NULL) {
+ PyArray_Descr *descr;
+ int offset;
+ PyObject *title;
- if (PyArg_ParseTuple(obj, "Oi|O",
- &descr, &offset, &title)) {
- Py_INCREF(descr);
- return PyArray_SetField(self, descr,
- offset, op);
- }
- }
- }
+ if (PyArg_ParseTuple(obj, "Oi|O",
+ &descr, &offset, &title)) {
+ Py_INCREF(descr);
+ return PyArray_SetField(self, descr,
+ offset, op);
+ }
+ }
+ }
- PyErr_Format(PyExc_ValueError,
- "field named %s not found.",
- PyString_AsString(index));
- return -1;
- }
+ PyErr_Format(PyExc_ValueError,
+ "field named %s not found.",
+ PyString_AsString(index));
+ return -1;
+ }
if (self->nd == 0) {
- if (index == Py_Ellipsis || index == Py_None || \
- (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \
- count_new_axes_0d(index) > 0)))
- return self->descr->f->setitem(op, self->data, self);
+ if (index == Py_Ellipsis || index == Py_None || \
+ (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \
+ count_new_axes_0d(index) > 0)))
+ return self->descr->f->setitem(op, self->data, self);
PyErr_SetString(PyExc_IndexError,
"0-d arrays can't be indexed.");
return -1;
}
- /* optimization for integer-tuple */
- if (self->nd > 1 && (PyTuple_Check(index) && (PyTuple_GET_SIZE(index) == self->nd)) \
- && PyArray_IntpFromSequence(index, vals, self->nd) == self->nd) {
- int i;
- char *item;
- for (i=0; i<self->nd; i++) {
- if (vals[i] < 0) vals[i] += self->dimensions[i];
- if ((vals[i] < 0) || (vals[i] >= self->dimensions[i])) {
- PyErr_Format(PyExc_IndexError,
- "index (%"INTP_FMT") out of range "\
- "(0<=index<%"INTP_FMT") in dimension %d",
- vals[i], self->dimensions[i], i);
- return -1;
- }
- }
- item = PyArray_GetPtr(self, vals);
- /* fprintf(stderr, "Here I am...\n");*/
- return self->descr->f->setitem(op, item, self);
- }
- PyErr_Clear();
+ /* optimization for integer-tuple */
+ if (self->nd > 1 && (PyTuple_Check(index) && (PyTuple_GET_SIZE(index) == self->nd)) \
+ && PyArray_IntpFromSequence(index, vals, self->nd) == self->nd) {
+ int i;
+ char *item;
+ for (i=0; i<self->nd; i++) {
+ if (vals[i] < 0) vals[i] += self->dimensions[i];
+ if ((vals[i] < 0) || (vals[i] >= self->dimensions[i])) {
+ PyErr_Format(PyExc_IndexError,
+ "index (%"INTP_FMT") out of range "\
+ "(0<=index<%"INTP_FMT") in dimension %d",
+ vals[i], self->dimensions[i], i);
+ return -1;
+ }
+ }
+ item = PyArray_GetPtr(self, vals);
+ /* fprintf(stderr, "Here I am...\n");*/
+ return self->descr->f->setitem(op, item, self);
+ }
+ PyErr_Clear();
- fancy = fancy_indexing_check(index);
+ fancy = fancy_indexing_check(index);
- if (fancy != SOBJ_NOTFANCY) {
- oned = ((self->nd == 1) && !(PyTuple_Check(index) && \
- PyTuple_GET_SIZE(index) > 1));
+ if (fancy != SOBJ_NOTFANCY) {
+ oned = ((self->nd == 1) && !(PyTuple_Check(index) && \
+ PyTuple_GET_SIZE(index) > 1));
- mit = (PyArrayMapIterObject *) \
- PyArray_MapIterNew(index, oned, fancy);
- if (mit == NULL) return -1;
- if (oned) {
- PyArrayIterObject *it;
- int rval;
- it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
- if (it == NULL) {Py_DECREF(mit); return -1;}
- rval = iter_ass_subscript(it, mit->indexobj, op);
- Py_DECREF(it);
- Py_DECREF(mit);
- return rval;
- }
+ mit = (PyArrayMapIterObject *) \
+ PyArray_MapIterNew(index, oned, fancy);
+ if (mit == NULL) return -1;
+ if (oned) {
+ PyArrayIterObject *it;
+ int rval;
+ it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
+ if (it == NULL) {Py_DECREF(mit); return -1;}
+ rval = iter_ass_subscript(it, mit->indexobj, op);
+ Py_DECREF(it);
+ Py_DECREF(mit);
+ return rval;
+ }
PyArray_MapIterBind(mit, self);
ret = PyArray_SetMap(mit, op);
Py_DECREF(mit);
return ret;
}
- return array_ass_sub_simple(self, index, op);
+ return array_ass_sub_simple(self, index, op);
}
@@ -2895,89 +2895,89 @@
array_subscript_nice(PyArrayObject *self, PyObject *op)
{
- PyArrayObject *mp;
- intp vals[MAX_DIMS];
+ PyArrayObject *mp;
+ intp vals[MAX_DIMS];
- if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) || \
- PyLong_Check(op)) {
- intp value;
- value = PyArray_PyIntAsIntp(op);
- if (PyErr_Occurred())
- PyErr_Clear();
- else {
- return array_item_nice(self, (Py_ssize_t) value);
- }
- }
- /* optimization for a tuple of integers */
- if (self->nd > 1 && PyTuple_Check(op) &&
- (PyTuple_GET_SIZE(op) == self->nd)
- && PyArray_IntpFromSequence(op, vals, self->nd) == self->nd) {
- int i;
- char *item;
- for (i=0; i<self->nd; i++) {
- if (vals[i] < 0) vals[i] += self->dimensions[i];
- if ((vals[i] < 0) || (vals[i] >= self->dimensions[i])) {
- PyErr_Format(PyExc_IndexError,
- "index (%"INTP_FMT") out of range "\
- "(0<=index<=%"INTP_FMT") in dimension %d",
- vals[i], self->dimensions[i], i);
- return NULL;
- }
- }
- item = PyArray_GetPtr(self, vals);
- return PyArray_Scalar(item, self->descr, (PyObject *)self);
- }
- PyErr_Clear();
+ if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) || \
+ PyLong_Check(op)) {
+ intp value;
+ value = PyArray_PyIntAsIntp(op);
+ if (PyErr_Occurred())
+ PyErr_Clear();
+ else {
+ return array_item_nice(self, (Py_ssize_t) value);
+ }
+ }
+ /* optimization for a tuple of integers */
+ if (self->nd > 1 && PyTuple_Check(op) &&
+ (PyTuple_GET_SIZE(op) == self->nd)
+ && PyArray_IntpFromSequence(op, vals, self->nd) == self->nd) {
+ int i;
+ char *item;
+ for (i=0; i<self->nd; i++) {
+ if (vals[i] < 0) vals[i] += self->dimensions[i];
+ if ((vals[i] < 0) || (vals[i] >= self->dimensions[i])) {
+ PyErr_Format(PyExc_IndexError,
+ "index (%"INTP_FMT") out of range "\
+ "(0<=index<=%"INTP_FMT") in dimension %d",
+ vals[i], self->dimensions[i], i);
+ return NULL;
+ }
+ }
+ item = PyArray_GetPtr(self, vals);
+ return PyArray_Scalar(item, self->descr, (PyObject *)self);
+ }
+ PyErr_Clear();
- mp = (PyArrayObject *)array_subscript(self, op);
+ mp = (PyArrayObject *)array_subscript(self, op);
- /* The following is just a copy of PyArray_Return with an
- additional logic in the nd == 0 case.
- */
+ /* The following is just a copy of PyArray_Return with an
+ additional logic in the nd == 0 case.
+ */
- if (mp == NULL) return NULL;
+ if (mp == NULL) return NULL;
if (PyErr_Occurred()) {
Py_XDECREF(mp);
return NULL;
}
-
- if (mp->nd == 0) {
- Bool noellipses = TRUE;
- if (op == Py_Ellipsis)
- noellipses = FALSE;
- else if (PySequence_Check(op)) {
- int n, i;
- PyObject *temp;
- n = PySequence_Size(op);
- i=0;
- while (i<n && noellipses) {
- temp = PySequence_GetItem(op, i);
- if (temp == Py_Ellipsis)
- noellipses = FALSE;
- Py_DECREF(temp);
- i++;
- }
- }
- if (noellipses) {
- PyObject *ret;
- ret = PyArray_ToScalar(mp->data, mp);
- Py_DECREF(mp);
- return ret;
- }
- }
- return (PyObject *)mp;
+
+ if (mp->nd == 0) {
+ Bool noellipses = TRUE;
+ if (op == Py_Ellipsis)
+ noellipses = FALSE;
+ else if (PySequence_Check(op)) {
+ int n, i;
+ PyObject *temp;
+ n = PySequence_Size(op);
+ i=0;
+ while (i<n && noellipses) {
+ temp = PySequence_GetItem(op, i);
+ if (temp == Py_Ellipsis)
+ noellipses = FALSE;
+ Py_DECREF(temp);
+ i++;
+ }
+ }
+ if (noellipses) {
+ PyObject *ret;
+ ret = PyArray_ToScalar(mp->data, mp);
+ Py_DECREF(mp);
+ return ret;
+ }
+ }
+ return (PyObject *)mp;
}
static PyMappingMethods array_as_mapping = {
#if PY_VERSION_HEX >= 0x02050000
- (lenfunc)array_length, /*mp_length*/
+ (lenfunc)array_length, /*mp_length*/
#else
- (inquiry)array_length, /*mp_length*/
+ (inquiry)array_length, /*mp_length*/
#endif
- (binaryfunc)array_subscript_nice, /*mp_subscript*/
- (objobjargproc)array_ass_sub, /*mp_ass_subscript*/
+ (binaryfunc)array_subscript_nice, /*mp_subscript*/
+ (objobjargproc)array_ass_sub, /*mp_ass_subscript*/
};
/****************** End of Mapping Protocol ******************************/
@@ -3039,7 +3039,7 @@
array_getcharbuf(PyArrayObject *self, Py_ssize_t segment, const char **ptrptr)
{
if (self->descr->type_num == PyArray_STRING || \
- self->descr->type_num == PyArray_UNICODE)
+ self->descr->type_num == PyArray_UNICODE)
return array_getreadbuf(self, segment, (void **) ptrptr);
else {
PyErr_SetString(PyExc_TypeError,
@@ -3053,12 +3053,12 @@
#if PY_VERSION_HEX >= 0x02050000
(readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/
(writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/
- (segcountproc)array_getsegcount, /*bf_getsegcount*/
+ (segcountproc)array_getsegcount, /*bf_getsegcount*/
(charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/
#else
(getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/
(getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/
- (getsegcountproc)array_getsegcount, /*bf_getsegcount*/
+ (getsegcountproc)array_getsegcount, /*bf_getsegcount*/
(getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/
#endif
};
@@ -3081,7 +3081,7 @@
*square,
*reciprocal,
*ones_like,
- *sqrt,
+ *sqrt,
*negative,
*absolute,
*invert,
@@ -3098,13 +3098,13 @@
*greater_equal,
*floor_divide,
*true_divide,
- *logical_or,
- *logical_and,
- *floor,
- *ceil,
- *maximum,
- *minimum,
- *rint;
+ *logical_or,
+ *logical_and,
+ *floor,
+ *ceil,
+ *maximum,
+ *minimum,
+ *rint;
} NumericOps;
static NumericOps n_ops; /* NB: static objects inlitialized to zero */
@@ -3113,12 +3113,12 @@
Those not present will not be changed
*/
-#define SET(op) temp=PyDict_GetItemString(dict, #op); \
- if (temp != NULL) { \
- if (!(PyCallable_Check(temp))) return -1; \
+#define SET(op) temp=PyDict_GetItemString(dict, #op); \
+ if (temp != NULL) { \
+ if (!(PyCallable_Check(temp))) return -1; \
Py_XDECREF(n_ops.op); \
- n_ops.op = temp; \
- }
+ n_ops.op = temp; \
+ }
/*OBJECT_API
@@ -3137,7 +3137,7 @@
SET(square);
SET(reciprocal);
SET(ones_like);
- SET(sqrt);
+ SET(sqrt);
SET(negative);
SET(absolute);
SET(invert);
@@ -3154,19 +3154,19 @@
SET(greater_equal);
SET(floor_divide);
SET(true_divide);
- SET(logical_or);
- SET(logical_and);
- SET(floor);
- SET(ceil);
- SET(maximum);
- SET(minimum);
- SET(rint);
+ SET(logical_or);
+ SET(logical_and);
+ SET(floor);
+ SET(ceil);
+ SET(maximum);
+ SET(minimum);
+ SET(rint);
return 0;
}
-#define GET(op) if (n_ops.op && \
- (PyDict_SetItemString(dict, #op, n_ops.op)==-1)) \
- goto fail;
+#define GET(op) if (n_ops.op && \
+ (PyDict_SetItemString(dict, #op, n_ops.op)==-1)) \
+ goto fail;
/*OBJECT_API
Get dictionary showing number functions that all arrays will use
@@ -3174,10 +3174,10 @@
static PyObject *
PyArray_GetNumericOps(void)
{
- PyObject *dict;
- if ((dict = PyDict_New())==NULL)
- return NULL;
- GET(add);
+ PyObject *dict;
+ if ((dict = PyDict_New())==NULL)
+ return NULL;
+ GET(add);
GET(subtract);
GET(multiply);
GET(divide);
@@ -3186,7 +3186,7 @@
GET(square);
GET(reciprocal);
GET(ones_like);
- GET(sqrt);
+ GET(sqrt);
GET(negative);
GET(absolute);
GET(invert);
@@ -3203,71 +3203,71 @@
GET(greater_equal);
GET(floor_divide);
GET(true_divide);
- GET(logical_or);
- GET(logical_and);
- GET(floor);
- GET(ceil);
- GET(maximum);
- GET(minimum);
- GET(rint);
- return dict;
+ GET(logical_or);
+ GET(logical_and);
+ GET(floor);
+ GET(ceil);
+ GET(maximum);
+ GET(minimum);
+ GET(rint);
+ return dict;
fail:
- Py_DECREF(dict);
- return NULL;
+ Py_DECREF(dict);
+ return NULL;
}
static PyObject *
PyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,
- int rtype)
+ int rtype)
{
- PyObject *args, *ret=NULL, *meth;
- if (op == NULL) {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
- }
- if (rtype == PyArray_NOTYPE)
- args = Py_BuildValue("(Oi)", m1, axis);
- else {
- PyArray_Descr *descr;
- descr = PyArray_DescrFromType(rtype);
- args = Py_BuildValue("(Oic)", m1, axis, descr->type);
- Py_DECREF(descr);
- }
- meth = PyObject_GetAttrString(op, "reduce");
- if (meth && PyCallable_Check(meth)) {
- ret = PyObject_Call(meth, args, NULL);
- }
- Py_DECREF(args);
- Py_DECREF(meth);
- return ret;
+ PyObject *args, *ret=NULL, *meth;
+ if (op == NULL) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+ if (rtype == PyArray_NOTYPE)
+ args = Py_BuildValue("(Oi)", m1, axis);
+ else {
+ PyArray_Descr *descr;
+ descr = PyArray_DescrFromType(rtype);
+ args = Py_BuildValue("(Oic)", m1, axis, descr->type);
+ Py_DECREF(descr);
+ }
+ meth = PyObject_GetAttrString(op, "reduce");
+ if (meth && PyCallable_Check(meth)) {
+ ret = PyObject_Call(meth, args, NULL);
+ }
+ Py_DECREF(args);
+ Py_DECREF(meth);
+ return ret;
}
static PyObject *
PyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,
- int rtype)
+ int rtype)
{
- PyObject *args, *ret=NULL, *meth;
- if (op == NULL) {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
- }
- if (rtype == PyArray_NOTYPE)
- args = Py_BuildValue("(Oi)", m1, axis);
- else {
- PyArray_Descr *descr;
- descr = PyArray_DescrFromType(rtype);
- args = Py_BuildValue("(Oic)", m1, axis, descr->type);
- Py_DECREF(descr);
- }
- meth = PyObject_GetAttrString(op, "accumulate");
- if (meth && PyCallable_Check(meth)) {
- ret = PyObject_Call(meth, args, NULL);
- }
- Py_DECREF(args);
- Py_DECREF(meth);
- return ret;
+ PyObject *args, *ret=NULL, *meth;
+ if (op == NULL) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+ if (rtype == PyArray_NOTYPE)
+ args = Py_BuildValue("(Oi)", m1, axis);
+ else {
+ PyArray_Descr *descr;
+ descr = PyArray_DescrFromType(rtype);
+ args = Py_BuildValue("(Oic)", m1, axis, descr->type);
+ Py_DECREF(descr);
+ }
+ meth = PyObject_GetAttrString(op, "accumulate");
+ if (meth && PyCallable_Check(meth)) {
+ ret = PyObject_Call(meth, args, NULL);
+ }
+ Py_DECREF(args);
+ Py_DECREF(meth);
+ return ret;
}
@@ -3293,7 +3293,7 @@
static PyObject *
PyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,
- PyObject *m2, PyObject *op)
+ PyObject *m2, PyObject *op)
{
if (op == NULL) {
Py_INCREF(Py_NotImplemented);
@@ -3321,7 +3321,7 @@
static PyObject *
array_subtract(PyArrayObject *m1, PyObject *m2)
{
- return PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);
+ return PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);
}
static PyObject *
@@ -3349,24 +3349,24 @@
const int optimize_fpexps = 1;
if (PyInt_Check(o2)) {
- *exp = (double)PyInt_AsLong(o2);
- return 1;
+ *exp = (double)PyInt_AsLong(o2);
+ return 1;
}
if (optimize_fpexps && PyFloat_Check(o2)) {
- *exp = PyFloat_AsDouble(o2);
- return 1;
+ *exp = PyFloat_AsDouble(o2);
+ return 1;
}
if ((PyArray_IsZeroDim(o2) &&
- ((PyArray_ISINTEGER(o2) ||
- (optimize_fpexps && PyArray_ISFLOAT(o2))))) ||
- PyArray_IsScalar(o2, Integer) ||
- (optimize_fpexps && PyArray_IsScalar(o2, Floating))) {
- temp = o2->ob_type->tp_as_number->nb_float(o2);
- if (temp != NULL) {
- *exp = PyFloat_AsDouble(o2);
- Py_DECREF(temp);
- return 1;
- }
+ ((PyArray_ISINTEGER(o2) ||
+ (optimize_fpexps && PyArray_ISFLOAT(o2))))) ||
+ PyArray_IsScalar(o2, Integer) ||
+ (optimize_fpexps && PyArray_IsScalar(o2, Floating))) {
+ temp = o2->ob_type->tp_as_number->nb_float(o2);
+ if (temp != NULL) {
+ *exp = PyFloat_AsDouble(o2);
+ Py_DECREF(temp);
+ return 1;
+ }
}
return 0;
}
@@ -3374,56 +3374,56 @@
/* optimize float array or complex array to a scalar power */
static PyObject *
fast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {
- double exp;
- if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) ||
- PyArray_ISCOMPLEX(a1))) {
- if (array_power_is_scalar(o2, &exp)) {
- PyObject *fastop = NULL;
- if (exp == 1.0) {
- /* we have to do this one special, as the
- "copy" method of array objects isn't set
- up early enough to be added
- by PyArray_SetNumericOps.
- */
- if (inplace) {
- Py_INCREF(a1);
- return (PyObject *)a1;
- } else {
- return PyArray_Copy(a1);
- }
- } else if (exp == -1.0) {
- fastop = n_ops.reciprocal;
- } else if (exp == 0.0) {
- fastop = n_ops.ones_like;
- } else if (exp == 0.5) {
- fastop = n_ops.sqrt;
- } else if (exp == 2.0) {
- fastop = n_ops.square;
- } else {
- return NULL;
- }
- if (inplace) {
- return PyArray_GenericInplaceUnaryFunction(a1,
- fastop);
- } else {
- return PyArray_GenericUnaryFunction(a1,
- fastop);
- }
- }
- }
- return NULL;
+ double exp;
+ if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) ||
+ PyArray_ISCOMPLEX(a1))) {
+ if (array_power_is_scalar(o2, &exp)) {
+ PyObject *fastop = NULL;
+ if (exp == 1.0) {
+ /* we have to do this one special, as the
+ "copy" method of array objects isn't set
+ up early enough to be added
+ by PyArray_SetNumericOps.
+ */
+ if (inplace) {
+ Py_INCREF(a1);
+ return (PyObject *)a1;
+ } else {
+ return PyArray_Copy(a1);
+ }
+ } else if (exp == -1.0) {
+ fastop = n_ops.reciprocal;
+ } else if (exp == 0.0) {
+ fastop = n_ops.ones_like;
+ } else if (exp == 0.5) {
+ fastop = n_ops.sqrt;
+ } else if (exp == 2.0) {
+ fastop = n_ops.square;
+ } else {
+ return NULL;
+ }
+ if (inplace) {
+ return PyArray_GenericInplaceUnaryFunction(a1,
+ fastop);
+ } else {
+ return PyArray_GenericUnaryFunction(a1,
+ fastop);
+ }
+ }
+ }
+ return NULL;
}
static PyObject *
array_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)
{
- /* modulo is ignored! */
- PyObject *value;
- value = fast_scalar_power(a1, o2, 0);
- if (!value) {
- value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);
- }
- return value;
+ /* modulo is ignored! */
+ PyObject *value;
+ value = fast_scalar_power(a1, o2, 0);
+ if (!value) {
+ value = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);
+ }
+ return value;
}
@@ -3563,56 +3563,56 @@
array_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)
{
return PyArray_GenericInplaceBinaryFunction(m1, m2,
- n_ops.floor_divide);
+ n_ops.floor_divide);
}
static PyObject *
array_inplace_true_divide(PyArrayObject *m1, PyObject *m2)
{
return PyArray_GenericInplaceBinaryFunction(m1, m2,
- n_ops.true_divide);
+ n_ops.true_divide);
}
/* Array evaluates as "TRUE" if any of the elements are non-zero*/
static int
array_any_nonzero(PyArrayObject *mp)
{
- intp index;
- PyArrayIterObject *it;
- Bool anyTRUE = FALSE;
+ intp index;
+ PyArrayIterObject *it;
+ Bool anyTRUE = FALSE;
- it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);
- if (it==NULL) return anyTRUE;
- index = it->size;
- while(index--) {
- if (mp->descr->f->nonzero(it->dataptr, mp)) {
- anyTRUE = TRUE;
- break;
- }
- PyArray_ITER_NEXT(it);
- }
- Py_DECREF(it);
- return anyTRUE;
+ it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);
+ if (it==NULL) return anyTRUE;
+ index = it->size;
+ while(index--) {
+ if (mp->descr->f->nonzero(it->dataptr, mp)) {
+ anyTRUE = TRUE;
+ break;
+ }
+ PyArray_ITER_NEXT(it);
+ }
+ Py_DECREF(it);
+ return anyTRUE;
}
static int
_array_nonzero(PyArrayObject *mp)
{
- intp n;
- n = PyArray_SIZE(mp);
- if (n == 1) {
- return mp->descr->f->nonzero(mp->data, mp);
- }
- else if (n == 0) {
- return 0;
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "The truth value of an array " \
- "with more than one element is ambiguous. " \
- "Use a.any() or a.all()");
- return -1;
- }
+ intp n;
+ n = PyArray_SIZE(mp);
+ if (n == 1) {
+ return mp->descr->f->nonzero(mp->data, mp);
+ }
+ else if (n == 0) {
+ return 0;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "The truth value of an array " \
+ "with more than one element is ambiguous. " \
+ "Use a.any() or a.all()");
+ return -1;
+ }
}
@@ -3642,20 +3642,20 @@
PyObject *pv, *pv2;
if (PyArray_SIZE(v) != 1) {
PyErr_SetString(PyExc_TypeError, "only length-1 arrays can be"\
- " converted to Python scalars");
+ " converted to Python scalars");
return NULL;
}
pv = v->descr->f->getitem(v->data, v);
if (pv == NULL) return NULL;
if (pv->ob_type->tp_as_number == 0) {
PyErr_SetString(PyExc_TypeError, "cannot convert to an int; "\
- "scalar object is not a number");
+ "scalar object is not a number");
Py_DECREF(pv);
return NULL;
}
if (pv->ob_type->tp_as_number->nb_int == 0) {
PyErr_SetString(PyExc_TypeError, "don't know how to convert "\
- "scalar number to int");
+ "scalar number to int");
Py_DECREF(pv);
return NULL;
}
@@ -3671,20 +3671,20 @@
PyObject *pv, *pv2;
if (PyArray_SIZE(v) != 1) {
PyErr_SetString(PyExc_TypeError, "only length-1 arrays can "\
- "be converted to Python scalars");
+ "be converted to Python scalars");
return NULL;
}
pv = v->descr->f->getitem(v->data, v);
if (pv == NULL) return NULL;
if (pv->ob_type->tp_as_number == 0) {
PyErr_SetString(PyExc_TypeError, "cannot convert to a "\
- "float; scalar object is not a number");
+ "float; scalar object is not a number");
Py_DECREF(pv);
return NULL;
}
if (pv->ob_type->tp_as_number->nb_float == 0) {
PyErr_SetString(PyExc_TypeError, "don't know how to convert "\
- "scalar number to float");
+ "scalar number to float");
Py_DECREF(pv);
return NULL;
}
@@ -3699,18 +3699,18 @@
PyObject *pv, *pv2;
if (PyArray_SIZE(v) != 1) {
PyErr_SetString(PyExc_TypeError, "only length-1 arrays can "\
- "be converted to Python scalars");
+ "be converted to Python scalars");
return NULL;
}
pv = v->descr->f->getitem(v->data, v);
if (pv->ob_type->tp_as_number == 0) {
PyErr_SetString(PyExc_TypeError, "cannot convert to an int; "\
- "scalar object is not a number");
+ "scalar object is not a number");
return NULL;
}
if (pv->ob_type->tp_as_number->nb_long == 0) {
PyErr_SetString(PyExc_TypeError, "don't know how to convert "\
- "scalar number to long");
+ "scalar number to long");
return NULL;
}
pv2 = pv->ob_type->tp_as_number->nb_long(pv);
@@ -3724,18 +3724,18 @@
PyObject *pv, *pv2;
if (PyArray_SIZE(v) != 1) {
PyErr_SetString(PyExc_TypeError, "only length-1 arrays can "\
- "be converted to Python scalars");
+ "be converted to Python scalars");
return NULL;
}
pv = v->descr->f->getitem(v->data, v);
if (pv->ob_type->tp_as_number == 0) {
PyErr_SetString(PyExc_TypeError, "cannot convert to an int; "\
- "scalar object is not a number");
+ "scalar object is not a number");
return NULL;
}
if (pv->ob_type->tp_as_number->nb_oct == 0) {
PyErr_SetString(PyExc_TypeError, "don't know how to convert "\
- "scalar number to oct");
+ "scalar number to oct");
return NULL;
}
pv2 = pv->ob_type->tp_as_number->nb_oct(pv);
@@ -3749,18 +3749,18 @@
PyObject *pv, *pv2;
if (PyArray_SIZE(v) != 1) {
PyErr_SetString(PyExc_TypeError, "only length-1 arrays can "\
- "be converted to Python scalars");
+ "be converted to Python scalars");
return NULL;
}
pv = v->descr->f->getitem(v->data, v);
if (pv->ob_type->tp_as_number == 0) {
PyErr_SetString(PyExc_TypeError, "cannot convert to an int; "\
- "scalar object is not a number");
+ "scalar object is not a number");
return NULL;
}
if (pv->ob_type->tp_as_number->nb_hex == 0) {
PyErr_SetString(PyExc_TypeError, "don't know how to convert "\
- "scalar number to hex");
+ "scalar number to hex");
return NULL;
}
pv2 = pv->ob_type->tp_as_number->nb_hex(pv);
@@ -3771,51 +3771,51 @@
static PyObject *
_array_copy_nice(PyArrayObject *self)
{
- return PyArray_Return((PyArrayObject *) \
- PyArray_Copy(self));
+ return PyArray_Return((PyArrayObject *) \
+ PyArray_Copy(self));
}
static PyNumberMethods array_as_number = {
- (binaryfunc)array_add, /*nb_add*/
- (binaryfunc)array_subtract, /*nb_subtract*/
- (binaryfunc)array_multiply, /*nb_multiply*/
- (binaryfunc)array_divide, /*nb_divide*/
- (binaryfunc)array_remainder, /*nb_remainder*/
- (binaryfunc)array_divmod, /*nb_divmod*/
- (ternaryfunc)array_power, /*nb_power*/
+ (binaryfunc)array_add, /*nb_add*/
+ (binaryfunc)array_subtract, /*nb_subtract*/
+ (binaryfunc)array_multiply, /*nb_multiply*/
+ (binaryfunc)array_divide, /*nb_divide*/
+ (binaryfunc)array_remainder, /*nb_remainder*/
+ (binaryfunc)array_divmod, /*nb_divmod*/
+ (ternaryfunc)array_power, /*nb_power*/
(unaryfunc)array_negative, /*nb_neg*/
- (unaryfunc)_array_copy_nice, /*nb_pos*/
- (unaryfunc)array_absolute, /*(unaryfunc)array_abs,*/
- (inquiry)_array_nonzero, /*nb_nonzero*/
- (unaryfunc)array_invert, /*nb_invert*/
- (binaryfunc)array_left_shift, /*nb_lshift*/
- (binaryfunc)array_right_shift, /*nb_rshift*/
- (binaryfunc)array_bitwise_and, /*nb_and*/
- (binaryfunc)array_bitwise_xor, /*nb_xor*/
- (binaryfunc)array_bitwise_or, /*nb_or*/
- 0, /*nb_coerce*/
- (unaryfunc)array_int, /*nb_int*/
- (unaryfunc)array_long, /*nb_long*/
- (unaryfunc)array_float, /*nb_float*/
- (unaryfunc)array_oct, /*nb_oct*/
- (unaryfunc)array_hex, /*nb_hex*/
+ (unaryfunc)_array_copy_nice, /*nb_pos*/
+ (unaryfunc)array_absolute, /*(unaryfunc)array_abs,*/
+ (inquiry)_array_nonzero, /*nb_nonzero*/
+ (unaryfunc)array_invert, /*nb_invert*/
+ (binaryfunc)array_left_shift, /*nb_lshift*/
+ (binaryfunc)array_right_shift, /*nb_rshift*/
+ (binaryfunc)array_bitwise_and, /*nb_and*/
+ (binaryfunc)array_bitwise_xor, /*nb_xor*/
+ (binaryfunc)array_bitwise_or, /*nb_or*/
+ 0, /*nb_coerce*/
+ (unaryfunc)array_int, /*nb_int*/
+ (unaryfunc)array_long, /*nb_long*/
+ (unaryfunc)array_float, /*nb_float*/
+ (unaryfunc)array_oct, /*nb_oct*/
+ (unaryfunc)array_hex, /*nb_hex*/
/*This code adds augmented assignment functionality*/
/*that was made available in Python 2.0*/
- (binaryfunc)array_inplace_add, /*inplace_add*/
- (binaryfunc)array_inplace_subtract, /*inplace_subtract*/
- (binaryfunc)array_inplace_multiply, /*inplace_multiply*/
- (binaryfunc)array_inplace_divide, /*inplace_divide*/
+ (binaryfunc)array_inplace_add, /*inplace_add*/
+ (binaryfunc)array_inplace_subtract, /*inplace_subtract*/
+ (binaryfunc)array_inplace_multiply, /*inplace_multiply*/
+ (binaryfunc)array_inplace_divide, /*inplace_divide*/
(binaryfunc)array_inplace_remainder, /*inplace_remainder*/
- (ternaryfunc)array_inplace_power, /*inplace_power*/
+ (ternaryfunc)array_inplace_power, /*inplace_power*/
(binaryfunc)array_inplace_left_shift, /*inplace_lshift*/
(binaryfunc)array_inplace_right_shift, /*inplace_rshift*/
(binaryfunc)array_inplace_bitwise_and, /*inplace_and*/
(binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/
(binaryfunc)array_inplace_bitwise_or, /*inplace_or*/
- (binaryfunc)array_floor_divide, /*nb_floor_divide*/
- (binaryfunc)array_true_divide, /*nb_true_divide*/
+ (binaryfunc)array_floor_divide, /*nb_floor_divide*/
+ (binaryfunc)array_true_divide, /*nb_true_divide*/
(binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/
(binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/
@@ -3835,7 +3835,7 @@
static PyObject *
array_slice(PyArrayObject *self, Py_ssize_t ilow,
- Py_ssize_t ihigh)
+ Py_ssize_t ihigh)
{
PyArrayObject *r;
Py_ssize_t l;
@@ -3860,24 +3860,24 @@
}
self->dimensions[0] = ihigh-ilow;
- Py_INCREF(self->descr);
- r = (PyArrayObject *) \
- PyArray_NewFromDescr(self->ob_type, self->descr,
- self->nd, self->dimensions,
- self->strides, data,
- self->flags, (PyObject *)self);
+ Py_INCREF(self->descr);
+ r = (PyArrayObject *) \
+ PyArray_NewFromDescr(self->ob_type, self->descr,
+ self->nd, self->dimensions,
+ self->strides, data,
+ self->flags, (PyObject *)self);
self->dimensions[0] = l;
- if (r == NULL) return NULL;
+ if (r == NULL) return NULL;
r->base = (PyObject *)self;
Py_INCREF(self);
- PyArray_UpdateFlags(r, UPDATE_ALL);
+ PyArray_UpdateFlags(r, UPDATE_ALL);
return (PyObject *)r;
}
static int
array_ass_slice(PyArrayObject *self, Py_ssize_t ilow,
- Py_ssize_t ihigh, PyObject *v) {
+ Py_ssize_t ihigh, PyObject *v) {
int ret;
PyArrayObject *tmp;
@@ -3886,11 +3886,11 @@
"cannot delete array elements");
return -1;
}
- if (!PyArray_ISWRITEABLE(self)) {
- PyErr_SetString(PyExc_RuntimeError,
- "array is not writeable");
- return -1;
- }
+ if (!PyArray_ISWRITEABLE(self)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "array is not writeable");
+ return -1;
+ }
if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \
== NULL)
return -1;
@@ -3907,9 +3907,9 @@
PyObject *res;
int ret;
-
+
res = PyArray_EnsureAnyArray(PyObject_RichCompare((PyObject *)self,
- el, Py_EQ));
+ el, Py_EQ));
if (res == NULL) return -1;
ret = array_any_nonzero((PyArrayObject *)res);
Py_DECREF(res);
@@ -3918,27 +3918,27 @@
static PySequenceMethods array_as_sequence = {
#if PY_VERSION_HEX >= 0x02050000
- (lenfunc)array_length, /*sq_length*/
+ (lenfunc)array_length, /*sq_length*/
(binaryfunc)NULL, /* sq_concat is handled by nb_add*/
(ssizeargfunc)NULL,
- (ssizeargfunc)array_item_nice,
- (ssizessizeargfunc)array_slice,
- (ssizeobjargproc)array_ass_item, /*sq_ass_item*/
- (ssizessizeobjargproc)array_ass_slice, /*sq_ass_slice*/
- (objobjproc) array_contains, /* sq_contains */
- (binaryfunc) NULL, /* sg_inplace_concat */
- (ssizeargfunc)NULL,
+ (ssizeargfunc)array_item_nice,
+ (ssizessizeargfunc)array_slice,
+ (ssizeobjargproc)array_ass_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)array_ass_slice, /*sq_ass_slice*/
+ (objobjproc) array_contains, /* sq_contains */
+ (binaryfunc) NULL, /* sg_inplace_concat */
+ (ssizeargfunc)NULL,
#else
- (inquiry)array_length, /*sq_length*/
+ (inquiry)array_length, /*sq_length*/
(binaryfunc)NULL, /* sq_concat is handled by nb_add*/
(intargfunc)NULL, /* sq_repeat is handled nb_multiply*/
- (intargfunc)array_item_nice, /*sq_item*/
- (intintargfunc)array_slice, /*sq_slice*/
- (intobjargproc)array_ass_item, /*sq_ass_item*/
- (intintobjargproc)array_ass_slice, /*sq_ass_slice*/
- (objobjproc) array_contains, /* sq_contains */
- (binaryfunc) NULL, /* sg_inplace_concat */
- (intargfunc) NULL /* sg_inplace_repeat */
+ (intargfunc)array_item_nice, /*sq_item*/
+ (intintargfunc)array_slice, /*sq_slice*/
+ (intobjargproc)array_ass_item, /*sq_ass_item*/
+ (intintobjargproc)array_ass_slice, /*sq_ass_slice*/
+ (objobjproc) array_contains, /* sq_contains */
+ (binaryfunc) NULL, /* sg_inplace_concat */
+ (intargfunc) NULL /* sg_inplace_repeat */
#endif
};
@@ -3956,7 +3956,7 @@
int i, N;
#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \
- *string = (char *)_pya_realloc(*string, *max_n); }
+ *string = (char *)_pya_realloc(*string, *max_n); }
if (nd == 0) {
@@ -4014,21 +4014,21 @@
sprintf(string, "array(");
if (dump_data(&string, &n, &max_n, self->data,
- self->nd, self->dimensions,
+ self->nd, self->dimensions,
self->strides, self) < 0) {
- _pya_free(string); return NULL;
- }
+ _pya_free(string); return NULL;
+ }
- if (PyArray_ISEXTENDED(self)) {
- char buf[100];
- snprintf(buf, sizeof(buf), "%d", self->descr->elsize);
- sprintf(string+n, ", '%c%s')", self->descr->type, buf);
- ret = PyString_FromStringAndSize(string, n+6+strlen(buf));
- }
- else {
- sprintf(string+n, ", '%c')", self->descr->type);
- ret = PyString_FromStringAndSize(string, n+6);
- }
+ if (PyArray_ISEXTENDED(self)) {
+ char buf[100];
+ snprintf(buf, sizeof(buf), "%d", self->descr->elsize);
+ sprintf(string+n, ", '%c%s')", self->descr->type, buf);
+ ret = PyString_FromStringAndSize(string, n+6+strlen(buf));
+ }
+ else {
+ sprintf(string+n, ", '%c')", self->descr->type);
+ ret = PyString_FromStringAndSize(string, n+6);
+ }
_pya_free(string);
@@ -4045,18 +4045,18 @@
PyArray_SetStringFunction(PyObject *op, int repr)
{
if (repr) {
- /* Dispose of previous callback */
+ /* Dispose of previous callback */
Py_XDECREF(PyArray_ReprFunction);
- /* Add a reference to new callback */
+ /* Add a reference to new callback */
Py_XINCREF(op);
- /* Remember new callback */
+ /* Remember new callback */
PyArray_ReprFunction = op;
} else {
- /* Dispose of previous callback */
+ /* Dispose of previous callback */
Py_XDECREF(PyArray_StrFunction);
- /* Add a reference to new callback */
+ /* Add a reference to new callback */
Py_XINCREF(op);
- /* Remember new callback */
+ /* Remember new callback */
PyArray_StrFunction = op;
}
}
@@ -4104,9 +4104,9 @@
c2 = *s2++;
if (c1 != c2) {
return (c1 < c2) ? -1 : 1;
- }
+ }
}
- return 0;
+ return 0;
}
/* This also handles possibly mis-aligned data */
@@ -4118,32 +4118,32 @@
static int
_myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)
{
- PyArray_UCS4 *sptr;
- PyArray_UCS4 *s1t=s1, *s2t=s2;
- int val;
- intp size;
+ PyArray_UCS4 *sptr;
+ PyArray_UCS4 *s1t=s1, *s2t=s2;
+ int val;
+ intp size;
- if ((intp)s1 % sizeof(PyArray_UCS4) != 0) {
- size = len1*sizeof(PyArray_UCS4);
- s1t = malloc(size);
- memcpy(s1t, s1, size);
- }
- if ((intp)s2 % sizeof(PyArray_UCS4) != 0) {
- size = len2*sizeof(PyArray_UCS4);
- s2t = malloc(size);
- memcpy(s2t, s2, size);
- }
- val = PyArray_CompareUCS4(s1t, s2t, MIN(len1,len2));
- if ((val != 0) || (len1 == len2)) goto finish;
- if (len2 > len1) {sptr = s2t+len1; val = -1;}
- else {sptr = s1t+len2; val = 1;}
- if (*sptr != 0) goto finish;
- val = 0;
-
+ if ((intp)s1 % sizeof(PyArray_UCS4) != 0) {
+ size = len1*sizeof(PyArray_UCS4);
+ s1t = malloc(size);
+ memcpy(s1t, s1, size);
+ }
+ if ((intp)s2 % sizeof(PyArray_UCS4) != 0) {
+ size = len2*sizeof(PyArray_UCS4);
+ s2t = malloc(size);
+ memcpy(s2t, s2, size);
+ }
+ val = PyArray_CompareUCS4(s1t, s2t, MIN(len1,len2));
+ if ((val != 0) || (len1 == len2)) goto finish;
+ if (len2 > len1) {sptr = s2t+len1; val = -1;}
+ else {sptr = s1t+len2; val = 1;}
+ if (*sptr != 0) goto finish;
+ val = 0;
+
finish:
- if (s1t != s1) free(s1t);
- if (s2t != s2) free(s2t);
- return val;
+ if (s1t != s1) free(s1t);
+ if (s2t != s2) free(s2t);
+ return val;
}
@@ -4157,79 +4157,79 @@
static int
_mystrncmp(char *s1, char *s2, int len1, int len2)
{
- char *sptr;
- int val;
+ char *sptr;
+ int val;
- val = strncmp(s1, s2, MIN(len1, len2));
- if ((val != 0) || (len1 == len2)) return val;
- if (len2 > len1) {sptr = s2+len1; val = -1;}
- else {sptr = s1+len2; val = 1;}
- if (*sptr != 0) return val;
- return 0;
+ val = strncmp(s1, s2, MIN(len1, len2));
+ if ((val != 0) || (len1 == len2)) return val;
+ if (len2 > len1) {sptr = s2+len1; val = -1;}
+ else {sptr = s1+len2; val = 1;}
+ if (*sptr != 0) return val;
+ return 0;
}
static int
_compare_strings(PyObject *result, PyArrayMultiIterObject *multi,
- int cmp_op, void *func)
+ int cmp_op, void *func)
{
- PyArrayIterObject *iself, *iother;
- Bool *dptr;
- intp size;
- int val;
- int N1, N2;
- int (*cmpfunc)(void *, void *, int, int);
-
- cmpfunc = func;
- dptr = (Bool *)PyArray_DATA(result);
- iself = multi->iters[0];
- iother = multi->iters[1];
- size = multi->size;
- N1 = iself->ao->descr->elsize;
- N2 = iother->ao->descr->elsize;
- if ((void *)cmpfunc == (void *)_myunincmp) {
- N1 >>= 2;
- N2 >>= 2;
- }
- while(size--) {
- val = cmpfunc((void *)iself->dataptr, (void *)iother->dataptr,
- N1, N2);
- switch (cmp_op) {
- case Py_EQ:
- *dptr = (val == 0);
- break;
- case Py_NE:
- *dptr = (val != 0);
- break;
- case Py_LT:
- *dptr = (val < 0);
- break;
- case Py_LE:
- *dptr = (val <= 0);
- break;
- case Py_GT:
- *dptr = (val > 0);
- break;
- case Py_GE:
- *dptr = (val >= 0);
- break;
- default:
- PyErr_SetString(PyExc_RuntimeError,
- "bad comparison operator");
- return -1;
- }
- PyArray_ITER_NEXT(iself);
- PyArray_ITER_NEXT(iother);
- dptr += 1;
- }
- return 0;
+ PyArrayIterObject *iself, *iother;
+ Bool *dptr;
+ intp size;
+ int val;
+ int N1, N2;
+ int (*cmpfunc)(void *, void *, int, int);
+
+ cmpfunc = func;
+ dptr = (Bool *)PyArray_DATA(result);
+ iself = multi->iters[0];
+ iother = multi->iters[1];
+ size = multi->size;
+ N1 = iself->ao->descr->elsize;
+ N2 = iother->ao->descr->elsize;
+ if ((void *)cmpfunc == (void *)_myunincmp) {
+ N1 >>= 2;
+ N2 >>= 2;
+ }
+ while(size--) {
+ val = cmpfunc((void *)iself->dataptr, (void *)iother->dataptr,
+ N1, N2);
+ switch (cmp_op) {
+ case Py_EQ:
+ *dptr = (val == 0);
+ break;
+ case Py_NE:
+ *dptr = (val != 0);
+ break;
+ case Py_LT:
+ *dptr = (val < 0);
+ break;
+ case Py_LE:
+ *dptr = (val <= 0);
+ break;
+ case Py_GT:
+ *dptr = (val > 0);
+ break;
+ case Py_GE:
+ *dptr = (val >= 0);
+ break;
+ default:
+ PyErr_SetString(PyExc_RuntimeError,
+ "bad comparison operator");
+ return -1;
+ }
+ PyArray_ITER_NEXT(iself);
+ PyArray_ITER_NEXT(iother);
+ dptr += 1;
+ }
+ return 0;
}
static PyObject *
_strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
{
PyObject *result;
- PyArrayMultiIterObject *mit;
- int val;
+ PyArrayMultiIterObject *mit;
+ int val;
/* Cast arrays to a common type */
if (self->descr->type != other->descr->type) {
@@ -4239,16 +4239,16 @@
Py_INCREF(other);
Py_INCREF(other->descr);
new = PyArray_FromAny((PyObject *)self, other->descr,
- 0, 0, 0, NULL);
+ 0, 0, 0, NULL);
if (new == NULL) return NULL;
self = (PyArrayObject *)new;
}
- else if (self->descr->type_num == PyArray_UNICODE && \
+ else if (self->descr->type_num == PyArray_UNICODE && \
other->descr->type_num == PyArray_STRING) {
Py_INCREF(self);
Py_INCREF(self->descr);
new = PyArray_FromAny((PyObject *)other, self->descr,
- 0, 0, 0, NULL);
+ 0, 0, 0, NULL);
if (new == NULL) return NULL;
other = (PyArrayObject *)new;
}
@@ -4266,29 +4266,29 @@
/* Broad-cast the arrays to a common shape */
mit = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, self, other);
- Py_DECREF(self);
- Py_DECREF(other);
+ Py_DECREF(self);
+ Py_DECREF(other);
if (mit == NULL) return NULL;
-
- result = PyArray_NewFromDescr(&PyArray_Type,
- PyArray_DescrFromType(PyArray_BOOL),
- mit->nd,
- mit->dimensions,
- NULL, NULL, 0,
- NULL);
- if (result == NULL) goto finish;
+
+ result = PyArray_NewFromDescr(&PyArray_Type,
+ PyArray_DescrFromType(PyArray_BOOL),
+ mit->nd,
+ mit->dimensions,
+ NULL, NULL, 0,
+ NULL);
+ if (result == NULL) goto finish;
- if (self->descr->type_num == PyArray_UNICODE) {
- val = _compare_strings(result, mit, cmp_op, _myunincmp);
- }
- else {
- val = _compare_strings(result, mit, cmp_op, _mystrncmp);
- }
-
- if (val < 0) {Py_DECREF(result); result = NULL;}
-
+ if (self->descr->type_num == PyArray_UNICODE) {
+ val = _compare_strings(result, mit, cmp_op, _myunincmp);
+ }
+ else {
+ val = _compare_strings(result, mit, cmp_op, _mystrncmp);
+ }
+
+ if (val < 0) {Py_DECREF(result); result = NULL;}
+
finish:
- Py_DECREF(mit);
+ Py_DECREF(mit);
return result;
}
@@ -4308,53 +4308,53 @@
static PyObject *
_void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
{
- if (!(cmp_op == Py_EQ || cmp_op == Py_NE)) {
- PyErr_SetString(PyExc_ValueError, "Void-arrays can only" \
- "be compared for equality.");
- return NULL;
- }
- if (PyArray_HASFIELDS(self)) {
- PyObject *res=NULL, *temp, *a, *b;
+ if (!(cmp_op == Py_EQ || cmp_op == Py_NE)) {
+ PyErr_SetString(PyExc_ValueError, "Void-arrays can only" \
+ "be compared for equality.");
+ return NULL;
+ }
+ if (PyArray_HASFIELDS(self)) {
+ PyObject *res=NULL, *temp, *a, *b;
PyObject *key, *value, *temp2;
- PyObject *op;
+ PyObject *op;
int pos=0;
- op = (cmp_op == Py_EQ ? n_ops.logical_and : n_ops.logical_or);
+ op = (cmp_op == Py_EQ ? n_ops.logical_and : n_ops.logical_or);
while (PyDict_Next(self->descr->fields, &pos, &key, &value)) {
- a = PyArray_EnsureAnyArray(array_subscript(self, key));
- if (a==NULL) {Py_XDECREF(res); return NULL;}
- b = array_subscript(other, key);
- if (b==NULL) {Py_XDECREF(res); Py_DECREF(a); return NULL;}
- temp = array_richcompare((PyArrayObject *)a,b,cmp_op);
- Py_DECREF(a);
- Py_DECREF(b);
- if (temp == NULL) {Py_XDECREF(res); return NULL;}
- if (res == NULL) {
- res = temp;
- }
- else {
- temp2 = PyObject_CallFunction(op, "OO", res, temp);
- Py_DECREF(temp);
- Py_DECREF(res);
- if (temp2 == NULL) return NULL;
- res = temp2;
- }
+ a = PyArray_EnsureAnyArray(array_subscript(self, key));
+ if (a==NULL) {Py_XDECREF(res); return NULL;}
+ b = array_subscript(other, key);
+ if (b==NULL) {Py_XDECREF(res); Py_DECREF(a); return NULL;}
+ temp = array_richcompare((PyArrayObject *)a,b,cmp_op);
+ Py_DECREF(a);
+ Py_DECREF(b);
+ if (temp == NULL) {Py_XDECREF(res); return NULL;}
+ if (res == NULL) {
+ res = temp;
+ }
+ else {
+ temp2 = PyObject_CallFunction(op, "OO", res, temp);
+ Py_DECREF(temp);
+ Py_DECREF(res);
+ if (temp2 == NULL) return NULL;
+ res = temp2;
+ }
}
- if (res == NULL && !PyErr_Occurred()) {
- PyErr_SetString(PyExc_ValueError, "No fields found.");
- }
+ if (res == NULL && !PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ValueError, "No fields found.");
+ }
return res;
- }
- else { /* compare as a string */
- /* assumes self and other have same descr->type */
- return _strings_richcompare(self, other, cmp_op);
- }
+ }
+ else { /* compare as a string */
+ /* assumes self and other have same descr->type */
+ return _strings_richcompare(self, other, cmp_op);
+ }
}
static PyObject *
array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
{
PyObject *array_other, *result = NULL;
- int typenum;
+ int typenum;
switch (cmp_op)
{
@@ -4367,65 +4367,65 @@
n_ops.less_equal);
break;
case Py_EQ:
- if (other == Py_None) {
- Py_INCREF(Py_False);
- return Py_False;
- }
+ if (other == Py_None) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
/* Try to convert other to an array */
- if (!PyArray_Check(other)) {
- typenum = self->descr->type_num;
- if (typenum != PyArray_OBJECT) {
- typenum = PyArray_NOTYPE;
- }
- array_other = PyArray_FromObject(other,
+ if (!PyArray_Check(other)) {
+ typenum = self->descr->type_num;
+ if (typenum != PyArray_OBJECT) {
+ typenum = PyArray_NOTYPE;
+ }
+ array_other = PyArray_FromObject(other,
typenum, 0, 0);
- /* If not successful, then return False
- This fixes code that used to
- allow equality comparisons between arrays
- and other objects which would give a result
- of False
- */
- if ((array_other == NULL) || \
- (array_other == Py_None)) {
- Py_XDECREF(array_other);
- PyErr_Clear();
- Py_INCREF(Py_False);
- return Py_False;
- }
- }
- else {
- Py_INCREF(other);
- array_other = other;
- }
+ /* If not successful, then return False
+ This fixes code that used to
+ allow equality comparisons between arrays
+ and other objects which would give a result
+ of False
+ */
+ if ((array_other == NULL) || \
+ (array_other == Py_None)) {
+ Py_XDECREF(array_other);
+ PyErr_Clear();
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ }
+ else {
+ Py_INCREF(other);
+ array_other = other;
+ }
result = PyArray_GenericBinaryFunction(self,
- array_other,
- n_ops.equal);
- if ((result == Py_NotImplemented) &&
- (self->descr->type_num == PyArray_VOID)) {
- int _res;
- _res = PyObject_RichCompareBool \
- ((PyObject *)self->descr,
- (PyObject *)\
- PyArray_DESCR(array_other),
- Py_EQ);
- if (_res < 0) {
- Py_DECREF(result);
- Py_DECREF(array_other);
- return NULL;
- }
- if (_res) {
- Py_DECREF(result);
- result = _void_compare\
- (self,
- (PyArrayObject *)array_other,
- cmp_op);
- Py_DECREF(array_other);
- }
- return result;
- }
+ array_other,
+ n_ops.equal);
+ if ((result == Py_NotImplemented) &&
+ (self->descr->type_num == PyArray_VOID)) {
+ int _res;
+ _res = PyObject_RichCompareBool \
+ ((PyObject *)self->descr,
+ (PyObject *)\
+ PyArray_DESCR(array_other),
+ Py_EQ);
+ if (_res < 0) {
+ Py_DECREF(result);
+ Py_DECREF(array_other);
+ return NULL;
+ }
+ if (_res) {
+ Py_DECREF(result);
+ result = _void_compare\
+ (self,
+ (PyArrayObject *)array_other,
+ cmp_op);
+ Py_DECREF(array_other);
+ }
+ return result;
+ }
/* If the comparison results in NULL, then the
- two array objects can not be compared together so
- return zero
+ two array objects can not be compared together so
+ return zero
*/
Py_DECREF(array_other);
if (result == NULL) {
@@ -4435,62 +4435,62 @@
}
break;
case Py_NE:
- if (other == Py_None) {
- Py_INCREF(Py_True);
- return Py_True;
- }
+ if (other == Py_None) {
+ Py_INCREF(Py_True);
+ return Py_True;
+ }
/* Try to convert other to an array */
- if (!PyArray_Check(other)) {
- typenum = self->descr->type_num;
- if (typenum != PyArray_OBJECT) {
- typenum = PyArray_NOTYPE;
- }
- array_other = PyArray_FromObject(other,
+ if (!PyArray_Check(other)) {
+ typenum = self->descr->type_num;
+ if (typenum != PyArray_OBJECT) {
+ typenum = PyArray_NOTYPE;
+ }
+ array_other = PyArray_FromObject(other,
typenum, 0, 0);
- /* If not successful, then objects cannot be
- compared and cannot be equal, therefore,
- return True;
- */
- if ((array_other == NULL) || \
- (array_other == Py_None)) {
- Py_XDECREF(array_other);
- PyErr_Clear();
- Py_INCREF(Py_True);
- return Py_True;
- }
- }
- else {
- Py_INCREF(other);
- array_other = other;
- }
- result = PyArray_GenericBinaryFunction(self,
- array_other,
- n_ops.not_equal);
- if ((result == Py_NotImplemented) &&
- (self->descr->type_num == PyArray_VOID)) {
- int _res;
- _res = PyObject_RichCompareBool\
- ((PyObject *)self->descr,
- (PyObject *)\
- PyArray_DESCR(array_other),
- Py_EQ);
- if (_res < 0) {
- Py_DECREF(result);
- Py_DECREF(array_other);
- return NULL;
- }
- if (_res) {
- Py_DECREF(result);
- result = _void_compare\
- (self,
- (PyArrayObject *)array_other,
- cmp_op);
- Py_DECREF(array_other);
- }
- return result;
- }
+ /* If not successful, then objects cannot be
+ compared and cannot be equal, therefore,
+ return True;
+ */
+ if ((array_other == NULL) || \
+ (array_other == Py_None)) {
+ Py_XDECREF(array_other);
+ PyErr_Clear();
+ Py_INCREF(Py_True);
+ return Py_True;
+ }
+ }
+ else {
+ Py_INCREF(other);
+ array_other = other;
+ }
+ result = PyArray_GenericBinaryFunction(self,
+ array_other,
+ n_ops.not_equal);
+ if ((result == Py_NotImplemented) &&
+ (self->descr->type_num == PyArray_VOID)) {
+ int _res;
+ _res = PyObject_RichCompareBool\
+ ((PyObject *)self->descr,
+ (PyObject *)\
+ PyArray_DESCR(array_other),
+ Py_EQ);
+ if (_res < 0) {
+ Py_DECREF(result);
+ Py_DECREF(array_other);
+ return NULL;
+ }
+ if (_res) {
+ Py_DECREF(result);
+ result = _void_compare\
+ (self,
+ (PyArrayObject *)array_other,
+ cmp_op);
+ Py_DECREF(array_other);
+ }
+ return result;
+ }
- Py_DECREF(array_other);
+ Py_DECREF(array_other);
if (result == NULL) {
PyErr_Clear();
Py_INCREF(Py_True);
@@ -4514,9 +4514,9 @@
if (self->descr->type_num == PyArray_OBJECT) return result;
array_other = PyArray_FromObject(other,PyArray_NOTYPE, 0, 0);
if (PyArray_ISSTRING(self) && PyArray_ISSTRING(array_other)) {
- Py_DECREF(result);
+ Py_DECREF(result);
result = _strings_richcompare(self, (PyArrayObject *)
- array_other, cmp_op);
+ array_other, cmp_op);
}
Py_DECREF(array_other);
}
@@ -4526,34 +4526,34 @@
static PyObject *
_check_axis(PyArrayObject *arr, int *axis, int flags)
{
- PyObject *temp;
- int n = arr->nd;
+ PyObject *temp;
+ int n = arr->nd;
- if ((*axis >= MAX_DIMS) || (n==0)) {
- temp = PyArray_Ravel(arr,0);
- if (temp) *axis = PyArray_NDIM(temp)-1;
- else *axis = 0;
- return temp;
- }
- else {
- if (flags) {
- temp = PyArray_CheckFromAny((PyObject *)arr, NULL,
+ if ((*axis >= MAX_DIMS) || (n==0)) {
+ temp = PyArray_Ravel(arr,0);
+ if (temp) *axis = PyArray_NDIM(temp)-1;
+ else *axis = 0;
+ return temp;
+ }
+ else {
+ if (flags) {
+ temp = PyArray_CheckFromAny((PyObject *)arr, NULL,
0, 0, flags, NULL);
- if (temp == NULL) return NULL;
- }
- else {
- Py_INCREF(arr);
- temp = (PyObject *)arr;
- }
- }
- if (*axis < 0) *axis += n;
- if ((*axis < 0) || (*axis >= n)) {
- PyErr_Format(PyExc_ValueError,
- "axis(=%d) out of bounds", *axis);
- Py_DECREF(temp);
- return NULL;
- }
- return temp;
+ if (temp == NULL) return NULL;
+ }
+ else {
+ Py_INCREF(arr);
+ temp = (PyObject *)arr;
+ }
+ }
+ if (*axis < 0) *axis += n;
+ if ((*axis < 0) || (*axis >= n)) {
+ PyErr_Format(PyExc_ValueError,
+ "axis(=%d) out of bounds", *axis);
+ Py_DECREF(temp);
+ return NULL;
+ }
+ return temp;
}
#include "arraymethods.c"
@@ -4565,14 +4565,14 @@
static PyObject *
PyArray_IntTupleFromIntp(int len, intp *vals)
{
- int i;
+ int i;
PyObject *intTuple = PyTuple_New(len);
if (!intTuple) goto fail;
for(i=0; i<len; i++) {
#if SIZEOF_INTP <= SIZEOF_LONG
PyObject *o = PyInt_FromLong((long) vals[i]);
#else
- PyObject *o = PyLong_FromLongLong((longlong) vals[i]);
+ PyObject *o = PyLong_FromLongLong((longlong) vals[i]);
#endif
if (!o) {
Py_DECREF(intTuple);
@@ -4594,38 +4594,38 @@
PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
{
int nd, i;
- PyObject *op;
+ PyObject *op;
/* Check to see if sequence is a single integer first.
or, can be made into one */
- if ((nd=PySequence_Length(seq)) == -1) {
- if (PyErr_Occurred()) PyErr_Clear();
+ if ((nd=PySequence_Length(seq)) == -1) {
+ if (PyErr_Occurred()) PyErr_Clear();
#if SIZEOF_LONG >= SIZEOF_INTP
- if (!(op = PyNumber_Int(seq))) return -1;
+ if (!(op = PyNumber_Int(seq))) return -1;
#else
- if (!(op = PyNumber_Long(seq))) return -1;
+ if (!(op = PyNumber_Long(seq))) return -1;
#endif
- nd = 1;
+ nd = 1;
#if SIZEOF_LONG >= SIZEOF_INTP
- vals[0] = (intp ) PyInt_AsLong(op);
+ vals[0] = (intp ) PyInt_AsLong(op);
#else
- vals[0] = (intp ) PyLong_AsLongLong(op);
+ vals[0] = (intp ) PyLong_AsLongLong(op);
#endif
- Py_DECREF(op);
- } else {
- for(i=0; i < MIN(nd,maxvals); i++) {
- op = PySequence_GetItem(seq, i);
- if (op == NULL) return -1;
+ Py_DECREF(op);
+ } else {
+ for(i=0; i < MIN(nd,maxvals); i++) {
+ op = PySequence_GetItem(seq, i);
+ if (op == NULL) return -1;
#if SIZEOF_LONG >= SIZEOF_INTP
- vals[i]=(intp )PyInt_AsLong(op);
+ vals[i]=(intp )PyInt_AsLong(op);
#else
- vals[i]=(intp )PyLong_AsLongLong(op);
+ vals[i]=(intp )PyLong_AsLongLong(op);
#endif
- Py_DECREF(op);
- if(PyErr_Occurred()) return -1;
- }
- }
- return nd;
+ Py_DECREF(op);
+ if(PyErr_Occurred()) return -1;
+ }
+ }
+ return nd;
}
@@ -4636,22 +4636,22 @@
static int
_IsContiguous(PyArrayObject *ap)
{
- register intp sd;
- register intp dim;
- register int i;
+ register intp sd;
+ register intp dim;
+ register int i;
- if (ap->nd == 0) return 1;
- sd = ap->descr->elsize;
- if (ap->nd == 1) return (ap->dimensions[0] == 1 || \
- sd == ap->strides[0]);
- for (i = ap->nd-1; i >= 0; --i) {
- dim = ap->dimensions[i];
- /* contiguous by definition */
- if (dim == 0) return 1;
- if (ap->strides[i] != sd) return 0;
- sd *= dim;
- }
- return 1;
+ if (ap->nd == 0) return 1;
+ sd = ap->descr->elsize;
+ if (ap->nd == 1) return (ap->dimensions[0] == 1 || \
+ sd == ap->strides[0]);
+ for (i = ap->nd-1; i >= 0; --i) {
+ dim = ap->dimensions[i];
+ /* contiguous by definition */
+ if (dim == 0) return 1;
+ if (ap->strides[i] != sd) return 0;
+ sd *= dim;
+ }
+ return 1;
}
@@ -4659,38 +4659,38 @@
static int
_IsFortranContiguous(PyArrayObject *ap)
{
- register intp sd;
- register intp dim;
- register int i;
+ register intp sd;
+ register intp dim;
+ register int i;
- if (ap->nd == 0) return 1;
- sd = ap->descr->elsize;
- if (ap->nd == 1) return (ap->dimensions[0] == 1 || \
- sd == ap->strides[0]);
- for (i=0; i< ap->nd; ++i) {
- dim = ap->dimensions[i];
- /* fortran contiguous by definition */
- if (dim == 0) return 1;
- if (ap->strides[i] != sd) return 0;
- sd *= dim;
- }
- return 1;
+ if (ap->nd == 0) return 1;
+ sd = ap->descr->elsize;
+ if (ap->nd == 1) return (ap->dimensions[0] == 1 || \
+ sd == ap->strides[0]);
+ for (i=0; i< ap->nd; ++i) {
+ dim = ap->dimensions[i];
+ /* fortran contiguous by definition */
+ if (dim == 0) return 1;
+ if (ap->strides[i] != sd) return 0;
+ sd *= dim;
+ }
+ return 1;
}
static int
_IsAligned(PyArrayObject *ap)
{
- int i, alignment, aligned=1;
- intp ptr;
- int type = ap->descr->type_num;
+ int i, alignment, aligned=1;
+ intp ptr;
+ int type = ap->descr->type_num;
- if ((type == PyArray_STRING) || (type == PyArray_VOID))
- return 1;
+ if ((type == PyArray_STRING) || (type == PyArray_VOID))
+ return 1;
- alignment = ap->descr->alignment;
- if (alignment == 1) return 1;
+ alignment = ap->descr->alignment;
+ if (alignment == 1) return 1;
- ptr = (intp) ap->data;
+ ptr = (intp) ap->data;
aligned = (ptr % alignment) == 0;
for (i=0; i <ap->nd; i++)
aligned &= ((ap->strides[i] % alignment) == 0);
@@ -4700,37 +4700,37 @@
static Bool
_IsWriteable(PyArrayObject *ap)
{
- PyObject *base=ap->base;
- void *dummy;
- Py_ssize_t n;
+ PyObject *base=ap->base;
+ void *dummy;
+ Py_ssize_t n;
- /* If we own our own data, then no-problem */
- if ((base == NULL) || (ap->flags & OWNDATA)) return TRUE;
+ /* If we own our own data, then no-problem */
+ if ((base == NULL) || (ap->flags & OWNDATA)) return TRUE;
- /* Get to the final base object
- If it is a writeable array, then return TRUE
- If we can find an array object
- or a writeable buffer object as the final base object
- or a string object (for pickling support memory savings).
- - this last could be removed if a proper pickleable
- buffer was added to Python.
- */
+ /* Get to the final base object
+ If it is a writeable array, then return TRUE
+ If we can find an array object
+ or a writeable buffer object as the final base object
+ or a string object (for pickling support memory savings).
+ - this last could be removed if a proper pickleable
+ buffer was added to Python.
+ */
- while(PyArray_Check(base)) {
- if (PyArray_CHKFLAGS(base, OWNDATA))
- return (Bool) (PyArray_ISWRITEABLE(base));
- base = PyArray_BASE(base);
- }
+ while(PyArray_Check(base)) {
+ if (PyArray_CHKFLAGS(base, OWNDATA))
+ return (Bool) (PyArray_ISWRITEABLE(base));
+ base = PyArray_BASE(base);
+ }
- /* here so pickle support works seamlessly
- and unpickled array can be set and reset writeable
- -- could be abused -- */
- if PyString_Check(base) return TRUE;
+ /* here so pickle support works seamlessly
+ and unpickled array can be set and reset writeable
+ -- could be abused -- */
+ if PyString_Check(base) return TRUE;
- if (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)
- return FALSE;
+ if (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)
+ return FALSE;
- return TRUE;
+ return TRUE;
}
@@ -4739,15 +4739,15 @@
static int
PyArray_ElementStrides(PyObject *arr)
{
- register int itemsize = PyArray_ITEMSIZE(arr);
- register int i, N=PyArray_NDIM(arr);
- register intp *strides = PyArray_STRIDES(arr);
+ register int itemsize = PyArray_ITEMSIZE(arr);
+ register int i, N=PyArray_NDIM(arr);
+ register intp *strides = PyArray_STRIDES(arr);
- for (i=0; i<N; i++) {
- if ((strides[i] % itemsize) != 0) return 0;
- }
+ for (i=0; i<N; i++) {
+ if ((strides[i] % itemsize) != 0) return 0;
+ }
- return 1;
+ return 1;
}
/*OBJECT_API
@@ -4757,31 +4757,31 @@
PyArray_UpdateFlags(PyArrayObject *ret, int flagmask)
{
- if (flagmask & FORTRAN) {
- if (_IsFortranContiguous(ret)) {
- ret->flags |= FORTRAN;
- if (ret->nd > 1) ret->flags &= ~CONTIGUOUS;
- }
- else ret->flags &= ~FORTRAN;
- }
- if (flagmask & CONTIGUOUS) {
- if (_IsContiguous(ret)) {
- ret->flags |= CONTIGUOUS;
- if (ret->nd > 1) ret->flags &= ~FORTRAN;
- }
- else ret->flags &= ~CONTIGUOUS;
- }
- if (flagmask & ALIGNED) {
- if (_IsAligned(ret)) ret->flags |= ALIGNED;
- else ret->flags &= ~ALIGNED;
- }
- /* This is not checked by default WRITEABLE is not
- part of UPDATE_ALL */
- if (flagmask & WRITEABLE) {
- if (_IsWriteable(ret)) ret->flags |= WRITEABLE;
- else ret->flags &= ~WRITEABLE;
+ if (flagmask & FORTRAN) {
+ if (_IsFortranContiguous(ret)) {
+ ret->flags |= FORTRAN;
+ if (ret->nd > 1) ret->flags &= ~CONTIGUOUS;
+ }
+ else ret->flags &= ~FORTRAN;
}
- return;
+ if (flagmask & CONTIGUOUS) {
+ if (_IsContiguous(ret)) {
+ ret->flags |= CONTIGUOUS;
+ if (ret->nd > 1) ret->flags &= ~FORTRAN;
+ }
+ else ret->flags &= ~CONTIGUOUS;
+ }
+ if (flagmask & ALIGNED) {
+ if (_IsAligned(ret)) ret->flags |= ALIGNED;
+ else ret->flags &= ~ALIGNED;
+ }
+ /* This is not checked by default WRITEABLE is not
+ part of UPDATE_ALL */
+ if (flagmask & WRITEABLE) {
+ if (_IsWriteable(ret)) ret->flags |= WRITEABLE;
+ else ret->flags &= ~WRITEABLE;
+ }
+ return;
}
/* This routine checks to see if newstrides (of length nd) will not
@@ -4803,24 +4803,24 @@
/*OBJECT_API*/
static Bool
PyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,
- intp *dims, intp *newstrides)
+ intp *dims, intp *newstrides)
{
- int i;
- intp byte_begin;
- intp begin;
- intp end;
+ int i;
+ intp byte_begin;
+ intp begin;
+ intp end;
- if (numbytes == 0)
- numbytes = PyArray_MultiplyList(dims, nd) * elsize;
+ if (numbytes == 0)
+ numbytes = PyArray_MultiplyList(dims, nd) * elsize;
- begin = -offset;
- end = numbytes - offset - elsize;
- for (i=0; i<nd; i++) {
- byte_begin = newstrides[i]*(dims[i]-1);
- if ((byte_begin < begin) || (byte_begin > end))
- return FALSE;
- }
- return TRUE;
+ begin = -offset;
+ end = numbytes - offset - elsize;
+ for (i=0; i<nd; i++) {
+ byte_begin = newstrides[i]*(dims[i]-1);
+ if ((byte_begin < begin) || (byte_begin > end))
+ return FALSE;
+ }
+ return TRUE;
}
@@ -4843,29 +4843,29 @@
static size_t
_array_fill_strides(intp *strides, intp *dims, int nd, size_t itemsize,
- int inflag, int *objflags)
+ int inflag, int *objflags)
{
- int i;
- /* Only make Fortran strides if not contiguous as well */
- if ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {
- for (i=0; i<nd; i++) {
- strides[i] = itemsize;
- itemsize *= dims[i] ? dims[i] : 1;
- }
- *objflags |= FORTRAN;
- if (nd > 1) *objflags &= ~CONTIGUOUS;
- else *objflags |= CONTIGUOUS;
- }
- else {
- for (i=nd-1;i>=0;i--) {
- strides[i] = itemsize;
- itemsize *= dims[i] ? dims[i] : 1;
- }
- *objflags |= CONTIGUOUS;
- if (nd > 1) *objflags &= ~FORTRAN;
- else *objflags |= FORTRAN;
- }
- return itemsize;
+ int i;
+ /* Only make Fortran strides if not contiguous as well */
+ if ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {
+ for (i=0; i<nd; i++) {
+ strides[i] = itemsize;
+ itemsize *= dims[i] ? dims[i] : 1;
+ }
+ *objflags |= FORTRAN;
+ if (nd > 1) *objflags &= ~CONTIGUOUS;
+ else *objflags |= CONTIGUOUS;
+ }
+ else {
+ for (i=nd-1;i>=0;i--) {
+ strides[i] = itemsize;
+ itemsize *= dims[i] ? dims[i] : 1;
+ }
+ *objflags |= CONTIGUOUS;
+ if (nd > 1) *objflags &= ~FORTRAN;
+ else *objflags |= FORTRAN;
+ }
+ return itemsize;
}
/*OBJECT_API
@@ -4874,26 +4874,26 @@
static PyObject *
PyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,
intp *strides, void *data, int itemsize, int flags,
- PyObject *obj)
+ PyObject *obj)
{
- PyArray_Descr *descr;
- PyObject *new;
+ PyArray_Descr *descr;
+ PyObject *new;
- descr = PyArray_DescrFromType(type_num);
- if (descr == NULL) return NULL;
- if (descr->elsize == 0) {
- if (itemsize < 1) {
- PyErr_SetString(PyExc_ValueError,
- "data type must provide an itemsize");
- Py_DECREF(descr);
- return NULL;
- }
- PyArray_DESCR_REPLACE(descr);
- descr->elsize = itemsize;
- }
- new = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,
- data, flags, obj);
- return new;
+ descr = PyArray_DescrFromType(type_num);
+ if (descr == NULL) return NULL;
+ if (descr->elsize == 0) {
+ if (itemsize < 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "data type must provide an itemsize");
+ Py_DECREF(descr);
+ return NULL;
+ }
+ PyArray_DESCR_REPLACE(descr);
+ descr->elsize = itemsize;
+ }
+ new = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,
+ data, flags, obj);
+ return new;
}
/* Change a sub-array field to the base descriptor */
@@ -4906,67 +4906,67 @@
*/
static int
_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,
- intp *newstrides, int oldnd, int isfortran)
+ intp *newstrides, int oldnd, int isfortran)
{
- PyArray_Descr *old;
- int newnd;
- int numnew;
- intp *mydim;
- int i;
- int tuple;
+ PyArray_Descr *old;
+ int newnd;
+ int numnew;
+ intp *mydim;
+ int i;
+ int tuple;
- old = *des;
- *des = old->subarray->base;
+ old = *des;
+ *des = old->subarray->base;
- mydim = newdims + oldnd;
- tuple = PyTuple_Check(old->subarray->shape);
- if (tuple) {
- numnew = PyTuple_GET_SIZE(old->subarray->shape);
- }
- else {
- numnew = 1;
- }
+ mydim = newdims + oldnd;
+ tuple = PyTuple_Check(old->subarray->shape);
+ if (tuple) {
+ numnew = PyTuple_GET_SIZE(old->subarray->shape);
+ }
+ else {
+ numnew = 1;
+ }
- newnd = oldnd + numnew;
- if (newnd > MAX_DIMS) goto finish;
- if (isfortran) {
- memmove(newdims+numnew, newdims, oldnd*sizeof(intp));
- mydim = newdims;
- }
+ newnd = oldnd + numnew;
+ if (newnd > MAX_DIMS) goto finish;
+ if (isfortran) {
+ memmove(newdims+numnew, newdims, oldnd*sizeof(intp));
+ mydim = newdims;
+ }
- if (tuple) {
- for (i=0; i<numnew; i++) {
- mydim[i] = (intp) PyInt_AsLong \
- (PyTuple_GET_ITEM(old->subarray->shape, i));
- }
- }
- else {
- mydim[0] = (intp) PyInt_AsLong(old->subarray->shape);
- }
+ if (tuple) {
+ for (i=0; i<numnew; i++) {
+ mydim[i] = (intp) PyInt_AsLong \
+ (PyTuple_GET_ITEM(old->subarray->shape, i));
+ }
+ }
+ else {
+ mydim[0] = (intp) PyInt_AsLong(old->subarray->shape);
+ }
- if (newstrides) {
- intp tempsize;
- intp *mystrides;
- mystrides = newstrides + oldnd;
- if (isfortran) {
- memmove(newstrides+numnew, newstrides,
- oldnd*sizeof(intp));
- mystrides = newstrides;
- }
- /* Make new strides -- alwasy C-contiguous */
- tempsize = (*des)->elsize;
- for (i=numnew-1; i>=0; i--) {
- mystrides[i] = tempsize;
- tempsize *= mydim[i] ? mydim[i] : 1;
- }
- }
+ if (newstrides) {
+ intp tempsize;
+ intp *mystrides;
+ mystrides = newstrides + oldnd;
+ if (isfortran) {
+ memmove(newstrides+numnew, newstrides,
+ oldnd*sizeof(intp));
+ mystrides = newstrides;
+ }
+ /* Make new strides -- alwasy C-contiguous */
+ tempsize = (*des)->elsize;
+ for (i=numnew-1; i>=0; i--) {
+ mystrides[i] = tempsize;
+ tempsize *= mydim[i] ? mydim[i] : 1;
+ }
+ }
finish:
- Py_INCREF(*des);
- Py_DECREF(old);
- return newnd;
+ Py_INCREF(*des);
+ Py_DECREF(old);
+ return newnd;
}
@@ -4976,170 +4976,170 @@
*/
static PyObject *
PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
- intp *dims, intp *strides, void *data,
- int flags, PyObject *obj)
+ intp *dims, intp *strides, void *data,
+ int flags, PyObject *obj)
{
- PyArrayObject *self;
- register int i;
- size_t sd;
- intp largest;
- intp size;
+ PyArrayObject *self;
+ register int i;
+ size_t sd;
+ intp largest;
+ intp size;
- if (descr->subarray) {
- PyObject *ret;
- intp newdims[2*MAX_DIMS];
- intp *newstrides=NULL;
- int isfortran=0;
- isfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \
- (!data && flags);
- memcpy(newdims, dims, nd*sizeof(intp));
- if (strides) {
- newstrides = newdims + MAX_DIMS;
- memcpy(newstrides, strides, nd*sizeof(intp));
- }
- nd =_update_descr_and_dimensions(&descr, newdims,
- newstrides, nd, isfortran);
- ret = PyArray_NewFromDescr(subtype, descr, nd, newdims,
- newstrides,
- data, flags, obj);
- return ret;
- }
+ if (descr->subarray) {
+ PyObject *ret;
+ intp newdims[2*MAX_DIMS];
+ intp *newstrides=NULL;
+ int isfortran=0;
+ isfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \
+ (!data && flags);
+ memcpy(newdims, dims, nd*sizeof(intp));
+ if (strides) {
+ newstrides = newdims + MAX_DIMS;
+ memcpy(newstrides, strides, nd*sizeof(intp));
+ }
+ nd =_update_descr_and_dimensions(&descr, newdims,
+ newstrides, nd, isfortran);
+ ret = PyArray_NewFromDescr(subtype, descr, nd, newdims,
+ newstrides,
+ data, flags, obj);
+ return ret;
+ }
- if (nd < 0) {
- PyErr_SetString(PyExc_ValueError,
- "number of dimensions must be >=0");
- Py_DECREF(descr);
- return NULL;
- }
+ if (nd < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "number of dimensions must be >=0");
+ Py_DECREF(descr);
+ return NULL;
+ }
if (nd > MAX_DIMS) {
PyErr_Format(PyExc_ValueError,
"maximum number of dimensions is %d", MAX_DIMS);
- Py_DECREF(descr);
+ Py_DECREF(descr);
return NULL;
- }
+ }
- /* Check dimensions */
- size = 1;
- sd = (size_t) descr->elsize;
- if (sd == 0) {
- PyErr_SetString(PyExc_ValueError, "Empty data-type");
- Py_DECREF(descr);
- return NULL;
- }
- largest = MAX_INTP / sd;
- for (i=0;i<nd;i++) {
- if (dims[i] == 0) continue;
- if (dims[i] < 0) {
- PyErr_SetString(PyExc_ValueError,
- "negative dimensions " \
- "are not allowed");
- Py_DECREF(descr);
- return NULL;
- }
- size *= dims[i];
- if (size <=0 || size > largest) {
- PyErr_SetString(PyExc_ValueError,
- "dimensions too large.");
- Py_DECREF(descr);
- return NULL;
- }
- }
-
- self = (PyArrayObject *) subtype->tp_alloc(subtype, 0);
- if (self == NULL) {
- Py_DECREF(descr);
- return NULL;
- }
- self->nd = nd;
- self->dimensions = NULL;
- self->data = NULL;
- if (data == NULL) {
- self->flags = DEFAULT;
- if (flags) {
- self->flags |= FORTRAN;
- if (nd > 1) self->flags &= ~CONTIGUOUS;
- flags = FORTRAN;
- }
- }
- else self->flags = (flags & ~UPDATEIFCOPY);
+ /* Check dimensions */
+ size = 1;
+ sd = (size_t) descr->elsize;
+ if (sd == 0) {
+ PyErr_SetString(PyExc_ValueError, "Empty data-type");
+ Py_DECREF(descr);
+ return NULL;
+ }
+ largest = MAX_INTP / sd;
+ for (i=0;i<nd;i++) {
+ if (dims[i] == 0) continue;
+ if (dims[i] < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "negative dimensions " \
+ "are not allowed");
+ Py_DECREF(descr);
+ return NULL;
+ }
+ size *= dims[i];
+ if (size <=0 || size > largest) {
+ PyErr_SetString(PyExc_ValueError,
+ "dimensions too large.");
+ Py_DECREF(descr);
+ return NULL;
+ }
+ }
+
+ self = (PyArrayObject *) subtype->tp_alloc(subtype, 0);
+ if (self == NULL) {
+ Py_DECREF(descr);
+ return NULL;
+ }
+ self->nd = nd;
+ self->dimensions = NULL;
+ self->data = NULL;
+ if (data == NULL) {
+ self->flags = DEFAULT;
+ if (flags) {
+ self->flags |= FORTRAN;
+ if (nd > 1) self->flags &= ~CONTIGUOUS;
+ flags = FORTRAN;
+ }
+ }
+ else self->flags = (flags & ~UPDATEIFCOPY);
- self->descr = descr;
- self->base = (PyObject *)NULL;
+ self->descr = descr;
+ self->base = (PyObject *)NULL;
self->weakreflist = (PyObject *)NULL;
- if (nd > 0) {
- self->dimensions = PyDimMem_NEW(2*nd);
- if (self->dimensions == NULL) {
- PyErr_NoMemory();
- goto fail;
- }
- self->strides = self->dimensions + nd;
- memcpy(self->dimensions, dims, sizeof(intp)*nd);
- if (strides == NULL) { /* fill it in */
- sd = _array_fill_strides(self->strides, dims, nd, sd,
- flags, &(self->flags));
- }
- else { /* we allow strides even when we create
- the memory, but be careful with this...
- */
- memcpy(self->strides, strides, sizeof(intp)*nd);
- sd *= size;
- }
- }
- else { self->dimensions = self->strides = NULL; }
+ if (nd > 0) {
+ self->dimensions = PyDimMem_NEW(2*nd);
+ if (self->dimensions == NULL) {
+ PyErr_NoMemory();
+ goto fail;
+ }
+ self->strides = self->dimensions + nd;
+ memcpy(self->dimensions, dims, sizeof(intp)*nd);
+ if (strides == NULL) { /* fill it in */
+ sd = _array_fill_strides(self->strides, dims, nd, sd,
+ flags, &(self->flags));
+ }
+ else { /* we allow strides even when we create
+ the memory, but be careful with this...
+ */
+ memcpy(self->strides, strides, sizeof(intp)*nd);
+ sd *= size;
+ }
+ }
+ else { self->dimensions = self->strides = NULL; }
- if (data == NULL) {
+ if (data == NULL) {
- /* Allocate something even for zero-space arrays
- e.g. shape=(0,) -- otherwise buffer exposure
- (a.data) doesn't work as it should. */
-
- if (sd==0) sd = descr->elsize;
+ /* Allocate something even for zero-space arrays
+ e.g. shape=(0,) -- otherwise buffer exposure
+ (a.data) doesn't work as it should. */
+
+ if (sd==0) sd = descr->elsize;
- if ((data = PyDataMem_NEW(sd))==NULL) {
- PyErr_NoMemory();
- goto fail;
- }
- self->flags |= OWNDATA;
+ if ((data = PyDataMem_NEW(sd))==NULL) {
+ PyErr_NoMemory();
+ goto fail;
+ }
+ self->flags |= OWNDATA;
- /* It is bad to have unitialized OBJECT pointers */
+ /* It is bad to have unitialized OBJECT pointers */
/* which could also be sub-fields of a VOID array */
- if (descr->hasobject) {
- /*
+ if (descr->hasobject) {
+ /*
if (descr != &OBJECT_Descr) {
PyErr_SetString(PyExc_TypeError,
"fields with object members " \
"not yet supported.");
goto fail;
}
- */
+ */
- memset(data, 0, sd);
- }
- }
- else {
+ memset(data, 0, sd);
+ }
+ }
+ else {
self->flags &= ~OWNDATA; /* If data is passed in,
- this object won't own it
- by default.
- Caller must arrange for
- this to be reset if truly
- desired */
+ this object won't own it
+ by default.
+ Caller must arrange for
+ this to be reset if truly
+ desired */
}
self->data = data;
/* call the __array_finalize__
- method if a subtype.
- If obj is NULL, then call method with Py_None
- */
- if ((subtype != &PyArray_Type)) {
- PyObject *res, *func, *args;
- static PyObject *str=NULL;
+ method if a subtype.
+ If obj is NULL, then call method with Py_None
+ */
+ if ((subtype != &PyArray_Type)) {
+ PyObject *res, *func, *args;
+ static PyObject *str=NULL;
- if (str == NULL) {
- str = PyString_InternFromString("__array_finalize__");
- }
- func = PyObject_GetAttr((PyObject *)self, str);
- if (func && func != Py_None) {
+ if (str == NULL) {
+ str = PyString_InternFromString("__array_finalize__");
+ }
+ func = PyObject_GetAttr((PyObject *)self, str);
+ if (func && func != Py_None) {
if (strides != NULL) { /* did not allocate own data
or funny strides */
/* update flags before finalize function */
@@ -5166,36 +5166,36 @@
else Py_XDECREF(func);
}
- return (PyObject *)self;
+ return (PyObject *)self;
fail:
- Py_DECREF(self);
- return NULL;
+ Py_DECREF(self);
+ return NULL;
}
static void
_putzero(char *optr, PyObject *zero, PyArray_Descr *dtype)
{
- if (dtype->hasobject == 0) {
- memset(optr, 0, dtype->elsize);
- }
- else if (PyDescr_ISOBJECT(dtype)) {
- PyObject **temp;
- Py_INCREF(zero);
- temp = (PyObject **)optr;
- *temp = zero;
- }
- else if (PyDescr_HASFIELDS(dtype)) {
+ if (dtype->hasobject == 0) {
+ memset(optr, 0, dtype->elsize);
+ }
+ else if (PyDescr_ISOBJECT(dtype)) {
+ PyObject **temp;
+ Py_INCREF(zero);
+ temp = (PyObject **)optr;
+ *temp = zero;
+ }
+ else if (PyDescr_HASFIELDS(dtype)) {
PyObject *key, *value, *title=NULL;
PyArray_Descr *new;
int offset, pos=0;
while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
- if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
- &title)) return;
+ if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
+ &title)) return;
_putzero(optr + offset, zero, new);
}
}
- return;
+ return;
}
@@ -5209,7 +5209,7 @@
*/
static PyObject *
PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,
- NPY_ORDER fortran)
+ NPY_ORDER fortran)
{
intp oldsize, newsize;
int new_nd=newshape->len, k, n, elsize;
@@ -5219,7 +5219,7 @@
size_t sd;
intp *dimptr;
char *new_data;
- intp largest;
+ intp largest;
if (!PyArray_ISONESEGMENT(self)) {
PyErr_SetString(PyExc_ValueError,
@@ -5227,80 +5227,80 @@
return NULL;
}
- if (fortran == PyArray_ANYORDER)
- fortran = PyArray_CORDER;
+ if (fortran == PyArray_ANYORDER)
+ fortran = PyArray_CORDER;
- if (self->descr->elsize == 0) {
- PyErr_SetString(PyExc_ValueError, "Bad data-type size.");
- return NULL;
- }
- newsize = 1;
- largest = MAX_INTP / self->descr->elsize;
- for (k=0; k<new_nd; k++) {
- if (new_dimensions[k]==0) break;
- if (new_dimensions[k] < 0) {
- PyErr_SetString(PyExc_ValueError,
- "negative dimensions not allowed");
- return NULL;
- }
- newsize *= new_dimensions[k];
- if (newsize <=0 || newsize > largest) {
- return PyErr_NoMemory();
- }
- }
+ if (self->descr->elsize == 0) {
+ PyErr_SetString(PyExc_ValueError, "Bad data-type size.");
+ return NULL;
+ }
+ newsize = 1;
+ largest = MAX_INTP / self->descr->elsize;
+ for (k=0; k<new_nd; k++) {
+ if (new_dimensions[k]==0) break;
+ if (new_dimensions[k] < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "negative dimensions not allowed");
+ return NULL;
+ }
+ newsize *= new_dimensions[k];
+ if (newsize <=0 || newsize > largest) {
+ return PyErr_NoMemory();
+ }
+ }
oldsize = PyArray_SIZE(self);
- if (oldsize != newsize) {
- if (!(self->flags & OWNDATA)) {
- PyErr_SetString(PyExc_ValueError,
- "cannot resize this array: " \
- "it does not own its data");
- return NULL;
- }
+ if (oldsize != newsize) {
+ if (!(self->flags & OWNDATA)) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot resize this array: " \
+ "it does not own its data");
+ return NULL;
+ }
- if (refcheck) refcnt = REFCOUNT(self);
- else refcnt = 1;
- if ((refcnt > 2) || (self->base != NULL) || \
- (self->weakreflist != NULL)) {
- PyErr_SetString(PyExc_ValueError,
- "cannot resize an array that has "\
- "been referenced or is referencing\n"\
- "another array in this way. Use the "\
- "resize function");
- return NULL;
- }
+ if (refcheck) refcnt = REFCOUNT(self);
+ else refcnt = 1;
+ if ((refcnt > 2) || (self->base != NULL) || \
+ (self->weakreflist != NULL)) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot resize an array that has "\
+ "been referenced or is referencing\n"\
+ "another array in this way. Use the "\
+ "resize function");
+ return NULL;
+ }
- if (newsize == 0) sd = self->descr->elsize;
- else sd = newsize * self->descr->elsize;
- /* Reallocate space if needed */
- new_data = PyDataMem_RENEW(self->data, sd);
- if (new_data == NULL) {
- PyErr_SetString(PyExc_MemoryError,
- "cannot allocate memory for array");
- return NULL;
- }
- self->data = new_data;
- }
+ if (newsize == 0) sd = self->descr->elsize;
+ else sd = newsize * self->descr->elsize;
+ /* Reallocate space if needed */
+ new_data = PyDataMem_RENEW(self->data, sd);
+ if (new_data == NULL) {
+ PyErr_SetString(PyExc_MemoryError,
+ "cannot allocate memory for array");
+ return NULL;
+ }
+ self->data = new_data;
+ }
if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {
- /* Fill new memory with zeros */
+ /* Fill new memory with zeros */
elsize = self->descr->elsize;
- if (self->descr->hasobject) {
- PyObject *zero = PyInt_FromLong(0);
+ if (self->descr->hasobject) {
+ PyObject *zero = PyInt_FromLong(0);
char *optr;
- optr = self->data + oldsize*elsize;
- n = newsize - oldsize;
- for (k=0; k<n; k++) {
- _putzero((char *)optr, zero, self->descr);
- optr += elsize;
- }
- Py_DECREF(zero);
- }
- else{
- memset(self->data+oldsize*elsize, 0,
- (newsize-oldsize)*elsize);
- }
- }
+ optr = self->data + oldsize*elsize;
+ n = newsize - oldsize;
+ for (k=0; k<n; k++) {
+ _putzero((char *)optr, zero, self->descr);
+ optr += elsize;
+ }
+ Py_DECREF(zero);
+ }
+ else{
+ memset(self->data+oldsize*elsize, 0,
+ (newsize-oldsize)*elsize);
+ }
+ }
if (self->nd != new_nd) { /* Different number of dimensions. */
self->nd = new_nd;
@@ -5308,19 +5308,19 @@
/* Need new dimensions and strides arrays */
dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);
if (dimptr == NULL) {
- PyErr_SetString(PyExc_MemoryError,
+ PyErr_SetString(PyExc_MemoryError,
"cannot allocate memory for array " \
"(array may be corrupted)");
return NULL;
}
self->dimensions = dimptr;
- self->strides = dimptr + new_nd;
+ self->strides = dimptr + new_nd;
}
/* make new_strides variable */
sd = (size_t) self->descr->elsize;
sd = (size_t) _array_fill_strides(new_strides, new_dimensions, new_nd, sd,
- self->flags, &(self->flags));
+ self->flags, &(self->flags));
memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));
memmove(self->strides, new_strides, new_nd*sizeof(intp));
@@ -5333,35 +5333,35 @@
static void
_fillobject(char *optr, PyObject *obj, PyArray_Descr *dtype)
{
- if (!dtype->hasobject) {
- if ((obj == Py_None) ||
- (PyInt_Check(obj) && PyInt_AsLong(obj)==0))
- return;
- else {
- PyObject *arr;
- Py_INCREF(dtype);
- arr = PyArray_NewFromDescr(&PyArray_Type, dtype,
- 0, NULL, NULL, NULL,
- 0, NULL);
- if (arr!=NULL)
- dtype->f->setitem(obj, optr, arr);
- Py_XDECREF(arr);
- }
- }
- if (PyDescr_ISOBJECT(dtype)) {
- PyObject **temp;
- Py_XINCREF(obj);
- temp = (PyObject **)optr;
- *temp = obj;
- return;
- }
- if (PyDescr_HASFIELDS(dtype)) {
+ if (!dtype->hasobject) {
+ if ((obj == Py_None) ||
+ (PyInt_Check(obj) && PyInt_AsLong(obj)==0))
+ return;
+ else {
+ PyObject *arr;
+ Py_INCREF(dtype);
+ arr = PyArray_NewFromDescr(&PyArray_Type, dtype,
+ 0, NULL, NULL, NULL,
+ 0, NULL);
+ if (arr!=NULL)
+ dtype->f->setitem(obj, optr, arr);
+ Py_XDECREF(arr);
+ }
+ }
+ if (PyDescr_ISOBJECT(dtype)) {
+ PyObject **temp;
+ Py_XINCREF(obj);
+ temp = (PyObject **)optr;
+ *temp = obj;
+ return;
+ }
+ if (PyDescr_HASFIELDS(dtype)) {
PyObject *key, *value, *title=NULL;
PyArray_Descr *new;
int offset, pos=0;
while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
- if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
- &title)) return;
+ if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
+ &title)) return;
_fillobject(optr + offset, obj, new);
}
}
@@ -5373,191 +5373,191 @@
PyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)
{
intp i,n;
- n = PyArray_SIZE(arr);
- if (arr->descr->type_num == PyArray_OBJECT) {
- PyObject **optr;
- optr = (PyObject **)(arr->data);
- n = PyArray_SIZE(arr);
- if (obj == NULL) {
- for (i=0; i<n; i++) {
- *optr++ = NULL;
- }
- }
- else {
- for (i=0; i<n; i++) {
- Py_INCREF(obj);
- *optr++ = obj;
- }
- }
- }
- else {
- char *optr;
- optr = arr->data;
- for (i=0; i<n; i++) {
- _fillobject(optr, obj, arr->descr);
- optr += arr->descr->elsize;
- }
- }
+ n = PyArray_SIZE(arr);
+ if (arr->descr->type_num == PyArray_OBJECT) {
+ PyObject **optr;
+ optr = (PyObject **)(arr->data);
+ n = PyArray_SIZE(arr);
+ if (obj == NULL) {
+ for (i=0; i<n; i++) {
+ *optr++ = NULL;
+ }
+ }
+ else {
+ for (i=0; i<n; i++) {
+ Py_INCREF(obj);
+ *optr++ = obj;
+ }
+ }
+ }
+ else {
+ char *optr;
+ optr = arr->data;
+ for (i=0; i<n; i++) {
+ _fillobject(optr, obj, arr->descr);
+ optr += arr->descr->elsize;
+ }
+ }
}
/*OBJECT_API*/
static int
PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
{
- PyObject *newarr;
- int itemsize, swap;
- void *fromptr;
- PyArray_Descr *descr;
- intp size;
+ PyObject *newarr;
+ int itemsize, swap;
+ void *fromptr;
+ PyArray_Descr *descr;
+ intp size;
PyArray_CopySwapFunc *copyswap;
- itemsize = arr->descr->elsize;
- if (PyArray_ISOBJECT(arr)) {
- fromptr = &obj;
- swap = 0;
- newarr = NULL;
- }
- else {
- descr = PyArray_DESCR(arr);
- Py_INCREF(descr);
- newarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);
- if (newarr == NULL) return -1;
- fromptr = PyArray_DATA(newarr);
- swap=!PyArray_ISNOTSWAPPED(arr);
- }
- size=PyArray_SIZE(arr);
- copyswap = arr->descr->f->copyswap;
- if (PyArray_ISONESEGMENT(arr)) {
- char *toptr=PyArray_DATA(arr);
- PyArray_FillWithScalarFunc* fillwithscalar =
- arr->descr->f->fillwithscalar;
- if (fillwithscalar && PyArray_ISALIGNED(arr)) {
- copyswap(fromptr, NULL, swap, newarr);
- fillwithscalar(toptr, size, fromptr, arr);
- }
- else {
- while (size--) {
- copyswap(toptr, fromptr, swap, arr);
- toptr += itemsize;
- }
- }
- }
- else {
- PyArrayIterObject *iter;
+ itemsize = arr->descr->elsize;
+ if (PyArray_ISOBJECT(arr)) {
+ fromptr = &obj;
+ swap = 0;
+ newarr = NULL;
+ }
+ else {
+ descr = PyArray_DESCR(arr);
+ Py_INCREF(descr);
+ newarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);
+ if (newarr == NULL) return -1;
+ fromptr = PyArray_DATA(newarr);
+ swap=!PyArray_ISNOTSWAPPED(arr);
+ }
+ size=PyArray_SIZE(arr);
+ copyswap = arr->descr->f->copyswap;
+ if (PyArray_ISONESEGMENT(arr)) {
+ char *toptr=PyArray_DATA(arr);
+ PyArray_FillWithScalarFunc* fillwithscalar =
+ arr->descr->f->fillwithscalar;
+ if (fillwithscalar && PyArray_ISALIGNED(arr)) {
+ copyswap(fromptr, NULL, swap, newarr);
+ fillwithscalar(toptr, size, fromptr, arr);
+ }
+ else {
+ while (size--) {
+ copyswap(toptr, fromptr, swap, arr);
+ toptr += itemsize;
+ }
+ }
+ }
+ else {
+ PyArrayIterObject *iter;
- iter = (PyArrayIterObject *)\
- PyArray_IterNew((PyObject *)arr);
- if (iter == NULL) {
- Py_XDECREF(newarr);
- return -1;
- }
- while(size--) {
- copyswap(iter->dataptr, fromptr, swap, arr);
- PyArray_ITER_NEXT(iter);
- }
- Py_DECREF(iter);
- }
- Py_XDECREF(newarr);
- return 0;
+ iter = (PyArrayIterObject *)\
+ PyArray_IterNew((PyObject *)arr);
+ if (iter == NULL) {
+ Py_XDECREF(newarr);
+ return -1;
+ }
+ while(size--) {
+ copyswap(iter->dataptr, fromptr, swap, arr);
+ PyArray_ITER_NEXT(iter);
+ }
+ Py_DECREF(iter);
+ }
+ Py_XDECREF(newarr);
+ return 0;
}
static PyObject *
array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
{
- static char *kwlist[] = {"shape", "dtype", "buffer",
- "offset", "strides",
- "order", NULL};
- PyArray_Descr *descr=NULL;
- int type_num;
- int itemsize;
+ static char *kwlist[] = {"shape", "dtype", "buffer",
+ "offset", "strides",
+ "order", NULL};
+ PyArray_Descr *descr=NULL;
+ int type_num;
+ int itemsize;
PyArray_Dims dims = {NULL, 0};
PyArray_Dims strides = {NULL, 0};
PyArray_Chunk buffer;
- longlong offset=0;
+ longlong offset=0;
NPY_ORDER order=PyArray_CORDER;
- int fortran = 0;
- PyArrayObject *ret;
+ int fortran = 0;
+ PyArrayObject *ret;
- buffer.ptr = NULL;
+ buffer.ptr = NULL;
/* Usually called with shape and type
but can also be called with buffer, strides, and swapped info
*/
- /* For now, let's just use this to create an empty, contiguous
- array of a specific type and shape.
- */
+ /* For now, let's just use this to create an empty, contiguous
+ array of a specific type and shape.
+ */
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&LO&O&",
- kwlist, PyArray_IntpConverter,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&LO&O&",
+ kwlist, PyArray_IntpConverter,
&dims,
PyArray_DescrConverter,
- &descr,
+ &descr,
PyArray_BufferConverter,
&buffer,
- &offset,
+ &offset,
&PyArray_IntpConverter,
&strides,
&PyArray_OrderConverter,
&order))
- goto fail;
+ goto fail;
if (order == PyArray_FORTRANORDER) fortran = 1;
- if (descr == NULL)
- descr = PyArray_DescrFromType(PyArray_DEFAULT);
+ if (descr == NULL)
+ descr = PyArray_DescrFromType(PyArray_DEFAULT);
- type_num = descr->type_num;
- itemsize = descr->elsize;
+ type_num = descr->type_num;
+ itemsize = descr->elsize;
- if (itemsize == 0) {
- PyErr_SetString(PyExc_ValueError,
- "data-type with unspecified variable length");
- goto fail;
- }
-
- if (strides.ptr != NULL) {
- intp nb, off;
- if (strides.len != dims.len) {
- PyErr_SetString(PyExc_ValueError,
- "strides, if given, must be " \
- "the same length as shape");
- goto fail;
- }
+ if (itemsize == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "data-type with unspecified variable length");
+ goto fail;
+ }
+
+ if (strides.ptr != NULL) {
+ intp nb, off;
+ if (strides.len != dims.len) {
+ PyErr_SetString(PyExc_ValueError,
+ "strides, if given, must be " \
+ "the same length as shape");
+ goto fail;
+ }
- if (buffer.ptr == NULL) {
- nb = 0;
- off = 0;
- }
- else {
- nb = buffer.len;
- off = (intp) offset;
- }
-
+ if (buffer.ptr == NULL) {
+ nb = 0;
+ off = 0;
+ }
+ else {
+ nb = buffer.len;
+ off = (intp) offset;
+ }
+
- if (!PyArray_CheckStrides(itemsize, dims.len,
- nb, off,
- dims.ptr, strides.ptr)) {
- PyErr_SetString(PyExc_ValueError,
- "strides is incompatible " \
- "with shape of requested " \
- "array and size of buffer");
- goto fail;
- }
- }
-
+ if (!PyArray_CheckStrides(itemsize, dims.len,
+ nb, off,
+ dims.ptr, strides.ptr)) {
+ PyErr_SetString(PyExc_ValueError,
+ "strides is incompatible " \
+ "with shape of requested " \
+ "array and size of buffer");
+ goto fail;
+ }
+ }
+
if (buffer.ptr == NULL) {
- ret = (PyArrayObject *) \
- PyArray_NewFromDescr(subtype, descr,
- (int)dims.len,
- dims.ptr,
- strides.ptr, NULL, fortran, NULL);
+ ret = (PyArrayObject *) \
+ PyArray_NewFromDescr(subtype, descr,
+ (int)dims.len,
+ dims.ptr,
+ strides.ptr, NULL, fortran, NULL);
if (ret == NULL) {descr=NULL;goto fail;}
if (descr->hasobject) { /* place Py_None in object positions */
PyArray_FillObjectArray(ret, Py_None);
- if (PyErr_Occurred()) {
- descr=NULL;
- goto fail;
- }
+ if (PyErr_Occurred()) {
+ descr=NULL;
+ goto fail;
+ }
}
}
else { /* buffer given -- use it */
@@ -5565,8 +5565,8 @@
dims.ptr[0] = (buffer.len-(intp)offset) / itemsize;
}
else if ((strides.ptr == NULL) && \
- (buffer.len < ((intp)itemsize)* \
- PyArray_MultiplyList(dims.ptr, dims.len))) {
+ (buffer.len < ((intp)itemsize)* \
+ PyArray_MultiplyList(dims.ptr, dims.len))) {
PyErr_SetString(PyExc_TypeError,
"buffer is too small for " \
"requested array");
@@ -5575,11 +5575,11 @@
/* get writeable and aligned */
if (fortran) buffer.flags |= FORTRAN;
ret = (PyArrayObject *)\
- PyArray_NewFromDescr(subtype, descr,
- dims.len, dims.ptr,
- strides.ptr,
- offset + (char *)buffer.ptr,
- buffer.flags, NULL);
+ PyArray_NewFromDescr(subtype, descr,
+ dims.len, dims.ptr,
+ strides.ptr,
+ offset + (char *)buffer.ptr,
+ buffer.flags, NULL);
if (ret == NULL) {descr=NULL; goto fail;}
PyArray_UpdateFlags(ret, UPDATE_ALL);
ret->base = buffer.base;
@@ -5591,7 +5591,7 @@
return (PyObject *)ret;
fail:
- Py_XDECREF(descr);
+ Py_XDECREF(descr);
if (dims.ptr) PyDimMem_FREE(dims.ptr);
if (strides.ptr) PyDimMem_FREE(strides.ptr);
return NULL;
@@ -5601,12 +5601,12 @@
static PyObject *
array_iter(PyArrayObject *arr)
{
- if (arr->nd == 0) {
- PyErr_SetString(PyExc_TypeError,
- "iteration over a scalar (0-dim array)");
- return NULL;
- }
- return PySeqIter_New((PyObject *)arr);
+ if (arr->nd == 0) {
+ PyErr_SetString(PyExc_TypeError,
+ "iteration over a scalar (0-dim array)");
+ return NULL;
+ }
+ return PySeqIter_New((PyObject *)arr);
}
@@ -5615,7 +5615,7 @@
static PyObject *
array_ndim_get(PyArrayObject *self)
{
- return PyInt_FromLong(self->nd);
+ return PyInt_FromLong(self->nd);
}
static PyObject *
@@ -5627,19 +5627,19 @@
static PyObject *
array_shape_get(PyArrayObject *self)
{
- return PyArray_IntTupleFromIntp(self->nd, self->dimensions);
+ return PyArray_IntTupleFromIntp(self->nd, self->dimensions);
}
static int
array_shape_set(PyArrayObject *self, PyObject *val)
{
- int nd;
- PyObject *ret;
+ int nd;
+ PyObject *ret;
/* Assumes C-order */
- ret = PyArray_Reshape(self, val);
- if (ret == NULL) return -1;
+ ret = PyArray_Reshape(self, val);
+ if (ret == NULL) return -1;
if (PyArray_DATA(ret) != PyArray_DATA(self)) {
Py_DECREF(ret);
PyErr_SetString(PyExc_AttributeError,
@@ -5647,91 +5647,91 @@
return -1;
}
- /* Free old dimensions and strides */
- PyDimMem_FREE(self->dimensions);
- nd = PyArray_NDIM(ret);
- self->nd = nd;
- if (nd > 0) { /* create new dimensions and strides */
- self->dimensions = PyDimMem_NEW(2*nd);
- if (self->dimensions == NULL) {
- Py_DECREF(ret);
- PyErr_SetString(PyExc_MemoryError,"");
- return -1;
- }
- self->strides = self->dimensions + nd;
- memcpy(self->dimensions, PyArray_DIMS(ret),
- nd*sizeof(intp));
- memcpy(self->strides, PyArray_STRIDES(ret),
- nd*sizeof(intp));
- }
- else {self->dimensions=NULL; self->strides=NULL;}
- Py_DECREF(ret);
- PyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);
- return 0;
+ /* Free old dimensions and strides */
+ PyDimMem_FREE(self->dimensions);
+ nd = PyArray_NDIM(ret);
+ self->nd = nd;
+ if (nd > 0) { /* create new dimensions and strides */
+ self->dimensions = PyDimMem_NEW(2*nd);
+ if (self->dimensions == NULL) {
+ Py_DECREF(ret);
+ PyErr_SetString(PyExc_MemoryError,"");
+ return -1;
+ }
+ self->strides = self->dimensions + nd;
+ memcpy(self->dimensions, PyArray_DIMS(ret),
+ nd*sizeof(intp));
+ memcpy(self->strides, PyArray_STRIDES(ret),
+ nd*sizeof(intp));
+ }
+ else {self->dimensions=NULL; self->strides=NULL;}
+ Py_DECREF(ret);
+ PyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);
+ return 0;
}
static PyObject *
array_strides_get(PyArrayObject *self)
{
- return PyArray_IntTupleFromIntp(self->nd, self->strides);
+ return PyArray_IntTupleFromIntp(self->nd, self->strides);
}
static int
array_strides_set(PyArrayObject *self, PyObject *obj)
{
- PyArray_Dims newstrides = {NULL, 0};
- PyArrayObject *new;
- intp numbytes=0;
- intp offset=0;
- Py_ssize_t buf_len;
- char *buf;
+ PyArray_Dims newstrides = {NULL, 0};
+ PyArrayObject *new;
+ intp numbytes=0;
+ intp offset=0;
+ Py_ssize_t buf_len;
+ char *buf;
- if (!PyArray_IntpConverter(obj, &newstrides) || \
- newstrides.ptr == NULL) {
- PyErr_SetString(PyExc_TypeError, "invalid strides");
- return -1;
- }
- if (newstrides.len != self->nd) {
- PyErr_Format(PyExc_ValueError, "strides must be " \
- " same length as shape (%d)", self->nd);
- goto fail;
- }
- new = self;
- while(new->base && PyArray_Check(new->base)) {
- new = (PyArrayObject *)(new->base);
- }
- /* Get the available memory through the buffer
- interface on new->base or if that fails
- from the current new */
- if (new->base && PyObject_AsReadBuffer(new->base,
- (const void **)&buf,
- &buf_len) >= 0) {
- offset = self->data - buf;
- numbytes = buf_len + offset;
- }
- else {
- PyErr_Clear();
- numbytes = PyArray_MultiplyList(new->dimensions,
- new->nd)*new->descr->elsize;
- offset = self->data - new->data;
- }
+ if (!PyArray_IntpConverter(obj, &newstrides) || \
+ newstrides.ptr == NULL) {
+ PyErr_SetString(PyExc_TypeError, "invalid strides");
+ return -1;
+ }
+ if (newstrides.len != self->nd) {
+ PyErr_Format(PyExc_ValueError, "strides must be " \
+ " same length as shape (%d)", self->nd);
+ goto fail;
+ }
+ new = self;
+ while(new->base && PyArray_Check(new->base)) {
+ new = (PyArrayObject *)(new->base);
+ }
+ /* Get the available memory through the buffer
+ interface on new->base or if that fails
+ from the current new */
+ if (new->base && PyObject_AsReadBuffer(new->base,
+ (const void **)&buf,
+ &buf_len) >= 0) {
+ offset = self->data - buf;
+ numbytes = buf_len + offset;
+ }
+ else {
+ PyErr_Clear();
+ numbytes = PyArray_MultiplyList(new->dimensions,
+ new->nd)*new->descr->elsize;
+ offset = self->data - new->data;
+ }
- if (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,
- offset,
- self->dimensions, newstrides.ptr)) {
- PyErr_SetString(PyExc_ValueError, "strides is not "\
- "compatible with available memory");
- goto fail;
- }
- memcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);
- PyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);
- PyDimMem_FREE(newstrides.ptr);
- return 0;
+ if (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,
+ offset,
+ self->dimensions, newstrides.ptr)) {
+ PyErr_SetString(PyExc_ValueError, "strides is not "\
+ "compatible with available memory");
+ goto fail;
+ }
+ memcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);
+ PyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);
+ PyDimMem_FREE(newstrides.ptr);
+ return 0;
fail:
- PyDimMem_FREE(newstrides.ptr);
- return -1;
+ PyDimMem_FREE(newstrides.ptr);
+ return -1;
}
@@ -5739,10 +5739,10 @@
static PyObject *
array_priority_get(PyArrayObject *self)
{
- if (PyArray_CheckExact(self))
- return PyFloat_FromDouble(PyArray_PRIORITY);
- else
- return PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);
+ if (PyArray_CheckExact(self))
+ return PyFloat_FromDouble(PyArray_PRIORITY);
+ else
+ return PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);
}
static PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);
@@ -5750,14 +5750,14 @@
static PyObject *
array_typestr_get(PyArrayObject *self)
{
- return arraydescr_protocol_typestr_get(self->descr);
+ return arraydescr_protocol_typestr_get(self->descr);
}
static PyObject *
array_descr_get(PyArrayObject *self)
{
- Py_INCREF(self->descr);
- return (PyObject *)self->descr;
+ Py_INCREF(self->descr);
+ return (PyObject *)self->descr;
}
static PyObject *arraydescr_protocol_descr_get(PyArray_Descr *self);
@@ -5765,32 +5765,32 @@
static PyObject *
array_protocol_descr_get(PyArrayObject *self)
{
- PyObject *res;
- PyObject *dobj;
+ PyObject *res;
+ PyObject *dobj;
- res = arraydescr_protocol_descr_get(self->descr);
- if (res) return res;
- PyErr_Clear();
+ res = arraydescr_protocol_descr_get(self->descr);
+ if (res) return res;
+ PyErr_Clear();
- /* get default */
- dobj = PyTuple_New(2);
- if (dobj == NULL) return NULL;
- PyTuple_SET_ITEM(dobj, 0, PyString_FromString(""));
- PyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));
- res = PyList_New(1);
- if (res == NULL) {Py_DECREF(dobj); return NULL;}
- PyList_SET_ITEM(res, 0, dobj);
- return res;
+ /* get default */
+ dobj = PyTuple_New(2);
+ if (dobj == NULL) return NULL;
+ PyTuple_SET_ITEM(dobj, 0, PyString_FromString(""));
+ PyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));
+ res = PyList_New(1);
+ if (res == NULL) {Py_DECREF(dobj); return NULL;}
+ PyList_SET_ITEM(res, 0, dobj);
+ return res;
}
static PyObject *
array_protocol_strides_get(PyArrayObject *self)
{
- if PyArray_ISCONTIGUOUS(self) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return PyArray_IntTupleFromIntp(self->nd, self->strides);
+ if PyArray_ISCONTIGUOUS(self) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyArray_IntTupleFromIntp(self->nd, self->strides);
}
@@ -5798,143 +5798,143 @@
static PyObject *
array_dataptr_get(PyArrayObject *self)
{
- return Py_BuildValue("NO",
- PyLong_FromVoidPtr(self->data),
- (self->flags & WRITEABLE ? Py_False :
- Py_True));
+ return Py_BuildValue("NO",
+ PyLong_FromVoidPtr(self->data),
+ (self->flags & WRITEABLE ? Py_False :
+ Py_True));
}
static PyObject *
array_ctypes_get(PyArrayObject *self)
{
- return PyObject_CallMethod(_numpy_internal, "_ctypes",
- "O", self);
+ return PyObject_CallMethod(_numpy_internal, "_ctypes",
+ "O", self);
}
static PyObject *
array_as_parameter_get(PyArrayObject *self)
{
- return PyLong_FromVoidPtr(self->data);
+ return PyLong_FromVoidPtr(self->data);
}
static PyObject *
array_interface_get(PyArrayObject *self)
{
- PyObject *dict;
- PyObject *obj;
- dict = PyDict_New();
- if (dict == NULL) return NULL;
-
- /* dataptr */
- obj = array_dataptr_get(self);
- PyDict_SetItemString(dict, "data", obj);
- Py_DECREF(obj);
+ PyObject *dict;
+ PyObject *obj;
+ dict = PyDict_New();
+ if (dict == NULL) return NULL;
+
+ /* dataptr */
+ obj = array_dataptr_get(self);
+ PyDict_SetItemString(dict, "data", obj);
+ Py_DECREF(obj);
- obj = array_protocol_strides_get(self);
- PyDict_SetItemString(dict, "strides", obj);
- Py_DECREF(obj);
+ obj = array_protocol_strides_get(self);
+ PyDict_SetItemString(dict, "strides", obj);
+ Py_DECREF(obj);
- obj = array_protocol_descr_get(self);
- PyDict_SetItemString(dict, "descr", obj);
- Py_DECREF(obj);
+ obj = array_protocol_descr_get(self);
+ PyDict_SetItemString(dict, "descr", obj);
+ Py_DECREF(obj);
- obj = arraydescr_protocol_typestr_get(self->descr);
- PyDict_SetItemString(dict, "typestr", obj);
- Py_DECREF(obj);
-
- obj = array_shape_get(self);
- PyDict_SetItemString(dict, "shape", obj);
- Py_DECREF(obj);
+ obj = arraydescr_protocol_typestr_get(self->descr);
+ PyDict_SetItemString(dict, "typestr", obj);
+ Py_DECREF(obj);
+
+ obj = array_shape_get(self);
+ PyDict_SetItemString(dict, "shape", obj);
+ Py_DECREF(obj);
- obj = PyInt_FromLong(3);
- PyDict_SetItemString(dict, "version", obj);
- Py_DECREF(obj);
+ obj = PyInt_FromLong(3);
+ PyDict_SetItemString(dict, "version", obj);
+ Py_DECREF(obj);
- return dict;
+ return dict;
}
static PyObject *
array_data_get(PyArrayObject *self)
{
- intp nbytes;
- if (!(PyArray_ISONESEGMENT(self))) {
- PyErr_SetString(PyExc_AttributeError, "cannot get single-"\
- "segment buffer for discontiguous array");
- return NULL;
- }
- nbytes = PyArray_NBYTES(self);
- if PyArray_ISWRITEABLE(self)
- return PyBuffer_FromReadWriteObject((PyObject *)self, 0,
- (int) nbytes);
- else
- return PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);
+ intp nbytes;
+ if (!(PyArray_ISONESEGMENT(self))) {
+ PyErr_SetString(PyExc_AttributeError, "cannot get single-"\
+ "segment buffer for discontiguous array");
+ return NULL;
+ }
+ nbytes = PyArray_NBYTES(self);
+ if PyArray_ISWRITEABLE(self)
+ return PyBuffer_FromReadWriteObject((PyObject *)self, 0,
+ (int) nbytes);
+ else
+ return PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);
}
static int
array_data_set(PyArrayObject *self, PyObject *op)
{
- void *buf;
- Py_ssize_t buf_len;
- int writeable=1;
+ void *buf;
+ Py_ssize_t buf_len;
+ int writeable=1;
- if (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {
- writeable = 0;
- if (PyObject_AsReadBuffer(op, (const void **)&buf,
- &buf_len) < 0) {
- PyErr_SetString(PyExc_AttributeError,
- "object does not have single-segment " \
- "buffer interface");
- return -1;
- }
- }
- if (!PyArray_ISONESEGMENT(self)) {
- PyErr_SetString(PyExc_AttributeError, "cannot set single-" \
- "segment buffer for discontiguous array");
- return -1;
- }
- if (PyArray_NBYTES(self) > buf_len) {
- PyErr_SetString(PyExc_AttributeError,
- "not enough data for array");
- return -1;
- }
- if (self->flags & OWNDATA) {
- PyArray_XDECREF(self);
- PyDataMem_FREE(self->data);
- }
- if (self->base) {
- if (self->flags & UPDATEIFCOPY) {
- ((PyArrayObject *)self->base)->flags |= WRITEABLE;
- self->flags &= ~UPDATEIFCOPY;
- }
- Py_DECREF(self->base);
- }
- Py_INCREF(op);
- self->base = op;
- self->data = buf;
- self->flags = CARRAY;
- if (!writeable)
- self->flags &= ~WRITEABLE;
- return 0;
+ if (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {
+ writeable = 0;
+ if (PyObject_AsReadBuffer(op, (const void **)&buf,
+ &buf_len) < 0) {
+ PyErr_SetString(PyExc_AttributeError,
+ "object does not have single-segment " \
+ "buffer interface");
+ return -1;
+ }
+ }
+ if (!PyArray_ISONESEGMENT(self)) {
+ PyErr_SetString(PyExc_AttributeError, "cannot set single-" \
+ "segment buffer for discontiguous array");
+ return -1;
+ }
+ if (PyArray_NBYTES(self) > buf_len) {
+ PyErr_SetString(PyExc_AttributeError,
+ "not enough data for array");
+ return -1;
+ }
+ if (self->flags & OWNDATA) {
+ PyArray_XDECREF(self);
+ PyDataMem_FREE(self->data);
+ }
+ if (self->base) {
+ if (self->flags & UPDATEIFCOPY) {
+ ((PyArrayObject *)self->base)->flags |= WRITEABLE;
+ self->flags &= ~UPDATEIFCOPY;
+ }
+ Py_DECREF(self->base);
+ }
+ Py_INCREF(op);
+ self->base = op;
+ self->data = buf;
+ self->flags = CARRAY;
+ if (!writeable)
+ self->flags &= ~WRITEABLE;
+ return 0;
}
static PyObject *
array_itemsize_get(PyArrayObject *self)
{
- return PyInt_FromLong((long) self->descr->elsize);
+ return PyInt_FromLong((long) self->descr->elsize);
}
static PyObject *
array_size_get(PyArrayObject *self)
{
- intp size=PyArray_SIZE(self);
+ intp size=PyArray_SIZE(self);
#if SIZEOF_INTP <= SIZEOF_LONG
return PyInt_FromLong((long) size);
#else
- if (size > MAX_LONG || size < MIN_LONG)
- return PyLong_FromLongLong(size);
- else
- return PyInt_FromLong((long) size);
+ if (size > MAX_LONG || size < MIN_LONG)
+ return PyLong_FromLongLong(size);
+ else
+ return PyInt_FromLong((long) size);
#endif
}
@@ -5945,10 +5945,10 @@
#if SIZEOF_INTP <= SIZEOF_LONG
return PyInt_FromLong((long) nbytes);
#else
- if (nbytes > MAX_LONG || nbytes < MIN_LONG)
- return PyLong_FromLongLong(nbytes);
- else
- return PyInt_FromLong((long) nbytes);
+ if (nbytes > MAX_LONG || nbytes < MIN_LONG)
+ return PyLong_FromLongLong(nbytes);
+ else
+ return PyInt_FromLong((long) nbytes);
#endif
}
@@ -5974,83 +5974,83 @@
if (!(PyArray_DescrConverter(arg, &newtype)) ||
newtype == NULL) {
PyErr_SetString(PyExc_TypeError, "invalid data-type for array");
- return -1;
+ return -1;
}
- if (newtype->type_num == PyArray_OBJECT || \
- self->descr->type_num == PyArray_OBJECT) {
- PyErr_SetString(PyExc_TypeError, \
- "Cannot change descriptor for object"\
- "array.");
- Py_DECREF(newtype);
- return -1;
- }
+ if (newtype->type_num == PyArray_OBJECT || \
+ self->descr->type_num == PyArray_OBJECT) {
+ PyErr_SetString(PyExc_TypeError, \
+ "Cannot change descriptor for object"\
+ "array.");
+ Py_DECREF(newtype);
+ return -1;
+ }
- if ((newtype->elsize != self->descr->elsize) && \
- (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \
- newtype->subarray)) goto fail;
+ if ((newtype->elsize != self->descr->elsize) && \
+ (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \
+ newtype->subarray)) goto fail;
- if (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;
- else index = 0;
+ if (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;
+ else index = 0;
- if (newtype->elsize < self->descr->elsize) {
- /* if it is compatible increase the size of the
- dimension at end (or at the front for FORTRAN)
- */
- if (self->descr->elsize % newtype->elsize != 0)
- goto fail;
- newdim = self->descr->elsize / newtype->elsize;
- self->dimensions[index] *= newdim;
- self->strides[index] = newtype->elsize;
- }
+ if (newtype->elsize < self->descr->elsize) {
+ /* if it is compatible increase the size of the
+ dimension at end (or at the front for FORTRAN)
+ */
+ if (self->descr->elsize % newtype->elsize != 0)
+ goto fail;
+ newdim = self->descr->elsize / newtype->elsize;
+ self->dimensions[index] *= newdim;
+ self->strides[index] = newtype->elsize;
+ }
- else if (newtype->elsize > self->descr->elsize) {
+ else if (newtype->elsize > self->descr->elsize) {
- /* Determine if last (or first if FORTRAN) dimension
- is compatible */
+ /* Determine if last (or first if FORTRAN) dimension
+ is compatible */
- newdim = self->dimensions[index] * self->descr->elsize;
- if ((newdim % newtype->elsize) != 0) goto fail;
+ newdim = self->dimensions[index] * self->descr->elsize;
+ if ((newdim % newtype->elsize) != 0) goto fail;
- self->dimensions[index] = newdim / newtype->elsize;
- self->strides[index] = newtype->elsize;
- }
+ self->dimensions[index] = newdim / newtype->elsize;
+ self->strides[index] = newtype->elsize;
+ }
/* fall through -- adjust type*/
- Py_DECREF(self->descr);
- if (newtype->subarray) {
- /* create new array object from data and update
- dimensions, strides and descr from it */
- PyArrayObject *temp;
+ Py_DECREF(self->descr);
+ if (newtype->subarray) {
+ /* create new array object from data and update
+ dimensions, strides and descr from it */
+ PyArrayObject *temp;
- /* We would decref newtype here --- temp will
- steal a reference to it */
- temp = (PyArrayObject *) \
- PyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,
- self->dimensions, self->strides,
- self->data, self->flags, NULL);
- if (temp == NULL) return -1;
- PyDimMem_FREE(self->dimensions);
- self->dimensions = temp->dimensions;
- self->nd = temp->nd;
- self->strides = temp->strides;
- newtype = temp->descr;
- Py_INCREF(temp->descr);
- /* Fool deallocator not to delete these*/
- temp->nd = 0;
- temp->dimensions = NULL;
- Py_DECREF(temp);
- }
+ /* We would decref newtype here --- temp will
+ steal a reference to it */
+ temp = (PyArrayObject *) \
+ PyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,
+ self->dimensions, self->strides,
+ self->data, self->flags, NULL);
+ if (temp == NULL) return -1;
+ PyDimMem_FREE(self->dimensions);
+ self->dimensions = temp->dimensions;
+ self->nd = temp->nd;
+ self->strides = temp->strides;
+ newtype = temp->descr;
+ Py_INCREF(temp->descr);
+ /* Fool deallocator not to delete these*/
+ temp->nd = 0;
+ temp->dimensions = NULL;
+ Py_DECREF(temp);
+ }
- self->descr = newtype;
- PyArray_UpdateFlags(self, UPDATE_ALL);
+ self->descr = newtype;
+ PyArray_UpdateFlags(self, UPDATE_ALL);
return 0;
fail:
- PyErr_SetString(PyExc_ValueError, msg);
- Py_DECREF(newtype);
- return -1;
+ PyErr_SetString(PyExc_ValueError, msg);
+ Py_DECREF(newtype);
+ return -1;
}
static PyObject *
@@ -6065,192 +6065,192 @@
inter->itemsize = self->descr->elsize;
inter->flags = self->flags;
/* reset unused flags */
- inter->flags &= ~(UPDATEIFCOPY | OWNDATA);
- if (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;
- /* Copy shape and strides over since these can be reset
- when the array is "reshaped".
- */
- if (self->nd > 0) {
- inter->shape = (intp *)_pya_malloc(2*sizeof(intp)*self->nd);
- inter->strides = inter->shape + self->nd;
- memcpy(inter->shape, self->dimensions, sizeof(intp)*self->nd);
- memcpy(inter->strides, self->strides, sizeof(intp)*self->nd);
- }
- else {
- inter->shape = NULL;
- inter->strides = NULL;
- }
+ inter->flags &= ~(UPDATEIFCOPY | OWNDATA);
+ if (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;
+ /* Copy shape and strides over since these can be reset
+ when the array is "reshaped".
+ */
+ if (self->nd > 0) {
+ inter->shape = (intp *)_pya_malloc(2*sizeof(intp)*self->nd);
+ inter->strides = inter->shape + self->nd;
+ memcpy(inter->shape, self->dimensions, sizeof(intp)*self->nd);
+ memcpy(inter->strides, self->strides, sizeof(intp)*self->nd);
+ }
+ else {
+ inter->shape = NULL;
+ inter->strides = NULL;
+ }
inter->data = self->data;
- if (self->descr->names) {
- inter->descr = arraydescr_protocol_descr_get(self->descr);
- if (inter->descr == NULL) PyErr_Clear();
- else inter->flags &= ARR_HAS_DESCR;
- }
- Py_INCREF(self);
+ if (self->descr->names) {
+ inter->descr = arraydescr_protocol_descr_get(self->descr);
+ if (inter->descr == NULL) PyErr_Clear();
+ else inter->flags &= ARR_HAS_DESCR;
+ }
+ Py_INCREF(self);
return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);
}
static PyObject *
array_base_get(PyArrayObject *self)
{
- if (self->base == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- else {
- Py_INCREF(self->base);
- return self->base;
- }
+ if (self->base == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ else {
+ Py_INCREF(self->base);
+ return self->base;
+ }
}
static PyObject *
array_real_get(PyArrayObject *self)
{
- PyArrayObject *ret;
+ PyArrayObject *ret;
- if (PyArray_ISCOMPLEX(self)) {
- ret = (PyArrayObject *)PyArray_New(self->ob_type,
- self->nd,
- self->dimensions,
- self->descr->type_num - \
- PyArray_NUM_FLOATTYPE,
- self->strides,
- self->data,
- 0,
- self->flags, (PyObject *)self);
- if (ret == NULL) return NULL;
- ret->flags &= ~CONTIGUOUS;
- ret->flags &= ~FORTRAN;
- Py_INCREF(self);
- ret->base = (PyObject *)self;
- return (PyObject *)ret;
- }
- else {
- Py_INCREF(self);
- return (PyObject *)self;
- }
+ if (PyArray_ISCOMPLEX(self)) {
+ ret = (PyArrayObject *)PyArray_New(self->ob_type,
+ self->nd,
+ self->dimensions,
+ self->descr->type_num - \
+ PyArray_NUM_FLOATTYPE,
+ self->strides,
+ self->data,
+ 0,
+ self->flags, (PyObject *)self);
+ if (ret == NULL) return NULL;
+ ret->flags &= ~CONTIGUOUS;
+ ret->flags &= ~FORTRAN;
+ Py_INCREF(self);
+ ret->base = (PyObject *)self;
+ return (PyObject *)ret;
+ }
+ else {
+ Py_INCREF(self);
+ return (PyObject *)self;
+ }
}
static int
array_real_set(PyArrayObject *self, PyObject *val)
{
- PyArrayObject *ret;
- PyArrayObject *new;
- int rint;
+ PyArrayObject *ret;
+ PyArrayObject *new;
+ int rint;
- new = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);
- if (new == NULL) return -1;
+ new = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);
+ if (new == NULL) return -1;
- if (PyArray_ISCOMPLEX(self)) {
- ret = (PyArrayObject *)PyArray_New(self->ob_type,
- self->nd,
- self->dimensions,
- self->descr->type_num - \
- PyArray_NUM_FLOATTYPE,
- self->strides,
- self->data,
- 0,
- self->flags,
- (PyObject *)self);
- if (ret == NULL) {Py_DECREF(new); return -1;}
- ret->flags &= ~CONTIGUOUS;
- ret->flags &= ~FORTRAN;
- Py_INCREF(self);
- ret->base = (PyObject *)self;
- }
- else {
- Py_INCREF(self);
- ret = self;
- }
- rint = PyArray_MoveInto(ret, new);
- Py_DECREF(ret);
- Py_DECREF(new);
- return rint;
+ if (PyArray_ISCOMPLEX(self)) {
+ ret = (PyArrayObject *)PyArray_New(self->ob_type,
+ self->nd,
+ self->dimensions,
+ self->descr->type_num - \
+ PyArray_NUM_FLOATTYPE,
+ self->strides,
+ self->data,
+ 0,
+ self->flags,
+ (PyObject *)self);
+ if (ret == NULL) {Py_DECREF(new); return -1;}
+ ret->flags &= ~CONTIGUOUS;
+ ret->flags &= ~FORTRAN;
+ Py_INCREF(self);
+ ret->base = (PyObject *)self;
+ }
+ else {
+ Py_INCREF(self);
+ ret = self;
+ }
+ rint = PyArray_MoveInto(ret, new);
+ Py_DECREF(ret);
+ Py_DECREF(new);
+ return rint;
}
static PyObject *
array_imag_get(PyArrayObject *self)
{
- PyArrayObject *ret;
+ PyArrayObject *ret;
PyArray_Descr *type;
- if (PyArray_ISCOMPLEX(self)) {
- type = PyArray_DescrFromType(self->descr->type_num -
- PyArray_NUM_FLOATTYPE);
- ret = (PyArrayObject *) \
- PyArray_NewFromDescr(self->ob_type,
- type,
- self->nd,
- self->dimensions,
- self->strides,
- self->data + type->elsize,
- self->flags, (PyObject *)self);
- if (ret == NULL) return NULL;
- ret->flags &= ~CONTIGUOUS;
- ret->flags &= ~FORTRAN;
- Py_INCREF(self);
- ret->base = (PyObject *)self;
- return (PyObject *) ret;
- }
- else {
- type = self->descr;
- Py_INCREF(type);
- ret = (PyArrayObject *)PyArray_Zeros(self->nd,
- self->dimensions,
- type,
- PyArray_ISFORTRAN(self));
- ret->flags &= ~WRITEABLE;
- if (PyArray_CheckExact(self))
- return (PyObject *)ret;
- else {
- PyObject *newret;
- newret = PyArray_View(ret, NULL, self->ob_type);
- Py_DECREF(ret);
- return newret;
- }
- }
+ if (PyArray_ISCOMPLEX(self)) {
+ type = PyArray_DescrFromType(self->descr->type_num -
+ PyArray_NUM_FLOATTYPE);
+ ret = (PyArrayObject *) \
+ PyArray_NewFromDescr(self->ob_type,
+ type,
+ self->nd,
+ self->dimensions,
+ self->strides,
+ self->data + type->elsize,
+ self->flags, (PyObject *)self);
+ if (ret == NULL) return NULL;
+ ret->flags &= ~CONTIGUOUS;
+ ret->flags &= ~FORTRAN;
+ Py_INCREF(self);
+ ret->base = (PyObject *)self;
+ return (PyObject *) ret;
+ }
+ else {
+ type = self->descr;
+ Py_INCREF(type);
+ ret = (PyArrayObject *)PyArray_Zeros(self->nd,
+ self->dimensions,
+ type,
+ PyArray_ISFORTRAN(self));
+ ret->flags &= ~WRITEABLE;
+ if (PyArray_CheckExact(self))
+ return (PyObject *)ret;
+ else {
+ PyObject *newret;
+ newret = PyArray_View(ret, NULL, self->ob_type);
+ Py_DECREF(ret);
+ return newret;
+ }
+ }
}
static int
array_imag_set(PyArrayObject *self, PyObject *val)
{
- if (PyArray_ISCOMPLEX(self)) {
- PyArrayObject *ret;
- PyArrayObject *new;
- int rint;
+ if (PyArray_ISCOMPLEX(self)) {
+ PyArrayObject *ret;
+ PyArrayObject *new;
+ int rint;
- new = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);
- if (new == NULL) return -1;
- ret = (PyArrayObject *)PyArray_New(self->ob_type,
- self->nd,
- self->dimensions,
- self->descr->type_num - \
- PyArray_NUM_FLOATTYPE,
- self->strides,
- self->data + \
- (self->descr->elsize >> 1),
- 0,
- self->flags, (PyObject *)self);
- if (ret == NULL) {
- Py_DECREF(new);
- return -1;
- }
- ret->flags &= ~CONTIGUOUS;
- ret->flags &= ~FORTRAN;
- Py_INCREF(self);
- ret->base = (PyObject *)self;
- rint = PyArray_MoveInto(ret, new);
- Py_DECREF(ret);
- Py_DECREF(new);
- return rint;
- }
- else {
- PyErr_SetString(PyExc_TypeError, "does not have imaginary " \
- "part to set");
- return -1;
- }
+ new = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);
+ if (new == NULL) return -1;
+ ret = (PyArrayObject *)PyArray_New(self->ob_type,
+ self->nd,
+ self->dimensions,
+ self->descr->type_num - \
+ PyArray_NUM_FLOATTYPE,
+ self->strides,
+ self->data + \
+ (self->descr->elsize >> 1),
+ 0,
+ self->flags, (PyObject *)self);
+ if (ret == NULL) {
+ Py_DECREF(new);
+ return -1;
+ }
+ ret->flags &= ~CONTIGUOUS;
+ ret->flags &= ~FORTRAN;
+ Py_INCREF(self);
+ ret->base = (PyObject *)self;
+ rint = PyArray_MoveInto(ret, new);
+ Py_DECREF(ret);
+ Py_DECREF(new);
+ return rint;
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "does not have imaginary " \
+ "part to set");
+ return -1;
+ }
}
static PyObject *
@@ -6262,32 +6262,32 @@
static int
array_flat_set(PyArrayObject *self, PyObject *val)
{
- PyObject *arr=NULL;
- int retval = -1;
- PyArrayIterObject *selfit=NULL, *arrit=NULL;
- PyArray_Descr *typecode;
+ PyObject *arr=NULL;
+ int retval = -1;
+ PyArrayIterObject *selfit=NULL, *arrit=NULL;
+ PyArray_Descr *typecode;
int swap;
PyArray_CopySwapFunc *copyswap;
- typecode = self->descr;
- Py_INCREF(typecode);
- arr = PyArray_FromAny(val, typecode,
- 0, 0, FORCECAST | FORTRAN_IF(self), NULL);
- if (arr == NULL) return -1;
- arrit = (PyArrayIterObject *)PyArray_IterNew(arr);
- if (arrit == NULL) goto exit;
- selfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
- if (selfit == NULL) goto exit;
+ typecode = self->descr;
+ Py_INCREF(typecode);
+ arr = PyArray_FromAny(val, typecode,
+ 0, 0, FORCECAST | FORTRAN_IF(self), NULL);
+ if (arr == NULL) return -1;
+ arrit = (PyArrayIterObject *)PyArray_IterNew(arr);
+ if (arrit == NULL) goto exit;
+ selfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
+ if (selfit == NULL) goto exit;
swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);
copyswap = self->descr->f->copyswap;
if (self->descr->hasobject) {
while(selfit->index < selfit->size) {
- PyArray_Item_XDECREF(selfit->dataptr, self->descr);
- PyArray_Item_INCREF(arrit->dataptr, PyArray_DESCR(arr));
+ PyArray_Item_XDECREF(selfit->dataptr, self->descr);
+ PyArray_Item_INCREF(arrit->dataptr, PyArray_DESCR(arr));
memmove(selfit->dataptr, arrit->dataptr,
sizeof(PyObject *));
- copyswap(selfit->dataptr, NULL, swap, self);
+ copyswap(selfit->dataptr, NULL, swap, self);
PyArray_ITER_NEXT(selfit);
PyArray_ITER_NEXT(arrit);
if (arrit->index == arrit->size)
@@ -6297,30 +6297,30 @@
goto exit;
}
- while(selfit->index < selfit->size) {
- memmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);
+ while(selfit->index < selfit->size) {
+ memmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);
copyswap(selfit->dataptr, NULL, swap, self);
- PyArray_ITER_NEXT(selfit);
- PyArray_ITER_NEXT(arrit);
- if (arrit->index == arrit->size)
- PyArray_ITER_RESET(arrit);
- }
- retval = 0;
+ PyArray_ITER_NEXT(selfit);
+ PyArray_ITER_NEXT(arrit);
+ if (arrit->index == arrit->size)
+ PyArray_ITER_RESET(arrit);
+ }
+ retval = 0;
exit:
- Py_XDECREF(selfit);
- Py_XDECREF(arrit);
- Py_XDECREF(arr);
- return retval;
+ Py_XDECREF(selfit);
+ Py_XDECREF(arrit);
+ Py_XDECREF(arr);
+ return retval;
}
static PyObject *
array_transpose_get(PyArrayObject *self)
{
- if (self->nd < 2) {
- Py_INCREF(self);
- return (PyObject *)self;
- }
- return PyArray_Transpose(self, NULL);
+ if (self->nd < 2) {
+ Py_INCREF(self);
+ return (PyObject *)self;
+ }
+ return PyArray_Transpose(self, NULL);
}
/* If this is None, no function call is made
@@ -6335,86 +6335,86 @@
static PyGetSetDef array_getsetlist[] = {
{"ndim",
- (getter)array_ndim_get,
- NULL,
- "number of array dimensions"},
+ (getter)array_ndim_get,
+ NULL,
+ "number of array dimensions"},
{"flags",
- (getter)array_flags_get,
+ (getter)array_flags_get,
NULL,
- "special dictionary of flags"},
+ "special dictionary of flags"},
{"shape",
- (getter)array_shape_get,
- (setter)array_shape_set,
- "tuple of array dimensions"},
+ (getter)array_shape_get,
+ (setter)array_shape_set,
+ "tuple of array dimensions"},
{"strides",
- (getter)array_strides_get,
- (setter)array_strides_set,
- "tuple of bytes steps in each dimension"},
+ (getter)array_strides_get,
+ (setter)array_strides_set,
+ "tuple of bytes steps in each dimension"},
{"data",
- (getter)array_data_get,
- (setter)array_data_set,
- "pointer to start of data"},
+ (getter)array_data_get,
+ (setter)array_data_set,
+ "pointer to start of data"},
{"itemsize",
- (getter)array_itemsize_get,
- NULL,
- "length of one element in bytes"},
+ (getter)array_itemsize_get,
+ NULL,
+ "length of one element in bytes"},
{"size",
(getter)array_size_get,
- NULL,
+ NULL,
"number of elements in the array"},
{"nbytes",
(getter)array_nbytes_get,
NULL,
"number of bytes in the array"},
- {"base",
- (getter)array_base_get,
- NULL,
- "base object"},
- {"dtype",
- (getter)array_descr_get,
- (setter)array_descr_set,
- "get(set) data-type-descriptor for array"},
+ {"base",
+ (getter)array_base_get,
+ NULL,
+ "base object"},
+ {"dtype",
+ (getter)array_descr_get,
+ (setter)array_descr_set,
+ "get(set) data-type-descriptor for array"},
{"real",
- (getter)array_real_get,
- (setter)array_real_set,
- "real part of array"},
+ (getter)array_real_get,
+ (setter)array_real_set,
+ "real part of array"},
{"imag",
- (getter)array_imag_get,
- (setter)array_imag_set,
- "imaginary part of array"},
- {"flat",
- (getter)array_flat_get,
- (setter)array_flat_set,
- "a 1-d view of a contiguous array"},
- {"ctypes",
- (getter)array_ctypes_get,
- NULL,
- "ctypes interface object"},
- {"_as_parameter_",
- (getter)array_as_parameter_get,
- NULL,
- "allow array to be interpreted as a ctypes object by returning the data memory location as an integer"},
- {"T",
- (getter)array_transpose_get,
- NULL,
- "return transpose for self.ndim <= 2 "},
- {"__array_interface__",
- (getter)array_interface_get,
- NULL,
- "Array protocol: Python side"},
+ (getter)array_imag_get,
+ (setter)array_imag_set,
+ "imaginary part of array"},
+ {"flat",
+ (getter)array_flat_get,
+ (setter)array_flat_set,
+ "a 1-d view of a contiguous array"},
+ {"ctypes",
+ (getter)array_ctypes_get,
+ NULL,
+ "ctypes interface object"},
+ {"_as_parameter_",
+ (getter)array_as_parameter_get,
+ NULL,
+ "allow array to be interpreted as a ctypes object by returning the data memory location as an integer"},
+ {"T",
+ (getter)array_transpose_get,
+ NULL,
+ "return transpose for self.ndim <= 2 "},
+ {"__array_interface__",
+ (getter)array_interface_get,
+ NULL,
+ "Array protocol: Python side"},
{"__array_struct__",
(getter)array_struct_get,
NULL,
"Array protocol: C-struct side"},
- {"__array_priority__",
- (getter)array_priority_get,
- NULL,
- "Array priority"},
+ {"__array_priority__",
+ (getter)array_priority_get,
+ NULL,
+ "Array priority"},
{"__array_finalize__",
(getter)array_finalize_get,
NULL,
"None"},
- {NULL, NULL, NULL, NULL}, /* Sentinel */
+ {NULL, NULL, NULL, NULL}, /* Sentinel */
};
/****************** end of attribute get and set routines *******************/
@@ -6433,83 +6433,83 @@
static char Arraytype__doc__[] =
"A array object represents a multidimensional, homogeneous array\n"
- " of fixed-size items. An associated data-type-descriptor object\n"
- " details the data-type in an array (including byteorder and any\n"
- " fields). An array can be constructed using the numpy.array\n"
- " command. Arrays are sequence, mapping and numeric objects.\n"
- " More information is available in the numpy module and by looking\n"
- " at the methods and attributes of an array.\n\n"
- " ndarray.__new__(subtype, shape=, dtype=float, buffer=None, \n"
- " offset=0, strides=None, order=None)\n\n"
- " There are two modes of creating an array using __new__:\n"
- " 1) If buffer is None, then only shape, dtype, and order \n"
- " are used\n"
- " 2) If buffer is an object exporting the buffer interface, then\n"
- " all keywords are interpreted.\n"
- " The dtype parameter can be any object that can be interpreted \n"
- " as a numpy.dtype object.\n\n"
- " No __init__ method is needed because the array is fully \n"
- " initialized after the __new__ method.";
+ " of fixed-size items. An associated data-type-descriptor object\n"
+ " details the data-type in an array (including byteorder and any\n"
+ " fields). An array can be constructed using the numpy.array\n"
+ " command. Arrays are sequence, mapping and numeric objects.\n"
+ " More information is available in the numpy module and by looking\n"
+ " at the methods and attributes of an array.\n\n"
+ " ndarray.__new__(subtype, shape=, dtype=float, buffer=None, \n"
+ " offset=0, strides=None, order=None)\n\n"
+ " There are two modes of creating an array using __new__:\n"
+ " 1) If buffer is None, then only shape, dtype, and order \n"
+ " are used\n"
+ " 2) If buffer is an object exporting the buffer interface, then\n"
+ " all keywords are interpreted.\n"
+ " The dtype parameter can be any object that can be interpreted \n"
+ " as a numpy.dtype object.\n\n"
+ " No __init__ method is needed because the array is fully \n"
+ " initialized after the __new__ method.";
static PyTypeObject PyArray_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "numpy.ndarray", /*tp_name*/
- sizeof(PyArrayObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "numpy.ndarray", /*tp_name*/
+ sizeof(PyArrayObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
/* methods */
- (destructor)array_dealloc, /*tp_dealloc */
- (printfunc)NULL, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- (cmpfunc)0, /*tp_compare*/
- (reprfunc)array_repr, /*tp_repr*/
- &array_as_number, /*tp_as_number*/
- &array_as_sequence, /*tp_as_sequence*/
- &array_as_mapping, /*tp_as_mapping*/
- (hashfunc)0, /*tp_hash*/
- (ternaryfunc)0, /*tp_call*/
- (reprfunc)array_str, /*tp_str*/
+ (destructor)array_dealloc, /*tp_dealloc */
+ (printfunc)NULL, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ (cmpfunc)0, /*tp_compare*/
+ (reprfunc)array_repr, /*tp_repr*/
+ &array_as_number, /*tp_as_number*/
+ &array_as_sequence, /*tp_as_sequence*/
+ &array_as_mapping, /*tp_as_mapping*/
+ (hashfunc)0, /*tp_hash*/
+ (ternaryfunc)0, /*tp_call*/
+ (reprfunc)array_str, /*tp_str*/
- (getattrofunc)0, /*tp_getattro*/
- (setattrofunc)0, /*tp_setattro*/
- &array_as_buffer, /*tp_as_buffer*/
+ (getattrofunc)0, /*tp_getattro*/
+ (setattrofunc)0, /*tp_setattro*/
+ &array_as_buffer, /*tp_as_buffer*/
(Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_CHECKTYPES), /*tp_flags*/
/*Documentation string */
- Arraytype__doc__, /*tp_doc*/
+ Arraytype__doc__, /*tp_doc*/
- (traverseproc)0, /*tp_traverse */
- (inquiry)0, /*tp_clear */
- (richcmpfunc)array_richcompare, /*tp_richcompare */
+ (traverseproc)0, /*tp_traverse */
+ (inquiry)0, /*tp_clear */
+ (richcmpfunc)array_richcompare, /*tp_richcompare */
offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */
/* Iterator support (use standard) */
- (getiterfunc)array_iter, /* tp_iter */
- (iternextfunc)0, /* tp_iternext */
+ (getiterfunc)array_iter, /* tp_iter */
+ (iternextfunc)0, /* tp_iternext */
/* Sub-classing (new-style object) support */
- array_methods, /* tp_methods */
- 0, /* tp_members */
- array_getsetlist, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)0, /* tp_init */
- array_alloc, /* tp_alloc */
- (newfunc)array_new, /* tp_new */
- _pya_free, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
- 0, /* tp_mro */
- 0, /* tp_cache */
- 0, /* tp_subclasses */
- 0 /* tp_weaklist */
+ array_methods, /* tp_methods */
+ 0, /* tp_members */
+ array_getsetlist, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)0, /* tp_init */
+ array_alloc, /* tp_alloc */
+ (newfunc)array_new, /* tp_new */
+ _pya_free, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0 /* tp_weaklist */
};
/* The rest of this code is to build the right kind of array from a python */
@@ -6524,47 +6524,47 @@
if(max < 1) return -1;
if(! PySequence_Check(s) || PyInstance_Check(s) || \
- PySequence_Length(s) < 0) {
+ PySequence_Length(s) < 0) {
PyErr_Clear(); return 0;
}
if (PyArray_Check(s))
- return PyArray_NDIM(s);
+ return PyArray_NDIM(s);
if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))
- return stop_at_string ? 0:1;
- if (stop_at_tuple && PyTuple_Check(s)) return 0;
- if ((e=PyObject_GetAttrString(s, "__array_interface__")) != NULL) {
- d = -1;
- if (PyDict_Check(e)) {
- PyObject *new;
- new = PyDict_GetItemString(e, "shape");
- if (new && PyTuple_Check(new))
- d = PyTuple_GET_SIZE(new);
- }
- Py_DECREF(e);
- if (d>-1) return d;
- }
- else PyErr_Clear();
- if ((e=PyObject_GetAttrString(s, "__array_struct__")) != NULL) {
- d = -1;
- if (PyCObject_Check(e)) {
- PyArrayInterface *inter;
- inter = (PyArrayInterface *)PyCObject_AsVoidPtr(e);
- if (inter->two == 2) {
- d = inter->nd;
- }
- }
- Py_DECREF(e);
- if (d > -1) return d;
- }
- else PyErr_Clear();
-
+ return stop_at_string ? 0:1;
+ if (stop_at_tuple && PyTuple_Check(s)) return 0;
+ if ((e=PyObject_GetAttrString(s, "__array_interface__")) != NULL) {
+ d = -1;
+ if (PyDict_Check(e)) {
+ PyObject *new;
+ new = PyDict_GetItemString(e, "shape");
+ if (new && PyTuple_Check(new))
+ d = PyTuple_GET_SIZE(new);
+ }
+ Py_DECREF(e);
+ if (d>-1) return d;
+ }
+ else PyErr_Clear();
+ if ((e=PyObject_GetAttrString(s, "__array_struct__")) != NULL) {
+ d = -1;
+ if (PyCObject_Check(e)) {
+ PyArrayInterface *inter;
+ inter = (PyArrayInterface *)PyCObject_AsVoidPtr(e);
+ if (inter->two == 2) {
+ d = inter->nd;
+ }
+ }
+ Py_DECREF(e);
+ if (d > -1) return d;
+ }
+ else PyErr_Clear();
+
if (PySequence_Length(s) == 0)
- return 1;
+ return 1;
if ((e=PySequence_GetItem(s,0)) == NULL) return -1;
if(e!=s) {
- d=discover_depth(e, max-1, stop_at_string, stop_at_tuple);
- if(d >= 0) d++;
- }
+ d=discover_depth(e, max-1, stop_at_string, stop_at_tuple);
+ if(d >= 0) d++;
+ }
Py_DECREF(e);
return d;
}
@@ -6572,21 +6572,21 @@
static int
discover_itemsize(PyObject *s, int nd, int *itemsize)
{
- int n, r, i;
- PyObject *e;
+ int n, r, i;
+ PyObject *e;
- n = PyObject_Length(s);
+ n = PyObject_Length(s);
- if ((nd == 0) || PyString_Check(s) || \
- PyUnicode_Check(s) || PyBuffer_Check(s)) {
- if PyUnicode_Check(s)
- *itemsize = MAX(*itemsize, 4*n);
- else
- *itemsize = MAX(*itemsize, n);
- return 0;
- }
- for (i=0; i<n; i++) {
- if ((e=PySequence_GetItem(s,i))==NULL) return -1;
+ if ((nd == 0) || PyString_Check(s) || \
+ PyUnicode_Check(s) || PyBuffer_Check(s)) {
+ if PyUnicode_Check(s)
+ *itemsize = MAX(*itemsize, 4*n);
+ else
+ *itemsize = MAX(*itemsize, n);
+ return 0;
+ }
+ for (i=0; i<n; i++) {
+ if ((e=PySequence_GetItem(s,i))==NULL) return -1;
r=discover_itemsize(e,nd-1,itemsize);
Py_DECREF(e);
if (r == -1) return -1;
@@ -6615,11 +6615,11 @@
Py_DECREF(e);
if (r == -1) return -1;
- if (check_it && n_lower != 0 && n_lower != d[1]) {
- PyErr_SetString(PyExc_ValueError,
- "inconsistent shape in sequence");
- return -1;
- }
+ if (check_it && n_lower != 0 && n_lower != d[1]) {
+ PyErr_SetString(PyExc_ValueError,
+ "inconsistent shape in sequence");
+ return -1;
+ }
if (d[1] > n_lower) n_lower = d[1];
}
d[1] = n_lower;
@@ -6633,38 +6633,38 @@
static PyArray_Descr *
_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)
{
- PyArray_Descr *outtype;
+ PyArray_Descr *outtype;
- if (chktype->type_num > mintype->type_num) outtype = chktype;
- else outtype = mintype;
+ if (chktype->type_num > mintype->type_num) outtype = chktype;
+ else outtype = mintype;
- Py_INCREF(outtype);
- if (PyTypeNum_ISEXTENDED(outtype->type_num) && \
- (PyTypeNum_ISEXTENDED(mintype->type_num) || \
- mintype->type_num==0)) {
- int testsize = outtype->elsize;
- register int chksize, minsize;
- chksize = chktype->elsize;
- minsize = mintype->elsize;
- /* Handle string->unicode case separately
- because string itemsize is twice as large */
- if (outtype->type_num == PyArray_UNICODE &&
- mintype->type_num == PyArray_STRING) {
- testsize = MAX(chksize, 4*minsize);
- }
- else {
- testsize = MAX(chksize, minsize);
- }
- if (testsize != outtype->elsize) {
- PyArray_DESCR_REPLACE(outtype);
- outtype->elsize = testsize;
- Py_XDECREF(outtype->fields);
- outtype->fields = NULL;
- Py_XDECREF(outtype->names);
- outtype->names = NULL;
- }
- }
- return outtype;
+ Py_INCREF(outtype);
+ if (PyTypeNum_ISEXTENDED(outtype->type_num) && \
+ (PyTypeNum_ISEXTENDED(mintype->type_num) || \
+ mintype->type_num==0)) {
+ int testsize = outtype->elsize;
+ register int chksize, minsize;
+ chksize = chktype->elsize;
+ minsize = mintype->elsize;
+ /* Handle string->unicode case separately
+ because string itemsize is twice as large */
+ if (outtype->type_num == PyArray_UNICODE &&
+ mintype->type_num == PyArray_STRING) {
+ testsize = MAX(chksize, 4*minsize);
+ }
+ else {
+ testsize = MAX(chksize, minsize);
+ }
+ if (testsize != outtype->elsize) {
+ PyArray_DESCR_REPLACE(outtype);
+ outtype->elsize = testsize;
+ Py_XDECREF(outtype->fields);
+ outtype->fields = NULL;
+ Py_XDECREF(outtype->names);
+ outtype->names = NULL;
+ }
+ }
+ return outtype;
}
static PyArray_Descr *
@@ -6707,44 +6707,44 @@
{
int l;
PyObject *ip;
- PyArray_Descr *chktype=NULL;
- PyArray_Descr *outtype;
+ PyArray_Descr *chktype=NULL;
+ PyArray_Descr *outtype;
- if (minitype == NULL)
- minitype = PyArray_DescrFromType(PyArray_BOOL);
- else Py_INCREF(minitype);
+ if (minitype == NULL)
+ minitype = PyArray_DescrFromType(PyArray_BOOL);
+ else Py_INCREF(minitype);
if (max < 0) goto deflt;
if (PyArray_Check(op)) {
- chktype = PyArray_DESCR(op);
- Py_INCREF(chktype);
- goto finish;
- }
+ chktype = PyArray_DESCR(op);
+ Py_INCREF(chktype);
+ goto finish;
+ }
- if (PyArray_IsScalar(op, Generic)) {
- chktype = PyArray_DescrFromScalar(op);
- goto finish;
- }
+ if (PyArray_IsScalar(op, Generic)) {
+ chktype = PyArray_DescrFromScalar(op);
+ goto finish;
+ }
chktype = _array_find_python_scalar_type(op);
if (chktype) {
goto finish;
}
- if ((ip=PyObject_GetAttrString(op, "__array_interface__"))!=NULL) {
- if (PyDict_Check(ip)) {
- PyObject *new;
- new = PyDict_GetItemString(ip, "typestr");
- if (new && PyString_Check(new)) {
- chktype =_array_typedescr_fromstr \
- (PyString_AS_STRING(new));
- }
- }
- Py_DECREF(ip);
+ if ((ip=PyObject_GetAttrString(op, "__array_interface__"))!=NULL) {
+ if (PyDict_Check(ip)) {
+ PyObject *new;
+ new = PyDict_GetItemString(ip, "typestr");
+ if (new && PyString_Check(new)) {
+ chktype =_array_typedescr_fromstr \
+ (PyString_AS_STRING(new));
+ }
+ }
+ Py_DECREF(ip);
if (chktype) goto finish;
- }
- else PyErr_Clear();
+ }
+ else PyErr_Clear();
if ((ip=PyObject_GetAttrString(op, "__array_struct__")) != NULL) {
PyArrayInterface *inter;
@@ -6753,91 +6753,91 @@
inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);
if (inter->two == 2) {
snprintf(buf, 40, "|%c%d", inter->typekind,
- inter->itemsize);
- chktype = _array_typedescr_fromstr(buf);
+ inter->itemsize);
+ chktype = _array_typedescr_fromstr(buf);
}
}
Py_DECREF(ip);
if (chktype) goto finish;
}
- else PyErr_Clear();
+ else PyErr_Clear();
if (PyString_Check(op)) {
- chktype = PyArray_DescrNewFromType(PyArray_STRING);
- chktype->elsize = PyString_GET_SIZE(op);
- goto finish;
+ chktype = PyArray_DescrNewFromType(PyArray_STRING);
+ chktype->elsize = PyString_GET_SIZE(op);
+ goto finish;
}
- if (PyUnicode_Check(op)) {
- chktype = PyArray_DescrNewFromType(PyArray_UNICODE);
- chktype->elsize = PyUnicode_GET_DATA_SIZE(op);
+ if (PyUnicode_Check(op)) {
+ chktype = PyArray_DescrNewFromType(PyArray_UNICODE);
+ chktype->elsize = PyUnicode_GET_DATA_SIZE(op);
#ifndef Py_UNICODE_WIDE
- chktype->elsize <<= 1;
+ chktype->elsize <<= 1;
#endif
- goto finish;
- }
+ goto finish;
+ }
- if (PyBuffer_Check(op)) {
- chktype = PyArray_DescrNewFromType(PyArray_VOID);
- chktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);
+ if (PyBuffer_Check(op)) {
+ chktype = PyArray_DescrNewFromType(PyArray_VOID);
+ chktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);
PyErr_Clear();
- goto finish;
- }
+ goto finish;
+ }
if (PyObject_HasAttrString(op, "__array__")) {
ip = PyObject_CallMethod(op, "__array__", NULL);
if(ip && PyArray_Check(ip)) {
- chktype = PyArray_DESCR(ip);
- Py_INCREF(chktype);
+ chktype = PyArray_DESCR(ip);
+ Py_INCREF(chktype);
Py_DECREF(ip);
- goto finish;
- }
+ goto finish;
+ }
Py_XDECREF(ip);
- if (PyErr_Occurred()) PyErr_Clear();
+ if (PyErr_Occurred()) PyErr_Clear();
}
- if (PyInstance_Check(op)) goto deflt;
+ if (PyInstance_Check(op)) goto deflt;
if (PySequence_Check(op)) {
l = PyObject_Length(op);
if (l < 0 && PyErr_Occurred()) {
- PyErr_Clear();
- goto deflt;
- }
+ PyErr_Clear();
+ goto deflt;
+ }
if (l == 0 && minitype->type_num == PyArray_BOOL) {
- Py_DECREF(minitype);
- minitype = PyArray_DescrFromType(PyArray_INTP);
- }
+ Py_DECREF(minitype);
+ minitype = PyArray_DescrFromType(PyArray_INTP);
+ }
while (--l >= 0) {
- PyArray_Descr *newtype;
+ PyArray_Descr *newtype;
ip = PySequence_GetItem(op, l);
if (ip==NULL) {
- PyErr_Clear();
- goto deflt;
- }
- chktype = _array_find_type(ip, minitype, max-1);
- newtype = _array_small_type(chktype, minitype);
- Py_DECREF(minitype);
- minitype = newtype;
- Py_DECREF(chktype);
+ PyErr_Clear();
+ goto deflt;
+ }
+ chktype = _array_find_type(ip, minitype, max-1);
+ newtype = _array_small_type(chktype, minitype);
+ Py_DECREF(minitype);
+ minitype = newtype;
+ Py_DECREF(chktype);
Py_DECREF(ip);
}
- chktype = minitype;
- Py_INCREF(minitype);
- goto finish;
+ chktype = minitype;
+ Py_INCREF(minitype);
+ goto finish;
}
deflt:
- chktype = PyArray_DescrFromType(PyArray_OBJECT);
+ chktype = PyArray_DescrFromType(PyArray_OBJECT);
finish:
- outtype = _array_small_type(chktype, minitype);
- Py_DECREF(chktype);
- Py_DECREF(minitype);
- return outtype;
+ outtype = _array_small_type(chktype, minitype);
+ Py_DECREF(chktype);
+ Py_DECREF(minitype);
+ return outtype;
}
static int
@@ -6848,7 +6848,7 @@
if (!PySequence_Check(v)) {
PyErr_SetString(PyExc_ValueError,
- "assignment from non-sequence");
+ "assignment from non-sequence");
return -1;
}
@@ -6859,7 +6859,7 @@
{
e=PySequence_GetItem(v,l);
if (e == NULL) return -1;
- r = PySequence_SetItem((PyObject*)self,l,e);
+ r = PySequence_SetItem((PyObject*)self,l,e);
Py_DECREF(e);
if(r == -1) return -1;
}
@@ -6872,32 +6872,32 @@
Array_FromPyScalar(PyObject *op, PyArray_Descr *typecode)
{
PyArrayObject *ret;
- int itemsize;
- int type;
+ int itemsize;
+ int type;
- itemsize = typecode->elsize;
- type = typecode->type_num;
+ itemsize = typecode->elsize;
+ type = typecode->type_num;
- if (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {
- itemsize = PyObject_Length(op);
- if (type == PyArray_UNICODE) itemsize *= 4;
+ if (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {
+ itemsize = PyObject_Length(op);
+ if (type == PyArray_UNICODE) itemsize *= 4;
- if (itemsize != typecode->elsize) {
- PyArray_DESCR_REPLACE(typecode);
- typecode->elsize = itemsize;
- }
- }
+ if (itemsize != typecode->elsize) {
+ PyArray_DESCR_REPLACE(typecode);
+ typecode->elsize = itemsize;
+ }
+ }
ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,
- 0, NULL,
- NULL, NULL, 0, NULL);
- if (ret == NULL) return NULL;
- if (ret->nd > 0) {
- PyErr_SetString(PyExc_ValueError,
- "shape-mismatch on array construction");
- Py_DECREF(ret);
- return NULL;
- }
+ 0, NULL,
+ NULL, NULL, 0, NULL);
+ if (ret == NULL) return NULL;
+ if (ret->nd > 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "shape-mismatch on array construction");
+ Py_DECREF(ret);
+ return NULL;
+ }
ret->descr->f->setitem(op, ret->data, ret);
@@ -6921,66 +6921,66 @@
static int
object_depth_and_dimension(PyObject *s, int max, intp *dims)
{
- intp *newdims, *test_dims;
- int nd, test_nd;
- int i, islist;
- intp size;
- PyObject *obj;
+ intp *newdims, *test_dims;
+ int nd, test_nd;
+ int i, islist;
+ intp size;
+ PyObject *obj;
- islist = PyList_Check(s);
- if (!(islist || PyTuple_Check(s)) ||
- ((size = PySequence_Size(s)) == 0))
- return 0;
- if (max < 2) {
- if (max < 1) return 0;
- dims[0] = size;
- return 1;
- }
- newdims = PyDimMem_NEW(2*(max-1));
- test_dims = newdims + (max-1);
- if (islist) obj = PyList_GET_ITEM(s, 0);
- else obj = PyTuple_GET_ITEM(s, 0);
- nd = object_depth_and_dimension(obj, max-1, newdims);
- for (i=1; i<size; i++) {
- if (islist) obj = PyList_GET_ITEM(s, 0);
- else obj = PyTuple_GET_ITEM(s, 0);
- test_nd = object_depth_and_dimension(obj, max-1, test_dims);
- if ((nd != test_nd) ||
- (!PyArray_CompareLists(newdims, test_dims, nd))) {
- nd = 0;
- break;
- }
- }
-
- for (i=1; i<=nd; i++) dims[i] = newdims[i-1];
- dims[0] = size;
- PyDimMem_FREE(newdims);
- return nd+1;
+ islist = PyList_Check(s);
+ if (!(islist || PyTuple_Check(s)) ||
+ ((size = PySequence_Size(s)) == 0))
+ return 0;
+ if (max < 2) {
+ if (max < 1) return 0;
+ dims[0] = size;
+ return 1;
+ }
+ newdims = PyDimMem_NEW(2*(max-1));
+ test_dims = newdims + (max-1);
+ if (islist) obj = PyList_GET_ITEM(s, 0);
+ else obj = PyTuple_GET_ITEM(s, 0);
+ nd = object_depth_and_dimension(obj, max-1, newdims);
+ for (i=1; i<size; i++) {
+ if (islist) obj = PyList_GET_ITEM(s, 0);
+ else obj = PyTuple_GET_ITEM(s, 0);
+ test_nd = object_depth_and_dimension(obj, max-1, test_dims);
+ if ((nd != test_nd) ||
+ (!PyArray_CompareLists(newdims, test_dims, nd))) {
+ nd = 0;
+ break;
+ }
+ }
+
+ for (i=1; i<=nd; i++) dims[i] = newdims[i-1];
+ dims[0] = size;
+ PyDimMem_FREE(newdims);
+ return nd+1;
}
static PyObject *
ObjectArray_FromNestedList(PyObject *s, PyArray_Descr *typecode, int fortran)
{
- int nd;
- intp d[MAX_DIMS];
- PyArrayObject *r;
+ int nd;
+ intp d[MAX_DIMS];
+ PyArrayObject *r;
- /* Get the depth and the number of dimensions */
- nd = object_depth_and_dimension(s, MAX_DIMS, d);
- if (nd < 0) return NULL;
+ /* Get the depth and the number of dimensions */
+ nd = object_depth_and_dimension(s, MAX_DIMS, d);
+ if (nd < 0) return NULL;
- if (nd == 0) return Array_FromPyScalar(s, typecode);
-
+ if (nd == 0) return Array_FromPyScalar(s, typecode);
+
r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,
- nd, d,
- NULL, NULL,
- fortran, NULL);
-
+ nd, d,
+ NULL, NULL,
+ fortran, NULL);
+
if(!r) return NULL;
if(Assign_Array(r,s) == -1) {
- Py_DECREF(r);
- return NULL;
- }
+ Py_DECREF(r);
+ return NULL;
+ }
return (PyObject*)r;
}
@@ -6991,81 +6991,81 @@
/* steals reference to typecode */
static PyObject *
Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,
- int min_depth, int max_depth, int isobject)
+ int min_depth, int max_depth, int isobject)
{
PyArrayObject *r;
int nd;
- intp d[MAX_DIMS];
- int stop_at_string;
- int stop_at_tuple;
- int check_it;
- int type = typecode->type_num;
- int itemsize = typecode->elsize;
+ intp d[MAX_DIMS];
+ int stop_at_string;
+ int stop_at_tuple;
+ int check_it;
+ int type = typecode->type_num;
+ int itemsize = typecode->elsize;
- if (isobject)
- return ObjectArray_FromNestedList(s, typecode, fortran);
+ if (isobject)
+ return ObjectArray_FromNestedList(s, typecode, fortran);
- stop_at_string = ((type == PyArray_OBJECT) || \
- (type == PyArray_STRING && \
- typecode->type == PyArray_STRINGLTR) || \
- (type == PyArray_UNICODE) || \
- (type == PyArray_VOID));
+ stop_at_string = ((type == PyArray_OBJECT) || \
+ (type == PyArray_STRING && \
+ typecode->type == PyArray_STRINGLTR) || \
+ (type == PyArray_UNICODE) || \
+ (type == PyArray_VOID));
- stop_at_tuple = (type == PyArray_VOID && (typecode->names \
- || typecode->subarray));
+ stop_at_tuple = (type == PyArray_VOID && (typecode->names \
+ || typecode->subarray));
if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,
- stop_at_tuple)) > 0)) {
- if (nd==0)
- return Array_FromPyScalar(s, typecode);
+ stop_at_tuple)) > 0)) {
+ if (nd==0)
+ return Array_FromPyScalar(s, typecode);
PyErr_SetString(PyExc_ValueError,
- "invalid input sequence");
- goto fail;
+ "invalid input sequence");
+ goto fail;
}
- if (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {
- nd = max_depth;
- }
+ if (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {
+ nd = max_depth;
+ }
- if ((max_depth && nd > max_depth) || \
- (min_depth && nd < min_depth)) {
+ if ((max_depth && nd > max_depth) || \
+ (min_depth && nd < min_depth)) {
PyErr_SetString(PyExc_ValueError,
- "invalid number of dimensions");
- goto fail;
+ "invalid number of dimensions");
+ goto fail;
}
- check_it = !(stop_at_string || type == PyArray_STRING);
- if(discover_dimensions(s,nd,d, check_it) == -1) goto fail;
+ check_it = !(stop_at_string || type == PyArray_STRING);
+ if(discover_dimensions(s,nd,d, check_it) == -1) goto fail;
- if (typecode->type == PyArray_CHARLTR && nd > 0 && d[nd-1]==1) {
- nd = nd-1;
- }
+ if (typecode->type == PyArray_CHARLTR && nd > 0 && d[nd-1]==1) {
+ nd = nd-1;
+ }
- if (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {
- if (discover_itemsize(s, nd, &itemsize) == -1) goto fail;
- if (type == PyArray_UNICODE) itemsize*=4;
- }
+ if (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {
+ if (discover_itemsize(s, nd, &itemsize) == -1) goto fail;
+ if (type == PyArray_UNICODE) itemsize*=4;
+ }
- if (itemsize != typecode->elsize) {
- PyArray_DESCR_REPLACE(typecode);
- typecode->elsize = itemsize;
- }
+ if (itemsize != typecode->elsize) {
+ PyArray_DESCR_REPLACE(typecode);
+ typecode->elsize = itemsize;
+ }
r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,
- nd, d,
- NULL, NULL,
- fortran, NULL);
+ nd, d,
+ NULL, NULL,
+ fortran, NULL);
if(!r) return NULL;
if(Assign_Array(r,s) == -1) {
- Py_DECREF(r);
- return NULL;
- }
+ Py_DECREF(r);
+ return NULL;
+ }
return (PyObject*)r;
fail:
- Py_DECREF(typecode);
- return NULL;
+ Py_DECREF(typecode);
+ return NULL;
}
@@ -7075,13 +7075,13 @@
static int
PyArray_ValidType(int type)
{
- PyArray_Descr *descr;
- int res=TRUE;
+ PyArray_Descr *descr;
+ int res=TRUE;
- descr = PyArray_DescrFromType(type);
- if (descr==NULL) res = FALSE;
- Py_DECREF(descr);
- return res;
+ descr = PyArray_DescrFromType(type);
+ if (descr==NULL) res = FALSE;
+ Py_DECREF(descr);
+ return res;
}
/* For backward compatibility */
@@ -7093,49 +7093,49 @@
static PyObject *
PyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)
{
- PyObject *out;
- int ret;
- PyArray_Descr *mpd;
+ PyObject *out;
+ int ret;
+ PyArray_Descr *mpd;
- mpd = mp->descr;
+ mpd = mp->descr;
- if (((mpd == at) || ((mpd->type_num == at->type_num) && \
- PyArray_EquivByteorders(mpd->byteorder,\
- at->byteorder) && \
- ((mpd->elsize == at->elsize) || \
- (at->elsize==0)))) && \
- PyArray_ISBEHAVED_RO(mp)) {
- Py_DECREF(at);
- Py_INCREF(mp);
- return (PyObject *)mp;
- }
+ if (((mpd == at) || ((mpd->type_num == at->type_num) && \
+ PyArray_EquivByteorders(mpd->byteorder,\
+ at->byteorder) && \
+ ((mpd->elsize == at->elsize) || \
+ (at->elsize==0)))) && \
+ PyArray_ISBEHAVED_RO(mp)) {
+ Py_DECREF(at);
+ Py_INCREF(mp);
+ return (PyObject *)mp;
+ }
- if (at->elsize == 0) {
- PyArray_DESCR_REPLACE(at);
- if (at == NULL) return NULL;
- if (mpd->type_num == PyArray_STRING && \
- at->type_num == PyArray_UNICODE)
- at->elsize = mpd->elsize << 2;
- if (mpd->type_num == PyArray_UNICODE &&
- at->type_num == PyArray_STRING)
- at->elsize = mpd->elsize >> 2;
- if (at->type_num == PyArray_VOID)
- at->elsize = mpd->elsize;
- }
+ if (at->elsize == 0) {
+ PyArray_DESCR_REPLACE(at);
+ if (at == NULL) return NULL;
+ if (mpd->type_num == PyArray_STRING && \
+ at->type_num == PyArray_UNICODE)
+ at->elsize = mpd->elsize << 2;
+ if (mpd->type_num == PyArray_UNICODE &&
+ at->type_num == PyArray_STRING)
+ at->elsize = mpd->elsize >> 2;
+ if (at->type_num == PyArray_VOID)
+ at->elsize = mpd->elsize;
+ }
- out = PyArray_NewFromDescr(mp->ob_type, at,
- mp->nd,
- mp->dimensions,
- NULL, NULL,
- fortran,
- (PyObject *)mp);
+ out = PyArray_NewFromDescr(mp->ob_type, at,
+ mp->nd,
+ mp->dimensions,
+ NULL, NULL,
+ fortran,
+ (PyObject *)mp);
- if (out == NULL) return NULL;
- ret = PyArray_CastTo((PyArrayObject *)out, mp);
- if (ret != -1) return out;
+ if (out == NULL) return NULL;
+ ret = PyArray_CastTo((PyArrayObject *)out, mp);
+ if (ret != -1) return out;
- Py_DECREF(out);
- return NULL;
+ Py_DECREF(out);
+ return NULL;
}
@@ -7147,29 +7147,29 @@
static PyArray_VectorUnaryFunc *
PyArray_GetCastFunc(PyArray_Descr *descr, int type_num)
{
- PyArray_VectorUnaryFunc *castfunc=NULL;
- if (type_num < PyArray_NTYPES) {
- castfunc = descr->f->cast[type_num];
- }
- if (castfunc == NULL) {
- PyObject *obj = descr->f->castdict;
- if (obj && PyDict_Check(obj)) {
- PyObject *key;
- PyObject *cobj;
- key = PyInt_FromLong(type_num);
- cobj = PyDict_GetItem(obj, key);
- Py_DECREF(key);
- if (PyCObject_Check(cobj)) {
- castfunc = PyCObject_AsVoidPtr(cobj);
- }
- }
- if (castfunc) return castfunc;
- }
- else return castfunc;
+ PyArray_VectorUnaryFunc *castfunc=NULL;
+ if (type_num < PyArray_NTYPES) {
+ castfunc = descr->f->cast[type_num];
+ }
+ if (castfunc == NULL) {
+ PyObject *obj = descr->f->castdict;
+ if (obj && PyDict_Check(obj)) {
+ PyObject *key;
+ PyObject *cobj;
+ key = PyInt_FromLong(type_num);
+ cobj = PyDict_GetItem(obj, key);
+ Py_DECREF(key);
+ if (PyCObject_Check(cobj)) {
+ castfunc = PyCObject_AsVoidPtr(cobj);
+ }
+ }
+ if (castfunc) return castfunc;
+ }
+ else return castfunc;
- PyErr_SetString(PyExc_ValueError,
- "No cast function available.");
- return NULL;
+ PyErr_SetString(PyExc_ValueError,
+ "No cast function available.");
+ return NULL;
}
/* Reference counts:
@@ -7182,135 +7182,135 @@
*/
static void
_strided_buffered_cast(char *dptr, intp dstride, int delsize, int dswap,
- PyArray_CopySwapNFunc *dcopyfunc,
- char *sptr, intp sstride, int selsize, int sswap,
- PyArray_CopySwapNFunc *scopyfunc,
- intp N, char **buffers, int bufsize,
- PyArray_VectorUnaryFunc *castfunc,
- PyArrayObject *dest, PyArrayObject *src)
+ PyArray_CopySwapNFunc *dcopyfunc,
+ char *sptr, intp sstride, int selsize, int sswap,
+ PyArray_CopySwapNFunc *scopyfunc,
+ intp N, char **buffers, int bufsize,
+ PyArray_VectorUnaryFunc *castfunc,
+ PyArrayObject *dest, PyArrayObject *src)
{
- int i;
- if (N <= bufsize) {
- /* 1. copy input to buffer and swap
- 2. cast input to output
- 3. swap output if necessary and copy from output buffer
- */
- scopyfunc(buffers[1], selsize, sptr, sstride, N, sswap, src);
- castfunc(buffers[1], buffers[0], N, src, dest);
- dcopyfunc(dptr, dstride, buffers[0], delsize, N, dswap, dest);
- return;
- }
+ int i;
+ if (N <= bufsize) {
+ /* 1. copy input to buffer and swap
+ 2. cast input to output
+ 3. swap output if necessary and copy from output buffer
+ */
+ scopyfunc(buffers[1], selsize, sptr, sstride, N, sswap, src);
+ castfunc(buffers[1], buffers[0], N, src, dest);
+ dcopyfunc(dptr, dstride, buffers[0], delsize, N, dswap, dest);
+ return;
+ }
- /* otherwise we need to divide up into bufsize pieces */
- i = 0;
- while(N > 0) {
- int newN;
- newN = MIN(N, bufsize);
- _strided_buffered_cast(dptr+i*dstride, dstride, delsize,
- dswap, dcopyfunc,
- sptr+i*sstride, sstride, selsize,
- sswap, scopyfunc,
- newN, buffers, bufsize, castfunc, dest, src);
- i += newN;
- N -= bufsize;
- }
- return;
+ /* otherwise we need to divide up into bufsize pieces */
+ i = 0;
+ while(N > 0) {
+ int newN;
+ newN = MIN(N, bufsize);
+ _strided_buffered_cast(dptr+i*dstride, dstride, delsize,
+ dswap, dcopyfunc,
+ sptr+i*sstride, sstride, selsize,
+ sswap, scopyfunc,
+ newN, buffers, bufsize, castfunc, dest, src);
+ i += newN;
+ N -= bufsize;
+ }
+ return;
}
static int
_broadcast_cast(PyArrayObject *out, PyArrayObject *in,
- PyArray_VectorUnaryFunc *castfunc, int iswap, int oswap)
+ PyArray_VectorUnaryFunc *castfunc, int iswap, int oswap)
{
- int delsize, selsize, maxaxis, i, N;
- PyArrayMultiIterObject *multi;
- intp maxdim, ostrides, istrides;
- char *buffers[2];
- PyArray_CopySwapNFunc *ocopyfunc, *icopyfunc;
- char *obptr;
+ int delsize, selsize, maxaxis, i, N;
+ PyArrayMultiIterObject *multi;
+ intp maxdim, ostrides, istrides;
+ char *buffers[2];
+ PyArray_CopySwapNFunc *ocopyfunc, *icopyfunc;
+ char *obptr;
- NPY_BEGIN_THREADS_DEF
+ NPY_BEGIN_THREADS_DEF
- delsize = PyArray_ITEMSIZE(out);
- selsize = PyArray_ITEMSIZE(in);
- multi = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, out, in);
- if (multi == NULL) return -1;
+ delsize = PyArray_ITEMSIZE(out);
+ selsize = PyArray_ITEMSIZE(in);
+ multi = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, out, in);
+ if (multi == NULL) return -1;
- if (multi->size != PyArray_SIZE(out)) {
- PyErr_SetString(PyExc_ValueError,
- "array dimensions are not "\
- "compatible for copy");
- Py_DECREF(multi);
- return -1;
- }
-
- icopyfunc = in->descr->f->copyswapn;
- ocopyfunc = out->descr->f->copyswapn;
- maxaxis = PyArray_RemoveLargest(multi);
- if (maxaxis < 0) { /* cast 1 0-d array to another */
- N = 1;
- maxdim = 1;
- ostrides = delsize;
- istrides = selsize;
- }
- else {
- maxdim = multi->dimensions[maxaxis];
- N = (int) (MIN(maxdim, PyArray_BUFSIZE));
- ostrides = multi->iters[0]->strides[maxaxis];
- istrides = multi->iters[1]->strides[maxaxis];
+ if (multi->size != PyArray_SIZE(out)) {
+ PyErr_SetString(PyExc_ValueError,
+ "array dimensions are not "\
+ "compatible for copy");
+ Py_DECREF(multi);
+ return -1;
+ }
+
+ icopyfunc = in->descr->f->copyswapn;
+ ocopyfunc = out->descr->f->copyswapn;
+ maxaxis = PyArray_RemoveLargest(multi);
+ if (maxaxis < 0) { /* cast 1 0-d array to another */
+ N = 1;
+ maxdim = 1;
+ ostrides = delsize;
+ istrides = selsize;
+ }
+ else {
+ maxdim = multi->dimensions[maxaxis];
+ N = (int) (MIN(maxdim, PyArray_BUFSIZE));
+ ostrides = multi->iters[0]->strides[maxaxis];
+ istrides = multi->iters[1]->strides[maxaxis];
- }
- buffers[0] = _pya_malloc(N*delsize);
- if (buffers[0] == NULL) {
- PyErr_NoMemory();
- return -1;
- }
- buffers[1] = _pya_malloc(N*selsize);
- if (buffers[1] == NULL) {
- _pya_free(buffers[0]);
- PyErr_NoMemory();
- return -1;
- }
- if (out->descr->hasobject)
- memset(buffers[0], 0, N*delsize);
- if (in->descr->hasobject)
- memset(buffers[1], 0, N*selsize);
+ }
+ buffers[0] = _pya_malloc(N*delsize);
+ if (buffers[0] == NULL) {
+ PyErr_NoMemory();
+ return -1;
+ }
+ buffers[1] = _pya_malloc(N*selsize);
+ if (buffers[1] == NULL) {
+ _pya_free(buffers[0]);
+ PyErr_NoMemory();
+ return -1;
+ }
+ if (out->descr->hasobject)
+ memset(buffers[0], 0, N*delsize);
+ if (in->descr->hasobject)
+ memset(buffers[1], 0, N*selsize);
#if NPY_ALLOW_THREADS
- if (PyArray_ISNUMBER(in) && PyArray_ISNUMBER(out)) {
- NPY_BEGIN_THREADS
- }
+ if (PyArray_ISNUMBER(in) && PyArray_ISNUMBER(out)) {
+ NPY_BEGIN_THREADS
+ }
#endif
- while(multi->index < multi->size) {
- _strided_buffered_cast(multi->iters[0]->dataptr,
- ostrides,
- delsize, oswap, ocopyfunc,
- multi->iters[1]->dataptr,
- istrides,
- selsize, iswap, icopyfunc,
- maxdim, buffers, N,
- castfunc, out, in);
- PyArray_MultiIter_NEXT(multi);
- }
+ while(multi->index < multi->size) {
+ _strided_buffered_cast(multi->iters[0]->dataptr,
+ ostrides,
+ delsize, oswap, ocopyfunc,
+ multi->iters[1]->dataptr,
+ istrides,
+ selsize, iswap, icopyfunc,
+ maxdim, buffers, N,
+ castfunc, out, in);
+ PyArray_MultiIter_NEXT(multi);
+ }
#if NPY_ALLOW_THREADS
- if (PyArray_ISNUMBER(in) && PyArray_ISNUMBER(out)) {
- NPY_END_THREADS
- }
+ if (PyArray_ISNUMBER(in) && PyArray_ISNUMBER(out)) {
+ NPY_END_THREADS
+ }
#endif
- Py_DECREF(multi);
- if (in->descr->hasobject) {
- obptr = buffers[1];
- for (i=0; i<N; i++, obptr+=selsize)
- PyArray_Item_XDECREF(obptr, out->descr);
- }
- if (out->descr->hasobject) {
- obptr = buffers[0];
- for (i=0; i<N; i++, obptr+=delsize)
- PyArray_Item_XDECREF(obptr, out->descr);
- }
- _pya_free(buffers[0]);
- _pya_free(buffers[1]);
- return 0;
+ Py_DECREF(multi);
+ if (in->descr->hasobject) {
+ obptr = buffers[1];
+ for (i=0; i<N; i++, obptr+=selsize)
+ PyArray_Item_XDECREF(obptr, out->descr);
+ }
+ if (out->descr->hasobject) {
+ obptr = buffers[0];
+ for (i=0; i<N; i++, obptr+=delsize)
+ PyArray_Item_XDECREF(obptr, out->descr);
+ }
+ _pya_free(buffers[0]);
+ _pya_free(buffers[1]);
+ return 0;
}
@@ -7328,52 +7328,52 @@
PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)
{
- int simple;
- int same;
- PyArray_VectorUnaryFunc *castfunc=NULL;
- int mpsize = PyArray_SIZE(mp);
- int iswap, oswap;
-
- NPY_BEGIN_THREADS_DEF
+ int simple;
+ int same;
+ PyArray_VectorUnaryFunc *castfunc=NULL;
+ int mpsize = PyArray_SIZE(mp);
+ int iswap, oswap;
+
+ NPY_BEGIN_THREADS_DEF
- if (mpsize == 0) return 0;
- if (!PyArray_ISWRITEABLE(out)) {
- PyErr_SetString(PyExc_ValueError,
- "output array is not writeable");
- return -1;
- }
+ if (mpsize == 0) return 0;
+ if (!PyArray_ISWRITEABLE(out)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output array is not writeable");
+ return -1;
+ }
- castfunc = PyArray_GetCastFunc(mp->descr, out->descr->type_num);
- if (castfunc == NULL) return -1;
+ castfunc = PyArray_GetCastFunc(mp->descr, out->descr->type_num);
+ if (castfunc == NULL) return -1;
- same = PyArray_SAMESHAPE(out, mp);
- simple = same && ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) ||
- (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));
+ same = PyArray_SAMESHAPE(out, mp);
+ simple = same && ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) ||
+ (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));
- if (simple) {
+ if (simple) {
#if NPY_ALLOW_THREADS
- if (PyArray_ISNUMBER(mp) && PyArray_ISNUMBER(out)) {
- NPY_BEGIN_THREADS }
+ if (PyArray_ISNUMBER(mp) && PyArray_ISNUMBER(out)) {
+ NPY_BEGIN_THREADS }
#endif
- castfunc(mp->data, out->data, mpsize, mp, out);
+ castfunc(mp->data, out->data, mpsize, mp, out);
#if NPY_ALLOW_THREADS
- if (PyArray_ISNUMBER(mp) && PyArray_ISNUMBER(out)) {
- NPY_END_THREADS }
+ if (PyArray_ISNUMBER(mp) && PyArray_ISNUMBER(out)) {
+ NPY_END_THREADS }
#endif
- return 0;
- }
+ return 0;
+ }
/* If the input or output is STRING, UNICODE, or VOID */
/* then getitem and setitem are used for the cast */
/* and byteswapping is handled by those methods */
- iswap = PyArray_ISBYTESWAPPED(mp) && !PyArray_ISFLEXIBLE(mp);
- oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out);
-
- return _broadcast_cast(out, mp, castfunc, iswap, oswap);
+ iswap = PyArray_ISBYTESWAPPED(mp) && !PyArray_ISFLEXIBLE(mp);
+ oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out);
+
+ return _broadcast_cast(out, mp, castfunc, iswap, oswap);
}
@@ -7381,95 +7381,95 @@
_bufferedcast(PyArrayObject *out, PyArrayObject *in,
PyArray_VectorUnaryFunc *castfunc)
{
- char *inbuffer, *bptr, *optr;
- char *outbuffer=NULL;
- PyArrayIterObject *it_in=NULL, *it_out=NULL;
- register intp i, index;
- intp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);
- int elsize=in->descr->elsize;
- int nels = PyArray_BUFSIZE;
- int el;
- int inswap, outswap=0;
- int obuf=!PyArray_ISCARRAY(out);
- int oelsize = out->descr->elsize;
+ char *inbuffer, *bptr, *optr;
+ char *outbuffer=NULL;
+ PyArrayIterObject *it_in=NULL, *it_out=NULL;
+ register intp i, index;
+ intp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);
+ int elsize=in->descr->elsize;
+ int nels = PyArray_BUFSIZE;
+ int el;
+ int inswap, outswap=0;
+ int obuf=!PyArray_ISCARRAY(out);
+ int oelsize = out->descr->elsize;
PyArray_CopySwapFunc *in_csn;
PyArray_CopySwapFunc *out_csn;
- int retval = -1;
+ int retval = -1;
in_csn = in->descr->f->copyswap;
out_csn = out->descr->f->copyswap;
- /* If the input or output is STRING, UNICODE, or VOID */
- /* then getitem and setitem are used for the cast */
- /* and byteswapping is handled by those methods */
+ /* If the input or output is STRING, UNICODE, or VOID */
+ /* then getitem and setitem are used for the cast */
+ /* and byteswapping is handled by those methods */
- inswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));
+ inswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));
- inbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);
- if (inbuffer == NULL) return -1;
- if (PyArray_ISOBJECT(in))
- memset(inbuffer, 0, PyArray_BUFSIZE*elsize);
- it_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);
- if (it_in == NULL) goto exit;
+ inbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);
+ if (inbuffer == NULL) return -1;
+ if (PyArray_ISOBJECT(in))
+ memset(inbuffer, 0, PyArray_BUFSIZE*elsize);
+ it_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);
+ if (it_in == NULL) goto exit;
- if (obuf) {
- outswap = !(PyArray_ISFLEXIBLE(out) || \
- PyArray_ISNOTSWAPPED(out));
- outbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);
- if (outbuffer == NULL) goto exit;
- if (PyArray_ISOBJECT(out))
- memset(outbuffer, 0, PyArray_BUFSIZE*oelsize);
+ if (obuf) {
+ outswap = !(PyArray_ISFLEXIBLE(out) || \
+ PyArray_ISNOTSWAPPED(out));
+ outbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);
+ if (outbuffer == NULL) goto exit;
+ if (PyArray_ISOBJECT(out))
+ memset(outbuffer, 0, PyArray_BUFSIZE*oelsize);
- it_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);
- if (it_out == NULL) goto exit;
+ it_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);
+ if (it_out == NULL) goto exit;
- nels = MIN(nels, PyArray_BUFSIZE);
- }
+ nels = MIN(nels, PyArray_BUFSIZE);
+ }
- optr = (obuf) ? outbuffer: out->data;
- bptr = inbuffer;
- el = 0;
- while(ncopies--) {
- index = it_in->size;
- PyArray_ITER_RESET(it_in);
- while(index--) {
+ optr = (obuf) ? outbuffer: out->data;
+ bptr = inbuffer;
+ el = 0;
+ while(ncopies--) {
+ index = it_in->size;
+ PyArray_ITER_RESET(it_in);
+ while(index--) {
in_csn(bptr, it_in->dataptr, inswap, in);
- bptr += elsize;
- PyArray_ITER_NEXT(it_in);
- el += 1;
- if ((el == nels) || (index == 0)) {
- /* buffer filled, do cast */
+ bptr += elsize;
+ PyArray_ITER_NEXT(it_in);
+ el += 1;
+ if ((el == nels) || (index == 0)) {
+ /* buffer filled, do cast */
- castfunc(inbuffer, optr, el, in, out);
+ castfunc(inbuffer, optr, el, in, out);
- if (obuf) {
- /* Copy from outbuffer to array */
- for(i=0; i<el; i++) {
+ if (obuf) {
+ /* Copy from outbuffer to array */
+ for(i=0; i<el; i++) {
out_csn(it_out->dataptr,
optr, outswap,
out);
- optr += oelsize;
- PyArray_ITER_NEXT(it_out);
- }
- optr = outbuffer;
- }
- else {
- optr += out->descr->elsize * nels;
- }
- el = 0;
- bptr = inbuffer;
- }
- }
- }
- retval = 0;
+ optr += oelsize;
+ PyArray_ITER_NEXT(it_out);
+ }
+ optr = outbuffer;
+ }
+ else {
+ optr += out->descr->elsize * nels;
+ }
+ el = 0;
+ bptr = inbuffer;
+ }
+ }
+ }
+ retval = 0;
exit:
- Py_XDECREF(it_in);
- PyDataMem_FREE(inbuffer);
- PyDataMem_FREE(outbuffer);
- if (obuf) {
- Py_XDECREF(it_out);
- }
- return retval;
+ Py_XDECREF(it_in);
+ PyDataMem_FREE(inbuffer);
+ PyDataMem_FREE(outbuffer);
+ if (obuf) {
+ Py_XDECREF(it_out);
+ }
+ return retval;
}
/*OBJECT_API
@@ -7479,40 +7479,40 @@
static int
PyArray_CastAnyTo(PyArrayObject *out, PyArrayObject *mp)
{
- int simple;
- PyArray_VectorUnaryFunc *castfunc=NULL;
- int mpsize = PyArray_SIZE(mp);
+ int simple;
+ PyArray_VectorUnaryFunc *castfunc=NULL;
+ int mpsize = PyArray_SIZE(mp);
- if (mpsize == 0) return 0;
- if (!PyArray_ISWRITEABLE(out)) {
- PyErr_SetString(PyExc_ValueError,
- "output array is not writeable");
- return -1;
- }
+ if (mpsize == 0) return 0;
+ if (!PyArray_ISWRITEABLE(out)) {
+ PyErr_SetString(PyExc_ValueError,
+ "output array is not writeable");
+ return -1;
+ }
- if (!(mpsize == PyArray_SIZE(out))) {
+ if (!(mpsize == PyArray_SIZE(out))) {
PyErr_SetString(PyExc_ValueError,
"arrays must have the same number of"
" elements for the cast.");
return -1;
}
- castfunc = PyArray_GetCastFunc(mp->descr, out->descr->type_num);
- if (castfunc == NULL) return -1;
+ castfunc = PyArray_GetCastFunc(mp->descr, out->descr->type_num);
+ if (castfunc == NULL) return -1;
simple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) ||
(PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));
- if (simple) {
- castfunc(mp->data, out->data, mpsize, mp, out);
- return 0;
- }
+ if (simple) {
+ castfunc(mp->data, out->data, mpsize, mp, out);
+ return 0;
+ }
if (PyArray_SAMESHAPE(out, mp)) {
int iswap, oswap;
iswap = PyArray_ISBYTESWAPPED(mp) && !PyArray_ISFLEXIBLE(mp);
- oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out);
+ oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out);
return _broadcast_cast(out, mp, castfunc, iswap, oswap);
}
@@ -7527,95 +7527,95 @@
PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
{
- PyArrayObject *ret=NULL;
- int type, itemsize;
- int copy = 0;
- int arrflags;
- PyArray_Descr *oldtype;
- char *msg = "cannot copy back to a read-only array";
+ PyArrayObject *ret=NULL;
+ int type, itemsize;
+ int copy = 0;
+ int arrflags;
+ PyArray_Descr *oldtype;
+ char *msg = "cannot copy back to a read-only array";
PyTypeObject *subtype;
- oldtype = PyArray_DESCR(arr);
+ oldtype = PyArray_DESCR(arr);
subtype = arr->ob_type;
- if (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}
- type = newtype->type_num;
- itemsize = newtype->elsize;
+ if (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}
+ type = newtype->type_num;
+ itemsize = newtype->elsize;
- /* Don't copy if sizes are compatible */
- if ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {
- arrflags = arr->flags;
+ /* Don't copy if sizes are compatible */
+ if ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {
+ arrflags = arr->flags;
- copy = (flags & ENSURECOPY) || \
- ((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \
- || ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \
- || (arr->nd > 1 && \
- ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \
- || ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));
+ copy = (flags & ENSURECOPY) || \
+ ((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \
+ || ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \
+ || (arr->nd > 1 && \
+ ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \
+ || ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));
- if (copy) {
+ if (copy) {
if ((flags & UPDATEIFCOPY) && \
(!PyArray_ISWRITEABLE(arr))) {
- Py_DECREF(newtype);
+ Py_DECREF(newtype);
PyErr_SetString(PyExc_ValueError, msg);
return NULL;
}
if ((flags & ENSUREARRAY)) {
subtype = &PyArray_Type;
}
- ret = (PyArrayObject *) \
- PyArray_NewFromDescr(subtype, newtype,
- arr->nd,
- arr->dimensions,
- NULL, NULL,
- flags & FORTRAN,
- (PyObject *)arr);
+ ret = (PyArrayObject *) \
+ PyArray_NewFromDescr(subtype, newtype,
+ arr->nd,
+ arr->dimensions,
+ NULL, NULL,
+ flags & FORTRAN,
+ (PyObject *)arr);
if (ret == NULL) return NULL;
- if (PyArray_CopyInto(ret, arr) == -1)
- {Py_DECREF(ret); return NULL;}
- if (flags & UPDATEIFCOPY) {
- ret->flags |= UPDATEIFCOPY;
- ret->base = (PyObject *)arr;
+ if (PyArray_CopyInto(ret, arr) == -1)
+ {Py_DECREF(ret); return NULL;}
+ if (flags & UPDATEIFCOPY) {
+ ret->flags |= UPDATEIFCOPY;
+ ret->base = (PyObject *)arr;
PyArray_FLAGS(ret->base) &= ~WRITEABLE;
- Py_INCREF(arr);
- }
- }
- /* If no copy then just increase the reference
- count and return the input */
- else {
- Py_DECREF(newtype);
+ Py_INCREF(arr);
+ }
+ }
+ /* If no copy then just increase the reference
+ count and return the input */
+ else {
+ Py_DECREF(newtype);
if ((flags & ENSUREARRAY)) {
- Py_INCREF(arr->descr);
- ret = (PyArrayObject *) \
+ Py_INCREF(arr->descr);
+ ret = (PyArrayObject *) \
PyArray_NewFromDescr(&PyArray_Type,
- arr->descr,
- arr->nd,
- arr->dimensions,
- arr->strides,
- arr->data,
- arr->flags,NULL);
+ arr->descr,
+ arr->nd,
+ arr->dimensions,
+ arr->strides,
+ arr->data,
+ arr->flags,NULL);
if (ret == NULL) return NULL;
ret->base = (PyObject *)arr;
}
else {
ret = arr;
}
- Py_INCREF(arr);
- }
- }
+ Py_INCREF(arr);
+ }
+ }
- /* The desired output type is different than the input
- array type */
- else {
- /* Cast to the desired type if we can do it safely
- Also cast if source is a ndim-0 array to mimic
- behavior with Python scalars */
- if (flags & FORCECAST || PyArray_NDIM(arr)==0 ||
- PyArray_CanCastTo(oldtype, newtype)) {
- if ((flags & UPDATEIFCOPY) && \
+ /* The desired output type is different than the input
+ array type */
+ else {
+ /* Cast to the desired type if we can do it safely
+ Also cast if source is a ndim-0 array to mimic
+ behavior with Python scalars */
+ if (flags & FORCECAST || PyArray_NDIM(arr)==0 ||
+ PyArray_CanCastTo(oldtype, newtype)) {
+ if ((flags & UPDATEIFCOPY) && \
(!PyArray_ISWRITEABLE(arr))) {
- Py_DECREF(newtype);
+ Py_DECREF(newtype);
PyErr_SetString(PyExc_ValueError, msg);
return NULL;
}
@@ -7624,129 +7624,129 @@
}
ret = (PyArrayObject *)\
PyArray_NewFromDescr(subtype,
- newtype,
- arr->nd,
- arr->dimensions,
- NULL, NULL,
- flags & FORTRAN,
- (PyObject *)arr);
+ newtype,
+ arr->nd,
+ arr->dimensions,
+ NULL, NULL,
+ flags & FORTRAN,
+ (PyObject *)arr);
if (ret == NULL) return NULL;
if (PyArray_CastTo(ret, arr) < 0) {
Py_DECREF(ret);
return NULL;
}
- if (flags & UPDATEIFCOPY) {
- ret->flags |= UPDATEIFCOPY;
- ret->base = (PyObject *)arr;
+ if (flags & UPDATEIFCOPY) {
+ ret->flags |= UPDATEIFCOPY;
+ ret->base = (PyObject *)arr;
PyArray_FLAGS(ret->base) &= ~WRITEABLE;
- Py_INCREF(arr);
- }
- }
- else {
- Py_DECREF(newtype);
- PyErr_SetString(PyExc_TypeError,
- "array cannot be safely cast " \
- "to required type");
- ret = NULL;
- }
- }
- return (PyObject *)ret;
+ Py_INCREF(arr);
+ }
+ }
+ else {
+ Py_DECREF(newtype);
+ PyErr_SetString(PyExc_TypeError,
+ "array cannot be safely cast " \
+ "to required type");
+ ret = NULL;
+ }
+ }
+ return (PyObject *)ret;
}
/* new reference */
static PyArray_Descr *
_array_typedescr_fromstr(char *str)
{
- PyArray_Descr *descr;
- int type_num;
- char typechar;
- int size;
- char msg[] = "unsupported typestring";
- int swap;
- char swapchar;
+ PyArray_Descr *descr;
+ int type_num;
+ char typechar;
+ int size;
+ char msg[] = "unsupported typestring";
+ int swap;
+ char swapchar;
- swapchar = str[0];
- str += 1;
+ swapchar = str[0];
+ str += 1;
-#define _MY_FAIL { \
- PyErr_SetString(PyExc_ValueError, msg); \
- return NULL; \
- }
+#define _MY_FAIL { \
+ PyErr_SetString(PyExc_ValueError, msg); \
+ return NULL; \
+ }
- typechar = str[0];
- size = atoi(str + 1);
- switch (typechar) {
- case 'b':
- if (size == sizeof(Bool))
- type_num = PyArray_BOOL;
- else _MY_FAIL
- break;
- case 'u':
- if (size == sizeof(uintp))
- type_num = PyArray_UINTP;
- else if (size == sizeof(char))
- type_num = PyArray_UBYTE;
- else if (size == sizeof(short))
- type_num = PyArray_USHORT;
- else if (size == sizeof(ulong))
- type_num = PyArray_ULONG;
- else if (size == sizeof(int))
- type_num = PyArray_UINT;
- else if (size == sizeof(ulonglong))
- type_num = PyArray_ULONGLONG;
- else _MY_FAIL
- break;
- case 'i':
- if (size == sizeof(intp))
- type_num = PyArray_INTP;
- else if (size == sizeof(char))
- type_num = PyArray_BYTE;
- else if (size == sizeof(short))
- type_num = PyArray_SHORT;
- else if (size == sizeof(long))
- type_num = PyArray_LONG;
- else if (size == sizeof(int))
- type_num = PyArray_INT;
- else if (size == sizeof(longlong))
- type_num = PyArray_LONGLONG;
- else _MY_FAIL
- break;
- case 'f':
- if (size == sizeof(float))
- type_num = PyArray_FLOAT;
- else if (size == sizeof(double))
- type_num = PyArray_DOUBLE;
- else if (size == sizeof(longdouble))
- type_num = PyArray_LONGDOUBLE;
- else _MY_FAIL
- break;
- case 'c':
- if (size == sizeof(float)*2)
- type_num = PyArray_CFLOAT;
- else if (size == sizeof(double)*2)
- type_num = PyArray_CDOUBLE;
- else if (size == sizeof(longdouble)*2)
- type_num = PyArray_CLONGDOUBLE;
- else _MY_FAIL
- break;
- case 'O':
- if (size == sizeof(PyObject *))
- type_num = PyArray_OBJECT;
- else _MY_FAIL
- break;
- case PyArray_STRINGLTR:
- type_num = PyArray_STRING;
- break;
- case PyArray_UNICODELTR:
- type_num = PyArray_UNICODE;
- size <<= 2;
- break;
- case 'V':
- type_num = PyArray_VOID;
- break;
- default:
- _MY_FAIL
- }
+ typechar = str[0];
+ size = atoi(str + 1);
+ switch (typechar) {
+ case 'b':
+ if (size == sizeof(Bool))
+ type_num = PyArray_BOOL;
+ else _MY_FAIL
+ break;
+ case 'u':
+ if (size == sizeof(uintp))
+ type_num = PyArray_UINTP;
+ else if (size == sizeof(char))
+ type_num = PyArray_UBYTE;
+ else if (size == sizeof(short))
+ type_num = PyArray_USHORT;
+ else if (size == sizeof(ulong))
+ type_num = PyArray_ULONG;
+ else if (size == sizeof(int))
+ type_num = PyArray_UINT;
+ else if (size == sizeof(ulonglong))
+ type_num = PyArray_ULONGLONG;
+ else _MY_FAIL
+ break;
+ case 'i':
+ if (size == sizeof(intp))
+ type_num = PyArray_INTP;
+ else if (size == sizeof(char))
+ type_num = PyArray_BYTE;
+ else if (size == sizeof(short))
+ type_num = PyArray_SHORT;
+ else if (size == sizeof(long))
+ type_num = PyArray_LONG;
+ else if (size == sizeof(int))
+ type_num = PyArray_INT;
+ else if (size == sizeof(longlong))
+ type_num = PyArray_LONGLONG;
+ else _MY_FAIL
+ break;
+ case 'f':
+ if (size == sizeof(float))
+ type_num = PyArray_FLOAT;
+ else if (size == sizeof(double))
+ type_num = PyArray_DOUBLE;
+ else if (size == sizeof(longdouble))
+ type_num = PyArray_LONGDOUBLE;
+ else _MY_FAIL
+ break;
+ case 'c':
+ if (size == sizeof(float)*2)
+ type_num = PyArray_CFLOAT;
+ else if (size == sizeof(double)*2)
+ type_num = PyArray_CDOUBLE;
+ else if (size == sizeof(longdouble)*2)
+ type_num = PyArray_CLONGDOUBLE;
+ else _MY_FAIL
+ break;
+ case 'O':
+ if (size == sizeof(PyObject *))
+ type_num = PyArray_OBJECT;
+ else _MY_FAIL
+ break;
+ case PyArray_STRINGLTR:
+ type_num = PyArray_STRING;
+ break;
+ case PyArray_UNICODELTR:
+ type_num = PyArray_UNICODE;
+ size <<= 2;
+ break;
+ case 'V':
+ type_num = PyArray_VOID;
+ break;
+ default:
+ _MY_FAIL
+ }
#undef _MY_FAIL
@@ -7754,13 +7754,13 @@
if (descr == NULL) return NULL;
swap = !PyArray_ISNBO(swapchar);
if (descr->elsize == 0 || swap) {
- /* Need to make a new PyArray_Descr */
- PyArray_DESCR_REPLACE(descr);
- if (descr==NULL) return NULL;
- if (descr->elsize == 0)
- descr->elsize = size;
- if (swap)
- descr->byteorder = swapchar;
+ /* Need to make a new PyArray_Descr */
+ PyArray_DESCR_REPLACE(descr);
+ if (descr==NULL) return NULL;
+ if (descr->elsize == 0)
+ descr->elsize = size;
+ if (swap)
+ descr->byteorder = swapchar;
}
return descr;
}
@@ -7769,54 +7769,54 @@
static PyObject *
PyArray_FromStructInterface(PyObject *input)
{
- PyArray_Descr *thetype=NULL;
- char buf[40];
- PyArrayInterface *inter;
- PyObject *attr, *r;
- char endian = PyArray_NATBYTE;
+ PyArray_Descr *thetype=NULL;
+ char buf[40];
+ PyArrayInterface *inter;
+ PyObject *attr, *r;
+ char endian = PyArray_NATBYTE;
attr = PyObject_GetAttrString(input, "__array_struct__");
if (attr == NULL) {
- PyErr_Clear();
- return Py_NotImplemented;
- }
- if (!PyCObject_Check(attr)) goto fail;
- inter = PyCObject_AsVoidPtr(attr);
- if (inter->two != 2) goto fail;
- if ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {
- endian = PyArray_OPPBYTE;
- inter->flags &= ~NOTSWAPPED;
- }
+ PyErr_Clear();
+ return Py_NotImplemented;
+ }
+ if (!PyCObject_Check(attr)) goto fail;
+ inter = PyCObject_AsVoidPtr(attr);
+ if (inter->two != 2) goto fail;
+ if ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {
+ endian = PyArray_OPPBYTE;
+ inter->flags &= ~NOTSWAPPED;
+ }
- if (inter->flags & ARR_HAS_DESCR) {
- if (PyArray_DescrConverter(inter->descr, &thetype) == PY_FAIL) {
- thetype = NULL;
- PyErr_Clear();
- }
- }
+ if (inter->flags & ARR_HAS_DESCR) {
+ if (PyArray_DescrConverter(inter->descr, &thetype) == PY_FAIL) {
+ thetype = NULL;
+ PyErr_Clear();
+ }
+ }
- if (thetype == NULL) {
- snprintf(buf, 40, "%c%c%d", endian, inter->typekind, inter->itemsize);
- if (!(thetype=_array_typedescr_fromstr(buf))) {
- Py_DECREF(attr);
- return NULL;
- }
- }
+ if (thetype == NULL) {
+ snprintf(buf, 40, "%c%c%d", endian, inter->typekind, inter->itemsize);
+ if (!(thetype=_array_typedescr_fromstr(buf))) {
+ Py_DECREF(attr);
+ return NULL;
+ }
+ }
r = PyArray_NewFromDescr(&PyArray_Type, thetype,
- inter->nd, inter->shape,
- inter->strides, inter->data,
- inter->flags, NULL);
- Py_INCREF(input);
- PyArray_BASE(r) = input;
+ inter->nd, inter->shape,
+ inter->strides, inter->data,
+ inter->flags, NULL);
+ Py_INCREF(input);
+ PyArray_BASE(r) = input;
Py_DECREF(attr);
PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL);
return r;
fail:
- PyErr_SetString(PyExc_ValueError, "invalid __array_struct__");
- Py_DECREF(attr);
- return NULL;
+ PyErr_SetString(PyExc_ValueError, "invalid __array_struct__");
+ Py_DECREF(attr);
+ return NULL;
}
#define PyIntOrLong_Check(obj) (PyInt_Check(obj) || PyLong_Check(obj))
@@ -7825,151 +7825,151 @@
static PyObject *
PyArray_FromInterface(PyObject *input)
{
- PyObject *attr=NULL, *item=NULL;
+ PyObject *attr=NULL, *item=NULL;
PyObject *tstr=NULL, *shape=NULL;
- PyObject *inter=NULL;
+ PyObject *inter=NULL;
PyObject *base=NULL;
PyArrayObject *ret;
- PyArray_Descr *type=NULL;
- char *data;
- Py_ssize_t buffer_len;
- int res, i, n;
- intp dims[MAX_DIMS], strides[MAX_DIMS];
- int dataflags = BEHAVED;
+ PyArray_Descr *type=NULL;
+ char *data;
+ Py_ssize_t buffer_len;
+ int res, i, n;
+ intp dims[MAX_DIMS], strides[MAX_DIMS];
+ int dataflags = BEHAVED;
- /* Get the memory from __array_data__ and __array_offset__ */
- /* Get the shape */
- /* Get the typestring -- ignore array_descr */
- /* Get the strides */
+ /* Get the memory from __array_data__ and __array_offset__ */
+ /* Get the shape */
+ /* Get the typestring -- ignore array_descr */
+ /* Get the strides */
- inter = PyObject_GetAttrString(input, "__array_interface__");
- if (inter == NULL) {PyErr_Clear(); return Py_NotImplemented;}
- if (!PyDict_Check(inter)) {Py_DECREF(inter); return Py_NotImplemented;}
+ inter = PyObject_GetAttrString(input, "__array_interface__");
+ if (inter == NULL) {PyErr_Clear(); return Py_NotImplemented;}
+ if (!PyDict_Check(inter)) {Py_DECREF(inter); return Py_NotImplemented;}
- shape = PyDict_GetItemString(inter, "shape");
+ shape = PyDict_GetItemString(inter, "shape");
if (shape == NULL) {Py_DECREF(inter); return Py_NotImplemented;}
tstr = PyDict_GetItemString(inter, "typestr");
if (tstr == NULL) {Py_DECREF(inter); return Py_NotImplemented;}
-
- attr = PyDict_GetItemString(inter, "data");
+
+ attr = PyDict_GetItemString(inter, "data");
base = input;
- if ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {
- if (attr && (attr != Py_None)) item=attr;
- else item=input;
- res = PyObject_AsWriteBuffer(item, (void **)&data,
- &buffer_len);
- if (res < 0) {
- PyErr_Clear();
- res = PyObject_AsReadBuffer(item, (const void **)&data,
- &buffer_len);
- if (res < 0) goto fail;
- dataflags &= ~WRITEABLE;
- }
- attr = PyDict_GetItemString(inter, "offset");
- if (attr) {
- longlong num = PyLong_AsLongLong(attr);
- if (error_converting(num)) {
- PyErr_SetString(PyExc_TypeError,
- "offset "\
- "must be an integer");
- goto fail;
- }
- data += num;
- }
+ if ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {
+ if (attr && (attr != Py_None)) item=attr;
+ else item=input;
+ res = PyObject_AsWriteBuffer(item, (void **)&data,
+ &buffer_len);
+ if (res < 0) {
+ PyErr_Clear();
+ res = PyObject_AsReadBuffer(item, (const void **)&data,
+ &buffer_len);
+ if (res < 0) goto fail;
+ dataflags &= ~WRITEABLE;
+ }
+ attr = PyDict_GetItemString(inter, "offset");
+ if (attr) {
+ longlong num = PyLong_AsLongLong(attr);
+ if (error_converting(num)) {
+ PyErr_SetString(PyExc_TypeError,
+ "offset "\
+ "must be an integer");
+ goto fail;
+ }
+ data += num;
+ }
base = item;
- }
- else {
- PyObject *dataptr;
- if (PyTuple_GET_SIZE(attr) != 2) {
- PyErr_SetString(PyExc_TypeError,
- "data must return " \
- "a 2-tuple with (data pointer "\
- "integer, read-only flag)");
- goto fail;
- }
- dataptr = PyTuple_GET_ITEM(attr, 0);
- if (PyString_Check(dataptr)) {
- res = sscanf(PyString_AsString(dataptr),
- "%p", (void **)&data);
- if (res < 1) {
- PyErr_SetString(PyExc_TypeError,
- "data string cannot be " \
- "converted");
- goto fail;
- }
- }
- else if (PyIntOrLong_Check(dataptr)) {
- data = PyLong_AsVoidPtr(dataptr);
- }
- else {
- PyErr_SetString(PyExc_TypeError, "first element " \
- "of data tuple must be integer" \
- " or string.");
- goto fail;
- }
- if (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {
- dataflags &= ~WRITEABLE;
- }
- }
- attr = tstr;
- if (!PyString_Check(attr)) {
- PyErr_SetString(PyExc_TypeError, "typestr must be a string");
- goto fail;
- }
- type = _array_typedescr_fromstr(PyString_AS_STRING(attr));
- if (type==NULL) goto fail;
- attr = shape;
- if (!PyTuple_Check(attr)) {
- PyErr_SetString(PyExc_TypeError, "shape must be a tuple");
- Py_DECREF(type);
- goto fail;
- }
- n = PyTuple_GET_SIZE(attr);
- for (i=0; i<n; i++) {
- item = PyTuple_GET_ITEM(attr, i);
- dims[i] = PyArray_PyIntAsIntp(item);
- if (error_converting(dims[i])) break;
- }
+ }
+ else {
+ PyObject *dataptr;
+ if (PyTuple_GET_SIZE(attr) != 2) {
+ PyErr_SetString(PyExc_TypeError,
+ "data must return " \
+ "a 2-tuple with (data pointer "\
+ "integer, read-only flag)");
+ goto fail;
+ }
+ dataptr = PyTuple_GET_ITEM(attr, 0);
+ if (PyString_Check(dataptr)) {
+ res = sscanf(PyString_AsString(dataptr),
+ "%p", (void **)&data);
+ if (res < 1) {
+ PyErr_SetString(PyExc_TypeError,
+ "data string cannot be " \
+ "converted");
+ goto fail;
+ }
+ }
+ else if (PyIntOrLong_Check(dataptr)) {
+ data = PyLong_AsVoidPtr(dataptr);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "first element " \
+ "of data tuple must be integer" \
+ " or string.");
+ goto fail;
+ }
+ if (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {
+ dataflags &= ~WRITEABLE;
+ }
+ }
+ attr = tstr;
+ if (!PyString_Check(attr)) {
+ PyErr_SetString(PyExc_TypeError, "typestr must be a string");
+ goto fail;
+ }
+ type = _array_typedescr_fromstr(PyString_AS_STRING(attr));
+ if (type==NULL) goto fail;
+ attr = shape;
+ if (!PyTuple_Check(attr)) {
+ PyErr_SetString(PyExc_TypeError, "shape must be a tuple");
+ Py_DECREF(type);
+ goto fail;
+ }
+ n = PyTuple_GET_SIZE(attr);
+ for (i=0; i<n; i++) {
+ item = PyTuple_GET_ITEM(attr, i);
+ dims[i] = PyArray_PyIntAsIntp(item);
+ if (error_converting(dims[i])) break;
+ }
- ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, type,
- n, dims,
- NULL, data,
- dataflags, NULL);
- if (ret == NULL) return NULL;
- Py_INCREF(base);
- ret->base = base;
+ ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, type,
+ n, dims,
+ NULL, data,
+ dataflags, NULL);
+ if (ret == NULL) return NULL;
+ Py_INCREF(base);
+ ret->base = base;
- attr = PyDict_GetItemString(inter, "strides");
- if (attr != NULL && attr != Py_None) {
- if (!PyTuple_Check(attr)) {
- PyErr_SetString(PyExc_TypeError,
- "strides must be a tuple");
- Py_DECREF(ret);
- return NULL;
- }
- if (n != PyTuple_GET_SIZE(attr)) {
- PyErr_SetString(PyExc_ValueError,
- "mismatch in length of "\
- "strides and shape");
- Py_DECREF(ret);
- return NULL;
- }
- for (i=0; i<n; i++) {
- item = PyTuple_GET_ITEM(attr, i);
- strides[i] = PyArray_PyIntAsIntp(item);
- if (error_converting(strides[i])) break;
- }
- if (PyErr_Occurred()) PyErr_Clear();
- memcpy(ret->strides, strides, n*sizeof(intp));
- }
- else PyErr_Clear();
- PyArray_UpdateFlags(ret, UPDATE_ALL);
- Py_DECREF(inter);
- return (PyObject *)ret;
+ attr = PyDict_GetItemString(inter, "strides");
+ if (attr != NULL && attr != Py_None) {
+ if (!PyTuple_Check(attr)) {
+ PyErr_SetString(PyExc_TypeError,
+ "strides must be a tuple");
+ Py_DECREF(ret);
+ return NULL;
+ }
+ if (n != PyTuple_GET_SIZE(attr)) {
+ PyErr_SetString(PyExc_ValueError,
+ "mismatch in length of "\
+ "strides and shape");
+ Py_DECREF(ret);
+ return NULL;
+ }
+ for (i=0; i<n; i++) {
+ item = PyTuple_GET_ITEM(attr, i);
+ strides[i] = PyArray_PyIntAsIntp(item);
+ if (error_converting(strides[i])) break;
+ }
+ if (PyErr_Occurred()) PyErr_Clear();
+ memcpy(ret->strides, strides, n*sizeof(intp));
+ }
+ else PyErr_Clear();
+ PyArray_UpdateFlags(ret, UPDATE_ALL);
+ Py_DECREF(inter);
+ return (PyObject *)ret;
fail:
- Py_XDECREF(inter);
- return NULL;
+ Py_XDECREF(inter);
+ return NULL;
}
/*OBJECT_API*/
@@ -7983,27 +7983,27 @@
if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}
if (context == NULL) {
if (typecode == NULL) new = PyObject_CallFunction(array_meth,
- NULL);
+ NULL);
else new = PyObject_CallFunction(array_meth, "O", typecode);
}
else {
if (typecode == NULL) {
new = PyObject_CallFunction(array_meth, "OO", Py_None,
- context);
+ context);
if (new == NULL && \
- PyErr_ExceptionMatches(PyExc_TypeError)) {
+ PyErr_ExceptionMatches(PyExc_TypeError)) {
PyErr_Clear();
new = PyObject_CallFunction(array_meth, "");
}
}
else {
new = PyObject_CallFunction(array_meth, "OO",
- typecode, context);
+ typecode, context);
if (new == NULL && \
- PyErr_ExceptionMatches(PyExc_TypeError)) {
+ PyErr_ExceptionMatches(PyExc_TypeError)) {
PyErr_Clear();
new = PyObject_CallFunction(array_meth, "O",
- typecode);
+ typecode);
}
}
}
@@ -8034,16 +8034,16 @@
PyObject *r=NULL;
int seq = FALSE;
- /* Is input object already an array? */
- /* This is where the flags are used */
+ /* Is input object already an array? */
+ /* This is where the flags are used */
if (PyArray_Check(op))
- r = PyArray_FromArray((PyArrayObject *)op, newtype, flags);
- else if (PyArray_IsScalar(op, Generic)) {
- if (flags & UPDATEIFCOPY) goto err;
- r = PyArray_FromScalar(op, newtype);
- } else if (newtype == NULL &&
+ r = PyArray_FromArray((PyArrayObject *)op, newtype, flags);
+ else if (PyArray_IsScalar(op, Generic)) {
+ if (flags & UPDATEIFCOPY) goto err;
+ r = PyArray_FromScalar(op, newtype);
+ } else if (newtype == NULL &&
(newtype = _array_find_python_scalar_type(op))) {
- if (flags & UPDATEIFCOPY) goto err;
+ if (flags & UPDATEIFCOPY) goto err;
r = Array_FromPyScalar(op, newtype);
}
else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \
@@ -8054,55 +8054,55 @@
if (r == NULL) {Py_XDECREF(newtype); return NULL;}
if (newtype != NULL || flags != 0) {
new = PyArray_FromArray((PyArrayObject *)r, newtype,
- flags);
+ flags);
Py_DECREF(r);
r = new;
}
}
- else {
- int isobject;
- if (flags & UPDATEIFCOPY) goto err;
- isobject = 0;
- if (newtype == NULL) {
- newtype = _array_find_type(op, NULL, MAX_DIMS);
- }
- else if (newtype->type_num == PyArray_OBJECT) {
- isobject = 1;
- }
- if (PySequence_Check(op)) {
- PyObject *thiserr;
- /* necessary but not sufficient */
+ else {
+ int isobject;
+ if (flags & UPDATEIFCOPY) goto err;
+ isobject = 0;
+ if (newtype == NULL) {
+ newtype = _array_find_type(op, NULL, MAX_DIMS);
+ }
+ else if (newtype->type_num == PyArray_OBJECT) {
+ isobject = 1;
+ }
+ if (PySequence_Check(op)) {
+ PyObject *thiserr;
+ /* necessary but not sufficient */
- Py_INCREF(newtype);
- r = Array_FromSequence(op, newtype, flags & FORTRAN,
- min_depth, max_depth, isobject);
- if (r == NULL && \
- ((thiserr = PyErr_Occurred()) && \
- !PyErr_GivenExceptionMatches(thiserr,
- PyExc_MemoryError))) {
- /* It wasn't really a sequence after all.
- * Try interpreting it as a scalar */
- PyErr_Clear();
- }
+ Py_INCREF(newtype);
+ r = Array_FromSequence(op, newtype, flags & FORTRAN,
+ min_depth, max_depth, isobject);
+ if (r == NULL && \
+ ((thiserr = PyErr_Occurred()) && \
+ !PyErr_GivenExceptionMatches(thiserr,
+ PyExc_MemoryError))) {
+ /* It wasn't really a sequence after all.
+ * Try interpreting it as a scalar */
+ PyErr_Clear();
+ }
else {
- seq = TRUE;
- Py_DECREF(newtype);
- }
+ seq = TRUE;
+ Py_DECREF(newtype);
+ }
}
if (!seq)
- r = Array_FromPyScalar(op, newtype);
- }
+ r = Array_FromPyScalar(op, newtype);
+ }
/* If we didn't succeed return NULL */
if (r == NULL) return NULL;
- /* Be sure we succeed here */
+ /* Be sure we succeed here */
if(!PyArray_Check(r)) {
PyErr_SetString(PyExc_RuntimeError,
- "internal error: PyArray_FromAny "\
- "not producing an array");
- Py_DECREF(r);
+ "internal error: PyArray_FromAny "\
+ "not producing an array");
+ Py_DECREF(r);
return NULL;
}
@@ -8121,10 +8121,10 @@
return r;
err:
- Py_XDECREF(newtype);
- PyErr_SetString(PyExc_TypeError,
- "UPDATEIFCOPY used for non-array input.");
- return NULL;
+ Py_XDECREF(newtype);
+ PyErr_SetString(PyExc_TypeError,
+ "UPDATEIFCOPY used for non-array input.");
+ return NULL;
}
/* new reference -- accepts NULL for mintype*/
@@ -8132,7 +8132,7 @@
static PyArray_Descr *
PyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)
{
- return _array_find_type(op, mintype, MAX_DIMS);
+ return _array_find_type(op, mintype, MAX_DIMS);
}
/*OBJECT_API
@@ -8142,17 +8142,17 @@
static int
PyArray_ObjectType(PyObject *op, int minimum_type)
{
- PyArray_Descr *intype;
- PyArray_Descr *outtype;
- int ret;
+ PyArray_Descr *intype;
+ PyArray_Descr *outtype;
+ int ret;
- intype = PyArray_DescrFromType(minimum_type);
- if (intype == NULL) PyErr_Clear();
- outtype = _array_find_type(op, intype, MAX_DIMS);
- ret = outtype->type_num;
- Py_DECREF(outtype);
- Py_DECREF(intype);
- return ret;
+ intype = PyArray_DescrFromType(minimum_type);
+ if (intype == NULL) PyErr_Clear();
+ outtype = _array_find_type(op, intype, MAX_DIMS);
+ ret = outtype->type_num;
+ Py_DECREF(outtype);
+ Py_DECREF(intype);
+ return ret;
}
@@ -8203,30 +8203,30 @@
PyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,
int max_depth, int requires, PyObject *context)
{
- PyObject *obj;
- if (requires & NOTSWAPPED) {
- if (!descr && PyArray_Check(op) && \
- !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {
- descr = PyArray_DescrNew(PyArray_DESCR(op));
- }
- else if (descr && !PyArray_ISNBO(descr->byteorder)) {
- PyArray_DESCR_REPLACE(descr);
+ PyObject *obj;
+ if (requires & NOTSWAPPED) {
+ if (!descr && PyArray_Check(op) && \
+ !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {
+ descr = PyArray_DescrNew(PyArray_DESCR(op));
}
+ else if (descr && !PyArray_ISNBO(descr->byteorder)) {
+ PyArray_DESCR_REPLACE(descr);
+ }
if (descr) {
descr->byteorder = PyArray_NATIVE;
}
- }
+ }
- obj = PyArray_FromAny(op, descr, min_depth, max_depth,
- requires, context);
- if ((requires & ELEMENTSTRIDES) &&
- (obj && !PyArray_ElementStrides(obj))) {
- PyObject *new;
- new = PyArray_NewCopy((PyArrayObject *)obj, PyArray_ANYORDER);
- Py_DECREF(obj);
- obj = new;
- }
- return obj;
+ obj = PyArray_FromAny(op, descr, min_depth, max_depth,
+ requires, context);
+ if ((requires & ELEMENTSTRIDES) &&
+ (obj && !PyArray_ElementStrides(obj))) {
+ PyObject *new;
+ new = PyArray_NewCopy((PyArrayObject *)obj, PyArray_ANYORDER);
+ Py_DECREF(obj);
+ obj = new;
+ }
+ return obj;
}
/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,
@@ -8247,12 +8247,12 @@
if (op == NULL) return NULL;
if (PyArray_CheckExact(op)) return op;
-
- if (PyArray_Check(op)) {
- new = PyArray_View((PyArrayObject *)op, NULL, &PyArray_Type);
- Py_DECREF(op);
- return new;
- }
+
+ if (PyArray_Check(op)) {
+ new = PyArray_View((PyArrayObject *)op, NULL, &PyArray_Type);
+ Py_DECREF(op);
+ return new;
+ }
if (PyArray_IsScalar(op, Generic)) {
new = PyArray_FromScalar(op, NULL);
Py_DECREF(op);
@@ -8267,8 +8267,8 @@
static PyObject *
PyArray_EnsureAnyArray(PyObject *op)
{
- if (op && PyArray_Check(op)) return op;
- return PyArray_EnsureArray(op);
+ if (op && PyArray_Check(op)) return op;
+ return PyArray_EnsureArray(op);
}
/*OBJECT_API
@@ -8277,101 +8277,101 @@
static int
PyArray_CanCastSafely(int fromtype, int totype)
{
- PyArray_Descr *from, *to;
- register int felsize, telsize;
+ PyArray_Descr *from, *to;
+ register int felsize, telsize;
if (fromtype == totype) return 1;
if (fromtype == PyArray_BOOL) return 1;
- if (totype == PyArray_BOOL) return 0;
+ if (totype == PyArray_BOOL) return 0;
if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;
- if (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;
+ if (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;
- from = PyArray_DescrFromType(fromtype);
- /* cancastto is a PyArray_NOTYPE terminated C-int-array of types that
- the data-type can be cast to safely.
- */
- if (from->f->cancastto) {
- int *curtype;
- curtype = from->f->cancastto;
- while (*curtype != PyArray_NOTYPE) {
- if (*curtype++ == totype) return 1;
- }
- }
- if (PyTypeNum_ISUSERDEF(totype)) return 0;
+ from = PyArray_DescrFromType(fromtype);
+ /* cancastto is a PyArray_NOTYPE terminated C-int-array of types that
+ the data-type can be cast to safely.
+ */
+ if (from->f->cancastto) {
+ int *curtype;
+ curtype = from->f->cancastto;
+ while (*curtype != PyArray_NOTYPE) {
+ if (*curtype++ == totype) return 1;
+ }
+ }
+ if (PyTypeNum_ISUSERDEF(totype)) return 0;
- to = PyArray_DescrFromType(totype);
- telsize = to->elsize;
- felsize = from->elsize;
- Py_DECREF(from);
- Py_DECREF(to);
+ to = PyArray_DescrFromType(totype);
+ telsize = to->elsize;
+ felsize = from->elsize;
+ Py_DECREF(from);
+ Py_DECREF(to);
switch(fromtype) {
case PyArray_BYTE:
- case PyArray_SHORT:
+ case PyArray_SHORT:
case PyArray_INT:
case PyArray_LONG:
- case PyArray_LONGLONG:
- if (PyTypeNum_ISINTEGER(totype)) {
- if (PyTypeNum_ISUNSIGNED(totype)) {
- return 0;
- }
- else {
- return (telsize >= felsize);
- }
- }
- else if (PyTypeNum_ISFLOAT(totype)) {
+ case PyArray_LONGLONG:
+ if (PyTypeNum_ISINTEGER(totype)) {
+ if (PyTypeNum_ISUNSIGNED(totype)) {
+ return 0;
+ }
+ else {
+ return (telsize >= felsize);
+ }
+ }
+ else if (PyTypeNum_ISFLOAT(totype)) {
if (felsize < 8)
return (telsize > felsize);
else
return (telsize >= felsize);
- }
- else if (PyTypeNum_ISCOMPLEX(totype)) {
+ }
+ else if (PyTypeNum_ISCOMPLEX(totype)) {
if (felsize < 8)
return ((telsize >> 1) > felsize);
else
return ((telsize >> 1) >= felsize);
- }
- else return totype > fromtype;
+ }
+ else return totype > fromtype;
case PyArray_UBYTE:
case PyArray_USHORT:
case PyArray_UINT:
- case PyArray_ULONG:
- case PyArray_ULONGLONG:
- if (PyTypeNum_ISINTEGER(totype)) {
- if (PyTypeNum_ISSIGNED(totype)) {
- return (telsize > felsize);
- }
- else {
- return (telsize >= felsize);
- }
- }
- else if (PyTypeNum_ISFLOAT(totype)) {
+ case PyArray_ULONG:
+ case PyArray_ULONGLONG:
+ if (PyTypeNum_ISINTEGER(totype)) {
+ if (PyTypeNum_ISSIGNED(totype)) {
+ return (telsize > felsize);
+ }
+ else {
+ return (telsize >= felsize);
+ }
+ }
+ else if (PyTypeNum_ISFLOAT(totype)) {
if (felsize < 8)
return (telsize > felsize);
else
return (telsize >= felsize);
- }
- else if (PyTypeNum_ISCOMPLEX(totype)) {
+ }
+ else if (PyTypeNum_ISCOMPLEX(totype)) {
if (felsize < 8)
return ((telsize >> 1) > felsize);
else
return ((telsize >> 1) >= felsize);
- }
- else return totype > fromtype;
+ }
+ else return totype > fromtype;
case PyArray_FLOAT:
case PyArray_DOUBLE:
- case PyArray_LONGDOUBLE:
- if (PyTypeNum_ISCOMPLEX(totype))
- return ((telsize >> 1) >= felsize);
- else
- return (totype > fromtype);
+ case PyArray_LONGDOUBLE:
+ if (PyTypeNum_ISCOMPLEX(totype))
+ return ((telsize >> 1) >= felsize);
+ else
+ return (totype > fromtype);
case PyArray_CFLOAT:
case PyArray_CDOUBLE:
- case PyArray_CLONGDOUBLE:
- return (totype > fromtype);
- case PyArray_STRING:
- case PyArray_UNICODE:
- return (totype > fromtype);
+ case PyArray_CLONGDOUBLE:
+ return (totype > fromtype);
+ case PyArray_STRING:
+ case PyArray_UNICODE:
+ return (totype > fromtype);
default:
return 0;
}
@@ -8382,32 +8382,32 @@
static Bool
PyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)
{
- int fromtype=from->type_num;
- int totype=to->type_num;
- Bool ret;
+ int fromtype=from->type_num;
+ int totype=to->type_num;
+ Bool ret;
- ret = (Bool) PyArray_CanCastSafely(fromtype, totype);
- if (ret) { /* Check String and Unicode more closely */
- if (fromtype == PyArray_STRING) {
- if (totype == PyArray_STRING) {
- ret = (from->elsize <= to->elsize);
- }
- else if (totype == PyArray_UNICODE) {
- ret = (from->elsize << 2 \
- <= to->elsize);
- }
- }
- else if (fromtype == PyArray_UNICODE) {
- if (totype == PyArray_UNICODE) {
- ret = (from->elsize <= to->elsize);
- }
- }
- /* TODO: If totype is STRING or unicode
- see if the length is long enough to hold the
- stringified value of the object.
- */
- }
- return ret;
+ ret = (Bool) PyArray_CanCastSafely(fromtype, totype);
+ if (ret) { /* Check String and Unicode more closely */
+ if (fromtype == PyArray_STRING) {
+ if (totype == PyArray_STRING) {
+ ret = (from->elsize <= to->elsize);
+ }
+ else if (totype == PyArray_UNICODE) {
+ ret = (from->elsize << 2 \
+ <= to->elsize);
+ }
+ }
+ else if (fromtype == PyArray_UNICODE) {
+ if (totype == PyArray_UNICODE) {
+ ret = (from->elsize <= to->elsize);
+ }
+ }
+ /* TODO: If totype is STRING or unicode
+ see if the length is long enough to hold the
+ stringified value of the object.
+ */
+ }
+ return ret;
}
/*OBJECT_API
@@ -8416,14 +8416,14 @@
static Bool
PyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)
{
- int fromtype;
- int totype;
+ int fromtype;
+ int totype;
- fromtype = _typenum_fromtypeobj((PyObject *)from, 0);
- totype = _typenum_fromtypeobj((PyObject *)to, 0);
- if (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE)
- return FALSE;
- return (Bool) PyArray_CanCastSafely(fromtype, totype);
+ fromtype = _typenum_fromtypeobj((PyObject *)from, 0);
+ totype = _typenum_fromtypeobj((PyObject *)to, 0);
+ if (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE)
+ return FALSE;
+ return (Bool) PyArray_CanCastSafely(fromtype, totype);
}
@@ -8438,8 +8438,8 @@
PyArray_IterNew(PyObject *obj)
{
PyArrayIterObject *it;
- int i, nd;
- PyArrayObject *ao = (PyArrayObject *)obj;
+ int i, nd;
+ PyArrayObject *ao = (PyArrayObject *)obj;
if (!PyArray_Check(ao)) {
PyErr_BadInternalCall();
@@ -8452,25 +8452,25 @@
if (it == NULL)
return NULL;
- nd = ao->nd;
- PyArray_UpdateFlags(ao, CONTIGUOUS);
- it->contiguous = 0;
- if PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;
+ nd = ao->nd;
+ PyArray_UpdateFlags(ao, CONTIGUOUS);
+ it->contiguous = 0;
+ if PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;
Py_INCREF(ao);
it->ao = ao;
- it->size = PyArray_SIZE(ao);
- it->nd_m1 = nd - 1;
- it->factors[nd-1] = 1;
- for (i=0; i < nd; i++) {
- it->dims_m1[i] = it->ao->dimensions[i] - 1;
- it->strides[i] = it->ao->strides[i];
- it->backstrides[i] = it->strides[i] * \
- it->dims_m1[i];
- if (i > 0)
- it->factors[nd-i-1] = it->factors[nd-i] * \
- it->ao->dimensions[nd-i];
- }
- PyArray_ITER_RESET(it);
+ it->size = PyArray_SIZE(ao);
+ it->nd_m1 = nd - 1;
+ it->factors[nd-1] = 1;
+ for (i=0; i < nd; i++) {
+ it->dims_m1[i] = it->ao->dimensions[i] - 1;
+ it->strides[i] = it->ao->strides[i];
+ it->backstrides[i] = it->strides[i] * \
+ it->dims_m1[i];
+ if (i > 0)
+ it->factors[nd-i-1] = it->factors[nd-i] * \
+ it->ao->dimensions[nd-i];
+ }
+ PyArray_ITER_RESET(it);
return (PyObject *)it;
}
@@ -8483,34 +8483,34 @@
static PyObject *
PyArray_IterAllButAxis(PyObject *obj, int *inaxis)
{
- PyArrayIterObject *it;
- int axis;
- it = (PyArrayIterObject *)PyArray_IterNew(obj);
- if (it == NULL) return NULL;
+ PyArrayIterObject *it;
+ int axis;
+ it = (PyArrayIterObject *)PyArray_IterNew(obj);
+ if (it == NULL) return NULL;
- if (*inaxis < 0) {
- int i, maxaxis=0;
- intp maxdim=PyArray_DIM(obj,0);
+ if (*inaxis < 0) {
+ int i, maxaxis=0;
+ intp maxdim=PyArray_DIM(obj,0);
for (i=1; i<PyArray_NDIM(obj); i++) {
if (PyArray_DIM(obj,i) > maxdim) {
maxaxis = i;
maxdim = PyArray_DIM(obj,i);
}
- }
- *inaxis = maxaxis;
- }
- axis = *inaxis;
- /* adjust so that will not iterate over axis */
- it->contiguous = 0;
- if (it->size != 0) {
- it->size /= PyArray_DIM(obj,axis);
- }
- it->dims_m1[axis] = 0;
- it->backstrides[axis] = 0;
+ }
+ *inaxis = maxaxis;
+ }
+ axis = *inaxis;
+ /* adjust so that will not iterate over axis */
+ it->contiguous = 0;
+ if (it->size != 0) {
+ it->size /= PyArray_DIM(obj,axis);
+ }
+ it->dims_m1[axis] = 0;
+ it->backstrides[axis] = 0;
- /* (won't fix factors so don't use
- PyArray_ITER_GOTO1D with this iterator) */
- return (PyObject *)it;
+ /* (won't fix factors so don't use
+ PyArray_ITER_GOTO1D with this iterator) */
+ return (PyObject *)it;
}
@@ -8526,33 +8526,33 @@
static int
PyArray_RemoveLargest(PyArrayMultiIterObject *multi)
{
- PyArrayIterObject *it;
- int i;
- int axis=0;
- intp longest;
+ PyArrayIterObject *it;
+ int i;
+ int axis=0;
+ intp longest;
- if (multi->nd == 0) return -1;
-
- longest = multi->dimensions[0];
- /* Find longest dimension */
- for (i=1; i<multi->nd; i++) {
- if (multi->dimensions[i] > longest) {
- axis = i;
- longest = multi->dimensions[i];
- }
- }
-
- for (i=0; i<multi->numiter; i++) {
- it = multi->iters[i];
- it->contiguous = 0;
- if (it->size != 0)
- it->size /= (it->dims_m1[axis]+1);
- it->dims_m1[axis] = 0;
- it->backstrides[axis] = 0;
- }
+ if (multi->nd == 0) return -1;
+
+ longest = multi->dimensions[0];
+ /* Find longest dimension */
+ for (i=1; i<multi->nd; i++) {
+ if (multi->dimensions[i] > longest) {
+ axis = i;
+ longest = multi->dimensions[i];
+ }
+ }
+
+ for (i=0; i<multi->numiter; i++) {
+ it = multi->iters[i];
+ it->contiguous = 0;
+ if (it->size != 0)
+ it->size /= (it->dims_m1[axis]+1);
+ it->dims_m1[axis] = 0;
+ it->backstrides[axis] = 0;
+ }
- multi->size = multi->iters[0]->size;
- return axis;
+ multi->size = multi->iters[0]->size;
+ return axis;
}
/* Returns an array scalar holding the element desired */
@@ -8560,13 +8560,13 @@
static PyObject *
arrayiter_next(PyArrayIterObject *it)
{
- PyObject *ret;
+ PyObject *ret;
- if (it->index < it->size) {
- ret = PyArray_ToScalar(it->dataptr, it->ao);
- PyArray_ITER_NEXT(it);
- return ret;
- }
+ if (it->index < it->size) {
+ ret = PyArray_ToScalar(it->dataptr, it->ao);
+ PyArray_ITER_NEXT(it);
+ return ret;
+ }
return NULL;
}
@@ -8587,476 +8587,476 @@
static PyObject *
iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)
{
- int index, strides, itemsize;
- intp count=0;
- char *dptr, *optr;
- PyObject *r;
- int swap;
+ int index, strides, itemsize;
+ intp count=0;
+ char *dptr, *optr;
+ PyObject *r;
+ int swap;
PyArray_CopySwapFunc *copyswap;
- if (ind->nd != 1) {
- PyErr_SetString(PyExc_ValueError,
- "boolean index array should have 1 dimension");
- return NULL;
- }
- index = (ind->dimensions[0]);
- strides = ind->strides[0];
- dptr = ind->data;
- /* Get size of return array */
- while(index--) {
- if (*((Bool *)dptr) != 0)
- count++;
- dptr += strides;
- }
- itemsize = self->ao->descr->elsize;
- Py_INCREF(self->ao->descr);
- r = PyArray_NewFromDescr(self->ao->ob_type,
- self->ao->descr, 1, &count,
- NULL, NULL,
- 0, (PyObject *)self->ao);
- if (r==NULL) return NULL;
+ if (ind->nd != 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "boolean index array should have 1 dimension");
+ return NULL;
+ }
+ index = (ind->dimensions[0]);
+ strides = ind->strides[0];
+ dptr = ind->data;
+ /* Get size of return array */
+ while(index--) {
+ if (*((Bool *)dptr) != 0)
+ count++;
+ dptr += strides;
+ }
+ itemsize = self->ao->descr->elsize;
+ Py_INCREF(self->ao->descr);
+ r = PyArray_NewFromDescr(self->ao->ob_type,
+ self->ao->descr, 1, &count,
+ NULL, NULL,
+ 0, (PyObject *)self->ao);
+ if (r==NULL) return NULL;
- /* Set up loop */
- optr = PyArray_DATA(r);
- index = ind->dimensions[0];
- dptr = ind->data;
+ /* Set up loop */
+ optr = PyArray_DATA(r);
+ index = ind->dimensions[0];
+ dptr = ind->data;
copyswap = self->ao->descr->f->copyswap;
- /* Loop over Boolean array */
- swap = (PyArray_ISNOTSWAPPED(self->ao) != PyArray_ISNOTSWAPPED(r));
- while(index--) {
- if (*((Bool *)dptr) != 0) {
+ /* Loop over Boolean array */
+ swap = (PyArray_ISNOTSWAPPED(self->ao) != PyArray_ISNOTSWAPPED(r));
+ while(index--) {
+ if (*((Bool *)dptr) != 0) {
copyswap(optr, self->dataptr, swap, self->ao);
- optr += itemsize;
- }
- dptr += strides;
- PyArray_ITER_NEXT(self);
- }
- PyArray_ITER_RESET(self);
- return r;
+ optr += itemsize;
+ }
+ dptr += strides;
+ PyArray_ITER_NEXT(self);
+ }
+ PyArray_ITER_RESET(self);
+ return r;
}
static PyObject *
iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
{
- intp num;
- PyObject *r;
- PyArrayIterObject *ind_it;
- int itemsize;
- int swap;
- char *optr;
- int index;
+ intp num;
+ PyObject *r;
+ PyArrayIterObject *ind_it;
+ int itemsize;
+ int swap;
+ char *optr;
+ int index;
PyArray_CopySwapFunc *copyswap;
- itemsize = self->ao->descr->elsize;
- if (ind->nd == 0) {
- num = *((intp *)ind->data);
- PyArray_ITER_GOTO1D(self, num);
- r = PyArray_ToScalar(self->dataptr, self->ao);
- PyArray_ITER_RESET(self);
- return r;
- }
+ itemsize = self->ao->descr->elsize;
+ if (ind->nd == 0) {
+ num = *((intp *)ind->data);
+ PyArray_ITER_GOTO1D(self, num);
+ r = PyArray_ToScalar(self->dataptr, self->ao);
+ PyArray_ITER_RESET(self);
+ return r;
+ }
- Py_INCREF(self->ao->descr);
- r = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,
- ind->nd, ind->dimensions,
- NULL, NULL,
- 0, (PyObject *)self->ao);
- if (r==NULL) return NULL;
+ Py_INCREF(self->ao->descr);
+ r = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,
+ ind->nd, ind->dimensions,
+ NULL, NULL,
+ 0, (PyObject *)self->ao);
+ if (r==NULL) return NULL;
- optr = PyArray_DATA(r);
- ind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);
- if (ind_it == NULL) {Py_DECREF(r); return NULL;}
- index = ind_it->size;
+ optr = PyArray_DATA(r);
+ ind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);
+ if (ind_it == NULL) {Py_DECREF(r); return NULL;}
+ index = ind_it->size;
copyswap = PyArray_DESCR(r)->f->copyswap;
swap = (PyArray_ISNOTSWAPPED(r) != PyArray_ISNOTSWAPPED(self->ao));
- while(index--) {
- num = *((intp *)(ind_it->dataptr));
- if (num < 0) num += self->size;
- if (num < 0 || num >= self->size) {
- PyErr_Format(PyExc_IndexError,
- "index %d out of bounds" \
- " 0<=index<%d", (int) num,
- (int) self->size);
- Py_DECREF(ind_it);
- Py_DECREF(r);
- PyArray_ITER_RESET(self);
- return NULL;
- }
- PyArray_ITER_GOTO1D(self, num);
+ while(index--) {
+ num = *((intp *)(ind_it->dataptr));
+ if (num < 0) num += self->size;
+ if (num < 0 || num >= self->size) {
+ PyErr_Format(PyExc_IndexError,
+ "index %d out of bounds" \
+ " 0<=index<%d", (int) num,
+ (int) self->size);
+ Py_DECREF(ind_it);
+ Py_DECREF(r);
+ PyArray_ITER_RESET(self);
+ return NULL;
+ }
+ PyArray_ITER_GOTO1D(self, num);
copyswap(optr, self->dataptr, swap, r);
- optr += itemsize;
- PyArray_ITER_NEXT(ind_it);
- }
- Py_DECREF(ind_it);
- PyArray_ITER_RESET(self);
- return r;
+ optr += itemsize;
+ PyArray_ITER_NEXT(ind_it);
+ }
+ Py_DECREF(ind_it);
+ PyArray_ITER_RESET(self);
+ return r;
}
static PyObject *
iter_subscript(PyArrayIterObject *self, PyObject *ind)
{
- PyArray_Descr *indtype=NULL;
- intp start, step_size;
- intp n_steps;
- PyObject *r;
- char *dptr;
- int size;
- PyObject *obj = NULL;
- int swap;
+ PyArray_Descr *indtype=NULL;
+ intp start, step_size;
+ intp n_steps;
+ PyObject *r;
+ char *dptr;
+ int size;
+ PyObject *obj = NULL;
+ int swap;
PyArray_CopySwapFunc *copyswap;
- if (ind == Py_Ellipsis) {
- ind = PySlice_New(NULL, NULL, NULL);
- obj = iter_subscript(self, ind);
- Py_DECREF(ind);
- return obj;
- }
- if (PyTuple_Check(ind)) {
- int len;
- len = PyTuple_GET_SIZE(ind);
- if (len > 1) goto fail;
- ind = PyTuple_GET_ITEM(ind, 0);
- }
+ if (ind == Py_Ellipsis) {
+ ind = PySlice_New(NULL, NULL, NULL);
+ obj = iter_subscript(self, ind);
+ Py_DECREF(ind);
+ return obj;
+ }
+ if (PyTuple_Check(ind)) {
+ int len;
+ len = PyTuple_GET_SIZE(ind);
+ if (len > 1) goto fail;
+ ind = PyTuple_GET_ITEM(ind, 0);
+ }
- /* Tuples >1d not accepted --- i.e. no newaxis */
- /* Could implement this with adjusted strides
- and dimensions in iterator */
+ /* 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 */
- PyArray_ITER_RESET(self);
+ /* Check for Boolean -- this is first becasue
+ Bool is a subclass of Int */
+ PyArray_ITER_RESET(self);
- if (PyBool_Check(ind)) {
- if (PyObject_IsTrue(ind)) {
- return PyArray_ToScalar(self->dataptr, self->ao);
- }
- else { /* empty array */
- intp ii = 0;
- Py_INCREF(self->ao->descr);
- r = PyArray_NewFromDescr(self->ao->ob_type,
- self->ao->descr,
- 1, &ii,
- NULL, NULL, 0,
- (PyObject *)self->ao);
- return r;
- }
- }
+ if (PyBool_Check(ind)) {
+ if (PyObject_IsTrue(ind)) {
+ return PyArray_ToScalar(self->dataptr, self->ao);
+ }
+ else { /* empty array */
+ intp ii = 0;
+ Py_INCREF(self->ao->descr);
+ r = PyArray_NewFromDescr(self->ao->ob_type,
+ self->ao->descr,
+ 1, &ii,
+ NULL, NULL, 0,
+ (PyObject *)self->ao);
+ return r;
+ }
+ }
- /* Check for Integer or Slice */
+ /* Check for Integer or Slice */
- if (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {
- start = parse_subindex(ind, &step_size, &n_steps,
- self->size);
- if (start == -1)
- goto fail;
- if (n_steps == RubberIndex || n_steps == PseudoIndex) {
- PyErr_SetString(PyExc_IndexError,
- "cannot use Ellipsis or newaxes here");
- goto fail;
- }
- PyArray_ITER_GOTO1D(self, start)
- if (n_steps == SingleIndex) { /* Integer */
- r = PyArray_ToScalar(self->dataptr, self->ao);
- PyArray_ITER_RESET(self);
- return r;
- }
- size = self->ao->descr->elsize;
- Py_INCREF(self->ao->descr);
- r = PyArray_NewFromDescr(self->ao->ob_type,
- self->ao->descr,
- 1, &n_steps,
- NULL, NULL,
- 0, (PyObject *)self->ao);
- if (r==NULL) goto fail;
- dptr = PyArray_DATA(r);
+ if (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {
+ start = parse_subindex(ind, &step_size, &n_steps,
+ self->size);
+ if (start == -1)
+ goto fail;
+ if (n_steps == RubberIndex || n_steps == PseudoIndex) {
+ PyErr_SetString(PyExc_IndexError,
+ "cannot use Ellipsis or newaxes here");
+ goto fail;
+ }
+ PyArray_ITER_GOTO1D(self, start)
+ if (n_steps == SingleIndex) { /* Integer */
+ r = PyArray_ToScalar(self->dataptr, self->ao);
+ PyArray_ITER_RESET(self);
+ return r;
+ }
+ size = self->ao->descr->elsize;
+ Py_INCREF(self->ao->descr);
+ r = PyArray_NewFromDescr(self->ao->ob_type,
+ self->ao->descr,
+ 1, &n_steps,
+ NULL, NULL,
+ 0, (PyObject *)self->ao);
+ if (r==NULL) goto fail;
+ dptr = PyArray_DATA(r);
swap = !PyArray_ISNOTSWAPPED(self->ao);
copyswap = PyArray_DESCR(r)->f->copyswap;
- while(n_steps--) {
+ while(n_steps--) {
copyswap(dptr, self->dataptr, swap, r);
- start += step_size;
- PyArray_ITER_GOTO1D(self, start)
- dptr += size;
- }
- PyArray_ITER_RESET(self);
- return r;
- }
+ start += step_size;
+ PyArray_ITER_GOTO1D(self, start)
+ dptr += size;
+ }
+ PyArray_ITER_RESET(self);
+ return r;
+ }
- /* convert to INTP array if Integer array scalar or List */
+ /* convert to INTP array if Integer array scalar or List */
- indtype = PyArray_DescrFromType(PyArray_INTP);
- if (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {
- Py_INCREF(indtype);
- obj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);
- if (obj == NULL) goto fail;
- }
- else {
- Py_INCREF(ind);
- obj = ind;
- }
+ indtype = PyArray_DescrFromType(PyArray_INTP);
+ if (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {
+ Py_INCREF(indtype);
+ obj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);
+ if (obj == NULL) goto fail;
+ }
+ else {
+ Py_INCREF(ind);
+ obj = ind;
+ }
- if (PyArray_Check(obj)) {
- /* Check for Boolean object */
- if (PyArray_TYPE(obj)==PyArray_BOOL) {
- r = iter_subscript_Bool(self, (PyArrayObject *)obj);
- Py_DECREF(indtype);
- }
- /* Check for integer array */
- else if (PyArray_ISINTEGER(obj)) {
- PyObject *new;
- new = PyArray_FromAny(obj, indtype, 0, 0,
+ if (PyArray_Check(obj)) {
+ /* Check for Boolean object */
+ if (PyArray_TYPE(obj)==PyArray_BOOL) {
+ r = iter_subscript_Bool(self, (PyArrayObject *)obj);
+ Py_DECREF(indtype);
+ }
+ /* Check for integer array */
+ else if (PyArray_ISINTEGER(obj)) {
+ PyObject *new;
+ new = PyArray_FromAny(obj, indtype, 0, 0,
FORCECAST | ALIGNED, NULL);
- if (new==NULL) goto fail;
+ if (new==NULL) goto fail;
Py_DECREF(obj);
- obj = new;
- r = iter_subscript_int(self, (PyArrayObject *)obj);
- }
- else {
- goto fail;
- }
- Py_DECREF(obj);
- return r;
- }
- else Py_DECREF(indtype);
+ obj = new;
+ r = iter_subscript_int(self, (PyArrayObject *)obj);
+ }
+ else {
+ goto fail;
+ }
+ Py_DECREF(obj);
+ return r;
+ }
+ else Py_DECREF(indtype);
fail:
- if (!PyErr_Occurred())
- PyErr_SetString(PyExc_IndexError, "unsupported iterator index");
- Py_XDECREF(indtype);
- Py_XDECREF(obj);
- return NULL;
+ if (!PyErr_Occurred())
+ PyErr_SetString(PyExc_IndexError, "unsupported iterator index");
+ Py_XDECREF(indtype);
+ Py_XDECREF(obj);
+ return NULL;
}
static int
iter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,
- PyArrayIterObject *val, int swap)
+ PyArrayIterObject *val, int swap)
{
- int index, strides, itemsize;
- char *dptr;
+ int index, strides, itemsize;
+ char *dptr;
PyArray_CopySwapFunc *copyswap;
- if (ind->nd != 1) {
- PyErr_SetString(PyExc_ValueError,
- "boolean index array should have 1 dimension");
- return -1;
- }
- itemsize = self->ao->descr->elsize;
- index = ind->dimensions[0];
- strides = ind->strides[0];
- dptr = ind->data;
- PyArray_ITER_RESET(self);
- /* Loop over Boolean array */
+ if (ind->nd != 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "boolean index array should have 1 dimension");
+ return -1;
+ }
+ itemsize = self->ao->descr->elsize;
+ index = ind->dimensions[0];
+ strides = ind->strides[0];
+ dptr = ind->data;
+ PyArray_ITER_RESET(self);
+ /* Loop over Boolean array */
copyswap = self->ao->descr->f->copyswap;
- while(index--) {
- if (*((Bool *)dptr) != 0) {
+ while(index--) {
+ if (*((Bool *)dptr) != 0) {
copyswap(self->dataptr, val->dataptr, swap, self->ao);
- PyArray_ITER_NEXT(val);
- if (val->index==val->size)
- PyArray_ITER_RESET(val);
- }
- dptr += strides;
- PyArray_ITER_NEXT(self);
- }
- PyArray_ITER_RESET(self);
- return 0;
+ PyArray_ITER_NEXT(val);
+ if (val->index==val->size)
+ PyArray_ITER_RESET(val);
+ }
+ dptr += strides;
+ PyArray_ITER_NEXT(self);
+ }
+ PyArray_ITER_RESET(self);
+ return 0;
}
static int
iter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,
- PyArrayIterObject *val, int swap)
+ PyArrayIterObject *val, int swap)
{
- PyArray_Descr *typecode;
- intp num;
- PyArrayIterObject *ind_it;
- int itemsize;
- int index;
+ PyArray_Descr *typecode;
+ intp num;
+ PyArrayIterObject *ind_it;
+ int itemsize;
+ int index;
PyArray_CopySwapFunc *copyswap;
- typecode = self->ao->descr;
- itemsize = typecode->elsize;
+ typecode = self->ao->descr;
+ itemsize = typecode->elsize;
copyswap = self->ao->descr->f->copyswap;
- if (ind->nd == 0) {
- num = *((intp *)ind->data);
- PyArray_ITER_GOTO1D(self, num);
+ if (ind->nd == 0) {
+ num = *((intp *)ind->data);
+ PyArray_ITER_GOTO1D(self, num);
copyswap(self->dataptr, val->dataptr, swap, self->ao);
- return 0;
- }
- ind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);
- if (ind_it == NULL) return -1;
- index = ind_it->size;
- while(index--) {
- num = *((intp *)(ind_it->dataptr));
- if (num < 0) num += self->size;
- if ((num < 0) || (num >= self->size)) {
- PyErr_Format(PyExc_IndexError,
- "index %d out of bounds" \
- " 0<=index<%d", (int) num,
- (int) self->size);
- Py_DECREF(ind_it);
- return -1;
- }
- PyArray_ITER_GOTO1D(self, num);
+ return 0;
+ }
+ ind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);
+ if (ind_it == NULL) return -1;
+ index = ind_it->size;
+ while(index--) {
+ num = *((intp *)(ind_it->dataptr));
+ if (num < 0) num += self->size;
+ if ((num < 0) || (num >= self->size)) {
+ PyErr_Format(PyExc_IndexError,
+ "index %d out of bounds" \
+ " 0<=index<%d", (int) num,
+ (int) self->size);
+ Py_DECREF(ind_it);
+ return -1;
+ }
+ PyArray_ITER_GOTO1D(self, num);
copyswap(self->dataptr, val->dataptr, swap, self->ao);
- PyArray_ITER_NEXT(ind_it);
- PyArray_ITER_NEXT(val);
- if (val->index == val->size)
- PyArray_ITER_RESET(val);
- }
- Py_DECREF(ind_it);
- return 0;
+ PyArray_ITER_NEXT(ind_it);
+ PyArray_ITER_NEXT(val);
+ if (val->index == val->size)
+ PyArray_ITER_RESET(val);
+ }
+ Py_DECREF(ind_it);
+ return 0;
}
static int
iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)
{
- PyObject *arrval=NULL;
- PyArrayIterObject *val_it=NULL;
- PyArray_Descr *type;
- PyArray_Descr *indtype=NULL;
- int swap, retval=-1;
- int itemsize;
- intp start, step_size;
- intp n_steps;
- PyObject *obj=NULL;
+ PyObject *arrval=NULL;
+ PyArrayIterObject *val_it=NULL;
+ PyArray_Descr *type;
+ PyArray_Descr *indtype=NULL;
+ int swap, retval=-1;
+ int itemsize;
+ intp start, step_size;
+ intp n_steps;
+ PyObject *obj=NULL;
PyArray_CopySwapFunc *copyswap;
- if (ind == Py_Ellipsis) {
- ind = PySlice_New(NULL, NULL, NULL);
- retval = iter_ass_subscript(self, ind, val);
- Py_DECREF(ind);
- return retval;
- }
+ if (ind == Py_Ellipsis) {
+ ind = PySlice_New(NULL, NULL, NULL);
+ retval = iter_ass_subscript(self, ind, val);
+ Py_DECREF(ind);
+ return retval;
+ }
- if (PyTuple_Check(ind)) {
- int len;
- len = PyTuple_GET_SIZE(ind);
- if (len > 1) goto finish;
- ind = PyTuple_GET_ITEM(ind, 0);
- }
+ if (PyTuple_Check(ind)) {
+ int len;
+ len = PyTuple_GET_SIZE(ind);
+ if (len > 1) goto finish;
+ ind = PyTuple_GET_ITEM(ind, 0);
+ }
- type = self->ao->descr;
- itemsize = type->elsize;
+ type = self->ao->descr;
+ itemsize = type->elsize;
- Py_INCREF(type);
- arrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);
- if (arrval==NULL) return -1;
- val_it = (PyArrayIterObject *)PyArray_IterNew(arrval);
- if (val_it==NULL) goto finish;
+ Py_INCREF(type);
+ arrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);
+ if (arrval==NULL) return -1;
+ val_it = (PyArrayIterObject *)PyArray_IterNew(arrval);
+ if (val_it==NULL) goto finish;
- /* Check for Boolean -- this is first becasue
- Bool is a subclass of Int */
+ /* Check for Boolean -- this is first becasue
+ Bool is a subclass of Int */
copyswap = PyArray_DESCR(arrval)->f->copyswap;
- swap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));
- if (PyBool_Check(ind)) {
- if (PyObject_IsTrue(ind)) {
+ swap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));
+ if (PyBool_Check(ind)) {
+ if (PyObject_IsTrue(ind)) {
copyswap(self->dataptr, PyArray_DATA(arrval),
swap, arrval);
- }
- retval=0;
- goto finish;
- }
+ }
+ retval=0;
+ goto finish;
+ }
- /* Check for Integer or Slice */
+ /* Check for Integer or Slice */
- if (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {
- start = parse_subindex(ind, &step_size, &n_steps,
- self->size);
- if (start == -1) goto finish;
- if (n_steps == RubberIndex || n_steps == PseudoIndex) {
- PyErr_SetString(PyExc_IndexError,
- "cannot use Ellipsis or newaxes here");
- goto finish;
- }
- PyArray_ITER_GOTO1D(self, start);
- if (n_steps == SingleIndex) { /* Integer */
+ if (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {
+ start = parse_subindex(ind, &step_size, &n_steps,
+ self->size);
+ if (start == -1) goto finish;
+ if (n_steps == RubberIndex || n_steps == PseudoIndex) {
+ PyErr_SetString(PyExc_IndexError,
+ "cannot use Ellipsis or newaxes here");
+ goto finish;
+ }
+ PyArray_ITER_GOTO1D(self, start);
+ if (n_steps == SingleIndex) { /* Integer */
copyswap(self->dataptr, PyArray_DATA(arrval),
swap, arrval);
- PyArray_ITER_RESET(self);
- retval=0;
- goto finish;
- }
- while(n_steps--) {
+ PyArray_ITER_RESET(self);
+ retval=0;
+ goto finish;
+ }
+ while(n_steps--) {
copyswap(self->dataptr, val_it->dataptr,
swap, arrval);
- start += step_size;
- PyArray_ITER_GOTO1D(self, start)
- PyArray_ITER_NEXT(val_it);
- if (val_it->index == val_it->size)
- PyArray_ITER_RESET(val_it);
- }
- PyArray_ITER_RESET(self);
- retval = 0;
- goto finish;
- }
+ start += step_size;
+ PyArray_ITER_GOTO1D(self, start)
+ PyArray_ITER_NEXT(val_it);
+ if (val_it->index == val_it->size)
+ PyArray_ITER_RESET(val_it);
+ }
+ PyArray_ITER_RESET(self);
+ retval = 0;
+ goto finish;
+ }
- /* convert to INTP array if Integer array scalar or List */
+ /* convert to INTP array if Integer array scalar or List */
- indtype = PyArray_DescrFromType(PyArray_INTP);
- if (PyArray_IsScalar(ind, Integer)) {
- Py_INCREF(indtype);
- obj = PyArray_FromScalar(ind, indtype);
- }
- else if (PyList_Check(ind)) {
- Py_INCREF(indtype);
- obj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);
- }
- else {
- Py_INCREF(ind);
- obj = ind;
- }
+ indtype = PyArray_DescrFromType(PyArray_INTP);
+ if (PyArray_IsScalar(ind, Integer)) {
+ Py_INCREF(indtype);
+ obj = PyArray_FromScalar(ind, indtype);
+ }
+ else if (PyList_Check(ind)) {
+ Py_INCREF(indtype);
+ obj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);
+ }
+ else {
+ Py_INCREF(ind);
+ obj = ind;
+ }
- if (PyArray_Check(obj)) {
- /* Check for Boolean object */
- if (PyArray_TYPE(obj)==PyArray_BOOL) {
- if (iter_ass_sub_Bool(self, (PyArrayObject *)obj,
- val_it, swap) < 0)
- goto finish;
- retval=0;
- }
- /* Check for integer array */
- else if (PyArray_ISINTEGER(obj)) {
- PyObject *new;
- Py_INCREF(indtype);
- new = PyArray_CheckFromAny(obj, indtype, 0, 0,
+ if (PyArray_Check(obj)) {
+ /* Check for Boolean object */
+ if (PyArray_TYPE(obj)==PyArray_BOOL) {
+ if (iter_ass_sub_Bool(self, (PyArrayObject *)obj,
+ val_it, swap) < 0)
+ goto finish;
+ retval=0;
+ }
+ /* Check for integer array */
+ else if (PyArray_ISINTEGER(obj)) {
+ PyObject *new;
+ Py_INCREF(indtype);
+ new = PyArray_CheckFromAny(obj, indtype, 0, 0,
FORCECAST | BEHAVED_NS, NULL);
- Py_DECREF(obj);
- obj = new;
- if (new==NULL) goto finish;
- if (iter_ass_sub_int(self, (PyArrayObject *)obj,
- val_it, swap) < 0)
- goto finish;
- retval=0;
- }
- }
+ Py_DECREF(obj);
+ obj = new;
+ if (new==NULL) goto finish;
+ if (iter_ass_sub_int(self, (PyArrayObject *)obj,
+ val_it, swap) < 0)
+ goto finish;
+ retval=0;
+ }
+ }
finish:
- if (!PyErr_Occurred() && retval < 0)
- PyErr_SetString(PyExc_IndexError,
- "unsupported iterator index");
- Py_XDECREF(indtype);
- Py_XDECREF(obj);
- Py_XDECREF(val_it);
- Py_XDECREF(arrval);
- return retval;
+ if (!PyErr_Occurred() && retval < 0)
+ PyErr_SetString(PyExc_IndexError,
+ "unsupported iterator index");
+ Py_XDECREF(indtype);
+ Py_XDECREF(obj);
+ Py_XDECREF(val_it);
+ Py_XDECREF(arrval);
+ return retval;
}
static PyMappingMethods iter_as_mapping = {
#if PY_VERSION_HEX >= 0x02050000
- (lenfunc)iter_length, /*mp_length*/
+ (lenfunc)iter_length, /*mp_length*/
#else
- (inquiry)iter_length, /*mp_length*/
+ (inquiry)iter_length, /*mp_length*/
#endif
- (binaryfunc)iter_subscript, /*mp_subscript*/
- (objobjargproc)iter_ass_subscript, /*mp_ass_subscript*/
+ (binaryfunc)iter_subscript, /*mp_subscript*/
+ (objobjargproc)iter_ass_subscript, /*mp_ass_subscript*/
};
@@ -9082,28 +9082,28 @@
*/
size = PyArray_SIZE(it->ao);
- Py_INCREF(it->ao->descr);
+ Py_INCREF(it->ao->descr);
if (PyArray_ISCONTIGUOUS(it->ao)) {
r = PyArray_NewFromDescr(&PyArray_Type,
- it->ao->descr,
- 1, &size,
- NULL, it->ao->data,
- it->ao->flags,
- (PyObject *)it->ao);
- if (r==NULL) return NULL;
+ it->ao->descr,
+ 1, &size,
+ NULL, it->ao->data,
+ it->ao->flags,
+ (PyObject *)it->ao);
+ if (r==NULL) return NULL;
}
else {
r = PyArray_NewFromDescr(&PyArray_Type,
- it->ao->descr,
- 1, &size,
- NULL, NULL,
- 0, (PyObject *)it->ao);
- if (r==NULL) return NULL;
- if (_flat_copyinto(r, (PyObject *)it->ao,
- PyArray_CORDER) < 0) {
- Py_DECREF(r);
- return NULL;
- }
+ it->ao->descr,
+ 1, &size,
+ NULL, NULL,
+ 0, (PyObject *)it->ao);
+ if (r==NULL) return NULL;
+ if (_flat_copyinto(r, (PyObject *)it->ao,
+ PyArray_CORDER) < 0) {
+ Py_DECREF(r);
+ return NULL;
+ }
PyArray_FLAGS(r) |= UPDATEIFCOPY;
it->ao->flags &= ~WRITEABLE;
}
@@ -9119,14 +9119,14 @@
iter_copy(PyArrayIterObject *it, PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) return NULL;
- return PyArray_Flatten(it->ao, 0);
+ return PyArray_Flatten(it->ao, 0);
}
static PyMethodDef iter_methods[] = {
/* to get array */
{"__array__", (PyCFunction)iter_array, 1, doc_iter_array},
- {"copy", (PyCFunction)iter_copy, 1, doc_iter_copy},
- {NULL, NULL} /* sentinel */
+ {"copy", (PyCFunction)iter_copy, 1, doc_iter_copy},
+ {NULL, NULL} /* sentinel */
};
static PyObject *
@@ -9143,9 +9143,9 @@
static PyMemberDef iter_members[] = {
- {"base", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},
+ {"base", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},
{"index", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},
- {NULL},
+ {NULL},
};
static PyObject *
@@ -9167,45 +9167,45 @@
}
static PyGetSetDef iter_getsets[] = {
- {"coords",
- (getter)iter_coords_get,
- NULL,
- "An N-d tuple of current coordinates."},
- {NULL, NULL, NULL, NULL},
+ {"coords",
+ (getter)iter_coords_get,
+ NULL,
+ "An N-d tuple of current coordinates."},
+ {NULL, NULL, NULL, NULL},
};
static PyTypeObject PyArrayIter_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "numpy.flatiter", /* tp_name */
+ 0, /* ob_size */
+ "numpy.flatiter", /* tp_name */
sizeof(PyArrayIterObject), /* tp_basicsize */
- 0, /* tp_itemsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor)arrayiter_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- &iter_as_mapping, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
+ (destructor)arrayiter_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ &iter_as_mapping, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- (richcmpfunc)iter_richcompare, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- (iternextfunc)arrayiter_next, /* tp_iternext */
- iter_methods, /* tp_methods */
- iter_members, /* tp_members */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ (richcmpfunc)iter_richcompare, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ (iternextfunc)arrayiter_next, /* tp_iternext */
+ iter_methods, /* tp_methods */
+ iter_members, /* tp_members */
iter_getsets, /* tp_getset */
};
@@ -9233,23 +9233,23 @@
static int
_convert_obj(PyObject *obj, PyArrayIterObject **iter)
{
- PyArray_Descr *indtype;
- PyObject *arr;
+ PyArray_Descr *indtype;
+ PyObject *arr;
- if (PySlice_Check(obj) || (obj == Py_Ellipsis))
- return 0;
- else if (PyArray_Check(obj) && PyArray_ISBOOL(obj)) {
- return _nonzero_indices(obj, iter);
- }
- else {
- indtype = PyArray_DescrFromType(PyArray_INTP);
- arr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);
- if (arr == NULL) return -1;
- *iter = (PyArrayIterObject *)PyArray_IterNew(arr);
- Py_DECREF(arr);
- if (*iter == NULL) return -1;
- }
- return 1;
+ if (PySlice_Check(obj) || (obj == Py_Ellipsis))
+ return 0;
+ else if (PyArray_Check(obj) && PyArray_ISBOOL(obj)) {
+ return _nonzero_indices(obj, iter);
+ }
+ else {
+ indtype = PyArray_DescrFromType(PyArray_INTP);
+ arr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);
+ if (arr == NULL) return -1;
+ *iter = (PyArrayIterObject *)PyArray_IterNew(arr);
+ Py_DECREF(arr);
+ if (*iter == NULL) return -1;
+ }
+ return 1;
}
/* Adjust dimensionality and strides for index object iterators
@@ -9259,117 +9259,117 @@
static int
PyArray_Broadcast(PyArrayMultiIterObject *mit)
{
- int i, nd, k, j;
- intp tmp;
- PyArrayIterObject *it;
+ int i, nd, k, j;
+ intp tmp;
+ PyArrayIterObject *it;
- /* Discover the broadcast number of dimensions */
- for (i=0, nd=0; i<mit->numiter; i++)
- nd = MAX(nd, mit->iters[i]->ao->nd);
- mit->nd = nd;
+ /* Discover the broadcast number of dimensions */
+ for (i=0, nd=0; i<mit->numiter; i++)
+ nd = MAX(nd, mit->iters[i]->ao->nd);
+ mit->nd = nd;
- /* Discover the broadcast shape in each dimension */
- for (i=0; i<nd; i++) {
- mit->dimensions[i] = 1;
- for (j=0; j<mit->numiter; j++) {
- it = mit->iters[j];
- /* This prepends 1 to shapes not already
- equal to nd */
- k = i + it->ao->nd - nd;
- if (k>=0) {
- tmp = it->ao->dimensions[k];
- if (tmp == 1) continue;
- if (mit->dimensions[i] == 1)
- mit->dimensions[i] = tmp;
- else if (mit->dimensions[i] != tmp) {
- PyErr_SetString(PyExc_ValueError,
- "shape mismatch: objects" \
- " cannot be broadcast" \
- " to a single shape");
- return -1;
- }
- }
- }
- }
+ /* Discover the broadcast shape in each dimension */
+ for (i=0; i<nd; i++) {
+ mit->dimensions[i] = 1;
+ for (j=0; j<mit->numiter; j++) {
+ it = mit->iters[j];
+ /* This prepends 1 to shapes not already
+ equal to nd */
+ k = i + it->ao->nd - nd;
+ if (k>=0) {
+ tmp = it->ao->dimensions[k];
+ if (tmp == 1) continue;
+ if (mit->dimensions[i] == 1)
+ mit->dimensions[i] = tmp;
+ else if (mit->dimensions[i] != tmp) {
+ PyErr_SetString(PyExc_ValueError,
+ "shape mismatch: objects" \
+ " cannot be broadcast" \
+ " to a single shape");
+ return -1;
+ }
+ }
+ }
+ }
- /* Reset the iterator dimensions and strides of each iterator
- object -- using 0 valued strides for broadcasting */
+ /* Reset the iterator dimensions and strides of each iterator
+ object -- using 0 valued strides for broadcasting */
- tmp = PyArray_MultiplyList(mit->dimensions, mit->nd);
- mit->size = tmp;
- for (i=0; i<mit->numiter; i++) {
- it = mit->iters[i];
- it->nd_m1 = mit->nd - 1;
- it->size = tmp;
- nd = it->ao->nd;
- it->factors[mit->nd-1] = 1;
- for (j=0; j < mit->nd; j++) {
- it->dims_m1[j] = mit->dimensions[j] - 1;
- k = j + nd - mit->nd;
- /* If this dimension was added or shape
- of underlying array was 1 */
- if ((k < 0) || \
- it->ao->dimensions[k] != mit->dimensions[j]) {
- it->contiguous = 0;
- it->strides[j] = 0;
- }
- else {
- it->strides[j] = it->ao->strides[k];
- }
- it->backstrides[j] = it->strides[j] * \
- it->dims_m1[j];
- if (j > 0)
- it->factors[mit->nd-j-1] = \
- it->factors[mit->nd-j] * \
- mit->dimensions[mit->nd-j];
- }
- PyArray_ITER_RESET(it);
- }
- return 0;
+ tmp = PyArray_MultiplyList(mit->dimensions, mit->nd);
+ mit->size = tmp;
+ for (i=0; i<mit->numiter; i++) {
+ it = mit->iters[i];
+ it->nd_m1 = mit->nd - 1;
+ it->size = tmp;
+ nd = it->ao->nd;
+ it->factors[mit->nd-1] = 1;
+ for (j=0; j < mit->nd; j++) {
+ it->dims_m1[j] = mit->dimensions[j] - 1;
+ k = j + nd - mit->nd;
+ /* If this dimension was added or shape
+ of underlying array was 1 */
+ if ((k < 0) || \
+ it->ao->dimensions[k] != mit->dimensions[j]) {
+ it->contiguous = 0;
+ it->strides[j] = 0;
+ }
+ else {
+ it->strides[j] = it->ao->strides[k];
+ }
+ it->backstrides[j] = it->strides[j] * \
+ it->dims_m1[j];
+ if (j > 0)
+ it->factors[mit->nd-j-1] = \
+ it->factors[mit->nd-j] * \
+ mit->dimensions[mit->nd-j];
+ }
+ PyArray_ITER_RESET(it);
+ }
+ return 0;
}
/* Reset the map iterator to the beginning */
static void
PyArray_MapIterReset(PyArrayMapIterObject *mit)
{
- int i,j; intp coord[MAX_DIMS];
- PyArrayIterObject *it;
- PyArray_CopySwapFunc *copyswap;
+ int i,j; intp coord[MAX_DIMS];
+ PyArrayIterObject *it;
+ PyArray_CopySwapFunc *copyswap;
- mit->index = 0;
+ mit->index = 0;
- copyswap = mit->iters[0]->ao->descr->f->copyswap;
+ copyswap = mit->iters[0]->ao->descr->f->copyswap;
- if (mit->subspace != NULL) {
- memcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);
- PyArray_ITER_RESET(mit->subspace);
- for (i=0; i<mit->numiter; i++) {
- it = mit->iters[i];
- PyArray_ITER_RESET(it);
- j = mit->iteraxes[i];
- copyswap(coord+j,it->dataptr,
- !PyArray_ISNOTSWAPPED(it->ao),
- it->ao);
- }
- PyArray_ITER_GOTO(mit->ait, coord);
- mit->subspace->dataptr = mit->ait->dataptr;
- mit->dataptr = mit->subspace->dataptr;
- }
- else {
- for (i=0; i<mit->numiter; i++) {
- it = mit->iters[i];
- if (it->size != 0) {
- PyArray_ITER_RESET(it);
- copyswap(coord+i,it->dataptr,
- !PyArray_ISNOTSWAPPED(it->ao),
- it->ao);
- }
- else coord[i] = 0;
- }
- PyArray_ITER_GOTO(mit->ait, coord);
- mit->dataptr = mit->ait->dataptr;
- }
- return;
+ if (mit->subspace != NULL) {
+ memcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);
+ PyArray_ITER_RESET(mit->subspace);
+ for (i=0; i<mit->numiter; i++) {
+ it = mit->iters[i];
+ PyArray_ITER_RESET(it);
+ j = mit->iteraxes[i];
+ copyswap(coord+j,it->dataptr,
+ !PyArray_ISNOTSWAPPED(it->ao),
+ it->ao);
+ }
+ PyArray_ITER_GOTO(mit->ait, coord);
+ mit->subspace->dataptr = mit->ait->dataptr;
+ mit->dataptr = mit->subspace->dataptr;
+ }
+ else {
+ for (i=0; i<mit->numiter; i++) {
+ it = mit->iters[i];
+ if (it->size != 0) {
+ PyArray_ITER_RESET(it);
+ copyswap(coord+i,it->dataptr,
+ !PyArray_ISNOTSWAPPED(it->ao),
+ it->ao);
+ }
+ else coord[i] = 0;
+ }
+ PyArray_ITER_GOTO(mit->ait, coord);
+ mit->dataptr = mit->ait->dataptr;
+ }
+ return;
}
/* This function needs to update the state of the map iterator
@@ -9378,56 +9378,56 @@
static void
PyArray_MapIterNext(PyArrayMapIterObject *mit)
{
- int i, j;
- intp coord[MAX_DIMS];
- PyArrayIterObject *it;
- PyArray_CopySwapFunc *copyswap;
+ int i, j;
+ intp coord[MAX_DIMS];
+ PyArrayIterObject *it;
+ PyArray_CopySwapFunc *copyswap;
- mit->index += 1;
- if (mit->index >= mit->size) return;
- copyswap = mit->iters[0]->ao->descr->f->copyswap;
- /* Sub-space iteration */
- if (mit->subspace != NULL) {
- PyArray_ITER_NEXT(mit->subspace);
- if (mit->subspace->index == mit->subspace->size) {
- /* reset coord to coordinates of
- beginning of the subspace */
- memcpy(coord, mit->bscoord,
- sizeof(intp)*mit->ait->ao->nd);
- PyArray_ITER_RESET(mit->subspace);
- for (i=0; i<mit->numiter; i++) {
- it = mit->iters[i];
- PyArray_ITER_NEXT(it);
- j = mit->iteraxes[i];
- copyswap(coord+j,it->dataptr,
- !PyArray_ISNOTSWAPPED(it->ao),
- it->ao);
- }
- PyArray_ITER_GOTO(mit->ait, coord);
- mit->subspace->dataptr = mit->ait->dataptr;
- }
- mit->dataptr = mit->subspace->dataptr;
- }
- else {
- for (i=0; i<mit->numiter; i++) {
- it = mit->iters[i];
- PyArray_ITER_NEXT(it);
- copyswap(coord+i,it->dataptr,
- !PyArray_ISNOTSWAPPED(it->ao),
- it->ao);
- }
- PyArray_ITER_GOTO(mit->ait, coord);
- mit->dataptr = mit->ait->dataptr;
- }
- return;
+ mit->index += 1;
+ if (mit->index >= mit->size) return;
+ copyswap = mit->iters[0]->ao->descr->f->copyswap;
+ /* Sub-space iteration */
+ if (mit->subspace != NULL) {
+ PyArray_ITER_NEXT(mit->subspace);
+ if (mit->subspace->index == mit->subspace->size) {
+ /* reset coord to coordinates of
+ beginning of the subspace */
+ memcpy(coord, mit->bscoord,
+ sizeof(intp)*mit->ait->ao->nd);
+ PyArray_ITER_RESET(mit->subspace);
+ for (i=0; i<mit->numiter; i++) {
+ it = mit->iters[i];
+ PyArray_ITER_NEXT(it);
+ j = mit->iteraxes[i];
+ copyswap(coord+j,it->dataptr,
+ !PyArray_ISNOTSWAPPED(it->ao),
+ it->ao);
+ }
+ PyArray_ITER_GOTO(mit->ait, coord);
+ mit->subspace->dataptr = mit->ait->dataptr;
+ }
+ mit->dataptr = mit->subspace->dataptr;
+ }
+ else {
+ for (i=0; i<mit->numiter; i++) {
+ it = mit->iters[i];
+ PyArray_ITER_NEXT(it);
+ copyswap(coord+i,it->dataptr,
+ !PyArray_ISNOTSWAPPED(it->ao),
+ it->ao);
+ }
+ PyArray_ITER_GOTO(mit->ait, coord);
+ mit->dataptr = mit->ait->dataptr;
+ }
+ return;
}
/* Bind a mapiteration to a particular array */
/* Determine if subspace iteration is necessary. If so,
1) Fill in mit->iteraxes
- 2) Create subspace iterator
- 3) Update nd, dimensions, and size.
+ 2) Create subspace iterator
+ 3) Update nd, dimensions, and size.
Subspace iteration is necessary if: arr->nd > mit->numiter
*/
@@ -9440,145 +9440,145 @@
static void
PyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)
{
- int subnd;
- PyObject *sub, *obj=NULL;
- int i, j, n, curraxis, ellipexp, noellip;
- PyArrayIterObject *it;
- intp dimsize;
- intp *indptr;
+ int subnd;
+ PyObject *sub, *obj=NULL;
+ int i, j, n, curraxis, ellipexp, noellip;
+ PyArrayIterObject *it;
+ intp dimsize;
+ intp *indptr;
- subnd = arr->nd - mit->numiter;
- if (subnd < 0) {
- PyErr_SetString(PyExc_ValueError,
- "too many indices for array");
- return;
- }
+ subnd = arr->nd - mit->numiter;
+ if (subnd < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "too many indices for array");
+ return;
+ }
- mit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);
- if (mit->ait == NULL) return;
+ mit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);
+ if (mit->ait == NULL) return;
- /* If this is just a view, then do nothing more */
- /* views are handled by just adjusting the strides
- and dimensions of the object.
- */
+ /* If this is just a view, then do nothing more */
+ /* views are handled by just adjusting the strides
+ and dimensions of the object.
+ */
- /* no subspace iteration needed. Finish up and Return */
- if (subnd == 0) {
- n = arr->nd;
- for (i=0; i<n; i++) {
- mit->iteraxes[i] = i;
- }
- goto finish;
- }
+ /* no subspace iteration needed. Finish up and Return */
+ if (subnd == 0) {
+ n = arr->nd;
+ for (i=0; i<n; i++) {
+ mit->iteraxes[i] = i;
+ }
+ goto finish;
+ }
- /* all indexing arrays have been converted to 0
- therefore we can extract the subspace with a simple
- getitem call which will use view semantics
- */
- /* But, be sure to do it with a true array.
- */
- if (PyArray_CheckExact(arr)) {
- sub = array_subscript_simple(arr, mit->indexobj);
- }
- else {
- Py_INCREF(arr);
- obj = PyArray_EnsureArray((PyObject *)arr);
- if (obj == NULL) goto fail;
- sub = array_subscript_simple((PyArrayObject *)obj, mit->indexobj);
- Py_DECREF(obj);
- }
+ /* all indexing arrays have been converted to 0
+ therefore we can extract the subspace with a simple
+ getitem call which will use view semantics
+ */
+ /* But, be sure to do it with a true array.
+ */
+ if (PyArray_CheckExact(arr)) {
+ sub = array_subscript_simple(arr, mit->indexobj);
+ }
+ else {
+ Py_INCREF(arr);
+ obj = PyArray_EnsureArray((PyObject *)arr);
+ if (obj == NULL) goto fail;
+ sub = array_subscript_simple((PyArrayObject *)obj, mit->indexobj);
+ Py_DECREF(obj);
+ }
- if (sub == NULL) goto fail;
- mit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);
- Py_DECREF(sub);
- if (mit->subspace == NULL) goto fail;
+ if (sub == NULL) goto fail;
+ mit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);
+ Py_DECREF(sub);
+ if (mit->subspace == NULL) goto fail;
- /* Expand dimensions of result */
- n = mit->subspace->ao->nd;
- for (i=0; i<n; i++)
- mit->dimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];
- mit->nd += n;
+ /* Expand dimensions of result */
+ n = mit->subspace->ao->nd;
+ for (i=0; i<n; i++)
+ mit->dimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];
+ mit->nd += n;
- /* Now, we still need to interpret the ellipsis and slice objects
- to determine which axes the indexing arrays are referring to
- */
- n = PyTuple_GET_SIZE(mit->indexobj);
+ /* Now, we still need to interpret the ellipsis and slice objects
+ to determine which axes the indexing arrays are referring to
+ */
+ n = PyTuple_GET_SIZE(mit->indexobj);
- /* The number of dimensions an ellipsis takes up */
- ellipexp = arr->nd - n + 1;
- /* Now fill in iteraxes -- remember indexing arrays have been
+ /* The number of dimensions an ellipsis takes up */
+ ellipexp = arr->nd - n + 1;
+ /* Now fill in iteraxes -- remember indexing arrays have been
converted to 0's in mit->indexobj */
- curraxis = 0;
- j = 0;
- noellip = 1; /* Only expand the first ellipsis */
- memset(mit->bscoord, 0, sizeof(intp)*arr->nd);
- for (i=0; i<n; i++) {
- /* We need to fill in the starting coordinates for
- the subspace */
- obj = PyTuple_GET_ITEM(mit->indexobj, i);
- if (PyInt_Check(obj) || PyLong_Check(obj))
- mit->iteraxes[j++] = curraxis++;
- else if (noellip && obj == Py_Ellipsis) {
- curraxis += ellipexp;
- noellip = 0;
- }
- else {
- intp start=0;
- intp stop, step;
- /* Should be slice object or
- another Ellipsis */
- if (obj == Py_Ellipsis) {
- mit->bscoord[curraxis] = 0;
- }
- else if (!PySlice_Check(obj) || \
- (slice_GetIndices((PySliceObject *)obj,
- arr->dimensions[curraxis],
- &start, &stop, &step,
- &dimsize) < 0)) {
- PyErr_Format(PyExc_ValueError,
- "unexpected object " \
- "(%s) in selection position %d",
- obj->ob_type->tp_name, i);
- goto fail;
- }
- else {
- mit->bscoord[curraxis] = start;
- }
- curraxis += 1;
- }
- }
+ curraxis = 0;
+ j = 0;
+ noellip = 1; /* Only expand the first ellipsis */
+ memset(mit->bscoord, 0, sizeof(intp)*arr->nd);
+ for (i=0; i<n; i++) {
+ /* We need to fill in the starting coordinates for
+ the subspace */
+ obj = PyTuple_GET_ITEM(mit->indexobj, i);
+ if (PyInt_Check(obj) || PyLong_Check(obj))
+ mit->iteraxes[j++] = curraxis++;
+ else if (noellip && obj == Py_Ellipsis) {
+ curraxis += ellipexp;
+ noellip = 0;
+ }
+ else {
+ intp start=0;
+ intp stop, step;
+ /* Should be slice object or
+ another Ellipsis */
+ if (obj == Py_Ellipsis) {
+ mit->bscoord[curraxis] = 0;
+ }
+ else if (!PySlice_Check(obj) || \
+ (slice_GetIndices((PySliceObject *)obj,
+ arr->dimensions[curraxis],
+ &start, &stop, &step,
+ &dimsize) < 0)) {
+ PyErr_Format(PyExc_ValueError,
+ "unexpected object " \
+ "(%s) in selection position %d",
+ obj->ob_type->tp_name, i);
+ goto fail;
+ }
+ else {
+ mit->bscoord[curraxis] = start;
+ }
+ curraxis += 1;
+ }
+ }
finish:
- /* Here check the indexes (now that we have iteraxes) */
- mit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);
- for (i=0; i<mit->numiter; i++) {
+ /* Here check the indexes (now that we have iteraxes) */
+ mit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);
+ for (i=0; i<mit->numiter; i++) {
intp indval;
- it = mit->iters[i];
- PyArray_ITER_RESET(it);
- dimsize = arr->dimensions[mit->iteraxes[i]];
- while(it->index < it->size) {
- indptr = ((intp *)it->dataptr);
+ it = mit->iters[i];
+ PyArray_ITER_RESET(it);
+ dimsize = arr->dimensions[mit->iteraxes[i]];
+ while(it->index < it->size) {
+ indptr = ((intp *)it->dataptr);
indval = *indptr;
- if (indval < 0) indval += dimsize;
- if (indval < 0 || indval >= dimsize) {
- PyErr_Format(PyExc_IndexError,
- "index (%d) out of range "\
- "(0<=index<=%d) in dimension %d",
- (int) indval, (int) (dimsize-1),
- mit->iteraxes[i]);
- goto fail;
- }
- PyArray_ITER_NEXT(it);
- }
- PyArray_ITER_RESET(it);
- }
- return;
+ if (indval < 0) indval += dimsize;
+ if (indval < 0 || indval >= dimsize) {
+ PyErr_Format(PyExc_IndexError,
+ "index (%d) out of range "\
+ "(0<=index<=%d) in dimension %d",
+ (int) indval, (int) (dimsize-1),
+ mit->iteraxes[i]);
+ goto fail;
+ }
+ PyArray_ITER_NEXT(it);
+ }
+ PyArray_ITER_RESET(it);
+ }
+ return;
fail:
- Py_XDECREF(mit->subspace);
- Py_XDECREF(mit->ait);
- mit->subspace = NULL;
- mit->ait = NULL;
- return;
+ Py_XDECREF(mit->subspace);
+ Py_XDECREF(mit->ait);
+ mit->subspace = NULL;
+ mit->ait = NULL;
+ return;
}
/* This function takes a Boolean array and constructs index objects and
@@ -9587,119 +9587,119 @@
static int
_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)
{
- PyArray_Descr *typecode;
- PyArrayObject *ba =NULL, *new=NULL;
- int nd, j;
- intp size, i, count;
- Bool *ptr;
- intp coords[MAX_DIMS], dims_m1[MAX_DIMS];
- intp *dptr[MAX_DIMS];
+ PyArray_Descr *typecode;
+ PyArrayObject *ba =NULL, *new=NULL;
+ int nd, j;
+ intp size, i, count;
+ Bool *ptr;
+ intp coords[MAX_DIMS], dims_m1[MAX_DIMS];
+ intp *dptr[MAX_DIMS];
- typecode=PyArray_DescrFromType(PyArray_BOOL);
- ba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,
- CARRAY, NULL);
- if (ba == NULL) return -1;
- nd = ba->nd;
- for (j=0; j<nd; j++) iters[j] = NULL;
- size = PyArray_SIZE(ba);
- ptr = (Bool *)ba->data;
- count = 0;
+ typecode=PyArray_DescrFromType(PyArray_BOOL);
+ ba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,
+ CARRAY, NULL);
+ if (ba == NULL) return -1;
+ nd = ba->nd;
+ for (j=0; j<nd; j++) iters[j] = NULL;
+ size = PyArray_SIZE(ba);
+ ptr = (Bool *)ba->data;
+ count = 0;
- /* pre-determine how many nonzero entries there are */
- for (i=0; i<size; i++)
- if (*(ptr++)) count++;
+ /* pre-determine how many nonzero entries there are */
+ for (i=0; i<size; i++)
+ if (*(ptr++)) count++;
- /* create count-sized index arrays for each dimension */
- for (j=0; j<nd; j++) {
- new = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &count,
- PyArray_INTP, NULL, NULL,
- 0, 0, NULL);
- if (new == NULL) goto fail;
- iters[j] = (PyArrayIterObject *) \
- PyArray_IterNew((PyObject *)new);
- Py_DECREF(new);
- if (iters[j] == NULL) goto fail;
- dptr[j] = (intp *)iters[j]->ao->data;
- coords[j] = 0;
- dims_m1[j] = ba->dimensions[j]-1;
- }
+ /* create count-sized index arrays for each dimension */
+ for (j=0; j<nd; j++) {
+ new = (PyArrayObject *)PyArray_New(&PyArray_Type, 1, &count,
+ PyArray_INTP, NULL, NULL,
+ 0, 0, NULL);
+ if (new == NULL) goto fail;
+ iters[j] = (PyArrayIterObject *) \
+ PyArray_IterNew((PyObject *)new);
+ Py_DECREF(new);
+ if (iters[j] == NULL) goto fail;
+ dptr[j] = (intp *)iters[j]->ao->data;
+ coords[j] = 0;
+ dims_m1[j] = ba->dimensions[j]-1;
+ }
- ptr = (Bool *)ba->data;
+ ptr = (Bool *)ba->data;
- if (count == 0) goto finish;
+ if (count == 0) goto finish;
- /* Loop through the Boolean array and copy coordinates
- for non-zero entries */
- for (i=0; i<size; i++) {
- if (*(ptr++)) {
- for (j=0; j<nd; j++)
- *(dptr[j]++) = coords[j];
- }
- /* Borrowed from ITER_NEXT macro */
- for (j=nd-1; j>=0; j--) {
- if (coords[j] < dims_m1[j]) {
- coords[j]++;
- break;
- }
- else {
- coords[j] = 0;
- }
- }
- }
+ /* Loop through the Boolean array and copy coordinates
+ for non-zero entries */
+ for (i=0; i<size; i++) {
+ if (*(ptr++)) {
+ for (j=0; j<nd; j++)
+ *(dptr[j]++) = coords[j];
+ }
+ /* Borrowed from ITER_NEXT macro */
+ for (j=nd-1; j>=0; j--) {
+ if (coords[j] < dims_m1[j]) {
+ coords[j]++;
+ break;
+ }
+ else {
+ coords[j] = 0;
+ }
+ }
+ }
finish:
- Py_DECREF(ba);
- return nd;
+ Py_DECREF(ba);
+ return nd;
fail:
- for (j=0; j<nd; j++) {
- Py_XDECREF(iters[j]);
- }
- Py_XDECREF(ba);
- return -1;
+ for (j=0; j<nd; j++) {
+ Py_XDECREF(iters[j]);
+ }
+ Py_XDECREF(ba);
+ return -1;
}
static PyObject *
PyArray_MapIterNew(PyObject *indexobj, int oned, int fancy)
{
PyArrayMapIterObject *mit;
- PyArray_Descr *indtype;
- PyObject *arr = NULL;
- int i, n, started, nonindex;
+ PyArray_Descr *indtype;
+ PyObject *arr = NULL;
+ int i, n, started, nonindex;
- if (fancy == SOBJ_BADARRAY) {
- PyErr_SetString(PyExc_IndexError, \
- "arrays used as indices must be of " \
- "integer (or boolean) type");
- return NULL;
- }
- if (fancy == SOBJ_TOOMANY) {
- PyErr_SetString(PyExc_IndexError, "too many indices");
- return NULL;
- }
+ if (fancy == SOBJ_BADARRAY) {
+ PyErr_SetString(PyExc_IndexError, \
+ "arrays used as indices must be of " \
+ "integer (or boolean) type");
+ return NULL;
+ }
+ if (fancy == SOBJ_TOOMANY) {
+ PyErr_SetString(PyExc_IndexError, "too many indices");
+ return NULL;
+ }
mit = (PyArrayMapIterObject *)_pya_malloc(sizeof(PyArrayMapIterObject));
PyObject_Init((PyObject *)mit, &PyArrayMapIter_Type);
if (mit == NULL)
return NULL;
- for (i=0; i<MAX_DIMS; i++)
- mit->iters[i] = NULL;
- mit->index = 0;
- mit->ait = NULL;
- mit->subspace = NULL;
- mit->numiter = 0;
- mit->consec = 1;
- Py_INCREF(indexobj);
- mit->indexobj = indexobj;
+ for (i=0; i<MAX_DIMS; i++)
+ mit->iters[i] = NULL;
+ mit->index = 0;
+ mit->ait = NULL;
+ mit->subspace = NULL;
+ mit->numiter = 0;
+ mit->consec = 1;
+ Py_INCREF(indexobj);
+ mit->indexobj = indexobj;
- if (fancy == SOBJ_LISTTUP) {
- PyObject *newobj;
- newobj = PySequence_Tuple(indexobj);
- if (newobj == NULL) goto fail;
- Py_DECREF(indexobj);
- indexobj = newobj;
- mit->indexobj = indexobj;
- }
+ if (fancy == SOBJ_LISTTUP) {
+ PyObject *newobj;
+ newobj = PySequence_Tuple(indexobj);
+ if (newobj == NULL) goto fail;
+ Py_DECREF(indexobj);
+ indexobj = newobj;
+ mit->indexobj = indexobj;
+ }
#undef SOBJ_NOTFANCY
#undef SOBJ_ISFANCY
@@ -9707,117 +9707,117 @@
#undef SOBJ_TOOMANY
#undef SOBJ_LISTTUP
- if (oned) return (PyObject *)mit;
+ if (oned) return (PyObject *)mit;
- /* Must have some kind of fancy indexing if we are here */
- /* indexobj is either a list, an arrayobject, or a tuple
- (with at least 1 list or arrayobject or Bool object), */
+ /* Must have some kind of fancy indexing if we are here */
+ /* indexobj is either a list, an arrayobject, or a tuple
+ (with at least 1 list or arrayobject or Bool object), */
- /* convert all inputs to iterators */
- if (PyArray_Check(indexobj) && \
- (PyArray_TYPE(indexobj) == PyArray_BOOL)) {
- mit->numiter = _nonzero_indices(indexobj, mit->iters);
- if (mit->numiter < 0) goto fail;
- mit->nd = 1;
- mit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;
- Py_DECREF(mit->indexobj);
- mit->indexobj = PyTuple_New(mit->numiter);
- if (mit->indexobj == NULL) goto fail;
- for (i=0; i<mit->numiter; i++) {
- PyTuple_SET_ITEM(mit->indexobj, i,
- PyInt_FromLong(0));
- }
- }
+ /* convert all inputs to iterators */
+ if (PyArray_Check(indexobj) && \
+ (PyArray_TYPE(indexobj) == PyArray_BOOL)) {
+ mit->numiter = _nonzero_indices(indexobj, mit->iters);
+ if (mit->numiter < 0) goto fail;
+ mit->nd = 1;
+ mit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;
+ Py_DECREF(mit->indexobj);
+ mit->indexobj = PyTuple_New(mit->numiter);
+ if (mit->indexobj == NULL) goto fail;
+ for (i=0; i<mit->numiter; i++) {
+ PyTuple_SET_ITEM(mit->indexobj, i,
+ PyInt_FromLong(0));
+ }
+ }
- else if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {
- mit->numiter = 1;
- indtype = PyArray_DescrFromType(PyArray_INTP);
- arr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);
- if (arr == NULL) goto fail;
- mit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);
- if (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}
- mit->nd = PyArray_NDIM(arr);
- memcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));
- mit->size = PyArray_SIZE(arr);
- Py_DECREF(arr);
- Py_DECREF(mit->indexobj);
- mit->indexobj = Py_BuildValue("(N)", PyInt_FromLong(0));
- }
- else { /* must be a tuple */
- PyObject *obj;
- PyArrayIterObject **iterp;
- PyObject *new;
- int numiters, j, n2;
- /* Make a copy of the tuple -- we will be replacing
- index objects with 0's */
- n = PyTuple_GET_SIZE(indexobj);
- n2 = n;
- new = PyTuple_New(n2);
- if (new == NULL) goto fail;
- started = 0;
- nonindex = 0;
- j = 0;
- for (i=0; i<n; i++) {
- obj = PyTuple_GET_ITEM(indexobj,i);
- iterp = mit->iters + mit->numiter;
- if ((numiters=_convert_obj(obj, iterp)) < 0) {
+ else if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {
+ mit->numiter = 1;
+ indtype = PyArray_DescrFromType(PyArray_INTP);
+ arr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);
+ if (arr == NULL) goto fail;
+ mit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);
+ if (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}
+ mit->nd = PyArray_NDIM(arr);
+ memcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));
+ mit->size = PyArray_SIZE(arr);
+ Py_DECREF(arr);
+ Py_DECREF(mit->indexobj);
+ mit->indexobj = Py_BuildValue("(N)", PyInt_FromLong(0));
+ }
+ else { /* must be a tuple */
+ PyObject *obj;
+ PyArrayIterObject **iterp;
+ PyObject *new;
+ int numiters, j, n2;
+ /* Make a copy of the tuple -- we will be replacing
+ index objects with 0's */
+ n = PyTuple_GET_SIZE(indexobj);
+ n2 = n;
+ new = PyTuple_New(n2);
+ if (new == NULL) goto fail;
+ started = 0;
+ nonindex = 0;
+ j = 0;
+ for (i=0; i<n; i++) {
+ obj = PyTuple_GET_ITEM(indexobj,i);
+ iterp = mit->iters + mit->numiter;
+ if ((numiters=_convert_obj(obj, iterp)) < 0) {
Py_DECREF(new);
- goto fail;
+ goto fail;
}
- if (numiters > 0) {
- started = 1;
- if (nonindex) mit->consec = 0;
- mit->numiter += numiters;
- if (numiters == 1) {
- PyTuple_SET_ITEM(new,j++,
- PyInt_FromLong(0));
- }
- else { /* we need to grow the
- new indexing object and fill
- it with 0s for each of the iterators
- produced */
- int k;
- n2 += numiters - 1;
- if (_PyTuple_Resize(&new, n2) < 0)
- goto fail;
- for (k=0;k<numiters;k++) {
- PyTuple_SET_ITEM \
- (new,j++,
- PyInt_FromLong(0));
- }
- }
- }
- else {
- if (started) nonindex = 1;
- Py_INCREF(obj);
- PyTuple_SET_ITEM(new,j++,obj);
- }
- }
- Py_DECREF(mit->indexobj);
- mit->indexobj = new;
- /* Store the number of iterators actually converted */
- /* These will be mapped to actual axes at bind time */
- if (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)
- goto fail;
- }
+ if (numiters > 0) {
+ started = 1;
+ if (nonindex) mit->consec = 0;
+ mit->numiter += numiters;
+ if (numiters == 1) {
+ PyTuple_SET_ITEM(new,j++,
+ PyInt_FromLong(0));
+ }
+ else { /* we need to grow the
+ new indexing object and fill
+ it with 0s for each of the iterators
+ produced */
+ int k;
+ n2 += numiters - 1;
+ if (_PyTuple_Resize(&new, n2) < 0)
+ goto fail;
+ for (k=0;k<numiters;k++) {
+ PyTuple_SET_ITEM \
+ (new,j++,
+ PyInt_FromLong(0));
+ }
+ }
+ }
+ else {
+ if (started) nonindex = 1;
+ Py_INCREF(obj);
+ PyTuple_SET_ITEM(new,j++,obj);
+ }
+ }
+ Py_DECREF(mit->indexobj);
+ mit->indexobj = new;
+ /* Store the number of iterators actually converted */
+ /* These will be mapped to actual axes at bind time */
+ if (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)
+ goto fail;
+ }
return (PyObject *)mit;
fail:
Py_DECREF(mit);
- return NULL;
+ return NULL;
}
static void
arraymapiter_dealloc(PyArrayMapIterObject *mit)
{
- int i;
- Py_XDECREF(mit->indexobj);
+ int i;
+ Py_XDECREF(mit->indexobj);
Py_XDECREF(mit->ait);
- Py_XDECREF(mit->subspace);
- for (i=0; i<mit->numiter; i++)
- Py_XDECREF(mit->iters[i]);
+ Py_XDECREF(mit->subspace);
+ for (i=0; i<mit->numiter; i++)
+ Py_XDECREF(mit->iters[i]);
_pya_free(mit);
}
@@ -9834,52 +9834,52 @@
static PyTypeObject PyArrayMapIter_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "numpy.mapiter", /* tp_name */
+ 0, /* ob_size */
+ "numpy.mapiter", /* tp_name */
sizeof(PyArrayIterObject), /* tp_basicsize */
- 0, /* tp_itemsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor)arraymapiter_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
+ (destructor)arraymapiter_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- (traverseproc)0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- (iternextfunc)0, /* tp_iternext */
- 0, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)0, /* tp_init */
- 0, /* tp_alloc */
- 0, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
- 0, /* tp_mro */
- 0, /* tp_cache */
- 0, /* tp_subclasses */
- 0 /* tp_weaklist */
+ 0, /* tp_doc */
+ (traverseproc)0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ (iternextfunc)0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0 /* tp_weaklist */
};
@@ -9893,51 +9893,51 @@
PyArray_MultiIterNew(int n, ...)
{
va_list va;
- PyArrayMultiIterObject *multi;
- PyObject *current;
- PyObject *arr;
+ PyArrayMultiIterObject *multi;
+ PyObject *current;
+ PyObject *arr;
- int i, err=0;
+ int i, err=0;
- if (n < 2 || n > MAX_DIMS) {
- PyErr_Format(PyExc_ValueError,
- "Need between 2 and (%d) " \
- "array objects (inclusive).", MAX_DIMS);
- }
+ if (n < 2 || n > MAX_DIMS) {
+ PyErr_Format(PyExc_ValueError,
+ "Need between 2 and (%d) " \
+ "array objects (inclusive).", MAX_DIMS);
+ }
/* fprintf(stderr, "multi new...");*/
- multi = _pya_malloc(sizeof(PyArrayMultiIterObject));
+ multi = _pya_malloc(sizeof(PyArrayMultiIterObject));
if (multi == NULL) return PyErr_NoMemory();
- PyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);
+ PyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);
- for (i=0; i<n; i++) multi->iters[i] = NULL;
- multi->numiter = n;
- multi->index = 0;
+ for (i=0; i<n; i++) multi->iters[i] = NULL;
+ multi->numiter = n;
+ multi->index = 0;
va_start(va, n);
- for (i=0; i<n; i++) {
- current = va_arg(va, PyObject *);
- arr = PyArray_FROM_O(current);
- if (arr==NULL) {
- err=1; break;
- }
- else {
- multi->iters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);
- Py_DECREF(arr);
- }
- }
+ for (i=0; i<n; i++) {
+ current = va_arg(va, PyObject *);
+ arr = PyArray_FROM_O(current);
+ if (arr==NULL) {
+ err=1; break;
+ }
+ else {
+ multi->iters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);
+ Py_DECREF(arr);
+ }
+ }
- va_end(va);
+ va_end(va);
- if (!err && PyArray_Broadcast(multi) < 0) err=1;
+ if (!err && PyArray_Broadcast(multi) < 0) err=1;
- if (err) {
+ if (err) {
Py_DECREF(multi);
- return NULL;
- }
+ return NULL;
+ }
- PyArray_MultiIter_RESET(multi);
+ PyArray_MultiIter_RESET(multi);
return (PyObject *)multi;
}
@@ -9946,92 +9946,92 @@
arraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
{
- int n, i;
- PyArrayMultiIterObject *multi;
- PyObject *arr;
+ int n, i;
+ PyArrayMultiIterObject *multi;
+ PyObject *arr;
- if (kwds != NULL) {
- PyErr_SetString(PyExc_ValueError,
- "keyword arguments not accepted.");
- return NULL;
- }
+ if (kwds != NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "keyword arguments not accepted.");
+ return NULL;
+ }
- n = PyTuple_Size(args);
- if (n < 2 || n > MAX_DIMS) {
- if (PyErr_Occurred()) return NULL;
- PyErr_Format(PyExc_ValueError,
- "Need at least two and fewer than (%d) " \
- "array objects.", MAX_DIMS);
- return NULL;
- }
+ n = PyTuple_Size(args);
+ if (n < 2 || n > MAX_DIMS) {
+ if (PyErr_Occurred()) return NULL;
+ PyErr_Format(PyExc_ValueError,
+ "Need at least two and fewer than (%d) " \
+ "array objects.", MAX_DIMS);
+ return NULL;
+ }
- multi = _pya_malloc(sizeof(PyArrayMultiIterObject));
+ multi = _pya_malloc(sizeof(PyArrayMultiIterObject));
if (multi == NULL) return PyErr_NoMemory();
- PyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);
+ PyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);
- multi->numiter = n;
- multi->index = 0;
- for (i=0; i<n; i++) multi->iters[i] = NULL;
- for (i=0; i<n; i++) {
- arr = PyArray_FromAny(PyTuple_GET_ITEM(args, i), NULL, 0, 0, 0, NULL);
- if (arr == NULL) goto fail;
- if ((multi->iters[i] = \
- (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)
- goto fail;
- Py_DECREF(arr);
- }
- if (PyArray_Broadcast(multi) < 0) goto fail;
- PyArray_MultiIter_RESET(multi);
+ multi->numiter = n;
+ multi->index = 0;
+ for (i=0; i<n; i++) multi->iters[i] = NULL;
+ for (i=0; i<n; i++) {
+ arr = PyArray_FromAny(PyTuple_GET_ITEM(args, i), NULL, 0, 0, 0, NULL);
+ if (arr == NULL) goto fail;
+ if ((multi->iters[i] = \
+ (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)
+ goto fail;
+ Py_DECREF(arr);
+ }
+ if (PyArray_Broadcast(multi) < 0) goto fail;
+ PyArray_MultiIter_RESET(multi);
return (PyObject *)multi;
fail:
Py_DECREF(multi);
- return NULL;
+ return NULL;
}
static PyObject *
arraymultiter_next(PyArrayMultiIterObject *multi)
{
- PyObject *ret;
- int i, n;
+ PyObject *ret;
+ int i, n;
- n = multi->numiter;
- ret = PyTuple_New(n);
- if (ret == NULL) return NULL;
- if (multi->index < multi->size) {
- for (i=0; i < n; i++) {
- PyArrayIterObject *it=multi->iters[i];
- PyTuple_SET_ITEM(ret, i,
- PyArray_ToScalar(it->dataptr, it->ao));
- PyArray_ITER_NEXT(it);
- }
- multi->index++;
- return ret;
- }
+ n = multi->numiter;
+ ret = PyTuple_New(n);
+ if (ret == NULL) return NULL;
+ if (multi->index < multi->size) {
+ for (i=0; i < n; i++) {
+ PyArrayIterObject *it=multi->iters[i];
+ PyTuple_SET_ITEM(ret, i,
+ PyArray_ToScalar(it->dataptr, it->ao));
+ PyArray_ITER_NEXT(it);
+ }
+ multi->index++;
+ return ret;
+ }
return NULL;
}
static void
arraymultiter_dealloc(PyArrayMultiIterObject *multi)
{
- int i;
+ int i;
- for (i=0; i<multi->numiter; i++)
- Py_XDECREF(multi->iters[i]);
- multi->ob_type->tp_free((PyObject *)multi);
+ for (i=0; i<multi->numiter; i++)
+ Py_XDECREF(multi->iters[i]);
+ multi->ob_type->tp_free((PyObject *)multi);
}
static PyObject *
arraymultiter_size_get(PyArrayMultiIterObject *self)
{
#if SIZEOF_INTP <= SIZEOF_LONG
- return PyInt_FromLong((long) self->size);
+ return PyInt_FromLong((long) self->size);
#else
- if (self->size < MAX_LONG)
- return PyInt_FromLong((long) self->size);
- else
- return PyLong_FromLongLong((longlong) self->size);
+ if (self->size < MAX_LONG)
+ return PyInt_FromLong((long) self->size);
+ else
+ return PyLong_FromLongLong((longlong) self->size);
#endif
}
@@ -10039,139 +10039,139 @@
arraymultiter_index_get(PyArrayMultiIterObject *self)
{
#if SIZEOF_INTP <= SIZEOF_LONG
- return PyInt_FromLong((long) self->index);
+ return PyInt_FromLong((long) self->index);
#else
- if (self->size < MAX_LONG)
- return PyInt_FromLong((long) self->index);
- else
- return PyLong_FromLongLong((longlong) self->index);
+ if (self->size < MAX_LONG)
+ return PyInt_FromLong((long) self->index);
+ else
+ return PyLong_FromLongLong((longlong) self->index);
#endif
}
static PyObject *
arraymultiter_shape_get(PyArrayMultiIterObject *self)
{
- return PyArray_IntTupleFromIntp(self->nd, self->dimensions);
+ return PyArray_IntTupleFromIntp(self->nd, self->dimensions);
}
static PyObject *
arraymultiter_iters_get(PyArrayMultiIterObject *self)
{
- PyObject *res;
- int i, n;
- n = self->numiter;
- res = PyTuple_New(n);
- if (res == NULL) return res;
- for (i=0; i<n; i++) {
- Py_INCREF(self->iters[i]);
- PyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);
- }
- return res;
+ PyObject *res;
+ int i, n;
+ n = self->numiter;
+ res = PyTuple_New(n);
+ if (res == NULL) return res;
+ for (i=0; i<n; i++) {
+ Py_INCREF(self->iters[i]);
+ PyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);
+ }
+ return res;
}
static PyGetSetDef arraymultiter_getsetlist[] = {
{"size",
- (getter)arraymultiter_size_get,
- NULL,
- "total size of broadcasted result"},
+ (getter)arraymultiter_size_get,
+ NULL,
+ "total size of broadcasted result"},
{"index",
- (getter)arraymultiter_index_get,
+ (getter)arraymultiter_index_get,
NULL,
- "current index in broadcasted result"},
- {"shape",
- (getter)arraymultiter_shape_get,
- NULL,
- "shape of broadcasted result"},
- {"iters",
- (getter)arraymultiter_iters_get,
- NULL,
- "tuple of individual iterators"},
- {NULL, NULL, NULL, NULL},
+ "current index in broadcasted result"},
+ {"shape",
+ (getter)arraymultiter_shape_get,
+ NULL,
+ "shape of broadcasted result"},
+ {"iters",
+ (getter)arraymultiter_iters_get,
+ NULL,
+ "tuple of individual iterators"},
+ {NULL, NULL, NULL, NULL},
};
static PyMemberDef arraymultiter_members[] = {
- {"numiter", T_INT, offsetof(PyArrayMultiIterObject, numiter),
- RO, NULL},
- {"nd", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},
- {NULL},
+ {"numiter", T_INT, offsetof(PyArrayMultiIterObject, numiter),
+ RO, NULL},
+ {"nd", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},
+ {NULL},
};
static PyObject *
arraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)
{
- if (!PyArg_ParseTuple(args, "")) return NULL;
+ if (!PyArg_ParseTuple(args, "")) return NULL;
- PyArray_MultiIter_RESET(self);
- Py_INCREF(Py_None);
- return Py_None;
+ PyArray_MultiIter_RESET(self);
+ Py_INCREF(Py_None);
+ return Py_None;
}
static PyMethodDef arraymultiter_methods[] = {
- {"reset", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},
- {NULL, NULL},
+ {"reset", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},
+ {NULL, NULL},
};
static PyTypeObject PyArrayMultiIter_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "numpy.broadcast", /* tp_name */
+ 0, /* ob_size */
+ "numpy.broadcast", /* tp_name */
sizeof(PyArrayMultiIterObject), /* tp_basicsize */
- 0, /* tp_itemsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor)arraymultiter_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
+ (destructor)arraymultiter_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- (iternextfunc)arraymultiter_next, /* tp_iternext */
- arraymultiter_methods, /* tp_methods */
- arraymultiter_members, /* tp_members */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ (iternextfunc)arraymultiter_next, /* tp_iternext */
+ arraymultiter_methods, /* tp_methods */
+ arraymultiter_members, /* tp_members */
arraymultiter_getsetlist, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)0, /* tp_init */
- 0, /* tp_alloc */
- arraymultiter_new, /* tp_new */
- _pya_free, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
- 0, /* tp_mro */
- 0, /* tp_cache */
- 0, /* tp_subclasses */
- 0 /* tp_weaklist */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)0, /* tp_init */
+ 0, /* tp_alloc */
+ arraymultiter_new, /* tp_new */
+ _pya_free, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0 /* tp_weaklist */
};
/*OBJECT_API*/
static PyArray_Descr *
PyArray_DescrNewFromType(int type_num)
{
- PyArray_Descr *old;
- PyArray_Descr *new;
+ PyArray_Descr *old;
+ PyArray_Descr *new;
- old = PyArray_DescrFromType(type_num);
- new = PyArray_DescrNew(old);
- Py_DECREF(old);
- return new;
+ old = PyArray_DescrFromType(type_num);
+ new = PyArray_DescrNew(old);
+ Py_DECREF(old);
+ return new;
}
/*** Array Descr Objects for dynamic types **/
@@ -10192,27 +10192,27 @@
static PyArray_Descr *
PyArray_DescrNew(PyArray_Descr *base)
{
- PyArray_Descr *new;
+ PyArray_Descr *new;
- new = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);
- if (new == NULL) return NULL;
- /* Don't copy PyObject_HEAD part */
- memcpy((char *)new+sizeof(PyObject),
- (char *)base+sizeof(PyObject),
- sizeof(PyArray_Descr)-sizeof(PyObject));
+ new = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);
+ if (new == NULL) return NULL;
+ /* Don't copy PyObject_HEAD part */
+ memcpy((char *)new+sizeof(PyObject),
+ (char *)base+sizeof(PyObject),
+ sizeof(PyArray_Descr)-sizeof(PyObject));
- if (new->fields == Py_None) new->fields = NULL;
- Py_XINCREF(new->fields);
+ if (new->fields == Py_None) new->fields = NULL;
+ Py_XINCREF(new->fields);
Py_XINCREF(new->names);
- if (new->subarray) {
- new->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));
- memcpy(new->subarray, base->subarray,
- sizeof(PyArray_ArrayDescr));
- Py_INCREF(new->subarray->shape);
- Py_INCREF(new->subarray->base);
- }
- Py_INCREF(new->typeobj);
- return new;
+ if (new->subarray) {
+ new->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));
+ memcpy(new->subarray, base->subarray,
+ sizeof(PyArray_ArrayDescr));
+ Py_INCREF(new->subarray->shape);
+ Py_INCREF(new->subarray->base);
+ }
+ Py_INCREF(new->typeobj);
+ return new;
}
/* should never be called for builtin-types unless
@@ -10221,15 +10221,15 @@
static void
arraydescr_dealloc(PyArray_Descr *self)
{
- Py_XDECREF(self->typeobj);
+ Py_XDECREF(self->typeobj);
Py_XDECREF(self->names);
- Py_XDECREF(self->fields);
- if (self->subarray) {
- Py_DECREF(self->subarray->shape);
- Py_DECREF(self->subarray->base);
- _pya_free(self->subarray);
- }
- self->ob_type->tp_free((PyObject *)self);
+ Py_XDECREF(self->fields);
+ if (self->subarray) {
+ Py_DECREF(self->subarray->shape);
+ Py_DECREF(self->subarray->base);
+ _pya_free(self->subarray);
+ }
+ self->ob_type->tp_free((PyObject *)self);
}
/* we need to be careful about setting attributes because these
@@ -10237,27 +10237,27 @@
data. Currently no attributes of dtype objects can be set.
*/
static PyMemberDef arraydescr_members[] = {
- {"type", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},
- {"kind", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},
- {"char", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},
- {"num", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},
- {"byteorder", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},
- {"itemsize", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},
- {"alignment", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},
+ {"type", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},
+ {"kind", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},
+ {"char", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},
+ {"num", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},
+ {"byteorder", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},
+ {"itemsize", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},
+ {"alignment", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},
{"hasobject", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},
{"names", T_OBJECT, offsetof(PyArray_Descr, names), RO, NULL},
- {NULL},
+ {NULL},
};
static PyObject *
arraydescr_subdescr_get(PyArray_Descr *self)
{
- if (self->subarray == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return Py_BuildValue("OO", (PyObject *)self->subarray->base,
- self->subarray->shape);
+ if (self->subarray == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return Py_BuildValue("OO", (PyObject *)self->subarray->base,
+ self->subarray->shape);
}
static PyObject *
@@ -10265,16 +10265,16 @@
{
char basic_=self->kind;
char endian = self->byteorder;
- int size=self->elsize;
+ int size=self->elsize;
if (endian == '=') {
endian = '<';
if (!PyArray_IsNativeByteOrder(endian)) endian = '>';
}
- if (self->type_num == PyArray_UNICODE) {
- size >>= 2;
- }
+ if (self->type_num == PyArray_UNICODE) {
+ size >>= 2;
+ }
return PyString_FromFormat("%c%c%d", endian, basic_, size);
}
@@ -10283,33 +10283,33 @@
{
int len;
PyTypeObject *typeobj = self->typeobj;
- PyObject *res;
- static int suffix_len=0;
+ PyObject *res;
+ static int suffix_len=0;
- if (PyTypeNum_ISUSERDEF(self->type_num)) {
- res = PyString_FromString(typeobj->tp_name);
- }
- else {
- if (suffix_len == 0)
- suffix_len = strlen("scalar");
- len = strlen(typeobj->tp_name) - suffix_len;
- res = PyString_FromStringAndSize(typeobj->tp_name, len);
- }
- if (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {
- PyObject *p;
- p = PyString_FromFormat("%d", self->elsize * 8);
- PyString_ConcatAndDel(&res, p);
- }
- return res;
+ if (PyTypeNum_ISUSERDEF(self->type_num)) {
+ res = PyString_FromString(typeobj->tp_name);
+ }
+ else {
+ if (suffix_len == 0)
+ suffix_len = strlen("scalar");
+ len = strlen(typeobj->tp_name) - suffix_len;
+ res = PyString_FromStringAndSize(typeobj->tp_name, len);
+ }
+ if (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {
+ PyObject *p;
+ p = PyString_FromFormat("%d", self->elsize * 8);
+ PyString_ConcatAndDel(&res, p);
+ }
+ return res;
}
static PyObject *
arraydescr_base_get(PyArray_Descr *self)
{
- if (self->subarray == NULL) {
- Py_INCREF(self);
+ if (self->subarray == NULL) {
+ Py_INCREF(self);
return (PyObject *)self;
- }
+ }
Py_INCREF(self->subarray->base);
return (PyObject *)(self->subarray->base);
}
@@ -10317,9 +10317,9 @@
static PyObject *
arraydescr_shape_get(PyArray_Descr *self)
{
- if (self->subarray == NULL) {
+ if (self->subarray == NULL) {
return Py_BuildValue("(N)", PyInt_FromLong(1));
- }
+ }
Py_INCREF(self->subarray->shape);
return (PyObject *)(self->subarray->shape);
}
@@ -10327,23 +10327,23 @@
static PyObject *
arraydescr_protocol_descr_get(PyArray_Descr *self)
{
- PyObject *dobj, *res;
+ PyObject *dobj, *res;
- if (self->names == NULL) {
- /* get default */
- dobj = PyTuple_New(2);
- if (dobj == NULL) return NULL;
- PyTuple_SET_ITEM(dobj, 0, PyString_FromString(""));
- PyTuple_SET_ITEM(dobj, 1, \
- arraydescr_protocol_typestr_get(self));
- res = PyList_New(1);
- if (res == NULL) {Py_DECREF(dobj); return NULL;}
- PyList_SET_ITEM(res, 0, dobj);
- return res;
- }
+ if (self->names == NULL) {
+ /* get default */
+ dobj = PyTuple_New(2);
+ if (dobj == NULL) return NULL;
+ PyTuple_SET_ITEM(dobj, 0, PyString_FromString(""));
+ PyTuple_SET_ITEM(dobj, 1, \
+ arraydescr_protocol_typestr_get(self));
+ res = PyList_New(1);
+ if (res == NULL) {Py_DECREF(dobj); return NULL;}
+ PyList_SET_ITEM(res, 0, dobj);
+ return res;
+ }
return PyObject_CallMethod(_numpy_internal, "_array_descr",
- "O", self);
+ "O", self);
}
/* returns 1 for a builtin type
@@ -10353,71 +10353,71 @@
static PyObject *
arraydescr_isbuiltin_get(PyArray_Descr *self)
{
- long val;
- val = 0;
- if (self->fields == Py_None) val = 1;
- if (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;
- return PyInt_FromLong(val);
+ long val;
+ val = 0;
+ if (self->fields == Py_None) val = 1;
+ if (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;
+ return PyInt_FromLong(val);
}
static PyObject *
arraydescr_isnative_get(PyArray_Descr *self)
{
- PyObject *ret;
+ PyObject *ret;
- ret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);
- Py_INCREF(ret);
- return ret;
+ ret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);
+ Py_INCREF(ret);
+ return ret;
}
static PyObject *
arraydescr_fields_get(PyArray_Descr *self)
{
- if (self->names == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return PyDictProxy_New(self->fields);
+ if (self->names == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyDictProxy_New(self->fields);
}
static PyGetSetDef arraydescr_getsets[] = {
- {"subdtype",
- (getter)arraydescr_subdescr_get,
- NULL,
- "A tuple of (descr, shape) or None."},
- {"descr",
- (getter)arraydescr_protocol_descr_get,
- NULL,
- "The array_protocol type descriptor."},
- {"str",
- (getter)arraydescr_protocol_typestr_get,
- NULL,
- "The array_protocol typestring."},
+ {"subdtype",
+ (getter)arraydescr_subdescr_get,
+ NULL,
+ "A tuple of (descr, shape) or None."},
+ {"descr",
+ (getter)arraydescr_protocol_descr_get,
+ NULL,
+ "The array_protocol type descriptor."},
+ {"str",
+ (getter)arraydescr_protocol_typestr_get,
+ NULL,
+ "The array_protocol typestring."},
{"name",
(getter)arraydescr_typename_get,
NULL,
"The name of the true data-type"},
- {"base",
- (getter)arraydescr_base_get,
- NULL,
- "The base data-type or self if no subdtype"},
+ {"base",
+ (getter)arraydescr_base_get,
+ NULL,
+ "The base data-type or self if no subdtype"},
{"shape",
(getter)arraydescr_shape_get,
NULL,
"The shape of the subdtype or (1,)"},
- {"isbuiltin",
- (getter)arraydescr_isbuiltin_get,
- NULL,
- "Is this a buillt-in data-type descriptor?"},
- {"isnative",
- (getter)arraydescr_isnative_get,
- NULL,
- "Is the byte-order of this descriptor native?"},
- {"fields",
- (getter)arraydescr_fields_get,
- NULL,
- NULL},
- {NULL, NULL, NULL, NULL},
+ {"isbuiltin",
+ (getter)arraydescr_isbuiltin_get,
+ NULL,
+ "Is this a buillt-in data-type descriptor?"},
+ {"isnative",
+ (getter)arraydescr_isnative_get,
+ NULL,
+ "Is the byte-order of this descriptor native?"},
+ {"fields",
+ (getter)arraydescr_fields_get,
+ NULL,
+ NULL},
+ {NULL, NULL, NULL, NULL},
};
static PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);
@@ -10428,82 +10428,82 @@
static PyObject *
arraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
{
- PyObject *odescr;
- PyArray_Descr *descr, *conv;
- int align=0;
- Bool copy=FALSE;
- static char *kwlist[] = {"dtype", "align", "copy", NULL};
+ PyObject *odescr;
+ PyArray_Descr *descr, *conv;
+ int align=0;
+ Bool copy=FALSE;
+ static char *kwlist[] = {"dtype", "align", "copy", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iO&",
- kwlist, &odescr, &align,
- PyArray_BoolConverter, ©))
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iO&",
+ kwlist, &odescr, &align,
+ PyArray_BoolConverter, ©))
+ return NULL;
- if (align) {
- conv = NULL;
- if PyDict_Check(odescr)
- conv = _convert_from_dict(odescr, 1);
- else if PyList_Check(odescr) {
- conv = _convert_from_list(odescr, 1, 0);
- if (conv == NULL) {
- /* There is an errror. Possibly it's
- because we have an array_descriptor.
- Try converting from an array_descriptor.
- If that fails then raise the old error.
- */
- PyObject *type, *value, *traceback;
- PyArray_Descr *temp;
- PyErr_Fetch(&type, &value, &traceback);
- temp = _convert_from_array_descr(odescr);
- if (!PyErr_Occurred()) {
- Py_DECREF(temp);
- Py_XDECREF(type);
- Py_XDECREF(value);
- Py_XDECREF(traceback);
- PyErr_SetString(PyExc_ValueError,
- "align cannot be True" \
- " with array_descriptor " \
- "specification.");
- }
- else {
- PyErr_Restore(type, value, traceback);
- }
- return NULL;
- }
- }
- else if PyString_Check(odescr)
- conv = _convert_from_commastring(odescr, 1);
- else {
- PyErr_SetString(PyExc_ValueError,
- "align can only be non-zero for " \
- "dictionary, list, and string objects.");
- }
- if (conv) return (PyObject *)conv;
- if (!PyErr_Occurred()) {
- PyErr_SetString(PyExc_ValueError,
- "data-type-descriptor not understood");
- }
- return NULL;
- }
+ if (align) {
+ conv = NULL;
+ if PyDict_Check(odescr)
+ conv = _convert_from_dict(odescr, 1);
+ else if PyList_Check(odescr) {
+ conv = _convert_from_list(odescr, 1, 0);
+ if (conv == NULL) {
+ /* There is an errror. Possibly it's
+ because we have an array_descriptor.
+ Try converting from an array_descriptor.
+ If that fails then raise the old error.
+ */
+ PyObject *type, *value, *traceback;
+ PyArray_Descr *temp;
+ PyErr_Fetch(&type, &value, &traceback);
+ temp = _convert_from_array_descr(odescr);
+ if (!PyErr_Occurred()) {
+ Py_DECREF(temp);
+ Py_XDECREF(type);
+ Py_XDECREF(value);
+ Py_XDECREF(traceback);
+ PyErr_SetString(PyExc_ValueError,
+ "align cannot be True" \
+ " with array_descriptor " \
+ "specification.");
+ }
+ else {
+ PyErr_Restore(type, value, traceback);
+ }
+ return NULL;
+ }
+ }
+ else if PyString_Check(odescr)
+ conv = _convert_from_commastring(odescr, 1);
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "align can only be non-zero for " \
+ "dictionary, list, and string objects.");
+ }
+ if (conv) return (PyObject *)conv;
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ValueError,
+ "data-type-descriptor not understood");
+ }
+ return NULL;
+ }
- if PyList_Check(odescr) {
- conv = _convert_from_array_descr(odescr);
- if (!conv) {
- PyErr_Clear();
- conv = _convert_from_list(odescr, 0, 0);
- }
- return (PyObject *)conv;
- }
+ if PyList_Check(odescr) {
+ conv = _convert_from_array_descr(odescr);
+ if (!conv) {
+ PyErr_Clear();
+ conv = _convert_from_list(odescr, 0, 0);
+ }
+ return (PyObject *)conv;
+ }
- if (!PyArray_DescrConverter(odescr, &conv))
- return NULL;
- /* Get a new copy of it unless it's already a copy */
- if (copy && conv->fields == Py_None) {
- descr = PyArray_DescrNew(conv);
- Py_DECREF(conv);
- conv = descr;
- }
- return (PyObject *)conv;
+ if (!PyArray_DescrConverter(odescr, &conv))
+ return NULL;
+ /* Get a new copy of it unless it's already a copy */
+ if (copy && conv->fields == Py_None) {
+ descr = PyArray_DescrNew(conv);
+ Py_DECREF(conv);
+ conv = descr;
+ }
+ return (PyObject *)conv;
}
static char doc_arraydescr_reduce[] = "self.__reduce__() for pickling.";
@@ -10516,70 +10516,70 @@
change the format. Be sure to handle the old versions in
arraydescr_setstate. */
const int version = 2;
- PyObject *ret, *mod, *obj;
- PyObject *state;
- char endian;
- int elsize, alignment;
+ PyObject *ret, *mod, *obj;
+ PyObject *state;
+ char endian;
+ int elsize, alignment;
- ret = PyTuple_New(3);
- if (ret == NULL) return NULL;
- mod = PyImport_ImportModule("numpy.core.multiarray");
- if (mod == NULL) {Py_DECREF(ret); return NULL;}
- obj = PyObject_GetAttrString(mod, "dtype");
- Py_DECREF(mod);
- if (obj == NULL) {Py_DECREF(ret); return NULL;}
- PyTuple_SET_ITEM(ret, 0, obj);
- if (PyTypeNum_ISUSERDEF(self->type_num) || \
- ((self->type_num == PyArray_VOID && \
- self->typeobj != &PyVoidArrType_Type))) {
- obj = (PyObject *)self->typeobj;
- Py_INCREF(obj);
- }
- else {
- elsize = self->elsize;
- if (self->type_num == PyArray_UNICODE) {
- elsize >>= 2;
- }
- obj = PyString_FromFormat("%c%d",self->kind, elsize);
- }
- PyTuple_SET_ITEM(ret, 1, Py_BuildValue("(Nii)", obj, 0, 1));
+ ret = PyTuple_New(3);
+ if (ret == NULL) return NULL;
+ mod = PyImport_ImportModule("numpy.core.multiarray");
+ if (mod == NULL) {Py_DECREF(ret); return NULL;}
+ obj = PyObject_GetAttrString(mod, "dtype");
+ Py_DECREF(mod);
+ if (obj == NULL) {Py_DECREF(ret); return NULL;}
+ PyTuple_SET_ITEM(ret, 0, obj);
+ if (PyTypeNum_ISUSERDEF(self->type_num) || \
+ ((self->type_num == PyArray_VOID && \
+ self->typeobj != &PyVoidArrType_Type))) {
+ obj = (PyObject *)self->typeobj;
+ Py_INCREF(obj);
+ }
+ else {
+ elsize = self->elsize;
+ if (self->type_num == PyArray_UNICODE) {
+ elsize >>= 2;
+ }
+ obj = PyString_FromFormat("%c%d",self->kind, elsize);
+ }
+ PyTuple_SET_ITEM(ret, 1, Py_BuildValue("(Nii)", obj, 0, 1));
- /* Now return the state which is at least
- byteorder, subarray, and fields */
- endian = self->byteorder;
- if (endian == '=') {
- endian = '<';
- if (!PyArray_IsNativeByteOrder(endian)) endian = '>';
- }
- state = PyTuple_New(7);
+ /* Now return the state which is at least
+ byteorder, subarray, and fields */
+ endian = self->byteorder;
+ if (endian == '=') {
+ endian = '<';
+ if (!PyArray_IsNativeByteOrder(endian)) endian = '>';
+ }
+ state = PyTuple_New(7);
PyTuple_SET_ITEM(state, 0, PyInt_FromLong(version));
- PyTuple_SET_ITEM(state, 1, PyString_FromFormat("%c", endian));
- PyTuple_SET_ITEM(state, 2, arraydescr_subdescr_get(self));
- if (self->names) {
+ PyTuple_SET_ITEM(state, 1, PyString_FromFormat("%c", endian));
+ PyTuple_SET_ITEM(state, 2, arraydescr_subdescr_get(self));
+ if (self->names) {
Py_INCREF(self->names);
- Py_INCREF(self->fields);
- PyTuple_SET_ITEM(state, 3, self->names);
+ Py_INCREF(self->fields);
+ PyTuple_SET_ITEM(state, 3, self->names);
PyTuple_SET_ITEM(state, 4, self->fields);
- }
- else {
- PyTuple_SET_ITEM(state, 3, Py_None);
- PyTuple_SET_ITEM(state, 4, Py_None);
- Py_INCREF(Py_None);
+ }
+ else {
+ PyTuple_SET_ITEM(state, 3, Py_None);
+ PyTuple_SET_ITEM(state, 4, Py_None);
Py_INCREF(Py_None);
- }
+ Py_INCREF(Py_None);
+ }
- /* for extended types it also includes elsize and alignment */
- if (PyTypeNum_ISEXTENDED(self->type_num)) {
- elsize = self->elsize;
- alignment = self->alignment;
- }
- else {elsize = -1; alignment = -1;}
+ /* for extended types it also includes elsize and alignment */
+ if (PyTypeNum_ISEXTENDED(self->type_num)) {
+ elsize = self->elsize;
+ alignment = self->alignment;
+ }
+ else {elsize = -1; alignment = -1;}
- PyTuple_SET_ITEM(state, 5, PyInt_FromLong(elsize));
- PyTuple_SET_ITEM(state, 6, PyInt_FromLong(alignment));
+ PyTuple_SET_ITEM(state, 5, PyInt_FromLong(elsize));
+ PyTuple_SET_ITEM(state, 6, PyInt_FromLong(alignment));
- PyTuple_SET_ITEM(ret, 2, state);
- return ret;
+ PyTuple_SET_ITEM(ret, 2, state);
+ return ret;
}
/* returns 1 if this data-type has an object portion
@@ -10589,25 +10589,25 @@
static int
_descr_find_object(PyArray_Descr *self)
{
- if (self->hasobject || self->type_num == PyArray_OBJECT || self->kind == 'O')
- return 1;
+ if (self->hasobject || self->type_num == PyArray_OBJECT || self->kind == 'O')
+ return 1;
if (PyDescr_HASFIELDS(self)) {
PyObject *key, *value, *title=NULL;
PyArray_Descr *new;
int offset, pos=0;
while (PyDict_Next(self->fields, &pos, &key, &value)) {
- if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
- &title)) {
- PyErr_Clear();
- return 0;
- }
- if (_descr_find_object(new)) {
- new->hasobject = 1;
- return 1;
- }
+ if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
+ &title)) {
+ PyErr_Clear();
+ return 0;
+ }
+ if (_descr_find_object(new)) {
+ new->hasobject = 1;
+ return 1;
+ }
}
}
- return 0;
+ return 0;
}
/* state is at least byteorder, subarray, and fields but could include elsize
@@ -10618,20 +10618,20 @@
static PyObject *
arraydescr_setstate(PyArray_Descr *self, PyObject *args)
{
- int elsize = -1, alignment = -1;
+ int elsize = -1, alignment = -1;
int version = 2;
- char endian;
- PyObject *subarray, *fields, *names=NULL;
+ char endian;
+ PyObject *subarray, *fields, *names=NULL;
int incref_names = 1;
- if (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}
+ if (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}
if (!PyArg_ParseTuple(args, "(icOOOii)", &version, &endian, &subarray,
&names, &fields, &elsize, &alignment)) {
PyErr_Clear();
if (!PyArg_ParseTuple(args, "(icOOii)", &version, &endian,
- &subarray, &fields, &elsize,
- &alignment)) {
+ &subarray, &fields, &elsize,
+ &alignment)) {
PyErr_Clear();
version = 0;
if (!PyArg_ParseTuple(args, "(cOOii)", &endian, &subarray,
@@ -10675,43 +10675,43 @@
return NULL;
}
- if (endian != '|' &&
- PyArray_IsNativeByteOrder(endian)) endian = '=';
+ if (endian != '|' &&
+ PyArray_IsNativeByteOrder(endian)) endian = '=';
- self->byteorder = endian;
- if (self->subarray) {
- Py_XDECREF(self->subarray->base);
- Py_XDECREF(self->subarray->shape);
- _pya_free(self->subarray);
- }
- self->subarray = NULL;
+ self->byteorder = endian;
+ if (self->subarray) {
+ Py_XDECREF(self->subarray->base);
+ Py_XDECREF(self->subarray->shape);
+ _pya_free(self->subarray);
+ }
+ self->subarray = NULL;
- if (subarray != Py_None) {
- self->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));
- self->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);
- Py_INCREF(self->subarray->base);
- self->subarray->shape = PyTuple_GET_ITEM(subarray, 1);
- Py_INCREF(self->subarray->shape);
- }
+ if (subarray != Py_None) {
+ self->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));
+ self->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);
+ Py_INCREF(self->subarray->base);
+ self->subarray->shape = PyTuple_GET_ITEM(subarray, 1);
+ Py_INCREF(self->subarray->shape);
+ }
- if (fields != Py_None) {
- Py_XDECREF(self->fields);
- self->fields = fields;
- Py_INCREF(fields);
+ if (fields != Py_None) {
+ Py_XDECREF(self->fields);
+ self->fields = fields;
+ Py_INCREF(fields);
Py_XDECREF(self->names);
self->names = names;
if (incref_names)
Py_INCREF(names);
- }
+ }
- if (PyTypeNum_ISEXTENDED(self->type_num)) {
- self->elsize = elsize;
- self->alignment = alignment;
- }
+ if (PyTypeNum_ISEXTENDED(self->type_num)) {
+ self->elsize = elsize;
+ self->alignment = alignment;
+ }
- self->hasobject = _descr_find_object(self);
- Py_INCREF(Py_None);
- return Py_None;
+ self->hasobject = _descr_find_object(self);
+ Py_INCREF(Py_None);
+ return Py_None;
}
@@ -10722,10 +10722,10 @@
(in all subfields as well)
Valid states: ('big', '>') or ('little' or '<')
- ('native', or '=')
+ ('native', or '=')
- If a descr structure with | is encountered it's own
- byte-order is not changed but any fields are:
+ If a descr structure with | is encountered it's own
+ byte-order is not changed but any fields are:
*/
/*OBJECT_API
@@ -10735,156 +10735,156 @@
static PyArray_Descr *
PyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)
{
- PyArray_Descr *new;
- char endian;
+ PyArray_Descr *new;
+ char endian;
- new = PyArray_DescrNew(self);
- endian = new->byteorder;
- if (endian != PyArray_IGNORE) {
- if (newendian == PyArray_SWAP) { /* swap byteorder */
- if PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;
- else endian = PyArray_NATBYTE;
- new->byteorder = endian;
- }
- else if (newendian != PyArray_IGNORE) {
- new->byteorder = newendian;
- }
- }
- if (new->names) {
- PyObject *newfields;
- PyObject *key, *value;
- PyObject *newvalue;
- PyObject *old;
- PyArray_Descr *newdescr;
- int pos = 0, len, i;
- newfields = PyDict_New();
- /* make new dictionary with replaced */
- /* PyArray_Descr Objects */
- while(PyDict_Next(self->fields, &pos, &key, &value)) {
- if (!PyString_Check(key) || \
- !PyTuple_Check(value) || \
- ((len=PyTuple_GET_SIZE(value)) < 2))
- continue;
+ new = PyArray_DescrNew(self);
+ endian = new->byteorder;
+ if (endian != PyArray_IGNORE) {
+ if (newendian == PyArray_SWAP) { /* swap byteorder */
+ if PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;
+ else endian = PyArray_NATBYTE;
+ new->byteorder = endian;
+ }
+ else if (newendian != PyArray_IGNORE) {
+ new->byteorder = newendian;
+ }
+ }
+ if (new->names) {
+ PyObject *newfields;
+ PyObject *key, *value;
+ PyObject *newvalue;
+ PyObject *old;
+ PyArray_Descr *newdescr;
+ int pos = 0, len, i;
+ newfields = PyDict_New();
+ /* make new dictionary with replaced */
+ /* PyArray_Descr Objects */
+ while(PyDict_Next(self->fields, &pos, &key, &value)) {
+ if (!PyString_Check(key) || \
+ !PyTuple_Check(value) || \
+ ((len=PyTuple_GET_SIZE(value)) < 2))
+ continue;
- old = PyTuple_GET_ITEM(value, 0);
- if (!PyArray_DescrCheck(old)) continue;
- newdescr = PyArray_DescrNewByteorder \
- ((PyArray_Descr *)old, newendian);
- if (newdescr == NULL) {
- Py_DECREF(newfields); Py_DECREF(new);
- return NULL;
- }
- newvalue = PyTuple_New(len);
- PyTuple_SET_ITEM(newvalue, 0, \
- (PyObject *)newdescr);
- for(i=1; i<len; i++) {
- old = PyTuple_GET_ITEM(value, i);
- Py_INCREF(old);
- PyTuple_SET_ITEM(newvalue, i, old);
- }
- PyDict_SetItem(newfields, key, newvalue);
- Py_DECREF(newvalue);
- }
- Py_DECREF(new->fields);
- new->fields = newfields;
- }
- if (new->subarray) {
- Py_DECREF(new->subarray->base);
- new->subarray->base = PyArray_DescrNewByteorder \
- (self->subarray->base, newendian);
- }
- return new;
+ old = PyTuple_GET_ITEM(value, 0);
+ if (!PyArray_DescrCheck(old)) continue;
+ newdescr = PyArray_DescrNewByteorder \
+ ((PyArray_Descr *)old, newendian);
+ if (newdescr == NULL) {
+ Py_DECREF(newfields); Py_DECREF(new);
+ return NULL;
+ }
+ newvalue = PyTuple_New(len);
+ PyTuple_SET_ITEM(newvalue, 0, \
+ (PyObject *)newdescr);
+ for(i=1; i<len; i++) {
+ old = PyTuple_GET_ITEM(value, i);
+ Py_INCREF(old);
+ PyTuple_SET_ITEM(newvalue, i, old);
+ }
+ PyDict_SetItem(newfields, key, newvalue);
+ Py_DECREF(newvalue);
+ }
+ Py_DECREF(new->fields);
+ new->fields = newfields;
+ }
+ if (new->subarray) {
+ Py_DECREF(new->subarray->base);
+ new->subarray->base = PyArray_DescrNewByteorder \
+ (self->subarray->base, newendian);
+ }
+ return new;
}
static char doc_arraydescr_newbyteorder[] = "self.newbyteorder(<endian>)"
- " returns a copy of the dtype object\n"
- " with altered byteorders. If <endian> is not given all byteorders\n"
- " are swapped. Otherwise endian can be '>', '<', or '=' to force\n"
- " a byteorder. Descriptors in all fields are also updated in the\n"
- " new dtype object.";
+ " returns a copy of the dtype object\n"
+ " with altered byteorders. If <endian> is not given all byteorders\n"
+ " are swapped. Otherwise endian can be '>', '<', or '=' to force\n"
+ " a byteorder. Descriptors in all fields are also updated in the\n"
+ " new dtype object.";
static PyObject *
arraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)
{
- char endian=PyArray_SWAP;
+ char endian=PyArray_SWAP;
- if (!PyArg_ParseTuple(args, "|O&", PyArray_ByteorderConverter,
- &endian)) return NULL;
+ if (!PyArg_ParseTuple(args, "|O&", PyArray_ByteorderConverter,
+ &endian)) return NULL;
- return (PyObject *)PyArray_DescrNewByteorder(self, endian);
+ return (PyObject *)PyArray_DescrNewByteorder(self, endian);
}
static PyMethodDef arraydescr_methods[] = {
/* for pickling */
{"__reduce__", (PyCFunction)arraydescr_reduce, METH_VARARGS,
- doc_arraydescr_reduce},
- {"__setstate__", (PyCFunction)arraydescr_setstate, METH_VARARGS,
- doc_arraydescr_setstate},
+ doc_arraydescr_reduce},
+ {"__setstate__", (PyCFunction)arraydescr_setstate, METH_VARARGS,
+ doc_arraydescr_setstate},
- {"newbyteorder", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,
- doc_arraydescr_newbyteorder},
- {NULL, NULL} /* sentinel */
+ {"newbyteorder", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,
+ doc_arraydescr_newbyteorder},
+ {NULL, NULL} /* sentinel */
};
static PyObject *
arraydescr_str(PyArray_Descr *self)
{
- PyObject *sub;
+ PyObject *sub;
- if (self->names) {
- PyObject *lst;
- lst = arraydescr_protocol_descr_get(self);
- if (!lst) {
- sub = PyString_FromString("<err>");
- PyErr_Clear();
- }
- else sub = PyObject_Str(lst);
- Py_XDECREF(lst);
- if (self->type_num != PyArray_VOID) {
- PyObject *p;
- PyObject *t=PyString_FromString("'");
- p = arraydescr_protocol_typestr_get(self);
- PyString_Concat(&p, t);
- PyString_ConcatAndDel(&t, p);
- p = PyString_FromString("(");
- PyString_ConcatAndDel(&p, t);
- PyString_ConcatAndDel(&p, PyString_FromString(", "));
- PyString_ConcatAndDel(&p, sub);
- PyString_ConcatAndDel(&p, PyString_FromString(")"));
- sub = p;
- }
- }
- else if (self->subarray) {
- PyObject *p;
- PyObject *t = PyString_FromString("(");
- p = arraydescr_str(self->subarray->base);
- PyString_ConcatAndDel(&t, p);
- PyString_ConcatAndDel(&t, PyString_FromString(","));
- PyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));
- PyString_ConcatAndDel(&t, PyString_FromString(")"));
- sub = t;
- }
- else {
- PyObject *t=PyString_FromString("'");
- sub = arraydescr_protocol_typestr_get(self);
- PyString_Concat(&sub, t);
- PyString_ConcatAndDel(&t, sub);
- sub = t;
- }
- return sub;
+ if (self->names) {
+ PyObject *lst;
+ lst = arraydescr_protocol_descr_get(self);
+ if (!lst) {
+ sub = PyString_FromString("<err>");
+ PyErr_Clear();
+ }
+ else sub = PyObject_Str(lst);
+ Py_XDECREF(lst);
+ if (self->type_num != PyArray_VOID) {
+ PyObject *p;
+ PyObject *t=PyString_FromString("'");
+ p = arraydescr_protocol_typestr_get(self);
+ PyString_Concat(&p, t);
+ PyString_ConcatAndDel(&t, p);
+ p = PyString_FromString("(");
+ PyString_ConcatAndDel(&p, t);
+ PyString_ConcatAndDel(&p, PyString_FromString(", "));
+ PyString_ConcatAndDel(&p, sub);
+ PyString_ConcatAndDel(&p, PyString_FromString(")"));
+ sub = p;
+ }
+ }
+ else if (self->subarray) {
+ PyObject *p;
+ PyObject *t = PyString_FromString("(");
+ p = arraydescr_str(self->subarray->base);
+ PyString_ConcatAndDel(&t, p);
+ PyString_ConcatAndDel(&t, PyString_FromString(","));
+ PyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));
+ PyString_ConcatAndDel(&t, PyString_FromString(")"));
+ sub = t;
+ }
+ else {
+ PyObject *t=PyString_FromString("'");
+ sub = arraydescr_protocol_typestr_get(self);
+ PyString_Concat(&sub, t);
+ PyString_ConcatAndDel(&t, sub);
+ sub = t;
+ }
+ return sub;
}
static PyObject *
arraydescr_repr(PyArray_Descr *self)
{
- PyObject *sub, *s;
- s = PyString_FromString("dtype(");
+ PyObject *sub, *s;
+ s = PyString_FromString("dtype(");
sub = arraydescr_str(self);
- PyString_ConcatAndDel(&s, sub);
- sub = PyString_FromString(")");
- PyString_ConcatAndDel(&s, sub);
- return s;
+ PyString_ConcatAndDel(&s, sub);
+ sub = PyString_FromString(")");
+ PyString_ConcatAndDel(&s, sub);
+ return s;
}
static PyObject *
@@ -10892,10 +10892,10 @@
{
PyArray_Descr *new=NULL;
PyObject *result = Py_NotImplemented;
- if (!PyArray_DescrCheck(other)) {
+ if (!PyArray_DescrCheck(other)) {
if (PyArray_DescrConverter(other, &new) == PY_FAIL)
return NULL;
- }
+ }
else {
new = (PyArray_Descr *)other;
Py_INCREF(new);
@@ -10955,35 +10955,35 @@
static Py_ssize_t
descr_length(PyObject *self0)
{
-
- PyArray_Descr *self = (PyArray_Descr *)self0;
+
+ PyArray_Descr *self = (PyArray_Descr *)self0;
- if (self->names)
+ if (self->names)
return PyDict_Size(self->fields);
- else return 0;
+ else return 0;
}
static PyObject *
descr_subscript(PyArray_Descr *self, PyObject *op)
{
- if (self->names) {
- if (PyString_Check(op) || PyUnicode_Check(op)) {
- PyObject *obj;
- obj = PyDict_GetItem(self->fields, op);
- if (obj != NULL) {
- PyObject *descr;
- descr = PyTuple_GET_ITEM(obj, 0);
- Py_INCREF(descr);
- return descr;
- }
- else {
- PyErr_Format(PyExc_KeyError,
- "field named \'%s\' not found.",
- PyString_AsString(op));
- }
- }
- else {
+ if (self->names) {
+ if (PyString_Check(op) || PyUnicode_Check(op)) {
+ PyObject *obj;
+ obj = PyDict_GetItem(self->fields, op);
+ if (obj != NULL) {
+ PyObject *descr;
+ descr = PyTuple_GET_ITEM(obj, 0);
+ Py_INCREF(descr);
+ return descr;
+ }
+ else {
+ PyErr_Format(PyExc_KeyError,
+ "field named \'%s\' not found.",
+ PyString_AsString(op));
+ }
+ }
+ else {
PyObject *name;
int value;
value = PyArray_PyIntAsInt(op);
@@ -11004,21 +11004,21 @@
"only integers, strings or unicode values allowed " \
"for getting fields.");
}
- else {
+ else {
PyObject *astr;
astr = arraydescr_str(self);
- PyErr_Format(PyExc_KeyError,
- "there are no fields in dtype %s.",
- PyString_AsString(astr));
+ PyErr_Format(PyExc_KeyError,
+ "there are no fields in dtype %s.",
+ PyString_AsString(astr));
Py_DECREF(astr);
- }
- return NULL;
+ }
+ return NULL;
}
static PyMappingMethods descr_as_mapping = {
- descr_length, /*mp_length*/
- (binaryfunc)descr_subscript, /*mp_subscript*/
- (objobjargproc)NULL, /*mp_ass_subscript*/
+ descr_length, /*mp_length*/
+ (binaryfunc)descr_subscript, /*mp_subscript*/
+ (objobjargproc)NULL, /*mp_ass_subscript*/
};
/****************** End of Mapping Protocol ******************************/
@@ -11026,52 +11026,52 @@
static PyTypeObject PyArrayDescr_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "numpy.dtype", /* tp_name */
+ 0, /* ob_size */
+ "numpy.dtype", /* tp_name */
sizeof(PyArray_Descr), /* tp_basicsize */
- 0, /* tp_itemsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor)arraydescr_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- (reprfunc)arraydescr_repr, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- &descr_as_mapping, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
+ (destructor)arraydescr_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ (reprfunc)arraydescr_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ &descr_as_mapping, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
(reprfunc)arraydescr_str, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
(richcmpfunc)arraydescr_richcompare, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- arraydescr_methods, /* tp_methods */
- arraydescr_members, /* tp_members */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ arraydescr_methods, /* tp_methods */
+ arraydescr_members, /* tp_members */
arraydescr_getsets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- arraydescr_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
- 0, /* tp_mro */
- 0, /* tp_cache */
- 0, /* tp_subclasses */
- 0 /* tp_weaklist */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ arraydescr_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0 /* tp_weaklist */
};
@@ -11109,8 +11109,8 @@
static void
arrayflags_dealloc(PyArrayFlagsObject *self)
{
- Py_XDECREF(self->arr);
- self->ob_type->tp_free((PyObject *)self);
+ Py_XDECREF(self->arr);
+ self->ob_type->tp_free((PyObject *)self);
}
@@ -11236,10 +11236,10 @@
static PyGetSetDef arrayflags_getsets[] = {
- {"contiguous",
- (getter)arrayflags_contiguous_get,
- NULL,
- ""},
+ {"contiguous",
+ (getter)arrayflags_contiguous_get,
+ NULL,
+ ""},
{"fortran",
(getter)arrayflags_fortran_get,
NULL,
@@ -11284,7 +11284,7 @@
(getter)arrayflags_num_get,
NULL,
""},
- {NULL, NULL, NULL, NULL},
+ {NULL, NULL, NULL, NULL},
};
static PyObject *
@@ -11295,70 +11295,70 @@
if (!PyString_Check(ind)) goto fail;
key = PyString_AS_STRING(ind);
n = PyString_GET_SIZE(ind);
- switch(n) {
- case 1:
- switch(key[0]) {
- case 'C':
- return arrayflags_contiguous_get(self);
- case 'F':
- return arrayflags_fortran_get(self);
- case 'W':
- return arrayflags_writeable_get(self);
- case 'B':
- return arrayflags_behaved_get(self);
- case 'O':
- return arrayflags_owndata_get(self);
- case 'A':
- return arrayflags_aligned_get(self);
- case 'U':
- return arrayflags_updateifcopy_get(self);
- default:
- goto fail;
- }
- break;
- case 2:
- if (strncmp(key, "CA", n)==0)
- return arrayflags_carray_get(self);
- if (strncmp(key, "FA", n)==0)
- return arrayflags_farray_get(self);
- break;
- case 3:
- if (strncmp(key, "FNC", n)==0)
- return arrayflags_fnc_get(self);
- break;
- case 4:
- if (strncmp(key, "FORC", n)==0)
- return arrayflags_forc_get(self);
- break;
- case 6:
- if (strncmp(key, "CARRAY", n)==0)
- return arrayflags_carray_get(self);
- if (strncmp(key, "FARRAY", n)==0)
- return arrayflags_farray_get(self);
- break;
- case 7:
- if (strncmp(key,"FORTRAN",n)==0)
- return arrayflags_fortran_get(self);
- if (strncmp(key,"BEHAVED",n)==0)
- return arrayflags_behaved_get(self);
- if (strncmp(key,"OWNDATA",n)==0)
- return arrayflags_owndata_get(self);
- if (strncmp(key,"ALIGNED",n)==0)
- return arrayflags_aligned_get(self);
- break;
- case 9:
- if (strncmp(key,"WRITEABLE",n)==0)
- return arrayflags_writeable_get(self);
- break;
- case 10:
- if (strncmp(key,"CONTIGUOUS",n)==0)
- return arrayflags_contiguous_get(self);
- break;
- case 12:
- if (strncmp(key, "UPDATEIFCOPY", n)==0)
- return arrayflags_updateifcopy_get(self);
- break;
- }
+ switch(n) {
+ case 1:
+ switch(key[0]) {
+ case 'C':
+ return arrayflags_contiguous_get(self);
+ case 'F':
+ return arrayflags_fortran_get(self);
+ case 'W':
+ return arrayflags_writeable_get(self);
+ case 'B':
+ return arrayflags_behaved_get(self);
+ case 'O':
+ return arrayflags_owndata_get(self);
+ case 'A':
+ return arrayflags_aligned_get(self);
+ case 'U':
+ return arrayflags_updateifcopy_get(self);
+ default:
+ goto fail;
+ }
+ break;
+ case 2:
+ if (strncmp(key, "CA", n)==0)
+ return arrayflags_carray_get(self);
+ if (strncmp(key, "FA", n)==0)
+ return arrayflags_farray_get(self);
+ break;
+ case 3:
+ if (strncmp(key, "FNC", n)==0)
+ return arrayflags_fnc_get(self);
+ break;
+ case 4:
+ if (strncmp(key, "FORC", n)==0)
+ return arrayflags_forc_get(self);
+ break;
+ case 6:
+ if (strncmp(key, "CARRAY", n)==0)
+ return arrayflags_carray_get(self);
+ if (strncmp(key, "FARRAY", n)==0)
+ return arrayflags_farray_get(self);
+ break;
+ case 7:
+ if (strncmp(key,"FORTRAN",n)==0)
+ return arrayflags_fortran_get(self);
+ if (strncmp(key,"BEHAVED",n)==0)
+ return arrayflags_behaved_get(self);
+ if (strncmp(key,"OWNDATA",n)==0)
+ return arrayflags_owndata_get(self);
+ if (strncmp(key,"ALIGNED",n)==0)
+ return arrayflags_aligned_get(self);
+ break;
+ case 9:
+ if (strncmp(key,"WRITEABLE",n)==0)
+ return arrayflags_writeable_get(self);
+ break;
+ case 10:
+ if (strncmp(key,"CONTIGUOUS",n)==0)
+ return arrayflags_contiguous_get(self);
+ break;
+ case 12:
+ if (strncmp(key, "UPDATEIFCOPY", n)==0)
+ return arrayflags_updateifcopy_get(self);
+ break;
+ }
fail:
PyErr_SetString(PyExc_KeyError, "Unknown flag");
@@ -11374,7 +11374,7 @@
key = PyString_AS_STRING(ind);
n = PyString_GET_SIZE(ind);
if (((n==9) && (strncmp(key, "WRITEABLE", n)==0)) ||
- ((n==1) && (strncmp(key, "W", n)==0)))
+ ((n==1) && (strncmp(key, "W", n)==0)))
return arrayflags_writeable_set(self, item);
else if (((n==7) && (strncmp(key, "ALIGNED", n)==0)) ||
((n==1) && (strncmp(key, "A", n)==0)))
@@ -11413,11 +11413,11 @@
static PyMappingMethods arrayflags_as_mapping = {
#if PY_VERSION_HEX >= 0x02050000
- (lenfunc)NULL, /*mp_length*/
+ (lenfunc)NULL, /*mp_length*/
#else
- (inquiry)NULL, /*mp_length*/
+ (inquiry)NULL, /*mp_length*/
#endif
- (binaryfunc)arrayflags_getitem, /*mp_subscript*/
+ (binaryfunc)arrayflags_getitem, /*mp_subscript*/
(objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/
};
@@ -11442,47 +11442,47 @@
0,
"numpy.flagsobj",
sizeof(PyArrayFlagsObject),
- 0, /* tp_itemsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor)arrayflags_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
+ (destructor)arrayflags_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
(reprfunc)arrayflags_print, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- &arrayflags_as_mapping, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ &arrayflags_as_mapping, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
(reprfunc)arrayflags_print, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- 0, /* tp_methods */
- 0, /* tp_members */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
arrayflags_getsets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- arrayflags_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
- 0, /* tp_bases */
- 0, /* tp_mro */
- 0, /* tp_cache */
- 0, /* tp_subclasses */
- 0 /* tp_weaklist */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ arrayflags_new, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0 /* tp_weaklist */
};
Modified: branches/ver1.0/numpy/core/src/arraytypes.inc.src
===================================================================
--- branches/ver1.0/numpy/core/src/arraytypes.inc.src 2006-07-26 12:29:49 UTC (rev 2897)
+++ branches/ver1.0/numpy/core/src/arraytypes.inc.src 2006-07-26 16:25:14 UTC (rev 2898)
@@ -7,19 +7,19 @@
static @type@
MyPyLong_As at name@(PyObject *vv)
{
- @type@ ret;
+ @type@ ret;
- if (!PyLong_Check(vv)) {
- PyObject *mylong;
- mylong = PyNumber_Long(vv);
- if (mylong == NULL) return (@type@) -1;
- vv = mylong;
- }
- else Py_INCREF(vv);
+ if (!PyLong_Check(vv)) {
+ PyObject *mylong;
+ mylong = PyNumber_Long(vv);
+ if (mylong == NULL) return (@type@) -1;
+ vv = mylong;
+ }
+ else Py_INCREF(vv);
- ret = PyLong_As at name@(vv);
- Py_DECREF(vv);
- return ret;
+ ret = PyLong_As at name@(vv);
+ Py_DECREF(vv);
+ return ret;
}
/**end repeat**/
@@ -32,9 +32,9 @@
static double nan=0;
if (nan == 0) {
- double mul = 1e100;
- double tmp = 0.0;
- double pinf=0;
+ double mul = 1e100;
+ double tmp = 0.0;
+ double pinf=0;
pinf = mul;
for (;;) {
pinf *= mul;
@@ -71,15 +71,15 @@
@TYP at _getitem(char *ip, PyArrayObject *ap) {
@typ@ t1;
- if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {
+ if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {
t1 = *((@typ@ *)ip);
return @func1@((@typ1@)t1);
- }
- else {
+ }
+ else {
ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),
- ap);
+ ap);
return @func1@((@typ1@)t1);
- }
+ }
}
static int
@@ -97,7 +97,7 @@
*((@typ@ *)ov)=temp;
else {
ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap),
- ap);
+ ap);
}
return 0;
@@ -121,8 +121,8 @@
(double)((@typ@ *)ip)[1]);
}
else {
- int size = sizeof(@typ@);
- Bool swap = !PyArray_ISNOTSWAPPED(ap);
+ int size = sizeof(@typ@);
+ Bool swap = !PyArray_ISNOTSWAPPED(ap);
copy_and_swap(&t1, ip, size, 1, 0, swap);
copy_and_swap(&t2, ip+size, size, 1, 0, swap);
return PyComplex_FromDoubles((double)t1, (double)t2);
@@ -142,15 +142,15 @@
Py_complex oop;
PyObject *op2;
c at typ@ temp;
- int rsize;
+ int rsize;
if (!(PyArray_IsScalar(op, @kind@))) {
if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {
op2 = ((PyArrayObject *)op)->descr->f->getitem \
(((PyArrayObject *)op)->data,
(PyArrayObject *)op);
- }
- else {
+ }
+ else {
op2 = op; Py_INCREF(op);
}
if (op2 == Py_None) {
@@ -164,16 +164,16 @@
temp.real = (@typ@) oop.real;
temp.imag = (@typ@) oop.imag;
}
- else {
+ else {
temp = ((Py at kind@ScalarObject *)op)->obval;
}
-
+
memcpy(ov, &temp, ap->descr->elsize);
if (!PyArray_ISNOTSWAPPED(ap))
byte_swap_vector(ov, 2, sizeof(@typ@));
-
- rsize = sizeof(@typ@);
- copy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));
+
+ rsize = sizeof(@typ@);
+ copy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));
return 0;
}
/**end repeat**/
@@ -181,7 +181,7 @@
static PyObject *
LONGDOUBLE_getitem(char *ip, PyArrayObject *ap)
{
- return PyArray_Scalar(ip, ap->descr, NULL);
+ return PyArray_Scalar(ip, ap->descr, NULL);
}
static int
@@ -192,10 +192,10 @@
temp = ((PyLongDoubleScalarObject *)op)->obval;
}
else {
- temp = (longdouble) MyPyFloat_AsDouble(op);
+ temp = (longdouble) MyPyFloat_AsDouble(op);
}
if (PyErr_Occurred()) return -1;
- if (ap == NULL || PyArray_ISBEHAVED(ap))
+ if (ap == NULL || PyArray_ISBEHAVED(ap))
*((longdouble *)ov)=temp;
else {
copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,
@@ -215,125 +215,125 @@
static PyObject *
UNICODE_getitem(char *ip, PyArrayObject *ap)
{
- PyObject *obj;
- int mysize;
- PyArray_UCS4 *dptr;
- char *buffer;
- int alloc=0;
+ PyObject *obj;
+ int mysize;
+ PyArray_UCS4 *dptr;
+ char *buffer;
+ int alloc=0;
- mysize = ap->descr->elsize >> 2;
- dptr = (PyArray_UCS4 *)ip + mysize-1;
- while(mysize > 0 && *dptr-- == 0) mysize--;
- if (!PyArray_ISBEHAVED(ap)) {
- buffer = _pya_malloc(mysize << 2);
- if (buffer == NULL)
- return PyErr_NoMemory();
- alloc = 1;
- memcpy(buffer, ip, mysize << 2);
- if (!PyArray_ISNOTSWAPPED(ap)) {
- byte_swap_vector(buffer, mysize, 4);
- }
- }
- else buffer = ip;
+ mysize = ap->descr->elsize >> 2;
+ dptr = (PyArray_UCS4 *)ip + mysize-1;
+ while(mysize > 0 && *dptr-- == 0) mysize--;
+ if (!PyArray_ISBEHAVED(ap)) {
+ buffer = _pya_malloc(mysize << 2);
+ if (buffer == NULL)
+ return PyErr_NoMemory();
+ alloc = 1;
+ memcpy(buffer, ip, mysize << 2);
+ if (!PyArray_ISNOTSWAPPED(ap)) {
+ byte_swap_vector(buffer, mysize, 4);
+ }
+ }
+ else buffer = ip;
#ifdef Py_UNICODE_WIDE
- obj = PyUnicode_FromUnicode((const Py_UNICODE *)buffer, mysize);
+ obj = PyUnicode_FromUnicode((const Py_UNICODE *)buffer, mysize);
#else
- /* create new empty unicode object of length mysize*2 */
- obj = MyPyUnicode_New(mysize*2);
- if (obj == NULL) {if (alloc) _pya_free(buffer); return obj;}
- mysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str,
- (PyArray_UCS4 *)buffer, mysize);
- /* reset length of unicode object to ucs2size */
- if (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {
- if (alloc) _pya_free(buffer);
- Py_DECREF(obj);
- return NULL;
- }
+ /* create new empty unicode object of length mysize*2 */
+ obj = MyPyUnicode_New(mysize*2);
+ if (obj == NULL) {if (alloc) _pya_free(buffer); return obj;}
+ mysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str,
+ (PyArray_UCS4 *)buffer, mysize);
+ /* reset length of unicode object to ucs2size */
+ if (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {
+ if (alloc) _pya_free(buffer);
+ Py_DECREF(obj);
+ return NULL;
+ }
#endif
- if (alloc) _pya_free(buffer);
-
- return obj;
+ if (alloc) _pya_free(buffer);
+
+ return obj;
}
static int
UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap)
{
PyObject *temp;
- Py_UNICODE *ptr;
- int datalen;
+ Py_UNICODE *ptr;
+ int datalen;
#ifndef Py_UNICODE_WIDE
- char *buffer;
-#endif
+ char *buffer;
+#endif
- if ((temp=PyObject_Unicode(op)) == NULL) return -1;
- ptr = PyUnicode_AS_UNICODE(temp);
- if ((ptr == NULL) || (PyErr_Occurred())) {
- Py_DECREF(temp);
- return -1;
- }
- datalen = PyUnicode_GET_DATA_SIZE(temp);
+ if ((temp=PyObject_Unicode(op)) == NULL) return -1;
+ ptr = PyUnicode_AS_UNICODE(temp);
+ if ((ptr == NULL) || (PyErr_Occurred())) {
+ Py_DECREF(temp);
+ return -1;
+ }
+ datalen = PyUnicode_GET_DATA_SIZE(temp);
#ifdef Py_UNICODE_WIDE
- memcpy(ov, ptr, MIN(ap->descr->elsize, datalen));
+ memcpy(ov, ptr, MIN(ap->descr->elsize, datalen));
#else
- if (!PyArray_ISALIGNED(ap)) {
- buffer = _pya_malloc(ap->descr->elsize);
- if (buffer == NULL) {
- Py_DECREF(temp);
- PyErr_NoMemory();
- return -1;
- }
- }
- else buffer = ov;
+ if (!PyArray_ISALIGNED(ap)) {
+ buffer = _pya_malloc(ap->descr->elsize);
+ if (buffer == NULL) {
+ Py_DECREF(temp);
+ PyErr_NoMemory();
+ return -1;
+ }
+ }
+ else buffer = ov;
datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)buffer,
- datalen >> 1,
- ap->descr->elsize >> 2);
- datalen <<= 2;
- if (!PyArray_ISALIGNED(ap)) {
- memcpy(ov, buffer, datalen);
- _pya_free(buffer);
- }
+ datalen >> 1,
+ ap->descr->elsize >> 2);
+ datalen <<= 2;
+ if (!PyArray_ISALIGNED(ap)) {
+ memcpy(ov, buffer, datalen);
+ _pya_free(buffer);
+ }
#endif
- /* Fill in the rest of the space with 0 */
- if (ap->descr->elsize > datalen) {
- memset(ov + datalen, 0, (ap->descr->elsize - datalen));
- }
-
- if (!PyArray_ISNOTSWAPPED(ap))
- byte_swap_vector(ov, ap->descr->elsize >> 2, 4);
- Py_DECREF(temp);
- return 0;
+ /* Fill in the rest of the space with 0 */
+ if (ap->descr->elsize > datalen) {
+ memset(ov + datalen, 0, (ap->descr->elsize - datalen));
+ }
+
+ if (!PyArray_ISNOTSWAPPED(ap))
+ byte_swap_vector(ov, ap->descr->elsize >> 2, 4);
+ Py_DECREF(temp);
+ return 0;
}
/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */
static PyObject *
STRING_getitem(char *ip, PyArrayObject *ap)
{
- if (ip[ap->descr->elsize-1])
- return PyString_FromStringAndSize(ip,ap->descr->elsize);
- else
- return PyString_FromString(ip);
+ if (ip[ap->descr->elsize-1])
+ return PyString_FromStringAndSize(ip,ap->descr->elsize);
+ else
+ return PyString_FromString(ip);
}
static int
STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap)
{
- char *ptr;
- int len;
- PyObject *temp=PyObject_Str(op);
-
- if (temp == NULL) return -1;
-
- if (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {
- Py_DECREF(temp);
- return -1;
- }
- memcpy(ov, ptr, MIN(ap->descr->elsize,len));
- if (ap->descr->elsize > len) {
- memset(ov + len, 0, (ap->descr->elsize - len));
- }
- Py_DECREF(temp);
- return 0;
+ char *ptr;
+ int len;
+ PyObject *temp=PyObject_Str(op);
+
+ if (temp == NULL) return -1;
+
+ if (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {
+ Py_DECREF(temp);
+ return -1;
+ }
+ memcpy(ov, ptr, MIN(ap->descr->elsize,len));
+ if (ap->descr->elsize > len) {
+ memset(ov + len, 0, (ap->descr->elsize - len));
+ }
+ Py_DECREF(temp);
+ return 0;
}
/* OBJECT */
@@ -368,7 +368,7 @@
Py_XDECREF(*obj);
memcpy(ov, &op, sizeof(PyObject *));
}
- return PyErr_Occurred() ? -1:0;
+ return PyErr_Occurred() ? -1:0;
}
/* VOID */
@@ -377,94 +377,94 @@
VOID_getitem(char *ip, PyArrayObject *ap)
{
PyObject *u=NULL;
- PyArray_Descr* descr;
+ PyArray_Descr* descr;
int itemsize;
- descr = ap->descr;
- if (descr->names) {
- PyObject *key;
- PyObject *names;
- int i, n;
- PyObject *ret;
- PyObject *tup, *title;
- PyArray_Descr *new;
- int offset;
- int savedflags;
+ descr = ap->descr;
+ if (descr->names) {
+ PyObject *key;
+ PyObject *names;
+ int i, n;
+ PyObject *ret;
+ PyObject *tup, *title;
+ PyArray_Descr *new;
+ int offset;
+ int savedflags;
- /* get the names from the fields dictionary*/
+ /* get the names from the fields dictionary*/
names = descr->names;
- if (!names) goto finish;
- n = PyTuple_GET_SIZE(names);
- ret = PyTuple_New(n);
- savedflags = ap->flags;
- for (i=0; i<n; i++) {
- key = PyTuple_GET_ITEM(names, i);
- tup = PyDict_GetItem(descr->fields, key);
- if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset,
- &title)) {
- Py_DECREF(ret);
+ if (!names) goto finish;
+ n = PyTuple_GET_SIZE(names);
+ ret = PyTuple_New(n);
+ savedflags = ap->flags;
+ for (i=0; i<n; i++) {
+ key = PyTuple_GET_ITEM(names, i);
+ tup = PyDict_GetItem(descr->fields, key);
+ if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset,
+ &title)) {
+ Py_DECREF(ret);
ap->descr = descr;
- return NULL;
- }
- ap->descr = new;
- /* update alignment based on offset */
- if ((new->alignment > 1) && \
- ((((intp)(ip+offset)) % new->alignment) != 0))
- ap->flags &= ~ALIGNED;
- else
- ap->flags |= ALIGNED;
+ return NULL;
+ }
+ ap->descr = new;
+ /* update alignment based on offset */
+ if ((new->alignment > 1) && \
+ ((((intp)(ip+offset)) % new->alignment) != 0))
+ ap->flags &= ~ALIGNED;
+ else
+ ap->flags |= ALIGNED;
- PyTuple_SET_ITEM(ret, i, \
- new->f->getitem(ip+offset, ap));
- ap->flags = savedflags;
- }
- ap->descr = descr;
- return ret;
- }
+ PyTuple_SET_ITEM(ret, i, \
+ new->f->getitem(ip+offset, ap));
+ ap->flags = savedflags;
+ }
+ ap->descr = descr;
+ return ret;
+ }
- if (descr->subarray) {
- /* return an array of the basic type */
- PyArray_Dims shape={NULL,-1};
- PyObject *ret;
- if (!(PyArray_IntpConverter(descr->subarray->shape,
- &shape))) {
- PyDimMem_FREE(shape.ptr);
- PyErr_SetString(PyExc_ValueError,
- "invalid shape in fixed-type tuple.");
- return NULL;
- }
+ if (descr->subarray) {
+ /* return an array of the basic type */
+ PyArray_Dims shape={NULL,-1};
+ PyObject *ret;
+ if (!(PyArray_IntpConverter(descr->subarray->shape,
+ &shape))) {
+ PyDimMem_FREE(shape.ptr);
+ PyErr_SetString(PyExc_ValueError,
+ "invalid shape in fixed-type tuple.");
+ return NULL;
+ }
Py_INCREF(descr->subarray->base);
- ret = PyArray_NewFromDescr(&PyArray_Type,
- descr->subarray->base,
- shape.len, shape.ptr,
- NULL, ip, ap->flags, NULL);
- PyDimMem_FREE(shape.ptr);
- if (!ret) return NULL;
- PyArray_BASE(ret) = (PyObject *)ap;
- Py_INCREF(ap);
- PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL);
- return ret;
- }
+ ret = PyArray_NewFromDescr(&PyArray_Type,
+ descr->subarray->base,
+ shape.len, shape.ptr,
+ NULL, ip, ap->flags, NULL);
+ PyDimMem_FREE(shape.ptr);
+ if (!ret) return NULL;
+ PyArray_BASE(ret) = (PyObject *)ap;
+ Py_INCREF(ap);
+ PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL);
+ return ret;
+ }
finish:
- if (descr->hasobject) {
- PyErr_SetString(PyExc_ValueError,
- "tried to get void-array with object"
- " members as buffer.");
- return NULL;
- }
+ if (descr->hasobject) {
+ PyErr_SetString(PyExc_ValueError,
+ "tried to get void-array with object"
+ " members as buffer.");
+ return NULL;
+ }
- itemsize=ap->descr->elsize;
- if (PyArray_ISWRITEABLE(ap))
- u = PyBuffer_FromReadWriteMemory(ip, itemsize);
- else
- u = PyBuffer_FromMemory(ip, itemsize);
- if (u==NULL) goto fail;
+ itemsize=ap->descr->elsize;
+ if (PyArray_ISWRITEABLE(ap))
+ u = PyBuffer_FromReadWriteMemory(ip, itemsize);
+ else
+ u = PyBuffer_FromMemory(ip, itemsize);
+ if (u==NULL) goto fail;
- /* default is to return buffer object pointing to current item */
- /* a view of it */
- return u;
-
+ /* default is to return buffer object pointing to current item */
+ /* a view of it */
+ return u;
+
fail:
return NULL;
}
@@ -476,96 +476,96 @@
static int
VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)
{
- PyArray_Descr* descr;
+ PyArray_Descr* descr;
int itemsize=ap->descr->elsize;
- int res;
+ int res;
- descr = ap->descr;
- if (descr->names && PyTuple_Check(op)) {
- PyObject *key;
- PyObject *names;
- int i, n;
- PyObject *tup, *title;
- PyArray_Descr *new;
- int offset;
- int savedflags;
- res = -1;
- /* get the names from the fields dictionary*/
+ descr = ap->descr;
+ if (descr->names && PyTuple_Check(op)) {
+ PyObject *key;
+ PyObject *names;
+ int i, n;
+ PyObject *tup, *title;
+ PyArray_Descr *new;
+ int offset;
+ int savedflags;
+ res = -1;
+ /* get the names from the fields dictionary*/
names = descr->names;
- n = PyTuple_GET_SIZE(names);
- if (PyTuple_GET_SIZE(op) != n) {
- PyErr_SetString(PyExc_ValueError,
- "size of tuple must match "\
- "number of fields.");
- return -1;
- }
- savedflags = ap->flags;
- for (i=0; i<n; i++) {
- key = PyTuple_GET_ITEM(names, i);
- tup = PyDict_GetItem(descr->fields, key);
- if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset,
- &title)) {
- ap->descr = descr;
- return -1;
- }
- ap->descr = new;
- /* remember to update alignment flags */
- if ((new->alignment > 1) && \
- ((((intp)(ip+offset)) % new->alignment) != 0))
- ap->flags &= ~ALIGNED;
- else
- ap->flags |= ALIGNED;
+ n = PyTuple_GET_SIZE(names);
+ if (PyTuple_GET_SIZE(op) != n) {
+ PyErr_SetString(PyExc_ValueError,
+ "size of tuple must match "\
+ "number of fields.");
+ return -1;
+ }
+ savedflags = ap->flags;
+ for (i=0; i<n; i++) {
+ key = PyTuple_GET_ITEM(names, i);
+ tup = PyDict_GetItem(descr->fields, key);
+ if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset,
+ &title)) {
+ ap->descr = descr;
+ return -1;
+ }
+ ap->descr = new;
+ /* remember to update alignment flags */
+ if ((new->alignment > 1) && \
+ ((((intp)(ip+offset)) % new->alignment) != 0))
+ ap->flags &= ~ALIGNED;
+ else
+ ap->flags |= ALIGNED;
- res = new->f->setitem(PyTuple_GET_ITEM(op, i),
- ip+offset, ap);
- ap->flags = savedflags;
- if (res < 0) break;
- }
- ap->descr = descr;
- return res;
- }
+ res = new->f->setitem(PyTuple_GET_ITEM(op, i),
+ ip+offset, ap);
+ ap->flags = savedflags;
+ if (res < 0) break;
+ }
+ ap->descr = descr;
+ return res;
+ }
- if (descr->subarray) {
- /* copy into an array of the same basic type */
- PyArray_Dims shape={NULL,-1};
- PyObject *ret;
- if (!(PyArray_IntpConverter(descr->subarray->shape,
- &shape))) {
- PyDimMem_FREE(shape.ptr);
- PyErr_SetString(PyExc_ValueError,
- "invalid shape in fixed-type tuple.");
- return -1;
- }
+ if (descr->subarray) {
+ /* copy into an array of the same basic type */
+ PyArray_Dims shape={NULL,-1};
+ PyObject *ret;
+ if (!(PyArray_IntpConverter(descr->subarray->shape,
+ &shape))) {
+ PyDimMem_FREE(shape.ptr);
+ PyErr_SetString(PyExc_ValueError,
+ "invalid shape in fixed-type tuple.");
+ return -1;
+ }
Py_INCREF(descr->subarray->base);
- ret = PyArray_NewFromDescr(&PyArray_Type,
- descr->subarray->base,
- shape.len, shape.ptr,
- NULL, ip, ap->flags, NULL);
- PyDimMem_FREE(shape.ptr);
- if (!ret) return -1;
- PyArray_BASE(ret) = (PyObject *)ap;
- Py_INCREF(ap);
- PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL);
- res = PyArray_CopyObject((PyArrayObject *)ret, op);
- Py_DECREF(ret);
- return res;
- }
+ ret = PyArray_NewFromDescr(&PyArray_Type,
+ descr->subarray->base,
+ shape.len, shape.ptr,
+ NULL, ip, ap->flags, NULL);
+ PyDimMem_FREE(shape.ptr);
+ if (!ret) return -1;
+ PyArray_BASE(ret) = (PyObject *)ap;
+ Py_INCREF(ap);
+ PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL);
+ res = PyArray_CopyObject((PyArrayObject *)ret, op);
+ Py_DECREF(ret);
+ return res;
+ }
- /* Default is to use buffer interface to set item */
- {
- const void *buffer;
- Py_ssize_t buflen;
- if (descr->hasobject) {
- PyErr_SetString(PyExc_ValueError,
- "tried to set void-array with object"
- " members using buffer.");
- return -1;
- }
- res = PyObject_AsReadBuffer(op, &buffer, &buflen);
- if (res == -1) goto fail;
- memcpy(ip, buffer, MIN(buflen, itemsize));
+ /* Default is to use buffer interface to set item */
+ {
+ const void *buffer;
+ Py_ssize_t buflen;
+ if (descr->hasobject) {
+ PyErr_SetString(PyExc_ValueError,
+ "tried to set void-array with object"
+ " members using buffer.");
+ return -1;
+ }
+ res = PyObject_AsReadBuffer(op, &buffer, &buflen);
+ if (res == -1) goto fail;
+ memcpy(ip, buffer, MIN(buflen, itemsize));
}
- return 0;
+ return 0;
fail:
return -1;
@@ -586,12 +586,12 @@
*/
static void
@from at _to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n,
- PyArrayObject *aip, PyArrayObject *aop)
+ PyArrayObject *aip, PyArrayObject *aop)
{
- while (n--) {
- *op++ = (@totyp@)*ip;
- @incr@;
- }
+ while (n--) {
+ *op++ = (@totyp@)*ip;
+ @incr@;
+ }
}
/**end repeat**/
@@ -601,11 +601,11 @@
*/
static void
@from at _to_BOOL(register @fromtyp@ *ip, register Bool *op, register intp n,
- PyArrayObject *aip, PyArrayObject *aop)
+ PyArrayObject *aip, PyArrayObject *aop)
{
- while (n--) {
- *op++ = (Bool)(*ip++ != FALSE);
- }
+ while (n--) {
+ *op++ = (Bool)(*ip++ != FALSE);
+ }
}
/**end repeat**/
@@ -615,12 +615,12 @@
*/
static void
@from at _to_BOOL(register @fromtyp@ *ip, register Bool *op, register intp n,
- PyArrayObject *aip, PyArrayObject *aop)
+ PyArrayObject *aip, PyArrayObject *aop)
{
- while (n--) {
- *op = (Bool)(((*ip).real != FALSE) || ((*ip).imag != FALSE));
- op++; ip++;
- }
+ while (n--) {
+ *op = (Bool)(((*ip).real != FALSE) || ((*ip).imag != FALSE));
+ op++; ip++;
+ }
}
/**end repeat**/
@@ -630,11 +630,11 @@
*/
static void
BOOL_to_ at to@(register Bool *ip, register @totyp@ *op, register intp n,
- PyArrayObject *aip, PyArrayObject *aop)
+ PyArrayObject *aip, PyArrayObject *aop)
{
- while (n--) {
- *op++ = (@totyp@)(*ip++ != FALSE);
- }
+ while (n--) {
+ *op++ = (@totyp@)(*ip++ != FALSE);
+ }
}
/**end repeat**/
@@ -647,12 +647,12 @@
*/
static void
@from at _to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n,
- PyArrayObject *aip, PyArrayObject *aop)
-{
- while (n--) {
- *op++ = (@totyp@)*ip++;
- *op++ = 0.0;
- }
+ PyArrayObject *aip, PyArrayObject *aop)
+{
+ while (n--) {
+ *op++ = (@totyp@)*ip++;
+ *op++ = 0.0;
+ }
}
/**end repeat**/
@@ -666,12 +666,12 @@
*/
static void
@from at _to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n,
- PyArrayObject *aip, PyArrayObject *aop)
+ PyArrayObject *aip, PyArrayObject *aop)
{
- n <<= 1;
- while (n--) {
- *op++ = (@totyp@)*ip++;
- }
+ n <<= 1;
+ while (n--) {
+ *op++ = (@totyp@)*ip++;
+ }
}
/**end repeat**/
@@ -684,14 +684,14 @@
*/
static void
@from at _to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,
- PyArrayObject *aop)
+ PyArrayObject *aop)
{
- register intp i;
- int skip=@skip@;
- for(i=0;i<n;i++,ip+=skip,op++) {
- Py_XDECREF(*op);
- *op = @from at _getitem((char *)ip, aip);
- }
+ register intp i;
+ int skip=@skip@;
+ for(i=0;i<n;i++,ip+=skip,op++) {
+ Py_XDECREF(*op);
+ *op = @from at _getitem((char *)ip, aip);
+ }
}
/**end repeat**/
@@ -703,13 +703,13 @@
*/
static void
OBJECT_to_ at to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,
- PyArrayObject *aop)
+ PyArrayObject *aop)
{
- register intp i;
- int skip=@skip@;
- for(i=0;i<n;i++,ip++,op+=skip) {
- @to at _setitem(*ip, (char *)op, aop);
- }
+ register intp i;
+ int skip=@skip@;
+ for(i=0;i<n;i++,ip++,op+=skip) {
+ @to at _setitem(*ip, (char *)op, aop);
+ }
}
/**end repeat**/
@@ -726,29 +726,29 @@
*/
static void
@from at _to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip,
- PyArrayObject *aop)
+ PyArrayObject *aop)
{
- register intp i;
- PyObject *temp=NULL;
- int skip=aip->descr->elsize;
- int oskip=@oskip@;
- for(i=0; i<n; i++, ip+=skip, op+=oskip) {
- temp = @from at _getitem((char *)ip, aip);
- if (temp==NULL) return;
- /* convert from Python object to needed one */
- if (@convert@) {
- PyObject *new, *args;
- /* call out to the Python builtin given by convstr */
- args = Py_BuildValue("(N)", temp);
- new = Py at convstr@_Type.tp_new(&Py at convstr@_Type, args, NULL);
- Py_DECREF(args);
- temp = new;
- if (temp==NULL) return;
- }
-
- @to at _setitem(temp,(char *)op, aop);
- Py_DECREF(temp);
- }
+ register intp i;
+ PyObject *temp=NULL;
+ int skip=aip->descr->elsize;
+ int oskip=@oskip@;
+ for(i=0; i<n; i++, ip+=skip, op+=oskip) {
+ temp = @from at _getitem((char *)ip, aip);
+ if (temp==NULL) return;
+ /* convert from Python object to needed one */
+ if (@convert@) {
+ PyObject *new, *args;
+ /* call out to the Python builtin given by convstr */
+ args = Py_BuildValue("(N)", temp);
+ new = Py at convstr@_Type.tp_new(&Py at convstr@_Type, args, NULL);
+ Py_DECREF(args);
+ temp = new;
+ if (temp==NULL) return;
+ }
+
+ @to at _setitem(temp,(char *)op, aop);
+ Py_DECREF(temp);
+ }
}
/**end repeat**/
@@ -763,21 +763,21 @@
static void
@from at _to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip,
- PyArrayObject *aop)
+ PyArrayObject *aop)
{
- register intp i;
- PyObject *temp=NULL;
- int skip=1;
- int oskip=aop->descr->elsize;
- for(i=0; i<n; i++, ip+=skip, op+=oskip) {
- temp = @from at _getitem((char *)ip, aip);
- if (temp==NULL) {
- Py_INCREF(Py_False);
- temp = Py_False;
- }
- @to at _setitem(temp,(char *)op, aop);
- Py_DECREF(temp);
- }
+ register intp i;
+ PyObject *temp=NULL;
+ int skip=1;
+ int oskip=aop->descr->elsize;
+ for(i=0; i<n; i++, ip+=skip, op+=oskip) {
+ temp = @from at _getitem((char *)ip, aip);
+ if (temp==NULL) {
+ Py_INCREF(Py_False);
+ temp = Py_False;
+ }
+ @to at _setitem(temp,(char *)op, aop);
+ Py_DECREF(temp);
+ }
}
/**end repeat**/
@@ -786,17 +786,17 @@
/****************** scan *************************************/
#define _ENDSCAN \
- if (num != 1) { \
- if (num == 0) return -3; \
- if (num == EOF) return -4; \
- return -5; \
- } \
- if (sep != NULL) { \
- num = fscanf(fp, sep); \
- if (num == 0) return 0; \
- if (num == EOF) return -1; \
- } \
- return 0
+ if (num != 1) { \
+ if (num == 0) return -3; \
+ if (num == EOF) return -4; \
+ return -5; \
+ } \
+ if (sep != NULL) { \
+ num = fscanf(fp, sep); \
+ if (num == 0) return 0; \
+ if (num == EOF) return -1; \
+ } \
+ return 0
/**begin repeat
@@ -807,9 +807,9 @@
static int
@fname at _scan (FILE *fp, @type@ *ip, char *sep, void *ignore)
{
- int num;
- num = fscanf(fp, "%"@format@, ip);
- _ENDSCAN;
+ int num;
+ num = fscanf(fp, "%"@format@, ip);
+ _ENDSCAN;
}
/**end repeat**/
@@ -823,22 +823,22 @@
static int
@fname at _scan (FILE *fp, @type@ *ip, char *sep, void *ignore)
{
- @btype@ temp;
- int num;
- num = fscanf(fp, "%"@format@, &temp);
- *ip = (@type@) temp;
- _ENDSCAN;
+ @btype@ temp;
+ int num;
+ num = fscanf(fp, "%"@format@, &temp);
+ *ip = (@type@) temp;
+ _ENDSCAN;
}
/**end repeat**/
static int
BOOL_scan (FILE *fp, Bool *ip, char *sep, void *ignore)
{
- int temp;
- int num;
- num = fscanf(fp, "%d", &temp);
- *ip = (Bool) (temp != 0);
- _ENDSCAN;
+ int temp;
+ int num;
+ num = fscanf(fp, "%d", &temp);
+ *ip = (Bool) (temp != 0);
+ _ENDSCAN;
}
/**begin repeat
@@ -860,11 +860,11 @@
static int
@fname at _fromstr(char *str, @type@ *ip, char **endptr, void *ignore)
{
- @btype@ result;
+ @btype@ result;
- result = PyOS_strto at func@(str, endptr, 0);
- *ip = (@type@) result;
- return 0;
+ result = PyOS_strto at func@(str, endptr, 0);
+ *ip = (@type@) result;
+ return 0;
}
/**end repeat**/
@@ -876,11 +876,11 @@
static int
@fname at _fromstr(char *str, @type@ *ip, char **endptr, void *ignore)
{
- double result;
+ double result;
- result = PyOS_ascii_strtod(str, endptr);
- *ip = (@type@) result;
- return 0;
+ result = PyOS_ascii_strtod(str, endptr);
+ *ip = (@type@) result;
+ return 0;
}
#else
#define @fname at _fromstr NULL
@@ -908,7 +908,7 @@
@fname at _copyswapn (void *dst, intp dstride, void *src, intp sstride,
intp n, int swap, void *arr)
{
- if (src != NULL) {
+ if (src != NULL) {
if (sstride == sizeof(@type@) && dstride == sizeof(@type@)) {
memcpy(dst, src, n*sizeof(@type@));
}
@@ -917,7 +917,7 @@
n, sizeof(@type@));
}
}
- if (swap) {
+ if (swap) {
_strided_byte_swap(dst, dstride, n, sizeof(@type@));
}
}
@@ -926,11 +926,11 @@
@fname at _copyswap (void *dst, void *src, int swap, void *arr)
{
- if (src != NULL) /* copy first if needed */
+ if (src != NULL) /* copy first if needed */
memcpy(dst, src, sizeof(@type@));
- if (swap) {
- register char *a, *b, c;
+ if (swap) {
+ register char *a, *b, c;
a = (char *)dst;
#if SIZEOF_ at fsize@ == 2
b = a + 1;
@@ -971,15 +971,15 @@
c = *a; *a++ = *b; *b-- = c;
c = *a; *a++ = *b; *b = c;
#else
- {
- register int i, nn;
- b = a + (SIZEOF_ at fsize@-1);
- nn = SIZEOF_ at fsize@ / 2;
- for (i=0; i<nn; i++) {
- c=*a; *a++ = *b; *b-- = c;
- }
- }
-#endif
+ {
+ register int i, nn;
+ b = a + (SIZEOF_ at fsize@-1);
+ nn = SIZEOF_ at fsize@ / 2;
+ for (i=0; i<nn; i++) {
+ c=*a; *a++ = *b; *b-- = c;
+ }
+ }
+#endif
}
}
@@ -995,7 +995,7 @@
@fname at _copyswapn (void *dst, intp dstride, void *src, intp sstride, intp n,
int swap, void *arr)
{
- if (src != NULL) {
+ if (src != NULL) {
if (sstride == sizeof(@type@) && dstride == sizeof(@type@)) {
memcpy(dst, src, n*sizeof(@type@));
}
@@ -1010,9 +1010,9 @@
static void
@fname at _copyswap (void *dst, void *src, int swap, void *arr)
{
- if (src != NULL) /* copy first if needed */
- memcpy(dst, src, sizeof(@type@));
- /* ignore swap */
+ if (src != NULL) /* copy first if needed */
+ memcpy(dst, src, sizeof(@type@));
+ /* ignore swap */
}
/**end repeat**/
@@ -1030,7 +1030,7 @@
int swap, void *arr)
{
- if (src != NULL) { /* copy first if needed */
+ if (src != NULL) { /* copy first if needed */
if (sstride == sizeof(@type@) && dstride == sizeof(@type@)) {
memcpy(dst, src, n*sizeof(@type@));
}
@@ -1040,7 +1040,7 @@
}
}
- if (swap) {
+ if (swap) {
_strided_byte_swap(dst, dstride, n, sizeof(@type@));
}
}
@@ -1048,12 +1048,12 @@
static void
@fname at _copyswap (void *dst, void *src, int swap, void *arr)
{
- if (src != NULL) /* copy first if needed */
- memcpy(dst, src, sizeof(@type@));
+ if (src != NULL) /* copy first if needed */
+ memcpy(dst, src, sizeof(@type@));
- if (swap) {
- register char *a, *b, c;
- a = (char *)dst;
+ if (swap) {
+ register char *a, *b, c;
+ a = (char *)dst;
#if SIZEOF_ at fsize@ == 4
b = a + 3;
c = *a; *a++ = *b; *b-- = c;
@@ -1125,21 +1125,21 @@
c = *a; *a++ = *b; *b-- = c;
c = *a; *a++ = *b; *b = c;
#else
- {
- register int i, nn;
- b = a + (SIZEOF_ at fsize@-1);
- nn = SIZEOF_ at fsize@ / 2;
- for (i=0; i<nn; i++) {
- c=*a; *a++ = *b; *b-- = c;
- }
- a += nn / 2;
- b = a + (SIZEOF_ at fsize@-1);
- nn = SIZEOF_ at fsize@ / 2;
- for (i=0; i<nn; i++) {
- c=*a; *a++ = *b; *b-- = c;
- }
- }
-#endif
+ {
+ register int i, nn;
+ b = a + (SIZEOF_ at fsize@-1);
+ nn = SIZEOF_ at fsize@ / 2;
+ for (i=0; i<nn; i++) {
+ c=*a; *a++ = *b; *b-- = c;
+ }
+ a += nn / 2;
+ b = a + (SIZEOF_ at fsize@-1);
+ nn = SIZEOF_ at fsize@ / 2;
+ for (i=0; i<nn; i++) {
+ c=*a; *a++ = *b; *b-- = c;
+ }
+ }
+#endif
}
}
@@ -1150,10 +1150,10 @@
OBJECT_copyswapn (PyObject **dst, intp dstride, PyObject **src, intp sstride,
register intp n, int swap, void *arr)
{
- register intp i;
- if (src != NULL) {
- dstride /= sizeof(PyObject **);
- sstride /= sizeof(PyObject **);
+ register intp i;
+ if (src != NULL) {
+ dstride /= sizeof(PyObject **);
+ sstride /= sizeof(PyObject **);
if (__ALIGNED(dst,sizeof(PyObject **)) && __ALIGNED(src, sizeof(PyObject **))) {
for (i=0; i<n; i++) {
Py_INCREF(*src);
@@ -1175,16 +1175,16 @@
src += sstride;
}
}
- }
- /* ignore swap */
- return;
+ }
+ /* ignore swap */
+ return;
}
static void
OBJECT_copyswap(PyObject **dst, PyObject **src, int swap, void *arr)
{
- if (src != NULL) {
+ if (src != NULL) {
if (__ALIGNED(dst,sizeof(PyObject **)) && __ALIGNED(src,sizeof(PyObject **))) {
Py_INCREF(*src);
Py_XDECREF(*dst);
@@ -1204,16 +1204,16 @@
STRING_copyswapn (char *dst, intp dstride, char *src, intp sstride,
intp n, int swap, PyArrayObject *arr)
{
- if (src != NULL && arr != NULL) {
- int itemsize = arr->descr->elsize;
+ if (src != NULL && arr != NULL) {
+ int itemsize = arr->descr->elsize;
if (dstride == itemsize && sstride == itemsize) {
memcpy(dst, src, itemsize * n);
}
else {
_unaligned_strided_byte_copy(dst, dstride, src, sstride, n, itemsize);
}
- }
- return;
+ }
+ return;
}
/* */
@@ -1230,18 +1230,18 @@
int offset, pos=0;
descr = arr->descr;
while (PyDict_Next(descr->fields, &pos, &key, &value)) {
- if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
- &title)) {arr->descr=descr;return;}
+ if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
+ &title)) {arr->descr=descr;return;}
arr->descr = new;
new->f->copyswapn(dst+offset, dstride, src+offset, sstride, n, swap, arr);
}
arr->descr = descr;
return;
}
- if (src != NULL) {
- memcpy(dst, src, itemsize * n);
- }
- return;
+ if (src != NULL) {
+ memcpy(dst, src, itemsize * n);
+ }
+ return;
}
static void
@@ -1254,18 +1254,18 @@
int offset, pos=0;
descr = arr->descr; /* Save it */
while (PyDict_Next(descr->fields, &pos, &key, &value)) {
- if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
- &title)) {arr->descr=descr;return;}
+ if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
+ &title)) {arr->descr=descr;return;}
arr->descr = new;
new->f->copyswap(dst+offset, src+offset, swap, arr);
}
arr->descr = descr;
return;
}
- if (src != NULL) {
- memcpy(dst, src, arr->descr->elsize);
- }
- return;
+ if (src != NULL) {
+ memcpy(dst, src, arr->descr->elsize);
+ }
+ return;
}
@@ -1274,58 +1274,58 @@
intp n, int swap, PyArrayObject *arr)
{
int itemsize;
- if (arr==NULL) return;
+ if (arr==NULL) return;
itemsize = arr->descr->elsize;
- if (src != NULL) {
+ if (src != NULL) {
if (dstride == itemsize && sstride == itemsize)
memcpy(dst, src, n * itemsize);
else
_unaligned_strided_byte_copy(dst, dstride, src,
sstride, n, itemsize);
- }
+ }
n *= itemsize;
- if (swap) {
- register char *a, *b, c;
- n >>= 2; /* n is the number of unicode characters to swap */
- for (a = (char *)dst; n>0; n--) {
- b = a + 3;
- c=*a; *a++ = *b; *b-- = c;
- c=*a; *a++ = *b; *b-- = c;
- a += 1;
- }
- }
+ if (swap) {
+ register char *a, *b, c;
+ n >>= 2; /* n is the number of unicode characters to swap */
+ for (a = (char *)dst; n>0; n--) {
+ b = a + 3;
+ c=*a; *a++ = *b; *b-- = c;
+ c=*a; *a++ = *b; *b-- = c;
+ a += 1;
+ }
+ }
}
static void
STRING_copyswap (char *dst, char *src, int swap, PyArrayObject *arr)
{
- if (src != NULL && arr != NULL) {
- memcpy(dst, src, arr->descr->elsize);
- }
+ if (src != NULL && arr != NULL) {
+ memcpy(dst, src, arr->descr->elsize);
+ }
}
static void
UNICODE_copyswap (char *dst, char *src, int swap, PyArrayObject *arr)
{
- int itemsize;
- if (arr == NULL) return;
- itemsize = arr->descr->elsize;
- if (src != NULL) {
- memcpy(dst, src, itemsize);
- }
-
- if (swap) {
- register char *a, *b, c;
- itemsize >>= 2;
- for (a = (char *)dst; itemsize>0; itemsize--) {
- b = a + 3;
- c=*a; *a++ = *b; *b-- = c;
- c=*a; *a++ = *b; *b-- = c;
- a += 1;
- }
- }
+ int itemsize;
+ if (arr == NULL) return;
+ itemsize = arr->descr->elsize;
+ if (src != NULL) {
+ memcpy(dst, src, itemsize);
+ }
+
+ if (swap) {
+ register char *a, *b, c;
+ itemsize >>= 2;
+ for (a = (char *)dst; itemsize>0; itemsize--) {
+ b = a + 3;
+ c=*a; *a++ = *b; *b-- = c;
+ c=*a; *a++ = *b; *b-- = c;
+ a += 1;
+ }
+ }
}
@@ -1338,15 +1338,15 @@
static Bool
@fname at _nonzero (@type@ *ip, PyArrayObject *ap)
{
- @type@ t1;
- if (ap==NULL || PyArray_ISBEHAVED_RO(ap))
- return (Bool) (*ip != 0);
- else {
- /* don't worry about swap, since we are just testing
- whether or not equal to 0 */
- memcpy(&t1, ip, sizeof(@type@));
- return (Bool) (t1 != 0);
- }
+ @type@ t1;
+ if (ap==NULL || PyArray_ISBEHAVED_RO(ap))
+ return (Bool) (*ip != 0);
+ else {
+ /* don't worry about swap, since we are just testing
+ whether or not equal to 0 */
+ memcpy(&t1, ip, sizeof(@type@));
+ return (Bool) (t1 != 0);
+ }
}
/**end repeat**/
@@ -1357,15 +1357,15 @@
static Bool
@fname at _nonzero (@type@ *ip, PyArrayObject *ap)
{
- @type@ t1;
- if (ap==NULL || PyArray_ISBEHAVED_RO(ap))
- return (Bool) ((ip->real != 0) || (ip->imag != 0));
- else {
- /* don't worry about swap, since we are just testing
- whether or not equal to 0 */
- memcpy(&t1, ip, sizeof(@type@));
- return (Bool) ((t1.real != 0) || (t1.imag != 0));
- }
+ @type@ t1;
+ if (ap==NULL || PyArray_ISBEHAVED_RO(ap))
+ return (Bool) ((ip->real != 0) || (ip->imag != 0));
+ else {
+ /* don't worry about swap, since we are just testing
+ whether or not equal to 0 */
+ memcpy(&t1, ip, sizeof(@type@));
+ return (Bool) ((t1.real != 0) || (t1.imag != 0));
+ }
}
/**end repeat**/
@@ -1376,33 +1376,33 @@
static Bool
Py_STRING_ISSPACE(char ch)
{
- char white[] = WHITESPACE;
- int j;
- Bool space=FALSE;
- for (j=0; j<WHITELEN; j++) {
- if (ch == white[j]) {
- space=TRUE;
- break;
- }
- }
- return space;
+ char white[] = WHITESPACE;
+ int j;
+ Bool space=FALSE;
+ for (j=0; j<WHITELEN; j++) {
+ if (ch == white[j]) {
+ space=TRUE;
+ break;
+ }
+ }
+ return space;
}
static Bool
STRING_nonzero (char *ip, PyArrayObject *ap)
{
- int len = ap->descr->elsize;
- int i;
- Bool nonz = FALSE;
+ int len = ap->descr->elsize;
+ int i;
+ Bool nonz = FALSE;
- for (i=0; i<len; i++) {
- if (!Py_STRING_ISSPACE(*ip)) {
- nonz = TRUE;
- break;
- }
- ip++;
- }
- return nonz;
+ for (i=0; i<len; i++) {
+ if (!Py_STRING_ISSPACE(*ip)) {
+ nonz = TRUE;
+ break;
+ }
+ ip++;
+ }
+ return nonz;
}
#ifdef Py_UNICODE_WIDE
@@ -1414,33 +1414,33 @@
static Bool
UNICODE_nonzero (PyArray_UCS4 *ip, PyArrayObject *ap)
{
- int len = ap->descr->elsize >> 2;
- int i;
- Bool nonz = FALSE;
- char *buffer=NULL;
+ int len = ap->descr->elsize >> 2;
+ int i;
+ Bool nonz = FALSE;
+ char *buffer=NULL;
- if ((!PyArray_ISNOTSWAPPED(ap)) || \
- (!PyArray_ISALIGNED(ap))) {
- buffer = _pya_malloc(ap->descr->elsize);
- if (buffer == NULL) {
- return nonz;
- }
- memcpy(buffer, ip, ap->descr->elsize);
- if (!PyArray_ISNOTSWAPPED(ap)) {
- byte_swap_vector(buffer, len, 4);
- }
- ip = (PyArray_UCS4 *)buffer;
- }
+ if ((!PyArray_ISNOTSWAPPED(ap)) || \
+ (!PyArray_ISALIGNED(ap))) {
+ buffer = _pya_malloc(ap->descr->elsize);
+ if (buffer == NULL) {
+ return nonz;
+ }
+ memcpy(buffer, ip, ap->descr->elsize);
+ if (!PyArray_ISNOTSWAPPED(ap)) {
+ byte_swap_vector(buffer, len, 4);
+ }
+ ip = (PyArray_UCS4 *)buffer;
+ }
- for (i=0; i<len; i++) {
- if (!PyArray_UCS4_ISSPACE(*ip)) {
- nonz = TRUE;
- break;
- }
- ip++;
- }
- _pya_free(buffer);
- return nonz;
+ for (i=0; i<len; i++) {
+ if (!PyArray_UCS4_ISSPACE(*ip)) {
+ nonz = TRUE;
+ break;
+ }
+ ip++;
+ }
+ _pya_free(buffer);
+ return nonz;
}
static Bool
@@ -1462,43 +1462,43 @@
static Bool
VOID_nonzero (char *ip, PyArrayObject *ap)
{
- int i;
- int len;
- Bool nonz = FALSE;
+ int i;
+ int len;
+ Bool nonz = FALSE;
- if (PyArray_HASFIELDS(ap)) {
- PyArray_Descr *descr, *new;
- PyObject *key, *value, *title;
+ if (PyArray_HASFIELDS(ap)) {
+ PyArray_Descr *descr, *new;
+ PyObject *key, *value, *title;
int savedflags, offset, pos=0;
- descr = ap->descr;
- savedflags = ap->flags;
+ descr = ap->descr;
+ savedflags = ap->flags;
while (PyDict_Next(descr->fields, &pos, &key, &value)) {
- if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
- &title)) {PyErr_Clear(); continue;}
+ if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
+ &title)) {PyErr_Clear(); continue;}
ap->descr = new;
- ap->flags = savedflags;
- if ((new->alignment > 1) && !__ALIGNED(ip+offset, new->alignment))
- ap->flags &= ~ALIGNED;
- else
- ap->flags |= ALIGNED;
+ ap->flags = savedflags;
+ if ((new->alignment > 1) && !__ALIGNED(ip+offset, new->alignment))
+ ap->flags &= ~ALIGNED;
+ else
+ ap->flags |= ALIGNED;
if (new->f->nonzero(ip+offset, ap)) {
- nonz=TRUE;
- break;
- }
+ nonz=TRUE;
+ break;
+ }
}
ap->descr = descr;
- ap->flags = savedflags;
- return nonz;
- }
- len = ap->descr->elsize;
- for (i=0; i<len; i++) {
- if (*ip != '\0') {
- nonz = TRUE;
- break;
- }
- ip++;
- }
- return nonz;
+ ap->flags = savedflags;
+ return nonz;
+ }
+ len = ap->descr->elsize;
+ for (i=0; i<len; i++) {
+ if (*ip != '\0') {
+ nonz = TRUE;
+ break;
+ }
+ ip++;
+ }
+ return nonz;
}
#undef __ALIGNED
@@ -1509,7 +1509,7 @@
static int
BOOL_compare(Bool *ip1, Bool *ip2, PyArrayObject *ap)
{
- return (*ip1 ? (*ip2 ? 0 : 1) : (*ip2 ? -1 : 0));
+ return (*ip1 ? (*ip2 ? 0 : 1) : (*ip2 ? -1 : 0));
}
/**begin repeat
@@ -1520,7 +1520,7 @@
static int
@fname at _compare (@type@ *ip1, @type@ *ip2, PyArrayObject *ap)
{
- return *ip1 < *ip2 ? -1 : *ip1 == *ip2 ? 0 : 1;
+ return *ip1 < *ip2 ? -1 : *ip1 == *ip2 ? 0 : 1;
}
/**end repeat**/
@@ -1534,45 +1534,45 @@
static int
@fname at _compare (@type@ *ip1, @type@ *ip2, PyArrayObject *ap)
{
- if (*ip1 == *ip2) {
- return ip1[1]<ip2[1] ? -1 : (ip1[1] == ip2[1] ? 0 : 1);
- }
- else {
- return *ip1 < *ip2 ? -1 : 1;
- }
+ if (*ip1 == *ip2) {
+ return ip1[1]<ip2[1] ? -1 : (ip1[1] == ip2[1] ? 0 : 1);
+ }
+ else {
+ return *ip1 < *ip2 ? -1 : 1;
+ }
}
/**end repeat**/
static int
OBJECT_compare(PyObject **ip1, PyObject **ip2, PyArrayObject *ap)
{
- return PyObject_Compare(*ip1, *ip2);
+ return PyObject_Compare(*ip1, *ip2);
}
static int
STRING_compare(char *ip1, char *ip2, PyArrayObject *ap)
{
- return strncmp(ip1, ip2, ap->descr->elsize);
+ return strncmp(ip1, ip2, ap->descr->elsize);
}
/* taken from Python */
static int
UNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2,
- PyArrayObject *ap)
+ PyArrayObject *ap)
{
register int itemsize=ap->descr->elsize;
- register PyArray_UCS4 c1, c2;
+ register PyArray_UCS4 c1, c2;
- if (itemsize < 0) return 0;
-
- while(itemsize-- > 0) {
- c1 = *ip1++;
- c2 = *ip2++;
-
- if (c1 != c2)
- return (c1 < c2) ? -1 : 1;
- }
- return 0;
+ if (itemsize < 0) return 0;
+
+ while(itemsize-- > 0) {
+ c1 = *ip1++;
+ c2 = *ip2++;
+
+ if (c1 != c2)
+ return (c1 < c2) ? -1 : 1;
+ }
+ return 0;
}
/* possibly redefine compare in terms of fields and subarrays if any */
@@ -1586,7 +1586,7 @@
static int
VOID_compare(char *ip1, char *ip2, PyArrayObject *ap)
{
- return STRING_compare(ip1, ip2, ap);
+ return STRING_compare(ip1, ip2, ap);
}
/****************** argfunc **********************************/
@@ -1601,17 +1601,17 @@
static int
@fname at _argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)
{
- register intp i;
- @type@ mp=*ip;
- *max_ind=0;
- for (i=1; i<n; i++) {
- @incr@;
- if (*ip > mp) {
- mp = *ip;
- *max_ind = i;
- }
- }
- return 0;
+ register intp i;
+ @type@ mp=*ip;
+ *max_ind=0;
+ for (i=1; i<n; i++) {
+ @incr@;
+ if (*ip > mp) {
+ mp = *ip;
+ *max_ind = i;
+ }
+ }
+ return 0;
}
/**end repeat**/
@@ -1619,16 +1619,16 @@
static int
OBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip)
{
- register intp i;
- PyObject *mp=ip[0]; *max_ind=0;
- for(i=1; i<n; i++) {
- ip++;
- if (PyObject_Compare(*ip,mp) > 0) {
- mp = *ip;
- *max_ind=i;
- }
- }
- return 0;
+ register intp i;
+ PyObject *mp=ip[0]; *max_ind=0;
+ for(i=1; i<n; i++) {
+ ip++;
+ if (PyObject_Compare(*ip,mp) > 0) {
+ mp = *ip;
+ *max_ind=i;
+ }
+ }
+ return 0;
}
/**begin repeat
@@ -1640,22 +1640,22 @@
static int
@fname at _argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)
{
- register intp i;
- int elsize = aip->descr->elsize;
- @type@ *mp = (@type@ *)_pya_malloc(elsize);
-
- if (mp==NULL) return 0;
- memcpy(mp, ip, elsize);
- *max_ind = 0;
- for(i=1; i<n; i++) {
- ip += elsize;
- if (@fname at _compare(ip,mp,aip) > 0) {
- memcpy(mp, ip, elsize);
- *max_ind=i;
- }
- }
- _pya_free(mp);
- return 0;
+ register intp i;
+ int elsize = aip->descr->elsize;
+ @type@ *mp = (@type@ *)_pya_malloc(elsize);
+
+ if (mp==NULL) return 0;
+ memcpy(mp, ip, elsize);
+ *max_ind = 0;
+ for(i=1; i<n; i++) {
+ ip += elsize;
+ if (@fname at _compare(ip,mp,aip) > 0) {
+ memcpy(mp, ip, elsize);
+ *max_ind=i;
+ }
+ }
+ _pya_free(mp);
+ return 0;
}
/**end repeat**/
@@ -1666,15 +1666,15 @@
BOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n,
void *ignore)
{
- register Bool tmp=FALSE;
- register intp i;
- for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
+ register Bool tmp=FALSE;
+ register intp i;
+ for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
if ((*((Bool *)ip1) != 0) && (*((Bool *)ip2) != 0)) {
tmp = TRUE;
break;
}
- }
- *((Bool *)op) = tmp;
+ }
+ *((Bool *)op) = tmp;
}
/**begin repeat
@@ -1684,15 +1684,15 @@
*/
static void
@name at _dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n,
- void *ignore)
+ void *ignore)
{
- register @out@ tmp=(@out@)0;
- register intp i;
- for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
- tmp += (@out@)(*((@type@ *)ip1)) * \
- (@out@)(*((@type@ *)ip2));
- }
- *((@type@ *)op) = (@type@) tmp;
+ register @out@ tmp=(@out@)0;
+ register intp i;
+ for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
+ tmp += (@out@)(*((@type@ *)ip1)) * \
+ (@out@)(*((@type@ *)ip2));
+ }
+ *((@type@ *)op) = (@type@) tmp;
}
/**end repeat**/
@@ -1702,46 +1702,46 @@
#type= float, double, longdouble#
*/
static void @name at _dot(char *ip1, intp is1, char *ip2, intp is2,
- char *op, intp n, void *ignore)
-{
- @type@ tmpr=(@type@)0.0, tmpi=(@type@)0.0;
- intp i;
- for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
- tmpr += ((@type@ *)ip1)[0] * ((@type@ *)ip2)[0]
- - ((@type@ *)ip1)[1] * ((@type@ *)ip2)[1];
- tmpi += ((@type@ *)ip1)[1] * ((@type@ *)ip2)[0]
- + ((@type@ *)ip1)[0] * ((@type@ *)ip2)[1];
- }
- ((@type@ *)op)[0] = tmpr; ((@type@ *)op)[1] = tmpi;
+ char *op, intp n, void *ignore)
+{
+ @type@ tmpr=(@type@)0.0, tmpi=(@type@)0.0;
+ intp i;
+ for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
+ tmpr += ((@type@ *)ip1)[0] * ((@type@ *)ip2)[0]
+ - ((@type@ *)ip1)[1] * ((@type@ *)ip2)[1];
+ tmpi += ((@type@ *)ip1)[1] * ((@type@ *)ip2)[0]
+ + ((@type@ *)ip1)[0] * ((@type@ *)ip2)[1];
+ }
+ ((@type@ *)op)[0] = tmpr; ((@type@ *)op)[1] = tmpi;
}
/**end repeat**/
static void
OBJECT_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n,
- void *ignore)
+ void *ignore)
{
- intp i;
- PyObject *tmp1, *tmp2, *tmp=NULL;
- PyObject **tmp3;
- for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
- tmp1 = PyNumber_Multiply(*((PyObject **)ip1),
- *((PyObject **)ip2));
- if (!tmp1) { Py_XDECREF(tmp); return;}
- if (i == 0) {
- tmp = tmp1;
- } else {
- tmp2 = PyNumber_Add(tmp, tmp1);
- Py_XDECREF(tmp);
- Py_XDECREF(tmp1);
- if (!tmp2) return;
- tmp = tmp2;
- }
- }
- tmp3 = (PyObject**) op;
- tmp2 = *tmp3;
- *((PyObject **)op) = tmp;
- Py_XDECREF(tmp2);
+ intp i;
+ PyObject *tmp1, *tmp2, *tmp=NULL;
+ PyObject **tmp3;
+ for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
+ tmp1 = PyNumber_Multiply(*((PyObject **)ip1),
+ *((PyObject **)ip2));
+ if (!tmp1) { Py_XDECREF(tmp); return;}
+ if (i == 0) {
+ tmp = tmp1;
+ } else {
+ tmp2 = PyNumber_Add(tmp, tmp1);
+ Py_XDECREF(tmp);
+ Py_XDECREF(tmp1);
+ if (!tmp2) return;
+ tmp = tmp2;
+ }
+ }
+ tmp3 = (PyObject**) op;
+ tmp2 = *tmp3;
+ *((PyObject **)op) = tmp;
+ Py_XDECREF(tmp2);
}
#define BOOL_fill NULL
@@ -1750,25 +1750,25 @@
static void
OBJECT_fill(PyObject **buffer, intp length, void *ignored)
{
- intp i;
- PyObject *start = buffer[0];
- PyObject *delta = buffer[1];
- delta = PyNumber_Subtract(delta, start);
- if (!delta) return;
- start = PyNumber_Add(start, delta);
- if (!start) goto finish;
- buffer += 2;
-
- for (i=2; i<length; i++, buffer++) {
- start = PyNumber_Add(start, delta);
- if (!start) goto finish;
- Py_XDECREF(*buffer);
- *buffer = start;
- }
+ intp i;
+ PyObject *start = buffer[0];
+ PyObject *delta = buffer[1];
+ delta = PyNumber_Subtract(delta, start);
+ if (!delta) return;
+ start = PyNumber_Add(start, delta);
+ if (!start) goto finish;
+ buffer += 2;
+
+ for (i=2; i<length; i++, buffer++) {
+ start = PyNumber_Add(start, delta);
+ if (!start) goto finish;
+ Py_XDECREF(*buffer);
+ *buffer = start;
+ }
finish:
- Py_DECREF(delta);
- return;
+ Py_DECREF(delta);
+ return;
}
/**begin repeat
@@ -1778,13 +1778,13 @@
static void
@NAME at _fill(@typ@ *buffer, intp length, void *ignored)
{
- register intp i;
- @typ@ start = buffer[0];
- @typ@ delta = buffer[1];
- delta -= start;
- for (i=2; i<length; ++i) {
- buffer[i] = start + i*delta;
- }
+ register intp i;
+ @typ@ start = buffer[0];
+ @typ@ delta = buffer[1];
+ delta -= start;
+ for (i=2; i<length; ++i) {
+ buffer[i] = start + i*delta;
+ }
}
/**end repeat**/
@@ -1795,21 +1795,21 @@
static void
@NAME at _fill(@typ@ *buffer, intp length, void *ignored)
{
- register intp i;
- @typ@ start;
- @typ@ delta;
+ register intp i;
+ @typ@ start;
+ @typ@ delta;
- start.real = buffer->real;
- start.imag = buffer->imag;
- delta.real = buffer[1].real;
- delta.imag = buffer[1].imag;
- delta.real -= start.real;
- delta.imag -= start.imag;
- buffer += 2;
- for (i=2; i<length; i++, buffer++) {
- buffer->real = start.real + i*delta.real;
- buffer->imag = start.imag + i*delta.imag;
- }
+ start.real = buffer->real;
+ start.imag = buffer->imag;
+ delta.real = buffer[1].real;
+ delta.imag = buffer[1].imag;
+ delta.real -= start.real;
+ delta.imag -= start.imag;
+ buffer += 2;
+ for (i=2; i<length; i++, buffer++) {
+ buffer->real = start.real + i*delta.real;
+ buffer->imag = start.imag + i*delta.imag;
+ }
}
/**end repeat**/
@@ -1818,13 +1818,13 @@
static void
OBJECT_fillwithscalar(PyObject **buffer, intp length, PyObject **value, void *ignored)
{
- intp i;
- PyObject *val = *value;
- for (i=0; i<length; i++) {
- Py_XDECREF(buffer[i]);
- Py_XINCREF(val);
- buffer[i] = val;
- }
+ intp i;
+ PyObject *val = *value;
+ for (i=0; i<length; i++) {
+ Py_XDECREF(buffer[i]);
+ Py_XINCREF(val);
+ buffer[i] = val;
+ }
}
/**begin repeat
#NAME=BOOL,BYTE,UBYTE#
@@ -1833,7 +1833,7 @@
static void
@NAME at _fillwithscalar(@typ@ *buffer, intp length, @typ@ *value, void *ignored)
{
- memset(buffer, *value, length);
+ memset(buffer, *value, length);
}
/**end repeat**/
@@ -1844,11 +1844,11 @@
static void
@NAME at _fillwithscalar(@typ@ *buffer, intp length, @typ@ *value, void *ignored)
{
- register intp i;
- @typ@ val = *value;
- for (i=0; i<length; ++i) {
- buffer[i] = val;
- }
+ register intp i;
+ @typ@ val = *value;
+ for (i=0; i<length; ++i) {
+ buffer[i] = val;
+ }
}
/**end repeat**/
@@ -1873,66 +1873,66 @@
*/
static PyArray_ArrFuncs _Py at NAME@_ArrFuncs = {
- {
- (PyArray_VectorUnaryFunc*)@from at _to_BOOL,
- (PyArray_VectorUnaryFunc*)@from at _to_BYTE,
- (PyArray_VectorUnaryFunc*)@from at _to_UBYTE,
- (PyArray_VectorUnaryFunc*)@from at _to_SHORT,
- (PyArray_VectorUnaryFunc*)@from at _to_USHORT,
- (PyArray_VectorUnaryFunc*)@from at _to_INT,
- (PyArray_VectorUnaryFunc*)@from at _to_UINT,
- (PyArray_VectorUnaryFunc*)@from at _to_LONG,
- (PyArray_VectorUnaryFunc*)@from at _to_ULONG,
- (PyArray_VectorUnaryFunc*)@from at _to_LONGLONG,
- (PyArray_VectorUnaryFunc*)@from at _to_ULONGLONG,
- (PyArray_VectorUnaryFunc*)@from at _to_FLOAT,
- (PyArray_VectorUnaryFunc*)@from at _to_DOUBLE,
- (PyArray_VectorUnaryFunc*)@from at _to_LONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from at _to_CFLOAT,
- (PyArray_VectorUnaryFunc*)@from at _to_CDOUBLE,
- (PyArray_VectorUnaryFunc*)@from at _to_CLONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from at _to_OBJECT,
- (PyArray_VectorUnaryFunc*)@from at _to_STRING,
- (PyArray_VectorUnaryFunc*)@from at _to_UNICODE,
- (PyArray_VectorUnaryFunc*)@from at _to_VOID
- },
- (PyArray_GetItemFunc*)@from at _getitem,
- (PyArray_SetItemFunc*)@from at _setitem,
- (PyArray_CopySwapNFunc*)@from at _copyswapn,
- (PyArray_CopySwapFunc*)@from at _copyswap,
- (PyArray_CompareFunc*)@from at _compare,
- (PyArray_ArgFunc*)@from at _argmax,
- (PyArray_DotFunc*)NULL,
- (PyArray_ScanFunc*)@from at _scan,
- (PyArray_FromStrFunc*)@from at _fromstr,
- (PyArray_NonzeroFunc*)@from at _nonzero,
- (PyArray_FillFunc*)NULL,
- (PyArray_FillWithScalarFunc*)NULL,
- {
- NULL, NULL, NULL
- },
- {
- NULL, NULL, NULL
- },
- NULL,
- (PyArray_ScalarKindFunc*)NULL,
- NULL,
- NULL,
- 0
+ {
+ (PyArray_VectorUnaryFunc*)@from at _to_BOOL,
+ (PyArray_VectorUnaryFunc*)@from at _to_BYTE,
+ (PyArray_VectorUnaryFunc*)@from at _to_UBYTE,
+ (PyArray_VectorUnaryFunc*)@from at _to_SHORT,
+ (PyArray_VectorUnaryFunc*)@from at _to_USHORT,
+ (PyArray_VectorUnaryFunc*)@from at _to_INT,
+ (PyArray_VectorUnaryFunc*)@from at _to_UINT,
+ (PyArray_VectorUnaryFunc*)@from at _to_LONG,
+ (PyArray_VectorUnaryFunc*)@from at _to_ULONG,
+ (PyArray_VectorUnaryFunc*)@from at _to_LONGLONG,
+ (PyArray_VectorUnaryFunc*)@from at _to_ULONGLONG,
+ (PyArray_VectorUnaryFunc*)@from at _to_FLOAT,
+ (PyArray_VectorUnaryFunc*)@from at _to_DOUBLE,
+ (PyArray_VectorUnaryFunc*)@from at _to_LONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from at _to_CFLOAT,
+ (PyArray_VectorUnaryFunc*)@from at _to_CDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from at _to_CLONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from at _to_OBJECT,
+ (PyArray_VectorUnaryFunc*)@from at _to_STRING,
+ (PyArray_VectorUnaryFunc*)@from at _to_UNICODE,
+ (PyArray_VectorUnaryFunc*)@from at _to_VOID
+ },
+ (PyArray_GetItemFunc*)@from at _getitem,
+ (PyArray_SetItemFunc*)@from at _setitem,
+ (PyArray_CopySwapNFunc*)@from at _copyswapn,
+ (PyArray_CopySwapFunc*)@from at _copyswap,
+ (PyArray_CompareFunc*)@from at _compare,
+ (PyArray_ArgFunc*)@from at _argmax,
+ (PyArray_DotFunc*)NULL,
+ (PyArray_ScanFunc*)@from at _scan,
+ (PyArray_FromStrFunc*)@from at _fromstr,
+ (PyArray_NonzeroFunc*)@from at _nonzero,
+ (PyArray_FillFunc*)NULL,
+ (PyArray_FillWithScalarFunc*)NULL,
+ {
+ NULL, NULL, NULL
+ },
+ {
+ NULL, NULL, NULL
+ },
+ NULL,
+ (PyArray_ScalarKindFunc*)NULL,
+ NULL,
+ NULL,
+ 0
};
static PyArray_Descr @from at _Descr = {
- PyObject_HEAD_INIT(&PyArrayDescr_Type)
- &Py at NAME@ArrType_Type,
- PyArray_ at from@LTR,
- PyArray_ at from@LTR,
- '@endian@', 0,
- PyArray_ at from@, 0,
- _ALIGN(@align@),
- NULL,
- NULL,
+ PyObject_HEAD_INIT(&PyArrayDescr_Type)
+ &Py at NAME@ArrType_Type,
+ PyArray_ at from@LTR,
+ PyArray_ at from@LTR,
+ '@endian@', 0,
+ PyArray_ at from@, 0,
+ _ALIGN(@align@),
NULL,
- &_Py at NAME@_ArrFuncs,
+ NULL,
+ NULL,
+ &_Py at NAME@_ArrFuncs,
};
/**end repeat**/
@@ -1950,67 +1950,67 @@
*/
static PyArray_ArrFuncs _Py at NAME@_ArrFuncs = {
- {
- (PyArray_VectorUnaryFunc*)@from at _to_BOOL,
- (PyArray_VectorUnaryFunc*)@from at _to_BYTE,
- (PyArray_VectorUnaryFunc*)@from at _to_UBYTE,
- (PyArray_VectorUnaryFunc*)@from at _to_SHORT,
- (PyArray_VectorUnaryFunc*)@from at _to_USHORT,
- (PyArray_VectorUnaryFunc*)@from at _to_INT,
- (PyArray_VectorUnaryFunc*)@from at _to_UINT,
- (PyArray_VectorUnaryFunc*)@from at _to_LONG,
- (PyArray_VectorUnaryFunc*)@from at _to_ULONG,
- (PyArray_VectorUnaryFunc*)@from at _to_LONGLONG,
- (PyArray_VectorUnaryFunc*)@from at _to_ULONGLONG,
- (PyArray_VectorUnaryFunc*)@from at _to_FLOAT,
- (PyArray_VectorUnaryFunc*)@from at _to_DOUBLE,
- (PyArray_VectorUnaryFunc*)@from at _to_LONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from at _to_CFLOAT,
- (PyArray_VectorUnaryFunc*)@from at _to_CDOUBLE,
- (PyArray_VectorUnaryFunc*)@from at _to_CLONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from at _to_OBJECT,
- (PyArray_VectorUnaryFunc*)@from at _to_STRING,
- (PyArray_VectorUnaryFunc*)@from at _to_UNICODE,
- (PyArray_VectorUnaryFunc*)@from at _to_VOID
- },
- (PyArray_GetItemFunc*)@from at _getitem,
- (PyArray_SetItemFunc*)@from at _setitem,
- (PyArray_CopySwapNFunc*)@from at _copyswapn,
- (PyArray_CopySwapFunc*)@from at _copyswap,
- (PyArray_CompareFunc*)@from at _compare,
- (PyArray_ArgFunc*)@from at _argmax,
- (PyArray_DotFunc*)@from at _dot,
- (PyArray_ScanFunc*)@from at _scan,
- (PyArray_FromStrFunc*)@from at _fromstr,
- (PyArray_NonzeroFunc*)@from at _nonzero,
- (PyArray_FillFunc*)@from at _fill,
- (PyArray_FillWithScalarFunc*)@from at _fillwithscalar,
- {
- NULL, NULL, NULL
- },
- {
- NULL, NULL, NULL
- },
- NULL,
- (PyArray_ScalarKindFunc*)NULL,
- NULL,
- NULL,
- 0
+ {
+ (PyArray_VectorUnaryFunc*)@from at _to_BOOL,
+ (PyArray_VectorUnaryFunc*)@from at _to_BYTE,
+ (PyArray_VectorUnaryFunc*)@from at _to_UBYTE,
+ (PyArray_VectorUnaryFunc*)@from at _to_SHORT,
+ (PyArray_VectorUnaryFunc*)@from at _to_USHORT,
+ (PyArray_VectorUnaryFunc*)@from at _to_INT,
+ (PyArray_VectorUnaryFunc*)@from at _to_UINT,
+ (PyArray_VectorUnaryFunc*)@from at _to_LONG,
+ (PyArray_VectorUnaryFunc*)@from at _to_ULONG,
+ (PyArray_VectorUnaryFunc*)@from at _to_LONGLONG,
+ (PyArray_VectorUnaryFunc*)@from at _to_ULONGLONG,
+ (PyArray_VectorUnaryFunc*)@from at _to_FLOAT,
+ (PyArray_VectorUnaryFunc*)@from at _to_DOUBLE,
+ (PyArray_VectorUnaryFunc*)@from at _to_LONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from at _to_CFLOAT,
+ (PyArray_VectorUnaryFunc*)@from at _to_CDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from at _to_CLONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from at _to_OBJECT,
+ (PyArray_VectorUnaryFunc*)@from at _to_STRING,
+ (PyArray_VectorUnaryFunc*)@from at _to_UNICODE,
+ (PyArray_VectorUnaryFunc*)@from at _to_VOID
+ },
+ (PyArray_GetItemFunc*)@from at _getitem,
+ (PyArray_SetItemFunc*)@from at _setitem,
+ (PyArray_CopySwapNFunc*)@from at _copyswapn,
+ (PyArray_CopySwapFunc*)@from at _copyswap,
+ (PyArray_CompareFunc*)@from at _compare,
+ (PyArray_ArgFunc*)@from at _argmax,
+ (PyArray_DotFunc*)@from at _dot,
+ (PyArray_ScanFunc*)@from at _scan,
+ (PyArray_FromStrFunc*)@from at _fromstr,
+ (PyArray_NonzeroFunc*)@from at _nonzero,
+ (PyArray_FillFunc*)@from at _fill,
+ (PyArray_FillWithScalarFunc*)@from at _fillwithscalar,
+ {
+ NULL, NULL, NULL
+ },
+ {
+ NULL, NULL, NULL
+ },
+ NULL,
+ (PyArray_ScalarKindFunc*)NULL,
+ NULL,
+ NULL,
+ 0
};
static PyArray_Descr @from at _Descr = {
- PyObject_HEAD_INIT(&PyArrayDescr_Type)
- &Py at NAME@ArrType_Type,
- PyArray_ at kind@LTR,
- PyArray_ at from@LTR,
- '@endian@', @isobject@,
- PyArray_ at from@,
- @num@*sizeof(@fromtyp@),
- _ALIGN(@fromtyp@),
- NULL,
- NULL,
+ PyObject_HEAD_INIT(&PyArrayDescr_Type)
+ &Py at NAME@ArrType_Type,
+ PyArray_ at kind@LTR,
+ PyArray_ at from@LTR,
+ '@endian@', @isobject@,
+ PyArray_ at from@,
+ @num@*sizeof(@fromtyp@),
+ _ALIGN(@fromtyp@),
NULL,
- &_Py at NAME@_ArrFuncs,
+ NULL,
+ NULL,
+ &_Py at NAME@_ArrFuncs,
};
/**end repeat**/
@@ -2019,27 +2019,27 @@
static char _letter_to_num[_MAX_LETTER];
static PyArray_Descr *_builtin_descrs[] = {
- &BOOL_Descr,
- &BYTE_Descr,
- &UBYTE_Descr,
- &SHORT_Descr,
- &USHORT_Descr,
- &INT_Descr,
- &UINT_Descr,
- &LONG_Descr,
- &ULONG_Descr,
- &LONGLONG_Descr,
- &ULONGLONG_Descr,
- &FLOAT_Descr,
- &DOUBLE_Descr,
- &LONGDOUBLE_Descr,
- &CFLOAT_Descr,
- &CDOUBLE_Descr,
- &CLONGDOUBLE_Descr,
- &OBJECT_Descr,
- &STRING_Descr,
- &UNICODE_Descr,
- &VOID_Descr,
+ &BOOL_Descr,
+ &BYTE_Descr,
+ &UBYTE_Descr,
+ &SHORT_Descr,
+ &USHORT_Descr,
+ &INT_Descr,
+ &UINT_Descr,
+ &LONG_Descr,
+ &ULONG_Descr,
+ &LONGLONG_Descr,
+ &ULONGLONG_Descr,
+ &FLOAT_Descr,
+ &DOUBLE_Descr,
+ &LONGDOUBLE_Descr,
+ &CFLOAT_Descr,
+ &CDOUBLE_Descr,
+ &CLONGDOUBLE_Descr,
+ &OBJECT_Descr,
+ &STRING_Descr,
+ &UNICODE_Descr,
+ &VOID_Descr,
};
/*OBJECT_API
@@ -2048,72 +2048,72 @@
static PyArray_Descr *
PyArray_DescrFromType(int type)
{
- PyArray_Descr *ret=NULL;
+ PyArray_Descr *ret=NULL;
- if (type < PyArray_NTYPES) {
- ret = _builtin_descrs[type];
- }
- else if (type == PyArray_NOTYPE) {
- /* This needs to not raise an error so
- that PyArray_DescrFromType(PyArray_NOTYPE)
- works for backwards-compatible C-API
- */
- return NULL;
- }
- else if ((type == PyArray_CHAR) || \
- (type == PyArray_CHARLTR)) {
- ret = PyArray_DescrNew(_builtin_descrs[PyArray_STRING]);
- ret->elsize = 1;
- ret->type = PyArray_CHARLTR;
- return ret;
- }
- else if PyTypeNum_ISUSERDEF(type) {
- ret = userdescrs[type-PyArray_USERDEF];
- }
- else {
- int num=PyArray_NTYPES;
- if (type < _MAX_LETTER)
- num = (int) _letter_to_num[type];
- if (num >= PyArray_NTYPES)
- ret = NULL;
- else
- ret = _builtin_descrs[num];
- }
- if (ret==NULL) {
- PyErr_SetString(PyExc_ValueError,
- "Invalid data-type for array");
- }
- else Py_INCREF(ret);
- return ret;
+ if (type < PyArray_NTYPES) {
+ ret = _builtin_descrs[type];
+ }
+ else if (type == PyArray_NOTYPE) {
+ /* This needs to not raise an error so
+ that PyArray_DescrFromType(PyArray_NOTYPE)
+ works for backwards-compatible C-API
+ */
+ return NULL;
+ }
+ else if ((type == PyArray_CHAR) || \
+ (type == PyArray_CHARLTR)) {
+ ret = PyArray_DescrNew(_builtin_descrs[PyArray_STRING]);
+ ret->elsize = 1;
+ ret->type = PyArray_CHARLTR;
+ return ret;
+ }
+ else if PyTypeNum_ISUSERDEF(type) {
+ ret = userdescrs[type-PyArray_USERDEF];
+ }
+ else {
+ int num=PyArray_NTYPES;
+ if (type < _MAX_LETTER)
+ num = (int) _letter_to_num[type];
+ if (num >= PyArray_NTYPES)
+ ret = NULL;
+ else
+ ret = _builtin_descrs[num];
+ }
+ if (ret==NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Invalid data-type for array");
+ }
+ else Py_INCREF(ret);
+ return ret;
}
static int
set_typeinfo(PyObject *dict)
{
- PyObject *infodict, *s;
- int i;
+ PyObject *infodict, *s;
+ int i;
- for (i=0; i<_MAX_LETTER; i++) {
- _letter_to_num[i] = PyArray_NTYPES;
- }
+ for (i=0; i<_MAX_LETTER; i++) {
+ _letter_to_num[i] = PyArray_NTYPES;
+ }
/**begin repeat
#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#
*/
- _letter_to_num[PyArray_ at name@LTR] = PyArray_ at name@;
+ _letter_to_num[PyArray_ at name@LTR] = PyArray_ at name@;
/**end repeat**/
- _letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;
+ _letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;
/**begin repeat
#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#
*/
- @name at _Descr.fields = Py_None;
+ @name at _Descr.fields = Py_None;
/**end repeat**/
- /* Set a dictionary with type information */
- infodict = PyDict_New();
- if (infodict == NULL) return -1;
+ /* Set a dictionary with type information */
+ infodict = PyDict_New();
+ if (infodict == NULL) return -1;
#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T
#define BITSOF_BYTE CHAR_BIT
@@ -2129,15 +2129,15 @@
#cx=i*6,N,N,N,l,N,N,N#
#cn=i*7,N,i,l,i,N,i#
*/
- PyDict_SetItemString(infodict, "@name@",
- s=Py_BuildValue("ciii at cx@@cn at O",
- PyArray_ at name@LTR,
- PyArray_ at name@,
- BITSOF_ at uname@,
- _ALIGN(@type@),
- @max@, @min@,
- (PyObject *)&Py at Name@ArrType_Type));
- Py_DECREF(s);
+ PyDict_SetItemString(infodict, "@name@",
+ s=Py_BuildValue("ciii at cx@@cn at O",
+ PyArray_ at name@LTR,
+ PyArray_ at name@,
+ BITSOF_ at uname@,
+ _ALIGN(@type@),
+ @max@, @min@,
+ (PyObject *)&Py at Name@ArrType_Type));
+ Py_DECREF(s);
/**end repeat**/
#define BITSOF_CFLOAT 2*BITSOF_FLOAT
@@ -2150,44 +2150,44 @@
#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#
#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#
*/
- PyDict_SetItemString(infodict, "@name@",
- s=Py_BuildValue("ciiiO", PyArray_ at name@LTR,
- PyArray_ at name@, BITSOF_ at name@,
- _ALIGN(@type@),
+ PyDict_SetItemString(infodict, "@name@",
+ s=Py_BuildValue("ciiiO", PyArray_ at name@LTR,
+ PyArray_ at name@, BITSOF_ at name@,
+ _ALIGN(@type@),
(PyObject *)\
&Py at Name@ArrType_Type));
- Py_DECREF(s);
+ Py_DECREF(s);
/**end repeat**/
-
- PyDict_SetItemString(infodict, "OBJECT",
- s=Py_BuildValue("ciiiO", PyArray_OBJECTLTR,
- PyArray_OBJECT,
- sizeof(PyObject *)*CHAR_BIT,
- _ALIGN(PyObject *),
+
+ PyDict_SetItemString(infodict, "OBJECT",
+ s=Py_BuildValue("ciiiO", PyArray_OBJECTLTR,
+ PyArray_OBJECT,
+ sizeof(PyObject *)*CHAR_BIT,
+ _ALIGN(PyObject *),
(PyObject *)\
&PyObjectArrType_Type));
- Py_DECREF(s);
- PyDict_SetItemString(infodict, "STRING",
- s=Py_BuildValue("ciiiO", PyArray_STRINGLTR,
- PyArray_STRING, 0,
- _ALIGN(char),
+ Py_DECREF(s);
+ PyDict_SetItemString(infodict, "STRING",
+ s=Py_BuildValue("ciiiO", PyArray_STRINGLTR,
+ PyArray_STRING, 0,
+ _ALIGN(char),
(PyObject *)\
&PyStringArrType_Type));
- Py_DECREF(s);
- PyDict_SetItemString(infodict, "UNICODE",
- s=Py_BuildValue("ciiiO", PyArray_UNICODELTR,
- PyArray_UNICODE, 0,
- _ALIGN(PyArray_UCS4),
+ Py_DECREF(s);
+ PyDict_SetItemString(infodict, "UNICODE",
+ s=Py_BuildValue("ciiiO", PyArray_UNICODELTR,
+ PyArray_UNICODE, 0,
+ _ALIGN(PyArray_UCS4),
(PyObject *)\
- &PyUnicodeArrType_Type));
- Py_DECREF(s);
- PyDict_SetItemString(infodict, "VOID",
- s=Py_BuildValue("ciiiO", PyArray_VOIDLTR,
- PyArray_VOID, 0,
- _ALIGN(char),
+ &PyUnicodeArrType_Type));
+ Py_DECREF(s);
+ PyDict_SetItemString(infodict, "VOID",
+ s=Py_BuildValue("ciiiO", PyArray_VOIDLTR,
+ PyArray_VOID, 0,
+ _ALIGN(char),
(PyObject *)\
- &PyVoidArrType_Type));
- Py_DECREF(s);
+ &PyVoidArrType_Type));
+ Py_DECREF(s);
#define SETTYPE(name) \
Py_INCREF(&Py##name##ArrType_Type); \
@@ -2197,7 +2197,7 @@
SETTYPE(Generic)
SETTYPE(Number)
SETTYPE(Integer)
- SETTYPE(Inexact)
+ SETTYPE(Inexact)
SETTYPE(SignedInteger)
SETTYPE(UnsignedInteger)
SETTYPE(Floating)
@@ -2205,11 +2205,11 @@
SETTYPE(Flexible)
SETTYPE(Character)
-#undef SETTYPE
+#undef SETTYPE
- PyDict_SetItemString(dict, "typeinfo", infodict);
- Py_DECREF(infodict);
- return 0;
+ PyDict_SetItemString(dict, "typeinfo", infodict);
+ Py_DECREF(infodict);
+ return 0;
}
#undef _MAX_LETTER
Modified: branches/ver1.0/numpy/core/src/scalartypes.inc.src
===================================================================
--- branches/ver1.0/numpy/core/src/scalartypes.inc.src 2006-07-26 12:29:49 UTC (rev 2897)
+++ branches/ver1.0/numpy/core/src/scalartypes.inc.src 2006-07-26 16:25:14 UTC (rev 2898)
@@ -6,8 +6,8 @@
#include "numpy/arrayscalars.h"
static PyBoolScalarObject _PyArrayScalar_BoolValues[2] = {
- {PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},
- {PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},
+ {PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},
+ {PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},
};
/* Inheritance established later when tp_bases is set (or tp_base for
@@ -22,51 +22,51 @@
static PyTypeObject Py at NAME@ArrType_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "@name at scalar", /*tp_name*/
- sizeof(PyObject), /*tp_basicsize*/
+ 0, /*ob_size*/
+ "@name at scalar", /*tp_name*/
+ sizeof(PyObject), /*tp_basicsize*/
};
/**end repeat**/
static void *
scalar_value(PyObject *scalar, PyArray_Descr *descr)
{
- enum NPY_TYPES type_num;
- if (descr == NULL) {
- descr = PyArray_DescrFromScalar(scalar);
- type_num = descr->type_num;
- Py_DECREF(descr);
- } else {
- type_num = descr->type_num;
- }
- switch (type_num) {
+ enum NPY_TYPES type_num;
+ if (descr == NULL) {
+ descr = PyArray_DescrFromScalar(scalar);
+ type_num = descr->type_num;
+ Py_DECREF(descr);
+ } else {
+ type_num = descr->type_num;
+ }
+ switch (type_num) {
#define CASE(ut,lt) case NPY_##ut: return &(((Py##lt##ScalarObject *)scalar)->obval)
- CASE(BOOL, Bool);
- CASE(BYTE, Byte);
- CASE(UBYTE, UByte);
- CASE(SHORT, Short);
- CASE(USHORT, UShort);
- CASE(INT, Int);
- CASE(UINT, UInt);
- CASE(LONG, Long);
- CASE(ULONG, ULong);
- CASE(LONGLONG, LongLong);
- CASE(ULONGLONG, ULongLong);
- CASE(FLOAT, Float);
- CASE(DOUBLE, Double);
- CASE(LONGDOUBLE, LongDouble);
- CASE(CFLOAT, CFloat);
- CASE(CDOUBLE, CDouble);
- CASE(CLONGDOUBLE, CLongDouble);
- CASE(OBJECT, Object);
+ CASE(BOOL, Bool);
+ CASE(BYTE, Byte);
+ CASE(UBYTE, UByte);
+ CASE(SHORT, Short);
+ CASE(USHORT, UShort);
+ CASE(INT, Int);
+ CASE(UINT, UInt);
+ CASE(LONG, Long);
+ CASE(ULONG, ULong);
+ CASE(LONGLONG, LongLong);
+ CASE(ULONGLONG, ULongLong);
+ CASE(FLOAT, Float);
+ CASE(DOUBLE, Double);
+ CASE(LONGDOUBLE, LongDouble);
+ CASE(CFLOAT, CFloat);
+ CASE(CDOUBLE, CDouble);
+ CASE(CLONGDOUBLE, CLongDouble);
+ CASE(OBJECT, Object);
#undef CASE
- case NPY_STRING: return (void *)PyString_AS_STRING(scalar);
- case NPY_UNICODE: return (void *)PyUnicode_AS_DATA(scalar);
- case NPY_VOID: return ((PyVoidScalarObject *)scalar)->obval;
- default:
- return NULL;
- }
- return NULL;
+ case NPY_STRING: return (void *)PyString_AS_STRING(scalar);
+ case NPY_UNICODE: return (void *)PyUnicode_AS_DATA(scalar);
+ case NPY_VOID: return ((PyVoidScalarObject *)scalar)->obval;
+ default:
+ return NULL;
+ }
+ return NULL;
}
/* no error checking is performed -- ctypeptr must be same type as scalar */
@@ -78,19 +78,19 @@
static void
PyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)
{
- PyArray_Descr *typecode;
- void *newptr;
- typecode = PyArray_DescrFromScalar(scalar);
- newptr = scalar_value(scalar, typecode);
+ PyArray_Descr *typecode;
+ void *newptr;
+ typecode = PyArray_DescrFromScalar(scalar);
+ newptr = scalar_value(scalar, typecode);
- if (PyTypeNum_ISEXTENDED(typecode->type_num)) {
- void **ct = (void **)ctypeptr;
- *ct = newptr;
- } else {
- memcpy(ctypeptr, newptr, typecode->elsize);
- }
- Py_DECREF(typecode);
- return;
+ if (PyTypeNum_ISEXTENDED(typecode->type_num)) {
+ void **ct = (void **)ctypeptr;
+ *ct = newptr;
+ } else {
+ memcpy(ctypeptr, newptr, typecode->elsize);
+ }
+ Py_DECREF(typecode);
+ return;
}
/* The output buffer must be large-enough to receive the value */
@@ -103,36 +103,36 @@
*/
static int
PyArray_CastScalarToCtype(PyObject *scalar, void *ctypeptr,
- PyArray_Descr *outcode)
+ PyArray_Descr *outcode)
{
- PyArray_Descr* descr;
- PyArray_VectorUnaryFunc* castfunc;
+ PyArray_Descr* descr;
+ PyArray_VectorUnaryFunc* castfunc;
- descr = PyArray_DescrFromScalar(scalar);
- castfunc = PyArray_GetCastFunc(descr, outcode->type_num);
- if (castfunc == NULL) return -1;
- if (PyTypeNum_ISEXTENDED(descr->type_num) ||
- PyTypeNum_ISEXTENDED(outcode->type_num)) {
- PyArrayObject *ain, *aout;
+ descr = PyArray_DescrFromScalar(scalar);
+ castfunc = PyArray_GetCastFunc(descr, outcode->type_num);
+ if (castfunc == NULL) return -1;
+ if (PyTypeNum_ISEXTENDED(descr->type_num) ||
+ PyTypeNum_ISEXTENDED(outcode->type_num)) {
+ PyArrayObject *ain, *aout;
- ain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);
- if (ain == NULL) {Py_DECREF(descr); return -1;}
- aout = (PyArrayObject *)
- PyArray_NewFromDescr(&PyArray_Type,
- outcode,
- 0, NULL,
- NULL, ctypeptr,
- CARRAY, NULL);
- if (aout == NULL) {Py_DECREF(ain); return -1;}
- castfunc(ain->data, aout->data, 1, ain, aout);
- Py_DECREF(ain);
- Py_DECREF(aout);
- }
- else {
- castfunc(scalar_value(scalar, descr), ctypeptr, 1, NULL, NULL);
- }
- Py_DECREF(descr);
- return 0;
+ ain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);
+ if (ain == NULL) {Py_DECREF(descr); return -1;}
+ aout = (PyArrayObject *)
+ PyArray_NewFromDescr(&PyArray_Type,
+ outcode,
+ 0, NULL,
+ NULL, ctypeptr,
+ CARRAY, NULL);
+ if (aout == NULL) {Py_DECREF(ain); return -1;}
+ castfunc(ain->data, aout->data, 1, ain, aout);
+ Py_DECREF(ain);
+ Py_DECREF(aout);
+ }
+ else {
+ castfunc(scalar_value(scalar, descr), ctypeptr, 1, NULL, NULL);
+ }
+ Py_DECREF(descr);
+ return 0;
}
/*OBJECT_API
@@ -140,14 +140,14 @@
*/
static int
PyArray_CastScalarDirect(PyObject *scalar, PyArray_Descr *indescr,
- void *ctypeptr, int outtype)
+ void *ctypeptr, int outtype)
{
- PyArray_VectorUnaryFunc* castfunc;
- castfunc = PyArray_GetCastFunc(indescr, outtype);
- if (castfunc == NULL) return -1;
- castfunc(scalar_value(scalar, indescr),
+ PyArray_VectorUnaryFunc* castfunc;
+ castfunc = PyArray_GetCastFunc(indescr, outtype);
+ if (castfunc == NULL) return -1;
+ castfunc(scalar_value(scalar, indescr),
ctypeptr, 1, NULL, NULL);
- return 0;
+ return 0;
}
/* 0-dim array from array-scalar object */
@@ -163,61 +163,61 @@
static PyObject *
PyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)
{
- PyArray_Descr *typecode;
- PyObject *r;
- char *memptr;
- PyObject *ret;
+ PyArray_Descr *typecode;
+ PyObject *r;
+ char *memptr;
+ PyObject *ret;
- /* convert to 0-dim array of scalar typecode */
- typecode = PyArray_DescrFromScalar(scalar);
- if ((typecode->type_num == PyArray_VOID) &&
- !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&
- outcode == NULL) {
- r = PyArray_NewFromDescr(&PyArray_Type,
- typecode,
- 0, NULL, NULL,
- ((PyVoidScalarObject *)scalar)->obval,
- ((PyVoidScalarObject *)scalar)->flags,
- NULL);
- PyArray_BASE(r) = (PyObject *)scalar;
- Py_INCREF(scalar);
- return r;
- }
- r = PyArray_NewFromDescr(&PyArray_Type,
- typecode,
- 0, NULL,
- NULL, NULL, 0, NULL);
- if (r==NULL) {Py_XDECREF(outcode); return NULL;}
+ /* convert to 0-dim array of scalar typecode */
+ typecode = PyArray_DescrFromScalar(scalar);
+ if ((typecode->type_num == PyArray_VOID) &&
+ !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&
+ outcode == NULL) {
+ r = PyArray_NewFromDescr(&PyArray_Type,
+ typecode,
+ 0, NULL, NULL,
+ ((PyVoidScalarObject *)scalar)->obval,
+ ((PyVoidScalarObject *)scalar)->flags,
+ NULL);
+ PyArray_BASE(r) = (PyObject *)scalar;
+ Py_INCREF(scalar);
+ return r;
+ }
+ r = PyArray_NewFromDescr(&PyArray_Type,
+ typecode,
+ 0, NULL,
+ NULL, NULL, 0, NULL);
+ if (r==NULL) {Py_XDECREF(outcode); return NULL;}
- memptr = scalar_value(scalar, typecode);
+ memptr = scalar_value(scalar, typecode);
#ifndef Py_UNICODE_WIDE
- if (typecode->type_num == PyArray_UNICODE) {
- PyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr,
- (PyArray_UCS4 *)PyArray_DATA(r),
- PyUnicode_GET_SIZE(scalar),
- PyArray_ITEMSIZE(r) >> 2);
- } else
+ if (typecode->type_num == PyArray_UNICODE) {
+ PyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr,
+ (PyArray_UCS4 *)PyArray_DATA(r),
+ PyUnicode_GET_SIZE(scalar),
+ PyArray_ITEMSIZE(r) >> 2);
+ } else
#endif
- {
- memcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));
- if (PyArray_ISOBJECT(r)) {
- Py_INCREF(*((PyObject **)memptr));
- }
- }
+ {
+ memcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));
+ if (PyArray_ISOBJECT(r)) {
+ Py_INCREF(*((PyObject **)memptr));
+ }
+ }
- if (outcode == NULL) return r;
+ if (outcode == NULL) return r;
- if (outcode->type_num == typecode->type_num) {
- if (!PyTypeNum_ISEXTENDED(typecode->type_num))
- return r;
- if (outcode->elsize == typecode->elsize);
- return r;
- }
+ if (outcode->type_num == typecode->type_num) {
+ if (!PyTypeNum_ISEXTENDED(typecode->type_num))
+ return r;
+ if (outcode->elsize == typecode->elsize);
+ return r;
+ }
- /* cast if necessary to desired output typecode */
- ret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);
- Py_DECREF(r);
- return ret;
+ /* cast if necessary to desired output typecode */
+ ret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);
+ Py_DECREF(r);
+ return ret;
}
/*OBJECT_API
@@ -229,48 +229,48 @@
static PyObject *
PyArray_ScalarFromObject(PyObject *object)
{
- PyObject *ret=NULL;
- if (PyArray_IsZeroDim(object)) {
- return PyArray_ToScalar(PyArray_DATA(object), object);
- }
- if (PyInt_Check(object)) {
- ret = PyArrayScalar_New(Long);
- if (ret == NULL) return NULL;
- PyArrayScalar_VAL(ret, Long) = PyInt_AS_LONG(object);
- }
- else if (PyFloat_Check(object)) {
- ret = PyArrayScalar_New(Double);
- if (ret == NULL) return NULL;
- PyArrayScalar_VAL(ret, Double) = PyFloat_AS_DOUBLE(object);
- }
- else if (PyComplex_Check(object)) {
- ret = PyArrayScalar_New(CDouble);
- if (ret == NULL) return NULL;
- PyArrayScalar_VAL(ret, CDouble).real = \
- ((PyComplexObject *)object)->cval.real;
- PyArrayScalar_VAL(ret, CDouble).imag = \
- ((PyComplexObject *)object)->cval.imag;
- }
- else if (PyLong_Check(object)) {
- longlong val;
- val = PyLong_AsLongLong(object);
- if (val==-1 && PyErr_Occurred()) {
- PyErr_Clear();
- return NULL;
- }
- ret = PyArrayScalar_New(LongLong);
- if (ret == NULL) return NULL;
- PyArrayScalar_VAL(ret, LongLong) = val;
- }
- else if (PyBool_Check(object)) {
- if (object == Py_True) {
- PyArrayScalar_RETURN_TRUE;
- }
- else {
- PyArrayScalar_RETURN_FALSE;
- }
- }
- return ret;
+ PyObject *ret=NULL;
+ if (PyArray_IsZeroDim(object)) {
+ return PyArray_ToScalar(PyArray_DATA(object), object);
+ }
+ if (PyInt_Check(object)) {
+ ret = PyArrayScalar_New(Long);
+ if (ret == NULL) return NULL;
+ PyArrayScalar_VAL(ret, Long) = PyInt_AS_LONG(object);
+ }
+ else if (PyFloat_Check(object)) {
+ ret = PyArrayScalar_New(Double);
+ if (ret == NULL) return NULL;
+ PyArrayScalar_VAL(ret, Double) = PyFloat_AS_DOUBLE(object);
+ }
+ else if (PyComplex_Check(object)) {
+ ret = PyArrayScalar_New(CDouble);
+ if (ret == NULL) return NULL;
+ PyArrayScalar_VAL(ret, CDouble).real = \
+ ((PyComplexObject *)object)->cval.real;
+ PyArrayScalar_VAL(ret, CDouble).imag = \
+ ((PyComplexObject *)object)->cval.imag;
+ }
+ else if (PyLong_Check(object)) {
+ longlong val;
+ val = PyLong_AsLongLong(object);
+ if (val==-1 && PyErr_Occurred()) {
+ PyErr_Clear();
+ return NULL;
+ }
+ ret = PyArrayScalar_New(LongLong);
+ if (ret == NULL) return NULL;
+ PyArrayScalar_VAL(ret, LongLong) = val;
+ }
+ else if (PyBool_Check(object)) {
+ if (object == Py_True) {
+ PyArrayScalar_RETURN_TRUE;
+ }
+ else {
+ PyArrayScalar_RETURN_FALSE;
+ }
+ }
+ return ret;
}
@@ -281,8 +281,8 @@
const size_t size = _PyObject_VAR_SIZE(type, nitems+1);
obj = (PyObject *)_pya_malloc(size);
- memset(obj, 0, size);
- if (type->tp_itemsize == 0)
+ memset(obj, 0, size);
+ if (type->tp_itemsize == 0)
PyObject_INIT(obj, type);
else
(void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);
@@ -292,80 +292,80 @@
static void
gentype_dealloc(PyObject *v)
{
- v->ob_type->tp_free(v);
+ v->ob_type->tp_free(v);
}
static PyObject *
gentype_power(PyObject *m1, PyObject *m2, PyObject *m3)
{
- PyObject *arr, *ret, *arg2;
- char *msg="unsupported operand type(s) for ** or pow()";
+ PyObject *arr, *ret, *arg2;
+ char *msg="unsupported operand type(s) for ** or pow()";
- if (!PyArray_IsScalar(m1,Generic)) {
- if (PyArray_Check(m1)) {
- ret = m1->ob_type->tp_as_number->nb_power(m1,m2,
- Py_None);
- }
- else {
- if (!PyArray_IsScalar(m2,Generic)) {
- PyErr_SetString(PyExc_TypeError, msg);
- return NULL;
- }
- arr = PyArray_FromScalar(m2, NULL);
- if (arr == NULL) return NULL;
- ret = arr->ob_type->tp_as_number->nb_power(m1, arr,
- Py_None);
- Py_DECREF(arr);
- }
- return ret;
- }
- if (!PyArray_IsScalar(m2, Generic)) {
- if (PyArray_Check(m2)) {
- ret = m2->ob_type->tp_as_number->nb_power(m1,m2,
- Py_None);
- }
- else {
- if (!PyArray_IsScalar(m1, Generic)) {
- PyErr_SetString(PyExc_TypeError, msg);
- return NULL;
- }
- arr = PyArray_FromScalar(m1, NULL);
- if (arr == NULL) return NULL;
- ret = arr->ob_type->tp_as_number->nb_power(arr, m2,
- Py_None);
- Py_DECREF(arr);
- }
- return ret;
- }
- arr=arg2=NULL;
- arr = PyArray_FromScalar(m1, NULL);
- arg2 = PyArray_FromScalar(m2, NULL);
- if (arr == NULL || arg2 == NULL) {
- Py_XDECREF(arr); Py_XDECREF(arg2); return NULL;
- }
- ret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);
- Py_DECREF(arr);
- Py_DECREF(arg2);
- return ret;
+ if (!PyArray_IsScalar(m1,Generic)) {
+ if (PyArray_Check(m1)) {
+ ret = m1->ob_type->tp_as_number->nb_power(m1,m2,
+ Py_None);
+ }
+ else {
+ if (!PyArray_IsScalar(m2,Generic)) {
+ PyErr_SetString(PyExc_TypeError, msg);
+ return NULL;
+ }
+ arr = PyArray_FromScalar(m2, NULL);
+ if (arr == NULL) return NULL;
+ ret = arr->ob_type->tp_as_number->nb_power(m1, arr,
+ Py_None);
+ Py_DECREF(arr);
+ }
+ return ret;
+ }
+ if (!PyArray_IsScalar(m2, Generic)) {
+ if (PyArray_Check(m2)) {
+ ret = m2->ob_type->tp_as_number->nb_power(m1,m2,
+ Py_None);
+ }
+ else {
+ if (!PyArray_IsScalar(m1, Generic)) {
+ PyErr_SetString(PyExc_TypeError, msg);
+ return NULL;
+ }
+ arr = PyArray_FromScalar(m1, NULL);
+ if (arr == NULL) return NULL;
+ ret = arr->ob_type->tp_as_number->nb_power(arr, m2,
+ Py_None);
+ Py_DECREF(arr);
+ }
+ return ret;
+ }
+ arr=arg2=NULL;
+ arr = PyArray_FromScalar(m1, NULL);
+ arg2 = PyArray_FromScalar(m2, NULL);
+ if (arr == NULL || arg2 == NULL) {
+ Py_XDECREF(arr); Py_XDECREF(arg2); return NULL;
+ }
+ ret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);
+ Py_DECREF(arr);
+ Py_DECREF(arg2);
+ return ret;
}
static PyObject *
gentype_generic_method(PyObject *self, PyObject *args, PyObject *kwds,
- char *str)
+ char *str)
{
- PyObject *arr, *meth, *ret;
+ PyObject *arr, *meth, *ret;
- arr = PyArray_FromScalar(self, NULL);
- if (arr == NULL) return NULL;
- meth = PyObject_GetAttrString(arr, str);
- if (meth == NULL) {Py_DECREF(arr); return NULL;}
- if (kwds == NULL)
- ret = PyObject_CallObject(meth, args);
- else
- ret = PyObject_Call(meth, args, kwds);
- Py_DECREF(meth);
- Py_DECREF(arr);
+ arr = PyArray_FromScalar(self, NULL);
+ if (arr == NULL) return NULL;
+ meth = PyObject_GetAttrString(arr, str);
+ if (meth == NULL) {Py_DECREF(arr); return NULL;}
+ if (kwds == NULL)
+ ret = PyObject_CallObject(meth, args);
+ else
+ ret = PyObject_Call(meth, args, kwds);
+ Py_DECREF(meth);
+ Py_DECREF(arr);
if (ret && PyArray_Check(ret))
return PyArray_Return((PyArrayObject *)ret);
else
@@ -381,7 +381,7 @@
static PyObject *
gentype_ at name@(PyObject *m1, PyObject *m2)
{
- return PyArray_Type.tp_as_number->nb_ at name@(m1, m2);
+ return PyArray_Type.tp_as_number->nb_ at name@(m1, m2);
}
/**end repeat**/
@@ -389,32 +389,32 @@
static PyObject *
gentype_multiply(PyObject *m1, PyObject *m2)
{
- PyObject *ret=NULL;
- long repeat;
+ PyObject *ret=NULL;
+ long repeat;
- if (!PyArray_IsScalar(m1, Generic) &&
- ((m1->ob_type->tp_as_number == NULL) ||
- (m1->ob_type->tp_as_number->nb_multiply == NULL))) {
- /* Try to convert m2 to an int and try sequence
- repeat */
- repeat = PyInt_AsLong(m2);
- if (repeat == -1 && PyErr_Occurred()) return NULL;
- ret = PySequence_Repeat(m1, (int) repeat);
- }
- else if (!PyArray_IsScalar(m2, Generic) &&
- ((m2->ob_type->tp_as_number == NULL) ||
- (m2->ob_type->tp_as_number->nb_multiply == NULL))) {
- /* Try to convert m1 to an int and try sequence
- repeat */
- repeat = PyInt_AsLong(m1);
- if (repeat == -1 && PyErr_Occurred()) return NULL;
- ret = PySequence_Repeat(m2, (int) repeat);
- }
- if (ret==NULL) {
- PyErr_Clear(); /* no effect if not set */
- ret = PyArray_Type.tp_as_number->nb_multiply(m1, m2);
- }
- return ret;
+ if (!PyArray_IsScalar(m1, Generic) &&
+ ((m1->ob_type->tp_as_number == NULL) ||
+ (m1->ob_type->tp_as_number->nb_multiply == NULL))) {
+ /* Try to convert m2 to an int and try sequence
+ repeat */
+ repeat = PyInt_AsLong(m2);
+ if (repeat == -1 && PyErr_Occurred()) return NULL;
+ ret = PySequence_Repeat(m1, (int) repeat);
+ }
+ else if (!PyArray_IsScalar(m2, Generic) &&
+ ((m2->ob_type->tp_as_number == NULL) ||
+ (m2->ob_type->tp_as_number->nb_multiply == NULL))) {
+ /* Try to convert m1 to an int and try sequence
+ repeat */
+ repeat = PyInt_AsLong(m1);
+ if (repeat == -1 && PyErr_Occurred()) return NULL;
+ ret = PySequence_Repeat(m2, (int) repeat);
+ }
+ if (ret==NULL) {
+ PyErr_Clear(); /* no effect if not set */
+ ret = PyArray_Type.tp_as_number->nb_multiply(m1, m2);
+ }
+ return ret;
}
/**begin repeat
@@ -425,55 +425,55 @@
static PyObject *
gentype_ at name@(PyObject *m1)
{
- PyObject *arr, *ret;
+ PyObject *arr, *ret;
- arr = PyArray_FromScalar(m1, NULL);
- if (arr == NULL) return NULL;
- ret = arr->ob_type->tp_as_number->nb_ at name@(arr);
- Py_DECREF(arr);
- return ret;
+ arr = PyArray_FromScalar(m1, NULL);
+ if (arr == NULL) return NULL;
+ ret = arr->ob_type->tp_as_number->nb_ at name@(arr);
+ Py_DECREF(arr);
+ return ret;
}
/**end repeat**/
static int
gentype_nonzero_number(PyObject *m1)
{
- PyObject *arr;
- int ret;
+ PyObject *arr;
+ int ret;
- arr = PyArray_FromScalar(m1, NULL);
- if (arr == NULL) return -1;
- ret = arr->ob_type->tp_as_number->nb_nonzero(arr);
- Py_DECREF(arr);
- return ret;
+ arr = PyArray_FromScalar(m1, NULL);
+ if (arr == NULL) return -1;
+ ret = arr->ob_type->tp_as_number->nb_nonzero(arr);
+ Py_DECREF(arr);
+ return ret;
}
static PyObject *
gentype_str(PyObject *self)
{
- PyArrayObject *arr;
- PyObject *ret, *tmp;
+ PyArrayObject *arr;
+ PyObject *ret, *tmp;
- arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);
- if (arr==NULL) return NULL;
- ret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));
- Py_DECREF(arr);
- Py_XDECREF(tmp);
- return ret;
+ arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);
+ if (arr==NULL) return NULL;
+ ret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));
+ Py_DECREF(arr);
+ Py_XDECREF(tmp);
+ return ret;
}
static PyObject *
gentype_repr(PyObject *self)
{
- PyArrayObject *arr;
- PyObject *ret, *tmp ;
+ PyArrayObject *arr;
+ PyObject *ret, *tmp ;
- arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);
- if (arr==NULL) return NULL;
- ret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));
- Py_DECREF(arr);
- Py_XDECREF(tmp);
- return ret;
+ arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);
+ if (arr==NULL) return NULL;
+ ret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));
+ Py_DECREF(arr);
+ Py_XDECREF(tmp);
+ return ret;
}
static void
@@ -513,20 +513,20 @@
static PyObject *
@name at type_@form@(PyObject *self)
{
- const @type@ *dptr, *ip;
- int len;
- PyObject *new;
- PyObject *ret;
+ const @type@ *dptr, *ip;
+ int len;
+ PyObject *new;
+ PyObject *ret;
- ip = dptr = Py at Name@_AS_ at NAME@(self);
- len = Py at Name@_GET_SIZE(self);
- dptr += len-1;
- while(len > 0 && *dptr-- == 0) len--;
- new = Py at Name@_From at Name@@extra@(ip, len);
- if (new == NULL) return PyString_FromString("");
- ret = Py at Name@_Type.tp_ at form@(new);
- Py_DECREF(new);
- return ret;
+ ip = dptr = Py at Name@_AS_ at NAME@(self);
+ len = Py at Name@_GET_SIZE(self);
+ dptr += len-1;
+ while(len > 0 && *dptr-- == 0) len--;
+ new = Py at Name@_From at Name@@extra@(ip, len);
+ if (new == NULL) return PyString_FromString("");
+ ret = Py at Name@_Type.tp_ at form@(new);
+ Py_DECREF(new);
+ return ret;
}
/**end repeat**/
@@ -554,14 +554,14 @@
{
static char buf1[100];
static char buf2[100];
- static char buf3[202];
+ static char buf3[202];
clongdouble x;
x = ((PyCLongDoubleScalarObject *)self)->obval;
format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR);
format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR);
- snprintf(buf3, sizeof(buf3), "(%s+%sj)", buf1, buf2);
- return PyString_FromString(buf3);
+ snprintf(buf3, sizeof(buf3), "(%s+%sj)", buf1, buf2);
+ return PyString_FromString(buf3);
}
#define longdoubletype_str longdoubletype_repr
@@ -582,14 +582,14 @@
static PyObject *
@char at longdoubletype_@name@(PyObject *self)
{
- double dval;
- PyObject *obj, *ret;
+ double dval;
+ PyObject *obj, *ret;
- dval = (double)(((Py at CHAR@LongDoubleScalarObject *)self)->obval)@POST@;
- obj = Py at KIND@_FromDouble(dval);
- ret = obj->ob_type->tp_as_number->nb_ at name@(obj);
- Py_DECREF(obj);
- return ret;
+ dval = (double)(((Py at CHAR@LongDoubleScalarObject *)self)->obval)@POST@;
+ obj = Py at KIND@_FromDouble(dval);
+ ret = obj->ob_type->tp_as_number->nb_ at name@(obj);
+ Py_DECREF(obj);
+ return ret;
}
/**end repeat**/
@@ -598,43 +598,43 @@
static Py_ssize_t
gentype_index(PyObject *self)
{
- PyObject *obj;
- if (!(PyArray_IsScalar(self, Integer))) {
- PyErr_SetString(PyExc_TypeError,
- "not an integer type.");
- return -1;
- }
- obj = gentype_int(self);
- if (obj == NULL) return -1;
- return PyInt_AsSsize_t(obj);
+ PyObject *obj;
+ if (!(PyArray_IsScalar(self, Integer))) {
+ PyErr_SetString(PyExc_TypeError,
+ "not an integer type.");
+ return -1;
+ }
+ obj = gentype_int(self);
+ if (obj == NULL) return -1;
+ return PyInt_AsSsize_t(obj);
}
#endif
static PyNumberMethods gentype_as_number = {
- (binaryfunc)gentype_add, /*nb_add*/
- (binaryfunc)gentype_subtract, /*nb_subtract*/
- (binaryfunc)gentype_multiply, /*nb_multiply*/
- (binaryfunc)gentype_divide, /*nb_divide*/
- (binaryfunc)gentype_remainder, /*nb_remainder*/
- (binaryfunc)gentype_divmod, /*nb_divmod*/
- (ternaryfunc)gentype_power, /*nb_power*/
+ (binaryfunc)gentype_add, /*nb_add*/
+ (binaryfunc)gentype_subtract, /*nb_subtract*/
+ (binaryfunc)gentype_multiply, /*nb_multiply*/
+ (binaryfunc)gentype_divide, /*nb_divide*/
+ (binaryfunc)gentype_remainder, /*nb_remainder*/
+ (binaryfunc)gentype_divmod, /*nb_divmod*/
+ (ternaryfunc)gentype_power, /*nb_power*/
(unaryfunc)gentype_negative,
- (unaryfunc)gentype_positive, /*nb_pos*/
- (unaryfunc)gentype_absolute, /*(unaryfunc)gentype_abs,*/
- (inquiry)gentype_nonzero_number, /*nb_nonzero*/
- (unaryfunc)gentype_invert, /*nb_invert*/
- (binaryfunc)gentype_lshift, /*nb_lshift*/
- (binaryfunc)gentype_rshift, /*nb_rshift*/
- (binaryfunc)gentype_and, /*nb_and*/
- (binaryfunc)gentype_xor, /*nb_xor*/
- (binaryfunc)gentype_or, /*nb_or*/
- 0, /*nb_coerce*/
- (unaryfunc)gentype_int, /*nb_int*/
- (unaryfunc)gentype_long, /*nb_long*/
- (unaryfunc)gentype_float, /*nb_float*/
- (unaryfunc)gentype_oct, /*nb_oct*/
- (unaryfunc)gentype_hex, /*nb_hex*/
+ (unaryfunc)gentype_positive, /*nb_pos*/
+ (unaryfunc)gentype_absolute, /*(unaryfunc)gentype_abs,*/
+ (inquiry)gentype_nonzero_number, /*nb_nonzero*/
+ (unaryfunc)gentype_invert, /*nb_invert*/
+ (binaryfunc)gentype_lshift, /*nb_lshift*/
+ (binaryfunc)gentype_rshift, /*nb_rshift*/
+ (binaryfunc)gentype_and, /*nb_and*/
+ (binaryfunc)gentype_xor, /*nb_xor*/
+ (binaryfunc)gentype_or, /*nb_or*/
+ 0, /*nb_coerce*/
+ (unaryfunc)gentype_int, /*nb_int*/
+ (unaryfunc)gentype_long, /*nb_long*/
+ (unaryfunc)gentype_float, /*nb_float*/
+ (unaryfunc)gentype_oct, /*nb_oct*/
+ (unaryfunc)gentype_hex, /*nb_hex*/
0, /*inplace_add*/
0, /*inplace_subtract*/
0, /*inplace_multiply*/
@@ -646,12 +646,12 @@
0, /*inplace_and*/
0, /*inplace_xor*/
0, /*inplace_or*/
- (binaryfunc)gentype_floor_divide, /*nb_floor_divide*/
- (binaryfunc)gentype_true_divide, /*nb_true_divide*/
+ (binaryfunc)gentype_floor_divide, /*nb_floor_divide*/
+ (binaryfunc)gentype_true_divide, /*nb_true_divide*/
0, /*nb_inplace_floor_divide*/
0, /*nb_inplace_true_divide*/
#if PY_VERSION_HEX >= 0x02050000
- (lenfunc)gentype_index, /* nb_index */
+ (lenfunc)gentype_index, /* nb_index */
#endif
};
@@ -660,19 +660,19 @@
gentype_richcompare(PyObject *self, PyObject *other, int cmp_op)
{
- PyObject *arr, *ret;
+ PyObject *arr, *ret;
- arr = PyArray_FromScalar(self, NULL);
- if (arr == NULL) return NULL;
- ret = arr->ob_type->tp_richcompare(arr, other, cmp_op);
- Py_DECREF(arr);
- return ret;
+ arr = PyArray_FromScalar(self, NULL);
+ if (arr == NULL) return NULL;
+ ret = arr->ob_type->tp_richcompare(arr, other, cmp_op);
+ Py_DECREF(arr);
+ return ret;
}
static PyObject *
gentype_ndim_get(PyObject *self)
{
- return PyInt_FromLong(0);
+ return PyInt_FromLong(0);
}
static PyObject *
@@ -684,56 +684,56 @@
static PyObject *
voidtype_flags_get(PyVoidScalarObject *self)
{
- return PyObject_CallMethod(_numpy_internal, "flagsobj", "Oii",
+ return PyObject_CallMethod(_numpy_internal, "flagsobj", "Oii",
self, self->flags, 1);
}
static PyObject *
voidtype_dtypedescr_get(PyVoidScalarObject *self)
{
- Py_INCREF(self->descr);
- return (PyObject *)self->descr;
+ Py_INCREF(self->descr);
+ return (PyObject *)self->descr;
}
static PyObject *
gentype_data_get(PyObject *self)
{
- PyArray_Descr *typecode;
- PyObject *ret;
+ PyArray_Descr *typecode;
+ PyObject *ret;
- typecode = PyArray_DescrFromScalar(self);
- ret = PyBuffer_FromObject(self, 0, typecode->elsize);
- Py_DECREF(typecode);
- return ret;
+ typecode = PyArray_DescrFromScalar(self);
+ ret = PyBuffer_FromObject(self, 0, typecode->elsize);
+ Py_DECREF(typecode);
+ return ret;
}
static PyObject *
gentype_itemsize_get(PyObject *self)
{
- PyArray_Descr *typecode;
- PyObject *ret;
+ PyArray_Descr *typecode;
+ PyObject *ret;
- typecode = PyArray_DescrFromScalar(self);
- ret = PyInt_FromLong((long) typecode->elsize);
- Py_DECREF(typecode);
- return ret;
+ typecode = PyArray_DescrFromScalar(self);
+ ret = PyInt_FromLong((long) typecode->elsize);
+ Py_DECREF(typecode);
+ return ret;
}
static PyObject *
gentype_size_get(PyObject *self)
{
- return PyInt_FromLong(1);
+ return PyInt_FromLong(1);
}
static void
gentype_struct_free(void *ptr, void *arg)
{
Py_DECREF((PyObject *)arg);
- if (((PyArrayInterface *)ptr)->shape != NULL) {
- _pya_free(((PyArrayInterface *)ptr)->shape);
- }
+ if (((PyArrayInterface *)ptr)->shape != NULL) {
+ _pya_free(((PyArrayInterface *)ptr)->shape);
+ }
_pya_free(ptr);
}
@@ -754,54 +754,54 @@
inter->shape = NULL;
inter->data = arr->data;
- return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);
+ return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);
}
static PyObject *
gentype_priority_get(PyObject *self)
{
- return PyFloat_FromDouble(NPY_SCALAR_PRIORITY);
+ return PyFloat_FromDouble(NPY_SCALAR_PRIORITY);
}
static PyObject *
gentype_typestr_get(PyObject *self)
{
- PyArrayObject *arr;
- PyObject *ret;
+ PyArrayObject *arr;
+ PyObject *ret;
- arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);
- ret = PyObject_GetAttrString((PyObject *)arr->descr, "str");
- Py_DECREF(arr);
- return ret;
+ arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);
+ ret = PyObject_GetAttrString((PyObject *)arr->descr, "str");
+ Py_DECREF(arr);
+ return ret;
}
static PyObject *
gentype_descr_get(PyObject *self)
{
- PyArrayObject *arr;
- PyObject *inter;
+ PyArrayObject *arr;
+ PyObject *inter;
PyObject *ret;
- arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);
- inter = PyObject_GetAttrString((PyObject *)arr, "__array_interface__");
- Py_DECREF(arr);
+ arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);
+ inter = PyObject_GetAttrString((PyObject *)arr, "__array_interface__");
+ Py_DECREF(arr);
if (inter == NULL) return NULL;
ret = PyDict_GetItemString(inter, "descr");
Py_DECREF(inter);
Py_XINCREF(ret);
- return ret;
+ return ret;
}
static PyObject *
gentype_shape_get(PyObject *self)
{
- return PyTuple_New(0);
+ return PyTuple_New(0);
}
static PyObject *
gentype_dataptr_get(PyObject *self)
{
- return Py_BuildValue("NO",PyString_FromString(""),Py_True);
+ return Py_BuildValue("NO",PyString_FromString(""),Py_True);
}
@@ -845,142 +845,143 @@
static PyObject *
gentype_typedescr_get(PyObject *self)
{
- return (PyObject *)PyArray_DescrFromScalar(self);
+ return (PyObject *)PyArray_DescrFromScalar(self);
}
static PyObject *
gentype_base_get(PyObject *self)
{
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
static PyArray_Descr *
_realdescr_fromcomplexscalar(PyObject *self, int *typenum)
{
- if (PyArray_IsScalar(self, CDouble)) {
- *typenum = PyArray_CDOUBLE;
- return PyArray_DescrFromType(PyArray_DOUBLE);
- }
- if (PyArray_IsScalar(self, CFloat)) {
- *typenum = PyArray_CFLOAT;
- return PyArray_DescrFromType(PyArray_FLOAT);
- }
- if (PyArray_IsScalar(self, CLongDouble)) {
- *typenum = PyArray_CLONGDOUBLE;
- return PyArray_DescrFromType(PyArray_LONGDOUBLE);
- }
- return NULL;
+ if (PyArray_IsScalar(self, CDouble)) {
+ *typenum = PyArray_CDOUBLE;
+ return PyArray_DescrFromType(PyArray_DOUBLE);
+ }
+ if (PyArray_IsScalar(self, CFloat)) {
+ *typenum = PyArray_CFLOAT;
+ return PyArray_DescrFromType(PyArray_FLOAT);
+ }
+ if (PyArray_IsScalar(self, CLongDouble)) {
+ *typenum = PyArray_CLONGDOUBLE;
+ return PyArray_DescrFromType(PyArray_LONGDOUBLE);
+ }
+ return NULL;
}
static PyObject *
gentype_real_get(PyObject *self)
{
- PyArray_Descr *typecode;
- PyObject *ret;
- int typenum;
+ PyArray_Descr *typecode;
+ PyObject *ret;
+ int typenum;
- if (PyArray_IsScalar(self, ComplexFloating)) {
- typecode = _realdescr_fromcomplexscalar(self, &typenum);
- ret = PyArray_Scalar(scalar_value(self, NULL), typecode, NULL);
- Py_DECREF(typecode);
- return ret;
- }
- else if (PyArray_IsScalar(self, Object)) {
- PyObject *obj = ((PyObjectScalarObject *)self)->obval;
- ret = PyObject_GetAttrString(obj, "real");
- if (ret != NULL) return ret;
- PyErr_Clear();
- }
- Py_INCREF(self);
- return (PyObject *)self;
+ if (PyArray_IsScalar(self, ComplexFloating)) {
+ typecode = _realdescr_fromcomplexscalar(self, &typenum);
+ ret = PyArray_Scalar(scalar_value(self, NULL),
+ typecode, NULL);
+ Py_DECREF(typecode);
+ return ret;
+ }
+ else if (PyArray_IsScalar(self, Object)) {
+ PyObject *obj = ((PyObjectScalarObject *)self)->obval;
+ ret = PyObject_GetAttrString(obj, "real");
+ if (ret != NULL) return ret;
+ PyErr_Clear();
+ }
+ Py_INCREF(self);
+ return (PyObject *)self;
}
static PyObject *
gentype_imag_get(PyObject *self)
{
- PyArray_Descr *typecode;
- PyObject *ret;
- int typenum;
+ PyArray_Descr *typecode;
+ PyObject *ret;
+ int typenum;
- typecode = _realdescr_fromcomplexscalar(self, &typenum);
- if (PyArray_IsScalar(self, ComplexFloating)) {
+ typecode = _realdescr_fromcomplexscalar(self, &typenum);
+ if (PyArray_IsScalar(self, ComplexFloating)) {
ret = PyArray_Scalar((char *)scalar_value(self, NULL)
+ typecode->elsize, typecode, NULL);
- }
- else if (PyArray_IsScalar(self, Object)) {
- PyObject *obj = ((PyObjectScalarObject *)self)->obval;
- PyArray_Descr *newtype;
- ret = PyObject_GetAttrString(obj, "imag");
- if (ret == NULL) {
- PyErr_Clear();
- obj = PyInt_FromLong(0);
- newtype = PyArray_DescrFromType(PyArray_OBJECT);
- ret = PyArray_Scalar((char *)&obj, newtype, NULL);
- Py_DECREF(newtype);
- Py_DECREF(obj);
- }
- }
- else {
- char *temp;
- temp = PyDataMem_NEW(typecode->elsize);
- memset(temp, '\0', typecode->elsize);
- ret = PyArray_Scalar(temp, typecode, NULL);
- PyDataMem_FREE(temp);
- }
+ }
+ else if (PyArray_IsScalar(self, Object)) {
+ PyObject *obj = ((PyObjectScalarObject *)self)->obval;
+ PyArray_Descr *newtype;
+ ret = PyObject_GetAttrString(obj, "imag");
+ if (ret == NULL) {
+ PyErr_Clear();
+ obj = PyInt_FromLong(0);
+ newtype = PyArray_DescrFromType(PyArray_OBJECT);
+ ret = PyArray_Scalar((char *)&obj, newtype, NULL);
+ Py_DECREF(newtype);
+ Py_DECREF(obj);
+ }
+ }
+ else {
+ char *temp;
+ temp = PyDataMem_NEW(typecode->elsize);
+ memset(temp, '\0', typecode->elsize);
+ ret = PyArray_Scalar(temp, typecode, NULL);
+ PyDataMem_FREE(temp);
+ }
- Py_DECREF(typecode);
- return ret;
+ Py_DECREF(typecode);
+ return ret;
}
static PyObject *
gentype_flat_get(PyObject *self)
{
- PyObject *ret, *arr;
+ PyObject *ret, *arr;
- arr = PyArray_FromScalar(self, NULL);
- if (arr == NULL) return NULL;
- ret = PyArray_IterNew(arr);
- Py_DECREF(arr);
- return ret;
+ arr = PyArray_FromScalar(self, NULL);
+ if (arr == NULL) return NULL;
+ ret = PyArray_IterNew(arr);
+ Py_DECREF(arr);
+ return ret;
}
static PyObject *
gentype_transpose_get(PyObject *self)
{
- Py_INCREF(self);
- return self;
+ Py_INCREF(self);
+ return self;
}
static PyGetSetDef gentype_getsets[] = {
{"ndim",
- (getter)gentype_ndim_get,
- (setter) 0,
- "number of array dimensions"},
+ (getter)gentype_ndim_get,
+ (setter) 0,
+ "number of array dimensions"},
{"flags",
- (getter)gentype_flags_get,
- (setter)0,
- "integer value of flags"},
+ (getter)gentype_flags_get,
+ (setter)0,
+ "integer value of flags"},
{"shape",
- (getter)gentype_shape_get,
- (setter)0,
- "tuple of array dimensions"},
+ (getter)gentype_shape_get,
+ (setter)0,
+ "tuple of array dimensions"},
{"strides",
- (getter)gentype_shape_get,
- (setter) 0,
- "tuple of bytes steps in each dimension"},
+ (getter)gentype_shape_get,
+ (setter) 0,
+ "tuple of bytes steps in each dimension"},
{"data",
- (getter)gentype_data_get,
- (setter) 0,
- "pointer to start of data"},
+ (getter)gentype_data_get,
+ (setter) 0,
+ "pointer to start of data"},
{"itemsize",
- (getter)gentype_itemsize_get,
- (setter)0,
- "length of one element in bytes"},
+ (getter)gentype_itemsize_get,
+ (setter)0,
+ "length of one element in bytes"},
{"size",
(getter)gentype_size_get,
(setter)0,
@@ -989,30 +990,30 @@
(getter)gentype_itemsize_get,
(setter)0,
"length of item in bytes"},
- {"base",
- (getter)gentype_base_get,
- (setter)0,
- "base object"},
- {"dtype",
- (getter)gentype_typedescr_get,
- NULL,
- "get array data-descriptor"},
+ {"base",
+ (getter)gentype_base_get,
+ (setter)0,
+ "base object"},
+ {"dtype",
+ (getter)gentype_typedescr_get,
+ NULL,
+ "get array data-descriptor"},
{"real",
- (getter)gentype_real_get,
- (setter)0,
- "real part of scalar"},
+ (getter)gentype_real_get,
+ (setter)0,
+ "real part of scalar"},
{"imag",
- (getter)gentype_imag_get,
- (setter)0,
- "imaginary part of scalar"},
- {"flat",
- (getter)gentype_flat_get,
- (setter)0,
- "a 1-d view of scalar"},
- {"T",
- (getter)gentype_transpose_get,
- (setter)0,
- "transpose"},
+ (getter)gentype_imag_get,
+ (setter)0,
+ "imaginary part of scalar"},
+ {"flat",
+ (getter)gentype_flat_get,
+ (setter)0,
+ "a 1-d view of scalar"},
+ {"T",
+ (getter)gentype_transpose_get,
+ (setter)0,
+ "transpose"},
{"__array_interface__",
(getter)gentype_interface_get,
NULL,
@@ -1021,11 +1022,11 @@
(getter)gentype_struct_get,
NULL,
"Array protocol: struct"},
- {"__array_priority__",
- (getter)gentype_priority_get,
- NULL,
- "Array priority."},
- {NULL, NULL, NULL, NULL} /* Sentinel */
+ {"__array_priority__",
+ (getter)gentype_priority_get,
+ NULL,
+ "Array priority."},
+ {NULL, NULL, NULL, NULL} /* Sentinel */
};
@@ -1036,13 +1037,13 @@
static PyObject *
gentype_getarray(PyObject *scalar, PyObject *args)
{
- PyArray_Descr *outcode=NULL;
- PyObject *ret;
+ PyArray_Descr *outcode=NULL;
+ PyObject *ret;
- if (!PyArg_ParseTuple(args, "|O&", &PyArray_DescrConverter,
- &outcode)) return NULL;
- ret = PyArray_FromScalar(scalar, outcode);
- return ret;
+ if (!PyArg_ParseTuple(args, "|O&", &PyArray_DescrConverter,
+ &outcode)) return NULL;
+ ret = PyArray_FromScalar(scalar, outcode);
+ return ret;
}
static char doc_sc_wraparray[] = "sc.__array_wrap__(obj) return scalar from array";
@@ -1050,21 +1051,21 @@
static PyObject *
gentype_wraparray(PyObject *scalar, PyObject *args)
{
- PyObject *arr;
+ PyObject *arr;
- if (PyTuple_Size(args) < 1) {
- PyErr_SetString(PyExc_TypeError,
- "only accepts 1 argument.");
- return NULL;
- }
- arr = PyTuple_GET_ITEM(args, 0);
- if (!PyArray_Check(arr)) {
- PyErr_SetString(PyExc_TypeError,
- "can only be called with ndarray object");
- return NULL;
- }
+ if (PyTuple_Size(args) < 1) {
+ PyErr_SetString(PyExc_TypeError,
+ "only accepts 1 argument.");
+ return NULL;
+ }
+ arr = PyTuple_GET_ITEM(args, 0);
+ if (!PyArray_Check(arr)) {
+ PyErr_SetString(PyExc_TypeError,
+ "can only be called with ndarray object");
+ return NULL;
+ }
- return PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);
+ return PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);
}
@@ -1076,7 +1077,7 @@
static PyObject *
gentype_ at name@(PyObject *self, PyObject *args)
{
- return gentype_generic_method(self, args, NULL, "@name@");
+ return gentype_generic_method(self, args, NULL, "@name@");
}
/**end repeat**/
@@ -1084,8 +1085,8 @@
gentype_squeeze(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) return NULL;
- Py_INCREF(self);
- return self;
+ Py_INCREF(self);
+ return self;
}
static int
@@ -1094,36 +1095,36 @@
static PyObject *
gentype_byteswap(PyObject *self, PyObject *args)
{
- Bool inplace=FALSE;
+ Bool inplace=FALSE;
- if (!PyArg_ParseTuple(args, "|O&", PyArray_BoolConverter, &inplace))
- return NULL;
+ if (!PyArg_ParseTuple(args, "|O&", PyArray_BoolConverter, &inplace))
+ return NULL;
- if (inplace) {
- PyErr_SetString(PyExc_ValueError,
- "cannot byteswap a scalar in-place");
- return NULL;
- }
- else {
- /* get the data, copyswap it and pass it to a new Array scalar
- */
- char *data;
- int numbytes;
- PyArray_Descr *descr;
- PyObject *new;
- char *newmem;
+ if (inplace) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot byteswap a scalar in-place");
+ return NULL;
+ }
+ else {
+ /* get the data, copyswap it and pass it to a new Array scalar
+ */
+ char *data;
+ int numbytes;
+ PyArray_Descr *descr;
+ PyObject *new;
+ char *newmem;
- numbytes = gentype_getreadbuf(self, 0, (void **)&data);
- descr = PyArray_DescrFromScalar(self);
- newmem = _pya_malloc(descr->elsize);
- if (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}
- else memcpy(newmem, data, descr->elsize);
- byte_swap_vector(newmem, 1, descr->elsize);
- new = PyArray_Scalar(newmem, descr, NULL);
- _pya_free(newmem);
- Py_DECREF(descr);
- return new;
- }
+ numbytes = gentype_getreadbuf(self, 0, (void **)&data);
+ descr = PyArray_DescrFromScalar(self);
+ newmem = _pya_malloc(descr->elsize);
+ if (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}
+ else memcpy(newmem, data, descr->elsize);
+ byte_swap_vector(newmem, 1, descr->elsize);
+ new = PyArray_Scalar(newmem, descr, NULL);
+ _pya_free(newmem);
+ Py_DECREF(descr);
+ return new;
+ }
}
@@ -1135,154 +1136,154 @@
static PyObject *
gentype_ at name@(PyObject *self, PyObject *args, PyObject *kwds)
{
- return gentype_generic_method(self, args, kwds, "@name@");
+ return gentype_generic_method(self, args, kwds, "@name@");
}
/**end repeat**/
static PyObject *
voidtype_getfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *ret;
+ PyObject *ret;
- ret = gentype_generic_method((PyObject *)self, args, kwds, "getfield");
- if (!ret) return ret;
- if (PyArray_IsScalar(ret, Generic) && \
- (!PyArray_IsScalar(ret, Void))) {
- PyArray_Descr *new;
- if (!PyArray_ISNBO(self->descr->byteorder)) {
- new = PyArray_DescrFromScalar(ret);
- byte_swap_vector(scalar_value(ret, new), 1, new->elsize);
- Py_DECREF(new);
- }
- }
- return ret;
+ ret = gentype_generic_method((PyObject *)self, args, kwds, "getfield");
+ if (!ret) return ret;
+ if (PyArray_IsScalar(ret, Generic) && \
+ (!PyArray_IsScalar(ret, Void))) {
+ PyArray_Descr *new;
+ if (!PyArray_ISNBO(self->descr->byteorder)) {
+ new = PyArray_DescrFromScalar(ret);
+ byte_swap_vector(scalar_value(ret, new), 1, new->elsize);
+ Py_DECREF(new);
+ }
+ }
+ return ret;
}
static PyObject *
gentype_setfield(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyErr_SetString(PyExc_TypeError,
- "Can't set fields in a non-void array scalar.");
- return NULL;
+ PyErr_SetString(PyExc_TypeError,
+ "Can't set fields in a non-void array scalar.");
+ return NULL;
}
static PyObject *
voidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)
{
- PyArray_Descr *typecode;
- int offset = 0;
- PyObject *value, *src;
- int mysize;
- char *dptr;
- static char *kwlist[] = {"value", "dtype", "offset", 0};
+ PyArray_Descr *typecode;
+ int offset = 0;
+ PyObject *value, *src;
+ int mysize;
+ char *dptr;
+ static char *kwlist[] = {"value", "dtype", "offset", 0};
- if ((self->flags & WRITEABLE) != WRITEABLE) {
- PyErr_SetString(PyExc_RuntimeError,
- "Can't write to memory");
- return NULL;
- }
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|i", kwlist,
- &value,
- PyArray_DescrConverter,
- &typecode, &offset)) return NULL;
+ if ((self->flags & WRITEABLE) != WRITEABLE) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Can't write to memory");
+ return NULL;
+ }
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|i", kwlist,
+ &value,
+ PyArray_DescrConverter,
+ &typecode, &offset)) return NULL;
- mysize = self->ob_size;
+ mysize = self->ob_size;
- if (offset < 0 || (offset + typecode->elsize) > mysize) {
- PyErr_Format(PyExc_ValueError,
- "Need 0 <= offset <= %d for requested type " \
- "but received offset = %d",
- mysize-typecode->elsize, offset);
- Py_DECREF(typecode);
- return NULL;
- }
+ if (offset < 0 || (offset + typecode->elsize) > mysize) {
+ PyErr_Format(PyExc_ValueError,
+ "Need 0 <= offset <= %d for requested type " \
+ "but received offset = %d",
+ mysize-typecode->elsize, offset);
+ Py_DECREF(typecode);
+ return NULL;
+ }
- dptr = self->obval + offset;
+ dptr = self->obval + offset;
- if (typecode->type_num == PyArray_OBJECT) {
- PyObject **temp;
- Py_INCREF(value);
- temp = (PyObject **)dptr;
- Py_XDECREF(*temp);
- memcpy(temp, &value, sizeof(PyObject *));
- }
- else {
- /* Copy data from value to correct place in dptr */
- src = PyArray_FromAny(value, typecode, 0, 0, CARRAY, NULL);
- if (src == NULL) return NULL;
- typecode->f->copyswap(dptr, PyArray_DATA(src),
- !PyArray_ISNBO(self->descr->byteorder),
- src);
- Py_DECREF(src);
- }
- Py_INCREF(Py_None);
- return Py_None;
+ if (typecode->type_num == PyArray_OBJECT) {
+ PyObject **temp;
+ Py_INCREF(value);
+ temp = (PyObject **)dptr;
+ Py_XDECREF(*temp);
+ memcpy(temp, &value, sizeof(PyObject *));
+ }
+ else {
+ /* Copy data from value to correct place in dptr */
+ src = PyArray_FromAny(value, typecode, 0, 0, CARRAY, NULL);
+ if (src == NULL) return NULL;
+ typecode->f->copyswap(dptr, PyArray_DATA(src),
+ !PyArray_ISNBO(self->descr->byteorder),
+ src);
+ Py_DECREF(src);
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
}
static PyObject *
gentype_reduce(PyObject *self, PyObject *args)
{
- PyObject *ret=NULL, *obj=NULL, *mod=NULL;
- const char *buffer;
- Py_ssize_t buflen;
+ PyObject *ret=NULL, *obj=NULL, *mod=NULL;
+ const char *buffer;
+ Py_ssize_t buflen;
- /* Return a tuple of (callable object, arguments) */
+ /* Return a tuple of (callable object, arguments) */
- ret = PyTuple_New(2);
- if (ret == NULL) return NULL;
- if (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {
- Py_DECREF(ret); return NULL;
- }
- mod = PyImport_ImportModule("numpy.core.multiarray");
- if (mod == NULL) return NULL;
- obj = PyObject_GetAttrString(mod, "scalar");
- Py_DECREF(mod);
- if (obj == NULL) return NULL;
- PyTuple_SET_ITEM(ret, 0, obj);
- obj = PyObject_GetAttrString((PyObject *)self, "dtype");
- if (PyArray_IsScalar(self, Object)) {
- mod = ((PyObjectScalarObject *)self)->obval;
- PyTuple_SET_ITEM(ret, 1,
- Py_BuildValue("NO", obj, mod));
- }
- else {
- mod = PyString_FromStringAndSize(buffer, buflen);
- PyTuple_SET_ITEM(ret, 1,
- Py_BuildValue("NN", obj, mod));
- }
- return ret;
+ ret = PyTuple_New(2);
+ if (ret == NULL) return NULL;
+ if (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {
+ Py_DECREF(ret); return NULL;
+ }
+ mod = PyImport_ImportModule("numpy.core.multiarray");
+ if (mod == NULL) return NULL;
+ obj = PyObject_GetAttrString(mod, "scalar");
+ Py_DECREF(mod);
+ if (obj == NULL) return NULL;
+ PyTuple_SET_ITEM(ret, 0, obj);
+ obj = PyObject_GetAttrString((PyObject *)self, "dtype");
+ if (PyArray_IsScalar(self, Object)) {
+ mod = ((PyObjectScalarObject *)self)->obval;
+ PyTuple_SET_ITEM(ret, 1,
+ Py_BuildValue("NO", obj, mod));
+ }
+ else {
+ mod = PyString_FromStringAndSize(buffer, buflen);
+ PyTuple_SET_ITEM(ret, 1,
+ Py_BuildValue("NN", obj, mod));
+ }
+ return ret;
}
/* ignores everything */
static PyObject *
gentype_setstate(PyObject *self, PyObject *args)
{
- Py_INCREF(Py_None);
- return (Py_None);
+ Py_INCREF(Py_None);
+ return (Py_None);
}
static PyObject *
gentype_dump(PyObject *self, PyObject *args)
{
- PyObject *file=NULL;
- int ret;
+ PyObject *file=NULL;
+ int ret;
- if (!PyArg_ParseTuple(args, "O", &file))
- return NULL;
- ret = PyArray_Dump(self, file, 2);
- if (ret < 0) return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ if (!PyArg_ParseTuple(args, "O", &file))
+ return NULL;
+ ret = PyArray_Dump(self, file, 2);
+ if (ret < 0) return NULL;
+ Py_INCREF(Py_None);
+ return Py_None;
}
static PyObject *
gentype_dumps(PyObject *self, PyObject *args)
{
- if (!PyArg_ParseTuple(args, ""))
- return NULL;
- return PyArray_Dumps(self, 2);
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ return PyArray_Dumps(self, 2);
}
@@ -1290,8 +1291,8 @@
static PyObject *
gentype_setflags(PyObject *self, PyObject *args, PyObject *kwds)
{
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
@@ -1299,23 +1300,23 @@
array docstrings
*/
static PyMethodDef gentype_methods[] = {
- {"tolist", (PyCFunction)gentype_tolist, 1, NULL},
+ {"tolist", (PyCFunction)gentype_tolist, 1, NULL},
{"item", (PyCFunction)gentype_item, METH_VARARGS, NULL},
- {"tofile", (PyCFunction)gentype_tofile,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"tostring", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},
+ {"tofile", (PyCFunction)gentype_tofile,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"tostring", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},
{"byteswap", (PyCFunction)gentype_byteswap,1, NULL},
{"astype", (PyCFunction)gentype_astype, 1, NULL},
- {"getfield", (PyCFunction)gentype_getfield,
- METH_VARARGS | METH_KEYWORDS, NULL},
- {"setfield", (PyCFunction)gentype_setfield,
- METH_VARARGS | METH_KEYWORDS, NULL},
+ {"getfield", (PyCFunction)gentype_getfield,
+ METH_VARARGS | METH_KEYWORDS, NULL},
+ {"setfield", (PyCFunction)gentype_setfield,
+ METH_VARARGS | METH_KEYWORDS, NULL},
{"copy", (PyCFunction)gentype_copy, 1, NULL},
{"resize", (PyCFunction)gentype_resize,
- METH_VARARGS|METH_KEYWORDS, NULL},
+ METH_VARARGS|METH_KEYWORDS, NULL},
- {"__array__", (PyCFunction)gentype_getarray, 1, doc_getarray},
- {"__array_wrap__", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},
+ {"__array__", (PyCFunction)gentype_getarray, 1, doc_getarray},
+ {"__array_wrap__", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},
/* for the copy module */
{"__copy__", (PyCFunction)gentype_copy, 1, NULL},
@@ -1323,115 +1324,115 @@
{"__reduce__", (PyCFunction) gentype_reduce, 1, NULL},
- /* For consistency does nothing */
- {"__setstate__", (PyCFunction) gentype_setstate, 1, NULL},
+ /* For consistency does nothing */
+ {"__setstate__", (PyCFunction) gentype_setstate, 1, NULL},
- {"dumps", (PyCFunction) gentype_dumps, 1, NULL},
- {"dump", (PyCFunction) gentype_dump, 1, NULL},
+ {"dumps", (PyCFunction) gentype_dumps, 1, NULL},
+ {"dump", (PyCFunction) gentype_dump, 1, NULL},
- /* Methods for array */
- {"fill", (PyCFunction)gentype_fill,
- METH_VARARGS, NULL},
- {"transpose", (PyCFunction)gentype_transpose,
- METH_VARARGS, NULL},
- {"take", (PyCFunction)gentype_take,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"put", (PyCFunction)gentype_put,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"putmask", (PyCFunction)gentype_putmask,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"repeat", (PyCFunction)gentype_repeat,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"choose", (PyCFunction)gentype_choose,
- METH_VARARGS, NULL},
- {"sort", (PyCFunction)gentype_sort,
- METH_VARARGS, NULL},
- {"argsort", (PyCFunction)gentype_argsort,
- METH_VARARGS, NULL},
- {"searchsorted", (PyCFunction)gentype_searchsorted,
- METH_VARARGS, NULL},
- {"argmax", (PyCFunction)gentype_argmax,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"argmin", (PyCFunction)gentype_argmin,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"reshape", (PyCFunction)gentype_reshape,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"squeeze", (PyCFunction)gentype_squeeze,
- METH_VARARGS, NULL},
- {"view", (PyCFunction)gentype_view,
- METH_VARARGS, NULL},
- {"swapaxes", (PyCFunction)gentype_swapaxes,
- METH_VARARGS, NULL},
- {"max", (PyCFunction)gentype_max,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"min", (PyCFunction)gentype_min,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"ptp", (PyCFunction)gentype_ptp,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"mean", (PyCFunction)gentype_mean,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"trace", (PyCFunction)gentype_trace,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"diagonal", (PyCFunction)gentype_diagonal,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"clip", (PyCFunction)gentype_clip,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"conj", (PyCFunction)gentype_conj,
- METH_VARARGS, NULL},
- {"conjugate", (PyCFunction)gentype_conjugate,
- METH_VARARGS, NULL},
- {"nonzero", (PyCFunction)gentype_nonzero,
- METH_VARARGS, NULL},
- {"std", (PyCFunction)gentype_std,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"var", (PyCFunction)gentype_var,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"sum", (PyCFunction)gentype_sum,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"cumsum", (PyCFunction)gentype_cumsum,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"prod", (PyCFunction)gentype_prod,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"cumprod", (PyCFunction)gentype_cumprod,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"all", (PyCFunction)gentype_all,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"any", (PyCFunction)gentype_any,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"compress", (PyCFunction)gentype_compress,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"flatten", (PyCFunction)gentype_flatten,
- METH_VARARGS, NULL},
- {"ravel", (PyCFunction)gentype_ravel,
- METH_VARARGS, NULL},
- {"round", (PyCFunction)gentype_round,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"setflags", (PyCFunction)gentype_setflags,
- METH_VARARGS|METH_KEYWORDS, NULL},
- {"newbyteorder", (PyCFunction)gentype_newbyteorder,
- METH_VARARGS, NULL},
- {NULL, NULL} /* sentinel */
+ /* Methods for array */
+ {"fill", (PyCFunction)gentype_fill,
+ METH_VARARGS, NULL},
+ {"transpose", (PyCFunction)gentype_transpose,
+ METH_VARARGS, NULL},
+ {"take", (PyCFunction)gentype_take,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"put", (PyCFunction)gentype_put,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"putmask", (PyCFunction)gentype_putmask,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"repeat", (PyCFunction)gentype_repeat,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"choose", (PyCFunction)gentype_choose,
+ METH_VARARGS, NULL},
+ {"sort", (PyCFunction)gentype_sort,
+ METH_VARARGS, NULL},
+ {"argsort", (PyCFunction)gentype_argsort,
+ METH_VARARGS, NULL},
+ {"searchsorted", (PyCFunction)gentype_searchsorted,
+ METH_VARARGS, NULL},
+ {"argmax", (PyCFunction)gentype_argmax,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"argmin", (PyCFunction)gentype_argmin,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"reshape", (PyCFunction)gentype_reshape,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"squeeze", (PyCFunction)gentype_squeeze,
+ METH_VARARGS, NULL},
+ {"view", (PyCFunction)gentype_view,
+ METH_VARARGS, NULL},
+ {"swapaxes", (PyCFunction)gentype_swapaxes,
+ METH_VARARGS, NULL},
+ {"max", (PyCFunction)gentype_max,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"min", (PyCFunction)gentype_min,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"ptp", (PyCFunction)gentype_ptp,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"mean", (PyCFunction)gentype_mean,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"trace", (PyCFunction)gentype_trace,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"diagonal", (PyCFunction)gentype_diagonal,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"clip", (PyCFunction)gentype_clip,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"conj", (PyCFunction)gentype_conj,
+ METH_VARARGS, NULL},
+ {"conjugate", (PyCFunction)gentype_conjugate,
+ METH_VARARGS, NULL},
+ {"nonzero", (PyCFunction)gentype_nonzero,
+ METH_VARARGS, NULL},
+ {"std", (PyCFunction)gentype_std,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"var", (PyCFunction)gentype_var,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"sum", (PyCFunction)gentype_sum,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"cumsum", (PyCFunction)gentype_cumsum,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"prod", (PyCFunction)gentype_prod,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"cumprod", (PyCFunction)gentype_cumprod,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"all", (PyCFunction)gentype_all,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"any", (PyCFunction)gentype_any,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"compress", (PyCFunction)gentype_compress,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"flatten", (PyCFunction)gentype_flatten,
+ METH_VARARGS, NULL},
+ {"ravel", (PyCFunction)gentype_ravel,
+ METH_VARARGS, NULL},
+ {"round", (PyCFunction)gentype_round,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"setflags", (PyCFunction)gentype_setflags,
+ METH_VARARGS|METH_KEYWORDS, NULL},
+ {"newbyteorder", (PyCFunction)gentype_newbyteorder,
+ METH_VARARGS, NULL},
+ {NULL, NULL} /* sentinel */
};
static PyGetSetDef voidtype_getsets[] = {
{"flags",
- (getter)voidtype_flags_get,
- (setter)0,
- "integer value of flags"},
- {"dtype",
- (getter)voidtype_dtypedescr_get,
- (setter)0,
- "dtype object"},
- {NULL, NULL}
+ (getter)voidtype_flags_get,
+ (setter)0,
+ "integer value of flags"},
+ {"dtype",
+ (getter)voidtype_dtypedescr_get,
+ (setter)0,
+ "dtype object"},
+ {NULL, NULL}
};
static PyMethodDef voidtype_methods[] = {
- {"getfield", (PyCFunction)voidtype_getfield,
- METH_VARARGS | METH_KEYWORDS, NULL},
- {"setfield", (PyCFunction)voidtype_setfield,
- METH_VARARGS | METH_KEYWORDS, NULL},
- {NULL, NULL}
+ {"getfield", (PyCFunction)voidtype_getfield,
+ METH_VARARGS | METH_KEYWORDS, NULL},
+ {"setfield", (PyCFunction)voidtype_setfield,
+ METH_VARARGS | METH_KEYWORDS, NULL},
+ {NULL, NULL}
};
/************* As_mapping functions for void array scalar ************/
@@ -1439,35 +1440,35 @@
static Py_ssize_t
voidtype_length(PyVoidScalarObject *self)
{
- if (!self->descr->names) {
- return 0;
- }
- else { /* return the number of fields */
+ if (!self->descr->names) {
+ return 0;
+ }
+ else { /* return the number of fields */
return (Py_ssize_t) PyTuple_GET_SIZE(self->descr->names);
- }
+ }
}
static PyObject *
voidtype_item(PyVoidScalarObject *self, Py_ssize_t n)
{
- intp m;
- PyObject *flist=NULL, *fieldinfo;
+ intp m;
+ PyObject *flist=NULL, *fieldinfo;
- if (!(PyDescr_HASFIELDS(self->descr))) {
- PyErr_SetString(PyExc_IndexError,
- "can't index void scalar without fields");
- return NULL;
- }
+ if (!(PyDescr_HASFIELDS(self->descr))) {
+ PyErr_SetString(PyExc_IndexError,
+ "can't index void scalar without fields");
+ return NULL;
+ }
flist = self->descr->names;
- m = PyTuple_GET_SIZE(flist);
- if (n < 0) n += m;
- if (n < 0 || n >= m) {
- PyErr_Format(PyExc_IndexError, "invalid index (%d)", (int) n);
- return NULL;
- }
- fieldinfo = PyDict_GetItem(self->descr->fields,
- PyTuple_GET_ITEM(flist, n));
- return voidtype_getfield(self, fieldinfo, NULL);
+ m = PyTuple_GET_SIZE(flist);
+ if (n < 0) n += m;
+ if (n < 0 || n >= m) {
+ PyErr_Format(PyExc_IndexError, "invalid index (%d)", (int) n);
+ return NULL;
+ }
+ fieldinfo = PyDict_GetItem(self->descr->fields,
+ PyTuple_GET_ITEM(flist, n));
+ return voidtype_getfield(self, fieldinfo, NULL);
}
@@ -1475,114 +1476,114 @@
static PyObject *
voidtype_subscript(PyVoidScalarObject *self, PyObject *ind)
{
- intp n;
- PyObject *fieldinfo;
+ intp n;
+ PyObject *fieldinfo;
- if (!(PyDescr_HASFIELDS(self->descr))) {
- PyErr_SetString(PyExc_IndexError,
- "can't index void scalar without fields");
- return NULL;
- }
+ if (!(PyDescr_HASFIELDS(self->descr))) {
+ PyErr_SetString(PyExc_IndexError,
+ "can't index void scalar without fields");
+ return NULL;
+ }
- if (PyString_Check(ind) || PyUnicode_Check(ind)) {
- /* look up in fields */
- fieldinfo = PyDict_GetItem(self->descr->fields, ind);
- if (!fieldinfo) goto fail;
- return voidtype_getfield(self, fieldinfo, NULL);
- }
+ if (PyString_Check(ind) || PyUnicode_Check(ind)) {
+ /* look up in fields */
+ fieldinfo = PyDict_GetItem(self->descr->fields, ind);
+ if (!fieldinfo) goto fail;
+ return voidtype_getfield(self, fieldinfo, NULL);
+ }
- /* try to convert it to a number */
- n = PyArray_PyIntAsIntp(ind);
- if (error_converting(n)) goto fail;
+ /* try to convert it to a number */
+ n = PyArray_PyIntAsIntp(ind);
+ if (error_converting(n)) goto fail;
- return voidtype_item(self, (Py_ssize_t)n);
+ return voidtype_item(self, (Py_ssize_t)n);
fail:
- PyErr_SetString(PyExc_IndexError, "invalid index");
- return NULL;
+ PyErr_SetString(PyExc_IndexError, "invalid index");
+ return NULL;
}
static int
voidtype_ass_item(PyVoidScalarObject *self, Py_ssize_t n, PyObject *val)
{
- intp m;
- PyObject *flist=NULL, *fieldinfo, *newtup;
- PyObject *res;
+ intp m;
+ PyObject *flist=NULL, *fieldinfo, *newtup;
+ PyObject *res;
- if (!(PyDescr_HASFIELDS(self->descr))) {
- PyErr_SetString(PyExc_IndexError,
- "can't index void scalar without fields");
- return -1;
- }
+ if (!(PyDescr_HASFIELDS(self->descr))) {
+ PyErr_SetString(PyExc_IndexError,
+ "can't index void scalar without fields");
+ return -1;
+ }
flist = self->descr->names;
- m = PyTuple_GET_SIZE(flist);
- if (n < 0) n += m;
- if (n < 0 || n >= m) goto fail;
- fieldinfo = PyDict_GetItem(self->descr->fields,
- PyTuple_GET_ITEM(flist, n));
- newtup = Py_BuildValue("(OOO)", val,
- PyTuple_GET_ITEM(fieldinfo, 0),
- PyTuple_GET_ITEM(fieldinfo, 1));
- res = voidtype_setfield(self, newtup, NULL);
- Py_DECREF(newtup);
- if (!res) return -1;
- Py_DECREF(res);
- return 0;
+ m = PyTuple_GET_SIZE(flist);
+ if (n < 0) n += m;
+ if (n < 0 || n >= m) goto fail;
+ fieldinfo = PyDict_GetItem(self->descr->fields,
+ PyTuple_GET_ITEM(flist, n));
+ newtup = Py_BuildValue("(OOO)", val,
+ PyTuple_GET_ITEM(fieldinfo, 0),
+ PyTuple_GET_ITEM(fieldinfo, 1));
+ res = voidtype_setfield(self, newtup, NULL);
+ Py_DECREF(newtup);
+ if (!res) return -1;
+ Py_DECREF(res);
+ return 0;
fail:
- PyErr_Format(PyExc_IndexError, "invalid index (%d)", (int) n);
- return -1;
+ PyErr_Format(PyExc_IndexError, "invalid index (%d)", (int) n);
+ return -1;
}
static int
voidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val)
{
- intp n;
- char *msg = "invalid index";
- PyObject *fieldinfo, *newtup;
- PyObject *res;
+ intp n;
+ char *msg = "invalid index";
+ PyObject *fieldinfo, *newtup;
+ PyObject *res;
- if (!PyDescr_HASFIELDS(self->descr)) {
- PyErr_SetString(PyExc_IndexError,
- "can't index void scalar without fields");
- return -1;
- }
+ if (!PyDescr_HASFIELDS(self->descr)) {
+ PyErr_SetString(PyExc_IndexError,
+ "can't index void scalar without fields");
+ return -1;
+ }
- if (PyString_Check(ind) || PyUnicode_Check(ind)) {
- /* look up in fields */
- fieldinfo = PyDict_GetItem(self->descr->fields, ind);
- if (!fieldinfo) goto fail;
- newtup = Py_BuildValue("(OOO)", val,
- PyTuple_GET_ITEM(fieldinfo, 0),
- PyTuple_GET_ITEM(fieldinfo, 1));
- res = voidtype_setfield(self, newtup, NULL);
- Py_DECREF(newtup);
- if (!res) return -1;
- Py_DECREF(res);
- return 0;
- }
+ if (PyString_Check(ind) || PyUnicode_Check(ind)) {
+ /* look up in fields */
+ fieldinfo = PyDict_GetItem(self->descr->fields, ind);
+ if (!fieldinfo) goto fail;
+ newtup = Py_BuildValue("(OOO)", val,
+ PyTuple_GET_ITEM(fieldinfo, 0),
+ PyTuple_GET_ITEM(fieldinfo, 1));
+ res = voidtype_setfield(self, newtup, NULL);
+ Py_DECREF(newtup);
+ if (!res) return -1;
+ Py_DECREF(res);
+ return 0;
+ }
- /* try to convert it to a number */
- n = PyArray_PyIntAsIntp(ind);
- if (error_converting(n)) goto fail;
- return voidtype_ass_item(self, (Py_ssize_t)n, val);
+ /* try to convert it to a number */
+ n = PyArray_PyIntAsIntp(ind);
+ if (error_converting(n)) goto fail;
+ return voidtype_ass_item(self, (Py_ssize_t)n, val);
fail:
- PyErr_SetString(PyExc_IndexError, msg);
- return -1;
+ PyErr_SetString(PyExc_IndexError, msg);
+ return -1;
}
static PyMappingMethods voidtype_as_mapping = {
#if PY_VERSION_HEX >= 0x02050000
- (lenfunc)voidtype_length, /*mp_length*/
+ (lenfunc)voidtype_length, /*mp_length*/
#else
- (inquiry)voidtype_length, /*mp_length*/
+ (inquiry)voidtype_length, /*mp_length*/
#endif
- (binaryfunc)voidtype_subscript, /*mp_subscript*/
- (objobjargproc)voidtype_ass_subscript, /*mp_ass_subscript*/
+ (binaryfunc)voidtype_subscript, /*mp_subscript*/
+ (objobjargproc)voidtype_ass_subscript, /*mp_ass_subscript*/
};
@@ -1591,15 +1592,15 @@
(lenfunc)voidtype_length, /*sq_length*/
0, /*sq_concat*/
0, /*sq_repeat*/
- (ssizeargfunc)voidtype_item, /*sq_item*/
- 0, /*sq_slice*/
+ (ssizeargfunc)voidtype_item, /*sq_item*/
+ 0, /*sq_slice*/
(ssizeobjargproc)voidtype_ass_item /*sq_ass_item*/
#else
(inquiry)voidtype_length, /*sq_length*/
0, /*sq_concat*/
0, /*sq_repeat*/
- (intargfunc)voidtype_item, /*sq_item*/
- 0, /*sq_slice*/
+ (intargfunc)voidtype_item, /*sq_item*/
+ 0, /*sq_slice*/
(intobjargproc)voidtype_ass_item /*sq_ass_item*/
#endif
};
@@ -1609,54 +1610,54 @@
static int
gentype_getreadbuf(PyObject *self, int segment, void **ptrptr)
{
- int numbytes;
- PyArray_Descr *outcode;
+ int numbytes;
+ PyArray_Descr *outcode;
- if (segment != 0) {
- PyErr_SetString(PyExc_SystemError,
- "Accessing non-existent array segment");
- return -1;
- }
+ if (segment != 0) {
+ PyErr_SetString(PyExc_SystemError,
+ "Accessing non-existent array segment");
+ return -1;
+ }
- outcode = PyArray_DescrFromScalar(self);
- numbytes = outcode->elsize;
- *ptrptr = (void *)scalar_value(self, outcode);
+ outcode = PyArray_DescrFromScalar(self);
+ numbytes = outcode->elsize;
+ *ptrptr = (void *)scalar_value(self, outcode);
- Py_DECREF(outcode);
- return numbytes;
+ Py_DECREF(outcode);
+ return numbytes;
}
static int
gentype_getsegcount(PyObject *self, int *lenp)
{
- PyArray_Descr *outcode;
+ PyArray_Descr *outcode;
- outcode = PyArray_DescrFromScalar(self);
- if (lenp)
- *lenp = outcode->elsize;
- Py_DECREF(outcode);
- return 1;
+ outcode = PyArray_DescrFromScalar(self);
+ if (lenp)
+ *lenp = outcode->elsize;
+ Py_DECREF(outcode);
+ return 1;
}
static int
gentype_getcharbuf(PyObject *self, int segment, const char **ptrptr)
{
- if (PyArray_IsScalar(self, String) || \
- PyArray_IsScalar(self, Unicode))
- return gentype_getreadbuf(self, segment, (void **)ptrptr);
- else {
- PyErr_SetString(PyExc_TypeError,
- "Non-character array cannot be interpreted "\
- "as character buffer.");
- return -1;
- }
+ if (PyArray_IsScalar(self, String) || \
+ PyArray_IsScalar(self, Unicode))
+ return gentype_getreadbuf(self, segment, (void **)ptrptr);
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "Non-character array cannot be interpreted "\
+ "as character buffer.");
+ return -1;
+ }
}
static PyBufferProcs gentype_as_buffer = {
(getreadbufferproc)gentype_getreadbuf, /*bf_getreadbuffer*/
(getwritebufferproc)0, /*bf_getwritebuffer*/
- (getsegcountproc)gentype_getsegcount, /*bf_getsegcount*/
+ (getsegcountproc)gentype_getsegcount, /*bf_getsegcount*/
(getcharbufferproc)gentype_getcharbuf, /*bf_getcharbuffer*/
};
@@ -1666,26 +1667,26 @@
static PyTypeObject PyGenericArrType_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "genericscalar", /*tp_name*/
- sizeof(PyObject), /*tp_basicsize*/
+ 0, /*ob_size*/
+ "genericscalar", /*tp_name*/
+ sizeof(PyObject), /*tp_basicsize*/
};
static void
void_dealloc(PyVoidScalarObject *v)
{
- if (v->flags & OWNDATA)
- PyDataMem_FREE(v->obval);
- Py_XDECREF(v->descr);
- Py_XDECREF(v->base);
- v->ob_type->tp_free(v);
+ if (v->flags & OWNDATA)
+ PyDataMem_FREE(v->obval);
+ Py_XDECREF(v->descr);
+ Py_XDECREF(v->base);
+ v->ob_type->tp_free(v);
}
static void
object_arrtype_dealloc(PyObject *v)
{
- Py_XDECREF(((PyObjectScalarObject *)v)->obval);
- v->ob_type->tp_free(v);
+ Py_XDECREF(((PyObjectScalarObject *)v)->obval);
+ v->ob_type->tp_free(v);
}
/* string and unicode inherit from Python Type first and so GET_ITEM is different to get to the Python Type.
@@ -1695,18 +1696,18 @@
*/
#define _WORK(num) \
- if (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) { \
- PyTypeObject *sup; \
- PyObject *ret; \
- /* We are inheriting from a Python type as well so \
- give it first dibs on conversion */ \
- sup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, num); \
- ret = sup->tp_new(type, args, kwds); \
- if (ret) return ret; \
- if (PyTuple_GET_SIZE(args)!=1) return NULL; \
- PyErr_Clear(); \
- /* now do default conversion */ \
- }
+ if (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) { \
+ PyTypeObject *sup; \
+ PyObject *ret; \
+ /* We are inheriting from a Python type as well so \
+ give it first dibs on conversion */ \
+ sup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, num); \
+ ret = sup->tp_new(type, args, kwds); \
+ if (ret) return ret; \
+ if (PyTuple_GET_SIZE(args)!=1) return NULL; \
+ PyErr_Clear(); \
+ /* now do default conversion */ \
+ }
#define _WORK1 _WORK(1)
#define _WORKz _WORK(0)
@@ -1720,17 +1721,17 @@
static PyObject *
@name at _arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- PyObject *obj=NULL;
- PyObject *arr;
- PyArray_Descr *typecode;
+ PyObject *obj=NULL;
+ PyObject *arr;
+ PyArray_Descr *typecode;
- _WORK at work@
+ _WORK at work@
- if (!PyArg_ParseTuple(args, "O", &obj)) return NULL;
+ if (!PyArg_ParseTuple(args, "O", &obj)) return NULL;
- typecode = PyArray_DescrFromType(PyArray_ at TYPE@);
- arr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);
- return PyArray_Return((PyArrayObject *)arr);
+ typecode = PyArray_DescrFromType(PyArray_ at TYPE@);
+ arr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);
+ return PyArray_Return((PyArrayObject *)arr);
}
/**end repeat**/
@@ -1743,126 +1744,126 @@
static PyObject *
bool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- PyObject *obj=NULL;
- PyObject *arr;
+ PyObject *obj=NULL;
+ PyObject *arr;
- if (!PyArg_ParseTuple(args, "O", &obj)) return NULL;
- if (obj == Py_False)
- PyArrayScalar_RETURN_FALSE;
- if (obj == Py_True)
- PyArrayScalar_RETURN_TRUE;
- arr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);
- if (arr && 0 == PyArray_NDIM(arr)) {
- Bool val = *((Bool *)PyArray_DATA(arr));
- Py_DECREF(arr);
- PyArrayScalar_RETURN_BOOL_FROM_LONG(val);
- }
- return PyArray_Return((PyArrayObject *)arr);
+ if (!PyArg_ParseTuple(args, "O", &obj)) return NULL;
+ if (obj == Py_False)
+ PyArrayScalar_RETURN_FALSE;
+ if (obj == Py_True)
+ PyArrayScalar_RETURN_TRUE;
+ arr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);
+ if (arr && 0 == PyArray_NDIM(arr)) {
+ Bool val = *((Bool *)PyArray_DATA(arr));
+ Py_DECREF(arr);
+ PyArrayScalar_RETURN_BOOL_FROM_LONG(val);
+ }
+ return PyArray_Return((PyArrayObject *)arr);
}
static PyObject *
bool_arrtype_and(PyObject *a, PyObject *b)
{
- if (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool))
- PyArrayScalar_RETURN_BOOL_FROM_LONG
- ((a == PyArrayScalar_True)&(b == PyArrayScalar_True));
- return PyGenericArrType_Type.tp_as_number->nb_and(a, b);
+ if (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool))
+ PyArrayScalar_RETURN_BOOL_FROM_LONG
+ ((a == PyArrayScalar_True)&(b == PyArrayScalar_True));
+ return PyGenericArrType_Type.tp_as_number->nb_and(a, b);
}
static PyObject *
bool_arrtype_or(PyObject *a, PyObject *b)
{
- if (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool))
- PyArrayScalar_RETURN_BOOL_FROM_LONG
- ((a == PyArrayScalar_True)|(b == PyArrayScalar_True));
- return PyGenericArrType_Type.tp_as_number->nb_or(a, b);
+ if (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool))
+ PyArrayScalar_RETURN_BOOL_FROM_LONG
+ ((a == PyArrayScalar_True)|(b == PyArrayScalar_True));
+ return PyGenericArrType_Type.tp_as_number->nb_or(a, b);
}
static PyObject *
bool_arrtype_xor(PyObject *a, PyObject *b)
{
- if (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool))
- PyArrayScalar_RETURN_BOOL_FROM_LONG
- ((a == PyArrayScalar_True)^(b == PyArrayScalar_True));
- return PyGenericArrType_Type.tp_as_number->nb_xor(a, b);
+ if (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool))
+ PyArrayScalar_RETURN_BOOL_FROM_LONG
+ ((a == PyArrayScalar_True)^(b == PyArrayScalar_True));
+ return PyGenericArrType_Type.tp_as_number->nb_xor(a, b);
}
static int
bool_arrtype_nonzero(PyObject *a)
{
- return a == PyArrayScalar_True;
+ return a == PyArrayScalar_True;
}
/* Arithmetic methods -- only so we can override &, |, ^. */
static PyNumberMethods bool_arrtype_as_number = {
- 0, /* nb_add */
- 0, /* nb_subtract */
- 0, /* nb_multiply */
- 0, /* nb_divide */
- 0, /* nb_remainder */
- 0, /* nb_divmod */
- 0, /* nb_power */
- 0, /* nb_negative */
- 0, /* nb_positive */
- 0, /* nb_absolute */
- (inquiry)bool_arrtype_nonzero, /* nb_nonzero */
- 0, /* nb_invert */
- 0, /* nb_lshift */
- 0, /* nb_rshift */
- (binaryfunc)bool_arrtype_and, /* nb_and */
- (binaryfunc)bool_arrtype_xor, /* nb_xor */
- (binaryfunc)bool_arrtype_or, /* nb_or */
+ 0, /* nb_add */
+ 0, /* nb_subtract */
+ 0, /* nb_multiply */
+ 0, /* nb_divide */
+ 0, /* nb_remainder */
+ 0, /* nb_divmod */
+ 0, /* nb_power */
+ 0, /* nb_negative */
+ 0, /* nb_positive */
+ 0, /* nb_absolute */
+ (inquiry)bool_arrtype_nonzero, /* nb_nonzero */
+ 0, /* nb_invert */
+ 0, /* nb_lshift */
+ 0, /* nb_rshift */
+ (binaryfunc)bool_arrtype_and, /* nb_and */
+ (binaryfunc)bool_arrtype_xor, /* nb_xor */
+ (binaryfunc)bool_arrtype_or, /* nb_or */
};
static PyObject *
void_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- PyObject *obj, *arr;
- ulonglong memu=1;
- PyObject *new=NULL;
- char *destptr;
+ PyObject *obj, *arr;
+ ulonglong memu=1;
+ PyObject *new=NULL;
+ char *destptr;
- if (!PyArg_ParseTuple(args, "O", &obj)) return NULL;
- /* For a VOID scalar first see if obj is an integer or long
- and create new memory of that size (filled with 0) for the scalar
- */
+ if (!PyArg_ParseTuple(args, "O", &obj)) return NULL;
+ /* For a VOID scalar first see if obj is an integer or long
+ and create new memory of that size (filled with 0) for the scalar
+ */
- if (PyLong_Check(obj) || PyInt_Check(obj) || \
- PyArray_IsScalar(obj, Integer) ||
- (PyArray_Check(obj) && PyArray_NDIM(obj)==0 && \
- PyArray_ISINTEGER(obj))) {
- new = obj->ob_type->tp_as_number->nb_long(obj);
- }
- if (new && PyLong_Check(new)) {
- PyObject *ret;
- memu = PyLong_AsUnsignedLongLong(new);
- Py_DECREF(new);
- if (PyErr_Occurred() || (memu > MAX_INT)) {
- PyErr_Clear();
- PyErr_Format(PyExc_OverflowError,
- "size must be smaller than %d",
- (int) MAX_INT);
- return NULL;
- }
- destptr = PyDataMem_NEW((int) memu);
- if (destptr == NULL) return PyErr_NoMemory();
- ret = type->tp_alloc(type, 0);
- if (ret == NULL) {
- PyDataMem_FREE(destptr);
- return PyErr_NoMemory();
- }
- ((PyVoidScalarObject *)ret)->obval = destptr;
- ((PyVoidScalarObject *)ret)->ob_size = (int) memu;
- ((PyVoidScalarObject *)ret)->descr = \
- PyArray_DescrNewFromType(PyArray_VOID);
- ((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;
- ((PyVoidScalarObject *)ret)->flags = BEHAVED | OWNDATA;
- ((PyVoidScalarObject *)ret)->base = NULL;
- memset(destptr, '\0', (size_t) memu);
- return ret;
- }
+ if (PyLong_Check(obj) || PyInt_Check(obj) || \
+ PyArray_IsScalar(obj, Integer) ||
+ (PyArray_Check(obj) && PyArray_NDIM(obj)==0 && \
+ PyArray_ISINTEGER(obj))) {
+ new = obj->ob_type->tp_as_number->nb_long(obj);
+ }
+ if (new && PyLong_Check(new)) {
+ PyObject *ret;
+ memu = PyLong_AsUnsignedLongLong(new);
+ Py_DECREF(new);
+ if (PyErr_Occurred() || (memu > MAX_INT)) {
+ PyErr_Clear();
+ PyErr_Format(PyExc_OverflowError,
+ "size must be smaller than %d",
+ (int) MAX_INT);
+ return NULL;
+ }
+ destptr = PyDataMem_NEW((int) memu);
+ if (destptr == NULL) return PyErr_NoMemory();
+ ret = type->tp_alloc(type, 0);
+ if (ret == NULL) {
+ PyDataMem_FREE(destptr);
+ return PyErr_NoMemory();
+ }
+ ((PyVoidScalarObject *)ret)->obval = destptr;
+ ((PyVoidScalarObject *)ret)->ob_size = (int) memu;
+ ((PyVoidScalarObject *)ret)->descr = \
+ PyArray_DescrNewFromType(PyArray_VOID);
+ ((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;
+ ((PyVoidScalarObject *)ret)->flags = BEHAVED | OWNDATA;
+ ((PyVoidScalarObject *)ret)->base = NULL;
+ memset(destptr, '\0', (size_t) memu);
+ return ret;
+ }
- arr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);
+ arr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);
return PyArray_Return((PyArrayObject *)arr);
}
@@ -1992,74 +1993,74 @@
/*object arrtype getattro and setattro */
static PyObject *
object_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {
- PyObject *res;
+ PyObject *res;
- /* first look in object and then hand off to generic type */
+ /* first look in object and then hand off to generic type */
- res = PyObject_GenericGetAttr(obj->obval, attr);
- if (res) return res;
- PyErr_Clear();
- return PyObject_GenericGetAttr((PyObject *)obj, attr);
+ res = PyObject_GenericGetAttr(obj->obval, attr);
+ if (res) return res;
+ PyErr_Clear();
+ return PyObject_GenericGetAttr((PyObject *)obj, attr);
}
static int
object_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {
- int res;
- /* first look in object and then hand off to generic type */
+ int res;
+ /* first look in object and then hand off to generic type */
- res = PyObject_GenericSetAttr(obj->obval, attr, val);
- if (res >= 0) return res;
- PyErr_Clear();
- return PyObject_GenericSetAttr((PyObject *)obj, attr, val);
+ res = PyObject_GenericSetAttr(obj->obval, attr, val);
+ if (res >= 0) return res;
+ PyErr_Clear();
+ return PyObject_GenericSetAttr((PyObject *)obj, attr, val);
}
static PyObject *
object_arrtype_concat(PyObjectScalarObject *self, PyObject *other)
{
- return PySequence_Concat(self->obval, other);
+ return PySequence_Concat(self->obval, other);
}
static Py_ssize_t
object_arrtype_length(PyObjectScalarObject *self)
{
- return PyObject_Length(self->obval);
+ return PyObject_Length(self->obval);
}
static PyObject *
object_arrtype_repeat(PyObjectScalarObject *self, Py_ssize_t count)
{
- return PySequence_Repeat(self->obval, count);
+ return PySequence_Repeat(self->obval, count);
}
static PyObject *
object_arrtype_subscript(PyObjectScalarObject *self, PyObject *key)
{
- return PyObject_GetItem(self->obval, key);
+ return PyObject_GetItem(self->obval, key);
}
static int
object_arrtype_ass_subscript(PyObjectScalarObject *self, PyObject *key,
- PyObject *value)
+ PyObject *value)
{
- return PyObject_SetItem(self->obval, key, value);
+ return PyObject_SetItem(self->obval, key, value);
}
static int
object_arrtype_contains(PyObjectScalarObject *self, PyObject *ob)
{
- return PySequence_Contains(self->obval, ob);
+ return PySequence_Contains(self->obval, ob);
}
static PyObject *
object_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)
{
- return PySequence_InPlaceConcat(self->obval, o);
+ return PySequence_InPlaceConcat(self->obval, o);
}
static PyObject *
object_arrtype_inplace_repeat(PyObjectScalarObject *self, Py_ssize_t count)
{
- return PySequence_InPlaceRepeat(self->obval, count);
+ return PySequence_InPlaceRepeat(self->obval, count);
}
static PySequenceMethods object_arrtype_as_sequence = {
@@ -2103,68 +2104,68 @@
static Py_ssize_t
object_arrtype_getsegcount(PyObjectScalarObject *self, Py_ssize_t *lenp)
{
- int newlen;
- int cnt;
- PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
+ int newlen;
+ int cnt;
+ PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
- if (pb == NULL || \
- pb->bf_getsegcount == NULL || \
- (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1)
- return 0;
+ if (pb == NULL || \
+ pb->bf_getsegcount == NULL || \
+ (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1)
+ return 0;
- if (lenp)
- *lenp = newlen;
+ if (lenp)
+ *lenp = newlen;
- return cnt;
+ return cnt;
}
static Py_ssize_t
object_arrtype_getreadbuf(PyObjectScalarObject *self, Py_ssize_t segment, void **ptrptr)
{
- PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
+ PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
- if (pb == NULL || \
- pb->bf_getreadbuffer == NULL ||
- pb->bf_getsegcount == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "expected a readable buffer object");
- return -1;
- }
+ if (pb == NULL || \
+ pb->bf_getreadbuffer == NULL ||
+ pb->bf_getsegcount == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "expected a readable buffer object");
+ return -1;
+ }
- return (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);
+ return (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);
}
static Py_ssize_t
object_arrtype_getwritebuf(PyObjectScalarObject *self, Py_ssize_t segment, void **ptrptr)
{
- PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
+ PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
- if (pb == NULL || \
- pb->bf_getwritebuffer == NULL ||
- pb->bf_getsegcount == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "expected a writeable buffer object");
- return -1;
- }
+ if (pb == NULL || \
+ pb->bf_getwritebuffer == NULL ||
+ pb->bf_getsegcount == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "expected a writeable buffer object");
+ return -1;
+ }
- return (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);
+ return (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);
}
static Py_ssize_t
object_arrtype_getcharbuf(PyObjectScalarObject *self, Py_ssize_t segment,
- const char **ptrptr)
+ const char **ptrptr)
{
- PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
+ PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
- if (pb == NULL || \
- pb->bf_getcharbuffer == NULL ||
- pb->bf_getsegcount == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "expected a character buffer object");
- return -1;
- }
+ if (pb == NULL || \
+ pb->bf_getcharbuffer == NULL ||
+ pb->bf_getsegcount == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "expected a character buffer object");
+ return -1;
+ }
- return (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);
+ return (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);
}
static PyBufferProcs object_arrtype_as_buffer = {
@@ -2184,14 +2185,14 @@
static PyObject *
object_arrtype_call(PyObjectScalarObject *obj, PyObject *args, PyObject *kwds)
{
- return PyObject_Call(obj->obval, args, kwds);
+ return PyObject_Call(obj->obval, args, kwds);
}
static PyTypeObject PyObjectArrType_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "objectscalar", /*tp_name*/
- sizeof(PyObjectScalarObject), /*tp_basicsize*/
+ 0, /*ob_size*/
+ "objectscalar", /*tp_name*/
+ sizeof(PyObjectScalarObject), /*tp_basicsize*/
0, /* tp_itemsize */
(destructor)object_arrtype_dealloc, /* tp_dealloc */
0, /* tp_print */
@@ -2217,9 +2218,9 @@
*/
static PyTypeObject Py at NAME@ArrType_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "@name at scalar", /*tp_name*/
- sizeof(Py at NAME@ScalarObject), /*tp_basicsize*/
+ 0, /*ob_size*/
+ "@name at scalar", /*tp_name*/
+ sizeof(Py at NAME@ScalarObject), /*tp_basicsize*/
};
/**end repeat**/
@@ -2247,9 +2248,9 @@
#endif
static PyTypeObject Py at NAME@ArrType_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ 0, /*ob_size*/
"@name@" _THIS_SIZE "scalar", /*tp_name*/
- sizeof(Py at NAME@ScalarObject), /*tp_basicsize*/
+ sizeof(Py at NAME@ScalarObject), /*tp_basicsize*/
};
#undef _THIS_SIZE
@@ -2284,9 +2285,9 @@
#endif
static PyTypeObject Py at NAME@ArrType_Type = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ 0, /*ob_size*/
"@name@" _THIS_SIZE1 "scalar", /*tp_name*/
- sizeof(Py at NAME@ScalarObject), /*tp_basicsize*/
+ sizeof(Py at NAME@ScalarObject), /*tp_basicsize*/
0, /*tp_itemsize*/
0, /*tp_dealloc*/
0, /*tp_print*/
@@ -2320,52 +2321,52 @@
static void
initialize_numeric_types(void)
{
- PyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;
- PyGenericArrType_Type.tp_as_number = &gentype_as_number;
- PyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;
- PyGenericArrType_Type.tp_flags = BASEFLAGS;
- PyGenericArrType_Type.tp_methods = gentype_methods;
- PyGenericArrType_Type.tp_getset = gentype_getsets;
- PyGenericArrType_Type.tp_new = NULL;
+ PyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;
+ PyGenericArrType_Type.tp_as_number = &gentype_as_number;
+ PyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;
+ PyGenericArrType_Type.tp_flags = BASEFLAGS;
+ PyGenericArrType_Type.tp_methods = gentype_methods;
+ PyGenericArrType_Type.tp_getset = gentype_getsets;
+ PyGenericArrType_Type.tp_new = NULL;
PyGenericArrType_Type.tp_alloc = gentype_alloc;
- PyGenericArrType_Type.tp_free = _pya_free;
- PyGenericArrType_Type.tp_repr = gentype_repr;
- PyGenericArrType_Type.tp_str = gentype_str;
- PyGenericArrType_Type.tp_richcompare = gentype_richcompare;
+ PyGenericArrType_Type.tp_free = _pya_free;
+ PyGenericArrType_Type.tp_repr = gentype_repr;
+ PyGenericArrType_Type.tp_str = gentype_str;
+ PyGenericArrType_Type.tp_richcompare = gentype_richcompare;
- PyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;
+ PyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;
- PyStringArrType_Type.tp_alloc = NULL;
- PyStringArrType_Type.tp_free = NULL;
+ PyStringArrType_Type.tp_alloc = NULL;
+ PyStringArrType_Type.tp_free = NULL;
- PyStringArrType_Type.tp_repr = stringtype_repr;
- PyStringArrType_Type.tp_str = stringtype_str;
+ PyStringArrType_Type.tp_repr = stringtype_repr;
+ PyStringArrType_Type.tp_str = stringtype_str;
- PyUnicodeArrType_Type.tp_repr = unicodetype_repr;
- PyUnicodeArrType_Type.tp_str = unicodetype_str;
+ PyUnicodeArrType_Type.tp_repr = unicodetype_repr;
+ PyUnicodeArrType_Type.tp_str = unicodetype_str;
- PyVoidArrType_Type.tp_methods = voidtype_methods;
- PyVoidArrType_Type.tp_getset = voidtype_getsets;
- PyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;
- PyVoidArrType_Type.tp_as_sequence = &voidtype_as_sequence;
+ PyVoidArrType_Type.tp_methods = voidtype_methods;
+ PyVoidArrType_Type.tp_getset = voidtype_getsets;
+ PyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;
+ PyVoidArrType_Type.tp_as_sequence = &voidtype_as_sequence;
- /**begin repeat
+ /**begin repeat
#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating,
ComplexFloating, Flexible, Character#
- */
+ */
Py at NAME@ArrType_Type.tp_flags = BASEFLAGS;
- /**end repeat**/
+ /**end repeat**/
- /**begin repeat
+ /**begin repeat
#name=bool, byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object#
#NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object#
- */
- Py at NAME@ArrType_Type.tp_flags = LEAFFLAGS;
- Py at NAME@ArrType_Type.tp_new = @name at _arrtype_new;
- Py at NAME@ArrType_Type.tp_richcompare = gentype_richcompare;
- /**end repeat**/
- /* Allow the Void type to be subclassed -- for adding new types */
- PyVoidArrType_Type.tp_flags = BASEFLAGS;
+ */
+ Py at NAME@ArrType_Type.tp_flags = LEAFFLAGS;
+ Py at NAME@ArrType_Type.tp_new = @name at _arrtype_new;
+ Py at NAME@ArrType_Type.tp_richcompare = gentype_richcompare;
+ /**end repeat**/
+ /* Allow the Void type to be subclassed -- for adding new types */
+ PyVoidArrType_Type.tp_flags = BASEFLAGS;
/**begin repeat
#name=bool, byte, short, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object#
@@ -2384,25 +2385,25 @@
PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;
#endif
- /* These need to be coded specially because getitem does not
- return a normal Python type
- */
- PyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;
- PyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;
+ /* These need to be coded specially because getitem does not
+ return a normal Python type
+ */
+ PyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;
+ PyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;
- /**begin repeat
+ /**begin repeat
#name=int, long, hex, oct, float, repr, str#
#kind=tp_as_number->nb*5, tp*2#
- */
- PyLongDoubleArrType_Type. at kind@_ at name@ = longdoubletype_ at name@;
- PyCLongDoubleArrType_Type. at kind@_ at name@ = clongdoubletype_ at name@;
- /**end repeat**/
+ */
+ PyLongDoubleArrType_Type. at kind@_ at name@ = longdoubletype_ at name@;
+ PyCLongDoubleArrType_Type. at kind@_ at name@ = clongdoubletype_ at name@;
+ /**end repeat**/
- PyStringArrType_Type.tp_itemsize = sizeof(char);
- PyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;
+ PyStringArrType_Type.tp_itemsize = sizeof(char);
+ PyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;
- PyArrayIter_Type.tp_iter = PyObject_SelfIter;
- PyArrayMapIter_Type.tp_iter = PyObject_SelfIter;
+ PyArrayIter_Type.tp_iter = PyObject_SelfIter;
+ PyArrayMapIter_Type.tp_iter = PyObject_SelfIter;
}
@@ -2410,54 +2411,54 @@
static PyTypeObject *typeobjects[] = {
&PyBoolArrType_Type,
&PyByteArrType_Type,
- &PyUByteArrType_Type,
+ &PyUByteArrType_Type,
&PyShortArrType_Type,
&PyUShortArrType_Type,
- &PyIntArrType_Type,
- &PyUIntArrType_Type,
- &PyLongArrType_Type,
- &PyULongArrType_Type,
- &PyLongLongArrType_Type,
- &PyULongLongArrType_Type,
- &PyFloatArrType_Type,
- &PyDoubleArrType_Type,
- &PyLongDoubleArrType_Type,
- &PyCFloatArrType_Type,
- &PyCDoubleArrType_Type,
- &PyCLongDoubleArrType_Type,
- &PyObjectArrType_Type,
- &PyStringArrType_Type,
- &PyUnicodeArrType_Type,
- &PyVoidArrType_Type
+ &PyIntArrType_Type,
+ &PyUIntArrType_Type,
+ &PyLongArrType_Type,
+ &PyULongArrType_Type,
+ &PyLongLongArrType_Type,
+ &PyULongLongArrType_Type,
+ &PyFloatArrType_Type,
+ &PyDoubleArrType_Type,
+ &PyLongDoubleArrType_Type,
+ &PyCFloatArrType_Type,
+ &PyCDoubleArrType_Type,
+ &PyCLongDoubleArrType_Type,
+ &PyObjectArrType_Type,
+ &PyStringArrType_Type,
+ &PyUnicodeArrType_Type,
+ &PyVoidArrType_Type
};
static int
_typenum_fromtypeobj(PyObject *type, int user)
{
- int typenum, i;
+ int typenum, i;
- typenum = PyArray_NOTYPE;
+ typenum = PyArray_NOTYPE;
i = 0;
- while(i < PyArray_NTYPES) {
- if (type == (PyObject *)typeobjects[i]) {
- typenum = i;
- break;
- }
+ while(i < PyArray_NTYPES) {
+ if (type == (PyObject *)typeobjects[i]) {
+ typenum = i;
+ break;
+ }
i++;
- }
+ }
- if (!user) return typenum;
+ if (!user) return typenum;
- /* Search any registered types */
- i = 0;
- while (i < PyArray_NUMUSERTYPES) {
- if (type == (PyObject *)(userdescrs[i]->typeobj)) {
- typenum = i + PyArray_USERDEF;
- break;
- }
- i++;
- }
- return typenum;
+ /* Search any registered types */
+ i = 0;
+ while (i < PyArray_NUMUSERTYPES) {
+ if (type == (PyObject *)(userdescrs[i]->typeobj)) {
+ typenum = i + PyArray_USERDEF;
+ break;
+ }
+ i++;
+ }
+ return typenum;
}
/*New reference */
@@ -2466,65 +2467,65 @@
static PyArray_Descr *
PyArray_DescrFromTypeObject(PyObject *type)
{
- int typenum;
- PyArray_Descr *new, *conv=NULL;
+ int typenum;
+ PyArray_Descr *new, *conv=NULL;
- /* if it's a builtin type, then use the typenumber */
- typenum = _typenum_fromtypeobj(type,1);
- if (typenum != PyArray_NOTYPE) {
- new = PyArray_DescrFromType(typenum);
- return new;
- }
+ /* if it's a builtin type, then use the typenumber */
+ typenum = _typenum_fromtypeobj(type,1);
+ if (typenum != PyArray_NOTYPE) {
+ new = PyArray_DescrFromType(typenum);
+ return new;
+ }
- /* Check the generic types */
- if ((type == (PyObject *) &PyNumberArrType_Type) || \
- (type == (PyObject *) &PyInexactArrType_Type) || \
- (type == (PyObject *) &PyFloatingArrType_Type))
- typenum = PyArray_DOUBLE;
- else if (type == (PyObject *)&PyComplexFloatingArrType_Type)
- typenum = PyArray_CDOUBLE;
- else if ((type == (PyObject *)&PyIntegerArrType_Type) || \
- (type == (PyObject *)&PySignedIntegerArrType_Type))
- typenum = PyArray_LONG;
- else if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)
- typenum = PyArray_ULONG;
- else if (type == (PyObject *) &PyCharacterArrType_Type)
- typenum = PyArray_STRING;
- else if ((type == (PyObject *) &PyGenericArrType_Type) || \
- (type == (PyObject *) &PyFlexibleArrType_Type))
- typenum = PyArray_VOID;
+ /* Check the generic types */
+ if ((type == (PyObject *) &PyNumberArrType_Type) || \
+ (type == (PyObject *) &PyInexactArrType_Type) || \
+ (type == (PyObject *) &PyFloatingArrType_Type))
+ typenum = PyArray_DOUBLE;
+ else if (type == (PyObject *)&PyComplexFloatingArrType_Type)
+ typenum = PyArray_CDOUBLE;
+ else if ((type == (PyObject *)&PyIntegerArrType_Type) || \
+ (type == (PyObject *)&PySignedIntegerArrType_Type))
+ typenum = PyArray_LONG;
+ else if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)
+ typenum = PyArray_ULONG;
+ else if (type == (PyObject *) &PyCharacterArrType_Type)
+ typenum = PyArray_STRING;
+ else if ((type == (PyObject *) &PyGenericArrType_Type) || \
+ (type == (PyObject *) &PyFlexibleArrType_Type))
+ typenum = PyArray_VOID;
- if (typenum != PyArray_NOTYPE) {
- return PyArray_DescrFromType(typenum);
- }
+ if (typenum != PyArray_NOTYPE) {
+ return PyArray_DescrFromType(typenum);
+ }
- /* Otherwise --- type is a sub-type of an array scalar
- currently only VOID allows it -- use it as the type-object.
- */
- /* look for a dtypedescr attribute */
- if (!PyType_IsSubtype((PyTypeObject *)type, &PyVoidArrType_Type)) {
- PyErr_SetString(PyExc_TypeError,
- "data type cannot be determined from "
- "type object");
- return NULL;
- }
- new = PyArray_DescrNewFromType(PyArray_VOID);
+ /* Otherwise --- type is a sub-type of an array scalar
+ currently only VOID allows it -- use it as the type-object.
+ */
+ /* look for a dtypedescr attribute */
+ if (!PyType_IsSubtype((PyTypeObject *)type, &PyVoidArrType_Type)) {
+ PyErr_SetString(PyExc_TypeError,
+ "data type cannot be determined from "
+ "type object");
+ return NULL;
+ }
+ new = PyArray_DescrNewFromType(PyArray_VOID);
- conv = _arraydescr_fromobj(type);
- if (conv) {
- new->fields = conv->fields;
- Py_INCREF(new->fields);
+ conv = _arraydescr_fromobj(type);
+ if (conv) {
+ new->fields = conv->fields;
+ Py_INCREF(new->fields);
new->names = conv->names;
Py_INCREF(new->names);
- new->elsize = conv->elsize;
- new->subarray = conv->subarray;
- conv->subarray = NULL;
- Py_DECREF(conv);
- }
+ new->elsize = conv->elsize;
+ new->subarray = conv->subarray;
+ conv->subarray = NULL;
+ Py_DECREF(conv);
+ }
Py_DECREF(new->typeobj);
new->typeobj = (PyTypeObject *)type;
Py_INCREF(type);
- return new;
+ return new;
}
/*OBJECT_API
@@ -2540,7 +2541,7 @@
"Fields must be a dictionary");
return NULL;
}
- tup = PyObject_CallMethod(_numpy_internal, "_makenames_list", "O", fields);
+ tup = PyObject_CallMethod(_numpy_internal, "_makenames_list", "O", fields);
if (tup == NULL) return NULL;
ret = PyTuple_GET_ITEM(tup, 0);
ret = PySequence_Tuple(ret);
@@ -2555,41 +2556,41 @@
static PyArray_Descr *
PyArray_DescrFromScalar(PyObject *sc)
{
- int type_num;
- PyArray_Descr *descr;
+ int type_num;
+ PyArray_Descr *descr;
- if (PyArray_IsScalar(sc, Void)) {
- descr = ((PyVoidScalarObject *)sc)->descr;
- Py_INCREF(descr);
- return descr;
- }
+ if (PyArray_IsScalar(sc, Void)) {
+ descr = ((PyVoidScalarObject *)sc)->descr;
+ Py_INCREF(descr);
+ return descr;
+ }
descr = PyArray_DescrFromTypeObject((PyObject *)sc->ob_type);
if (descr->elsize == 0) {
- PyArray_DESCR_REPLACE(descr);
+ PyArray_DESCR_REPLACE(descr);
type_num = descr->type_num;
- if (type_num == PyArray_STRING)
- descr->elsize = PyString_GET_SIZE(sc);
- else if (type_num == PyArray_UNICODE) {
- descr->elsize = PyUnicode_GET_DATA_SIZE(sc);
+ if (type_num == PyArray_STRING)
+ descr->elsize = PyString_GET_SIZE(sc);
+ else if (type_num == PyArray_UNICODE) {
+ descr->elsize = PyUnicode_GET_DATA_SIZE(sc);
#ifndef Py_UNICODE_WIDE
- descr->elsize <<= 1;
+ descr->elsize <<= 1;
#endif
- }
- else {
- descr->elsize =
- ((PyVoidScalarObject *)sc)->ob_size;
- descr->fields = PyObject_GetAttrString(sc, "fields");
- if (!descr->fields || !PyDict_Check(descr->fields) ||
- (descr->fields == Py_None)) {
- Py_XDECREF(descr->fields);
- descr->fields = NULL;
- }
+ }
+ else {
+ descr->elsize =
+ ((PyVoidScalarObject *)sc)->ob_size;
+ descr->fields = PyObject_GetAttrString(sc, "fields");
+ if (!descr->fields || !PyDict_Check(descr->fields) ||
+ (descr->fields == Py_None)) {
+ Py_XDECREF(descr->fields);
+ descr->fields = NULL;
+ }
if (descr->fields)
descr->names = PyArray_FieldNames(descr->fields);
- PyErr_Clear();
- }
+ PyErr_Clear();
+ }
}
- return descr;
+ return descr;
}
/* New reference */
@@ -2599,13 +2600,13 @@
static PyObject *
PyArray_TypeObjectFromType(int type)
{
- PyArray_Descr *descr;
- PyObject *obj;
+ PyArray_Descr *descr;
+ PyObject *obj;
- descr = PyArray_DescrFromType(type);
- if (descr == NULL) return NULL;
- obj = (PyObject *)descr->typeobj;
- Py_INCREF(obj);
- Py_DECREF(descr);
- return obj;
+ descr = PyArray_DescrFromType(type);
+ if (descr == NULL) return NULL;
+ obj = (PyObject *)descr->typeobj;
+ Py_INCREF(obj);
+ Py_DECREF(descr);
+ return obj;
}
More information about the Numpy-svn
mailing list