
I am seeing a problem on Solaris since I upgraded to svn HEAD. np.isinf does not handle np.inf. See ipython session below. I am not seeing this problem w/ HEAD on an ubuntu linux box I tested on In [1]: import numpy as np In [2]: np.__version__ Out[2]: '2.0.0.dev8480' In [3]: x = np.inf np.inf np.info np.infty In [3]: x = np.inf In [4]: np.isinf(x) Warning: invalid value encountered in isinf Out[4]: True In [5]: np.seter np.seterr np.seterrcall np.seterrobj In [5]: np.seterr(all='raise') Out[5]: {'over': 'print', 'divide': 'print', 'invalid': 'print', 'under': 'ignore'} In [6]: np.isinf(x) --------------------------------------------------------------------------- FloatingPointError Traceback (most recent call last) /home/titan/johnh/<ipython console> FloatingPointError: invalid value encountered in isinf In [7]: !uname -a SunOS udesktop191 5.10 Generic_139556-08 i86pc i386 i86pc In [43]: !gcc --version gcc (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath) Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Posted on tracker: http://projects.scipy.org/numpy/ticket/1547

On 07/15/2010 04:54 AM, John Hunter wrote:
I am seeing a problem on Solaris since I upgraded to svn HEAD. np.isinf does not handle np.inf. See ipython session below. I am not seeing this problem w/ HEAD on an ubuntu linux box I tested on
In [1]: import numpy as np
In [2]: np.__version__ Out[2]: '2.0.0.dev8480'
In [3]: x = np.inf np.inf np.info np.infty
In [3]: x = np.inf
In [4]: np.isinf(x) Warning: invalid value encountered in isinf Out[4]: True
In [5]: np.seter np.seterr np.seterrcall np.seterrobj
In [5]: np.seterr(all='raise') Out[5]: {'over': 'print', 'divide': 'print', 'invalid': 'print', 'under': 'ignore'}
In [6]: np.isinf(x) --------------------------------------------------------------------------- FloatingPointError Traceback (most recent call last)
/home/titan/johnh/<ipython console>
FloatingPointError: invalid value encountered in isinf
In [7]: !uname -a SunOS udesktop191 5.10 Generic_139556-08 i86pc i386 i86pc
In [43]: !gcc --version gcc (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath) Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Posted on tracker:
John, This is related to this thread: http://www.mail-archive.com/numpy-discussion@scipy.org/msg25796.html The first of the two bugs I noted was fixed; you are seeing the second. Eric
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Thu, 15 Jul 2010 09:54:12 -0500, John Hunter wrote: [clip]
In [4]: np.isinf(x) Warning: invalid value encountered in isinf Out[4]: True
As far as I know, isinf has always created NaNs -- since 2006 it has been defined on "unsupported" platforms as (!isnan((x)) && isnan((x)-(x))) I'll replace it by the obvious ((x) == NPY_INFINITY || (x) == -NPY_INFINITY) which is true only for +-inf, and cannot raise any FPU exceptions. -- Pauli Virtanen

On 07/15/2010 11:45 AM, Pauli Virtanen wrote:
Thu, 15 Jul 2010 09:54:12 -0500, John Hunter wrote: [clip]
In [4]: np.isinf(x) Warning: invalid value encountered in isinf Out[4]: True
As far as I know, isinf has always created NaNs -- since 2006 it has been defined on "unsupported" platforms as
(!isnan((x))&& isnan((x)-(x)))
I'll replace it by the obvious
((x) == NPY_INFINITY || (x) == -NPY_INFINITY)
which is true only for +-inf, and cannot raise any FPU exceptions.
Is it certain that the Solaris compiler lacks isinf? Is it possible that it has it, but it is not being detected? Eric

On Thu, Jul 15, 2010 at 7:11 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:14 PM, Eric Firing <efiring@hawaii.edu> wrote:
Is it certain that the Solaris compiler lacks isinf? Is it possible that it has it, but it is not being detected?
Just to clarify, I'm not using the sun compiler, but gcc-3.4.3 on solaris x86
Correction: the version of gcc I compiled numpy with is different than the one in my default path. The version I compiled numpy with is
/opt/app/g++lib6/gcc-4.2/bin/gcc --version gcc (GCC) 4.2.2
running on solaris 5.10 JDH

