[New-bugs-announce] [issue35845] Can't read a F-contiguous memoryview in physical order

Antoine Pitrou report at bugs.python.org
Mon Jan 28 15:51:37 EST 2019


New submission from Antoine Pitrou <pitrou at free.fr>:

This request is motivated in detail here:
https://github.com/python/peps/pull/883#issuecomment-458290745

In short: in C, when you have a Py_buffer, you can directly read the memory in whatever order you want (including physical order).  It is not possible in pure Python, though.  Somewhat unintuitively, memoryview.tobytes() as well as bytes(memoryview) read bytes in *logical* order, even though it flattens the dimensions and doesn't keep the original type.  Logical order is different from physical order for Fortran-contiguous arrays.

One possible way of alleviating this would be to offer a memoryview.transpose() method, similar to the Numpy transpose() method (see https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.transpose.html).

One could also imagine a memoryview.to_c_contiguous() method.

Or even: a memoryview.raw_memory() method, that would 1) flatten dimensions 2) cast to 'B' format 3) keep physical order.

----------
components: Interpreter Core
messages: 334491
nosy: pitrou, skrah
priority: normal
severity: normal
stage: needs patch
status: open
title: Can't read a F-contiguous memoryview in physical order
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35845>
_______________________________________


More information about the New-bugs-announce mailing list