speeding up symmetric distance matrix computation

1 visualizzazione (ultimi 30 giorni)
gdgc
gdgc il 7 Dic 2017
Modificato: gdgc il 7 Dic 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.

Risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by