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

Zero vector detection in IDL



Given a big byte or integer array (actually a 1-D vector), is there a
fast IDL way to check whether any non-zero elements exist?

Something like "if (total(x) EQ 0)..." or a where() construct will work,
but scans the whole vector when the first non-zero element is enough to
answer the question.  max(x) is even worse.

On the other hand:
  for i=0,n-1 do begin
      if (x(i) NE 0) then begin
          (it's not all zero)
          goto, BREAK
      endif
  endif
  BREAK:
will stop early if possible, but looping a
conditional is maybe not the
fastest structure in IDL.

An internal command that implements the loop concept would be what I'm
looking for I think but I don't know if it exists.

Any better ideas?

Thanks,
Frank
frank.morgan@jhuapl.edu