[Python-Dev] Allocation of shape and strides fields in Py_buffer

Travis Oliphant oliphant.travis at ieee.org
Wed Dec 10 16:54:01 CET 2008

Antoine Pitrou wrote:
> Alexander Belopolsky <alexander.belopolsky <at> gmail.com> writes:
>> I did not follow numpy development for the last year or more, so I
>> won't qualify as "the numpy folks," but my understanding is that numpy
>> does exactly what Nick recommended: the viewed object owns shape and
>> strides just as it owns the data.  The viewing object increases the
>> reference count of the viewed object and thus assures that data, shape
>> and strides don't go away prematurely.
> That doesn't work if e.g. you take a slice of a memoryview object, since the
> shape changes in the process.
> See http://bugs.python.org/issue4580

I think there was some confusion about how to support slicing with 
memory view objects.  I remember thinking about it but not getting to 
the code to write it.   The memory object is both an exporter and 
consumer of the buffer protocol.  It can have it's own semantics about 
storing shape and strides information separate from the buffer protocol.

The memory view object needs some way to translate the information it 
gets from the underlying object to the consumer of the information.

My thinking is that the memory view object itself will allocate shape 
and strides information as it needs it.


More information about the Python-Dev mailing list