[Numpy-discussion] CASTABLE flag
Charles R Harris
charlesr.harris at gmail.com
Mon Jan 7 16:00:42 EST 2008
Hi,
On Jan 7, 2008 1:16 PM, Timothy Hochberg <tim.hochberg at ieee.org> wrote:
>
> 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.
>
> Maybe a combination of a typecast function and the errstate would work
well. The typecast function would provide a clear local override of the
default errstate flags, while the user would have the option to specify what
sort of behavior they care about in general.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080107/f175e77d/attachment.html>
More information about the NumPy-Discussion
mailing list