MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Question about Compiling, external functions, and For loops

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56500] Question about Compiling, external functions, and For loops
  • From: Ravi Balasubramanian <ravib at andrew.cmu.edu>
  • Date: Tue, 26 Apr 2005 21:53:38 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Math Group-ers,

[Contact the author to get the notebook attachment mentioned below
    -  moderator]

I think I have a pretty standard problem, but I was unable to find a 
solution either in the help pages or in Mathgroup; apologies if the 
answer is already online; I will really appreciate it if you can direct 
me to it.

My code is attached in an nb file.  I have a function findCost2, created 
as a module, that must be called many times in a for-loop.  Since I have 
to call it so many times, I want to compile the whole for-loop.  Here 
are the specifics:

findCost2 is an interpolation function: given a two-d matrix of costs, 
and a new state, it finds the cost of the new state by interpolating the 
nearby values.  I pass findCost2 the matrix of costs, the list of states 
(given in two 1-d arrays, viz., thetaTable and thetapTable), and the new 
state; it returns a cost value.

compiledLoop is a compiled module that calls findCost2 many times, while 
uncompiledLoop is an uncompiled module that calls findCost2 many times. 
  Here is a comparison of the two speeds.
compiledLoop Time: 134.734 Second
uncompiledLoop Time: 136. Second

I notice that there is not much gain in compiling, probably because of 
the external calls to findCost2; but I would really prefer not include 
the code in findCost2 into the loop.  This seems to be a standard 
question in the Mathgroup archives; is there a solution?  Any 
suggestions?  Help greatly appreciated.

Ravi Balasubramanian
The Robotics Institute,
Carnegie Mellon University



  • Prev by Date: Re: odd mathematica blindspot
  • Next by Date: Re: odd mathematica blindspot
  • Previous by thread: Re: Converting a mapping into a well-defined function
  • Next by thread: Programming