The Python C API includes a function, PyBuffer_IsContiguous
for verifying if the returned buffer is contiguous.
How to construct an object such as that function returns a false value?
Here are a few examples that do not work (all tried with Python 3.10):
a = b"123"
b = b"456"
c = bytearray(a[0:1] + b[0:1])
# This one returns a contiguous buffer even if id(b[0]) == id(c[1])
# Who does the copying? Why? Any rules?
np.zeros((2, 3)).T
# PyObject_GetBuffer fails instead of returning a strided array
memoryview(b"123")[::2]
# PyObject_GetBuffer fails instead of returning a strided array