On Thu, Jul 15, 2010 at 6:11 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:14 PM, Eric Firing <efiring@hawaii.edu> wrote:
Is it certain that the Solaris compiler lacks isinf? Is it possible that it has it, but it is not being detected?
Just to clarify, I'm not using the sun compiler, but gcc-3.4.3 on solaris x86
Might be related to this thread<http://thread.gmane.org/gmane.comp.python.numeric.general/38298>. What version of numpy are you using? Chuck

On Thu, Jul 15, 2010 at 7:27 PM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:11 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:14 PM, Eric Firing <efiring@hawaii.edu> wrote:
Is it certain that the Solaris compiler lacks isinf? Is it possible that it has it, but it is not being detected?
Just to clarify, I'm not using the sun compiler, but gcc-3.4.3 on solaris x86
Might be related to this thread. What version of numpy are you using?
svn HEAD (2.0.0.dev8480) After reading the thread you suggested, I tried forcing the CFLAGS=-DNPY_HAVE_DECL_ISFINITE flag to be set, but this is apparently a bad idea for my platform... File "/home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/__init__.py", line 5, in ? import multiarray ImportError: ld.so.1: python: fatal: relocation error: file /home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/multiarray.so: symbol isfinite: referenced symbol not found so while I think my bug is related to that thread, I don't see anything in that thread to help me fix my problem. Or am I missing something?

On Thu, Jul 15, 2010 at 6:42 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 7:27 PM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:11 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:14 PM, Eric Firing <efiring@hawaii.edu>
wrote:
Is it certain that the Solaris compiler lacks isinf? Is it possible that it has it, but it is not being detected?
Just to clarify, I'm not using the sun compiler, but gcc-3.4.3 on solaris x86
Might be related to this thread. What version of numpy are you using?
svn HEAD (2.0.0.dev8480)
After reading the thread you suggested, I tried forcing the
CFLAGS=-DNPY_HAVE_DECL_ISFINITE
flag to be set, but this is apparently a bad idea for my platform...
File "/home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/__init__.py", line 5, in ? import multiarray ImportError: ld.so.1: python: fatal: relocation error: file /home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/multiarray.so: symbol isfinite: referenced symbol not found
so while I think my bug is related to that thread, I don't see anything in that thread to help me fix my problem. Or am I missing something? ____
In the thread there is a way to check if isinf is in the library. You can also grep through the python include files where its presence should be set, that's in /usr/include/python2.6/pyconfig.h on my system. If it's present, then you should be able to apply David's fix<http://projects.scipy.org/numpy/changeset/8455>which amount to just a few lines. Chuck

On Thu, Jul 15, 2010 at 6:55 PM, Charles R Harris <charlesr.harris@gmail.com
wrote:
On Thu, Jul 15, 2010 at 6:42 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 7:27 PM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:11 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:14 PM, Eric Firing <efiring@hawaii.edu>
wrote:
Is it certain that the Solaris compiler lacks isinf? Is it possible that it has it, but it is not being detected?
Just to clarify, I'm not using the sun compiler, but gcc-3.4.3 on solaris x86
Might be related to this thread. What version of numpy are you using?
svn HEAD (2.0.0.dev8480)
After reading the thread you suggested, I tried forcing the
CFLAGS=-DNPY_HAVE_DECL_ISFINITE
flag to be set, but this is apparently a bad idea for my platform...
File "/home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/__init__.py", line 5, in ? import multiarray ImportError: ld.so.1: python: fatal: relocation error: file
/home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/multiarray.so: symbol isfinite: referenced symbol not found
so while I think my bug is related to that thread, I don't see anything in that thread to help me fix my problem. Or am I missing something? ____
In the thread there is a way to check if isinf is in the library. You can also grep through the python include files where its presence should be set, that's in /usr/include/python2.6/pyconfig.h on my system. If it's present, then you should be able to apply David's fix<http://projects.scipy.org/numpy/changeset/8455>which amount to just a few lines.
PS, of course we should fix the macro also. Since the bit values of +/- infinity are known we should be able to define them as constants using a couple of ifdefs and unions. I believe SUN has quad precision so we might need to check the layout, but the usual case seems to be zero mantissa, maximum exponent, and the sign. Not a number differs in that the mantissa is non-zero. I believe there are two versions of nans, signaling and non-signaling, but in any case it doesn't look to me like it should be impossible to simply have all those values as numpy constants like pi and e. Chuck

