[Numpy-discussion] bug in oldnumeric.ma

Anne Archibald peridot.faceted@gmail....
Fri May 9 15:12:03 CDT 2008

2008/5/9 Eric Firing <efiring@hawaii.edu>:
> Stefan, (and Jarrod and Pierre)
>  (Context for anyone new to the thread: the subject is slightly
>  misleading, because the bug is/was present in both oldnumeric.ma and
>  numpy.ma; the discussion of fix pertains to the latter only.)
>  Regarding your objections to r5137: good point.  I wondered about that.
>   I think the function should look like this (although it might be
>  possible to speed up the implementation for the most common case):
>      md = make_mask((fb != fb.astype(int)) & (fa < 0), shrink=True)

Unfortunately this isn't quite the right condition:

In [18]: x = 2.**35; numpy.array([-1.])**x; numpy.array(x).astype(int)==x
Out[18]: array([ 1.])
Out[18]: False

Switching to int64 seems to help:

In [27]: x = 2.**62; numpy.array([-1.])**x;
Out[27]: array([ 1.])
Out[27]: True

This seems to work, but may be platform-dependent: 2**62+1 cannot be
represented as an IEEE float, so whether pow() successfully deals with
it may be different for machines that don't work with 80-bit
floating-point internally.

A suspenders-and-belt approach would check for NaNs and add them to
the mask, but this still doesn't cover the case where the user has
numpy set to raise exceptions any time NaNs are generated.


More information about the Numpy-discussion mailing list