[37] | 1 | %Install_lightspeed |
---|
| 2 | % Compiles mex files for the lightspeed library. |
---|
| 3 | |
---|
| 4 | % Written by Tom Minka |
---|
| 5 | % (c) Microsoft Corporation. All rights reserved. |
---|
| 6 | |
---|
| 7 | % thanks to Kevin Murphy for suggesting this routine. |
---|
| 8 | |
---|
| 9 | fprintf('Compiling lightspeed mex files...\n'); |
---|
| 10 | fprintf('Change directory to lightspeed for this to work.\n'); |
---|
| 11 | |
---|
| 12 | % Matlab version |
---|
| 13 | v = sscanf(version,'%d.%d.%*s (R%d) %*s'); |
---|
| 14 | % v(3) is the R number |
---|
| 15 | % could also use v(3)>=13 |
---|
| 16 | atleast65 = (v(1)>6 || (v(1)==6 && v(2)>=5)); |
---|
| 17 | |
---|
| 18 | % copy matlab's original repmat.m as xrepmat.m |
---|
| 19 | if exist('xrepmat.m') ~= 2 |
---|
| 20 | w = which('repmat','-all'); |
---|
| 21 | cmd = ['"' w{end} '" xrepmat.m']; |
---|
| 22 | if ispc |
---|
| 23 | system(['copy ' cmd]); |
---|
| 24 | else |
---|
| 25 | system(['cp -rp ' cmd]); |
---|
| 26 | end |
---|
| 27 | end |
---|
| 28 | |
---|
| 29 | % Routines that use LAPACK |
---|
| 30 | if ispc |
---|
| 31 | if strcmp(mexcompiler,'cl') |
---|
| 32 | if atleast65 |
---|
| 33 | % version >= 6.5 |
---|
| 34 | lapacklib = fullfile(matlabroot,'extern\lib\win32\microsoft\libmwlapack.lib'); |
---|
| 35 | end |
---|
| 36 | else |
---|
| 37 | lapacklib = fullfile(matlabroot,'extern\lib\win32\lcc\libmwlapack.lib'); |
---|
| 38 | end |
---|
| 39 | if ~exist(lapacklib,'file') |
---|
| 40 | lapacklib = 'dtrsm.c'; |
---|
| 41 | fprintf('libmwlapack.lib was not found. To get additional optimizations, paste its location into install_lightspeed.m\n'); |
---|
| 42 | else |
---|
| 43 | fprintf('Using the lapack library at %s\n',lapacklib); |
---|
| 44 | end |
---|
| 45 | %%% Paste the location of libmwlapack.lib %%% |
---|
| 46 | %lapacklib = ''; |
---|
| 47 | clear functions |
---|
| 48 | eval(['mex solve_triu.c "' lapacklib '"']); |
---|
| 49 | eval(['mex solve_tril.c "' lapacklib '"']); |
---|
| 50 | else |
---|
| 51 | % UNIX |
---|
| 52 | mex solve_triu.c |
---|
| 53 | mex solve_tril.c |
---|
| 54 | end |
---|
| 55 | |
---|
| 56 | mex -c flops.c |
---|
| 57 | mex sameobject.c |
---|
| 58 | mex int_hist.c |
---|
| 59 | mex -c mexutil.c |
---|
| 60 | mex -c util.c |
---|
| 61 | |
---|
| 62 | if ispc |
---|
| 63 | % Windows |
---|
| 64 | %if exist('util.obj','file') |
---|
| 65 | mex addflops.c flops.obj |
---|
| 66 | mex digamma.c util.obj |
---|
| 67 | mex gammaln.c util.obj |
---|
| 68 | mex randbinom.c util.obj |
---|
| 69 | mex randgamma.c util.obj |
---|
| 70 | mex repmat.c mexutil.obj |
---|
| 71 | mex sample_hist.c util.obj |
---|
| 72 | mex trigamma.c util.obj |
---|
| 73 | try |
---|
| 74 | % standalone programs |
---|
| 75 | % compilation instructions are described at: |
---|
| 76 | % http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/ch1_im15.html#27765 |
---|
| 77 | if atleast65 |
---|
| 78 | % -V5 is required for Matlab >=6.5 |
---|
| 79 | mex -f lccengmatopts.bat matfile.c -V5 |
---|
| 80 | %mex -f msvc71engmatopts.bat matfile.c -V5 |
---|
| 81 | else |
---|
| 82 | mex -f lccengmatopts.bat matfile.c |
---|
| 83 | end |
---|
| 84 | mex -f lccengmatopts.bat test_flops.c |
---|
| 85 | catch |
---|
| 86 | disp('Could not install the standalone programs.'); |
---|
| 87 | disp(lasterr) |
---|
| 88 | end |
---|
| 89 | else |
---|
| 90 | % UNIX |
---|
| 91 | mex addflops.c flops.o |
---|
| 92 | mex digamma.c util.o -lm |
---|
| 93 | mex gammaln.c util.o -lm |
---|
| 94 | mex randbinom.c util.o -lm |
---|
| 95 | mex randgamma.c util.o -lm |
---|
| 96 | mex repmat.c mexutil.o |
---|
| 97 | mex sample_hist.c util.o -lm |
---|
| 98 | mex trigamma.c util.o -lm |
---|
| 99 | try |
---|
| 100 | % standalone programs |
---|
| 101 | if atleast65 |
---|
| 102 | % -V5 is required only for Matlab >=6.5 |
---|
| 103 | mex -f matopts.sh matfile.c -V5 |
---|
| 104 | else |
---|
| 105 | mex -f matopts.sh matfile.c |
---|
| 106 | end |
---|
| 107 | mex -f matopts.sh test_flops.c |
---|
| 108 | catch |
---|
| 109 | disp('Could not install the standalone programs.'); |
---|
| 110 | disp(lasterr); |
---|
| 111 | fprintf('Note: if matlab cannot find matopts.sh, your installation of matlab is faulty.\nIf you get this error, don''t worry, lightspeed should still work.'); |
---|
| 112 | end |
---|
| 113 | end |
---|
| 114 | |
---|
| 115 | fprintf('Done.\n'); |
---|