Re: RE: Function compile problems
- To: mathgroup at smc.vnet.net
- Subject: [mg26218] Re: [mg26211] RE: [mg26128] Function compile problems
- From: "Carl K. Woll" <carlw at u.washington.edu>
- Date: Sun, 3 Dec 2000 18:05:52 -0500 (EST)
- References: <200012020710.CAA14568@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Ted, I think you misunderstood Dave's comment. He wasn't trying to make Chris' code run more efficiently, he was trying to explain how to make the code work, since the original code wasn't able to be compiled as the compiler didn't know what to do with g. By adding the third argument to the Compile function, and changing nothing else in the function to be compiled, the compiler was able to figure out how to compile the function. As far as efficient code goes, my attempt goes something like this x=Range[-1,1,.5] tmp=Cos[4 x] Block[{tmp},x tmp] which in my tests is ~5 times faster than the Map alternative you presented. Carl Woll Physics Dept U of Washington ----- Original Message ----- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil> To: mathgroup at smc.vnet.net Subject: [mg26218] [mg26211] RE: [mg26128] Function compile problems > 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 > >
- References:
- RE: Function compile problems
- From: "Ersek, Ted R" <ErsekTR@navair.navy.mil>
- RE: Function compile problems