I've just ported a Numeric+Python program from windows to linux and I'm generating floating point exceptions in the linux version which did not occur in windows. I'm trying to generate a gaussian distribution by: Input = Numeric.arange(-1024,1024)/20.0 Output = Numeric.exp(-(Input**2)) At the edges of the distribution the largish negative arguments cause the f.p. exception and prevent calculation of the entire array. On windows the underflow errors are presumably rounded down to 0.0 automatically. Is it possible to get this behaviour on linux/ix86? Anyone got any suggestions on a workarround for this? I see the numpy docs suggest using Masked Arrays, but since I don't know in advance which array items will generate the exceptions, I don't know which items to mask. Can the MA module generate an array mask based on f.p. exceptions from a calculation? any suggestions would be much appreciated. Bryan -- Bryan Cole Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom. tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382
OK, I've worked out how to do this with MA. I mask the Numeric array input to MA.exp() using MA.masked_outside( ... ,-700, 700) then convert the result back to a Numeric array using MA.filled( ..., 0.0) then continue as normal. I'm still interested if there's a more elegant approach. Bryan On Fri, 2002-08-09 at 16:52, bryan cole wrote:
I've just ported a Numeric+Python program from windows to linux and I'm generating floating point exceptions in the linux version which did not occur in windows.
I'm trying to generate a gaussian distribution by:
Input = Numeric.arange(-1024,1024)/20.0 Output = Numeric.exp(-(Input**2))
At the edges of the distribution the largish negative arguments cause the f.p. exception and prevent calculation of the entire array.
On windows the underflow errors are presumably rounded down to 0.0 automatically. Is it possible to get this behaviour on linux/ix86?
Anyone got any suggestions on a workarround for this? I see the numpy docs suggest using Masked Arrays, but since I don't know in advance which array items will generate the exceptions, I don't know which items to mask. Can the MA module generate an array mask based on f.p. exceptions from a calculation?
any suggestions would be much appreciated.
Bryan
-- Bryan Cole Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom. tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382
------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion -- Bryan Cole Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom. tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382
bryan cole <bryan.cole@teraview.co.uk> writes:
I'm trying to generate a gaussian distribution by:
Input = Numeric.arange(-1024,1024)/20.0 Output = Numeric.exp(-(Input**2))
At the edges of the distribution the largish negative arguments cause the f.p. exception and prevent calculation of the entire array.
On windows the underflow errors are presumably rounded down to 0.0 automatically. Is it possible to get this behaviour on linux/ix86?
Yes, rebuild the Python interpreter (not NumPy!) and add the compilation option "-lieee". Alternatively, download and install the current development version of Python from the CVS server (I haven't tried it, but it is supposed to fix this problem as well). Ultimately the problem is in the C standard library. On some platforms it signals underflow as an overflow error, on others it doesn't. Python thus has to get work around such problems in a platform-specific way. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais -------------------------------------------------------------------------------
participants (2)
-
bryan cole
-
Konrad Hinsen