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

Home » Public Forums » archive » Re: Faster approach for total(data,dimension) possible?
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: Faster approach for total(data,dimension) possible? [message #67071 is a reply to message #67070] Wed, 24 June 2009 04:19 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Jun 24, 3:54 am, chris <rog...@googlemail.com> wrote:
> Hi,
> i'm looking for a faster approach to do the following:
>
> data=rebin(dist(100),100,100,50,/sample)
> mask=total(data,3) gt 0.
>
> Depending on the size of data and on the hardware of the client the
> code above runs too slow for me. I'd like to find all pixels in a
> hyperspectral application, which bands are not zero. The result should
> be a mask with the same 2D-dimensions as original data for further
> processing.

My first thought was to use ARRAY_EQUAL rather than TOTAL since
ARRAY_EQUAL(im,0) will stop computations as soon as a non-zero element
is found. But as far as I know, ARRAY_EQUAL can only return a
scalar argument, which means that one would have to loop over each
element of the output mask. Ugh.

But if we are forced to use TOTAL, there is no need for a double
precision computation. I found a significant speedup by replacing
the second line with

mask = total(data,3,/integer) GT 0

I also found a smaller speedup with the following code, which is based
on the theory that mathematical operations are always quickest on byte
data.

mask = total(data GT 0,/preserve_type,3) GT 0

-Wayne
[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
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: bar_plot and ploterr
Next Topic: Re: Envi virtual machine

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

Current Time: Wed Oct 08 16:04:48 PDT 2025

Total time taken to generate the page: 0.00455 seconds