Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: distance function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70146] Re: distance function
  • From: "Chris Chiasson" <chris at chiasson.name>
  • Date: Thu, 5 Oct 2006 03:33:04 -0400 (EDT)
  • References: <200609300912.FAA13156@smc.vnet.net> <efq5f5$28g$1@smc.vnet.net> <4523F71B.8020509@dordos.net>

thanks!

I thought compile could go "inside" the function.

Of course, evaluating the code before compilation leaves out one of my
pattern definitions :-[

On 10/4/06, Peter Pein <petsie at dordos.net> wrote:
> Chris Chiasson schrieb:
> > Could someone please explain why Mathematica seems to be expecting the
> > output of cc to be a vector?
> >
> > pts[1]=Table[{Random[],Random[]},{3}];
> > cc[p_,p_]=0;
> > cc[p_,q_]:=cc[q,p]=Sqrt[#.#]&[p-q];
> > ccC=Compile[{{p,_Real,1},{q,_Real,1}},cc[p,q]];
> > Outer[ccC,pts[1],pts[1],1]
> >
>
> I guess it's because p and q are vectors and compile doesn't analyze cc.
>
> b.t.w. It doesn't make much sense to compile only the call to a function
> but not the function itself:
>
> pts[1] = Table[Random[], {1000}, {2}];
> ccC = Compile[{{p, _Real, 1}, {q, _Real, 1}}, cc[p, q], {{_cc, _Real}}];
> Timing[Outer[ccC, pts[1], pts[1], 1];]
>
> lasts 17.5 seconds but if you compile cc inline:
>
> pts[1] = Table[Random[], {1000}, {2}];
> ccC = Compile[{{p, _Real, 1}, {q, _Real, 1}}, Evaluate@cc[p, q]];
> Timing[Outer[ccC, pts[1], pts[1], 1];]
>
> only 1.8 seconds are necessary.
>
> Peter
>


-- 
http://chris.chiasson.name/


  • Prev by Date: Re: Re: distance function
  • Next by Date: RE: Re: Performance--Dual Core
  • Previous by thread: Re: distance function
  • Next by thread: Re: HoldPattern question