[Numpy-discussion] tighten up ufunc casting rule

josef.pktd at gmail.com josef.pktd at gmail.com
Sun Jun 5 20:06:48 EDT 2011


On Sun, Jun 5, 2011 at 6:51 PM, Gael Varoquaux
<gael.varoquaux at normalesup.org> wrote:
> On Sun, Jun 05, 2011 at 04:41:26PM -0600, Charles R Harris wrote:
>>      Now, with regards to the actual failures induced by the new
>>      branch, it took me a while to understand why they where happening,
>>      and now I realise that we probably should have explicit coercions
>>      at these locations.
>
>>    So the failures in those cases is a good thing?
>
> Yes.

I remember in stats distributions, there were casting bugs like this
and they are nasty to find.

assigning a nan to an int has been changed to raise an exception, but
inline operation still produces silent results

>>> a = np.arange(3, dtype=np.int32)
>>> a[0] = np.nan
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    a[0] = np.nan
ValueError: cannot convert float NaN to integer

>>> a += np.nan
>>> a
array([-2147483648, -2147483648, -2147483648])

>>> a = np.arange(3, dtype=np.int32)
>>> a *= np.array([1.,1., np.nan])
>>> a
array([          0,           1, -2147483648])

definitely wrong

Josef


>
> Gael
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list