Author ncoghlan
Recipients jcon, kermode, mark.dickinson, ncoghlan, petri.lehtinen, pitrou, pv, rupole, skrah, teoliphant, vstinner
Date 2011-07-05.12:47:13
SpamBayes Score 1.44458e-11
Marked as misclassified No
Message-id <1309870034.21.0.937094452819.issue10181@psf.upfronthosting.co.za>
In-reply-to
Content
It took me a bit of thinking, but I figured out why the "contiguous" flags imply STRIDES. A quick recap of all the flags:

WRITABLE -> error if can't support write access

FORMAT -> request format info in Py_buffer struct. Should never error, but report unsigned bytes if not requested

ND -> requests shape info in Py_buffer struct. Report 1 dimensional if not requested. Error if data is not C contiguous (as STRIDES is required to handle any non-C contiguous cases).

STRIDES -> requests shape and stride info. Error if correct buffer access requires stride support and this flag is not passed.

C_CONTIGUOUS/F_CONTIGUOUS/ANY_CONTIGUOUS -> variants that also request shape and stride info but are limited to handling C contiguous memory, Fortran contiguous memory or either.

INDIRECT -> requests shape and suboffset info. Error if correct buffer access requires suboffset support and this flag is not passed.

So, to address the specific confusion, the basic "STRIDES" request just says "give me the strides info" and I can deal with whatever you give me. The "CONTIGUOUS" variants say "give me the strides info, but I can only cope with certain layouts, so error if you can't provide them". "ND" is a way to say "I can copy with multiple dimensions, but only the C version without using strides info"

Suppose we have a 3x4 array of unsigned bytes (i.e. 12 bytes of data). In C format, the strides info would be [4, 1] (buf[0][0] and buf[0][1] are adjacent in memory, while buf[0][0] and buf[1][0] are 4 bytes apart). In FORTRAN format that layout is different, so the strides info would be [1, 3] (and now buf[0][0] and buf[1][0] are adjacent while buf[0][0] and buf[0][1] are 3 bytes apart).

The difference between ND and C_CONTIGUOUS is that the latter asks for both the shape and strides fields in the Py_buffer object to be populated while the former only requests shape information.
History
Date User Action Args
2011-07-05 12:47:14ncoghlansetrecipients: + ncoghlan, teoliphant, mark.dickinson, rupole, kermode, pitrou, vstinner, pv, skrah, jcon, petri.lehtinen
2011-07-05 12:47:14ncoghlansetmessageid: <1309870034.21.0.937094452819.issue10181@psf.upfronthosting.co.za>
2011-07-05 12:47:13ncoghlanlinkissue10181 messages
2011-07-05 12:47:13ncoghlancreate