[Numpy-discussion] Should abs([nan]) be supported?

Alex Leach beamesleach at gmail.com
Sun Sep 30 11:14:19 EDT 2012


Ondřej Čertík <ondrej.certik <at> gmail.com> writes:
> 
> On Tue, Sep 4, 2012 at 8:38 PM, Travis Oliphant <travis <at> continuum.io>
> wrote:


> I think the test should be changed to check for RuntimeWarning on some of
> the cases.   This might take a little work as it looks like the code uses
> generators across multiple tests and
> would have to be changed to handle expecting warnings.

> >
> > Alternatively, the error context can be set before the test runs and then
> > restored afterwords:
> >
> > olderr = np.seterr(invalid='ignore')
> > abs(a)
> > np.seterr(**olderr)
> >
> >
> > or, using an errstate context ---
> >
> > with np.errstate(invalid='ignore'):
> >       abs(a)
> 
> I see --- so abs([nan]) should emit a warning, but in the test we
> should suppress it.
> I'll work on that.
> 

Just witnessing this error now.. I'm building numpy on 64bit Linux with 
Intel's icc, and on OSX Mountain Lion with clang. I thought it was a problem
with the built-in abs, as I used the following test case:-

$ /usr/local/bin/python
>>> import numpy as np
>>> abs(np.array([1e-08, 1, 1000020.0000000099] ) - \
...     np.array([0, np.nan, 1000000.0] ) )

With the OSX clang build, this returns without an error message.
array([  1.00000000e-08,              nan,   2.00000000e+01])

But on Ubuntu with my icc build of Python-2.7.3, I get that FloatingPointError,
and corresponding numpy test failures.

I figure this is caused by a compile flag that I did or didn't use, so dug
around the icc man page, and think I found the cause for it...
I built my Ubuntu python with the '-fp-model strict' option, as per
recommendations I've seen, but this turns on floating point exceptions, so I'm
going to rebuild with '-fp-model precise -fp-model source', and see how it
goes...

Cheers,
Alex





More information about the NumPy-Discussion mailing list