diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-14 23:15:21 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-14 23:15:21 +0000 |
commit | f77587b2cd9091a99a31bb0d5f99c57cc077aa8e (patch) | |
tree | 8894af7b880beece61903e47dd84c7205e3ee8d3 /numpy/core/src | |
parent | 06acb9555bf64997423b124620fb469cab24cb2b (diff) | |
download | numpy-f77587b2cd9091a99a31bb0d5f99c57cc077aa8e.tar.gz |
Fix Python 2.5 compatibility to work with new b3 release
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/arrayobject.c | 20 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 2 | ||||
-rw-r--r-- | numpy/core/src/scalarmathmodule.c.src | 23 | ||||
-rw-r--r-- | numpy/core/src/scalartypes.inc.src | 57 |
4 files changed, 63 insertions, 39 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index f0fea6a04..d3bbe9a24 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -3036,7 +3036,7 @@ array_getwritebuf(PyArrayObject *self, Py_ssize_t segment, void **ptrptr) } static Py_ssize_t -array_getcharbuf(PyArrayObject *self, Py_ssize_t segment, const char **ptrptr) +array_getcharbuf(PyArrayObject *self, Py_ssize_t segment, constchar **ptrptr) { if (self->descr->type_num == PyArray_STRING || \ self->descr->type_num == PyArray_UNICODE) @@ -3790,6 +3790,20 @@ _array_copy_nice(PyArrayObject *self) PyArray_Copy(self)); } +#if PY_VERSION_HEX >= 0x02050000 +static PyObject * +array_index(PyArrayObject *v) +{ + if (PyArray_SIZE(v) != 1 || !PyArray_ISINTEGER(v)) { + PyErr_SetString(PyExc_TypeError, "only length-1 integer " \ + "arrays can be converted to an index"); + return NULL; + } + return v->descr->f->getitem(v->data, v); +} +#endif + + static PyNumberMethods array_as_number = { (binaryfunc)array_add, /*nb_add*/ (binaryfunc)array_subtract, /*nb_subtract*/ @@ -3834,6 +3848,10 @@ static PyNumberMethods array_as_number = { (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/ (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/ +#if PY_VERSION_HEX >= 0x02050000 + (unaryfunc)array_index, /* nb_index */ +#endif + }; /****************** End of Buffer Protocol *******************************/ diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index 257e93258..a687cb757 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -6118,7 +6118,7 @@ labeled. static unsigned int PyArray_GetNDArrayCVersion(void) { - return (unsigned int)NDARRAY_VERSION; + return (unsigned int)NPY_VERSION; } static PyObject * diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src index bf99a5d26..be35878ca 100644 --- a/numpy/core/src/scalarmathmodule.c.src +++ b/numpy/core/src/scalarmathmodule.c.src @@ -712,8 +712,8 @@ static PyObject * /**end repeat**/ /**begin repeat - #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6# - #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6# + #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*5# + #oper=lshift*6, rshift*6, and*6, or*6, xor*6# **/ #define @name@_@oper@ NULL /**end repeat**/ @@ -819,20 +819,6 @@ static PyObject * /**end repeat**/ -#if PY_VERSION_HEX >= 0x02050000 -/**begin repeat - #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong# - #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong# -**/ -static Py_ssize_t -@name@_index(PyObject *a) -{ - return PyArrayScalar_VAL(a, @Name@); -} -/**end repeat**/ -#endif - - /**begin repeat #oper=le,ge,lt,gt,eq,ne# #op=<=,>=,<,>,==,!=# @@ -937,7 +923,7 @@ static PyNumberMethods @name@_as_number = { 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 - (lenfunc)@name@_index, /*nb_index*/ + (unaryfunc)NULL, /*nb_index*/ #endif }; /**end repeat**/ @@ -951,6 +937,9 @@ add_scalarmath(void) #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble# #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble# **/ +#if PY_VERSION_HEX >= 0x02050000 + @name@_as_number.nb_index = Py@NAME@ArrType_Type.tp_as_number->nb_index; +#endif Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number); Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare; /**end repeat**/ diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src index e680b9fc4..25e3454f7 100644 --- a/numpy/core/src/scalartypes.inc.src +++ b/numpy/core/src/scalartypes.inc.src @@ -593,23 +593,6 @@ static PyObject * } /**end repeat**/ -#if PY_VERSION_HEX >= 0x02050000 -/* This needs a better implementation */ -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); -} -#endif - static PyNumberMethods gentype_as_number = { (binaryfunc)gentype_add, /*nb_add*/ @@ -651,7 +634,7 @@ static PyNumberMethods gentype_as_number = { 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 - (lenfunc)gentype_index, /* nb_index */ + (unaryfunc)NULL, /* nb_index */ #endif }; @@ -1641,7 +1624,7 @@ gentype_getsegcount(PyObject *self, int *lenp) } static int -gentype_getcharbuf(PyObject *self, int segment, const char **ptrptr) +gentype_getcharbuf(PyObject *self, int segment, constchar **ptrptr) { if (PyArray_IsScalar(self, String) || \ PyArray_IsScalar(self, Unicode)) @@ -1795,6 +1778,26 @@ bool_arrtype_nonzero(PyObject *a) return a == PyArrayScalar_True; } +#if PY_VERSION_HEX >= 0x02050000 +/**begin repeat +#name=byte, short, int, long, ubyte, ushort, longlong, uint, ulong, ulonglong# +#Name=Byte, Short, Int, Long, UByte, UShort, LongLong, UInt, ULong, ULongLong# +#type=PyInt_FromLong*6, PyLong_FromLongLong*1, PyLong_FromUnsignedLong*2, PyLong_FromUnsignedLongLong# +*/ +static PyNumberMethods @name@_arrtype_as_number; +static PyObject * +@name@_index(PyObject *self) +{ + return @type@(PyArrayScalar_VAL(self, @Name@)); +} +/**end repeat**/ +static PyObject * +bool_index(PyObject *a) +{ + return PyInt_FromLong(PyArrayScalar_VAL(a, Bool)); +} +#endif + /* Arithmetic methods -- only so we can override &, |, ^. */ static PyNumberMethods bool_arrtype_as_number = { 0, /* nb_add */ @@ -2154,7 +2157,7 @@ object_arrtype_getwritebuf(PyObjectScalarObject *self, Py_ssize_t segment, void static Py_ssize_t object_arrtype_getcharbuf(PyObjectScalarObject *self, Py_ssize_t segment, - const char **ptrptr) + constchar **ptrptr) { PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer; @@ -2336,6 +2339,20 @@ initialize_numeric_types(void) PyGenericArrType_Type.tp_richcompare = gentype_richcompare; PyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number; +#if PY_VERSION_HEX >= 0x02050000 + /* need to add dummy versions with filled-in nb_index + in-order for PyType_Ready to fill in .__index__() method + */ + /**begin repeat +#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong# +#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong# + */ + Py@NAME@ArrType_Type.tp_as_number = &@name@_arrtype_as_number; + Py@NAME@ArrType_Type.tp_as_number->nb_index = (unaryfunc)@name@_index; + + /**end repeat**/ + PyBoolArrType_Type.tp_as_number->nb_index = (unaryfunc)bool_index; +#endif PyStringArrType_Type.tp_alloc = NULL; PyStringArrType_Type.tp_free = NULL; |