Numeric: fromfunction() performance

jsaul jsaul at gmx.de
Sat Oct 19 13:54:31 EDT 2002


* jsaul [2002-10-19 10:48]:
> i = Numeric.arange(1.*nf)
> q = Numeric.exp((-x1*i-1j*x2)*i)

I should have mentioned one annoying behaviour of Numeric.exp()
applied to an array containing "large negative" values: If the
real part of its argument becomes smaller than about -740, then an
"OverflowError: math range error" exception is raised. This is
certainly not intentional, as in case of an underflow, exp()
should evaluate to 0.0, as [c]math.exp() does, which is the only
behaviour that makes sense here.

This behaviour, which I consider a bug, requires the *explicit*
prevention of underflow. This is particularly annoying in a case
like the above, because it does not allow me to safely write

    q = Numeric.exp((-x1*i-1j*x2)*i)

because of x1*i**2 frequently becoming very large.
Thus I have to write something like

    q = Numeric.exp(maximum(-x1*i*i, -700.) -1j*x2*i)

instead, which adds considerable overhead. And this is not fancy
stuff, but just a good old Gaussian approaching zero!

The reason for the error is not clear to me, though. The GNU libm
function exp() does evaluate to 0.0 for very large negative
arguments (e.g. -1000.), in conformance with IEEE Std 1003.1-2001
and precessors. In case of underflow, errno is set to ERANGE,
fine. However, finite(exp(-1000.)) evaluates to 1, and I wouldn't
thus expect an error to be raised by check_array(), though I may
have overlooked something.

Cheers, jsaul
-- 
Que le gusta rrrodarrr la errre.



More information about the Python-list mailing list