Stefan Krah <ste...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue34778>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to