[Numpy-discussion] Regression: in-place operations (possibly intentional)

Chris Barker chris.barker at noaa.gov
Fri Sep 21 17:04:33 EDT 2012

On Fri, Sep 21, 2012 at 10:03 AM, Nathaniel Smith <njs at pobox.com> wrote:

> You're right of course. What I meant is that
>   a += b
> should produce the same result as
>   a[...] = a + b
> If we change the casting rule for the first one but not the second, though,
> then these will produce different results if a is integer and b is float:

I certainly agree that we would want that, however, numpy still needs
to deal tih pyton symantics, which means that wile (at the numpy
level) we can control what "a[...] =" means, and we can control what
"a + b" produces, we can't change what "a + b" means depending on the
context of the left hand side.

that means we need to do the casting at the assignment stage, which I
gues is your point -- so:

a_int += a_float

should do the addition with the "regular" casting rules, then cast to
an int after doing that.

not sure the implimentation details.

Oh, and:

a += b

should be the same as

a[..] = a + b

should be the same as

np.add(a, b, out=a)

not sure what the story is with that at this point.



Christopher Barker, Ph.D.

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