[SciPy-dev] In-place operators and casting
Charles R Harris
charlesr.harris at gmail.com
Fri Nov 25 17:58:32 CST 2005
On 11/24/05, Paul Barrett <pebarrett at gmail.com> wrote:
>
> On 11/23/05, Ed Schofield <schofield at ftw.at> wrote:
> >
> >
> >
> >
> As you noted, a += b is really just a short hand for a = a + b, so
> upcasting makes sense to me. Either way the user really
>
I never think of it having that meaning. I think of it as shorthand saying
reuse the same memory used by the variable a so that the operation is
efficient and parsimonious. The variable a, for instance, could reside in a
register, which is where these notations came from in c; the old DEC
machines had an asm instruction for ++a and a += 3 is also a natural
expression when a is in a register. So in the case cited, I tend to think of
a as residing in a register and a += b as short hand for a corresponding
machine instruction saying to add b to the register value.
Anyway, Matlab pretty much sidesteps these problems by making everything
double. Using actual integers in Matlab is unnatural. Because scipy allows
far more control over types, and because I see a += b as an expression about
memory usage, I vote not to promote the result. If you get the wrong answer,
tough. However, it might be nice to throw an error in these cases as using
different types is just about morally equivalent to using arrays of
different dimensions.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-dev/attachments/20051125/4a3262a9/attachment.html
More information about the Scipy-dev
mailing list