[Numpy-discussion] Binary ufuncs: minimum

Chris.Barker Chris.Barker at noaa.gov
Wed May 28 03:08:32 EDT 2008


Keith Goodman wrote:
>> Interestingly, MATLAB (v7.5.0) takes a different approach:
>> ans =
>>  127    1
>>>> -A
>> ans =
>>  127   -1

can anyone explain that? -- just curious.

Charles R Harris wrote:
> We could simply define the range of int8 as [-127,127], but that is 
> somewhat problematical also.

That would be nice, but probably a pain to do and could be a serious 
performance hit. And would no longer match hardware/C standards.

Charles R Harris wrote:
> I disagree. By definition, abs() >= 0 always.

and 127 + 1 = 128

This is hardware integer math. It has it's own definition, and 
apparently abs(-128) = -128.

> unsigned return will cause problems is in the augmented assignments,

well, could folks end up with inadvertent upcasting in mixed operations, 
also?

a = np.array(..., dtype=np.int8)
b = np.array(..., dtype=np.int8)

a = abs(a)

c = a + b  # or b + a

what type is c?

by the way, are you proposing that abs() always returns a unsigned 
integer type?

-Chris





-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list