N(N-1)/2 distances from a d*N matrix of column vectors (5000<N<50000)

1 view (last 30 days)
I have a d*N matrix of column vectors for 5000<N<50000 and wish to calculate the N(N-1)/2 distances between the vectors. The program permutes the vectors by indexing the matrix with a pair of FOR loops.
(1) Can anyone guestimate the potential speed up if I create a MEX file first?
(2) Is Matlab Coder the only way to make MEX files that Matlab can read directly?
(3) I understand it is possible to (i) interface with Xcode (ii) run .exe files from Matlab on Windows machines - Whats the simplest way of running Xcode/C++ compiled code from Matlab on a Mac?
Many thanks & Regards

Answers (2)

Ryan Livingston
Ryan Livingston on 17 Aug 2017
Edited: Ryan Livingston on 17 Aug 2017
(1) Estimating speedup is very difficult because it depends on so many factors. Here's some of the documentation Coder provides about MEX acceleration:
As the first link says, it is best to profile your code in MATLAB using the MATLAB profiler. This will point out expensive sections. You can then move those expensive parts into separate functions, generate code from those functions, and use the generated MEX files.
Also note, that if the runtime is dominated by built-in operations/functions like svd, lu, fft, then MATLAB Coder likely won't speed up the code since those operations are already compiled in MATLAB.
(2) You can hand write C, C++, and Fortran and compile those into MEX files as well:
(3) Could you elaborate on what you'd like to accomplish by interfacing compiled code from MATLAB? Do you want to use XCode to compile the MEX? Are you looking to use a shared library in MATLAB? Are you looking to just invoke an executable from MATLAB like you could do with the system command or ! operator?

Torsten
Torsten on 17 Aug 2017
Generate a copy of the matrix and use the solution given under
https://statinfer.wordpress.com/2011/11/14/efficient-matlab-i-pairwise-distances/
Best wishes
Torsten.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!