* Fix buffer protocol implementation According to the buffer protocol, `ndim` is a _required_ field [1], and should always be set correctly. Additionally, `shape` should be set if flags includes `PyBUF_ND` or higher [2]. The current implementation only set those fields if flags was `PyBUF_STRIDES`. [1] https://docs.python.org/3/c-api/buffer.html#request-independent-fields [2] https://docs.python.org/3/c-api/buffer.html#shape-strides-suboffsets * Apply suggestions from review * Obey contiguity requests for buffer protocol If a contiguous buffer is requested, and the underlying buffer isn't, then that should raise. This matches NumPy behaviour if you do something like: ``` struct.unpack_from('5d', np.arange(20.0)[::4]) # Raises for contiguity ``` Also, if a buffer is contiguous, then it can masquerade as a less-complex buffer, either by dropping strides, or even pretending to be 1D. This matches NumPy behaviour if you do something like: ``` a = np.full((3, 5), 30.0) struct.unpack_from('15d', a) # --> Produces 1D tuple from 2D buffer. ``` * Handle review comments * Test buffer protocol against NumPy * Also check PyBUF_FORMAT results
| Name |
Last commit
|
Last Update |
|---|---|---|
| .. | ||
| detail | Loading commit data... | |
| eigen | Loading commit data... | |
| stl | Loading commit data... | |
| attr.h | Loading commit data... | |
| buffer_info.h | Loading commit data... | |
| cast.h | Loading commit data... | |
| chrono.h | Loading commit data... | |
| common.h | Loading commit data... | |
| complex.h | Loading commit data... | |
| eigen.h | Loading commit data... | |
| embed.h | Loading commit data... | |
| eval.h | Loading commit data... | |
| functional.h | Loading commit data... | |
| gil.h | Loading commit data... | |
| gil_safe_call_once.h | Loading commit data... | |
| iostream.h | Loading commit data... | |
| numpy.h | Loading commit data... | |
| operators.h | Loading commit data... | |
| options.h | Loading commit data... | |
| pybind11.h | Loading commit data... | |
| pytypes.h | Loading commit data... | |
| stl.h | Loading commit data... | |
| stl_bind.h | Loading commit data... | |
| type_caster_pyobject_ptr.h | Loading commit data... | |
| typing.h | Loading commit data... | |
| warnings.h | Loading commit data... |