Re: Re: Interpoint distances
- To: mathgroup at smc.vnet.net
- Subject: [mg41394] Re: [mg41372] Re: Interpoint distances
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sat, 17 May 2003 05:51:45 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
If you do not mind using your Union cheat than here is a very fast method based on completely different idea form all the others. It actually does count all the distances twice, yet still it is still much faster than my previous version. We first define the function that solves the same problem for complex numbers rather than points, and we compile it: ComplexIntD=Compile[{{t,_Complex,1}},Union[Flatten[Abs[Table[t- RotateLeft[ t,i],{i,1,Length[t]-1}]]]]]; Now all we need to do is to convert a list of points to a list of complex numbers and apply the above function: intD2[l_List]:=ComplexIntD[Complex@@@l] For a list of 500 numbers I get t = Table[{Random[], Random[]}, {500}]; intD2[t];//Timing {1.23 Second,Null} which on my 400 megahertz machine is over 40 times faster than your code. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ On Friday, May 16, 2003, at 07:45 pm, DIAMOND Mark R. wrote: > Andrej, > > You are quite right. Union was a cheat ... relying on the fact that the > probability of two random reals in [0,1] being equal was zero (rather > than > impossible), and obviously somewhat more likely with finite precision. > > I have a slow machine ... so I'm very grateful for the speedup > suggestions > and will compare them over the weekend and post the results. > > Cheers, > Mark > -- > Mark R. Diamond > > > > > >