pdist2 - bottleneck is in argument parsing

2 vues (au cours des 30 derniers jours)
Nicholas Bauer
Nicholas Bauer le 11 Juil 2018
Réponse apportée : OCDER le 11 Juil 2018
I'm profiling some code to see where the bottlenecks are, and I saw the bottleneck was in pdist2--expected.
What was unexpected is that the profiler is showing that there are two hot spots: 17% in pdist2mex and 37% in internal.stats.parseArgs(!). It's spending twice as much time parsing arguments as calculating distances.
How can I eliminate this overhead?
  1 commentaire
dpb
dpb le 11 Juil 2018
For a specific case you could probably decipher the arguments and call pdist2mex directly if your data are suitably arranged.
I've not looked at the details recently so don't recall just what is done up front otomh.

Connectez-vous pour commenter.

Réponses (1)

OCDER
OCDER le 11 Juil 2018
To bypass the overhead, you could make your own MEX file for pdist2. Or, use pdist2mex directly, but then you'll have to find this mex file and pull it out of the private folder into your own folder in the matlab path.
EXAMPLE
X = randn(100, 5);
Y = randn(25, 5);
dist = 'euc';
additionalArg = [];
smallestLargestFlag = [];
radius = [];
D = pdist2mex(X',Y',dist,additionalArg,smallestLargestFlag,radius); %Same as pdist2(X, Y, dist)

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by