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

Home » Public Forums » archive » Re: Odd behaviour in array indexing ?
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: Odd behaviour in array indexing ? [message #34182 is a reply to message #34179] Fri, 21 February 2003 07:48 Go to previous messageGo to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
mwvogel wrote:
>
> Today I realized something is amiss in IDL
> When I do
> index = [1,0,2,3,1,2,3,4]
> m = FLTARR(8)
> d = FINDGEN(8)
> m[index] = d
> print, m
> 1.00000 4.00000 5.00000 6.00000 7.00000
> 0.000000 0.000000 0.000000
>
> Now I would have assumed that IDL would automatically *add* the numbers with
> identical indices. ...

I'm not sure why you would assume that.

> ... Not doing
> so is a potential performance penaly, right ?

Actually, doing it would incur a performance penalty. The way it's
actually implemented internally is equivalent to the following:

for i=0,7 do m[index[i]] = d[i]

except, of course, that it's far faster as "m[index] = d" than as an
explicit loop. That's a pretty efficient loop. I can't see anyway to
implement the behavior you want, that isn't a whole lot slower. The
closest I can get is equivalent to:

initialized = intarr(8)
FOR i=0,7 DO BEGIN
IF initialized[index[i]] THEN m[index[i]] = d[i];
 ELSE m[index[i]] = m[index[i]] + d[i];

initialized[index[i]] = 1;
ENDIF
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Plotting to more than one window
Next Topic: Altivec support in ENVI and/or IDL?

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

Current Time: Wed Oct 08 19:31:04 PDT 2025

Total time taken to generate the page: 0.00398 seconds