Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

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



  • Prev by Date: Re: Implicit Derivatives
  • Next by Date: Problems installing ExtendGraphics MathLink libraries in linux
  • Previous by thread: Re: Arithmetic simplification
  • Next by thread: Re: RE: Function compile problems