Skip to content
Snippets Groups Projects
Commit d9bf25965cee authored by Clemens's avatar Clemens
Browse files

Always consider 0-sized arrays as C- and F-contiguous (GH-3728)

parent dccd25ac322e
No related branches found
No related tags found
No related merge requests found
......@@ -347,6 +347,9 @@
}
/* Check axes */
if (buf->len > 0) {
// 0-sized arrays do not undergo these checks since their strides are
// irrelevant and they are always both C- and F-contiguous.
for (i = 0; i < ndim; i++) {
spec = axes_specs[i];
if (unlikely(!__pyx_check_strides(buf, i, ndim, spec)))
......@@ -358,6 +361,7 @@
/* Check contiguity */
if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag)))
goto fail;
}
/* Initialize */
if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice,
......
......@@ -62,3 +62,25 @@
"""
cdef double[::1] a = array
return a
def test_zero_sized_multidim_ccontig(array):
"""
>>> contig = np.ascontiguousarray(np.zeros((4,4,4))[::2, 2:2, ::2])
>>> _ = test_zero_sized_multidim_ccontig(contig)
>>> a = np.zeros((4,4,4))[::2, 2:2, ::2]
>>> if NUMPY_HAS_RELAXED_STRIDES: _ = test_zero_sized_multidim_ccontig(a)
"""
cdef double[:, :, ::1] a = array
return a
def test_zero_sized_multidim_fcontig(array):
"""
>>> contig = np.ascontiguousarray(np.zeros((4,4,4))[::2, 2:2, ::2])
>>> _ = test_zero_sized_multidim_fcontig(contig)
>>> a = np.zeros((4,4,4))[::2, 2:2, ::2]
>>> if NUMPY_HAS_RELAXED_STRIDES: _ = test_zero_sized_multidim_fcontig(a)
"""
cdef double[::1, :, :] a = array
return a
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment