[Numpy-discussion] Binary ufuncs: minimum

Charles R Harris charlesr.harris at gmail.com
Wed May 28 07:37:45 EDT 2008


On Wed, May 28, 2008 at 1:08 AM, Chris.Barker <Chris.Barker at noaa.gov> wrote:

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

Just tossing the idea out there. I am more  bothered by this:

In [1]: ones(1,dtype=int8) & ones(1,dtype=uint8)
Out[1]: array([1], dtype=int16)

In [2]: ones(1,dtype=int8) << ones(1,dtype=uint8)
Out[2]: array([2], dtype=int16)

In [3]: ones(1,dtype=int64) & ones(1,dtype=uint64)
Out[3]: array([1], dtype=object)

In [4]: ones(1,dtype=int64) << ones(1,dtype=uint64)
Out[4]: array([2], dtype=object)

Which really does blaspheme the hardware spirits.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080528/57ff46ce/attachment.html>


More information about the NumPy-Discussion mailing list