8000 Merge pull request #420 from seberg/contig · numpy/numpy@fd63e8f · GitHub
[go: up one dir, main page]

Skip to content

Commit fd63e8f

Browse files
committed
Merge pull request #420 from seberg/contig
Reset flags when Axes are removed. Array might now be 1D, or removed axe...
2 parents c8ed8ba + 380ce94 commit fd63e8f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

numpy/core/src/multiarray/shape.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,4 +1186,7 @@ PyArray_RemoveAxesInPlace(PyArrayObject *arr, npy_bool *flags)
11861186

11871187
/* The final number of dimensions */
11881188
fa->nd = idim_out;
1189+
1190+
/* Update contiguous flags */
1191+
PyArray_UpdateFlags(arr, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
11891192
}

numpy/core/tests/test_regression.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,22 @@ def test_array_scalar_contiguous(self):
15281528
assert_(np.array(np.float32(1.0)).flags.c_contiguous)
15291529
assert_(np.array(np.float32(1.0)).flags.f_contiguous)
15301530

1531+
def test_squeeze_contiguous(self):
1532+
"""Similar to GitHub issue #387"""
1533+
a = np.zeros((1,2)).squeeze()
1534+
b = np.zeros((2,2,2), order='F')[:,:,::2].squeeze()
1535+
assert_(a.flags.c_contiguous)
1536+
assert_(a.flags.f_contiguous)
1537+
assert_(b.flags.f_contiguous)
1538+
1539+
def test_reduce_contiguous(self):
1540+
"""GitHub issue #387"""
1541+
a = np.add.reduce(np.zeros((2,1,2)), (0,1))
1542+
b = np.add.reduce(np.zeros((2,1,2)), 1)
1543+
assert_(a.flags.c_contiguous)
1544+
assert_(a.flags.f_contiguous)
1545+
assert_(b.flags.c_contiguous)
1546+
15311547
def test_object_array_self_reference(self):
15321548
# Object arrays with references to themselves can cause problems
15331549
a = np.array(0, dtype=object)

0 commit comments

Comments
 (0)
0