diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2013-10-25 18:58:08 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2014-02-06 17:51:59 +0100 |
commit | 009b17a85a22707e63ac9ea1896413992bbf9ce5 (patch) | |
tree | 0ee515c01f08801cbf68f219d4acd617d5e4aa9a | |
parent | b85dcf89078968b9d8e42ded22a5ed32c5d434f6 (diff) | |
download | numpy-009b17a85a22707e63ac9ea1896413992bbf9ce5.tar.gz |
BUG: Fix native byteorder check for trivial loops
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 29 | ||||
-rw-r--r-- | numpy/core/src/private/lowlevel_strided_loops.h | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_indexing.py | 4 |
3 files changed, 27 insertions, 14 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 7e2ba3316..ee8d8eef4 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -1421,8 +1421,11 @@ array_subscript(PyArrayObject *self, PyObject *op) /* Check if the index is simple enough */ if (PyArray_TRIVIALLY_ITERABLE(ind) && - PyArray_DESCR(ind)->type_num == NPY_INTP && - PyArray_ISALIGNED(ind) && PyArray_ISNBO(PyArray_DESCR(ind))) { + /* Check if the type is equivalent to INTP */ + PyArray_ITEMSIZE(ind) == sizeof(npy_intp) && + PyArray_DESCR(ind)->kind == 'i' && + PyArray_ISALIGNED(ind) && + PyDataType_ISNOTSWAPPED(PyArray_DESCR(ind))) { Py_INCREF(PyArray_DESCR(self)); result = PyArray_NewFromDescr(&PyArray_Type, @@ -1740,9 +1743,11 @@ array_ass_sub(PyArrayObject *self, PyObject *ind, PyObject *op) (PyArray_EQUIVALENTLY_ITERABLE(ind, tmp_arr) || (PyArray_NDIM(tmp_arr) == 0 && PyArray_TRIVIALLY_ITERABLE(tmp_arr))) && - /* Check the type/alginment of the index */ - PyArray_DESCR(ind)->type_num == NPY_INTP && - PyArray_ISALIGNED(ind) && PyArray_ISNBO(PyArray_DESCR(ind))) { + /* Check if the type is equivalent to INTP */ + PyArray_ITEMSIZE(ind) == sizeof(npy_intp) && + PyArray_DESCR(ind)->kind == 'i' && + PyArray_ISALIGNED(ind) && + PyDataType_ISNOTSWAPPED(PyArray_DESCR(ind))) { /* trivial_set checks the index for us */ if (mapiter_trivial_set(self, ind, tmp_arr) < 0) { @@ -2247,8 +2252,11 @@ PyArray_MapIterCheckIndices(PyArrayMapIterObject *mit) /* See if it is possible to just trivially iterate the array */ if (PyArray_TRIVIALLY_ITERABLE(op) && - PyArray_DESCR(op)->type_num == NPY_INTP && - PyArray_ISALIGNED(op) && PyArray_ISNBO(PyArray_DESCR(op))) { + /* Check if the type is equivalent to INTP */ + PyArray_ITEMSIZE(op) == sizeof(npy_intp) && + PyArray_DESCR(op)->kind == 'i' && + PyArray_ISALIGNED(op) && + PyDataType_ISNOTSWAPPED(PyArray_DESCR(op))) { char *data; npy_intp stride; @@ -2499,6 +2507,11 @@ PyArray_MapIterNew(npy_index_info *indices , int index_num, int index_type, * If subspace is not NULL, NpyIter cannot allocate extra_op for us. */ else if (extra_op_flags && (subspace != NULL)) { + npy_uint32 tmp_op_flags[NPY_MAXDIMS]; + for (i=0; i < mit->numiter; i++) { + tmp_op_flags[i] = NPY_ITER_READONLY; + } + Py_INCREF(extra_op_dtype); mit->extra_op_dtype = extra_op_dtype; @@ -2514,7 +2527,7 @@ PyArray_MapIterNew(npy_index_info *indices , int index_num, int index_type, NPY_ITER_MULTI_INDEX, NPY_KEEPORDER, NPY_UNSAFE_CASTING, - op_flags, NULL); + tmp_op_flags, NULL); if (tmp_iter == NULL) { goto fail; } diff --git a/numpy/core/src/private/lowlevel_strided_loops.h b/numpy/core/src/private/lowlevel_strided_loops.h index c74cd901a..a6bb4c7eb 100644 --- a/numpy/core/src/private/lowlevel_strided_loops.h +++ b/numpy/core/src/private/lowlevel_strided_loops.h @@ -668,7 +668,7 @@ npy_bswap8_unaligned(char * x) PyArray_DIMS(arr2), \ PyArray_NDIM(arr1)) && \ (PyArray_FLAGS(arr1)&(NPY_ARRAY_C_CONTIGUOUS| \ - NPY_ARRAY_F_CONTIGUOUS)) == \ + NPY_ARRAY_F_CONTIGUOUS)) & \ (PyArray_FLAGS(arr2)&(NPY_ARRAY_C_CONTIGUOUS| \ NPY_ARRAY_F_CONTIGUOUS)) \ ) @@ -679,12 +679,12 @@ npy_bswap8_unaligned(char * x) PyArray_CHKFLAGS(arr, NPY_ARRAY_F_CONTIGUOUS) \ ) #define PyArray_PREPARE_TRIVIAL_ITERATION(arr, count, data, stride) \ - count = PyArray_SIZE(arr), \ - data = PyArray_BYTES(arr), \ + count = PyArray_SIZE(arr); \ + data = PyArray_BYTES(arr); \ stride = ((PyArray_NDIM(arr) == 0) ? 0 : \ ((PyArray_NDIM(arr) == 1) ? \ PyArray_STRIDE(arr, 0) : \ - PyArray_ITEMSIZE(arr))) \ + PyArray_ITEMSIZE(arr))); #define PyArray_TRIVIALLY_ITERABLE_PAIR(arr1, arr2) (\ diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py index 38535eaa2..b79caa6c4 100644 --- a/numpy/core/tests/test_indexing.py +++ b/numpy/core/tests/test_indexing.py @@ -182,8 +182,8 @@ class TestMultiIndexingAutomated(TestCase): np.empty((0, 1, 1), dtype=np.intp), # empty broadcastable np.array([0, 1, -2]), np.array([[2], [0], [1]]), - np.array([[0, -1], [0, 1]]), - np.array([2, -1]), + np.array([[0, -1], [0, 1]], dtype=np.dtype('intp').newbyteorder()), + np.array([2, -1], dtype=np.int8), np.zeros([1]*31, dtype=int), # trigger too large array. np.array([0., 1.])] # invalid datatype # Some simpler indices that still cover a bit more |