[Numpy-discussion] ndarray and the buffer protocol

Dag Sverre Seljebotn dagss@student.matnat.uio...
Thu Jul 9 15:26:29 CDT 2009


>> Hello all,
>>
>> (resending for the Nth time, as the previous attempts
>>  didn't make it to the list)
>>
>> I'm new to this list (and numpy is mostly new to me :-).
>>
>> Using python 2.6 and numpy 1.3.
>>
>> My plan is to write some C extensions that will perform
>> rather specialised processing on multichannel digital audio
>> data stored stored in numpy arrays.
>>
>> Sinc 2.6 python has a new buffer protocol, and referring
>> to this, the numpy website states rather fuzzily:
>>
>>   Of course, numpy makes a good interoperation library to
>>   support the buffer protocol. Numpy can both consume and
>>   produce protocol-supporting objects. A numpy ndarray can
>>   be constructed as a view of an object supporting the
>>   buffer protocol, and a numpy ndarray supports buffer
>>   object views of its data.
>>
>> I'd want the C code to be based on using the new buffer
>> protocol - everything else is marked as 'deprecated', also
>> in the numpy docs.
>>
>> But it remains quite unclear if numpy 1.3 does or does not
>> support this, and if yes, how.
>
> It does not support the new buffer protocol -- the stuff on the web page
> refers to the old buffer protocol.
>
> You might consider using Cython for at least smaller parts of your work --
> it has support for the new buffer protocol as well as emulating it for
> NumPy arrays for any NumPy version.
>
> http://wiki.cython.org/enhancements/buffer
>
> As well as Cython/Includes/numpy.pxd within the Cython distribution.
>
> A short look at numpy.pxd will tell you how to write NumPy-specific access
> to get the same information that the buffer protocol would have given you,
> if you want to stay in C.

Looking closer at the webpage I must say I'm really puzzled too now -- it
says rather unambigiously that it should work; but at least I can't get it
to work either (under Py2.6).

Somebody closer to it than me should really comment...

Dag Sverre



More information about the NumPy-Discussion mailing list