Stefan Krah <stefan-use...@bytereef.org> added the comment: Nick Coghlan <rep...@bugs.python.org> wrote: > So I agree with Victor that 1-D bytes -> any shape/format and any > shape/format -> 1-D bytes should be allowed, but I think we should > hold off on allowing arbitrary transformations in a single step.
1-D bytes -> any shape/format would work if everyone agrees on the Numpy mailing list post that I linked to in an earlier message. [Summary: PyBUF_SIMPLE may downcast any C-contiguous array to unsigned bytes.] Otherwise a PyBUF_SIMPLE getbuffer call to the newly shaped memoryview would be required to fail, and these calls are almost certain to occur somewhere, e.g. in PyObject_AsWriteBuffer(). But then memoryview would also need a 'shape' parameter: m = memoryview(x, format='L', shape=[3, 4]) In that case, making it a method might indeed be more clear to underline that something extraordinary is going on: m = memoryview(x).cast(format='L', shape=[3, 4]) It also takes away a potential speed loss for regular uses. 1-D bytes would then be defined as 'b', 'B' and 'c', I presume? Being able to cast to 'c' would also solve certain memoryview index assignment problems that arise if we opt for strict typing as the struct module does. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue5231> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com