Re: distance function
- To: mathgroup at smc.vnet.net
- Subject: [mg70138] Re: distance function
- From: Peter Pein <petsie at dordos.net>
- Date: Thu, 5 Oct 2006 03:32:36 -0400 (EDT)
- References: <200609300912.FAA13156@smc.vnet.net> <efq5f5$28g$1@smc.vnet.net>
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