[issue34778] Memoryview for column-major (f_contiguous) arrays from bytes impossible to achieve
Stefan Krah
report at bugs.python.org
Sat Feb 2 05:23:55 EST 2019
Stefan Krah <stefan at bytereef.org> added the comment:
It seems reasonable to support f-contiguous for cast() and tobytes().
For tobytes() it's implemented in the issue that Antoine linked to.
General support for strides in cast(), i.e. a zero-copy view for
non-contiguous arrays does not seem possible because buf.ptr is
moved around. Even NumPy does not support that:
>>> x = np.array([1,2,3])
>>> x.view('B')
array([1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
0, 0], dtype=uint8)
>>>
>>> x[::-1].view('B')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: To change to a dtype of a different size, the array must be C-contiguous
>>>
>>> y = x.astype('B')
>>> y.flags['OWNDATA'] # It's a copy.
True
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34778>
_______________________________________
More information about the Python-bugs-list
mailing list