I have two point sets `point`

and `impPoint`

. I want to calculate a distance function from each element in the `point`

set to all elements in `impoint`

sets. I have written a compiled version of the function, but its speed is a little slow. Is there any way to speed up the code?

```
w=0.1;
qs=0.1;
n=200;
nn=n*n;
nimp=0.1;
Nimp=IntegerPart(nimp*nn);
point=RandomReal(1,{nn,2});
impPoint=RandomSample(point,Nimp);
pm=ReplacePart(Table(1,Nimp),(RandomSample(Range(1,Nimp,1),Nimp/2)//Partition(#,1)&)->-1);
cf=Compile({{w,_Real},{qs,_Real},{pm,_Real,1},{Nimp,_Real},{impPoint,_Real,2},{point,_Real,1}},Total(Table(w/qs^2*Exp(-(((point((1))-impPoint((i,1)))^2+(point((2))-impPoint((i,2)))^2))/qs^2),{i,1,Nimp})*pm),CompilationTarget->"C",Parallelization->True,RuntimeAttributes->{Listable},RuntimeOptions->"Speed");
AbsoluteTiming(cf(w,qs,pm,Nimp,impPoint,point)//Total)
```

In fact, `n`

takes 5000, so I don’t recommend using `DistanceMatrix`

, because it saves time but costs a lot of memory.