diff options
author | Nathaniel J. Smith <njs@pobox.com> | 2012-05-19 09:49:27 +0100 |
---|---|---|
committer | Nathaniel J. Smith <njs@pobox.com> | 2012-05-19 09:49:27 +0100 |
commit | 412c8a6ad055b7809e5a77e8d5f257c33e102284 (patch) | |
tree | 94bc1f878e3e4cfd981e786cc389a82636f85299 | |
parent | c247305a75a20e4e5d421e691d931d6cc98c39ce (diff) | |
parent | 6c883959588b29c5ac92ef2723d24a93db63d716 (diff) | |
download | numpy-412c8a6ad055b7809e5a77e8d5f257c33e102284.tar.gz |
Merge branch 'master' into clean-up-diagonal
-rw-r--r-- | bscript | 3 | ||||
-rw-r--r-- | doc/source/reference/c-api.array.rst | 4 | ||||
-rw-r--r-- | numpy/core/bscript | 4 | ||||
-rw-r--r-- | numpy/core/src/multiarray/buffer.c | 4 | ||||
-rw-r--r-- | numpy/core/src/multiarray/nditer_constr.c | 43 | ||||
-rw-r--r-- | numpy/core/tests/test_maskna.py | 9 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 13 | ||||
-rw-r--r-- | numpy/core/tests/test_nditer.py | 11 |
8 files changed, 41 insertions, 50 deletions
@@ -22,6 +22,7 @@ import __builtin__ __builtin__.__NUMPY_SETUP__ = True from bento.commands import hooks +from bento.backends import waf_backend import waflib @@ -109,7 +110,7 @@ def pre_configure(context): conf = context.waf_context conf.load("compiler_c") - conf.load("python") + conf.load("custom_python", tooldir=[waf_backend.WAF_TOOLDIR]) conf.check_python_version((2, 4, 0)) conf.check_python_headers() diff --git a/doc/source/reference/c-api.array.rst b/doc/source/reference/c-api.array.rst index 89981a977..8eedc689a 100644 --- a/doc/source/reference/c-api.array.rst +++ b/doc/source/reference/c-api.array.rst @@ -224,6 +224,8 @@ From scratch .. cfunction:: PyObject* PyArray_NewFromDescr(PyTypeObject* subtype, PyArray_Descr* descr, int nd, npy_intp* dims, npy_intp* strides, void* data, int flags, PyObject* obj) + This function steals a reference to *descr* if it is not NULL. + This is the main array creation function. Most new arrays are created with this flexible function. @@ -322,6 +324,8 @@ From scratch .. cfunction:: PyObject* PyArray_SimpleNewFromDescr(int nd, npy_intp* dims, PyArray_Descr* descr) + This function steals a reference to *descr* if it is not NULL. + Create a new array with the provided data-type descriptor, *descr* , of the shape deteremined by *nd* and *dims*. diff --git a/numpy/core/bscript b/numpy/core/bscript index 19ab200bf..c0438fcb8 100644 --- a/numpy/core/bscript +++ b/numpy/core/bscript @@ -456,8 +456,8 @@ def pbuild(context): pjoin('src', 'multiarray', 'scalartypes.c.src'), pjoin('src', 'multiarray', 'sequence.c'), pjoin('src', 'multiarray', 'shape.c'), - pjoin('src', 'multiarray', 'ucsnarrow.c')] - pjoin('src', 'multiarray', 'usertypes.c'), + pjoin('src', 'multiarray', 'ucsnarrow.c'), + pjoin('src', 'multiarray', 'usertypes.c')] else: sources = extension.sources includes = ["src/multiarray", "src/private"] diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c index 3f58451c8..0cb4e9929 100644 --- a/numpy/core/src/multiarray/buffer.c +++ b/numpy/core/src/multiarray/buffer.c @@ -605,6 +605,10 @@ array_getbuffer(PyObject *obj, Py_buffer *view, int flags) self = (PyArrayObject*)obj; /* Check whether we can provide the wanted properties */ + if (PyArray_HASMASKNA(obj)) { + PyErr_SetString(PyExc_TypeError, "NA-masked arrays are not supported by the Python buffer protocol"); + goto fail; + } if ((flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS && !PyArray_CHKFLAGS(self, NPY_ARRAY_C_CONTIGUOUS)) { PyErr_SetString(PyExc_ValueError, "ndarray is not C-contiguous"); diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c index 81ebb7a38..7800027b9 100644 --- a/numpy/core/src/multiarray/nditer_constr.c +++ b/numpy/core/src/multiarray/nditer_constr.c @@ -2599,7 +2599,6 @@ npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype, npy_int8 *perm = NIT_PERM(iter); npy_intp new_shape[NPY_MAXDIMS], strides[NPY_MAXDIMS], stride = op_dtype->elsize; - char reversestride[NPY_MAXDIMS], anyreverse = 0; NpyIter_AxisData *axisdata; npy_intp sizeof_axisdata; npy_intp i; @@ -2628,7 +2627,6 @@ npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype, axisdata = NIT_AXISDATA(iter); sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop); - memset(reversestride, 0, NPY_MAXDIMS); /* Initialize the strides to invalid values */ for (i = 0; i < NPY_MAXDIMS; ++i) { strides[i] = NPY_MAX_INTP; @@ -2652,13 +2650,6 @@ npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype, "for iterator dimension %d to %d\n", (int)i, (int)idim, (int)stride); strides[i] = stride; - if (p < 0) { - reversestride[i] = 1; - anyreverse = 1; - } - else { - reversestride[i] = 0; - } if (shape == NULL) { new_shape[i] = NAD_SHAPE(axisdata); stride *= new_shape[i]; @@ -2721,13 +2712,6 @@ npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype, "for iterator dimension %d to %d\n", (int)i, (int)idim, (int)stride); strides[i] = stride; - if (p < 0) { - reversestride[i] = 1; - anyreverse = 1; - } - else { - reversestride[i] = 0; - } if (shape == NULL) { new_shape[i] = NAD_SHAPE(axisdata); stride *= new_shape[i]; @@ -2816,33 +2800,6 @@ npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype, return NULL; } - /* If there are any reversed axes, create a view that reverses them */ - if (anyreverse) { - char *dataptr = PyArray_DATA(ret); - PyArrayObject *newret; - - for (idim = 0; idim < op_ndim; ++idim) { - if (reversestride[idim]) { - dataptr += strides[idim]*(shape[idim]-1); - strides[idim] = -strides[idim]; - } - } - Py_INCREF(op_dtype); - newret = (PyArrayObject *)PyArray_NewFromDescr(subtype, - op_dtype, op_ndim, - shape, strides, dataptr, - NPY_ARRAY_WRITEABLE, NULL); - if (newret == NULL) { - Py_DECREF(ret); - return NULL; - } - if (PyArray_SetBaseObject(newret, (PyObject *)ret) < 0) { - Py_DECREF(newret); - return NULL; - } - ret = newret; - } - /* Make sure all the flags are good */ PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL); diff --git a/numpy/core/tests/test_maskna.py b/numpy/core/tests/test_maskna.py index 0b48ab803..c19cd70c2 100644 --- a/numpy/core/tests/test_maskna.py +++ b/numpy/core/tests/test_maskna.py @@ -109,6 +109,15 @@ def test_array_maskna_construction(): assert_(a.flags.maskna) assert_equal(np.isna(a), True) +@dec.skipif(sys.version_info < (2, 6)) +def test_array_maskna_pep3118(): + global memoryview + if sys.version_info[:2] == (2, 6): + from numpy.core.multiarray import memorysimpleview as memoryview + + a = np.array([0, 1, np.NA], maskna=True) + # The buffer protocol doesn't support NA masks, should raise an error + assert_raises(TypeError, memoryview, a) def test_array_maskna_asarray(): a = np.arange(6).reshape(2,3) diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index c315ea385..348ebbdaa 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1223,6 +1223,19 @@ class TestArgmin(TestCase): assert_equal(np.argmin(arr), pos, err_msg="%r"%arr) assert_equal(arr[np.argmin(arr)], np.min(arr), err_msg="%r"%arr) + def test_minimum_signed_integers(self): + + a = np.array([1, -2**7, -2**7 + 1], dtype=np.int8) + assert_equal(np.argmin(a), 1) + + a = np.array([1, -2**15, -2**15 + 1], dtype=np.int16) + assert_equal(np.argmin(a), 1) + + a = np.array([1, -2**31, -2**31 + 1], dtype=np.int32) + assert_equal(np.argmin(a), 1) + + a = np.array([1, -2**63, -2**63 + 1], dtype=np.int64) + assert_equal(np.argmin(a), 1) class TestMinMax(TestCase): diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py index afb047491..f790b0d10 100644 --- a/numpy/core/tests/test_nditer.py +++ b/numpy/core/tests/test_nditer.py @@ -840,6 +840,7 @@ def test_iter_array_cast(): assert_equal(i.operands[0], a) assert_equal(i.operands[0].dtype, np.dtype('f8')) # The memory layout of the temporary should match a (a is (48,4,16)) + # except negative strides get flipped to positive strides. assert_equal(i.operands[0].strides, (96,8,32)) a = a[::-1,:,::-1] i = nditer(a, [], [['readonly','copy']], @@ -847,7 +848,7 @@ def test_iter_array_cast(): op_dtypes=[np.dtype('f8')]) assert_equal(i.operands[0], a) assert_equal(i.operands[0].dtype, np.dtype('f8')) - assert_equal(i.operands[0].strides, (-96,8,-32)) + assert_equal(i.operands[0].strides, (96,8,32)) # Same-kind cast 'f8' -> 'f4' -> 'f8' a = np.arange(24, dtype='f8').reshape(2,3,4).T @@ -877,10 +878,12 @@ def test_iter_array_cast_buggy(): casting='unsafe', op_dtypes=[np.dtype('f4')]) assert_equal(i.operands[0].dtype, np.dtype('f4')) - assert_equal(i.operands[0].strides, (-4,)) - i.operands[0][:] = 1 + # Even though the stride was negative in 'a', it + # becomes positive in the temporary + assert_equal(i.operands[0].strides, (4,)) + i.operands[0][:] = [1,2,3] i = None - assert_equal(a, [1,1,1]) + assert_equal(a, [1,2,3]) def test_iter_array_cast_errors(): # Check that invalid casts are caught |