On Thu, Jul 15, 2010 at 7:09 PM, Charles R Harris <charlesr.harris@gmail.com
wrote:
On Thu, Jul 15, 2010 at 6:55 PM, Charles R Harris < charlesr.harris@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:42 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 7:27 PM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:11 PM, John Hunter <jdh2358@gmail.com>
wrote:
On Thu, Jul 15, 2010 at 6:14 PM, Eric Firing <efiring@hawaii.edu>
wrote:
Is it certain that the Solaris compiler lacks isinf? Is it possible that it has it, but it is not being detected?
Just to clarify, I'm not using the sun compiler, but gcc-3.4.3 on solaris x86
Might be related to this thread. What version of numpy are you using?
svn HEAD (2.0.0.dev8480)
After reading the thread you suggested, I tried forcing the
CFLAGS=-DNPY_HAVE_DECL_ISFINITE
flag to be set, but this is apparently a bad idea for my platform...
File "/home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/__init__.py", line 5, in ? import multiarray ImportError: ld.so.1: python: fatal: relocation error: file
/home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/multiarray.so: symbol isfinite: referenced symbol not found
so while I think my bug is related to that thread, I don't see anything in that thread to help me fix my problem. Or am I missing something? ____
In the thread there is a way to check if isinf is in the library. You can also grep through the python include files where its presence should be set, that's in /usr/include/python2.6/pyconfig.h on my system. If it's present, then you should be able to apply David's fix<http://projects.scipy.org/numpy/changeset/8455>which amount to just a few lines.
PS, of course we should fix the macro also. Since the bit values of +/- infinity are known we should be able to define them as constants using a couple of ifdefs and unions. I believe SUN has quad precision so we might need to check the layout, but the usual case seems to be zero mantissa, maximum exponent, and the sign. Not a number differs in that the mantissa is non-zero. I believe there are two versions of nans, signaling and non-signaling, but in any case it doesn't look to me like it should be impossible to simply have all those values as numpy constants like pi and e.
And here are some functions stolen from here<http://ftp.math.utah.edu/pub//zsh/zsh-4.1.1-nonstop-fp.tar.gz>. They have have an oldstyle BSD type license which need quoting. #if !defined(HAVE_ISINF) /**/ int (isinf)(double x) { if ((-1.0 < x) && (x < 1.0)) /* x is small, and thus finite */ return (0); else if ((x + x) == x) /* only true if x == Infinity */ return (1); else /* must be finite (normal or subnormal), or NaN */ return (0); } #endif #if !defined(HAVE_ISNAN) /**/ static double (store)(double *x) { return (*x); } /**/ int (isnan)(double x) { /* (x != x) should be sufficient, but some compilers incorrectly optimize it away */ return (store(&x) != store(&x)); } #endif Chuck

Thu, 15 Jul 2010 19:09:15 -0600, Charles R Harris wrote: [clip]
PS, of course we should fix the macro also. Since the bit values of +/- infinity are known we should be able to define them as constants using a couple of ifdefs and unions.
We already do that, NPY_INFINITY and -NPY_INFINITY. [clip]
int (isinf)(double x) { if ((-1.0 < x) && (x < 1.0)) /* x is small, and thus finite */ return (0); else if ((x + x) == x) /* only true if x == Infinity */ return (1); else /* must be finite (normal or subnormal), or NaN */ return (0); }
This function can generate overflows, for example for x = 0.6 * np.finfo(np.float64).max -- Pauli Virtanen

On Fri, Jul 16, 2010 at 2:27 AM, Pauli Virtanen <pav@iki.fi> wrote:
Thu, 15 Jul 2010 19:09:15 -0600, Charles R Harris wrote: [clip]
PS, of course we should fix the macro also. Since the bit values of +/- infinity are known we should be able to define them as constants using a couple of ifdefs and unions.
We already do that, NPY_INFINITY and -NPY_INFINITY.
[clip]
int (isinf)(double x) { if ((-1.0 < x) && (x < 1.0)) /* x is small, and thus finite */ return (0); else if ((x + x) == x) /* only true if x == Infinity */ return (1); else /* must be finite (normal or subnormal), or NaN */ return (0); }
This function can generate overflows, for example for
x = 0.6 * np.finfo(np.float64).max
Yep, but the test still works correctly. Unless overflow can somehow be flagged to raise an error. Beebe is usually pretty careful... Chuck

