[Numpy-discussion] Numarray feature request: supporting the buffer interface

Prabhu Ramachandran prabhu_r at users.sf.net
Fri Jan 7 09:55:10 CST 2005

>>>>> "TM" == Todd Miller <jmiller at stsci.edu> writes:

    TM> On Fri, 2005-01-07 at 09:19, Chris Perkins wrote:
    >> On Fri, 7 Jan 2005 10:01:37 +0530, Prabhu Ramachandran
    >> <prabhu_r at users.sf.net> wrote:
    >> >
    >> > I noticed that numarray does not support this interface.  My
    >> > feature request is that numarray arrays also support this
    >> > buffer interface (if possible).
    >> I second this request.

    TM> Without looking at code, my guess is that the C source level
    TM> compatibility of numarray with Numeric will enable a "direct
    TM> graft" of the buffer protocol code from Numeric to numarray.
    TM> I think it will be easy... but...

    TM> numarray has a concept of "misbehaved arrays", i.e.  arrays in
    TM> the binary format of another platform and therefore
    TM> byte-swapped, or arrays spread across records and therefore
    TM> possibly noncontiguous or misaligned.  I think these buffers
    TM> are likely unusable so providing access to them is a mistake.
    TM> Misbehaved arrays probably don't arise in the work of most
    TM> users, but they are a possibility that has to be accounted
    TM> for.

    TM> For cases of misbehaved arrays, I think raising a ValueError
    TM> exception is necessary.  How does that sound?

I think that sounds reasonable.  In my particular use case I always
flatten (ravel) the array before using it as a buffer.  I guess that
in cases where the array is non-contiguous or misaligned a copy of the
data is made on ravel so these would not be a problem for me.  For
misbehaved arrays, a ValueError with a decent error message would be

Anyway, thanks for considering the feature request!


More information about the Numpy-discussion mailing list