Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg70095] Re: distance function
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at>
  • Date: Tue, 3 Oct 2006 06:16:44 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <> <efq5f5$28g$>

Chris Chiasson wrote:
> 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]

Hi Chris,

Written in the following way, Compile does not complain anymore:

pts[1] = Table[{Random[], Random[]}, {3}];
ccC = Compile[{{p, _Real, 1}, {q, _Real, 1}},
     If[p == q, 0, (Sqrt[#1 . #1] & )[p - q]]];
Outer[ccC, pts[1], pts[1], 1]


This, of course, does not explain why in first instance Compile was 
expecting a rank 1 vector. Using the optional argument of Compile to 
tell Mathematica what is the return type of an external function does 
not help either:

ccC = Compile[{{p, _Real, 1}, {q, _Real, 1}}, cc[p, q], {{cc, _Real, 0}}];


  • Prev by Date: Re: variance of product of random variables
  • Next by Date: Another Minor Mathematica Front End Glitch/Bug
  • Previous by thread: Re: RE: Re: Re: distance function
  • Next by thread: Re: distance function