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

Home » Public Forums » archive » Re: Getting array indices
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Getting array indices [message #62698] Tue, 23 September 2008 14:07 Go to next message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
> That takes about twice as long as the "MOD" method on my machine:
> x86_64 Win32 Windows Microsoft Windows 7.0 Oct 25 2007 64 64

Interesting... indeed, for small arrays, it is about the same speed...
but the mod method is much faster on bigger arrays! (same speed with the
/dim keyword or not, 'verts' is used in both methods, so there is no
penalty for re-creating the index array)

Jean
Re: Getting array indices [message #62699 is a reply to message #62698] Tue, 23 September 2008 14:17 Go to previous message
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
> Because of "indgen(ns)" or because of array_indices?

Because of array_indices according to this test:
;; .run test.pro
array = findgen(15, 3)
ind_in = lindgen(n_elements(array))

t1 = systime(/sec)
FOR i = 0UL, 1e5 DO BEGIN
ind = array_indices(array, ind_in
ENDFOR
print, systime(/sec)-t1

t1 = systime(/sec)
FOR i = 0UL, 1e5 DO BEGIN
sz = size(array)
nx = sz[1]
ny = sz[2]
verts = lindgen(nx*ny)
verts = transpose( [ [verts mod nx], [verts/nx] ] )
ENDFOR
print, systime(/sec)-t1
END

IDL> .run test
% Compiled module: $MAIN$.
1.2473059
0.50232387
IDL> print, !version
{ i386 darwin unix Mac OS X 6.4.1 Sep 25 2007 32 64}


For closure I whipped this together into a quick function
all_array_indices.pro so I don't have to remember how to do this
again.
http://people.bu.edu/balarsen/IDLdoc/all_array_indices.html

Brian

------------------------------------------------------------ --------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL
Re: Getting array indices [message #62700 is a reply to message #62698] Tue, 23 September 2008 13:47 Go to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
On Sep 23, 4:23 pm, Vince Hradil <hrad...@yahoo.com> wrote:
> On Sep 23, 12:53 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
> wrote:
>
>>> Here's a way to get verts:
>
>>> sz = size(array)
>>> nx = sz[0]
>>> ny = sz[1]
>>> nz = sz[2]
>>> ns = sz[sz[0]+2]
>>> verts = findgen(ns)
>
>> Shouldn't it be indgen() ...
>
>>> verts = transpose([ [verts mod nx], [verts/nx mod ny], [verts/nx/
>>> ny] ])
>
>>> BTW, I'd like to find a faster way, if there is one.
>
>> what about this:
>> print, array_indices(arr, indgen(ns))
>
>> Jean
>
> That takes about twice as long as the "MOD" method on my machine:
> x86_64 Win32 Windows Microsoft Windows 7.0 Oct 25 2007    64    64

Because of "indgen(ns)" or because of array_indices?

Paolo
Re: Getting array indices [message #62701 is a reply to message #62700] Tue, 23 September 2008 13:41 Go to previous message
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
Interesting what you learn when you dig into a routine...

array_indices.pro
<<snip>>
for d=ndim-1, 1, -1 do begin
; Remove indices from even higher dimensions.
if (d lt ndim-1) then $
temp mod= dimProduct[d]
; Indices for higher dimensions.
result[d, *] = temp/dimProduct[d-1]
endfor
<</snip>>

of course some people say that all you get when you dig that deep is
dirty :)

Brian

------------------------------------------------------------ --------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Getting array indices
Next Topic: Re: what is the best way to do a surface (or 2D) interpolation?

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

Current Time: Wed Oct 08 09:15:56 PDT 2025

Total time taken to generate the page: 0.00718 seconds