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

Home » Public Forums » archive » Re: fast array comparison
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: fast array comparison [message #33159 is a reply to message #33158] Sun, 08 December 2002 12:35 Go to previous messageGo to previous message
Sean Raffuse is currently offline  Sean Raffuse
Messages: 46
Registered: July 2001
Member
Sorry, sent that last post before I wanted to.


> David,
>
> Thanks for this. It works almost perfectly. I am a little confused
though.
> It seems that the indices keyword returns the indices of the requested
array
> and not the available array.

> IDL> request_array = [5,6,7,8,9,10]
> IDL> avail_array = [3,7,8,9,12,13,16]
> IDL> int = setintersection(avail_array, request_array, Indices=i)
> IDL> print, int, i
> 7 8 9
> 2 3 4
>

How do I switch it so that indices returns the indices of the available
array. I am apparently not understanding the code.

Thanks yet again,

Sean


>
>
> "David Fanning" <david@dfanning.com> wrote in message
> news:MPG.185d3307aad96bee989a51@news.frii.com...
>> Sean Raffuse (sean@me.wustl.edu) writes:
>>
>>> Let's say I have two arrays.
>>>
>>> requested_array = [5,6,7,8,9,10]
>>> available_array = [3,7,8,9,12,13,16]
>>>
>>> What is the absolute fastest way to determine the indices of
> available_array
>>> that contain values in requested_array? The indices need not match.
> i.e.,
>>> if the two arrays above were used, I would like to return
index=[1,2,3]
>>> because the requested values 7, 8 and 9 are in the available array.
>>
>> The absolute fastest way MUST involve histograms, so
>> I maintain with a great deal of confidence (say, in the 40-50
>> percent range) that this is the fastest possible algorithm:
>>
>> ************************************************************ ************
>> FUNCTION SetIntersection, a, b, Indices=indices
>> minab = Min(a, Max=maxa) > Min(b, Max=maxb) ;Only need intersection of
>> ranges
>> maxab = maxa < maxb
>>
>> ; If either set is empty, or ranges don't intersect: result = NULL.
>>
>> IF maxab LT minab OR maxab LT 0 THEN RETURN, -1
>> r = Where((Histogram(a, Min=minab, Max=maxab) NE 0) AND $
>> (Histogram(b, Min=minab, Max=maxab) NE 0), count)
>> IF Arg_Present(indices) THEN $
>> indices = Where((Histogram(a, Min=minab, Max=maxab) NE 0))
>> IF count EQ 0 THEN RETURN, -1 ELSE RETURN, r + minab
>> END
>> ************************************************************ ************
>>
>> Use it like this:
>>
>>
>> IDL> request_array = [5,6,7,8,9,10]
>> IDL> avail_array = [3,7,8,9,12,13,16]
>> IDL> int = setintersection(avail_array, request_array, Indices=i)
>> IDL> print, int, i
>> 7 8 9
>> 2 3 4
>>
>> Cheers,
>>
>> David
>>
>> --
>> David W. Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Phone: 970-221-0438, E-mail: david@dfanning.com
>> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>> Toll-Free IDL Book Orders: 1-888-461-0155
>
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: calling C from IDL under OS X
Next Topic: 3D Scatterplots

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

Current Time: Fri Oct 10 04:16:07 PDT 2025

Total time taken to generate the page: 1.20000 seconds