[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help to optimize for speed



>From way of Hamid <kohen@jpl.nasa.gov> writes:



> Hi,
> 
> I have this for loop that searches for a particular pattern (roi).
> This search takes for ever.
> Does anyone knows how to optimize this code for speed.

How about this?

ncols = size1(1)
cc = convol(bscl, roi, total(roi), /center, /edge_truncate)
wh = where(abs(cc - 1) LT 0.01, nmatches)
if nmatches GT 0 then begin
  rows = wh / ncols   - 1
  cols = wh MOD ncols - 1
endif
...

This will find the best close matches, just a few of them, which you
can then examine in more detail, like you are already doing.  ROWS and
COLS contain the row and column indices for each likely match.
Depending on how tolerant of noise you are, you can increase or reduce
the value of 0.01.

Just looking at your code, it seems that you are hurting yourself by
making lots of calls to EXTRAC, which is a function written in IDL.
Doing the array subscripting explicitly should speed things up some.

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------