Issue #22445: PyBuffer_IsContiguous() now implements precise contiguity

tests, compatible with NumPy's NPY_RELAXED_STRIDES_CHECKING compilation
flag.  Previously the function reported false negatives for corner cases.
This commit is contained in:
Stefan Krah 2015-02-01 14:53:54 +01:00
parent a5e1dbef14
commit 363af44a4a
4 changed files with 90 additions and 29 deletions

View file

@ -1007,6 +1007,7 @@ class TestBufferProtocol(unittest.TestCase):
# shape, strides, offset
structure = (
([], [], 0),
([1,3,1], [], 0),
([12], [], 0),
([12], [-1], 11),
([6], [2], 0),
@ -1078,6 +1079,18 @@ class TestBufferProtocol(unittest.TestCase):
self.assertRaises(BufferError, ndarray, ex, getbuf=PyBUF_ANY_CONTIGUOUS)
nd = ndarray(ex, getbuf=PyBUF_SIMPLE)
# Issue #22445: New precise contiguity definition.
for shape in [1,12,1], [7,0,7]:
for order in 0, ND_FORTRAN:
ex = ndarray(items, shape=shape, flags=order|ND_WRITABLE)
self.assertTrue(is_contiguous(ex, 'F'))
self.assertTrue(is_contiguous(ex, 'C'))
for flags in requests:
nd = ndarray(ex, getbuf=flags)
self.assertTrue(is_contiguous(nd, 'F'))
self.assertTrue(is_contiguous(nd, 'C'))
def test_ndarray_exceptions(self):
nd = ndarray([9], [1])
ndm = ndarray([9], [1], flags=ND_VAREXPORT)