diff options
-rw-r--r-- | numpy/core/include/numpy/arrayobject.h | 2 | ||||
-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 | ||||
-rw-r--r-- | numpy/ctypeslib.py | 3 | ||||
-rw-r--r-- | numpy/numarray/alter_code1.py | 2 | ||||
-rw-r--r-- | numpy/numarray/alter_code2.py | 2 | ||||
-rw-r--r-- | numpy/oldnumeric/alter_code1.py | 2 | ||||
-rw-r--r-- | numpy/oldnumeric/alter_code2.py | 2 | ||||
-rw-r--r-- | numpy/setup.py | 1 | ||||
-rw-r--r-- | numpy/testing/numpytest.py | 2 | ||||
-rw-r--r-- | numpy/tests/test_ctypeslib.py (renamed from numpy/lib/tests/test_utils.py) | 27 |
13 files changed, 89 insertions, 56 deletions
diff --git a/numpy/core/include/numpy/arrayobject.h b/numpy/core/include/numpy/arrayobject.h index c025dbe19..d4298975b 100644 --- a/numpy/core/include/numpy/arrayobject.h +++ b/numpy/core/include/numpy/arrayobject.h @@ -644,8 +644,10 @@ typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX #define PY_SSIZE_T_MIN INT_MIN #define NPY_SSIZE_T_PYFMT "i" +#define constchar const char #else #define NPY_SSIZE_T_PYFMT "n" +#define constchar char #endif #if SIZEOF_PY_INTPTR_T == SIZEOF_INT 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; diff --git a/numpy/ctypeslib.py b/numpy/ctypeslib.py index 739c6632e..ddd8bb714 100644 --- a/numpy/ctypeslib.py +++ b/numpy/ctypeslib.py @@ -1,5 +1,8 @@ __all__ = ['ctypes_load_library', 'ndpointer'] +import sys, os +from numpy import integer, product, ndarray, dtype as _dtype +from numpy.core.multiarray import _flagdict, flagsobj # Adapted from Albert Strasheim def ctypes_load_library(libname, loader_path): diff --git a/numpy/numarray/alter_code1.py b/numpy/numarray/alter_code1.py index f30c3dd37..897b019db 100644 --- a/numpy/numarray/alter_code1.py +++ b/numpy/numarray/alter_code1.py @@ -52,7 +52,7 @@ Makes the following changes: - .setimaginary() --> .imag """ -__all__ = ['fromfile', 'fromstr', 'convertfile', 'convertall'] +__all__ = ['convertfile', 'convertall'] import sys import os diff --git a/numpy/numarray/alter_code2.py b/numpy/numarray/alter_code2.py index a80cc16ff..46be8043b 100644 --- a/numpy/numarray/alter_code2.py +++ b/numpy/numarray/alter_code2.py @@ -3,7 +3,7 @@ This module converts code written for numpy.numarray to work with numpy """ -#__all__ = ['fromfile', 'fromstr', 'convertfile', 'convertall'] +#__all__ = ['convertfile', 'convertall'] __all__ = [] import warnings diff --git a/numpy/oldnumeric/alter_code1.py b/numpy/oldnumeric/alter_code1.py index 35c407e8b..eacd3ed2a 100644 --- a/numpy/oldnumeric/alter_code1.py +++ b/numpy/oldnumeric/alter_code1.py @@ -28,7 +28,7 @@ Makes the following changes: * Converts uses of type(...) is <type> isinstance(..., <type>) """ -__all__ = ['fromfile', 'fromstr', 'convertfile', 'convertall'] +__all__ = ['convertfile', 'convertall'] import sys import os diff --git a/numpy/oldnumeric/alter_code2.py b/numpy/oldnumeric/alter_code2.py index 766f861d0..c8ecd114c 100644 --- a/numpy/oldnumeric/alter_code2.py +++ b/numpy/oldnumeric/alter_code2.py @@ -17,7 +17,7 @@ Makes the following changes: oldnumeric.random_array, and oldnumeric.fft """ -#__all__ = ['fromfile', 'fromstr', 'convertfile', 'convertall'] +#__all__ = ['convertfile', 'convertall'] __all__ = [] import warnings diff --git a/numpy/setup.py b/numpy/setup.py index 61538ec28..ebc382096 100644 --- a/numpy/setup.py +++ b/numpy/setup.py @@ -15,6 +15,7 @@ def configuration(parent_package='',top_path=None): config.add_subpackage('linalg') config.add_subpackage('random') config.add_data_dir('doc') + config.add_data_dir('tests') config.make_config_py() # installs __config__.py return config diff --git a/numpy/testing/numpytest.py b/numpy/testing/numpytest.py index c07124753..74b7c1a1e 100644 --- a/numpy/testing/numpytest.py +++ b/numpy/testing/numpytest.py @@ -452,6 +452,8 @@ class NumpyTest: continue modules.append(module) + + self.test_files = [] suites = [] for module in modules: diff --git a/numpy/lib/tests/test_utils.py b/numpy/tests/test_ctypeslib.py index fc98a92b6..6931bc36b 100644 --- a/numpy/lib/tests/test_utils.py +++ b/numpy/tests/test_ctypeslib.py @@ -1,18 +1,19 @@ from numpy.testing import * set_package_path() import numpy as N +from numpy.ctypeslib import ndpointer restore_path() class test_ndpointer(NumpyTestCase): def check_dtype(self): dt = N.intc - p = N.ndpointer(dtype=dt) + p = ndpointer(dtype=dt) self.assert_(p.from_param(N.array([1], dt))) dt = '<i4' - p = N.ndpointer(dtype=dt) + p = ndpointer(dtype=dt) self.assert_(p.from_param(N.array([1], dt))) dt = N.dtype('>i4') - p = N.ndpointer(dtype=dt) + p = ndpointer(dtype=dt) p.from_param(N.array([1], dt)) self.assertRaises(TypeError, p.from_param, N.array([1], dt.newbyteorder('swap'))) @@ -20,10 +21,10 @@ class test_ndpointer(NumpyTestCase): dtformats = [N.intc, N.float64] dtdescr = {'names' : dtnames, 'formats' : dtformats} dt = N.dtype(dtdescr) - p = N.ndpointer(dtype=dt) + p = ndpointer(dtype=dt) self.assert_(p.from_param(N.zeros((10,), dt))) samedt = N.dtype(dtdescr) - p = N.ndpointer(dtype=samedt) + p = ndpointer(dtype=samedt) self.assert_(p.from_param(N.zeros((10,), dt))) dt2 = N.dtype(dtdescr, align=True) if dt.itemsize != dt2.itemsize: @@ -32,29 +33,29 @@ class test_ndpointer(NumpyTestCase): self.assert_(p.from_param(N.zeros((10,), dt2))) def check_ndim(self): - p = N.ndpointer(ndim=0) + p = ndpointer(ndim=0) self.assert_(p.from_param(N.array(1))) self.assertRaises(TypeError, p.from_param, N.array([1])) - p = N.ndpointer(ndim=1) + p = ndpointer(ndim=1) self.assertRaises(TypeError, p.from_param, N.array(1)) self.assert_(p.from_param(N.array([1]))) - p = N.ndpointer(ndim=2) + p = ndpointer(ndim=2) self.assert_(p.from_param(N.array([[1]]))) def check_shape(self): - p = N.ndpointer(shape=(1,2)) + p = ndpointer(shape=(1,2)) self.assert_(p.from_param(N.array([[1,2]]))) self.assertRaises(TypeError, p.from_param, N.array([[1],[2]])) - p = N.ndpointer(shape=()) + p = ndpointer(shape=()) self.assert_(p.from_param(N.array(1))) def check_flags(self): x = N.array([[1,2,3]], order='F') - p = N.ndpointer(flags='FORTRAN') + p = ndpointer(flags='FORTRAN') self.assert_(p.from_param(x)) - p = N.ndpointer(flags='CONTIGUOUS') + p = ndpointer(flags='CONTIGUOUS') self.assertRaises(TypeError, p.from_param, x) - p = N.ndpointer(flags=x.flags.num) + p = ndpointer(flags=x.flags.num) self.assert_(p.from_param(x)) self.assertRaises(TypeError, p.from_param, N.array([[1,2,3]])) |