diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2012-10-21 23:18:27 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2012-10-21 23:29:31 +0200 |
commit | dc4e38bb792825d7da23500c01b1cbd9dc4595b5 (patch) | |
tree | 30e681b092fd190e20e6f57ab575fcae45f40e0e | |
parent | a0891abcd7deea0af6f1e7b91e59d1da2101bdff (diff) | |
download | numpy-dc4e38bb792825d7da23500c01b1cbd9dc4595b5.tar.gz |
BUG: Fix bug with size 1-dims in CreateSortedStridePerm
This reverts changes done to CreateSortedStridePerm in commit
9194b3af. The problem is that it would fail for 3x1x3 Fortran order
array for example. And special handleing seems unnecessary at least
after 1-dim axis not mattering for contiguous flags.
This "closes Issue #434"
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 1 | ||||
-rw-r--r-- | numpy/core/src/multiarray/dtype_transfer.c | 6 | ||||
-rw-r--r-- | numpy/core/src/multiarray/shape.c | 18 | ||||
-rw-r--r-- | numpy/core/src/umath/reduction.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_api.py | 4 |
5 files changed, 11 insertions, 20 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 0c5062720..ef6c40b46 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -1112,7 +1112,6 @@ PyArray_NewLikeArray(PyArrayObject *prototype, NPY_ORDER order, int idim; PyArray_CreateSortedStridePerm(PyArray_NDIM(prototype), - PyArray_SHAPE(prototype), PyArray_STRIDES(prototype), strideperm); diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c index 138275c4c..01cb93562 100644 --- a/numpy/core/src/multiarray/dtype_transfer.c +++ b/numpy/core/src/multiarray/dtype_transfer.c @@ -3921,7 +3921,7 @@ PyArray_PrepareOneRawArrayIter(int ndim, npy_intp *shape, } /* Sort the axes based on the destination strides */ - PyArray_CreateSortedStridePerm(ndim, shape, strides, strideperm); + PyArray_CreateSortedStridePerm(ndim, strides, strideperm); for (i = 0; i < ndim; ++i) { int iperm = strideperm[ndim - i - 1].perm; out_shape[i] = shape[iperm]; @@ -4051,7 +4051,7 @@ PyArray_PrepareTwoRawArrayIter(int ndim, npy_intp *shape, } /* Sort the axes based on the destination strides */ - PyArray_CreateSortedStridePerm(ndim, shape, stridesA, strideperm); + PyArray_CreateSortedStridePerm(ndim, stridesA, strideperm); for (i = 0; i < ndim; ++i) { int iperm = strideperm[ndim - i - 1].perm; out_shape[i] = shape[iperm]; @@ -4185,7 +4185,7 @@ PyArray_PrepareThreeRawArrayIter(int ndim, npy_intp *shape, } /* Sort the axes based on the destination strides */ - PyArray_CreateSortedStridePerm(ndim, shape, stridesA, strideperm); + PyArray_CreateSortedStridePerm(ndim, stridesA, strideperm); for (i = 0; i < ndim; ++i) { int iperm = strideperm[ndim - i - 1].perm; out_shape[i] = shape[iperm]; diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c index 91d18474c..6da07e4cd 100644 --- a/numpy/core/src/multiarray/shape.c +++ b/numpy/core/src/multiarray/shape.c @@ -823,7 +823,7 @@ int _npy_stride_sort_item_comparator(const void *a, const void *b) bstride = -bstride; } - if (astride == bstride || astride == 0 || bstride == 0) { + if (astride == bstride) { /* * Make the qsort stable by next comparing the perm order. * (Note that two perm entries will never be equal) @@ -835,9 +835,7 @@ int _npy_stride_sort_item_comparator(const void *a, const void *b) if (astride > bstride) { return -1; } - else { - return 1; - } + return 1; } /*NUMPY_API @@ -848,8 +846,7 @@ int _npy_stride_sort_item_comparator(const void *a, const void *b) * [(2, 12), (0, 4), (1, -2)]. */ NPY_NO_EXPORT void -PyArray_CreateSortedStridePerm(int ndim, npy_intp *shape, - npy_intp *strides, +PyArray_CreateSortedStridePerm(int ndim, npy_intp *strides, npy_stride_sort_item *out_strideperm) { int i; @@ -857,12 +854,7 @@ PyArray_CreateSortedStridePerm(int ndim, npy_intp *shape, /* Set up the strideperm values */ for (i = 0; i < ndim; ++i) { out_strideperm[i].perm = i; - if (shape[i] == 1) { - out_strideperm[i].stride = 0; - } - else { - out_strideperm[i].stride = strides[i]; - } + out_strideperm[i].stride = strides[i]; } /* Sort them */ @@ -1001,7 +993,7 @@ PyArray_Ravel(PyArrayObject *arr, NPY_ORDER order) npy_intp stride; int i, ndim = PyArray_NDIM(arr); - PyArray_CreateSortedStridePerm(PyArray_NDIM(arr), PyArray_SHAPE(arr), + PyArray_CreateSortedStridePerm(PyArray_NDIM(arr), PyArray_STRIDES(arr), strideperm); stride = strideperm[ndim-1].stride; diff --git a/numpy/core/src/umath/reduction.c b/numpy/core/src/umath/reduction.c index 529d5523a..444682d57 100644 --- a/numpy/core/src/umath/reduction.c +++ b/numpy/core/src/umath/reduction.c @@ -51,7 +51,7 @@ allocate_reduce_result(PyArrayObject *arr, npy_bool *axis_flags, Py_INCREF(dtype); } - PyArray_CreateSortedStridePerm(PyArray_NDIM(arr), PyArray_SHAPE(arr), + PyArray_CreateSortedStridePerm(PyArray_NDIM(arr), PyArray_STRIDES(arr), strideperm); /* Build the new strides and shape */ diff --git a/numpy/core/tests/test_api.py b/numpy/core/tests/test_api.py index 3c365992b..7c6b11850 100644 --- a/numpy/core/tests/test_api.py +++ b/numpy/core/tests/test_api.py @@ -138,9 +138,9 @@ def test_copyto(): assert_raises(TypeError, np.copyto, [1,2,3], [2,3,4]) def test_copy_order(): - a = np.arange(24).reshape(2,3,4) + a = np.arange(24).reshape(2,1,3,4) b = a.copy(order='F') - c = np.arange(24).reshape(2,4,3).swapaxes(1,2) + c = np.arange(24).reshape(2,1,4,3).swapaxes(2,3) def check_copy_result(x, y, ccontig, fcontig, strides=False): assert_(not (x is y)) |