[Numpy-discussion] ufuncs on user-defined types in numarray
Todd Miller
jmiller at stsci.edu
Fri Dec 17 07:10:12 CST 2004
On Fri, 2004-12-17 at 08:31, konrad.hinsen at laposte.net wrote:
> 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?
It's a missing feature.
> Is there another way to make ufuncs work with user-defined classes and types?
Not that I know of. How critical a feature is it? Do you have a work around?
numarray ufunc handling is in flux as I'm adding numarray support to
scipy. At some point, there's going to be a major ufunc consolidation,
and perhaps I can add this additional feature then.
Regards,
Todd
More information about the Numpy-discussion
mailing list