-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall_mex.m
94 lines (84 loc) · 3.16 KB
/
install_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function install_mex(VERB)
% install_mex
% installs mex files for SoftImpute and PROPACK package
% install_mexSimple( verbose )
% will display more verbose diagnoistic messages
% if the variable "verbose" is true.
%
% This install_mex file has been modified by Rahul Mazumder based on the one
% written by Stephen Becker, Jan 2010 for their SVT package
if nargin < 1 || ~VERB
VERBOSE = '';
else
VERBOSE = '-v';
end
X='';
if ispc
cc = get_compiler_config();
if strcmpi(cc,'microsoft'), cc = 'microsoft';
else, cc = 'lcc'; % Matlab's bundled compiler
end
c = computer;
if strfind(c,'64')
libpath = fullfile(matlabroot,'extern','lib','win64',cc);
else
libpath = fullfile(matlabroot,'extern','lib','win32',cc);
end
LAPACK = fullfile(libpath,'libmwlapack.lib');
BLAS = fullfile(libpath,'libmwblas.lib');
WIN = '-DWINDOWS';
else
WIN = '-UWINDOWS';
LAPACK = '-lmwlapack';
% on linux/unix, sometimes MATLAB won't install its mwblas library
% if the system already has a blas library. So check for this:
% (note, not in the same location as on Windows)
c = lower(computer);
if ismac, suffix = '.dylib'; else suffix = '.so'; end
blasFile = fullfile(matlabroot,'bin',c, ['libmwblas',suffix] );
if exist(blasFile,'file')
BLAS = '-lmwblas';
else
BLAS = '-lblas';
X='-DNO_BLAS'; % tell it not to include blas.h
end
end
EXT = []; % for native. Use this when compiling for your own computer
% 2006a is v 7.2
if verLessThan('matlab', '7.3')
LARGEARRAYDIMS = [];
Y='-DNO_MATRIX_H'; % don't include matrix.h 'cause it doesn't exist!
else
LARGEARRAYDIMS = '-largeArrayDims';
Y=[];
end
OPT = '-O';
% compile PROPACK
cd PROPACK_utils
mexHelper(VERBOSE,WIN,OPT,LARGEARRAYDIMS,EXT,'bdsqr_mex.c','dbdqr.c','-output','bdsqr',LAPACK,BLAS,X,Y);
mexHelper(VERBOSE,WIN,OPT,LARGEARRAYDIMS,EXT,'reorth_mex.c','reorth.c','-output','reorth',LAPACK,BLAS,X,Y);
cd ..
% compile SoftImpute code
cd Matlab_files
mexHelper(VERBOSE,WIN,OPT,LARGEARRAYDIMS,EXT,'project_obs_UV.c',BLAS,X,Y);
cd ..
function cc = get_compiler_config()
% tested on Windows w/ R2008 only
% This has to be in a function, otherwise old versions of matlab
% get confused because "mex" is used as a structure (well, a class)
% AND as a function.
try
% this requires both a new verson of matlab and
% that a compiler has been selected
cc = mex.getCompilerConfigurations('C');
cc = cc.Manufacturer;
% Watch out for this error later (in old versions of matlab)
% MATLAB:mir_error_function_previously_indexed_by_dot
catch
cc = [];
fprintf('You may want to run ''mex -setup'' to setup the mex compiler,\n if you''ve never used the mex compiler before\n');
wbsite='http://www.mathworks.com/support/solutions/en/data/1-6IJJ3L/index.html?solution=1-6IJJ3L';
fprintf('If you have version 2008b or newer, and 64-bit Windows,\n');
fprintf('then MATLAB does not come with a builtin compiler\n');
fprintf('If you need a free C/C++ compiler, please see this mathworks website:\n%s\n',wbsite);
end