summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2015-06-18 10:46:02 -0400
committerCharles Harris <charlesr.harris@gmail.com>2015-06-18 10:46:02 -0400
commit4027d16f0aa19e551067bf0c93dbe057e0142bb8 (patch)
tree3e282743bbdff9afef1f852935233a66c7bc8b10 /numpy/core
parent2c29b138aedb1774e7f984f4a237243455c423ad (diff)
parentb26aef66a998b8a6877ee261e4d97ec8f815dad2 (diff)
downloadnumpy-4027d16f0aa19e551067bf0c93dbe057e0142bb8.tar.gz
Merge pull request #5980 from seberg/large-flat-concat
BUG: Large concatenates with axis=None causing segfault.
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c9
-rw-r--r--numpy/core/tests/test_shape_base.py13
2 files changed, 18 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index 018345e6c..f8656d8c3 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -479,7 +479,7 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays,
PyTypeObject *subtype = &PyArray_Type;
double priority = NPY_PRIORITY;
int iarrays;
- npy_intp stride, sizes[NPY_MAXDIMS];
+ npy_intp stride;
npy_intp shape = 0;
PyArray_Descr *dtype = NULL;
PyArrayObject *ret = NULL;
@@ -496,7 +496,7 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays,
* array's shape.
*/
for (iarrays = 0; iarrays < narrays; ++iarrays) {
- shape += sizes[iarrays] = PyArray_SIZE(arrays[iarrays]);
+ shape += PyArray_SIZE(arrays[iarrays]);
/* Check for overflow */
if (shape < 0) {
PyErr_SetString(PyExc_ValueError,
@@ -551,7 +551,7 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays,
for (iarrays = 0; iarrays < narrays; ++iarrays) {
/* Adjust the window dimensions for this array */
- sliding_view->dimensions[0] = sizes[iarrays];
+ sliding_view->dimensions[0] = PyArray_SIZE(arrays[iarrays]);
/* Copy the data for this array */
if (PyArray_CopyAsFlat((PyArrayObject *)sliding_view, arrays[iarrays],
@@ -562,7 +562,8 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays,
}
/* Slide to the start of the next window */
- sliding_view->data += sliding_view->strides[0] * sizes[iarrays];
+ sliding_view->data +=
+ sliding_view->strides[0] * PyArray_SIZE(arrays[iarrays]);
}
Py_DECREF(sliding_view);
diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py
index c6399bb07..c387bc616 100644
--- a/numpy/core/tests/test_shape_base.py
+++ b/numpy/core/tests/test_shape_base.py
@@ -172,6 +172,7 @@ class TestVstack(TestCase):
desired = array([[1, 2], [1, 2]])
assert_array_equal(res, desired)
+
def test_concatenate_axis_None():
a = np.arange(4, dtype=np.float64).reshape((2, 2))
b = list(range(3))
@@ -188,6 +189,18 @@ def test_concatenate_axis_None():
assert_array_equal(r, d)
+def test_large_concatenate_axis_None():
+ # When no axis is given, concatenate uses flattened versions.
+ # This also had a bug with many arrays (see gh-5979).
+ x = np.arange(1, 100)
+ r = np.concatenate(x, None)
+ assert_array_equal(x, r)
+
+ # This should probably be deprecated:
+ r = np.concatenate(x, 100) # axis is >= MAXDIMS
+ assert_array_equal(x, r)
+
+
def test_concatenate():
# Test concatenate function
# No arrays raise ValueError