[SciPy-dev] Nan's

Pearu Peterson pearu at cens.ioc.ee
Sat Nov 2 02:42:24 CST 2002


On Fri, 1 Nov 2002, Travis Oliphant wrote:

> I think the issues with nans can be resolved.

I hope so. I would like very much if NaN and Infs would work under Python.
Unfortunately there are number of subtle Python related issues with them
that will zero all their advantages if these issues are not resolved
first. The main issue is related to the platform-independence.

> Matlab uses them.  Octave uses them.

I note again. The difference between these software and Python is
that they *support* IEEE while Python does not.

> It seems that scipy should be able to handle them properly on the same
> platforms where these codes work.

That is, scipy must implement the missing IEEE support, but it cannot rely
on Python default behaviour on IEEE stuff as this behaviour *is* platform
dependent, currently.

For me at least, it is crucial that the result of
  r==1.0
should be unique for all major platforms and for all floats (including
NaN). Currently it is not and therefore it is a source of difficult to 
find bugs if NaN is allowed.

> IEEE has a well-defined standard for them, also that most compilers can
> support if configured correctly.   The problem is when you use a
> compiler in a configuration where it intentionally breaks IEEE standards.
> 
> For example,
> 
> gcc CANNOT use the -ffast-math flag on a file where nan comparisons will
> be taking place.
> 
> So, removing -ffast-umath from a gcc compiled file suddenly makes nan
> comparisons work correctly as defined by the IEEE

Nothing in distutils or scipy_distutils forces gcc to use the -ffast-math
flag. For example, the default flags used to compile C extension modules
with the debian distributed Python are

  -DNDEBUG -g -O3 -Wall -Wstrict-prototypes

You can find out these flags by executing the following code

#
from distutils import sysconfig
sysconfig._init_posix()
print sysconfig._config_vars['OPT']
#

The only way the -ffast-math flag can get into this option list is
if the one who compiled Python specifically forced to use it.

Does Mandrake, Suse, Redhat, etc. use the -ffast-math flag for compiling
Python?

If yes, then I can implement hooks for scipy_distutils that will disable
-ffast-math for scipy modules. If non of the Python distributors use
the -ffast-math flag, then the users must recompile their Python without
the -ffast-math flag, I presume.

> I'm not as good at figuring out the distutils stuff as others on this
> list, so could somebody show me how to make sure that the flag -ffast-math
> is not turned on while compiling fastumathmodule.c (and some of the
> cephes librarys files as well).

I quick hack for removing -ffast-math flag from OPT is

#
from distutils import sysconfig
save_init_posix = sysconfig._init_posix
def my_init_posix():
    save_init_posix()
    g = sysconfig._config_vars
    g['OPT'] = g['OPT'].replace('-ffast-math','')
sysconfig._init_posix = my_init_posix
#

that should be placed into one of the setup files (similar hooks should be
implemented for _init_nt, _init_mac).

Pearu




More information about the Scipy-dev mailing list