[Numpy-discussion] Binary ufuncs: minimum

Charles R Harris charlesr.harris@gmail....
Tue May 27 17:22:42 CDT 2008


On Tue, May 27, 2008 at 4:12 PM, Charles R Harris <charlesr.harris@gmail.com>
wrote:

>
>
> 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)
>

I think this could be done in code_generators/generate_umath

 'absolute' :
    Ufunc(1, 1, None,
          'takes |x| elementwise.',
          TD(nocmplx),
          TD(cmplx, out=('f', 'd', 'g')),
          TD(O, f='PyNumber_Absolute'),
          ),

by defining unsigned output types for the ints.

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


More information about the Numpy-discussion mailing list