On Thu, Jul 15, 2010 at 6:42 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 7:27 PM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:11 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:14 PM, Eric Firing <efiring@hawaii.edu>
wrote:
Is it certain that the Solaris compiler lacks isinf? Is it possible that it has it, but it is not being detected?
Just to clarify, I'm not using the sun compiler, but gcc-3.4.3 on solaris x86
Might be related to this thread. What version of numpy are you using?
svn HEAD (2.0.0.dev8480)
After reading the thread you suggested, I tried forcing the
CFLAGS=-DNPY_HAVE_DECL_ISFINITE
flag to be set, but this is apparently a bad idea for my platform...
File "/home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/__init__.py", line 5, in ? import multiarray ImportError: ld.so.1: python: fatal: relocation error: file /home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/multiarray.so: symbol isfinite: referenced symbol not found
so while I think my bug is related to that thread, I don't see anything in that thread to help me fix my problem. Or am I missing something? __
Can you try out this patch without David's fixes? diff --git a/numpy/core/include/numpy/npy_math.h b/numpy/core/include/numpy/npy_ index d53900e..341fb58 100644 --- a/numpy/core/include/numpy/npy_math.h +++ b/numpy/core/include/numpy/npy_math.h @@ -151,13 +151,13 @@ double npy_spacing(double x); #endif #ifndef NPY_HAVE_DECL_ISFINITE - #define npy_isfinite(x) !npy_isnan((x) + (-x)) + #define npy_isfinite(x) (((x) + (x)) != (x) && (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)) + #define npy_isinf(x) (((x) + (x)) == (x) && (x) != 0) #else #define npy_isinf(x) isinf((x)) #endif Chuck

Testing with arithmetic can raise overflows and underflows. I think the correct isinf is to compare to NPY_INFINITY and -NPY_INFINITY. Patch is attached to #1500 ----- Alkuperäinen viesti -----
On Thu, Jul 15, 2010 at 6:42 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 7:27 PM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:11 PM, John Hunter <jdh2358@gmail.com> wrote:
On Thu, Jul 15, 2010 at 6:14 PM, Eric Firing <efiring@hawaii.edu>
wrote:
Is it certain that the Solaris compiler lacks isinf? Is it possible that it has it, but it is not being detected?
Just to clarify, I'm not using the sun compiler, but gcc-3.4.3 on solaris x86
Might be related to this thread. What version of numpy are you using?
svn HEAD (2.0.0.dev8480)
After reading the thread you suggested, I tried forcing the
CFLAGS=-DNPY_HAVE_DECL_ISFINITE
flag to be set, but this is apparently a bad idea for my platform...
File "/home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/__init__.py", line 5, in ? import multiarray ImportError: ld.so.1: python: fatal: relocation error: file /home/titan/johnh/dev/lib/python2.4/site-packages/numpy/core/multiarray.so: symbol isfinite: referenced symbol not found
so while I think my bug is related to that thread, I don't see anything in that thread to help me fix my problem. Or am I missing something? __
Can you try out this patch without David's fixes?
diff --git a/numpy/core/include/numpy/npy_math.h b/numpy/core/include/numpy/npy_ index d53900e..341fb58 100644 --- a/numpy/core/include/numpy/npy_math.h +++ b/numpy/core/include/numpy/npy_math.h @@ -151,13 +151,13 @@ double npy_spacing(double x); #endif
#ifndef NPY_HAVE_DECL_ISFINITE - #define npy_isfinite(x) !npy_isnan((x) + (-x)) + #define npy_isfinite(x) (((x) + (x)) != (x) && (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)) + #define npy_isinf(x) (((x) + (x)) == (x) && (x) != 0) #else #define npy_isinf(x) isinf((x)) #endif
Chuck
participants (4)
-
Charles R Harris
-
Eric Firing
-
John Hunter
-
Pauli Virtanen