[Numpy-discussion] range check: feature request for numarray
Todd Miller
jmiller at stsci.edu
Thu Feb 20 00:08:13 EST 2003
Francesc Alted wrote:
>Hi,
>
>
>
Hi Francesc,
I'm sorry about the slow response on this. I looked into what it would
take to do this, and while I agree with you in principle, right now my
hands are full trying to beat down numarray overhead.
>I think it would be useful to provide some range checking in numarray. For
>example, right now, you can do:
>
>In [24]: a=numarray.array([1,2],numarray.Int8)
>
>In [25]: a[1] = 256
>
>In [26]: a
>Out[26]: array([1, 0], type=Int8)
>
>and nothing happens. But I'm proposing to raise an OverflowWarning so that
>people can be aware of such range overflows.
>
That sounds reasonable. If you'd care to do a patch, I think we would
want it. If you don't have time, it may be a little while before we do.
>Maybe it is desirable that the default would be to not issue the warning,
>except when the user wanted to know about that.
>
>
I think I'd rather see the warning on by default, even though it might
"break" some existing code.
>So, my proposal is that the actual behaviour should be mantained, but when
>you want to be aware of all the warnings something like this could happen:
>
>In [28]: warnings.resetwarnings()
>
>In [29]: a=numarray.array([1,2],numarray.Int8)
>
>In [30]: a[1] = 256
>OverflowWarning: value assignment not in the type range
>
>In [31]: a
>Out[31]: array([1, 0], type=Int8)
>
>But perhaps this feature might slow a bit the performance of assignments.
>
Yes, but probably not too much.
>Regards,
>
>
>
Todd
More information about the NumPy-Discussion
mailing list