-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile_dt_mex.m
78 lines (68 loc) · 2.09 KB
/
compile_dt_mex.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function compile_dt_mex(varargin)
%COMPILE_DT_MEX Compile MEX versions of dynamic time warping functions
% In addition to MATLAB versions of the dynamic time warping code, this
% repository offers MEX versions, which are much preferred. The MEX
% versions offer close to a 100x speed benefit and are designed to use
% substantially less memory.
%
% The repository includes Mac versions of the MEX files already compiled,
% but this function allows compiling the MEX files for other platforms.
%
% If you see warnings about non-MEX implementations when running code
% from this repository, call this function once to compile the MEX
% functions.
%
% No parameters are required, but you can optionally provide parameters:
%
% COMPILE_DT_MEX('debug', true) turns off optimizations, adds debugging
% symbols to the binaries and turns on verbose compilation, all to help
% debug issues with the MEX files.
%
% COMPILE_DT_MEX('warnings', true) turns on all warnings during compile
% time (only tested with Clang compiler).
%% parameters
debug = false;
warnings = false;
% load custom parameters
nparams = length(varargin);
if 0 < mod(nparams, 2)
error('Parameters must be specified as parameter/value pairs');
end
for i = 1:2:nparams
nm = lower(varargin{i});
if ~exist(nm, 'var')
error('Invalid parameter: %s.', nm);
end
eval([nm ' = varargin{i+1};']);
end
% switch to directory
old_dir = pwd;
new_dir = fileparts(mfilename('fullpath'));
cd(fullfile(new_dir, 'private'));
% print nice message
fprintf('Compiling DTW functions...\n');
c = {};
% show warnings
if warnings
c{end + 1} = 'CFLAGS="\$CFLAGS -Weverything"';
end
% enable debugging
if debug
c{end + 1} = '-g';
c{end + 1} = '-v';
else
c{end + 1} = '-silent';
end
% include Accelerate framework
if ismac
c{end + 1} = 'LDFLAGS="\$LDFLAGS -framework Accelerate"';
end
% call mex functions
functions = {'dtpa', 'dtw_path', 'dtw_ua', 'dtw_ua_cos'};
for j = 1:length(functions)
fprintf('%s\n', functions{j});
d = [c [functions{j} '.c']];
mex(d{:});
end
% return to old directory
cd(old_dir);