RE: Function compile problems

*To*: mathgroup at smc.vnet.net*Subject*: [mg26211] RE: [mg26128] Function compile problems*From*: "Ersek, Ted R" <ErsekTR at navair.navy.mil>*Date*: Sat, 2 Dec 2000 02:10:38 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

Dave Withoff and I replied to a question from Chris Krautschik on how to get a CompiledFunction to run efficiently. Dave Withoff is a Mathematica guru, and I am not quite as far along. I will not be surprised if I made a mistake here, but I can't see it. In the lines below it seems Dave Withoff's version runs slower than standard evaluation and my version runs faster than standard evaluation. Am I wrong? This is the first time I have seen the 3rd argument in Compile used, and I don't get results I am comfortable with. I would like to have a good example that demonstrates use of the 3rd argument in Compile. (****************************) (*** Standard Evaluation ****) In[1]:= Do[Map[ First[#] * Cos[4*Last[#]]&, Table[{x, y}, {x, -1.0, 1.0, 0.5}, {y, 1.0, -1.0, -0.5}], {2} ],{10^3} ]//Timing Out[2]= {1.37 Second,Null} (****************************) (*** Dave Withoff **********) In[3]:= f1=Compile[{{n,_Integer}}, g[{r_,t_}]:=r Cos[n t]; xy=Table[{x,y},{x,-1,1,0.5},{y,1,-1,-0.5}]; Map[g,xy,{2}], {{_g,_Real}} ]; Do[f1[4],{10^3}]//Timing Out[4]= {3.52 Second,Null} (****************************) (*** Ted Ersek **************) In[5]:= f2 =Compile[{{n, _Integer}}, Map[ First[#] * Cos[n*Last[#]]&, Table[{x, y}, {x, -1.0, 1.0, 0.5}, {y, 1.0, -1.0, -0.5}],{2} ] ]; Do[f2[4],{10^3}]//Timing Out[6]= {0.28 Second,Null} -------------------- Regards, Ted Ersek Download Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html

**Follow-Ups**:**Re: RE: Function compile problems***From:*"Carl K. Woll" <carlw@u.washington.edu>