[Numpy-discussion] ufuncs on user-defined types in numarray

konrad.hinsen at laposte.net konrad.hinsen at laposte.net
Fri Dec 17 05:30:02 EST 2004

I am working on making ScientificPython 
(http://dirac.cnrs-orleans.fr/ScientificPython/) compatible with 
numarray. One problem I stumbled across is that one feature of Numeric 
seems to be absent from numarray: the possibility to call ufuncs with 
arguments of non-numeric types, leading to a corresponding method call.

As an illustration, the following example works fine with Numeric, but 
crashes with numarray:

from Numeric import sqrt
#from numarray import sqrt

class DummyValue:

     def __init__(self, string):
         self.string = string

     def __str__(self):
         return self.string

     def sqrt(self):
         return DummyValue('sqrt(%s)' % self.string)

x = DummyValue('x')
print sqrt(x)

Is this a bug or a feature? Is there another way to make ufuncs work 
with user-defined classes and types?

Konrad Hinsen
Laboratoire Léon 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: hinsen at llb.saclay.cea.fr

More information about the NumPy-Discussion mailing list