[Numpy-discussion] range check: feature request for numarray

Francesc Alted falted at openlc.org
Wed Feb 19 04:06:02 CST 2003


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.

Maybe it is desirable that the default would be to not issue the warning,
except when the user wanted to know about that.

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.


Francesc Alted

`` We are shaped by our thoughts, we become what we think.
 When the mind is pure, joy follows like a shadow that never
 leaves. '' -- Buddha, The Dhammapada

More information about the Numpy-discussion mailing list