diff options
| author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
| commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
| tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/toolbox/MultiNcut/tim_eigs.m | |
| parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) | |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/toolbox/MultiNcut/tim_eigs.m')
| -rwxr-xr-x | SD-VBS/common/toolbox/MultiNcut/tim_eigs.m | 1084 |
1 files changed, 1084 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/MultiNcut/tim_eigs.m b/SD-VBS/common/toolbox/MultiNcut/tim_eigs.m new file mode 100755 index 0000000..4b80262 --- /dev/null +++ b/SD-VBS/common/toolbox/MultiNcut/tim_eigs.m | |||
| @@ -0,0 +1,1084 @@ | |||
| 1 | function varargout = tim_eigs(varargin) | ||
| 2 | |||
| 3 | nombre_A_times_X = 0; %tim | ||
| 4 | nombreIterations = 0; %tim | ||
| 5 | |||
| 6 | %seule difference avec eigs : | ||
| 7 | % arguments_Afun = varargin{7-Amatrix-Bnotthere:end}; | ||
| 8 | %(pour l'instant : n'accepte que 2 arguments dans le cas de Afun : Afun(W,X)) | ||
| 9 | %permet d'aller plus vite en minimisant les acces a varargin | ||
| 10 | %(Timothee) | ||
| 11 | |||
| 12 | %EIGS Find a few eigenvalues and eigenvectors of a matrix using ARPACK. | ||
| 13 | % D = EIGS(A) returns a vector of A's 6 largest magnitude eigenvalues. | ||
| 14 | % A must be square and should be large and sparse. | ||
| 15 | % | ||
| 16 | % [V,D] = EIGS(A) returns a diagonal matrix D of A's 6 largest magnitude | ||
| 17 | % eigenvalues and a matrix V whose columns are the corresponding eigenvectors. | ||
| 18 | % | ||
| 19 | % [V,D,FLAG] = EIGS(A) also returns a convergence flag. If FLAG is 0 | ||
| 20 | % then all the eigenvalues converged; otherwise not all converged. | ||
| 21 | % | ||
| 22 | % EIGS(A,B) solves the generalized eigenvalue problem A*V == B*V*D. B must | ||
| 23 | % be symmetric (or Hermitian) positive definite and the same size as A. | ||
| 24 | % EIGS(A,[],...) indicates the standard eigenvalue problem A*V == V*D. | ||
| 25 | % | ||
| 26 | % EIGS(A,K) and EIGS(A,B,K) return the K largest magnitude eigenvalues. | ||
| 27 | % | ||
| 28 | % EIGS(A,K,SIGMA) and EIGS(A,B,K,SIGMA) return K eigenvalues based on SIGMA: | ||
| 29 | % 'LM' or 'SM' - Largest or Smallest Magnitude | ||
| 30 | % For real symmetric problems, SIGMA may also be: | ||
| 31 | % 'LA' or 'SA' - Largest or Smallest Algebraic | ||
| 32 | % 'BE' - Both Ends, one more from high end if K is odd | ||
| 33 | % For nonsymmetric and complex problems, SIGMA may also be: | ||
| 34 | % 'LR' or 'SR' - Largest or Smallest Real part | ||
| 35 | % 'LI' or 'SI' - Largest or Smallest Imaginary part | ||
| 36 | % If SIGMA is a real or complex scalar including 0, EIGS finds the eigenvalues | ||
| 37 | % closest to SIGMA. For scalar SIGMA, and also when SIGMA = 'SM' which uses | ||
| 38 | % the same algorithm as SIGMA = 0, B need only be symmetric (or Hermitian) | ||
| 39 | % positive semi-definite since it is not Cholesky factored as in the other cases. | ||
| 40 | % | ||
| 41 | % EIGS(A,K,SIGMA,OPTS) and EIGS(A,B,K,SIGMA,OPTS) specify options: | ||
| 42 | % OPTS.issym: symmetry of A or A-SIGMA*B represented by AFUN [{0} | 1] | ||
| 43 | % OPTS.isreal: complexity of A or A-SIGMA*B represented by AFUN [0 | {1}] | ||
| 44 | % OPTS.tol: convergence: Ritz estimate residual <= tol*NORM(A) [scalar | {eps}] | ||
| 45 | % OPTS.maxit: maximum number of iterations [integer | {300}] | ||
| 46 | % OPTS.p: number of Lanczos vectors: K+1<p<=N [integer | {2K}] | ||
| 47 | % OPTS.v0: starting vector [N-by-1 vector | {randomly generated by ARPACK}] | ||
| 48 | % OPTS.disp: diagnostic information display level [0 | {1} | 2] | ||
| 49 | % OPTS.cholB: B is actually its Cholesky factor CHOL(B) [{0} | 1] | ||
| 50 | % OPTS.permB: sparse B is actually CHOL(B(permB,permB)) [permB | {1:N}] | ||
| 51 | % | ||
| 52 | % EIGS(AFUN,N) accepts the function AFUN instead of the matrix A. | ||
| 53 | % Y = AFUN(X) should return | ||
| 54 | % A*X if SIGMA is not specified, or is a string other than 'SM' | ||
| 55 | % A\X if SIGMA is 0 or 'SM' | ||
| 56 | % (A-SIGMA*I)\X if SIGMA is a nonzero scalar (standard eigenvalue problem) | ||
| 57 | % (A-SIGMA*B)\X if SIGMA is a nonzero scalar (generalized eigenvalue problem) | ||
| 58 | % N is the size of A. The matrix A, A-SIGMA*I or A-SIGMA*B represented by AFUN is | ||
| 59 | % assumed to be real and nonsymmetric unless specified otherwise by OPTS.isreal | ||
| 60 | % and OPTS.issym. In all these EIGS syntaxes, EIGS(A,...) may be replaced by | ||
| 61 | % EIGS(AFUN,N,...). | ||
| 62 | % | ||
| 63 | % EIGS(AFUN,N,K,SIGMA,OPTS,P1,P2,...) and EIGS(AFUN,N,B,K,SIGMA,OPTS,P1,P2,...) | ||
| 64 | % provide for additional arguments which are passed to AFUN(X,P1,P2,...). | ||
| 65 | % | ||
| 66 | % Examples: | ||
| 67 | % A = delsq(numgrid('C',15)); d1 = eigs(A,5,'SM'); | ||
| 68 | % Equivalently, if dnRk is the following one-line function: | ||
| 69 | % function y = dnRk(x,R,k) | ||
| 70 | % y = (delsq(numgrid(R,k))) \ x; | ||
| 71 | % then pass dnRk's additional arguments, 'C' and 15, to EIGS: | ||
| 72 | % n = size(A,1); opts.issym = 1; d2 = eigs(@dnRk,n,5,'SM',opts,'C',15); | ||
| 73 | % | ||
| 74 | % See also EIG, SVDS, ARPACKC. | ||
| 75 | |||
| 76 | % Copyright 1984-2002 The MathWorks, Inc. | ||
| 77 | % $Revision: 1.45 $ $Date: 2002/05/14 18:50:58 $ | ||
| 78 | |||
| 79 | cputms = zeros(5,1); | ||
| 80 | t0 = cputime; % start timing pre-processing | ||
| 81 | |||
| 82 | if (nargout > 3) | ||
| 83 | error('Too many output arguments.') | ||
| 84 | end | ||
| 85 | |||
| 86 | % Process inputs and do error-checking | ||
| 87 | if isa(varargin{1},'double') | ||
| 88 | A = varargin{1}; | ||
| 89 | Amatrix = 1; | ||
| 90 | else | ||
| 91 | A = fcnchk(varargin{1}); | ||
| 92 | Amatrix = 0; | ||
| 93 | end | ||
| 94 | |||
| 95 | isrealprob = 1; % isrealprob = isreal(A) & isreal(B) & isreal(sigma) | ||
| 96 | if Amatrix | ||
| 97 | isrealprob = isreal(A); | ||
| 98 | end | ||
| 99 | |||
| 100 | issymA = 0; | ||
| 101 | if Amatrix | ||
| 102 | issymA = isequal(A,A'); | ||
| 103 | end | ||
| 104 | |||
| 105 | if Amatrix | ||
| 106 | [m,n] = size(A); | ||
| 107 | if (m ~= n) | ||
| 108 | error('A must be a square matrix or a function which computes A*x.') | ||
| 109 | end | ||
| 110 | else | ||
| 111 | n = varargin{2}; | ||
| 112 | nstr = 'Size of problem, ''n'', must be a positive integer.'; | ||
| 113 | if ~isequal(size(n),[1,1]) | ~isreal(n) | ||
| 114 | error(nstr) | ||
| 115 | end | ||
| 116 | if (round(n) ~= n) | ||
| 117 | warning('MATLAB:eigs:NonIntegerSize',['%s\n ' ... | ||
| 118 | 'Rounding input size.'],nstr) | ||
| 119 | n = round(n); | ||
| 120 | end | ||
| 121 | if issparse(n) | ||
| 122 | n = full(n); | ||
| 123 | end | ||
| 124 | end | ||
| 125 | |||
| 126 | Bnotthere = 0; | ||
| 127 | Bstr = sprintf(['Generalized matrix B must be the same size as A and' ... | ||
| 128 | ' either a symmetric positive (semi-)definite matrix or' ... | ||
| 129 | ' its Cholesky factor.']); | ||
| 130 | if (nargin < (3-Amatrix-Bnotthere)) | ||
| 131 | B = []; | ||
| 132 | Bnotthere = 1; | ||
| 133 | else | ||
| 134 | Bk = varargin{3-Amatrix-Bnotthere}; | ||
| 135 | if isempty(Bk) % allow eigs(A,[],k,sigma,opts); | ||
| 136 | B = Bk; | ||
| 137 | else | ||
| 138 | if isequal(size(Bk),[1,1]) & (n ~= 1) | ||
| 139 | B = []; | ||
| 140 | k = Bk; | ||
| 141 | Bnotthere = 1; | ||
| 142 | else % eigs(9,8,...) assumes A=9, B=8, ... NOT A=9, k=8, ... | ||
| 143 | B = Bk; | ||
| 144 | if ~isa(B,'double') | ~isequal(size(B),[n,n]) | ||
| 145 | error(Bstr) | ||
| 146 | end | ||
| 147 | isrealprob = isrealprob & isreal(B); | ||
| 148 | end | ||
| 149 | end | ||
| 150 | end | ||
| 151 | |||
| 152 | if Amatrix & ((nargin - ~Bnotthere)>4) | ||
| 153 | error('Too many inputs.') | ||
| 154 | end | ||
| 155 | |||
| 156 | if (nargin < (4-Amatrix-Bnotthere)) | ||
| 157 | k = min(n,6); | ||
| 158 | else | ||
| 159 | k = varargin{4-Amatrix-Bnotthere}; | ||
| 160 | end | ||
| 161 | |||
| 162 | kstr = ['Number of eigenvalues requested, k, must be a' ... | ||
| 163 | ' positive integer <= n.']; | ||
| 164 | if ~isa(k,'double') | ~isequal(size(k),[1,1]) | ~isreal(k) | (k>n) | ||
| 165 | error(kstr) | ||
| 166 | end | ||
| 167 | if issparse(k) | ||
| 168 | k = full(k); | ||
| 169 | end | ||
| 170 | if (round(k) ~= k) | ||
| 171 | warning('MATLAB:eigs:NonIntegerEigQty',['%s\n ' ... | ||
| 172 | 'Rounding number of eigenvalues.'],kstr) | ||
| 173 | k = round(k); | ||
| 174 | end | ||
| 175 | |||
| 176 | whchstr = sprintf(['Eigenvalue range sigma must be a valid 2-element string.']); | ||
| 177 | if (nargin < (5-Amatrix-Bnotthere)) | ||
| 178 | % default: eigs('LM') => ARPACK which='LM', sigma=0 | ||
| 179 | eigs_sigma = 'LM'; | ||
| 180 | whch = 'LM'; | ||
| 181 | sigma = 0; | ||
| 182 | else | ||
| 183 | eigs_sigma = varargin{5-Amatrix-Bnotthere}; | ||
| 184 | if isstr(eigs_sigma) | ||
| 185 | % eigs(string) => ARPACK which=string, sigma=0 | ||
| 186 | if ~isequal(size(eigs_sigma),[1,2]) | ||
| 187 | |||
