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

Home » Public Forums » archive » reversing calculation order
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
reversing calculation order [message #4087] Mon, 24 April 1995 00:00 Go to next message
rclark is currently offline  rclark
Messages: 12
Registered: September 1992
Junior Member
I need to fill in some values for a vector from a recurrence relation.

V(0:N-1) = func(V(1:*)) ;I wish there was a shorthand for (*-1)

Where V(N) is the only value initially defined (Well actually it is
calculated from an ascending recurrence relation but the values of
V(0:N-1) from that step are of no further interest. The results of the
second recurrence are the ones returned.)

I know that ROTATE can be used to reverse the order of the vector for the
calculation, and then reverse them again to put it back in the right
order. But is it possible to eliminate these two reverse operations and do
the calculation in backwards direction? (no FOR loops, too slow!)

The vector is fairly short but this function will get called a lot.

Richard Clark
rclark@lpl.arizona.edu
--
Still working on the other 999 lines.
Re: reversing calculation order [message #4105 is a reply to message #4087] Thu, 04 May 1995 00:00 Go to previous messageGo to next message
Fergus Gallagher is currently offline  Fergus Gallagher
Messages: 41
Registered: January 1995
Member
rclark@phantasos.lpl.arizona.edu (Richard Clark) wrote:
>
> I need to fill in some values for a vector from a recurrence relation.
>
> V(0:N-1) = func(V(1:*)) ;I wish there was a shorthand for (*-1)
>
> Where V(N) is the only value initially defined (Well actually it is
> calculated from an ascending recurrence relation but the values of
> V(0:N-1) from that step are of no further interest. The results of the
> second recurrence are the ones returned.)
>
> I know that ROTATE can be used to reverse the order of the vector for the
> calculation, and then reverse them again to put it back in the right
> order. But is it possible to eliminate these two reverse operations and do
> the calculation in backwards direction? (no FOR loops, too slow!)
>
> The vector is fairly short but this function will get called a lot.
>


Vector elements can be accessed with other vectors, e.g.,

IDL> x = fltarr(n)
IDL> i = n-1-indgen(n)

IDL> y = cumulative_sum(x(i)) ; made-function that is order dependent
IDL> z = y(i) ; reverse it again

As an additional point, any function enclosed in () becomes a vector, so
that the above could have been abbreviated to

IDL> y = (cumulative_sum(x(i)))(i)

Mind you, ROTATE is pretty fast.......

Fergus

=================================================
| Fergus Gallagher |
| Remote Sensing Applications Development Unit |
| British National Space Centre |
| Monks Wood |
| Huntingdon PE17 2LS / UK |
| |
| F.Gallagher@nerc.ac.uk |
| http://uh.nmt.ac.uk/bnsc/fgg.html |
=================================================
Re: reversing calculation order [message #4190 is a reply to message #4087] Fri, 05 May 1995 00:00 Go to previous message
amaravad is currently offline  amaravad
Messages: 11
Registered: September 1994
Junior Member
Is there an IDLized way to compute the cummulative sum of an array.

func=findgen(N)
cumm_sum=fltarr(N)
for i=0,N-1 do cumm_sum(i)=total(func(0:i))

How can I eliminate the for loop in the above code.

thanks

ratty
--
Ratnakar Amaravadi Software/Hardware Engineer
Department of Radiology I.U. School of Medicine
(317)274-1843 (w) amaravad@indiana.edu
(317)274-4074 (fax) ratty@foyt.indyrad.iupui.edu
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Envi ROI Spectral/Bandmath
Next Topic: Is there an emacs mode??

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

Current Time: Wed Oct 08 19:42:17 PDT 2025

Total time taken to generate the page: 0.00515 seconds