├── LICENSE ├── README.md ├── debug_sampling.m ├── private ├── P321.m ├── blkdiagn.m ├── covMaternard3.m ├── ess.m ├── isdiag.m ├── logmvnpdf.m ├── mtimesx │ ├── eraseme_mtimesx.mexa64 │ ├── license.txt │ ├── make.m │ ├── mtimesx.c │ ├── mtimesx.m │ ├── mtimesx.mexa64 │ ├── mtimesx_20110223.pdf │ ├── mtimesx_RealTimesReal.c │ ├── mtimesx_build.m │ ├── mtimesx_sparse.m │ ├── mtimesx_test_ddequal.m │ ├── mtimesx_test_ddspeed.m │ ├── mtimesx_test_dsequal.m │ ├── mtimesx_test_dsspeed.m │ ├── mtimesx_test_nd.m │ ├── mtimesx_test_sdequal.m │ ├── mtimesx_test_sdspeed.m │ ├── mtimesx_test_ssequal.m │ └── mtimesx_test_ssspeed.m ├── mv2nat.m ├── nat2mv.m ├── resampling.m ├── sampleminibatch.m ├── sampleqxstar.m ├── sgdstep.m ├── stacksigma.m ├── test_sgdstep.m └── whiten.m ├── test_script1d.m ├── test_script2d.m └── vgpssm.m /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Roger Frigola 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VGPSSM 2 | Variational Gaussian Process State-Space Models 3 | 4 | This is an attempt at making a Matlab toolbox based on the research code I wrote for the 2014 NIPS paper: [Variational Gaussian Process State-Space Models](http://papers.nips.cc/paper/5375-variational-gaussian-process-state-space-models.pdf). 5 | 6 | Unfortunately I did not have time to add much functionality to the toolbox and I am currently not able to offer any support. 7 | 8 | To run the code: 9 | 10 | * Make sure you have the GPML toolbox on your Matlab path 11 | 12 | * Run test_script1d.m to see an example of the options and calling syntax. -------------------------------------------------------------------------------- /debug_sampling.m: -------------------------------------------------------------------------------- 1 | % Debug sampling 2 | 3 | 4 | x = squeeze(qxstar); 5 | figure 6 | plot(x(:,:,1)) 7 | 8 | -------------------------------------------------------------------------------- /private/P321.m: -------------------------------------------------------------------------------- 1 | function Y = P321(X) 2 | % Shorthand for common permuting dimensions 1 and 3 in a 3d array. 3 | 4 | Y = permute(X, [3 2 1]); 5 | 6 | end -------------------------------------------------------------------------------- /private/blkdiagn.m: -------------------------------------------------------------------------------- 1 | function B = blkdiagn(A,n) 2 | % Repeats matrix A n times to create a block diagonal matrix. 3 | 4 | B = zeros(n * size(A)); 5 | for i = 1:n 6 | ii = 1+(i-1)*size(A,1) : i*size(A,1); 7 | for j = 1:n 8 | if i ~= j, continue; end 9 | jj = 1+(j-1)*size(A,2) : j*size(A,2); 10 | B(ii,jj) = A; 11 | end 12 | end 13 | 14 | end -------------------------------------------------------------------------------- /private/covMaternard3.m: -------------------------------------------------------------------------------- 1 | function K = covMaternard3(hyp, x, z, i) 2 | 3 | % Matern covariance function with nu = d/2 and with Automatic Relevance 4 | % Determination (ARD) distance measure. For d=1 the function is also known as 5 | % the exponential covariance function or the Ornstein-Uhlenbeck covariance 6 | % in 1d. The covariance function is: 7 | % 8 | % k(x^p,x^q) = sf^2 * f( sqrt(d)*r ) * exp(-sqrt(d)*r) 9 | % 10 | % with f(t)=1 for d=1, f(t)=1+t for d=3 and f(t)=1+t+t²/3 for d=5. 11 | % Here r is the distance sqrt((x^p-x^q)'*inv(P)*(x^p-x^q)), where the P matrix 12 | % is diagonal with ARD parameters ell_1^2,...,ell_D^2, where D is the dimension 13 | % of the input space and sf2 is the signal variance. The hyperparameters are: 14 | % 15 | % hyp = [ log(ell_1) 16 | % log(ell_2) 17 | % .. 18 | % log(ell_D) 19 | % log(sf) ] 20 | % 21 | % Copyright (c) by Hannes Nickisch, 2013-10-13. 22 | % 23 | % See also COVFUNCTIONS.M. 24 | 25 | if nargin<2, K = '(D+1)'; return; end % report number of parameters 26 | if nargin<3, z = []; end % make sure, z exists 27 | xeqz = isempty(z); dg = strcmp(z,'diag'); % determine mode 28 | 29 | [n,D] = size(x); 30 | ell = exp(hyp(1:D)); 31 | sf2 = exp(2*hyp(D+1)); 32 | d = 3; 33 | 34 | switch d 35 | case 1, f = @(t) 1; df = @(t) 1./t; % df(t) = (f(t)-f'(t))/t 36 | case 3, f = @(t) 1 + t; df = @(t) 1; 37 | case 5, f = @(t) 1 + t.*(1+t/3); df = @(t) (1+t)/3; 38 | end 39 | m = @(t,f) f(t).*exp(-t); dm = @(t,f) df(t).*exp(-t); 40 | 41 | % precompute distances 42 | if dg % vector kxx 43 | K = zeros(size(x,1),1); 44 | else 45 | if xeqz % symmetric matrix Kxx 46 | K = sq_dist(diag(sqrt(d)./ell)*x'); 47 | else % cross covariances Kxz 48 | K = sq_dist(diag(sqrt(d)./ell)*x',diag(sqrt(d)./ell)*z'); 49 | end 50 | end 51 | 52 | if nargin<4 % covariances 53 | K = sf2*m(sqrt(K),f); 54 | else % derivatives 55 | if i<=D % length scale parameter 56 | if dg 57 | Ki = zeros(size(x,1),1); 58 | else 59 | if xeqz 60 | Ki = sq_dist(sqrt(d)/ell(i)*x(:,i)'); 61 | else 62 | Ki = sq_dist(sqrt(d)/ell(i)*x(:,i)',sqrt(d)/ell(i)*z(:,i)'); 63 | end 64 | end 65 | K = sf2*dm(sqrt(K),f).*Ki; 66 | K(Ki<1e-12) = 0; % fix limit case for d=1 67 | elseif i==D+1 % magnitude parameter 68 | K = 2*sf2*m(sqrt(K),f); 69 | else 70 | error('Unknown hyperparameter') 71 | end 72 | end -------------------------------------------------------------------------------- /private/ess.m: -------------------------------------------------------------------------------- 1 | function e = ess(w) 2 | 3 | e = 1 / sum((w/sum(w)).^2); 4 | 5 | end 6 | -------------------------------------------------------------------------------- /private/isdiag.m: -------------------------------------------------------------------------------- 1 | function answer = isdiag (A) 2 | 3 | % degenerate shape: 4 | if ( isempty(A) ) 5 | answer = false; 6 | return 7 | elseif isscalar(A) 8 | answer = true; 9 | return 10 | end 11 | 12 | siz = size(A); 13 | ind_diag = sub2ind(siz, 1:siz(1), 1:siz(2))'; % index of diagonal elements. 14 | ind_nz = find(A); % index of non-zero elements. 15 | %ind_diag, ind_nz, all(ismember(ind_nz, ind_diag)) % DEBUG 16 | answer = isempty(ind_nz) || all(ismember(ind_nz, ind_diag)); 17 | end -------------------------------------------------------------------------------- /private/logmvnpdf.m: -------------------------------------------------------------------------------- 1 | function lp = logmvnpdf(X, Mu, Sigma) 2 | 3 | % d = x(:) - mu; 4 | % L = chol(Sigma); 5 | % alpha = solve_chol(L,d); 6 | % lp = - d' * alpha/2 - sum(log(diag(L))) - numel(d)*log(2*pi)/2; 7 | 8 | 9 | 10 | if nargin<1 11 | error(message('stats:mvnpdf:TooFewInputs')); 12 | elseif ndims(X)~=2 13 | error(message('stats:mvnpdf:InvalidData')); 14 | end 15 | 16 | % Get size of data. Column vectors provisionally interpreted as multiple scalar data. 17 | [n,d] = size(X); 18 | if d<1 19 | error(message('stats:mvnpdf:TooFewDimensions')); 20 | end 21 | 22 | % Assume zero mean, data are already centered 23 | if nargin < 2 || isempty(Mu) 24 | X0 = X; 25 | 26 | % Get scalar mean, and use it to center data 27 | elseif numel(Mu) == 1 28 | X0 = X - Mu; 29 | 30 | % Get vector mean, and use it to center data 31 | elseif ndims(Mu) == 2 32 | [n2,d2] = size(Mu); 33 | if d2 ~= d % has to have same number of coords as X 34 | error(message('stats:mvnpdf:ColSizeMismatch')); 35 | elseif n2 == n % lengths match 36 | X0 = X - Mu; 37 | elseif n2 == 1 % mean is a single row, rep it out to match data 38 | X0 = bsxfun(@minus,X,Mu); 39 | elseif n == 1 % data is a single row, rep it out to match mean 40 | n = n2; 41 | X0 = bsxfun(@minus,X,Mu); 42 | else % sizes don't match 43 | error(message('stats:mvnpdf:RowSizeMismatch')); 44 | end 45 | 46 | else 47 | error(message('stats:mvnpdf:BadMu')); 48 | end 49 | 50 | % Assume identity covariance, data are already standardized 51 | if nargin < 3 || isempty(Sigma) 52 | % Special case: if Sigma isn't supplied, then interpret X 53 | % and Mu as row vectors if they were both column vectors 54 | if (d == 1) && (numel(X) > 1) 55 | X0 = X0'; 56 | d = size(X0,2); 57 | end 58 | xRinv = X0; 59 | logSqrtDetSigma = 0; 60 | 61 | % Single covariance matrix 62 | elseif ndims(Sigma) == 2 63 | sz = size(Sigma); 64 | if sz(1)==1 && sz(2)>1 65 | % Just the diagonal of Sigma has been passed in. 66 | sz(1) = sz(2); 67 | sigmaIsDiag = true; 68 | else 69 | sigmaIsDiag = false; 70 | end 71 | 72 | % Special case: if Sigma is supplied, then use it to try to interpret 73 | % X and Mu as row vectors if they were both column vectors. 74 | if (d == 1) && (numel(X) > 1) && (sz(1) == n) 75 | X0 = X0'; 76 | d = size(X0,2); 77 | end 78 | 79 | %Check that sigma is the right size 80 | if sz(1) ~= sz(2) 81 | error(message('stats:mvnpdf:BadCovariance')); 82 | elseif ~isequal(sz, [d d]) 83 | error(message('stats:mvnpdf:CovSizeMismatch')); 84 | else 85 | if sigmaIsDiag 86 | if any(Sigma<=0) 87 | error(message('stats:mvnpdf:BadDiagSigma')); 88 | end 89 | R = sqrt(Sigma); 90 | xRinv = bsxfun(@rdivide,X0,R); 91 | logSqrtDetSigma = sum(log(R)); 92 | else 93 | % Make sure Sigma is a valid covariance matrix 94 | [R,err] = cholcov(Sigma,0); 95 | if err ~= 0 96 | error(message('stats:mvnpdf:BadMatrixSigma')); 97 | end 98 | % Create array of standardized data, and compute log(sqrt(det(Sigma))) 99 | xRinv = X0 / R; 100 | logSqrtDetSigma = sum(log(diag(R))); 101 | end 102 | end 103 | 104 | % Multiple covariance matrices 105 | elseif ndims(Sigma) == 3 106 | 107 | sz = size(Sigma); 108 | if sz(1)==1 && sz(2)>1 109 | % Just the diagonal of Sigma has been passed in. 110 | sz(1) = sz(2); 111 | Sigma = reshape(Sigma,sz(2),sz(3))'; 112 | sigmaIsDiag = true; 113 | else 114 | sigmaIsDiag = false; 115 | end 116 | 117 | % Special case: if Sigma is supplied, then use it to try to interpret 118 | % X and Mu as row vectors if they were both column vectors. 119 | if (d == 1) && (numel(X) > 1) && (sz(1) == n) 120 | X0 = X0'; 121 | [n,d] = size(X0); 122 | end 123 | 124 | % Data and mean are a single row, rep them out to match covariance 125 | if n == 1 % already know size(Sigma,3) > 1 126 | n = sz(3); 127 | X0 = repmat(X0,n,1); % rep centered data out to match cov 128 | end 129 | 130 | % Make sure Sigma is the right size 131 | if sz(1) ~= sz(2) 132 | error(message('stats:mvnpdf:BadCovarianceMultiple')); 133 | elseif (sz(1) ~= d) || (sz(2) ~= d) % Sigma is a stack of dxd matrices 134 | error(message('stats:mvnpdf:CovSizeMismatchMultiple')); 135 | elseif sz(3) ~= n 136 | error(message('stats:mvnpdf:CovSizeMismatchPages')); 137 | else 138 | if sigmaIsDiag 139 | if any(any(Sigma<=0)) 140 | error(message('stats:mvnpdf:BadDiagSigma')); 141 | end 142 | R = sqrt(Sigma); 143 | xRinv = X0./R; 144 | logSqrtDetSigma = sum(log(R),2); 145 | else 146 | % Create array of standardized data, and vector of log(sqrt(det(Sigma))) 147 | xRinv = zeros(n,d,superiorfloat(X0,Sigma)); 148 | logSqrtDetSigma = zeros(n,1,class(Sigma)); 149 | for i = 1:n 150 | % Make sure Sigma is a valid covariance matrix 151 | [R,err] = cholcov(Sigma(:,:,i),0); 152 | if err ~= 0 153 | error(message('stats:mvnpdf:BadMatrixSigmaMultiple')); 154 | end 155 | xRinv(i,:) = X0(i,:) / R; 156 | logSqrtDetSigma(i) = sum(log(diag(R))); 157 | end 158 | end 159 | end 160 | 161 | elseif ndims(Sigma) > 3 162 | error(message('stats:mvnpdf:BadCovariance')); 163 | end 164 | 165 | % The quadratic form is the inner products of the standardized data 166 | quadform = sum(xRinv.^2, 2); 167 | 168 | lp = -0.5*quadform - logSqrtDetSigma - d*log(2*pi)/2; 169 | end -------------------------------------------------------------------------------- /private/mtimesx/eraseme_mtimesx.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RogerFrigola/VGPSSM/968d24ceb9652d64a737575e0cd6b285762a9ecd/private/mtimesx/eraseme_mtimesx.mexa64 -------------------------------------------------------------------------------- /private/mtimesx/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, James Tursa 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /private/mtimesx/make.m: -------------------------------------------------------------------------------- 1 | function make() 2 | blas_lib = '/misc/apps/matlab/matlabR2014a/bin/glnxa64/libmwblas.so'; 3 | mex('-DDEFINEUNIX','mtimesx.c',blas_lib) 4 | % mex('-DDEFINEUNIX','-largeArrayDims','mtimesx.c',blas_lib) 5 | end -------------------------------------------------------------------------------- /private/mtimesx/mtimesx.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RogerFrigola/VGPSSM/968d24ceb9652d64a737575e0cd6b285762a9ecd/private/mtimesx/mtimesx.c -------------------------------------------------------------------------------- /private/mtimesx/mtimesx.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RogerFrigola/VGPSSM/968d24ceb9652d64a737575e0cd6b285762a9ecd/private/mtimesx/mtimesx.m -------------------------------------------------------------------------------- /private/mtimesx/mtimesx.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RogerFrigola/VGPSSM/968d24ceb9652d64a737575e0cd6b285762a9ecd/private/mtimesx/mtimesx.mexa64 -------------------------------------------------------------------------------- /private/mtimesx/mtimesx_20110223.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RogerFrigola/VGPSSM/968d24ceb9652d64a737575e0cd6b285762a9ecd/private/mtimesx/mtimesx_20110223.pdf -------------------------------------------------------------------------------- /private/mtimesx/mtimesx_build.m: -------------------------------------------------------------------------------- 1 | % mtimesx_build compiles mtimesx.c with BLAS libraries 2 | %****************************************************************************** 3 | % 4 | % MATLAB (R) is a trademark of The Mathworks (R) Corporation 5 | % 6 | % Function: mtimesx_build 7 | % Filename: mtimesx_build.m 8 | % Programmer: James Tursa 9 | % Version: 1.40 10 | % Date: October 4, 2010 11 | % Copyright: (c) 2009, 2010 by James Tursa, All Rights Reserved 12 | % 13 | % This code uses the BSD License: 14 | % 15 | % Redistribution and use in source and binary forms, with or without 16 | % modification, are permitted provided that the following conditions are 17 | % met: 18 | % 19 | % * Redistributions of source code must retain the above copyright 20 | % notice, this list of conditions and the following disclaimer. 21 | % * Redistributions in binary form must reproduce the above copyright 22 | % notice, this list of conditions and the following disclaimer in 23 | % the documentation and/or other materials provided with the distribution 24 | % 25 | % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 29 | % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | % POSSIBILITY OF SUCH DAMAGE. 36 | % 37 | %-- 38 | % 39 | % mtimesx_build compiles mtimesx.c and mtimesx_RealTimesReal.c with the BLAS 40 | % libraries libmwblas.lib (if present) or libmwlapack.lib (if libmwblas.lib 41 | % is not present). This function basically works as follows: 42 | % 43 | % - Opens the current mexopts.bat file in the directory [prefdir], and 44 | % checks to make sure that the compiler selected is cl or lcc. If it 45 | % is not, then a warning is issued and the compilation continues with 46 | % the assumption that the microsoft BLAS libraries will work. 47 | % 48 | % - Looks for the file libmwblas.lib or libmwlapack.lib files in the 49 | % appropriate directory: [matlabroot '\extern\lib\win32\microsoft'] 50 | % or [matlabroot '\extern\lib\win32\lcc'] 51 | % or [matlabroot '\extern\lib\win64\microsoft'] 52 | % or [matlabroot '\extern\lib\win64\lcc'] 53 | % 54 | % - Changes directory to the directory of the file mtimesx.m. 55 | % 56 | % - Compiles mtimesx.c (which includes mtimesx_RealTimesReal.c) along with 57 | % either libmwblas.lib or libmwlapack.lib depending on the version of 58 | % MATLAB. The resulting exedcutable mex file is placed in the same 59 | % directory as the source code. The files mtimesx.m, mtimesx.c, and 60 | % mtimesx_RealTimesReal.c must all be in the same directory. 61 | % 62 | % - Changes the directory back to the original directory. 63 | % 64 | % Change Log: 65 | % 2009/Sep/27 --> 1.00, Initial Release 66 | % 2010/Feb/15 --> 1.10, Fixed largearrardims typo to largeArrayDims 67 | % 2010/Oct/04 --> 1.40, Updated support for OpenMP compiling 68 | % 69 | %************************************************************************** 70 | 71 | function mtimesx_build(x) 72 | disp(' '); 73 | disp('... Build routine for mtimesx'); 74 | 75 | TRUE = 1; 76 | FALSE = 0; 77 | 78 | %\ 79 | % Check for number of inputs & outputs 80 | %/ 81 | 82 | noopenmp = FALSE; 83 | if( nargin == 1 ) 84 | if( isequal(upper(x),'NOOPENMP') ) 85 | noopenmp = TRUE; 86 | else 87 | error('Invalid input.'); 88 | end 89 | elseif( nargin ~= 0 ) 90 | error('Too many inputs. Expected none.'); 91 | end 92 | if( nargout ~= 0 ) 93 | error('Too many outputs. Expected none.'); 94 | end 95 | 96 | %\ 97 | % Check for non-PC 98 | %/ 99 | 100 | disp('... Checking for PC'); 101 | try 102 | % ispc does not appear in MATLAB 5.3 103 | pc = ispc ; 104 | catch 105 | % if ispc fails, assume we are on a Windows PC if it's not unix 106 | pc = ~isunix ; 107 | end 108 | 109 | if( ~pc ) 110 | disp('Non-PC auto build is not currently supported. You will have to'); 111 | disp('manually compile the mex routine. E.g., as follows:'); 112 | disp(' '); 113 | disp('>> blas_lib = ''the_actual_path_and_name_of_your_systems_BLAS_library'''); 114 | disp('>> mex(''-DDEFINEUNIX'',''mtimesx.c'',blas_lib)'); 115 | disp(' '); 116 | disp('or'); 117 | disp(' '); 118 | disp('>> mex(''-DDEFINEUNIX'',''-largeArrayDims'',''mtimesx.c'',blas_lib)'); 119 | disp(' '); 120 | error('Unable to compile mtimesx.c'); 121 | end 122 | 123 | %\ 124 | % Check to see that mtimesx.c source code is present 125 | %/ 126 | 127 | disp('... Finding path of mtimesx C source code files'); 128 | try 129 | mname = mfilename('fullpath'); 130 | catch 131 | mname = mfilename; 132 | end 133 | cname = [mname(1:end-6) '.c']; 134 | if( isempty(dir(cname)) ) 135 | disp('Cannot find the file mtimesx.c in the same directory as the'); 136 | disp('file mtimesx_build.m. Please ensure that they are in the same'); 137 | disp('directory and try again. The following file was not found:'); 138 | disp(' '); 139 | disp(cname); 140 | disp(' '); 141 | error('Unable to compile mtimesx.c'); 142 | end 143 | disp(['... Found file mtimesx.c in ' cname]); 144 | 145 | %\ 146 | % Check to see that mtimesx_RealTimesReal.c source code is present 147 | %/ 148 | 149 | rname = [mname(1:end-13) 'mtimesx_RealTimesReal.c']; 150 | if( isempty(dir(rname)) ) 151 | disp('Cannot find the file mtimesx_RealTimesReal.c in the same'); 152 | disp('directory as the file mtimesx_build.m. Please ensure that'); 153 | disp('they are in the same directory and try again. The'); 154 | disp('following file was not found:'); 155 | disp(' '); 156 | disp(rname); 157 | disp(' '); 158 | error('Unable to compile mtimesx.c'); 159 | end 160 | disp(['... Found file mtimesx_RealTimesReal.c in ' rname]); 161 | 162 | %\ 163 | % Open the current mexopts.bat file 164 | %/ 165 | 166 | mexopts = [prefdir '\mexopts.bat']; 167 | fid = fopen(mexopts); 168 | if( fid == -1 ) 169 | error('A C/C++ compiler has not been selected with mex -setup'); 170 | end 171 | disp(['... Opened the mexopts.bat file in ' mexopts]); 172 | disp('... Reading the mexopts.bat file to find the compiler and options used.'); 173 | 174 | %\ 175 | % Check for the correct compiler selected. 176 | %/ 177 | 178 | ok_cl = FALSE; 179 | ok_lcc = FALSE; 180 | omp_option = ''; 181 | compiler = '(unknown)'; 182 | compilername = ''; 183 | while( TRUE ) 184 | tline = fgets(fid); 185 | if( isequal(tline,-1) ) 186 | break; 187 | else 188 | if( isempty(compilername) ) 189 | y = findstr(tline,'OPTS.BAT'); 190 | if( ~isempty(y) ) 191 | x = findstr(tline,'rem '); 192 | if( ~isempty(x) ) 193 | compilername = tline(x+4:y-1); 194 | end 195 | end 196 | end 197 | x = findstr(tline,'COMPILER=lcc'); 198 | if( ~isempty(x) ) 199 | ok_lcc = TRUE; 200 | libdir = 'lcc'; 201 | compiler = 'LCC'; 202 | disp(['... ' compiler ' is the selected compiler']); 203 | break; 204 | end 205 | x = findstr(tline,'COMPILER=cl'); 206 | if( ~isempty(x) ) 207 | ok_cl = TRUE; 208 | libdir = 'microsoft'; 209 | compiler = ['Microsoft_' compilername '_cl']; 210 | omp_option = ' /openmp'; 211 | disp(['... ' compiler ' is the selected compiler']); 212 | break; 213 | end 214 | x = findstr(tline,'COMPILER=bcc32'); 215 | if( ~isempty(x) ) 216 | ok_cl = TRUE; 217 | libdir = 'microsoft'; 218 | compiler = ['Borland_' compilername '_bcc32']; 219 | disp(['... ' compiler ' is the selected compiler']); 220 | disp('... Assuming that Borland will link with Microsoft libraries'); 221 | break; 222 | end 223 | x = findstr(tline,'COMPILER=icl'); 224 | if( ~isempty(x) ) 225 | ok_cl = TRUE; 226 | if( pc ) 227 | omp_option = ' -Qopenmp'; 228 | else 229 | omp_option = ' -openmp'; 230 | end 231 | libdir = 'microsoft'; 232 | compiler = ['Intel_' compilername '_icl']; 233 | disp(['... ' compiler ' is the selected compiler']); 234 | disp('... Assuming that Intel will link with Microsoft libraries'); 235 | break; 236 | end 237 | x = findstr(tline,'COMPILER=wc1386'); 238 | if( ~isempty(x) ) 239 | ok_cl = TRUE; 240 | libdir = 'microsoft'; 241 | compiler = ['Watcom_' compilername '_wc1386']; 242 | disp(['... ' compiler ' is the selected compiler']); 243 | disp('... Assuming that Watcom will link with Microsoft libraries'); 244 | break; 245 | end 246 | x = findstr(tline,'COMPILER=gcc'); 247 | if( ~isempty(x) ) 248 | ok_cl = TRUE; 249 | libdir = 'microsoft'; 250 | omp_option = ' -fopenmp'; 251 | compiler = 'GCC'; 252 | disp(['... ' compiler ' is the selected compiler']); 253 | disp('... Assuming that GCC will link with Microsoft libraries'); 254 | break; 255 | end 256 | end 257 | end 258 | fclose(fid); 259 | 260 | %\ 261 | % MS Visual C/C++ or lcc compiler has not been selected 262 | %/ 263 | 264 | if( ~(ok_cl | ok_lcc) ) 265 | warning('... Supported C/C++ compiler has not been selected with mex -setup'); 266 | warning('... Assuming that Selected Compiler will link with Microsoft libraries'); 267 | warning('... Continuing at risk ...'); 268 | libdir = 'microsoft'; 269 | end 270 | 271 | %\ 272 | % If an OpenMP supported compiler is potentially present, make sure that the 273 | % necessary compile option is present in the mexopts.bat file on the COMPFLAGS 274 | % line. If necessary, build a new mexopts.bat file with the correct option 275 | % added to the COMPFLAGS line. 276 | %/ 277 | 278 | while( TRUE ) 279 | ok_openmp = FALSE; 280 | ok_compflags = FALSE; 281 | xname = ''; 282 | if( isempty(omp_option) ) 283 | disp('... OpenMP compiler not detected ... you may want to check this website:'); 284 | disp(' http://openmp.org/wp/openmp-compilers/'); 285 | elseif( noopenmp ) 286 | disp(['... OpenMP compiler potentially detected, but not checking for ''' omp_option ''' compile option']); 287 | else 288 | disp('... OpenMP compiler potentially detected'); 289 | disp(['... Checking to see that the ''' omp_option ''' compile option is present']); 290 | fid = fopen(mexopts); 291 | while( TRUE ) 292 | tline = fgets(fid); 293 | if( isequal(tline,-1) ) 294 | break; 295 | else 296 | x = findstr(tline,'set COMPFLAGS'); 297 | if( ~isempty(x) ) 298 | ok_compflags = TRUE; 299 | x = findstr(tline,omp_option); 300 | if( ~isempty(x) ) 301 | ok_openmp = TRUE; 302 | end 303 | break; 304 | end 305 | end 306 | end 307 | fclose(fid); 308 | if( ~ok_compflags ) 309 | warning(['... COMPFLAGS line not found ... ''' omp_option ''' will not be added.']); 310 | elseif( ~ok_openmp ) 311 | disp(['... The ''' omp_option ''' compile option is not present ... adding it']); 312 | xname = [mname(1:end-6) '_mexopts.bat']; 313 | disp(['... Creating custom options file ' xname ' with the ''' omp_option ''' option added.']); 314 | fid = fopen(mexopts); 315 | fidx = fopen(xname,'w'); 316 | if( fidx == -1 ) 317 | xname = ''; 318 | warning(['... Unable to create custom mexopts.bat file ... ''' omp_option ''' will not be added']); 319 | else 320 | while( TRUE ) 321 | tline = fgets(fid); 322 | if( isequal(tline,-1) ) 323 | break; 324 | else 325 | x = findstr(tline,'set COMPFLAGS'); 326 | if( ~isempty(x) ) 327 | n = numel(tline); 328 | e = n; 329 | while( tline(e) < 32 ) 330 | e = e - 1; 331 | end 332 | tline = [tline(1:e) omp_option tline(e+1:n)]; 333 | end 334 | fwrite(fidx,tline); 335 | end 336 | end 337 | fclose(fidx); 338 | end 339 | fclose(fid); 340 | end 341 | end 342 | 343 | %\ 344 | % Construct full file name of libmwblas.lib and libmwlapack.lib. Note that 345 | % not all versions have both files. Earlier versions only had the lapack 346 | % file, which contained both blas and lapack routines. 347 | %/ 348 | 349 | comp = computer; 350 | mext = mexext; 351 | lc = length(comp); 352 | lm = length(mext); 353 | cbits = comp(max(1:lc-1):lc); 354 | mbits = mext(max(1:lm-1):lm); 355 | if( isequal(cbits,'64') | isequal(mbits,'64') ) 356 | compdir = 'win64'; 357 | largearraydims = '-largeArrayDims'; 358 | else 359 | compdir = 'win32'; 360 | largearraydims = ''; 361 | end 362 | 363 | lib_blas = [matlabroot '\extern\lib\' compdir '\' libdir '\libmwblas.lib']; 364 | d = dir(lib_blas); 365 | if( isempty(d) ) 366 | disp('... BLAS library file not found, so linking with the LAPACK library'); 367 | lib_blas = [matlabroot '\extern\lib\' compdir '\' libdir '\libmwlapack.lib']; 368 | end 369 | disp(['... Using BLAS library lib_blas = ''' lib_blas '''']); 370 | 371 | %\ 372 | % Save old directory and change to source code directory 373 | %/ 374 | 375 | cdold = cd; 376 | if( length(mname) > 13 ) 377 | cd(mname(1:end-13)); 378 | end 379 | 380 | %\ 381 | % Do the compile 382 | %/ 383 | 384 | disp('... Now attempting to compile ...'); 385 | disp(' '); 386 | try 387 | if( isunix ) 388 | if( isempty(largearraydims) ) 389 | if( isempty(xname) ) 390 | disp(['mex(''-DDEFINEUNIX'',''' cname ''',lib_blas,''-DCOMPILER=' compiler ''')']); 391 | disp(' '); 392 | mex('-DDEFINEUNIX',cname,lib_blas,['-DCOMPILER=' compiler]); 393 | else 394 | disp(['mex(''-f'',''' xname ''',''-DDEFINEUNIX'',''' cname ''',lib_blas,''-DCOMPILER=' compiler ''')']); 395 | disp(' '); 396 | mex('-f',xname,'-DDEFINEUNIX',cname,lib_blas,['-DCOMPILER=' compiler]); 397 | end 398 | else 399 | if( isempty(xname) ) 400 | disp(['mex(''-DDEFINEUNIX'',''' cname ''',''' largearraydims ''',lib_blas,''-DCOMPILER=' compiler ''')']); 401 | disp(' '); 402 | mex('-DDEFINEUNIX',largearraydims,cname,lib_blas,['-DCOMPILER=' compiler]); 403 | else 404 | disp(['mex(''-f'',''' xname ''',''-DDEFINEUNIX'',''' cname ''',''' largearraydims ''',lib_blas,''-DCOMPILER=' compiler ''')']); 405 | disp(' '); 406 | mex('-f',xname,'-DDEFINEUNIX',largearraydims,cname,lib_blas,['-DCOMPILER=' compiler]); 407 | end 408 | end 409 | else 410 | if( isempty(largearraydims) ) 411 | if( isempty(xname) ) 412 | disp(['mex(''' cname ''',lib_blas,''-DCOMPILER=' compiler ''')']); 413 | disp(' '); 414 | mex(cname,lib_blas,['-DCOMPILER=' compiler]); 415 | else 416 | disp(['mex(''-f'',''' xname ''',''' cname ''',lib_blas,''-DCOMPILER=' compiler ''')']); 417 | disp(' '); 418 | mex('-f',xname,cname,lib_blas,['-DCOMPILER=' compiler]); 419 | end 420 | else 421 | if( isempty(xname) ) 422 | disp(['mex(''' cname ''',''' largearraydims ''',lib_blas,''-DCOMPILER=' compiler ''')']); 423 | disp(' '); 424 | mex(cname,largearraydims,lib_blas,['-DCOMPILER=' compiler]); 425 | else 426 | disp(['mex(''-f'',''' xname ''',''' cname ''',''' largearraydims ''',lib_blas,''-DCOMPILER=' compiler ''')']); 427 | disp(' '); 428 | mex('-f',xname,cname,largearraydims,lib_blas,['-DCOMPILER=' compiler]); 429 | end 430 | end 431 | end 432 | disp('... mex mtimesx.c build completed ... you may now use mtimesx.'); 433 | disp(' '); 434 | mtimesx; 435 | break; 436 | catch 437 | if( noopenmp ) 438 | cd(cdold); 439 | disp(' '); 440 | disp('... Well, *that* didn''t work either!'); 441 | disp(' '); 442 | disp('The mex command failed. This may be because you have already run'); 443 | disp('mex -setup and selected a non-C compiler, such as Fortran. If this'); 444 | disp('is the case, then rerun mex -setup and select a C/C++ compiler.'); 445 | disp(' '); 446 | error('Unable to compile mtimesx.c'); 447 | else 448 | disp(' '); 449 | disp('... Well, *that* didn''t work ...'); 450 | disp(' '); 451 | if( isequal(omp_option,' /openmp') ) 452 | disp('This may be because an OpenMP compile option was added that the'); 453 | disp('compiler did not like. For example, the Standard versions of the'); 454 | disp('Microsoft C/C++ compilers do not support OpenMP, only the'); 455 | disp('Professional versions do. Attempting to compile again but this'); 456 | disp(['time will not add the ''' omp_option ''' option.']) 457 | else 458 | disp('This may be because an OpenMP compile option was added that the'); 459 | disp('compiler did not like. Attempting to compile again, but this time'); 460 | disp(['will not add the ''' omp_option ''' option.']) 461 | end 462 | disp(' '); 463 | noopenmp = TRUE; 464 | end 465 | end 466 | end 467 | 468 | %\ 469 | % Restore old directory 470 | %/ 471 | 472 | cd(cdold); 473 | 474 | return 475 | end 476 | -------------------------------------------------------------------------------- /private/mtimesx/mtimesx_sparse.m: -------------------------------------------------------------------------------- 1 | % mtimesx_sparse does sparse matrix multiply of two inputs 2 | %****************************************************************************** 3 | % 4 | % MATLAB (R) is a trademark of The Mathworks (R) Corporation 5 | % 6 | % Function: mtimesx_sparse 7 | % Filename: mtimesx_sparse.m 8 | % Programmer: James Tursa 9 | % Version: 1.00 10 | % Date: September 27, 2009 11 | % Copyright: (c) 2009 by James Tursa, All Rights Reserved 12 | % 13 | % This code uses the BSD License: 14 | % 15 | % Redistribution and use in source and binary forms, with or without 16 | % modification, are permitted provided that the following conditions are 17 | % met: 18 | % 19 | % * Redistributions of source code must retain the above copyright 20 | % notice, this list of conditions and the following disclaimer. 21 | % * Redistributions in binary form must reproduce the above copyright 22 | % notice, this list of conditions and the following disclaimer in 23 | % the documentation and/or other materials provided with the distribution 24 | % 25 | % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 29 | % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | % POSSIBILITY OF SUCH DAMAGE. 36 | % 37 | %-- 38 | % 39 | % mtimesx_sparse is a helper function for mtimesx and is not intended to be called 40 | % directly by the user. 41 | % 42 | % --------------------------------------------------------------------------------------------------------------------------------- 43 | 44 | function result = mtimesx_sparse(a,transa,b,transb) 45 | if( transa == 'N' ) 46 | if( transb == 'N' ) 47 | result = a * b; 48 | elseif( transb == 'G' ) 49 | result = a * conj(b); 50 | elseif( transb == 'T' ) 51 | result = a * b.'; 52 | else 53 | result = a * b'; 54 | end 55 | elseif( transa == 'G' ) 56 | if( transb == 'N' ) 57 | result = conj(a) * b; 58 | elseif( transb == 'G' ) 59 | result = conj(a) * conj(b); 60 | elseif( transb == 'T' ) 61 | result = conj(a) * b.'; 62 | else 63 | result = conj(a) * b'; 64 | end 65 | elseif( transa == 'T' ) 66 | if( transb == 'N' ) 67 | result = a.' * b; 68 | elseif( transb == 'G' ) 69 | result = a.' * conj(b); 70 | elseif( transb == 'T' ) 71 | result = a.' * b.'; 72 | else 73 | result = a.' * b'; 74 | end 75 | else 76 | if( transb == 'N' ) 77 | result = a' * b; 78 | elseif( transb == 'G' ) 79 | result = a' * conj(b); 80 | elseif( transb == 'T' ) 81 | result = a' * b.'; 82 | else 83 | result = a' * b'; 84 | end 85 | end 86 | end 87 | -------------------------------------------------------------------------------- /private/mtimesx/mtimesx_test_ddequal.m: -------------------------------------------------------------------------------- 1 | % Test routine for mtimesx, op(double) * op(double) equality vs MATLAB 2 | %****************************************************************************** 3 | % 4 | % MATLAB (R) is a trademark of The Mathworks (R) Corporation 5 | % 6 | % Function: mtimesx_test_ddequal 7 | % Filename: mtimesx_test_ddequal.m 8 | % Programmer: James Tursa 9 | % Version: 1.0 10 | % Date: September 27, 2009 11 | % Copyright: (c) 2009 by James Tursa, All Rights Reserved 12 | % 13 | % This code uses the BSD License: 14 | % 15 | % Redistribution and use in source and binary forms, with or without 16 | % modification, are permitted provided that the following conditions are 17 | % met: 18 | % 19 | % * Redistributions of source code must retain the above copyright 20 | % notice, this list of conditions and the following disclaimer. 21 | % * Redistributions in binary form must reproduce the above copyright 22 | % notice, this list of conditions and the following disclaimer in 23 | % the documentation and/or other materials provided with the distribution 24 | % 25 | % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 29 | % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | % POSSIBILITY OF SUCH DAMAGE. 36 | % 37 | % Syntax: 38 | % 39 | % T = mtimesx_test_ddequal 40 | % 41 | % Output: 42 | % 43 | % T = A character array containing a summary of the results. 44 | % 45 | %-------------------------------------------------------------------------- 46 | 47 | function dtable = mtimesx_test_ddequal 48 | 49 | global mtimesx_dtable 50 | 51 | disp(' '); 52 | disp('****************************************************************************'); 53 | disp('* *'); 54 | disp('* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *'); 55 | disp('* *'); 56 | disp('* This test program can take an hour or so to complete. It is suggested *'); 57 | disp('* that you close all applications and run this program during your lunch *'); 58 | disp('* break or overnight to minimize impacts to your computer usage. *'); 59 | disp('* *'); 60 | disp('* The program will be done when you see the message: DONE ! *'); 61 | disp('* *'); 62 | disp('****************************************************************************'); 63 | disp(' '); 64 | input('Press Enter to start test, or Ctrl-C to exit ','s'); 65 | 66 | start_time = datenum(clock); 67 | 68 | compver = [computer ', ' version ', mtimesx mode ' mtimesx]; 69 | k = length(compver); 70 | RC = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx'; 71 | 72 | mtimesx_dtable = char([]); 73 | mtimesx_dtable(162,74) = ' '; 74 | mtimesx_dtable(1,1:k) = compver; 75 | mtimesx_dtable(2,:) = RC; 76 | for r=3:162 77 | mtimesx_dtable(r,:) = ' -- -- -- --'; 78 | end 79 | 80 | disp(' '); 81 | disp(compver); 82 | disp('Test program for function mtimesx:') 83 | disp('----------------------------------'); 84 | 85 | %-------------------------------------------------------------------------- 86 | %-------------------------------------------------------------------------- 87 | 88 | disp(' '); 89 | disp('Numerical Comparison Tests ...'); 90 | disp(' '); 91 | disp('(real) * (real)'); 92 | disp(' '); 93 | 94 | rsave = 2; 95 | 96 | r = rsave; 97 | 98 | %if( false ) % debug jump 99 | 100 | if( isequal([]*[],mtimesx([],[])) ) 101 | disp('Empty * Empty EQUAL'); 102 | else 103 | disp('Empty * Empty NOT EQUAL <---'); 104 | end 105 | 106 | r = r + 1; 107 | A = rand(1,1); 108 | B = rand(1,10000); 109 | maxdiffNN('Scalar * Vector ',A,B,r); 110 | 111 | r = r + 1; 112 | A = rand(1,10000); 113 | B = rand(1,1); 114 | maxdiffNN('Vector * Scalar ',A,B,r); 115 | 116 | r = r + 1; 117 | A = rand(1,1); 118 | B = rand(10,20,30,40); 119 | maxdiffNN('Scalar * Array ',A,B,r); 120 | 121 | r = r + 1; 122 | A = rand(10,20,30,40); 123 | B = rand(1,1); 124 | maxdiffNN('Array * Scalar ',A,B,r); 125 | 126 | r = r + 1; 127 | A = rand(1,10000000); 128 | B = rand(10000000,1); 129 | maxdiffNN('Vector i Vector ',A,B,r); 130 | 131 | r = r + 1; 132 | A = rand(2500,1); 133 | B = rand(1,2500); 134 | maxdiffNN('Vector o Vector ',A,B,r); 135 | 136 | r = r + 1; 137 | A = rand(1,1000); 138 | B = rand(1000,1000); 139 | maxdiffNN('Vector * Matrix ',A,B,r); 140 | 141 | r = r + 1; 142 | A = rand(1000,1000); 143 | B = rand(1000,1); 144 | maxdiffNN('Matrix * Vector ',A,B,r); 145 | 146 | r = r + 1; 147 | A = rand(1000,1000); 148 | B = rand(1000,1000); 149 | maxdiffNN('Matrix * Matrix ',A,B,r); 150 | 151 | %-------------------------------------------------------------------------- 152 | disp(' '); 153 | disp('(real) * (complex)'); 154 | disp(' '); 155 | 156 | r = rsave; 157 | 158 | r = r + 1; 159 | A = rand(1,1); 160 | B = rand(1,10000) + rand(1,10000)*1i; 161 | maxdiffNN('Scalar * Vector ',A,B,r); 162 | 163 | r = r + 1; 164 | A = rand(1,10000); 165 | B = rand(1,1) + rand(1,1)*1i; 166 | maxdiffNN('Vector * Scalar ',A,B,r); 167 | 168 | r = r + 1; 169 | A = rand(1,1); 170 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 171 | maxdiffNN('Scalar * Array ',A,B,r); 172 | 173 | r = r + 1; 174 | A = rand(10,20,30,40); 175 | B = rand(1,1) + rand(1,1)*1i; 176 | maxdiffNN('Array * Scalar ',A,B,r); 177 | 178 | r = r + 1; 179 | A = rand(1,10000000); 180 | B = rand(10000000,1) + rand(10000000,1)*1i; 181 | maxdiffNN('Vector i Vector ',A,B,r); 182 | 183 | r = r + 1; 184 | A = rand(2500,1); 185 | B = rand(1,2500) + rand(1,2500)*1i; 186 | maxdiffNN('Vector o Vector ',A,B,r); 187 | 188 | r = r + 1; 189 | A = rand(1,1000); 190 | B = rand(1000,1000) + rand(1000,1000)*1i; 191 | maxdiffNN('Vector * Matrix ',A,B,r); 192 | 193 | r = r + 1; 194 | A = rand(1000,1000); 195 | B = rand(1000,1) + rand(1000,1)*1i; 196 | maxdiffNN('Matrix * Vector ',A,B,r); 197 | 198 | r = r + 1; 199 | A = rand(1000,1000); 200 | B = rand(1000,1000) + rand(1000,1000)*1i; 201 | maxdiffNN('Matrix * Matrix ',A,B,r); 202 | 203 | %-------------------------------------------------------------------------- 204 | disp(' '); 205 | disp('(complex) * (real)'); 206 | disp(' '); 207 | 208 | r = rsave; 209 | 210 | r = r + 1; 211 | A = rand(1,1) + rand(1,1)*1i; 212 | B = rand(1,10000); 213 | maxdiffNN('Scalar * Vector ',A,B,r); 214 | 215 | r = r + 1; 216 | A = rand(1,10000)+ rand(1,10000)*1i; 217 | B = rand(1,1); 218 | maxdiffNN('Vector * Scalar ',A,B,r); 219 | 220 | r = r + 1; 221 | A = rand(1,1) + rand(1,1)*1i; 222 | B = rand(10,20,30,40); 223 | maxdiffNN('Scalar * Array ',A,B,r); 224 | 225 | r = r + 1; 226 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 227 | B = rand(1,1); 228 | maxdiffNN('Array * Scalar ',A,B,r); 229 | 230 | r = r + 1; 231 | A = rand(1,10000000) + rand(1,10000000)*1i; 232 | B = rand(10000000,1); 233 | maxdiffNN('Vector i Vector ',A,B,r); 234 | 235 | r = r + 1; 236 | A = rand(2500,1) + rand(2500,1)*1i; 237 | B = rand(1,2500); 238 | maxdiffNN('Vector o Vector ',A,B,r); 239 | 240 | r = r + 1; 241 | A = rand(1,1000) + rand(1,1000)*1i; 242 | B = rand(1000,1000); 243 | maxdiffNN('Vector * Matrix ',A,B,r); 244 | 245 | r = r + 1; 246 | A = rand(1000,1000) + rand(1000,1000)*1i; 247 | B = rand(1000,1); 248 | maxdiffNN('Matrix * Vector ',A,B,r); 249 | 250 | r = r + 1; 251 | A = rand(1000,1000) + rand(1000,1000)*1i; 252 | B = rand(1000,1000); 253 | maxdiffNN('Matrix * Matrix ',A,B,r); 254 | 255 | %-------------------------------------------------------------------------- 256 | disp(' '); 257 | disp('(complex) * (complex)'); 258 | disp(' '); 259 | 260 | r = rsave; 261 | 262 | r = r + 1; 263 | A = rand(1,1) + rand(1,1)*1i; 264 | B = rand(1,10000) + rand(1,10000)*1i; 265 | maxdiffNN('Scalar * Vector ',A,B,r); 266 | 267 | r = r + 1; 268 | A = rand(1,10000)+ rand(1,10000)*1i; 269 | B = rand(1,1) + rand(1,1)*1i; 270 | maxdiffNN('Vector * Scalar ',A,B,r); 271 | 272 | r = r + 1; 273 | A = rand(1,1) + rand(1,1)*1i; 274 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 275 | maxdiffNN('Scalar * Array ',A,B,r); 276 | 277 | r = r + 1; 278 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 279 | B = rand(1,1) + rand(1,1)*1i; 280 | maxdiffNN('Array * Scalar ',A,B,r); 281 | 282 | r = r + 1; 283 | A = rand(1,10000000) + rand(1,10000000)*1i; 284 | B = rand(10000000,1) + rand(10000000,1)*1i; 285 | maxdiffNN('Vector i Vector ',A,B,r); 286 | 287 | r = r + 1; 288 | A = rand(2500,1) + rand(2500,1)*1i; 289 | B = rand(1,2500) + rand(1,2500)*1i; 290 | maxdiffNN('Vector o Vector ',A,B,r); 291 | 292 | r = r + 1; 293 | A = rand(1,1000) + rand(1,1000)*1i; 294 | B = rand(1000,1000) + rand(1000,1000)*1i; 295 | maxdiffNN('Vector * Matrix ',A,B,r); 296 | 297 | r = r + 1; 298 | A = rand(1000,1000) + rand(1000,1000)*1i; 299 | B = rand(1000,1) + rand(1000,1)*1i; 300 | maxdiffNN('Matrix * Vector ',A,B,r); 301 | 302 | r = r + 1; 303 | A = rand(1000,1000) + rand(1000,1000)*1i; 304 | B = rand(1000,1000) + rand(1000,1000)*1i; 305 | maxdiffNN('Matrix * Matrix ',A,B,r); 306 | 307 | running_time(datenum(clock) - start_time); 308 | 309 | %-------------------------------------------------------------------------- 310 | %-------------------------------------------------------------------------- 311 | 312 | %end % debug jump 313 | 314 | disp('----------------------------------'); 315 | disp(' '); 316 | disp('Numerical Comparison Tests ...'); 317 | disp(' '); 318 | disp('(real) * (real).'''); 319 | disp(' '); 320 | 321 | if( isequal([]*[].',mtimesx([],[],'T')) ) 322 | disp('Empty * Empty.'' EQUAL'); 323 | else 324 | disp('Empty * Empty.'' NOT EQUAL <---'); 325 | end 326 | 327 | r = r + 1; 328 | mtimesx_dtable(r,:) = RC; 329 | 330 | rsave = r; 331 | 332 | r = r + 1; 333 | A = rand(1,1); 334 | B = rand(10000,1); 335 | maxdiffNT('Scalar * Vector.'' ',A,B,r); 336 | 337 | r = r + 1; 338 | A = rand(10000,1); 339 | B = rand(1,1); 340 | maxdiffNT('Vector * Scalar.'' ',A,B,r); 341 | 342 | r = r + 1; 343 | A = rand(10,20,30,40); 344 | B = rand(1,1); 345 | maxdiffNT('Array * Scalar.'' ',A,B,r); 346 | 347 | r = r + 1; 348 | A = rand(1,10000000); 349 | B = rand(1,10000000); 350 | maxdiffNT('Vector i Vector.'' ',A,B,r); 351 | 352 | r = r + 1; 353 | A = rand(2500,1); 354 | B = rand(2500,1); 355 | maxdiffNT('Vector o Vector.'' ',A,B,r); 356 | 357 | r = r + 1; 358 | A = rand(1,1000); 359 | B = rand(1000,1000); 360 | maxdiffNT('Vector * Matrix.'' ',A,B,r); 361 | 362 | r = r + 1; 363 | A = rand(1000,1000); 364 | B = rand(1,1000); 365 | maxdiffNT('Matrix * Vector.'' ',A,B,r); 366 | 367 | r = r + 1; 368 | A = rand(1000,1000); 369 | B = rand(1000,1000); 370 | maxdiffNT('Matrix * Matrix.'' ',A,B,r); 371 | 372 | %-------------------------------------------------------------------------- 373 | disp(' '); 374 | disp('(real) * (complex).'''); 375 | disp(' '); 376 | 377 | r = rsave; 378 | 379 | r = r + 1; 380 | A = rand(1,1); 381 | B = rand(1,10000) + rand(1,10000)*1i; 382 | maxdiffNT('Scalar * Vector.'' ',A,B,r); 383 | 384 | r = r + 1; 385 | A = rand(10000,1); 386 | B = rand(1,1) + rand(1,1)*1i; 387 | maxdiffNT('Vector * Scalar.'' ',A,B,r); 388 | 389 | r = r + 1; 390 | A = rand(10,20,30,40); 391 | B = rand(1,1) + rand(1,1)*1i; 392 | maxdiffNT('Array * Scalar.'' ',A,B,r); 393 | 394 | r = r + 1; 395 | A = rand(1,10000000); 396 | B = rand(1,10000000) + rand(1,10000000)*1i; 397 | maxdiffNT('Vector i Vector.'' ',A,B,r); 398 | 399 | r = r + 1; 400 | A = rand(2500,1); 401 | B = rand(2500,1) + rand(2500,1)*1i; 402 | maxdiffNT('Vector o Vector.'' ',A,B,r); 403 | 404 | r = r + 1; 405 | A = rand(1,1000); 406 | B = rand(1000,1000) + rand(1000,1000)*1i; 407 | maxdiffNT('Vector * Matrix.'' ',A,B,r); 408 | 409 | r = r + 1; 410 | A = rand(1000,1000); 411 | B = rand(1,1000) + rand(1,1000)*1i; 412 | maxdiffNT('Matrix * Vector.'' ',A,B,r); 413 | 414 | r = r + 1; 415 | A = rand(1000,1000); 416 | B = rand(1000,1000) + rand(1000,1000)*1i; 417 | maxdiffNT('Matrix * Matrix.'' ',A,B,r); 418 | 419 | %-------------------------------------------------------------------------- 420 | disp(' '); 421 | disp('(complex) * (real).'''); 422 | disp(' '); 423 | 424 | r = rsave; 425 | 426 | r = r + 1; 427 | A = rand(1,1) + rand(1,1)*1i; 428 | B = rand(1,10000); 429 | maxdiffNT('Scalar * Vector.'' ',A,B,r); 430 | 431 | r = r + 1; 432 | A = rand(10000,1)+ rand(10000,1)*1i; 433 | B = rand(1,1); 434 | maxdiffNT('Vector * Scalar.'' ',A,B,r); 435 | 436 | r = r + 1; 437 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 438 | B = rand(1,1); 439 | maxdiffNT('Array * Scalar.'' ',A,B,r); 440 | 441 | r = r + 1; 442 | A = rand(1,10000000) + rand(1,10000000)*1i; 443 | B = rand(1,10000000); 444 | maxdiffNT('Vector i Vector.'' ',A,B,r); 445 | 446 | r = r + 1; 447 | A = rand(2500,1) + rand(2500,1)*1i; 448 | B = rand(2500,1); 449 | maxdiffNT('Vector o Vector.'' ',A,B,r); 450 | 451 | r = r + 1; 452 | A = rand(1,1000) + rand(1,1000)*1i; 453 | B = rand(1000,1000); 454 | maxdiffNT('Vector * Matrix.'' ',A,B,r); 455 | 456 | r = r + 1; 457 | A = rand(1000,1000) + rand(1000,1000)*1i; 458 | B = rand(1,1000); 459 | maxdiffNT('Matrix * Vector.'' ',A,B,r); 460 | 461 | r = r + 1; 462 | A = rand(1000,1000) + rand(1000,1000)*1i; 463 | B = rand(1000,1000); 464 | maxdiffNT('Matrix * Matrix.'' ',A,B,r); 465 | 466 | %-------------------------------------------------------------------------- 467 | disp(' '); 468 | disp('(complex) * (complex).'''); 469 | disp(' '); 470 | 471 | r = rsave; 472 | 473 | r = r + 1; 474 | A = rand(1,1) + rand(1,1)*1i; 475 | B = rand(1,10000) + rand(1,10000)*1i; 476 | maxdiffNT('Scalar * Vector.'' ',A,B,r); 477 | 478 | r = r + 1; 479 | A = rand(10000,1)+ rand(10000,1)*1i; 480 | B = rand(1,1) + rand(1,1)*1i; 481 | maxdiffNT('Vector * Scalar.'' ',A,B,r); 482 | 483 | r = r + 1; 484 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 485 | B = rand(1,1) + rand(1,1)*1i; 486 | maxdiffNT('Array * Scalar.'' ',A,B,r); 487 | 488 | r = r + 1; 489 | A = rand(1,10000000) + rand(1,10000000)*1i; 490 | B = rand(1,10000000) + rand(1,10000000)*1i; 491 | maxdiffNT('Vector i Vector.'' ',A,B,r); 492 | 493 | r = r + 1; 494 | A = rand(2500,1) + rand(2500,1)*1i; 495 | B = rand(2500,1) + rand(2500,1)*1i; 496 | maxdiffNT('Vector o Vector.'' ',A,B,r); 497 | 498 | r = r + 1; 499 | A = rand(1,1000) + rand(1,1000)*1i; 500 | B = rand(1000,1000) + rand(1000,1000)*1i; 501 | maxdiffNT('Vector * Matrix.'' ',A,B,r); 502 | 503 | r = r + 1; 504 | A = rand(1000,1000) + rand(1000,1000)*1i; 505 | B = rand(1,1000) + rand(1,1000)*1i; 506 | maxdiffNT('Matrix * Vector.'' ',A,B,r); 507 | 508 | r = r + 1; 509 | A = rand(1000,1000) + rand(1000,1000)*1i; 510 | B = rand(1000,1000) + rand(1000,1000)*1i; 511 | maxdiffNT('Matrix * Matrix.'' ',A,B,r); 512 | 513 | running_time(datenum(clock) - start_time); 514 | 515 | %-------------------------------------------------------------------------- 516 | %-------------------------------------------------------------------------- 517 | 518 | %end % debug jump 519 | 520 | disp('----------------------------------'); 521 | disp(' '); 522 | disp('Numerical Comparison Tests ...'); 523 | disp(' '); 524 | disp('(real) * (real)'''); 525 | disp(' '); 526 | 527 | if( isequal([]*[]',mtimesx([],[],'C')) ) 528 | disp('Empty * Empty'' EQUAL'); 529 | else 530 | disp('Empty * Empty'' NOT EQUAL <---'); 531 | end 532 | 533 | r = r + 1; 534 | mtimesx_dtable(r,:) = RC; 535 | 536 | rsave = r; 537 | 538 | r = r + 1; 539 | A = rand(1,1); 540 | B = rand(10000,1); 541 | maxdiffNC('Scalar * Vector'' ',A,B,r); 542 | 543 | r = r + 1; 544 | A = rand(10000,1); 545 | B = rand(1,1); 546 | maxdiffNC('Vector * Scalar'' ',A,B,r); 547 | 548 | r = r + 1; 549 | A = rand(10,20,30,40); 550 | B = rand(1,1); 551 | maxdiffNC('Array * Scalar'' ',A,B,r); 552 | 553 | r = r + 1; 554 | A = rand(1,10000000); 555 | B = rand(1,10000000); 556 | maxdiffNC('Vector i Vector'' ',A,B,r); 557 | 558 | r = r + 1; 559 | A = rand(2500,1); 560 | B = rand(2500,1); 561 | maxdiffNC('Vector o Vector'' ',A,B,r); 562 | 563 | r = r + 1; 564 | A = rand(1,1000); 565 | B = rand(1000,1000); 566 | maxdiffNC('Vector * Matrix'' ',A,B,r); 567 | 568 | r = r + 1; 569 | A = rand(1000,1000); 570 | B = rand(1,1000); 571 | maxdiffNC('Matrix * Vector'' ',A,B,r); 572 | 573 | r = r + 1; 574 | A = rand(1000,1000); 575 | B = rand(1000,1000); 576 | maxdiffNC('Matrix * Matrix'' ',A,B,r); 577 | 578 | %-------------------------------------------------------------------------- 579 | disp(' '); 580 | disp('(real) * (complex)'''); 581 | disp(' '); 582 | 583 | r = rsave; 584 | 585 | r = r + 1; 586 | A = rand(1,1); 587 | B = rand(1,10000) + rand(1,10000)*1i; 588 | maxdiffNC('Scalar * Vector'' ',A,B,r); 589 | 590 | r = r + 1; 591 | A = rand(10000,1); 592 | B = rand(1,1) + rand(1,1)*1i; 593 | maxdiffNC('Vector * Scalar'' ',A,B,r); 594 | 595 | r = r + 1; 596 | A = rand(10,20,30,40); 597 | B = rand(1,1) + rand(1,1)*1i; 598 | maxdiffNC('Array * Scalar'' ',A,B,r); 599 | 600 | r = r + 1; 601 | A = rand(1,10000000); 602 | B = rand(1,10000000) + rand(1,10000000)*1i; 603 | maxdiffNC('Vector i Vector'' ',A,B,r); 604 | 605 | r = r + 1; 606 | A = rand(2500,1); 607 | B = rand(2500,1) + rand(2500,1)*1i; 608 | maxdiffNC('Vector o Vector'' ',A,B,r); 609 | 610 | r = r + 1; 611 | A = rand(1,1000); 612 | B = rand(1000,1000) + rand(1000,1000)*1i; 613 | maxdiffNC('Vector * Matrix'' ',A,B,r); 614 | 615 | r = r + 1; 616 | A = rand(1000,1000); 617 | B = rand(1,1000) + rand(1,1000)*1i; 618 | maxdiffNC('Matrix * Vector'' ',A,B,r); 619 | 620 | r = r + 1; 621 | A = rand(1000,1000); 622 | B = rand(1000,1000) + rand(1000,1000)*1i; 623 | maxdiffNC('Matrix * Matrix'' ',A,B,r); 624 | 625 | %-------------------------------------------------------------------------- 626 | disp(' '); 627 | disp('(complex) * (real)'''); 628 | disp(' '); 629 | 630 | r = rsave; 631 | 632 | r = r + 1; 633 | A = rand(1,1) + rand(1,1)*1i; 634 | B = rand(1,10000); 635 | maxdiffNC('Scalar * Vector'' ',A,B,r); 636 | 637 | r = r + 1; 638 | A = rand(10000,1)+ rand(10000,1)*1i; 639 | B = rand(1,1); 640 | maxdiffNC('Vector * Scalar'' ',A,B,r); 641 | 642 | r = r + 1; 643 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 644 | B = rand(1,1); 645 | maxdiffNC('Array * Scalar'' ',A,B,r); 646 | 647 | r = r + 1; 648 | A = rand(1,10000000) + rand(1,10000000)*1i; 649 | B = rand(1,10000000); 650 | maxdiffNC('Vector i Vector'' ',A,B,r); 651 | 652 | r = r + 1; 653 | A = rand(2500,1) + rand(2500,1)*1i; 654 | B = rand(2500,1); 655 | maxdiffNC('Vector o Vector'' ',A,B,r); 656 | 657 | r = r + 1; 658 | A = rand(1,1000) + rand(1,1000)*1i; 659 | B = rand(1000,1000); 660 | maxdiffNC('Vector * Matrix'' ',A,B,r); 661 | 662 | r = r + 1; 663 | A = rand(1000,1000) + rand(1000,1000)*1i; 664 | B = rand(1,1000); 665 | maxdiffNC('Matrix * Vector'' ',A,B,r); 666 | 667 | r = r + 1; 668 | A = rand(1000,1000) + rand(1000,1000)*1i; 669 | B = rand(1000,1000); 670 | maxdiffNC('Matrix * Matrix'' ',A,B,r); 671 | 672 | %-------------------------------------------------------------------------- 673 | disp(' '); 674 | disp('(complex) * (complex)'''); 675 | disp(' '); 676 | 677 | r = rsave; 678 | 679 | r = r + 1; 680 | A = rand(1,1) + rand(1,1)*1i; 681 | B = rand(1,10000) + rand(1,10000)*1i; 682 | maxdiffNC('Scalar * Vector'' ',A,B,r); 683 | 684 | r = r + 1; 685 | A = rand(10000,1)+ rand(10000,1)*1i; 686 | B = rand(1,1) + rand(1,1)*1i; 687 | maxdiffNC('Vector * Scalar'' ',A,B,r); 688 | 689 | r = r + 1; 690 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 691 | B = rand(1,1) + rand(1,1)*1i; 692 | maxdiffNC('Array * Scalar'' ',A,B,r); 693 | 694 | r = r + 1; 695 | A = rand(1,10000000) + rand(1,10000000)*1i; 696 | B = rand(1,10000000) + rand(1,10000000)*1i; 697 | maxdiffNC('Vector i Vector'' ',A,B,r); 698 | 699 | r = r + 1; 700 | A = rand(2500,1) + rand(2500,1)*1i; 701 | B = rand(2500,1) + rand(2500,1)*1i; 702 | maxdiffNC('Vector o Vector'' ',A,B,r); 703 | 704 | r = r + 1; 705 | A = rand(1,1000) + rand(1,1000)*1i; 706 | B = rand(1000,1000) + rand(1000,1000)*1i; 707 | maxdiffNC('Vector * Matrix'' ',A,B,r); 708 | 709 | r = r + 1; 710 | A = rand(1000,1000) + rand(1000,1000)*1i; 711 | B = rand(1,1000) + rand(1,1000)*1i; 712 | maxdiffNC('Matrix * Vector'' ',A,B,r); 713 | 714 | r = r + 1; 715 | A = rand(1000,1000) + rand(1000,1000)*1i; 716 | B = rand(1000,1000) + rand(1000,1000)*1i; 717 | maxdiffNC('Matrix * Matrix'' ',A,B,r); 718 | 719 | running_time(datenum(clock) - start_time); 720 | 721 | %-------------------------------------------------------------------------- 722 | %-------------------------------------------------------------------------- 723 | 724 | disp(' '); 725 | disp('Numerical Comparison Tests ...'); 726 | disp(' '); 727 | disp('(real) * conj(real)'); 728 | disp(' '); 729 | 730 | %if( false ) % debug jump 731 | 732 | if( isequal([]*conj([]),mtimesx([],[],'G')) ) 733 | disp('Empty * conj(Empty) EQUAL'); 734 | else 735 | disp('Empty * conj(Empty) NOT EQUAL <---'); 736 | end 737 | 738 | r = r + 1; 739 | mtimesx_dtable(r,:) = RC; 740 | 741 | r = rsave; 742 | 743 | r = r + 1; 744 | A = rand(1,1); 745 | B = rand(1,10000); 746 | maxdiffNG('Scalar * conj(Vector) ',A,B,r); 747 | 748 | r = r + 1; 749 | A = rand(1,10000); 750 | B = rand(1,1); 751 | maxdiffNG('Vector * conj(Scalar) ',A,B,r); 752 | 753 | r = r + 1; 754 | A = rand(1,1); 755 | B = rand(10,20,30,40); 756 | maxdiffNG('Scalar * conj(Array) ',A,B,r); 757 | 758 | r = r + 1; 759 | A = rand(10,20,30,40); 760 | B = rand(1,1); 761 | maxdiffNG('Array * conj(Scalar) ',A,B,r); 762 | 763 | r = r + 1; 764 | A = rand(1,10000000); 765 | B = rand(10000000,1); 766 | maxdiffNG('Vector i conj(Vector) ',A,B,r); 767 | 768 | r = r + 1; 769 | A = rand(2500,1); 770 | B = rand(1,2500); 771 | maxdiffNG('Vector o conj(Vector) ',A,B,r); 772 | 773 | r = r + 1; 774 | A = rand(1,1000); 775 | B = rand(1000,1000); 776 | maxdiffNG('Vector * conj(Matrix) ',A,B,r); 777 | 778 | r = r + 1; 779 | A = rand(1000,1000); 780 | B = rand(1000,1); 781 | maxdiffNG('Matrix * conj(Vector) ',A,B,r); 782 | 783 | r = r + 1; 784 | A = rand(1000,1000); 785 | B = rand(1000,1000); 786 | maxdiffNG('Matrix * conj(Matrix) ',A,B,r); 787 | 788 | %-------------------------------------------------------------------------- 789 | disp(' '); 790 | disp('(real) * conj(complex)'); 791 | disp(' '); 792 | 793 | r = rsave; 794 | 795 | r = r + 1; 796 | A = rand(1,1); 797 | B = rand(1,10000) + rand(1,10000)*1i; 798 | maxdiffNG('Scalar * conj(Vector) ',A,B,r); 799 | 800 | r = r + 1; 801 | A = rand(1,10000); 802 | B = rand(1,1) + rand(1,1)*1i; 803 | maxdiffNG('Vector * conj(Scalar) ',A,B,r); 804 | 805 | r = r + 1; 806 | A = rand(1,1); 807 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 808 | maxdiffNG('Scalar * conj(Array) ',A,B,r); 809 | 810 | r = r + 1; 811 | A = rand(10,20,30,40); 812 | B = rand(1,1) + rand(1,1)*1i; 813 | maxdiffNG('Array * conj(Scalar) ',A,B,r); 814 | 815 | r = r + 1; 816 | A = rand(1,10000000); 817 | B = rand(10000000,1) + rand(10000000,1)*1i; 818 | maxdiffNG('Vector i conj(Vector) ',A,B,r); 819 | 820 | r = r + 1; 821 | A = rand(2500,1); 822 | B = rand(1,2500) + rand(1,2500)*1i; 823 | maxdiffNG('Vector o conj(Vector) ',A,B,r); 824 | 825 | r = r + 1; 826 | A = rand(1,1000); 827 | B = rand(1000,1000) + rand(1000,1000)*1i; 828 | maxdiffNG('Vector * conj(Matrix) ',A,B,r); 829 | 830 | r = r + 1; 831 | A = rand(1000,1000); 832 | B = rand(1000,1) + rand(1000,1)*1i; 833 | maxdiffNG('Matrix * conj(Vector) ',A,B,r); 834 | 835 | r = r + 1; 836 | A = rand(1000,1000); 837 | B = rand(1000,1000) + rand(1000,1000)*1i; 838 | maxdiffNG('Matrix * conj(Matrix) ',A,B,r); 839 | 840 | %-------------------------------------------------------------------------- 841 | disp(' '); 842 | disp('(complex) * conj((real)'); 843 | disp(' '); 844 | 845 | r = rsave; 846 | 847 | r = r + 1; 848 | A = rand(1,1) + rand(1,1)*1i; 849 | B = rand(1,10000); 850 | maxdiffNG('Scalar * conj(Vector) ',A,B,r); 851 | 852 | r = r + 1; 853 | A = rand(1,10000)+ rand(1,10000)*1i; 854 | B = rand(1,1); 855 | maxdiffNG('Vector * conj(Scalar) ',A,B,r); 856 | 857 | r = r + 1; 858 | A = rand(1,1) + rand(1,1)*1i; 859 | B = rand(10,20,30,40); 860 | maxdiffNG('Scalar * conj(Array) ',A,B,r); 861 | 862 | r = r + 1; 863 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 864 | B = rand(1,1); 865 | maxdiffNG('Array * conj(Scalar) ',A,B,r); 866 | 867 | r = r + 1; 868 | A = rand(1,10000000) + rand(1,10000000)*1i; 869 | B = rand(10000000,1); 870 | maxdiffNG('Vector i conj(Vector) ',A,B,r); 871 | 872 | r = r + 1; 873 | A = rand(2500,1) + rand(2500,1)*1i; 874 | B = rand(1,2500); 875 | maxdiffNG('Vector o conj(Vector) ',A,B,r); 876 | 877 | r = r + 1; 878 | A = rand(1,1000) + rand(1,1000)*1i; 879 | B = rand(1000,1000); 880 | maxdiffNG('Vector * conj(Matrix) ',A,B,r); 881 | 882 | r = r + 1; 883 | A = rand(1000,1000) + rand(1000,1000)*1i; 884 | B = rand(1000,1); 885 | maxdiffNG('Matrix * conj(Vector) ',A,B,r); 886 | 887 | r = r + 1; 888 | A = rand(1000,1000) + rand(1000,1000)*1i; 889 | B = rand(1000,1000); 890 | maxdiffNG('Matrix * conj(Matrix) ',A,B,r); 891 | 892 | %-------------------------------------------------------------------------- 893 | disp(' '); 894 | disp('(complex) * conj(complex)'); 895 | disp(' '); 896 | 897 | r = rsave; 898 | 899 | r = r + 1; 900 | A = rand(1,1) + rand(1,1)*1i; 901 | B = rand(1,10000) + rand(1,10000)*1i; 902 | maxdiffNG('Scalar * conj(Vector) ',A,B,r); 903 | 904 | r = r + 1; 905 | A = rand(1,10000)+ rand(1,10000)*1i; 906 | B = rand(1,1) + rand(1,1)*1i; 907 | maxdiffNG('Vector * conj(Scalar) ',A,B,r); 908 | 909 | r = r + 1; 910 | A = rand(1,1) + rand(1,1)*1i; 911 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 912 | maxdiffNG('Scalar * conj(Array) ',A,B,r); 913 | 914 | r = r + 1; 915 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 916 | B = rand(1,1) + rand(1,1)*1i; 917 | maxdiffNG('Array * conj(Scalar) ',A,B,r); 918 | 919 | r = r + 1; 920 | A = rand(1,10000000) + rand(1,10000000)*1i; 921 | B = rand(10000000,1) + rand(10000000,1)*1i; 922 | maxdiffNG('Vector i conj(Vector) ',A,B,r); 923 | 924 | r = r + 1; 925 | A = rand(2500,1) + rand(2500,1)*1i; 926 | B = rand(1,2500) + rand(1,2500)*1i; 927 | maxdiffNG('Vector o conj(Vector) ',A,B,r); 928 | 929 | r = r + 1; 930 | A = rand(1,1000) + rand(1,1000)*1i; 931 | B = rand(1000,1000) + rand(1000,1000)*1i; 932 | maxdiffNG('Vector * conj(Matrix) ',A,B,r); 933 | 934 | r = r + 1; 935 | A = rand(1000,1000) + rand(1000,1000)*1i; 936 | B = rand(1000,1) + rand(1000,1)*1i; 937 | maxdiffNG('Matrix * conj(Vector) ',A,B,r); 938 | 939 | r = r + 1; 940 | A = rand(1000,1000) + rand(1000,1000)*1i; 941 | B = rand(1000,1000) + rand(1000,1000)*1i; 942 | maxdiffNG('Matrix * conj(Matrix) ',A,B,r); 943 | 944 | running_time(datenum(clock) - start_time); 945 | 946 | %-------------------------------------------------------------------------- 947 | %-------------------------------------------------------------------------- 948 | 949 | disp('----------------------------------'); 950 | disp(' '); 951 | disp('Numerical Comparison Tests ...'); 952 | disp(' '); 953 | disp('(real).'' * (real)'); 954 | disp(' '); 955 | 956 | if( isequal([]'*[],mtimesx([],'C',[])) ) 957 | disp('Empty.'' * Empty EQUAL'); 958 | else 959 | disp('Empty.'' * Empty NOT EQUAL <---'); 960 | end 961 | 962 | r = r + 1; 963 | mtimesx_dtable(r,:) = RC; 964 | 965 | rsave = r; 966 | 967 | r = r + 1; 968 | A = rand(1,1); 969 | B = rand(1,10000); 970 | maxdiffTN('Scalar.'' * Vector ',A,B,r); 971 | 972 | r = r + 1; 973 | A = rand(10000,1); 974 | B = rand(1,1); 975 | maxdiffTN('Vector.'' * Scalar ',A,B,r); 976 | 977 | r = r + 1; 978 | A = rand(1,1); 979 | B = rand(10,20,30,40); 980 | maxdiffTN('Scalar.'' * Array ',A,B,r); 981 | 982 | r = r + 1; 983 | A = rand(10000000,1); 984 | B = rand(10000000,1); 985 | maxdiffTN('Vector.'' i Vector ',A,B,r); 986 | 987 | r = r + 1; 988 | A = rand(1,2500); 989 | B = rand(1,2500); 990 | maxdiffTN('Vector.'' o Vector ',A,B,r); 991 | 992 | r = r + 1; 993 | A = rand(1000,1); 994 | B = rand(1000,1000); 995 | maxdiffTN('Vector.'' * Matrix ',A,B,r); 996 | 997 | r = r + 1; 998 | A = rand(1000,1000); 999 | B = rand(1000,1); 1000 | maxdiffTN('Matrix.'' * Vector ',A,B,r); 1001 | 1002 | r = r + 1; 1003 | A = rand(1000,1000); 1004 | B = rand(1000,1000); 1005 | maxdiffTN('Matrix.'' * Matrix ',A,B,r); 1006 | 1007 | %-------------------------------------------------------------------------- 1008 | disp(' '); 1009 | disp('(real).'' * (complex)'); 1010 | disp(' '); 1011 | 1012 | r = rsave; 1013 | 1014 | r = r + 1; 1015 | A = rand(1,1); 1016 | B = rand(1,10000) + rand(1,10000)*1i; 1017 | maxdiffTN('Scalar.'' * Vector ',A,B,r); 1018 | 1019 | r = r + 1; 1020 | A = rand(10000,1); 1021 | B = rand(1,1) + rand(1,1)*1i; 1022 | maxdiffTN('Vector.'' * Scalar ',A,B,r); 1023 | 1024 | r = r + 1; 1025 | A = rand(1,1); 1026 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 1027 | maxdiffTN('Scalar.'' * Array ',A,B,r); 1028 | 1029 | r = r + 1; 1030 | A = rand(10000000,1); 1031 | B = rand(10000000,1) + rand(10000000,1)*1i; 1032 | maxdiffTN('Vector.'' i Vector ',A,B,r); 1033 | 1034 | r = r + 1; 1035 | A = rand(1,2500); 1036 | B = rand(1,2500) + rand(1,2500)*1i; 1037 | maxdiffTN('Vector.'' o Vector ',A,B,r); 1038 | 1039 | r = r + 1; 1040 | A = rand(1000,1); 1041 | B = rand(1000,1000) + rand(1000,1000)*1i; 1042 | maxdiffTN('Vector.'' * Matrix ',A,B,r); 1043 | 1044 | r = r + 1; 1045 | A = rand(1000,1000); 1046 | B = rand(1000,1) + rand(1000,1)*1i; 1047 | maxdiffTN('Matrix.'' * Vector ',A,B,r); 1048 | 1049 | r = r + 1; 1050 | A = rand(1000,1000); 1051 | B = rand(1000,1000) + rand(1000,1000)*1i; 1052 | maxdiffTN('Matrix.'' * Matrix ',A,B,r); 1053 | 1054 | %-------------------------------------------------------------------------- 1055 | disp(' '); 1056 | disp('(complex).'' * (real)'); 1057 | disp(' '); 1058 | 1059 | r = rsave; 1060 | 1061 | r = r + 1; 1062 | A = rand(1,1) + rand(1,1)*1i; 1063 | B = rand(1,10000); 1064 | maxdiffTN('Scalar.'' * Vector ',A,B,r); 1065 | 1066 | r = r + 1; 1067 | A = rand(10000,1)+ rand(10000,1)*1i; 1068 | B = rand(1,1); 1069 | maxdiffTN('Vector.'' * Scalar ',A,B,r); 1070 | 1071 | r = r + 1; 1072 | A = rand(1,1) + rand(1,1)*1i; 1073 | B = rand(10,20,30,40); 1074 | maxdiffTN('Scalar.'' * Array ',A,B,r); 1075 | 1076 | r = r + 1; 1077 | A = rand(10000000,1) + rand(10000000,1)*1i; 1078 | B = rand(10000000,1); 1079 | maxdiffTN('Vector.'' i Vector ',A,B,r); 1080 | 1081 | r = r + 1; 1082 | A = rand(1,2500) + rand(1,2500)*1i; 1083 | B = rand(1,2500); 1084 | maxdiffTN('Vector.'' o Vector ',A,B,r); 1085 | 1086 | r = r + 1; 1087 | A = rand(1000,1) + rand(1000,1)*1i; 1088 | B = rand(1000,1000); 1089 | maxdiffTN('Vector.'' * Matrix ',A,B,r); 1090 | 1091 | r = r + 1; 1092 | A = rand(1000,1000) + rand(1000,1000)*1i; 1093 | B = rand(1000,1); 1094 | maxdiffTN('Matrix.'' * Vector ',A,B,r); 1095 | 1096 | r = r + 1; 1097 | A = rand(1000,1000) + rand(1000,1000)*1i; 1098 | B = rand(1000,1000); 1099 | maxdiffTN('Matrix.'' * Matrix ',A,B,r); 1100 | 1101 | %-------------------------------------------------------------------------- 1102 | disp(' '); 1103 | disp('(complex).'' * (complex)'); 1104 | disp(' '); 1105 | 1106 | r = rsave; 1107 | 1108 | r = r + 1; 1109 | A = rand(1,1) + rand(1,1)*1i; 1110 | B = rand(1,10000) + rand(1,10000)*1i; 1111 | maxdiffTN('Scalar.'' * Vector ',A,B,r); 1112 | 1113 | r = r + 1; 1114 | A = rand(10000,1)+ rand(10000,1)*1i; 1115 | B = rand(1,1) + rand(1,1)*1i; 1116 | maxdiffTN('Vector.'' * Scalar ',A,B,r); 1117 | 1118 | r = r + 1; 1119 | A = rand(1,1) + rand(1,1)*1i; 1120 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 1121 | maxdiffTN('Scalar.'' * Array ',A,B,r); 1122 | 1123 | r = r + 1; 1124 | A = rand(10000000,1) + rand(10000000,1)*1i; 1125 | B = rand(10000000,1) + rand(10000000,1)*1i; 1126 | maxdiffTN('Vector.'' i Vector ',A,B,r); 1127 | 1128 | r = r + 1; 1129 | A = rand(1,2500) + rand(1,2500)*1i; 1130 | B = rand(1,2500) + rand(1,2500)*1i; 1131 | maxdiffTN('Vector.'' o Vector ',A,B,r); 1132 | 1133 | r = r + 1; 1134 | A = rand(1000,1) + rand(1000,1)*1i; 1135 | B = rand(1000,1000) + rand(1000,1000)*1i; 1136 | maxdiffTN('Vector.'' * Matrix ',A,B,r); 1137 | 1138 | r = r + 1; 1139 | A = rand(1000,1000) + rand(1000,1000)*1i; 1140 | B = rand(1000,1) + rand(1000,1)*1i; 1141 | maxdiffTN('Matrix.'' * Vector ',A,B,r); 1142 | 1143 | r = r + 1; 1144 | A = rand(1000,1000) + rand(1000,1000)*1i; 1145 | B = rand(1000,1000) + rand(1000,1000)*1i; 1146 | maxdiffTN('Matrix.'' * Matrix ',A,B,r); 1147 | 1148 | running_time(datenum(clock) - start_time); 1149 | 1150 | %-------------------------------------------------------------------------- 1151 | %-------------------------------------------------------------------------- 1152 | 1153 | %end % debug jump 1154 | 1155 | disp('----------------------------------'); 1156 | disp(' '); 1157 | disp('Numerical Comparison Tests ...'); 1158 | disp(' '); 1159 | disp('(real).'' * (real).'''); 1160 | disp(' '); 1161 | 1162 | if( isequal([].'*[]',mtimesx([],'T',[],'C')) ) 1163 | disp('Empty.'' * Empty.'' EQUAL'); 1164 | else 1165 | disp('Empty.'' * Empty.'' NOT EQUAL <---'); 1166 | end 1167 | 1168 | r = r + 1; 1169 | mtimesx_dtable(r,:) = RC; 1170 | 1171 | rsave = r; 1172 | 1173 | r = r + 1; 1174 | A = rand(1,1); 1175 | B = rand(10000,1); 1176 | maxdiffTT('Scalar.'' * Vector.'' ',A,B,r); 1177 | 1178 | r = r + 1; 1179 | A = rand(10000,1); 1180 | B = rand(1,1); 1181 | maxdiffTT('Vector.'' * Scalar.'' ',A,B,r); 1182 | 1183 | r = r + 1; 1184 | A = rand(10000000,1); 1185 | B = rand(1,10000000); 1186 | maxdiffTT('Vector.'' i Vector.'' ',A,B,r); 1187 | 1188 | r = r + 1; 1189 | A = rand(1,2500); 1190 | B = rand(2500,1); 1191 | maxdiffTT('Vector.'' o Vector.'' ',A,B,r); 1192 | 1193 | r = r + 1; 1194 | A = rand(1000,1); 1195 | B = rand(1000,1000); 1196 | maxdiffTT('Vector.'' * Matrix.'' ',A,B,r); 1197 | 1198 | r = r + 1; 1199 | A = rand(1000,1000); 1200 | B = rand(1,1000); 1201 | maxdiffTT('Matrix.'' * Vector.'' ',A,B,r); 1202 | 1203 | r = r + 1; 1204 | A = rand(1000,1000); 1205 | B = rand(1000,1000); 1206 | maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r); 1207 | 1208 | %-------------------------------------------------------------------------- 1209 | disp(' '); 1210 | disp('(real).'' * (complex).'''); 1211 | disp(' '); 1212 | 1213 | r = rsave; 1214 | 1215 | r = r + 1; 1216 | A = rand(1,1); 1217 | B = rand(1,10000) + rand(1,10000)*1i; 1218 | maxdiffTT('Scalar.'' * Vector.'' ',A,B,r); 1219 | 1220 | r = r + 1; 1221 | A = rand(10000,1); 1222 | B = rand(1,1) + rand(1,1)*1i; 1223 | maxdiffTT('Vector.'' * Scalar.'' ',A,B,r); 1224 | 1225 | r = r + 1; 1226 | A = rand(10000000,1); 1227 | B = rand(1,10000000) + rand(1,10000000)*1i; 1228 | maxdiffTT('Vector.'' i Vector.'' ',A,B,r); 1229 | 1230 | r = r + 1; 1231 | A = rand(1,2500); 1232 | B = rand(2500,1) + rand(2500,1)*1i; 1233 | maxdiffTT('Vector.'' o Vector.'' ',A,B,r); 1234 | 1235 | r = r + 1; 1236 | A = rand(1000,1); 1237 | B = rand(1000,1000) + rand(1000,1000)*1i; 1238 | maxdiffTT('Vector.'' * Matrix.'' ',A,B,r); 1239 | 1240 | r = r + 1; 1241 | A = rand(1000,1000); 1242 | B = rand(1,1000) + rand(1,1000)*1i; 1243 | maxdiffTT('Matrix.'' * Vector.'' ',A,B,r); 1244 | 1245 | r = r + 1; 1246 | A = rand(1000,1000); 1247 | B = rand(1000,1000) + rand(1000,1000)*1i; 1248 | maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r); 1249 | 1250 | %-------------------------------------------------------------------------- 1251 | disp(' '); 1252 | disp('(complex).'' * (real).'''); 1253 | disp(' '); 1254 | 1255 | r = rsave; 1256 | 1257 | r = r + 1; 1258 | A = rand(1,1) + rand(1,1)*1i; 1259 | B = rand(1,10000); 1260 | maxdiffTT('Scalar.'' * Vector.'' ',A,B,r); 1261 | 1262 | r = r + 1; 1263 | A = rand(10000,1)+ rand(10000,1)*1i; 1264 | B = rand(1,1); 1265 | maxdiffTT('Vector.'' * Scalar.'' ',A,B,r); 1266 | 1267 | r = r + 1; 1268 | A = rand(10000000,1) + rand(10000000,1)*1i; 1269 | B = rand(1,10000000); 1270 | maxdiffTT('Vector.'' i Vector.'' ',A,B,r); 1271 | 1272 | r = r + 1; 1273 | A = rand(1,2500) + rand(1,2500)*1i; 1274 | B = rand(2500,1); 1275 | maxdiffTT('Vector.'' o Vector.'' ',A,B,r); 1276 | 1277 | r = r + 1; 1278 | A = rand(1000,1) + rand(1000,1)*1i; 1279 | B = rand(1000,1000); 1280 | maxdiffTT('Vector.'' * Matrix.'' ',A,B,r); 1281 | 1282 | r = r + 1; 1283 | A = rand(1000,1000) + rand(1000,1000)*1i; 1284 | B = rand(1,1000); 1285 | maxdiffTT('Matrix.'' * Vector.'' ',A,B,r); 1286 | 1287 | r = r + 1; 1288 | A = rand(1000,1000) + rand(1000,1000)*1i; 1289 | B = rand(1000,1000); 1290 | maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r); 1291 | 1292 | %-------------------------------------------------------------------------- 1293 | disp(' '); 1294 | disp('(complex).'' * (complex).'''); 1295 | disp(' '); 1296 | 1297 | r = rsave; 1298 | 1299 | r = r + 1; 1300 | A = rand(1,1) + rand(1,1)*1i; 1301 | B = rand(1,10000) + rand(1,10000)*1i; 1302 | maxdiffTT('Scalar.'' * Vector.'' ',A,B,r); 1303 | 1304 | r = r + 1; 1305 | A = rand(10000,1)+ rand(10000,1)*1i; 1306 | B = rand(1,1) + rand(1,1)*1i; 1307 | maxdiffTT('Vector.'' * Scalar.'' ',A,B,r); 1308 | 1309 | r = r + 1; 1310 | A = rand(10000000,1) + rand(10000000,1)*1i; 1311 | B = rand(1,10000000) + rand(1,10000000)*1i; 1312 | maxdiffTT('Vector.'' i Vector.'' ',A,B,r); 1313 | 1314 | r = r + 1; 1315 | A = rand(1,2500) + rand(1,2500)*1i; 1316 | B = rand(2500,1) + rand(2500,1)*1i; 1317 | maxdiffTT('Vector.'' o Vector.'' ',A,B,r); 1318 | 1319 | r = r + 1; 1320 | A = rand(1000,1) + rand(1000,1)*1i; 1321 | B = rand(1000,1000) + rand(1000,1000)*1i; 1322 | maxdiffTT('Vector.'' * Matrix.'' ',A,B,r); 1323 | 1324 | r = r + 1; 1325 | A = rand(1000,1000) + rand(1000,1000)*1i; 1326 | B = rand(1,1000) + rand(1,1000)*1i; 1327 | maxdiffTT('Matrix.'' * Vector.'' ',A,B,r); 1328 | 1329 | r = r + 1; 1330 | A = rand(1000,1000) + rand(1000,1000)*1i; 1331 | B = rand(1000,1000) + rand(1000,1000)*1i; 1332 | maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r); 1333 | 1334 | running_time(datenum(clock) - start_time); 1335 | 1336 | %-------------------------------------------------------------------------- 1337 | %-------------------------------------------------------------------------- 1338 | 1339 | %end % debug jump 1340 | 1341 | disp('----------------------------------'); 1342 | disp(' '); 1343 | disp('Numerical Comparison Tests ...'); 1344 | disp(' '); 1345 | disp('(real).'' * (real)'''); 1346 | disp(' '); 1347 | 1348 | if( isequal([].'*[]',mtimesx([],'T',[],'C')) ) 1349 | disp('Empty.'' * Empty'' EQUAL'); 1350 | else 1351 | disp('Empty.'' * Empty'' NOT EQUAL <---'); 1352 | end 1353 | 1354 | r = r + 1; 1355 | mtimesx_dtable(r,:) = RC; 1356 | 1357 | rsave = r; 1358 | 1359 | r = r + 1; 1360 | A = rand(1,1); 1361 | B = rand(10000,1); 1362 | maxdiffTC('Scalar.'' * Vector'' ',A,B,r); 1363 | 1364 | r = r + 1; 1365 | A = rand(10000,1); 1366 | B = rand(1,1); 1367 | maxdiffTC('Vector.'' * Scalar'' ',A,B,r); 1368 | 1369 | r = r + 1; 1370 | A = rand(10000000,1); 1371 | B = rand(1,10000000); 1372 | maxdiffTC('Vector.'' i Vector'' ',A,B,r); 1373 | 1374 | r = r + 1; 1375 | A = rand(1,2500); 1376 | B = rand(2500,1); 1377 | maxdiffTC('Vector.'' o Vector'' ',A,B,r); 1378 | 1379 | r = r + 1; 1380 | A = rand(1000,1); 1381 | B = rand(1000,1000); 1382 | maxdiffTC('Vector.'' * Matrix'' ',A,B,r); 1383 | 1384 | r = r + 1; 1385 | A = rand(1000,1000); 1386 | B = rand(1,1000); 1387 | maxdiffTC('Matrix.'' * Vector'' ',A,B,r); 1388 | 1389 | r = r + 1; 1390 | A = rand(1000,1000); 1391 | B = rand(1000,1000); 1392 | maxdiffTC('Matrix.'' * Matrix'' ',A,B,r); 1393 | 1394 | %-------------------------------------------------------------------------- 1395 | disp(' '); 1396 | disp('(real).'' * (complex)'''); 1397 | disp(' '); 1398 | 1399 | r = rsave; 1400 | 1401 | r = r + 1; 1402 | A = rand(1,1); 1403 | B = rand(1,10000) + rand(1,10000)*1i; 1404 | maxdiffTC('Scalar.'' * Vector'' ',A,B,r); 1405 | 1406 | r = r + 1; 1407 | A = rand(10000,1); 1408 | B = rand(1,1) + rand(1,1)*1i; 1409 | maxdiffTC('Vector.'' * Scalar'' ',A,B,r); 1410 | 1411 | r = r + 1; 1412 | A = rand(10000000,1); 1413 | B = rand(1,10000000) + rand(1,10000000)*1i; 1414 | maxdiffTC('Vector.'' i Vector'' ',A,B,r); 1415 | 1416 | r = r + 1; 1417 | A = rand(1,2500); 1418 | B = rand(2500,1) + rand(2500,1)*1i; 1419 | maxdiffTC('Vector.'' o Vector'' ',A,B,r); 1420 | 1421 | r = r + 1; 1422 | A = rand(1000,1); 1423 | B = rand(1000,1000) + rand(1000,1000)*1i; 1424 | maxdiffTC('Vector.'' * Matrix'' ',A,B,r); 1425 | 1426 | r = r + 1; 1427 | A = rand(1000,1000); 1428 | B = rand(1,1000) + rand(1,1000)*1i; 1429 | maxdiffTC('Matrix.'' * Vector'' ',A,B,r); 1430 | 1431 | r = r + 1; 1432 | A = rand(1000,1000); 1433 | B = rand(1000,1000) + rand(1000,1000)*1i; 1434 | maxdiffTC('Matrix.'' * Matrix'' ',A,B,r); 1435 | 1436 | %-------------------------------------------------------------------------- 1437 | disp(' '); 1438 | disp('(complex).'' * (real)'''); 1439 | disp(' '); 1440 | 1441 | r = rsave; 1442 | 1443 | r = r + 1; 1444 | A = rand(1,1) + rand(1,1)*1i; 1445 | B = rand(1,10000); 1446 | maxdiffTC('Scalar.'' * Vector'' ',A,B,r); 1447 | 1448 | r = r + 1; 1449 | A = rand(10000,1)+ rand(10000,1)*1i; 1450 | B = rand(1,1); 1451 | maxdiffTC('Vector.'' * Scalar'' ',A,B,r); 1452 | 1453 | r = r + 1; 1454 | A = rand(10000000,1) + rand(10000000,1)*1i; 1455 | B = rand(1,10000000); 1456 | maxdiffTC('Vector.'' i Vector'' ',A,B,r); 1457 | 1458 | r = r + 1; 1459 | A = rand(1,2500) + rand(1,2500)*1i; 1460 | B = rand(2500,1); 1461 | maxdiffTC('Vector.'' o Vector'' ',A,B,r); 1462 | 1463 | r = r + 1; 1464 | A = rand(1000,1) + rand(1000,1)*1i; 1465 | B = rand(1000,1000); 1466 | maxdiffTC('Vector.'' * Matrix'' ',A,B,r); 1467 | 1468 | r = r + 1; 1469 | A = rand(1000,1000) + rand(1000,1000)*1i; 1470 | B = rand(1,1000); 1471 | maxdiffTC('Matrix.'' * Vector'' ',A,B,r); 1472 | 1473 | r = r + 1; 1474 | A = rand(1000,1000) + rand(1000,1000)*1i; 1475 | B = rand(1000,1000); 1476 | maxdiffTC('Matrix.'' * Matrix'' ',A,B,r); 1477 | 1478 | %-------------------------------------------------------------------------- 1479 | disp(' '); 1480 | disp('(complex).'' * (complex)'''); 1481 | disp(' '); 1482 | 1483 | r = rsave; 1484 | 1485 | r = r + 1; 1486 | A = rand(1,1) + rand(1,1)*1i; 1487 | B = rand(1,10000) + rand(1,10000)*1i; 1488 | maxdiffTC('Scalar.'' * Vector'' ',A,B,r); 1489 | 1490 | r = r + 1; 1491 | A = rand(10000,1)+ rand(10000,1)*1i; 1492 | B = rand(1,1) + rand(1,1)*1i; 1493 | maxdiffTC('Vector.'' * Scalar'' ',A,B,r); 1494 | 1495 | r = r + 1; 1496 | A = rand(10000000,1) + rand(10000000,1)*1i; 1497 | B = rand(1,10000000) + rand(1,10000000)*1i; 1498 | maxdiffTC('Vector.'' i Vector'' ',A,B,r); 1499 | 1500 | r = r + 1; 1501 | A = rand(1,2500) + rand(1,2500)*1i; 1502 | B = rand(2500,1) + rand(2500,1)*1i; 1503 | maxdiffTC('Vector.'' o Vector'' ',A,B,r); 1504 | 1505 | r = r + 1; 1506 | A = rand(1000,1) + rand(1000,1)*1i; 1507 | B = rand(1000,1000) + rand(1000,1000)*1i; 1508 | maxdiffTC('Vector.'' * Matrix'' ',A,B,r); 1509 | 1510 | r = r + 1; 1511 | A = rand(1000,1000) + rand(1000,1000)*1i; 1512 | B = rand(1,1000) + rand(1,1000)*1i; 1513 | maxdiffTC('Matrix.'' * Vector'' ',A,B,r); 1514 | 1515 | r = r + 1; 1516 | A = rand(1000,1000) + rand(1000,1000)*1i; 1517 | B = rand(1000,1000) + rand(1000,1000)*1i; 1518 | maxdiffTC('Matrix.'' * Matrix'' ',A,B,r); 1519 | 1520 | running_time(datenum(clock) - start_time); 1521 | 1522 | %-------------------------------------------------------------------------- 1523 | %-------------------------------------------------------------------------- 1524 | 1525 | disp('----------------------------------'); 1526 | disp(' '); 1527 | disp('Numerical Comparison Tests ...'); 1528 | disp(' '); 1529 | disp('(real).'' * conj(real)'); 1530 | disp(' '); 1531 | 1532 | if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) ) 1533 | disp('Empty.'' * conj(Empty) EQUAL'); 1534 | else 1535 | disp('Empty.'' * conj(Empty) NOT EQUAL <---'); 1536 | end 1537 | 1538 | r = r + 1; 1539 | mtimesx_dtable(r,:) = RC; 1540 | 1541 | rsave = r; 1542 | 1543 | r = r + 1; 1544 | A = rand(1,1); 1545 | B = rand(1,10000); 1546 | maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r); 1547 | 1548 | r = r + 1; 1549 | A = rand(10000,1); 1550 | B = rand(1,1); 1551 | maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r); 1552 | 1553 | r = r + 1; 1554 | A = rand(1,1); 1555 | B = rand(10,20,30,40); 1556 | maxdiffTG('Scalar.'' * conj(Array) ',A,B,r); 1557 | 1558 | r = r + 1; 1559 | A = rand(10000000,1); 1560 | B = rand(10000000,1); 1561 | maxdiffTG('Vector.'' i conj(Vector) ',A,B,r); 1562 | 1563 | r = r + 1; 1564 | A = rand(1,2500); 1565 | B = rand(1,2500); 1566 | maxdiffTG('Vector.'' o conj(Vector) ',A,B,r); 1567 | 1568 | r = r + 1; 1569 | A = rand(1000,1); 1570 | B = rand(1000,1000); 1571 | maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r); 1572 | 1573 | r = r + 1; 1574 | A = rand(1000,1000); 1575 | B = rand(1000,1); 1576 | maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r); 1577 | 1578 | r = r + 1; 1579 | A = rand(1000,1000); 1580 | B = rand(1000,1000); 1581 | maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r); 1582 | 1583 | %-------------------------------------------------------------------------- 1584 | disp(' '); 1585 | disp('(real).'' * conj(complex)'); 1586 | disp(' '); 1587 | 1588 | r = rsave; 1589 | 1590 | r = r + 1; 1591 | A = rand(1,1); 1592 | B = rand(1,10000) + rand(1,10000)*1i; 1593 | maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r); 1594 | 1595 | r = r + 1; 1596 | A = rand(10000,1); 1597 | B = rand(1,1) + rand(1,1)*1i; 1598 | maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r); 1599 | 1600 | r = r + 1; 1601 | A = rand(1,1); 1602 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 1603 | maxdiffTG('Scalar.'' * conj(Array) ',A,B,r); 1604 | 1605 | r = r + 1; 1606 | A = rand(10000000,1); 1607 | B = rand(10000000,1) + rand(10000000,1)*1i; 1608 | maxdiffTG('Vector.'' i conj(Vector) ',A,B,r); 1609 | 1610 | r = r + 1; 1611 | A = rand(1,2500); 1612 | B = rand(1,2500) + rand(1,2500)*1i; 1613 | maxdiffTG('Vector.'' o conj(Vector) ',A,B,r); 1614 | 1615 | r = r + 1; 1616 | A = rand(1000,1); 1617 | B = rand(1000,1000) + rand(1000,1000)*1i; 1618 | maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r); 1619 | 1620 | r = r + 1; 1621 | A = rand(1000,1000); 1622 | B = rand(1000,1) + rand(1000,1)*1i; 1623 | maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r); 1624 | 1625 | r = r + 1; 1626 | A = rand(1000,1000); 1627 | B = rand(1000,1000) + rand(1000,1000)*1i; 1628 | maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r); 1629 | 1630 | %-------------------------------------------------------------------------- 1631 | disp(' '); 1632 | disp('(complex).'' * conj(real)'); 1633 | disp(' '); 1634 | 1635 | r = rsave; 1636 | 1637 | r = r + 1; 1638 | A = rand(1,1) + rand(1,1)*1i; 1639 | B = rand(1,10000); 1640 | maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r); 1641 | 1642 | r = r + 1; 1643 | A = rand(10000,1)+ rand(10000,1)*1i; 1644 | B = rand(1,1); 1645 | maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r); 1646 | 1647 | r = r + 1; 1648 | A = rand(1,1) + rand(1,1)*1i; 1649 | B = rand(10,20,30,40); 1650 | maxdiffTG('Scalar.'' * conj(Array) ',A,B,r); 1651 | 1652 | r = r + 1; 1653 | A = rand(10000000,1) + rand(10000000,1)*1i; 1654 | B = rand(10000000,1); 1655 | maxdiffTG('Vector.'' i conj(Vector) ',A,B,r); 1656 | 1657 | r = r + 1; 1658 | A = rand(1,2500) + rand(1,2500)*1i; 1659 | B = rand(1,2500); 1660 | maxdiffTG('Vector.'' o conj(Vector) ',A,B,r); 1661 | 1662 | r = r + 1; 1663 | A = rand(1000,1) + rand(1000,1)*1i; 1664 | B = rand(1000,1000); 1665 | maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r); 1666 | 1667 | r = r + 1; 1668 | A = rand(1000,1000) + rand(1000,1000)*1i; 1669 | B = rand(1000,1); 1670 | maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r); 1671 | 1672 | r = r + 1; 1673 | A = rand(1000,1000) + rand(1000,1000)*1i; 1674 | B = rand(1000,1000); 1675 | maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r); 1676 | 1677 | %-------------------------------------------------------------------------- 1678 | disp(' '); 1679 | disp('(complex).'' * conj(complex)'); 1680 | disp(' '); 1681 | 1682 | r = rsave; 1683 | 1684 | r = r + 1; 1685 | A = rand(1,1) + rand(1,1)*1i; 1686 | B = rand(1,10000) + rand(1,10000)*1i; 1687 | maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r); 1688 | 1689 | r = r + 1; 1690 | A = rand(10000,1)+ rand(10000,1)*1i; 1691 | B = rand(1,1) + rand(1,1)*1i; 1692 | maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r); 1693 | 1694 | r = r + 1; 1695 | A = rand(1,1) + rand(1,1)*1i; 1696 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 1697 | maxdiffTG('Scalar.'' * conj(Array) ',A,B,r); 1698 | 1699 | r = r + 1; 1700 | A = rand(10000000,1) + rand(10000000,1)*1i; 1701 | B = rand(10000000,1) + rand(10000000,1)*1i; 1702 | maxdiffTG('Vector.'' i conj(Vector) ',A,B,r); 1703 | 1704 | r = r + 1; 1705 | A = rand(1,2500) + rand(1,2500)*1i; 1706 | B = rand(1,2500) + rand(1,2500)*1i; 1707 | maxdiffTG('Vector.'' o conj(Vector) ',A,B,r); 1708 | 1709 | r = r + 1; 1710 | A = rand(1000,1) + rand(1000,1)*1i; 1711 | B = rand(1000,1000) + rand(1000,1000)*1i; 1712 | maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r); 1713 | 1714 | r = r + 1; 1715 | A = rand(1000,1000) + rand(1000,1000)*1i; 1716 | B = rand(1000,1) + rand(1000,1)*1i; 1717 | maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r); 1718 | 1719 | r = r + 1; 1720 | A = rand(1000,1000) + rand(1000,1000)*1i; 1721 | B = rand(1000,1000) + rand(1000,1000)*1i; 1722 | maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r); 1723 | 1724 | running_time(datenum(clock) - start_time); 1725 | 1726 | %-------------------------------------------------------------------------- 1727 | %-------------------------------------------------------------------------- 1728 | 1729 | disp('----------------------------------'); 1730 | disp(' '); 1731 | disp('Numerical Comparison Tests ...'); 1732 | disp(' '); 1733 | disp('(real)'' * (real)'); 1734 | disp(' '); 1735 | 1736 | if( isequal([]'*[],mtimesx([],'C',[])) ) 1737 | disp('Empty'' * Empty EQUAL'); 1738 | else 1739 | disp('Empty'' * Empty NOT EQUAL <---'); 1740 | end 1741 | 1742 | r = r + 1; 1743 | mtimesx_dtable(r,:) = RC; 1744 | 1745 | rsave = r; 1746 | 1747 | r = r + 1; 1748 | A = rand(1,1); 1749 | B = rand(1,10000); 1750 | maxdiffCN('Scalar'' * Vector ',A,B,r); 1751 | 1752 | r = r + 1; 1753 | A = rand(10000,1); 1754 | B = rand(1,1); 1755 | maxdiffCN('Vector'' * Scalar ',A,B,r); 1756 | 1757 | r = r + 1; 1758 | A = rand(1,1); 1759 | B = rand(10,20,30,40); 1760 | maxdiffCN('Scalar'' * Array ',A,B,r); 1761 | 1762 | r = r + 1; 1763 | A = rand(10000000,1); 1764 | B = rand(10000000,1); 1765 | maxdiffCN('Vector'' i Vector ',A,B,r); 1766 | 1767 | r = r + 1; 1768 | A = rand(1,2500); 1769 | B = rand(1,2500); 1770 | maxdiffCN('Vector'' o Vector ',A,B,r); 1771 | 1772 | r = r + 1; 1773 | A = rand(1000,1); 1774 | B = rand(1000,1000); 1775 | maxdiffCN('Vector'' * Matrix ',A,B,r); 1776 | 1777 | r = r + 1; 1778 | A = rand(1000,1000); 1779 | B = rand(1000,1); 1780 | maxdiffCN('Matrix'' * Vector ',A,B,r); 1781 | 1782 | r = r + 1; 1783 | A = rand(1000,1000); 1784 | B = rand(1000,1000); 1785 | maxdiffCN('Matrix'' * Matrix ',A,B,r); 1786 | 1787 | %-------------------------------------------------------------------------- 1788 | disp(' '); 1789 | disp('(real)'' * (complex)'); 1790 | disp(' '); 1791 | 1792 | r = rsave; 1793 | 1794 | r = r + 1; 1795 | A = rand(1,1); 1796 | B = rand(1,10000) + rand(1,10000)*1i; 1797 | maxdiffCN('Scalar'' * Vector ',A,B,r); 1798 | 1799 | r = r + 1; 1800 | A = rand(10000,1); 1801 | B = rand(1,1) + rand(1,1)*1i; 1802 | maxdiffCN('Vector'' * Scalar ',A,B,r); 1803 | 1804 | r = r + 1; 1805 | A = rand(1,1); 1806 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 1807 | maxdiffCN('Scalar'' * Array ',A,B,r); 1808 | 1809 | r = r + 1; 1810 | A = rand(10000000,1); 1811 | B = rand(10000000,1) + rand(10000000,1)*1i; 1812 | maxdiffCN('Vector'' i Vector ',A,B,r); 1813 | 1814 | r = r + 1; 1815 | A = rand(1,2500); 1816 | B = rand(1,2500) + rand(1,2500)*1i; 1817 | maxdiffCN('Vector'' o Vector ',A,B,r); 1818 | 1819 | r = r + 1; 1820 | A = rand(1000,1); 1821 | B = rand(1000,1000) + rand(1000,1000)*1i; 1822 | maxdiffCN('Vector'' * Matrix ',A,B,r); 1823 | 1824 | r = r + 1; 1825 | A = rand(1000,1000); 1826 | B = rand(1000,1) + rand(1000,1)*1i; 1827 | maxdiffCN('Matrix'' * Vector ',A,B,r); 1828 | 1829 | r = r + 1; 1830 | A = rand(1000,1000); 1831 | B = rand(1000,1000) + rand(1000,1000)*1i; 1832 | maxdiffCN('Matrix'' * Matrix ',A,B,r); 1833 | 1834 | %-------------------------------------------------------------------------- 1835 | disp(' '); 1836 | disp('(complex)'' * (real)'); 1837 | disp(' '); 1838 | 1839 | r = rsave; 1840 | 1841 | r = r + 1; 1842 | A = rand(1,1) + rand(1,1)*1i; 1843 | B = rand(1,10000); 1844 | maxdiffCN('Scalar'' * Vector ',A,B,r); 1845 | 1846 | r = r + 1; 1847 | A = rand(10000,1)+ rand(10000,1)*1i; 1848 | B = rand(1,1); 1849 | maxdiffCN('Vector'' * Scalar ',A,B,r); 1850 | 1851 | r = r + 1; 1852 | A = rand(1,1) + rand(1,1)*1i; 1853 | B = rand(10,20,30,40); 1854 | maxdiffCN('Scalar'' * Array ',A,B,r); 1855 | 1856 | r = r + 1; 1857 | A = rand(10000000,1) + rand(10000000,1)*1i; 1858 | B = rand(10000000,1); 1859 | maxdiffCN('Vector'' i Vector ',A,B,r); 1860 | 1861 | r = r + 1; 1862 | A = rand(1,2500) + rand(1,2500)*1i; 1863 | B = rand(1,2500); 1864 | maxdiffCN('Vector'' o Vector ',A,B,r); 1865 | 1866 | r = r + 1; 1867 | A = rand(1000,1) + rand(1000,1)*1i; 1868 | B = rand(1000,1000); 1869 | maxdiffCN('Vector'' * Matrix ',A,B,r); 1870 | 1871 | r = r + 1; 1872 | A = rand(1000,1000) + rand(1000,1000)*1i; 1873 | B = rand(1000,1); 1874 | maxdiffCN('Matrix'' * Vector ',A,B,r); 1875 | 1876 | r = r + 1; 1877 | A = rand(1000,1000) + rand(1000,1000)*1i; 1878 | B = rand(1000,1000); 1879 | maxdiffCN('Matrix'' * Matrix ',A,B,r); 1880 | 1881 | %-------------------------------------------------------------------------- 1882 | disp(' '); 1883 | disp('(complex)'' * (complex)'); 1884 | disp(' '); 1885 | 1886 | r = rsave; 1887 | 1888 | r = r + 1; 1889 | A = rand(1,1) + rand(1,1)*1i; 1890 | B = rand(1,10000) + rand(1,10000)*1i; 1891 | maxdiffCN('Scalar'' * Vector ',A,B,r); 1892 | 1893 | r = r + 1; 1894 | A = rand(10000,1)+ rand(10000,1)*1i; 1895 | B = rand(1,1) + rand(1,1)*1i; 1896 | maxdiffCN('Vector'' * Scalar ',A,B,r); 1897 | 1898 | r = r + 1; 1899 | A = rand(1,1) + rand(1,1)*1i; 1900 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 1901 | maxdiffCN('Scalar'' * Array ',A,B,r); 1902 | 1903 | r = r + 1; 1904 | A = rand(10000000,1) + rand(10000000,1)*1i; 1905 | B = rand(10000000,1) + rand(10000000,1)*1i; 1906 | maxdiffCN('Vector'' i Vector ',A,B,r); 1907 | 1908 | r = r + 1; 1909 | A = rand(1,2500) + rand(1,2500)*1i; 1910 | B = rand(1,2500) + rand(1,2500)*1i; 1911 | maxdiffCN('Vector'' o Vector ',A,B,r); 1912 | 1913 | r = r + 1; 1914 | A = rand(1000,1) + rand(1000,1)*1i; 1915 | B = rand(1000,1000) + rand(1000,1000)*1i; 1916 | maxdiffCN('Vector'' * Matrix ',A,B,r); 1917 | 1918 | r = r + 1; 1919 | A = rand(1000,1000) + rand(1000,1000)*1i; 1920 | B = rand(1000,1) + rand(1000,1)*1i; 1921 | maxdiffCN('Matrix'' * Vector ',A,B,r); 1922 | 1923 | r = r + 1; 1924 | A = rand(1000,1000) + rand(1000,1000)*1i; 1925 | B = rand(1000,1000) + rand(1000,1000)*1i; 1926 | maxdiffCN('Matrix'' * Matrix ',A,B,r); 1927 | 1928 | running_time(datenum(clock) - start_time); 1929 | 1930 | %-------------------------------------------------------------------------- 1931 | %-------------------------------------------------------------------------- 1932 | 1933 | %end % debug jump 1934 | 1935 | disp('----------------------------------'); 1936 | disp(' '); 1937 | disp('Numerical Comparison Tests ...'); 1938 | disp(' '); 1939 | disp('(real)'' * (real).'''); 1940 | disp(' '); 1941 | 1942 | if( isequal([]'*[]',mtimesx([],'C',[],'C')) ) 1943 | disp('Empty'' * Empty.'' EQUAL'); 1944 | else 1945 | disp('Empty'' * Empty.'' NOT EQUAL <---'); 1946 | end 1947 | 1948 | r = r + 1; 1949 | mtimesx_dtable(r,:) = RC; 1950 | 1951 | rsave = r; 1952 | 1953 | r = r + 1; 1954 | A = rand(1,1); 1955 | B = rand(10000,1); 1956 | maxdiffCT('Scalar'' * Vector.'' ',A,B,r); 1957 | 1958 | r = r + 1; 1959 | A = rand(10000,1); 1960 | B = rand(1,1); 1961 | maxdiffCT('Vector'' * Scalar.'' ',A,B,r); 1962 | 1963 | r = r + 1; 1964 | A = rand(10000000,1); 1965 | B = rand(1,10000000); 1966 | maxdiffCT('Vector'' i Vector.'' ',A,B,r); 1967 | 1968 | r = r + 1; 1969 | A = rand(1,2500); 1970 | B = rand(2500,1); 1971 | maxdiffCT('Vector'' o Vector.'' ',A,B,r); 1972 | 1973 | r = r + 1; 1974 | A = rand(1000,1); 1975 | B = rand(1000,1000); 1976 | maxdiffCT('Vector'' * Matrix.'' ',A,B,r); 1977 | 1978 | r = r + 1; 1979 | A = rand(1000,1000); 1980 | B = rand(1,1000); 1981 | maxdiffCT('Matrix'' * Vector.'' ',A,B,r); 1982 | 1983 | r = r + 1; 1984 | A = rand(1000,1000); 1985 | B = rand(1000,1000); 1986 | maxdiffCT('Matrix'' * Matrix.'' ',A,B,r); 1987 | 1988 | %-------------------------------------------------------------------------- 1989 | disp(' '); 1990 | disp('(real)'' * (complex).'''); 1991 | disp(' '); 1992 | 1993 | r = rsave; 1994 | 1995 | r = r + 1; 1996 | A = rand(1,1); 1997 | B = rand(1,10000) + rand(1,10000)*1i; 1998 | maxdiffCT('Scalar'' * Vector.'' ',A,B,r); 1999 | 2000 | r = r + 1; 2001 | A = rand(10000,1); 2002 | B = rand(1,1) + rand(1,1)*1i; 2003 | maxdiffCT('Vector'' * Scalar.'' ',A,B,r); 2004 | 2005 | r = r + 1; 2006 | A = rand(10000000,1); 2007 | B = rand(1,10000000) + rand(1,10000000)*1i; 2008 | maxdiffCT('Vector'' i Vector.'' ',A,B,r); 2009 | 2010 | r = r + 1; 2011 | A = rand(1,2500); 2012 | B = rand(2500,1) + rand(2500,1)*1i; 2013 | maxdiffCT('Vector'' o Vector.'' ',A,B,r); 2014 | 2015 | r = r + 1; 2016 | A = rand(1000,1); 2017 | B = rand(1000,1000) + rand(1000,1000)*1i; 2018 | maxdiffCT('Vector'' * Matrix.'' ',A,B,r); 2019 | 2020 | r = r + 1; 2021 | A = rand(1000,1000); 2022 | B = rand(1,1000) + rand(1,1000)*1i; 2023 | maxdiffCT('Matrix'' * Vector.'' ',A,B,r); 2024 | 2025 | r = r + 1; 2026 | A = rand(1000,1000); 2027 | B = rand(1000,1000) + rand(1000,1000)*1i; 2028 | maxdiffCT('Matrix'' * Matrix.'' ',A,B,r); 2029 | 2030 | %-------------------------------------------------------------------------- 2031 | disp(' '); 2032 | disp('(complex)'' * (real).'''); 2033 | disp(' '); 2034 | 2035 | r = rsave; 2036 | 2037 | r = r + 1; 2038 | A = rand(1,1) + rand(1,1)*1i; 2039 | B = rand(1,10000); 2040 | maxdiffCT('Scalar'' * Vector.'' ',A,B,r); 2041 | 2042 | r = r + 1; 2043 | A = rand(10000,1)+ rand(10000,1)*1i; 2044 | B = rand(1,1); 2045 | maxdiffCT('Vector'' * Scalar.'' ',A,B,r); 2046 | 2047 | r = r + 1; 2048 | A = rand(10000000,1) + rand(10000000,1)*1i; 2049 | B = rand(1,10000000); 2050 | maxdiffCT('Vector'' i Vector.'' ',A,B,r); 2051 | 2052 | r = r + 1; 2053 | A = rand(1,2500) + rand(1,2500)*1i; 2054 | B = rand(2500,1); 2055 | maxdiffCT('Vector'' o Vector.'' ',A,B,r); 2056 | 2057 | r = r + 1; 2058 | A = rand(1000,1) + rand(1000,1)*1i; 2059 | B = rand(1000,1000); 2060 | maxdiffCT('Vector'' * Matrix.'' ',A,B,r); 2061 | 2062 | r = r + 1; 2063 | A = rand(1000,1000) + rand(1000,1000)*1i; 2064 | B = rand(1,1000); 2065 | maxdiffCT('Matrix'' * Vector.'' ',A,B,r); 2066 | 2067 | r = r + 1; 2068 | A = rand(1000,1000) + rand(1000,1000)*1i; 2069 | B = rand(1000,1000); 2070 | maxdiffCT('Matrix'' * Matrix.'' ',A,B,r); 2071 | 2072 | %-------------------------------------------------------------------------- 2073 | disp(' '); 2074 | disp('(complex)'' * (complex).'''); 2075 | disp(' '); 2076 | 2077 | r = rsave; 2078 | 2079 | r = r + 1; 2080 | A = rand(1,1) + rand(1,1)*1i; 2081 | B = rand(1,10000) + rand(1,10000)*1i; 2082 | maxdiffCT('Scalar'' * Vector.'' ',A,B,r); 2083 | 2084 | r = r + 1; 2085 | A = rand(10000,1)+ rand(10000,1)*1i; 2086 | B = rand(1,1) + rand(1,1)*1i; 2087 | maxdiffCT('Vector'' * Scalar.'' ',A,B,r); 2088 | 2089 | r = r + 1; 2090 | A = rand(10000000,1) + rand(10000000,1)*1i; 2091 | B = rand(1,10000000) + rand(1,10000000)*1i; 2092 | maxdiffCT('Vector'' i Vector.'' ',A,B,r); 2093 | 2094 | r = r + 1; 2095 | A = rand(1,2500) + rand(1,2500)*1i; 2096 | B = rand(2500,1) + rand(2500,1)*1i; 2097 | maxdiffCT('Vector'' o Vector.'' ',A,B,r); 2098 | 2099 | r = r + 1; 2100 | A = rand(1000,1) + rand(1000,1)*1i; 2101 | B = rand(1000,1000) + rand(1000,1000)*1i; 2102 | maxdiffCT('Vector'' * Matrix.'' ',A,B,r); 2103 | 2104 | r = r + 1; 2105 | A = rand(1000,1000) + rand(1000,1000)*1i; 2106 | B = rand(1,1000) + rand(1,1000)*1i; 2107 | maxdiffCT('Matrix'' * Vector.'' ',A,B,r); 2108 | 2109 | r = r + 1; 2110 | A = rand(1000,1000) + rand(1000,1000)*1i; 2111 | B = rand(1000,1000) + rand(1000,1000)*1i; 2112 | maxdiffCT('Matrix'' * Matrix.'' ',A,B,r); 2113 | 2114 | running_time(datenum(clock) - start_time); 2115 | 2116 | %-------------------------------------------------------------------------- 2117 | %-------------------------------------------------------------------------- 2118 | 2119 | %end % debug jump 2120 | 2121 | disp('----------------------------------'); 2122 | disp(' '); 2123 | disp('Numerical Comparison Tests ...'); 2124 | disp(' '); 2125 | disp('(real)'' * (real)'''); 2126 | disp(' '); 2127 | 2128 | if( isequal([]'*[]',mtimesx([],'C',[],'C')) ) 2129 | disp('Empty'' * Empty'' EQUAL'); 2130 | else 2131 | disp('Empty'' * Empty'' NOT EQUAL <---'); 2132 | end 2133 | 2134 | r = r + 1; 2135 | mtimesx_dtable(r,:) = RC; 2136 | 2137 | rsave = r; 2138 | 2139 | r = r + 1; 2140 | A = rand(1,1); 2141 | B = rand(10000,1); 2142 | maxdiffCC('Scalar'' * Vector'' ',A,B,r); 2143 | 2144 | r = r + 1; 2145 | A = rand(10000,1); 2146 | B = rand(1,1); 2147 | maxdiffCC('Vector'' * Scalar'' ',A,B,r); 2148 | 2149 | r = r + 1; 2150 | A = rand(10000000,1); 2151 | B = rand(1,10000000); 2152 | maxdiffCC('Vector'' i Vector'' ',A,B,r); 2153 | 2154 | r = r + 1; 2155 | A = rand(1,2500); 2156 | B = rand(2500,1); 2157 | maxdiffCC('Vector'' o Vector'' ',A,B,r); 2158 | 2159 | r = r + 1; 2160 | A = rand(1000,1); 2161 | B = rand(1000,1000); 2162 | maxdiffCC('Vector'' * Matrix'' ',A,B,r); 2163 | 2164 | r = r + 1; 2165 | A = rand(1000,1000); 2166 | B = rand(1,1000); 2167 | maxdiffCC('Matrix'' * Vector'' ',A,B,r); 2168 | 2169 | r = r + 1; 2170 | A = rand(1000,1000); 2171 | B = rand(1000,1000); 2172 | maxdiffCC('Matrix'' * Matrix'' ',A,B,r); 2173 | 2174 | %-------------------------------------------------------------------------- 2175 | disp(' '); 2176 | disp('(real)'' * (complex)'''); 2177 | disp(' '); 2178 | 2179 | r = rsave; 2180 | 2181 | r = r + 1; 2182 | A = rand(1,1); 2183 | B = rand(1,10000) + rand(1,10000)*1i; 2184 | maxdiffCC('Scalar'' * Vector'' ',A,B,r); 2185 | 2186 | r = r + 1; 2187 | A = rand(10000,1); 2188 | B = rand(1,1) + rand(1,1)*1i; 2189 | maxdiffCC('Vector'' * Scalar'' ',A,B,r); 2190 | 2191 | r = r + 1; 2192 | A = rand(10000000,1); 2193 | B = rand(1,10000000) + rand(1,10000000)*1i; 2194 | maxdiffCC('Vector'' i Vector'' ',A,B,r); 2195 | 2196 | r = r + 1; 2197 | A = rand(1,2500); 2198 | B = rand(2500,1) + rand(2500,1)*1i; 2199 | maxdiffCC('Vector'' o Vector'' ',A,B,r); 2200 | 2201 | r = r + 1; 2202 | A = rand(1000,1); 2203 | B = rand(1000,1000) + rand(1000,1000)*1i; 2204 | maxdiffCC('Vector'' * Matrix'' ',A,B,r); 2205 | 2206 | r = r + 1; 2207 | A = rand(1000,1000); 2208 | B = rand(1,1000) + rand(1,1000)*1i; 2209 | maxdiffCC('Matrix'' * Vector'' ',A,B,r); 2210 | 2211 | r = r + 1; 2212 | A = rand(1000,1000); 2213 | B = rand(1000,1000) + rand(1000,1000)*1i; 2214 | maxdiffCC('Matrix'' * Matrix'' ',A,B,r); 2215 | 2216 | %-------------------------------------------------------------------------- 2217 | disp(' '); 2218 | disp('(complex)'' * (real)'''); 2219 | disp(' '); 2220 | 2221 | r = rsave; 2222 | 2223 | r = r + 1; 2224 | A = rand(1,1) + rand(1,1)*1i; 2225 | B = rand(1,10000); 2226 | maxdiffCC('Scalar'' * Vector'' ',A,B,r); 2227 | 2228 | r = r + 1; 2229 | A = rand(10000,1)+ rand(10000,1)*1i; 2230 | B = rand(1,1); 2231 | maxdiffCC('Vector'' * Scalar'' ',A,B,r); 2232 | 2233 | r = r + 1; 2234 | A = rand(10000000,1) + rand(10000000,1)*1i; 2235 | B = rand(1,10000000); 2236 | maxdiffCC('Vector'' i Vector'' ',A,B,r); 2237 | 2238 | r = r + 1; 2239 | A = rand(1,2500) + rand(1,2500)*1i; 2240 | B = rand(2500,1); 2241 | maxdiffCC('Vector'' o Vector'' ',A,B,r); 2242 | 2243 | r = r + 1; 2244 | A = rand(1000,1) + rand(1000,1)*1i; 2245 | B = rand(1000,1000); 2246 | maxdiffCC('Vector'' * Matrix'' ',A,B,r); 2247 | 2248 | r = r + 1; 2249 | A = rand(1000,1000) + rand(1000,1000)*1i; 2250 | B = rand(1,1000); 2251 | maxdiffCC('Matrix'' * Vector'' ',A,B,r); 2252 | 2253 | r = r + 1; 2254 | A = rand(1000,1000) + rand(1000,1000)*1i; 2255 | B = rand(1000,1000); 2256 | maxdiffCC('Matrix'' * Matrix'' ',A,B,r); 2257 | 2258 | %-------------------------------------------------------------------------- 2259 | disp(' '); 2260 | disp('(complex)'' * (complex)'''); 2261 | disp(' '); 2262 | 2263 | r = rsave; 2264 | 2265 | r = r + 1; 2266 | A = rand(1,1) + rand(1,1)*1i; 2267 | B = rand(1,10000) + rand(1,10000)*1i; 2268 | maxdiffCC('Scalar'' * Vector'' ',A,B,r); 2269 | 2270 | r = r + 1; 2271 | A = rand(10000,1)+ rand(10000,1)*1i; 2272 | B = rand(1,1) + rand(1,1)*1i; 2273 | maxdiffCC('Vector'' * Scalar'' ',A,B,r); 2274 | 2275 | r = r + 1; 2276 | A = rand(10000000,1) + rand(10000000,1)*1i; 2277 | B = rand(1,10000000) + rand(1,10000000)*1i; 2278 | maxdiffCC('Vector'' i Vector'' ',A,B,r); 2279 | 2280 | r = r + 1; 2281 | A = rand(1,2500) + rand(1,2500)*1i; 2282 | B = rand(2500,1) + rand(2500,1)*1i; 2283 | maxdiffCC('Vector'' o Vector'' ',A,B,r); 2284 | 2285 | r = r + 1; 2286 | A = rand(1000,1) + rand(1000,1)*1i; 2287 | B = rand(1000,1000) + rand(1000,1000)*1i; 2288 | maxdiffCC('Vector'' * Matrix'' ',A,B,r); 2289 | 2290 | r = r + 1; 2291 | A = rand(1000,1000) + rand(1000,1000)*1i; 2292 | B = rand(1,1000) + rand(1,1000)*1i; 2293 | maxdiffCC('Matrix'' * Vector'' ',A,B,r); 2294 | 2295 | r = r + 1; 2296 | A = rand(1000,1000) + rand(1000,1000)*1i; 2297 | B = rand(1000,1000) + rand(1000,1000)*1i; 2298 | maxdiffCC('Matrix'' * Matrix'' ',A,B,r); 2299 | 2300 | running_time(datenum(clock) - start_time); 2301 | 2302 | %-------------------------------------------------------------------------- 2303 | %-------------------------------------------------------------------------- 2304 | 2305 | disp('----------------------------------'); 2306 | disp(' '); 2307 | disp('Numerical Comparison Tests ...'); 2308 | disp(' '); 2309 | disp('(real)'' * conj(real)'); 2310 | disp(' '); 2311 | 2312 | if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) ) 2313 | disp('Empty'' * conj(Empty) EQUAL'); 2314 | else 2315 | disp('Empty'' * conj(Empty) NOT EQUAL <---'); 2316 | end 2317 | 2318 | r = r + 1; 2319 | mtimesx_dtable(r,:) = RC; 2320 | 2321 | rsave = r; 2322 | 2323 | r = r + 1; 2324 | A = rand(1,1); 2325 | B = rand(1,10000); 2326 | maxdiffCG('Scalar'' * conj(Vector) ',A,B,r); 2327 | 2328 | r = r + 1; 2329 | A = rand(10000,1); 2330 | B = rand(1,1); 2331 | maxdiffCG('Vector'' * conj(Scalar) ',A,B,r); 2332 | 2333 | r = r + 1; 2334 | A = rand(1,1); 2335 | B = rand(10,20,30,40); 2336 | maxdiffCG('Scalar'' * conj(Array) ',A,B,r); 2337 | 2338 | r = r + 1; 2339 | A = rand(10000000,1); 2340 | B = rand(10000000,1); 2341 | maxdiffCG('Vector'' i conj(Vector) ',A,B,r); 2342 | 2343 | r = r + 1; 2344 | A = rand(1,2500); 2345 | B = rand(1,2500); 2346 | maxdiffCG('Vector'' o conj(Vector) ',A,B,r); 2347 | 2348 | r = r + 1; 2349 | A = rand(1000,1); 2350 | B = rand(1000,1000); 2351 | maxdiffCG('Vector'' * conj(Matrix) ',A,B,r); 2352 | 2353 | r = r + 1; 2354 | A = rand(1000,1000); 2355 | B = rand(1000,1); 2356 | maxdiffCG('Matrix'' * conj(Vector) ',A,B,r); 2357 | 2358 | r = r + 1; 2359 | A = rand(1000,1000); 2360 | B = rand(1000,1000); 2361 | maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r); 2362 | 2363 | %-------------------------------------------------------------------------- 2364 | disp(' '); 2365 | disp('(real)'' * conj(complex)'); 2366 | disp(' '); 2367 | 2368 | r = rsave; 2369 | 2370 | r = r + 1; 2371 | A = rand(1,1); 2372 | B = rand(1,10000) + rand(1,10000)*1i; 2373 | maxdiffCG('Scalar'' * conj(Vector) ',A,B,r); 2374 | 2375 | r = r + 1; 2376 | A = rand(10000,1); 2377 | B = rand(1,1) + rand(1,1)*1i; 2378 | maxdiffCG('Vector'' * conj(Scalar) ',A,B,r); 2379 | 2380 | r = r + 1; 2381 | A = rand(1,1); 2382 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 2383 | maxdiffCG('Scalar'' * conj(Array) ',A,B,r); 2384 | 2385 | r = r + 1; 2386 | A = rand(10000000,1); 2387 | B = rand(10000000,1) + rand(10000000,1)*1i; 2388 | maxdiffCG('Vector'' i conj(Vector) ',A,B,r); 2389 | 2390 | r = r + 1; 2391 | A = rand(1,2500); 2392 | B = rand(1,2500) + rand(1,2500)*1i; 2393 | maxdiffCG('Vector'' o conj(Vector) ',A,B,r); 2394 | 2395 | r = r + 1; 2396 | A = rand(1000,1); 2397 | B = rand(1000,1000) + rand(1000,1000)*1i; 2398 | maxdiffCG('Vector'' * conj(Matrix) ',A,B,r); 2399 | 2400 | r = r + 1; 2401 | A = rand(1000,1000); 2402 | B = rand(1000,1) + rand(1000,1)*1i; 2403 | maxdiffCG('Matrix'' * conj(Vector) ',A,B,r); 2404 | 2405 | r = r + 1; 2406 | A = rand(1000,1000); 2407 | B = rand(1000,1000) + rand(1000,1000)*1i; 2408 | maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r); 2409 | 2410 | %-------------------------------------------------------------------------- 2411 | disp(' '); 2412 | disp('(complex)'' * conj(real)'); 2413 | disp(' '); 2414 | 2415 | r = rsave; 2416 | 2417 | r = r + 1; 2418 | A = rand(1,1) + rand(1,1)*1i; 2419 | B = rand(1,10000); 2420 | maxdiffCG('Scalar'' * conj(Vector) ',A,B,r); 2421 | 2422 | r = r + 1; 2423 | A = rand(10000,1)+ rand(10000,1)*1i; 2424 | B = rand(1,1); 2425 | maxdiffCG('Vector'' * conj(Scalar) ',A,B,r); 2426 | 2427 | r = r + 1; 2428 | A = rand(1,1) + rand(1,1)*1i; 2429 | B = rand(10,20,30,40); 2430 | maxdiffCG('Scalar'' * conj(Array) ',A,B,r); 2431 | 2432 | r = r + 1; 2433 | A = rand(10000000,1) + rand(10000000,1)*1i; 2434 | B = rand(10000000,1); 2435 | maxdiffCG('Vector'' i conj(Vector) ',A,B,r); 2436 | 2437 | r = r + 1; 2438 | A = rand(1,2500) + rand(1,2500)*1i; 2439 | B = rand(1,2500); 2440 | maxdiffCG('Vector'' o conj(Vector) ',A,B,r); 2441 | 2442 | r = r + 1; 2443 | A = rand(1000,1) + rand(1000,1)*1i; 2444 | B = rand(1000,1000); 2445 | maxdiffCG('Vector'' * conj(Matrix) ',A,B,r); 2446 | 2447 | r = r + 1; 2448 | A = rand(1000,1000) + rand(1000,1000)*1i; 2449 | B = rand(1000,1); 2450 | maxdiffCG('Matrix'' * conj(Vector) ',A,B,r); 2451 | 2452 | r = r + 1; 2453 | A = rand(1000,1000) + rand(1000,1000)*1i; 2454 | B = rand(1000,1000); 2455 | maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r); 2456 | 2457 | %-------------------------------------------------------------------------- 2458 | disp(' '); 2459 | disp('(complex)'' * conj(complex)'); 2460 | disp(' '); 2461 | 2462 | r = rsave; 2463 | 2464 | r = r + 1; 2465 | A = rand(1,1) + rand(1,1)*1i; 2466 | B = rand(1,10000) + rand(1,10000)*1i; 2467 | maxdiffCG('Scalar'' * conj(Vector) ',A,B,r); 2468 | 2469 | r = r + 1; 2470 | A = rand(10000,1)+ rand(10000,1)*1i; 2471 | B = rand(1,1) + rand(1,1)*1i; 2472 | maxdiffCG('Vector'' * conj(Scalar) ',A,B,r); 2473 | 2474 | r = r + 1; 2475 | A = rand(1,1) + rand(1,1)*1i; 2476 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 2477 | maxdiffCG('Scalar'' * conj(Array) ',A,B,r); 2478 | 2479 | r = r + 1; 2480 | A = rand(10000000,1) + rand(10000000,1)*1i; 2481 | B = rand(10000000,1) + rand(10000000,1)*1i; 2482 | maxdiffCG('Vector'' i conj(Vector) ',A,B,r); 2483 | 2484 | r = r + 1; 2485 | A = rand(1,2500) + rand(1,2500)*1i; 2486 | B = rand(1,2500) + rand(1,2500)*1i; 2487 | maxdiffCG('Vector'' o conj(Vector) ',A,B,r); 2488 | 2489 | r = r + 1; 2490 | A = rand(1000,1) + rand(1000,1)*1i; 2491 | B = rand(1000,1000) + rand(1000,1000)*1i; 2492 | maxdiffCG('Vector'' * conj(Matrix) ',A,B,r); 2493 | 2494 | r = r + 1; 2495 | A = rand(1000,1000) + rand(1000,1000)*1i; 2496 | B = rand(1000,1) + rand(1000,1)*1i; 2497 | maxdiffCG('Matrix'' * conj(Vector) ',A,B,r); 2498 | 2499 | r = r + 1; 2500 | A = rand(1000,1000) + rand(1000,1000)*1i; 2501 | B = rand(1000,1000) + rand(1000,1000)*1i; 2502 | maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r); 2503 | 2504 | running_time(datenum(clock) - start_time); 2505 | 2506 | %-------------------------------------------------------------------------- 2507 | %-------------------------------------------------------------------------- 2508 | 2509 | %end % debug jump 2510 | 2511 | disp(' '); 2512 | disp('Numerical Comparison Tests ...'); 2513 | disp(' '); 2514 | disp('conj(real) * (real)'); 2515 | disp(' '); 2516 | 2517 | if( isequal(conj([])*[],mtimesx([],'G',[])) ) 2518 | disp('conj(Empty) * Empty EQUAL'); 2519 | else 2520 | disp('conj(Empty) * Empty NOT EQUAL <---'); 2521 | end 2522 | 2523 | r = r + 1; 2524 | mtimesx_dtable(r,:) = RC; 2525 | 2526 | r = rsave; 2527 | 2528 | r = r + 1; 2529 | A = rand(1,1); 2530 | B = rand(1,10000); 2531 | maxdiffGN('conj(Scalar) * Vector ',A,B,r); 2532 | 2533 | r = r + 1; 2534 | A = rand(1,10000); 2535 | B = rand(1,1); 2536 | maxdiffGN('conj(Vector) * Scalar ',A,B,r); 2537 | 2538 | r = r + 1; 2539 | A = rand(1,1); 2540 | B = rand(10,20,30,40); 2541 | maxdiffGN('conj(Scalar) * Array ',A,B,r); 2542 | 2543 | r = r + 1; 2544 | A = rand(10,20,30,40); 2545 | B = rand(1,1); 2546 | maxdiffGN('conj(Array) * Scalar ',A,B,r); 2547 | 2548 | r = r + 1; 2549 | A = rand(1,10000000); 2550 | B = rand(10000000,1); 2551 | maxdiffGN('conj(Vector) i Vector ',A,B,r); 2552 | 2553 | r = r + 1; 2554 | A = rand(2500,1); 2555 | B = rand(1,2500); 2556 | maxdiffGN('conj(Vector) o Vector ',A,B,r); 2557 | 2558 | r = r + 1; 2559 | A = rand(1,1000); 2560 | B = rand(1000,1000); 2561 | maxdiffGN('conj(Vector) * Matrix ',A,B,r); 2562 | 2563 | r = r + 1; 2564 | A = rand(1000,1000); 2565 | B = rand(1000,1); 2566 | maxdiffGN('conj(Matrix) * Vector ',A,B,r); 2567 | 2568 | r = r + 1; 2569 | A = rand(1000,1000); 2570 | B = rand(1000,1000); 2571 | maxdiffGN('conj(Matrix) * Matrix ',A,B,r); 2572 | 2573 | %-------------------------------------------------------------------------- 2574 | disp(' '); 2575 | disp('conj(real) * (complex)'); 2576 | disp(' '); 2577 | 2578 | r = rsave; 2579 | 2580 | r = r + 1; 2581 | A = rand(1,1); 2582 | B = rand(1,10000) + rand(1,10000)*1i; 2583 | maxdiffGN('conj(Scalar) * Vector ',A,B,r); 2584 | 2585 | r = r + 1; 2586 | A = rand(1,10000); 2587 | B = rand(1,1) + rand(1,1)*1i; 2588 | maxdiffGN('conj(Vector) * Scalar ',A,B,r); 2589 | 2590 | r = r + 1; 2591 | A = rand(1,1); 2592 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 2593 | maxdiffGN('conj(Scalar) * Array ',A,B,r); 2594 | 2595 | r = r + 1; 2596 | A = rand(10,20,30,40); 2597 | B = rand(1,1) + rand(1,1)*1i; 2598 | maxdiffGN('conj(Array) * Scalar ',A,B,r); 2599 | 2600 | r = r + 1; 2601 | A = rand(1,10000000); 2602 | B = rand(10000000,1) + rand(10000000,1)*1i; 2603 | maxdiffGN('conj(Vector) i Vector ',A,B,r); 2604 | 2605 | r = r + 1; 2606 | A = rand(2500,1); 2607 | B = rand(1,2500) + rand(1,2500)*1i; 2608 | maxdiffGN('conj(Vector) o Vector ',A,B,r); 2609 | 2610 | r = r + 1; 2611 | A = rand(1,1000); 2612 | B = rand(1000,1000) + rand(1000,1000)*1i; 2613 | maxdiffGN('conj(Vector) * Matrix ',A,B,r); 2614 | 2615 | r = r + 1; 2616 | A = rand(1000,1000); 2617 | B = rand(1000,1) + rand(1000,1)*1i; 2618 | maxdiffGN('conj(Matrix) * Vector ',A,B,r); 2619 | 2620 | r = r + 1; 2621 | A = rand(1000,1000); 2622 | B = rand(1000,1000) + rand(1000,1000)*1i; 2623 | maxdiffGN('conj(Matrix) * Matrix ',A,B,r); 2624 | 2625 | %-------------------------------------------------------------------------- 2626 | disp(' '); 2627 | disp('conj(complex)* (real)'); 2628 | disp(' '); 2629 | 2630 | r = rsave; 2631 | 2632 | r = r + 1; 2633 | A = rand(1,1) + rand(1,1)*1i; 2634 | B = rand(1,10000); 2635 | maxdiffGN('conj(Scalar) * Vector ',A,B,r); 2636 | 2637 | r = r + 1; 2638 | A = rand(1,10000)+ rand(1,10000)*1i; 2639 | B = rand(1,1); 2640 | maxdiffGN('conj(Vector) * Scalar ',A,B,r); 2641 | 2642 | r = r + 1; 2643 | A = rand(1,1) + rand(1,1)*1i; 2644 | B = rand(10,20,30,40); 2645 | maxdiffGN('conj(Scalar) * Array ',A,B,r); 2646 | 2647 | r = r + 1; 2648 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 2649 | B = rand(1,1); 2650 | maxdiffGN('conj(Array) * Scalar ',A,B,r); 2651 | 2652 | r = r + 1; 2653 | A = rand(1,10000000) + rand(1,10000000)*1i; 2654 | B = rand(10000000,1); 2655 | maxdiffGN('conj(Vector) i Vector ',A,B,r); 2656 | 2657 | r = r + 1; 2658 | A = rand(2500,1) + rand(2500,1)*1i; 2659 | B = rand(1,2500); 2660 | maxdiffGN('conj(Vector) o Vector ',A,B,r); 2661 | 2662 | r = r + 1; 2663 | A = rand(1,1000) + rand(1,1000)*1i; 2664 | B = rand(1000,1000); 2665 | maxdiffGN('conj(Vector) * Matrix ',A,B,r); 2666 | 2667 | r = r + 1; 2668 | A = rand(1000,1000) + rand(1000,1000)*1i; 2669 | B = rand(1000,1); 2670 | maxdiffGN('conj(Matrix) * Vector ',A,B,r); 2671 | 2672 | r = r + 1; 2673 | A = rand(1000,1000) + rand(1000,1000)*1i; 2674 | B = rand(1000,1000); 2675 | maxdiffGN('conj(Matrix) * Matrix ',A,B,r); 2676 | 2677 | %-------------------------------------------------------------------------- 2678 | disp(' '); 2679 | disp('conj(complex)* (complex)'); 2680 | disp(' '); 2681 | 2682 | r = rsave; 2683 | 2684 | r = r + 1; 2685 | A = rand(1,1) + rand(1,1)*1i; 2686 | B = rand(1,10000) + rand(1,10000)*1i; 2687 | maxdiffGN('conj(Scalar) * Vector ',A,B,r); 2688 | 2689 | r = r + 1; 2690 | A = rand(1,10000)+ rand(1,10000)*1i; 2691 | B = rand(1,1) + rand(1,1)*1i; 2692 | maxdiffGN('conj(Vector) * Scalar ',A,B,r); 2693 | 2694 | r = r + 1; 2695 | A = rand(1,1) + rand(1,1)*1i; 2696 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 2697 | maxdiffGN('conj(Scalar) * Array ',A,B,r); 2698 | 2699 | r = r + 1; 2700 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 2701 | B = rand(1,1) + rand(1,1)*1i; 2702 | maxdiffGN('conj(Array) * Scalar ',A,B,r); 2703 | 2704 | r = r + 1; 2705 | A = rand(1,10000000) + rand(1,10000000)*1i; 2706 | B = rand(10000000,1) + rand(10000000,1)*1i; 2707 | maxdiffGN('conj(Vector) i Vector ',A,B,r); 2708 | 2709 | r = r + 1; 2710 | A = rand(2500,1) + rand(2500,1)*1i; 2711 | B = rand(1,2500) + rand(1,2500)*1i; 2712 | maxdiffGN('conj(Vector) o Vector ',A,B,r); 2713 | 2714 | r = r + 1; 2715 | A = rand(1,1000) + rand(1,1000)*1i; 2716 | B = rand(1000,1000) + rand(1000,1000)*1i; 2717 | maxdiffGN('conj(Vector) * Matrix ',A,B,r); 2718 | 2719 | r = r + 1; 2720 | A = rand(1000,1000) + rand(1000,1000)*1i; 2721 | B = rand(1000,1) + rand(1000,1)*1i; 2722 | maxdiffGN('conj(Matrix) * Vector ',A,B,r); 2723 | 2724 | r = r + 1; 2725 | A = rand(1000,1000) + rand(1000,1000)*1i; 2726 | B = rand(1000,1000) + rand(1000,1000)*1i; 2727 | maxdiffGN('conj(Matrix) * Matrix ',A,B,r); 2728 | 2729 | running_time(datenum(clock) - start_time); 2730 | 2731 | %-------------------------------------------------------------------------- 2732 | %-------------------------------------------------------------------------- 2733 | 2734 | %end % debug jump 2735 | 2736 | disp('----------------------------------'); 2737 | disp(' '); 2738 | disp('Numerical Comparison Tests ...'); 2739 | disp(' '); 2740 | disp('conj(real) * (real).'''); 2741 | disp(' '); 2742 | 2743 | if( isequal(conj([])*[].',mtimesx([],'G',[],'T')) ) 2744 | disp('conj(Empty) * Empty.'' EQUAL'); 2745 | else 2746 | disp('conj(Empty) * Empty.'' NOT EQUAL <---'); 2747 | end 2748 | 2749 | r = r + 1; 2750 | mtimesx_dtable(r,:) = RC; 2751 | 2752 | rsave = r; 2753 | 2754 | r = r + 1; 2755 | A = rand(1,1); 2756 | B = rand(10000,1); 2757 | maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r); 2758 | 2759 | r = r + 1; 2760 | A = rand(10000,1); 2761 | B = rand(1,1); 2762 | maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r); 2763 | 2764 | r = r + 1; 2765 | A = rand(10,20,30,40); 2766 | B = rand(1,1); 2767 | maxdiffGT('conj(Array) * Scalar.'' ',A,B,r); 2768 | 2769 | r = r + 1; 2770 | A = rand(1,10000000); 2771 | B = rand(1,10000000); 2772 | maxdiffGT('conj(Vector) i Vector.'' ',A,B,r); 2773 | 2774 | r = r + 1; 2775 | A = rand(2500,1); 2776 | B = rand(2500,1); 2777 | maxdiffGT('conj(Vector) o Vector.'' ',A,B,r); 2778 | 2779 | r = r + 1; 2780 | A = rand(1,1000); 2781 | B = rand(1000,1000); 2782 | maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r); 2783 | 2784 | r = r + 1; 2785 | A = rand(1000,1000); 2786 | B = rand(1,1000); 2787 | maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r); 2788 | 2789 | r = r + 1; 2790 | A = rand(1000,1000); 2791 | B = rand(1000,1000); 2792 | maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r); 2793 | 2794 | %-------------------------------------------------------------------------- 2795 | disp(' '); 2796 | disp('conj(real) * (complex).'''); 2797 | disp(' '); 2798 | 2799 | r = rsave; 2800 | 2801 | r = r + 1; 2802 | A = rand(1,1); 2803 | B = rand(1,10000) + rand(1,10000)*1i; 2804 | maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r); 2805 | 2806 | r = r + 1; 2807 | A = rand(10000,1); 2808 | B = rand(1,1) + rand(1,1)*1i; 2809 | maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r); 2810 | 2811 | r = r + 1; 2812 | A = rand(10,20,30,40); 2813 | B = rand(1,1) + rand(1,1)*1i; 2814 | maxdiffGT('conj(Array) * Scalar.'' ',A,B,r); 2815 | 2816 | r = r + 1; 2817 | A = rand(1,10000000); 2818 | B = rand(1,10000000) + rand(1,10000000)*1i; 2819 | maxdiffGT('conj(Vector) i Vector.'' ',A,B,r); 2820 | 2821 | r = r + 1; 2822 | A = rand(2500,1); 2823 | B = rand(2500,1) + rand(2500,1)*1i; 2824 | maxdiffGT('conj(Vector) o Vector.'' ',A,B,r); 2825 | 2826 | r = r + 1; 2827 | A = rand(1,1000); 2828 | B = rand(1000,1000) + rand(1000,1000)*1i; 2829 | maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r); 2830 | 2831 | r = r + 1; 2832 | A = rand(1000,1000); 2833 | B = rand(1,1000) + rand(1,1000)*1i; 2834 | maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r); 2835 | 2836 | r = r + 1; 2837 | A = rand(1000,1000); 2838 | B = rand(1000,1000) + rand(1000,1000)*1i; 2839 | maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r); 2840 | 2841 | %-------------------------------------------------------------------------- 2842 | disp(' '); 2843 | disp('conj(complex) * (real).'''); 2844 | disp(' '); 2845 | 2846 | r = rsave; 2847 | 2848 | r = r + 1; 2849 | A = rand(1,1) + rand(1,1)*1i; 2850 | B = rand(1,10000); 2851 | maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r); 2852 | 2853 | r = r + 1; 2854 | A = rand(10000,1)+ rand(10000,1)*1i; 2855 | B = rand(1,1); 2856 | maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r); 2857 | 2858 | r = r + 1; 2859 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 2860 | B = rand(1,1); 2861 | maxdiffGT('conj(Array) * Scalar.'' ',A,B,r); 2862 | 2863 | r = r + 1; 2864 | A = rand(1,10000000) + rand(1,10000000)*1i; 2865 | B = rand(1,10000000); 2866 | maxdiffGT('conj(Vector) i Vector.'' ',A,B,r); 2867 | 2868 | r = r + 1; 2869 | A = rand(2500,1) + rand(2500,1)*1i; 2870 | B = rand(2500,1); 2871 | maxdiffGT('conj(Vector) o Vector.'' ',A,B,r); 2872 | 2873 | r = r + 1; 2874 | A = rand(1,1000) + rand(1,1000)*1i; 2875 | B = rand(1000,1000); 2876 | maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r); 2877 | 2878 | r = r + 1; 2879 | A = rand(1000,1000) + rand(1000,1000)*1i; 2880 | B = rand(1,1000); 2881 | maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r); 2882 | 2883 | r = r + 1; 2884 | A = rand(1000,1000) + rand(1000,1000)*1i; 2885 | B = rand(1000,1000); 2886 | maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r); 2887 | 2888 | %-------------------------------------------------------------------------- 2889 | disp(' '); 2890 | disp('conj(complex) * (complex).'''); 2891 | disp(' '); 2892 | 2893 | r = rsave; 2894 | 2895 | r = r + 1; 2896 | A = rand(1,1) + rand(1,1)*1i; 2897 | B = rand(1,10000) + rand(1,10000)*1i; 2898 | maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r); 2899 | 2900 | r = r + 1; 2901 | A = rand(10000,1)+ rand(10000,1)*1i; 2902 | B = rand(1,1) + rand(1,1)*1i; 2903 | maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r); 2904 | 2905 | r = r + 1; 2906 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 2907 | B = rand(1,1) + rand(1,1)*1i; 2908 | maxdiffGT('conj(Array) * Scalar.'' ',A,B,r); 2909 | 2910 | r = r + 1; 2911 | A = rand(1,10000000) + rand(1,10000000)*1i; 2912 | B = rand(1,10000000) + rand(1,10000000)*1i; 2913 | maxdiffGT('conj(Vector) i Vector.'' ',A,B,r); 2914 | 2915 | r = r + 1; 2916 | A = rand(2500,1) + rand(2500,1)*1i; 2917 | B = rand(2500,1) + rand(2500,1)*1i; 2918 | maxdiffGT('conj(Vector) o Vector.'' ',A,B,r); 2919 | 2920 | r = r + 1; 2921 | A = rand(1,1000) + rand(1,1000)*1i; 2922 | B = rand(1000,1000) + rand(1000,1000)*1i; 2923 | maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r); 2924 | 2925 | r = r + 1; 2926 | A = rand(1000,1000) + rand(1000,1000)*1i; 2927 | B = rand(1,1000) + rand(1,1000)*1i; 2928 | maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r); 2929 | 2930 | r = r + 1; 2931 | A = rand(1000,1000) + rand(1000,1000)*1i; 2932 | B = rand(1000,1000) + rand(1000,1000)*1i; 2933 | maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r); 2934 | 2935 | running_time(datenum(clock) - start_time); 2936 | 2937 | %-------------------------------------------------------------------------- 2938 | %-------------------------------------------------------------------------- 2939 | 2940 | %end % debug jump 2941 | 2942 | disp('----------------------------------'); 2943 | disp(' '); 2944 | disp('Numerical Comparison Tests ...'); 2945 | disp(' '); 2946 | disp('conj(real) * (real)'''); 2947 | disp(' '); 2948 | 2949 | if( isequal(conj([])*[]',mtimesx([],'G',[],'C')) ) 2950 | disp('conj(Empty) * Empty'' EQUAL'); 2951 | else 2952 | disp('conj(Empty) * Empty'' NOT EQUAL <---'); 2953 | end 2954 | 2955 | r = r + 1; 2956 | mtimesx_dtable(r,:) = RC; 2957 | 2958 | rsave = r; 2959 | 2960 | r = r + 1; 2961 | A = rand(1,1); 2962 | B = rand(10000,1); 2963 | maxdiffGC('conj(Scalar) * Vector'' ',A,B,r); 2964 | 2965 | r = r + 1; 2966 | A = rand(10000,1); 2967 | B = rand(1,1); 2968 | maxdiffGC('conj(Vector) * Scalar'' ',A,B,r); 2969 | 2970 | r = r + 1; 2971 | A = rand(10,20,30,40); 2972 | B = rand(1,1); 2973 | maxdiffGC('conj(Array) * Scalar'' ',A,B,r); 2974 | 2975 | r = r + 1; 2976 | A = rand(1,10000000); 2977 | B = rand(1,10000000); 2978 | maxdiffGC('conj(Vector) i Vector'' ',A,B,r); 2979 | 2980 | r = r + 1; 2981 | A = rand(2500,1); 2982 | B = rand(2500,1); 2983 | maxdiffGC('conj(Vector) o Vector'' ',A,B,r); 2984 | 2985 | r = r + 1; 2986 | A = rand(1,1000); 2987 | B = rand(1000,1000); 2988 | maxdiffGC('conj(Vector) * Matrix'' ',A,B,r); 2989 | 2990 | r = r + 1; 2991 | A = rand(1000,1000); 2992 | B = rand(1,1000); 2993 | maxdiffGC('conj(Matrix) * Vector'' ',A,B,r); 2994 | 2995 | r = r + 1; 2996 | A = rand(1000,1000); 2997 | B = rand(1000,1000); 2998 | maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r); 2999 | 3000 | %-------------------------------------------------------------------------- 3001 | disp(' '); 3002 | disp('conj(real) * (complex)'''); 3003 | disp(' '); 3004 | 3005 | r = rsave; 3006 | 3007 | r = r + 1; 3008 | A = rand(1,1); 3009 | B = rand(1,10000) + rand(1,10000)*1i; 3010 | maxdiffGC('conj(Scalar) * Vector'' ',A,B,r); 3011 | 3012 | r = r + 1; 3013 | A = rand(10000,1); 3014 | B = rand(1,1) + rand(1,1)*1i; 3015 | maxdiffGC('conj(Vector) * Scalar'' ',A,B,r); 3016 | 3017 | r = r + 1; 3018 | A = rand(10,20,30,40); 3019 | B = rand(1,1) + rand(1,1)*1i; 3020 | maxdiffGC('conj(Array) * Scalar'' ',A,B,r); 3021 | 3022 | r = r + 1; 3023 | A = rand(1,10000000); 3024 | B = rand(1,10000000) + rand(1,10000000)*1i; 3025 | maxdiffGC('conj(Vector) i Vector'' ',A,B,r); 3026 | 3027 | r = r + 1; 3028 | A = rand(2500,1); 3029 | B = rand(2500,1) + rand(2500,1)*1i; 3030 | maxdiffGC('conj(Vector) o Vector'' ',A,B,r); 3031 | 3032 | r = r + 1; 3033 | A = rand(1,1000); 3034 | B = rand(1000,1000) + rand(1000,1000)*1i; 3035 | maxdiffGC('conj(Vector) * Matrix'' ',A,B,r); 3036 | 3037 | r = r + 1; 3038 | A = rand(1000,1000); 3039 | B = rand(1,1000) + rand(1,1000)*1i; 3040 | maxdiffGC('conj(Matrix) * Vector'' ',A,B,r); 3041 | 3042 | r = r + 1; 3043 | A = rand(1000,1000); 3044 | B = rand(1000,1000) + rand(1000,1000)*1i; 3045 | maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r); 3046 | 3047 | %-------------------------------------------------------------------------- 3048 | disp(' '); 3049 | disp('conj(complex) * (real)'''); 3050 | disp(' '); 3051 | 3052 | r = rsave; 3053 | 3054 | r = r + 1; 3055 | A = rand(1,1) + rand(1,1)*1i; 3056 | B = rand(1,10000); 3057 | maxdiffGC('conj(Scalar) * Vector'' ',A,B,r); 3058 | 3059 | r = r + 1; 3060 | A = rand(10000,1)+ rand(10000,1)*1i; 3061 | B = rand(1,1); 3062 | maxdiffGC('conj(Vector) * Scalar'' ',A,B,r); 3063 | 3064 | r = r + 1; 3065 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 3066 | B = rand(1,1); 3067 | maxdiffGC('conj(Array) * Scalar'' ',A,B,r); 3068 | 3069 | r = r + 1; 3070 | A = rand(1,10000000) + rand(1,10000000)*1i; 3071 | B = rand(1,10000000); 3072 | maxdiffGC('conj(Vector) i Vector'' ',A,B,r); 3073 | 3074 | r = r + 1; 3075 | A = rand(2500,1) + rand(2500,1)*1i; 3076 | B = rand(2500,1); 3077 | maxdiffGC('conj(Vector) o Vector'' ',A,B,r); 3078 | 3079 | r = r + 1; 3080 | A = rand(1,1000) + rand(1,1000)*1i; 3081 | B = rand(1000,1000); 3082 | maxdiffGC('conj(Vector) * Matrix'' ',A,B,r); 3083 | 3084 | r = r + 1; 3085 | A = rand(1000,1000) + rand(1000,1000)*1i; 3086 | B = rand(1,1000); 3087 | maxdiffGC('conj(Matrix) * Vector'' ',A,B,r); 3088 | 3089 | r = r + 1; 3090 | A = rand(1000,1000) + rand(1000,1000)*1i; 3091 | B = rand(1000,1000); 3092 | maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r); 3093 | 3094 | %-------------------------------------------------------------------------- 3095 | disp(' '); 3096 | disp('conj(complex) * (complex)'''); 3097 | disp(' '); 3098 | 3099 | r = rsave; 3100 | 3101 | r = r + 1; 3102 | A = rand(1,1) + rand(1,1)*1i; 3103 | B = rand(1,10000) + rand(1,10000)*1i; 3104 | maxdiffGC('conj(Scalar) * Vector'' ',A,B,r); 3105 | 3106 | r = r + 1; 3107 | A = rand(10000,1)+ rand(10000,1)*1i; 3108 | B = rand(1,1) + rand(1,1)*1i; 3109 | maxdiffGC('conj(Vector) * Scalar'' ',A,B,r); 3110 | 3111 | r = r + 1; 3112 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 3113 | B = rand(1,1) + rand(1,1)*1i; 3114 | maxdiffGC('conj(Array) * Scalar'' ',A,B,r); 3115 | 3116 | r = r + 1; 3117 | A = rand(1,10000000) + rand(1,10000000)*1i; 3118 | B = rand(1,10000000) + rand(1,10000000)*1i; 3119 | maxdiffGC('conj(Vector) i Vector'' ',A,B,r); 3120 | 3121 | r = r + 1; 3122 | A = rand(2500,1) + rand(2500,1)*1i; 3123 | B = rand(2500,1) + rand(2500,1)*1i; 3124 | maxdiffGC('conj(Vector) o Vector'' ',A,B,r); 3125 | 3126 | r = r + 1; 3127 | A = rand(1,1000) + rand(1,1000)*1i; 3128 | B = rand(1000,1000) + rand(1000,1000)*1i; 3129 | maxdiffGC('conj(Vector) * Matrix'' ',A,B,r); 3130 | 3131 | r = r + 1; 3132 | A = rand(1000,1000) + rand(1000,1000)*1i; 3133 | B = rand(1,1000) + rand(1,1000)*1i; 3134 | maxdiffGC('conj(Matrix) * Vector'' ',A,B,r); 3135 | 3136 | r = r + 1; 3137 | A = rand(1000,1000) + rand(1000,1000)*1i; 3138 | B = rand(1000,1000) + rand(1000,1000)*1i; 3139 | maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r); 3140 | 3141 | running_time(datenum(clock) - start_time); 3142 | 3143 | %-------------------------------------------------------------------------- 3144 | %-------------------------------------------------------------------------- 3145 | 3146 | %end % debug jump 3147 | 3148 | disp(' '); 3149 | disp('Numerical Comparison Tests ...'); 3150 | disp(' '); 3151 | disp('conj(real) * conj(real)'); 3152 | disp(' '); 3153 | 3154 | if( isequal(conj([])*conj([]),mtimesx([],'G',[],'G')) ) 3155 | disp('conj(Empty) * conj(Empty) EQUAL'); 3156 | else 3157 | disp('conj(Empty) * conj(Empty) NOT EQUAL <---'); 3158 | end 3159 | 3160 | r = r + 1; 3161 | mtimesx_dtable(r,:) = RC; 3162 | 3163 | rsave = r; 3164 | 3165 | r = r + 1; 3166 | A = rand(1,1); 3167 | B = rand(1,10000); 3168 | maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r); 3169 | 3170 | r = r + 1; 3171 | A = rand(1,10000); 3172 | B = rand(1,1); 3173 | maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r); 3174 | 3175 | r = r + 1; 3176 | A = rand(1,1); 3177 | B = rand(10,20,30,40); 3178 | maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r); 3179 | 3180 | r = r + 1; 3181 | A = rand(10,20,30,40); 3182 | B = rand(1,1); 3183 | maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r); 3184 | 3185 | r = r + 1; 3186 | A = rand(1,10000000); 3187 | B = rand(10000000,1); 3188 | maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r); 3189 | 3190 | r = r + 1; 3191 | A = rand(2500,1); 3192 | B = rand(1,2500); 3193 | maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r); 3194 | 3195 | r = r + 1; 3196 | A = rand(1,1000); 3197 | B = rand(1000,1000); 3198 | maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r); 3199 | 3200 | r = r + 1; 3201 | A = rand(1000,1000); 3202 | B = rand(1000,1); 3203 | maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r); 3204 | 3205 | r = r + 1; 3206 | A = rand(1000,1000); 3207 | B = rand(1000,1000); 3208 | maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r); 3209 | 3210 | %-------------------------------------------------------------------------- 3211 | disp(' '); 3212 | disp('conj(real) * conj(complex)'); 3213 | disp(' '); 3214 | 3215 | r = rsave; 3216 | 3217 | r = r + 1; 3218 | A = rand(1,1); 3219 | B = rand(1,10000) + rand(1,10000)*1i; 3220 | maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r); 3221 | 3222 | r = r + 1; 3223 | A = rand(1,10000); 3224 | B = rand(1,1) + rand(1,1)*1i; 3225 | maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r); 3226 | 3227 | r = r + 1; 3228 | A = rand(1,1); 3229 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 3230 | maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r); 3231 | 3232 | r = r + 1; 3233 | A = rand(10,20,30,40); 3234 | B = rand(1,1) + rand(1,1)*1i; 3235 | maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r); 3236 | 3237 | r = r + 1; 3238 | A = rand(1,10000000); 3239 | B = rand(10000000,1) + rand(10000000,1)*1i; 3240 | maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r); 3241 | 3242 | r = r + 1; 3243 | A = rand(2500,1); 3244 | B = rand(1,2500) + rand(1,2500)*1i; 3245 | maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r); 3246 | 3247 | r = r + 1; 3248 | A = rand(1,1000); 3249 | B = rand(1000,1000) + rand(1000,1000)*1i; 3250 | maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r); 3251 | 3252 | r = r + 1; 3253 | A = rand(1000,1000); 3254 | B = rand(1000,1) + rand(1000,1)*1i; 3255 | maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r); 3256 | 3257 | r = r + 1; 3258 | A = rand(1000,1000); 3259 | B = rand(1000,1000) + rand(1000,1000)*1i; 3260 | maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r); 3261 | 3262 | %-------------------------------------------------------------------------- 3263 | disp(' '); 3264 | disp('conj(complex)* conj(real)'); 3265 | disp(' '); 3266 | 3267 | r = rsave; 3268 | 3269 | r = r + 1; 3270 | A = rand(1,1) + rand(1,1)*1i; 3271 | B = rand(1,10000); 3272 | maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r); 3273 | 3274 | r = r + 1; 3275 | A = rand(1,10000)+ rand(1,10000)*1i; 3276 | B = rand(1,1); 3277 | maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r); 3278 | 3279 | r = r + 1; 3280 | A = rand(1,1) + rand(1,1)*1i; 3281 | B = rand(10,20,30,40); 3282 | maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r); 3283 | 3284 | r = r + 1; 3285 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 3286 | B = rand(1,1); 3287 | maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r); 3288 | 3289 | r = r + 1; 3290 | A = rand(1,10000000) + rand(1,10000000)*1i; 3291 | B = rand(10000000,1); 3292 | maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r); 3293 | 3294 | r = r + 1; 3295 | A = rand(2500,1) + rand(2500,1)*1i; 3296 | B = rand(1,2500); 3297 | maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r); 3298 | 3299 | r = r + 1; 3300 | A = rand(1,1000) + rand(1,1000)*1i; 3301 | B = rand(1000,1000); 3302 | maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r); 3303 | 3304 | r = r + 1; 3305 | A = rand(1000,1000) + rand(1000,1000)*1i; 3306 | B = rand(1000,1); 3307 | maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r); 3308 | 3309 | r = r + 1; 3310 | A = rand(1000,1000) + rand(1000,1000)*1i; 3311 | B = rand(1000,1000); 3312 | maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r); 3313 | 3314 | %-------------------------------------------------------------------------- 3315 | disp(' '); 3316 | disp('conj(complex)* conj(complex)'); 3317 | disp(' '); 3318 | 3319 | r = rsave; 3320 | 3321 | r = r + 1; 3322 | A = rand(1,1) + rand(1,1)*1i; 3323 | B = rand(1,10000) + rand(1,10000)*1i; 3324 | maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r); 3325 | 3326 | r = r + 1; 3327 | A = rand(1,10000)+ rand(1,10000)*1i; 3328 | B = rand(1,1) + rand(1,1)*1i; 3329 | maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r); 3330 | 3331 | r = r + 1; 3332 | A = rand(1,1) + rand(1,1)*1i; 3333 | B = rand(10,20,30,40) + rand(10,20,30,40)*1i; 3334 | maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r); 3335 | 3336 | r = r + 1; 3337 | A = rand(10,20,30,40) + rand(10,20,30,40)*1i; 3338 | B = rand(1,1) + rand(1,1)*1i; 3339 | maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r); 3340 | 3341 | r = r + 1; 3342 | A = rand(1,10000000) + rand(1,10000000)*1i; 3343 | B = rand(10000000,1) + rand(10000000,1)*1i; 3344 | maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r); 3345 | 3346 | r = r + 1; 3347 | A = rand(2500,1) + rand(2500,1)*1i; 3348 | B = rand(1,2500) + rand(1,2500)*1i; 3349 | maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r); 3350 | 3351 | r = r + 1; 3352 | A = rand(1,1000) + rand(1,1000)*1i; 3353 | B = rand(1000,1000) + rand(1000,1000)*1i; 3354 | maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r); 3355 | 3356 | r = r + 1; 3357 | A = rand(1000,1000) + rand(1000,1000)*1i; 3358 | B = rand(1000,1) + rand(1000,1)*1i; 3359 | maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r); 3360 | 3361 | r = r + 1; 3362 | A = rand(1000,1000) + rand(1000,1000)*1i; 3363 | B = rand(1000,1000) + rand(1000,1000)*1i; 3364 | maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r); 3365 | 3366 | running_time(datenum(clock) - start_time); 3367 | 3368 | %-------------------------------------------------------------------------- 3369 | %-------------------------------------------------------------------------- 3370 | 3371 | %end % debug jump 3372 | 3373 | disp('----------------------------------'); 3374 | disp(' '); 3375 | disp('Numerical Comparison Tests ... symmetric cases op(A) * op(A)'); 3376 | disp(' '); 3377 | disp('real'); 3378 | 3379 | r = r + 1; 3380 | mtimesx_dtable(r,:) = RC; 3381 | 3382 | rsave = r; 3383 | 3384 | r = r + 1; 3385 | A = rand(2000); 3386 | maxdiffsymCN('Matrix'' * Same ',A,r); 3387 | 3388 | r = r + 1; 3389 | A = rand(2000); 3390 | maxdiffsymNC('Matrix * Same''',A,r); 3391 | 3392 | r = r + 1; 3393 | A = rand(2000); 3394 | maxdiffsymTN('Matrix.'' * Same ',A,r); 3395 | 3396 | r = r + 1; 3397 | A = rand(2000); 3398 | maxdiffsymNT('Matrix * Same.''',A,r); 3399 | 3400 | r = r + 1; 3401 | A = rand(2000); 3402 | maxdiffsymGC('conj(Matrix) * Same''',A,r); 3403 | 3404 | r = r + 1; 3405 | A = rand(2000); 3406 | maxdiffsymCG('Matrix'' * conj(Same)',A,r); 3407 | 3408 | r = r + 1; 3409 | A = rand(2000); 3410 | maxdiffsymGT('conj(Matrix) * Same.'' ',A,r); 3411 | 3412 | r = r + 1; 3413 | A = rand(2000); 3414 | maxdiffsymTG('Matrix.'' * conj(Same)',A,r); 3415 | 3416 | r = rsave; 3417 | 3418 | disp(' ' ); 3419 | disp('complex'); 3420 | 3421 | r = r + 1; 3422 | A = rand(2000) + rand(2000)*1i; 3423 | maxdiffsymCN('Matrix'' * Same ',A,r); 3424 | 3425 | r = r + 1; 3426 | A = rand(2000) + rand(2000)*1i; 3427 | maxdiffsymNC('Matrix * Same''',A,r); 3428 | 3429 | r = r + 1; 3430 | A = rand(2000) + rand(2000)*1i; 3431 | maxdiffsymTN('Matrix.'' * Same ',A,r); 3432 | 3433 | r = r + 1; 3434 | A = rand(2000) + rand(2000)*1i; 3435 | maxdiffsymNT('Matrix * Same.''',A,r); 3436 | 3437 | r = r + 1; 3438 | A = rand(2000) + rand(2000)*1i; 3439 | maxdiffsymGC('conj(Matrix) * Same''',A,r); 3440 | 3441 | r = r + 1; 3442 | A = rand(2000) + rand(2000)*1i; 3443 | maxdiffsymCG('Matrix'' * conj(Same)',A,r); 3444 | 3445 | r = r + 1; 3446 | A = rand(2000) + rand(2000)*1i; 3447 | maxdiffsymGT('conj(Matrix) * Same.''',A,r); 3448 | 3449 | r = r + 1; 3450 | A = rand(2000) + rand(2000)*1i; 3451 | maxdiffsymTG('Matrix.'' * conj(Same)',A,r); 3452 | 3453 | running_time(datenum(clock) - start_time); 3454 | 3455 | %-------------------------------------------------------------------------- 3456 | %-------------------------------------------------------------------------- 3457 | 3458 | %end % debug jump 3459 | 3460 | disp(' '); 3461 | disp('Numerical Comparison Tests ... special scalar cases'); 3462 | disp(' '); 3463 | disp('(scalar) * (real)'); 3464 | disp(' '); 3465 | 3466 | r = r + 1; 3467 | mtimesx_dtable(r,:) = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx'; 3468 | 3469 | rsave = r; 3470 | 3471 | r = r + 1; 3472 | A = 1; 3473 | B = rand(2500); 3474 | maxdiffNN('( 1+0i) * Matrix ',A,B,r); 3475 | 3476 | r = r + 1; 3477 | A = 1 + 1i; 3478 | B = rand(2500); 3479 | maxdiffNN('( 1+1i) * Matrix ',A,B,r); 3480 | 3481 | r = r + 1; 3482 | A = 1 - 1i; 3483 | B = rand(2500); 3484 | maxdiffNN('( 1-1i) * Matrix ',A,B,r); 3485 | 3486 | r = r + 1; 3487 | A = 1 + 2i; 3488 | B = rand(2500); 3489 | maxdiffNN('( 1+2i) * Matrix ',A,B,r); 3490 | 3491 | r = r + 1; 3492 | A = -1; 3493 | B = rand(2500); 3494 | maxdiffNN('(-1+0i) * Matrix ',A,B,r); 3495 | 3496 | r = r + 1; 3497 | A = -1 + 1i; 3498 | B = rand(2500); 3499 | maxdiffNN('(-1+1i) * Matrix ',A,B,r); 3500 | 3501 | r = r + 1; 3502 | A = -1 - 1i; 3503 | B = rand(2500); 3504 | maxdiffNN('(-1-1i) * Matrix ',A,B,r); 3505 | 3506 | r = r + 1; 3507 | A = -1 + 2i; 3508 | B = rand(2500); 3509 | maxdiffNN('(-1+2i) * Matrix ',A,B,r); 3510 | 3511 | r = r + 1; 3512 | A = 2 + 1i; 3513 | B = rand(2500); 3514 | maxdiffNN('( 2+1i) * Matrix ',A,B,r); 3515 | 3516 | r = r + 1; 3517 | A = 2 - 1i; 3518 | B = rand(2500); 3519 | maxdiffNN('( 2-1i) * Matrix ',A,B,r); 3520 | 3521 | disp(' '); 3522 | disp('(scalar) * (complex)'); 3523 | disp(' '); 3524 | 3525 | r = rsave; 3526 | 3527 | r = r + 1; 3528 | A = 1; 3529 | B = rand(2500) + rand(2500)*1i; 3530 | maxdiffNN('( 1+0i) * Matrix ',A,B,r); 3531 | 3532 | r = r + 1; 3533 | A = 1 + 1i; 3534 | B = rand(2500) + rand(2500)*1i; 3535 | maxdiffNN('( 1+1i) * Matrix ',A,B,r); 3536 | 3537 | r = r + 1; 3538 | A = 1 - 1i; 3539 | B = rand(2500) + rand(2500)*1i; 3540 | maxdiffNN('( 1-1i) * Matrix ',A,B,r); 3541 | 3542 | r = r + 1; 3543 | A = 1 + 2i; 3544 | B = rand(2500) + rand(2500)*1i; 3545 | maxdiffNN('( 1+2i) * Matrix ',A,B,r); 3546 | 3547 | r = r + 1; 3548 | A = -1; 3549 | B = rand(2500) + rand(2500)*1i; 3550 | maxdiffNN('(-1+0i) * Matrix ',A,B,r); 3551 | 3552 | r = r + 1; 3553 | A = -1 + 1i; 3554 | B = rand(2500) + rand(2500)*1i; 3555 | maxdiffNN('(-1+1i) * Matrix ',A,B,r); 3556 | 3557 | r = r + 1; 3558 | A = -1 - 1i; 3559 | B = rand(2500) + rand(2500)*1i; 3560 | maxdiffNN('(-1-1i) * Matrix ',A,B,r); 3561 | 3562 | r = r + 1; 3563 | A = -1 + 2i; 3564 | B = rand(2500) + rand(2500)*1i; 3565 | maxdiffNN('(-1+2i) * Matrix ',A,B,r); 3566 | 3567 | r = r + 1; 3568 | A = 2 + 1i; 3569 | B = rand(2500) + rand(2500)*1i; 3570 | maxdiffNN('( 2+1i) * Matrix ',A,B,r); 3571 | 3572 | r = r + 1; 3573 | A = 2 - 1i; 3574 | B = rand(2500) + rand(2500)*1i; 3575 | maxdiffNN('( 2-1i) * Matrix ',A,B,r); 3576 | 3577 | disp(' '); 3578 | disp('(scalar) * (complex)'''); 3579 | disp(' '); 3580 | 3581 | %r = rsave; 3582 | 3583 | r = r + 1; 3584 | A = 1; 3585 | B = rand(2500) + rand(2500)*1i; 3586 | maxdiffNC('( 1+0i) * Matrix'' ',A,B,r); 3587 | 3588 | r = r + 1; 3589 | A = 1 + 1i; 3590 | B = rand(2500) + rand(2500)*1i; 3591 | maxdiffNC('( 1+1i) * Matrix'' ',A,B,r); 3592 | 3593 | r = r + 1; 3594 | A = 1 - 1i; 3595 | B = rand(2500) + rand(2500)*1i; 3596 | maxdiffNC('( 1-1i) * Matrix'' ',A,B,r); 3597 | 3598 | r = r + 1; 3599 | A = 1 + 2i; 3600 | B = rand(2500) + rand(2500)*1i; 3601 | maxdiffNC('( 1+2i) * Matrix'' ',A,B,r); 3602 | 3603 | r = r + 1; 3604 | A = -1; 3605 | B = rand(2500) + rand(2500)*1i; 3606 | maxdiffNC('(-1+0i) * Matrix'' ',A,B,r); 3607 | 3608 | r = r + 1; 3609 | A = -1 + 1i; 3610 | B = rand(2500) + rand(2500)*1i; 3611 | maxdiffNC('(-1+1i) * Matrix'' ',A,B,r); 3612 | 3613 | r = r + 1; 3614 | A = -1 - 1i; 3615 | B = rand(2500) + rand(2500)*1i; 3616 | maxdiffNC('(-1-1i) * Matrix'' ',A,B,r); 3617 | 3618 | r = r + 1; 3619 | A = -1 + 2i; 3620 | B = rand(2500) + rand(2500)*1i; 3621 | maxdiffNC('(-1+2i) * Matrix'' ',A,B,r); 3622 | 3623 | r = r + 1; 3624 | A = 2 + 1i; 3625 | B = rand(2500) + rand(2500)*1i; 3626 | maxdiffNC('( 2+1i) * Matrix'' ',A,B,r); 3627 | 3628 | r = r + 1; 3629 | A = 2 - 1i; 3630 | B = rand(2500) + rand(2500)*1i; 3631 | maxdiffNC('( 2-1i) * Matrix'' ',A,B,r); 3632 | 3633 | running_time(datenum(clock) - start_time); 3634 | 3635 | %-------------------------------------------------------------------------- 3636 | %-------------------------------------------------------------------------- 3637 | 3638 | %end % debug jump 3639 | 3640 | disp(' '); 3641 | disp('Numerical Comparison Tests ... special (scalar) * (sparse) cases'); 3642 | disp('Real * Real, Real * Cmpx, Cmpx * Real, Cmpx * Cmpx'); 3643 | disp(' '); 3644 | 3645 | r = r + 1; 3646 | mtimesx_dtable(r,:) = RC; 3647 | 3648 | % rsave = r; 3649 | 3650 | r = r + 1; 3651 | A = rand(1,1); 3652 | B = sprand(5000,5000,.1); 3653 | maxdiffNN('Scalar * Sparse',A,B,r); 3654 | 3655 | A = rand(1,1); 3656 | B = sprand(5000,5000,.1); B = B + B*2i; 3657 | maxdiffNN('Scalar * Sparse',A,B,r); 3658 | 3659 | A = rand(1,1) + rand(1,1)*1i; 3660 | B = sprand(5000,5000,.1); 3661 | maxdiffNN('Scalar * Sparse',A,B,r); 3662 | 3663 | A = rand(1,1) + rand(1,1)*1i; 3664 | B = sprand(5000,5000,.1); B = B + B*2i; 3665 | maxdiffNN('Scalar * Sparse',A,B,r); 3666 | 3667 | r = r + 1; 3668 | A = rand(1,1); 3669 | B = sprand(5000,5000,.1); 3670 | maxdiffNT('Scalar * Sparse.''',A,B,r); 3671 | 3672 | A = rand(1,1); 3673 | B = sprand(5000,5000,.1); B = B + B*2i; 3674 | maxdiffNT('Scalar * Sparse.''',A,B,r); 3675 | 3676 | A = rand(1,1) + rand(1,1)*1i; 3677 | B = sprand(5000,5000,.1); 3678 | maxdiffNT('Scalar * Sparse.''',A,B,r); 3679 | 3680 | A = rand(1,1) + rand(1,1)*1i; 3681 | B = sprand(5000,5000,.1); B = B + B*2i; 3682 | maxdiffNT('Scalar * Sparse.''',A,B,r); 3683 | 3684 | r = r + 1; 3685 | A = rand(1,1); 3686 | B = sprand(5000,5000,.1); 3687 | maxdiffNC('Scalar * Sparse''',A,B,r); 3688 | 3689 | A = rand(1,1); 3690 | B = sprand(5000,5000,.1); B = B + B*2i; 3691 | maxdiffNC('Scalar * Sparse''',A,B,r); 3692 | 3693 | A = rand(1,1) + rand(1,1)*1i; 3694 | B = sprand(5000,5000,.1); 3695 | maxdiffNC('Scalar * Sparse''',A,B,r); 3696 | 3697 | A = rand(1,1) + rand(1,1)*1i; 3698 | B = sprand(5000,5000,.1); B = B + B*2i; 3699 | maxdiffNC('Scalar * Sparse''',A,B,r); 3700 | 3701 | r = r + 1; 3702 | A = rand(1,1); 3703 | B = sprand(5000,5000,.1); 3704 | maxdiffNG('Scalar * conj(Sparse)',A,B,r); 3705 | 3706 | A = rand(1,1); 3707 | B = sprand(5000,5000,.1); B = B + B*2i; 3708 | maxdiffNG('Scalar * conj(Sparse)',A,B,r); 3709 | 3710 | A = rand(1,1) + rand(1,1)*1i; 3711 | B = sprand(5000,5000,.1); 3712 | maxdiffNG('Scalar * conj(Sparse)',A,B,r); 3713 | 3714 | A = rand(1,1) + rand(1,1)*1i; 3715 | B = sprand(5000,5000,.1); B = B + B*2i; 3716 | maxdiffNG('Scalar * conj(Sparse)',A,B,r); 3717 | 3718 | running_time(datenum(clock) - start_time); 3719 | 3720 | %-------------------------------------------------------------------------- 3721 | %-------------------------------------------------------------------------- 3722 | 3723 | disp(' '); 3724 | disp(' --- DONE ! ---'); 3725 | disp(' '); 3726 | disp('Summary of Numerical Comparison Tests, max relative element difference:'); 3727 | disp(' '); 3728 | mtimesx_dtable(1,1:k) = compver; 3729 | disp(mtimesx_dtable); 3730 | disp(' '); 3731 | 3732 | dtable = mtimesx_dtable; 3733 | 3734 | end 3735 | 3736 | %-------------------------------------------------------------------------- 3737 | %-------------------------------------------------------------------------- 3738 | 3739 | function maxdiffNN(T,A,B,r) 3740 | Cm = A*B; 3741 | Cx = mtimesx(A,B); 3742 | maxdiffout(T,A,B,Cm,Cx,r); 3743 | return 3744 | end 3745 | 3746 | %-------------------------------------------------------------------------- 3747 | %-------------------------------------------------------------------------- 3748 | 3749 | function maxdiffCN(T,A,B,r) 3750 | Cm = A'*B; 3751 | Cx = mtimesx(A,'C',B); 3752 | maxdiffout(T,A,B,Cm,Cx,r); 3753 | return 3754 | end 3755 | 3756 | %-------------------------------------------------------------------------- 3757 | %-------------------------------------------------------------------------- 3758 | 3759 | function maxdiffTN(T,A,B,r) 3760 | Cm = A.'*B; 3761 | Cx = mtimesx(A,'T',B); 3762 | maxdiffout(T,A,B,Cm,Cx,r); 3763 | return 3764 | end 3765 | 3766 | %-------------------------------------------------------------------------- 3767 | %-------------------------------------------------------------------------- 3768 | 3769 | function maxdiffGN(T,A,B,r) 3770 | Cm = conj(A)*B; 3771 | Cx = mtimesx(A,'G',B); 3772 | maxdiffout(T,A,B,Cm,Cx,r); 3773 | return 3774 | end 3775 | 3776 | %-------------------------------------------------------------------------- 3777 | %-------------------------------------------------------------------------- 3778 | 3779 | function maxdiffNC(T,A,B,r) 3780 | Cm = A*B'; 3781 | Cx = mtimesx(A,B,'C'); 3782 | maxdiffout(T,A,B,Cm,Cx,r); 3783 | return 3784 | end 3785 | 3786 | %-------------------------------------------------------------------------- 3787 | %-------------------------------------------------------------------------- 3788 | 3789 | function maxdiffCC(T,A,B,r) 3790 | Cm = A'*B'; 3791 | Cx = mtimesx(A,'C',B,'C'); 3792 | maxdiffout(T,A,B,Cm,Cx,r); 3793 | return 3794 | end 3795 | 3796 | %-------------------------------------------------------------------------- 3797 | %-------------------------------------------------------------------------- 3798 | 3799 | function maxdiffTC(T,A,B,r) 3800 | Cm = A.'*B'; 3801 | Cx = mtimesx(A,'T',B,'C'); 3802 | maxdiffout(T,A,B,Cm,Cx,r); 3803 | return 3804 | end 3805 | 3806 | %-------------------------------------------------------------------------- 3807 | %-------------------------------------------------------------------------- 3808 | 3809 | function maxdiffGC(T,A,B,r) 3810 | Cm = conj(A)*B'; 3811 | Cx = mtimesx(A,'G',B,'C'); 3812 | maxdiffout(T,A,B,Cm,Cx,r); 3813 | return 3814 | end 3815 | 3816 | %-------------------------------------------------------------------------- 3817 | %-------------------------------------------------------------------------- 3818 | 3819 | function maxdiffNT(T,A,B,r) 3820 | Cm = A*B.'; 3821 | Cx = mtimesx(A,B,'T'); 3822 | maxdiffout(T,A,B,Cm,Cx,r); 3823 | return 3824 | end 3825 | 3826 | %-------------------------------------------------------------------------- 3827 | %-------------------------------------------------------------------------- 3828 | 3829 | function maxdiffCT(T,A,B,r) 3830 | Cm = A'*B.'; 3831 | Cx = mtimesx(A,'C',B,'T'); 3832 | maxdiffout(T,A,B,Cm,Cx,r); 3833 | return 3834 | end 3835 | 3836 | %-------------------------------------------------------------------------- 3837 | %-------------------------------------------------------------------------- 3838 | 3839 | function maxdiffTT(T,A,B,r) 3840 | Cm = A.'*B.'; 3841 | Cx = mtimesx(A,'T',B,'T'); 3842 | maxdiffout(T,A,B,Cm,Cx,r); 3843 | return 3844 | end 3845 | 3846 | %-------------------------------------------------------------------------- 3847 | %-------------------------------------------------------------------------- 3848 | 3849 | function maxdiffGT(T,A,B,r) 3850 | Cm = conj(A)*B.'; 3851 | Cx = mtimesx(A,'G',B,'T'); 3852 | maxdiffout(T,A,B,Cm,Cx,r); 3853 | return 3854 | end 3855 | 3856 | %-------------------------------------------------------------------------- 3857 | %-------------------------------------------------------------------------- 3858 | 3859 | function maxdiffNG(T,A,B,r) 3860 | Cm = A*conj(B); 3861 | Cx = mtimesx(A,B,'G'); 3862 | maxdiffout(T,A,B,Cm,Cx,r); 3863 | return 3864 | end 3865 | 3866 | %-------------------------------------------------------------------------- 3867 | %-------------------------------------------------------------------------- 3868 | 3869 | function maxdiffCG(T,A,B,r) 3870 | Cm = A'*conj(B); 3871 | Cx = mtimesx(A,'C',B,'G'); 3872 | maxdiffout(T,A,B,Cm,Cx,r); 3873 | return 3874 | end 3875 | 3876 | %-------------------------------------------------------------------------- 3877 | %-------------------------------------------------------------------------- 3878 | 3879 | function maxdiffTG(T,A,B,r) 3880 | Cm = A.'*conj(B); 3881 | Cx = mtimesx(A,'T',B,'G'); 3882 | maxdiffout(T,A,B,Cm,Cx,r); 3883 | return 3884 | end 3885 | 3886 | %-------------------------------------------------------------------------- 3887 | %-------------------------------------------------------------------------- 3888 | 3889 | function maxdiffGG(T,A,B,r) 3890 | Cm = conj(A)*conj(B); 3891 | Cx = mtimesx(A,'G',B,'G'); 3892 | maxdiffout(T,A,B,Cm,Cx,r); 3893 | return 3894 | end 3895 | 3896 | %-------------------------------------------------------------------------- 3897 | %-------------------------------------------------------------------------- 3898 | 3899 | function maxdiffsymCN(T,A,r) 3900 | Cm = A'*A; 3901 | Cx = mtimesx(A,'C',A); 3902 | maxdiffsymout(T,A,Cm,Cx,r); 3903 | return 3904 | end 3905 | 3906 | %-------------------------------------------------------------------------- 3907 | %-------------------------------------------------------------------------- 3908 | 3909 | function maxdiffsymNC(T,A,r) 3910 | Cm = A*A'; 3911 | Cx = mtimesx(A,A,'C'); 3912 | maxdiffsymout(T,A,Cm,Cx,r); 3913 | return 3914 | end 3915 | 3916 | %-------------------------------------------------------------------------- 3917 | %-------------------------------------------------------------------------- 3918 | 3919 | function maxdiffsymTN(T,A,r) 3920 | Cm = A.'*A; 3921 | Cx = mtimesx(A,'T',A); 3922 | maxdiffsymout(T,A,Cm,Cx,r); 3923 | return 3924 | end 3925 | 3926 | %-------------------------------------------------------------------------- 3927 | %-------------------------------------------------------------------------- 3928 | 3929 | function maxdiffsymNT(T,A,r) 3930 | Cm = A*A.'; 3931 | Cx = mtimesx(A,A,'T'); 3932 | maxdiffsymout(T,A,Cm,Cx,r); 3933 | return 3934 | end 3935 | 3936 | %-------------------------------------------------------------------------- 3937 | %-------------------------------------------------------------------------- 3938 | 3939 | function maxdiffsymTG(T,A,r) 3940 | Cm = A.'*conj(A); 3941 | Cx = mtimesx(A,'T',A,'G'); 3942 | maxdiffsymout(T,A,Cm,Cx,r); 3943 | return 3944 | end 3945 | 3946 | %-------------------------------------------------------------------------- 3947 | %-------------------------------------------------------------------------- 3948 | 3949 | function maxdiffsymGT(T,A,r) 3950 | Cm = conj(A)*A.'; 3951 | Cx = mtimesx(A,'G',A,'T'); 3952 | maxdiffsymout(T,A,Cm,Cx,r); 3953 | return 3954 | end 3955 | 3956 | %-------------------------------------------------------------------------- 3957 | %-------------------------------------------------------------------------- 3958 | 3959 | function maxdiffsymCG(T,A,r) 3960 | Cm = A'*conj(A); 3961 | Cx = mtimesx(A,'C',A,'G'); 3962 | maxdiffsymout(T,A,Cm,Cx,r); 3963 | return 3964 | end 3965 | 3966 | %-------------------------------------------------------------------------- 3967 | %-------------------------------------------------------------------------- 3968 | 3969 | function maxdiffsymGC(T,A,r) 3970 | Cm = conj(A)*A'; 3971 | Cx = mtimesx(A,'G',A,'C'); 3972 | maxdiffsymout(T,A,Cm,Cx,r); 3973 | return 3974 | end 3975 | 3976 | %-------------------------------------------------------------------------- 3977 | %-------------------------------------------------------------------------- 3978 | 3979 | function maxdiffout(T,A,B,Cm,Cx,r) 3980 | global mtimesx_dtable 3981 | lt = length(T); 3982 | b = repmat(' ',1,30-lt); 3983 | if( isequal(Cm,Cx) ) 3984 | disp([T b ' EQUAL']); 3985 | d = 0; 3986 | else 3987 | Cm = Cm(:); 3988 | Cx = Cx(:); 3989 | if( isreal(Cm) && isreal(Cx) ) 3990 | rx = Cx ~= Cm; 3991 | d = max(abs((Cx(rx)-Cm(rx))./Cm(rx))); 3992 | else 3993 | Cmr = real(Cm); 3994 | Cmi = imag(Cm); 3995 | Cxr = real(Cx); 3996 | Cxi = imag(Cx); 3997 | rx = Cxr ~= Cmr; 3998 | ix = Cxi ~= Cmi; 3999 | dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx))))); 4000 | di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix))))); 4001 | if( isempty(dr) ) 4002 | d = di; 4003 | elseif( isempty(di) ) 4004 | d = dr; 4005 | else 4006 | d = max(dr,di); 4007 | end 4008 | end 4009 | disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]); 4010 | end 4011 | mtimesx_dtable(r,1:length(T)) = T; 4012 | if( isreal(A) && isreal(B) ) 4013 | if( d == 0 ) 4014 | x = [T b ' 0']; 4015 | else 4016 | x = [T b sprintf('%11.2e',d)]; 4017 | end 4018 | mtimesx_dtable(r,1:length(x)) = x; 4019 | elseif( isreal(A) && ~isreal(B) ) 4020 | if( d == 0 ) 4021 | x = ' 0'; 4022 | else 4023 | x = sprintf('%11.2e',d); 4024 | end 4025 | mtimesx_dtable(r,42:41+length(x)) = x; 4026 | elseif( ~isreal(A) && isreal(B) ) 4027 | if( d == 0 ) 4028 | x = ' 0'; 4029 | else 4030 | x = sprintf('%11.2e',d); 4031 | end 4032 | mtimesx_dtable(r,53:52+length(x)) = x; 4033 | else 4034 | if( d == 0 ) 4035 | x = ' 0'; 4036 | else 4037 | x = sprintf('%11.2e',d); 4038 | end 4039 | mtimesx_dtable(r,64:63+length(x)) = x; 4040 | end 4041 | 4042 | return 4043 | end 4044 | 4045 | %-------------------------------------------------------------------------- 4046 | %-------------------------------------------------------------------------- 4047 | 4048 | function maxdiffsymout(T,A,Cm,Cx,r) 4049 | global mtimesx_dtable 4050 | lt = length(T); 4051 | b = repmat(' ',1,30-lt); 4052 | if( isequal(Cm,Cx) ) 4053 | disp([T b ' EQUAL']); 4054 | d = 0; 4055 | else 4056 | Cm = Cm(:); 4057 | Cx = Cx(:); 4058 | if( isreal(Cm) && isreal(Cx) ) 4059 | rx = Cx ~= Cm; 4060 | d = max(abs((Cx(rx)-Cm(rx))./Cm(rx))); 4061 | else 4062 | Cmr = real(Cm); 4063 | Cmi = imag(Cm); 4064 | Cxr = real(Cx); 4065 | Cxi = imag(Cx); 4066 | rx = Cxr ~= Cmr; 4067 | ix = Cxi ~= Cmi; 4068 | dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx))))); 4069 | di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix))))); 4070 | if( isempty(dr) ) 4071 | d = di; 4072 | elseif( isempty(di) ) 4073 | d = dr; 4074 | else 4075 | d = max(dr,di); 4076 | end 4077 | end 4078 | disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]); 4079 | end 4080 | if( isreal(A) ) 4081 | if( d == 0 ) 4082 | x = [T b ' 0']; 4083 | else 4084 | x = [T b sprintf('%11.2e',d)]; 4085 | end 4086 | mtimesx_dtable(r,1:length(x)) = x; 4087 | else 4088 | if( d == 0 ) 4089 | x = ' 0'; 4090 | else 4091 | x = sprintf('%11.2e',d); 4092 | end 4093 | mtimesx_dtable(r,1:length(T)) = T; 4094 | mtimesx_dtable(r,64:63+length(x)) = x; 4095 | end 4096 | 4097 | return 4098 | end 4099 | 4100 | %-------------------------------------------------------------------------- 4101 | %-------------------------------------------------------------------------- 4102 | 4103 | function running_time(d) 4104 | h = 24*d; 4105 | hh = floor(h); 4106 | m = 60*(h - hh); 4107 | mm = floor(m); 4108 | s = 60*(m - mm); 4109 | ss = floor(s); 4110 | disp(' '); 4111 | rt = sprintf('Running time hh:mm:ss = %2.0f:%2.0f:%2.0f',hh,mm,ss); 4112 | if( rt(28) == ' ' ) 4113 | rt(28) = '0'; 4114 | end 4115 | if( rt(31) == ' ' ) 4116 | rt(31) = '0'; 4117 | end 4118 | disp(rt); 4119 | disp(' '); 4120 | return 4121 | end 4122 | -------------------------------------------------------------------------------- /private/mtimesx/mtimesx_test_nd.m: -------------------------------------------------------------------------------- 1 | % Test routine for mtimesx, multi-dimensional speed and equality to MATLAB 2 | %****************************************************************************** 3 | % 4 | % MATLAB (R) is a trademark of The Mathworks (R) Corporation 5 | % 6 | % Function: mtimesx_test_nd 7 | % Filename: mtimesx_test_nd.m 8 | % Programmer: James Tursa 9 | % Version: 1.40 10 | % Date: October 4, 2010 11 | % Copyright: (c) 2009,2010 by James Tursa, All Rights Reserved 12 | % 13 | % This code uses the BSD License: 14 | % 15 | % Redistribution and use in source and binary forms, with or without 16 | % modification, are permitted provided that the following conditions are 17 | % met: 18 | % 19 | % * Redistributions of source code must retain the above copyright 20 | % notice, this list of conditions and the following disclaimer. 21 | % * Redistributions in binary form must reproduce the above copyright 22 | % notice, this list of conditions and the following disclaimer in 23 | % the documentation and/or other materials provided with the distribution 24 | % 25 | % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 29 | % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | % POSSIBILITY OF SUCH DAMAGE. 36 | % 37 | % Syntax: 38 | % 39 | % A = mtimesx_test_nd % default n=4 is used 40 | % A = mtimesx_test_nd(n) 41 | % 42 | % where n = number of repetitions (should be 4 <= n <= 100) 43 | % 44 | % Output: 45 | % 46 | % Prints out speed and equality test results. 47 | % A = cell array with tabled results. 48 | % 49 | % 2010/Oct/04 --> 1.40, Added OpenMP support for custom code 50 | % Expanded sparse * single and sparse * nD support 51 | % 52 | %-------------------------------------------------------------------------- 53 | 54 | function Cr = mtimesx_test_nd(n) 55 | mtimesx; % load the mex routine into memory 56 | if( nargin == 0 ) 57 | n = 4; 58 | else 59 | n = floor(n); 60 | if( ~(n >= 4 && n <= 100) ) 61 | n = 4; 62 | end 63 | end 64 | cn = sprintf('%g',n); 65 | 66 | disp(' '); 67 | disp('MTIMESX multi-dimensional equality and speed tests'); 68 | disp('--------------------------------------------------'); 69 | disp(' '); 70 | disp('(M x K) * ( K x N) equality tests, SPEED mode, M,K,N <= 4'); 71 | trans = 'NGTC'; 72 | cmpx = {'real ','cmpx '}; 73 | mtimesx('speed'); 74 | smallok = true; 75 | for m=1:4 76 | for k=1:4 77 | for n=1:4 78 | for transa=1:4 79 | if( transa <= 2 ) 80 | ma = m; 81 | ka = k; 82 | else 83 | ma = k; 84 | ka = m; 85 | end 86 | for transb=1:4 87 | if( transb <= 2 ) 88 | kb = k; 89 | nb = n; 90 | else 91 | kb = n; 92 | nb = k; 93 | end 94 | for cmplxa=1:2 95 | if( cmplxa == 1 ) 96 | A = floor(rand(ma,ka)*100+1); 97 | else 98 | A = floor(rand(ma,ka)*100+1) + floor(rand(ma,ka)*100+1)*1i; 99 | end 100 | for cmplxb=1:2 101 | if( cmplxb == 1 ) 102 | B = floor(rand(kb,nb)*100+1); 103 | else 104 | B = floor(rand(kb,nb)*100+1) + floor(rand(kb,nb)*100+1)*1i; 105 | end 106 | Cm = mtimesx_sparse(A,trans(transa),B,trans(transb)); 107 | Cx = mtimesx(A,trans(transa),B,trans(transb)); 108 | if( isequal(Cm,Cx) ) 109 | disp(['(' cmpx{cmplxa} num2str(m) ' x ' num2str(k) ')' trans(transa) ... 110 | ' * (' cmpx{cmplxb} num2str(k) ' x ' num2str(n) ')' trans(transb) ' EQUAL']); 111 | else 112 | disp(['(' cmpx{cmplxa} num2str(m) ' x ' num2str(k) ')' trans(transa) ... 113 | ' * (' cmpx{cmplxb} num2str(k) ' x ' num2str(n) ')' trans(transb) ' NOT EQUAL']); 114 | smallok = false; 115 | end 116 | end 117 | end 118 | end 119 | end 120 | end 121 | end 122 | end 123 | 124 | if( mtimesx('openmp') ) 125 | disp(' '); 126 | disp('(M x K) * ( K x N) equality tests, SPEEDOMP mode, M,K,N <= 4'); 127 | mtimesx('speedomp'); 128 | smallokomp = true; 129 | for m=1:4 130 | for k=1:4 131 | for n=1:4 132 | for transa=1:4 133 | if( transa <= 2 ) 134 | ma = m; 135 | ka = k; 136 | else 137 | ma = k; 138 | ka = m; 139 | end 140 | for transb=1:4 141 | if( transb <= 2 ) 142 | kb = k; 143 | nb = n; 144 | else 145 | kb = n; 146 | nb = k; 147 | end 148 | for cmplxa=1:2 149 | if( cmplxa == 1 ) 150 | A = floor(rand(ma,ka)*100+1); 151 | else 152 | A = floor(rand(ma,ka)*100+1) + floor(rand(ma,ka)*100+1)*1i; 153 | end 154 | A = reshape(repmat(A,1000,1),ma,ka,1000); 155 | for cmplxb=1:2 156 | if( cmplxb == 1 ) 157 | B = floor(rand(kb,nb)*100+1); 158 | else 159 | B = floor(rand(kb,nb)*100+1) + floor(rand(kb,nb)*100+1)*1i; 160 | end 161 | B = reshape(repmat(B,1000,1),kb,nb,1000); 162 | Cm = mtimesx_sparse(A(:,:,1),trans(transa),B(:,:,1),trans(transb)); 163 | Cx = mtimesx(A,trans(transa),B,trans(transb)); 164 | if( isequal(Cm,Cx(:,:,1)) ) 165 | disp(['(' cmpx{cmplxa} num2str(m) ' x ' num2str(k) ')' trans(transa) ... 166 | ' * (' cmpx{cmplxb} num2str(k) ' x ' num2str(n) ')' trans(transb) ' EQUAL']); 167 | else 168 | disp(['(' cmpx{cmplxa} num2str(m) ' x ' num2str(k) ')' trans(transa) ... 169 | ' * (' cmpx{cmplxb} num2str(k) ' x ' num2str(n) ')' trans(transb) ' NOT EQUAL']); 170 | smallokomp = false; 171 | end 172 | end 173 | end 174 | end 175 | end 176 | end 177 | end 178 | end 179 | end 180 | 181 | disp(' '); 182 | if( smallok ) 183 | disp('All small matrix multiplies are OK in SPEED mode'); 184 | else 185 | disp('ERROR --> One or more of the small matrix multiplies was not equal in SPEED mode'); 186 | end 187 | if( mtimesx('openmp') ) 188 | if( smallokomp ) 189 | disp('All small matrix multiplies are OK in SPEEDOMP mode'); 190 | else 191 | disp('ERROR --> One or more of the small matrix multiplies was not equal in SPEEDOMP mode'); 192 | end 193 | end 194 | 195 | disp(' '); 196 | disp(['mtimesx multi-dimensional test routine using ' cn ' repetitions']); 197 | 198 | if( mtimesx('OPENMP') ) 199 | topm = 6; 200 | else 201 | topm = 4; 202 | end 203 | Cr = cell(6,topm+1); 204 | Cr{1,1} = 'All operands real'; 205 | 206 | for m=2:topm+1 207 | if( m == 2 ) 208 | mtimesx('BLAS'); 209 | elseif( m == 3 ) 210 | mtimesx('LOOPS'); 211 | elseif( m == 4 ) 212 | mtimesx('MATLAB'); 213 | elseif( m == 5 ) 214 | mtimesx('SPEED'); 215 | elseif( m == 6 ) 216 | mtimesx('LOOPSOMP'); 217 | else 218 | mtimesx('SPEEDOMP'); 219 | end 220 | Cr{1,m} = mtimesx; 221 | 222 | disp(' '); 223 | disp('--------------------------------------------------------------'); 224 | disp('--------------------------------------------------------------'); 225 | disp(' '); 226 | disp(['MTIMESX mode: ' mtimesx]); 227 | disp(' '); 228 | disp('(real 3x5x1x4x3x2x1x8) * (real 5x7x3x1x3x2x5) example'); 229 | Cr{2,1} = '(3x5xND) *(5x7xND)'; 230 | A = rand(3,5,1,4,3,2,1,8); 231 | B = rand(5,7,3,1,3,2,5); 232 | % mtimes 233 | tm = zeros(1,n); 234 | for k=1:n 235 | clear Cm 236 | A(1) = 2*A(1); 237 | B(1) = 2*B(1); 238 | tic 239 | Cm = zeros(3,7,3,4,3,2,5,8); 240 | for k1=1:3 241 | for k2=1:4 242 | for k3=1:3 243 | for k4=1:2 244 | for k5=1:5 245 | for k6=1:8 246 | Cm(:,:,k1,k2,k3,k4,k5,k6) = A(:,:,1,k2,k3,k4,1,k6) * B(:,:,k1,1,k3,k4,k5); 247 | end 248 | end 249 | end 250 | end 251 | end 252 | end 253 | tm(k) = toc; 254 | end 255 | % mtimesx 256 | tx = zeros(1,n); 257 | for k=1:n 258 | clear Cx 259 | tic 260 | Cx = mtimesx(A,B); 261 | tx(k) = toc; 262 | end 263 | % results 264 | tm = median(tm); 265 | tx = median(tx); 266 | if( tx < tm ) 267 | faster = sprintf('%7.1f',100*(tm)/tx-100); 268 | slower = ''; 269 | else 270 | faster = sprintf('%7.1f',-(100*(tx)/tm-100)); 271 | slower = ' (i.e., slower)'; 272 | end 273 | Cr{2,m} = faster; 274 | disp(' '); 275 | disp(['mtimes Elapsed time ' num2str(tm) ' seconds.']); 276 | disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']); 277 | disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB mtimes' slower]) 278 | if( isequal(Cx,Cm) ) 279 | disp(['MTIMESX ' mtimesx ' mode result matches mtimes: EQUAL']) 280 | else 281 | dx = max(abs(Cx(:)-Cm(:))); 282 | disp(['MTIMESX ' mtimesx ' mode result does not match mtimes: NOT EQUAL , max diff = ' num2str(dx)]) 283 | end 284 | 285 | disp(' '); 286 | disp('--------------------------------------------------------------'); 287 | disp('(real 3x3x1000000) * (real 3x3x1000000) example'); 288 | Cr{3,1} = '(3x3xN) *(3x3xN)'; 289 | A = rand(3,3,1000000); 290 | B = rand(3,3,1000000); 291 | % mtimes 292 | tm = zeros(1,n); 293 | for k=1:n 294 | clear Cm 295 | A(1) = 2*A(1); 296 | B(1) = 2*B(1); 297 | tic 298 | Cm = zeros(3,3,1000000); 299 | for k1=1:1000000 300 | Cm(:,:,k1) = A(:,:,k1) * B(:,:,k1); 301 | end 302 | tm(k) = toc; 303 | end 304 | % mtimesx 305 | tx = zeros(1,n); 306 | for k=1:n 307 | clear Cx 308 | tic 309 | Cx = mtimesx(A,B); 310 | tx(k) = toc; 311 | end 312 | % results 313 | tm = median(tm); 314 | tx = median(tx); 315 | if( tx < tm ) 316 | faster = sprintf('%7.1f',100*(tm)/tx-100); 317 | slower = ''; 318 | else 319 | faster = sprintf('%7.1f',-(100*(tx)/tm-100)); 320 | slower = ' (i.e., slower)'; 321 | end 322 | Cr{3,m} = faster; 323 | disp(' '); 324 | disp(['mtimes Elapsed time ' num2str(tm) ' seconds.']); 325 | disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']); 326 | disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB mtimes' slower]) 327 | if( isequal(Cx,Cm) ) 328 | disp(['MTIMESX ' mtimesx ' mode result matches mtimes: EQUAL']) 329 | else 330 | dx = max(abs(Cx(:)-Cm(:))); 331 | disp(['MTIMESX ' mtimesx ' mode result does not match mtimes: NOT EQUAL , max diff = ' num2str(dx)]) 332 | end 333 | 334 | disp(' '); 335 | disp('--------------------------------------------------------------'); 336 | disp('(real 2x2x2000000) * (real 2x2x2000000) example'); 337 | Cr{4,1} = '(2x2xN) *(2x2xN)'; 338 | A = rand(2,2,2000000); 339 | B = rand(2,2,2000000); 340 | % mtimes 341 | tm = zeros(1,n); 342 | for k=1:n 343 | clear Cm 344 | A(1) = 2*A(1); 345 | B(1) = 2*B(1); 346 | tic 347 | Cm = zeros(2,2,2000000); 348 | for k1=1:2000000 349 | Cm(:,:,k1) = A(:,:,k1) * B(:,:,k1); 350 | end 351 | tm(k) = toc; 352 | end 353 | % mtimesx 354 | tx = zeros(1,n); 355 | for k=1:n 356 | clear Cx 357 | tic 358 | Cx = mtimesx(A,B); 359 | tx(k) = toc; 360 | end 361 | % results 362 | tm = median(tm); 363 | tx = median(tx); 364 | if( tx < tm ) 365 | faster = sprintf('%7.1f',100*(tm)/tx-100); 366 | slower = ''; 367 | else 368 | faster = sprintf('%7.1f',-(100*(tx)/tm-100)); 369 | slower = ' (i.e., slower)'; 370 | end 371 | Cr{4,m} = faster; 372 | disp(' '); 373 | disp(['mtimes Elapsed time ' num2str(tm) ' seconds.']); 374 | disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']); 375 | disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB mtimes' slower]) 376 | if( isequal(Cx,Cm) ) 377 | disp(['MTIMESX ' mtimesx ' mode result matches mtimes: EQUAL']) 378 | else 379 | dx = max(abs(Cx(:)-Cm(:))); 380 | disp(['MTIMESX ' mtimesx ' mode result does not match mtimes: NOT EQUAL , max diff = ' num2str(dx)]) 381 | end 382 | 383 | disp(' '); 384 | disp('--------------------------------------------------------------'); 385 | disp('(real 2x2x2000000) * (real 1x1x2000000) example'); 386 | Cr{5,1} = '(2x2xN) *(1x1xN)'; 387 | A = rand(2,2,2000000); 388 | B = rand(1,1,2000000); 389 | % mtimes 390 | tm = zeros(1,n); 391 | for k=1:n 392 | clear Cm 393 | A(1) = 2*A(1); 394 | B(1) = 2*B(1); 395 | tic 396 | Cm = zeros(2,2,2000000); 397 | for k1=1:2000000 398 | Cm(:,:,k1) = A(:,:,k1) * B(:,:,k1); 399 | end 400 | tm(k) = toc; 401 | end 402 | % mtimesx 403 | tx = zeros(1,n); 404 | for k=1:n 405 | clear Cx 406 | tic 407 | Cx = mtimesx(A,B); 408 | tx(k) = toc; 409 | end 410 | % results 411 | tm = median(tm); 412 | tx = median(tx); 413 | if( tx < tm ) 414 | faster = sprintf('%7.1f',100*(tm)/tx-100); 415 | slower = ''; 416 | else 417 | faster = sprintf('%7.1f',-(100*(tx)/tm-100)); 418 | slower = ' (i.e., slower)'; 419 | end 420 | Cr{5,m} = faster; 421 | disp(' '); 422 | disp(['mtimes Elapsed time ' num2str(tm) ' seconds.']); 423 | disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']); 424 | disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB mtimes' slower]) 425 | if( isequal(Cx,Cm) ) 426 | disp(['MTIMESX ' mtimesx ' mode result matches mtimes: EQUAL']) 427 | else 428 | dx = max(abs(Cx(:)-Cm(:))); 429 | disp(['MTIMESX ' mtimesx ' mode result does not match mtimes: NOT EQUAL , max diff = ' num2str(dx)]) 430 | end 431 | 432 | try 433 | bsxfun(@times,1,1); 434 | Cr{6,1} = 'above vs bsxfun'; 435 | A = rand(2,2,2000000); 436 | B = rand(1,1,2000000); 437 | % bsxfun 438 | tm = zeros(1,n); 439 | for k=1:n 440 | clear Cm 441 | A(1) = 2*A(1); 442 | B(1) = 2*B(1); 443 | tic 444 | Cm = bsxfun(@times,A,B); 445 | tm(k) = toc; 446 | end 447 | % mtimesx 448 | tx = zeros(1,n); 449 | for k=1:n 450 | clear Cx 451 | tic 452 | Cx = mtimesx(A,B); 453 | tx(k) = toc; 454 | end 455 | % results 456 | tm = median(tm); 457 | tx = median(tx); 458 | if( tx < tm ) 459 | faster = sprintf('%7.1f',100*(tm)/tx-100); 460 | slower = ''; 461 | else 462 | faster = sprintf('%7.1f',-(100*(tx)/tm-100)); 463 | slower = ' (i.e., slower)'; 464 | end 465 | Cr{6,m} = faster; 466 | disp(' '); 467 | disp(['bsxfun Elapsed time ' num2str(tm) ' seconds.']); 468 | disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']); 469 | disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB bsxfun with @times' slower]) 470 | if( isequal(Cx,Cm) ) 471 | disp(['MTIMESX ' mtimesx ' mode result matches bsxfun with @times: EQUAL']) 472 | else 473 | dx = max(abs(Cx(:)-Cm(:))); 474 | disp(['MTIMESX ' mtimesx ' mode result does not match bsxfun with @times: NOT EQUAL , max diff = ' num2str(dx)]) 475 | end 476 | catch 477 | disp('Could not perform comparison with bsxfun, possibly because your version of'); 478 | disp('MATLAB does not have it. You can download a substitute for bsxfun from the'); 479 | disp('FEX here: http://www.mathworks.com/matlabcentral/fileexchange/23005-bsxfun-substitute'); 480 | end 481 | 482 | end 483 | 484 | disp(' '); 485 | disp('Percent Faster Results Table'); 486 | disp(' '); 487 | disp(Cr); 488 | 489 | disp(' '); 490 | disp('Done'); 491 | disp(' '); 492 | 493 | end 494 | -------------------------------------------------------------------------------- /private/mv2nat.m: -------------------------------------------------------------------------------- 1 | function [eta1, eta2] = mv2nat(mu, Sigma) 2 | % Natural parameters of a Gaussian from mean and covariance 3 | 4 | eta1 = Sigma \ mu(:); 5 | eta2 = -0.5 * inv(Sigma); 6 | 7 | eta1 = reshape(eta1, size(mu)); -------------------------------------------------------------------------------- /private/nat2mv.m: -------------------------------------------------------------------------------- 1 | function [mu, Sigma] = nat2mv(eta1, eta2) 2 | % Mean and covariance of a Gaussian from natural parameters 3 | 4 | Sigma = inv( -2 * eta2 ); 5 | mu = Sigma * eta1(:); 6 | 7 | mu = reshape(mu, size(eta1)); -------------------------------------------------------------------------------- /private/resampling.m: -------------------------------------------------------------------------------- 1 | function i = resampling(q, type) 2 | M = length(q); 3 | 4 | if(type == 1) % -- Multinomial, 'simple' from 'sigsys/resample.m' 5 | u = rand(M,1); 6 | qc = cumsum(q); 7 | qc = qc(:); 8 | qc=qc/qc(M); 9 | [~,ind1]=sort([u;qc]); 10 | ind2=find(ind1<=M); 11 | i=ind2'-(0:M-1); 12 | elseif(type == 2) % -- Systematic 13 | qc = cumsum(q); 14 | u = ((0:M-1)+rand(1))/M; 15 | i = zeros(1,M); k = 1; 16 | for j = 1:M 17 | while(qc(k) numLagSteps 59 | Xfixedlag(i-numLagSteps,:,:,1) = X(i-numLagSteps, :,:); % @ t 60 | Xfixedlag(i-numLagSteps,:,:,2) = X(i-numLagSteps+1,:,:); % @ t+1 61 | end 62 | end 63 | %disp([char(8) ', ESS: ' num2str(round(ess(w)))]) 64 | disp([char(8) ', Unique: ' num2str(numel(unique(X(i-numLagSteps,:,:))))]) 65 | 66 | % End of trajectories 67 | Xfixedlag(i-numLagSteps+1:end,:,:,1) = X(i-numLagSteps+1:end-1,:,:); 68 | Xfixedlag(i-numLagSteps+1:end,:,:,2) = X(i-numLagSteps+2:end, :,:); 69 | % Remove data at edges 70 | Xfixedlag = Xfixedlag(1+numLeftEdge:end-numRightEdge,:,:,:); 71 | 72 | if any(isnan(Xfixedlag(:))) 73 | keyboard 74 | end 75 | 76 | end 77 | 78 | 79 | 80 | function trtrm = TraceTerm(Q, B, A, Sigma) 81 | % Compute: -1/2 * trace(inv(Q) * (A * Sigma * A')) 82 | 83 | [~,M,numParticles] = size(A); 84 | D = size(Sigma, 1) / M; 85 | Y = nan(D,D,numParticles); 86 | % TODO could exploit symmetry and use some tensor product library 87 | ii = 1:M; 88 | 89 | if isdiag(Q) 90 | invQ = inv(Q); 91 | ASigmaAt = nan(numParticles, 1); 92 | trtrm = zeros(numParticles, 1); 93 | for d = 1:D 94 | ASigmaAt = sum((P321(A) * Sigma((d-1)*M+ii, (d-1)*M+ii)) .* P321(A), 2); 95 | trtrm = trtrm + invQ(d,d) * (B + ASigmaAt); 96 | end 97 | trtrm = -0.5 * trtrm; 98 | else 99 | for i = 0:D-1 100 | for j = 0:D-1 101 | for k = 1:numParticles 102 | Y(i+1,j+1,k) = A(1,:,k) * Sigma(i*M+ii, j*M+ii) * permute(A(1,:,k),[2 1 3]); 103 | end 104 | if i == j 105 | Y(i+1,j+1,:) = P321(B) + Y(i+1,j+1,:); 106 | end 107 | %Y(i+1,j+1,:) = bsxfun(@times, A, bsxfun(@times, Sigma(i*M+ii, j*M+ii), permute(A,[2 1 3]))); 108 | end 109 | end 110 | % TODO could use some tensor product library 111 | invQ = inv(Q); 112 | for k = 1:numParticles 113 | Y(:,:,k) = invQ * Y(:,:,k); 114 | end 115 | % Compute trace 116 | trtrm = Y(1,1,:); 117 | for d = 2:D 118 | trtrm = trtrm + Y(d,d,:); 119 | end 120 | trtrm = -0.5 * trtrm; 121 | trtrm = P321(trtrm); 122 | end 123 | 124 | 125 | end 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /private/sgdstep.m: -------------------------------------------------------------------------------- 1 | function [theta, state] = sgdstep(alg, theta, state, grad, hypers) 2 | 3 | switch alg 4 | case 'Adam' 5 | % Kingma and Ba 2015, Adam: a Method for Stochastic Optimization 6 | state.t = state.t + 1; 7 | thisbeta1 = hypers.beta1 * hypers.lambda ^ (state.t - 1); 8 | state.m = thisbeta1 * state.m + (1 - thisbeta1) * grad; 9 | state.v = hypers.beta2 * state.v + (1 - hypers.beta2) * grad .^ 2; 10 | mhat = state.m / (1 - hypers.beta1 ^ state.t); 11 | vhat = state.v / (1 - hypers.beta2 ^ state.t); 12 | theta = theta - hypers.alpha * mhat ./ (sqrt(vhat) + hypers.epsilon); 13 | 14 | case 'RMSProp' 15 | % Tieleman, T. and Hinton, G. (2012), Lecture 6.5 - rmsprop, COURSERA: Neural Networks for Machine Learning 16 | state.r = (1 - hypers.gamma) * grad .^2 + hypers.gamma * state.r; 17 | v = hypers.alpha * grad ./ sqrt(state.r); 18 | theta = theta - v; 19 | end 20 | 21 | end -------------------------------------------------------------------------------- /private/stacksigma.m: -------------------------------------------------------------------------------- 1 | function Sigma2 = stacksigma(Sigma, numStates) 2 | 3 | n = size(Sigma,1) / numStates; 4 | Sigma2 = nan(n, n, numStates); 5 | for i = 1:numStates 6 | ii = (i-1)*n+1:i*n; 7 | Sigma2(:,:,i) = Sigma(ii,ii); 8 | end 9 | 10 | end -------------------------------------------------------------------------------- /private/test_sgdstep.m: -------------------------------------------------------------------------------- 1 | function test_sgdstep() 2 | 3 | theta = [50; 2]; 4 | 5 | % Adam hyper-parameters 6 | hypers.alpha = 6e-1; 7 | hypers.beta1 = 0.9; 8 | hypers.beta2 = 0.999; 9 | hypers.epsilon = 1e-8; 10 | hypers.lambda = 1 - 1e-8; 11 | % Initialise state 12 | state.t = 0; 13 | state.m = zeros(size(theta)); 14 | state.v = state.m; 15 | 16 | 17 | % Optimise for a fixed number of iterations 18 | numIter = 1000; 19 | figure; hold on 20 | f = nan(numIter,1); 21 | theta = [theta, nan(size(theta,1), numIter)]; 22 | for t = 1:numIter 23 | [f(t),grad] = onehump(theta(:,t)); 24 | [theta(:,t+1), state] = sgdstep('Adam', theta(:,t), state, grad, hypers); 25 | end 26 | plot(theta(1,:), theta(2,:), 'k.-') 27 | 28 | 29 | % RMSProp 30 | clear hyper state 31 | hypers.alpha = .1; 32 | hypers.gamma = 0.9; 33 | state.r = zeros(size(theta,1), 1); 34 | for t = 1:numIter 35 | [f(t),grad] = onehump(theta(:,t)); 36 | [theta(:,t+1), state] = sgdstep('RMSProp', theta(:,t), state, grad, hypers); 37 | end 38 | plot(theta(1,:), theta(2,:), 'r.-') 39 | 40 | end 41 | 42 | -------------------------------------------------------------------------------- /private/whiten.m: -------------------------------------------------------------------------------- 1 | function [Z, mu, R] = whiten(X) 2 | % Whiten matrix X where each row is a datapoint so that: Z = (X-mu) * R 3 | % where Z has zero mean and identity covariance matrix. 4 | 5 | mu = mean(X); 6 | Z = bsxfun(@minus, X, mu); 7 | 8 | Sigma = cov(Z); 9 | [U,S,V] = svd(Sigma); 10 | epsilon = 1e-9; 11 | R = U * diag(1./sqrt(diag(S) + epsilon)) * U'; 12 | Z = Z * R; 13 | 14 | end -------------------------------------------------------------------------------- /test_script1d.m: -------------------------------------------------------------------------------- 1 | function test_script1d() 2 | 3 | options.numStates = 1; 4 | options.bDerivativeStates = false; % define state as x = (q, qdot) 5 | options.optimisation.alg = 'RMSProp'; 6 | options.px0 = {zeros(options.numStates,1) zeros(options.numStates, options.numStates)}; % mean and cov of p(x_0) 7 | options.qxstar.type = 'SMC'; % How to get q*(x_{0:T}) 8 | options.qxstar.numParticles = 300; 9 | options.qxstar.numLagSteps = 3; 10 | options.gpf.meanfun = @(x) 0 * x(:, 1:options.numStates); 11 | options.gpf.covfun = @covMaternard3; 12 | options.gpf.theta0 = []; 13 | options.gpf.numInducingPoints = 20; 14 | options.q.type = 'Diagonal'; 15 | options.lik.type = 'Lin+GaussianDiag'; % GP+Gaussian, Student, function handle, etc. 16 | options.lik.theta0 = []; 17 | options.ini.strategy = 'LinearSubSpace'; 18 | options.convergence.type = 'FixedIter'; 19 | options.convergence.numIter = 50; 20 | options.minibatch.type = 'Uniform'; 21 | options.minibatch.lengthMiniBatch = 100; 22 | options.minibatch.edgeLength = 10; 23 | options.inifun = @InitialiseParameters1d; 24 | options.debugplot = @Plot1DSystem; 25 | 26 | Y = generatedata(); 27 | U = zeros(size(Y,1), 2); 28 | vgpssm(Y, U, options) 29 | 30 | end 31 | 32 | 33 | 34 | function P = InitialiseParameters1d(S, options) 35 | 36 | % Inducing inputs (spherical Gaussian + random selection of inputs) 37 | P.Z = [ 3 * randn(options.gpf.numInducingPoints, options.numStates) ... 38 | S.U(randperm(size(S.U,1), options.gpf.numInducingPoints),:)]; 39 | 40 | % GP covfun hyper-parameters 41 | if ~isempty(options.gpf.theta0) 42 | P.theta.gp = options.gpf.theta0; 43 | else 44 | sigmaf = 1.6; 45 | P.theta.gp = [ 1.8 + zeros(size(P.Z, 2), 1); log(sigmaf)]; 46 | end 47 | 48 | % State transition noise 49 | P.theta.Q = eye(options.numStates); 50 | 51 | % Dynamics initialisation 52 | switch options.ini.strategy 53 | % Sample initial mean q(u) from prior p(u) 54 | case 'LinearSubSpace' 55 | % Use linear subspace identification method for initialisation 56 | data = iddata(S.Y, S.U); 57 | sys = n4sid(data, options.numStates); 58 | % convert to discrete ss model!!!!!!! 59 | mu = sys.A * P.Z(:,1:options.numStates)' + sys.B * P.Z(:,options.numStates+1:end)'; 60 | mu = mu'; 61 | case 'RandomNonlinear' 62 | % TODO 63 | case 'MarginallyStableLinear' 64 | % TODO 65 | end 66 | % Initialisation of Sigma will have an influence on smoother 67 | %tmp = feval(options.gpf.covfun, P.theta.gp, P.Z); 68 | tmp = 4^2 * eye(options.gpf.numInducingPoints); 69 | Sigma = blkdiagn(tmp, options.numStates); 70 | [P.eta1new, P.eta2new] = mv2nat(mu, Sigma);function plot1dsystem(P,options) 71 | 72 | [mu,Sigma] = nat2mv(P.eta1new, P.eta2new); 73 | 74 | plot(P.Z(:,1), mu(:,1),'o') 75 | hold on 76 | %plot([-6 4 6],[-5 5 -3],'g','LineWidth',2) 77 | plot([-6 4 6],[-5 5 -3]-[-6 4 6],'g','LineWidth',2) 78 | 79 | xstar = linspace(-6,6,300)'; 80 | 81 | Kuu = options.gpf.covfun(P.theta.gp, P.Z); 82 | L = chol(Kuu + 1e-6 * Kuu(1,1) * eye(size(Kuu))); 83 | xu = [xstar zeros(size(xstar,1), 2)]; 84 | Kmu = options.gpf.covfun(P.theta.gp, xu, P.Z); 85 | A = (Kmu / L) / L'; 86 | V = L' \ Kmu'; 87 | B = options.gpf.covfun(P.theta.gp, xu, 'diag') - sum(V.*V, 1)'; 88 | plot(xstar, A * mu, 'b') 89 | if true 90 | % plot(xstar, A * mu + 2 * sqrt(B), 'r') 91 | % plot(xstar, A * mu - 2 * sqrt(B), 'r') 92 | ASA = diag(A * Sigma * A'); 93 | plot(xstar, A * mu + 2 * sqrt(B + ASA), 'm') 94 | plot(xstar, A * mu - 2 * sqrt(B + ASA), 'm') 95 | end 96 | 97 | end 98 | 99 | % Likelihood 100 | P.theta.lik = options.lik.theta0; 101 | switch options.lik.type 102 | case 'Lin+GaussianDiag' 103 | if options.numStates >= size(S.Y, 2) 104 | P.theta.lik.C = [eye(size(S.Y, 2)) zeros(size(S.Y, 2), options.numStates-size(S.Y, 2))]; 105 | end 106 | end 107 | % TODO: This should be initialised with the noise estimated when 108 | % initialising the dynamics. 109 | P.theta.lik.R = eye(size(S.Y, 2)); 110 | 111 | end 112 | 113 | 114 | 115 | function out = generatedata() 116 | % Generate data from nonlin system (no external inputs). 117 | 118 | persistent X 119 | 120 | T = 1e4; 121 | 122 | if isempty(X) 123 | X = nan(T,1); 124 | X(1) = 0; 125 | for i = 2:T 126 | X(i) = nonlin(X(i-1)); 127 | end 128 | end 129 | out = X; 130 | 131 | end 132 | 133 | 134 | 135 | function xp = nonlin(x) 136 | % Very simple piece-wise linear system like in Andrew's paper. 137 | 138 | if x < 4 139 | xp = x + 1; 140 | else 141 | xp = -4*x + 21; 142 | end 143 | 144 | %xp = -0.8 * x; 145 | 146 | q = 1^2; 147 | xp = xp + sqrt(q) * randn(1); 148 | 149 | end 150 | 151 | 152 | 153 | function Plot1DSystem(P,options) 154 | 155 | [mu,Sigma] = nat2mv(P.eta1new, P.eta2new); 156 | 157 | plot(P.Z(:,1), mu(:,1),'o') 158 | hold on 159 | meanType = 'identity'; 160 | switch meanType 161 | case 'identity' 162 | plot([-6 4 6],[-5 5 -3],'g','LineWidth',2) 163 | case 'zero' 164 | plot([-6 4 6],[-5 5 -3]-[-6 4 6],'g','LineWidth',2) 165 | end 166 | xstar = linspace(-6,6,300)'; 167 | 168 | Kuu = options.gpf.covfun(P.theta.gp, P.Z); 169 | L = chol(Kuu + 1e-6 * Kuu(1,1) * eye(size(Kuu))); 170 | xu = [xstar zeros(size(xstar,1), 2)]; 171 | Kmu = options.gpf.covfun(P.theta.gp, xu, P.Z); 172 | A = (Kmu / L) / L'; 173 | V = L' \ Kmu'; 174 | B = options.gpf.covfun(P.theta.gp, xu, 'diag') - sum(V.*V, 1)'; 175 | plot(xstar, A * mu, 'b') 176 | if true 177 | % plot(xstar, A * mu + 2 * sqrt(B), 'r') 178 | % plot(xstar, A * mu - 2 * sqrt(B), 'r') 179 | ASA = diag(A * Sigma * A'); 180 | plot(xstar, A * mu + 2 * sqrt(B + ASA), 'm') 181 | plot(xstar, A * mu - 2 * sqrt(B + ASA), 'm') 182 | end 183 | 184 | end 185 | -------------------------------------------------------------------------------- /test_script2d.m: -------------------------------------------------------------------------------- 1 | function test_script2d() 2 | 3 | options.numStates = 2; 4 | options.bDerivativeStates = false; % define state as x = (q, qdot) 5 | options.optimisation.alg = 'RMSProp'; 6 | options.px0 = {zeros(options.numStates,1) zeros(options.numStates, options.numStates)}; % mean and cov of p(x_0) 7 | options.qxstar.type = 'SMC'; % How to get q*(x_{0:T}) 8 | options.qxstar.numParticles = 100; 9 | options.qxstar.numLagSteps = 3; 10 | options.gpf.meanfun = @(x) x(:, 1:options.numStates); 11 | options.gpf.covfun = @covMaternard3; 12 | options.gpf.theta0 = []; 13 | options.gpf.numInducingPoints = 20; 14 | options.q.type = 'Diagonal'; 15 | options.lik.type = 'Lin+GaussianDiag'; % GP+Gaussian, Student, function handle, etc. 16 | options.lik.theta0 = []; 17 | options.ini.strategy = 'LinearSubSpace'; 18 | options.convergence.type = 'FixedIter'; 19 | options.convergence.numIter = 200; 20 | options.minibatch.type = 'Uniform'; 21 | options.minibatch.lengthMiniBatch = 50; 22 | options.minibatch.edgeLength = 10; 23 | options.inifun = @InitialiseParameters2d; 24 | options.debugplot = @Plot2DSystem; 25 | 26 | [Y, U] = generatedata(); 27 | vgpssm(Y, U, options) 28 | 29 | end 30 | 31 | 32 | function P = InitialiseParameters2d(S, options) 33 | % TODO: update this has hard coded stuff and won not work in general!!!! 34 | 35 | % Inducing inputs (spherical Gaussian + random selection of inputs) 36 | P.Z = [ 3 * randn(options.gpf.numInducingPoints, options.numStates) ... 37 | S.U(randperm(size(S.U,1), Plot2DSystemoptions.gpf.numInducingPoints),:)]; 38 | 39 | % GP covfun hyper-parameters 40 | if ~isempty(options.gpf.theta0) 41 | P.theta.gp = options.gpf.theta0; 42 | else 43 | sigmaf = 1.6; 44 | P.theta.gp = [ 2.3 + zeros(size(P.Z, 2), 1); log(sigmaf)]; 45 | end 46 | 47 | % State transition noise 48 | P.theta.Q = eye(options.numStates); 49 | 50 | 51 | % Dynamics initialisation 52 | switch options.ini.strategy 53 | % Sample initial mean q(u) from prior p(u) 54 | case 'LinearSubSpace' 55 | % Use linear subspace identification method for initialisation 56 | data = iddata(S.Y, S.U); 57 | sys = n4sid(data, options.numStates); 58 | % convert to discrete ss model!!!!!!! 59 | mu = sys.A * P.Z(:,1:options.numStates)' + sys.B * P.Z(:,options.numStates+1:end)'; 60 | mu = mu' - options.gpf.meanfun(P.Z); 61 | disp('N4SID C matrix: ') 62 | disp(sys.C) 63 | case 'RandomNonlinear' 64 | % TODO 65 | case 'MarginallyStableLinear' 66 | % TODO 67 | end 68 | 69 | % Likelihood 70 | P.theta.lik = options.lik.theta0; 71 | switch options.lik.type 72 | case 'Lin+GaussianDiag' 73 | if options.numStates >= size(S.Y, 2) 74 | P.theta.lik.C = [eye(size(S.Y, 2)) zeros(size(S.Y, 2), options.numStates-size(S.Y, 2))]; 75 | end 76 | end 77 | % TODO: This should be initialised with the noise estimated when 78 | % initialising the dynamics. 79 | P.theta.lik.R = eye(size(S.Y, 2)); 80 | 81 | % Initialisation of Sigma will have an influence on smoother 82 | %tmp = feval(options.gpf.covfun, P.theta.gp, P.Z); 83 | tmp = 1^2 * eye(options.gpf.numInducingPoints); 84 | Sigma = blkdiagn(tmp, options.numStates); 85 | [P.eta1new, P.eta2new] = mv2nat(mu, Sigma); 86 | 87 | end 88 | 89 | 90 | function [Y, U] = generatedata() 91 | % Generate data from nonlin system (no external inputs). 92 | 93 | persistent X 94 | 95 | T = 1e4; 96 | U = randn(T,0); 97 | if isempty(X) 98 | A = [0 1; -1 -1]; 99 | B = []; 100 | C = eye(2); 101 | D = []; 102 | dt = 0.4; 103 | dsys = c2d(ss(A,B,C,D), dt); 104 | 105 | X = nan(T,2); 106 | X(1,:) = [1 1]; 107 | for i = 2:T 108 | X(i,:) = (dsys.A * X(i-1,:)')' + randn(1,2); 109 | end 110 | end 111 | Y = X * [1 0]'; % no observation noise! 112 | 113 | end 114 | 115 | 116 | function Plot2DSystem(P,options) 117 | 118 | [mu,Sigma] = nat2mv(P.eta1new, P.eta2new); 119 | 120 | % Ground truth 121 | % x1 x2 122 | % x1 0.9306 0.321 123 | % x2 -0.321 0.6096 124 | A = [0.9306 0.321; -0.321 0.6096]; 125 | 126 | 127 | type = 'DoNotPlotMean'; 128 | switch type 129 | case 'PlotMean' 130 | m = options.gpf.meanfun(P.Z); 131 | subplot(121) 132 | plot3(P.Z(:,1), P.Z(:,2), m(:,1) + mu(:,1), 'bo') 133 | grid on; rotate3d on 134 | subplot(122) 135 | plot3(P.Z(:,1), P.Z(:,2), m(:,2) + mu(:,2), 'bo') 136 | grid on; rotate3d on 137 | 138 | xlims = get(gca,'XLim'); 139 | ylims = get(gca,'YLim'); 140 | [X1,X2] = meshgrid(linspace(xlims(1),xlims(2),10), linspace(ylims(1),ylims(2),10)); 141 | subplot(121) 142 | hold on 143 | surf(X1, X2, reshape([X1(:) X2(:)] * A(1,:)', size(X1)),'FaceColor','none') 144 | subplot(122) 145 | hold on 146 | surf(X1, X2, reshape([X1(:) X2(:)] * A(2,:)', size(X1)),'FaceColor','none') 147 | 148 | 149 | case 'DoNotPlotMean' 150 | subplot(121) 151 | plot3(P.Z(:,1), P.Z(:,2), mu(:,1), 'bo') 152 | grid on; rotate3d on 153 | subplot(122) 154 | plot3(P.Z(:,1), P.Z(:,2), mu(:,2), 'bo') 155 | grid on; rotate3d on 156 | 157 | xlims = get(gca,'XLim'); 158 | ylims = get(gca,'YLim'); 159 | [X1,X2] = meshgrid(linspace(xlims(1),xlims(2),10), linspace(ylims(1),ylims(2),10)); 160 | m = options.gpf.meanfun([X1(:) X2(:)]); 161 | subplot(121) 162 | hold on 163 | mesh(X1, X2, reshape([X1(:) X2(:)] * A(1,:)' - m(:,1), size(X1)),'EdgeColor',[0 0 0]) 164 | subplot(122) 165 | hold on 166 | mesh(X1, X2, reshape([X1(:) X2(:)] * A(2,:)' - m(:,2), size(X1)),'EdgeColor',[0 0 0]) 167 | end 168 | % Compute error metric 169 | pred = options.gpf.meanfun(P.Z) + mu; 170 | truth = P.Z * A'; 171 | disp([char(8) ', err:' num2str( sqrt( sum(sum( (pred-truth).^2 )) ) )]) 172 | %disp([pred truth pred-truth]) 173 | 174 | 175 | % Plot prediction 176 | [mu,Sigma] = nat2mv(P.eta1new, P.eta2new); 177 | xstar = [X1(:) X2(:)]; 178 | Kuu = options.gpf.covfun(P.theta.gp, P.Z); 179 | L = chol(Kuu + 1e-6 * Kuu(1,1) * eye(size(Kuu))); 180 | Kmu = options.gpf.covfun(P.theta.gp, xstar, P.Z); 181 | A = (Kmu / L) / L'; 182 | V = L' \ Kmu'; 183 | B = options.gpf.covfun(P.theta.gp, xstar, 'diag') - sum(V.*V, 1)'; 184 | subplot(121) 185 | hold on 186 | mesh(X1, X2, reshape(A * mu(:,1), size(X1)),'FaceColor','none','EdgeColor',[0 0 1]) 187 | ASA = diag(A * Sigma(1:20,1:20) * A'); 188 | mesh(X1, X2, reshape(A * mu(:,1) + 2 * sqrt(B + ASA), size(X1)),'FaceColor','none','EdgeColor',[1 0 1]) 189 | mesh(X1, X2, reshape(A * mu(:,1) - 2 * sqrt(B + ASA), size(X1)),'FaceColor','none','EdgeColor',[1 0 1]) 190 | subplot(122) 191 | hold on 192 | mesh(X1, X2, reshape(A * mu(:,2), size(X1)),'FaceColor','none','EdgeColor',[0 0 1]) 193 | ASA = diag(A * Sigma(21:40,21:40) * A'); 194 | mesh(X1, X2, reshape(A * mu(:,2) + 2 * sqrt(B + ASA), size(X1)),'FaceColor','none','EdgeColor',[1 0 1]) 195 | mesh(X1, X2, reshape(A * mu(:,2) - 2 * sqrt(B + ASA), size(X1)),'FaceColor','none','EdgeColor',[1 0 1]) 196 | 197 | end -------------------------------------------------------------------------------- /vgpssm.m: -------------------------------------------------------------------------------- 1 | function vgpssm(Y,U,options) 2 | %VGPSSM 3 | % 4 | % Roger Frigola, 2014-2015. 5 | 6 | % Check for gpml toolbox 7 | if ~exist('covSEard.m','file') 8 | error('Please start up GPML toolbox. It can be downloaded from http://www.gaussianprocess.org/gpml/code') 9 | end 10 | 11 | S.T = size(Y,1); 12 | S.numObs = size(Y,2); 13 | if nargin < 2, U = zeros(S.T,0); end 14 | S.numInputs = size(U,2); 15 | if nargin < 3, options = DefaultOptions(); end 16 | 17 | % Separately whiten inputs and outputs 18 | %[S.Y, S.whit.muY, S.whit.RY] = whiten(Y); 19 | %[S.U, S.whit.muU, S.whit.RU] = whiten(U); 20 | S.Y = Y; 21 | S.U = U; 22 | 23 | figure 24 | 25 | i = 1; % iteration number 26 | P = options.inifun(S, options); 27 | clear SGD; % clears persistent state 28 | while ~IsConverged(i, options) 29 | disp(['Iter: ' num2str(i)]) 30 | % Sample mini-batch 31 | [tt, numMiniBatches] = sampleminibatch(S.T, options); 32 | 33 | % Get samples from q*(x_{0:T}) 34 | switch options.qxstar.type 35 | case {'SMC' 'SMC_FixedLagSmoother'} 36 | % Use SMC fixed-lag smoother 37 | qxstar = sampleqxstar(S, tt, P, options); 38 | case 'Variational' 39 | % TODO: parameterised q(x) 40 | end 41 | 42 | % Get q*(u) 43 | P = GetOptimalqu(P, qxstar, S.U(tt,:), numMiniBatches, options); 44 | 45 | % Get parameter gradient (hyperparameters, pseudo-inputs, etc.) 46 | gradP = GetGradient(P, qxstar, S.U(tt,:), S.Y(tt,:), options); 47 | 48 | % Update q(u) 49 | if i < 20, rho = 0.8; else rho = 0.4 * (options.convergence.numIter-i)/options.convergence.numIter; end 50 | disp([char(8) ', rho: ' num2str(rho)]) 51 | P.eta1new = rho * P.eta1new + (1-rho) * P.eta1old; 52 | P.eta2new = rho * P.eta2new + (1-rho) * P.eta2old; 53 | 54 | % Update parameters 55 | if i < 50, gamma = 0; else gamma = 0.006 * (options.convergence.numIter-i)/options.convergence.numIter; end 56 | P.theta.lik.C = P.theta.lik.C + gamma * gradP.theta.lik.C; 57 | subplot(122); plot(i,P.theta.lik.C(1),'.'); hold on; 58 | %P = SGD(P, gradP, i, options); 59 | 60 | % DEBUG 61 | if true 62 | subplot(121) 63 | options.debugplot(P,options); drawnow 64 | end 65 | 66 | % Iteration number 67 | i = i + 1; 68 | end 69 | 70 | figure 71 | options.debugplot(P,options) 72 | keyboard 73 | 74 | % Unwhiten 75 | error('see p. 48') 76 | 77 | end 78 | 79 | 80 | 81 | % ----------------------------------------------------------------------- % 82 | function options = DefaultOptions() 83 | % Default options for vgpssm.m 84 | 85 | options.numStates = 2; 86 | options.bDerivativeStates = false; % define state as x = (q, qdot) 87 | options.optimisation.alg = 'RMSProp'; 88 | options.px0 = {zeros(options.numStates,1) zeros(options.numStates, options.numStates)}; % mean and cov of p(x_0) 89 | options.qxstar.type = 'SMC'; % How to get q*(x_{0:T}) 90 | options.qxstar.numParticles = 500; 91 | options.qxstar.numLagSteps = 3; 92 | options.gpf.meanfun = @(x) x(:, 1:options.numStates); 93 | options.gpf.covfun = @covMaternard3; 94 | options.gpf.theta0 = []; 95 | options.gpf.numInducingPoints = 20; 96 | options.q.type = 'Diagonal'; 97 | options.lik.type = 'Lin+GaussianDiag'; % GP+Gaussian, Student, function handle, etc. 98 | options.lik.theta0 = []; 99 | options.ini.strategy = 'LinearSubSpace'; 100 | options.convergence.type = 'FixedIter'; 101 | options.convergence.numIter = 100; 102 | options.minibatch.type = 'Uniform'; 103 | options.minibatch.lengthMiniBatch = 200; 104 | options.minibatch.edgeLength = 10; 105 | options.inifun = @DefaultInitialiseParameters; 106 | 107 | end 108 | 109 | 110 | function P = DefaultInitialiseParameters(S, options) 111 | % TODO: update this has hard coded stuff and won not work in general!!!! 112 | 113 | % Inducing inputs (spherical Gaussian + random selection of inputs) 114 | P.Z = [ 3 * randn(options.gpf.numInducingPoints, options.numStates) ... 115 | S.U(randperm(size(S.U,1), options.gpf.numInducingPoints),:)]; 116 | 117 | % GP covfun hyper-parameters 118 | if ~isempty(options.gpf.theta0) 119 | P.theta.gp = options.gpf.theta0; 120 | else 121 | sigmaf = 1.6; 122 | P.theta.gp = [ 2.3 + zeros(size(P.Z, 2), 1); log(sigmaf)]; 123 | end 124 | 125 | % State transition noise 126 | P.theta.Q = eye(options.numStates); 127 | 128 | % Dynamics initialisation 129 | switch options.ini.strategy 130 | % Sample initial mean q(u) from prior p(u) 131 | case 'LinearSubSpace' 132 | % Use linear subspace identification method for initialisation 133 | data = iddata(S.Y, S.U); 134 | sys = n4sid(data, options.numStates); 135 | % convert to discrete ss model!!!!!!! 136 | mu = sys.A * P.Z(:,1:options.numStates)' + sys.B * P.Z(:,options.numStates+1:end)'; 137 | mu = mu' - options.gpf.meanfun(P.Z); 138 | case 'RandomNonlinear' 139 | % TODO 140 | case 'MarginallyStableLinear' 141 | % TODO 142 | end 143 | 144 | % Likelihood 145 | P.theta.lik = options.lik.theta0; 146 | switch options.lik.type 147 | case 'Lin+GaussianDiag' 148 | if options.numStates >= size(S.Y, 2) 149 | P.theta.lik.C = [eye(size(S.Y, 2)) zeros(size(S.Y, 2), options.numStates-size(S.Y, 2))]; 150 | end 151 | end 152 | % TODO: This should be initialised with the noise estimated when 153 | % initialising the dynamics. 154 | P.theta.lik.R = eye(size(S.Y, 2)); 155 | 156 | % Initialisation of Sigma will have an influence on smoother 157 | %tmp = feval(options.gpf.covfun, P.theta.gp, P.Z); 158 | tmp = 1^2 * eye(options.gpf.numInducingPoints); 159 | Sigma = blkdiagn(tmp, options.numStates); 160 | [P.eta1new, P.eta2new] = mv2nat(mu, Sigma); 161 | 162 | end 163 | 164 | 165 | 166 | function P = SGD(P, gradP, etaOpt, i, options) 167 | % Wrapper for a stochastic gradient descent algorithm. 168 | 169 | persistent state 170 | if isempty(state) 171 | 172 | end 173 | 174 | [theta, state] = sgdstep(options.optimisation.alg, theta, state, grad, hypers); 175 | end 176 | 177 | 178 | 179 | function bConverged = IsConverged(i, options) 180 | % Convergence test for stochastic variational inference 181 | 182 | bConverged = 0; 183 | switch options.convergence.type 184 | case 'FixedIter' 185 | if i > options.convergence.numIter 186 | bConverged = 1; 187 | end 188 | otherwise 189 | error('Convergence criterion not recognised.') 190 | end 191 | 192 | end 193 | 194 | 195 | 196 | function P = GetOptimalqu(P, qxstar, U, numMiniBatches, options) 197 | % Computes optimal q(u) using samples of q*(x) 198 | 199 | P.eta1old = P.eta1new; 200 | P.eta2old = P.eta2new; 201 | 202 | numParticles = size(qxstar,3); 203 | M = options.gpf.numInducingPoints; 204 | Kuu = options.gpf.covfun(P.theta.gp, P.Z); 205 | invKuu = inv(Kuu + 1e-6 * eye(size(Kuu))); % FIXME: should only use L 206 | L = chol(Kuu + 1e-6 * Kuu(1,1) * eye(size(Kuu))); 207 | 208 | sum1 = zeros(numel(P.eta1new), 1); 209 | sum2 = zeros(size(P.eta2new)); 210 | % TODO: ideally, this loop should be avoided 211 | for i = 1:size(qxstar,1) 212 | xu = [P321(qxstar(i,:,:,1)) repmat(U(i,:), numParticles, 1)]; 213 | m = options.gpf.meanfun(xu); 214 | Kmu = options.gpf.covfun(P.theta.gp, xu, P.Z); 215 | A = (Kmu / L) / L'; % Kmu / Kuu 216 | 217 | % Monte Carlo estimates of the expectations 218 | %sum1 = sum1 + 1/numParticles * sum(bsxfun(@times, P321(qxstar(i,:,:,2)), A))'; 219 | tmp = P.theta.Q \ (P321(qxstar(i,:,:,2)) - m)'; 220 | for d = 1:options.numStates 221 | ii = 1+(d-1)*M : d*M; 222 | sum1(ii) = sum1(ii) + mean(bsxfun(@times, A', tmp(d,:)), 2); 223 | end 224 | 225 | %sum2 = sum2 + 1/numParticles * (A'*A); 226 | if ~isdiag(P.theta.Q) 227 | error('TODO: implement for nondiagonal Q'); 228 | else 229 | invQ = inv(P.theta.Q); 230 | tmp = 1/numParticles * (A'*A); 231 | for d = 1:options.numStates 232 | ii = 1+(d-1)*M : d*M; 233 | for e = 1:options.numStates 234 | if d ~= e, continue; end 235 | jj = 1+(e-1)*M : e*M; 236 | sum2(ii,jj) = sum2(ii,jj) + invQ(d,d) * tmp; 237 | end 238 | end 239 | end 240 | end 241 | 242 | % eta1 = theta.sqrtQ^-2 * numMiniBatches * sum1; 243 | % eta2 = -0.5 * (invKuu + numMiniBatches * sum2 * theta.sqrtQ^-2); 244 | 245 | P.eta1new = numMiniBatches * sum1 + blkdiagn(invKuu, options.numStates) * reshape(options.gpf.meanfun(P.Z),[],1); 246 | P.eta1new = reshape(P.eta1new, [], options.numStates); 247 | P.eta2new = -0.5 * (blkdiagn(invKuu, options.numStates) + numMiniBatches * sum2); 248 | 249 | end 250 | 251 | 252 | 253 | function gradP = GetGradient(P, qxstar, U, Y, options) 254 | % Gradient of the ELBO with respect to various parameters 255 | 256 | gradP = P; 257 | 258 | % Reuse Monte Carlo estimates of expectations from qstaru 259 | [mu, Sigma] = nat2mv(P.eta1new, P.eta2new); 260 | Sigma = stacksigma(Sigma, options.numStates); 261 | Kuu = options.gpf.covfun(P.theta.gp, P.Z); 262 | invKuu = inv(Kuu + 1e-6 * eye(size(Kuu))); % FIXME: should only use L 263 | L = chol(Kuu + 1e-6 * Kuu(1,1) * eye(size(Kuu))); 264 | alpha = Kuu \ (mu - options.gpf.meanfun(P.Z)); 265 | 266 | % Pre-compute all necessary expectations wrt the smoothing distribution 267 | phi6 = zeros(size(Y,2), 1); 268 | phi7 = zeros(size(Y,2), numel(P.theta.lik.C)); 269 | % TODO: ideally, this loop should be avoided 270 | numParticles = options.qxstar.numParticles; 271 | for i = 1:size(qxstar,1) 272 | xu = [P321(qxstar(i,:,:,1)) repmat(U(i,:), numParticles, 1)]; 273 | m = options.gpf.meanfun(xu); 274 | Kmu = options.gpf.covfun(P.theta.gp, xu, P.Z); 275 | A = (Kmu / L) / L'; % Kmu / Kuu 276 | 277 | % phi 6 278 | ztild = bsxfun(@minus, Y(i,:)', P.theta.lik.C * permute(qxstar(i,:,:,2), [2 3 1]) ); 279 | phi6 = phi6 + mean(ztild .* ztild, 2); 280 | 281 | % phi 7 282 | for j = 1:numel(P.theta.lik.C) 283 | dCdtheta = zeros(size(P.theta.lik.C)); 284 | dCdtheta(j) = 1; 285 | phi7(:,j) = phi7(:,j) + mean(ztild .* (dCdtheta * permute(qxstar(i,:,:,2), [2 3 1])), 2); 286 | end 287 | 288 | % % Monte Carlo estimates of the expectations 289 | % %sum1 = sum1 + 1/numParticles * sum(bsxfun(@times, P321(qxstar(i,:,:,2)), A))'; 290 | % tmp = P.theta.Q \ (P321(qxstar(i,:,:,2)) - m)'; 291 | % for d = 1:options.numStates 292 | % ii = 1+(d-1)*M : d*M; 293 | % sum1(ii) = sum1(ii) + mean(bsxfun(@times, A', tmp(d,:)), 2); 294 | % end 295 | % 296 | % %sum2 = sum2 + 1/numParticles * (A'*A); 297 | % if ~isdiag(P.theta.Q) 298 | % error('TODO: implement for nondiagonal Q'); 299 | % else 300 | % invQ = inv(P.theta.Q); 301 | % tmp = 1/numParticles * (A'*A); 302 | % for d = 1:options.numStatesfunction P = SGD(P, gradP, etaOpt, i, options) 303 | % Wrapper for a stochastic gradient descent algorithm. 304 | % ii = 1+(d-1)*M : d*M; 305 | % for e = 1:options.numStates 306 | % if d ~= e, continue; end 307 | % jj = 1+(e-1)*M : e*M; 308 | % sum2(ii,jj) = sum2(ii,jj) + invQ(d,d) * tmp; 309 | % end 310 | % end 311 | % end 312 | end 313 | % TODO: normalise by num of minibatches as we do for eta1 and eta2 314 | 315 | 316 | % Inducing inputs: P.Z 317 | % dK 318 | % gradP.Z = AssembleGrad(); 319 | 320 | % GP hyper-parameters: P.theta.gp 321 | for i = 1:numel(P.theta.gp) 322 | tmp = 0; 323 | dKdtheta = options.gpf.covfun(P.theta.gp, P.Z, [], i); 324 | % Prior KL term 325 | for j = 1: options.numStates 326 | alphaalpha = alpha(:,j) * alpha(:,j)'; 327 | tmp = tmp + 0.5 * trace(dKdtheta * (alphaalpha + invKuu * (Sigma(:,:,j) - eye(options.gpf.numInducingPoints)) )); 328 | end 329 | % Trace term 330 | dAdtheta = []; 331 | dBdtheta = []; 332 | 333 | % Dynamics term 334 | 335 | 336 | gradP.theta.gp(i) = tmp; 337 | end 338 | 339 | % State noise: P.theta.Q 340 | % Trace term 341 | 342 | % Dynamics term 343 | 344 | gradP.theta.Q = []; 345 | 346 | 347 | % Linear likelihood: P.theta.lik.C 348 | % Data term 349 | for i = 1:numel(P.theta.lik.C) 350 | gradP.theta.lik.C(i) = diag(inv(P.theta.lik.R))' * phi7(:,i); 351 | end 352 | 353 | % Linear likelihood: P.theta.lik.R, TODO: should reparameterise this! 354 | % Data term 355 | invR = inv(P.theta.lik.R); 356 | for i = 1:size(P.theta.lik.R,1) 357 | dRdtheta = zeros(size(invR)); 358 | dRdtheta(i,i) = 1; 359 | gradP.theta.lik.R(i,i) = - 0.5 * trace(invR * dRdtheta(i,i)) ... 360 | + 0.5 * diag(invR * dRdtheta * invR)' * phi6; 361 | end 362 | 363 | end 364 | 365 | --------------------------------------------------------------------------------