[Numpy-discussion] bug in oldnumeric.ma

Eric Firing efiring@hawaii....
Fri May 9 16:13:02 CDT 2008

Anne Archibald wrote:
> 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;
> numpy.array(x).astype(numpy.int64)==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.

There may not be a perfect solution, but I suspect your suggestion to 
use int64 is more than good enough to get things going for a 1.1 
release.  The docstring could note the limitation.  If it is established 
that the calculation will fail for a power outside some domain, then 
such a domain check could be added to the mask.


> Anne
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

More information about the Numpy-discussion mailing list