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

Home » Public Forums » archive » Re: Succinct way of testing array membership
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: Succinct way of testing array membership [message #81201] Thu, 30 August 2012 12:16 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
For very large vectors, WHERE() methods are slow because (1) you compute the index of where the member is found, even if you just care about membership, and more important (2) WHERE operates on the entire vector, and does not exit as soon as the member is found. A faster method would be

function array_contains,v,x
;Is x an element of V?
return,~array_equal( (v eq x), 0b)
end

since ARRAY_EQUAL exits as soon as the first match is found. I can't imagine the speed difference is significant for normal size vectors, though.

--Wayne



On Thursday, August 30, 2012 12:51:48 PM UTC-4, godber wrote:
> Is there a more succinct way of testing array membership than using where and n_elements on the indexes? Something like array_contains(a, 'pancakes')?
>
>
>
> Austin
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: A simple DLM question
Next Topic: plotting symbols on map using direct graphics 8.2

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

Current Time: Wed Oct 08 17:15:17 PDT 2025

Total time taken to generate the page: 0.00391 seconds