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

Todd Miller jmiller at stsci.edu
Fri Jan 7 06:45:04 CST 2005

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.
> Note that numarray arrays have a member called "_data" that does
> support the buffer interface.  I have been using code like this for a
> while (pseudocode):
> def asBuffer(a):
>     if a is a numarray array:
>         return a._data
>     elif a is a Numeric array:
>         return a
>     else: ... do something else
> But it would be nice if the numarray array supported the buffer
> interface directly. I have no idea how hard or easy this would be to
> do.

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

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

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


More information about the Numpy-discussion mailing list