[Numpy-discussion] metadata and metabehavior for arrays (for scipy.base or Numeric3)

konrad.hinsen at laposte.net konrad.hinsen at laposte.net
Thu Apr 7 00:24:04 EDT 2005

On 06.04.2005, at 18:06, Sébastien de Menten wrote:

> Do you think it is possible to integrate a similar mechanism in array  
> functions (like searchsorted, argmax, ...).

That is less obvious. A generic interface for ufuncs is possible  
because of the uniform calling interface. Actually, there should  
perhaps be two ufunc application methods, for unary and for binary  
ufuncs. The other array functions each have a peculiar calling pattern.  
They can certainly be implemented through delegation to a method, but  
that would be one method per function. But I think that is inevitable  
if you want full flexibility.

> If we can register functions taking one array as argument within  
> scipy.base and let it dispatch those functions as ufunc, we could use  
> a similar strategy.
> For instance, let "sort" and "argmax" be registered as gfunc (general  
> functions on an array <> ufunc), then any class that would like to  
> overide any of them could do it too with the same trick Konrad exposed  
> here above.

Does that make sense in practice? Suppose you write a class that  
implements tables, i.e. arrays plus axis labels. You would want sort()  
to return an object of the same class, but argmax() to return a plain  
integer. The generic gfunc handler could do little else than dispatch  
on the name of the gfunc.

> Konrad, do you think it is tricky to have a prototype of your  
> suggestion (i.e. the modification does not need a full understanding  
> of Numeric and you can locate it approximately in the source code) ?

I haven't looked at the Numeric code in ages, but my guess is that the  
ufunc part should be easy to do, as it is just a modification of a  
generic handler that already exists.

Konrad Hinsen
Laboratoire Leon Brillouin, CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: khinsen at cea.fr

More information about the NumPy-Discussion mailing list