comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Sky Falling, etc. : Array substitution + addition with plus-equal (+=)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Sky Falling, etc. : Array substitution + addition with plus-equal (+=) [message #53029 is a reply to message #52941] Tue, 13 March 2007 05:26 Go to previous messageGo to previous message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Mon, 12 Mar 2007, Ed Hyer wrote:

> Tentatively filed under "The Sky Is Falling!," and I hope it will be
> resolved in the same fashion.
>
> Here is the test case, which gives the correct result:
>
> IDL> test=fltarr(2,2,4)
> IDL> testadd=fltarr(2,2,2) + 1
> IDL> print,total(test),total(testadd)
> 0.00000 8.00000
> IDL> test[0,0,1] += testadd
> IDL> print,total(test),total(testadd)
> 8.00000 8.00000
> IDL> test[0,0,1] += testadd
> IDL> print,total(test),total(testadd)
> 16.0000 8.00000
> IDL> print,test
> 0.00000 0.00000
> 0.00000 0.00000
>
> 2.00000 2.00000
> 2.00000 2.00000
>
> 2.00000 2.00000
> 2.00000 2.00000
>
> 0.00000 0.00000
> 0.00000 0.00000
>
> That is exactly what I expect from this operation.
>
> Here is another case, with results somewhat different
> IDL> test=fltarr(2,2,4)
> IDL> testadd=fltarr(2,2,2)
> IDL> testadd[0,0,*]=1
> IDL> print,total(test),total(testadd)
> 0.00000 2.00000
> IDL> test[0,0,1] += testadd
> IDL> print,total(test),total(testadd)
> 2.00000 2.00000
> IDL> print,test
> 0.00000 0.00000
> 0.00000 0.00000
>
> 1.00000 0.00000
> 0.00000 0.00000
>
> 1.00000 0.00000
> 0.00000 0.00000
>
> 0.00000 0.00000
> 0.00000 0.00000 ; So far, so good
> IDL> test[0,0,1] += testadd ; Now, let's add again
> IDL> print,total(test),total(testadd)
> 10.0000 2.00000 ; Pardon the
> expression, WTF?
> IDL> print,test
> 0.00000 0.00000
> 0.00000 0.00000
>
> 2.00000 1.00000
> 1.00000 1.00000
>
> 2.00000 1.00000
> 1.00000 1.00000
>
> 0.00000 0.00000
> 0.00000 0.00000 ; Not even JD Smith
> expected _that_.
>
> Any ideas?
>

FL gives the same result, so it is correct :-)))

test[0,0,1] += testadd is transformed to the following form:

tmp = test[0,0,1] + testadd
test[0,0,1] = tmp

The first line is scalar - array addition, so the scalar is added to every
element of the array (8 addition!), and tmp will be an array.

In the second line an array is assigned to a scalar subscripted array, so
tmp is inserted into test.

I hope this helps.

regards,
lajos
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: randomn problem
Next Topic: Re: Array resize with arbitrary arithmetic

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 10:35:49 PDT 2025

Total time taken to generate the page: 1.36287 seconds