[Numpy-discussion] CASTABLE flag

Timothy Hochberg tim.hochberg at ieee.org
Mon Jan 7 15:16:46 EST 2008


Another possible approach is to treat downcasting similar to underflow. That
is give it it's own flag in the errstate and people can set it to ignore,
warn or raise on downcasting as desired. One could potentially have two
flags, one for downcasting across kinds (float->int, int->bool) and one for
downcasting within kinds (float64->float32). In this case, I personally
would set the first to raise and the second to ignore and would suggest that
as the default.

IMO:

   1. It's a no brainer to raise and exception when assigning a complex
   value to a float or integer target. Using "Z.real" or "Z.imag" is
   clearer and has the same performance.
   2. I'm fairly dubious about assigning float to ints as is. First off
   it looks like a bug magnet to me due to accidentally assigning a floating
   point value to a target that one believes to be float but is in fact
   integer. Second, C-style rounding is pretty evil; it's not always consistent
   across platforms, so relying on it for anything other than truncating
   already integral values is asking for trouble.
   3. Downcasting within kinds seems much less hazardous than downcasting
   across kinds, although I'd still be happy to be able regulate it with
   errstate.


-tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080107/07d04a38/attachment.html>


More information about the NumPy-Discussion mailing list