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

Home » Public Forums » archive » How to speed up code which checks lots of values of an array
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
How to speed up code which checks lots of values of an array [message #74367] Thu, 13 January 2011 08:06 Go to next message
Robin Wilson is currently offline  Robin Wilson
Messages: 40
Registered: August 2010
Member
Hi all,

I've been writing some code which checks that all of the values in one
half of an array are less than a threshold, and all of the values on the
right half of an array are greater than a threshold. I've written the
code below, which seems to be a fairly clean way of writing it, and
works for any length of array (which is important for my use of it).

However, it's not very fast. I wondered if it might be able to be sped
up using some sort of magic like the Histogram command... Any ideas?

---CODE---
; Assume we're given a 1D array called line with our values in it

len = N_ELEMENTS(line)

section_len = (len - 1) / 2

; Get the left-hand half of the array
LHS = line[0:section_len - 1]
RHS = line[section_len + 1: len - 1]

res = WHERE(LHS GT 180, LHS_count)
res = WHERE(RHS LT 180, RHS_count)

IF LHS_count EQ 0 AND RHS_count EQ 0 THEN BEGIN
; Do stuff
ENDIF

---END CODE---

Cheers,

Robin
Re: How to speed up code which checks lots of values of an array [message #74501 is a reply to message #74367] Tue, 18 January 2011 15:32 Go to previous message
JDS is currently offline  JDS
Messages: 94
Registered: March 2009
Member
A perfect use ARRAY_EQUAL() and the short circuit `&&' operator. Both will abort the remainder of the calculation as soon as the test fails, so depending on how often that happens, you will see a factor of few speedup.

if array_equal(LHS gt 180,0b) && array_equal(RHS lt 180,0b) then...

JD
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Double Xaxis pb with ticks
Next Topic: Why is MEAN so slow?

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

Current Time: Wed Oct 08 21:14:55 PDT 2025

Total time taken to generate the page: 1.19961 seconds