[Numpy-discussion] 2 bugs related to isinf and isfinite generate crazy warnings
Charles R Harris
charlesr.harris@gmail....
Wed Jun 2 21:12:17 CDT 2010
On Wed, Jun 2, 2010 at 7:11 PM, Eric Firing <efiring@hawaii.edu> wrote:
> http://www.mail-archive.com/numpy-discussion@scipy.org/msg23912.html
>
> On some systems--but evidently not for most numpy users, or there would
> have been a steady stream of screams--the appearance of np.inf in any
> call to np.isfinite or np.isinf yields this:
>
> In [1]:import numpy as np
>
> In [2]:np.isinf(np.inf)
> Warning: invalid value encountered in isinf
> Out[2]:True
>
>
> This generates streams of warnings if np.isinf or np.isfinite is applied
> to an array with many inf values.
>
> The problem is a combination of two bugs:
>
> 1) When building with setup.py, but perhaps not with scons (which I
> haven't tried yet), NPY_HAVE_DECL_ISFINITE and friends are never
> defined, even though they should be--this is all on ubuntu 10.4, in my
> case, and isfinite and isinf most definitely are in math.h. It looks to
> me like the only mechanism for defining these is in SConstruct.
>
> 2) So, with no access to the built-in isinf etc., npy_math.h falls back
> on the compact but slow macros that replace the much nicer ones that
> were in numpy a year or so ago. Here is the relevant part of npy_math.h:
>
> #ifndef NPY_HAVE_DECL_ISFINITE
> #define npy_isfinite(x) !npy_isnan((x) + (-x))
> #else
> #define npy_isfinite(x) isfinite((x))
> #endif
>
> #ifndef NPY_HAVE_DECL_ISINF
> #define npy_isinf(x) (!npy_isfinite(x) && !npy_isnan(x))
> #else
> #define npy_isinf(x) isinf((x))
> #endif
>
> isinf calls isfinite, and isfinite calls isnan(x-x). If x is inf, this
> generates a nan, so the return value is correct--but generating that nan
> set the INVALID flag, hence the warning.
>
> Sorry I don't have a patch to offer.
>
>
I'm guessing that the problem is that in gcc isinf is a macro, the relevant
functions are actually __isinff, __isinf, and __isinfl.
The library itself yields:
$[charris@ubuntu lib]$ nm -D libc.so.6 | grep isinf
0000000000032d10 T __isinf
0000000000033110 T __isinff
0000000000033420 T __isinfl
0000000000032d10 W isinf
0000000000033110 W isinff
0000000000033420 W isinfl
Where the symbols without the underscores are weak. I have no idea what the
implications of that are ;)
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100602/f9b734c1/attachment.html
More information about the NumPy-Discussion
mailing list