MathGroup Archive 2007

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

Search the Archive

Re: Compile a Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83172] Re: Compile a Module
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 13 Nov 2007 07:02:27 -0500 (EST)
  • Organization: Uni Leipzig
  • References: <fhbnuc$r4s$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de

Hi,
cAlongAway =
  Compile[{{tip, _Real, 1}, {end, _Real, 1}, {calc, _Real, 1}},
   Module[{mid, r, theta},
    mid = (tip + end)/2;
    r = Sqrt[Dot[calc - mid, calc - mid]];
    theta = VectorAngle[calc - mid, end - mid];
    {r Cos[theta], r Sin[theta]}]]

??
but you see when you look ino the compiled code
there is still the call to VectorAngle[] and usual such
a call degrade the execution speed of the
compiled function.

Regards
   Jens

JOHN ERB wrote:
> Can the following module be compiled?
>   It needs to be used 10^4 times in my program.
>   It is used to calculate the distance parallel and perpendicular
>   to the midpoint of  2D line segment with reference to a point of interest (calc).
>    
>   AlongAway[{tip_,end_,calc_}]:=Module[{mid,r,theta,along,away},
> mid=(tip+end)/2;
> r=Sqrt[Dot[calc-mid,calc-mid]];
> theta=VectorAngle[calc-mid,end-mid];
> along=r Cos[theta];
> away=r Sin[theta];
> {along,away}]
>    
>   AlongAway[{{-1, 0}, {1, 0}, {2, 1}}]
> (* answer is {2,1} *)
>    
>   (* the code below does not seem to work *)
>   cAlongAway=Compile[{{tip,_Real},{end,_Real},{calc,_Real}},AlongAway]
>    
>   John C. Erb
> 


  • Prev by Date: Re: Mac OS X 10.5 - Mathematica 5.1 hangs - 6.0 works?
  • Next by Date: Re: Compile a Module
  • Previous by thread: Compile a Module
  • Next by thread: Re: Compile a Module