[Numpy-discussion] Alternate C-only array protocol for speed?

David M. Cooke cookedm at physics.mcmaster.ca
Fri Apr 8 14:52:02 CDT 2005


Travis Oliphant <oliphant at ee.byu.edu> writes:

> David M. Cooke wrote:
>
>>It seems that people are worried about speed of the attribute-based
>>array interface when using small arrays in C.
>>
>>
> I think we are talking about here an *array protocol*   (i.e. like the
> buffer protocol and sequence
> protocol).
>
> So far we have just described the Python level interface.  I would
> like to see an array protocol added (perhaps to the buffer protocol
> table).  This could be done just as David describes --- we don't even
> need to use the C-pointer (just return a void *pointer which has a
> version as the first entry).

The purpose of the CObject was to make it possible to pass it through
Python (through the attribute access).

> I think this is how the C-level should be handled, I think.  Yes, it
> does not require changes to Python to implement the __array_c__
> attribute.  But, ultimately, it would be better if we used the C-level
> protocol concept that Python already uses for other objects.

Ah, ok, so you'd have a slot in the type object (like the
number, sequence, or buffer protocols), with the appropriate (C-level)
functions. This would require it to be in the Python core, though, and
would only work for a new version of Python. Alternatively, you have a
special attribute/method that returns an object with the right C API
-- much like CObjects are used for wrapping Numeric's C API.

I would really like to see something working at the C level (so you're
not passing dimensions back-and-forth as Python tuples with Python
ints), but the Python-level array interface you've proposed will work
for now.

This should be revisited once people are using the new array
interface, and we have an idea of how it's being used, and the
performance costs.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca




More information about the Numpy-discussion mailing list