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

Home » Public Forums » archive » Array searching efficiency
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: Array searching efficiency [message #75057 is a reply to message #74959] Thu, 10 February 2011 16:32 Go to previous messageGo to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Feb 10, 9:47 pm, Matt Francis <mattjamesfran...@gmail.com> wrote:
> The first step is to establish, for a given time, which two maps I
> need to interpolate between. I have the times for each map stored in a
> single array, in time order. If I can work out the indices in that
> array of the two map times then I'm done. This is a simple problem to
> solve in any number of ways, but the question is which is the fastest?
>
> I've come up with this:
>
> iup = (WHERE(times-time_now GT 0))[0]
> ilow = iup-1
>
> I'm not sure how WHERE works 'under the hood', but assuming that at
> some level it loops over the given array, then optimally once [times -
> time_now] becomes positive you would stop searching. Implementing that
> kind of algorithm in a WHILE loop is probably slower than using WHERE
> though.

where() is certainly *not* optimal for this. It has no reason to stop
searching on the first occurrence. It will keep searching to the end,
as its job is to return every occurrence, and it cannot assume there
will be only one. Besides, you would be doing one call of where() for
each time you are searching for. A very wasteful repeat of searches.

A single call to value_locate does this. Something like

ind=value_locate(times,times_to_search)

will return an array with the index for each value in times_to_search.
Whether the returned index is below or above the value you search for
depends on the ordering of times. See the help on value_locate.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: reading and writing very slow
Next Topic: possible bug with center keyword option for FFT

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

Current Time: Sat Oct 11 00:53:21 PDT 2025

Total time taken to generate the page: 0.31951 seconds