Commit 34ab658b authored by Clemens's avatar Clemens Committed by Stefan Behnel

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

Fixes https://github.com/cython/cython/issues/2093
parent 1910ad2b
......@@ -347,18 +347,22 @@ static int __Pyx_ValidateAndInit_memviewslice(
}
/* Check axes */
for (i = 0; i < ndim; i++) {
spec = axes_specs[i];
if (unlikely(!__pyx_check_strides(buf, i, ndim, spec)))
goto fail;
if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec)))
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)))
goto fail;
if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec)))
goto fail;
}
/* Check contiguity */
if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag)))
goto fail;
}
/* 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,
new_memview != NULL) == -1)) {
......
......@@ -62,3 +62,25 @@ def test_zero_sized(array):
"""
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment