From 823aed7b2324feb1d8e4bd52504e8bc86309126a Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Sun, 13 Apr 2008 06:05:28 +0000 Subject: Reindent. Needs style cleanup too. Small cleanup of MyPyFloat_AsDouble. --- numpy/core/src/arraytypes.inc.src | 3085 ++++++++++++++++++------------------- 1 file changed, 1542 insertions(+), 1543 deletions(-) (limited to 'numpy/core/src') diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src index c1349b216..dda5a12be 100644 --- a/numpy/core/src/arraytypes.inc.src +++ b/numpy/core/src/arraytypes.inc.src @@ -3,102 +3,102 @@ static longlong -MyPyLong_AsLongLong(PyObject *vv) +MyPyLong_AsLongLong(PyObject *obj) { - longlong ret; + longlong ret; - if (!PyLong_Check(vv)) { - PyObject *mylong; - mylong = PyNumber_Long(vv); - if (mylong == NULL) { - return (longlong) -1; - } - vv = mylong; - } - else { - Py_INCREF(vv); + if (!PyLong_Check(obj)) { + PyObject *mylong; + mylong = PyNumber_Long(obj); + if (mylong == NULL) { + return (longlong) -1; } + obj = mylong; + } + else { + Py_INCREF(obj); + } - ret = PyLong_AsLongLong(vv); - Py_DECREF(vv); - return ret; + ret = PyLong_AsLongLong(obj); + Py_DECREF(obj); + return ret; } static ulong -MyPyLong_AsUnsignedLong(PyObject *vv) +MyPyLong_AsUnsignedLong(PyObject *obj) { - ulong ret; + ulong ret; - if (!PyLong_Check(vv)) { - PyObject *mylong; - mylong = PyNumber_Long(vv); - if (mylong == NULL) { - return (ulong) -1; - } - vv = mylong; - } - else { - Py_INCREF(vv); + if (!PyLong_Check(obj)) { + PyObject *mylong; + mylong = PyNumber_Long(obj); + if (mylong == NULL) { + return (ulong) -1; } + obj = mylong; + } + else { + Py_INCREF(obj); + } - ret = PyLong_AsUnsignedLong(vv); - if (PyErr_Occurred()) { - PyErr_Clear(); - ret = (ulong) PyLong_AsLong(vv); - } - Py_DECREF(vv); - return ret; + ret = PyLong_AsUnsignedLong(obj); + if (PyErr_Occurred()) { + PyErr_Clear(); + ret = (ulong) PyLong_AsLong(obj); + } + Py_DECREF(obj); + return ret; } static ulonglong -MyPyLong_AsUnsignedLongLong(PyObject *vv) +MyPyLong_AsUnsignedLongLong(PyObject *obj) { - ulonglong ret; + ulonglong ret; - if (!PyLong_Check(vv)) { - PyObject *mylong; - mylong = PyNumber_Long(vv); - if (mylong == NULL) { - return (ulonglong) -1; - } - vv = mylong; - } - else { - Py_INCREF(vv); + if (!PyLong_Check(obj)) { + PyObject *mylong; + mylong = PyNumber_Long(obj); + if (mylong == NULL) { + return (ulonglong) -1; } + obj = mylong; + } + else { + Py_INCREF(obj); + } - ret = PyLong_AsUnsignedLongLong(vv); - if (PyErr_Occurred()) { - PyErr_Clear(); - ret = (ulonglong) PyLong_AsLongLong(vv); - } - Py_DECREF(vv); - return ret; + ret = PyLong_AsUnsignedLongLong(obj); + if (PyErr_Occurred()) { + PyErr_Clear(); + ret = (ulonglong) PyLong_AsLongLong(obj); + } + Py_DECREF(obj); + return ret; } static double _getNAN(void) { #ifdef NAN - return NAN; + return NAN; #else - static double nan=0; - - if (nan == 0) { - double mul = 1e100; - double tmp = 0.0; - double pinf=0; - pinf = mul; - for (;;) { - pinf *= mul; - if (pinf == tmp) break; - tmp = pinf; - } - nan = pinf / pinf; - } - return nan; + static double nan=0; + + if (nan == 0) { + double mul = 1e100; + double tmp = 0.0; + double pinf=0; + pinf = mul; + for (;;) { + pinf *= mul; + if (pinf == tmp) break; + tmp = pinf; + } + nan = pinf / pinf; + } + return nan; #endif } @@ -106,21 +106,20 @@ _getNAN(void) { static double MyPyFloat_AsDouble(PyObject *obj) { - PyObject *tmp; - double d; - if (PyString_Check(obj)) { - tmp = PyFloat_FromString(obj, 0); - if (tmp) { - d = PyFloat_AsDouble(tmp); - Py_DECREF(tmp); - return d; - } - else { - return _getNAN(); - } + if (PyString_Check(obj)) { + PyObject *tmp = PyFloat_FromString(obj, 0); + if (tmp) { + double d = PyFloat_AsDouble(tmp); + Py_DECREF(tmp); + return d; } - if (obj == Py_None) return _getNAN(); - return PyFloat_AsDouble(obj); + else { + return _getNAN(); + } + } + if (obj == Py_None) + return _getNAN(); + return PyFloat_AsDouble(obj); } @@ -138,46 +137,46 @@ MyPyFloat_AsDouble(PyObject *obj) static PyObject * @TYP@_getitem(char *ip, PyArrayObject *ap) { - @typ@ t1; + @typ@ t1; - if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { - t1 = *((@typ@ *)ip); - return @func1@((@typ1@)t1); - } - else { - ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap), - ap); - return @func1@((@typ1@)t1); - } + if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { + t1 = *((@typ@ *)ip); + return @func1@((@typ1@)t1); + } + else { + ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap), + ap); + return @func1@((@typ1@)t1); + } } static int @TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) { - @typ@ temp; /* ensures alignment */ + @typ@ temp; /* ensures alignment */ - if (PyArray_IsScalar(op, @kind@)) { - temp = ((Py@kind@ScalarObject *)op)->obval; - } - else { - temp = (@typ@)@func2@(op); - } - if (PyErr_Occurred()) { - if (PySequence_Check(op)) { - PyErr_Clear(); - PyErr_SetString(PyExc_ValueError, "setting an array" \ - " element with a sequence."); - } - return -1; - } - if (ap == NULL || PyArray_ISBEHAVED(ap)) - *((@typ@ *)ov)=temp; - else { - ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), - ap); + if (PyArray_IsScalar(op, @kind@)) { + temp = ((Py@kind@ScalarObject *)op)->obval; + } + else { + temp = (@typ@)@func2@(op); + } + if (PyErr_Occurred()) { + if (PySequence_Check(op)) { + PyErr_Clear(); + PyErr_SetString(PyExc_ValueError, "setting an array" \ + " element with a sequence."); } + return -1; + } + if (ap == NULL || PyArray_ISBEHAVED(ap)) + *((@typ@ *)ov)=temp; + else { + ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), + ap); + } - return 0; + return 0; } /**end repeat**/ @@ -191,19 +190,19 @@ static int static PyObject * @TYP@_getitem(char *ip, PyArrayObject *ap) { - @typ@ t1, t2; + @typ@ t1, t2; - if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { - return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], - (double)((@typ@ *)ip)[1]); - } - else { - 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); - } + if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { + return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], + (double)((@typ@ *)ip)[1]); + } + else { + 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); + } } /**end repeat**/ @@ -216,75 +215,75 @@ static PyObject * static int @TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) { - Py_complex oop; - PyObject *op2; - c@typ@ temp; - int rsize; + Py_complex oop; + PyObject *op2; + c@typ@ temp; + 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 { - op2 = op; Py_INCREF(op); - } - if (op2 == Py_None) { - oop.real = oop.imag = _getNAN(); - } - else { - oop = PyComplex_AsCComplex (op2); - } - Py_DECREF(op2); - if (PyErr_Occurred()) return -1; - temp.real = (@typ@) oop.real; - temp.imag = (@typ@) oop.imag; + 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 { + op2 = op; Py_INCREF(op); + } + if (op2 == Py_None) { + oop.real = oop.imag = _getNAN(); } else { - temp = ((Py@kind@ScalarObject *)op)->obval; + oop = PyComplex_AsCComplex (op2); } + Py_DECREF(op2); + if (PyErr_Occurred()) return -1; + temp.real = (@typ@) oop.real; + temp.imag = (@typ@) oop.imag; + } + else { + temp = ((Py@kind@ScalarObject *)op)->obval; + } - memcpy(ov, &temp, ap->descr->elsize); - if (!PyArray_ISNOTSWAPPED(ap)) - byte_swap_vector(ov, 2, sizeof(@typ@)); + 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)); - return 0; + rsize = sizeof(@typ@); + copy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap)); + return 0; } /**end repeat**/ static PyObject * LONGDOUBLE_getitem(char *ip, PyArrayObject *ap) { - return PyArray_Scalar(ip, ap->descr, NULL); + return PyArray_Scalar(ip, ap->descr, NULL); } static int LONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) { - longdouble temp; /* ensures alignment */ + longdouble temp; /* ensures alignment */ - if (PyArray_IsScalar(op, LongDouble)) { - temp = ((PyLongDoubleScalarObject *)op)->obval; - } - else { - temp = (longdouble) MyPyFloat_AsDouble(op); - } - if (PyErr_Occurred()) return -1; - if (ap == NULL || PyArray_ISBEHAVED(ap)) - *((longdouble *)ov)=temp; - else { - copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0, - !PyArray_ISNOTSWAPPED(ap)); - } - return 0; + if (PyArray_IsScalar(op, LongDouble)) { + temp = ((PyLongDoubleScalarObject *)op)->obval; + } + else { + temp = (longdouble) MyPyFloat_AsDouble(op); + } + if (PyErr_Occurred()) return -1; + if (ap == NULL || PyArray_ISBEHAVED(ap)) + *((longdouble *)ov)=temp; + else { + copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0, + !PyArray_ISNOTSWAPPED(ap)); + } + return 0; } static PyObject * CLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) { - return PyArray_Scalar(ip, ap->descr, NULL); + return PyArray_Scalar(ip, ap->descr, NULL); } @@ -292,102 +291,102 @@ CLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) static PyObject * UNICODE_getitem(char *ip, PyArrayObject *ap) { - 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); - } + 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; + } + 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; - } -#endif + /* 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; + return obj; } static int UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) { - PyObject *temp; - Py_UNICODE *ptr; - int datalen; + PyObject *temp; + Py_UNICODE *ptr; + int datalen; #ifndef Py_UNICODE_WIDE - char *buffer; + char *buffer; #endif - if (!PyString_Check(op) && !PyUnicode_Check(op) && + if (!PyString_Check(op) && !PyUnicode_Check(op) && PySequence_Check(op) && PySequence_Size(op) > 0) { - PyErr_SetString(PyExc_ValueError, - "setting an array element with a sequence"); - return -1; - } - /* Sequence_Size might have returned an error */ - if (PyErr_Occurred()) PyErr_Clear(); - 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); + PyErr_SetString(PyExc_ValueError, + "setting an array element with a sequence"); + return -1; + } + /* Sequence_Size might have returned an error */ + if (PyErr_Occurred()) PyErr_Clear(); + 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; - 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); + 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); + } #endif - /* Fill in the rest of the space with 0 */ - if (ap->descr->elsize > datalen) { - memset(ov + datalen, 0, (ap->descr->elsize - datalen)); - } + /* 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; + 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 @@ -396,45 +395,45 @@ UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) static PyObject * STRING_getitem(char *ip, PyArrayObject *ap) { - /* Will eliminate NULLs at the end */ - char *ptr; - int size = ap->descr->elsize; + /* Will eliminate NULLs at the end */ + char *ptr; + int size = ap->descr->elsize; - ptr = ip + size-1; - while (*ptr-- == '\0' && size > 0) size--; - return PyString_FromStringAndSize(ip,size); + ptr = ip + size-1; + while (*ptr-- == '\0' && size > 0) size--; + return PyString_FromStringAndSize(ip,size); } static int STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) { - char *ptr; - Py_ssize_t len; - PyObject *temp=NULL; + char *ptr; + Py_ssize_t len; + PyObject *temp=NULL; - if (!PyString_Check(op) && !PyUnicode_Check(op) && + if (!PyString_Check(op) && !PyUnicode_Check(op) && PySequence_Check(op) && PySequence_Size(op) > 0) { - PyErr_SetString(PyExc_ValueError, - "setting an array element with a sequence"); - return -1; - } - /* Sequence_Size might have returned an error */ - if (PyErr_Occurred()) PyErr_Clear(); - if ((temp = PyObject_Str(op)) == NULL) return -1; + PyErr_SetString(PyExc_ValueError, + "setting an array element with a sequence"); + return -1; + } + /* Sequence_Size might have returned an error */ + if (PyErr_Occurred()) PyErr_Clear(); + if ((temp = PyObject_Str(op)) == NULL) return -1; - if (PyString_AsStringAndSize(temp, &ptr, &len) == -1) { - Py_DECREF(temp); - return -1; - } - memcpy(ov, ptr, MIN(ap->descr->elsize,len)); - /* If string lenth is smaller than room in array - Then fill the rest of the element size - with NULL */ - if (ap->descr->elsize > len) { - memset(ov + len, 0, (ap->descr->elsize - len)); - } + if (PyString_AsStringAndSize(temp, &ptr, &len) == -1) { Py_DECREF(temp); - return 0; + return -1; + } + memcpy(ov, ptr, MIN(ap->descr->elsize,len)); + /* If string lenth is smaller than room in array + Then fill the rest of the element size + with NULL */ + if (ap->descr->elsize > len) { + memset(ov + len, 0, (ap->descr->elsize - len)); + } + Py_DECREF(temp); + return 0; } /* OBJECT */ @@ -442,38 +441,38 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) static PyObject * OBJECT_getitem(char *ip, PyArrayObject *ap) { - if (*(PyObject **)ip == NULL) { - Py_INCREF(Py_None); - return Py_None; - } - if (!ap || PyArray_ISALIGNED(ap)) { - Py_INCREF(*(PyObject **)ip); - return *(PyObject **)ip; - } - else { - PyObject **obj; - obj = (PyObject **)ip; - Py_INCREF(*obj); - return *obj; - } + if (*(PyObject **)ip == NULL) { + Py_INCREF(Py_None); + return Py_None; + } + if (!ap || PyArray_ISALIGNED(ap)) { + Py_INCREF(*(PyObject **)ip); + return *(PyObject **)ip; + } + else { + PyObject **obj; + obj = (PyObject **)ip; + Py_INCREF(*obj); + return *obj; + } } static int OBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) { - Py_INCREF(op); - if (!ap || PyArray_ISALIGNED(ap)) { - Py_XDECREF(*(PyObject **)ov); - *(PyObject **)ov = op; - } - else { - PyObject **obj; - obj = (PyObject **)ov; - Py_XDECREF(*obj); - memcpy(ov, &op, sizeof(PyObject *)); - } - return PyErr_Occurred() ? -1:0; + Py_INCREF(op); + if (!ap || PyArray_ISALIGNED(ap)) { + Py_XDECREF(*(PyObject **)ov); + *(PyObject **)ov = op; + } + else { + PyObject **obj; + obj = (PyObject **)ov; + Py_XDECREF(*obj); + memcpy(ov, &op, sizeof(PyObject *)); + } + return PyErr_Occurred() ? -1:0; } /* VOID */ @@ -481,98 +480,98 @@ OBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) static PyObject * VOID_getitem(char *ip, PyArrayObject *ap) { - PyObject *u=NULL; - PyArray_Descr* descr; - int itemsize; + PyObject *u=NULL; + 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; - - /* 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; ifields, 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; - - PyTuple_SET_ITEM(ret, i, \ - new->f->getitem(ip+offset, ap)); - ap->flags = 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*/ + names = descr->names; + if (!names) goto finish; + n = PyTuple_GET_SIZE(names); + ret = PyTuple_New(n); + savedflags = ap->flags; + for (i=0; ifields, key); + if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, + &title)) { + Py_DECREF(ret); 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; - } - 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; - } - - finish: - if (PyDataType_FLAGCHK(descr, NPY_ITEM_HASOBJECT) || - PyDataType_FLAGCHK(descr, NPY_ITEM_IS_POINTER)) { - PyErr_SetString(PyExc_ValueError, - "tried to get void-array with object" - " members as buffer."); 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; + } - 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; + 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; + } - fail: +finish: + if (PyDataType_FLAGCHK(descr, NPY_ITEM_HASOBJECT) || + PyDataType_FLAGCHK(descr, NPY_ITEM_IS_POINTER)) { + 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; + + /* default is to return buffer object pointing to current item */ + /* a view of it */ + return u; + +fail: + return NULL; } @@ -582,103 +581,103 @@ static int PyArray_CopyObject(PyArrayObject *, PyObject *); static int VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) { - PyArray_Descr* descr; - int itemsize=ap->descr->elsize; - int res; + PyArray_Descr* descr; + int itemsize=ap->descr->elsize; + 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*/ - 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; ifields, 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; - } + 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; ifields, key); + if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, + &title)) { 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; - } - 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; + 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; + } - /* Default is to use buffer interface to set item */ - { - const void *buffer; - Py_ssize_t buflen; - if (PyDataType_FLAGCHK(descr, NPY_ITEM_HASOBJECT) || - PyDataType_FLAGCHK(descr, NPY_ITEM_IS_POINTER)) { - 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, NPY_MIN(buflen, itemsize)); - if (itemsize > buflen) { - memset(ip+buflen, 0, (itemsize-buflen)); - } + 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; + } + + /* Default is to use buffer interface to set item */ + { + const void *buffer; + Py_ssize_t buflen; + if (PyDataType_FLAGCHK(descr, NPY_ITEM_HASOBJECT) || + PyDataType_FLAGCHK(descr, NPY_ITEM_IS_POINTER)) { + 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, NPY_MIN(buflen, itemsize)); + if (itemsize > buflen) { + memset(ip+buflen, 0, (itemsize-buflen)); } - return 0; + } + return 0; - fail: - return -1; +fail: + return -1; } @@ -698,10 +697,10 @@ static void @from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n, PyArrayObject *aip, PyArrayObject *aop) { - while (n--) { - *op++ = (@totyp@)*ip; - @incr@; - } + while (n--) { + *op++ = (@totyp@)*ip; + @incr@; + } } /**end repeat**/ @@ -713,9 +712,9 @@ static void @from@_to_BOOL(register @fromtyp@ *ip, register Bool *op, register intp n, PyArrayObject *aip, PyArrayObject *aop) { - while (n--) { - *op++ = (Bool)(*ip++ != FALSE); - } + while (n--) { + *op++ = (Bool)(*ip++ != FALSE); + } } /**end repeat**/ @@ -727,10 +726,10 @@ static void @from@_to_BOOL(register @fromtyp@ *ip, register Bool *op, register intp n, 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**/ @@ -742,9 +741,9 @@ static void BOOL_to_@to@(register Bool *ip, register @totyp@ *op, register intp n, PyArrayObject *aip, PyArrayObject *aop) { - while (n--) { - *op++ = (@totyp@)(*ip++ != FALSE); - } + while (n--) { + *op++ = (@totyp@)(*ip++ != FALSE); + } } /**end repeat**/ @@ -759,10 +758,10 @@ static void @from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n, PyArrayObject *aip, PyArrayObject *aop) { - while (n--) { - *op++ = (@totyp@)*ip++; - *op++ = 0.0; - } + while (n--) { + *op++ = (@totyp@)*ip++; + *op++ = 0.0; + } } /**end repeat**/ @@ -778,10 +777,10 @@ static void @from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n, PyArrayObject *aip, PyArrayObject *aop) { - n <<= 1; - while (n--) { - *op++ = (@totyp@)*ip++; - } + n <<= 1; + while (n--) { + *op++ = (@totyp@)*ip++; + } } /**end repeat**/ @@ -796,12 +795,12 @@ static void @from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip, PyArrayObject *aop) { - register intp i; - int skip=@skip@; - for(i=0;idescr->elsize; - int oskip=@oskip@; - for(i=0; idescr->elsize; + int oskip=@oskip@; + for(i=0; idescr->elsize; - for(i=0; idescr->elsize; + for(i=0; idescr->elsize; - if (dstride == itemsize && sstride == itemsize) { - memcpy(dst, src, itemsize * n); - } - else { - _unaligned_strided_byte_copy(dst, dstride, src, sstride, n, itemsize); - } + if (src != NULL && arr != NULL) { + int itemsize = arr->descr->elsize; + if (dstride == itemsize && sstride == itemsize) { + memcpy(dst, src, itemsize * n); } - return; + else { + _unaligned_strided_byte_copy(dst, dstride, src, sstride, n, itemsize); + } + } + return; } /* */ @@ -1326,95 +1325,95 @@ static void VOID_copyswapn (char *dst, intp dstride, char *src, intp sstride, intp n, int swap, PyArrayObject *arr) { - if (arr == NULL) return; - if (PyArray_HASFIELDS(arr)) { - PyObject *key, *value, *title=NULL; - PyArray_Descr *new, *descr; - int offset; - Py_ssize_t 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; - } - arr->descr = new; - new->f->copyswapn(dst+offset, dstride, - (src != NULL ? src+offset : NULL), - sstride, n, swap, arr); - } - arr->descr = descr; - return; - } - if (swap && arr->descr->subarray != NULL) { - PyArray_Descr *descr, *new; - npy_intp num; - npy_intp i; - int subitemsize; - char *dstptr, *srcptr; - descr = arr->descr; - new = descr->subarray->base; - arr->descr = new; - dstptr = dst; - srcptr = src; - subitemsize = new->elsize; - num = descr->elsize / subitemsize; - for (i=0; if->copyswapn(dstptr, subitemsize, srcptr, - subitemsize, num, swap, arr); - dstptr += dstride; - if (srcptr) srcptr += sstride; - } - arr->descr = descr; - return; - } - if (src != NULL) { - memcpy(dst, src, arr->descr->elsize * n); - } + if (arr == NULL) return; + if (PyArray_HASFIELDS(arr)) { + PyObject *key, *value, *title=NULL; + PyArray_Descr *new, *descr; + int offset; + Py_ssize_t 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; + } + arr->descr = new; + new->f->copyswapn(dst+offset, dstride, + (src != NULL ? src+offset : NULL), + sstride, n, swap, arr); + } + arr->descr = descr; return; + } + if (swap && arr->descr->subarray != NULL) { + PyArray_Descr *descr, *new; + npy_intp num; + npy_intp i; + int subitemsize; + char *dstptr, *srcptr; + descr = arr->descr; + new = descr->subarray->base; + arr->descr = new; + dstptr = dst; + srcptr = src; + subitemsize = new->elsize; + num = descr->elsize / subitemsize; + for (i=0; if->copyswapn(dstptr, subitemsize, srcptr, + subitemsize, num, swap, arr); + dstptr += dstride; + if (srcptr) srcptr += sstride; + } + arr->descr = descr; + return; + } + if (src != NULL) { + memcpy(dst, src, arr->descr->elsize * n); + } + return; } static void VOID_copyswap (char *dst, char *src, int swap, PyArrayObject *arr) { - if (arr==NULL) return; - if (PyArray_HASFIELDS(arr)) { - PyObject *key, *value, *title=NULL; - PyArray_Descr *new, *descr; - int offset; - Py_ssize_t 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; - } - arr->descr = new; - new->f->copyswap(dst+offset, - (src != NULL ? src+offset : NULL), - swap, arr); - } - arr->descr = descr; - return; - } - if (swap && arr->descr->subarray != NULL) { - PyArray_Descr *descr, *new; - npy_intp num; - int itemsize; - descr = arr->descr; - new = descr->subarray->base; - arr->descr = new; - itemsize = new->elsize; - num = descr->elsize / itemsize; - new->f->copyswapn(dst, itemsize, src, - itemsize, num, swap, arr); - arr->descr = descr; - return; - } - if (src != NULL) { - memcpy(dst, src, arr->descr->elsize); - } + if (arr==NULL) return; + if (PyArray_HASFIELDS(arr)) { + PyObject *key, *value, *title=NULL; + PyArray_Descr *new, *descr; + int offset; + Py_ssize_t 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; + } + arr->descr = new; + new->f->copyswap(dst+offset, + (src != NULL ? src+offset : NULL), + swap, arr); + } + arr->descr = descr; + return; + } + if (swap && arr->descr->subarray != NULL) { + PyArray_Descr *descr, *new; + npy_intp num; + int itemsize; + descr = arr->descr; + new = descr->subarray->base; + arr->descr = new; + itemsize = new->elsize; + num = descr->elsize / itemsize; + new->f->copyswapn(dst, itemsize, src, + itemsize, num, swap, arr); + arr->descr = descr; return; + } + if (src != NULL) { + memcpy(dst, src, arr->descr->elsize); + } + return; } @@ -1422,59 +1421,59 @@ static void UNICODE_copyswapn (char *dst, intp dstride, char *src, intp sstride, intp n, int swap, PyArrayObject *arr) { - int itemsize; - if (arr==NULL) return; - itemsize = arr->descr->elsize; - 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 += 2; - } + int itemsize; + if (arr==NULL) return; + itemsize = arr->descr->elsize; + 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 += 2; } + } } 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 += 2; - } + 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 += 2; } + } } @@ -1487,15 +1486,15 @@ UNICODE_copyswap (char *dst, char *src, int swap, PyArrayObject *arr) static Bool @fname@_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**/ @@ -1506,15 +1505,15 @@ static Bool static Bool @fname@_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**/ @@ -1525,33 +1524,33 @@ static Bool static Bool Py_STRING_ISSPACE(char ch) { - char white[] = WHITESPACE; - int j; - Bool space=FALSE; - for (j=0; jdescr->elsize; - int i; - Bool nonz = FALSE; + int len = ap->descr->elsize; + int i; + Bool nonz = FALSE; - for (i=0; idescr->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)) || \ + 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; + 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; idescr; - savedflags = ap->flags; - while (PyDict_Next(descr->fields, &pos, &key, &value)) { - 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; - if (new->f->nonzero(ip+offset, ap)) { - nonz=TRUE; - break; - } - } - ap->descr = descr; - ap->flags = savedflags; - return nonz; - } - len = ap->descr->elsize; - for (i=0; idescr; + savedflags = ap->flags; + while (PyDict_Next(descr->fields, &pos, &key, &value)) { + 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; + if (new->f->nonzero(ip+offset, ap)) { + nonz=TRUE; + break; + } } + ap->descr = descr; + ap->flags = savedflags; return nonz; + } + len = ap->descr->elsize; + for (i=0; idescr->elsize; - register PyArray_UCS4 c1, c2; + register int itemsize=ap->descr->elsize; + register PyArray_UCS4 c1, c2; - if (itemsize < 0) return 0; + if (itemsize < 0) return 0; - while(itemsize-- > 0) { - c1 = *ip1++; - c2 = *ip2++; + while(itemsize-- > 0) { + c1 = *ip1++; + c2 = *ip2++; - if (c1 != c2) - return (c1 < c2) ? -1 : 1; - } - return 0; + if (c1 != c2) + return (c1 < c2) ? -1 : 1; + } + return 0; } /* If fields are defined, then compare on first field and if equal @@ -1751,63 +1750,63 @@ UNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, static int VOID_compare(char *ip1, char *ip2, PyArrayObject *ap) { - PyArray_Descr *descr, *new; - PyObject *names, *key; - PyObject *tup, *title; - char *nip1, *nip2; - int i, offset, res=0; - - if (!PyArray_HASFIELDS(ap)) - return STRING_compare(ip1, ip2, ap); - - descr = ap->descr; - /* Compare on the first-field. If equal, then - compare on the second-field, etc. - */ - names = descr->names; - for (i=0; ifields, key); - if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, - &title)) { - goto finish; - } - ap->descr = new; - nip1 = ip1+offset; - nip2 = ip2+offset; - if (new->alignment > 1) { - if (((intp)(nip1) % new->alignment) != 0) { - /* create buffer and copy */ - nip1 = _pya_malloc(new->elsize); - if (nip1 == NULL) goto finish; - memcpy(nip1, ip1+offset, new->elsize); - } - if (((intp)(nip2) % new->alignment) != 0) { - /* copy data to a buffer */ - nip2 = _pya_malloc(new->elsize); - if (nip2 == NULL) { - if (nip1 != ip1+offset) - _pya_free(nip1); - goto finish; - } - memcpy(nip2, ip2+offset, new->elsize); - } - } - res = new->f->compare(nip1, nip2, ap); - if (new->alignment > 1) { - if (nip1 != ip1+offset) { - _pya_free(nip1); - } - if (nip2 != ip2+offset) { - _pya_free(nip2); - } - } - if (res != 0) break; - } + PyArray_Descr *descr, *new; + PyObject *names, *key; + PyObject *tup, *title; + char *nip1, *nip2; + int i, offset, res=0; + + if (!PyArray_HASFIELDS(ap)) + return STRING_compare(ip1, ip2, ap); + + descr = ap->descr; + /* Compare on the first-field. If equal, then + compare on the second-field, etc. + */ + names = descr->names; + for (i=0; ifields, key); + if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, + &title)) { + goto finish; + } + ap->descr = new; + nip1 = ip1+offset; + nip2 = ip2+offset; + if (new->alignment > 1) { + if (((intp)(nip1) % new->alignment) != 0) { + /* create buffer and copy */ + nip1 = _pya_malloc(new->elsize); + if (nip1 == NULL) goto finish; + memcpy(nip1, ip1+offset, new->elsize); + } + if (((intp)(nip2) % new->alignment) != 0) { + /* copy data to a buffer */ + nip2 = _pya_malloc(new->elsize); + if (nip2 == NULL) { + if (nip1 != ip1+offset) + _pya_free(nip1); + goto finish; + } + memcpy(nip2, ip2+offset, new->elsize); + } + } + res = new->f->compare(nip1, nip2, ap); + if (new->alignment > 1) { + if (nip1 != ip1+offset) { + _pya_free(nip1); + } + if (nip2 != ip2+offset) { + _pya_free(nip2); + } + } + if (res != 0) break; + } - finish: - ap->descr = descr; - return res; +finish: + ap->descr = descr; + return res; } /****************** argfunc **********************************/ @@ -1822,17 +1821,17 @@ VOID_compare(char *ip1, char *ip2, PyArrayObject *ap) static int @fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) { - register intp i; - @type@ mp=*ip; - *max_ind=0; - for (i=1; i mp) { - mp = *ip; - *max_ind = i; - } + register intp i; + @type@ mp=*ip; + *max_ind=0; + for (i=1; i mp) { + mp = *ip; + *max_ind = i; } - return 0; + } + return 0; } /**end repeat**/ @@ -1840,21 +1839,21 @@ static int static int OBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) { - register intp i; - PyObject *mp=ip[0]; *max_ind=0; - i = 1; - while(i 0) { - mp = *ip; - *max_ind=i; - } + register intp i; + PyObject *mp=ip[0]; *max_ind=0; + i = 1; + while(i 0) { + mp = *ip; + *max_ind=i; } - return 0; + } + return 0; } /**begin repeat @@ -1866,22 +1865,22 @@ OBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) static int @fname@_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 0) { - memcpy(mp, ip, elsize); - *max_ind=i; - } + 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 0) { + memcpy(mp, ip, elsize); + *max_ind=i; } - _pya_free(mp); - return 0; + } + _pya_free(mp); + return 0; } /**end repeat**/ @@ -1892,15 +1891,15 @@ static void 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;ireal; - 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; ireal = start.real + i*delta.real; - buffer->imag = start.imag + i*delta.imag; - } + 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; ireal = start.real + i*delta.real; + buffer->imag = start.imag + i*delta.imag; + } } /**end repeat**/ @@ -2050,13 +2049,13 @@ static void static void OBJECT_fillwithscalar(PyObject **buffer, intp length, PyObject **value, void *ignored) { - intp i; - PyObject *val = *value; - for (i=0; i max_val) { - out[i] = max_val; - } - } - return; - } + register npy_intp i; + @type@ max_val=0, min_val=0; + if (max != NULL) + max_val = *max; + if (min != NULL) + min_val = *min; + + if (max == NULL) { for (i = 0; i < ni; i++) { - if (in[i] < min_val) { - out[i] = min_val; - } else if (in[i] > max_val) { - out[i] = max_val; - } + if (in[i] < min_val) { + out[i] = min_val; + } } + return; + } + if (min == NULL) { + for (i = 0; i < ni; i++) { + if (in[i] > max_val) { + out[i] = max_val; + } + } return; + } + + for (i = 0; i < ni; i++) { + if (in[i] < min_val) { + out[i] = min_val; + } else if (in[i] > max_val) { + out[i] = max_val; + } + } + + return; } /**end repeat**/ @@ -2143,43 +2142,43 @@ static void static void @name@_fastclip(@type@ *in, intp ni, @type@ *min, @type@ *max, @type@ *out) { - register npy_intp i; - @type@ max_val, min_val; - - min_val = *min; + register npy_intp i; + @type@ max_val, min_val; + + min_val = *min; + max_val = *max; + + if (max != NULL) max_val = *max; + if (min != NULL) + min_val = *min; - if (max != NULL) - max_val = *max; - if (min != NULL) - min_val = *min; - - if (max == NULL) { - for (i = 0; i < ni; i++) { - if (PyArray_CLT(in[i],min_val)) { - out[i] = min_val; - } - } - return; - } - - if (min == NULL) { - for (i = 0; i < ni; i++) { - if (PyArray_CGT(in[i], max_val)) { - out[i] = max_val; - } - } - return; - } + if (max == NULL) { + for (i = 0; i < ni; i++) { + if (PyArray_CLT(in[i],min_val)) { + out[i] = min_val; + } + } + return; + } + if (min == NULL) { for (i = 0; i < ni; i++) { - if (PyArray_CLT(in[i], min_val)) { - out[i] = min_val; - } else if (PyArray_CGT(in[i], max_val)) { - out[i] = max_val; - } + if (PyArray_CGT(in[i], max_val)) { + out[i] = max_val; + } } return; + } + + for (i = 0; i < ni; i++) { + if (PyArray_CLT(in[i], min_val)) { + out[i] = min_val; + } else if (PyArray_CGT(in[i], max_val)) { + out[i] = max_val; + } + } + return; } /**end repeat**/ @@ -2197,25 +2196,25 @@ static void static void @name@_fastputmask(@type@ *in, Bool *mask, intp ni, @type@ *vals, intp nv) { - register npy_intp i; - @type@ s_val; + register npy_intp i; + @type@ s_val; - if (nv == 1) { - s_val = *vals; - for (i = 0; i < ni; i++) { - if (mask[i]) { - in[i] = s_val; - } - } + if (nv == 1) { + s_val = *vals; + for (i = 0; i < ni; i++) { + if (mask[i]) { + in[i] = s_val; + } } - else { - for (i = 0; i < ni; i++) { - if (mask[i]) { - in[i] = vals[i%nv]; - } - } + } + else { + for (i = 0; i < ni; i++) { + if (mask[i]) { + in[i] = vals[i%nv]; + } } - return; + } + return; } /**end repeat**/ @@ -2241,67 +2240,67 @@ static void */ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = { - { - (PyArray_VectorUnaryFunc*)@from@_to_BOOL, - (PyArray_VectorUnaryFunc*)@from@_to_BYTE, - (PyArray_VectorUnaryFunc*)@from@_to_UBYTE, - (PyArray_VectorUnaryFunc*)@from@_to_SHORT, - (PyArray_VectorUnaryFunc*)@from@_to_USHORT, - (PyArray_VectorUnaryFunc*)@from@_to_INT, - (PyArray_VectorUnaryFunc*)@from@_to_UINT, - (PyArray_VectorUnaryFunc*)@from@_to_LONG, - (PyArray_VectorUnaryFunc*)@from@_to_ULONG, - (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, - (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, - (PyArray_VectorUnaryFunc*)@from@_to_FLOAT, - (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, - (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_OBJECT, - (PyArray_VectorUnaryFunc*)@from@_to_STRING, - (PyArray_VectorUnaryFunc*)@from@_to_UNICODE, - (PyArray_VectorUnaryFunc*)@from@_to_VOID - }, - (PyArray_GetItemFunc*)@from@_getitem, - (PyArray_SetItemFunc*)@from@_setitem, - (PyArray_CopySwapNFunc*)@from@_copyswapn, - (PyArray_CopySwapFunc*)@from@_copyswap, - (PyArray_CompareFunc*)@from@_compare, - (PyArray_ArgFunc*)@from@_argmax, - (PyArray_DotFunc*)NULL, - (PyArray_ScanFunc*)@from@_scan, - (PyArray_FromStrFunc*)@from@_fromstr, - (PyArray_NonzeroFunc*)@from@_nonzero, - (PyArray_FillFunc*)NULL, - (PyArray_FillWithScalarFunc*)NULL, - { - NULL, NULL, NULL - }, - { - NULL, NULL, NULL - }, - NULL, - (PyArray_ScalarKindFunc*)NULL, - NULL, - NULL, - (PyArray_FastClipFunc *)NULL, - (PyArray_FastPutmaskFunc *)NULL + { + (PyArray_VectorUnaryFunc*)@from@_to_BOOL, + (PyArray_VectorUnaryFunc*)@from@_to_BYTE, + (PyArray_VectorUnaryFunc*)@from@_to_UBYTE, + (PyArray_VectorUnaryFunc*)@from@_to_SHORT, + (PyArray_VectorUnaryFunc*)@from@_to_USHORT, + (PyArray_VectorUnaryFunc*)@from@_to_INT, + (PyArray_VectorUnaryFunc*)@from@_to_UINT, + (PyArray_VectorUnaryFunc*)@from@_to_LONG, + (PyArray_VectorUnaryFunc*)@from@_to_ULONG, + (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, + (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, + (PyArray_VectorUnaryFunc*)@from@_to_FLOAT, + (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, + (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_OBJECT, + (PyArray_VectorUnaryFunc*)@from@_to_STRING, + (PyArray_VectorUnaryFunc*)@from@_to_UNICODE, + (PyArray_VectorUnaryFunc*)@from@_to_VOID + }, + (PyArray_GetItemFunc*)@from@_getitem, + (PyArray_SetItemFunc*)@from@_setitem, + (PyArray_CopySwapNFunc*)@from@_copyswapn, + (PyArray_CopySwapFunc*)@from@_copyswap, + (PyArray_CompareFunc*)@from@_compare, + (PyArray_ArgFunc*)@from@_argmax, + (PyArray_DotFunc*)NULL, + (PyArray_ScanFunc*)@from@_scan, + (PyArray_FromStrFunc*)@from@_fromstr, + (PyArray_NonzeroFunc*)@from@_nonzero, + (PyArray_FillFunc*)NULL, + (PyArray_FillWithScalarFunc*)NULL, + { + NULL, NULL, NULL + }, + { + NULL, NULL, NULL + }, + NULL, + (PyArray_ScalarKindFunc*)NULL, + NULL, + NULL, + (PyArray_FastClipFunc *)NULL, + (PyArray_FastPutmaskFunc *)NULL }; static PyArray_Descr @from@_Descr = { - PyObject_HEAD_INIT(&PyArrayDescr_Type) + PyObject_HEAD_INIT(&PyArrayDescr_Type) &Py@NAME@ArrType_Type, - PyArray_@from@LTR, - PyArray_@from@LTR, - '@endian@', 0, - PyArray_@from@, 0, - _ALIGN(@align@), - NULL, - NULL, - NULL, - &_Py@NAME@_ArrFuncs, + PyArray_@from@LTR, + PyArray_@from@LTR, + '@endian@', 0, + PyArray_@from@, 0, + _ALIGN(@align@), + NULL, + NULL, + NULL, + &_Py@NAME@_ArrFuncs, }; /**end repeat**/ @@ -2319,68 +2318,68 @@ static PyArray_Descr @from@_Descr = { */ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = { - { - (PyArray_VectorUnaryFunc*)@from@_to_BOOL, - (PyArray_VectorUnaryFunc*)@from@_to_BYTE, - (PyArray_VectorUnaryFunc*)@from@_to_UBYTE, - (PyArray_VectorUnaryFunc*)@from@_to_SHORT, - (PyArray_VectorUnaryFunc*)@from@_to_USHORT, - (PyArray_VectorUnaryFunc*)@from@_to_INT, - (PyArray_VectorUnaryFunc*)@from@_to_UINT, - (PyArray_VectorUnaryFunc*)@from@_to_LONG, - (PyArray_VectorUnaryFunc*)@from@_to_ULONG, - (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, - (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, - (PyArray_VectorUnaryFunc*)@from@_to_FLOAT, - (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, - (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_OBJECT, - (PyArray_VectorUnaryFunc*)@from@_to_STRING, - (PyArray_VectorUnaryFunc*)@from@_to_UNICODE, - (PyArray_VectorUnaryFunc*)@from@_to_VOID - }, - (PyArray_GetItemFunc*)@from@_getitem, - (PyArray_SetItemFunc*)@from@_setitem, - (PyArray_CopySwapNFunc*)@from@_copyswapn, - (PyArray_CopySwapFunc*)@from@_copyswap, - (PyArray_CompareFunc*)@from@_compare, - (PyArray_ArgFunc*)@from@_argmax, - (PyArray_DotFunc*)@from@_dot, - (PyArray_ScanFunc*)@from@_scan, - (PyArray_FromStrFunc*)@from@_fromstr, - (PyArray_NonzeroFunc*)@from@_nonzero, - (PyArray_FillFunc*)@from@_fill, - (PyArray_FillWithScalarFunc*)@from@_fillwithscalar, - { - NULL, NULL, NULL - }, - { - NULL, NULL, NULL - }, - NULL, - (PyArray_ScalarKindFunc*)NULL, - NULL, - NULL, - (PyArray_FastClipFunc*)@from@_fastclip, - (PyArray_FastPutmaskFunc*)@from@_fastputmask + { + (PyArray_VectorUnaryFunc*)@from@_to_BOOL, + (PyArray_VectorUnaryFunc*)@from@_to_BYTE, + (PyArray_VectorUnaryFunc*)@from@_to_UBYTE, + (PyArray_VectorUnaryFunc*)@from@_to_SHORT, + (PyArray_VectorUnaryFunc*)@from@_to_USHORT, + (PyArray_VectorUnaryFunc*)@from@_to_INT, + (PyArray_VectorUnaryFunc*)@from@_to_UINT, + (PyArray_VectorUnaryFunc*)@from@_to_LONG, + (PyArray_VectorUnaryFunc*)@from@_to_ULONG, + (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, + (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, + (PyArray_VectorUnaryFunc*)@from@_to_FLOAT, + (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, + (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_OBJECT, + (PyArray_VectorUnaryFunc*)@from@_to_STRING, + (PyArray_VectorUnaryFunc*)@from@_to_UNICODE, + (PyArray_VectorUnaryFunc*)@from@_to_VOID + }, + (PyArray_GetItemFunc*)@from@_getitem, + (PyArray_SetItemFunc*)@from@_setitem, + (PyArray_CopySwapNFunc*)@from@_copyswapn, + (PyArray_CopySwapFunc*)@from@_copyswap, + (PyArray_CompareFunc*)@from@_compare, + (PyArray_ArgFunc*)@from@_argmax, + (PyArray_DotFunc*)@from@_dot, + (PyArray_ScanFunc*)@from@_scan, + (PyArray_FromStrFunc*)@from@_fromstr, + (PyArray_NonzeroFunc*)@from@_nonzero, + (PyArray_FillFunc*)@from@_fill, + (PyArray_FillWithScalarFunc*)@from@_fillwithscalar, + { + NULL, NULL, NULL + }, + { + NULL, NULL, NULL + }, + NULL, + (PyArray_ScalarKindFunc*)NULL, + NULL, + NULL, + (PyArray_FastClipFunc*)@from@_fastclip, + (PyArray_FastPutmaskFunc*)@from@_fastputmask }; static PyArray_Descr @from@_Descr = { - PyObject_HEAD_INIT(&PyArrayDescr_Type) + PyObject_HEAD_INIT(&PyArrayDescr_Type) &Py@NAME@ArrType_Type, - PyArray_@kind@LTR, - PyArray_@from@LTR, - '@endian@', @isobject@, - PyArray_@from@, - @num@*sizeof(@fromtyp@), - _ALIGN(@fromtyp@), - NULL, - NULL, - NULL, - &_Py@NAME@_ArrFuncs, + PyArray_@kind@LTR, + PyArray_@from@LTR, + '@endian@', @isobject@, + PyArray_@from@, + @num@*sizeof(@fromtyp@), + _ALIGN(@fromtyp@), + NULL, + NULL, + NULL, + &_Py@NAME@_ArrFuncs, }; /**end repeat**/ @@ -2389,27 +2388,27 @@ static PyArray_Descr @from@_Descr = { 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 @@ -2418,72 +2417,72 @@ static PyArray_Descr *_builtin_descrs[] = { 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); + 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_@name@LTR] = PyArray_@name@; + _letter_to_num[PyArray_@name@LTR] = PyArray_@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@_Descr.fields = Py_None; + @name@_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 @@ -2499,15 +2498,15 @@ set_typeinfo(PyObject *dict) #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@cx@@cn@O", - PyArray_@name@LTR, - PyArray_@name@, - BITSOF_@uname@, - _ALIGN(@type@), - @max@, @min@, - (PyObject *)&Py@Name@ArrType_Type)); - Py_DECREF(s); + PyDict_SetItemString(infodict, "@name@", + s=Py_BuildValue("ciii@cx@@cn@O", + PyArray_@name@LTR, + PyArray_@name@, + BITSOF_@uname@, + _ALIGN(@type@), + @max@, @min@, + (PyObject *)&Py@Name@ArrType_Type)); + Py_DECREF(s); /**end repeat**/ #define BITSOF_CFLOAT 2*BITSOF_FLOAT @@ -2520,51 +2519,51 @@ set_typeinfo(PyObject *dict) #name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE# #Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble# */ - PyDict_SetItemString(infodict, "@name@", - s=Py_BuildValue("ciiiO", PyArray_@name@LTR, - PyArray_@name@, BITSOF_@name@, - _ALIGN(@type@), - (PyObject *)\ - &Py@Name@ArrType_Type)); - Py_DECREF(s); -/**end repeat**/ - - 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), - (PyObject *)\ - &PyStringArrType_Type)); - 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), - (PyObject *)\ - &PyVoidArrType_Type)); - Py_DECREF(s); + PyDict_SetItemString(infodict, "@name@", + s=Py_BuildValue("ciiiO", PyArray_@name@LTR, + PyArray_@name@, BITSOF_@name@, + _ALIGN(@type@), + (PyObject *)\ + &Py@Name@ArrType_Type)); + Py_DECREF(s); + /**end repeat**/ + + 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), + (PyObject *)\ + &PyStringArrType_Type)); + 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), + (PyObject *)\ + &PyVoidArrType_Type)); + Py_DECREF(s); #define SETTYPE(name) \ - Py_INCREF(&Py##name##ArrType_Type); \ - PyDict_SetItemString(infodict, #name, \ - (PyObject *)&Py##name##ArrType_Type); + Py_INCREF(&Py##name##ArrType_Type); \ + PyDict_SetItemString(infodict, #name, \ + (PyObject *)&Py##name##ArrType_Type); - SETTYPE(Generic) + SETTYPE(Generic) SETTYPE(Number) SETTYPE(Integer) SETTYPE(Inexact) @@ -2578,8 +2577,8 @@ set_typeinfo(PyObject *dict) #undef SETTYPE PyDict_SetItemString(dict, "typeinfo", infodict); - Py_DECREF(infodict); - return 0; + Py_DECREF(infodict); + return 0; } #undef _MAX_LETTER -- cgit v1.2.1