speeding up symmetric distance matrix computation

1 Ansicht (letzte 30 Tage)
gdgc
gdgc am 7 Dez. 2017
Bearbeitet: gdgc am 7 Dez. 2017
Hi everyone,
I'm currently working on some discrete vortex algorithm, and the main time consuming part can be sumed up by these few lines :
% initilization
n=1e4;
z=complex(rand(1,n),rand(1,n)); % vortices complex position
gam=rand(n,1); % circulation of vortices
% the part i'm trying to speed up
vel=gam./(z-z.');
vel(1:n+1:end)=0;
sumvel=sum(vel,1);
This involves the computation of a distance matrix, which is symmetric, so theoretically it should be possible to reduce the computation time of the z-z.' part.
I tried to use :
  • matlab dist and pdist builtin functions
  • custom (for i=1:n, for j=i+1:n) loops to avoid computing symmetric terms.
  • some mathworks file exchange functions, such as this one
Unfortunately, no one is faster than the brute force original one. Probably because it is using the full potential of vectorization. I precise that I don't need to compute it for thousands and thousands of points (5000 maximum), so I'm not limited or slowed down by huge memory transfer.
However I need to loop that process millions of time, and speeding it up a little would save me hours.
Any suggestion would be more than welcomed.

Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by