[Numpy-discussion] __float__ is not called when instance can not evaluated.
Sebastian Krämer
basti.kr@gmail....
Tue May 6 14:03:14 CDT 2008
Hi all,
I'm currently working on a function that converts a
sympy (http://code.google.com/p/sympy) expression to a lambda-function.
In this lambda-function all sympy builtin functions are replaced by
numpy functions, since they are faster.
Now it may happen that users pass sympy-symbols like pi to these lambda
functions and so it is possible that numpy-functions get these symbols.
The same functionality is implemented using python's math module, and it
works because the math functions call the __float__ method and therefor
get a number they can work with.
However, numpy doesn't do this, it only looks if there is a method with
the same name as the called function.
e.g:
>> numpy.cos(sympy.pi)
<type 'exceptions.AttributeError'>: cos
whereas:
>> math.cos(sympy.pi)
-1.0
Would it be possible to change numpys behaviour so that x.__float__() is
tried after x.cos() has failed? Or are there any other possible
solutions?
Thanks in advance,
Sebastian
More information about the Numpy-discussion
mailing list