[Numpy-discussion] Questions about the array interface.

Scott Gilbert xscottg at yahoo.com
Fri Apr 8 11:06:04 EDT 2005

--- Tim Hochberg <tim.hochberg at cox.net> wrote:
> The point about not passing around the tuples probably being faster is a 
> good one. Another thought is that requiring tuples instead of general 
> sequences would make the helper faster (since one could use 
> *PyTuple_GET_**ITEM*, which I believe is much faster than 
> PySequence_GetItem). This would possibly shift more pain onto the 
> implementer of the object though. I suspect that the best strategy, 
> orthogonal to requiring all attributes or not, is to use PySequence_Fast 
> to get a fast sequence and work with that. This means that objects that 
> return tuples for strides, etc would run at maximum possible speed, 
> while other sequences would still work.

I hadn't seen this "fast" sequence stuff before.  Thanks for the pointer.

> Back to requiring attributes or not. I suspect that the fastest correct 
> way is to require all attributes, but allow them to be None, in which 
> case the default value is used. Then any errors are easily bubbled up 
> and a fast check for None choses whether to use the defaults or not.

How about saying that, for all the optional attributes, if they return None
that's to be treated the same way as if they weren't present at all?  In
other words, they're still optional, but people in the know would know that
returning None was probably faster...

More information about the NumPy-Discussion mailing list