NaN handling

G

Grant Edwards

Fair enough. If you want to go through numpy's code to rip out its floating
point error handling, knock yourself out. It's not going to be trivial, though.
It's heavily embedded in the ufunc machinery.

Does numpy's NaN handling only work within numpy functions, or
does it enable HW FP signals and then catch them for "normal"
floating point operations that take place outside of numpy code?
 
G

Grant Edwards

Traceback (most recent call last):
File "<pyshell#5>", line 1, in -toplevel-
float("NaN")
ValueError: invalid literal for float(): NaN

As Tim Peters has said often enough, this sort of thing is specific to the
underlying C library and will remain so until someone cares enough to write
or fund a cross-platform solution.

Yea, that's a royal PITA. I had to add my own code into the
"pickle" classes to handle NaNs. Having a pickler that only
works for a subset of the legal IEEE FP values proved to be
sort of useless.
 
R

Robert Kern

Grant said:
Does numpy's NaN handling only work within numpy functions, or
does it enable HW FP signals and then catch them for "normal"
floating point operations that take place outside of numpy code?

Just in numpy code, it seems.

In [1]: import numpy
i
In [2]: import math

In [3]: numpy.seterr(invalid='raise')
Out[3]: {'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore', 'under':
'ignore'}

In [4]: numpy.log(-1.0)
---------------------------------------------------------------------------
exceptions.FloatingPointError Traceback (most recent call
last)

/Users/kern/<ipython console>

FloatingPointError: invalid encountered in log

In [5]: math.log(-1.0)
Out[5]: nan

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top