MathGroup Archive 1996

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

Search the Archive

Re: "Compile[]" and "InterpolatingFunction" objects

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3012] Re: "Compile[]" and "InterpolatingFunction" objects
  • From: Robert Knapp <rknapp>
  • Date: Mon, 22 Jan 1996 03:06:55 -0500
  • Organization: Wolfram Research, Inc.

Jonathan Rich wrote:
> 
> I am trying to produce efficient compiled code which evaluates an expression
> that includes "InterpolatingFunction" objects.  So I have two questions:
> 
> 1) Are "InterpolatingFunction" objects Compiled by default?  The Book doesn't
> say although in Appendix A.8 under "InterpolatingFunction" it says
> `See also:  CompiledFunction'.
> 
No.  The reference is not to InterpolatingFunction objects being
compiled, but being similar to CompiledFunction objects in that they
only evaluate for numeric arguments.

> 2)  How do I compile an InterpolatingFunction w/o having the compiled
> pseudocode
> use an external evaluation (pseudocode instruction # 24) for the result of the
> InterpolatingFunction?  Here is a simple example:
> 
> list=Table[{i,i},{i,4}];
> interpFunc=Interpolation[list];
> f1=Compile[{x},Evaluate[interpFunc[x]]];
> f1//InputForm
> 
> In the output you will see that the compiled code uses an external evaluation,
> which defeats the whole purpose of using "Compile[]" (which is to speed up the
> computation--it may be that "Interpolation[]" produces compiled code, but I
> can't find this documented anywhere).
> 
The evaluation of an InterpolatingFunction object with its argument
requires going through the Mathematica evaluator.
InterpolatingFunctions evaluate via internal code, so are not evaluated
by the compiled function interpreter.  Thus, the result of the above
lines is (very slightly) less efficient than the InterpolatingFunction
itself.  

There are situations where it is of advantage to Compile an
InterpolatingFunction object.  This occurs when either its argument is a
complicated function or you are computing some complicated function of
the result.  

For example:

list=Table[{i,i},{i,4}];
interpFunc=Interpolation[list];
f1=Compile[{x},Evaluate[(Tan[interpFunc[Exp[Sin[x^2+x-1]+x]]])^2]];

> Thanks for your help on this.

Substantial changes have been made to the structure of
InterpolatingFunction objects for Version 3.0.  With these changes,
compiling an InterpolatingFunction object will result in the evaluation
being done using only machine numbers, which is substantially faster.

Rob Knapp
WRI
> 
> --
> Jonathan Rich
> Geoscience Dept., Northwestern Univ.

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: Readability suggestions
  • Next by Date: Re: "Compile[]" and "InterpolatingFunction" objects
  • Previous by thread: RE: "Compile[]" and "InterpolatingFunction" objects
  • Next by thread: Re: "Compile[]" and "InterpolatingFunction" objects