-
Notifications
You must be signed in to change notification settings - Fork 0
/
mexme_gentleboost.m
178 lines (142 loc) · 4.97 KB
/
mexme_gentleboost.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
function mexme_gentleboost(options)
warning off;
echo on
files1 = {'gentleboost_predict' , 'srng_model' , 'NN_predict'};
files2 = {'gentleboost_model'};
files3 = {'svmtrain.c svm.cpp svm_model_matlab.c' , 'svmpredict.c svm.cpp svm_model_matlab.c'};
if( (nargin < 1) || isempty(options) )
options.config_file = [];
options.ext = [];
options.useOMP = 0;
options.userBLAS = [];
end
if(~any(strcmp(fieldnames(options) , 'config_file')))
options.config_file = [];
end
if(~any(strcmp(fieldnames(options) , 'useOMP')))
options.useOMP = 0;
end
if(~exist(options.config_file , 'file'))
options.config_file = [];
end
if(ispc)
if (~exist(options.config_file , 'file'))
optpath = prefdir;
mexoptfile = [optpath filesep 'mexopts.bat'];
else
mexoptfile = options.config_file;
end
res = getmexopts(mexoptfile);
if(strcmp(res , 'lcc'))
tempdir = fullfile(matlabroot , 'extern\lib\win32\lcc');
if(options.useOMP==1)
disp('OMP option can''t be used with LCC compiler, force to 0')
options.useOMP = 0;
end
elseif(strcmp(res , 'cl') || strcmp(res , 'icl'))
tempdir = fullfile(matlabroot , sprintf('extern\\lib\\%s\\microsoft', computer('arch')));
end
if(isempty(options.userBLAS))
if(exist(fullfile(tempdir , 'libmwblas.lib') , 'file') == 2)
libblas = ['"' , fullfile(tempdir , 'libmwblas.lib') , '"'];
else % prior version of matlab %
libblas = ['"' , fullfile(tempdir , 'libmwlapack.lib') , '"'];
end
else
libblas = options.userBLAS;
end
else
libblas = '-lmwblas';
end
strOMP = [];
if(options.useOMP)
if(ispc)
if(strcmp(res , 'cl'))
strOMP = ' COMPFLAGS="$COMPFLAGS /openmp" ';
elseif(strcmp(res , 'icl'))
strOMP = ' COMPFLAGS="$COMPFLAGS /Qopenmp" ';
end
else
strOMP = ' CFLAGS="\$CFLAGS -fopenmp -Wall" LDFLAGS="\$LDFLAGS -fopenmp" ';
end
end
try
for i = 1 : length(files1)
str = [];
if(options.useOMP)
str = '-v -DOMP';
end
if(~isempty(options.config_file))
str = [str, ' -f ' , options.config_file , ' '];
end
if(~isempty(options.ext))
str = [str , '-output ' , files1{i} , '.' , options.ext , ' '];
end
str = [str , files1{i} , '.c ' , libblas , strOMP];
disp(['compiling ' files1{i}])
eval(['mex ' str])
end
C = computer;
for i = 1 : length(files2)
str = [];
if(strcmp(C , 'PCWIN64') || strcmp(C , 'GLNXA64') || strcmp(C , 'MACI64') || strcmp(C , 'SOL64'))
str = '-DOS64 -largeArrayDims ';
end
if(options.useOMP)
str = [str , '-v -DOMP '];
end
if(~isempty(options.config_file))
str = [str, ' -f ' , options.config_file , ' '];
end
if(~isempty(options.ext))
str = [str , '-output ' , files2{i} , '.' , options.ext , ' '];
end
str = [str , files2{i} , '.c ' , libblas , strOMP];
disp(['compiling ' files2{i}])
eval(['mex ' str])
end
for i = 1 : length(files3)
str = [];
if(strcmp(C , 'PCWIN64') || strcmp(C , 'GLNXA64') || strcmp(C , 'MACI64') || strcmp(C , 'SOL64'))
str = '-largeArrayDims ';
end
temp = files3{i};
ind = find(isspace(temp));
[dummy , name] = fileparts(temp(1:ind-1));
if(~isempty(options.ext))
str = [str , '-output ' , name , '.' , options.ext , ' '];
end
str = [str , temp];
disp(['compiling ' name])
eval(['mex ' str])
end
catch exception
if(~isempty(exception))
fprintf(['\n Error during compilation, be sure to:\n'...
'i) You have C compiler installed (prefered compiler are MSVC/Intel/GCC)\n'...
'ii) You did "mex -setup" in matlab prompt before running mexme_gentleboost\n']);
end
end
echo off
function res = getmexopts(mexoptfile)
% function res = getmexopts(Tag)
% Get the MCC or MEX configuration
% Author Bruno Luong <brunoluong@yahoo.com>
% Last update: 29-Jun-2009
Tag = 'COMPILER';
% Try to get MEX option first
fid=fopen(mexoptfile,'r');
if fid>0
iscompilerline=@(S) (strcmp(S,['set ' Tag]));
C=textscan(fid,'%s %s', 'delimiter', '=', 'whitespace', '');
fclose(fid);
cline=find(cellfun(iscompilerline,C{1}));
if isempty(cline)
error('getmexopt [Bruno]: cannot get Tag %s', Tag)
end
res=C{2}{cline};
root=regexprep(matlabroot,'\\','\\\\');
res = regexprep(res,'%MATLAB%',root);
else
error('getmexopts [Bruno]: cannot open comopts.bat file')
end