[Numpy-discussion] -ffast-math

Dan Goodman dg.gmane at thesamovar.net
Sun Dec 1 18:14:57 EST 2013


Dan Goodman <dg.gmane <at> thesamovar.net> writes:
...
> I got around 5x slower. Using numexpr 'dumbly' (i.e. just putting the
> expression in directly) was slower than the function above, but doing a
> hybrid between the two approaches worked well:
> 
> def timefunc_numexpr_smart():
>     _sin_term = sin(2.0*freq*pi*t)
>     _exp_term = exp(-dt/tau)
>     _a_term = (_sin_term-_sin_term*_exp_term)
>     _const_term = -b*_exp_term + b
>     v[:] = numexpr.evaluate('a*_a_term+v*_exp_term+_const_term')
>     #numexpr.evaluate('a*_a_term+v*_exp_term+_const_term', out=v)
> 
> This was about 3.5x slower than weave. If I used the commented out final
> line then it was only 1.5x slower than weave, but it also gives wrong
> results. I reported this as a bug in numexpr a long time ago but I guess it
> hasn't been fixed yet (or maybe I didn't upgrade my version recently).

I just upgraded numexpr to 2.2 where they did fix this bug, and now the
'smart' numexpr version runs exactly as fast as weave (so I guess there were
some performance enhancements in numexpr as well).

Fantastic!

Dan




More information about the NumPy-Discussion mailing list