Re: Fast shear [message #29122] |
Tue, 05 February 2002 09:42  |
Wayne Landsman
Messages: 117 Registered: January 1997
|
Senior Member |
|
|
the_cacc@hotmail.com wrote
> Anyone know a way of doing the following as fast as possible:
> for i = 0, n-1 DO array[*,i] = SHIFT(array[*,i],delta[i])
> where delta is an INTARR.
Well, I think a loop over rows is necessary, but the speed can be vastly
improved by using the folllowing IDL maxim for efficient programming,
which gets my vote in the "IDL maxim most deserving of wider
recognition" category.
"Avoid the use of an asterisk on the left-hand side of an assignment."
which in this case means to rewrite the assignment as
for i = 0, n-1 DO array[0,i] = SHIFT(array[*,i],delta[i])
For a fltarr(2048,2048) on my Solaris machine running V5.5, I find a
factor of 15 improvement in speed.
I believe that one uses an asterisk on the left hand side, that
IDL first creates a temporary variable, places the contents of the right
hand side into this temporary variable, and then places the temporary
variable back into array. By specifying array[0,i] one directly
gives the starting location where to place the contents of the right
hand side.
--Wayne Landsman
landsman@mpb.gsfc.nasa.gov
|
|
|
Re: Fast shear [message #29179 is a reply to message #29122] |
Thu, 07 February 2002 09:41  |
k-bowman
Messages: 12 Registered: December 2001
|
Junior Member |
|
|
In article <3C60199D.E4810C70@mpb.gsfc.nasa.gov>, Wayne Landsman <landsman@mpb.gsfc.nasa.gov> wrote:
> for i = 0, n-1 DO array[*,i] = SHIFT(array[*,i],delta[i])
>
> which in this case means to rewrite the assignment as
>
> for i = 0, n-1 DO array[0,i] = SHIFT(array[*,i],delta[i])
>
> I believe that one uses an asterisk on the left hand side, that
> IDL first creates a temporary variable, places the contents of the right
> hand side into this temporary variable, and then places the temporary
> variable back into array. By specifying array[0,i] one directly
> gives the starting location where to place the contents of the right
> hand side.
I thought that using an asterisk on the LHS meant that IDL created a temporary index array, i.e.
for i = 0, n-1 DO array[[0,1,2,3,...,m-1],i] = SHIFT(array[*,i],delta[i])
where m is the size of the first dimension. The slow down is due to the the indirect array indexing.
The fast method (e.g., array[0,i] = ...) specifies where to start storing the RHS, so it only works for the first dimension (that is, in memory order).
Ken
|
|
|
Re: Fast shear [message #29219 is a reply to message #29122] |
Wed, 06 February 2002 04:41  |
the_cacc
Messages: 104 Registered: October 2001
|
Senior Member |
|
|
Wayne Landsman <landsman@mpb.gsfc.nasa.gov> wrote in message news:<3C60199D.E4810C70@mpb.gsfc.nasa.gov>...
>
> "Avoid the use of an asterisk on the left-hand side of an assignment."
>
> which in this case means to rewrite the assignment as
>
> for i = 0, n-1 DO array[0,i] = SHIFT(array[*,i],delta[i])
>
> For a fltarr(2048,2048) on my Solaris machine running V5.5, I find a
> factor of 15 improvement in speed.
>
WOW! Wayne, that's magic. I get 10-15X speed-up. The world *has* to be
told about this. One drawback - the code does not strictly make sense,
hell who cares !?
Cheers.
|
|
|