Re: distance function

• To: mathgroup at smc.vnet.net
• Subject: [mg70095] Re: distance function
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Tue, 3 Oct 2006 06:16:44 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <200609300912.FAA13156@smc.vnet.net> <efq5f5\$28g\$1@smc.vnet.net>

```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:

In[1]:=
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]

Out[3]=
{{0.,1.00434,0.161348},{1.00434,0.,0.845952},{0.161348,0.845952,0.}}

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}}];

HTH,
Jean-Marc

```

• 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