[Numpy-discussion] Latest Array-Interface PEP

Travis Oliphant oliphant at ee.byu.edu
Thu Jan 4 15:49:32 CST 2007


Christopher Barker wrote:
> Travis,
>
> First, thanks for doing this -- Python really needs it!
>  >  While this approach
>   
>>     works, it requires attribute lookups which can be expensive when
>>     sharing many small arrays.  
>>     
>
> Ah, I do like reducing that overhead -- I know I use arrays a lot for 
> small data sets too, so that overhead can be significant.
>
> I'm not well qualified to review the tech details, but to make sure I 
> have this right:
>
>   
>>     static PyObject* bf_getarrayview (PyObject *obj)
>>
>>     This function must return a new reference to a PyArrViewObject
>>     which contains the details of the array information exposed by the
>>     object.  If failure occurs, then NULL is returned and an exception 
>>     set.  
>>     
>
> So If I have some C code that wants to use any array passed in, I can 
> just call:
>
> bf_getarrayview (obj)
>   
Yes you could call this (but you would call it from the type object like 
this

obj->ob_type->tp_as_buffer->bf_getarrayview(obj)

Or more likely (and I should add this to the C-API) you would call.

PyArrayView_FromObject(obj)

which does this under the covers.
> and if it doesn't return NULL, I have a valid array that I can query to 
> see if it fits what I'm expecting.
>
> Have I got that right?
>
> If so, this would be great.
>
> By the way,, how compatible is this with the existing buffer protocol?
>   
It's basically orthogonal.  In other-words, if you defined the array 
view protocol you would not need the buffer protocol at all.  But you 
could easily define both.

-Travis



More information about the Numpy-discussion mailing list