[Numpy-discussion] Binary ufuncs: minimum

Charles R Harris charlesr.harris@gmail....
Tue May 27 17:12:23 CDT 2008


On Tue, May 27, 2008 at 4:07 PM, Christopher Barker <Chris.Barker@noaa.gov>
wrote:

> Charles R Harris wrote:
>
> > Yep, abs fails:
> >
> > In [1]: abs(array([-128,-128], dtype=int8))
> > Out[1]: array([-128, -128], dtype=int8)
>
> Well, yes, but this is a know vagary of the the hardware implementation
> for signed integers, as demonstrated by that JAVA Puzzles video that Jon
> Wright pointed us to a couple days ago. (Which to me could have been
> titled: "Why I don't want to use JAVA")
>
> Sure, it could be fixed in this case by promoting to a larger type, but
> it's going to fail at the largest integer anyway, and I don't think any
> expects abs() to return a new type.
>

No, it could be completely fixed by promoting the output to the
corresponding unsigned type. It wouldn't even require much cleverness in the
ufunc.

In [2]: abs(array([-128,-128], dtype=int8)).view(uint8)
Out[2]: array([128, 128], dtype=uint8)

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080527/08cee166/attachment.html 


More information about the Numpy-discussion mailing list