pdist2 - bottleneck is in argument parsing

2 views (last 30 days)
Nicholas Bauer
Nicholas Bauer on 11 Jul 2018
Answered: OCDER on 11 Jul 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 Comment
dpb
dpb on 11 Jul 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.

Sign in to comment.

Answers (1)

OCDER
OCDER on 11 Jul 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)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!