plateform
stringclasses 1
value | repo_name
stringlengths 13
113
| name
stringlengths 3
74
| ext
stringclasses 1
value | path
stringlengths 12
229
| size
int64 23
843k
| source_encoding
stringclasses 9
values | md5
stringlengths 32
32
| text
stringlengths 23
843k
|
---|---|---|---|---|---|---|---|---|
github
|
wgshun/AndrewNG-Machinelearning-master
|
submit.m
|
.m
|
AndrewNG-Machinelearning-master/homework/machine-learning-ex1/machine-learning-ex1/ex1/submit.m
| 1,876 |
utf_8
|
8d1c467b830a89c187c05b121cb8fbfd
|
function submit()
addpath('./lib');
conf.assignmentSlug = 'linear-regression';
conf.itemName = 'Linear Regression with Multiple Variables';
conf.partArrays = { ...
{ ...
'1', ...
{ 'warmUpExercise.m' }, ...
'Warm-up Exercise', ...
}, ...
{ ...
'2', ...
{ 'computeCost.m' }, ...
'Computing Cost (for One Variable)', ...
}, ...
{ ...
'3', ...
{ 'gradientDescent.m' }, ...
'Gradient Descent (for One Variable)', ...
}, ...
{ ...
'4', ...
{ 'featureNormalize.m' }, ...
'Feature Normalization', ...
}, ...
{ ...
'5', ...
{ 'computeCostMulti.m' }, ...
'Computing Cost (for Multiple Variables)', ...
}, ...
{ ...
'6', ...
{ 'gradientDescentMulti.m' }, ...
'Gradient Descent (for Multiple Variables)', ...
}, ...
{ ...
'7', ...
{ 'normalEqn.m' }, ...
'Normal Equations', ...
}, ...
};
conf.output = @output;
submitWithConfiguration(conf);
end
function out = output(partId)
% Random Test Cases
X1 = [ones(20,1) (exp(1) + exp(2) * (0.1:0.1:2))'];
Y1 = X1(:,2) + sin(X1(:,1)) + cos(X1(:,2));
X2 = [X1 X1(:,2).^0.5 X1(:,2).^0.25];
Y2 = Y1.^0.5 + Y1;
if partId == '1'
out = sprintf('%0.5f ', warmUpExercise());
elseif partId == '2'
out = sprintf('%0.5f ', computeCost(X1, Y1, [0.5 -0.5]'));
elseif partId == '3'
out = sprintf('%0.5f ', gradientDescent(X1, Y1, [0.5 -0.5]', 0.01, 10));
elseif partId == '4'
out = sprintf('%0.5f ', featureNormalize(X2(:,2:4)));
elseif partId == '5'
out = sprintf('%0.5f ', computeCostMulti(X2, Y2, [0.1 0.2 0.3 0.4]'));
elseif partId == '6'
out = sprintf('%0.5f ', gradientDescentMulti(X2, Y2, [-0.1 -0.2 -0.3 -0.4]', 0.01, 10));
elseif partId == '7'
out = sprintf('%0.5f ', normalEqn(X2, Y2));
end
end
|
github
|
wgshun/AndrewNG-Machinelearning-master
|
submitWithConfiguration.m
|
.m
|
AndrewNG-Machinelearning-master/homework/machine-learning-ex1/machine-learning-ex1/ex1/lib/submitWithConfiguration.m
| 5,562 |
utf_8
|
4ac719ea6570ac228ea6c7a9c919e3f5
|
function submitWithConfiguration(conf)
addpath('./lib/jsonlab');
parts = parts(conf);
fprintf('== Submitting solutions | %s...\n', conf.itemName);
tokenFile = 'token.mat';
if exist(tokenFile, 'file')
load(tokenFile);
[email token] = promptToken(email, token, tokenFile);
else
[email token] = promptToken('', '', tokenFile);
end
if isempty(token)
fprintf('!! Submission Cancelled\n');
return
end
try
response = submitParts(conf, email, token, parts);
catch
e = lasterror();
fprintf('\n!! Submission failed: %s\n', e.message);
fprintf('\n\nFunction: %s\nFileName: %s\nLineNumber: %d\n', ...
e.stack(1,1).name, e.stack(1,1).file, e.stack(1,1).line);
fprintf('\nPlease correct your code and resubmit.\n');
return
end
if isfield(response, 'errorMessage')
fprintf('!! Submission failed: %s\n', response.errorMessage);
elseif isfield(response, 'errorCode')
fprintf('!! Submission failed: %s\n', response.message);
else
showFeedback(parts, response);
save(tokenFile, 'email', 'token');
end
end
function [email token] = promptToken(email, existingToken, tokenFile)
if (~isempty(email) && ~isempty(existingToken))
prompt = sprintf( ...
'Use token from last successful submission (%s)? (Y/n): ', ...
email);
reenter = input(prompt, 's');
if (isempty(reenter) || reenter(1) == 'Y' || reenter(1) == 'y')
token = existingToken;
return;
else
delete(tokenFile);
end
end
email = input('Login (email address): ', 's');
token = input('Token: ', 's');
end
function isValid = isValidPartOptionIndex(partOptions, i)
isValid = (~isempty(i)) && (1 <= i) && (i <= numel(partOptions));
end
function response = submitParts(conf, email, token, parts)
body = makePostBody(conf, email, token, parts);
submissionUrl = submissionUrl();
responseBody = getResponse(submissionUrl, body);
jsonResponse = validateResponse(responseBody);
response = loadjson(jsonResponse);
end
function body = makePostBody(conf, email, token, parts)
bodyStruct.assignmentSlug = conf.assignmentSlug;
bodyStruct.submitterEmail = email;
bodyStruct.secret = token;
bodyStruct.parts = makePartsStruct(conf, parts);
opt.Compact = 1;
body = savejson('', bodyStruct, opt);
end
function partsStruct = makePartsStruct(conf, parts)
for part = parts
partId = part{:}.id;
fieldName = makeValidFieldName(partId);
outputStruct.output = conf.output(partId);
partsStruct.(fieldName) = outputStruct;
end
end
function [parts] = parts(conf)
parts = {};
for partArray = conf.partArrays
part.id = partArray{:}{1};
part.sourceFiles = partArray{:}{2};
part.name = partArray{:}{3};
parts{end + 1} = part;
end
end
function showFeedback(parts, response)
fprintf('== \n');
fprintf('== %43s | %9s | %-s\n', 'Part Name', 'Score', 'Feedback');
fprintf('== %43s | %9s | %-s\n', '---------', '-----', '--------');
for part = parts
score = '';
partFeedback = '';
partFeedback = response.partFeedbacks.(makeValidFieldName(part{:}.id));
partEvaluation = response.partEvaluations.(makeValidFieldName(part{:}.id));
score = sprintf('%d / %3d', partEvaluation.score, partEvaluation.maxScore);
fprintf('== %43s | %9s | %-s\n', part{:}.name, score, partFeedback);
end
evaluation = response.evaluation;
totalScore = sprintf('%d / %d', evaluation.score, evaluation.maxScore);
fprintf('== --------------------------------\n');
fprintf('== %43s | %9s | %-s\n', '', totalScore, '');
fprintf('== \n');
end
% use urlread or curl to send submit results to the grader and get a response
function response = getResponse(url, body)
% try using urlread() and a secure connection
params = {'jsonBody', body};
[response, success] = urlread(url, 'post', params);
if (success == 0)
% urlread didn't work, try curl & the peer certificate patch
if ispc
% testing note: use 'jsonBody =' for a test case
json_command = sprintf('echo jsonBody=%s | curl -k -X POST -d @- %s', body, url);
else
% it's linux/OS X, so use the other form
json_command = sprintf('echo ''jsonBody=%s'' | curl -k -X POST -d @- %s', body, url);
end
% get the response body for the peer certificate patch method
[code, response] = system(json_command);
% test the success code
if (code ~= 0)
fprintf('[error] submission with curl() was not successful\n');
end
end
end
% validate the grader's response
function response = validateResponse(resp)
% test if the response is json or an HTML page
isJson = length(resp) > 0 && resp(1) == '{';
isHtml = findstr(lower(resp), '<html');
if (isJson)
response = resp;
elseif (isHtml)
% the response is html, so it's probably an error message
printHTMLContents(resp);
error('Grader response is an HTML message');
else
error('Grader sent no response');
end
end
% parse a HTML response and print it's contents
function printHTMLContents(response)
strippedResponse = regexprep(response, '<[^>]+>', ' ');
strippedResponse = regexprep(strippedResponse, '[\t ]+', ' ');
fprintf(strippedResponse);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Service configuration
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function submissionUrl = submissionUrl()
submissionUrl = 'https://www-origin.coursera.org/api/onDemandProgrammingImmediateFormSubmissions.v1';
end
|
github
|
wgshun/AndrewNG-Machinelearning-master
|
savejson.m
|
.m
|
AndrewNG-Machinelearning-master/homework/machine-learning-ex1/machine-learning-ex1/ex1/lib/jsonlab/savejson.m
| 17,462 |
utf_8
|
861b534fc35ffe982b53ca3ca83143bf
|
function json=savejson(rootname,obj,varargin)
%
% json=savejson(rootname,obj,filename)
% or
% json=savejson(rootname,obj,opt)
% json=savejson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a JSON (JavaScript
% Object Notation) string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09
%
% $Id: savejson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array).
% filename: a string for the file name to save the output JSON data.
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.FloatFormat ['%.10g'|string]: format to show each numeric element
% of a 1D/2D array;
% opt.ArrayIndent [1|0]: if 1, output explicit data array with
% precedent indentation; if 0, no indentation
% opt.ArrayToStruct[0|1]: when set to 0, savejson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [0|1]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, savejson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.Inf ['"$1_Inf_"'|string]: a customized regular expression pattern
% to represent +/-Inf. The matched pattern is '([-+]*)Inf'
% and $1 represents the sign. For those who want to use
% 1e999 to represent Inf, they can set opt.Inf to '$11e999'
% opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern
% to represent NaN
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSONP='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
% opt.SaveBinary [0|1]: 1 - save the JSON file in binary mode; 0 - text mode.
% opt.Compact [0|1]: 1- out compact JSON format (remove all newlines and tabs)
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a string in the JSON format (see http://json.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% savejson('jmesh',jsonmesh)
% savejson('',jsonmesh,'ArrayIndent',0,'FloatFormat','\t%.5g')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
whitespaces=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
if(jsonopt('Compact',0,opt)==1)
whitespaces=struct('tab','','newline','','sep',',');
end
if(~isfield(opt,'whitespaces_'))
opt.whitespaces_=whitespaces;
end
nl=whitespaces.newline;
json=obj2json(rootname,obj,rootlevel,opt);
if(rootisarray)
json=sprintf('%s%s',json,nl);
else
json=sprintf('{%s%s%s}\n',nl,json,nl);
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=sprintf('%s(%s);%s',jsonp,json,nl);
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
if(jsonopt('SaveBinary',0,opt)==1)
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
else
fid = fopen(opt.FileName, 'wt');
fwrite(fid,json,'char');
end
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2json(name,item,level,varargin)
if(iscell(item))
txt=cell2json(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2json(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2json(name,item,level,varargin{:});
else
txt=mat2json(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2json(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=jsonopt('whitespaces_',struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n')),varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
nl=ws.newline;
if(len>1)
if(~isempty(name))
txt=sprintf('%s"%s": [%s',padding0, checkname(name,varargin{:}),nl); name='';
else
txt=sprintf('%s[%s',padding0,nl);
end
elseif(len==0)
if(~isempty(name))
txt=sprintf('%s"%s": []',padding0, checkname(name,varargin{:})); name='';
else
txt=sprintf('%s[]',padding0);
end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
txt=sprintf('%s%s',txt,obj2json(name,item{i,j},level+(dim(1)>1)+1,varargin{:}));
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
%if(j==dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=struct2json(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
padding1=repmat(ws.tab,1,level+(dim(1)>1)+(len>1));
nl=ws.newline;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding0,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding0,nl); end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=sprintf('%s%s"%s": {%s',txt,padding1, checkname(name,varargin{:}),nl);
else
txt=sprintf('%s%s{%s',txt,padding1,nl);
end
if(~isempty(names))
for e=1:length(names)
txt=sprintf('%s%s',txt,obj2json(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:}));
if(e<length(names)) txt=sprintf('%s%s',txt,','); end
txt=sprintf('%s%s',txt,nl);
end
end
txt=sprintf('%s%s}',txt,padding1);
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=str2json(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding1,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding1,nl); end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
if(isoct)
val=regexprep(item(e,:),'\\','\\');
val=regexprep(val,'"','\"');
val=regexprep(val,'^"','\"');
else
val=regexprep(item(e,:),'\\','\\\\');
val=regexprep(val,'"','\\"');
val=regexprep(val,'^"','\\"');
end
val=escapejsonstring(val);
if(len==1)
obj=['"' checkname(name,varargin{:}) '": ' '"',val,'"'];
if(isempty(name)) obj=['"',val,'"']; end
txt=sprintf('%s%s%s%s',txt,padding1,obj);
else
txt=sprintf('%s%s%s%s',txt,padding0,['"',val,'"']);
end
if(e==len) sep=''; end
txt=sprintf('%s%s',txt,sep);
end
if(len>1) txt=sprintf('%s%s%s%s',txt,nl,padding1,']'); end
%%-------------------------------------------------------------------------
function txt=mat2json(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) ||jsonopt('ArrayToStruct',0,varargin{:}))
if(isempty(name))
txt=sprintf('%s{%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
else
txt=sprintf('%s"%s": {%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,checkname(name,varargin{:}),nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
end
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1 && level>0)
numtxt=regexprep(regexprep(matdata2json(item,level+1,varargin{:}),'^\[',''),']','');
else
numtxt=matdata2json(item,level+1,varargin{:});
end
if(isempty(name))
txt=sprintf('%s%s',padding1,numtxt);
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
else
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
end
end
return;
end
dataformat='%s%s%s%s%s';
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsSparse_": ','1', sep);
if(size(item,1)==1)
% Row vector, store only column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([iy(:),data'],level+2,varargin{:}), nl);
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,data],level+2,varargin{:}), nl);
else
% General case, store row and column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,iy,data],level+2,varargin{:}), nl);
end
else
if(isreal(item))
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json(item(:)',level+2,varargin{:}), nl);
else
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([real(item(:)) imag(item(:))],level+2,varargin{:}), nl);
end
end
txt=sprintf('%s%s%s',txt,padding1,'}');
%%-------------------------------------------------------------------------
function txt=matdata2json(mat,level,varargin)
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
tab=ws.tab;
nl=ws.newline;
if(size(mat,1)==1)
pre='';
post='';
level=level-1;
else
pre=sprintf('[%s',nl);
post=sprintf('%s%s]',nl,repmat(tab,1,level-1));
end
if(isempty(mat))
txt='null';
return;
end
floatformat=jsonopt('FloatFormat','%.10g',varargin{:});
%if(numel(mat)>1)
formatstr=['[' repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf('],%s',nl)]];
%else
% formatstr=[repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf(',\n')]];
%end
if(nargin>=2 && size(mat,1)>1 && jsonopt('ArrayIndent',1,varargin{:})==1)
formatstr=[repmat(tab,1,level) formatstr];
end
txt=sprintf(formatstr,mat');
txt(end-length(nl):end)=[];
if(islogical(mat) && jsonopt('ParseLogical',0,varargin{:})==1)
txt=regexprep(txt,'1','true');
txt=regexprep(txt,'0','false');
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],\n['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
txt=[pre txt post];
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function newstr=escapejsonstring(str)
newstr=str;
isoct=exist('OCTAVE_VERSION','builtin');
if(isoct)
vv=sscanf(OCTAVE_VERSION,'%f');
if(vv(1)>=3.8) isoct=0; end
end
if(isoct)
escapechars={'\a','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},escapechars{i});
end
else
escapechars={'\a','\b','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},regexprep(escapechars{i},'\\','\\\\'));
end
end
|
github
|
wgshun/AndrewNG-Machinelearning-master
|
loadjson.m
|
.m
|
AndrewNG-Machinelearning-master/homework/machine-learning-ex1/machine-learning-ex1/ex1/lib/jsonlab/loadjson.m
| 18,732 |
ibm852
|
ab98cf173af2d50bbe8da4d6db252a20
|
function data = loadjson(fname,varargin)
%
% data=loadjson(fname,opt)
% or
% data=loadjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09, including previous works from
%
% Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
% created on 2009/11/02
% François Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393
% created on 2009/03/22
% Joel Feenstra:
% http://www.mathworks.com/matlabcentral/fileexchange/20565
% created on 2008/07/03
%
% $Id: loadjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a JSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.FastArrayParser [1|0 or integer]: if set to 1, use a
% speed-optimized array parser when loading an
% array object. The fast array parser may
% collapse block arrays into a single large
% array similar to rules defined in cell2mat; 0 to
% use a legacy parser; if set to a larger-than-1
% value, this option will specify the minimum
% dimension to enable the fast array parser. For
% example, if the input is a 3D array, setting
% FastArrayParser to 1 will return a 3D array;
% setting to 2 will return a cell array of 2D
% arrays; setting to 3 will return to a 2D cell
% array of 1D vectors; setting to 4 will return a
% 3D cell array.
% opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% dat=loadjson('{"obj":{"string":"value","array":[1,2,3]}}')
% dat=loadjson(['examples' filesep 'example1.json'])
% dat=loadjson(['examples' filesep 'example1.json'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
if(jsonopt('ShowProgress',0,opt)==1)
opt.progressbar_=waitbar(0,'loading ...');
end
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
if(isfield(opt,'progressbar_'))
close(opt.progressbar_);
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=data(j).x0x5F_ArraySize_;
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
if next_char ~= '}'
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
parse_char(':');
val = parse_value(varargin{:});
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}'
break;
end
parse_char(',');
end
end
parse_char('}');
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim2=[];
arraydepth=jsonopt('JSONLAB_ArrayDepth_',1,varargin{:});
pbar=jsonopt('progressbar_',-1,varargin{:});
if next_char ~= ']'
if(jsonopt('FastArrayParser',1,varargin{:})>=1 && arraydepth>=jsonopt('FastArrayParser',1,varargin{:}))
[endpos, e1l, e1r, maxlevel]=matching_bracket(inStr,pos);
arraystr=['[' inStr(pos:endpos)];
arraystr=regexprep(arraystr,'"_NaN_"','NaN');
arraystr=regexprep(arraystr,'"([-+]*)_Inf_"','$1Inf');
arraystr(arraystr==sprintf('\n'))=[];
arraystr(arraystr==sprintf('\r'))=[];
%arraystr=regexprep(arraystr,'\s*,',','); % this is slow,sometimes needed
if(~isempty(e1l) && ~isempty(e1r)) % the array is in 2D or higher D
astr=inStr((e1l+1):(e1r-1));
astr=regexprep(astr,'"_NaN_"','NaN');
astr=regexprep(astr,'"([-+]*)_Inf_"','$1Inf');
astr(astr==sprintf('\n'))=[];
astr(astr==sprintf('\r'))=[];
astr(astr==' ')='';
if(isempty(find(astr=='[', 1))) % array is 2D
dim2=length(sscanf(astr,'%f,',[1 inf]));
end
else % array is 1D
astr=arraystr(2:end-1);
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',[1,inf]);
if(nextidx>=length(astr)-1)
object=obj;
pos=endpos;
parse_char(']');
return;
end
end
if(~isempty(dim2))
astr=arraystr;
astr(astr=='[')='';
astr(astr==']')='';
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',inf);
if(nextidx>=length(astr)-1)
object=reshape(obj,dim2,numel(obj)/dim2)';
pos=endpos;
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
return;
end
end
arraystr=regexprep(arraystr,'\]\s*,','];');
else
arraystr='[';
end
try
if(isoct && regexp(arraystr,'"','once'))
error('Octave eval can produce empty cells for JSON-like input');
end
object=eval(arraystr);
pos=endpos;
catch
while 1
newopt=varargin2struct(varargin{:},'JSONLAB_ArrayDepth_',arraydepth+1);
val = parse_value(newopt);
object{end+1} = val;
if next_char == ']'
break;
end
parse_char(',');
end
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr len esc index_esc len_esc
% len, ns = length(inStr), keyboard
if inStr(pos) ~= '"'
error_pos('String starting with " expected at position %d');
else
pos = pos + 1;
end
str = '';
while pos <= len
while index_esc <= len_esc && esc(index_esc) < pos
index_esc = index_esc + 1;
end
if index_esc > len_esc
str = [str inStr(pos:len)];
pos = len + 1;
break;
else
str = [str inStr(pos:esc(index_esc)-1)];
pos = esc(index_esc);
end
nstr = length(str); switch inStr(pos)
case '"'
pos = pos + 1;
if(~isempty(str))
if(strcmp(str,'_Inf_'))
str=Inf;
elseif(strcmp(str,'-_Inf_'))
str=-Inf;
elseif(strcmp(str,'_NaN_'))
str=NaN;
end
end
return;
case '\'
if pos+1 > len
error_pos('End of file reached right after escape character');
end
pos = pos + 1;
switch inStr(pos)
case {'"' '\' '/'}
str(nstr+1) = inStr(pos);
pos = pos + 1;
case {'b' 'f' 'n' 'r' 't'}
str(nstr+1) = sprintf(['\' inStr(pos)]);
pos = pos + 1;
case 'u'
if pos+4 > len
error_pos('End of file reached in escaped unicode character');
end
str(nstr+(1:6)) = inStr(pos-1:pos+4);
pos = pos + 5;
end
otherwise % should never happen
str(nstr+1) = inStr(pos), keyboard
pos = pos + 1;
end
end
error_pos('End of file while expecting end of inStr');
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct
currstr=inStr(pos:end);
numstr=0;
if(isoct~=0)
numstr=regexp(currstr,'^\s*-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?','end');
[num, one] = sscanf(currstr, '%f', 1);
delta=numstr+1;
else
[num, one, err, delta] = sscanf(currstr, '%f', 1);
if ~isempty(err)
error_pos('Error reading number at position %d');
end
end
pos = pos + delta-1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
pbar=jsonopt('progressbar_',-1,varargin{:});
if(pbar>0)
waitbar(pos/len,pbar,'loading ...');
end
switch(inStr(pos))
case '"'
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'-','0','1','2','3','4','5','6','7','8','9'}
val = parse_number(varargin{:});
return;
case 't'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'true')
val = true;
pos = pos + 4;
return;
end
case 'f'
if pos+4 <= len && strcmpi(inStr(pos:pos+4), 'false')
val = false;
pos = pos + 5;
return;
end
case 'n'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'null')
val = [];
pos = pos + 4;
return;
end
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos, e1l, e1r, maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
wgshun/AndrewNG-Machinelearning-master
|
loadubjson.m
|
.m
|
AndrewNG-Machinelearning-master/homework/machine-learning-ex1/machine-learning-ex1/ex1/lib/jsonlab/loadubjson.m
| 15,574 |
utf_8
|
5974e78e71b81b1e0f76123784b951a4
|
function data = loadubjson(fname,varargin)
%
% data=loadubjson(fname,opt)
% or
% data=loadubjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/01
%
% $Id: loadubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a UBJSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadubjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.IntEndian [B|L]: specify the endianness of the integer fields
% in the UBJSON input data. B - Big-Endian format for
% integers (as required in the UBJSON specification);
% L - input integer fields are in Little-Endian order.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% obj=struct('string','value','array',[1 2 3]);
% ubjdata=saveubjson('obj',obj);
% dat=loadubjson(ubjdata)
% dat=loadubjson(['examples' filesep 'example1.ubj'])
% dat=loadubjson(['examples' filesep 'example1.ubj'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken fileendian systemendian
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
fileendian=upper(jsonopt('IntEndian','B',opt));
[os,maxelem,systemendian]=computer;
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
%%
function newdata=parse_collection(id,data,obj)
if(jsoncount>0 && exist('data','var'))
if(~iscell(data))
newdata=cell(1);
newdata{1}=data;
data=newdata;
end
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=double(data(j).x0x5F_ArraySize_);
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1); % TODO
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
count=double(parse_number());
end
if next_char ~= '}'
num=0;
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
%parse_char(':');
val = parse_value(varargin{:});
num=num+1;
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}' || (count>=0 && num>=count)
break;
end
%parse_char(',');
end
end
if(count==-1)
parse_char('}');
end
%%-------------------------------------------------------------------------
function [cid,len]=elem_info(type)
id=strfind('iUIlLdD',type);
dataclass={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
if(id>0)
cid=dataclass{id};
len=bytelen(id);
else
error_pos('unsupported type at position %d');
end
%%-------------------------------------------------------------------------
function [data adv]=parse_block(type,count,varargin)
global pos inStr isoct fileendian systemendian
[cid,len]=elem_info(type);
datastr=inStr(pos:pos+len*count-1);
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
id=strfind('iUIlLdD',type);
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,cid));
end
data=typecast(newdata,cid);
adv=double(len*count);
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim=[];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1);
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
if(next_char=='[')
dim=parse_array(varargin{:});
count=prod(double(dim));
else
count=double(parse_number());
end
end
if(~isempty(type))
if(count>=0)
[object adv]=parse_block(type,count,varargin{:});
if(~isempty(dim))
object=reshape(object,dim);
end
pos=pos+adv;
return;
else
endpos=matching_bracket(inStr,pos);
[cid,len]=elem_info(type);
count=(endpos-pos)/len;
[object adv]=parse_block(type,count,varargin{:});
pos=pos+adv;
parse_char(']');
return;
end
end
if next_char ~= ']'
while 1
val = parse_value(varargin{:});
object{end+1} = val;
if next_char == ']'
break;
end
%parse_char(',');
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
if(count==-1)
parse_char(']');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr esc index_esc len_esc
% len, ns = length(inStr), keyboard
type=inStr(pos);
if type ~= 'S' && type ~= 'C' && type ~= 'H'
error_pos('String starting with S expected at position %d');
else
pos = pos + 1;
end
if(type == 'C')
str=inStr(pos);
pos=pos+1;
return;
end
bytelen=double(parse_number());
if(length(inStr)>=pos+bytelen-1)
str=inStr(pos:pos+bytelen-1);
pos=pos+bytelen;
else
error_pos('End of file while expecting end of inStr');
end
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct fileendian systemendian
id=strfind('iUIlLdD',inStr(pos));
if(isempty(id))
error_pos('expecting a number at position %d');
end
type={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
datastr=inStr(pos+1:pos+bytelen(id));
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,type{id}));
end
num=typecast(newdata,type{id});
pos = pos + bytelen(id)+1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
switch(inStr(pos))
case {'S','C','H'}
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'i','U','I','l','L','d','D'}
val = parse_number(varargin{:});
return;
case 'T'
val = true;
pos = pos + 1;
return;
case 'F'
val = false;
pos = pos + 1;
return;
case {'Z','N'}
val = [];
pos = pos + 1;
return;
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos e1l e1r maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
wgshun/AndrewNG-Machinelearning-master
|
saveubjson.m
|
.m
|
AndrewNG-Machinelearning-master/homework/machine-learning-ex1/machine-learning-ex1/ex1/lib/jsonlab/saveubjson.m
| 16,123 |
utf_8
|
61d4f51010aedbf97753396f5d2d9ec0
|
function json=saveubjson(rootname,obj,varargin)
%
% json=saveubjson(rootname,obj,filename)
% or
% json=saveubjson(rootname,obj,opt)
% json=saveubjson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a Universal
% Binary JSON (UBJSON) binary string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/17
%
% $Id: saveubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array)
% filename: a string for the file name to save the output UBJSON data
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.ArrayToStruct[0|1]: when set to 0, saveubjson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [1|0]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, saveubjson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSON='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a binary string in the UBJSON format (see http://ubjson.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% saveubjson('jsonmesh',jsonmesh)
% saveubjson('jsonmesh',jsonmesh,'meshdata.ubj')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
json=obj2ubjson(rootname,obj,rootlevel,opt);
if(~rootisarray)
json=['{' json '}'];
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=[jsonp '(' json ')'];
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2ubjson(name,item,level,varargin)
if(iscell(item))
txt=cell2ubjson(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2ubjson(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2ubjson(name,item,level,varargin{:});
else
txt=mat2ubjson(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2ubjson(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item); % let's handle 1D cell first
if(len>1)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) '[']; name='';
else
txt='[';
end
elseif(len==0)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) 'Z']; name='';
else
txt='Z';
end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
txt=[txt obj2ubjson(name,item{i,j},level+(len>1),varargin{:})];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=struct2ubjson(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=[txt S_(checkname(name,varargin{:})) '{'];
else
txt=[txt '{'];
end
if(~isempty(names))
for e=1:length(names)
txt=[txt obj2ubjson(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:})];
end
end
txt=[txt '}'];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=str2ubjson(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
val=item(e,:);
if(len==1)
obj=['' S_(checkname(name,varargin{:})) '' '',S_(val),''];
if(isempty(name)) obj=['',S_(val),'']; end
txt=[txt,'',obj];
else
txt=[txt,'',['',S_(val),'']];
end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=mat2ubjson(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) || jsonopt('ArrayToStruct',0,varargin{:}))
cid=I_(uint32(max(size(item))));
if(isempty(name))
txt=['{' S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1)) ];
else
if(isempty(item))
txt=[S_(checkname(name,varargin{:})),'Z'];
return;
else
txt=[S_(checkname(name,varargin{:})),'{',S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1))];
end
end
else
if(isempty(name))
txt=matdata2ubjson(item,level+1,varargin{:});
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
numtxt=regexprep(regexprep(matdata2ubjson(item,level+1,varargin{:}),'^\[',''),']','');
txt=[S_(checkname(name,varargin{:})) numtxt];
else
txt=[S_(checkname(name,varargin{:})),matdata2ubjson(item,level+1,varargin{:})];
end
end
return;
end
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=[txt,S_('_ArrayIsComplex_'),'T'];
end
txt=[txt,S_('_ArrayIsSparse_'),'T'];
if(size(item,1)==1)
% Row vector, store only column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([iy(:),data'],level+2,varargin{:})];
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,data],level+2,varargin{:})];
else
% General case, store row and column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,iy,data],level+2,varargin{:})];
end
else
if(isreal(item))
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson(item(:)',level+2,varargin{:})];
else
txt=[txt,S_('_ArrayIsComplex_'),'T'];
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([real(item(:)) imag(item(:))],level+2,varargin{:})];
end
end
txt=[txt,'}'];
%%-------------------------------------------------------------------------
function txt=matdata2ubjson(mat,level,varargin)
if(isempty(mat))
txt='Z';
return;
end
if(size(mat,1)==1)
level=level-1;
end
type='';
hasnegtive=(mat<0);
if(isa(mat,'integer') || isinteger(mat) || (isfloat(mat) && all(mod(mat(:),1) == 0)))
if(isempty(hasnegtive))
if(max(mat(:))<=2^8)
type='U';
end
end
if(isempty(type))
% todo - need to consider negative ones separately
id= histc(abs(max(mat(:))),[0 2^7 2^15 2^31 2^63]);
if(isempty(find(id)))
error('high-precision data is not yet supported');
end
key='iIlL';
type=key(find(id));
end
txt=[I_a(mat(:),type,size(mat))];
elseif(islogical(mat))
logicalval='FT';
if(numel(mat)==1)
txt=logicalval(mat+1);
else
txt=['[$U#' I_a(size(mat),'l') typecast(swapbytes(uint8(mat(:)')),'uint8')];
end
else
if(numel(mat)==1)
txt=['[' D_(mat) ']'];
else
txt=D_a(mat(:),'D',size(mat));
end
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function val=S_(str)
if(length(str)==1)
val=['C' str];
else
val=['S' I_(int32(length(str))) str];
end
%%-------------------------------------------------------------------------
function val=I_(num)
if(~isinteger(num))
error('input is not an integer');
end
if(num>=0 && num<255)
val=['U' data2byte(swapbytes(cast(num,'uint8')),'uint8')];
return;
end
key='iIlL';
cid={'int8','int16','int32','int64'};
for i=1:4
if((num>0 && num<2^(i*8-1)) || (num<0 && num>=-2^(i*8-1)))
val=[key(i) data2byte(swapbytes(cast(num,cid{i})),'uint8')];
return;
end
end
error('unsupported integer');
%%-------------------------------------------------------------------------
function val=D_(num)
if(~isfloat(num))
error('input is not a float');
end
if(isa(num,'single'))
val=['d' data2byte(num,'uint8')];
else
val=['D' data2byte(num,'uint8')];
end
%%-------------------------------------------------------------------------
function data=I_a(num,type,dim,format)
id=find(ismember('iUIlL',type));
if(id==0)
error('unsupported integer array');
end
% based on UBJSON specs, all integer types are stored in big endian format
if(id==1)
data=data2byte(swapbytes(int8(num)),'uint8');
blen=1;
elseif(id==2)
data=data2byte(swapbytes(uint8(num)),'uint8');
blen=1;
elseif(id==3)
data=data2byte(swapbytes(int16(num)),'uint8');
blen=2;
elseif(id==4)
data=data2byte(swapbytes(int32(num)),'uint8');
blen=4;
elseif(id==5)
data=data2byte(swapbytes(int64(num)),'uint8');
blen=8;
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/blen)) data(:)'];
end
data=['[' data(:)'];
else
data=reshape(data,blen,numel(data)/blen);
data(2:blen+1,:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function data=D_a(num,type,dim,format)
id=find(ismember('dD',type));
if(id==0)
error('unsupported float array');
end
if(id==1)
data=data2byte(single(num),'uint8');
elseif(id==2)
data=data2byte(double(num),'uint8');
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/(id*4))) data(:)'];
end
data=['[' data];
else
data=reshape(data,(id*4),length(data)/(id*4));
data(2:(id*4+1),:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function bytes=data2byte(varargin)
bytes=typecast(varargin{:});
bytes=bytes(:)';
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
buildWpyr.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/buildWpyr.m
| 2,705 |
utf_8
|
1c4ff4ecab086742bb93ea70f1e9e015
|
% [PYR, INDICES] = buildWpyr(IM, HEIGHT, FILT, EDGES)
%
% Construct a separable orthonormal QMF/wavelet pyramid on matrix (or vector) IM.
%
% HEIGHT (optional) specifies the number of pyramid levels to build. Default
% is maxPyrHt(IM,FILT). You can also specify 'auto' to use this value.
%
% FILT (optional) can be a string naming a standard filter (see
% namedFilter), or a vector which will be used for (separable)
% convolution. Filter can be of even or odd length, but should be symmetric.
% Default = 'qmf9'. EDGES specifies edge-handling, and
% defaults to 'reflect1' (see corrDn).
%
% PYR is a vector containing the N pyramid subbands, ordered from fine
% to coarse. INDICES is an Nx2 matrix containing the sizes of
% each subband. This is compatible with the MatLab Wavelet toolbox.
% Eero Simoncelli, 6/96.
function [pyr,pind] = buildWpyr(im, ht, filt, edges)
if (nargin < 1)
error('First argument (IM) is required');
end
%------------------------------------------------------------
%% OPTIONAL ARGS:
if (exist('filt') ~= 1)
filt = 'qmf9';
end
if (exist('edges') ~= 1)
edges= 'reflect1';
end
if isstr(filt)
filt = namedFilter(filt);
end
if ( (size(filt,1) > 1) & (size(filt,2) > 1) )
error('FILT should be a 1D filter (i.e., a vector)');
else
filt = filt(:);
end
hfilt = modulateFlip(filt);
% Stagger sampling if filter is odd-length:
if (mod(size(filt,1),2) == 0)
stag = 2;
else
stag = 1;
end
im_sz = size(im);
max_ht = maxPyrHt(im_sz, size(filt,1));
if ( (exist('ht') ~= 1) | (ht == 'auto') )
ht = max_ht;
else
if (ht > max_ht)
error(sprintf('Cannot build pyramid higher than %d levels.',max_ht));
end
end
if (ht <= 0)
pyr = im(:);
pind = im_sz;
else
if (im_sz(2) == 1)
lolo = corrDn(im, filt, edges, [2 1], [stag 1]);
hihi = corrDn(im, hfilt, edges, [2 1], [2 1]);
elseif (im_sz(1) == 1)
lolo = corrDn(im, filt', edges, [1 2], [1 stag]);
hihi = corrDn(im, hfilt', edges, [1 2], [1 2]);
else
lo = corrDn(im, filt, edges, [2 1], [stag 1]);
hi = corrDn(im, hfilt, edges, [2 1], [2 1]);
lolo = corrDn(lo, filt', edges, [1 2], [1 stag]);
lohi = corrDn(hi, filt', edges, [1 2], [1 stag]); % horizontal
hilo = corrDn(lo, hfilt', edges, [1 2], [1 2]); % vertical
hihi = corrDn(hi, hfilt', edges, [1 2], [1 2]); % diagonal
end
[npyr,nind] = buildWpyr(lolo, ht-1, filt, edges);
if ((im_sz(1) == 1) | (im_sz(2) == 1))
pyr = [hihi(:); npyr];
pind = [size(hihi); nind];
else
pyr = [lohi(:); hilo(:); hihi(:); npyr];
pind = [size(lohi); size(hilo); size(hihi); nind];
end
end
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
pyrBand.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/pyrBand.m
| 406 |
utf_8
|
0cad3c43324c84276383d06f6f6a5b60
|
% RES = pyrBand(PYR, INDICES, BAND_NUM)
%
% Access a subband from a pyramid (gaussian, laplacian, QMF/wavelet,
% or steerable). Subbands are numbered consecutively, from finest
% (highest spatial frequency) to coarsest (lowest spatial frequency).
% Eero Simoncelli, 6/96.
function res = pyrBand(pyr, pind, band)
res = reshape( pyr(pyrBandIndices(pind,band)), pind(band,1), pind(band,2) );
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
buildFullSFpyr2.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/buildFullSFpyr2.m
| 3,031 |
utf_8
|
4a1191e10f08e0d219040bdc7864a575
|
% [PYR, INDICES, STEERMTX, HARMONICS] = buildFullSFpyr2(IM, HEIGHT, ORDER, TWIDTH)
%
% Construct a steerable pyramid on matrix IM, in the Fourier domain.
% Unlike the standard transform, subdivides the highpass band into
% orientations.
function [pyr,pind,steermtx,harmonics] = buildFullSFpyr2(im, ht, order, twidth)
%-----------------------------------------------------------------
%% DEFAULTS:
max_ht = floor(log2(min(size(im)))+1);
if (exist('ht') ~= 1)
ht = max_ht;
else
if (ht > max_ht)
error(sprintf('Cannot build pyramid higher than %d levels.',max_ht));
end
end
if (exist('order') ~= 1)
order = 3;
elseif ((order > 15) | (order < 0))
fprintf(1,'Warning: ORDER must be an integer in the range [0,15]. Truncating.\n');
order = min(max(order,0),15);
else
order = round(order);
end
nbands = order+1;
if (exist('twidth') ~= 1)
twidth = 1;
elseif (twidth <= 0)
fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n');
twidth = 1;
end
%-----------------------------------------------------------------
%% Steering stuff:
if (mod((nbands),2) == 0)
harmonics = [0:(nbands/2)-1]'*2 + 1;
else
harmonics = [0:(nbands-1)/2]'*2;
end
steermtx = steer2HarmMtx(harmonics, pi*[0:nbands-1]/nbands, 'even');
%-----------------------------------------------------------------
dims = size(im);
ctr = ceil((dims+0.5)/2);
[xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ...
([1:dims(1)]-ctr(1))./(dims(1)/2) );
angle = atan2(yramp,xramp);
log_rad = sqrt(xramp.^2 + yramp.^2);
log_rad(ctr(1),ctr(2)) = log_rad(ctr(1),ctr(2)-1);
log_rad = log2(log_rad);
%% Radial transition function (a raised cosine in log-frequency):
[Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]);
Yrcos = sqrt(Yrcos);
YIrcos = sqrt(1.0 - Yrcos.^2);
lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
imdft = fftshift(fft2(im));
lo0dft = imdft .* lo0mask;
[pyr,pind] = buildSFpyrLevs(lo0dft, log_rad, Xrcos, Yrcos, angle, ht, nbands);
%% Split the highpass band into orientations
hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
lutsize = 1024;
Xcosn = pi*[-(2*lutsize+1):(lutsize+1)]/lutsize; % [-2*pi:pi]
order = nbands-1;
const = (2^(2*order))*(factorial(order)^2)/(nbands*factorial(2*order));
Ycosn = sqrt(const) * (cos(Xcosn)).^order;
bands = zeros(prod(size(imdft)), nbands);
bind = zeros(nbands,2);
for b = 1:nbands
anglemask = pointOp(angle, Ycosn, Xcosn(1)+pi*(b-1)/nbands, Xcosn(2)-Xcosn(1));
Mask = ((-sqrt(-1))^(nbands-1))*anglemask.*hi0mask;
% make real the contents in the HF cross (to avoid information loss in these freqs.)
% It distributes evenly these contents among the nbands orientations
Mask(1,:) = ones(1,size(im,2))/sqrt(nbands);
Mask(2:size(im,1),1) = ones(size(im,1)-1,1)/sqrt(nbands);
banddft = imdft .* Mask;
band = real(ifft2(fftshift(banddft)));
bands(:,b) = real(band(:));
bind(b,:) = size(band);
end
pyr = [bands(:); pyr];
pind = [bind; pind];
pind = [ [0 0]; pind]; %% Dummy highpass
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
var2.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/var2.m
| 393 |
utf_8
|
46f01727b1895ebb42fea033f942c562
|
% V = VAR2(MTX,MEAN)
%
% Sample variance of a matrix.
% Passing MEAN (optional) makes the calculation faster.
function res = var2(mtx, mn)
if (exist('mn') ~= 1)
mn = mean2(mtx);
end
if (isreal(mtx))
res = sum(sum(abs(mtx-mn).^2)) / (prod(size(mtx)) - 1);
else
res = sum(sum(real(mtx-mn).^2)) + i*sum(sum(imag(mtx-mn).^2));
res = res / (prod(size(mtx)) - 1);
end
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
reconSFpyrLevs.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/reconSFpyrLevs.m
| 2,013 |
utf_8
|
bff5aabf51101f5a06bf4a3a59d0de00
|
% RESDFT = reconSFpyrLevs(PYR,INDICES,LOGRAD,XRCOS,YRCOS,ANGLE,NBANDS,LEVS,BANDS)
%
% Recursive function for reconstructing levels of a steerable pyramid
% representation. This is called by reconSFpyr, and is not usually
% called directly.
% Eero Simoncelli, 5/97.
function resdft = reconSFpyrLevs(pyr,pind,log_rad,Xrcos,Yrcos,angle,nbands,levs,bands);
lo_ind = nbands+1;
dims = pind(1,:);
ctr = ceil((dims+0.5)/2);
log_rad = log_rad + 1;
if any(levs > 1)
lodims = ceil((dims-0.5)/2);
loctr = ceil((lodims+0.5)/2);
lostart = ctr-loctr+1;
loend = lostart+lodims-1;
nlog_rad = log_rad(lostart(1):loend(1),lostart(2):loend(2));
nangle = angle(lostart(1):loend(1),lostart(2):loend(2));
if (size(pind,1) > lo_ind)
nresdft = reconSFpyrLevs( pyr(1+sum(prod(pind(1:lo_ind-1,:)')):size(pyr,1)),...
pind(lo_ind:size(pind,1),:), ...
nlog_rad, Xrcos, Yrcos, nangle, nbands,levs-1, bands);
else
nresdft = fftshift(fft2(pyrBand(pyr,pind,lo_ind)));
end
YIrcos = sqrt(abs(1.0 - Yrcos.^2));
lomask = pointOp(nlog_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
resdft = zeros(dims);
resdft(lostart(1):loend(1),lostart(2):loend(2)) = nresdft .* lomask;
else
resdft = zeros(dims);
end
if any(levs == 1)
lutsize = 1024;
Xcosn = pi*[-(2*lutsize+1):(lutsize+1)]/lutsize; % [-2*pi:pi]
order = nbands-1;
%% divide by sqrt(sum_(n=0)^(N-1) cos(pi*n/N)^(2(N-1)) )
const = (2^(2*order))*(factorial(order)^2)/(nbands*factorial(2*order));
Ycosn = sqrt(const) * (cos(Xcosn)).^order;
himask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1),0);
ind = 1;
for b = 1:nbands
if any(bands == b)
anglemask = pointOp(angle,Ycosn,Xcosn(1)+pi*(b-1)/nbands,Xcosn(2)-Xcosn(1));
band = reshape(pyr(ind:ind+prod(dims)-1), dims(1), dims(2));
banddft = fftshift(fft2(band));
resdft = resdft + (i)^(nbands-1) * banddft.*anglemask.*himask;
end
ind = ind + prod(dims);
end
end
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
rcosFn.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/rcosFn.m
| 1,167 |
utf_8
|
e668c06ae18191dea3d63f2c3035cdcb
|
% [X, Y] = rcosFn(WIDTH, POSITION, VALUES)
%
% Return a lookup table (suitable for use by INTERP1)
% containing a "raised cosine" soft threshold function:
%
% Y = VALUES(1) + (VALUES(2)-VALUES(1)) *
% cos^2( PI/2 * (X - POSITION + WIDTH)/WIDTH )
%
% WIDTH is the width of the region over which the transition occurs
% (default = 1). POSITION is the location of the center of the
% threshold (default = 0). VALUES (default = [0,1]) specifies the
% values to the left and right of the transition.
% Eero Simoncelli, 7/96.
function [X, Y] = rcosFn(width,position,values)
%------------------------------------------------------------
% OPTIONAL ARGS:
if (exist('width') ~= 1)
width = 1;
end
if (exist('position') ~= 1)
position = 0;
end
if (exist('values') ~= 1)
values = [0,1];
end
%------------------------------------------------------------
sz = 256; %% arbitrary!
X = pi * [-sz-1:1] / (2*sz);
Y = values(1) + (values(2)-values(1)) * cos(X).^2;
% Make sure end values are repeated, for extrapolation...
Y(1) = Y(2);
Y(sz+3) = Y(sz+2);
X = position + (2*width/pi) * (X + pi/4);
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
vector.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/vector.m
| 240 |
utf_8
|
99db83250fc29065ecdb3bff900669d3
|
% [VEC] = vector(MTX)
%
% Pack elements of MTX into a column vector. Same as VEC = MTX(:)
% Previously named "vectorize" (changed to avoid overlap with Matlab's
% "vectorize" function).
function vec = vector(mtx)
vec = mtx(:);
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
showIm.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/showIm.m
| 6,332 |
utf_8
|
fc722445cecdb4685413ce683c5c414f
|
% RANGE = showIm (MATRIX, RANGE, ZOOM, LABEL, NSHADES )
%
% Display a MatLab MATRIX as a grayscale image in the current figure,
% inside the current axes. If MATRIX is complex, the real and imaginary
% parts are shown side-by-side, with the same grayscale mapping.
%
% If MATRIX is a string, it should be the name of a variable bound to a
% MATRIX in the base (global) environment. This matrix is displayed as an
% image, with the title set to the string.
%
% RANGE (optional) is a 2-vector specifying the values that map to
% black and white, respectively. Passing a value of 'auto' (default)
% sets RANGE=[min,max] (as in MatLab's imagesc). 'auto2' sets
% RANGE=[mean-2*stdev, mean+2*stdev]. 'auto3' sets
% RANGE=[p1-(p2-p1)/8, p2+(p2-p1)/8], where p1 is the 10th percentile
% value of the sorted MATRIX samples, and p2 is the 90th percentile
% value.
%
% ZOOM specifies the number of matrix samples per screen pixel. It
% will be rounded to an integer, or 1 divided by an integer. A value
% of 'same' or 'auto' (default) causes the zoom value to be chosen
% automatically to fit the image into the current axes. A value of
% 'full' fills the axis region (leaving no room for labels). See
% pixelAxes.m.
%
% If LABEL (optional, default = 1, unless zoom='full') is non-zero, the range
% of values that are mapped into the gray colormap and the dimensions
% (size) of the matrix and zoom factor are printed below the image. If label
% is a string, it is used as a title.
%
% NSHADES (optional) specifies the number of gray shades, and defaults
% to the size of the current colormap.
% Eero Simoncelli, 6/96.
%%TODO: should use "newplot"
function range = showIm( im, range, zoom, label, nshades );
%------------------------------------------------------------
%% OPTIONAL ARGS:
if (nargin < 1)
error('Requires at least one input argument.');
end
MLv = version;
if isstr(im)
if (strcmp(MLv(1),'4'))
error('Cannot pass string arg for MATRIX in MatLab version 4.x');
end
label = im;
im = evalin('base',im);
end
if (exist('range') ~= 1)
range = 'auto1';
end
if (exist('nshades') ~= 1)
nshades = size(colormap,1);
end
nshades = max( nshades, 2 );
if (exist('zoom') ~= 1)
zoom = 'auto';
end
if (exist('label') ~= 1)
if strcmp(zoom,'full')
label = 0; % no labeling
else
label = 1; % just print grayrange & dims
end
end
%------------------------------------------------------------
%% Automatic range calculation:
if (strcmp(range,'auto1') | strcmp(range,'auto'))
if isreal(im)
[mn,mx] = range2(im);
else
[mn1,mx1] = range2(real(im));
[mn2,mx2] = range2(imag(im));
mn = min(mn1,mn2);
mx = max(mx1,mx2);
end
if any(size(im)==1)
pad = (mx-mn)/12; % MAGIC NUMBER: graph padding
range = [mn-pad, mx+pad];
else
range = [mn,mx];
end
elseif strcmp(range,'auto2')
if isreal(im)
stdev = sqrt(var2(im));
av = mean2(im);
else
stdev = sqrt((var2(real(im)) + var2(imag(im)))/2);
av = (mean2(real(im)) + mean2(imag(im)))/2;
end
range = [av-2*stdev,av+2*stdev]; % MAGIC NUMBER: 2 stdevs
elseif strcmp(range, 'auto3')
percentile = 0.1; % MAGIC NUMBER: 0<p<0.5
[N,X] = histo(im);
binsz = X(2)-X(1);
N = N+1e-10; % Ensure cumsum will be monotonic for call to interp1
cumN = [0, cumsum(N)]/sum(N);
cumX = [X(1)-binsz, X] + (binsz/2);
ctrRange = interp1(cumN,cumX, [percentile, 1-percentile]);
range = mean(ctrRange) + (ctrRange-mean(ctrRange))/(1-2*percentile);
elseif isstr(range)
error(sprintf('Bad RANGE argument: %s',range))
end
if ((range(2) - range(1)) <= eps)
range(1) = range(1) - 0.5;
range(2) = range(2) + 0.5;
end
if isreal(im)
factor=1;
else
factor = 1+sqrt(-1);
end
xlbl_offset = 0; % default value
if (~any(size(im)==1))
%% MatLab's "image" rounds when mapping to the colormap, so we compute
%% (im-r1)*(nshades-1)/(r2-r1) + 1.5
mult = ((nshades-1) / (range(2)-range(1)));
d_im = (mult * im) + factor*(1.5 - range(1)*mult);
end
if isreal(im)
if (any(size(im)==1))
hh = plot( im);
axis([1, prod(size(im)), range]);
else
hh = image( d_im );
axis('off');
zoom = pixelAxes(size(d_im),zoom);
end
else
if (any(size(im)==1))
subplot(2,1,1);
hh = plot(real(im));
axis([1, prod(size(im)), range]);
subplot(2,1,2);
hh = plot(imag(im));
axis([1, prod(size(im)), range]);
else
subplot(1,2,1);
hh = image(real(d_im));
axis('off'); zoom = pixelAxes(size(d_im),zoom);
ax = gca; orig_units = get(ax,'Units');
set(ax,'Units','points');
pos1 = get(ax,'Position');
set(ax,'Units',orig_units);
subplot(1,2,2);
hh = image(imag(d_im));
axis('off'); zoom = pixelAxes(size(d_im),zoom);
ax = gca; orig_units = get(ax,'Units');
set(ax,'Units','points');
pos2 = get(ax,'Position');
set(ax,'Units',orig_units);
xlbl_offset = (pos1(1)-pos2(1))/2;
end
end
if ~any(size(im)==1)
colormap(gray(nshades));
end
if ((label ~= 0))
if isstr(label)
title(label);
h = get(gca,'Title');
orig_units = get(h,'Units');
set(h,'Units','points');
pos = get(h,'Position');
pos(1:2) = pos(1:2) + [xlbl_offset, -3]; % MAGIC NUMBER: y pixel offset
set(h,'Position',pos);
set(h,'Units',orig_units);
end
if (~any(size(im)==1))
if (zoom > 1)
zformat = sprintf('* %d',round(zoom));
else
zformat = sprintf('/ %d',round(1/zoom));
end
if isreal(im)
format=[' Range: [%.3g, %.3g] \n Dims: [%d, %d] ', zformat];
else
format=['Range: [%.3g, %.3g] ---- Dims: [%d, %d]', zformat];
end
xlabel(sprintf(format, range(1), range(2), size(im,1), size(im,2)));
h = get(gca,'Xlabel');
set(h,'FontSize', 9); % MAGIC NUMBER: font size!!!
orig_units = get(h,'Units');
set(h,'Units','points');
pos = get(h,'Position');
pos(1:2) = pos(1:2) + [xlbl_offset, 10]; % MAGIC NUMBER: y offset in points
set(h,'Position',pos);
set(h,'Units',orig_units);
set(h,'Visible','on'); % axis('image') turned the xlabel off...
end
end
return;
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
upConv.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/upConv.m
| 2,750 |
utf_8
|
c396c00dd8d50ee2a930427fead849be
|
% RES = upConv(IM, FILT, EDGES, STEP, START, STOP, RES)
%
% Upsample matrix IM, followed by convolution with matrix FILT. These
% arguments should be 1D or 2D matrices, and IM must be larger (in
% both dimensions) than FILT. The origin of filt
% is assumed to be floor(size(filt)/2)+1.
%
% EDGES is a string determining boundary handling:
% 'circular' - Circular convolution
% 'reflect1' - Reflect about the edge pixels
% 'reflect2' - Reflect, doubling the edge pixels
% 'repeat' - Repeat the edge pixels
% 'zero' - Assume values of zero outside image boundary
% 'extend' - Reflect and invert
% 'dont-compute' - Zero output when filter overhangs OUTPUT boundaries
%
% Upsampling factors are determined by STEP (optional, default=[1 1]),
% a 2-vector [y,x].
%
% The window over which the convolution occurs is specfied by START
% (optional, default=[1,1], and STOP (optional, default =
% step .* (size(IM) + floor((start-1)./step))).
%
% RES is an optional result matrix. The convolution result will be
% destructively added into this matrix. If this argument is passed, the
% result matrix will not be returned. DO NOT USE THIS ARGUMENT IF
% YOU DO NOT UNDERSTAND WHAT THIS MEANS!!
%
% NOTE: this operation corresponds to multiplication of a signal
% vector by a matrix whose columns contain copies of the time-reversed
% (or space-reversed) FILT shifted by multiples of STEP. See corrDn.m
% for the operation corresponding to the transpose of this matrix.
% Eero Simoncelli, 6/96. revised 2/97.
function result = upConv(im,filt,edges,step,start,stop,res)
%% THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD)
fprintf(1,'Warning: You should compile the MEX code for "upConv", found in the MEX subdirectory. It is much faster.\n');
%------------------------------------------------------------
%% OPTIONAL ARGS:
if (exist('edges') == 1)
if (strcmp(edges,'reflect1') ~= 1)
warning('Using REFLECT1 edge-handling (use MEX code for other options).');
end
end
if (exist('step') ~= 1)
step = [1,1];
end
if (exist('start') ~= 1)
start = [1,1];
end
% A multiple of step
if (exist('stop') ~= 1)
stop = step .* (floor((start-ones(size(start)))./step)+size(im))
end
if ( ceil((stop(1)+1-start(1)) / step(1)) ~= size(im,1) )
error('Bad Y result dimension');
end
if ( ceil((stop(2)+1-start(2)) / step(2)) ~= size(im,2) )
error('Bad X result dimension');
end
if (exist('res') ~= 1)
res = zeros(stop-start+1);
end
%------------------------------------------------------------
tmp = zeros(size(res));
tmp(start(1):step(1):stop(1),start(2):step(2):stop(2)) = im;
result = rconv2(tmp,filt) + res;
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
range2.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/range2.m
| 477 |
utf_8
|
4b8ed3c6da04efbf2862f0b36b91d524
|
% [MIN, MAX] = range2(MTX)
%
% Compute minimum and maximum values of MTX, returning them as a 2-vector.
% Eero Simoncelli, 3/97.
function [mn, mx] = range2(mtx)
%% NOTE: THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD)
fprintf(1,'WARNING: You should compile the MEX code for "range2", found in the MEX subdirectory. It is MUCH faster.\n');
if (~isreal(mtx))
error('MTX must be real-valued');
end
mn = min(min(mtx));
mx = max(max(mtx));
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
reconFullSFpyr2.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/reconFullSFpyr2.m
| 3,257 |
utf_8
|
447f5204894b159fbb4ea4de2dccf877
|
% RES = reconFullSFpyr2(PYR, INDICES, LEVS, BANDS, TWIDTH)
%
% Reconstruct image from its steerable pyramid representation, in the Fourier
% domain, as created by buildSFpyr.
% Unlike the standard transform, subdivides the highpass band into
% orientations.
function res = reconFullSFpyr2(pyr, pind, levs, bands, twidth)
%%------------------------------------------------------------
%% DEFAULTS:
if (exist('levs') ~= 1)
levs = 'all';
end
if (exist('bands') ~= 1)
bands = 'all';
end
if (exist('twidth') ~= 1)
twidth = 1;
elseif (twidth <= 0)
fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n');
twidth = 1;
end
%%------------------------------------------------------------
nbands = spyrNumBands(pind)/2;
maxLev = 2+spyrHt(pind(nbands+1:size(pind,1),:));
if strcmp(levs,'all')
levs = [0:maxLev]';
else
if (any(levs > maxLev) | any(levs < 0))
error(sprintf('Level numbers must be in the range [0, %d].', maxLev));
end
levs = levs(:);
end
if strcmp(bands,'all')
bands = [1:nbands]';
else
if (any(bands < 1) | any(bands > nbands))
error(sprintf('Band numbers must be in the range [1,3].', nbands));
end
bands = bands(:);
end
%----------------------------------------------------------------------
dims = pind(2,:);
ctr = ceil((dims+0.5)/2);
[xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ...
([1:dims(1)]-ctr(1))./(dims(1)/2) );
angle = atan2(yramp,xramp);
log_rad = sqrt(xramp.^2 + yramp.^2);
log_rad(ctr(1),ctr(2)) = log_rad(ctr(1),ctr(2)-1);
log_rad = log2(log_rad);
%% Radial transition function (a raised cosine in log-frequency):
[Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]);
Yrcos = sqrt(Yrcos);
YIrcos = sqrt(1.0 - Yrcos.^2);
if (size(pind,1) == 2)
if (any(levs==1))
resdft = fftshift(fft2(pyrBand(pyr,pind,2)));
else
resdft = zeros(pind(2,:));
end
else
resdft = reconSFpyrLevs(pyr(1+sum(prod(pind(1:nbands+1,:)')):size(pyr,1)), ...
pind(nbands+2:size(pind,1),:), ...
log_rad, Xrcos, Yrcos, angle, nbands, levs, bands);
end
lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
resdft = resdft .* lo0mask;
%% Oriented highpass bands:
if any(levs == 0)
lutsize = 1024;
Xcosn = pi*[-(2*lutsize+1):(lutsize+1)]/lutsize; % [-2*pi:pi]
order = nbands-1;
%% divide by sqrt(sum_(n=0)^(N-1) cos(pi*n/N)^(2(N-1)) )
const = (2^(2*order))*(factorial(order)^2)/(nbands*factorial(2*order));
Ycosn = sqrt(const) * (cos(Xcosn)).^order;
hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
ind = 1;
for b = 1:nbands
if any(bands == b)
anglemask = pointOp(angle,Ycosn,Xcosn(1)+pi*(b-1)/nbands,Xcosn(2)-Xcosn(1));
band = reshape(pyr(ind:ind+prod(dims)-1), dims(1), dims(2));
banddft = fftshift(fft2(band));
% make real the contents in the HF cross (to avoid information loss in these freqs.)
% It distributes evenly these contents among the nbands orientations
Mask = (sqrt(-1))^(nbands-1) * anglemask.*hi0mask;
Mask(1,:) = ones(1,size(Mask,2))/sqrt(nbands);
Mask(2:size(Mask,1),1) = ones(size(Mask,1)-1,1)/sqrt(nbands);
resdft = resdft + banddft.*Mask;
end
ind = ind + prod(dims);
end
end
res = real(ifft2(ifftshift(resdft)));
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
steer2HarmMtx.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/steer2HarmMtx.m
| 1,874 |
utf_8
|
8efc390a04b19bdec63526c7bbd1407e
|
% MTX = steer2HarmMtx(HARMONICS, ANGLES, REL_PHASES)
%
% Compute a steering matrix (maps a directional basis set onto the
% angular Fourier harmonics). HARMONICS is a vector specifying the
% angular harmonics contained in the steerable basis/filters. ANGLES
% (optional) is a vector specifying the angular position of each filter.
% REL_PHASES (optional, default = 'even') specifies whether the harmonics
% are cosine or sine phase aligned about those positions.
% The result matrix is suitable for passing to the function STEER.
% Eero Simoncelli, 7/96.
function mtx = steer2HarmMtx(harmonics, angles, evenorodd)
%%=================================================================
%%% Optional Parameters:
if (exist('evenorodd') ~= 1)
evenorodd = 'even';
end
% Make HARMONICS a row vector
harmonics = harmonics(:)';
numh = 2*size(harmonics,2) - any(harmonics == 0);
if (exist('angles') ~= 1)
angles = pi * [0:numh-1]'/numh;
else
angles = angles(:);
end
%%=================================================================
if isstr(evenorodd)
if strcmp(evenorodd,'even')
evenorodd = 0;
elseif strcmp(evenorodd,'odd')
evenorodd = 1;
else
error('EVEN_OR_ODD should be the string EVEN or ODD');
end
end
%% Compute inverse matrix, which maps Fourier components onto
%% steerable basis.
imtx = zeros(size(angles,1),numh);
col = 1;
for h=harmonics
args = h*angles;
if (h == 0)
imtx(:,col) = ones(size(angles));
col = col+1;
elseif evenorodd
imtx(:,col) = sin(args);
imtx(:,col+1) = -cos(args);
col = col+2;
else
imtx(:,col) = cos(args);
imtx(:,col+1) = sin(args);
col = col+2;
end
end
r = rank(imtx);
if (( r ~= numh ) & ( r ~= size(angles,1) ))
fprintf(2,'WARNING: matrix is not full rank');
end
mtx = pinv(imtx);
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
subMtx.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/subMtx.m
| 441 |
utf_8
|
18fe3fa6f65d3fbc8cd38682559c3619
|
% MTX = subMtx(VEC, DIMENSIONS, START_INDEX)
%
% Reshape a portion of VEC starting from START_INDEX (optional,
% default=1) to the given dimensions.
% Eero Simoncelli, 6/96.
function mtx = subMtx(vec, sz, offset)
if (exist('offset') ~= 1)
offset = 1;
end
vec = vec(:);
sz = sz(:);
if (size(sz,1) ~= 2)
error('DIMENSIONS must be a 2-vector.');
end
mtx = reshape( vec(offset:offset+prod(sz)-1), sz(1), sz(2) );
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
spyrHt.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/spyrHt.m
| 321 |
utf_8
|
acae1ee5a657f2e4d75b2e60e954a515
|
% [HEIGHT] = spyrHt(INDICES)
%
% Compute height of steerable pyramid with given index matrix.
% Eero Simoncelli, 6/96.
function [ht] = spyrHt(pind)
nbands = spyrNumBands(pind);
% Don't count lowpass, or highpass residual bands
if (size(pind,1) > 2)
ht = (size(pind,1)-2)/nbands;
else
ht = 0;
end
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
spyrBand.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/spyrBand.m
| 853 |
utf_8
|
24b93860a4de0346982a44edcb390ab5
|
% [LEV,IND] = spyrBand(PYR,INDICES,LEVEL,BAND)
%
% Access a band from a steerable pyramid.
%
% LEVEL indicates the scale (finest = 1, coarsest = spyrHt(INDICES)).
%
% BAND (optional, default=1) indicates which subband
% (1 = vertical, rest proceeding anti-clockwise).
% Eero Simoncelli, 6/96.
function res = spyrBand(pyr,pind,level,band)
if (exist('level') ~= 1)
level = 1;
end
if (exist('band') ~= 1)
band = 1;
end
nbands = spyrNumBands(pind);
if ((band > nbands) | (band < 1))
error(sprintf('Bad band number (%d) should be in range [1,%d].', band, nbands));
end
maxLev = spyrHt(pind);
if ((level > maxLev) | (level < 1))
error(sprintf('Bad level number (%d), should be in range [1,%d].', level, maxLev));
end
firstband = 1 + band + nbands*(level-1);
res = pyrBand(pyr, pind, firstband);
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
wpyrBand.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/wpyrBand.m
| 912 |
utf_8
|
ec3f9e1a26cc9775110888b67417876a
|
% RES = wpyrBand(PYR, INDICES, LEVEL, BAND)
%
% Access a subband from a separable QMF/wavelet pyramid.
%
% LEVEL (optional, default=1) indicates the scale (finest = 1,
% coarsest = wpyrHt(INDICES)).
%
% BAND (optional, default=1) indicates which subband (1=horizontal,
% 2=vertical, 3=diagonal).
% Eero Simoncelli, 6/96.
function im = wpyrBand(pyr,pind,level,band)
if (exist('level') ~= 1)
level = 1;
end
if (exist('band') ~= 1)
band = 1;
end
if ((pind(1,1) == 1) | (pind(1,2) ==1))
nbands = 1;
else
nbands = 3;
end
if ((band > nbands) | (band < 1))
error(sprintf('Bad band number (%d) should be in range [1,%d].', band, nbands));
end
maxLev = wpyrHt(pind);
if ((level > maxLev) | (level < 1))
error(sprintf('Bad level number (%d), should be in range [1,%d].', level, maxLev));
end
band = band + nbands*(level-1);
im = pyrBand(pyr,pind,band);
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
innerProd.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/innerProd.m
| 415 |
utf_8
|
e759ef690a2e4eadf5f81e0b8282888f
|
% RES = innerProd(MTX)
%
% Compute (MTX' * MTX) efficiently (i.e., without copying the matrix)
function res = innerProd(mtx)
%% NOTE: THIS CODE SHOULD NOT BE USED! (MEX FILE IS CALLED INSTEAD)
fprintf(1,'WARNING: You should compile the MEX version of "innerProd.c",\n found in the MEX subdirectory of matlabPyrTools, and put it in your matlab path. It is MUCH faster.\n');
res = mtx' * mtx;
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
reconSFpyr.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/reconSFpyr.m
| 3,141 |
utf_8
|
bb26483e3afdf1b4b46da4b35efaec7b
|
% RES = reconSFpyr(PYR, INDICES, LEVS, BANDS, TWIDTH)
%
% Reconstruct image from its steerable pyramid representation, in the Fourier
% domain, as created by buildSFpyr.
%
% PYR is a vector containing the N pyramid subbands, ordered from fine
% to coarse. INDICES is an Nx2 matrix containing the sizes of
% each subband. This is compatible with the MatLab Wavelet toolbox.
%
% LEVS (optional) should be a list of levels to include, or the string
% 'all' (default). 0 corresonds to the residual highpass subband.
% 1 corresponds to the finest oriented scale. The lowpass band
% corresponds to number spyrHt(INDICES)+1.
%
% BANDS (optional) should be a list of bands to include, or the string
% 'all' (default). 1 = vertical, rest proceeding anti-clockwise.
%
% TWIDTH is the width of the transition region of the radial lowpass
% function, in octaves (default = 1, which gives a raised cosine for
% the bandpass filters).
% Eero Simoncelli, 5/97.
function res = reconSFpyr(pyr, pind, levs, bands, twidth)
%%------------------------------------------------------------
%% DEFAULTS:
if (exist('levs') ~= 1)
levs = 'all';
end
if (exist('bands') ~= 1)
bands = 'all';
end
if (exist('twidth') ~= 1)
twidth = 1;
elseif (twidth <= 0)
fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n');
twidth = 1;
end
%%------------------------------------------------------------
nbands = spyrNumBands(pind);
maxLev = 1+spyrHt(pind);
if strcmp(levs,'all')
levs = [0:maxLev]';
else
if (any(levs > maxLev) | any(levs < 0))
error(sprintf('Level numbers must be in the range [0, %d].', maxLev));
end
levs = levs(:);
end
if strcmp(bands,'all')
bands = [1:nbands]';
else
if (any(bands < 1) | any(bands > nbands))
error(sprintf('Band numbers must be in the range [1,3].', nbands));
end
bands = bands(:);
end
%----------------------------------------------------------------------
dims = pind(1,:);
ctr = ceil((dims+0.5)/2);
[xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ...
([1:dims(1)]-ctr(1))./(dims(1)/2) );
angle = atan2(yramp,xramp);
log_rad = sqrt(xramp.^2 + yramp.^2);
log_rad(ctr(1),ctr(2)) = log_rad(ctr(1),ctr(2)-1);
log_rad = log2(log_rad);
%% Radial transition function (a raised cosine in log-frequency):
[Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]);
Yrcos = sqrt(Yrcos);
YIrcos = sqrt(abs(1.0 - Yrcos.^2));
if (size(pind,1) == 2)
if (any(levs==1))
resdft = fftshift(fft2(pyrBand(pyr,pind,2)));
else
resdft = zeros(pind(2,:));
end
else
resdft = reconSFpyrLevs(pyr(1+prod(pind(1,:)):size(pyr,1)), ...
pind(2:size(pind,1),:), ...
log_rad, Xrcos, Yrcos, angle, nbands, levs, bands);
end
lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
resdft = resdft .* lo0mask;
%% residual highpass subband
if any(levs == 0)
hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
hidft = fftshift(fft2(subMtx(pyr, pind(1,:))));
resdft = resdft + hidft .* hi0mask;
end
res = real(ifft2(ifftshift(resdft)));
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
corrDn.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/corrDn.m
| 2,195 |
utf_8
|
61533e2b3b4b039c523120d2ec1363aa
|
% RES = corrDn(IM, FILT, EDGES, STEP, START, STOP)
%
% Compute correlation of matrices IM with FILT, followed by
% downsampling. These arguments should be 1D or 2D matrices, and IM
% must be larger (in both dimensions) than FILT. The origin of filt
% is assumed to be floor(size(filt)/2)+1.
%
% EDGES is a string determining boundary handling:
% 'circular' - Circular convolution
% 'reflect1' - Reflect about the edge pixels
% 'reflect2' - Reflect, doubling the edge pixels
% 'repeat' - Repeat the edge pixels
% 'zero' - Assume values of zero outside image boundary
% 'extend' - Reflect and invert
% 'dont-compute' - Zero output when filter overhangs input boundaries
%
% Downsampling factors are determined by STEP (optional, default=[1 1]),
% which should be a 2-vector [y,x].
%
% The window over which the convolution occurs is specfied by START
% (optional, default=[1,1], and STOP (optional, default=size(IM)).
%
% NOTE: this operation corresponds to multiplication of a signal
% vector by a matrix whose rows contain copies of the FILT shifted by
% multiples of STEP. See upConv.m for the operation corresponding to
% the transpose of this matrix.
% Eero Simoncelli, 6/96, revised 2/97.
function res = corrDn(im, filt, edges, step, start, stop)
%% NOTE: THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD)
fprintf(1,'Warning: You should compile the MEX code for "corrDn", found in the MEX subdirectory. It is MUCH faster.\n');
%------------------------------------------------------------
%% OPTIONAL ARGS:
if (exist('edges') == 1)
if (strcmp(edges,'reflect1') ~= 1)
warning('Using REFLECT1 edge-handling (use MEX code for other options).');
end
end
if (exist('step') ~= 1)
step = [1,1];
end
if (exist('start') ~= 1)
start = [1,1];
end
if (exist('stop') ~= 1)
stop = size(im);
end
%------------------------------------------------------------
% Reverse order of taps in filt, to do correlation instead of convolution
filt = filt(size(filt,1):-1:1,size(filt,2):-1:1);
tmp = rconv2(im,filt);
res = tmp(start(1):step(1):stop(1),start(2):step(2):stop(2));
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
maxPyrHt.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/maxPyrHt.m
| 628 |
utf_8
|
00ee02d58475fcdf592ef59a15fa0af3
|
% HEIGHT = maxPyrHt(IMSIZE, FILTSIZE)
%
% Compute maximum pyramid height for given image and filter sizes.
% Specifically: the number of corrDn operations that can be sequentially
% performed when subsampling by a factor of 2.
% Eero Simoncelli, 6/96.
function height = maxPyrHt(imsz, filtsz)
imsz = imsz(:);
filtsz = filtsz(:);
if any(imsz == 1) % 1D image
imsz = prod(imsz);
filtsz = prod(filtsz);
elseif any(filtsz == 1) % 2D image, 1D filter
filtsz = [filtsz(1); filtsz(1)];
end
if any(imsz < filtsz)
height = 0;
else
height = 1 + maxPyrHt( floor(imsz/2), filtsz );
end
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
buildSFpyrLevs.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/buildSFpyrLevs.m
| 1,887 |
utf_8
|
e58fd43a3b9e8101ef5ada17c5116eed
|
% [PYR, INDICES] = buildSFpyrLevs(LODFT, LOGRAD, XRCOS, YRCOS, ANGLE, HEIGHT, NBANDS)
%
% Recursive function for constructing levels of a steerable pyramid. This
% is called by buildSFpyr, and is not usually called directly.
% Eero Simoncelli, 5/97.
function [pyr,pind] = buildSFpyrLevs(lodft,log_rad,Xrcos,Yrcos,angle,ht,nbands);
if (ht <= 0)
lo0 = ifft2(ifftshift(lodft));
pyr = real(lo0(:));
pind = size(lo0);
else
bands = zeros(prod(size(lodft)), nbands);
bind = zeros(nbands,2);
log_rad = log_rad + 1;
lutsize = 1024;
Xcosn = pi*[-(2*lutsize+1):(lutsize+1)]/lutsize; % [-2*pi:pi]
order = nbands-1;
%% divide by sqrt(sum_(n=0)^(N-1) cos(pi*n/N)^(2(N-1)) )
%% Thanks to Patrick Teo for writing this out :)
const = (2^(2*order))*(factorial(order)^2)/(nbands*factorial(2*order));
Ycosn = sqrt(const) * (cos(Xcosn)).^order;
himask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
for b = 1:nbands
anglemask = pointOp(angle, Ycosn, Xcosn(1)+pi*(b-1)/nbands, Xcosn(2)-Xcosn(1));
banddft = ((-i)^(nbands-1)) .* lodft .* anglemask .* himask;
band = ifft2(ifftshift(banddft));
bands(:,b) = real(band(:));
bind(b,:) = size(band);
end
dims = size(lodft);
ctr = ceil((dims+0.5)/2);
lodims = ceil((dims-0.5)/2);
loctr = ceil((lodims+0.5)/2);
lostart = ctr-loctr+1;
loend = lostart+lodims-1;
log_rad = log_rad(lostart(1):loend(1),lostart(2):loend(2));
angle = angle(lostart(1):loend(1),lostart(2):loend(2));
lodft = lodft(lostart(1):loend(1),lostart(2):loend(2));
YIrcos = abs(sqrt(1.0 - Yrcos.^2));
lomask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
lodft = lomask .* lodft;
[npyr,nind] = buildSFpyrLevs(lodft, log_rad, Xrcos, Yrcos, angle, ht-1, nbands);
pyr = [bands(:); npyr];
pind = [bind; nind];
end
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
pixelAxes.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/pixelAxes.m
| 2,053 |
utf_8
|
177c4d9d58d2280676a45dd83ef3e50a
|
% [ZOOM] = pixelAxes(DIMS, ZOOM)
%
% Set the axes of the current plot to cover a multiple of DIMS pixels,
% thereby eliminating screen aliasing artifacts when displaying an
% image of size DIMS.
%
% ZOOM (optional, default='same') expresses the desired number of
% samples displayed per screen pixel. It should be a scalar, which
% will be rounded to the nearest integer, or 1 over an integer. It
% may also be the string 'same' or 'auto', in which case the value is chosen so
% as to produce an image closest in size to the currently displayed
% image. It may also be the string 'full', in which case the image is
% made as large as possible while still fitting in the window.
% Eero Simoncelli, 2/97.
function [zoom] = pixelAxes(dims, zoom)
%------------------------------------------------------------
%% OPTIONAL ARGS:
if (exist('zoom') ~= 1)
zoom = 'same';
end
%% Reverse dimension order, since Figure Positions reported as (x,y).
dims = dims(2:-1:1);
%% Use MatLab's axis function to force square pixels, etc:
axis('image');
ax = gca;
oldunits = get(ax,'Units');
if strcmp(zoom,'full');
set(ax,'Units','normalized');
set(ax,'Position',[0 0 1 1]);
zoom = 'same';
end
set(ax,'Units','pixels');
pos = get(ax,'Position');
ctr = pos(1:2)+pos(3:4)/2;
if (strcmp(zoom,'same') | strcmp(zoom,'auto'))
%% HACK: enlarge slightly so that floor doesn't round down
zoom = min( pos(3:4) ./ (dims - 1) );
elseif isstr(zoom)
error(sprintf('Bad ZOOM argument: %s',zoom));
end
%% Force zoom value to be an integer, or inverse integer.
if (zoom < 0.75)
zoom = 1/ceil(1/zoom);
%% Round upward, subtracting 0.5 to avoid floating point errors.
newsz = ceil(zoom*(dims-0.5));
else
zoom = floor(zoom + 0.001); % Avoid floating pt errors
if (zoom < 1.5) % zoom=1
zoom = 1;
newsz = dims + 0.5;
else
newsz = zoom*(dims-1) + mod(zoom,2);
end
end
set(ax,'Position', [floor(ctr-newsz/2)+0.5, newsz] )
% Restore units
set(ax,'Units',oldunits);
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
pyrBandIndices.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/pyrBandIndices.m
| 613 |
utf_8
|
a5387a946b44f72051b9a72faae6130c
|
% RES = pyrBandIndices(INDICES, BAND_NUM)
%
% Return indices for accessing a subband from a pyramid
% (gaussian, laplacian, QMF/wavelet, steerable).
% Eero Simoncelli, 6/96.
function indices = pyrBandIndices(pind,band)
if ((band > size(pind,1)) | (band < 1))
error(sprintf('BAND_NUM must be between 1 and number of pyramid bands (%d).', ...
size(pind,1)));
end
if (size(pind,2) ~= 2)
error('INDICES must be an Nx2 matrix indicating the size of the pyramid subbands');
end
ind = 1;
for l=1:band-1
ind = ind + prod(pind(l,:));
end
indices = ind:ind+prod(pind(band,:))-1;
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
pointOp.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/pointOp.m
| 1,159 |
utf_8
|
040e1c3bc4afc4f9cfab4aa964e16082
|
% RES = pointOp(IM, LUT, ORIGIN, INCREMENT, WARNINGS)
%
% Apply a point operation, specified by lookup table LUT, to image IM.
% LUT must be a row or column vector, and is assumed to contain
% (equi-spaced) samples of the function. ORIGIN specifies the
% abscissa associated with the first sample, and INCREMENT specifies the
% spacing between samples. Between-sample values are estimated via
% linear interpolation. If WARNINGS is non-zero, the function prints
% a warning whenever the lookup table is extrapolated.
%
% This function is much faster than MatLab's interp1, and allows
% extrapolation beyond the lookup table domain. The drawbacks are
% that the lookup table must be equi-spaced, and the interpolation is
% linear.
% Eero Simoncelli, 8/96.
function res = pointOp(im, lut, origin, increment, warnings)
%% NOTE: THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD)
fprintf(1,'WARNING: You should compile the MEX code for "pointOp", found in the MEX subdirectory. It is MUCH faster.\n');
X = origin + increment*[0:size(lut(:),1)-1];
Y = lut(:);
res = reshape(interp1(X, Y, im(:), 'linear'),size(im));
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
reconWpyr.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/reconWpyr.m
| 4,140 |
utf_8
|
de1ba8ead0f28186c92b026ec2d0631a
|
% RES = reconWpyr(PYR, INDICES, FILT, EDGES, LEVS, BANDS)
%
% Reconstruct image from its separable orthonormal QMF/wavelet pyramid
% representation, as created by buildWpyr.
%
% PYR is a vector containing the N pyramid subbands, ordered from fine
% to coarse. INDICES is an Nx2 matrix containing the sizes of
% each subband. This is compatible with the MatLab Wavelet toolbox.
%
% FILT (optional) can be a string naming a standard filter (see
% namedFilter), or a vector which will be used for (separable)
% convolution. Default = 'qmf9'. EDGES specifies edge-handling,
% and defaults to 'reflect1' (see corrDn).
%
% LEVS (optional) should be a vector of levels to include, or the string
% 'all' (default). 1 corresponds to the finest scale. The lowpass band
% corresponds to wpyrHt(INDICES)+1.
%
% BANDS (optional) should be a vector of bands to include, or the string
% 'all' (default). 1=horizontal, 2=vertical, 3=diagonal. This is only used
% for pyramids of 2D images.
% Eero Simoncelli, 6/96.
function res = reconWpyr(pyr, ind, filt, edges, levs, bands)
if (nargin < 2)
error('First two arguments (PYR INDICES) are required');
end
%%------------------------------------------------------------
%% OPTIONAL ARGS:
if (exist('filt') ~= 1)
filt = 'qmf9';
end
if (exist('edges') ~= 1)
edges= 'reflect1';
end
if (exist('levs') ~= 1)
levs = 'all';
end
if (exist('bands') ~= 1)
bands = 'all';
end
%%------------------------------------------------------------
maxLev = 1+wpyrHt(ind);
if strcmp(levs,'all')
levs = [1:maxLev]';
else
if (any(levs > maxLev))
error(sprintf('Level numbers must be in the range [1, %d].', maxLev));
end
levs = levs(:);
end
if strcmp(bands,'all')
bands = [1:3]';
else
if (any(bands < 1) | any(bands > 3))
error('Band numbers must be in the range [1,3].');
end
bands = bands(:);
end
if isstr(filt)
filt = namedFilter(filt);
end
filt = filt(:);
hfilt = modulateFlip(filt);
%% For odd-length filters, stagger the sampling lattices:
if (mod(size(filt,1),2) == 0)
stag = 2;
else
stag = 1;
end
%% Compute size of result image: assumes critical sampling (boundaries correct)
res_sz = ind(1,:);
if (res_sz(1) == 1)
loind = 2;
res_sz(2) = sum(ind(:,2));
elseif (res_sz(2) == 1)
loind = 2;
res_sz(1) = sum(ind(:,1));
else
loind = 4;
res_sz = ind(1,:) + ind(2,:); %%horizontal + vertical bands.
hres_sz = [ind(1,1), res_sz(2)];
lres_sz = [ind(2,1), res_sz(2)];
end
%% First, recursively collapse coarser scales:
if any(levs > 1)
if (size(ind,1) > loind)
nres = reconWpyr( pyr(1+sum(prod(ind(1:loind-1,:)')):size(pyr,1)), ...
ind(loind:size(ind,1),:), filt, edges, levs-1, bands);
else
nres = pyrBand(pyr, ind, loind); % lowpass subband
end
if (res_sz(1) == 1)
res = upConv(nres, filt', edges, [1 2], [1 stag], res_sz);
elseif (res_sz(2) == 1)
res = upConv(nres, filt, edges, [2 1], [stag 1], res_sz);
else
ires = upConv(nres, filt', edges, [1 2], [1 stag], lres_sz);
res = upConv(ires, filt, edges, [2 1], [stag 1], res_sz);
end
else
res = zeros(res_sz);
end
%% Add in reconstructed bands from this level:
if any(levs == 1)
if (res_sz(1) == 1)
upConv(pyrBand(pyr,ind,1), hfilt', edges, [1 2], [1 2], res_sz, res);
elseif (res_sz(2) == 1)
upConv(pyrBand(pyr,ind,1), hfilt, edges, [2 1], [2 1], res_sz, res);
else
if any(bands == 1) % horizontal
ires = upConv(pyrBand(pyr,ind,1),filt',edges,[1 2],[1 stag],hres_sz);
upConv(ires,hfilt,edges,[2 1],[2 1],res_sz,res); %destructively modify res
end
if any(bands == 2) % vertical
ires = upConv(pyrBand(pyr,ind,2),hfilt',edges,[1 2],[1 2],lres_sz);
upConv(ires,filt,edges,[2 1],[stag 1],res_sz,res); %destructively modify res
end
if any(bands == 3) % diagonal
ires = upConv(pyrBand(pyr,ind,3),hfilt',edges,[1 2],[1 2],hres_sz);
upConv(ires,hfilt,edges,[2 1],[2 1],res_sz,res); %destructively modify res
end
end
end
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
shift.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/shift.m
| 453 |
utf_8
|
3e12f9ab9679c3cc88b56885c167121a
|
% [RES] = shift(MTX, OFFSET)
%
% Circular shift 2D matrix samples by OFFSET (a [Y,X] 2-vector),
% such that RES(POS) = MTX(POS-OFFSET).
function res = shift(mtx, offset)
dims = size(mtx);
offset = mod(-offset,dims);
res = [ mtx(offset(1)+1:dims(1), offset(2)+1:dims(2)), ...
mtx(offset(1)+1:dims(1), 1:offset(2)); ...
mtx(1:offset(1), offset(2)+1:dims(2)), ...
mtx(1:offset(1), 1:offset(2)) ];
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
namedFilter.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/namedFilter.m
| 3,278 |
utf_8
|
837312a94d58a44dd9503ab3736cffe7
|
% KERNEL = NAMED_FILTER(NAME)
%
% Some standard 1D filter kernels. These are scaled such that
% their L2-norm is 1.0.
%
% binomN - binomial coefficient filter of order N-1
% haar: - Haar wavelet.
% qmf8, qmf12, qmf16 - Symmetric Quadrature Mirror Filters [Johnston80]
% daub2,daub3,daub4 - Daubechies wavelet [Daubechies88].
% qmf5, qmf9, qmf13: - Symmetric Quadrature Mirror Filters [Simoncelli88,Simoncelli90]
%
% See bottom of file for full citations.
% Eero Simoncelli, 6/96.
function [kernel] = named_filter(name)
if strcmp(name(1:min(5,size(name,2))), 'binom')
kernel = sqrt(2) * binomialFilter(str2num(name(6:size(name,2))));
elseif strcmp(name,'qmf5')
kernel = [-0.076103 0.3535534 0.8593118 0.3535534 -0.076103]';
elseif strcmp(name,'qmf9')
kernel = [0.02807382 -0.060944743 -0.073386624 0.41472545 0.7973934 ...
0.41472545 -0.073386624 -0.060944743 0.02807382]';
elseif strcmp(name,'qmf13')
kernel = [-0.014556438 0.021651438 0.039045125 -0.09800052 ...
-0.057827797 0.42995453 0.7737113 0.42995453 -0.057827797 ...
-0.09800052 0.039045125 0.021651438 -0.014556438]';
elseif strcmp(name,'qmf8')
kernel = sqrt(2) * [0.00938715 -0.07065183 0.06942827 0.4899808 ...
0.4899808 0.06942827 -0.07065183 0.00938715 ]';
elseif strcmp(name,'qmf12')
kernel = sqrt(2) * [-0.003809699 0.01885659 -0.002710326 -0.08469594 ...
0.08846992 0.4843894 0.4843894 0.08846992 -0.08469594 -0.002710326 ...
0.01885659 -0.003809699 ]';
elseif strcmp(name,'qmf16')
kernel = sqrt(2) * [0.001050167 -0.005054526 -0.002589756 0.0276414 -0.009666376 ...
-0.09039223 0.09779817 0.4810284 0.4810284 0.09779817 -0.09039223 -0.009666376 ...
0.0276414 -0.002589756 -0.005054526 0.001050167 ]';
elseif strcmp(name,'haar')
kernel = [1 1]' / sqrt(2);
elseif strcmp(name,'daub2')
kernel = [0.482962913145 0.836516303738 0.224143868042 -0.129409522551]';
elseif strcmp(name,'daub3')
kernel = [0.332670552950 0.806891509311 0.459877502118 -0.135011020010 ...
-0.085441273882 0.035226291882]';
elseif strcmp(name,'daub4')
kernel = [0.230377813309 0.714846570553 0.630880767930 -0.027983769417 ...
-0.187034811719 0.030841381836 0.032883011667 -0.010597401785]';
elseif strcmp(name,'gauss5') % for backward-compatibility
kernel = sqrt(2) * [0.0625 0.25 0.375 0.25 0.0625]';
elseif strcmp(name,'gauss3') % for backward-compatibility
kernel = sqrt(2) * [0.25 0.5 0.25]';
else
error(sprintf('Bad filter name: %s\n',name));
end
% [Johnston80] - J D Johnston, "A filter family designed for use in quadrature
% mirror filter banks", Proc. ICASSP, pp 291-294, 1980.
%
% [Daubechies88] - I Daubechies, "Orthonormal bases of compactly supported wavelets",
% Commun. Pure Appl. Math, vol. 42, pp 909-996, 1988.
%
% [Simoncelli88] - E P Simoncelli, "Orthogonal sub-band image transforms",
% PhD Thesis, MIT Dept. of Elec. Eng. and Comp. Sci. May 1988.
% Also available as: MIT Media Laboratory Vision and Modeling Technical
% Report #100.
%
% [Simoncelli90] - E P Simoncelli and E H Adelson, "Subband image coding",
% Subband Transforms, chapter 4, ed. John W Woods, Kluwer Academic
% Publishers, Norwell, MA, 1990, pp 143--192.
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
wpyrHt.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/wpyrHt.m
| 285 |
utf_8
|
5b256ddf8ffadaa7888328a31159035e
|
% [HEIGHT] = wpyrHt(INDICES)
%
% Compute height of separable QMF/wavelet pyramid with given index matrix.
% Eero Simoncelli, 6/96.
function [ht] = wpyrHt(pind)
if ((pind(1,1) == 1) | (pind(1,2) ==1))
nbands = 1;
else
nbands = 3;
end
ht = (size(pind,1)-1)/nbands;
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
buildSFpyr.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/buildSFpyr.m
| 3,362 |
utf_8
|
c23de2136a85b1bc58eff471a98d44aa
|
% [PYR, INDICES, STEERMTX, HARMONICS] = buildSFpyr(IM, HEIGHT, ORDER, TWIDTH)
%
% Construct a steerable pyramid on matrix IM, in the Fourier domain.
% This is similar to buildSpyr, except that:
%
% + Reconstruction is exact (within floating point errors)
% + It can produce any number of orientation bands.
% - Typically slower, especially for non-power-of-two sizes.
% - Boundary-handling is circular.
%
% HEIGHT (optional) specifies the number of pyramid levels to build. Default
% is maxPyrHt(size(IM),size(FILT));
%
% The squared radial functions tile the Fourier plane, with a raised-cosine
% falloff. Angular functions are cos(theta-k\pi/(K+1))^K, where K is
% the ORDER (one less than the number of orientation bands, default= 3).
%
% TWIDTH is the width of the transition region of the radial lowpass
% function, in octaves (default = 1, which gives a raised cosine for
% the bandpass filters).
%
% PYR is a vector containing the N pyramid subbands, ordered from fine
% to coarse. INDICES is an Nx2 matrix containing the sizes of
% each subband. This is compatible with the MatLab Wavelet toolbox.
% See the function STEER for a description of STEERMTX and HARMONICS.
% Eero Simoncelli, 5/97.
% See http://www.cis.upenn.edu/~eero/steerpyr.html for more
% information about the Steerable Pyramid image decomposition.
function [pyr,pind,steermtx,harmonics] = buildSFpyr(im, ht, order, twidth)
%-----------------------------------------------------------------
%% DEFAULTS:
max_ht = floor(log2(min(size(im)))+2);
if (exist('ht') ~= 1)
ht = max_ht;
else
if (ht > max_ht)
error(sprintf('Cannot build pyramid higher than %d levels.',max_ht));
end
end
if (exist('order') ~= 1)
order = 3;
elseif ((order > 15) | (order < 0))
fprintf(1,'Warning: ORDER must be an integer in the range [0,15]. Truncating.\n');
order = min(max(order,0),15);
else
order = round(order);
end
nbands = order+1;
if (exist('twidth') ~= 1)
twidth = 1;
elseif (twidth <= 0)
fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n');
twidth = 1;
end
%-----------------------------------------------------------------
%% Steering stuff:
if (mod((nbands),2) == 0)
harmonics = [0:(nbands/2)-1]'*2 + 1;
else
harmonics = [0:(nbands-1)/2]'*2;
end
steermtx = steer2HarmMtx(harmonics, pi*[0:nbands-1]/nbands, 'even');
%-----------------------------------------------------------------
dims = size(im);
ctr = ceil((dims+0.5)/2);
[xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ...
([1:dims(1)]-ctr(1))./(dims(1)/2) );
angle = atan2(yramp,xramp);
log_rad = sqrt(xramp.^2 + yramp.^2);
log_rad(ctr(1),ctr(2)) = log_rad(ctr(1),ctr(2)-1);
log_rad = log2(log_rad);
%% Radial transition function (a raised cosine in log-frequency):
[Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]);
Yrcos = sqrt(Yrcos);
YIrcos = sqrt(1.0 - Yrcos.^2);
lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
imdft = fftshift(fft2(im));
lo0dft = imdft .* lo0mask;
[pyr,pind] = buildSFpyrLevs(lo0dft, log_rad, Xrcos, Yrcos, angle, ht, nbands);
hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0);
hi0dft = imdft .* hi0mask;
hi0 = ifft2(ifftshift(hi0dft));
pyr = [real(hi0(:)) ; pyr];
pind = [size(hi0); pind];
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
modulateFlip.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/modulateFlip.m
| 480 |
utf_8
|
9f2392c42cf1ad73accf1b25c3327ac7
|
% [HFILT] = modulateFlipShift(LFILT)
%
% QMF/Wavelet highpass filter construction: modulate by (-1)^n,
% reverse order (and shift by one, which is handled by the convolution
% routines). This is an extension of the original definition of QMF's
% (e.g., see Simoncelli90).
% Eero Simoncelli, 7/96.
function [hfilt] = modulateFlipShift(lfilt)
lfilt = lfilt(:);
sz = size(lfilt,1);
sz2 = ceil(sz/2);
ind = [sz:-1:1]';
hfilt = lfilt(ind) .* (-1).^(ind-sz2);
|
github
|
phcerdan/BLS-GSM_Denoising_Portilla-master
|
spyrNumBands.m
|
.m
|
BLS-GSM_Denoising_Portilla-master/Simoncelli_PyrTools/spyrNumBands.m
| 500 |
utf_8
|
2173f8841142e73d6f87cb5242a2f9a7
|
% [NBANDS] = spyrNumBands(INDICES)
%
% Compute number of orientation bands in a steerable pyramid with
% given index matrix. If the pyramid contains only the highpass and
% lowpass bands (i.e., zero levels), returns 0.
% Eero Simoncelli, 2/97.
function [nbands] = spyrNumBands(pind)
if (size(pind,1) == 2)
nbands = 0;
else
% Count number of orientation bands:
b = 3;
while ((b <= size(pind,1)) & all( pind(b,:) == pind(2,:)) )
b = b+1;
end
nbands = b-2;
end
|
github
|
biomedical-cybernetics/coalescent_embedding-master
|
lanbpro.m
|
.m
|
coalescent_embedding-master/coemb_svds_eigs/lanbpro.m
| 19,514 |
utf_8
|
897b157335c2a5c269845380328709c4
|
function [U,B_k,V,p,ierr,work] = lanbpro(varargin)
%LANBPRO Lanczos bidiagonalization with partial reorthogonalization.
% LANBPRO computes the Lanczos bidiagonalization of a real
% matrix using the with partial reorthogonalization.
%
% [U_k,B_k,V_k,R,ierr,work] = LANBPRO(A,K,R0,OPTIONS,U_old,B_old,V_old)
% [U_k,B_k,V_k,R,ierr,work] = LANBPRO('Afun','Atransfun',M,N,K,R0, ...
% OPTIONS,U_old,B_old,V_old)
%
% Computes K steps of the Lanczos bidiagonalization algorithm with partial
% reorthogonalization (BPRO) with M-by-1 starting vector R0, producing a
% lower bidiagonal K-by-K matrix B_k, an N-by-K matrix V_k, an M-by-K
% matrix U_k and an M-by-1 vector R such that
% A*V_k = U_k*B_k + R
% Partial reorthogonalization is used to keep the columns of V_K and U_k
% semiorthogonal:
% MAX(DIAG((EYE(K) - V_K'*V_K))) <= OPTIONS.delta
% and
% MAX(DIAG((EYE(K) - U_K'*U_K))) <= OPTIONS.delta.
%
% B_k = LANBPRO(...) returns the bidiagonal matrix only.
%
% The first input argument is either a real matrix, or a string
% containing the name of an M-file which applies a linear operator
% to the columns of a given matrix. In the latter case, the second
% input must be the name of an M-file which applies the transpose of
% the same linear operator to the columns of a given matrix,
% and the third and fourth arguments must be M and N, the dimensions
% of then problem.
%
% The OPTIONS structure is used to control the reorthogonalization:
% OPTIONS.delta: Desired level of orthogonality
% (default = sqrt(eps/K)).
% OPTIONS.eta : Level of orthogonality after reorthogonalization
% (default = eps^(3/4)/sqrt(K)).
% OPTIONS.cgs : Flag for switching between different reorthogonalization
% algorithms:
% 0 = iterated modified Gram-Schmidt (default)
% 1 = iterated classical Gram-Schmidt
% OPTIONS.elr : If OPTIONS.elr = 1 (default) then extended local
% reorthogonalization is enforced.
% OPTIONS.onesided
% : If OPTIONS.onesided = 0 (default) then both the left
% (U) and right (V) Lanczos vectors are kept
% semiorthogonal.
% OPTIONS.onesided = 1 then only the columns of U are
% are reorthogonalized.
% OPTIONS.onesided = -1 then only the columns of V are
% are reorthogonalized.
% OPTIONS.waitbar
% : The progress of the algorithm is display graphically.
%
% If both R0, U_old, B_old, and V_old are provided, they must
% contain a partial Lanczos bidiagonalization of A on the form
%
% A V_old = U_old B_old + R0 .
%
% In this case the factorization is extended to dimension K x K by
% continuing the Lanczos bidiagonalization algorithm with R0 as a
% starting vector.
%
% The output array work contains information about the work used in
% reorthogonalizing the u- and v-vectors.
% work = [ RU PU ]
% [ RV PV ]
% where
% RU = Number of reorthogonalizations of U.
% PU = Number of inner products used in reorthogonalizing U.
% RV = Number of reorthogonalizations of V.
% PV = Number of inner products used in reorthogonalizing V.
% References:
% R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998.
%
% G. H. Golub & C. F. Van Loan, "Matrix Computations",
% 3. Ed., Johns Hopkins, 1996. Section 9.3.4.
%
% B. N. Parlett, ``The Symmetric Eigenvalue Problem'',
% Prentice-Hall, Englewood Cliffs, NJ, 1980.
%
% H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'',
% Math. Comp. 42 (1984), no. 165, 115--142.
%
% Rasmus Munk Larsen, DAIMI, 1998.
% Check input arguments.
global LANBPRO_TRUTH
LANBPRO_TRUTH=0;
if LANBPRO_TRUTH==1
global MU NU MUTRUE NUTRUE
global MU_AFTER NU_AFTER MUTRUE_AFTER NUTRUE_AFTER
end
if nargin<1 | length(varargin)<2
error('Not enough input arguments.');
end
narg=length(varargin);
A = varargin{1};
if isnumeric(A) | isstruct(A)
if isnumeric(A)
if ~isreal(A)
error('A must be real')
end
[m n] = size(A);
elseif isstruct(A)
[m n] = size(A.R);
end
k=varargin{2};
if narg >= 3 & ~isempty(varargin{3});
p = varargin{3};
else
p = rand(m,1)-0.5;
end
if narg < 4, options = []; else options=varargin{4}; end
if narg > 4
if narg<7
error('All or none of U_old, B_old and V_old must be provided.')
else
U = varargin{5}; B_k = varargin{6}; V = varargin{7};
end
else
U = []; B_k = []; V = [];
end
if narg > 7, anorm=varargin{8}; else anorm = []; end
else
if narg<5
error('Not enough input arguments.');
end
Atrans = varargin{2};
if ~isstr(Atrans)
error('Afunc and Atransfunc must be names of m-files')
end
m = varargin{3};
n = varargin{4};
if ~isreal(n) | abs(fix(n)) ~= n | ~isreal(m) | abs(fix(m)) ~= m
error('M and N must be positive integers.')
end
k=varargin{5};
if narg < 6, p = rand(m,1)-0.5; else p=varargin{6}; end
if narg < 7, options = []; else options=varargin{7}; end
if narg > 7
if narg < 10
error('All or none of U_old, B_old and V_old must be provided.')
else
U = varargin{8}; B_k = varargin{9}; V = varargin{10};
end
else
U = []; B_k = []; V=[];
end
if narg > 10, anorm=varargin{11}; else anorm = []; end
end
% Quick return for min(m,n) equal to 0 or 1.
if min(m,n) == 0
U = []; B_k = []; V = []; p = []; ierr = 0; work = zeros(2,2);
return
elseif min(m,n) == 1
if isnumeric(A)
U = 1; B_k = A; V = 1; p = 0; ierr = 0; work = zeros(2,2);
else
U = 1; B_k = feval(A,1); V = 1; p = 0; ierr = 0; work = zeros(2,2);
end
if nargout<3
U = B_k;
end
return
end
% Set options.
%m2 = 3/2*(sqrt(m)+1);
%n2 = 3/2*(sqrt(n)+1);
m2 = 3/2;
n2 = 3/2;
delta = sqrt(eps/k); % Desired level of orthogonality.
eta = eps^(3/4)/sqrt(k); % Level of orth. after reorthogonalization.
cgs = 0; % Flag for switching between iterated MGS and CGS.
elr = 2; % Flag for switching extended local
% reorthogonalization on and off.
gamma = 1/sqrt(2); % Tolerance for iterated Gram-Schmidt.
onesided = 0; t = 0; waitb = 0;
% Parse options struct
if ~isempty(options) & isstruct(options)
c = fieldnames(options);
for i=1:length(c)
if strmatch(c(i),'delta'), delta = getfield(options,'delta'); end
if strmatch(c(i),'eta'), eta = getfield(options,'eta'); end
if strmatch(c(i),'cgs'), cgs = getfield(options,'cgs'); end
if strmatch(c(i),'elr'), elr = getfield(options,'elr'); end
if strmatch(c(i),'gamma'), gamma = getfield(options,'gamma'); end
if strmatch(c(i),'onesided'), onesided = getfield(options,'onesided'); end
if strmatch(c(i),'waitbar'), waitb=1; end
end
end
if waitb
waitbarh = waitbar(0,'Lanczos bidiagonalization in progress...');
end
if isempty(anorm)
anorm = []; est_anorm=1;
else
est_anorm=0;
end
% Conservative statistical estimate on the size of round-off terms.
% Notice that {\bf u} == eps/2.
FUDGE = 1.01; % Fudge factor for ||A||_2 estimate.
npu = 0; npv = 0; ierr = 0;
p = p(:);
% Prepare for Lanczos iteration.
if isempty(U)
V = zeros(n,k); U = zeros(m,k);
beta = zeros(k+1,1); alpha = zeros(k,1);
beta(1) = norm(p);
% Initialize MU/NU-recurrences for monitoring loss of orthogonality.
nu = zeros(k,1); mu = zeros(k+1,1);
mu(1)=1; nu(1)=1;
numax = zeros(k,1); mumax = zeros(k,1);
force_reorth = 0; nreorthu = 0; nreorthv = 0;
j0 = 1;
else
j = size(U,2); % Size of existing factorization
% Allocate space for Lanczos vectors
U = [U, zeros(m,k-j)];
V = [V, zeros(n,k-j)];
alpha = zeros(k+1,1); beta = zeros(k+1,1);
alpha(1:j) = diag(B_k); if j>1 beta(2:j) = diag(B_k,-1); end
beta(j+1) = norm(p);
% Reorthogonalize p.
if j<k & beta(j+1)*delta < anorm*eps,
fro = 1;
ierr = j;
end
int = [1:j]';
[p,beta(j+1),rr] = reorth(U,p,beta(j+1),int,gamma,cgs);
npu = rr*j; nreorthu = 1; force_reorth= 1;
% Compute Gerscgorin bound on ||B_k||_2
if est_anorm
anorm = FUDGE*sqrt(norm(B_k'*B_k,1));
end
mu = m2*eps*ones(k+1,1); nu = zeros(k,1);
numax = zeros(k,1); mumax = zeros(k,1);
force_reorth = 1; nreorthu = 0; nreorthv = 0;
j0 = j+1;
end
if isnumeric(A)
At = A';
end
if delta==0
fro = 1; % The user has requested full reorthogonalization.
else
fro = 0;
end
if LANBPRO_TRUTH==1
MUTRUE = zeros(k,k); NUTRUE = zeros(k-1,k-1);
MU = zeros(k,k); NU = zeros(k-1,k-1);
MUTRUE_AFTER = zeros(k,k); NUTRUE_AFTER = zeros(k-1,k-1);
MU_AFTER = zeros(k,k); NU_AFTER = zeros(k-1,k-1);
end
% Perform Lanczos bidiagonalization with partial reorthogonalization.
for j=j0:k
if waitb
waitbar(j/k,waitbarh)
end
if beta(j) ~= 0
U(:,j) = p/beta(j);
else
U(:,j) = p;
end
% Replace norm estimate with largest Ritz value.
if j==6
B = [[diag(alpha(1:j-1))+diag(beta(2:j-1),-1)]; ...
[zeros(1,j-2),beta(j)]];
anorm = FUDGE*norm(B);
est_anorm = 0;
end
%%%%%%%%%% Lanczos step to generate v_j. %%%%%%%%%%%%%
if j==1
if isnumeric(A)
r = At*U(:,1);
elseif isstruct(A)
r = A.R\U(:,1);
else
r = feval(Atrans,U(:,1));
end
alpha(1) = norm(r);
if est_anorm
anorm = FUDGE*alpha(1);
end
else
if isnumeric(A)
r = At*U(:,j) - beta(j)*V(:,j-1);
elseif isstruct(A)
r = A.R\U(:,j) - beta(j)*V(:,j-1);
else
r = feval(Atrans,U(:,j)) - beta(j)*V(:,j-1);
end
alpha(j) = norm(r);
% Extended local reorthogonalization
if alpha(j)<gamma*beta(j) & elr & ~fro
normold = alpha(j);
stop = 0;
while ~stop
t = V(:,j-1)'*r;
r = r - V(:,j-1)*t;
alpha(j) = norm(r);
if beta(j) ~= 0
beta(j) = beta(j) + t;
end
if alpha(j)>=gamma*normold
stop = 1;
else
normold = alpha(j);
end
end
end
if est_anorm
if j==2
anorm = max(anorm,FUDGE*sqrt(alpha(1)^2+beta(2)^2+alpha(2)*beta(2)));
else
anorm = max(anorm,FUDGE*sqrt(alpha(j-1)^2+beta(j)^2+alpha(j-1)* ...
beta(j-1) + alpha(j)*beta(j)));
end
end
if ~fro & alpha(j) ~= 0
% Update estimates of the level of orthogonality for the
% columns 1 through j-1 in V.
nu = update_nu(nu,mu,j,alpha,beta,anorm);
numax(j) = max(abs(nu(1:j-1)));
end
if j>1 & LANBPRO_TRUTH
NU(1:j-1,j-1) = nu(1:j-1);
NUTRUE(1:j-1,j-1) = V(:,1:j-1)'*r/alpha(j);
end
if elr>0
nu(j-1) = n2*eps;
end
% IF level of orthogonality is worse than delta THEN
% Reorthogonalize v_j against some previous v_i's, 0<=i<j.
if onesided~=-1 & ( fro | numax(j) > delta | force_reorth ) & alpha(j)~=0
% Decide which vectors to orthogonalize against:
if fro | eta==0
int = [1:j-1]';
elseif force_reorth==0
int = compute_int(nu,j-1,delta,eta,0,0,0);
end
% Else use int from last reorth. to avoid spillover from mu_{j-1}
% to nu_j.
% Reorthogonalize v_j
[r,alpha(j),rr] = reorth(V,r,alpha(j),int,gamma,cgs);
npv = npv + rr*length(int); % number of inner products.
nu(int) = n2*eps; % Reset nu for orthogonalized vectors.
% If necessary force reorthogonalization of u_{j+1}
% to avoid spillover
if force_reorth==0
force_reorth = 1;
else
force_reorth = 0;
end
nreorthv = nreorthv + 1;
end
end
% Check for convergence or failure to maintain semiorthogonality
if alpha(j) < max(n,m)*anorm*eps & j<k,
% If alpha is "small" we deflate by setting it
% to 0 and attempt to restart with a basis for a new
% invariant subspace by replacing r with a random starting vector:
%j
%disp('restarting, alpha = 0')
alpha(j) = 0;
bailout = 1;
for attempt=1:3
r = rand(m,1)-0.5;
if isnumeric(A)
r = At*r;
elseif isstruct(A)
r = A.R\r;
else
r = feval(Atrans,r);
end
nrm=sqrt(r'*r); % not necessary to compute the norm accurately here.
int = [1:j-1]';
[r,nrmnew,rr] = reorth(V,r,nrm,int,gamma,cgs);
npv = npv + rr*length(int(:)); nreorthv = nreorthv + 1;
nu(int) = n2*eps;
if nrmnew > 0
% A vector numerically orthogonal to span(Q_k(:,1:j)) was found.
% Continue iteration.
bailout=0;
break;
end
end
if bailout
j = j-1;
ierr = -j;
break;
else
r=r/nrmnew; % Continue with new normalized r as starting vector.
force_reorth = 1;
if delta>0
fro = 0; % Turn off full reorthogonalization.
end
end
elseif j<k & ~fro & anorm*eps > delta*alpha(j)
% fro = 1;
ierr = j;
end
if j>1 & LANBPRO_TRUTH
NU_AFTER(1:j-1,j-1) = nu(1:j-1);
NUTRUE_AFTER(1:j-1,j-1) = V(:,1:j-1)'*r/alpha(j);
end
if alpha(j) ~= 0
V(:,j) = r/alpha(j);
else
V(:,j) = r;
end
%%%%%%%%%% Lanczos step to generate u_{j+1}. %%%%%%%%%%%%%
if waitb
waitbar((2*j+1)/(2*k),waitbarh)
end
if isnumeric(A)
p = A*V(:,j) - alpha(j)*U(:,j);
elseif isstruct(A)
p = A.Rt\V(:,j) - alpha(j)*U(:,j);
else
p = feval(A,V(:,j)) - alpha(j)*U(:,j);
end
beta(j+1) = norm(p);
% Extended local reorthogonalization
if beta(j+1)<gamma*alpha(j) & elr & ~fro
normold = beta(j+1);
stop = 0;
while ~stop
t = U(:,j)'*p;
p = p - U(:,j)*t;
beta(j+1) = norm(p);
if alpha(j) ~= 0
alpha(j) = alpha(j) + t;
end
if beta(j+1) >= gamma*normold
stop = 1;
else
normold = beta(j+1);
end
end
end
if est_anorm
% We should update estimate of ||A|| before updating mu - especially
% important in the first step for problems with large norm since alpha(1)
% may be a severe underestimate!
if j==1
anorm = max(anorm,FUDGE*pythag(alpha(1),beta(2)));
else
anorm = max(anorm,FUDGE*sqrt(alpha(j)^2+beta(j+1)^2 + alpha(j)*beta(j)));
end
end
if ~fro & beta(j+1) ~= 0
% Update estimates of the level of orthogonality for the columns of V.
mu = update_mu(mu,nu,j,alpha,beta,anorm);
mumax(j) = max(abs(mu(1:j)));
end
if LANBPRO_TRUTH==1
MU(1:j,j) = mu(1:j);
MUTRUE(1:j,j) = U(:,1:j)'*p/beta(j+1);
end
if elr>0
mu(j) = m2*eps;
end
% IF level of orthogonality is worse than delta THEN
% Reorthogonalize u_{j+1} against some previous u_i's, 0<=i<=j.
if onesided~=1 & (fro | mumax(j) > delta | force_reorth) & beta(j+1)~=0
% Decide which vectors to orthogonalize against.
if fro | eta==0
int = [1:j]';
elseif force_reorth==0
int = compute_int(mu,j,delta,eta,0,0,0);
else
int = [int; max(int)+1];
end
% Else use int from last reorth. to avoid spillover from nu to mu.
% if onesided~=0
% fprintf('i = %i, nr = %i, fro = %i\n',j,size(int(:),1),fro)
% end
% Reorthogonalize u_{j+1}
[p,beta(j+1),rr] = reorth(U,p,beta(j+1),int,gamma,cgs);
npu = npu + rr*length(int); nreorthu = nreorthu + 1;
% Reset mu to epsilon.
mu(int) = m2*eps;
if force_reorth==0
force_reorth = 1; % Force reorthogonalization of v_{j+1}.
else
force_reorth = 0;
end
end
% Check for convergence or failure to maintain semiorthogonality
if beta(j+1) < max(m,n)*anorm*eps & j<k,
% If beta is "small" we deflate by setting it
% to 0 and attempt to restart with a basis for a new
% invariant subspace by replacing p with a random starting vector:
%j
%disp('restarting, beta = 0')
beta(j+1) = 0;
bailout = 1;
for attempt=1:3
p = rand(n,1)-0.5;
if isnumeric(A)
p = A*p;
elseif isstruct(A)
p = A.Rt\p;
else
p = feval(A,p);
end
nrm=sqrt(p'*p); % not necessary to compute the norm accurately here.
int = [1:j]';
[p,nrmnew,rr] = reorth(U,p,nrm,int,gamma,cgs);
npu = npu + rr*length(int(:)); nreorthu = nreorthu + 1;
mu(int) = m2*eps;
if nrmnew > 0
% A vector numerically orthogonal to span(Q_k(:,1:j)) was found.
% Continue iteration.
bailout=0;
break;
end
end
if bailout
ierr = -j;
break;
else
p=p/nrmnew; % Continue with new normalized p as starting vector.
force_reorth = 1;
if delta>0
fro = 0; % Turn off full reorthogonalization.
end
end
elseif j<k & ~fro & anorm*eps > delta*beta(j+1)
% fro = 1;
ierr = j;
end
if LANBPRO_TRUTH==1
MU_AFTER(1:j,j) = mu(1:j);
MUTRUE_AFTER(1:j,j) = U(:,1:j)'*p/beta(j+1);
end
end
if waitb
close(waitbarh)
end
if j<k
k = j;
end
B_k = spdiags([alpha(1:k) [beta(2:k);0]],[0 -1],k,k);
if nargout==1
U = B_k;
elseif k~=size(U,2) | k~=size(V,2)
U = U(:,1:k);
V = V(:,1:k);
end
if nargout>5
work = [[nreorthu,npu];[nreorthv,npv]];
end
function mu = update_mu(muold,nu,j,alpha,beta,anorm)
% UPDATE_MU: Update the mu-recurrence for the u-vectors.
%
% mu_new = update_mu(mu,nu,j,alpha,beta,anorm)
% Rasmus Munk Larsen, DAIMI, 1998.
binv = 1/beta(j+1);
mu = muold;
eps1 = 100*eps/2;
if j==1
T = eps1*(pythag(alpha(1),beta(2)) + pythag(alpha(1),beta(1)));
T = T + eps1*anorm;
mu(1) = T / beta(2);
else
mu(1) = alpha(1)*nu(1) - alpha(j)*mu(1);
% T = eps1*(pythag(alpha(j),beta(j+1)) + pythag(alpha(1),beta(1)));
T = eps1*(sqrt(alpha(j).^2+beta(j+1).^2) + sqrt(alpha(1).^2+beta(1).^2));
T = T + eps1*anorm;
mu(1) = (mu(1) + sign(mu(1))*T) / beta(j+1);
% Vectorized version of loop:
if j>2
k=2:j-1;
mu(k) = alpha(k).*nu(k) + beta(k).*nu(k-1) - alpha(j)*mu(k);
%T = eps1*(pythag(alpha(j),beta(j+1)) + pythag(alpha(k),beta(k)));
T = eps1*(sqrt(alpha(j).^2+beta(j+1).^2) + sqrt(alpha(k).^2+beta(k).^2));
T = T + eps1*anorm;
mu(k) = binv*(mu(k) + sign(mu(k)).*T);
end
% T = eps1*(pythag(alpha(j),beta(j+1)) + pythag(alpha(j),beta(j)));
T = eps1*(sqrt(alpha(j).^2+beta(j+1).^2) + sqrt(alpha(j).^2+beta(j).^2));
T = T + eps1*anorm;
mu(j) = beta(j)*nu(j-1);
mu(j) = (mu(j) + sign(mu(j))*T) / beta(j+1);
end
mu(j+1) = 1;
function nu = update_nu(nuold,mu,j,alpha,beta,anorm)
% UPDATE_MU: Update the nu-recurrence for the v-vectors.
%
% nu_new = update_nu(nu,mu,j,alpha,beta,anorm)
% Rasmus Munk Larsen, DAIMI, 1998.
nu = nuold;
ainv = 1/alpha(j);
eps1 = 100*eps/2;
if j>1
k = 1:(j-1);
% T = eps1*(pythag(alpha(k),beta(k+1)) + pythag(alpha(j),beta(j)));
T = eps1*(sqrt(alpha(k).^2+beta(k+1).^2) + sqrt(alpha(j).^2+beta(j).^2));
T = T + eps1*anorm;
nu(k) = beta(k+1).*mu(k+1) + alpha(k).*mu(k) - beta(j)*nu(k);
nu(k) = ainv*(nu(k) + sign(nu(k)).*T);
end
nu(j) = 1;
function x = pythag(y,z)
%PYTHAG Computes sqrt( y^2 + z^2 ).
%
% x = pythag(y,z)
%
% Returns sqrt(y^2 + z^2) but is careful to scale to avoid overflow.
% Christian H. Bischof, Argonne National Laboratory, 03/31/89.
[m n] = size(y);
if m>1 | n>1
y = y(:); z=z(:);
rmax = max(abs([y z]'))';
id=find(rmax==0);
if length(id)>0
rmax(id) = 1;
x = rmax.*sqrt((y./rmax).^2 + (z./rmax).^2);
x(id)=0;
else
x = rmax.*sqrt((y./rmax).^2 + (z./rmax).^2);
end
x = reshape(x,m,n);
else
rmax = max(abs([y;z]));
if (rmax==0)
x = 0;
else
x = rmax*sqrt((y/rmax)^2 + (z/rmax)^2);
end
end
|
github
|
biomedical-cybernetics/coalescent_embedding-master
|
coalescent_embedding.m
|
.m
|
coalescent_embedding-master/coemb_svds_eigs/coalescent_embedding.m
| 25,870 |
utf_8
|
486c75e222bfe5b52daa60a6d09d78cb
|
function coords = coalescent_embedding(x, pre_weighting, dim_red, angular_adjustment, dims)
% Authors:
% - main code: Alessandro Muscoloni, 2017-09-21
% - support functions: indicated at the beginning of the function
% Released under MIT License
% Copyright (c) 2017 A. Muscoloni, J. M. Thomas, C. V. Cannistraci
% Reference:
% A. Muscoloni, J. M. Thomas, S. Ciucci, G. Bianconi, and C. V. Cannistraci,
% "Machine learning meets complex networks via coalescent embedding in the hyperbolic space",
% Nature Communications 8, 1615 (2017). doi:10.1038/s41467-017-01825-5
% The time complexity of the algorithms is O(N^2) or O(E*N) depending on the pre-weighting
% and dimension reduction technique used, see the references for details.
%%% INPUT %%%
% x - adjacency matrix of the network, which must be:
% symmetric, zero-diagonal, one connected component, not fully connected;
% the network can be weighted
%
% pre_weighting - rule for pre-weighting the matrix, the alternatives are:
% 'original' -> the original weights are considered;
% NB: they should suggest distances and not similarities
% 'reverse' -> the original weights reversed are considered;
% NB: to use when they suggest similarities
% 'RA1' -> Repulsion-Attraction v1
% 'RA2' -> Repulsion-Attraction v2
% 'EBC' -> Edge-Betweenness-Centrality
%
% dim_red - dimension reduction technique, the alternatives are:
% 'ISO' -> Isomap (valid for 2D and 3D)
% 'ncISO' -> noncentered Isomap (valid for 2D and 3D)
% 'LE' -> Laplacian Eigenmaps (valid for 2D and 3D)
% 'MCE' -> Minimum Curvilinear Embedding (only valid for 2D)
% 'ncMCE' -> noncentered Minimum Curvilinear Embedding (only valid for 2D)
%
% angular_adjustment - method for the angular adjustment, the alternatives are:
% 'original' -> original angular distances are preserved (valid for 2D and 3D)
% 'EA' -> equidistant adjustment (only valid for 2D)
%
% dims - dimensions of the hyperbolic embedding space, the alternatives are:
% 2 -> hyperbolic disk
% 3 -> hyperbolic sphere
%%% OUTPUT %%%
% coords - polar or spherical hyperbolic coordinates of the nodes
% in the hyperbolic disk they are in the form: [theta,r]
% in the hyperbolic sphere they are in the form: [azimuth,elevation,r]
% for details see the documentation of the MATLAB functions
% "cart2pol" and "cart2sph"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check input
validateattributes(x, {'numeric'}, {'square','finite','nonnegative'});
if ~issymmetric(x)
error('The input matrix must be symmetric.')
end
if any(x(speye(size(x))==1))
error('The input matrix must be zero-diagonal.')
end
validateattributes(pre_weighting, {'char'}, {});
validateattributes(dim_red, {'char'}, {});
validateattributes(angular_adjustment, {'char'}, {});
validateattributes(dims, {'numeric'}, {'scalar','integer','>=',2,'<=',3});
if ~any(strcmp(pre_weighting,{'original','reverse','RA1','RA2','EBC'}))
error('Possible pre-weighting rules: ''original'',''reverse'',''RA1'',''RA2'',''EBC''.');
end
if dims == 2
if ~any(strcmp(dim_red,{'ISO','ncISO','MCE','ncMCE','LE'}))
error('Possible dimension reduction techniques in 2D: ''ISO'', ''ncISO'', ''MCE'', ''ncMCE'', ''LE''.');
end
if ~any(strcmp(angular_adjustment,{'original','EA'}))
error('Possible angular adjustment methods in 2D: ''original'', ''EA''.');
end
elseif dims == 3
if ~any(strcmp(dim_red,{'ISO','ncISO','LE'}))
error('Possible dimension reduction techniques in 3D: ''ISO'', ''ncISO'', ''LE''.');
end
if ~any(strcmp(angular_adjustment,{'original'}))
error('Possible angular adjustment methods in 3D: ''original''.');
end
end
% pre-weighting
if strcmp(pre_weighting,'original')
xw = x;
elseif strcmp(pre_weighting,'reverse')
xw = reverse_weights(x);
elseif strcmp(pre_weighting,'RA1')
xw = RA1_weighting(double(x>0));
elseif strcmp(pre_weighting,'RA2')
xw = RA2_weighting(double(x>0));
elseif strcmp(pre_weighting,'EBC')
xw = EBC_weighting(double(x>0));
end
% dimension reduction and set of hyperbolic coordinates
if dims == 2
coords = zeros(size(x,1),2);
if strcmp(dim_red,'ISO')
coords(:,1) = set_angular_coordinates_ISO_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'ncISO')
coords(:,1) = set_angular_coordinates_ncISO_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'MCE')
coords(:,1) = set_angular_coordinates_MCE_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'ncMCE')
coords(:,1) = set_angular_coordinates_ncMCE_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'LE')
coords(:,1) = set_angular_coordinates_LE_2D(xw, angular_adjustment);
end
coords(:,2) = set_radial_coordinates(x);
elseif dims == 3
coords = zeros(size(x,1),3);
if strcmp(dim_red,'ISO')
[coords(:,1),coords(:,2)] = set_angular_coordinates_ISO_3D(xw);
elseif strcmp(dim_red,'ncISO')
[coords(:,1),coords(:,2)] = set_angular_coordinates_ncISO_3D(xw);
elseif strcmp(dim_red,'LE')
[coords(:,1),coords(:,2)] = set_angular_coordinates_LE_3D(xw);
end
coords(:,3) = set_radial_coordinates(x);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Support Functions %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
function xrev = reverse_weights(x)
xrev = x;
xrev(xrev>0) = abs(x(x>0) - min(x(x>0)) - max(x(x>0)));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_RA1 = RA1_weighting(x)
n = size(x,1);
cn = x*x;
deg = full(sum(x,1));
x_RA1 = x .* (repmat(deg,n,1) + repmat(deg',1,n) + (repmat(deg,n,1) .* repmat(deg',1,n))) ./ (1 + cn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_RA2 = RA2_weighting(x)
n = size(x,1);
cn = x*x;
ext = repmat(sum(x,2),1,n) - cn - 1;
x_RA2 = x .* (1 + ext + ext' + ext.*ext') ./ (1 + cn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_EBC = EBC_weighting(x)
[~,x_EBC] = betweenness_centrality(sparse(x));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_ISO_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = ISOMAP_propack(xw, 2, 'yes');
% from cartesian to polar coordinates
% using dimensions 1 and 2 of embedding
[ang_coords,~] = cart2pol(dr_coords(:,1),dr_coords(:,2));
% change angular range from [-pi,pi] to [0,2pi]
ang_coords = mod(ang_coords + 2*pi, 2*pi);
if strcmp(angular_adjustment,'EA')
ang_coords = equidistant_adjustment(ang_coords);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_ncISO_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = ISOMAP_propack(xw, 3, 'no');
% from cartesian to polar coordinates
% using dimensions 2 and 3 of embedding
[ang_coords,~] = cart2pol(dr_coords(:,2),dr_coords(:,3));
% change angular range from [-pi,pi] to [0,2pi]
ang_coords = mod(ang_coords + 2*pi, 2*pi);
if strcmp(angular_adjustment,'EA')
ang_coords = equidistant_adjustment(ang_coords);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_MCE_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = MCE_propack(xw, 1, 'yes');
if strcmp(angular_adjustment,'original')
% circular adjustment of dimension 1
ang_coords = circular_adjustment(dr_coords(:,1));
elseif strcmp(angular_adjustment,'EA')
% equidistant adjustment of dimension 1
ang_coords = equidistant_adjustment(dr_coords(:,1));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_ncMCE_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = MCE_propack(xw, 2, 'no');
if strcmp(angular_adjustment,'original')
% circular adjustment of dimension 2
ang_coords = circular_adjustment(dr_coords(:,2));
elseif strcmp(angular_adjustment,'EA')
% equidistant adjustment of dimension 2
ang_coords = equidistant_adjustment(dr_coords(:,2));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_LE_2D(xw, angular_adjustment)
% dimension reduction
st = triu(full(xw),1);
st = mean(st(st>0));
heat_kernel = zeros(size(xw));
heat_kernel(xw>0) = exp(-((xw(xw>0)./st).^2));
dr_coords = LE_eigs(heat_kernel, 2);
% from cartesian to polar coordinates
% using dimensions 2 and 3 of embedding
% (dimensions 1 and 2 in the code since the first is skipped by the function)
[ang_coords,~] = cart2pol(dr_coords(:,1),dr_coords(:,2));
% change angular range from [-pi,pi] to [0,2pi]
ang_coords = mod(ang_coords + 2*pi, 2*pi);
if strcmp(angular_adjustment,'EA')
ang_coords = equidistant_adjustment(ang_coords);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = equidistant_adjustment(coords)
% sort input coordinates
[~,idx] = sort(coords);
% assign equidistant angular coordinates in [0,2pi[ according to the sorting
angles = linspace(0, 2*pi, length(coords)+1);
ang_coords(idx) = angles(1:end-1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = circular_adjustment(coords)
% scale the input coordinates into the range [0,2pi]
n = length(coords);
m = 2*pi*(n-1)/n;
ang_coords = ((coords - min(coords)) ./ (max(coords) - min(coords))) * m;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [azimuth, elevation] = set_angular_coordinates_ISO_3D(xw)
% dimension reduction
dr_coords = ISOMAP_propack(xw, 3, 'yes');
% from cartesian to spherical coordinates
% using dimensions 1-3 of embedding
[azimuth,elevation,~] = cart2sph(dr_coords(:,1),dr_coords(:,2),dr_coords(:,3));
% change angular range from [-pi,pi] to [0,2pi]
azimuth = mod(azimuth + 2*pi, 2*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [azimuth, elevation] = set_angular_coordinates_ncISO_3D(xw)
% dimension reduction
dr_coords = ISOMAP_propack(xw, 4, 'no');
% from cartesian to spherical coordinates
% using dimensions 2-4 of embedding
[azimuth,elevation,~] = cart2sph(dr_coords(:,2),dr_coords(:,3),dr_coords(:,4));
% change angular range from [-pi,pi] to [0,2pi]
azimuth = mod(azimuth + 2*pi, 2*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [azimuth, elevation] = set_angular_coordinates_LE_3D(xw)
% dimension reduction
st = triu(full(xw),1);
st = mean(st(st>0));
heat_kernel = zeros(size(xw));
heat_kernel(xw>0) = exp(-((xw(xw>0)./st).^2));
dr_coords = LE_eigs(heat_kernel, 3);
% from cartesian to spherical coordinates
% using dimensions 2-4 of embedding (the first is skipped by the LE function)
[azimuth,elevation,~] = cart2sph(dr_coords(:,1),dr_coords(:,2),dr_coords(:,3));
% change angular range from [-pi,pi] to [0,2pi]
azimuth = mod(azimuth + 2*pi, 2*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function radial_coordinates = set_radial_coordinates(x)
n = size(x,1);
deg = full(sum(x>0,1));
if all(deg == deg(1))
error('All the nodes have the same degree, the degree distribution cannot fit a power-law.');
end
% fit power-law degree distribution
gamma_range = 1.01:0.01:10.00;
small_size_limit = 100;
if length(deg) < small_size_limit
gamma = plfit(deg, 'finite', 'range', gamma_range);
else
gamma = plfit(deg, 'range', gamma_range);
end
beta = 1 / (gamma - 1);
% sort nodes by decreasing degree
[~,idx] = sort(deg, 'descend');
% for beta > 1 (gamma < 2) some radial coordinates are negative
radial_coordinates = zeros(1, n);
radial_coordinates(idx) = max(0, 2*beta*log(1:n) + 2*(1-beta)*log(n));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [V, time] = LE_eigs(x, m)
% Laplacian Eigenmaps for network embedding in a low dimensional space.
% 2013-01-27 - Gregorio Alanis-Lobato
% 2017-02-02 - Alessandro Muscoloni: introduced the usage of eigs
%%% INPUT %%%
% x - adjacency matrix
% m - dimensions of embedding
%%% OUTPUT %%%
% V - coordinates of embedding
% time - computational time (in seconds)
% suppress eigs warnings (recurring for small matrices)
warning('off','MATLAB:nearlySingularMatrix')
warning('off','MATLAB:eigs:SigmaNearExactEig')
t = tic;
x = sparse(max(x,x'));
D = sum(x,2);
D = diag(D);
% graph laplacian
L = D - x;
time = toc(t);
% solve the generalised eigenvalue problem L*V = lambda*D*V
% and use the eigenvectors related to the smallest eigenvalues
% discarding the first, since it is zero.
try
t = tic;
[V,E] = eigs(L, D, m+1, 'sm');
[~,idx] = sort(E(speye(size(E))==1));
V = V(:,idx);
V = V(:,2:m+1);
time = time + toc(t);
catch exc %#ok<NASGU>
% for small matrices the following error could occur:
% "The shifted operator is singular. The shift is an eigenvalue. Try to use some other shift please".
% in this case the function eig is used.
% warning('Error using the function EIGS:\n%s\nThe function EIG has been used.', exc.message)
t = tic;
[V,~] = eig(full(L), full(D));
V = V(:,2:m+1);
time = time + toc(t);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [V, time] = ISOMAP_propack(x, m, centering)
% ISOMAP for network embedding in a low dimensional space.
% 2011-09-27 - Carlo Vittorio Cannistraci
% 2017-02-02 - Alessandro Muscoloni: introduced the PROPACK version of SVD
%%% INPUT %%%
% x - adjacency matrix
% m - dimensions of embedding
% centering - 'yes' or 'no' for centering the kernel
%%% OUTPUT %%%
% V - coordinates of embedding
% time - computational time (in seconds)
t = tic;
x = max(x, x');
% shortest paths kernel
kernel = graphallshortestpaths(sparse(x),'directed','false');
clear x;
% kernel centering
if strcmp(centering, 'yes')
kernel = kernel_centering(kernel);
end
% singular value decomposition
[~,S,V] = lansvd(kernel, m, 'L');
V = (sqrt(S) * V')';
time = toc(t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [V, time] = MCE_propack(x, m, centering)
% Minimum Curvilinear Embedding for network embedding in a low dimensional space.
% 2011-09-27 - Carlo Vittorio Cannistraci
% 2017-02-02 - Alessandro Muscoloni: introduced the PROPACK version of SVD
%%% INPUT %%%
% x - adjacency matrix
% m - dimensions of embedding
% centering - 'yes' or 'no' for centering the kernel
%%% OUTPUT %%%
% V - coordinates of embedding
% time - computational time (in seconds)
t = tic;
x = max(x, x');
% MC-kernel
kernel = graphallshortestpaths(graphminspantree(sparse(x),'method','kruskal'),'directed','false');
clear x;
% kernel centering
if strcmp(centering, 'yes')
kernel = kernel_centering(kernel);
end
% singular value decomposition
[~,S,V] = lansvd(kernel, m, 'L');
V = (sqrt(S) * V')';
time = toc(t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function D = kernel_centering(D)
% 2011-09-27 - Carlo Vittorio Cannistraci
%%% INPUT %%%
% D - Distance matrix
%%% OUTPUT %%%
% D - Centered distance matrix
% Centering
N = size(D,1);
J = eye(N) - (1/N)*ones(N);
D = -0.5*(J*(D.^2)*J);
% Housekeeping
D(isnan(D)) = 0;
D(isinf(D)) = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [alpha, xmin, L]=plfit(x, varargin)
% PLFIT fits a power-law distributional model to data.
% Source: http://www.santafe.edu/~aaronc/powerlaws/
%
% PLFIT(x) estimates x_min and alpha according to the goodness-of-fit
% based method described in Clauset, Shalizi, Newman (2007). x is a
% vector of observations of some quantity to which we wish to fit the
% power-law distribution p(x) ~ x^-alpha for x >= xmin.
% PLFIT automatically detects whether x is composed of real or integer
% values, and applies the appropriate method. For discrete data, if
% min(x) > 1000, PLFIT uses the continuous approximation, which is
% a reliable in this regime.
%
% The fitting procedure works as follows:
% 1) For each possible choice of x_min, we estimate alpha via the
% method of maximum likelihood, and calculate the Kolmogorov-Smirnov
% goodness-of-fit statistic D.
% 2) We then select as our estimate of x_min, the value that gives the
% minimum value D over all values of x_min.
%
% Note that this procedure gives no estimate of the uncertainty of the
% fitted parameters, nor of the validity of the fit.
%
% Example:
% x = (1-rand(10000,1)).^(-1/(2.5-1));
% [alpha, xmin, L] = plfit(x);
%
% The output 'alpha' is the maximum likelihood estimate of the scaling
% exponent, 'xmin' is the estimate of the lower bound of the power-law
% behavior, and L is the log-likelihood of the data x>=xmin under the
% fitted power law.
%
% For more information, try 'type plfit'
%
% See also PLVAR, PLPVA
% Version 1.0 (2007 May)
% Version 1.0.2 (2007 September)
% Version 1.0.3 (2007 September)
% Version 1.0.4 (2008 January)
% Version 1.0.5 (2008 March)
% Version 1.0.6 (2008 July)
% Version 1.0.7 (2008 October)
% Version 1.0.8 (2009 February)
% Version 1.0.9 (2009 October)
% Version 1.0.10 (2010 January)
% Version 1.0.11 (2012 January)
% Copyright (C) 2008-2012 Aaron Clauset (Santa Fe Institute)
% Distributed under GPL 2.0
% http://www.gnu.org/copyleft/gpl.html
% PLFIT comes with ABSOLUTELY NO WARRANTY
%
% Notes:
%
% 1. In order to implement the integer-based methods in Matlab, the numeric
% maximization of the log-likelihood function was used. This requires
% that we specify the range of scaling parameters considered. We set
% this range to be [1.50 : 0.01 : 3.50] by default. This vector can be
% set by the user like so,
%
% a = plfit(x,'range',[1.001:0.001:5.001]);
%
% 2. PLFIT can be told to limit the range of values considered as estimates
% for xmin in three ways. First, it can be instructed to sample these
% possible values like so,
%
% a = plfit(x,'sample',100);
%
% which uses 100 uniformly distributed values on the sorted list of
% unique values in the data set. Second, it can simply omit all
% candidates above a hard limit, like so
%
% a = plfit(x,'limit',3.4);
%
% Finally, it can be forced to use a fixed value, like so
%
% a = plfit(x,'xmin',3.4);
%
% In the case of discrete data, it rounds the limit to the nearest
% integer.
%
% 3. When the input sample size is small (e.g., < 100), the continuous
% estimator is slightly biased (toward larger values of alpha). To
% explicitly use an experimental finite-size correction, call PLFIT like
% so
%
% a = plfit(x,'finite');
%
% which does a small-size correction to alpha.
%
% 4. For continuous data, PLFIT can return erroneously large estimates of
% alpha when xmin is so large that the number of obs x >= xmin is very
% small. To prevent this, we can truncate the search over xmin values
% before the finite-size bias becomes significant by calling PLFIT as
%
% a = plfit(x,'nosmall');
%
% which skips values xmin with finite size bias > 0.1.
vec = [];
sample = [];
xminx = [];
limit = [];
finite = false;
nosmall = false;
nowarn = false;
% parse command-line parameters; trap for bad input
i=1;
while i<=length(varargin),
argok = 1;
if ischar(varargin{i}),
switch varargin{i},
case 'range', vec = varargin{i+1}; i = i + 1;
case 'sample', sample = varargin{i+1}; i = i + 1;
case 'limit', limit = varargin{i+1}; i = i + 1;
case 'xmin', xminx = varargin{i+1}; i = i + 1;
case 'finite', finite = true;
case 'nowarn', nowarn = true;
case 'nosmall', nosmall = true;
otherwise, argok=0;
end
end
if ~argok,
disp(['(PLFIT) Ignoring invalid argument #' num2str(i+1)]);
end
i = i+1;
end
if ~isempty(vec) && (~isvector(vec) || min(vec)<=1),
fprintf('(PLFIT) Error: ''range'' argument must contain a vector; using default.\n');
vec = [];
end;
if ~isempty(sample) && (~isscalar(sample) || sample<2),
fprintf('(PLFIT) Error: ''sample'' argument must be a positive integer > 1; using default.\n');
sample = [];
end;
if ~isempty(limit) && (~isscalar(limit) || limit<min(x)),
fprintf('(PLFIT) Error: ''limit'' argument must be a positive value >= 1; using default.\n');
limit = [];
end;
if ~isempty(xminx) && (~isscalar(xminx) || xminx>=max(x)),
fprintf('(PLFIT) Error: ''xmin'' argument must be a positive value < max(x); using default behavior.\n');
xminx = [];
end;
% reshape input vector
x = reshape(x,numel(x),1);
% select method (discrete or continuous) for fitting
if isempty(setdiff(x,floor(x))), f_dattype = 'INTS';
elseif isreal(x), f_dattype = 'REAL';
else f_dattype = 'UNKN';
end;
if strcmp(f_dattype,'INTS') && min(x) > 1000 && length(x)>100,
f_dattype = 'REAL';
end;
% estimate xmin and alpha, accordingly
switch f_dattype,
case 'REAL',
xmins = unique(x);
xmins = xmins(1:end-1);
if ~isempty(xminx),
xmins = xmins(find(xmins>=xminx,1,'first'));
end;
if ~isempty(limit),
xmins(xmins>limit) = [];
end;
if ~isempty(sample),
xmins = xmins(unique(round(linspace(1,length(xmins),sample))));
end;
dat = zeros(size(xmins));
z = sort(x);
for xm=1:length(xmins)
xmin = xmins(xm);
z = z(z>=xmin);
n = length(z);
% estimate alpha using direct MLE
a = n ./ sum( log(z./xmin) );
if nosmall,
if (a-1)/sqrt(n) > 0.1
dat(xm:end) = [];
xm = length(xmins)+1; %#ok<FXSET,NASGU>
break;
end;
end;
% compute KS statistic
cx = (0:n-1)'./n;
cf = 1-(xmin./z).^a;
dat(xm) = max( abs(cf-cx) );
end;
D = min(dat);
xmin = xmins(find(dat<=D,1,'first'));
z = x(x>=xmin);
n = length(z);
alpha = 1 + n ./ sum( log(z./xmin) );
if finite, alpha = alpha*(n-1)/n+1/n; end; % finite-size correction
if n < 50 && ~finite && ~nowarn,
% fprintf('(PLFIT) Warning: finite-size bias may be present.\n');
end;
L = n*log((alpha-1)/xmin) - alpha.*sum(log(z./xmin));
case 'INTS',
if isempty(vec),
vec = (1.50:0.01:3.50); % covers range of most practical
end; % scaling parameters
zvec = zeta(vec);
xmins = unique(x);
xmins = xmins(1:end-1);
if ~isempty(xminx),
xmins = xmins(find(xmins>=xminx,1,'first'));
end;
if ~isempty(limit),
limit = round(limit);
xmins(xmins>limit) = [];
end;
if ~isempty(sample),
xmins = xmins(unique(round(linspace(1,length(xmins),sample))));
end;
if isempty(xmins)
fprintf('(PLFIT) Error: x must contain at least two unique values.\n');
alpha = NaN; xmin = x(1); D = NaN; %#ok<NASGU>
return;
end;
xmax = max(x);
dat = zeros(length(xmins),2);
z = x;
fcatch = 0;
for xm=1:length(xmins)
xmin = xmins(xm);
z = z(z>=xmin);
n = length(z);
% estimate alpha via direct maximization of likelihood function
if fcatch==0
try
% vectorized version of numerical calculation
zdiff = sum( repmat((1:xmin-1)',1,length(vec)).^-repmat(vec,xmin-1,1) ,1);
L = -vec.*sum(log(z)) - n.*log(zvec - zdiff);
catch
% catch: force loop to default to iterative version for
% remainder of the search
fcatch = 1;
end;
end;
if fcatch==1
% force iterative calculation (more memory efficient, but
% can be slower)
L = -Inf*ones(size(vec));
slogz = sum(log(z));
xminvec = (1:xmin-1);
for k=1:length(vec)
L(k) = -vec(k)*slogz - n*log(zvec(k) - sum(xminvec.^-vec(k)));
end
end;
[Y,I] = max(L); %#ok<ASGLU>
% compute KS statistic
fit = cumsum((((xmin:xmax).^-vec(I)))./ (zvec(I) - sum((1:xmin-1).^-vec(I))));
cdi = cumsum(hist(z,xmin:xmax)./n);
dat(xm,:) = [max(abs( fit - cdi )) vec(I)];
end
% select the index for the minimum value of D
[D,I] = min(dat(:,1)); %#ok<ASGLU>
xmin = xmins(I);
z = x(x>=xmin);
n = length(z);
alpha = dat(I,2);
if finite, alpha = alpha*(n-1)/n+1/n; end; % finite-size correction
if n < 50 && ~finite && ~nowarn,
% fprintf('(PLFIT) Warning: finite-size bias may be present.\n');
end;
L = -alpha*sum(log(z)) - n*log(zvec(find(vec<=alpha,1,'last')) - sum((1:xmin-1).^-alpha));
otherwise,
fprintf('(PLFIT) Error: x must contain only reals or only integers.\n');
alpha = [];
xmin = [];
L = [];
return;
end;
|
github
|
biomedical-cybernetics/coalescent_embedding-master
|
coalescent_embedding.m
|
.m
|
coalescent_embedding-master/coemb_svd_eig/coalescent_embedding.m
| 25,081 |
utf_8
|
0f84d1345d19f28fe588f1bc8da8aeec
|
function coords = coalescent_embedding(x, pre_weighting, dim_red, angular_adjustment, dims)
% Authors:
% - main code: Alessandro Muscoloni, 2017-09-21
% - support functions: indicated at the beginning of the function
% Released under MIT License
% Copyright (c) 2017 A. Muscoloni, J. M. Thomas, C. V. Cannistraci
% Reference:
% A. Muscoloni, J. M. Thomas, S. Ciucci, G. Bianconi, and C. V. Cannistraci,
% "Machine learning meets complex networks via coalescent embedding in the hyperbolic space",
% Nature Communications 8, 1615 (2017). doi:10.1038/s41467-017-01825-5
% The time complexity of the algorithms is O(N^3).
%%% INPUT %%%
% x - adjacency matrix of the network, which must be:
% symmetric, zero-diagonal, one connected component, not fully connected;
% the network can be weighted
%
% pre_weighting - rule for pre-weighting the matrix, the alternatives are:
% 'original' -> the original weights are considered;
% NB: they should suggest distances and not similarities
% 'reverse' -> the original weights reversed are considered;
% NB: to use when they suggest similarities
% 'RA1' -> Repulsion-Attraction v1
% 'RA2' -> Repulsion-Attraction v2
% 'EBC' -> Edge-Betweenness-Centrality
%
% dim_red - dimension reduction technique, the alternatives are:
% 'ISO' -> Isomap (valid for 2D and 3D)
% 'ncISO' -> noncentered Isomap (valid for 2D and 3D)
% 'LE' -> Laplacian Eigenmaps (valid for 2D and 3D)
% 'MCE' -> Minimum Curvilinear Embedding (only valid for 2D)
% 'ncMCE' -> noncentered Minimum Curvilinear Embedding (only valid for 2D)
%
% angular_adjustment - method for the angular adjustment, the alternatives are:
% 'original' -> original angular distances are preserved (valid for 2D and 3D)
% 'EA' -> equidistant adjustment (only valid for 2D)
%
% dims - dimensions of the hyperbolic embedding space, the alternatives are:
% 2 -> hyperbolic disk
% 3 -> hyperbolic sphere
%%% OUTPUT %%%
% coords - polar or spherical hyperbolic coordinates of the nodes
% in the hyperbolic disk they are in the form: [theta,r]
% in the hyperbolic sphere they are in the form: [azimuth,elevation,r]
% for details see the documentation of the MATLAB functions
% "cart2pol" and "cart2sph"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check input
validateattributes(x, {'numeric'}, {'square','finite','nonnegative'});
if ~issymmetric(x)
error('The input matrix must be symmetric.')
end
if any(x(speye(size(x))==1))
error('The input matrix must be zero-diagonal.')
end
validateattributes(pre_weighting, {'char'}, {});
validateattributes(dim_red, {'char'}, {});
validateattributes(angular_adjustment, {'char'}, {});
validateattributes(dims, {'numeric'}, {'scalar','integer','>=',2,'<=',3});
if ~any(strcmp(pre_weighting,{'original','reverse','RA1','RA2','EBC'}))
error('Possible pre-weighting rules: ''original'',''reverse'',''RA1'',''RA2'',''EBC''.');
end
if dims == 2
if ~any(strcmp(dim_red,{'ISO','ncISO','MCE','ncMCE','LE'}))
error('Possible dimension reduction techniques in 2D: ''ISO'', ''ncISO'', ''MCE'', ''ncMCE'', ''LE''.');
end
if ~any(strcmp(angular_adjustment,{'original','EA'}))
error('Possible angular adjustment methods in 2D: ''original'', ''EA''.');
end
elseif dims == 3
if ~any(strcmp(dim_red,{'ISO','ncISO','LE'}))
error('Possible dimension reduction techniques in 3D: ''ISO'', ''ncISO'', ''LE''.');
end
if ~any(strcmp(angular_adjustment,{'original'}))
error('Possible angular adjustment methods in 3D: ''original''.');
end
end
% pre-weighting
if strcmp(pre_weighting,'original')
xw = x;
elseif strcmp(pre_weighting,'reverse')
xw = reverse_weights(x);
elseif strcmp(pre_weighting,'RA1')
xw = RA1_weighting(double(x>0));
elseif strcmp(pre_weighting,'RA2')
xw = RA2_weighting(double(x>0));
elseif strcmp(pre_weighting,'EBC')
xw = EBC_weighting(double(x>0));
end
% dimension reduction and set of hyperbolic coordinates
if dims == 2
coords = zeros(size(x,1),2);
if strcmp(dim_red,'ISO')
coords(:,1) = set_angular_coordinates_ISO_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'ncISO')
coords(:,1) = set_angular_coordinates_ncISO_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'MCE')
coords(:,1) = set_angular_coordinates_MCE_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'ncMCE')
coords(:,1) = set_angular_coordinates_ncMCE_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'LE')
coords(:,1) = set_angular_coordinates_LE_2D(xw, angular_adjustment);
end
coords(:,2) = set_radial_coordinates(x);
elseif dims == 3
coords = zeros(size(x,1),3);
if strcmp(dim_red,'ISO')
[coords(:,1),coords(:,2)] = set_angular_coordinates_ISO_3D(xw);
elseif strcmp(dim_red,'ncISO')
[coords(:,1),coords(:,2)] = set_angular_coordinates_ncISO_3D(xw);
elseif strcmp(dim_red,'LE')
[coords(:,1),coords(:,2)] = set_angular_coordinates_LE_3D(xw);
end
coords(:,3) = set_radial_coordinates(x);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Support Functions %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
function xrev = reverse_weights(x)
xrev = x;
xrev(xrev>0) = abs(x(x>0) - min(x(x>0)) - max(x(x>0)));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_RA1 = RA1_weighting(x)
n = size(x,1);
cn = x*x;
deg = full(sum(x,1));
x_RA1 = x .* (repmat(deg,n,1) + repmat(deg',1,n) + (repmat(deg,n,1) .* repmat(deg',1,n))) ./ (1 + cn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_RA2 = RA2_weighting(x)
n = size(x,1);
cn = x*x;
ext = repmat(sum(x,2),1,n) - cn - 1;
x_RA2 = x .* (1 + ext + ext' + ext.*ext') ./ (1 + cn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_EBC = EBC_weighting(x)
[~,x_EBC] = betweenness_centrality(sparse(x));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_ISO_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = isomap_graph_carlo(xw, 2, 'yes');
% from cartesian to polar coordinates
% using dimensions 1 and 2 of embedding
[ang_coords,~] = cart2pol(dr_coords(:,1),dr_coords(:,2));
% change angular range from [-pi,pi] to [0,2pi]
ang_coords = mod(ang_coords + 2*pi, 2*pi);
if strcmp(angular_adjustment,'EA')
ang_coords = equidistant_adjustment(ang_coords);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_ncISO_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = isomap_graph_carlo(xw, 3, 'no');
% from cartesian to polar coordinates
% using dimensions 2 and 3 of embedding
[ang_coords,~] = cart2pol(dr_coords(:,2),dr_coords(:,3));
% change angular range from [-pi,pi] to [0,2pi]
ang_coords = mod(ang_coords + 2*pi, 2*pi);
if strcmp(angular_adjustment,'EA')
ang_coords = equidistant_adjustment(ang_coords);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_MCE_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = mce(xw, 1, 'yes');
if strcmp(angular_adjustment,'original')
% circular adjustment of dimension 1
ang_coords = circular_adjustment(dr_coords(:,1));
elseif strcmp(angular_adjustment,'EA')
% equidistant adjustment of dimension 1
ang_coords = equidistant_adjustment(dr_coords(:,1));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_ncMCE_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = mce(xw, 2, 'no');
if strcmp(angular_adjustment,'original')
% circular adjustment of dimension 2
ang_coords = circular_adjustment(dr_coords(:,2));
elseif strcmp(angular_adjustment,'EA')
% equidistant adjustment of dimension 2
ang_coords = equidistant_adjustment(dr_coords(:,2));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_LE_2D(xw, angular_adjustment)
% dimension reduction
st = triu(full(xw),1);
st = mean(st(st>0));
heat_kernel = zeros(size(xw));
heat_kernel(xw>0) = exp(-((xw(xw>0)./st).^2));
dr_coords = leig_graph_carlo_classical(heat_kernel, 2, 'no');
% from cartesian to polar coordinates
% using dimensions 2 and 3 of embedding
% (dimensions 1 and 2 in the code since the first is skipped by the function)
[ang_coords,~] = cart2pol(dr_coords(:,1),dr_coords(:,2));
% change angular range from [-pi,pi] to [0,2pi]
ang_coords = mod(ang_coords + 2*pi, 2*pi);
if strcmp(angular_adjustment,'EA')
ang_coords = equidistant_adjustment(ang_coords);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = equidistant_adjustment(coords)
% sort input coordinates
[~,idx] = sort(coords);
% assign equidistant angular coordinates in [0,2pi[ according to the sorting
angles = linspace(0, 2*pi, length(coords)+1);
ang_coords(idx) = angles(1:end-1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = circular_adjustment(coords)
% scale the input coordinates into the range [0,2pi]
n = length(coords);
m = 2*pi*(n-1)/n;
ang_coords = ((coords - min(coords)) ./ (max(coords) - min(coords))) * m;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [azimuth, elevation] = set_angular_coordinates_ISO_3D(xw)
% dimension reduction
dr_coords = isomap_graph_carlo(xw, 3, 'yes');
% from cartesian to spherical coordinates
% using dimensions 1-3 of embedding
[azimuth,elevation,~] = cart2sph(dr_coords(:,1),dr_coords(:,2),dr_coords(:,3));
% change angular range from [-pi,pi] to [0,2pi]
azimuth = mod(azimuth + 2*pi, 2*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [azimuth, elevation] = set_angular_coordinates_ncISO_3D(xw)
% dimension reduction
dr_coords = isomap_graph_carlo(xw, 4, 'no');
% from cartesian to spherical coordinates
% using dimensions 2-4 of embedding
[azimuth,elevation,~] = cart2sph(dr_coords(:,2),dr_coords(:,3),dr_coords(:,4));
% change angular range from [-pi,pi] to [0,2pi]
azimuth = mod(azimuth + 2*pi, 2*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [azimuth, elevation] = set_angular_coordinates_LE_3D(xw)
% dimension reduction
st = triu(full(xw),1);
st = mean(st(st>0));
heat_kernel = zeros(size(xw));
heat_kernel(xw>0) = exp(-((xw(xw>0)./st).^2));
dr_coords = leig_graph_carlo_classical(heat_kernel, 3, 'no');
% from cartesian to spherical coordinates
% using dimensions 2-4 of embedding (the first is skipped by the LE function)
[azimuth,elevation,~] = cart2sph(dr_coords(:,1),dr_coords(:,2),dr_coords(:,3));
% change angular range from [-pi,pi] to [0,2pi]
azimuth = mod(azimuth + 2*pi, 2*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function radial_coordinates = set_radial_coordinates(x)
n = size(x,1);
deg = full(sum(x>0,1));
if all(deg == deg(1))
error('All the nodes have the same degree, the degree distribution cannot fit a power-law.');
end
% fit power-law degree distribution
gamma_range = 1.01:0.01:10.00;
small_size_limit = 100;
if length(deg) < small_size_limit
gamma = plfit(deg, 'finite', 'range', gamma_range);
else
gamma = plfit(deg, 'range', gamma_range);
end
beta = 1 / (gamma - 1);
% sort nodes by decreasing degree
[~,idx] = sort(deg, 'descend');
% for beta > 1 (gamma < 2) some radial coordinates are negative
radial_coordinates = zeros(1, n);
radial_coordinates(idx) = max(0, 2*beta*log(1:n) + 2*(1-beta)*log(n));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [f, time] = leig_graph_carlo_classical(x, d, centring)
% Maps the high-dimensional samples in 'x' to a low dimensional space using
% Laplacian Eigenmaps (coded 27-JANUARY-2013 by Gregorio Alanis-Lobato)
t = tic;
graph = max(x, x');
% Kernel centering
if strcmp(centring, 'yes')
graph=kernel_centering(graph); %Compute the centred MC-kernel
end
D = sum(graph, 2); %Degree values
D = diag(D); %Degree matrix
% Graph laplacian
L = D - graph;
% Solving the generalised eigenvalue problem L*f = lambda*D*f
[f, ~] = eig(L, D);
f = real(f(:, 2:d+1));
time = toc(t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [s,time] = isomap_graph_carlo(x, n, centring)
%INPUT
% x => Distance or correlation matrix x
% n => Dimension into which the data is to be projected
% centring => 'yes' is x should be centred or 'no' if not
%OUTPUT
% s => Sample configuration in the space of n dimensions
t = tic;
% initialization
x = max(x, x');
% Iso-kernel computation
kernel=graphallshortestpaths(sparse(x),'directed','false');
clear x
kernel=max(kernel,kernel');
% Kernel centering
if strcmp(centring, 'yes')
kernel=kernel_centering(kernel); %Compute the centred Iso-kernel
end
% Embedding
[~,L,V] = svd(kernel, 'econ');
sqrtL = sqrt(L(1:n,1:n)); clear L
V = V(:,1:n);
s = real((sqrtL * V')');
time = toc(t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [s, time] = mce(x, n, centring)
%Given a distance or correlation matrix x, it performs Minimum Curvilinear
%Embedding (MCE) or non-centred MCE (ncMCE) (coded 27-SEPTEMBER-2011 by
%Carlo Cannistraci)
%INPUT
% x => Distance or correlation matrix x
% n => Dimension into which the data is to be projected
% centring => 'yes' is x should be centred or 'no' if not
%OUTPUT
% s => Sample configuration in the space of n dimensions
t = tic;
% initialization
x = max(x, x');
% MC-kernel computation
kernel=graphallshortestpaths(graphminspantree(sparse(x),'method','kruskal'),'directed','false');
clear x
kernel=max(kernel,kernel');
% Kernel centering
if strcmp(centring, 'yes')
kernel=kernel_centering(kernel); %Compute the centred MC-kernel
end
% Embedding
[~,L,V] = svd(kernel, 'econ');
sqrtL = sqrt(L(1:n,1:n)); clear L
V = V(:,1:n);
s = (sqrtL * V')';
s=real(s(:,1:n));
time = toc(t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function D = kernel_centering(D)
% 2011-09-27 - Carlo Vittorio Cannistraci
%%% INPUT %%%
% D - Distance matrix
%%% OUTPUT %%%
% D - Centered distance matrix
% Centering
N = size(D,1);
J = eye(N) - (1/N)*ones(N);
D = -0.5*(J*(D.^2)*J);
% Housekeeping
D(isnan(D)) = 0;
D(isinf(D)) = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [alpha, xmin, L]=plfit(x, varargin)
% PLFIT fits a power-law distributional model to data.
% Source: http://www.santafe.edu/~aaronc/powerlaws/
%
% PLFIT(x) estimates x_min and alpha according to the goodness-of-fit
% based method described in Clauset, Shalizi, Newman (2007). x is a
% vector of observations of some quantity to which we wish to fit the
% power-law distribution p(x) ~ x^-alpha for x >= xmin.
% PLFIT automatically detects whether x is composed of real or integer
% values, and applies the appropriate method. For discrete data, if
% min(x) > 1000, PLFIT uses the continuous approximation, which is
% a reliable in this regime.
%
% The fitting procedure works as follows:
% 1) For each possible choice of x_min, we estimate alpha via the
% method of maximum likelihood, and calculate the Kolmogorov-Smirnov
% goodness-of-fit statistic D.
% 2) We then select as our estimate of x_min, the value that gives the
% minimum value D over all values of x_min.
%
% Note that this procedure gives no estimate of the uncertainty of the
% fitted parameters, nor of the validity of the fit.
%
% Example:
% x = (1-rand(10000,1)).^(-1/(2.5-1));
% [alpha, xmin, L] = plfit(x);
%
% The output 'alpha' is the maximum likelihood estimate of the scaling
% exponent, 'xmin' is the estimate of the lower bound of the power-law
% behavior, and L is the log-likelihood of the data x>=xmin under the
% fitted power law.
%
% For more information, try 'type plfit'
%
% See also PLVAR, PLPVA
% Version 1.0 (2007 May)
% Version 1.0.2 (2007 September)
% Version 1.0.3 (2007 September)
% Version 1.0.4 (2008 January)
% Version 1.0.5 (2008 March)
% Version 1.0.6 (2008 July)
% Version 1.0.7 (2008 October)
% Version 1.0.8 (2009 February)
% Version 1.0.9 (2009 October)
% Version 1.0.10 (2010 January)
% Version 1.0.11 (2012 January)
% Copyright (C) 2008-2012 Aaron Clauset (Santa Fe Institute)
% Distributed under GPL 2.0
% http://www.gnu.org/copyleft/gpl.html
% PLFIT comes with ABSOLUTELY NO WARRANTY
%
% Notes:
%
% 1. In order to implement the integer-based methods in Matlab, the numeric
% maximization of the log-likelihood function was used. This requires
% that we specify the range of scaling parameters considered. We set
% this range to be [1.50 : 0.01 : 3.50] by default. This vector can be
% set by the user like so,
%
% a = plfit(x,'range',[1.001:0.001:5.001]);
%
% 2. PLFIT can be told to limit the range of values considered as estimates
% for xmin in three ways. First, it can be instructed to sample these
% possible values like so,
%
% a = plfit(x,'sample',100);
%
% which uses 100 uniformly distributed values on the sorted list of
% unique values in the data set. Second, it can simply omit all
% candidates above a hard limit, like so
%
% a = plfit(x,'limit',3.4);
%
% Finally, it can be forced to use a fixed value, like so
%
% a = plfit(x,'xmin',3.4);
%
% In the case of discrete data, it rounds the limit to the nearest
% integer.
%
% 3. When the input sample size is small (e.g., < 100), the continuous
% estimator is slightly biased (toward larger values of alpha). To
% explicitly use an experimental finite-size correction, call PLFIT like
% so
%
% a = plfit(x,'finite');
%
% which does a small-size correction to alpha.
%
% 4. For continuous data, PLFIT can return erroneously large estimates of
% alpha when xmin is so large that the number of obs x >= xmin is very
% small. To prevent this, we can truncate the search over xmin values
% before the finite-size bias becomes significant by calling PLFIT as
%
% a = plfit(x,'nosmall');
%
% which skips values xmin with finite size bias > 0.1.
vec = [];
sample = [];
xminx = [];
limit = [];
finite = false;
nosmall = false;
nowarn = false;
% parse command-line parameters; trap for bad input
i=1;
while i<=length(varargin),
argok = 1;
if ischar(varargin{i}),
switch varargin{i},
case 'range', vec = varargin{i+1}; i = i + 1;
case 'sample', sample = varargin{i+1}; i = i + 1;
case 'limit', limit = varargin{i+1}; i = i + 1;
case 'xmin', xminx = varargin{i+1}; i = i + 1;
case 'finite', finite = true;
case 'nowarn', nowarn = true;
case 'nosmall', nosmall = true;
otherwise, argok=0;
end
end
if ~argok,
disp(['(PLFIT) Ignoring invalid argument #' num2str(i+1)]);
end
i = i+1;
end
if ~isempty(vec) && (~isvector(vec) || min(vec)<=1),
fprintf('(PLFIT) Error: ''range'' argument must contain a vector; using default.\n');
vec = [];
end;
if ~isempty(sample) && (~isscalar(sample) || sample<2),
fprintf('(PLFIT) Error: ''sample'' argument must be a positive integer > 1; using default.\n');
sample = [];
end;
if ~isempty(limit) && (~isscalar(limit) || limit<min(x)),
fprintf('(PLFIT) Error: ''limit'' argument must be a positive value >= 1; using default.\n');
limit = [];
end;
if ~isempty(xminx) && (~isscalar(xminx) || xminx>=max(x)),
fprintf('(PLFIT) Error: ''xmin'' argument must be a positive value < max(x); using default behavior.\n');
xminx = [];
end;
% reshape input vector
x = reshape(x,numel(x),1);
% select method (discrete or continuous) for fitting
if isempty(setdiff(x,floor(x))), f_dattype = 'INTS';
elseif isreal(x), f_dattype = 'REAL';
else f_dattype = 'UNKN';
end;
if strcmp(f_dattype,'INTS') && min(x) > 1000 && length(x)>100,
f_dattype = 'REAL';
end;
% estimate xmin and alpha, accordingly
switch f_dattype,
case 'REAL',
xmins = unique(x);
xmins = xmins(1:end-1);
if ~isempty(xminx),
xmins = xmins(find(xmins>=xminx,1,'first'));
end;
if ~isempty(limit),
xmins(xmins>limit) = [];
end;
if ~isempty(sample),
xmins = xmins(unique(round(linspace(1,length(xmins),sample))));
end;
dat = zeros(size(xmins));
z = sort(x);
for xm=1:length(xmins)
xmin = xmins(xm);
z = z(z>=xmin);
n = length(z);
% estimate alpha using direct MLE
a = n ./ sum( log(z./xmin) );
if nosmall,
if (a-1)/sqrt(n) > 0.1
dat(xm:end) = [];
xm = length(xmins)+1; %#ok<FXSET,NASGU>
break;
end;
end;
% compute KS statistic
cx = (0:n-1)'./n;
cf = 1-(xmin./z).^a;
dat(xm) = max( abs(cf-cx) );
end;
D = min(dat);
xmin = xmins(find(dat<=D,1,'first'));
z = x(x>=xmin);
n = length(z);
alpha = 1 + n ./ sum( log(z./xmin) );
if finite, alpha = alpha*(n-1)/n+1/n; end; % finite-size correction
if n < 50 && ~finite && ~nowarn,
% fprintf('(PLFIT) Warning: finite-size bias may be present.\n');
end;
L = n*log((alpha-1)/xmin) - alpha.*sum(log(z./xmin));
case 'INTS',
if isempty(vec),
vec = (1.50:0.01:3.50); % covers range of most practical
end; % scaling parameters
zvec = zeta(vec);
xmins = unique(x);
xmins = xmins(1:end-1);
if ~isempty(xminx),
xmins = xmins(find(xmins>=xminx,1,'first'));
end;
if ~isempty(limit),
limit = round(limit);
xmins(xmins>limit) = [];
end;
if ~isempty(sample),
xmins = xmins(unique(round(linspace(1,length(xmins),sample))));
end;
if isempty(xmins)
fprintf('(PLFIT) Error: x must contain at least two unique values.\n');
alpha = NaN; xmin = x(1); D = NaN; %#ok<NASGU>
return;
end;
xmax = max(x);
dat = zeros(length(xmins),2);
z = x;
fcatch = 0;
for xm=1:length(xmins)
xmin = xmins(xm);
z = z(z>=xmin);
n = length(z);
% estimate alpha via direct maximization of likelihood function
if fcatch==0
try
% vectorized version of numerical calculation
zdiff = sum( repmat((1:xmin-1)',1,length(vec)).^-repmat(vec,xmin-1,1) ,1);
L = -vec.*sum(log(z)) - n.*log(zvec - zdiff);
catch
% catch: force loop to default to iterative version for
% remainder of the search
fcatch = 1;
end;
end;
if fcatch==1
% force iterative calculation (more memory efficient, but
% can be slower)
L = -Inf*ones(size(vec));
slogz = sum(log(z));
xminvec = (1:xmin-1);
for k=1:length(vec)
L(k) = -vec(k)*slogz - n*log(zvec(k) - sum(xminvec.^-vec(k)));
end
end;
[Y,I] = max(L); %#ok<ASGLU>
% compute KS statistic
fit = cumsum((((xmin:xmax).^-vec(I)))./ (zvec(I) - sum((1:xmin-1).^-vec(I))));
cdi = cumsum(hist(z,xmin:xmax)./n);
dat(xm,:) = [max(abs( fit - cdi )) vec(I)];
end
% select the index for the minimum value of D
[D,I] = min(dat(:,1)); %#ok<ASGLU>
xmin = xmins(I);
z = x(x>=xmin);
n = length(z);
alpha = dat(I,2);
if finite, alpha = alpha*(n-1)/n+1/n; end; % finite-size correction
if n < 50 && ~finite && ~nowarn,
% fprintf('(PLFIT) Warning: finite-size bias may be present.\n');
end;
L = -alpha*sum(log(z)) - n*log(zvec(find(vec<=alpha,1,'last')) - sum((1:xmin-1).^-alpha));
otherwise,
fprintf('(PLFIT) Error: x must contain only reals or only integers.\n');
alpha = [];
xmin = [];
L = [];
return;
end;
|
github
|
biomedical-cybernetics/coalescent_embedding-master
|
plot_embedding.m
|
.m
|
coalescent_embedding-master/usage_example/plot_embedding.m
| 4,230 |
utf_8
|
2f9d8f22d3ab6070f6eeaf9070e1ad04
|
function plot_embedding(x, coords, coloring, labels)
% Authors:
% - main code: Alessandro Muscoloni, 2017-09-21
% - support functions: indicated at the beginning of the function
% Released under MIT License
% Copyright (c) 2017 A. Muscoloni, J. M. Thomas, C. V. Cannistraci
% Reference:
% A. Muscoloni, J. M. Thomas, S. Ciucci, G. Bianconi, and C. V. Cannistraci,
% "Machine learning meets complex networks via coalescent embedding in the hyperbolic space",
% Nature Communications 8, 1615 (2017). doi:10.1038/s41467-017-01825-5
%%% INPUT %%%
% x - adjacency matrix (NxN) of the network
%
% coords - polar (Nx2) or spherical (Nx3) hyperbolic coordinates of the nodes
% in the hyperbolic disk they are in the form: [theta,r]
% in the hyperbolic sphere they are in the form: [azimuth,elevation,r]
%
% coloring - string indicating how to color the nodes:
% 'popularity' - nodes colored by degree with a blue-to-red colormap
% (valid for 2D and 3D)
% 'similarity' - nodes colored by angular coordinate with a HSV colormap
% (valid only for 2D)
% 'labels' - nodes colored by labels, which can be all unique
% (for example to indicate an ordering of the nodes)
% or not (for example to indicate community memberships)
% (valid for 2D and 3D)
%
% labels - numerical labels for the nodes (only needed if coloring = 'labels')
% check input
narginchk(3,4);
validateattributes(x, {'numeric'}, {'square','finite','nonnegative'});
if ~issymmetric(x)
error('The input matrix must be symmetric.')
end
if any(x(speye(size(x))==1))
error('The input matrix must be zero-diagonal.')
end
validateattributes(coords, {'numeric'}, {'2d','nrows',length(x)})
dims = size(coords,2);
validateattributes(dims, {'numeric'}, {'>=',2,'<=',3});
validateattributes(coloring, {'char'}, {});
if dims == 2 && ~any(strcmp(coloring,{'popularity','similarity','labels'}))
error('Possible coloring options in 2D: ''popularity'',''similarity'',''labels''.');
end
if dims == 3 && ~any(strcmp(coloring,{'popularity','labels'}))
error('Possible coloring options in 3D: ''popularity'',''labels''.');
end
if strcmp(coloring,'labels')
validateattributes(labels, {'numeric'}, {'vector','numel',length(x)})
end
% set plot options
edge_width = 1;
edge_color = [0.85 0.85 0.85];
node_size = 150;
% set the node colors
if strcmp(coloring,'popularity')
deg = full(sum(x>0,1));
deg = round((max(deg)-1) * (deg-min(deg))/(max(deg)-min(deg)) + 1);
colors = colormap_blue_to_red(max(deg));
colors = colors(deg,:);
elseif strcmp(coloring,'similarity')
colormap('hsv')
colors = coords(:,1);
elseif strcmp(coloring,'labels')
uniq_lab = unique(labels);
temp = zeros(size(labels));
for i = 1:length(uniq_lab)
temp(labels==uniq_lab(i)) = i;
end
labels = temp; clear uniq_lab temp;
colors = hsv(length(unique(labels)));
colors = colors(labels,:);
end
% plot the network
hold on
radius = 2*log(length(x));
if dims == 2
[coords(:,1),coords(:,2)] = pol2cart(coords(:,1),coords(:,2));
[h1,h2] = gplot(x, coords, 'k'); plot(h1, h2, 'Color', edge_color, 'LineWidth', edge_width);
scatter(coords(:,1), coords(:,2), node_size, colors, 'filled', 'MarkerEdgeColor', 'k');
xlim([-radius, radius]); ylim([-radius, radius])
elseif dims == 3
[coords(:,1),coords(:,2),coords(:,3)] = sph2cart(coords(:,1),coords(:,2),coords(:,3));
[r,c] = find(triu(x>0,1));
for i = 1:length(r)
plot3([coords(r(i),1) coords(c(i),1)],[coords(r(i),2) coords(c(i),2)], [coords(r(i),3) coords(c(i),3)], ...
'Color', edge_color, 'LineWidth', edge_width)
end
scatter3(coords(:,1), coords(:,2), coords(:,3), node_size, colors, 'filled', 'MarkerEdgeColor', 'k');
xlim([-radius, radius]); ylim([-radius, radius]); zlim([-radius, radius])
end
axis square
axis off
function colors = colormap_blue_to_red(n)
colors = zeros(n,3);
m = round(linspace(1,n,4));
colors(1:m(2),2) = linspace(0,1,m(2));
colors(1:m(2),3) = 1;
colors(m(2):m(3),1) = linspace(0,1,m(3)-m(2)+1);
colors(m(2):m(3),2) = 1;
colors(m(2):m(3),3) = linspace(1,0,m(3)-m(2)+1);
colors(m(3):n,1) = 1;
colors(m(3):n,2) = linspace(1,0,n-m(3)+1);
|
github
|
biomedical-cybernetics/coalescent_embedding-master
|
coalescent_embedding.m
|
.m
|
coalescent_embedding-master/usage_example/coalescent_embedding.m
| 25,081 |
utf_8
|
0f84d1345d19f28fe588f1bc8da8aeec
|
function coords = coalescent_embedding(x, pre_weighting, dim_red, angular_adjustment, dims)
% Authors:
% - main code: Alessandro Muscoloni, 2017-09-21
% - support functions: indicated at the beginning of the function
% Released under MIT License
% Copyright (c) 2017 A. Muscoloni, J. M. Thomas, C. V. Cannistraci
% Reference:
% A. Muscoloni, J. M. Thomas, S. Ciucci, G. Bianconi, and C. V. Cannistraci,
% "Machine learning meets complex networks via coalescent embedding in the hyperbolic space",
% Nature Communications 8, 1615 (2017). doi:10.1038/s41467-017-01825-5
% The time complexity of the algorithms is O(N^3).
%%% INPUT %%%
% x - adjacency matrix of the network, which must be:
% symmetric, zero-diagonal, one connected component, not fully connected;
% the network can be weighted
%
% pre_weighting - rule for pre-weighting the matrix, the alternatives are:
% 'original' -> the original weights are considered;
% NB: they should suggest distances and not similarities
% 'reverse' -> the original weights reversed are considered;
% NB: to use when they suggest similarities
% 'RA1' -> Repulsion-Attraction v1
% 'RA2' -> Repulsion-Attraction v2
% 'EBC' -> Edge-Betweenness-Centrality
%
% dim_red - dimension reduction technique, the alternatives are:
% 'ISO' -> Isomap (valid for 2D and 3D)
% 'ncISO' -> noncentered Isomap (valid for 2D and 3D)
% 'LE' -> Laplacian Eigenmaps (valid for 2D and 3D)
% 'MCE' -> Minimum Curvilinear Embedding (only valid for 2D)
% 'ncMCE' -> noncentered Minimum Curvilinear Embedding (only valid for 2D)
%
% angular_adjustment - method for the angular adjustment, the alternatives are:
% 'original' -> original angular distances are preserved (valid for 2D and 3D)
% 'EA' -> equidistant adjustment (only valid for 2D)
%
% dims - dimensions of the hyperbolic embedding space, the alternatives are:
% 2 -> hyperbolic disk
% 3 -> hyperbolic sphere
%%% OUTPUT %%%
% coords - polar or spherical hyperbolic coordinates of the nodes
% in the hyperbolic disk they are in the form: [theta,r]
% in the hyperbolic sphere they are in the form: [azimuth,elevation,r]
% for details see the documentation of the MATLAB functions
% "cart2pol" and "cart2sph"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check input
validateattributes(x, {'numeric'}, {'square','finite','nonnegative'});
if ~issymmetric(x)
error('The input matrix must be symmetric.')
end
if any(x(speye(size(x))==1))
error('The input matrix must be zero-diagonal.')
end
validateattributes(pre_weighting, {'char'}, {});
validateattributes(dim_red, {'char'}, {});
validateattributes(angular_adjustment, {'char'}, {});
validateattributes(dims, {'numeric'}, {'scalar','integer','>=',2,'<=',3});
if ~any(strcmp(pre_weighting,{'original','reverse','RA1','RA2','EBC'}))
error('Possible pre-weighting rules: ''original'',''reverse'',''RA1'',''RA2'',''EBC''.');
end
if dims == 2
if ~any(strcmp(dim_red,{'ISO','ncISO','MCE','ncMCE','LE'}))
error('Possible dimension reduction techniques in 2D: ''ISO'', ''ncISO'', ''MCE'', ''ncMCE'', ''LE''.');
end
if ~any(strcmp(angular_adjustment,{'original','EA'}))
error('Possible angular adjustment methods in 2D: ''original'', ''EA''.');
end
elseif dims == 3
if ~any(strcmp(dim_red,{'ISO','ncISO','LE'}))
error('Possible dimension reduction techniques in 3D: ''ISO'', ''ncISO'', ''LE''.');
end
if ~any(strcmp(angular_adjustment,{'original'}))
error('Possible angular adjustment methods in 3D: ''original''.');
end
end
% pre-weighting
if strcmp(pre_weighting,'original')
xw = x;
elseif strcmp(pre_weighting,'reverse')
xw = reverse_weights(x);
elseif strcmp(pre_weighting,'RA1')
xw = RA1_weighting(double(x>0));
elseif strcmp(pre_weighting,'RA2')
xw = RA2_weighting(double(x>0));
elseif strcmp(pre_weighting,'EBC')
xw = EBC_weighting(double(x>0));
end
% dimension reduction and set of hyperbolic coordinates
if dims == 2
coords = zeros(size(x,1),2);
if strcmp(dim_red,'ISO')
coords(:,1) = set_angular_coordinates_ISO_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'ncISO')
coords(:,1) = set_angular_coordinates_ncISO_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'MCE')
coords(:,1) = set_angular_coordinates_MCE_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'ncMCE')
coords(:,1) = set_angular_coordinates_ncMCE_2D(xw, angular_adjustment);
elseif strcmp(dim_red,'LE')
coords(:,1) = set_angular_coordinates_LE_2D(xw, angular_adjustment);
end
coords(:,2) = set_radial_coordinates(x);
elseif dims == 3
coords = zeros(size(x,1),3);
if strcmp(dim_red,'ISO')
[coords(:,1),coords(:,2)] = set_angular_coordinates_ISO_3D(xw);
elseif strcmp(dim_red,'ncISO')
[coords(:,1),coords(:,2)] = set_angular_coordinates_ncISO_3D(xw);
elseif strcmp(dim_red,'LE')
[coords(:,1),coords(:,2)] = set_angular_coordinates_LE_3D(xw);
end
coords(:,3) = set_radial_coordinates(x);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Support Functions %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
function xrev = reverse_weights(x)
xrev = x;
xrev(xrev>0) = abs(x(x>0) - min(x(x>0)) - max(x(x>0)));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_RA1 = RA1_weighting(x)
n = size(x,1);
cn = x*x;
deg = full(sum(x,1));
x_RA1 = x .* (repmat(deg,n,1) + repmat(deg',1,n) + (repmat(deg,n,1) .* repmat(deg',1,n))) ./ (1 + cn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_RA2 = RA2_weighting(x)
n = size(x,1);
cn = x*x;
ext = repmat(sum(x,2),1,n) - cn - 1;
x_RA2 = x .* (1 + ext + ext' + ext.*ext') ./ (1 + cn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_EBC = EBC_weighting(x)
[~,x_EBC] = betweenness_centrality(sparse(x));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_ISO_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = isomap_graph_carlo(xw, 2, 'yes');
% from cartesian to polar coordinates
% using dimensions 1 and 2 of embedding
[ang_coords,~] = cart2pol(dr_coords(:,1),dr_coords(:,2));
% change angular range from [-pi,pi] to [0,2pi]
ang_coords = mod(ang_coords + 2*pi, 2*pi);
if strcmp(angular_adjustment,'EA')
ang_coords = equidistant_adjustment(ang_coords);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_ncISO_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = isomap_graph_carlo(xw, 3, 'no');
% from cartesian to polar coordinates
% using dimensions 2 and 3 of embedding
[ang_coords,~] = cart2pol(dr_coords(:,2),dr_coords(:,3));
% change angular range from [-pi,pi] to [0,2pi]
ang_coords = mod(ang_coords + 2*pi, 2*pi);
if strcmp(angular_adjustment,'EA')
ang_coords = equidistant_adjustment(ang_coords);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_MCE_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = mce(xw, 1, 'yes');
if strcmp(angular_adjustment,'original')
% circular adjustment of dimension 1
ang_coords = circular_adjustment(dr_coords(:,1));
elseif strcmp(angular_adjustment,'EA')
% equidistant adjustment of dimension 1
ang_coords = equidistant_adjustment(dr_coords(:,1));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_ncMCE_2D(xw, angular_adjustment)
% dimension reduction
dr_coords = mce(xw, 2, 'no');
if strcmp(angular_adjustment,'original')
% circular adjustment of dimension 2
ang_coords = circular_adjustment(dr_coords(:,2));
elseif strcmp(angular_adjustment,'EA')
% equidistant adjustment of dimension 2
ang_coords = equidistant_adjustment(dr_coords(:,2));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = set_angular_coordinates_LE_2D(xw, angular_adjustment)
% dimension reduction
st = triu(full(xw),1);
st = mean(st(st>0));
heat_kernel = zeros(size(xw));
heat_kernel(xw>0) = exp(-((xw(xw>0)./st).^2));
dr_coords = leig_graph_carlo_classical(heat_kernel, 2, 'no');
% from cartesian to polar coordinates
% using dimensions 2 and 3 of embedding
% (dimensions 1 and 2 in the code since the first is skipped by the function)
[ang_coords,~] = cart2pol(dr_coords(:,1),dr_coords(:,2));
% change angular range from [-pi,pi] to [0,2pi]
ang_coords = mod(ang_coords + 2*pi, 2*pi);
if strcmp(angular_adjustment,'EA')
ang_coords = equidistant_adjustment(ang_coords);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = equidistant_adjustment(coords)
% sort input coordinates
[~,idx] = sort(coords);
% assign equidistant angular coordinates in [0,2pi[ according to the sorting
angles = linspace(0, 2*pi, length(coords)+1);
ang_coords(idx) = angles(1:end-1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ang_coords = circular_adjustment(coords)
% scale the input coordinates into the range [0,2pi]
n = length(coords);
m = 2*pi*(n-1)/n;
ang_coords = ((coords - min(coords)) ./ (max(coords) - min(coords))) * m;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [azimuth, elevation] = set_angular_coordinates_ISO_3D(xw)
% dimension reduction
dr_coords = isomap_graph_carlo(xw, 3, 'yes');
% from cartesian to spherical coordinates
% using dimensions 1-3 of embedding
[azimuth,elevation,~] = cart2sph(dr_coords(:,1),dr_coords(:,2),dr_coords(:,3));
% change angular range from [-pi,pi] to [0,2pi]
azimuth = mod(azimuth + 2*pi, 2*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [azimuth, elevation] = set_angular_coordinates_ncISO_3D(xw)
% dimension reduction
dr_coords = isomap_graph_carlo(xw, 4, 'no');
% from cartesian to spherical coordinates
% using dimensions 2-4 of embedding
[azimuth,elevation,~] = cart2sph(dr_coords(:,2),dr_coords(:,3),dr_coords(:,4));
% change angular range from [-pi,pi] to [0,2pi]
azimuth = mod(azimuth + 2*pi, 2*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [azimuth, elevation] = set_angular_coordinates_LE_3D(xw)
% dimension reduction
st = triu(full(xw),1);
st = mean(st(st>0));
heat_kernel = zeros(size(xw));
heat_kernel(xw>0) = exp(-((xw(xw>0)./st).^2));
dr_coords = leig_graph_carlo_classical(heat_kernel, 3, 'no');
% from cartesian to spherical coordinates
% using dimensions 2-4 of embedding (the first is skipped by the LE function)
[azimuth,elevation,~] = cart2sph(dr_coords(:,1),dr_coords(:,2),dr_coords(:,3));
% change angular range from [-pi,pi] to [0,2pi]
azimuth = mod(azimuth + 2*pi, 2*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function radial_coordinates = set_radial_coordinates(x)
n = size(x,1);
deg = full(sum(x>0,1));
if all(deg == deg(1))
error('All the nodes have the same degree, the degree distribution cannot fit a power-law.');
end
% fit power-law degree distribution
gamma_range = 1.01:0.01:10.00;
small_size_limit = 100;
if length(deg) < small_size_limit
gamma = plfit(deg, 'finite', 'range', gamma_range);
else
gamma = plfit(deg, 'range', gamma_range);
end
beta = 1 / (gamma - 1);
% sort nodes by decreasing degree
[~,idx] = sort(deg, 'descend');
% for beta > 1 (gamma < 2) some radial coordinates are negative
radial_coordinates = zeros(1, n);
radial_coordinates(idx) = max(0, 2*beta*log(1:n) + 2*(1-beta)*log(n));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [f, time] = leig_graph_carlo_classical(x, d, centring)
% Maps the high-dimensional samples in 'x' to a low dimensional space using
% Laplacian Eigenmaps (coded 27-JANUARY-2013 by Gregorio Alanis-Lobato)
t = tic;
graph = max(x, x');
% Kernel centering
if strcmp(centring, 'yes')
graph=kernel_centering(graph); %Compute the centred MC-kernel
end
D = sum(graph, 2); %Degree values
D = diag(D); %Degree matrix
% Graph laplacian
L = D - graph;
% Solving the generalised eigenvalue problem L*f = lambda*D*f
[f, ~] = eig(L, D);
f = real(f(:, 2:d+1));
time = toc(t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [s,time] = isomap_graph_carlo(x, n, centring)
%INPUT
% x => Distance or correlation matrix x
% n => Dimension into which the data is to be projected
% centring => 'yes' is x should be centred or 'no' if not
%OUTPUT
% s => Sample configuration in the space of n dimensions
t = tic;
% initialization
x = max(x, x');
% Iso-kernel computation
kernel=graphallshortestpaths(sparse(x),'directed','false');
clear x
kernel=max(kernel,kernel');
% Kernel centering
if strcmp(centring, 'yes')
kernel=kernel_centering(kernel); %Compute the centred Iso-kernel
end
% Embedding
[~,L,V] = svd(kernel, 'econ');
sqrtL = sqrt(L(1:n,1:n)); clear L
V = V(:,1:n);
s = real((sqrtL * V')');
time = toc(t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [s, time] = mce(x, n, centring)
%Given a distance or correlation matrix x, it performs Minimum Curvilinear
%Embedding (MCE) or non-centred MCE (ncMCE) (coded 27-SEPTEMBER-2011 by
%Carlo Cannistraci)
%INPUT
% x => Distance or correlation matrix x
% n => Dimension into which the data is to be projected
% centring => 'yes' is x should be centred or 'no' if not
%OUTPUT
% s => Sample configuration in the space of n dimensions
t = tic;
% initialization
x = max(x, x');
% MC-kernel computation
kernel=graphallshortestpaths(graphminspantree(sparse(x),'method','kruskal'),'directed','false');
clear x
kernel=max(kernel,kernel');
% Kernel centering
if strcmp(centring, 'yes')
kernel=kernel_centering(kernel); %Compute the centred MC-kernel
end
% Embedding
[~,L,V] = svd(kernel, 'econ');
sqrtL = sqrt(L(1:n,1:n)); clear L
V = V(:,1:n);
s = (sqrtL * V')';
s=real(s(:,1:n));
time = toc(t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function D = kernel_centering(D)
% 2011-09-27 - Carlo Vittorio Cannistraci
%%% INPUT %%%
% D - Distance matrix
%%% OUTPUT %%%
% D - Centered distance matrix
% Centering
N = size(D,1);
J = eye(N) - (1/N)*ones(N);
D = -0.5*(J*(D.^2)*J);
% Housekeeping
D(isnan(D)) = 0;
D(isinf(D)) = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [alpha, xmin, L]=plfit(x, varargin)
% PLFIT fits a power-law distributional model to data.
% Source: http://www.santafe.edu/~aaronc/powerlaws/
%
% PLFIT(x) estimates x_min and alpha according to the goodness-of-fit
% based method described in Clauset, Shalizi, Newman (2007). x is a
% vector of observations of some quantity to which we wish to fit the
% power-law distribution p(x) ~ x^-alpha for x >= xmin.
% PLFIT automatically detects whether x is composed of real or integer
% values, and applies the appropriate method. For discrete data, if
% min(x) > 1000, PLFIT uses the continuous approximation, which is
% a reliable in this regime.
%
% The fitting procedure works as follows:
% 1) For each possible choice of x_min, we estimate alpha via the
% method of maximum likelihood, and calculate the Kolmogorov-Smirnov
% goodness-of-fit statistic D.
% 2) We then select as our estimate of x_min, the value that gives the
% minimum value D over all values of x_min.
%
% Note that this procedure gives no estimate of the uncertainty of the
% fitted parameters, nor of the validity of the fit.
%
% Example:
% x = (1-rand(10000,1)).^(-1/(2.5-1));
% [alpha, xmin, L] = plfit(x);
%
% The output 'alpha' is the maximum likelihood estimate of the scaling
% exponent, 'xmin' is the estimate of the lower bound of the power-law
% behavior, and L is the log-likelihood of the data x>=xmin under the
% fitted power law.
%
% For more information, try 'type plfit'
%
% See also PLVAR, PLPVA
% Version 1.0 (2007 May)
% Version 1.0.2 (2007 September)
% Version 1.0.3 (2007 September)
% Version 1.0.4 (2008 January)
% Version 1.0.5 (2008 March)
% Version 1.0.6 (2008 July)
% Version 1.0.7 (2008 October)
% Version 1.0.8 (2009 February)
% Version 1.0.9 (2009 October)
% Version 1.0.10 (2010 January)
% Version 1.0.11 (2012 January)
% Copyright (C) 2008-2012 Aaron Clauset (Santa Fe Institute)
% Distributed under GPL 2.0
% http://www.gnu.org/copyleft/gpl.html
% PLFIT comes with ABSOLUTELY NO WARRANTY
%
% Notes:
%
% 1. In order to implement the integer-based methods in Matlab, the numeric
% maximization of the log-likelihood function was used. This requires
% that we specify the range of scaling parameters considered. We set
% this range to be [1.50 : 0.01 : 3.50] by default. This vector can be
% set by the user like so,
%
% a = plfit(x,'range',[1.001:0.001:5.001]);
%
% 2. PLFIT can be told to limit the range of values considered as estimates
% for xmin in three ways. First, it can be instructed to sample these
% possible values like so,
%
% a = plfit(x,'sample',100);
%
% which uses 100 uniformly distributed values on the sorted list of
% unique values in the data set. Second, it can simply omit all
% candidates above a hard limit, like so
%
% a = plfit(x,'limit',3.4);
%
% Finally, it can be forced to use a fixed value, like so
%
% a = plfit(x,'xmin',3.4);
%
% In the case of discrete data, it rounds the limit to the nearest
% integer.
%
% 3. When the input sample size is small (e.g., < 100), the continuous
% estimator is slightly biased (toward larger values of alpha). To
% explicitly use an experimental finite-size correction, call PLFIT like
% so
%
% a = plfit(x,'finite');
%
% which does a small-size correction to alpha.
%
% 4. For continuous data, PLFIT can return erroneously large estimates of
% alpha when xmin is so large that the number of obs x >= xmin is very
% small. To prevent this, we can truncate the search over xmin values
% before the finite-size bias becomes significant by calling PLFIT as
%
% a = plfit(x,'nosmall');
%
% which skips values xmin with finite size bias > 0.1.
vec = [];
sample = [];
xminx = [];
limit = [];
finite = false;
nosmall = false;
nowarn = false;
% parse command-line parameters; trap for bad input
i=1;
while i<=length(varargin),
argok = 1;
if ischar(varargin{i}),
switch varargin{i},
case 'range', vec = varargin{i+1}; i = i + 1;
case 'sample', sample = varargin{i+1}; i = i + 1;
case 'limit', limit = varargin{i+1}; i = i + 1;
case 'xmin', xminx = varargin{i+1}; i = i + 1;
case 'finite', finite = true;
case 'nowarn', nowarn = true;
case 'nosmall', nosmall = true;
otherwise, argok=0;
end
end
if ~argok,
disp(['(PLFIT) Ignoring invalid argument #' num2str(i+1)]);
end
i = i+1;
end
if ~isempty(vec) && (~isvector(vec) || min(vec)<=1),
fprintf('(PLFIT) Error: ''range'' argument must contain a vector; using default.\n');
vec = [];
end;
if ~isempty(sample) && (~isscalar(sample) || sample<2),
fprintf('(PLFIT) Error: ''sample'' argument must be a positive integer > 1; using default.\n');
sample = [];
end;
if ~isempty(limit) && (~isscalar(limit) || limit<min(x)),
fprintf('(PLFIT) Error: ''limit'' argument must be a positive value >= 1; using default.\n');
limit = [];
end;
if ~isempty(xminx) && (~isscalar(xminx) || xminx>=max(x)),
fprintf('(PLFIT) Error: ''xmin'' argument must be a positive value < max(x); using default behavior.\n');
xminx = [];
end;
% reshape input vector
x = reshape(x,numel(x),1);
% select method (discrete or continuous) for fitting
if isempty(setdiff(x,floor(x))), f_dattype = 'INTS';
elseif isreal(x), f_dattype = 'REAL';
else f_dattype = 'UNKN';
end;
if strcmp(f_dattype,'INTS') && min(x) > 1000 && length(x)>100,
f_dattype = 'REAL';
end;
% estimate xmin and alpha, accordingly
switch f_dattype,
case 'REAL',
xmins = unique(x);
xmins = xmins(1:end-1);
if ~isempty(xminx),
xmins = xmins(find(xmins>=xminx,1,'first'));
end;
if ~isempty(limit),
xmins(xmins>limit) = [];
end;
if ~isempty(sample),
xmins = xmins(unique(round(linspace(1,length(xmins),sample))));
end;
dat = zeros(size(xmins));
z = sort(x);
for xm=1:length(xmins)
xmin = xmins(xm);
z = z(z>=xmin);
n = length(z);
% estimate alpha using direct MLE
a = n ./ sum( log(z./xmin) );
if nosmall,
if (a-1)/sqrt(n) > 0.1
dat(xm:end) = [];
xm = length(xmins)+1; %#ok<FXSET,NASGU>
break;
end;
end;
% compute KS statistic
cx = (0:n-1)'./n;
cf = 1-(xmin./z).^a;
dat(xm) = max( abs(cf-cx) );
end;
D = min(dat);
xmin = xmins(find(dat<=D,1,'first'));
z = x(x>=xmin);
n = length(z);
alpha = 1 + n ./ sum( log(z./xmin) );
if finite, alpha = alpha*(n-1)/n+1/n; end; % finite-size correction
if n < 50 && ~finite && ~nowarn,
% fprintf('(PLFIT) Warning: finite-size bias may be present.\n');
end;
L = n*log((alpha-1)/xmin) - alpha.*sum(log(z./xmin));
case 'INTS',
if isempty(vec),
vec = (1.50:0.01:3.50); % covers range of most practical
end; % scaling parameters
zvec = zeta(vec);
xmins = unique(x);
xmins = xmins(1:end-1);
if ~isempty(xminx),
xmins = xmins(find(xmins>=xminx,1,'first'));
end;
if ~isempty(limit),
limit = round(limit);
xmins(xmins>limit) = [];
end;
if ~isempty(sample),
xmins = xmins(unique(round(linspace(1,length(xmins),sample))));
end;
if isempty(xmins)
fprintf('(PLFIT) Error: x must contain at least two unique values.\n');
alpha = NaN; xmin = x(1); D = NaN; %#ok<NASGU>
return;
end;
xmax = max(x);
dat = zeros(length(xmins),2);
z = x;
fcatch = 0;
for xm=1:length(xmins)
xmin = xmins(xm);
z = z(z>=xmin);
n = length(z);
% estimate alpha via direct maximization of likelihood function
if fcatch==0
try
% vectorized version of numerical calculation
zdiff = sum( repmat((1:xmin-1)',1,length(vec)).^-repmat(vec,xmin-1,1) ,1);
L = -vec.*sum(log(z)) - n.*log(zvec - zdiff);
catch
% catch: force loop to default to iterative version for
% remainder of the search
fcatch = 1;
end;
end;
if fcatch==1
% force iterative calculation (more memory efficient, but
% can be slower)
L = -Inf*ones(size(vec));
slogz = sum(log(z));
xminvec = (1:xmin-1);
for k=1:length(vec)
L(k) = -vec(k)*slogz - n*log(zvec(k) - sum(xminvec.^-vec(k)));
end
end;
[Y,I] = max(L); %#ok<ASGLU>
% compute KS statistic
fit = cumsum((((xmin:xmax).^-vec(I)))./ (zvec(I) - sum((1:xmin-1).^-vec(I))));
cdi = cumsum(hist(z,xmin:xmax)./n);
dat(xm,:) = [max(abs( fit - cdi )) vec(I)];
end
% select the index for the minimum value of D
[D,I] = min(dat(:,1)); %#ok<ASGLU>
xmin = xmins(I);
z = x(x>=xmin);
n = length(z);
alpha = dat(I,2);
if finite, alpha = alpha*(n-1)/n+1/n; end; % finite-size correction
if n < 50 && ~finite && ~nowarn,
% fprintf('(PLFIT) Warning: finite-size bias may be present.\n');
end;
L = -alpha*sum(log(z)) - n*log(zvec(find(vec<=alpha,1,'last')) - sum((1:xmin-1).^-alpha));
otherwise,
fprintf('(PLFIT) Error: x must contain only reals or only integers.\n');
alpha = [];
xmin = [];
L = [];
return;
end;
|
github
|
biomedical-cybernetics/coalescent_embedding-master
|
plot_embedding.m
|
.m
|
coalescent_embedding-master/visualization_and_evaluation/plot_embedding.m
| 4,230 |
utf_8
|
2f9d8f22d3ab6070f6eeaf9070e1ad04
|
function plot_embedding(x, coords, coloring, labels)
% Authors:
% - main code: Alessandro Muscoloni, 2017-09-21
% - support functions: indicated at the beginning of the function
% Released under MIT License
% Copyright (c) 2017 A. Muscoloni, J. M. Thomas, C. V. Cannistraci
% Reference:
% A. Muscoloni, J. M. Thomas, S. Ciucci, G. Bianconi, and C. V. Cannistraci,
% "Machine learning meets complex networks via coalescent embedding in the hyperbolic space",
% Nature Communications 8, 1615 (2017). doi:10.1038/s41467-017-01825-5
%%% INPUT %%%
% x - adjacency matrix (NxN) of the network
%
% coords - polar (Nx2) or spherical (Nx3) hyperbolic coordinates of the nodes
% in the hyperbolic disk they are in the form: [theta,r]
% in the hyperbolic sphere they are in the form: [azimuth,elevation,r]
%
% coloring - string indicating how to color the nodes:
% 'popularity' - nodes colored by degree with a blue-to-red colormap
% (valid for 2D and 3D)
% 'similarity' - nodes colored by angular coordinate with a HSV colormap
% (valid only for 2D)
% 'labels' - nodes colored by labels, which can be all unique
% (for example to indicate an ordering of the nodes)
% or not (for example to indicate community memberships)
% (valid for 2D and 3D)
%
% labels - numerical labels for the nodes (only needed if coloring = 'labels')
% check input
narginchk(3,4);
validateattributes(x, {'numeric'}, {'square','finite','nonnegative'});
if ~issymmetric(x)
error('The input matrix must be symmetric.')
end
if any(x(speye(size(x))==1))
error('The input matrix must be zero-diagonal.')
end
validateattributes(coords, {'numeric'}, {'2d','nrows',length(x)})
dims = size(coords,2);
validateattributes(dims, {'numeric'}, {'>=',2,'<=',3});
validateattributes(coloring, {'char'}, {});
if dims == 2 && ~any(strcmp(coloring,{'popularity','similarity','labels'}))
error('Possible coloring options in 2D: ''popularity'',''similarity'',''labels''.');
end
if dims == 3 && ~any(strcmp(coloring,{'popularity','labels'}))
error('Possible coloring options in 3D: ''popularity'',''labels''.');
end
if strcmp(coloring,'labels')
validateattributes(labels, {'numeric'}, {'vector','numel',length(x)})
end
% set plot options
edge_width = 1;
edge_color = [0.85 0.85 0.85];
node_size = 150;
% set the node colors
if strcmp(coloring,'popularity')
deg = full(sum(x>0,1));
deg = round((max(deg)-1) * (deg-min(deg))/(max(deg)-min(deg)) + 1);
colors = colormap_blue_to_red(max(deg));
colors = colors(deg,:);
elseif strcmp(coloring,'similarity')
colormap('hsv')
colors = coords(:,1);
elseif strcmp(coloring,'labels')
uniq_lab = unique(labels);
temp = zeros(size(labels));
for i = 1:length(uniq_lab)
temp(labels==uniq_lab(i)) = i;
end
labels = temp; clear uniq_lab temp;
colors = hsv(length(unique(labels)));
colors = colors(labels,:);
end
% plot the network
hold on
radius = 2*log(length(x));
if dims == 2
[coords(:,1),coords(:,2)] = pol2cart(coords(:,1),coords(:,2));
[h1,h2] = gplot(x, coords, 'k'); plot(h1, h2, 'Color', edge_color, 'LineWidth', edge_width);
scatter(coords(:,1), coords(:,2), node_size, colors, 'filled', 'MarkerEdgeColor', 'k');
xlim([-radius, radius]); ylim([-radius, radius])
elseif dims == 3
[coords(:,1),coords(:,2),coords(:,3)] = sph2cart(coords(:,1),coords(:,2),coords(:,3));
[r,c] = find(triu(x>0,1));
for i = 1:length(r)
plot3([coords(r(i),1) coords(c(i),1)],[coords(r(i),2) coords(c(i),2)], [coords(r(i),3) coords(c(i),3)], ...
'Color', edge_color, 'LineWidth', edge_width)
end
scatter3(coords(:,1), coords(:,2), coords(:,3), node_size, colors, 'filled', 'MarkerEdgeColor', 'k');
xlim([-radius, radius]); ylim([-radius, radius]); zlim([-radius, radius])
end
axis square
axis off
function colors = colormap_blue_to_red(n)
colors = zeros(n,3);
m = round(linspace(1,n,4));
colors(1:m(2),2) = linspace(0,1,m(2));
colors(1:m(2),3) = 1;
colors(m(2):m(3),1) = linspace(0,1,m(3)-m(2)+1);
colors(m(2):m(3),2) = 1;
colors(m(2):m(3),3) = linspace(1,0,m(3)-m(2)+1);
colors(m(3):n,1) = 1;
colors(m(3):n,2) = linspace(1,0,n-m(3)+1);
|
github
|
biomedical-cybernetics/coalescent_embedding-master
|
compute_angular_separation.m
|
.m
|
coalescent_embedding-master/visualization_and_evaluation/angular_separation_index/compute_angular_separation.m
| 10,618 |
utf_8
|
ccbc95531e7b891f35adce0aed6455b5
|
function [index, group_index, pvalue] = compute_angular_separation(coords, labels, show_plot, rand_reps, rand_seed, worst_comp)
% MATLAB implementation of the angular separation index (ASI):
% a quantitative measure to evaluate the separation of groups
% over the circle circumference (2D) or sphere surface (3D).
% Reference:
% A. Muscoloni and C. V. Cannistraci (2019), "Angular separability of data clusters or network communities
% in geometrical space and its relevance to hyperbolic embedding", arXiv:1907.00025
% Released under MIT License
% Copyright (c) 2019 A. Muscoloni, C. V. Cannistraci
%%% INPUT %%%
% coords - 2D case: Nx1 vector containing for each sample the angular coordinates
% 3D case: Nx2 matrix containing for each sample the coordinates (azimut,elevation)
% angular and azimuth coordinates must be in [0,2pi]
% elevation coordinates must be in [-pi/2,pi/2]
% the code automatically selects the 2D or 3D case depending on the size of the "coords" variable
% labels - N labels for the samples indicating the group membership (numeric vector or cell of strings)
% show_plot - [optional] 1 or 0 to indicate whether the plot of the results has to be shown or not (default = 1)
% rand_reps - [optional] repetitions for evaluating random coordinates (default = 1000)
% rand_seed - [optional] nonnegative integer seed for random number generator (by default a seed is created based on the current time)
% worst_comp - [optional] 1 or 0 to indicate if the worst case should be approximated computationally or theoretically (default = 1)
% note that for the 3D case only the value 1 is valid
% (NB: optional inputs not given or empty assume the default value)
%%% OUTPUT %%%
% index - overall index in [0,1], a value 1 indicates that all the groups
% are perfectly separated over the circle circumference (2D) or sphere surface (3D),
% the more the groups are mixed the more the index tends to 0, representing a worst-case scenario.
% group_index - vector containing an index in [0,1] for each group,
% to assess its separation with respect to the other groups
% pvalue - empirical p-value computed comparing the observed index with a null distribution
% of indexes obtained from random permutations of the coordinates
% check input
narginchk(2,6)
validateattributes(coords, {'numeric'}, {})
N = size(coords,1);
D = size(coords,2) + 1;
if D == 2
if any(coords(:,1)<0 | coords(:,1)>2*pi)
error('Angular coordinates must be in [0,2pi]')
end
if N < 4
error('The index in 2D cannot be assessed for less than 4 samples')
end
elseif D == 3
if any(coords(:,1)<0 | coords(:,1)>2*pi)
error('Azimuth coordinates must be in [0,2pi]')
end
if any(coords(:,2)<-pi/2 | coords(:,2)>pi/2)
error('Elevation coordinates must be in [-pi/2,pi/2]')
end
if N < 6
error('The index in 3D cannot be assessed for less than 6 samples')
end
else
error('Input coordinates must be a one-column vector (2D case) or two-columns matrix (3D case)')
end
validateattributes(labels, {'numeric','cell'}, {'vector','numel',N})
if ~exist('show_plot','var') || isempty(show_plot)
show_plot = 1;
else
validateattributes(show_plot, {'numeric'}, {'scalar','binary'})
end
if ~exist('rand_reps','var') || isempty(rand_reps)
rand_reps = 1000;
else
validateattributes(rand_reps, {'numeric'}, {'scalar','integer','positive'})
end
if ~exist('rand_seed','var') || isempty(rand_seed)
rand_str = RandStream('mt19937ar','Seed','shuffle');
else
validateattributes(rand_seed, {'numeric'}, {'scalar','integer','nonnegative'})
rand_str = RandStream('mt19937ar','Seed',rand_seed);
end
if ~exist('worst_comp','var') || isempty(worst_comp)
worst_comp = 1;
else
validateattributes(worst_comp, {'numeric'}, {'scalar','binary'})
if D == 3 && worst_comp == 0
error('In 3D the worst case can be approximated only computationally (worst_comp = 1)')
end
end
% convert labels
unique_labels = unique(labels);
M = length(unique(labels));
if M==1 || M==N
error('The number of groups must be greater than 1 and lower than the number of samples')
end
temp = zeros(N,1);
Nk = zeros(M,1);
for k = 1:M
if isnumeric(labels)
temp(labels==unique_labels(k)) = k;
else
temp(strcmp(labels,unique_labels{k})) = k;
end
Nk(k) = sum(temp == k);
end
labels = temp; clear temp;
% compute index
[index, group_index, pvalue, index_rand] = compute_index(D, coords, labels, N, Nk, M, rand_reps, rand_str, worst_comp);
% restore original labels in group index
if isnumeric(unique_labels)
group_index(:,1) = unique_labels;
else
group_index = num2cell(group_index);
group_index(:,1) = unique_labels(:);
end
% plot results
if show_plot
plot_results(index, index_rand, pvalue)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [index, group_index, pvalue, index_rand] = compute_index(D, coords, labels, N, Nk, M, rand_reps, rand_str, worst_comp)
if D == 2
compute_mistakes = @compute_mistakes_2D;
else
compute_mistakes = @compute_mistakes_3D;
end
% compute mistakes in input coordinates
mistakes = compute_mistakes(coords, labels, N, Nk, M);
% compute mistakes in random coordinates
mistakes_rand = zeros(M,rand_reps);
for i = 1:rand_reps
idx_rand = randperm(rand_str, size(coords,1));
mistakes_rand(:,i) = compute_mistakes(coords(idx_rand,:), labels, N, Nk, M);
end
if all(isnan(mistakes)) || all(isnan(mistakes_rand(:)))
error('The index could not be computed for any group.')
end
% find the worst case
if worst_comp == 1
[~,idx] = max(nansum(mistakes_rand,1));
mistakes_worst = mistakes_rand(:,idx);
else
mistakes_worst = ceil((N-Nk).*(Nk-1)./Nk);
mistakes_worst(Nk == 1) = NaN;
end
% compute group index
group_index = zeros(M,2);
group_index(:,2) = 1 - mistakes./mistakes_worst;
% compute overall index
index = 1 - nansum(mistakes)/nansum(mistakes_worst);
index = max(index,0);
% compute pvalue
index_rand = 1 - nansum(mistakes_rand,1)./repmat(nansum(mistakes_worst),1,rand_reps);
index_rand = max(index_rand,0);
pvalue = (sum(index_rand >= index) + 1) / (rand_reps + 1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function plot_results(index, index_rand, pvalue)
% plot figure
figure('color', 'white')
[fy,fx] = ksdensity(index_rand);
plot(fx, fy, 'k', 'LineWidth', 2)
hold on
plot([index,index], [0,max(fy)*1.1], 'r', 'LineWidth', 2)
set(gca,'YLim',[0,max(fy)*1.1],'XTick',0:0.1:1,'XLim',[0,max(max(fx),index)*1.1])
box on
xlabel('index')
ylabel('probability density')
text(1, 1.05, ['pvalue = ' num2str(pvalue)], 'Units', 'normalized', 'HorizontalAlignment', 'right')
legend({'null distribution','observed value'},'Location','northoutside','Orientation','vertical')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%% 2D separation (circle circumference) %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function mistakes = compute_mistakes_2D(coords, labels, N, Nk, M)
% ranking of the samples
x = zeros(N,1);
[~,idx] = sort(coords);
x(idx) = 1:N;
% for each group
mistakes = zeros(M,1);
for k = 1:M
if Nk(k) == 1
mistakes(k) = NaN;
continue;
end
% compute number of wrong samples within the extremes of the group,
% where the extremes are the adjacent samples at the maximum distance:
% - find the number of samples of other groups between adjacent samples
% of the current group
% - sum them excluding the maximum value, since it will be related to
% wrong samples outside the extremes
x_k = x(labels == k);
x_list = sort(x_k);
wr = zeros(Nk(k),1);
for l = 1:Nk(k)-1
wr(l) = x_list(l+1)-x_list(l)-1;
end
wr(end) = N-x_list(end)+x_list(1)-1;
[~,max_id] = max(wr);
wr(max_id) = [];
mistakes(k) = sum(wr);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%% 3D separation (sphere surface) %%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function mistakes = compute_mistakes_3D(coords, labels, N, Nk, M)
% rank samples for azimuth
azim_rank = zeros(N,1);
[~,idx] = sort(coords(:,1));
azim_rank(idx) = 1:N;
mistakes = zeros(M,1);
for k = 1:M
if Nk(k) < 3
mistakes(k) = NaN;
continue;
end
try
% map the samples between the group extremes to a rectangular 2D area
[xy_group, xy_other] = map_samples_between_group_extremes_3D(labels==k, azim_rank, coords(:,1), coords(:,2), N, Nk(k));
if isempty(xy_other)
mistakes(k) = 0;
else
% compute mistakes within the polygonal area delimited by the group samples
pol_idx = convhull(xy_group(:,1),xy_group(:,2));
[in_pol, on_pol] = inpolygon(xy_other(:,1),xy_other(:,2),xy_group(pol_idx,1),xy_group(pol_idx,2));
mistakes(k) = sum(in_pol) - sum(on_pol);
end
catch
mistakes(k) = NaN;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [xy_group, xy_other] = map_samples_between_group_extremes_3D(labels_k, azim_rank, azim, elev, N, Nk)
% find group extremes: azimuth
azim_k_order = sort(azim_rank(labels_k));
wr = zeros(Nk,1);
for i = 1:Nk-1
wr(i) = azim_k_order(i+1) - azim_k_order(i) - 1;
end
wr(Nk) = N - azim_k_order(end) + azim_k_order(1) - 1;
[~,max_idx] = max(wr);
if max_idx == Nk
azim_ext = [azim(azim_rank==azim_k_order(1)) azim(azim_rank==azim_k_order(Nk))];
disc = 0;
else
azim_ext = [azim(azim_rank==azim_k_order(max_idx)) azim(azim_rank==azim_k_order(max_idx+1))];
disc = 1;
end
% find group extremes: elevation
elev_ext = [min(elev(labels_k)) max(elev(labels_k))];
% detect samples between the group extremes
detected = (elev>=elev_ext(1) & elev<=elev_ext(2)) & ...
((~disc & (azim>=azim_ext(1) & azim<=azim_ext(2))) | (disc & (azim>=azim_ext(2) | azim<=azim_ext(1))));
% map the coordinates to a rectangular 2D area
if ~disc
x_detected = azim(detected) - azim_ext(1);
else
x_detected = mod(azim(detected) + (2*pi-azim_ext(2)), 2*pi);
end
y_detected = elev(detected) - elev_ext(1);
% divide samples belonging to the group and not
xy_group = [x_detected(labels_k(detected)==1) y_detected(labels_k(detected)==1)];
xy_other = [x_detected(labels_k(detected)==0) y_detected(labels_k(detected)==0)];
|
github
|
kareem1925/coursera-Neural-Networks-for-Machine-Learning-master
|
train.m
|
.m
|
coursera-Neural-Networks-for-Machine-Learning-master/week05/Assignment2/train.m
| 8,724 |
utf_8
|
f1ced206e6c895129b06f256ffe18f88
|
% This function trains a neural network language model.
function [model] = train(epochs)
% Inputs:
% epochs: Number of epochs to run.
% Output:
% model: A struct containing the learned weights and biases and vocabulary.
if size(ver('Octave'),1)
OctaveMode = 1;
warning('error', 'Octave:broadcast');
start_time = time;
else
OctaveMode = 0;
start_time = clock;
end
% SET HYPERPARAMETERS HERE.
batchsize = 100; % Mini-batch size.
learning_rate = 0.1; % Learning rate; default = 0.1.
momentum = 0.9; % Momentum; default = 0.9.
numhid1 = 50; % Dimensionality of embedding space; default = 50.
numhid2 = 200; % Number of units in hidden layer; default = 200.
init_wt = 0.01; % Standard deviation of the normal distribution
% which is sampled to get the initial weights; default = 0.01
% VARIABLES FOR TRACKING TRAINING PROGRESS.
show_training_CE_after = 100;
show_validation_CE_after = 1000;
% LOAD DATA.
[train_input, train_target, valid_input, valid_target, ...
test_input, test_target, vocab] = load_data(batchsize);
[numwords, batchsize, numbatches] = size(train_input);
vocab_size = size(vocab, 2);
% INITIALIZE WEIGHTS AND BIASES.
word_embedding_weights = init_wt * randn(vocab_size, numhid1);
embed_to_hid_weights = init_wt * randn(numwords * numhid1, numhid2);
hid_to_output_weights = init_wt * randn(numhid2, vocab_size);
hid_bias = zeros(numhid2, 1);
output_bias = zeros(vocab_size, 1);
word_embedding_weights_delta = zeros(vocab_size, numhid1);
word_embedding_weights_gradient = zeros(vocab_size, numhid1);
embed_to_hid_weights_delta = zeros(numwords * numhid1, numhid2);
hid_to_output_weights_delta = zeros(numhid2, vocab_size);
hid_bias_delta = zeros(numhid2, 1);
output_bias_delta = zeros(vocab_size, 1);
expansion_matrix = eye(vocab_size);
count = 0;
tiny = exp(-30);
% TRAIN.
for epoch = 1:epochs
fprintf(1, 'Epoch %d\n', epoch);
this_chunk_CE = 0;
trainset_CE = 0;
% LOOP OVER MINI-BATCHES.
for m = 1:numbatches
input_batch = train_input(:, :, m);
target_batch = train_target(:, :, m);
% FORWARD PROPAGATE.
% Compute the state of each layer in the network given the input batch
% and all weights and biases
[embedding_layer_state, hidden_layer_state, output_layer_state] = ...
fprop(input_batch, ...
word_embedding_weights, embed_to_hid_weights, ...
hid_to_output_weights, hid_bias, output_bias);
% COMPUTE DERIVATIVE.
%% Expand the target to a sparse 1-of-K vector.
expanded_target_batch = expansion_matrix(:, target_batch);
%% Compute derivative of cross-entropy loss function.
error_deriv = output_layer_state - expanded_target_batch;
% MEASURE LOSS FUNCTION.
CE = -sum(sum(...
expanded_target_batch .* log(output_layer_state + tiny))) / batchsize;
count = count + 1;
this_chunk_CE = this_chunk_CE + (CE - this_chunk_CE) / count;
trainset_CE = trainset_CE + (CE - trainset_CE) / m;
fprintf(1, '\rBatch %d Train CE %.3f', m, this_chunk_CE);
if mod(m, show_training_CE_after) == 0
fprintf(1, '\n');
count = 0;
this_chunk_CE = 0;
end
if OctaveMode
fflush(1);
end
% BACK PROPAGATE.
%% OUTPUT LAYER.
hid_to_output_weights_gradient = hidden_layer_state * error_deriv';
output_bias_gradient = sum(error_deriv, 2);
back_propagated_deriv_1 = (hid_to_output_weights * error_deriv) ...
.* hidden_layer_state .* (1 - hidden_layer_state);
%% HIDDEN LAYER.
% FILL IN CODE. Replace the line below by one of the options.
embed_to_hid_weights_gradient = embedding_layer_state * back_propagated_deriv_1';
% Options:
% (a) embed_to_hid_weights_gradient = back_propagated_deriv_1' * embedding_layer_state;
% (b) embed_to_hid_weights_gradient = embedding_layer_state * back_propagated_deriv_1';
% (c) embed_to_hid_weights_gradient = back_propagated_deriv_1;
% (d) embed_to_hid_weights_gradient = embedding_layer_state;
% FILL IN CODE. Replace the line below by one of the options.
hid_bias_gradient = sum(back_propagated_deriv_1, 2);
% Options
% (a) hid_bias_gradient = sum(back_propagated_deriv_1, 2);
% (b) hid_bias_gradient = sum(back_propagated_deriv_1, 1);
% (c) hid_bias_gradient = back_propagated_deriv_1;
% (d) hid_bias_gradient = back_propagated_deriv_1';
% FILL IN CODE. Replace the line below by one of the options.
back_propagated_deriv_2 = embed_to_hid_weights * back_propagated_deriv_1;
% Options
% (a) back_propagated_deriv_2 = embed_to_hid_weights * back_propagated_deriv_1;
% (b) back_propagated_deriv_2 = back_propagated_deriv_1 * embed_to_hid_weights;
% (c) back_propagated_deriv_2 = back_propagated_deriv_1' * embed_to_hid_weights;
% (d) back_propagated_deriv_2 = back_propagated_deriv_1 * embed_to_hid_weights';
word_embedding_weights_gradient(:) = 0;
%% EMBEDDING LAYER.
for w = 1:numwords
word_embedding_weights_gradient = word_embedding_weights_gradient + ...
expansion_matrix(:, input_batch(w, :)) * ...
(back_propagated_deriv_2(1 + (w - 1) * numhid1 : w * numhid1, :)');
end
% UPDATE WEIGHTS AND BIASES.
word_embedding_weights_delta = ...
momentum .* word_embedding_weights_delta + ...
word_embedding_weights_gradient ./ batchsize;
word_embedding_weights = word_embedding_weights...
- learning_rate * word_embedding_weights_delta;
embed_to_hid_weights_delta = ...
momentum .* embed_to_hid_weights_delta + ...
embed_to_hid_weights_gradient ./ batchsize;
embed_to_hid_weights = embed_to_hid_weights...
- learning_rate * embed_to_hid_weights_delta;
hid_to_output_weights_delta = ...
momentum .* hid_to_output_weights_delta + ...
hid_to_output_weights_gradient ./ batchsize;
hid_to_output_weights = hid_to_output_weights...
- learning_rate * hid_to_output_weights_delta;
hid_bias_delta = momentum .* hid_bias_delta + ...
hid_bias_gradient ./ batchsize;
hid_bias = hid_bias - learning_rate * hid_bias_delta;
output_bias_delta = momentum .* output_bias_delta + ...
output_bias_gradient ./ batchsize;
output_bias = output_bias - learning_rate * output_bias_delta;
% VALIDATE.
if mod(m, show_validation_CE_after) == 0
fprintf(1, '\rRunning validation ...');
if OctaveMode
fflush(1);
end
[embedding_layer_state, hidden_layer_state, output_layer_state] = ...
fprop(valid_input, word_embedding_weights, embed_to_hid_weights,...
hid_to_output_weights, hid_bias, output_bias);
datasetsize = size(valid_input, 2);
expanded_valid_target = expansion_matrix(:, valid_target);
CE = -sum(sum(...
expanded_valid_target .* log(output_layer_state + tiny))) /datasetsize;
fprintf(1, ' Validation CE %.3f\n', CE);
if OctaveMode
fflush(1);
end
end
end
fprintf(1, '\rAverage Training CE %.3f\n', trainset_CE);
end
fprintf(1, 'Finished Training.\n');
if OctaveMode
fflush(1);
end
fprintf(1, 'Final Training CE %.3f\n', trainset_CE);
% EVALUATE ON VALIDATION SET.
fprintf(1, '\rRunning validation ...');
if OctaveMode
fflush(1);
end
[embedding_layer_state, hidden_layer_state, output_layer_state] = ...
fprop(valid_input, word_embedding_weights, embed_to_hid_weights,...
hid_to_output_weights, hid_bias, output_bias);
datasetsize = size(valid_input, 2);
expanded_valid_target = expansion_matrix(:, valid_target);
CE = -sum(sum(...
expanded_valid_target .* log(output_layer_state + tiny))) / datasetsize;
fprintf(1, '\rFinal Validation CE %.3f\n', CE);
if OctaveMode
fflush(1);
end
% EVALUATE ON TEST SET.
fprintf(1, '\rRunning test ...');
if OctaveMode
fflush(1);
end
[embedding_layer_state, hidden_layer_state, output_layer_state] = ...
fprop(test_input, word_embedding_weights, embed_to_hid_weights,...
hid_to_output_weights, hid_bias, output_bias);
datasetsize = size(test_input, 2);
expanded_test_target = expansion_matrix(:, test_target);
CE = -sum(sum(...
expanded_test_target .* log(output_layer_state + tiny))) / datasetsize;
fprintf(1, '\rFinal Test CE %.3f\n', CE);
if OctaveMode
fflush(1);
end
model.word_embedding_weights = word_embedding_weights;
model.embed_to_hid_weights = embed_to_hid_weights;
model.hid_to_output_weights = hid_to_output_weights;
model.hid_bias = hid_bias;
model.output_bias = output_bias;
model.vocab = vocab;
% In MATLAB replace line below with 'end_time = clock;'
if OctaveMode
end_time = time;
diff = end_time - start_time;
else
end_time = clock;
diff = etime(end_time, start_time);
end
fprintf(1, 'Training took %.2f seconds\n', diff);
end
|
github
|
kareem1925/coursera-Neural-Networks-for-Machine-Learning-master
|
a4_main.m
|
.m
|
coursera-Neural-Networks-for-Machine-Learning-master/week13/Assignment4/a4_main.m
| 4,551 |
utf_8
|
a36e706a0a625e7ca1eeadc45f05145f
|
% This file was published on Wed Nov 14 20:48:30 2012, UTC.
function a4_main(n_hid, lr_rbm, lr_classification, n_iterations)
% first, train the rbm
global report_calls_to_sample_bernoulli
report_calls_to_sample_bernoulli = false;
global data_sets
if prod(size(data_sets)) ~= 1,
error('You must run a4_init before you do anything else.');
end
rbm_w = optimize([n_hid, 256], ...
@(rbm_w, data) cd1(rbm_w, data.inputs), ... % discard labels
data_sets.training, ...
lr_rbm, ...
n_iterations);
% rbm_w is now a weight matrix of <n_hid> by <number of visible units, i.e. 256>
show_rbm(rbm_w);
input_to_hid = rbm_w;
% calculate the hidden layer representation of the labeled data
hidden_representation = logistic(input_to_hid * data_sets.training.inputs);
% train hid_to_class
data_2.inputs = hidden_representation;
data_2.targets = data_sets.training.targets;
hid_to_class = optimize([10, n_hid], @(model, data) classification_phi_gradient(model, data), data_2, lr_classification, n_iterations);
% report results
for data_details = reshape({'training', data_sets.training, 'validation', data_sets.validation, 'test', data_sets.test}, [2, 3]),
data_name = data_details{1};
data = data_details{2};
hid_input = input_to_hid * data.inputs; % size: <number of hidden units> by <number of data cases>
hid_output = logistic(hid_input); % size: <number of hidden units> by <number of data cases>
class_input = hid_to_class * hid_output; % size: <number of classes> by <number of data cases>
class_normalizer = log_sum_exp_over_rows(class_input); % log(sum(exp of class_input)) is what we subtract to get properly normalized log class probabilities. size: <1> by <number of data cases>
log_class_prob = class_input - repmat(class_normalizer, [size(class_input, 1), 1]); % log of probability of each class. size: <number of classes, i.e. 10> by <number of data cases>
error_rate = mean(double(argmax_over_rows(class_input) ~= argmax_over_rows(data.targets))); % scalar
loss = -mean(sum(log_class_prob .* data.targets, 1)); % scalar. select the right log class probability using that sum; then take the mean over all data cases.
fprintf('For the %s data, the classification cross-entropy loss is %f, and the classification error rate (i.e. the misclassification rate) is %f\n', data_name, loss, error_rate);
end
report_calls_to_sample_bernoulli = true;
end
function d_phi_by_d_input_to_class = classification_phi_gradient(input_to_class, data)
% This is about a very simple model: there's an input layer, and a softmax output layer. There are no hidden layers, and no biases.
% This returns the gradient of phi (a.k.a. negative the loss) for the <input_to_class> matrix.
% <input_to_class> is a matrix of size <number of classes> by <number of input units>.
% <data> has fields .inputs (matrix of size <number of input units> by <number of data cases>) and .targets (matrix of size <number of classes> by <number of data cases>).
% first: forward pass
class_input = input_to_class * data.inputs; % input to the components of the softmax. size: <number of classes> by <number of data cases>
class_normalizer = log_sum_exp_over_rows(class_input); % log(sum(exp)) is what we subtract to get normalized log class probabilities. size: <1> by <number of data cases>
log_class_prob = class_input - repmat(class_normalizer, [size(class_input, 1), 1]); % log of probability of each class. size: <number of classes> by <number of data cases>
class_prob = exp(log_class_prob); % probability of each class. Each column (i.e. each case) sums to 1. size: <number of classes> by <number of data cases>
% now: gradient computation
d_loss_by_d_class_input = -(data.targets - class_prob) ./ size(data.inputs, 2); % size: <number of classes> by <number of data cases>
d_loss_by_d_input_to_class = d_loss_by_d_class_input * data.inputs.'; % size: <number of classes> by <number of input units>
d_phi_by_d_input_to_class = -d_loss_by_d_input_to_class;
end
function indices = argmax_over_rows(matrix)
[dump, indices] = max(matrix);
end
function ret = log_sum_exp_over_rows(matrix)
% This computes log(sum(exp(a), 1)) in a numerically stable way
maxs_small = max(matrix, [], 1);
maxs_big = repmat(maxs_small, [size(matrix, 1), 1]);
ret = log(sum(exp(matrix - maxs_big), 1)) + maxs_small;
end
|
github
|
kareem1925/coursera-Neural-Networks-for-Machine-Learning-master
|
a3.m
|
.m
|
coursera-Neural-Networks-for-Machine-Learning-master/week09/Assignment3/a3.m
| 12,963 |
utf_8
|
cd34878083ef445c9f8930ac125fac6b
|
function a3(wd_coefficient, n_hid, n_iters, learning_rate, momentum_multiplier, do_early_stopping, mini_batch_size)
warning('error', 'Octave:broadcast');
if exist('page_output_immediately'), page_output_immediately(1); end
more off;
model = initial_model(n_hid);
from_data_file = load('data.mat');
datas = from_data_file.data;
n_training_cases = size(datas.training.inputs, 2);
if n_iters ~= 0, test_gradient(model, datas.training, wd_coefficient); end
% optimization
theta = model_to_theta(model);
momentum_speed = theta * 0;
training_data_losses = [];
validation_data_losses = [];
if do_early_stopping,
best_so_far.theta = -1; % this will be overwritten soon
best_so_far.validation_loss = inf;
best_so_far.after_n_iters = -1;
end
for optimization_iteration_i = 1:n_iters,
model = theta_to_model(theta);
training_batch_start = mod((optimization_iteration_i-1) * mini_batch_size, n_training_cases)+1;
training_batch.inputs = datas.training.inputs(:, training_batch_start : training_batch_start + mini_batch_size - 1);
training_batch.targets = datas.training.targets(:, training_batch_start : training_batch_start + mini_batch_size - 1);
gradient = model_to_theta(d_loss_by_d_model(model, training_batch, wd_coefficient));
momentum_speed = momentum_speed * momentum_multiplier - gradient;
theta = theta + momentum_speed * learning_rate;
model = theta_to_model(theta);
training_data_losses = [training_data_losses, loss(model, datas.training, wd_coefficient)];
validation_data_losses = [validation_data_losses, loss(model, datas.validation, wd_coefficient)];
if do_early_stopping && validation_data_losses(end) < best_so_far.validation_loss,
best_so_far.theta = theta; % this will be overwritten soon
best_so_far.validation_loss = validation_data_losses(end);
best_so_far.after_n_iters = optimization_iteration_i;
end
if mod(optimization_iteration_i, round(n_iters/10)) == 0,
fprintf('After %d optimization iterations, training data loss is %f, and validation data loss is %f\n', optimization_iteration_i, training_data_losses(end), validation_data_losses(end));
end
end
if n_iters ~= 0, test_gradient(model, datas.training, wd_coefficient); end % check again, this time with more typical parameters
if do_early_stopping,
fprintf('Early stopping: validation loss was lowest after %d iterations. We chose the model that we had then.\n', best_so_far.after_n_iters);
theta = best_so_far.theta;
end
% the optimization is finished. Now do some reporting.
model = theta_to_model(theta);
if n_iters ~= 0,
clf;
hold on;
plot(training_data_losses, 'b');
plot(validation_data_losses, 'r');
legend('training', 'validation');
ylabel('loss');
xlabel('iteration number');
hold off;
end
datas2 = {datas.training, datas.validation, datas.test};
data_names = {'training', 'validation', 'test'};
for data_i = 1:3,
data = datas2{data_i};
data_name = data_names{data_i};
fprintf('\nThe loss on the %s data is %f\n', data_name, loss(model, data, wd_coefficient));
if wd_coefficient~=0,
fprintf('The classification loss (i.e. without weight decay) on the %s data is %f\n', data_name, loss(model, data, 0));
end
fprintf('The classification error rate on the %s data is %f\n', data_name, classification_performance(model, data));
end
end
function test_gradient(model, data, wd_coefficient)
base_theta = model_to_theta(model);
h = 1e-2;
correctness_threshold = 1e-5;
analytic_gradient = model_to_theta(d_loss_by_d_model(model, data, wd_coefficient));
% Test the gradient not for every element of theta, because that's a lot of work. Test for only a few elements.
for i = 1:100,
test_index = mod(i * 1299721, size(base_theta,1)) + 1; % 1299721 is prime and thus ensures a somewhat random-like selection of indices
analytic_here = analytic_gradient(test_index);
theta_step = base_theta * 0;
theta_step(test_index) = h;
contribution_distances = [-4:-1, 1:4];
contribution_weights = [1/280, -4/105, 1/5, -4/5, 4/5, -1/5, 4/105, -1/280];
temp = 0;
for contribution_index = 1:8,
temp = temp + loss(theta_to_model(base_theta + theta_step * contribution_distances(contribution_index)), data, wd_coefficient) * contribution_weights(contribution_index);
end
fd_here = temp / h;
diff = abs(analytic_here - fd_here);
% fprintf('%d %e %e %e %e\n', test_index, base_theta(test_index), diff, fd_here, analytic_here);
if diff < correctness_threshold, continue; end
if diff / (abs(analytic_here) + abs(fd_here)) < correctness_threshold, continue; end
error(sprintf('Theta element #%d, with value %e, has finite difference gradient %e but analytic gradient %e. That looks like an error.\n', test_index, base_theta(test_index), fd_here, analytic_here));
end
fprintf('Gradient test passed. That means that the gradient that your code computed is within 0.001%% of the gradient that the finite difference approximation computed, so the gradient calculation procedure is probably correct (not certainly, but probably).\n');
end
function ret = logistic(input)
ret = 1 ./ (1 + exp(-input));
end
function ret = log_sum_exp_over_rows(a)
% This computes log(sum(exp(a), 1)) in a numerically stable way
maxs_small = max(a, [], 1);
maxs_big = repmat(maxs_small, [size(a, 1), 1]);
ret = log(sum(exp(a - maxs_big), 1)) + maxs_small;
end
function ret = loss(model, data, wd_coefficient)
% model.input_to_hid is a matrix of size <number of hidden units> by <number of inputs i.e. 256>. It contains the weights from the input units to the hidden units.
% model.hid_to_class is a matrix of size <number of classes i.e. 10> by <number of hidden units>. It contains the weights from the hidden units to the softmax units.
% data.inputs is a matrix of size <number of inputs i.e. 256> by <number of data cases>. Each column describes a different data case.
% data.targets is a matrix of size <number of classes i.e. 10> by <number of data cases>. Each column describes a different data case. It contains a one-of-N encoding of the class, i.e. one element in every column is 1 and the others are 0.
% Before we can calculate the loss, we need to calculate a variety of intermediate values, like the state of the hidden units.
hid_input = model.input_to_hid * data.inputs; % input to the hidden units, i.e. before the logistic. size: <number of hidden units> by <number of data cases>
hid_output = logistic(hid_input); % output of the hidden units, i.e. after the logistic. size: <number of hidden units> by <number of data cases>
class_input = model.hid_to_class * hid_output; % input to the components of the softmax. size: <number of classes, i.e. 10> by <number of data cases>
% The following three lines of code implement the softmax.
% However, it's written differently from what the lectures say.
% In the lectures, a softmax is described using an exponential divided by a sum of exponentials.
% What we do here is exactly equivalent (you can check the math or just check it in practice), but this is more numerically stable.
% "Numerically stable" means that this way, there will never be really big numbers involved.
% The exponential in the lectures can lead to really big numbers, which are fine in mathematical equations, but can lead to all sorts of problems in Octave.
% Octave isn't well prepared to deal with really large numbers, like the number 10 to the power 1000. Computations with such numbers get unstable, so we avoid them.
class_normalizer = log_sum_exp_over_rows(class_input); % log(sum(exp of class_input)) is what we subtract to get properly normalized log class probabilities. size: <1> by <number of data cases>
log_class_prob = class_input - repmat(class_normalizer, [size(class_input, 1), 1]); % log of probability of each class. size: <number of classes, i.e. 10> by <number of data cases>
class_prob = exp(log_class_prob); % probability of each class. Each column (i.e. each case) sums to 1. size: <number of classes, i.e. 10> by <number of data cases>
classification_loss = -mean(sum(log_class_prob .* data.targets, 1)); % select the right log class probability using that sum; then take the mean over all data cases.
wd_loss = sum(model_to_theta(model).^2)/2*wd_coefficient; % weight decay loss. very straightforward: E = 1/2 * wd_coeffecient * theta^2
ret = classification_loss + wd_loss;
end
function ret = d_loss_by_d_model(model, data, wd_coefficient)
% model.input_to_hid is a matrix of size <number of hidden units> by <number of inputs i.e. 256>
% model.hid_to_class is a matrix of size <number of classes i.e. 10> by <number of hidden units>
% data.inputs is a matrix of size <number of inputs i.e. 256> by <number of data cases>. Each column describes a different data case.
% data.targets is a matrix of size <number of classes i.e. 10> by <number of data cases>. Each column describes a different data case. It contains a one-of-N encoding of the class, i.e. one element in every column is 1 and the others are 0.
% The returned object is supposed to be exactly like parameter <model>, i.e. it has fields ret.input_to_hid and ret.hid_to_class. However, the contents of those matrices are gradients (d loss by d model parameter), instead of model parameters.
% This is the only function that you're expected to change. Right now, it just returns a lot of zeros, which is obviously not the correct output. Your job is to replace that by a correct computation.
batchsize = size(data.inputs, 2);
hid_input = model.input_to_hid * data.inputs;
hid_output = logistic(hid_input);
class_input = model.hid_to_class * hid_output;
class_normalizer = log_sum_exp_over_rows(class_input); % log(sum(exp of class_input)) is what we subtract to get properly normalized log class probabilities. size: <1> by <number of data cases>
log_class_prob = class_input - repmat(class_normalizer, [size(class_input, 1), 1]); % log of probability of each class. size: <number of classes, i.e. 10> by <number of data cases>
class_prob = exp(log_class_prob); % probability of each class. Each column (i.e. each case) sums to 1. size: <number of classes, i.e. 10> by <number of data cases>
% COMPUTE DERIVATIVE.
error_deriv = class_prob - data.targets; % size: 10 by <number of data cases>
% BACK PROPAGATE.
hid_to_class_weight_gradient = hid_output * error_deriv'; % size: <number of hidden units> by 10
back_propagated_deriv = (model.hid_to_class' * error_deriv) ...
.* hid_output .* (1 - hid_output); % size: <number of hidden units> by <number of data cases>
input_to_hid_weight_gradient = data.inputs * back_propagated_deriv'; % size: 256 by <number of hidden units>
% REGULARIZATION
ret.input_to_hid = model.input_to_hid * wd_coefficient + input_to_hid_weight_gradient' ./ batchsize;
ret.hid_to_class = model.hid_to_class * wd_coefficient + hid_to_class_weight_gradient' ./ batchsize;
end
function ret = model_to_theta(model)
% This function takes a model (or gradient in model form), and turns it into one long vector. See also theta_to_model.
input_to_hid_transpose = transpose(model.input_to_hid);
hid_to_class_transpose = transpose(model.hid_to_class);
ret = [input_to_hid_transpose(:); hid_to_class_transpose(:)];
end
function ret = theta_to_model(theta)
% This function takes a model (or gradient) in the form of one long vector (maybe produced by model_to_theta), and restores it to the structure format, i.e. with fields .input_to_hid and .hid_to_class, both matrices.
n_hid = size(theta, 1) / (256+10);
ret.input_to_hid = transpose(reshape(theta(1: 256*n_hid), 256, n_hid));
ret.hid_to_class = reshape(theta(256 * n_hid + 1 : size(theta,1)), n_hid, 10).';
end
function ret = initial_model(n_hid)
n_params = (256+10) * n_hid;
as_row_vector = cos(0:(n_params-1));
ret = theta_to_model(as_row_vector(:) * 0.1); % We don't use random initialization, for this assignment. This way, everybody will get the same results.
end
function ret = classification_performance(model, data)
% This returns the fraction of data cases that is incorrectly classified by the model.
hid_input = model.input_to_hid * data.inputs; % input to the hidden units, i.e. before the logistic. size: <number of hidden units> by <number of data cases>
hid_output = logistic(hid_input); % output of the hidden units, i.e. after the logistic. size: <number of hidden units> by <number of data cases>
class_input = model.hid_to_class * hid_output; % input to the components of the softmax. size: <number of classes, i.e. 10> by <number of data cases>
[dump, choices] = max(class_input); % choices is integer: the chosen class, plus 1.
[dump, targets] = max(data.targets); % targets is integer: the target class, plus 1.
ret = mean(double(choices ~= targets));
end
|
github
|
kareem1925/coursera-Neural-Networks-for-Machine-Learning-master
|
learn_perceptron.m
|
.m
|
coursera-Neural-Networks-for-Machine-Learning-master/week03/Assignment1/learn_perceptron.m
| 6,061 |
utf_8
|
324d2562f581a7c4f740975df04da068
|
%% Learns the weights of a perceptron and displays the results.
function [w] = learn_perceptron(neg_examples_nobias,pos_examples_nobias,w_init,w_gen_feas)
%%
% Learns the weights of a perceptron for a 2-dimensional dataset and plots
% the perceptron at each iteration where an iteration is defined as one
% full pass through the data. If a generously feasible weight vector
% is provided then the visualization will also show the distance
% of the learned weight vectors to the generously feasible weight vector.
% Required Inputs:
% neg_examples_nobias - The num_neg_examples x 2 matrix for the examples with target 0.
% num_neg_examples is the number of examples for the negative class.
% pos_examples_nobias - The num_pos_examples x 2 matrix for the examples with target 1.
% num_pos_examples is the number of examples for the positive class.
% w_init - A 3-dimensional initial weight vector. The last element is the bias.
% w_gen_feas - A generously feasible weight vector.
% Returns:
% w - The learned weight vector.
%%
%Bookkeeping
num_neg_examples = size(neg_examples_nobias,1);
num_pos_examples = size(pos_examples_nobias,1);
num_err_history = [];
w_dist_history = [];
%Here we add a column of ones to the examples in order to allow us to learn
%bias parameters.
neg_examples = [neg_examples_nobias,ones(num_neg_examples,1)];
pos_examples = [pos_examples_nobias,ones(num_pos_examples,1)];
%If weight vectors have not been provided, initialize them appropriately.
if (~exist('w_init','var') || isempty(w_init))
w = randn(3,1);
else
w = w_init;
end
if (~exist('w_gen_feas','var'))
w_gen_feas = [];
end
%Find the data points that the perceptron has incorrectly classified
%and record the number of errors it makes.
iter = 0;
[mistakes0, mistakes1] = eval_perceptron(neg_examples,pos_examples,w);
num_errs = size(mistakes0,1) + size(mistakes1,1);
num_err_history(end+1) = num_errs;
fprintf('Number of errors in iteration %d:\t%d\n',iter,num_errs);
fprintf(['weights:\t', mat2str(w), '\n']);
plot_perceptron(neg_examples, pos_examples, mistakes0, mistakes1, num_err_history, w, w_dist_history);
key = input('<Press enter to continue, q to quit.>', 's');
if (key == 'q')
return;
end
%If a generously feasible weight vector exists, record the distance
%to it from the initial weight vector.
if (length(w_gen_feas) ~= 0)
w_dist_history(end+1) = norm(w - w_gen_feas);
end
%Iterate until the perceptron has correctly classified all points.
while (num_errs > 0)
iter = iter + 1;
%Update the weights of the perceptron.
w = update_weights(neg_examples,pos_examples,w);
%If a generously feasible weight vector exists, record the distance
%to it from the current weight vector.
if (length(w_gen_feas) ~= 0)
w_dist_history(end+1) = norm(w - w_gen_feas);
end
%Find the data points that the perceptron has incorrectly classified.
%and record the number of errors it makes.
[mistakes0, mistakes1] = eval_perceptron(neg_examples,pos_examples,w);
num_errs = size(mistakes0,1) + size(mistakes1,1);
num_err_history(end+1) = num_errs;
fprintf('Number of errors in iteration %d:\t%d\n',iter,num_errs);
fprintf(['weights:\t', mat2str(w), '\n']);
plot_perceptron(neg_examples, pos_examples, mistakes0, mistakes1, num_err_history, w, w_dist_history);
key = input('<Press enter to continue, q to quit.>', 's');
if (key == 'q')
break;
end
end
%WRITE THE CODE TO COMPLETE THIS FUNCTION
function [w] = update_weights(neg_examples, pos_examples, w_current)
%%
% Updates the weights of the perceptron for incorrectly classified points
% using the perceptron update algorithm. This function makes one sweep
% over the dataset.
% Inputs:
% neg_examples - The num_neg_examples x 3 matrix for the examples with target 0.
% num_neg_examples is the number of examples for the negative class.
% pos_examples- The num_pos_examples x 3 matrix for the examples with target 1.
% num_pos_examples is the number of examples for the positive class.
% w_current - A 3-dimensional weight vector, the last element is the bias.
% Returns:
% w - The weight vector after one pass through the dataset using the perceptron
% learning rule.
%%
w = w_current;
num_neg_examples = size(neg_examples,1);
num_pos_examples = size(pos_examples,1);
for i=1:num_neg_examples
this_case = neg_examples(i,:);
x = this_case'; %Hint
activation = this_case*w;
if (activation >= 0)
%YOUR CODE HERE
w -= x
end
end
for i=1:num_pos_examples
this_case = pos_examples(i,:);
x = this_case';
activation = this_case*w;
if (activation < 0)
%YOUR CODE HERE
w += x
end
end
function [mistakes0, mistakes1] = eval_perceptron(neg_examples, pos_examples, w)
%%
% Evaluates the perceptron using a given weight vector. Here, evaluation
% refers to finding the data points that the perceptron incorrectly classifies.
% Inputs:
% neg_examples - The num_neg_examples x 3 matrix for the examples with target 0.
% num_neg_examples is the number of examples for the negative class.
% pos_examples- The num_pos_examples x 3 matrix for the examples with target 1.
% num_pos_examples is the number of examples for the positive class.
% w - A 3-dimensional weight vector, the last element is the bias.
% Returns:
% mistakes0 - A vector containing the indices of the negative examples that have been
% incorrectly classified as positive.
% mistakes0 - A vector containing the indices of the positive examples that have been
% incorrectly classified as negative.
%%
num_neg_examples = size(neg_examples,1);
num_pos_examples = size(pos_examples,1);
mistakes0 = [];
mistakes1 = [];
for i=1:num_neg_examples
x = neg_examples(i,:)';
activation = x'*w;
if (activation >= 0)
mistakes0 = [mistakes0;i];
end
end
for i=1:num_pos_examples
x = pos_examples(i,:)';
activation = x'*w;
if (activation < 0)
mistakes1 = [mistakes1;i];
end
end
|
github
|
kareem1925/coursera-Neural-Networks-for-Machine-Learning-master
|
plot_perceptron.m
|
.m
|
coursera-Neural-Networks-for-Machine-Learning-master/week03/Assignment1/plot_perceptron.m
| 3,409 |
utf_8
|
808099ac46c6f636fa74de07abbcc8bb
|
%% Plots information about a perceptron classifier on a 2-dimensional dataset.
function plot_perceptron(neg_examples, pos_examples, mistakes0, mistakes1, num_err_history, w, w_dist_history)
%%
% The top-left plot shows the dataset and the classification boundary given by
% the weights of the perceptron. The negative examples are shown as circles
% while the positive examples are shown as squares. If an example is colored
% green then it means that the example has been correctly classified by the
% provided weights. If it is colored red then it has been incorrectly classified.
% The top-right plot shows the number of mistakes the perceptron algorithm has
% made in each iteration so far.
% The bottom-left plot shows the distance to some generously feasible weight
% vector if one has been provided (note, there can be an infinite number of these).
% Points that the classifier has made a mistake on are shown in red,
% while points that are correctly classified are shown in green.
% The goal is for all of the points to be green (if it is possible to do so).
% Inputs:
% neg_examples - The num_neg_examples x 3 matrix for the examples with target 0.
% num_neg_examples is the number of examples for the negative class.
% pos_examples- The num_pos_examples x 3 matrix for the examples with target 1.
% num_pos_examples is the number of examples for the positive class.
% mistakes0 - A vector containing the indices of the datapoints from class 0 incorrectly
% classified by the perceptron. This is a subset of neg_examples.
% mistakes1 - A vector containing the indices of the datapoints from class 1 incorrectly
% classified by the perceptron. This is a subset of pos_examples.
% num_err_history - A vector containing the number of mistakes for each
% iteration of learning so far.
% w - A 3-dimensional vector corresponding to the current weights of the
% perceptron. The last element is the bias.
% w_dist_history - A vector containing the L2-distance to a generously
% feasible weight vector for each iteration of learning so far.
% Empty if one has not been provided.
%%
f = figure(1);
clf(f);
neg_correct_ind = setdiff(1:size(neg_examples,1),mistakes0);
pos_correct_ind = setdiff(1:size(pos_examples,1),mistakes1);
subplot(2,2,1);
hold on;
if (~isempty(neg_examples))
plot(neg_examples(neg_correct_ind,1),neg_examples(neg_correct_ind,2),'og','markersize',20);
end
if (~isempty(pos_examples))
plot(pos_examples(pos_correct_ind,1),pos_examples(pos_correct_ind,2),'sg','markersize',20);
end
if (size(mistakes0,1) > 0)
plot(neg_examples(mistakes0,1),neg_examples(mistakes0,2),'or','markersize',20);
end
if (size(mistakes1,1) > 0)
plot(pos_examples(mistakes1,1),pos_examples(mistakes1,2),'sr','markersize',20);
end
title('Classifier');
%In order to plot the decision line, we just need to get two points.
plot([-5,5],[(-w(end)+5*w(1))/w(2),(-w(end)-5*w(1))/w(2)],'k')
xlim([-1,1]);
ylim([-1,1]);
hold off;
subplot(2,2,2);
plot(0:length(num_err_history)-1,num_err_history);
xlim([-1,max(15,length(num_err_history))]);
ylim([0,size(neg_examples,1)+size(pos_examples,1)+1]);
title('Number of errors');
xlabel('Iteration');
ylabel('Number of errors');
subplot(2,2,3);
plot(0:length(w_dist_history)-1,w_dist_history);
xlim([-1,max(15,length(num_err_history))]);
ylim([0,15]);
title('Distance')
xlabel('Iteration');
ylabel('Distance');
|
github
|
kwstat/nipals-main
|
empca_w.m
|
.m
|
nipals-main/old/mathworks/empca_w.m
| 4,645 |
utf_8
|
9a790ceff1d06189c3da4e99576ea16f
|
% use this file
function [u, s, v, a] = empca_w(a, w, ncomp, emtol, maxiters)
%EMPCA Expectation-Maximization Principal Component Analysis
% [U, S, V] = EMPCA(A,W,N) calculates N principal components of matrix A,
% using weight matrix W.
% Returns U, S, V that approximate the N-rank truncation of the singular
% value decomposition of A. S is a diagonal matrix with singular values
% corresponding to the contribution of each principal component to matrix
% A. U and V have orthonormal columns. Matrix A is interpreted as a 2D
% array. A can be a full or sparse matrix of class 'single', 'double', or
% 'gpuArray'. N must be a positive integer, and is reduced to the minimum
% dimension of A if higher.
%
% [U, S, V, E] = EMPCA(A,W,N) also returns the residual error matrix E
% resulting from the PCA decomposition, such that A == U*S*V' + E.
%
% [...] = EMPCA(A,W) calculates all the components.
%
% [...] = EMPCA(A,W,N,TOL) keeps principal components when changes in U
% during the last EM iteration are smaller than TOL, instead of the
% default value of 1e-6. TOL must be a scalar.
%
% [...] = EMPCA(A,W,N,TOL,MAXITER) keeps principal components after MAXITER
% EM iterations if convergence has not been reached. If omitted, a
% maximum of 100 EM iterations are computed. MAXITER must be a positive
% integer.
%
% This function implements the expectation maximization principal
% component analysis algorithm by Stephen Bailey, available in
% http://arxiv.org/pdf/1208.4122v2.pdf
% Bailey, Stephen. "Principal Component Analysis with Noisy and/or
% Missing Data." Publications of the Astronomical Society of the Pacific
% 124.919 (2012): 1015-1023.
% regarding empca paper notation:
% phi : u
% c : C
% ------------------
B1 = [50 67 90 98 120;
55 71 93 102 129;
65 76 95 105 134;
50 80 102 130 138;
60 82 97 135 151;
65 89 106 137 153;
75 95 117 133 155];
B1wt = [1 1 1 1 1;
1 1 1 1 1;
1 1 1 1 1 ;
1 1 1 1 1 ;
1 1 1 1 1 ;
1 1 1 1 1 ;
1 1 1 1 1 ];
% In B2, the first two elements of the first column are really NA,
% but the code will set the values to 0 and then use 0 weight
B2 = [0 67 90 98 120;
0 71 93 102 129;
65 76 95 105 134;
50 80 102 130 138;
60 82 97 135 151;
65 89 106 137 153;
75 95 117 133 155];
B2wt = [0 1 1 1 1;
0 1 1 1 1;
1 1 1 1 1 ;
1 1 1 1 1 ;
1 1 1 1 1 ;
1 1 1 1 1 ;
1 1 1 1 1 ];
% -----------------------------
X = B2
W = B2wt
ncomp = 4;
% column-centered & scaled
X = bsxfun(@minus, X, mean(X));
X = bsxfun(@rdivide, X, std(X))
%% parameters to determine when an eigenvector is found:
emtol = 1e-12; % max change in absolute eigenvector difference between EM iterations
maxiters = 100; % or when maxiters is reached, whatever first
emtol = max(emtol,eps(class(X))); % make sure emtol is not below eps
%X = reshape(X,size(X,1),[]); % force it to be 2D
if ~exist('ncomp','var')
ncomp = min(size(X)); % set to max rank if not specified
else
warning 'ncomp reduced to max rank'
ncomp = min(ncomp,min(size(X))); % reduce if higher than maximum possible rank
end
% allocate space for results
P = @zeros(size(X,1),ncomp,class(X));
C = @zeros(size(X,2),ncomp,class(X));
% macrp tp return normalized columns
normc = @(m)bsxfun(@rdivide,m,sqrt(sum(m.^2)));
%W = ~isnan(X);
%X(~W) = 0;
%% empca
for comp = 1:ncomp
% random direction vector
P(:,comp) = normc(@randn([size(X,1) 1],class(X)));
for iter = 1:maxiters % repeat until u does not change
P0 = P(:,comp); % store previous u for comparison
% E step
C(:,comp) = X' * P(:,comp);
% M-step with weights. Bailey eqn 21. sum(,2)= rowsums
% .* is element-wise
% column C[,h] times each column of t(W)
CW = bsxfun(@times, C(:,comp) , W');
P(:,comp) = sum(X .* CW',2) ./ (CW' * C(:,comp));
P(:,comp) = normc(P(:,comp));
if max(abs(P0-P(:,comp))) <= emtol
break
end
end
disp(['comp ' num2str(comp) ' kept after ' num2str(iter) ' iterations'])
X = X - P(:,comp) * C(:,comp)'; % deflate X = X - P*C'
X(~W) = 0;
disp("test")
end
% restore missing values
% X(~W) = NaN;
s2 = diag(sum(C.^2));
v = normc(C);
disp("-----------------------------");
output_precision(2)
disp ("Value of P (scores)"), disp (eval(mat2str(P,3)));
disp("s2"), disp(s2);
disp("v (loadings)"), disp(v);
disp("Value of C"), disp(C);
disp("P'P"), disp(round(P'*P)) % check U is orthonormal
|
github
|
hongzhenwang/RRPN-revise-master
|
classification_demo.m
|
.m
|
RRPN-revise-master/caffe-fast-rcnn/matlab/demo/classification_demo.m
| 5,412 |
utf_8
|
8f46deabe6cde287c4759f3bc8b7f819
|
function [scores, maxlabel] = classification_demo(im, use_gpu)
% [scores, maxlabel] = classification_demo(im, use_gpu)
%
% Image classification demo using BVLC CaffeNet.
%
% IMPORTANT: before you run this demo, you should download BVLC CaffeNet
% from Model Zoo (http://caffe.berkeleyvision.org/model_zoo.html)
%
% ****************************************************************************
% For detailed documentation and usage on Caffe's Matlab interface, please
% refer to Caffe Interface Tutorial at
% http://caffe.berkeleyvision.org/tutorial/interfaces.html#matlab
% ****************************************************************************
%
% input
% im color image as uint8 HxWx3
% use_gpu 1 to use the GPU, 0 to use the CPU
%
% output
% scores 1000-dimensional ILSVRC score vector
% maxlabel the label of the highest score
%
% You may need to do the following before you start matlab:
% $ export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:/usr/local/cuda-5.5/lib64
% $ export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
% Or the equivalent based on where things are installed on your system
%
% Usage:
% im = imread('../../examples/images/cat.jpg');
% scores = classification_demo(im, 1);
% [score, class] = max(scores);
% Five things to be aware of:
% caffe uses row-major order
% matlab uses column-major order
% caffe uses BGR color channel order
% matlab uses RGB color channel order
% images need to have the data mean subtracted
% Data coming in from matlab needs to be in the order
% [width, height, channels, images]
% where width is the fastest dimension.
% Here is the rough matlab for putting image data into the correct
% format in W x H x C with BGR channels:
% % permute channels from RGB to BGR
% im_data = im(:, :, [3, 2, 1]);
% % flip width and height to make width the fastest dimension
% im_data = permute(im_data, [2, 1, 3]);
% % convert from uint8 to single
% im_data = single(im_data);
% % reshape to a fixed size (e.g., 227x227).
% im_data = imresize(im_data, [IMAGE_DIM IMAGE_DIM], 'bilinear');
% % subtract mean_data (already in W x H x C with BGR channels)
% im_data = im_data - mean_data;
% If you have multiple images, cat them with cat(4, ...)
% Add caffe/matlab to you Matlab search PATH to use matcaffe
if exist('../+caffe', 'dir')
addpath('..');
else
error('Please run this demo from caffe/matlab/demo');
end
% Set caffe mode
if exist('use_gpu', 'var') && use_gpu
caffe.set_mode_gpu();
gpu_id = 0; % we will use the first gpu in this demo
caffe.set_device(gpu_id);
else
caffe.set_mode_cpu();
end
% Initialize the network using BVLC CaffeNet for image classification
% Weights (parameter) file needs to be downloaded from Model Zoo.
model_dir = '../../models/bvlc_reference_caffenet/';
net_model = [model_dir 'deploy.prototxt'];
net_weights = [model_dir 'bvlc_reference_caffenet.caffemodel'];
phase = 'test'; % run with phase test (so that dropout isn't applied)
if ~exist(net_weights, 'file')
error('Please download CaffeNet from Model Zoo before you run this demo');
end
% Initialize a network
net = caffe.Net(net_model, net_weights, phase);
if nargin < 1
% For demo purposes we will use the cat image
fprintf('using caffe/examples/images/cat.jpg as input image\n');
im = imread('../../examples/images/cat.jpg');
end
% prepare oversampled input
% input_data is Height x Width x Channel x Num
tic;
input_data = {prepare_image(im)};
toc;
% do forward pass to get scores
% scores are now Channels x Num, where Channels == 1000
tic;
% The net forward function. It takes in a cell array of N-D arrays
% (where N == 4 here) containing data of input blob(s) and outputs a cell
% array containing data from output blob(s)
scores = net.forward(input_data);
toc;
scores = scores{1};
scores = mean(scores, 2); % take average scores over 10 crops
[~, maxlabel] = max(scores);
% call caffe.reset_all() to reset caffe
caffe.reset_all();
% ------------------------------------------------------------------------
function crops_data = prepare_image(im)
% ------------------------------------------------------------------------
% caffe/matlab/+caffe/imagenet/ilsvrc_2012_mean.mat contains mean_data that
% is already in W x H x C with BGR channels
d = load('../+caffe/imagenet/ilsvrc_2012_mean.mat');
mean_data = d.mean_data;
IMAGE_DIM = 256;
CROPPED_DIM = 227;
% Convert an image returned by Matlab's imread to im_data in caffe's data
% format: W x H x C with BGR channels
im_data = im(:, :, [3, 2, 1]); % permute channels from RGB to BGR
im_data = permute(im_data, [2, 1, 3]); % flip width and height
im_data = single(im_data); % convert from uint8 to single
im_data = imresize(im_data, [IMAGE_DIM IMAGE_DIM], 'bilinear'); % resize im_data
im_data = im_data - mean_data; % subtract mean_data (already in W x H x C, BGR)
% oversample (4 corners, center, and their x-axis flips)
crops_data = zeros(CROPPED_DIM, CROPPED_DIM, 3, 10, 'single');
indices = [0 IMAGE_DIM-CROPPED_DIM] + 1;
n = 1;
for i = indices
for j = indices
crops_data(:, :, :, n) = im_data(i:i+CROPPED_DIM-1, j:j+CROPPED_DIM-1, :);
crops_data(:, :, :, n+5) = crops_data(end:-1:1, :, :, n);
n = n + 1;
end
end
center = floor(indices(2) / 2) + 1;
crops_data(:,:,:,5) = ...
im_data(center:center+CROPPED_DIM-1,center:center+CROPPED_DIM-1,:);
crops_data(:,:,:,10) = crops_data(end:-1:1, :, :, 5);
|
github
|
hongzhenwang/RRPN-revise-master
|
voc_eval.m
|
.m
|
RRPN-revise-master/lib/datasets/VOCdevkit-matlab-wrapper/voc_eval.m
| 1,332 |
utf_8
|
3ee1d5373b091ae4ab79d26ab657c962
|
function res = voc_eval(path, comp_id, test_set, output_dir)
VOCopts = get_voc_opts(path);
VOCopts.testset = test_set;
for i = 1:length(VOCopts.classes)
cls = VOCopts.classes{i};
res(i) = voc_eval_cls(cls, VOCopts, comp_id, output_dir);
end
fprintf('\n~~~~~~~~~~~~~~~~~~~~\n');
fprintf('Results:\n');
aps = [res(:).ap]';
fprintf('%.1f\n', aps * 100);
fprintf('%.1f\n', mean(aps) * 100);
fprintf('~~~~~~~~~~~~~~~~~~~~\n');
function res = voc_eval_cls(cls, VOCopts, comp_id, output_dir)
test_set = VOCopts.testset;
year = VOCopts.dataset(4:end);
addpath(fullfile(VOCopts.datadir, 'VOCcode'));
res_fn = sprintf(VOCopts.detrespath, comp_id, cls);
recall = [];
prec = [];
ap = 0;
ap_auc = 0;
do_eval = (str2num(year) <= 2007) | ~strcmp(test_set, 'test');
if do_eval
% Bug in VOCevaldet requires that tic has been called first
tic;
[recall, prec, ap] = VOCevaldet(VOCopts, comp_id, cls, true);
ap_auc = xVOCap(recall, prec);
% force plot limits
ylim([0 1]);
xlim([0 1]);
print(gcf, '-djpeg', '-r0', ...
[output_dir '/' cls '_pr.jpg']);
end
fprintf('!!! %s : %.4f %.4f\n', cls, ap, ap_auc);
res.recall = recall;
res.prec = prec;
res.ap = ap;
res.ap_auc = ap_auc;
save([output_dir '/' cls '_pr.mat'], ...
'res', 'recall', 'prec', 'ap', 'ap_auc');
rmpath(fullfile(VOCopts.datadir, 'VOCcode'));
|
github
|
he010103/CFWCR-master
|
CFWCR_VOT_CPU.m
|
.m
|
CFWCR-master/vot2017_trax/CFWCR_VOT_CPU.m
| 43,818 |
utf_8
|
db95c9ee695c163e60cc186dafe33b36
|
function CFWCR_VOT_CPU()
% *************************************************************
% VOT: Always call exit command at the end to terminate Matlab!
% *************************************************************
cleanup = onCleanup(@() exit() );
% *************************************************************
% VOT: Set random seed to a different value every time.
% *************************************************************
RandStream.setGlobalStream(RandStream('mt19937ar', 'Seed', sum(clock)));
% *************************************************************
% VOT: init the resources
% *************************************************************
[wrapper_path, name, ext] = fileparts(mfilename('fullpath'));
addpath(wrapper_path);
cd_ind = strfind(wrapper_path, filesep());
repo_path = wrapper_path(1:cd_ind(end)-1);
addpath(repo_path);
setup_paths();
vl_setupnn();
% **********************************
% VOT: Get initialization data
% **********************************
[handle, image, region] = vot('polygon');
% Initialize the tracker
disp(image);
bb_scale = 1;
% If the provided region is a polygon ...
if numel(region) > 4
% Init with an axis aligned bounding box with correct area and center
% coordinate
cx = mean(region(1:2:end));
cy = mean(region(2:2:end));
x1 = min(region(1:2:end));
x2 = max(region(1:2:end));
y1 = min(region(2:2:end));
y2 = max(region(2:2:end));
A1 = norm(region(1:2) - region(3:4)) * norm(region(3:4) - region(5:6));
A2 = (x2 - x1) * (y2 - y1);
s = sqrt(A1/A2);
w = s * (x2 - x1) + 1;
h = s * (y2 - y1) + 1;
else
cx = region(1) + (region(3) - 1)/2;
cy = region(2) + (region(4) - 1)/2;
w = region(3);
h = region(4);
end
init_c = [cx cy];
init_sz = bb_scale * [w h];
im_size = size(imread(image));
im_size = im_size([2 1]);
init_pos = min(max(round(init_c - (init_sz - 1)/2), [1 1]), im_size);
init_sz = min(max(round(init_sz), [1 1]), im_size - init_pos + 1);
region = [init_pos, init_sz];
frame = 1
% **********************************
% VOT: ECO init
% **********************************
params = init_param(region);
max_train_samples = params.nSamples;
features = params.t_features;
% Set some default parameters
params = init_default_params(params);
if isfield(params, 't_global')
global_fparams = params.t_global;
else
global_fparams = [];
end
% Init sequence data
pos = params.init_pos(:)';
target_sz = params.init_sz(:)';
init_target_sz = target_sz;
% Check if color image
im = imread(image);
if size(im,3) == 3
if all(all(im(:,:,1) == im(:,:,2)))
is_color_image = false;
else
is_color_image = true;
end
else
is_color_image = false;
end
if size(im,3) > 1 && is_color_image == false
im = im(:,:,1);
end
params.use_mexResize = false;
global_fparams.use_mexResize = false;
% Calculate search area and initial scale factor
search_area = prod(init_target_sz * params.search_area_scale);
if search_area > params.max_image_sample_size
currentScaleFactor = sqrt(search_area / params.max_image_sample_size);
elseif search_area < params.min_image_sample_size
currentScaleFactor = sqrt(search_area / params.min_image_sample_size);
else
currentScaleFactor = 1.0;
end
% target size at the initial scale
base_target_sz = target_sz / currentScaleFactor;
% window size, taking padding into account
switch params.search_area_shape
case 'proportional'
img_sample_sz = floor( base_target_sz * params.search_area_scale); % proportional area, same aspect ratio as the target
case 'square'
img_sample_sz = repmat(sqrt(prod(base_target_sz * params.search_area_scale)), 1, 2); % square area, ignores the target aspect ratio
case 'fix_padding'
img_sample_sz = base_target_sz + sqrt(prod(base_target_sz * params.search_area_scale) + (base_target_sz(1) - base_target_sz(2))/4) - sum(base_target_sz)/2; % const padding
case 'custom'
img_sample_sz = [base_target_sz(1)*2 base_target_sz(2)*2]; % for testing
end
[features, global_fparams, feature_info] = init_features(features, global_fparams, is_color_image, img_sample_sz, 'odd_cells');
% Set feature info
img_support_sz = feature_info.img_support_sz;
feature_sz = feature_info.data_sz;
feature_dim = feature_info.dim;
num_feature_blocks = length(feature_dim);
feature_reg = permute(num2cell(feature_info.penalty), [2 3 1]);
% Get feature specific parameters
feature_params = init_feature_params(features, feature_info);
feature_extract_info = get_feature_extract_info(features);
if params.use_projection_matrix
compressed_dim = feature_params.compressed_dim;
else
compressed_dim = feature_dim;
end
compressed_dim_cell = permute(num2cell(compressed_dim), [2 3 1]);
% Size of the extracted feature maps
feature_sz_cell = permute(mat2cell(feature_sz, ones(1,num_feature_blocks), 2), [2 3 1]);
% Number of Fourier coefficients to save for each filter layer. This will
% be an odd number.
filter_sz = feature_sz + mod(feature_sz+1, 2);
filter_sz_cell = permute(mat2cell(filter_sz, ones(1,num_feature_blocks), 2), [2 3 1]);
% The size of the label function DFT. Equal to the maximum filter size.
output_sz = max(filter_sz, [], 1);
% How much each feature block has to be padded to the obtain output_sz
pad_sz = cellfun(@(filter_sz) (output_sz - filter_sz) / 2, filter_sz_cell, 'uniformoutput', false);
% Compute the Fourier series indices and their transposes
ky = cellfun(@(sz) (-ceil((sz(1) - 1)/2) : floor((sz(1) - 1)/2))', filter_sz_cell, 'uniformoutput', false);
kx = cellfun(@(sz) -ceil((sz(2) - 1)/2) : 0, filter_sz_cell, 'uniformoutput', false);
% construct the Gaussian label function using Poisson formula
sig_y = sqrt(prod(floor(base_target_sz))) * params.output_sigma_factor * (output_sz ./ img_support_sz);
yf_y = cellfun(@(ky) single(sqrt(2*pi) * sig_y(1) / output_sz(1) * exp(-2 * (pi * sig_y(1) * ky / output_sz(1)).^2)), ky, 'uniformoutput', false);
yf_x = cellfun(@(kx) single(sqrt(2*pi) * sig_y(2) / output_sz(2) * exp(-2 * (pi * sig_y(2) * kx / output_sz(2)).^2)), kx, 'uniformoutput', false);
yf = cellfun(@(yf_y, yf_x) yf_y * yf_x, yf_y, yf_x, 'uniformoutput', false);
% construct cosine window
cos_window = cellfun(@(sz) single(hann(sz(1)+2)*hann(sz(2)+2)'), feature_sz_cell, 'uniformoutput', false);
cos_window = cellfun(@(cos_window) cos_window(2:end-1,2:end-1), cos_window, 'uniformoutput', false);
% Compute Fourier series of interpolation function
[interp1_fs, interp2_fs] = cellfun(@(sz) get_interp_fourier(sz, params), filter_sz_cell, 'uniformoutput', false);
% Get the reg_window_edge parameter
reg_window_edge = {};
for k = 1:length(features)
if isfield(features{k}.fparams, 'reg_window_edge')
reg_window_edge = cat(3, reg_window_edge, permute(num2cell(features{k}.fparams.reg_window_edge(:)), [2 3 1]));
else
reg_window_edge = cat(3, reg_window_edge, cell(1, 1, length(features{k}.fparams.nDim)));
end
end
% Construct spatial regularization filter
reg_filter = cellfun(@(reg_window_edge) get_reg_filter(img_support_sz, base_target_sz, params, reg_window_edge), reg_window_edge, 'uniformoutput', false);
% Compute the energy of the filter (used for preconditioner)
reg_energy = cellfun(@(reg_filter) real(reg_filter(:)' * reg_filter(:)), reg_filter, 'uniformoutput', false);
if params.use_scale_filter
[nScales, scale_step, scaleFactors, scale_filter, params] = init_scale_filter(params);
else
% Use the translation filter to estimate the scale.
nScales = params.number_of_scales;
scale_step = params.scale_step;
scale_exp = (-floor((nScales-1)/2):ceil((nScales-1)/2));
scaleFactors = scale_step .^ scale_exp;
end
if nScales > 0
%force reasonable scale changes
min_scale_factor = scale_step ^ ceil(log(max(5 ./ img_support_sz)) / log(scale_step));
max_scale_factor = scale_step ^ floor(log(min([size(im,1) size(im,2)] ./ base_target_sz)) / log(scale_step));
end
% Set conjugate gradient uptions
init_CG_opts.CG_use_FR = true;
init_CG_opts.tol = 1e-6;
init_CG_opts.CG_standard_alpha = true;
init_CG_opts.debug = 0;
CG_opts.CG_use_FR = params.CG_use_FR;
CG_opts.tol = 1e-6;
CG_opts.CG_standard_alpha = params.CG_standard_alpha;
CG_opts.debug = 0;
time = 0;
% Initialize and allocate
prior_weights = zeros(max_train_samples,1, 'single');
sample_weights = prior_weights;
samplesf = cell(1, 1, num_feature_blocks);
for k = 1:num_feature_blocks
samplesf{k} = complex(zeros(max_train_samples,compressed_dim(k),filter_sz(k,1),(filter_sz(k,2)+1)/2,'single'));
end
score_matrix = inf(max_train_samples, 'single');
latest_ind = [];
frames_since_last_train = inf;
num_training_samples = 0;
minimum_sample_weight = params.learning_rate*(1-params.learning_rate)^(2*max_train_samples);
res_norms = [];
residuals_pcg = [];
if frame == 1
% Extract image region for training sample
sample_pos = round(pos);
sample_scale = currentScaleFactor;
xl = extract_features(im, sample_pos, currentScaleFactor, features, global_fparams, feature_extract_info);
% Do windowing of features
xlw = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xl, cos_window, 'uniformoutput', false);
% Compute the fourier series
xlf = cellfun(@cfft2, xlw, 'uniformoutput', false);
% Interpolate features to the continuous domain
xlf = interpolate_dft(xlf, interp1_fs, interp2_fs);
% New sample to be added
xlf = compact_fourier_coeff(xlf);
% Initialize projection matrix
xl1 = cellfun(@(x) reshape(x, [], size(x,3)), xl, 'uniformoutput', false);
xl1 = cellfun(@(x) bsxfun(@minus, x, mean(x, 1)), xl1, 'uniformoutput', false);
if strcmpi(params.proj_init_method, 'pca')
[projection_matrix, ~, ~] = cellfun(@(x) svd(x' * x), xl1, 'uniformoutput', false);
projection_matrix = cellfun(@(P, dim) single(P(:,1:dim)), projection_matrix, compressed_dim_cell, 'uniformoutput', false);
elseif strcmpi(params.proj_init_method, 'rand_uni')
projection_matrix = cellfun(@(x, dim) single(randn(size(x,2), dim)), xl1, compressed_dim_cell, 'uniformoutput', false);
projection_matrix = cellfun(@(P) bsxfun(@rdivide, P, sqrt(sum(P.^2,1))), projection_matrix, 'uniformoutput', false);
elseif strcmpi(params.proj_init_method, 'none')
projection_matrix = [];
else
error('Unknown initialization method for the projection matrix: %s', params.proj_init_method);
end
clear xl1 xlw
% Shift sample
shift_samp = 2*pi * (pos - sample_pos) ./ (sample_scale * img_support_sz);
xlf = shift_sample(xlf, shift_samp, kx, ky);
% Project sample
xlf_proj = project_sample(xlf, projection_matrix);
elseif params.learning_rate > 0
if ~params.use_detection_sample
% Extract image region for training sample
sample_pos = round(pos);
sample_scale = currentScaleFactor;
xl = extract_features(im, sample_pos, currentScaleFactor, features, global_fparams, feature_extract_info);
% Project sample
xl_proj = project_sample(xl, projection_matrix);
% Do windowing of features
xl_proj = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xl_proj, cos_window, 'uniformoutput', false);
% Compute the fourier series
xlf1_proj = cellfun(@cfft2, xl_proj, 'uniformoutput', false);
% Interpolate features to the continuous domain
xlf1_proj = interpolate_dft(xlf1_proj, interp1_fs, interp2_fs);
% New sample to be added
xlf_proj = compact_fourier_coeff(xlf1_proj);
else
% Use the sample that was used for detection
sample_scale = sample_scale(scale_ind);
xlf_proj = cellfun(@(xf) xf(:,1:(size(xf,2)+1)/2,:,scale_ind), xtf_proj, 'uniformoutput', false);
end
% Shift the sample so that the target is centered
shift_samp = 2*pi * (pos - sample_pos) ./ (sample_scale * img_support_sz);
xlf_proj = shift_sample(xlf_proj, shift_samp, kx, ky);
end
xlf_proj_perm = cellfun(@(xf) permute(xf, [4 3 1 2]), xlf_proj, 'uniformoutput', false);
if params.use_sample_merge
% Find the distances with existing samples
dist_vector = find_cluster_distances(samplesf, xlf_proj_perm, num_feature_blocks, num_training_samples, max_train_samples, params);
[merged_sample, new_cluster, merged_cluster_id, new_cluster_id, score_matrix, prior_weights,num_training_samples] = ...
merge_clusters(samplesf, xlf_proj_perm, dist_vector, score_matrix, prior_weights,...
num_training_samples,num_feature_blocks,max_train_samples,minimum_sample_weight,params);
else
% Do the traditional adding of a training sample and weight update
% of C-COT
[prior_weights, replace_ind] = update_prior_weights(prior_weights, sample_weights, latest_ind, frame, params);
latest_ind = replace_ind;
merged_cluster_id = 0;
new_cluster = xlf_proj_perm;
new_cluster_id = replace_ind;
end
if frame > 1 && params.learning_rate > 0 || frame == 1 && ~params.update_projection_matrix
% Insert the new training sample
for k = 1:num_feature_blocks
if merged_cluster_id > 0
samplesf{k}(merged_cluster_id,:,:,:) = merged_sample{k};
end
if new_cluster_id > 0
samplesf{k}(new_cluster_id,:,:,:) = new_cluster{k};
end
end
end
sample_weights = prior_weights;
train_tracker = (frame < params.skip_after_frame) || (frames_since_last_train >= params.train_gap);
if train_tracker
% Used for preconditioning
new_sample_energy = cellfun(@(xlf) abs(xlf .* conj(xlf)), xlf_proj, 'uniformoutput', false);
if frame == 1
if params.update_projection_matrix
hf = cell(2,1,num_feature_blocks);
lf_ind = cellfun(@(sz) sz(1) * (sz(2)-1)/2 + 1, filter_sz_cell, 'uniformoutput', false);
proj_energy = cellfun(@(P, yf) 2*sum(abs(yf(:)).^2) / sum(feature_dim) * ones(size(P), 'single'), projection_matrix, yf, 'uniformoutput', false);
else
hf = cell(1,1,num_feature_blocks);
end
% Initialize the filter
for k = 1:num_feature_blocks
hf{1,1,k} = complex(zeros([filter_sz(k,1) (filter_sz(k,2)+1)/2 compressed_dim(k)], 'single'));
end
% Initialize Conjugate Gradient parameters
CG_opts.maxit = params.init_CG_iter; % Number of initial iterations if projection matrix is not updated
init_CG_opts.maxit = ceil(params.init_CG_iter / params.init_GN_iter);
sample_energy = new_sample_energy;
rhs_samplef = cell(size(hf));
diag_M = cell(size(hf));
p = []; rho = []; r_old = [];
else
CG_opts.maxit = params.CG_iter;
if params.CG_forgetting_rate == inf || params.learning_rate >= 1
% CG will be reset
p = []; rho = []; r_old = [];
else
rho = rho / (1-params.learning_rate)^params.CG_forgetting_rate;
end
% Update the approximate average sample energy using the learning
% rate. This is only used to construct the preconditioner.
sample_energy = cellfun(@(se, nse) (1 - params.learning_rate) * se + params.learning_rate * nse, sample_energy, new_sample_energy, 'uniformoutput', false);
end
% Do training
if frame == 1 && params.update_projection_matrix
% Initial Gauss-Newton optimization of the filter and
% projection matrix.
% Construct stuff for the proj matrix part
init_samplef = cellfun(@(x) permute(x, [4 3 1 2]), xlf, 'uniformoutput', false);
init_samplef_H = cellfun(@(X) conj(reshape(X, size(X,2), [])), init_samplef, 'uniformoutput', false);
% Construct preconditioner
diag_M(1,1,:) = cellfun(@(m, reg_energy) (1-params.precond_reg_param) * bsxfun(@plus, params.precond_data_param * m, (1-params.precond_data_param) * mean(m,3)) + params.precond_reg_param*reg_energy, sample_energy, reg_energy, 'uniformoutput',false);
diag_M(2,1,:) = cellfun(@(m) params.precond_proj_param * (m + params.projection_reg), proj_energy, 'uniformoutput',false);
projection_matrix_init = projection_matrix;
for iter = 1:params.init_GN_iter
% Project sample with new matrix
init_samplef_proj = cellfun(@(x,P) mtimesx(x, P, 'speed'), init_samplef, projection_matrix, 'uniformoutput', false);
init_hf = cellfun(@(x) permute(x, [3 4 1 2]), hf(1,1,:), 'uniformoutput', false);
% Construct the right hand side vector for the filter part
rhs_samplef(1,1,:) = cellfun(@(xf, yf) bsxfun(@times, conj(permute(xf, [3 4 2 1])), yf), init_samplef_proj, yf, 'uniformoutput', false);
% Construct the right hand side vector for the projection matrix part
fyf = cellfun(@(f, yf) reshape(bsxfun(@times, conj(f), yf), [], size(f,3)), hf(1,1,:), yf, 'uniformoutput', false);
rhs_samplef(2,1,:) = cellfun(@(P, XH, fyf, fi) (2*real(XH * fyf - XH(:,fi:end) * fyf(fi:end,:)) - params.projection_reg * P), ...
projection_matrix, init_samplef_H, fyf, lf_ind, 'uniformoutput', false);
% Initialize the projection matrix increment to zero
hf(2,1,:) = cellfun(@(P) zeros(size(P), 'single'), projection_matrix, 'uniformoutput', false);
% do conjugate gradient
[hf, ~, ~, ~, res_norms_temp] = pcg_ccot(...
@(x) lhs_operation_joint(x, init_samplef_proj, reg_filter, feature_reg, init_samplef, init_samplef_H, init_hf, params.projection_reg),...
rhs_samplef, init_CG_opts, ...
@(x) diag_precond(x, diag_M), ...
[], hf);
% Make the filter symmetric (avoid roundoff errors)
hf(1,1,:) = symmetrize_filter(hf(1,1,:));
% Add to the projection matrix
projection_matrix = cellfun(@plus, projection_matrix, hf(2,1,:), 'uniformoutput', false);
res_norms = [res_norms; res_norms_temp];
end
% Extract filter
hf = hf(1,1,:);
% Re-project and insert training sample
xlf_proj = project_sample(xlf, projection_matrix);
for k = 1:num_feature_blocks
samplesf{k}(1,:,:,:) = permute(xlf_proj{k}, [4 3 1 2]);
end
else
% Construct the right hand side vector
rhs_samplef = cellfun(@(xf) permute(mtimesx(sample_weights, 'T', xf, 'speed'), [3 4 2 1]), samplesf, 'uniformoutput', false);
rhs_samplef = cellfun(@(xf, yf) bsxfun(@times, conj(xf), yf), rhs_samplef, yf, 'uniformoutput', false);
% Construct preconditioner
diag_M = cellfun(@(m, reg_energy) (1-params.precond_reg_param) * bsxfun(@plus, params.precond_data_param * m, (1-params.precond_data_param) * mean(m,3)) + params.precond_reg_param*reg_energy, sample_energy, reg_energy, 'uniformoutput',false);
% do conjugate gradient
[hf, ~, ~, ~, res_norms, p, rho, r_old] = pcg_ccot(...
@(x) lhs_operation(x, samplesf, reg_filter, sample_weights, feature_reg),...
rhs_samplef, CG_opts, ...
@(x) diag_precond(x, diag_M), ...
[], hf, p, rho, r_old);
end
% Reconstruct the full Fourier series
hf_full = full_fourier_coeff(hf);
frames_since_last_train = 0;
else
frames_since_last_train = frames_since_last_train+1;
end
% Update the scale filter
if nScales > 0 && params.use_scale_filter
scale_filter = scale_filter_update(im, pos, base_target_sz, currentScaleFactor, scale_filter, params);
end
% Update the target size (only used for computing output box)
target_sz = base_target_sz * currentScaleFactor;
while true
% **********************************
% VOT: Get next frame
% **********************************
[handle, image] = handle.frame(handle);
if isempty(image)
break;
end;
disp(image);
frame = frame + 1;
% **********************************
% VOT: ECO update
% **********************************
im = imread(image);
if size(im,3) > 1 && is_color_image == false
im = im(:,:,1);
end
if frame > 1
old_pos = inf(size(pos));
iter = 1;
%translation search
while iter <= params.refinement_iterations && any(old_pos ~= pos)
% Extract features at multiple resolutions
sample_pos = round(pos);
det_sample_pos = sample_pos;
sample_scale = currentScaleFactor*scaleFactors;
xt = extract_features(im, sample_pos, sample_scale, features, global_fparams, feature_extract_info);
% Project sample
xt_proj = project_sample(xt, projection_matrix);
% Do windowing of features
xt_proj = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xt_proj, cos_window, 'uniformoutput', false);
% Compute the fourier series
xtf_proj = cellfun(@cfft2, xt_proj, 'uniformoutput', false);
% Interpolate features to the continuous domain
xtf_proj = interpolate_dft(xtf_proj, interp1_fs, interp2_fs);
% Compute convolution for each feature block in the Fourier domain
scores_fs_feat = cellfun(@(hf, xf, pad_sz) padarray(sum(bsxfun(@times, hf, xf), 3), pad_sz), hf_full, xtf_proj, pad_sz, 'uniformoutput', false);
switch params.weights_type
case 'constant'
scores_fs_feat{1,1,1} = param.weights(1) *scores_fs_feat{1,1,1};
scores_fs_feat{1,1,2} = param.weights(2) *scores_fs_feat{1,1,1};
case 'sigmoid'
coe = params.initial - params.factor./ (1 + exp(-double(frame)/params.divide_denominator));
scores_fs_feat{1,1,1} = 1*scores_fs_feat{1,1,1};
scores_fs_feat{1,1,2} = coe*scores_fs_feat{1,1,2};
end
% Also sum over all feature blocks.
% Gives the fourier coefficients of the convolution response.
scores_fs = permute(sum(cell2mat(scores_fs_feat), 3), [1 2 4 3]);
% Optimize the continuous score function with Newton's method.
[trans_row, trans_col, scale_ind] = optimize_scores(scores_fs, params.newton_iterations);
% Compute the translation vector in pixel-coordinates and round
% to the closest integer pixel.
translation_vec = [trans_row, trans_col] .* (img_support_sz./output_sz) * currentScaleFactor * scaleFactors(scale_ind);
scale_change_factor = scaleFactors(scale_ind);
% update position
old_pos = pos;
pos = sample_pos + translation_vec;
if params.clamp_position
pos = max([1 1], min([size(im,1) size(im,2)], pos));
end
% Do scale tracking with the scale filter
if nScales > 0 && params.use_scale_filter
scale_change_factor = scale_filter_track(im, pos, base_target_sz, currentScaleFactor, scale_filter, params);
end
% Update the scale
currentScaleFactor = currentScaleFactor * scale_change_factor;
% Adjust to make sure we are not to large or to small
if currentScaleFactor < min_scale_factor
currentScaleFactor = min_scale_factor;
elseif currentScaleFactor > max_scale_factor
currentScaleFactor = max_scale_factor;
end
iter = iter + 1;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Model update step
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Extract sample and init projection matrix
if frame == 1
% Extract image region for training sample
sample_pos = round(pos);
sample_scale = currentScaleFactor;
xl = extract_features(im, sample_pos, currentScaleFactor, features, global_fparams, feature_extract_info);
% Do windowing of features
xlw = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xl, cos_window, 'uniformoutput', false);
% Compute the fourier series
xlf = cellfun(@cfft2, xlw, 'uniformoutput', false);
% Interpolate features to the continuous domain
xlf = interpolate_dft(xlf, interp1_fs, interp2_fs);
% New sample to be added
xlf = compact_fourier_coeff(xlf);
% Initialize projection matrix
xl1 = cellfun(@(x) reshape(x, [], size(x,3)), xl, 'uniformoutput', false);
xl1 = cellfun(@(x) bsxfun(@minus, x, mean(x, 1)), xl1, 'uniformoutput', false);
if strcmpi(params.proj_init_method, 'pca')
[projection_matrix, ~, ~] = cellfun(@(x) svd(x' * x), xl1, 'uniformoutput', false);
projection_matrix = cellfun(@(P, dim) single(P(:,1:dim)), projection_matrix, compressed_dim_cell, 'uniformoutput', false);
elseif strcmpi(params.proj_init_method, 'rand_uni')
projection_matrix = cellfun(@(x, dim) single(randn(size(x,2), dim)), xl1, compressed_dim_cell, 'uniformoutput', false);
projection_matrix = cellfun(@(P) bsxfun(@rdivide, P, sqrt(sum(P.^2,1))), projection_matrix, 'uniformoutput', false);
elseif strcmpi(params.proj_init_method, 'none')
projection_matrix = [];
else
error('Unknown initialization method for the projection matrix: %s', params.proj_init_method);
end
clear xl1 xlw
% Shift sample
shift_samp = 2*pi * (pos - sample_pos) ./ (sample_scale * img_support_sz);
xlf = shift_sample(xlf, shift_samp, kx, ky);
% Project sample
xlf_proj = project_sample(xlf, projection_matrix);
elseif params.learning_rate > 0
if ~params.use_detection_sample
% Extract image region for training sample
sample_pos = round(pos);
sample_scale = currentScaleFactor;
xl = extract_features(im, sample_pos, currentScaleFactor, features, global_fparams, feature_extract_info);
% Project sample
xl_proj = project_sample(xl, projection_matrix);
% Do windowing of features
xl_proj = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xl_proj, cos_window, 'uniformoutput', false);
% Compute the fourier series
xlf1_proj = cellfun(@cfft2, xl_proj, 'uniformoutput', false);
% Interpolate features to the continuous domain
xlf1_proj = interpolate_dft(xlf1_proj, interp1_fs, interp2_fs);
% New sample to be added
xlf_proj = compact_fourier_coeff(xlf1_proj);
else
% Use the sample that was used for detection
sample_scale = sample_scale(scale_ind);
xlf_proj = cellfun(@(xf) xf(:,1:(size(xf,2)+1)/2,:,scale_ind), xtf_proj, 'uniformoutput', false);
end
% Shift the sample so that the target is centered
shift_samp = 2*pi * (pos - sample_pos) ./ (sample_scale * img_support_sz);
xlf_proj = shift_sample(xlf_proj, shift_samp, kx, ky);
end
xlf_proj_perm = cellfun(@(xf) permute(xf, [4 3 1 2]), xlf_proj, 'uniformoutput', false);
if params.use_sample_merge
% Find the distances with existing samples
dist_vector = find_cluster_distances(samplesf, xlf_proj_perm, num_feature_blocks, num_training_samples, max_train_samples, params);
[merged_sample, new_cluster, merged_cluster_id, new_cluster_id, score_matrix, prior_weights,num_training_samples] = ...
merge_clusters(samplesf, xlf_proj_perm, dist_vector, score_matrix, prior_weights,...
num_training_samples,num_feature_blocks,max_train_samples,minimum_sample_weight,params);
else
% Do the traditional adding of a training sample and weight update
% of C-COT
[prior_weights, replace_ind] = update_prior_weights(prior_weights, sample_weights, latest_ind, frame, params);
latest_ind = replace_ind;
merged_cluster_id = 0;
new_cluster = xlf_proj_perm;
new_cluster_id = replace_ind;
end
if frame > 1 && params.learning_rate > 0 || frame == 1 && ~params.update_projection_matrix
% Insert the new training sample
for k = 1:num_feature_blocks
if merged_cluster_id > 0
samplesf{k}(merged_cluster_id,:,:,:) = merged_sample{k};
end
if new_cluster_id > 0
samplesf{k}(new_cluster_id,:,:,:) = new_cluster{k};
end
end
end
sample_weights = prior_weights;
train_tracker = (frame < params.skip_after_frame) || (frames_since_last_train >= params.train_gap);
if train_tracker
% Used for preconditioning
new_sample_energy = cellfun(@(xlf) abs(xlf .* conj(xlf)), xlf_proj, 'uniformoutput', false);
if frame == 1
if params.update_projection_matrix
hf = cell(2,1,num_feature_blocks);
lf_ind = cellfun(@(sz) sz(1) * (sz(2)-1)/2 + 1, filter_sz_cell, 'uniformoutput', false);
proj_energy = cellfun(@(P, yf) 2*sum(abs(yf(:)).^2) / sum(feature_dim) * ones(size(P), 'single'), projection_matrix, yf, 'uniformoutput', false);
else
hf = cell(1,1,num_feature_blocks);
end
% Initialize the filter
for k = 1:num_feature_blocks
hf{1,1,k} = complex(zeros([filter_sz(k,1) (filter_sz(k,2)+1)/2 compressed_dim(k)], 'single'));
end
% Initialize Conjugate Gradient parameters
CG_opts.maxit = params.init_CG_iter; % Number of initial iterations if projection matrix is not updated
init_CG_opts.maxit = ceil(params.init_CG_iter / params.init_GN_iter);
sample_energy = new_sample_energy;
rhs_samplef = cell(size(hf));
diag_M = cell(size(hf));
p = []; rho = []; r_old = [];
else
CG_opts.maxit = params.CG_iter;
if params.CG_forgetting_rate == inf || params.learning_rate >= 1
% CG will be reset
p = []; rho = []; r_old = [];
else
rho = rho / (1-params.learning_rate)^params.CG_forgetting_rate;
end
% Update the approximate average sample energy using the learning
% rate. This is only used to construct the preconditioner.
sample_energy = cellfun(@(se, nse) (1 - params.learning_rate) * se + params.learning_rate * nse, sample_energy, new_sample_energy, 'uniformoutput', false);
end
% Do training
if frame == 1 && params.update_projection_matrix
% Initial Gauss-Newton optimization of the filter and
% projection matrix.
% Construct stuff for the proj matrix part
init_samplef = cellfun(@(x) permute(x, [4 3 1 2]), xlf, 'uniformoutput', false);
init_samplef_H = cellfun(@(X) conj(reshape(X, size(X,2), [])), init_samplef, 'uniformoutput', false);
% Construct preconditioner
diag_M(1,1,:) = cellfun(@(m, reg_energy) (1-params.precond_reg_param) * bsxfun(@plus, params.precond_data_param * m, (1-params.precond_data_param) * mean(m,3)) + params.precond_reg_param*reg_energy, sample_energy, reg_energy, 'uniformoutput',false);
diag_M(2,1,:) = cellfun(@(m) params.precond_proj_param * (m + params.projection_reg), proj_energy, 'uniformoutput',false);
projection_matrix_init = projection_matrix;
for iter = 1:params.init_GN_iter
% Project sample with new matrix
init_samplef_proj = cellfun(@(x,P) mtimesx(x, P, 'speed'), init_samplef, projection_matrix, 'uniformoutput', false);
init_hf = cellfun(@(x) permute(x, [3 4 1 2]), hf(1,1,:), 'uniformoutput', false);
% Construct the right hand side vector for the filter part
rhs_samplef(1,1,:) = cellfun(@(xf, yf) bsxfun(@times, conj(permute(xf, [3 4 2 1])), yf), init_samplef_proj, yf, 'uniformoutput', false);
% Construct the right hand side vector for the projection matrix part
fyf = cellfun(@(f, yf) reshape(bsxfun(@times, conj(f), yf), [], size(f,3)), hf(1,1,:), yf, 'uniformoutput', false);
rhs_samplef(2,1,:) = cellfun(@(P, XH, fyf, fi) (2*real(XH * fyf - XH(:,fi:end) * fyf(fi:end,:)) - params.projection_reg * P), ...
projection_matrix, init_samplef_H, fyf, lf_ind, 'uniformoutput', false);
% Initialize the projection matrix increment to zero
hf(2,1,:) = cellfun(@(P) zeros(size(P), 'single'), projection_matrix, 'uniformoutput', false);
% do conjugate gradient
[hf, ~, ~, ~, res_norms_temp] = pcg_ccot(...
@(x) lhs_operation_joint(x, init_samplef_proj, reg_filter, feature_reg, init_samplef, init_samplef_H, init_hf, params.projection_reg),...
rhs_samplef, init_CG_opts, ...
@(x) diag_precond(x, diag_M), ...
[], hf);
% Make the filter symmetric (avoid roundoff errors)
hf(1,1,:) = symmetrize_filter(hf(1,1,:));
% Add to the projection matrix
projection_matrix = cellfun(@plus, projection_matrix, hf(2,1,:), 'uniformoutput', false);
res_norms = [res_norms; res_norms_temp];
end
% Extract filter
hf = hf(1,1,:);
% Re-project and insert training sample
xlf_proj = project_sample(xlf, projection_matrix);
for k = 1:num_feature_blocks
samplesf{k}(1,:,:,:) = permute(xlf_proj{k}, [4 3 1 2]);
end
else
% Construct the right hand side vector
rhs_samplef = cellfun(@(xf) permute(mtimesx(sample_weights, 'T', xf, 'speed'), [3 4 2 1]), samplesf, 'uniformoutput', false);
rhs_samplef = cellfun(@(xf, yf) bsxfun(@times, conj(xf), yf), rhs_samplef, yf, 'uniformoutput', false);
% Construct preconditioner
diag_M = cellfun(@(m, reg_energy) (1-params.precond_reg_param) * bsxfun(@plus, params.precond_data_param * m, (1-params.precond_data_param) * mean(m,3)) + params.precond_reg_param*reg_energy, sample_energy, reg_energy, 'uniformoutput',false);
% do conjugate gradient
[hf, ~, ~, ~, res_norms, p, rho, r_old] = pcg_ccot(...
@(x) lhs_operation(x, samplesf, reg_filter, sample_weights, feature_reg),...
rhs_samplef, CG_opts, ...
@(x) diag_precond(x, diag_M), ...
[], hf, p, rho, r_old);
end
% Reconstruct the full Fourier series
hf_full = full_fourier_coeff(hf);
frames_since_last_train = 0;
else
frames_since_last_train = frames_since_last_train+1;
end
% Update the scale filter
if nScales > 0 && params.use_scale_filter
scale_filter = scale_filter_update(im, pos, base_target_sz, currentScaleFactor, scale_filter, params);
end
% Update the target size (only used for computing output box)
target_sz = base_target_sz * currentScaleFactor;
%save position and calculate FPS
region = round([pos([2,1]) - (target_sz([2,1]) - 1)/2, target_sz([2,1])]);
region = double(region);
disp(region);
% **********************************
% VOT: Report position for frame
% **********************************
handle = handle.report(handle, region);
end;
% **********************************
% VOT: Output the results
% **********************************
handle.quit(handle);
end
function params = init_param(region)
cnn_params.nn_name = 'imagenet-vgg-m-2048-cut.mat'; % Name of the network
cnn_params.output_layer = [3 14];
cnn_params.downsample_factor = [2 1]; % How much to downsample each output layer
cnn_params.input_size_mode = 'adaptive'; % How to choose the sample size
cnn_params.input_size_scale = 1; % Extra scale factor of the input samples to the network (1 is no scaling)
cnn_params.use_gpu = false;
% cnn_params.gpu_id = [3];
% Which features to include
params.t_features = {
struct('getFeature',@get_cnn_layers, 'fparams',cnn_params),...
};
% Global feature parameters1s
params.t_global.normalize_power = 2; % Lp normalization with this p
params.t_global.normalize_size = true; % Also normalize with respect to the spatial size of the feature
params.t_global.normalize_dim = true; % Also normalize with respect to the dimensionality of the feature
% Image sample parameters
params.search_area_shape = 'square'; % The shape of the samples
params.search_area_scale = 4.0; % The scaling of the target size to get the search area
params.min_image_sample_size = 200^2; % Minimum area of image samples
params.max_image_sample_size = 250^2; % Maximum area of image samples
% Detection parameters
params.refinement_iterations = 1; % Number of iterations used to refine the resulting position in a frame
params.newton_iterations = 5; % The number of Newton iterations used for optimizing the detection rere
params.clamp_position = false; % Clamp the target position to be inside the image
% Learning parameters
params.output_sigma_factor = 1/12; % Label function sigma
params.learning_rate = 0.012; % Learning rate
params.nSamples = 100; % Maximum number of stored training samples
params.sample_replace_strategy = 'lowest_prior'; % Which sample to replace when the memory is full
params.lt_size = 0; % The size of the long-term memory (where all samples have equal weight)
params.train_gap = 5; % The number of intermediate frames with no training (0 corresponds to training every frame)
params.skip_after_frame = 1; % After which frame number the sparse update scheme should start (1 is directly)
params.use_detection_sample = true; % Use the sample that was extracted at the detection stage also for learning
% Factorized convolution parameters
params.use_projection_matrix = true; % Use projection matrix, i.e. use the factorized convolution formulation
params.update_projection_matrix = true; % Whether the projection matrix should be optimized or not
params.proj_init_method = 'pca'; % Method for initializing the projection matrix
params.projection_reg = 2e-7; % Regularization paremeter of the projection matrix
% Generative sample space model parameters
params.use_sample_merge = true; % Use the generative sample space model to merge samples
params.sample_update_criteria = 'Merge'; % Strategy for updating the samples
params.weight_update_criteria = 'WeightedAdd'; % Strategy for updating the distance matrix
params.neglect_higher_frequency = false; % Neglect hiigher frequency components in the distance comparison for speed
% Conjugate Gradient parameters
params.CG_iter = 5; % The number of Conjugate Gradient iterations in each update after the first frame
params.init_CG_iter = 10*20; % The total number of Conjugate Gradient iterations used in the first frame
params.init_GN_iter = 10; % The number of Gauss-Newton iterations used in the first frame (only if the projection matrix is updated)
params.CG_use_FR = false; % Use the Fletcher-Reeves (true) or Polak-Ribiere (false) formula in the Conjugate Gradient
params.CG_standard_alpha = true; % Use the standard formula for computing the step length in Conjugate Gradient
params.CG_forgetting_rate = 75; % Forgetting rate of the last conjugate direction
params.precond_data_param = 0.7; % Weight of the data term in the preconditioner
params.precond_reg_param = 0.1; % Weight of the regularization term in the preconditioner
params.precond_proj_param = 30; % Weight of the projection matrix part in the preconditioner
% Regularization window parameters
params.use_reg_window = true; % Use spatial regularization or not
params.reg_window_min = 1e-4; % The minimum value of the regularization window
params.reg_window_edge = 10e-3; % The impact of the spatial regularization
params.reg_window_power = 2; % The degree of the polynomial to use (e.g. 2 is a quadratic window)
params.reg_sparsity_threshold = 0.12; % A relative threshold of which DFT coefficients that should be set to zero
% Interpolation parameters
params.interpolation_method = 'bicubic'; % The kind of interpolation kernel
params.interpolation_bicubic_a = -0.75; % The parameter for the bicubic interpolation kernel
params.interpolation_centering = true; % Center the kernel at the feature sample
params.interpolation_windowing = false; % Do additional windowing on the Fourier coefficients of the kernel
% Scale parameters for the translation model
% Only used if: params.use_scale_filter = false
params.use_scale_filter = false
params.number_of_scales = 10; % Number of scales to run the detector
params.scale_step = 1.03; % The scale factor
params.weights = [1, 2]; % The weights factor
params.weights_type = 'sigmoid'; % type: constant, sigmoid
params.divide_denominator = 100;
params.initial = 1;
params.factor = 0;
% Initialize
params.init_sz = [region(4), region(3)];
params.init_pos = [region(2), region(1)] + (params.init_sz - 1)/2;
end
|
github
|
he010103/CFWCR-master
|
CFWCR_VOT.m
|
.m
|
CFWCR-master/vot2017_trax/CFWCR_VOT.m
| 43,816 |
utf_8
|
52fc356daac0e7d8a71d2b955e6a1313
|
function CFWCR_VOT()
% *************************************************************
% VOT: Always call exit command at the end to terminate Matlab!
% *************************************************************
cleanup = onCleanup(@() exit() );
% *************************************************************
% VOT: Set random seed to a different value every time.
% *************************************************************
RandStream.setGlobalStream(RandStream('mt19937ar', 'Seed', sum(clock)));
% *************************************************************
% VOT: init the resources
% *************************************************************
[wrapper_path, name, ext] = fileparts(mfilename('fullpath'));
addpath(wrapper_path);
cd_ind = strfind(wrapper_path, filesep());
repo_path = wrapper_path(1:cd_ind(end)-1);
addpath(repo_path);
setup_paths();
vl_setupnn();
% **********************************
% VOT: Get initialization data
% **********************************
[handle, image, region] = vot('polygon');
% Initialize the tracker
disp(image);
bb_scale = 1;
% If the provided region is a polygon ...
if numel(region) > 4
% Init with an axis aligned bounding box with correct area and center
% coordinate
cx = mean(region(1:2:end));
cy = mean(region(2:2:end));
x1 = min(region(1:2:end));
x2 = max(region(1:2:end));
y1 = min(region(2:2:end));
y2 = max(region(2:2:end));
A1 = norm(region(1:2) - region(3:4)) * norm(region(3:4) - region(5:6));
A2 = (x2 - x1) * (y2 - y1);
s = sqrt(A1/A2);
w = s * (x2 - x1) + 1;
h = s * (y2 - y1) + 1;
else
cx = region(1) + (region(3) - 1)/2;
cy = region(2) + (region(4) - 1)/2;
w = region(3);
h = region(4);
end
init_c = [cx cy];
init_sz = bb_scale * [w h];
im_size = size(imread(image));
im_size = im_size([2 1]);
init_pos = min(max(round(init_c - (init_sz - 1)/2), [1 1]), im_size);
init_sz = min(max(round(init_sz), [1 1]), im_size - init_pos + 1);
region = [init_pos, init_sz];
frame = 1
% **********************************
% VOT: ECO init
% **********************************
params = init_param(region);
max_train_samples = params.nSamples;
features = params.t_features;
% Set some default parameters
params = init_default_params(params);
if isfield(params, 't_global')
global_fparams = params.t_global;
else
global_fparams = [];
end
% Init sequence data
pos = params.init_pos(:)';
target_sz = params.init_sz(:)';
init_target_sz = target_sz;
% Check if color image
im = imread(image);
if size(im,3) == 3
if all(all(im(:,:,1) == im(:,:,2)))
is_color_image = false;
else
is_color_image = true;
end
else
is_color_image = false;
end
if size(im,3) > 1 && is_color_image == false
im = im(:,:,1);
end
params.use_mexResize = false;
global_fparams.use_mexResize = false;
% Calculate search area and initial scale factor
search_area = prod(init_target_sz * params.search_area_scale);
if search_area > params.max_image_sample_size
currentScaleFactor = sqrt(search_area / params.max_image_sample_size);
elseif search_area < params.min_image_sample_size
currentScaleFactor = sqrt(search_area / params.min_image_sample_size);
else
currentScaleFactor = 1.0;
end
% target size at the initial scale
base_target_sz = target_sz / currentScaleFactor;
% window size, taking padding into account
switch params.search_area_shape
case 'proportional'
img_sample_sz = floor( base_target_sz * params.search_area_scale); % proportional area, same aspect ratio as the target
case 'square'
img_sample_sz = repmat(sqrt(prod(base_target_sz * params.search_area_scale)), 1, 2); % square area, ignores the target aspect ratio
case 'fix_padding'
img_sample_sz = base_target_sz + sqrt(prod(base_target_sz * params.search_area_scale) + (base_target_sz(1) - base_target_sz(2))/4) - sum(base_target_sz)/2; % const padding
case 'custom'
img_sample_sz = [base_target_sz(1)*2 base_target_sz(2)*2]; % for testing
end
[features, global_fparams, feature_info] = init_features(features, global_fparams, is_color_image, img_sample_sz, 'odd_cells');
% Set feature info
img_support_sz = feature_info.img_support_sz;
feature_sz = feature_info.data_sz;
feature_dim = feature_info.dim;
num_feature_blocks = length(feature_dim);
feature_reg = permute(num2cell(feature_info.penalty), [2 3 1]);
% Get feature specific parameters
feature_params = init_feature_params(features, feature_info);
feature_extract_info = get_feature_extract_info(features);
if params.use_projection_matrix
compressed_dim = feature_params.compressed_dim;
else
compressed_dim = feature_dim;
end
compressed_dim_cell = permute(num2cell(compressed_dim), [2 3 1]);
% Size of the extracted feature maps
feature_sz_cell = permute(mat2cell(feature_sz, ones(1,num_feature_blocks), 2), [2 3 1]);
% Number of Fourier coefficients to save for each filter layer. This will
% be an odd number.
filter_sz = feature_sz + mod(feature_sz+1, 2);
filter_sz_cell = permute(mat2cell(filter_sz, ones(1,num_feature_blocks), 2), [2 3 1]);
% The size of the label function DFT. Equal to the maximum filter size.
output_sz = max(filter_sz, [], 1);
% How much each feature block has to be padded to the obtain output_sz
pad_sz = cellfun(@(filter_sz) (output_sz - filter_sz) / 2, filter_sz_cell, 'uniformoutput', false);
% Compute the Fourier series indices and their transposes
ky = cellfun(@(sz) (-ceil((sz(1) - 1)/2) : floor((sz(1) - 1)/2))', filter_sz_cell, 'uniformoutput', false);
kx = cellfun(@(sz) -ceil((sz(2) - 1)/2) : 0, filter_sz_cell, 'uniformoutput', false);
% construct the Gaussian label function using Poisson formula
sig_y = sqrt(prod(floor(base_target_sz))) * params.output_sigma_factor * (output_sz ./ img_support_sz);
yf_y = cellfun(@(ky) single(sqrt(2*pi) * sig_y(1) / output_sz(1) * exp(-2 * (pi * sig_y(1) * ky / output_sz(1)).^2)), ky, 'uniformoutput', false);
yf_x = cellfun(@(kx) single(sqrt(2*pi) * sig_y(2) / output_sz(2) * exp(-2 * (pi * sig_y(2) * kx / output_sz(2)).^2)), kx, 'uniformoutput', false);
yf = cellfun(@(yf_y, yf_x) yf_y * yf_x, yf_y, yf_x, 'uniformoutput', false);
% construct cosine window
cos_window = cellfun(@(sz) single(hann(sz(1)+2)*hann(sz(2)+2)'), feature_sz_cell, 'uniformoutput', false);
cos_window = cellfun(@(cos_window) cos_window(2:end-1,2:end-1), cos_window, 'uniformoutput', false);
% Compute Fourier series of interpolation function
[interp1_fs, interp2_fs] = cellfun(@(sz) get_interp_fourier(sz, params), filter_sz_cell, 'uniformoutput', false);
% Get the reg_window_edge parameter
reg_window_edge = {};
for k = 1:length(features)
if isfield(features{k}.fparams, 'reg_window_edge')
reg_window_edge = cat(3, reg_window_edge, permute(num2cell(features{k}.fparams.reg_window_edge(:)), [2 3 1]));
else
reg_window_edge = cat(3, reg_window_edge, cell(1, 1, length(features{k}.fparams.nDim)));
end
end
% Construct spatial regularization filter
reg_filter = cellfun(@(reg_window_edge) get_reg_filter(img_support_sz, base_target_sz, params, reg_window_edge), reg_window_edge, 'uniformoutput', false);
% Compute the energy of the filter (used for preconditioner)
reg_energy = cellfun(@(reg_filter) real(reg_filter(:)' * reg_filter(:)), reg_filter, 'uniformoutput', false);
if params.use_scale_filter
[nScales, scale_step, scaleFactors, scale_filter, params] = init_scale_filter(params);
else
% Use the translation filter to estimate the scale.
nScales = params.number_of_scales;
scale_step = params.scale_step;
scale_exp = (-floor((nScales-1)/2):ceil((nScales-1)/2));
scaleFactors = scale_step .^ scale_exp;
end
if nScales > 0
%force reasonable scale changes
min_scale_factor = scale_step ^ ceil(log(max(5 ./ img_support_sz)) / log(scale_step));
max_scale_factor = scale_step ^ floor(log(min([size(im,1) size(im,2)] ./ base_target_sz)) / log(scale_step));
end
% Set conjugate gradient uptions
init_CG_opts.CG_use_FR = true;
init_CG_opts.tol = 1e-6;
init_CG_opts.CG_standard_alpha = true;
init_CG_opts.debug = 0;
CG_opts.CG_use_FR = params.CG_use_FR;
CG_opts.tol = 1e-6;
CG_opts.CG_standard_alpha = params.CG_standard_alpha;
CG_opts.debug = 0;
time = 0;
% Initialize and allocate
prior_weights = zeros(max_train_samples,1, 'single');
sample_weights = prior_weights;
samplesf = cell(1, 1, num_feature_blocks);
for k = 1:num_feature_blocks
samplesf{k} = complex(zeros(max_train_samples,compressed_dim(k),filter_sz(k,1),(filter_sz(k,2)+1)/2,'single'));
end
score_matrix = inf(max_train_samples, 'single');
latest_ind = [];
frames_since_last_train = inf;
num_training_samples = 0;
minimum_sample_weight = params.learning_rate*(1-params.learning_rate)^(2*max_train_samples);
res_norms = [];
residuals_pcg = [];
if frame == 1
% Extract image region for training sample
sample_pos = round(pos);
sample_scale = currentScaleFactor;
xl = extract_features(im, sample_pos, currentScaleFactor, features, global_fparams, feature_extract_info);
% Do windowing of features
xlw = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xl, cos_window, 'uniformoutput', false);
% Compute the fourier series
xlf = cellfun(@cfft2, xlw, 'uniformoutput', false);
% Interpolate features to the continuous domain
xlf = interpolate_dft(xlf, interp1_fs, interp2_fs);
% New sample to be added
xlf = compact_fourier_coeff(xlf);
% Initialize projection matrix
xl1 = cellfun(@(x) reshape(x, [], size(x,3)), xl, 'uniformoutput', false);
xl1 = cellfun(@(x) bsxfun(@minus, x, mean(x, 1)), xl1, 'uniformoutput', false);
if strcmpi(params.proj_init_method, 'pca')
[projection_matrix, ~, ~] = cellfun(@(x) svd(x' * x), xl1, 'uniformoutput', false);
projection_matrix = cellfun(@(P, dim) single(P(:,1:dim)), projection_matrix, compressed_dim_cell, 'uniformoutput', false);
elseif strcmpi(params.proj_init_method, 'rand_uni')
projection_matrix = cellfun(@(x, dim) single(randn(size(x,2), dim)), xl1, compressed_dim_cell, 'uniformoutput', false);
projection_matrix = cellfun(@(P) bsxfun(@rdivide, P, sqrt(sum(P.^2,1))), projection_matrix, 'uniformoutput', false);
elseif strcmpi(params.proj_init_method, 'none')
projection_matrix = [];
else
error('Unknown initialization method for the projection matrix: %s', params.proj_init_method);
end
clear xl1 xlw
% Shift sample
shift_samp = 2*pi * (pos - sample_pos) ./ (sample_scale * img_support_sz);
xlf = shift_sample(xlf, shift_samp, kx, ky);
% Project sample
xlf_proj = project_sample(xlf, projection_matrix);
elseif params.learning_rate > 0
if ~params.use_detection_sample
% Extract image region for training sample
sample_pos = round(pos);
sample_scale = currentScaleFactor;
xl = extract_features(im, sample_pos, currentScaleFactor, features, global_fparams, feature_extract_info);
% Project sample
xl_proj = project_sample(xl, projection_matrix);
% Do windowing of features
xl_proj = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xl_proj, cos_window, 'uniformoutput', false);
% Compute the fourier series
xlf1_proj = cellfun(@cfft2, xl_proj, 'uniformoutput', false);
% Interpolate features to the continuous domain
xlf1_proj = interpolate_dft(xlf1_proj, interp1_fs, interp2_fs);
% New sample to be added
xlf_proj = compact_fourier_coeff(xlf1_proj);
else
% Use the sample that was used for detection
sample_scale = sample_scale(scale_ind);
xlf_proj = cellfun(@(xf) xf(:,1:(size(xf,2)+1)/2,:,scale_ind), xtf_proj, 'uniformoutput', false);
end
% Shift the sample so that the target is centered
shift_samp = 2*pi * (pos - sample_pos) ./ (sample_scale * img_support_sz);
xlf_proj = shift_sample(xlf_proj, shift_samp, kx, ky);
end
xlf_proj_perm = cellfun(@(xf) permute(xf, [4 3 1 2]), xlf_proj, 'uniformoutput', false);
if params.use_sample_merge
% Find the distances with existing samples
dist_vector = find_cluster_distances(samplesf, xlf_proj_perm, num_feature_blocks, num_training_samples, max_train_samples, params);
[merged_sample, new_cluster, merged_cluster_id, new_cluster_id, score_matrix, prior_weights,num_training_samples] = ...
merge_clusters(samplesf, xlf_proj_perm, dist_vector, score_matrix, prior_weights,...
num_training_samples,num_feature_blocks,max_train_samples,minimum_sample_weight,params);
else
% Do the traditional adding of a training sample and weight update
% of C-COT
[prior_weights, replace_ind] = update_prior_weights(prior_weights, sample_weights, latest_ind, frame, params);
latest_ind = replace_ind;
merged_cluster_id = 0;
new_cluster = xlf_proj_perm;
new_cluster_id = replace_ind;
end
if frame > 1 && params.learning_rate > 0 || frame == 1 && ~params.update_projection_matrix
% Insert the new training sample
for k = 1:num_feature_blocks
if merged_cluster_id > 0
samplesf{k}(merged_cluster_id,:,:,:) = merged_sample{k};
end
if new_cluster_id > 0
samplesf{k}(new_cluster_id,:,:,:) = new_cluster{k};
end
end
end
sample_weights = prior_weights;
train_tracker = (frame < params.skip_after_frame) || (frames_since_last_train >= params.train_gap);
if train_tracker
% Used for preconditioning
new_sample_energy = cellfun(@(xlf) abs(xlf .* conj(xlf)), xlf_proj, 'uniformoutput', false);
if frame == 1
if params.update_projection_matrix
hf = cell(2,1,num_feature_blocks);
lf_ind = cellfun(@(sz) sz(1) * (sz(2)-1)/2 + 1, filter_sz_cell, 'uniformoutput', false);
proj_energy = cellfun(@(P, yf) 2*sum(abs(yf(:)).^2) / sum(feature_dim) * ones(size(P), 'single'), projection_matrix, yf, 'uniformoutput', false);
else
hf = cell(1,1,num_feature_blocks);
end
% Initialize the filter
for k = 1:num_feature_blocks
hf{1,1,k} = complex(zeros([filter_sz(k,1) (filter_sz(k,2)+1)/2 compressed_dim(k)], 'single'));
end
% Initialize Conjugate Gradient parameters
CG_opts.maxit = params.init_CG_iter; % Number of initial iterations if projection matrix is not updated
init_CG_opts.maxit = ceil(params.init_CG_iter / params.init_GN_iter);
sample_energy = new_sample_energy;
rhs_samplef = cell(size(hf));
diag_M = cell(size(hf));
p = []; rho = []; r_old = [];
else
CG_opts.maxit = params.CG_iter;
if params.CG_forgetting_rate == inf || params.learning_rate >= 1
% CG will be reset
p = []; rho = []; r_old = [];
else
rho = rho / (1-params.learning_rate)^params.CG_forgetting_rate;
end
% Update the approximate average sample energy using the learning
% rate. This is only used to construct the preconditioner.
sample_energy = cellfun(@(se, nse) (1 - params.learning_rate) * se + params.learning_rate * nse, sample_energy, new_sample_energy, 'uniformoutput', false);
end
% Do training
if frame == 1 && params.update_projection_matrix
% Initial Gauss-Newton optimization of the filter and
% projection matrix.
% Construct stuff for the proj matrix part
init_samplef = cellfun(@(x) permute(x, [4 3 1 2]), xlf, 'uniformoutput', false);
init_samplef_H = cellfun(@(X) conj(reshape(X, size(X,2), [])), init_samplef, 'uniformoutput', false);
% Construct preconditioner
diag_M(1,1,:) = cellfun(@(m, reg_energy) (1-params.precond_reg_param) * bsxfun(@plus, params.precond_data_param * m, (1-params.precond_data_param) * mean(m,3)) + params.precond_reg_param*reg_energy, sample_energy, reg_energy, 'uniformoutput',false);
diag_M(2,1,:) = cellfun(@(m) params.precond_proj_param * (m + params.projection_reg), proj_energy, 'uniformoutput',false);
projection_matrix_init = projection_matrix;
for iter = 1:params.init_GN_iter
% Project sample with new matrix
init_samplef_proj = cellfun(@(x,P) mtimesx(x, P, 'speed'), init_samplef, projection_matrix, 'uniformoutput', false);
init_hf = cellfun(@(x) permute(x, [3 4 1 2]), hf(1,1,:), 'uniformoutput', false);
% Construct the right hand side vector for the filter part
rhs_samplef(1,1,:) = cellfun(@(xf, yf) bsxfun(@times, conj(permute(xf, [3 4 2 1])), yf), init_samplef_proj, yf, 'uniformoutput', false);
% Construct the right hand side vector for the projection matrix part
fyf = cellfun(@(f, yf) reshape(bsxfun(@times, conj(f), yf), [], size(f,3)), hf(1,1,:), yf, 'uniformoutput', false);
rhs_samplef(2,1,:) = cellfun(@(P, XH, fyf, fi) (2*real(XH * fyf - XH(:,fi:end) * fyf(fi:end,:)) - params.projection_reg * P), ...
projection_matrix, init_samplef_H, fyf, lf_ind, 'uniformoutput', false);
% Initialize the projection matrix increment to zero
hf(2,1,:) = cellfun(@(P) zeros(size(P), 'single'), projection_matrix, 'uniformoutput', false);
% do conjugate gradient
[hf, ~, ~, ~, res_norms_temp] = pcg_ccot(...
@(x) lhs_operation_joint(x, init_samplef_proj, reg_filter, feature_reg, init_samplef, init_samplef_H, init_hf, params.projection_reg),...
rhs_samplef, init_CG_opts, ...
@(x) diag_precond(x, diag_M), ...
[], hf);
% Make the filter symmetric (avoid roundoff errors)
hf(1,1,:) = symmetrize_filter(hf(1,1,:));
% Add to the projection matrix
projection_matrix = cellfun(@plus, projection_matrix, hf(2,1,:), 'uniformoutput', false);
res_norms = [res_norms; res_norms_temp];
end
% Extract filter
hf = hf(1,1,:);
% Re-project and insert training sample
xlf_proj = project_sample(xlf, projection_matrix);
for k = 1:num_feature_blocks
samplesf{k}(1,:,:,:) = permute(xlf_proj{k}, [4 3 1 2]);
end
else
% Construct the right hand side vector
rhs_samplef = cellfun(@(xf) permute(mtimesx(sample_weights, 'T', xf, 'speed'), [3 4 2 1]), samplesf, 'uniformoutput', false);
rhs_samplef = cellfun(@(xf, yf) bsxfun(@times, conj(xf), yf), rhs_samplef, yf, 'uniformoutput', false);
% Construct preconditioner
diag_M = cellfun(@(m, reg_energy) (1-params.precond_reg_param) * bsxfun(@plus, params.precond_data_param * m, (1-params.precond_data_param) * mean(m,3)) + params.precond_reg_param*reg_energy, sample_energy, reg_energy, 'uniformoutput',false);
% do conjugate gradient
[hf, ~, ~, ~, res_norms, p, rho, r_old] = pcg_ccot(...
@(x) lhs_operation(x, samplesf, reg_filter, sample_weights, feature_reg),...
rhs_samplef, CG_opts, ...
@(x) diag_precond(x, diag_M), ...
[], hf, p, rho, r_old);
end
% Reconstruct the full Fourier series
hf_full = full_fourier_coeff(hf);
frames_since_last_train = 0;
else
frames_since_last_train = frames_since_last_train+1;
end
% Update the scale filter
if nScales > 0 && params.use_scale_filter
scale_filter = scale_filter_update(im, pos, base_target_sz, currentScaleFactor, scale_filter, params);
end
% Update the target size (only used for computing output box)
target_sz = base_target_sz * currentScaleFactor;
while true
% **********************************
% VOT: Get next frame
% **********************************
[handle, image] = handle.frame(handle);
if isempty(image)
break;
end;
disp(image);
frame = frame + 1;
% **********************************
% VOT: ECO update
% **********************************
im = imread(image);
if size(im,3) > 1 && is_color_image == false
im = im(:,:,1);
end
if frame > 1
old_pos = inf(size(pos));
iter = 1;
%translation search
while iter <= params.refinement_iterations && any(old_pos ~= pos)
% Extract features at multiple resolutions
sample_pos = round(pos);
det_sample_pos = sample_pos;
sample_scale = currentScaleFactor*scaleFactors;
xt = extract_features(im, sample_pos, sample_scale, features, global_fparams, feature_extract_info);
% Project sample
xt_proj = project_sample(xt, projection_matrix);
% Do windowing of features
xt_proj = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xt_proj, cos_window, 'uniformoutput', false);
% Compute the fourier series
xtf_proj = cellfun(@cfft2, xt_proj, 'uniformoutput', false);
% Interpolate features to the continuous domain
xtf_proj = interpolate_dft(xtf_proj, interp1_fs, interp2_fs);
% Compute convolution for each feature block in the Fourier domain
scores_fs_feat = cellfun(@(hf, xf, pad_sz) padarray(sum(bsxfun(@times, hf, xf), 3), pad_sz), hf_full, xtf_proj, pad_sz, 'uniformoutput', false);
switch params.weights_type
case 'constant'
scores_fs_feat{1,1,1} = param.weights(1) *scores_fs_feat{1,1,1};
scores_fs_feat{1,1,2} = param.weights(2) *scores_fs_feat{1,1,1};
case 'sigmoid'
coe = params.initial - params.factor./ (1 + exp(-double(frame)/params.divide_denominator));
scores_fs_feat{1,1,1} = 1*scores_fs_feat{1,1,1};
scores_fs_feat{1,1,2} = coe*scores_fs_feat{1,1,2};
end
% Also sum over all feature blocks.
% Gives the fourier coefficients of the convolution response.
scores_fs = permute(sum(cell2mat(scores_fs_feat), 3), [1 2 4 3]);
% Optimize the continuous score function with Newton's method.
[trans_row, trans_col, scale_ind] = optimize_scores(scores_fs, params.newton_iterations);
% Compute the translation vector in pixel-coordinates and round
% to the closest integer pixel.
translation_vec = [trans_row, trans_col] .* (img_support_sz./output_sz) * currentScaleFactor * scaleFactors(scale_ind);
scale_change_factor = scaleFactors(scale_ind);
% update position
old_pos = pos;
pos = sample_pos + translation_vec;
if params.clamp_position
pos = max([1 1], min([size(im,1) size(im,2)], pos));
end
% Do scale tracking with the scale filter
if nScales > 0 && params.use_scale_filter
scale_change_factor = scale_filter_track(im, pos, base_target_sz, currentScaleFactor, scale_filter, params);
end
% Update the scale
currentScaleFactor = currentScaleFactor * scale_change_factor;
% Adjust to make sure we are not to large or to small
if currentScaleFactor < min_scale_factor
currentScaleFactor = min_scale_factor;
elseif currentScaleFactor > max_scale_factor
currentScaleFactor = max_scale_factor;
end
iter = iter + 1;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Model update step
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Extract sample and init projection matrix
if frame == 1
% Extract image region for training sample
sample_pos = round(pos);
sample_scale = currentScaleFactor;
xl = extract_features(im, sample_pos, currentScaleFactor, features, global_fparams, feature_extract_info);
% Do windowing of features
xlw = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xl, cos_window, 'uniformoutput', false);
% Compute the fourier series
xlf = cellfun(@cfft2, xlw, 'uniformoutput', false);
% Interpolate features to the continuous domain
xlf = interpolate_dft(xlf, interp1_fs, interp2_fs);
% New sample to be added
xlf = compact_fourier_coeff(xlf);
% Initialize projection matrix
xl1 = cellfun(@(x) reshape(x, [], size(x,3)), xl, 'uniformoutput', false);
xl1 = cellfun(@(x) bsxfun(@minus, x, mean(x, 1)), xl1, 'uniformoutput', false);
if strcmpi(params.proj_init_method, 'pca')
[projection_matrix, ~, ~] = cellfun(@(x) svd(x' * x), xl1, 'uniformoutput', false);
projection_matrix = cellfun(@(P, dim) single(P(:,1:dim)), projection_matrix, compressed_dim_cell, 'uniformoutput', false);
elseif strcmpi(params.proj_init_method, 'rand_uni')
projection_matrix = cellfun(@(x, dim) single(randn(size(x,2), dim)), xl1, compressed_dim_cell, 'uniformoutput', false);
projection_matrix = cellfun(@(P) bsxfun(@rdivide, P, sqrt(sum(P.^2,1))), projection_matrix, 'uniformoutput', false);
elseif strcmpi(params.proj_init_method, 'none')
projection_matrix = [];
else
error('Unknown initialization method for the projection matrix: %s', params.proj_init_method);
end
clear xl1 xlw
% Shift sample
shift_samp = 2*pi * (pos - sample_pos) ./ (sample_scale * img_support_sz);
xlf = shift_sample(xlf, shift_samp, kx, ky);
% Project sample
xlf_proj = project_sample(xlf, projection_matrix);
elseif params.learning_rate > 0
if ~params.use_detection_sample
% Extract image region for training sample
sample_pos = round(pos);
sample_scale = currentScaleFactor;
xl = extract_features(im, sample_pos, currentScaleFactor, features, global_fparams, feature_extract_info);
% Project sample
xl_proj = project_sample(xl, projection_matrix);
% Do windowing of features
xl_proj = cellfun(@(feat_map, cos_window) bsxfun(@times, feat_map, cos_window), xl_proj, cos_window, 'uniformoutput', false);
% Compute the fourier series
xlf1_proj = cellfun(@cfft2, xl_proj, 'uniformoutput', false);
% Interpolate features to the continuous domain
xlf1_proj = interpolate_dft(xlf1_proj, interp1_fs, interp2_fs);
% New sample to be added
xlf_proj = compact_fourier_coeff(xlf1_proj);
else
% Use the sample that was used for detection
sample_scale = sample_scale(scale_ind);
xlf_proj = cellfun(@(xf) xf(:,1:(size(xf,2)+1)/2,:,scale_ind), xtf_proj, 'uniformoutput', false);
end
% Shift the sample so that the target is centered
shift_samp = 2*pi * (pos - sample_pos) ./ (sample_scale * img_support_sz);
xlf_proj = shift_sample(xlf_proj, shift_samp, kx, ky);
end
xlf_proj_perm = cellfun(@(xf) permute(xf, [4 3 1 2]), xlf_proj, 'uniformoutput', false);
if params.use_sample_merge
% Find the distances with existing samples
dist_vector = find_cluster_distances(samplesf, xlf_proj_perm, num_feature_blocks, num_training_samples, max_train_samples, params);
[merged_sample, new_cluster, merged_cluster_id, new_cluster_id, score_matrix, prior_weights,num_training_samples] = ...
merge_clusters(samplesf, xlf_proj_perm, dist_vector, score_matrix, prior_weights,...
num_training_samples,num_feature_blocks,max_train_samples,minimum_sample_weight,params);
else
% Do the traditional adding of a training sample and weight update
% of C-COT
[prior_weights, replace_ind] = update_prior_weights(prior_weights, sample_weights, latest_ind, frame, params);
latest_ind = replace_ind;
merged_cluster_id = 0;
new_cluster = xlf_proj_perm;
new_cluster_id = replace_ind;
end
if frame > 1 && params.learning_rate > 0 || frame == 1 && ~params.update_projection_matrix
% Insert the new training sample
for k = 1:num_feature_blocks
if merged_cluster_id > 0
samplesf{k}(merged_cluster_id,:,:,:) = merged_sample{k};
end
if new_cluster_id > 0
samplesf{k}(new_cluster_id,:,:,:) = new_cluster{k};
end
end
end
sample_weights = prior_weights;
train_tracker = (frame < params.skip_after_frame) || (frames_since_last_train >= params.train_gap);
if train_tracker
% Used for preconditioning
new_sample_energy = cellfun(@(xlf) abs(xlf .* conj(xlf)), xlf_proj, 'uniformoutput', false);
if frame == 1
if params.update_projection_matrix
hf = cell(2,1,num_feature_blocks);
lf_ind = cellfun(@(sz) sz(1) * (sz(2)-1)/2 + 1, filter_sz_cell, 'uniformoutput', false);
proj_energy = cellfun(@(P, yf) 2*sum(abs(yf(:)).^2) / sum(feature_dim) * ones(size(P), 'single'), projection_matrix, yf, 'uniformoutput', false);
else
hf = cell(1,1,num_feature_blocks);
end
% Initialize the filter
for k = 1:num_feature_blocks
hf{1,1,k} = complex(zeros([filter_sz(k,1) (filter_sz(k,2)+1)/2 compressed_dim(k)], 'single'));
end
% Initialize Conjugate Gradient parameters
CG_opts.maxit = params.init_CG_iter; % Number of initial iterations if projection matrix is not updated
init_CG_opts.maxit = ceil(params.init_CG_iter / params.init_GN_iter);
sample_energy = new_sample_energy;
rhs_samplef = cell(size(hf));
diag_M = cell(size(hf));
p = []; rho = []; r_old = [];
else
CG_opts.maxit = params.CG_iter;
if params.CG_forgetting_rate == inf || params.learning_rate >= 1
% CG will be reset
p = []; rho = []; r_old = [];
else
rho = rho / (1-params.learning_rate)^params.CG_forgetting_rate;
end
% Update the approximate average sample energy using the learning
% rate. This is only used to construct the preconditioner.
sample_energy = cellfun(@(se, nse) (1 - params.learning_rate) * se + params.learning_rate * nse, sample_energy, new_sample_energy, 'uniformoutput', false);
end
% Do training
if frame == 1 && params.update_projection_matrix
% Initial Gauss-Newton optimization of the filter and
% projection matrix.
% Construct stuff for the proj matrix part
init_samplef = cellfun(@(x) permute(x, [4 3 1 2]), xlf, 'uniformoutput', false);
init_samplef_H = cellfun(@(X) conj(reshape(X, size(X,2), [])), init_samplef, 'uniformoutput', false);
% Construct preconditioner
diag_M(1,1,:) = cellfun(@(m, reg_energy) (1-params.precond_reg_param) * bsxfun(@plus, params.precond_data_param * m, (1-params.precond_data_param) * mean(m,3)) + params.precond_reg_param*reg_energy, sample_energy, reg_energy, 'uniformoutput',false);
diag_M(2,1,:) = cellfun(@(m) params.precond_proj_param * (m + params.projection_reg), proj_energy, 'uniformoutput',false);
projection_matrix_init = projection_matrix;
for iter = 1:params.init_GN_iter
% Project sample with new matrix
init_samplef_proj = cellfun(@(x,P) mtimesx(x, P, 'speed'), init_samplef, projection_matrix, 'uniformoutput', false);
init_hf = cellfun(@(x) permute(x, [3 4 1 2]), hf(1,1,:), 'uniformoutput', false);
% Construct the right hand side vector for the filter part
rhs_samplef(1,1,:) = cellfun(@(xf, yf) bsxfun(@times, conj(permute(xf, [3 4 2 1])), yf), init_samplef_proj, yf, 'uniformoutput', false);
% Construct the right hand side vector for the projection matrix part
fyf = cellfun(@(f, yf) reshape(bsxfun(@times, conj(f), yf), [], size(f,3)), hf(1,1,:), yf, 'uniformoutput', false);
rhs_samplef(2,1,:) = cellfun(@(P, XH, fyf, fi) (2*real(XH * fyf - XH(:,fi:end) * fyf(fi:end,:)) - params.projection_reg * P), ...
projection_matrix, init_samplef_H, fyf, lf_ind, 'uniformoutput', false);
% Initialize the projection matrix increment to zero
hf(2,1,:) = cellfun(@(P) zeros(size(P), 'single'), projection_matrix, 'uniformoutput', false);
% do conjugate gradient
[hf, ~, ~, ~, res_norms_temp] = pcg_ccot(...
@(x) lhs_operation_joint(x, init_samplef_proj, reg_filter, feature_reg, init_samplef, init_samplef_H, init_hf, params.projection_reg),...
rhs_samplef, init_CG_opts, ...
@(x) diag_precond(x, diag_M), ...
[], hf);
% Make the filter symmetric (avoid roundoff errors)
hf(1,1,:) = symmetrize_filter(hf(1,1,:));
% Add to the projection matrix
projection_matrix = cellfun(@plus, projection_matrix, hf(2,1,:), 'uniformoutput', false);
res_norms = [res_norms; res_norms_temp];
end
% Extract filter
hf = hf(1,1,:);
% Re-project and insert training sample
xlf_proj = project_sample(xlf, projection_matrix);
for k = 1:num_feature_blocks
samplesf{k}(1,:,:,:) = permute(xlf_proj{k}, [4 3 1 2]);
end
else
% Construct the right hand side vector
rhs_samplef = cellfun(@(xf) permute(mtimesx(sample_weights, 'T', xf, 'speed'), [3 4 2 1]), samplesf, 'uniformoutput', false);
rhs_samplef = cellfun(@(xf, yf) bsxfun(@times, conj(xf), yf), rhs_samplef, yf, 'uniformoutput', false);
% Construct preconditioner
diag_M = cellfun(@(m, reg_energy) (1-params.precond_reg_param) * bsxfun(@plus, params.precond_data_param * m, (1-params.precond_data_param) * mean(m,3)) + params.precond_reg_param*reg_energy, sample_energy, reg_energy, 'uniformoutput',false);
% do conjugate gradient
[hf, ~, ~, ~, res_norms, p, rho, r_old] = pcg_ccot(...
@(x) lhs_operation(x, samplesf, reg_filter, sample_weights, feature_reg),...
rhs_samplef, CG_opts, ...
@(x) diag_precond(x, diag_M), ...
[], hf, p, rho, r_old);
end
% Reconstruct the full Fourier series
hf_full = full_fourier_coeff(hf);
frames_since_last_train = 0;
else
frames_since_last_train = frames_since_last_train+1;
end
% Update the scale filter
if nScales > 0 && params.use_scale_filter
scale_filter = scale_filter_update(im, pos, base_target_sz, currentScaleFactor, scale_filter, params);
end
% Update the target size (only used for computing output box)
target_sz = base_target_sz * currentScaleFactor;
%save position and calculate FPS
region = round([pos([2,1]) - (target_sz([2,1]) - 1)/2, target_sz([2,1])]);
region = double(region);
disp(region);
% **********************************
% VOT: Report position for frame
% **********************************
handle = handle.report(handle, region);
end;
% **********************************
% VOT: Output the results
% **********************************
handle.quit(handle);
end
function params = init_param(region)
cnn_params.nn_name = 'imagenet-vgg-m-2048-cut.mat'; % Name of the network
cnn_params.output_layer = [3 14];
cnn_params.downsample_factor = [2 1]; % How much to downsample each output layer
cnn_params.input_size_mode = 'adaptive'; % How to choose the sample size
cnn_params.input_size_scale = 1; % Extra scale factor of the input samples to the network (1 is no scaling)
cnn_params.use_gpu = true;
cnn_params.gpu_id = [3];
% Which features to include
params.t_features = {
struct('getFeature',@get_cnn_layers, 'fparams',cnn_params),...
};
% Global feature parameters1s
params.t_global.normalize_power = 2; % Lp normalization with this p
params.t_global.normalize_size = true; % Also normalize with respect to the spatial size of the feature
params.t_global.normalize_dim = true; % Also normalize with respect to the dimensionality of the feature
% Image sample parameters
params.search_area_shape = 'square'; % The shape of the samples
params.search_area_scale = 4.0; % The scaling of the target size to get the search area
params.min_image_sample_size = 200^2; % Minimum area of image samples
params.max_image_sample_size = 250^2; % Maximum area of image samples
% Detection parameters
params.refinement_iterations = 1; % Number of iterations used to refine the resulting position in a frame
params.newton_iterations = 5; % The number of Newton iterations used for optimizing the detection rere
params.clamp_position = false; % Clamp the target position to be inside the image
% Learning parameters
params.output_sigma_factor = 1/12; % Label function sigma
params.learning_rate = 0.012; % Learning rate
params.nSamples = 100; % Maximum number of stored training samples
params.sample_replace_strategy = 'lowest_prior'; % Which sample to replace when the memory is full
params.lt_size = 0; % The size of the long-term memory (where all samples have equal weight)
params.train_gap = 5; % The number of intermediate frames with no training (0 corresponds to training every frame)
params.skip_after_frame = 1; % After which frame number the sparse update scheme should start (1 is directly)
params.use_detection_sample = true; % Use the sample that was extracted at the detection stage also for learning
% Factorized convolution parameters
params.use_projection_matrix = true; % Use projection matrix, i.e. use the factorized convolution formulation
params.update_projection_matrix = true; % Whether the projection matrix should be optimized or not
params.proj_init_method = 'pca'; % Method for initializing the projection matrix
params.projection_reg = 2e-7; % Regularization paremeter of the projection matrix
% Generative sample space model parameters
params.use_sample_merge = true; % Use the generative sample space model to merge samples
params.sample_update_criteria = 'Merge'; % Strategy for updating the samples
params.weight_update_criteria = 'WeightedAdd'; % Strategy for updating the distance matrix
params.neglect_higher_frequency = false; % Neglect hiigher frequency components in the distance comparison for speed
% Conjugate Gradient parameters
params.CG_iter = 5; % The number of Conjugate Gradient iterations in each update after the first frame
params.init_CG_iter = 10*20; % The total number of Conjugate Gradient iterations used in the first frame
params.init_GN_iter = 10; % The number of Gauss-Newton iterations used in the first frame (only if the projection matrix is updated)
params.CG_use_FR = false; % Use the Fletcher-Reeves (true) or Polak-Ribiere (false) formula in the Conjugate Gradient
params.CG_standard_alpha = true; % Use the standard formula for computing the step length in Conjugate Gradient
params.CG_forgetting_rate = 75; % Forgetting rate of the last conjugate direction
params.precond_data_param = 0.7; % Weight of the data term in the preconditioner
params.precond_reg_param = 0.1; % Weight of the regularization term in the preconditioner
params.precond_proj_param = 30; % Weight of the projection matrix part in the preconditioner
% Regularization window parameters
params.use_reg_window = true; % Use spatial regularization or not
params.reg_window_min = 1e-4; % The minimum value of the regularization window
params.reg_window_edge = 10e-3; % The impact of the spatial regularization
params.reg_window_power = 2; % The degree of the polynomial to use (e.g. 2 is a quadratic window)
params.reg_sparsity_threshold = 0.12; % A relative threshold of which DFT coefficients that should be set to zero
% Interpolation parameters
params.interpolation_method = 'bicubic'; % The kind of interpolation kernel
params.interpolation_bicubic_a = -0.75; % The parameter for the bicubic interpolation kernel
params.interpolation_centering = true; % Center the kernel at the feature sample
params.interpolation_windowing = false; % Do additional windowing on the Fourier coefficients of the kernel
% Scale parameters for the translation model
% Only used if: params.use_scale_filter = false
params.use_scale_filter = false
params.number_of_scales = 10; % Number of scales to run the detector
params.scale_step = 1.03; % The scale factor
params.weights = [1, 2]; % The weights factor
params.weights_type = 'sigmoid'; % type: constant, sigmoid
params.divide_denominator = 100;
params.initial = 1;
params.factor = 0;
% Initialize
params.init_sz = [region(4), region(3)];
params.init_pos = [region(2), region(1)] + (params.init_sz - 1)/2;
end
|
github
|
he010103/CFWCR-master
|
vot.m
|
.m
|
CFWCR-master/vot2017_trax/vot.m
| 3,603 |
utf_8
|
306282b396b7bee687e83a489af86142
|
function [handle, image, region] = vot(format)
% vot Initialize communication and obtain communication structure
%
% This function is used to initialize communication with the toolkit.
%
% The resulting handle is a structure provides several functions for
% further interaction:
% - frame(handle): Get new frame from the sequence.
% - report(handle, region): Report region for current frame and advance.
% - quit(handle): Closes the communication and saves the data.
%
% Input:
% - format (string): Desired region input format.
%
% Output:
% - handle (structure): Updated communication handle structure.
% - image (string): Path to the first image file.
% - region (vector): Initial region encoded as a rectangle or as a polygon.
if nargin < 1
format = 'rectangle';
end
[handle, image, region] = tracker_initialize(format);
handle.frame = @tracker_frame;
handle.report = @tracker_report;
handle.quit = @tracker_quit;
end
function [handle, image, region] = tracker_initialize(format)
% tracker_initialize Initialize communication structure
%
% This function is used to initialize communication with the toolkit.
%
% Input:
% - format (string): Desired region input format.
%
% Output:
% - handle (structure): Updated communication handle structure.
% - image (string): Path to the first image file.
% - region (vector): Initial region encoded as a rectangle or as a polygon.
if ~ismember(format, {'rectangle', 'polygon'})
error('VOT: Illegal region format.');
end;
if ~isempty(getenv('TRAX_MEX'))
addpath(getenv('TRAX_MEX'));
end;
traxserver('setup', format, 'path');
[image, region] = traxserver('wait');
handle = struct('trax', true);
if isempty(image) || isempty(region)
tracker_quit(handle);
return;
end;
handle.initialization = region;
end
function [handle, image] = tracker_frame(handle)
% tracker_frame Get new frame from the sequence
%
% This function is used to get new frame from the current sequence
%
% Input:
% - handle (structure): Communication handle structure.
%
% Output:
% - handle (structure): Updated communication handle structure.
% - image (string): Path to image file.
if ~isstruct(handle)
error('VOT: Handle should be a structure.');
end;
if ~isempty(handle.initialization)
traxserver('status', handle.initialization);
handle.initialization = [];
end;
[image, region] = traxserver('wait');
if isempty(image) || ~isempty(region)
handle.quit(handle);
end;
end
function handle = tracker_report(handle, region)
% tracker_report Report region for current frame and advance
%
% This function stores the region for the current frame and advances
% the internal counter to the next frame.
%
% Input:
% - handle (structure): Communication handle structure.
% - region (vector): Predicted region as a rectangle or a polygon.
%
% Output:
% - handle (structure): Updated communication handle structure.
if isempty(region)
region = 0;
end;
if ~isstruct(handle)
error('VOT: Handle should be a structure.');
end;
if ~isempty(handle.initialization)
handle.initialization = [];
end;
traxserver('status', region);
end
function tracker_quit(handle)
% tracker_quit Closes the communication and saves the data
%
% This function closes the communication with the toolkit and
% saves the remaining data.
%
% Input:
% - handle (structure): Communication handle structure.
%
if ~isstruct(handle)
error('VOT: Handle should be a structure.');
end;
traxserver('quit');
end
|
github
|
he010103/CFWCR-master
|
mtimesx_test_ssspeed.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_test_ssspeed.m
| 415,311 |
utf_8
|
c663b5bc66edbfec752f88862a1805d1
|
% Test routine for mtimesx, op(single) * op(single) speed vs MATLAB
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_test_ssspeed
% Filename: mtimesx_test_ssspeed.m
% Programmer: James Tursa
% Version: 1.0
% Date: September 27, 2009
% Copyright: (c) 2009 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Syntax (arguments in brackets [ ] are optional):
%
% T = mtimesx_test_ddspeed( [N [,D]] )
%
% Inputs:
%
% N = Number of runs to make for each individual test. The test result will
% be the median of N runs. N must be even. If N is odd, it will be
% automatically increased to the next even number. The default is 10,
% which can take *hours* to run. Best to run this program overnight.
% D = The string 'details'. If present, this will cause all of the
% individual intermediate run results to print as they happen.
%
% Output:
%
% T = A character array containing a summary of the results.
%
%--------------------------------------------------------------------------
function ttable = mtimesx_test_ssspeed(nn,details)
global mtimesx_ttable
disp(' ');
disp('****************************************************************************');
disp('* *');
disp('* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *');
disp('* *');
disp('* This test program can take several *hours* to complete, particularly *');
disp('* when using the default number of runs as 10. It is strongly suggested *');
disp('* to close all applications and run this program overnight to get the *');
disp('* best possible result with minimal impacts to your computer usage. *');
disp('* *');
disp('* The program will be done when you see the message: DONE ! *');
disp('* *');
disp('****************************************************************************');
disp(' ');
try
input('Press Enter to start test, or Ctrl-C to exit ','s');
catch
ttable = '';
return
end
start_time = datenum(clock);
if nargin >= 1
n = nn;
else
n = 10;
end
if nargin < 2
details = false;
else
if( isempty(details) ) % code to get rid of the lint message
details = true;
else
details = true;
end
end
RC = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
compver = [computer ', ' version ', mtimesx mode ' mtimesx ', median of ' num2str(n) ' runs'];
k = length(compver);
nl = 199;
mtimesx_ttable = char([]);
mtimesx_ttable(1:nl,1:74) = ' ';
mtimesx_ttable(1,1:k) = compver;
mtimesx_ttable(2,:) = RC;
for r=3:(nl-2)
mtimesx_ttable(r,:) = ' -- -- -- --';
end
mtimesx_ttable(nl,1:6) = 'DONE !';
disp(' ');
disp(compver);
disp('Test program for function mtimesx:')
disp('----------------------------------');
rsave = 2;
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = single(rand(1,1));
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400));
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1));
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1));
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500));
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000));
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1));
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = single(rand(1,1));
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400));
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1));
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1));
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500));
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000));
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1));
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real).''');
disp(' ');
rsave = r;
mtimesx_ttable(r,:) = RC;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1));
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000));
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1));
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000));
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000));
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000));
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1));
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000));
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000));
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1));
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000));
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1));
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000));
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000));
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000));
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1));
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000));
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000));
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = single(rand(1,1));
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400));
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1));
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1));
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500));
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000));
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1));
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = single(rand(1,1));
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400));
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1));
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1));
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500));
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000));
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1));
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400));
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1));
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500));
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000));
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1));
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400));
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1));
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500));
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000));
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1));
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000));
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1));
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000));
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000));
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000));
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1));
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000));
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000));
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000));
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1));
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000));
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000));
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000));
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1));
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000));
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000));
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400));
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1));
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500));
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000));
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1));
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400));
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1));
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500));
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000));
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1));
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400));
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1));
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500));
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000));
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1));
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400));
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1));
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500));
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000));
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1));
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000));
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1));
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000));
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000));
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000));
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1));
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000));
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000));
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000));
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1));
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000));
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000));
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000));
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1));
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000));
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000));
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400));
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1));
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500));
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000));
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1));
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400));
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1));
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500));
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000));
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1));
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = single(rand(1,1));
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400));
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1));
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1));
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500));
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000));
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1));
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = single(rand(1,1));
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400));
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1));
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1));
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500));
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000));
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1));
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1));
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000));
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1));
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000));
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000));
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000));
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1));
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000));
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000));
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1));
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1));
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000));
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1));
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000));
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000));
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1));
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000));
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1));
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000));
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000));
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000));
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = single(rand(1,1));
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400));
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1));
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1));
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500));
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000));
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1));
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000));
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000));
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = single(rand(1,1));
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400));
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1));
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1));
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500));
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000));
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1));
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000));
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs ... symmetric cases op(A) * op(A)']);
disp(' ');
disp('real');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(2000));
maxtimesymCN('Matrix'' * Same ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymNC('Matrix * Same'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymTN('Matrix.'' * Same ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymNT('Matrix * Same.'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymGC('conj(Matrix) * Same'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymCG('Matrix'' * conj(Same)',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymGT('conj(Matrix) * Same.'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymTG('Matrix.'' * conj(Same)',A,n,details,r);
r = rsave;
disp(' ');
disp('complex');
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymCN('Matrix'' * Same ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymNC('Matrix * Same'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymTN('Matrix.'' * Same ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymNT('Matrix * Same.'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymGC('conj(Matrix) * Same'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymCG('Matrix'' * conj(Same)',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymGT('conj(Matrix) * Same.'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymTG('Matrix.'' * conj(Same)',A,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs ... special scalar cases']);
disp(' ');
disp('(scalar) * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(1);
B = single(rand(2500));
maxtimeNN('( 1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500));
maxtimeNN('( 1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500));
maxtimeNN('( 1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500));
maxtimeNN('( 1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = single(rand(2500));
maxtimeNN('(-1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500));
maxtimeNN('(-1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500));
maxtimeNN('(-1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500));
maxtimeNN('(-1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500));
maxtimeNN('( 2+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500));
maxtimeNN('( 2-1i) * Matrix ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(1);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('(-1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('(-1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('(-1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('(-1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 2+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 2-1i) * Matrix ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(1);
B = single(rand(2500));
maxtimeNC('( 1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500));
maxtimeNC('( 1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500));
maxtimeNC('( 1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500));
maxtimeNC('( 1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = single(rand(2500));
maxtimeNC('(-1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500));
maxtimeNC('(-1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500));
maxtimeNC('(-1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500));
maxtimeNC('(-1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500));
maxtimeNC('( 2+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500));
maxtimeNC('( 2-1i) * Matrix'' ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(1);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('(-1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('(-1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('(-1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('(-1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 2+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 2-1i) * Matrix'' ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(1);
B = single(rand(2500));
maxtimeNT('( 1+0i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500));
maxtimeNT('( 1+1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500));
maxtimeNT('( 1-1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500));
maxtimeNT('( 1+2i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = single(rand(2500));
maxtimeNT('(-1+0i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500));
maxtimeNT('(-1+1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500));
maxtimeNT('(-1-1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500));
maxtimeNT('(-1+2i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500));
maxtimeNT('( 2+1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500));
maxtimeNT('( 2-1i) * Matrix.'' ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(1);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('( 1+0i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('( 1+1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('( 1-1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('( 1+2i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('(-1+0i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('(-1+1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('(-1-1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('(-1+2i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('( 2+1i) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNT('( 2-1i) * Matrix.'' ',A,B,n,details,r);
disp(' ');
disp('(scalar) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(1);
B = single(rand(2500));
maxtimeNG('( 1+0i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500));
maxtimeNG('( 1+1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500));
maxtimeNG('( 1-1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500));
maxtimeNG('( 1+2i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = single(rand(2500));
maxtimeNG('(-1+0i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500));
maxtimeNG('(-1+1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500));
maxtimeNG('(-1-1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500));
maxtimeNG('(-1+2i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500));
maxtimeNG('( 2+1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500));
maxtimeNG('( 2-1i) * conj(Matrix) ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(1);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('( 1+0i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('( 1+1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('( 1-1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('( 1+2i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('(-1+0i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('(-1+1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('(-1-1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('(-1+2i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('( 2+1i) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxtimeNG('( 2-1i) * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(' --- DONE ! ---');
disp(' ');
disp(['Summary of Timing Tests, ' num2str(n) ' runs, + = percent faster, - = percent slower:']);
disp(' ');
mtimesx_ttable(1,1:k) = compver;
disp(mtimesx_ttable);
disp(' ');
ttable = mtimesx_ttable;
running_time(datenum(clock) - start_time);
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B;
mtoc(k) = toc;
tic;
mtimesx(A,B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B.';
mtoc(k) = toc;
tic;
mtimesx(A,B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B';
mtoc(k) = toc;
tic;
mtimesx(A,B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B;
mtoc(k) = toc;
tic;
mtimesx(A,'T',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B';
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B;
mtoc(k) = toc;
tic;
mtimesx(A,'C',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B';
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B;
mtoc(k) = toc;
tic;
mtimesx(A,'G',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B';
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymCN(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*A;
mtoc(k) = toc;
tic;
mtimesx(A,'C',A);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymNC(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*A';
mtoc(k) = toc;
tic;
mtimesx(A,A,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymTN(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*A;
mtoc(k) = toc;
tic;
mtimesx(A,'T',A);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymNT(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*A.';
mtoc(k) = toc;
tic;
mtimesx(A,A,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymCG(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*conj(A);
mtoc(k) = toc;
tic;
mtimesx(A,'C',A,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymGC(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*A';
mtoc(k) = toc;
tic;
mtimesx(A,'G',A,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymTG(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*conj(A);
mtoc(k) = toc;
tic;
mtimesx(A,'T',A,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymGT(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*A.';
mtoc(k) = toc;
tic;
mtimesx(A,'G',A,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeout(T,A,B,p,r)
global mtimesx_ttable
mtimesx_ttable(r,1:length(T)) = T;
if( isreal(A) && isreal(B) )
lt = length(T);
b = repmat(' ',1,30-lt);
x = [T b sprintf('%10.0f%%',-p)];
mtimesx_ttable(r,1:length(x)) = x;
elseif( isreal(A) && ~isreal(B) )
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,42:41+length(x)) = x;
elseif( ~isreal(A) && isreal(B) )
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,53:52+length(x)) = x;
else
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymout(T,A,p,r)
global mtimesx_ttable
if( isreal(A) )
lt = length(T);
b = repmat(' ',1,30-lt);
x = [T b sprintf('%10.0f%%',-p)];
mtimesx_ttable(r,1:length(x)) = x;
else
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,1:length(T)) = T;
mtimesx_ttable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function running_time(d)
h = 24*d;
hh = floor(h);
m = 60*(h - hh);
mm = floor(m);
s = 60*(m - mm);
ss = floor(s);
disp(' ');
rt = sprintf('Running time hh:mm:ss = %2.0f:%2.0f:%2.0f',hh,mm,ss);
if( rt(28) == ' ' )
rt(28) = '0';
end
if( rt(31) == ' ' )
rt(31) = '0';
end
disp(rt);
disp(' ');
return
end
|
github
|
he010103/CFWCR-master
|
mtimesx_build.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_build.m
| 16,162 |
utf_8
|
1133797528213727d31a9a075188a4d0
|
% mtimesx_build compiles mtimesx.c with BLAS libraries
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_build
% Filename: mtimesx_build.m
% Programmer: James Tursa
% Version: 1.40
% Date: October 4, 2010
% Copyright: (c) 2009, 2010 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
%--
%
% mtimesx_build compiles mtimesx.c and mtimesx_RealTimesReal.c with the BLAS
% libraries libmwblas.lib (if present) or libmwlapack.lib (if libmwblas.lib
% is not present). This function basically works as follows:
%
% - Opens the current mexopts.bat file in the directory [prefdir], and
% checks to make sure that the compiler selected is cl or lcc. If it
% is not, then a warning is issued and the compilation continues with
% the assumption that the microsoft BLAS libraries will work.
%
% - Looks for the file libmwblas.lib or libmwlapack.lib files in the
% appropriate directory: [matlabroot '\extern\lib\win32\microsoft']
% or [matlabroot '\extern\lib\win32\lcc']
% or [matlabroot '\extern\lib\win64\microsoft']
% or [matlabroot '\extern\lib\win64\lcc']
%
% - Changes directory to the directory of the file mtimesx.m.
%
% - Compiles mtimesx.c (which includes mtimesx_RealTimesReal.c) along with
% either libmwblas.lib or libmwlapack.lib depending on the version of
% MATLAB. The resulting exedcutable mex file is placed in the same
% directory as the source code. The files mtimesx.m, mtimesx.c, and
% mtimesx_RealTimesReal.c must all be in the same directory.
%
% - Changes the directory back to the original directory.
%
% Change Log:
% 2009/Sep/27 --> 1.00, Initial Release
% 2010/Feb/15 --> 1.10, Fixed largearrardims typo to largeArrayDims
% 2010/Oct/04 --> 1.40, Updated support for OpenMP compiling
%
%**************************************************************************
function mtimesx_build(x)
disp(' ');
disp('... Build routine for mtimesx');
TRUE = 1;
FALSE = 0;
%\
% Check for number of inputs & outputs
%/
noopenmp = FALSE;
if( nargin == 1 )
if( isequal(upper(x),'NOOPENMP') )
noopenmp = TRUE;
else
error('Invalid input.');
end
elseif( nargin ~= 0 )
error('Too many inputs. Expected none.');
end
if( nargout ~= 0 )
error('Too many outputs. Expected none.');
end
%\
% Check for non-PC
%/
disp('... Checking for PC');
try
% ispc does not appear in MATLAB 5.3
pc = ispc ;
catch
% if ispc fails, assume we are on a Windows PC if it's not unix
pc = ~isunix ;
end
if( ~pc )
disp('building linux version');
mex('mtimesx.c','-DDEFINEUNIX','-largeArrayDims','-lmwblas');
return;
end
%\
% Check to see that mtimesx.c source code is present
%/
disp('... Finding path of mtimesx C source code files');
try
mname = mfilename('fullpath');
catch
mname = mfilename;
end
cname = [mname(1:end-6) '.c'];
if( isempty(dir(cname)) )
disp('Cannot find the file mtimesx.c in the same directory as the');
disp('file mtimesx_build.m. Please ensure that they are in the same');
disp('directory and try again. The following file was not found:');
disp(' ');
disp(cname);
disp(' ');
error('Unable to compile mtimesx.c');
end
disp(['... Found file mtimesx.c in ' cname]);
%\
% Check to see that mtimesx_RealTimesReal.c source code is present
%/
rname = [mname(1:end-13) 'mtimesx_RealTimesReal.c'];
if( isempty(dir(rname)) )
disp('Cannot find the file mtimesx_RealTimesReal.c in the same');
disp('directory as the file mtimesx_build.m. Please ensure that');
disp('they are in the same directory and try again. The');
disp('following file was not found:');
disp(' ');
disp(rname);
disp(' ');
error('Unable to compile mtimesx.c');
end
disp(['... Found file mtimesx_RealTimesReal.c in ' rname]);
%\
% Open the current mexopts.bat file
%/
matlab_ver = version('-release');
if str2num(matlab_ver(1:4)) >= 2014
mexopts = [prefdir '\mex_C++_win64.xml'];
else
mexopts = [prefdir '\mexopts.bat'];
end
fid = fopen(mexopts);
if( fid == -1 )
error('A C/C++ compiler has not been selected with mex -setup');
end
disp(['... Opened the mexopts.bat file in ' mexopts]);
disp('... Reading the mexopts.bat file to find the compiler and options used.');
%\
% Check for the correct compiler selected.
%/
ok_cl = FALSE;
ok_lcc = FALSE;
omp_option = '';
compiler = '(unknown)';
compilername = '';
while( TRUE )
tline = fgets(fid);
if( isequal(tline,-1) )
break;
else
if( isempty(compilername) )
y = findstr(tline,'OPTS.BAT');
if( ~isempty(y) )
x = findstr(tline,'rem ');
if( ~isempty(x) )
compilername = tline(x+4:y-1);
end
end
end
x = findstr(tline,'COMPILER=lcc');
if( ~isempty(x) )
ok_lcc = TRUE;
libdir = 'lcc';
compiler = 'LCC';
disp(['... ' compiler ' is the selected compiler']);
break;
end
x = findstr(tline,'COMPILER=cl');
if( ~isempty(x) )
ok_cl = TRUE;
libdir = 'microsoft';
compiler = ['Microsoft_' compilername '_cl'];
omp_option = ' /openmp';
disp(['... ' compiler ' is the selected compiler']);
break;
end
x = findstr(tline,'COMPILER=bcc32');
if( ~isempty(x) )
ok_cl = TRUE;
libdir = 'microsoft';
compiler = ['Borland_' compilername '_bcc32'];
disp(['... ' compiler ' is the selected compiler']);
disp('... Assuming that Borland will link with Microsoft libraries');
break;
end
x = findstr(tline,'COMPILER=icl');
if( ~isempty(x) )
ok_cl = TRUE;
if( pc )
omp_option = ' -Qopenmp';
else
omp_option = ' -openmp';
end
libdir = 'microsoft';
compiler = ['Intel_' compilername '_icl'];
disp(['... ' compiler ' is the selected compiler']);
disp('... Assuming that Intel will link with Microsoft libraries');
break;
end
x = findstr(tline,'COMPILER=wc1386');
if( ~isempty(x) )
ok_cl = TRUE;
libdir = 'microsoft';
compiler = ['Watcom_' compilername '_wc1386'];
disp(['... ' compiler ' is the selected compiler']);
disp('... Assuming that Watcom will link with Microsoft libraries');
break;
end
x = findstr(tline,'COMPILER=gcc');
if( ~isempty(x) )
ok_cl = TRUE;
libdir = 'microsoft';
omp_option = ' -fopenmp';
compiler = 'GCC';
disp(['... ' compiler ' is the selected compiler']);
disp('... Assuming that GCC will link with Microsoft libraries');
break;
end
end
end
fclose(fid);
%\
% MS Visual C/C++ or lcc compiler has not been selected
%/
if( ~(ok_cl | ok_lcc) )
warning('... Supported C/C++ compiler has not been selected with mex -setup');
warning('... Assuming that Selected Compiler will link with Microsoft libraries');
warning('... Continuing at risk ...');
libdir = 'microsoft';
end
%\
% If an OpenMP supported compiler is potentially present, make sure that the
% necessary compile option is present in the mexopts.bat file on the COMPFLAGS
% line. If necessary, build a new mexopts.bat file with the correct option
% added to the COMPFLAGS line.
%/
while( TRUE )
ok_openmp = FALSE;
ok_compflags = FALSE;
xname = '';
if( isempty(omp_option) )
disp('... OpenMP compiler not detected ... you may want to check this website:');
disp(' http://openmp.org/wp/openmp-compilers/');
elseif( noopenmp )
disp(['... OpenMP compiler potentially detected, but not checking for ''' omp_option ''' compile option']);
else
disp('... OpenMP compiler potentially detected');
disp(['... Checking to see that the ''' omp_option ''' compile option is present']);
fid = fopen(mexopts);
while( TRUE )
tline = fgets(fid);
if( isequal(tline,-1) )
break;
else
x = findstr(tline,'set COMPFLAGS');
if( ~isempty(x) )
ok_compflags = TRUE;
x = findstr(tline,omp_option);
if( ~isempty(x) )
ok_openmp = TRUE;
end
break;
end
end
end
fclose(fid);
if( ~ok_compflags )
warning(['... COMPFLAGS line not found ... ''' omp_option ''' will not be added.']);
elseif( ~ok_openmp )
disp(['... The ''' omp_option ''' compile option is not present ... adding it']);
xname = [mname(1:end-6) '_mexopts.bat'];
disp(['... Creating custom options file ' xname ' with the ''' omp_option ''' option added.']);
fid = fopen(mexopts);
fidx = fopen(xname,'w');
if( fidx == -1 )
xname = '';
warning(['... Unable to create custom mexopts.bat file ... ''' omp_option ''' will not be added']);
else
while( TRUE )
tline = fgets(fid);
if( isequal(tline,-1) )
break;
else
x = findstr(tline,'set COMPFLAGS');
if( ~isempty(x) )
n = numel(tline);
e = n;
while( tline(e) < 32 )
e = e - 1;
end
tline = [tline(1:e) omp_option tline(e+1:n)];
end
fwrite(fidx,tline);
end
end
fclose(fidx);
end
fclose(fid);
end
end
%\
% Construct full file name of libmwblas.lib and libmwlapack.lib. Note that
% not all versions have both files. Earlier versions only had the lapack
% file, which contained both blas and lapack routines.
%/
comp = computer;
mext = mexext;
lc = length(comp);
lm = length(mext);
cbits = comp(max(1:lc-1):lc);
mbits = mext(max(1:lm-1):lm);
if( isequal(cbits,'64') | isequal(mbits,'64') )
compdir = 'win64';
largearraydims = '-largeArrayDims';
else
compdir = 'win32';
largearraydims = '';
end
lib_blas = [matlabroot '\extern\lib\' compdir '\' libdir '\libmwblas.lib'];
d = dir(lib_blas);
if( isempty(d) )
disp('... BLAS library file not found, so linking with the LAPACK library');
lib_blas = [matlabroot '\extern\lib\' compdir '\' libdir '\libmwlapack.lib'];
end
disp(['... Using BLAS library lib_blas = ''' lib_blas '''']);
%\
% Save old directory and change to source code directory
%/
cdold = cd;
if( length(mname) > 13 )
cd(mname(1:end-13));
end
%\
% Do the compile
%/
disp('... Now attempting to compile ...');
disp(' ');
try
if( isunix )
if( isempty(largearraydims) )
if( isempty(xname) )
disp(['mex(''-DDEFINEUNIX'',''' cname ''',lib_blas,''-DCOMPILER=' compiler ''')']);
disp(' ');
mex('-DDEFINEUNIX',cname,lib_blas,['-DCOMPILER=' compiler]);
else
disp(['mex(''-f'',''' xname ''',''-DDEFINEUNIX'',''' cname ''',lib_blas,''-DCOMPILER=' compiler ''')']);
disp(' ');
mex('-f',xname,'-DDEFINEUNIX',cname,lib_blas,['-DCOMPILER=' compiler]);
end
else
if( isempty(xname) )
disp(['mex(''-DDEFINEUNIX'',''' cname ''',''' largearraydims ''',lib_blas,''-DCOMPILER=' compiler ''')']);
disp(' ');
mex('-DDEFINEUNIX',largearraydims,cname,lib_blas,['-DCOMPILER=' compiler]);
else
disp(['mex(''-f'',''' xname ''',''-DDEFINEUNIX'',''' cname ''',''' largearraydims ''',lib_blas,''-DCOMPILER=' compiler ''')']);
disp(' ');
mex('-f',xname,'-DDEFINEUNIX',largearraydims,cname,lib_blas,['-DCOMPILER=' compiler]);
end
end
else
if( isempty(largearraydims) )
if( isempty(xname) )
disp(['mex(''' cname ''',lib_blas,''-DCOMPILER=' compiler ''')']);
disp(' ');
mex(cname,lib_blas,['-DCOMPILER=' compiler]);
else
disp(['mex(''-f'',''' xname ''',''' cname ''',lib_blas,''-DCOMPILER=' compiler ''')']);
disp(' ');
mex('-f',xname,cname,lib_blas,['-DCOMPILER=' compiler]);
end
else
if( isempty(xname) )
disp(['mex(''' cname ''',''' largearraydims ''',lib_blas,''-DCOMPILER=' compiler ''')']);
disp(' ');
mex(cname,largearraydims,lib_blas,['-DCOMPILER=' compiler]);
else
disp(['mex(''-f'',''' xname ''',''' cname ''',''' largearraydims ''',lib_blas,''-DCOMPILER=' compiler ''')']);
disp(' ');
mex('-f',xname,cname,largearraydims,lib_blas,['-DCOMPILER=' compiler]);
end
end
end
disp('... mex mtimesx.c build completed ... you may now use mtimesx.');
disp(' ');
mtimesx;
break;
catch
if( noopenmp )
cd(cdold);
disp(' ');
disp('... Well, *that* didn''t work either!');
disp(' ');
disp('The mex command failed. This may be because you have already run');
disp('mex -setup and selected a non-C compiler, such as Fortran. If this');
disp('is the case, then rerun mex -setup and select a C/C++ compiler.');
disp(' ');
error('Unable to compile mtimesx.c');
else
disp(' ');
disp('... Well, *that* didn''t work ...');
disp(' ');
if( isequal(omp_option,' /openmp') )
disp('This may be because an OpenMP compile option was added that the');
disp('compiler did not like. For example, the Standard versions of the');
disp('Microsoft C/C++ compilers do not support OpenMP, only the');
disp('Professional versions do. Attempting to compile again but this');
disp(['time will not add the ''' omp_option ''' option.'])
else
disp('This may be because an OpenMP compile option was added that the');
disp('compiler did not like. Attempting to compile again, but this time');
disp(['will not add the ''' omp_option ''' option.'])
end
disp(' ');
noopenmp = TRUE;
end
end
end
%\
% Restore old directory
%/
cd(cdold);
return
end
|
github
|
he010103/CFWCR-master
|
mtimesx_test_nd.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_test_nd.m
| 14,364 |
utf_8
|
0d3b436cea001bccb9c6cccdaa21b34d
|
% Test routine for mtimesx, multi-dimensional speed and equality to MATLAB
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_test_nd
% Filename: mtimesx_test_nd.m
% Programmer: James Tursa
% Version: 1.40
% Date: October 4, 2010
% Copyright: (c) 2009,2010 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Syntax:
%
% A = mtimesx_test_nd % default n=4 is used
% A = mtimesx_test_nd(n)
%
% where n = number of repetitions (should be 4 <= n <= 100)
%
% Output:
%
% Prints out speed and equality test results.
% A = cell array with tabled results.
%
% 2010/Oct/04 --> 1.40, Added OpenMP support for custom code
% Expanded sparse * single and sparse * nD support
%
%--------------------------------------------------------------------------
function Cr = mtimesx_test_nd(n)
mtimesx; % load the mex routine into memory
if( nargin == 0 )
n = 4;
else
n = floor(n);
if( ~(n >= 4 && n <= 100) )
n = 4;
end
end
cn = sprintf('%g',n);
disp(' ');
disp('MTIMESX multi-dimensional equality and speed tests');
disp('--------------------------------------------------');
disp(' ');
disp('(M x K) * ( K x N) equality tests, SPEED mode, M,K,N <= 4');
trans = 'NGTC';
cmpx = {'real ','cmpx '};
mtimesx('speed');
smallok = true;
for m=1:4
for k=1:4
for n=1:4
for transa=1:4
if( transa <= 2 )
ma = m;
ka = k;
else
ma = k;
ka = m;
end
for transb=1:4
if( transb <= 2 )
kb = k;
nb = n;
else
kb = n;
nb = k;
end
for cmplxa=1:2
if( cmplxa == 1 )
A = floor(rand(ma,ka)*100+1);
else
A = floor(rand(ma,ka)*100+1) + floor(rand(ma,ka)*100+1)*1i;
end
for cmplxb=1:2
if( cmplxb == 1 )
B = floor(rand(kb,nb)*100+1);
else
B = floor(rand(kb,nb)*100+1) + floor(rand(kb,nb)*100+1)*1i;
end
Cm = mtimesx_sparse(A,trans(transa),B,trans(transb));
Cx = mtimesx(A,trans(transa),B,trans(transb));
if( isequal(Cm,Cx) )
disp(['(' cmpx{cmplxa} num2str(m) ' x ' num2str(k) ')' trans(transa) ...
' * (' cmpx{cmplxb} num2str(k) ' x ' num2str(n) ')' trans(transb) ' EQUAL']);
else
disp(['(' cmpx{cmplxa} num2str(m) ' x ' num2str(k) ')' trans(transa) ...
' * (' cmpx{cmplxb} num2str(k) ' x ' num2str(n) ')' trans(transb) ' NOT EQUAL']);
smallok = false;
end
end
end
end
end
end
end
end
if( mtimesx('openmp') )
disp(' ');
disp('(M x K) * ( K x N) equality tests, SPEEDOMP mode, M,K,N <= 4');
mtimesx('speedomp');
smallokomp = true;
for m=1:4
for k=1:4
for n=1:4
for transa=1:4
if( transa <= 2 )
ma = m;
ka = k;
else
ma = k;
ka = m;
end
for transb=1:4
if( transb <= 2 )
kb = k;
nb = n;
else
kb = n;
nb = k;
end
for cmplxa=1:2
if( cmplxa == 1 )
A = floor(rand(ma,ka)*100+1);
else
A = floor(rand(ma,ka)*100+1) + floor(rand(ma,ka)*100+1)*1i;
end
A = reshape(repmat(A,1000,1),ma,ka,1000);
for cmplxb=1:2
if( cmplxb == 1 )
B = floor(rand(kb,nb)*100+1);
else
B = floor(rand(kb,nb)*100+1) + floor(rand(kb,nb)*100+1)*1i;
end
B = reshape(repmat(B,1000,1),kb,nb,1000);
Cm = mtimesx_sparse(A(:,:,1),trans(transa),B(:,:,1),trans(transb));
Cx = mtimesx(A,trans(transa),B,trans(transb));
if( isequal(Cm,Cx(:,:,1)) )
disp(['(' cmpx{cmplxa} num2str(m) ' x ' num2str(k) ')' trans(transa) ...
' * (' cmpx{cmplxb} num2str(k) ' x ' num2str(n) ')' trans(transb) ' EQUAL']);
else
disp(['(' cmpx{cmplxa} num2str(m) ' x ' num2str(k) ')' trans(transa) ...
' * (' cmpx{cmplxb} num2str(k) ' x ' num2str(n) ')' trans(transb) ' NOT EQUAL']);
smallokomp = false;
end
end
end
end
end
end
end
end
end
disp(' ');
if( smallok )
disp('All small matrix multiplies are OK in SPEED mode');
else
disp('ERROR --> One or more of the small matrix multiplies was not equal in SPEED mode');
end
if( mtimesx('openmp') )
if( smallokomp )
disp('All small matrix multiplies are OK in SPEEDOMP mode');
else
disp('ERROR --> One or more of the small matrix multiplies was not equal in SPEEDOMP mode');
end
end
disp(' ');
disp(['mtimesx multi-dimensional test routine using ' cn ' repetitions']);
if( mtimesx('OPENMP') )
topm = 6;
else
topm = 4;
end
Cr = cell(6,topm+1);
Cr{1,1} = 'All operands real';
for m=2:topm+1
if( m == 2 )
mtimesx('BLAS');
elseif( m == 3 )
mtimesx('LOOPS');
elseif( m == 4 )
mtimesx('MATLAB');
elseif( m == 5 )
mtimesx('SPEED');
elseif( m == 6 )
mtimesx('LOOPSOMP');
else
mtimesx('SPEEDOMP');
end
Cr{1,m} = mtimesx;
disp(' ');
disp('--------------------------------------------------------------');
disp('--------------------------------------------------------------');
disp(' ');
disp(['MTIMESX mode: ' mtimesx]);
disp(' ');
disp('(real 3x5x1x4x3x2x1x8) * (real 5x7x3x1x3x2x5) example');
Cr{2,1} = '(3x5xND) *(5x7xND)';
A = rand(3,5,1,4,3,2,1,8);
B = rand(5,7,3,1,3,2,5);
% mtimes
tm = zeros(1,n);
for k=1:n
clear Cm
A(1) = 2*A(1);
B(1) = 2*B(1);
tic
Cm = zeros(3,7,3,4,3,2,5,8);
for k1=1:3
for k2=1:4
for k3=1:3
for k4=1:2
for k5=1:5
for k6=1:8
Cm(:,:,k1,k2,k3,k4,k5,k6) = A(:,:,1,k2,k3,k4,1,k6) * B(:,:,k1,1,k3,k4,k5);
end
end
end
end
end
end
tm(k) = toc;
end
% mtimesx
tx = zeros(1,n);
for k=1:n
clear Cx
tic
Cx = mtimesx(A,B);
tx(k) = toc;
end
% results
tm = median(tm);
tx = median(tx);
if( tx < tm )
faster = sprintf('%7.1f',100*(tm)/tx-100);
slower = '';
else
faster = sprintf('%7.1f',-(100*(tx)/tm-100));
slower = ' (i.e., slower)';
end
Cr{2,m} = faster;
disp(' ');
disp(['mtimes Elapsed time ' num2str(tm) ' seconds.']);
disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']);
disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB mtimes' slower])
if( isequal(Cx,Cm) )
disp(['MTIMESX ' mtimesx ' mode result matches mtimes: EQUAL'])
else
dx = max(abs(Cx(:)-Cm(:)));
disp(['MTIMESX ' mtimesx ' mode result does not match mtimes: NOT EQUAL , max diff = ' num2str(dx)])
end
disp(' ');
disp('--------------------------------------------------------------');
disp('(real 3x3x1000000) * (real 3x3x1000000) example');
Cr{3,1} = '(3x3xN) *(3x3xN)';
A = rand(3,3,1000000);
B = rand(3,3,1000000);
% mtimes
tm = zeros(1,n);
for k=1:n
clear Cm
A(1) = 2*A(1);
B(1) = 2*B(1);
tic
Cm = zeros(3,3,1000000);
for k1=1:1000000
Cm(:,:,k1) = A(:,:,k1) * B(:,:,k1);
end
tm(k) = toc;
end
% mtimesx
tx = zeros(1,n);
for k=1:n
clear Cx
tic
Cx = mtimesx(A,B);
tx(k) = toc;
end
% results
tm = median(tm);
tx = median(tx);
if( tx < tm )
faster = sprintf('%7.1f',100*(tm)/tx-100);
slower = '';
else
faster = sprintf('%7.1f',-(100*(tx)/tm-100));
slower = ' (i.e., slower)';
end
Cr{3,m} = faster;
disp(' ');
disp(['mtimes Elapsed time ' num2str(tm) ' seconds.']);
disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']);
disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB mtimes' slower])
if( isequal(Cx,Cm) )
disp(['MTIMESX ' mtimesx ' mode result matches mtimes: EQUAL'])
else
dx = max(abs(Cx(:)-Cm(:)));
disp(['MTIMESX ' mtimesx ' mode result does not match mtimes: NOT EQUAL , max diff = ' num2str(dx)])
end
disp(' ');
disp('--------------------------------------------------------------');
disp('(real 2x2x2000000) * (real 2x2x2000000) example');
Cr{4,1} = '(2x2xN) *(2x2xN)';
A = rand(2,2,2000000);
B = rand(2,2,2000000);
% mtimes
tm = zeros(1,n);
for k=1:n
clear Cm
A(1) = 2*A(1);
B(1) = 2*B(1);
tic
Cm = zeros(2,2,2000000);
for k1=1:2000000
Cm(:,:,k1) = A(:,:,k1) * B(:,:,k1);
end
tm(k) = toc;
end
% mtimesx
tx = zeros(1,n);
for k=1:n
clear Cx
tic
Cx = mtimesx(A,B);
tx(k) = toc;
end
% results
tm = median(tm);
tx = median(tx);
if( tx < tm )
faster = sprintf('%7.1f',100*(tm)/tx-100);
slower = '';
else
faster = sprintf('%7.1f',-(100*(tx)/tm-100));
slower = ' (i.e., slower)';
end
Cr{4,m} = faster;
disp(' ');
disp(['mtimes Elapsed time ' num2str(tm) ' seconds.']);
disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']);
disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB mtimes' slower])
if( isequal(Cx,Cm) )
disp(['MTIMESX ' mtimesx ' mode result matches mtimes: EQUAL'])
else
dx = max(abs(Cx(:)-Cm(:)));
disp(['MTIMESX ' mtimesx ' mode result does not match mtimes: NOT EQUAL , max diff = ' num2str(dx)])
end
disp(' ');
disp('--------------------------------------------------------------');
disp('(real 2x2x2000000) * (real 1x1x2000000) example');
Cr{5,1} = '(2x2xN) *(1x1xN)';
A = rand(2,2,2000000);
B = rand(1,1,2000000);
% mtimes
tm = zeros(1,n);
for k=1:n
clear Cm
A(1) = 2*A(1);
B(1) = 2*B(1);
tic
Cm = zeros(2,2,2000000);
for k1=1:2000000
Cm(:,:,k1) = A(:,:,k1) * B(:,:,k1);
end
tm(k) = toc;
end
% mtimesx
tx = zeros(1,n);
for k=1:n
clear Cx
tic
Cx = mtimesx(A,B);
tx(k) = toc;
end
% results
tm = median(tm);
tx = median(tx);
if( tx < tm )
faster = sprintf('%7.1f',100*(tm)/tx-100);
slower = '';
else
faster = sprintf('%7.1f',-(100*(tx)/tm-100));
slower = ' (i.e., slower)';
end
Cr{5,m} = faster;
disp(' ');
disp(['mtimes Elapsed time ' num2str(tm) ' seconds.']);
disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']);
disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB mtimes' slower])
if( isequal(Cx,Cm) )
disp(['MTIMESX ' mtimesx ' mode result matches mtimes: EQUAL'])
else
dx = max(abs(Cx(:)-Cm(:)));
disp(['MTIMESX ' mtimesx ' mode result does not match mtimes: NOT EQUAL , max diff = ' num2str(dx)])
end
try
bsxfun(@times,1,1);
Cr{6,1} = 'above vs bsxfun';
A = rand(2,2,2000000);
B = rand(1,1,2000000);
% bsxfun
tm = zeros(1,n);
for k=1:n
clear Cm
A(1) = 2*A(1);
B(1) = 2*B(1);
tic
Cm = bsxfun(@times,A,B);
tm(k) = toc;
end
% mtimesx
tx = zeros(1,n);
for k=1:n
clear Cx
tic
Cx = mtimesx(A,B);
tx(k) = toc;
end
% results
tm = median(tm);
tx = median(tx);
if( tx < tm )
faster = sprintf('%7.1f',100*(tm)/tx-100);
slower = '';
else
faster = sprintf('%7.1f',-(100*(tx)/tm-100));
slower = ' (i.e., slower)';
end
Cr{6,m} = faster;
disp(' ');
disp(['bsxfun Elapsed time ' num2str(tm) ' seconds.']);
disp(['MTIMESX Elapsed time ' num2str(tx) ' seconds.']);
disp(['MTIMESX ' mtimesx ' mode is ' faster '% faster than MATLAB bsxfun with @times' slower])
if( isequal(Cx,Cm) )
disp(['MTIMESX ' mtimesx ' mode result matches bsxfun with @times: EQUAL'])
else
dx = max(abs(Cx(:)-Cm(:)));
disp(['MTIMESX ' mtimesx ' mode result does not match bsxfun with @times: NOT EQUAL , max diff = ' num2str(dx)])
end
catch
disp('Could not perform comparison with bsxfun, possibly because your version of');
disp('MATLAB does not have it. You can download a substitute for bsxfun from the');
disp('FEX here: http://www.mathworks.com/matlabcentral/fileexchange/23005-bsxfun-substitute');
end
end
disp(' ');
disp('Percent Faster Results Table');
disp(' ');
disp(Cr);
disp(' ');
disp('Done');
disp(' ');
end
|
github
|
he010103/CFWCR-master
|
mtimesx_test_sdequal.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_test_sdequal.m
| 350,821 |
utf_8
|
7e6a367b3ad6154ce1e4da70a91ba4cf
|
% Test routine for mtimesx, op(single) * op(double) equality vs MATLAB
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_test_sdequal
% Filename: mtimesx_test_sdequal.m
% Programmer: James Tursa
% Version: 1.0
% Date: September 27, 2009
% Copyright: (c) 2009 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Syntax:
%
% T = mtimesx_test_ddequal
%
% Output:
%
% T = A character array containing a summary of the results.
%
%--------------------------------------------------------------------------
function dtable = mtimesx_test_sdequal
global mtimesx_dtable
disp(' ');
disp('****************************************************************************');
disp('* *');
disp('* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *');
disp('* *');
disp('* This test program can take an hour or so to complete. It is suggested *');
disp('* that you close all applications and run this program during your lunch *');
disp('* break or overnight to minimize impacts to your computer usage. *');
disp('* *');
disp('* The program will be done when you see the message: DONE ! *');
disp('* *');
disp('****************************************************************************');
disp(' ');
try
input('Press Enter to start test, or Ctrl-C to exit ','s');
catch
dtable = '';
return
end
start_time = datenum(clock);
compver = [computer ', ' version ', mtimesx mode ' mtimesx];
k = length(compver);
RC = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
mtimesx_dtable = char([]);
mtimesx_dtable(157,74) = ' ';
mtimesx_dtable(1,1:k) = compver;
mtimesx_dtable(2,:) = RC;
for r=3:157
mtimesx_dtable(r,:) = ' -- -- -- --';
end
disp(' ');
disp(compver);
disp('Test program for function mtimesx:')
disp('----------------------------------');
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real)');
disp(' ');
rsave = 2;
r = rsave;
%if( false ) % debug jump
if( isequal([]*[],mtimesx([],[])) )
disp('Empty * Empty EQUAL');
else
disp('Empty * Empty NOT EQUAL <---');
end
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000);
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = rand(1,1);
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40);
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1);
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1);
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500);
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000);
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1);
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = rand(1,1) + rand(1,1)*1i;
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1) + rand(1,1)*1i;
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = rand(1,1);
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40);
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1);
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500);
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000);
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1);
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNN('Matrix * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real).''');
disp(' ');
if( isequal([]*[].',mtimesx([],[],'T')) )
disp('Empty * Empty.'' EQUAL');
else
disp('Empty * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(10000,1);
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1);
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000);
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1);
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000);
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000);
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1) + rand(1,1)*1i;
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000);
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1);
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000);
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000);
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real)''');
disp(' ');
if( isequal([]*[]',mtimesx([],[],'C')) )
disp('Empty * Empty'' EQUAL');
else
disp('Empty * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(10000,1);
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1);
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000);
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1);
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000);
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000);
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1) + rand(1,1)*1i;
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000);
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1);
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000);
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000);
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNC('Matrix * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * conj(real)');
disp(' ');
%if( false ) % debug jump
if( isequal([]*conj([]),mtimesx([],[],'G')) )
disp('Empty * conj(Empty) EQUAL');
else
disp('Empty * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000);
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = rand(1,1);
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40);
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1);
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1);
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500);
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000);
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1);
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = rand(1,1) + rand(1,1)*1i;
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1) + rand(1,1)*1i;
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj((real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = rand(1,1);
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40);
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1);
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500);
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000);
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1);
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real)');
disp(' ');
if( isequal([]'*[],mtimesx([],'C',[])) )
disp('Empty.'' * Empty EQUAL');
else
disp('Empty.'' * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000);
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40);
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1);
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500);
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000);
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1);
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40);
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1);
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500);
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000);
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1);
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real).''');
disp(' ');
if( isequal([].'*[]',mtimesx([],'T',[],'C')) )
disp('Empty.'' * Empty.'' EQUAL');
else
disp('Empty.'' * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(10000,1);
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000);
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1);
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000);
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000);
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000);
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1);
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000);
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000);
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real)''');
disp(' ');
if( isequal([].'*[]',mtimesx([],'T',[],'C')) )
disp('Empty.'' * Empty'' EQUAL');
else
disp('Empty.'' * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(10000,1);
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000);
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1);
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000);
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000);
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000);
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1);
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000);
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000);
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * conj(real)');
disp(' ');
if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) )
disp('Empty.'' * conj(Empty) EQUAL');
else
disp('Empty.'' * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000);
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40);
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1);
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500);
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000);
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1);
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40);
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1);
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500);
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000);
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1);
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real)');
disp(' ');
if( isequal([]'*[],mtimesx([],'C',[])) )
disp('Empty'' * Empty EQUAL');
else
disp('Empty'' * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000);
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40);
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1);
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500);
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000);
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1);
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40);
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1);
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500);
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000);
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1);
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCN('Matrix'' * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real).''');
disp(' ');
if( isequal([]'*[]',mtimesx([],'C',[],'C')) )
disp('Empty'' * Empty.'' EQUAL');
else
disp('Empty'' * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(10000,1);
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000);
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1);
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000);
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000);
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000);
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1);
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000);
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000);
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real)''');
disp(' ');
if( isequal([]'*[]',mtimesx([],'C',[],'C')) )
disp('Empty'' * Empty'' EQUAL');
else
disp('Empty'' * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(10000,1);
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000);
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1);
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000);
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000);
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000);
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1);
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000);
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000);
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * conj(real)');
disp(' ');
if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) )
disp('Empty'' * conj(Empty) EQUAL');
else
disp('Empty'' * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000);
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40);
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1);
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500);
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000);
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1);
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40);
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1);
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500);
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000);
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1);
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real)');
disp(' ');
if( isequal(conj([])*[],mtimesx([],'G',[])) )
disp('conj(Empty) * Empty EQUAL');
else
disp('conj(Empty) * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000);
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = rand(1,1);
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40);
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1);
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1);
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500);
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000);
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1);
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = rand(1,1) + rand(1,1)*1i;
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1) + rand(1,1)*1i;
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = rand(1,1);
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40);
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1);
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500);
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000);
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1);
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real).''');
disp(' ');
if( isequal(conj([])*[].',mtimesx([],'G',[],'T')) )
disp('conj(Empty) * Empty.'' EQUAL');
else
disp('conj(Empty) * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(10000,1);
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1);
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000);
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1);
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000);
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000);
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1) + rand(1,1)*1i;
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000);
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1);
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000);
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000);
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real)''');
disp(' ');
if( isequal(conj([])*[]',mtimesx([],'G',[],'C')) )
disp('conj(Empty) * Empty'' EQUAL');
else
disp('conj(Empty) * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(10000,1);
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1);
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1);
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000);
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1);
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000);
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000);
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = rand(1,1) + rand(1,1)*1i;
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1) + rand(1,1)*1i;
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1);
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000);
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1);
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000);
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000);
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * conj(real)');
disp(' ');
if( isequal(conj([])*conj([]),mtimesx([],'G',[],'G')) )
disp('conj(Empty) * conj(Empty) EQUAL');
else
disp('conj(Empty) * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000);
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = rand(1,1);
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40);
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1);
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1);
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500);
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000);
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1);
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000);
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = rand(1,1) + rand(1,1)*1i;
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = rand(1,1) + rand(1,1)*1i;
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000);
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = rand(1,1);
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40);
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1);
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500);
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000);
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1);
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000);
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ... symmetric cases op(A) * op(A)');
disp(' ');
disp('real');
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(2000));
maxdiffsymCN('Matrix'' * Same ',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymNC('Matrix * Same''',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymTN('Matrix.'' * Same ',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymNT('Matrix * Same.''',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymGC('conj(Matrix) * Same''',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymCG('Matrix'' * conj(Same)',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymGT('conj(Matrix) * Same.'' ',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymTG('Matrix.'' * conj(Same)',A,r);
r = rsave;
disp(' ' );
disp('complex');
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymCN('Matrix'' * Same ',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymNC('Matrix * Same''',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymTN('Matrix.'' * Same ',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymNT('Matrix * Same.''',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymGC('conj(Matrix) * Same''',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymCG('Matrix'' * conj(Same)',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymGT('conj(Matrix) * Same.''',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymTG('Matrix.'' * conj(Same)',A,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ... special scalar cases');
disp(' ');
disp('(scalar) * (real)');
disp(' ');
r = r + 1;
mtimesx_dtable(r,:) = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
rsave = r;
r = r + 1;
A = single(1);
B = rand(2500);
maxdiffNN('( 1+0i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 + 1i);
B = rand(2500);
maxdiffNN('( 1+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 - 1i);
B = rand(2500);
maxdiffNN('( 1-1i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 + 2i);
B = rand(2500);
maxdiffNN('( 1+2i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1);
B = rand(2500);
maxdiffNN('(-1+0i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 + 1i);
B = rand(2500);
maxdiffNN('(-1+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 - 1i);
B = rand(2500);
maxdiffNN('(-1-1i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 + 2i);
B = rand(2500);
maxdiffNN('(-1+2i) * Matrix ',A,B,r);
r = r + 1;
A = single(2 + 1i);
B = rand(2500);
maxdiffNN('( 2+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(2 - 1i);
B = rand(2500);
maxdiffNN('( 2-1i) * Matrix ',A,B,r);
disp(' ');
disp('(scalar) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(1);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 1+0i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 + 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 1+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 - 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 1-1i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 + 2i);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 1+2i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('(-1+0i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 + 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('(-1+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 - 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('(-1-1i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 + 2i);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('(-1+2i) * Matrix ',A,B,r);
r = r + 1;
A = single(2 + 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 2+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(2 - 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 2-1i) * Matrix ',A,B,r);
disp(' ');
disp('(scalar) * (complex)''');
disp(' ');
%r = rsave;
r = r + 1;
A = single(1);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 1+0i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(1 + 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 1+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(1 - 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 1-1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(1 + 2i);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 1+2i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(-1);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('(-1+0i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(-1 + 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('(-1+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(-1 - 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('(-1-1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(-1 + 2i);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('(-1+2i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(2 + 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 2+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(2 - 1i);
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 2-1i) * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(' --- DONE ! ---');
disp(' ');
disp('Summary of Numerical Comparison Tests, max relative element difference:');
disp(' ');
mtimesx_dtable(1,1:k) = compver;
disp(mtimesx_dtable);
disp(' ');
dtable = mtimesx_dtable;
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNN(T,A,B,r)
Cm = A*B;
Cx = mtimesx(A,B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCN(T,A,B,r)
Cm = A'*B;
Cx = mtimesx(A,'C',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTN(T,A,B,r)
Cm = A.'*B;
Cx = mtimesx(A,'T',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGN(T,A,B,r)
Cm = conj(A)*B;
Cx = mtimesx(A,'G',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNC(T,A,B,r)
Cm = A*B';
Cx = mtimesx(A,B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCC(T,A,B,r)
Cm = A'*B';
Cx = mtimesx(A,'C',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTC(T,A,B,r)
Cm = A.'*B';
Cx = mtimesx(A,'T',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGC(T,A,B,r)
Cm = conj(A)*B';
Cx = mtimesx(A,'G',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNT(T,A,B,r)
Cm = A*B.';
Cx = mtimesx(A,B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCT(T,A,B,r)
Cm = A'*B.';
Cx = mtimesx(A,'C',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTT(T,A,B,r)
Cm = A.'*B.';
Cx = mtimesx(A,'T',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGT(T,A,B,r)
Cm = conj(A)*B.';
Cx = mtimesx(A,'G',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNG(T,A,B,r)
Cm = A*conj(B);
Cx = mtimesx(A,B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCG(T,A,B,r)
Cm = A'*conj(B);
Cx = mtimesx(A,'C',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTG(T,A,B,r)
Cm = A.'*conj(B);
Cx = mtimesx(A,'T',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGG(T,A,B,r)
Cm = conj(A)*conj(B);
Cx = mtimesx(A,'G',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymCN(T,A,r)
Cm = A'*A;
Cx = mtimesx(A,'C',A);
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymNC(T,A,r)
Cm = A*A';
Cx = mtimesx(A,A,'C');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymTN(T,A,r)
Cm = A.'*A;
Cx = mtimesx(A,'T',A);
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymNT(T,A,r)
Cm = A*A.';
Cx = mtimesx(A,A,'T');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymTG(T,A,r)
Cm = A.'*conj(A);
Cx = mtimesx(A,'T',A,'G');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymGT(T,A,r)
Cm = conj(A)*A.';
Cx = mtimesx(A,'G',A,'T');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymCG(T,A,r)
Cm = A'*conj(A);
Cx = mtimesx(A,'C',A,'G');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymGC(T,A,r)
Cm = conj(A)*A';
Cx = mtimesx(A,'G',A,'C');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffout(T,A,B,Cm,Cx,r)
global mtimesx_dtable
lt = length(T);
b = repmat(' ',1,30-lt);
if( isequal(Cm,Cx) )
disp([T b ' EQUAL']);
d = 0;
else
Cm = Cm(:);
Cx = Cx(:);
if( isreal(Cm) && isreal(Cx) )
rx = Cx ~= Cm;
d = max(abs((Cx(rx)-Cm(rx))./Cm(rx)));
else
Cmr = real(Cm);
Cmi = imag(Cm);
Cxr = real(Cx);
Cxi = imag(Cx);
rx = Cxr ~= Cmr;
ix = Cxi ~= Cmi;
dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx)))));
di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix)))));
if( isempty(dr) )
d = di;
elseif( isempty(di) )
d = dr;
else
d = max(dr,di);
end
end
disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]);
end
mtimesx_dtable(r,1:length(T)) = T;
if( isreal(A) && isreal(B) )
if( d == 0 )
x = [T b ' 0'];
else
x = [T b sprintf('%11.2e',d)];
end
mtimesx_dtable(r,1:length(x)) = x;
elseif( isreal(A) && ~isreal(B) )
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,42:41+length(x)) = x;
elseif( ~isreal(A) && isreal(B) )
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,53:52+length(x)) = x;
else
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymout(T,A,Cm,Cx,r)
global mtimesx_dtable
lt = length(T);
b = repmat(' ',1,30-lt);
if( isequal(Cm,Cx) )
disp([T b ' EQUAL']);
d = 0;
else
Cm = Cm(:);
Cx = Cx(:);
if( isreal(Cm) && isreal(Cx) )
rx = Cx ~= Cm;
d = max(abs((Cx(rx)-Cm(rx))./Cm(rx)));
else
Cmr = real(Cm);
Cmi = imag(Cm);
Cxr = real(Cx);
Cxi = imag(Cx);
rx = Cxr ~= Cmr;
ix = Cxi ~= Cmi;
dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx)))));
di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix)))));
if( isempty(dr) )
d = di;
elseif( isempty(di) )
d = dr;
else
d = max(dr,di);
end
end
disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]);
end
if( isreal(A) )
if( d == 0 )
x = [T b ' 0'];
else
x = [T b sprintf('%11.2e',d)];
end
mtimesx_dtable(r,1:length(x)) = x;
else
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,1:length(T)) = T;
mtimesx_dtable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function running_time(d)
h = 24*d;
hh = floor(h);
m = 60*(h - hh);
mm = floor(m);
s = 60*(m - mm);
ss = floor(s);
disp(' ');
rt = sprintf('Running time hh:mm:ss = %2.0f:%2.0f:%2.0f',hh,mm,ss);
if( rt(28) == ' ' )
rt(28) = '0';
end
if( rt(31) == ' ' )
rt(31) = '0';
end
disp(rt);
disp(' ');
return
end
|
github
|
he010103/CFWCR-master
|
mtimesx_test_ddequal.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_test_ddequal.m
| 94,229 |
utf_8
|
219fa3623cf14a54da7d267a29e61151
|
% Test routine for mtimesx, op(double) * op(double) equality vs MATLAB
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_test_ddequal
% Filename: mtimesx_test_ddequal.m
% Programmer: James Tursa
% Version: 1.0
% Date: September 27, 2009
% Copyright: (c) 2009 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Syntax:
%
% T = mtimesx_test_ddequal
%
% Output:
%
% T = A character array containing a summary of the results.
%
%--------------------------------------------------------------------------
function dtable = mtimesx_test_ddequal
global mtimesx_dtable
disp(' ');
disp('****************************************************************************');
disp('* *');
disp('* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *');
disp('* *');
disp('* This test program can take an hour or so to complete. It is suggested *');
disp('* that you close all applications and run this program during your lunch *');
disp('* break or overnight to minimize impacts to your computer usage. *');
disp('* *');
disp('* The program will be done when you see the message: DONE ! *');
disp('* *');
disp('****************************************************************************');
disp(' ');
input('Press Enter to start test, or Ctrl-C to exit ','s');
start_time = datenum(clock);
compver = [computer ', ' version ', mtimesx mode ' mtimesx];
k = length(compver);
RC = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
mtimesx_dtable = char([]);
mtimesx_dtable(162,74) = ' ';
mtimesx_dtable(1,1:k) = compver;
mtimesx_dtable(2,:) = RC;
for r=3:162
mtimesx_dtable(r,:) = ' -- -- -- --';
end
disp(' ');
disp(compver);
disp('Test program for function mtimesx:')
disp('----------------------------------');
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real)');
disp(' ');
rsave = 2;
r = rsave;
%if( false ) % debug jump
if( isequal([]*[],mtimesx([],[])) )
disp('Empty * Empty EQUAL');
else
disp('Empty * Empty NOT EQUAL <---');
end
r = r + 1;
A = rand(1,1);
B = rand(1,10000);
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = rand(1,1);
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40);
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1);
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1);
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500);
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000);
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1);
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = rand(1,1);
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40);
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1);
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500);
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000);
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1);
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNN('Matrix * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real).''');
disp(' ');
if( isequal([]*[].',mtimesx([],[],'T')) )
disp('Empty * Empty.'' EQUAL');
else
disp('Empty * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(10000,1);
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1);
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000);
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1);
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000);
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000);
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000);
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1);
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000);
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000);
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real)''');
disp(' ');
if( isequal([]*[]',mtimesx([],[],'C')) )
disp('Empty * Empty'' EQUAL');
else
disp('Empty * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(10000,1);
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1);
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000);
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1);
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000);
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000);
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000);
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1);
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000);
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000);
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNC('Matrix * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * conj(real)');
disp(' ');
%if( false ) % debug jump
if( isequal([]*conj([]),mtimesx([],[],'G')) )
disp('Empty * conj(Empty) EQUAL');
else
disp('Empty * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000);
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = rand(1,1);
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40);
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1);
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1);
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500);
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000);
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1);
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1) + rand(1,1)*1i;
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj((real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = rand(1,1);
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40);
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1);
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500);
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000);
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1);
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real)');
disp(' ');
if( isequal([]'*[],mtimesx([],'C',[])) )
disp('Empty.'' * Empty EQUAL');
else
disp('Empty.'' * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(1,10000);
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40);
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1);
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500);
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000);
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1);
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40);
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1);
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500);
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000);
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1);
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real).''');
disp(' ');
if( isequal([].'*[]',mtimesx([],'T',[],'C')) )
disp('Empty.'' * Empty.'' EQUAL');
else
disp('Empty.'' * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(10000,1);
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000);
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1);
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000);
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000);
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000);
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1);
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000);
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000);
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real)''');
disp(' ');
if( isequal([].'*[]',mtimesx([],'T',[],'C')) )
disp('Empty.'' * Empty'' EQUAL');
else
disp('Empty.'' * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(10000,1);
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000);
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1);
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000);
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000);
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000);
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1);
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000);
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000);
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * conj(real)');
disp(' ');
if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) )
disp('Empty.'' * conj(Empty) EQUAL');
else
disp('Empty.'' * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(1,10000);
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40);
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1);
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500);
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000);
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1);
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40);
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1);
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500);
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000);
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1);
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real)');
disp(' ');
if( isequal([]'*[],mtimesx([],'C',[])) )
disp('Empty'' * Empty EQUAL');
else
disp('Empty'' * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(1,10000);
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40);
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1);
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500);
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000);
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1);
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40);
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1);
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500);
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000);
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1);
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCN('Matrix'' * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real).''');
disp(' ');
if( isequal([]'*[]',mtimesx([],'C',[],'C')) )
disp('Empty'' * Empty.'' EQUAL');
else
disp('Empty'' * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(10000,1);
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000);
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1);
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000);
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000);
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000);
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1);
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000);
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000);
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real)''');
disp(' ');
if( isequal([]'*[]',mtimesx([],'C',[],'C')) )
disp('Empty'' * Empty'' EQUAL');
else
disp('Empty'' * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(10000,1);
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000);
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1);
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000);
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000);
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000);
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1);
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000);
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000);
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * conj(real)');
disp(' ');
if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) )
disp('Empty'' * conj(Empty) EQUAL');
else
disp('Empty'' * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(1,10000);
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40);
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1);
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500);
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000);
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1);
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40);
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1);
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500);
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000);
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1);
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real)');
disp(' ');
if( isequal(conj([])*[],mtimesx([],'G',[])) )
disp('conj(Empty) * Empty EQUAL');
else
disp('conj(Empty) * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000);
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = rand(1,1);
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40);
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1);
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1);
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500);
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000);
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1);
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = rand(1,1);
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40);
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1);
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500);
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000);
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1);
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real).''');
disp(' ');
if( isequal(conj([])*[].',mtimesx([],'G',[],'T')) )
disp('conj(Empty) * Empty.'' EQUAL');
else
disp('conj(Empty) * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(10000,1);
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1);
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000);
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1);
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000);
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000);
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000);
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1);
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000);
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000);
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real)''');
disp(' ');
if( isequal(conj([])*[]',mtimesx([],'G',[],'C')) )
disp('conj(Empty) * Empty'' EQUAL');
else
disp('conj(Empty) * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(10000,1);
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1);
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1);
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000);
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1);
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000);
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000);
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1);
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000);
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1);
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000);
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000);
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1,1000) + rand(1,1000)*1i;
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * conj(real)');
disp(' ');
if( isequal(conj([])*conj([]),mtimesx([],'G',[],'G')) )
disp('conj(Empty) * conj(Empty) EQUAL');
else
disp('conj(Empty) * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = rand(1,10000);
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = rand(1,1);
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40);
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1);
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1);
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500);
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000);
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1);
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000);
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = rand(1,1) + rand(1,1)*1i;
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000);
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = rand(1,1);
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40);
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1);
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500);
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000);
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1);
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000);
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,10000) + rand(1,10000)*1i;
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,40) + rand(10,20,30,40)*1i;
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1) + rand(1000,1)*1i;
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = rand(1000,1000) + rand(1000,1000)*1i;
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ... symmetric cases op(A) * op(A)');
disp(' ');
disp('real');
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(2000);
maxdiffsymCN('Matrix'' * Same ',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymNC('Matrix * Same''',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymTN('Matrix.'' * Same ',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymNT('Matrix * Same.''',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymGC('conj(Matrix) * Same''',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymCG('Matrix'' * conj(Same)',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymGT('conj(Matrix) * Same.'' ',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymTG('Matrix.'' * conj(Same)',A,r);
r = rsave;
disp(' ' );
disp('complex');
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymCN('Matrix'' * Same ',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymNC('Matrix * Same''',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymTN('Matrix.'' * Same ',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymNT('Matrix * Same.''',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymGC('conj(Matrix) * Same''',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymCG('Matrix'' * conj(Same)',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymGT('conj(Matrix) * Same.''',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymTG('Matrix.'' * conj(Same)',A,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ... special scalar cases');
disp(' ');
disp('(scalar) * (real)');
disp(' ');
r = r + 1;
mtimesx_dtable(r,:) = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
rsave = r;
r = r + 1;
A = 1;
B = rand(2500);
maxdiffNN('( 1+0i) * Matrix ',A,B,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500);
maxdiffNN('( 1+1i) * Matrix ',A,B,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500);
maxdiffNN('( 1-1i) * Matrix ',A,B,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500);
maxdiffNN('( 1+2i) * Matrix ',A,B,r);
r = r + 1;
A = -1;
B = rand(2500);
maxdiffNN('(-1+0i) * Matrix ',A,B,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500);
maxdiffNN('(-1+1i) * Matrix ',A,B,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500);
maxdiffNN('(-1-1i) * Matrix ',A,B,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500);
maxdiffNN('(-1+2i) * Matrix ',A,B,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500);
maxdiffNN('( 2+1i) * Matrix ',A,B,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500);
maxdiffNN('( 2-1i) * Matrix ',A,B,r);
disp(' ');
disp('(scalar) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = 1;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 1+0i) * Matrix ',A,B,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 1+1i) * Matrix ',A,B,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 1-1i) * Matrix ',A,B,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 1+2i) * Matrix ',A,B,r);
r = r + 1;
A = -1;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('(-1+0i) * Matrix ',A,B,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('(-1+1i) * Matrix ',A,B,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('(-1-1i) * Matrix ',A,B,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('(-1+2i) * Matrix ',A,B,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 2+1i) * Matrix ',A,B,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNN('( 2-1i) * Matrix ',A,B,r);
disp(' ');
disp('(scalar) * (complex)''');
disp(' ');
%r = rsave;
r = r + 1;
A = 1;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 1+0i) * Matrix'' ',A,B,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 1+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 1-1i) * Matrix'' ',A,B,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 1+2i) * Matrix'' ',A,B,r);
r = r + 1;
A = -1;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('(-1+0i) * Matrix'' ',A,B,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('(-1+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('(-1-1i) * Matrix'' ',A,B,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('(-1+2i) * Matrix'' ',A,B,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 2+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500) + rand(2500)*1i;
maxdiffNC('( 2-1i) * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ... special (scalar) * (sparse) cases');
disp('Real * Real, Real * Cmpx, Cmpx * Real, Cmpx * Cmpx');
disp(' ');
r = r + 1;
mtimesx_dtable(r,:) = RC;
% rsave = r;
r = r + 1;
A = rand(1,1);
B = sprand(5000,5000,.1);
maxdiffNN('Scalar * Sparse',A,B,r);
A = rand(1,1);
B = sprand(5000,5000,.1); B = B + B*2i;
maxdiffNN('Scalar * Sparse',A,B,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1);
maxdiffNN('Scalar * Sparse',A,B,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1); B = B + B*2i;
maxdiffNN('Scalar * Sparse',A,B,r);
r = r + 1;
A = rand(1,1);
B = sprand(5000,5000,.1);
maxdiffNT('Scalar * Sparse.''',A,B,r);
A = rand(1,1);
B = sprand(5000,5000,.1); B = B + B*2i;
maxdiffNT('Scalar * Sparse.''',A,B,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1);
maxdiffNT('Scalar * Sparse.''',A,B,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1); B = B + B*2i;
maxdiffNT('Scalar * Sparse.''',A,B,r);
r = r + 1;
A = rand(1,1);
B = sprand(5000,5000,.1);
maxdiffNC('Scalar * Sparse''',A,B,r);
A = rand(1,1);
B = sprand(5000,5000,.1); B = B + B*2i;
maxdiffNC('Scalar * Sparse''',A,B,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1);
maxdiffNC('Scalar * Sparse''',A,B,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1); B = B + B*2i;
maxdiffNC('Scalar * Sparse''',A,B,r);
r = r + 1;
A = rand(1,1);
B = sprand(5000,5000,.1);
maxdiffNG('Scalar * conj(Sparse)',A,B,r);
A = rand(1,1);
B = sprand(5000,5000,.1); B = B + B*2i;
maxdiffNG('Scalar * conj(Sparse)',A,B,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1);
maxdiffNG('Scalar * conj(Sparse)',A,B,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1); B = B + B*2i;
maxdiffNG('Scalar * conj(Sparse)',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(' --- DONE ! ---');
disp(' ');
disp('Summary of Numerical Comparison Tests, max relative element difference:');
disp(' ');
mtimesx_dtable(1,1:k) = compver;
disp(mtimesx_dtable);
disp(' ');
dtable = mtimesx_dtable;
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNN(T,A,B,r)
Cm = A*B;
Cx = mtimesx(A,B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCN(T,A,B,r)
Cm = A'*B;
Cx = mtimesx(A,'C',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTN(T,A,B,r)
Cm = A.'*B;
Cx = mtimesx(A,'T',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGN(T,A,B,r)
Cm = conj(A)*B;
Cx = mtimesx(A,'G',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNC(T,A,B,r)
Cm = A*B';
Cx = mtimesx(A,B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCC(T,A,B,r)
Cm = A'*B';
Cx = mtimesx(A,'C',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTC(T,A,B,r)
Cm = A.'*B';
Cx = mtimesx(A,'T',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGC(T,A,B,r)
Cm = conj(A)*B';
Cx = mtimesx(A,'G',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNT(T,A,B,r)
Cm = A*B.';
Cx = mtimesx(A,B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCT(T,A,B,r)
Cm = A'*B.';
Cx = mtimesx(A,'C',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTT(T,A,B,r)
Cm = A.'*B.';
Cx = mtimesx(A,'T',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGT(T,A,B,r)
Cm = conj(A)*B.';
Cx = mtimesx(A,'G',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNG(T,A,B,r)
Cm = A*conj(B);
Cx = mtimesx(A,B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCG(T,A,B,r)
Cm = A'*conj(B);
Cx = mtimesx(A,'C',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTG(T,A,B,r)
Cm = A.'*conj(B);
Cx = mtimesx(A,'T',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGG(T,A,B,r)
Cm = conj(A)*conj(B);
Cx = mtimesx(A,'G',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymCN(T,A,r)
Cm = A'*A;
Cx = mtimesx(A,'C',A);
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymNC(T,A,r)
Cm = A*A';
Cx = mtimesx(A,A,'C');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymTN(T,A,r)
Cm = A.'*A;
Cx = mtimesx(A,'T',A);
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymNT(T,A,r)
Cm = A*A.';
Cx = mtimesx(A,A,'T');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymTG(T,A,r)
Cm = A.'*conj(A);
Cx = mtimesx(A,'T',A,'G');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymGT(T,A,r)
Cm = conj(A)*A.';
Cx = mtimesx(A,'G',A,'T');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymCG(T,A,r)
Cm = A'*conj(A);
Cx = mtimesx(A,'C',A,'G');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymGC(T,A,r)
Cm = conj(A)*A';
Cx = mtimesx(A,'G',A,'C');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffout(T,A,B,Cm,Cx,r)
global mtimesx_dtable
lt = length(T);
b = repmat(' ',1,30-lt);
if( isequal(Cm,Cx) )
disp([T b ' EQUAL']);
d = 0;
else
Cm = Cm(:);
Cx = Cx(:);
if( isreal(Cm) && isreal(Cx) )
rx = Cx ~= Cm;
d = max(abs((Cx(rx)-Cm(rx))./Cm(rx)));
else
Cmr = real(Cm);
Cmi = imag(Cm);
Cxr = real(Cx);
Cxi = imag(Cx);
rx = Cxr ~= Cmr;
ix = Cxi ~= Cmi;
dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx)))));
di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix)))));
if( isempty(dr) )
d = di;
elseif( isempty(di) )
d = dr;
else
d = max(dr,di);
end
end
disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]);
end
mtimesx_dtable(r,1:length(T)) = T;
if( isreal(A) && isreal(B) )
if( d == 0 )
x = [T b ' 0'];
else
x = [T b sprintf('%11.2e',d)];
end
mtimesx_dtable(r,1:length(x)) = x;
elseif( isreal(A) && ~isreal(B) )
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,42:41+length(x)) = x;
elseif( ~isreal(A) && isreal(B) )
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,53:52+length(x)) = x;
else
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymout(T,A,Cm,Cx,r)
global mtimesx_dtable
lt = length(T);
b = repmat(' ',1,30-lt);
if( isequal(Cm,Cx) )
disp([T b ' EQUAL']);
d = 0;
else
Cm = Cm(:);
Cx = Cx(:);
if( isreal(Cm) && isreal(Cx) )
rx = Cx ~= Cm;
d = max(abs((Cx(rx)-Cm(rx))./Cm(rx)));
else
Cmr = real(Cm);
Cmi = imag(Cm);
Cxr = real(Cx);
Cxi = imag(Cx);
rx = Cxr ~= Cmr;
ix = Cxi ~= Cmi;
dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx)))));
di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix)))));
if( isempty(dr) )
d = di;
elseif( isempty(di) )
d = dr;
else
d = max(dr,di);
end
end
disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]);
end
if( isreal(A) )
if( d == 0 )
x = [T b ' 0'];
else
x = [T b sprintf('%11.2e',d)];
end
mtimesx_dtable(r,1:length(x)) = x;
else
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,1:length(T)) = T;
mtimesx_dtable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function running_time(d)
h = 24*d;
hh = floor(h);
m = 60*(h - hh);
mm = floor(m);
s = 60*(m - mm);
ss = floor(s);
disp(' ');
rt = sprintf('Running time hh:mm:ss = %2.0f:%2.0f:%2.0f',hh,mm,ss);
if( rt(28) == ' ' )
rt(28) = '0';
end
if( rt(31) == ' ' )
rt(31) = '0';
end
disp(rt);
disp(' ');
return
end
|
github
|
he010103/CFWCR-master
|
mtimesx_test_dsequal.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_test_dsequal.m
| 350,693 |
utf_8
|
325490ae690791eb9f0e7d03408cc540
|
% Test routine for mtimesx, op(double) * op(single) equality vs MATLAB
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_test_dsequal
% Filename: mtimesx_test_dsequal.m
% Programmer: James Tursa
% Version: 1.0
% Date: September 27, 2009
% Copyright: (c) 2009 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Syntax:
%
% T = mtimesx_test_ddequal
%
% Output:
%
% T = A character array containing a summary of the results.
%
%--------------------------------------------------------------------------
function dtable = mtimesx_test_dsequal
global mtimesx_dtable
disp(' ');
disp('****************************************************************************');
disp('* *');
disp('* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *');
disp('* *');
disp('* This test program can take an hour or so to complete. It is suggested *');
disp('* that you close all applications and run this program during your lunch *');
disp('* break or overnight to minimize impacts to your computer usage. *');
disp('* *');
disp('* The program will be done when you see the message: DONE ! *');
disp('* *');
disp('****************************************************************************');
disp(' ');
try
input('Press Enter to start test, or Ctrl-C to exit ','s');
catch
dtable = '';
return
end
start_time = datenum(clock);
compver = [computer ', ' version ', mtimesx mode ' mtimesx];
k = length(compver);
RC = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
mtimesx_dtable = char([]);
mtimesx_dtable(157,74) = ' ';
mtimesx_dtable(1,1:k) = compver;
mtimesx_dtable(2,:) = RC;
for r=3:157
mtimesx_dtable(r,:) = ' -- -- -- --';
end
disp(' ');
disp(compver);
disp('Test program for function mtimesx:')
disp('----------------------------------');
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real)');
disp(' ');
rsave = 2;
r = rsave;
%if( false ) % debug jump
if( isequal([]*[],mtimesx([],[])) )
disp('Empty * Empty EQUAL');
else
disp('Empty * Empty NOT EQUAL <---');
end
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000));
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = single(rand(1,1));
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40));
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1));
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1));
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500));
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000));
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1));
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = single(rand(1,1));
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40));
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1));
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500));
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000));
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1));
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNN('Matrix * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real).''');
disp(' ');
if( isequal([]*[].',mtimesx([],[],'T')) )
disp('Empty * Empty.'' EQUAL');
else
disp('Empty * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(10000,1));
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1));
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000));
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1));
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000));
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000));
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000));
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1));
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000));
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000));
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real)''');
disp(' ');
if( isequal([]*[]',mtimesx([],[],'C')) )
disp('Empty * Empty'' EQUAL');
else
disp('Empty * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(10000,1));
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1));
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000));
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1));
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000));
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000));
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000));
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1));
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000));
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000));
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNC('Matrix * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * conj(real)');
disp(' ');
%if( false ) % debug jump
if( isequal([]*conj([]),mtimesx([],[],'G')) )
disp('Empty * conj(Empty) EQUAL');
else
disp('Empty * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000));
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = single(rand(1,1));
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40));
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1));
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1));
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500));
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000));
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1));
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj((real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = single(rand(1,1));
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40));
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1));
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500));
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000));
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1));
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real)');
disp(' ');
if( isequal([]'*[],mtimesx([],'C',[])) )
disp('Empty.'' * Empty EQUAL');
else
disp('Empty.'' * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000));
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40));
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1));
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500));
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000));
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1));
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40));
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1));
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500));
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000));
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1));
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real).''');
disp(' ');
if( isequal([].'*[]',mtimesx([],'T',[],'C')) )
disp('Empty.'' * Empty.'' EQUAL');
else
disp('Empty.'' * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(10000,1));
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000));
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1));
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000));
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000));
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000));
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1));
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000));
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000));
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real)''');
disp(' ');
if( isequal([].'*[]',mtimesx([],'T',[],'C')) )
disp('Empty.'' * Empty'' EQUAL');
else
disp('Empty.'' * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(10000,1));
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000));
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1));
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000));
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000));
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000));
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1));
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000));
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000));
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * conj(real)');
disp(' ');
if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) )
disp('Empty.'' * conj(Empty) EQUAL');
else
disp('Empty.'' * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000));
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40));
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1));
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500));
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000));
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1));
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40));
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1));
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500));
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000));
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1));
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real)');
disp(' ');
if( isequal([]'*[],mtimesx([],'C',[])) )
disp('Empty'' * Empty EQUAL');
else
disp('Empty'' * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000));
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40));
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1));
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500));
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000));
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1));
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40));
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1));
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500));
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000));
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1));
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCN('Matrix'' * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real).''');
disp(' ');
if( isequal([]'*[]',mtimesx([],'C',[],'C')) )
disp('Empty'' * Empty.'' EQUAL');
else
disp('Empty'' * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(10000,1));
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000));
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1));
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000));
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000));
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000));
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1));
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000));
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000));
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real)''');
disp(' ');
if( isequal([]'*[]',mtimesx([],'C',[],'C')) )
disp('Empty'' * Empty'' EQUAL');
else
disp('Empty'' * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(10000,1));
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000));
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1));
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000));
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000));
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000));
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1));
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000));
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000));
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * conj(real)');
disp(' ');
if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) )
disp('Empty'' * conj(Empty) EQUAL');
else
disp('Empty'' * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000));
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40));
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1));
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500));
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000));
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1));
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40));
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1));
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500));
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000));
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1));
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1) + rand(1000,1)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real)');
disp(' ');
if( isequal(conj([])*[],mtimesx([],'G',[])) )
disp('conj(Empty) * Empty EQUAL');
else
disp('conj(Empty) * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000));
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = single(rand(1,1));
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40));
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1));
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1));
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500));
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000));
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1));
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = single(rand(1,1));
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40));
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1));
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500));
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000));
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1));
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real).''');
disp(' ');
if( isequal(conj([])*[].',mtimesx([],'G',[],'T')) )
disp('conj(Empty) * Empty.'' EQUAL');
else
disp('conj(Empty) * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(10000,1));
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1));
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000));
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1));
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000));
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000));
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000));
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1));
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000));
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000));
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real)''');
disp(' ');
if( isequal(conj([])*[]',mtimesx([],'G',[],'C')) )
disp('conj(Empty) * Empty'' EQUAL');
else
disp('conj(Empty) * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(10000,1));
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1));
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1));
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000));
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1));
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000));
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000));
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1));
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000));
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1));
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000));
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000));
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = rand(10000,1)+ rand(10000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * conj(real)');
disp(' ');
if( isequal(conj([])*conj([]),mtimesx([],'G',[],'G')) )
disp('conj(Empty) * conj(Empty) EQUAL');
else
disp('conj(Empty) * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000));
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = single(rand(1,1));
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40));
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1));
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1));
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500));
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000));
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1));
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000));
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000));
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = single(rand(1,1));
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40));
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1));
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500));
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000));
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1));
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000));
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,10000)+ rand(1,10000)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1,1000) + rand(1,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = rand(1000,1000) + rand(1000,1000)*1i;
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ... symmetric cases op(A) * op(A)');
disp(' ');
disp('real');
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = rand(2000);
maxdiffsymCN('Matrix'' * Same ',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymNC('Matrix * Same''',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymTN('Matrix.'' * Same ',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymNT('Matrix * Same.''',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymGC('conj(Matrix) * Same''',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymCG('Matrix'' * conj(Same)',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymGT('conj(Matrix) * Same.'' ',A,r);
r = r + 1;
A = rand(2000);
maxdiffsymTG('Matrix.'' * conj(Same)',A,r);
r = rsave;
disp(' ' );
disp('complex');
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymCN('Matrix'' * Same ',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymNC('Matrix * Same''',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymTN('Matrix.'' * Same ',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymNT('Matrix * Same.''',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymGC('conj(Matrix) * Same''',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymCG('Matrix'' * conj(Same)',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymGT('conj(Matrix) * Same.''',A,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxdiffsymTG('Matrix.'' * conj(Same)',A,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ... special scalar cases');
disp(' ');
disp('(scalar) * (real)');
disp(' ');
r = r + 1;
mtimesx_dtable(r,:) = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
rsave = r;
r = r + 1;
A = 1;
B = single(rand(2500));
maxdiffNN('( 1+0i) * Matrix ',A,B,r);
r = r + 1;
A = 1 + 1i;
B = single(rand(2500));
maxdiffNN('( 1+1i) * Matrix ',A,B,r);
r = r + 1;
A = 1 - 1i;
B = single(rand(2500));
maxdiffNN('( 1-1i) * Matrix ',A,B,r);
r = r + 1;
A = 1 + 2i;
B = single(rand(2500));
maxdiffNN('( 1+2i) * Matrix ',A,B,r);
r = r + 1;
A = -1;
B = single(rand(2500));
maxdiffNN('(-1+0i) * Matrix ',A,B,r);
r = r + 1;
A = -1 + 1i;
B = single(rand(2500));
maxdiffNN('(-1+1i) * Matrix ',A,B,r);
r = r + 1;
A = -1 - 1i;
B = single(rand(2500));
maxdiffNN('(-1-1i) * Matrix ',A,B,r);
r = r + 1;
A = -1 + 2i;
B = single(rand(2500));
maxdiffNN('(-1+2i) * Matrix ',A,B,r);
r = r + 1;
A = 2 + 1i;
B = single(rand(2500));
maxdiffNN('( 2+1i) * Matrix ',A,B,r);
r = r + 1;
A = 2 - 1i;
B = single(rand(2500));
maxdiffNN('( 2-1i) * Matrix ',A,B,r);
disp(' ');
disp('(scalar) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = 1;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 1+0i) * Matrix ',A,B,r);
r = r + 1;
A = 1 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 1+1i) * Matrix ',A,B,r);
r = r + 1;
A = 1 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 1-1i) * Matrix ',A,B,r);
r = r + 1;
A = 1 + 2i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 1+2i) * Matrix ',A,B,r);
r = r + 1;
A = -1;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('(-1+0i) * Matrix ',A,B,r);
r = r + 1;
A = -1 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('(-1+1i) * Matrix ',A,B,r);
r = r + 1;
A = -1 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('(-1-1i) * Matrix ',A,B,r);
r = r + 1;
A = -1 + 2i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('(-1+2i) * Matrix ',A,B,r);
r = r + 1;
A = 2 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 2+1i) * Matrix ',A,B,r);
r = r + 1;
A = 2 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 2-1i) * Matrix ',A,B,r);
disp(' ');
disp('(scalar) * (complex)''');
disp(' ');
%r = rsave;
r = r + 1;
A = 1;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 1+0i) * Matrix'' ',A,B,r);
r = r + 1;
A = 1 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 1+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = 1 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 1-1i) * Matrix'' ',A,B,r);
r = r + 1;
A = 1 + 2i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 1+2i) * Matrix'' ',A,B,r);
r = r + 1;
A = -1;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('(-1+0i) * Matrix'' ',A,B,r);
r = r + 1;
A = -1 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('(-1+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = -1 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('(-1-1i) * Matrix'' ',A,B,r);
r = r + 1;
A = -1 + 2i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('(-1+2i) * Matrix'' ',A,B,r);
r = r + 1;
A = 2 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 2+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = 2 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 2-1i) * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(' --- DONE ! ---');
disp(' ');
disp('Summary of Numerical Comparison Tests, max relative element difference:');
disp(' ');
mtimesx_dtable(1,1:k) = compver;
disp(mtimesx_dtable);
disp(' ');
dtable = mtimesx_dtable;
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNN(T,A,B,r)
Cm = A*B;
Cx = mtimesx(A,B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCN(T,A,B,r)
Cm = A'*B;
Cx = mtimesx(A,'C',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTN(T,A,B,r)
Cm = A.'*B;
Cx = mtimesx(A,'T',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGN(T,A,B,r)
Cm = conj(A)*B;
Cx = mtimesx(A,'G',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNC(T,A,B,r)
Cm = A*B';
Cx = mtimesx(A,B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCC(T,A,B,r)
Cm = A'*B';
Cx = mtimesx(A,'C',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTC(T,A,B,r)
Cm = A.'*B';
Cx = mtimesx(A,'T',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGC(T,A,B,r)
Cm = conj(A)*B';
Cx = mtimesx(A,'G',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNT(T,A,B,r)
Cm = A*B.';
Cx = mtimesx(A,B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCT(T,A,B,r)
Cm = A'*B.';
Cx = mtimesx(A,'C',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTT(T,A,B,r)
Cm = A.'*B.';
Cx = mtimesx(A,'T',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGT(T,A,B,r)
Cm = conj(A)*B.';
Cx = mtimesx(A,'G',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNG(T,A,B,r)
Cm = A*conj(B);
Cx = mtimesx(A,B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCG(T,A,B,r)
Cm = A'*conj(B);
Cx = mtimesx(A,'C',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTG(T,A,B,r)
Cm = A.'*conj(B);
Cx = mtimesx(A,'T',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGG(T,A,B,r)
Cm = conj(A)*conj(B);
Cx = mtimesx(A,'G',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymCN(T,A,r)
Cm = A'*A;
Cx = mtimesx(A,'C',A);
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymNC(T,A,r)
Cm = A*A';
Cx = mtimesx(A,A,'C');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymTN(T,A,r)
Cm = A.'*A;
Cx = mtimesx(A,'T',A);
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymNT(T,A,r)
Cm = A*A.';
Cx = mtimesx(A,A,'T');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymTG(T,A,r)
Cm = A.'*conj(A);
Cx = mtimesx(A,'T',A,'G');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymGT(T,A,r)
Cm = conj(A)*A.';
Cx = mtimesx(A,'G',A,'T');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymCG(T,A,r)
Cm = A'*conj(A);
Cx = mtimesx(A,'C',A,'G');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymGC(T,A,r)
Cm = conj(A)*A';
Cx = mtimesx(A,'G',A,'C');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffout(T,A,B,Cm,Cx,r)
global mtimesx_dtable
lt = length(T);
b = repmat(' ',1,30-lt);
if( isequal(Cm,Cx) )
disp([T b ' EQUAL']);
d = 0;
else
Cm = Cm(:);
Cx = Cx(:);
if( isreal(Cm) && isreal(Cx) )
rx = Cx ~= Cm;
d = max(abs((Cx(rx)-Cm(rx))./Cm(rx)));
else
Cmr = real(Cm);
Cmi = imag(Cm);
Cxr = real(Cx);
Cxi = imag(Cx);
rx = Cxr ~= Cmr;
ix = Cxi ~= Cmi;
dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx)))));
di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix)))));
if( isempty(dr) )
d = di;
elseif( isempty(di) )
d = dr;
else
d = max(dr,di);
end
end
disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]);
end
mtimesx_dtable(r,1:length(T)) = T;
if( isreal(A) && isreal(B) )
if( d == 0 )
x = [T b ' 0'];
else
x = [T b sprintf('%11.2e',d)];
end
mtimesx_dtable(r,1:length(x)) = x;
elseif( isreal(A) && ~isreal(B) )
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,42:41+length(x)) = x;
elseif( ~isreal(A) && isreal(B) )
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,53:52+length(x)) = x;
else
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymout(T,A,Cm,Cx,r)
global mtimesx_dtable
lt = length(T);
b = repmat(' ',1,30-lt);
if( isequal(Cm,Cx) )
disp([T b ' EQUAL']);
d = 0;
else
Cm = Cm(:);
Cx = Cx(:);
if( isreal(Cm) && isreal(Cx) )
rx = Cx ~= Cm;
d = max(abs((Cx(rx)-Cm(rx))./Cm(rx)));
else
Cmr = real(Cm);
Cmi = imag(Cm);
Cxr = real(Cx);
Cxi = imag(Cx);
rx = Cxr ~= Cmr;
ix = Cxi ~= Cmi;
dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx)))));
di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix)))));
if( isempty(dr) )
d = di;
elseif( isempty(di) )
d = dr;
else
d = max(dr,di);
end
end
disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]);
end
if( isreal(A) )
if( d == 0 )
x = [T b ' 0'];
else
x = [T b sprintf('%11.2e',d)];
end
mtimesx_dtable(r,1:length(x)) = x;
else
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,1:length(T)) = T;
mtimesx_dtable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function running_time(d)
h = 24*d;
hh = floor(h);
m = 60*(h - hh);
mm = floor(m);
s = 60*(m - mm);
ss = floor(s);
disp(' ');
rt = sprintf('Running time hh:mm:ss = %2.0f:%2.0f:%2.0f',hh,mm,ss);
if( rt(28) == ' ' )
rt(28) = '0';
end
if( rt(31) == ' ' )
rt(31) = '0';
end
disp(rt);
disp(' ');
return
end
|
github
|
he010103/CFWCR-master
|
mtimesx_test_sdspeed.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_test_sdspeed.m
| 388,309 |
utf_8
|
1ed55a613d5cbfe9a11579562f600c9a
|
% Test routine for mtimesx, op(single) * op(double) speed vs MATLAB
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_test_sdspeed
% Filename: mtimesx_test_sdspeed.m
% Programmer: James Tursa
% Version: 1.0
% Date: September 27, 2009
% Copyright: (c) 2009 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Syntax (arguments in brackets [ ] are optional):
%
% T = mtimesx_test_ddspeed( [N [,D]] )
%
% Inputs:
%
% N = Number of runs to make for each individual test. The test result will
% be the median of N runs. N must be even. If N is odd, it will be
% automatically increased to the next even number. The default is 10,
% which can take *hours* to run. Best to run this program overnight.
% D = The string 'details'. If present, this will cause all of the
% individual intermediate run results to print as they happen.
%
% Output:
%
% T = A character array containing a summary of the results.
%
%--------------------------------------------------------------------------
function ttable = mtimesx_test_sdspeed(nn,details)
global mtimesx_ttable
disp(' ');
disp('****************************************************************************');
disp('* *');
disp('* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *');
disp('* *');
disp('* This test program can take several *hours* to complete, particularly *');
disp('* when using the default number of runs as 10. It is strongly suggested *');
disp('* to close all applications and run this program overnight to get the *');
disp('* best possible result with minimal impacts to your computer usage. *');
disp('* *');
disp('* The program will be done when you see the message: DONE ! *');
disp('* *');
disp('****************************************************************************');
disp(' ');
try
input('Press Enter to start test, or Ctrl-C to exit ','s');
catch
ttable = '';
return
end
start_time = datenum(clock);
if nargin >= 1
n = nn;
else
n = 10;
end
if nargin < 2
details = false;
else
if( isempty(details) ) % code to get rid of the lint message
details = true;
else
details = true;
end
end
RC = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
compver = [computer ', ' version ', mtimesx mode ' mtimesx ', median of ' num2str(n) ' runs'];
k = length(compver);
mtimesx_ttable = char([]);
mtimesx_ttable(100,74) = ' ';
mtimesx_ttable(1,1:k) = compver;
mtimesx_ttable(2,:) = RC;
for r=3:170
mtimesx_ttable(r,:) = ' -- -- -- --';
end
disp(' ');
disp(compver);
disp('Test program for function mtimesx:')
disp('----------------------------------');
rsave = 2;
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = rand(1,1);
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400);
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1);
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1);
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500);
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000);
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1);
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = rand(1,1) + rand(1,1)*1i;
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1) + rand(1,1)*1i;
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = rand(1,1);
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400);
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1);
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1);
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500);
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000);
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1);
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real).''');
disp(' ');
rsave = r;
mtimesx_ttable(r,:) = RC;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1);
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000);
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1);
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000);
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000);
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1) + rand(1,1)*1i;
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000);
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1);
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000);
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000);
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1);
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000);
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1);
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000);
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000);
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1) + rand(1,1)*1i;
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000);
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1);
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000);
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000);
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = rand(1,1);
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400);
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1);
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1);
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500);
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000);
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1);
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = rand(1,1) + rand(1,1)*1i;
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1) + rand(1,1)*1i;
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = rand(1,1);
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400);
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1);
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1);
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500);
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000);
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1);
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400);
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1);
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500);
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000);
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1);
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400);
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1);
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500);
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000);
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1);
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000);
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1);
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000);
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000);
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000);
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1);
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000);
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000);
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000);
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1);
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000);
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000);
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000);
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1);
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000);
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000);
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400);
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1);
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500);
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000);
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1);
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400);
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1);
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500);
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000);
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1);
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400);
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1);
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500);
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000);
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1);
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400);
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1);
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500);
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000);
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1);
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000);
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1);
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000);
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000);
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000);
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1);
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000);
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000);
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000);
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1);
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000);
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000);
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000);
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1);
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000);
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000);
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400);
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1);
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500);
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000);
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1);
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500));
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400);
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1);
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500);
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000);
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1);
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,1) + rand(2000,1)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = rand(1,1);
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400);
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1);
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1);
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500);
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000);
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1);
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = rand(1,1) + rand(1,1)*1i;
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1) + rand(1,1)*1i;
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = rand(1,1);
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400);
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1);
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1);
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500);
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000);
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1);
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1);
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000);
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1);
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000);
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000);
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1) + rand(1,1)*1i;
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000);
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1);
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000);
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000);
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1);
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1);
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000);
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1);
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000);
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000);
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1));
B = rand(1,1) + rand(1,1)*1i;
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1) + rand(1,1)*1i;
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1);
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = rand(1,1);
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000);
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1);
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000);
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000);
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1000000,1) + rand(1000000,1)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000);
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = rand(1,1);
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400);
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1);
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1);
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500);
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000);
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1);
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000);
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000));
B = rand(1,1) + rand(1,1)*1i;
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1));
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400));
B = rand(1,1) + rand(1,1)*1i;
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000));
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1));
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000));
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000);
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = rand(1,1);
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400);
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1);
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1);
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500);
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000);
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1);
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000);
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1000000) + rand(1,1000000)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(1,2000) + rand(1,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = single(rand(2000,2000) + rand(2000,2000)*1i);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs ... symmetric cases op(A) * op(A)']);
disp(' ');
disp('real');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = single(rand(2000));
maxtimesymCN('Matrix'' * Same ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymNC('Matrix * Same'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymTN('Matrix.'' * Same ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymNT('Matrix * Same.'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymGC('conj(Matrix) * Same'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymCG('Matrix'' * conj(Same)',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymGT('conj(Matrix) * Same.'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000));
maxtimesymTG('Matrix.'' * conj(Same)',A,n,details,r);
r = rsave;
disp(' ');
disp('complex');
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymCN('Matrix'' * Same ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymNC('Matrix * Same'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymTN('Matrix.'' * Same ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymNT('Matrix * Same.'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymGC('conj(Matrix) * Same'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymCG('Matrix'' * conj(Same)',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymGT('conj(Matrix) * Same.'' ',A,n,details,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxtimesymTG('Matrix.'' * conj(Same)',A,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs ... special scalar cases']);
disp(' ');
disp('(scalar) * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(1);
B = rand(2500);
maxtimeNN('( 1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = rand(2500);
maxtimeNN('( 1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = rand(2500);
maxtimeNN('( 1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = rand(2500);
maxtimeNN('( 1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = rand(2500);
maxtimeNN('(-1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = rand(2500);
maxtimeNN('(-1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = rand(2500);
maxtimeNN('(-1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = rand(2500);
maxtimeNN('(-1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = rand(2500);
maxtimeNN('( 2+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = rand(2500);
maxtimeNN('( 2-1i) * Matrix ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(1);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('(-1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('(-1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('(-1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('(-1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 2+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 2-1i) * Matrix ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex)''');
disp(' ');
%r = rsave;
r = r + 1;
A = single(1);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(1 - 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(1 + 2i);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('(-1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('(-1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 - 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('(-1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(-1 + 2i);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('(-1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(2 + 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 2+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = single(2 - 1i);
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 2-1i) * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(' --- DONE ! ---');
disp(' ');
disp(['Summary of Timing Tests, ' num2str(n) ' runs, + = percent faster, - = percent slower:']);
disp(' ');
mtimesx_ttable(1,1:k) = compver;
disp(mtimesx_ttable);
disp(' ');
ttable = mtimesx_ttable;
running_time(datenum(clock) - start_time);
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B;
mtoc(k) = toc;
tic;
mtimesx(A,B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B.';
mtoc(k) = toc;
tic;
mtimesx(A,B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B';
mtoc(k) = toc;
tic;
mtimesx(A,B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B;
mtoc(k) = toc;
tic;
mtimesx(A,'T',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B';
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B;
mtoc(k) = toc;
tic;
mtimesx(A,'C',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B';
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B;
mtoc(k) = toc;
tic;
mtimesx(A,'G',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B';
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymCN(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*A;
mtoc(k) = toc;
tic;
mtimesx(A,'C',A);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymNC(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*A';
mtoc(k) = toc;
tic;
mtimesx(A,A,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymTN(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*A;
mtoc(k) = toc;
tic;
mtimesx(A,'T',A);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymNT(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*A.';
mtoc(k) = toc;
tic;
mtimesx(A,A,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymCG(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*conj(A);
mtoc(k) = toc;
tic;
mtimesx(A,'C',A,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymGC(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*A';
mtoc(k) = toc;
tic;
mtimesx(A,'G',A,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymTG(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*conj(A);
mtoc(k) = toc;
tic;
mtimesx(A,'T',A,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymGT(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*A.';
mtoc(k) = toc;
tic;
mtimesx(A,'G',A,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeout(T,A,B,p,r)
global mtimesx_ttable
mtimesx_ttable(r,1:length(T)) = T;
if( isreal(A) && isreal(B) )
lt = length(T);
b = repmat(' ',1,30-lt);
x = [T b sprintf('%10.0f%%',-p)];
mtimesx_ttable(r,1:length(x)) = x;
elseif( isreal(A) && ~isreal(B) )
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,42:41+length(x)) = x;
elseif( ~isreal(A) && isreal(B) )
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,53:52+length(x)) = x;
else
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymout(T,A,p,r)
global mtimesx_ttable
if( isreal(A) )
lt = length(T);
b = repmat(' ',1,30-lt);
x = [T b sprintf('%10.0f%%',-p)];
mtimesx_ttable(r,1:length(x)) = x;
else
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,1:length(T)) = T;
mtimesx_ttable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function running_time(d)
h = 24*d;
hh = floor(h);
m = 60*(h - hh);
mm = floor(m);
s = 60*(m - mm);
ss = floor(s);
disp(' ');
rt = sprintf('Running time hh:mm:ss = %2.0f:%2.0f:%2.0f',hh,mm,ss);
if( rt(28) == ' ' )
rt(28) = '0';
end
if( rt(31) == ' ' )
rt(31) = '0';
end
disp(rt);
disp(' ');
return
end
|
github
|
he010103/CFWCR-master
|
mtimesx_test_ddspeed.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_test_ddspeed.m
| 121,611 |
utf_8
|
32613fb321b2de56bd52cb4b4567187d
|
% Test routine for mtimesx, op(double) * op(double) speed vs MATLAB
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_test_ddspeed
% Filename: mtimesx_test_ddspeed.m
% Programmer: James Tursa
% Version: 1.0
% Date: September 27, 2009
% Copyright: (c) 2009 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Syntax (arguments in brackets [ ] are optional):
%
% T = mtimesx_test_ddspeed( [N [,D]] )
%
% Inputs:
%
% N = Number of runs to make for each individual test. The test result will
% be the median of N runs. N must be even. If N is odd, it will be
% automatically increased to the next even number. The default is 10,
% which can take *hours* to run. Best to run this program overnight.
% D = The string 'details'. If present, this will cause all of the
% individual intermediate run results to print as they happen.
%
% Output:
%
% T = A character array containing a summary of the results.
%
%--------------------------------------------------------------------------
function ttable = mtimesx_test_ddspeed(nn,details)
global mtimesx_ttable
disp(' ');
disp('****************************************************************************');
disp('* *');
disp('* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *');
disp('* *');
disp('* This test program can take several *hours* to complete, particularly *');
disp('* when using the default number of runs as 10. It is strongly suggested *');
disp('* to close all applications and run this program overnight to get the *');
disp('* best possible result with minimal impacts to your computer usage. *');
disp('* *');
disp('* The program will be done when you see the message: DONE ! *');
disp('* *');
disp('****************************************************************************');
disp(' ');
try
input('Press Enter to start test, or Ctrl-C to exit ','s');
catch
ttable = '';
return
end
start_time = datenum(clock);
if nargin >= 1
n = nn;
else
n = 10;
end
if nargin < 2
details = false;
else
if( isempty(details) ) % code to get rid of the lint message
details = true;
else
details = true;
end
end
RC = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
compver = [computer ', ' version ', mtimesx mode ' mtimesx ', median of ' num2str(n) ' runs'];
k = length(compver);
nl = 199;
mtimesx_ttable = char([]);
mtimesx_ttable(1:nl,1:74) = ' ';
mtimesx_ttable(1,1:k) = compver;
mtimesx_ttable(2,:) = RC;
for r=3:(nl-2)
mtimesx_ttable(r,:) = ' -- -- -- --';
end
mtimesx_ttable(nl,1:6) = 'DONE !';
disp(' ');
disp(compver);
disp('Test program for function mtimesx:')
disp('----------------------------------');
rsave = 2;
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = rand(1,1);
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400);
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1);
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1);
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500);
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000);
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1);
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = rand(1,1);
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400);
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1);
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1);
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500);
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000);
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1);
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real).''');
disp(' ');
rsave = r;
mtimesx_ttable(r,:) = RC;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1);
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000);
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1);
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000);
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000);
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000);
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1);
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000);
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000);
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1);
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000);
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1);
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000);
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000);
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000);
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1);
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000);
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000);
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = rand(1,1);
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400);
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1);
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1);
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500);
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000);
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1);
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1) + rand(1,1)*1i;
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = rand(1,1);
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400);
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1);
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1);
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500);
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000);
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1);
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400);
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1);
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500);
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000);
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1);
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400);
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1);
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500);
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000);
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1);
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000);
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1);
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000);
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000);
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000);
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1);
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000);
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000);
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000);
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1);
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000);
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000);
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000);
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1);
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000);
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000);
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400);
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1);
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500);
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000);
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1);
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400);
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1);
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500);
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000);
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1);
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400);
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1);
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500);
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000);
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1);
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400);
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1);
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500);
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000);
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1);
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000);
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1);
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000);
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000);
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000);
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1);
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000);
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000);
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000);
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1);
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000);
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000);
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000);
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1);
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000);
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000);
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400);
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1);
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500);
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000);
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1);
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400);
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1);
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500);
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000);
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1);
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = rand(1,1);
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400);
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1);
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1);
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500);
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000);
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1);
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = rand(1,1);
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400);
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1);
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1);
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500);
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000);
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1);
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1);
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000);
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1);
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000);
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000);
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000);
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1);
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000);
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000);
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1);
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1);
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000);
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1);
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000);
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000);
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1);
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = rand(1,1);
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000);
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1);
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000);
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000);
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(1,10000000) + rand(1,10000000)*1i;
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(2500,1) + rand(2500,1)*1i;
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(1,2000) + rand(1,2000)*1i;
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000);
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = rand(1,1);
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400);
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1);
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1);
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500);
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000);
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1);
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000);
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = rand(1,1) + rand(1,1)*1i;
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000);
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = rand(1,1);
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400);
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1);
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1);
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500);
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000);
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1);
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000);
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(1,1000000) + rand(1,1000000)*1i;
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = rand(10,20,30,400) + rand(10,20,30,400)*1i;
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = rand(1,1) + rand(1,1)*1i;
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = rand(10000000,1) + rand(10000000,1)*1i;
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = rand(1,2500) + rand(1,2500)*1i;
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,1) + rand(2000,1)*1i;
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = rand(2000,2000) + rand(2000,2000)*1i;
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs ... symmetric cases op(A) * op(A)']);
disp(' ');
disp('real');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(2000);
maxtimesymCN('Matrix'' * Same ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymNC('Matrix * Same'' ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymTN('Matrix.'' * Same ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymNT('Matrix * Same.'' ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymGC('conj(Matrix) * Same'' ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymCG('Matrix'' * conj(Same)',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymGT('conj(Matrix) * Same.'' ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymTG('Matrix.'' * conj(Same)',A,n,details,r);
r = rsave;
disp(' ');
disp('complex');
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymCN('Matrix'' * Same ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymNC('Matrix * Same'' ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymTN('Matrix.'' * Same ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymNT('Matrix * Same.'' ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymGC('conj(Matrix) * Same'' ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymCG('Matrix'' * conj(Same)',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymGT('conj(Matrix) * Same.'' ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymTG('Matrix.'' * conj(Same)',A,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs ... special scalar cases']);
disp(' ');
disp('(scalar) * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = 1;
B = rand(2500);
maxtimeNN('( 1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500);
maxtimeNN('( 1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500);
maxtimeNN('( 1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500);
maxtimeNN('( 1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1;
B = rand(2500);
maxtimeNN('(-1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500);
maxtimeNN('(-1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500);
maxtimeNN('(-1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500);
maxtimeNN('(-1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500);
maxtimeNN('( 2+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500);
maxtimeNN('( 2-1i) * Matrix ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = 1;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('(-1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('(-1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('(-1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('(-1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 2+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNN('( 2-1i) * Matrix ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = 1;
B = rand(2500);
maxtimeNT('( 1+0i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500);
maxtimeNT('( 1+1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500);
maxtimeNT('( 1-1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500);
maxtimeNT('( 1+2i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = -1;
B = rand(2500);
maxtimeNT('(-1+0i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500);
maxtimeNT('(-1+1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500);
maxtimeNT('(-1-1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500);
maxtimeNT('(-1+2i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500);
maxtimeNT('( 2+1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500);
maxtimeNT('( 2-1i) * Matrix.''',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = 1;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('( 1+0i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('( 1+1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('( 1-1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('( 1+2i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = -1;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('(-1+0i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('(-1+1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('(-1-1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('(-1+2i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('( 2+1i) * Matrix.''',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNT('( 2-1i) * Matrix.''',A,B,n,details,r);
disp(' ');
disp('(scalar) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = 1;
B = rand(2500);
maxtimeNC('( 1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500);
maxtimeNC('( 1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500);
maxtimeNC('( 1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500);
maxtimeNC('( 1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1;
B = rand(2500);
maxtimeNC('(-1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500);
maxtimeNC('(-1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500);
maxtimeNC('(-1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500);
maxtimeNC('(-1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500);
maxtimeNC('( 2+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500);
maxtimeNC('( 2-1i) * Matrix'' ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = 1;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('(-1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('(-1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('(-1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('(-1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 2+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNC('( 2-1i) * Matrix'' ',A,B,n,details,r);
disp(' ');
disp('(scalar) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = 1;
B = rand(2500);
maxtimeNG('( 1+0i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500);
maxtimeNG('( 1+1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500);
maxtimeNG('( 1-1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500);
maxtimeNG('( 1+2i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = -1;
B = rand(2500);
maxtimeNG('(-1+0i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500);
maxtimeNG('(-1+1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500);
maxtimeNG('(-1-1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500);
maxtimeNG('(-1+2i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500);
maxtimeNG('( 2+1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500);
maxtimeNG('( 2-1i) * conj(Matrix)',A,B,n,details,r);
disp(' ');
disp('(scalar) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = 1;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('( 1+0i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('( 1+1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('( 1-1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('( 1+2i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = -1;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('(-1+0i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('(-1+1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('(-1-1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('(-1+2i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('( 2+1i) * conj(Matrix)',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = rand(2500) + rand(2500)*1i;
maxtimeNG('( 2-1i) * conj(Matrix)',A,B,n,details,r);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs ... special sparse cases']);
disp('Real * Real, Real * Cmpx, Cmpx * Real, Cmpx * Cmpx');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = sprand(5000,5000,.1);
maxtimeNN('Scalar * Sparse',A,B,n,details,r);
A = rand(1,1);
B = sprand(5000,5000,.1); B = B + B*2i;
maxtimeNN('Scalar * Sparse',A,B,n,details,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1);
maxtimeNN('Scalar * Sparse',A,B,n,details,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1); B = B + B*2i;
maxtimeNN('Scalar * Sparse',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = sprand(5000,5000,.1);
maxtimeNT('Scalar * Sparse.''',A,B,n,details,r);
A = rand(1,1);
B = sprand(5000,5000,.1); B = B + B*2i;
maxtimeNT('Scalar * Sparse.''',A,B,n,details,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1);
maxtimeNT('Scalar * Sparse.''',A,B,n,details,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1); B = B + B*2i;
maxtimeNT('Scalar * Sparse.''',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = sprand(5000,5000,.1);
maxtimeNC('Scalar * Sparse''',A,B,n,details,r);
A = rand(1,1);
B = sprand(5000,5000,.1); B = B + B*2i;
maxtimeNC('Scalar * Sparse''',A,B,n,details,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1);
maxtimeNC('Scalar * Sparse''',A,B,n,details,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1); B = B + B*2i;
maxtimeNC('Scalar * Sparse''',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = sprand(5000,5000,.1);
maxtimeNG('Scalar * conj(Sparse)',A,B,n,details,r);
A = rand(1,1);
B = sprand(5000,5000,.1); B = B + B*2i;
maxtimeNG('Scalar * conj(Sparse)',A,B,n,details,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1);
maxtimeNG('Scalar * conj(Sparse)',A,B,n,details,r);
A = rand(1,1) + rand(1,1)*1i;
B = sprand(5000,5000,.1); B = B + B*2i;
maxtimeNG('Scalar * conj(Sparse)',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(' --- DONE ! ---');
disp(' ');
disp(['Summary of Timing Tests, ' num2str(n) ' runs, + = percent faster, - = percent slower:']);
disp(' ');
mtimesx_ttable(1,1:k) = compver;
disp(mtimesx_ttable);
disp(' ');
ttable = mtimesx_ttable;
running_time(datenum(clock) - start_time);
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B;
mtoc(k) = toc;
tic;
mtimesx(A,B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B.';
mtoc(k) = toc;
tic;
mtimesx(A,B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B';
mtoc(k) = toc;
tic;
mtimesx(A,B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B;
mtoc(k) = toc;
tic;
mtimesx(A,'T',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B';
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B;
mtoc(k) = toc;
tic;
mtimesx(A,'C',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B';
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B;
mtoc(k) = toc;
tic;
mtimesx(A,'G',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B';
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymCN(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*A;
mtoc(k) = toc;
tic;
mtimesx(A,'C',A);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymNC(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*A';
mtoc(k) = toc;
tic;
mtimesx(A,A,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymTN(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*A;
mtoc(k) = toc;
tic;
mtimesx(A,'T',A);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymNT(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*A.';
mtoc(k) = toc;
tic;
mtimesx(A,A,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymCG(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*conj(A);
mtoc(k) = toc;
tic;
mtimesx(A,'C',A,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymGC(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*A';
mtoc(k) = toc;
tic;
mtimesx(A,'G',A,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymTG(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*conj(A);
mtoc(k) = toc;
tic;
mtimesx(A,'T',A,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymGT(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*A.';
mtoc(k) = toc;
tic;
mtimesx(A,'G',A,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeout(T,A,B,p,r)
global mtimesx_ttable
mtimesx_ttable(r,1:length(T)) = T;
if( isreal(A) && isreal(B) )
lt = length(T);
b = repmat(' ',1,30-lt);
x = [T b sprintf('%10.0f%%',-p)];
mtimesx_ttable(r,1:length(x)) = x;
elseif( isreal(A) && ~isreal(B) )
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,42:41+length(x)) = x;
elseif( ~isreal(A) && isreal(B) )
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,53:52+length(x)) = x;
else
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymout(T,A,p,r)
global mtimesx_ttable
if( isreal(A) )
lt = length(T);
b = repmat(' ',1,30-lt);
x = [T b sprintf('%10.0f%%',-p)];
mtimesx_ttable(r,1:length(x)) = x;
else
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,1:length(T)) = T;
mtimesx_ttable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function running_time(d)
h = 24*d;
hh = floor(h);
m = 60*(h - hh);
mm = floor(m);
s = 60*(m - mm);
ss = floor(s);
disp(' ');
rt = sprintf('Running time hh:mm:ss = %2.0f:%2.0f:%2.0f',hh,mm,ss);
if( rt(28) == ' ' )
rt(28) = '0';
end
if( rt(31) == ' ' )
rt(31) = '0';
end
disp(rt);
disp(' ');
return
end
|
github
|
he010103/CFWCR-master
|
mtimesx_sparse.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_sparse.m
| 3,015 |
utf_8
|
eeb3eb2df4d70c69695b45188807e91c
|
% mtimesx_sparse does sparse matrix multiply of two inputs
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_sparse
% Filename: mtimesx_sparse.m
% Programmer: James Tursa
% Version: 1.00
% Date: September 27, 2009
% Copyright: (c) 2009 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
%--
%
% mtimesx_sparse is a helper function for mtimesx and is not intended to be called
% directly by the user.
%
% ---------------------------------------------------------------------------------------------------------------------------------
function result = mtimesx_sparse(a,transa,b,transb)
if( transa == 'N' )
if( transb == 'N' )
result = a * b;
elseif( transb == 'G' )
result = a * conj(b);
elseif( transb == 'T' )
result = a * b.';
else
result = a * b';
end
elseif( transa == 'G' )
if( transb == 'N' )
result = conj(a) * b;
elseif( transb == 'G' )
result = conj(a) * conj(b);
elseif( transb == 'T' )
result = conj(a) * b.';
else
result = conj(a) * b';
end
elseif( transa == 'T' )
if( transb == 'N' )
result = a.' * b;
elseif( transb == 'G' )
result = a.' * conj(b);
elseif( transb == 'T' )
result = a.' * b.';
else
result = a.' * b';
end
else
if( transb == 'N' )
result = a' * b;
elseif( transb == 'G' )
result = a' * conj(b);
elseif( transb == 'T' )
result = a' * b.';
else
result = a' * b';
end
end
end
|
github
|
he010103/CFWCR-master
|
mtimesx_test_dsspeed.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_test_dsspeed.m
| 388,140 |
utf_8
|
53e3e8d0e86784747c58c68664ae0d85
|
% Test routine for mtimesx, op(double) * op(single) speed vs MATLAB
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_test_dsspeed
% Filename: mtimesx_test_dsspeed.m
% Programmer: James Tursa
% Version: 1.0
% Date: September 27, 2009
% Copyright: (c) 2009 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Syntax (arguments in brackets [ ] are optional):
%
% T = mtimesx_test_ddspeed( [N [,D]] )
%
% Inputs:
%
% N = Number of runs to make for each individual test. The test result will
% be the median of N runs. N must be even. If N is odd, it will be
% automatically increased to the next even number. The default is 10,
% which can take *hours* to run. Best to run this program overnight.
% D = The string 'details'. If present, this will cause all of the
% individual intermediate run results to print as they happen.
%
% Output:
%
% T = A character array containing a summary of the results.
%
%--------------------------------------------------------------------------
function ttable = mtimesx_test_dsspeed(nn,details)
global mtimesx_ttable
disp(' ');
disp('****************************************************************************');
disp('* *');
disp('* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *');
disp('* *');
disp('* This test program can take several *hours* to complete, particularly *');
disp('* when using the default number of runs as 10. It is strongly suggested *');
disp('* to close all applications and run this program overnight to get the *');
disp('* best possible result with minimal impacts to your computer usage. *');
disp('* *');
disp('* The program will be done when you see the message: DONE ! *');
disp('* *');
disp('****************************************************************************');
disp(' ');
try
input('Press Enter to start test, or Ctrl-C to exit ','s');
catch
ttable = '';
return
end
start_time = datenum(clock);
if nargin >= 1
n = nn;
else
n = 10;
end
if nargin < 2
details = false;
else
if( isempty(details) ) % code to get rid of the lint message
details = true;
else
details = true;
end
end
RC = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
compver = [computer ', ' version ', mtimesx mode ' mtimesx ', median of ' num2str(n) ' runs'];
k = length(compver);
mtimesx_ttable = char([]);
mtimesx_ttable(100,74) = ' ';
mtimesx_ttable(1,1:k) = compver;
mtimesx_ttable(2,:) = RC;
for r=3:170
mtimesx_ttable(r,:) = ' -- -- -- --';
end
disp(' ');
disp(compver);
disp('Test program for function mtimesx:')
disp('----------------------------------');
rsave = 2;
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = single(rand(1,1));
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400));
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1));
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1));
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500));
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000));
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1));
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = single(rand(1,1));
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400));
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1));
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1));
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500));
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000));
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1));
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNN('Scalar * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNN('Vector * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeNN('Scalar * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNN('Array * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeNN('Vector i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeNN('Vector o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNN('Vector * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeNN('Matrix * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNN('Matrix * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real).''');
disp(' ');
rsave = r;
mtimesx_ttable(r,:) = RC;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1));
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000));
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1));
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000));
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000));
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000));
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1));
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000));
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000));
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNT('Scalar * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNT('Vector * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNT('Array * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeNT('Vector i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeNT('Vector o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNT('Vector * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeNT('Matrix * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNT('Matrix * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1));
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000));
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1));
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000));
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000));
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000));
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1));
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000));
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000));
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNC('Scalar * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNC('Vector * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNC('Array * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeNC('Vector i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeNC('Vector o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNC('Vector * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeNC('Matrix * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNC('Matrix * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = single(rand(1,1));
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400));
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1));
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1));
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500));
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000));
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1));
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = single(rand(1,1));
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400));
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1));
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1));
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500));
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000));
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1));
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeNG('Scalar * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNG('Vector * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeNG('Scalar * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeNG('Array * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeNG('Vector i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeNG('Vector o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNG('Vector * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeNG('Matrix * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeNG('Matrix * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400));
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1));
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500));
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000));
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1));
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400));
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1));
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500));
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000));
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1));
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTN('Scalar.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTN('Vector.'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeTN('Scalar.'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeTN('Vector.'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeTN('Vector.'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTN('Vector.'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeTN('Matrix.'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTN('Matrix.'' * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000));
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1));
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000));
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000));
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000));
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1));
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000));
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000));
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTT('Scalar.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTT('Vector.'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeTT('Vector.'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeTT('Vector.'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTT('Vector.'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeTT('Matrix.'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTT('Matrix.'' * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000));
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1));
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000));
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000));
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000));
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1));
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000));
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000));
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTC('Scalar.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTC('Vector.'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeTC('Vector.'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeTC('Vector.'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTC('Vector.'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeTC('Matrix.'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTC('Matrix.'' * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real).'' * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400));
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1));
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500));
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000));
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1));
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400));
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1));
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500));
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000));
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1));
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeTG('Scalar.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeTG('Vector.'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeTG('Scalar.'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeTG('Vector.'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeTG('Vector.'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTG('Vector.'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeTG('Matrix.'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeTG('Matrix.'' * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400));
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1));
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500));
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000));
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1));
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400));
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1));
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500));
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000));
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1));
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCN('Scalar'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCN('Vector'' * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeCN('Scalar'' * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeCN('Vector'' i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeCN('Vector'' o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCN('Vector'' * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeCN('Matrix'' * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCN('Matrix'' * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000));
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1));
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000));
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000));
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000));
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1));
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000));
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000));
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCT('Scalar'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCT('Vector'' * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeCT('Vector'' i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeCT('Vector'' o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCT('Vector'' * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeCT('Matrix'' * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCT('Matrix'' * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000));
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1));
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000));
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000));
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000));
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1));
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000));
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000));
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCC('Scalar'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCC('Vector'' * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeCC('Vector'' i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeCC('Vector'' o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCC('Vector'' * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeCC('Matrix'' * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCC('Matrix'' * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('(real)'' * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400));
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1));
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500));
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000));
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1));
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400));
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1));
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500));
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000));
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1));
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeCG('Scalar'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeCG('Vector'' * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeCG('Scalar'' * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10000000,1) + rand(10000000,1)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeCG('Vector'' i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2500) + rand(1,2500)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeCG('Vector'' o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,1) + rand(2000,1)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCG('Vector'' * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeCG('Matrix'' * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeCG('Matrix'' * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = single(rand(1,1));
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400));
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1));
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1));
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500));
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000));
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1));
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = single(rand(1,1));
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400));
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1));
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1));
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500));
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000));
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1));
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGN('conj(Scalar) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGN('conj(Vector) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeGN('conj(Scalar) * Array ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGN('conj(Array) * Scalar ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeGN('conj(Vector) i Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeGN('conj(Vector) o Vector ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGN('conj(Vector) * Matrix ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeGN('conj(Matrix) * Vector ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGN('conj(Matrix) * Matrix ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real).''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1));
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000));
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1));
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000));
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000));
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000));
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1));
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000));
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000));
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGT('conj(Scalar) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGT('conj(Vector) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGT('conj(Array) * Scalar.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeGT('conj(Vector) i Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeGT('conj(Vector) o Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGT('conj(Vector) * Matrix.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeGT('conj(Matrix) * Vector.'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGT('conj(Matrix) * Matrix.'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * (real)''');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1));
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1));
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000));
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1));
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000));
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000));
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1));
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,40) + rand(10,20,30,40)*1i;
B = single(rand(1,1));
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000));
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1));
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000));
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000));
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGC('conj(Scalar) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1000000,1) + rand(1000000,1)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGC('conj(Vector) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGC('conj(Array) * Scalar'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxtimeGC('conj(Vector) i Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(2500,1) + rand(2500,1)*1i);
maxtimeGC('conj(Vector) o Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGC('conj(Vector) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(1,2000) + rand(1,2000)*1i);
maxtimeGC('conj(Matrix) * Vector'' ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGC('conj(Matrix) * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs']);
disp(' ');
disp('conj(real) * conj(real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000));
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = single(rand(1,1));
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400));
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1));
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1));
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500));
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000));
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1));
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000));
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1);
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1);
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400);
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000);
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000));
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = single(rand(1,1));
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400));
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1));
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1));
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500));
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000));
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1));
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000));
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(1,1000000) + rand(1,1000000)*1i);
maxtimeGG('conj(Scalar) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1000000) + rand(1,1000000)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGG('conj(Vector) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,1) + rand(1,1)*1i;
B = single(rand(10,20,30,400) + rand(10,20,30,400)*1i);
maxtimeGG('conj(Scalar) * conj(Array) ',A,B,n,details,r);
r = r + 1;
A = rand(10,20,30,400) + rand(10,20,30,400)*1i;
B = single(rand(1,1) + rand(1,1)*1i);
maxtimeGG('conj(Array) * conj(Scalar) ',A,B,n,details,r);
r = r + 1;
A = rand(1,10000000) + rand(1,10000000)*1i;
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxtimeGG('conj(Vector) i conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2500,1) + rand(2500,1)*1i;
B = single(rand(1,2500) + rand(1,2500)*1i);
maxtimeGG('conj(Vector) o conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(1,2000) + rand(1,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGG('conj(Vector) * conj(Matrix) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,1) + rand(2000,1)*1i);
maxtimeGG('conj(Matrix) * conj(Vector) ',A,B,n,details,r);
r = r + 1;
A = rand(2000,2000) + rand(2000,2000)*1i;
B = single(rand(2000,2000) + rand(2000,2000)*1i);
maxtimeGG('conj(Matrix) * conj(Matrix) ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs ... symmetric cases op(A) * op(A)']);
disp(' ');
disp('real');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = rsave;
r = r + 1;
A = rand(2000);
maxtimesymCN('Matrix'' * Same ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymNC('Matrix * Same'' ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymTN('Matrix.'' * Same ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymNT('Matrix * Same.'' ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymGC('conj(Matrix) * Same'' ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymCG('Matrix'' * conj(Same)',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymGT('conj(Matrix) * Same.'' ',A,n,details,r);
r = r + 1;
A = rand(2000);
maxtimesymTG('Matrix.'' * conj(Same)',A,n,details,r);
r = rsave;
disp(' ');
disp('complex');
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymCN('Matrix'' * Same ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymNC('Matrix * Same'' ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymTN('Matrix.'' * Same ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymNT('Matrix * Same.'' ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymGC('conj(Matrix) * Same'' ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymCG('Matrix'' * conj(Same)',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymGT('conj(Matrix) * Same.'' ',A,n,details,r);
r = r + 1;
A = rand(2000) + rand(2000)*1i;
maxtimesymTG('Matrix.'' * conj(Same)',A,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp(['Timing Tests ... median of ' num2str(n) ' runs ... special scalar cases']);
disp(' ');
disp('(scalar) * (real)');
disp(' ');
r = r + 1;
mtimesx_ttable(r,:) = RC;
rsave = r;
r = r + 1;
A = 1;
B = single(rand(2500));
maxtimeNN('( 1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = single(rand(2500));
maxtimeNN('( 1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = single(rand(2500));
maxtimeNN('( 1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = single(rand(2500));
maxtimeNN('( 1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1;
B = single(rand(2500));
maxtimeNN('(-1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = single(rand(2500));
maxtimeNN('(-1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = single(rand(2500));
maxtimeNN('(-1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = single(rand(2500));
maxtimeNN('(-1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = single(rand(2500));
maxtimeNN('( 2+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = single(rand(2500));
maxtimeNN('( 2-1i) * Matrix ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = 1;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('(-1+0i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('(-1+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('(-1-1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('(-1+2i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 2+1i) * Matrix ',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNN('( 2-1i) * Matrix ',A,B,n,details,r);
disp(' ');
disp('(scalar) * (complex)''');
disp(' ');
%r = rsave;
r = r + 1;
A = 1;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 1 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 1 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 1 + 2i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('(-1+0i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('(-1+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('(-1-1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = -1 + 2i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('(-1+2i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 2 + 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 2+1i) * Matrix'' ',A,B,n,details,r);
r = r + 1;
A = 2 - 1i;
B = single(rand(2500) + rand(2500)*1i);
maxtimeNC('( 2-1i) * Matrix'' ',A,B,n,details,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(' --- DONE ! ---');
disp(' ');
disp(['Summary of Timing Tests, ' num2str(n) ' runs, + = percent faster, - = percent slower:']);
disp(' ');
mtimesx_ttable(1,1:k) = compver;
disp(mtimesx_ttable);
disp(' ');
ttable = mtimesx_ttable;
running_time(datenum(clock) - start_time);
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B;
mtoc(k) = toc;
tic;
mtimesx(A,B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B.';
mtoc(k) = toc;
tic;
mtimesx(A,B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*B';
mtoc(k) = toc;
tic;
mtimesx(A,B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeNG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B;
mtoc(k) = toc;
tic;
mtimesx(A,'T',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*B';
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeTG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'T',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B;
mtoc(k) = toc;
tic;
mtimesx(A,'C',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*B';
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeCG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'C',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGN(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B;
mtoc(k) = toc;
tic;
mtimesx(A,'G',B);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGT(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B.';
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGC(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*B';
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeGG(T,A,B,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*conj(B);
mtoc(k) = toc;
tic;
mtimesx(A,'G',B,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
B(1,1) = 2*B(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimeout(T,A,B,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymCN(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*A;
mtoc(k) = toc;
tic;
mtimesx(A,'C',A);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymNC(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*A';
mtoc(k) = toc;
tic;
mtimesx(A,A,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymTN(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*A;
mtoc(k) = toc;
tic;
mtimesx(A,'T',A);
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymNT(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A*A.';
mtoc(k) = toc;
tic;
mtimesx(A,A,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymCG(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A'*conj(A);
mtoc(k) = toc;
tic;
mtimesx(A,'C',A,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymGC(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*A';
mtoc(k) = toc;
tic;
mtimesx(A,'G',A,'C');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymTG(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
A.'*conj(A);
mtoc(k) = toc;
tic;
mtimesx(A,'T',A,'G');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymGT(T,A,n,details,r)
pp(n) = 0;
mtoc(n) = 0;
xtoc(n) = 0;
for k=1:n
tic;
conj(A)*A.';
mtoc(k) = toc;
tic;
mtimesx(A,'G',A,'T');
xtoc(k) = toc;
pp(k) = (100 * (xtoc(k) - mtoc(k)) / min(mtoc(k),xtoc(k)));
A(1,1) = 2*A(1,1); % prevent JIT accelerator from interfering with timing
end
if( details )
disp('MATLAB mtimes times:');
disp(mtoc);
disp('mtimesx times:')
disp(xtoc);
disp('mtimesx percent faster times (+ = faster, - = slower)');
disp(-pp);
end
p = median(pp);
ap = abs(p);
sp = sprintf('%6.1f',ap);
if( ap < 5 )
c = '(not significant)';
else
c = '';
end
if( p < 0 )
a = [' <' repmat('-',[1,floor((ap+5)/10)])];
disp([T ' mtimesx is ' sp '% faster than MATLAB mtimes' a c]);
else
disp([T ' mtimesx is ' sp '% slower than MATLAB mtimes ' c]);
end
maxtimesymout(T,A,p,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimeout(T,A,B,p,r)
global mtimesx_ttable
mtimesx_ttable(r,1:length(T)) = T;
if( isreal(A) && isreal(B) )
lt = length(T);
b = repmat(' ',1,30-lt);
x = [T b sprintf('%10.0f%%',-p)];
mtimesx_ttable(r,1:length(x)) = x;
elseif( isreal(A) && ~isreal(B) )
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,42:41+length(x)) = x;
elseif( ~isreal(A) && isreal(B) )
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,53:52+length(x)) = x;
else
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxtimesymout(T,A,p,r)
global mtimesx_ttable
if( isreal(A) )
lt = length(T);
b = repmat(' ',1,30-lt);
x = [T b sprintf('%10.0f%%',-p)];
mtimesx_ttable(r,1:length(x)) = x;
else
x = sprintf('%10.0f%%',-p);
mtimesx_ttable(r,1:length(T)) = T;
mtimesx_ttable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function running_time(d)
h = 24*d;
hh = floor(h);
m = 60*(h - hh);
mm = floor(m);
s = 60*(m - mm);
ss = floor(s);
disp(' ');
rt = sprintf('Running time hh:mm:ss = %2.0f:%2.0f:%2.0f',hh,mm,ss);
if( rt(28) == ' ' )
rt(28) = '0';
end
if( rt(31) == ' ' )
rt(31) = '0';
end
disp(rt);
disp(' ');
return
end
|
github
|
he010103/CFWCR-master
|
mtimesx_test_ssequal.m
|
.m
|
CFWCR-master/external_libs/mtimesx/mtimesx_test_ssequal.m
| 355,156 |
utf_8
|
4c01cb508f7cf6adb1b848f98ee9ca41
|
% Test routine for mtimesx, op(single) * op(single) equality vs MATLAB
%******************************************************************************
%
% MATLAB (R) is a trademark of The Mathworks (R) Corporation
%
% Function: mtimesx_test_ssequal
% Filename: mtimesx_test_ssequal.m
% Programmer: James Tursa
% Version: 1.0
% Date: September 27, 2009
% Copyright: (c) 2009 by James Tursa, All Rights Reserved
%
% This code uses the BSD License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Syntax:
%
% T = mtimesx_test_ssequal
%
% Output:
%
% T = A character array containing a summary of the results.
%
%--------------------------------------------------------------------------
function dtable = mtimesx_test_ssequal
global mtimesx_dtable
disp(' ');
disp('****************************************************************************');
disp('* *');
disp('* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *');
disp('* *');
disp('* This test program can take an hour or so to complete. It is suggested *');
disp('* that you close all applications and run this program during your lunch *');
disp('* break or overnight to minimize impacts to your computer usage. *');
disp('* *');
disp('* The program will be done when you see the message: DONE ! *');
disp('* *');
disp('****************************************************************************');
disp(' ');
try
input('Press Enter to start test, or Ctrl-C to exit ','s');
catch
dtable = '';
return
end
start_time = datenum(clock);
compver = [computer ', ' version ', mtimesx mode ' mtimesx];
k = length(compver);
RC = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
mtimesx_dtable = char([]);
mtimesx_dtable(157,74) = ' ';
mtimesx_dtable(1,1:k) = compver;
mtimesx_dtable(2,:) = RC;
for r=3:157
mtimesx_dtable(r,:) = ' -- -- -- --';
end
disp(' ');
disp(compver);
disp('Test program for function mtimesx:')
disp('----------------------------------');
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real)');
disp(' ');
rsave = 2;
r = rsave;
%if( false ) % debug jump
if( isequal([]*[],mtimesx([],[])) )
disp('Empty * Empty EQUAL');
else
disp('Empty * Empty NOT EQUAL <---');
end
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000));
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = single(rand(1,1));
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40));
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1));
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1));
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500));
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000));
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1));
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = single(rand(1,1));
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40));
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1));
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500));
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000));
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1));
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffNN('Matrix * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNN('Scalar * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNN('Vector * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffNN('Scalar * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNN('Array * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffNN('Vector i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffNN('Vector o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNN('Vector * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffNN('Matrix * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNN('Matrix * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real).''');
disp(' ');
if( isequal([]*[].',mtimesx([],[],'T')) )
disp('Empty * Empty.'' EQUAL');
else
disp('Empty * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(10000,1));
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1));
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000));
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1));
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000));
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000));
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000));
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1));
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000));
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000));
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNT('Scalar * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNT('Vector * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNT('Array * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffNT('Vector i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffNT('Vector o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNT('Vector * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffNT('Matrix * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNT('Matrix * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * (real)''');
disp(' ');
if( isequal([]*[]',mtimesx([],[],'C')) )
disp('Empty * Empty'' EQUAL');
else
disp('Empty * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(10000,1));
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1));
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000));
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1));
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000));
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000));
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000));
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1));
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000));
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000));
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffNC('Matrix * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNC('Scalar * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNC('Vector * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNC('Array * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffNC('Vector i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffNC('Vector o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNC('Vector * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffNC('Matrix * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNC('Matrix * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real) * conj(real)');
disp(' ');
%if( false ) % debug jump
if( isequal([]*conj([]),mtimesx([],[],'G')) )
disp('Empty * conj(Empty) EQUAL');
else
disp('Empty * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000));
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = single(rand(1,1));
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40));
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1));
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1));
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500));
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000));
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1));
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj((real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = single(rand(1,1));
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40));
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1));
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500));
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000));
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1));
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffNG('Scalar * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNG('Vector * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffNG('Scalar * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffNG('Array * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffNG('Vector i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffNG('Vector o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNG('Vector * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffNG('Matrix * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffNG('Matrix * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real)');
disp(' ');
if( isequal([]'*[],mtimesx([],'C',[])) )
disp('Empty.'' * Empty EQUAL');
else
disp('Empty.'' * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000));
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40));
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1));
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500));
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000));
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1));
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40));
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1));
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500));
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000));
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1));
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTN('Scalar.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTN('Vector.'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffTN('Scalar.'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffTN('Vector.'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffTN('Vector.'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTN('Vector.'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffTN('Matrix.'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTN('Matrix.'' * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real).''');
disp(' ');
if( isequal([].'*[]',mtimesx([],'T',[],'C')) )
disp('Empty.'' * Empty.'' EQUAL');
else
disp('Empty.'' * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(10000,1));
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000));
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1));
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000));
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000));
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000));
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1));
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000));
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000));
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTT('Scalar.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTT('Vector.'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffTT('Vector.'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffTT('Vector.'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTT('Vector.'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffTT('Matrix.'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTT('Matrix.'' * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * (real)''');
disp(' ');
if( isequal([].'*[]',mtimesx([],'T',[],'C')) )
disp('Empty.'' * Empty'' EQUAL');
else
disp('Empty.'' * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(10000,1));
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000));
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1));
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000));
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000));
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000));
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1));
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000));
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000));
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTC('Scalar.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTC('Vector.'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffTC('Vector.'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffTC('Vector.'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTC('Vector.'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffTC('Matrix.'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTC('Matrix.'' * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real).'' * conj(real)');
disp(' ');
if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) )
disp('Empty.'' * conj(Empty) EQUAL');
else
disp('Empty.'' * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000));
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40));
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1));
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500));
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000));
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1));
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40));
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1));
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500));
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000));
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1));
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex).'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffTG('Scalar.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffTG('Vector.'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffTG('Scalar.'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffTG('Vector.'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffTG('Vector.'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTG('Vector.'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffTG('Matrix.'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffTG('Matrix.'' * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real)');
disp(' ');
if( isequal([]'*[],mtimesx([],'C',[])) )
disp('Empty'' * Empty EQUAL');
else
disp('Empty'' * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000));
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40));
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1));
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500));
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000));
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1));
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40));
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1));
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500));
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000));
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1));
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffCN('Matrix'' * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCN('Scalar'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCN('Vector'' * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffCN('Scalar'' * Array ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffCN('Vector'' i Vector ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffCN('Vector'' o Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCN('Vector'' * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffCN('Matrix'' * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCN('Matrix'' * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real).''');
disp(' ');
if( isequal([]'*[]',mtimesx([],'C',[],'C')) )
disp('Empty'' * Empty.'' EQUAL');
else
disp('Empty'' * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(10000,1));
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000));
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1));
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000));
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000));
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000));
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1));
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000));
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000));
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCT('Scalar'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCT('Vector'' * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffCT('Vector'' i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffCT('Vector'' o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCT('Vector'' * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffCT('Matrix'' * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCT('Matrix'' * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * (real)''');
disp(' ');
if( isequal([]'*[]',mtimesx([],'C',[],'C')) )
disp('Empty'' * Empty'' EQUAL');
else
disp('Empty'' * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(10000,1));
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000));
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1));
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000));
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000));
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000));
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1));
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000));
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000));
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCC('Scalar'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCC('Vector'' * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffCC('Vector'' i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffCC('Vector'' o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCC('Vector'' * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffCC('Matrix'' * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCC('Matrix'' * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('(real)'' * conj(real)');
disp(' ');
if( isequal([]'*conj([]),mtimesx([],'C',[],'G')) )
disp('Empty'' * conj(Empty) EQUAL');
else
disp('Empty'' * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000));
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40));
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1));
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500));
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000));
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1));
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(real)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40));
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1));
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500));
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000));
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1));
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('(complex)'' * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffCG('Scalar'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffCG('Vector'' * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffCG('Scalar'' * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10000000,1) + rand(10000000,1)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffCG('Vector'' i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,2500) + rand(1,2500)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffCG('Vector'' o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1) + rand(1000,1)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCG('Vector'' * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffCG('Matrix'' * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffCG('Matrix'' * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real)');
disp(' ');
if( isequal(conj([])*[],mtimesx([],'G',[])) )
disp('conj(Empty) * Empty EQUAL');
else
disp('conj(Empty) * Empty NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000));
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = single(rand(1,1));
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40));
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1));
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1));
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500));
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000));
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1));
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = single(rand(1,1));
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40));
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1));
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500));
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000));
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1));
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGN('conj(Scalar) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGN('conj(Vector) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffGN('conj(Scalar) * Array ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGN('conj(Array) * Scalar ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffGN('conj(Vector) i Vector ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffGN('conj(Vector) o Vector ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGN('conj(Vector) * Matrix ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffGN('conj(Matrix) * Vector ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGN('conj(Matrix) * Matrix ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real).''');
disp(' ');
if( isequal(conj([])*[].',mtimesx([],'G',[],'T')) )
disp('conj(Empty) * Empty.'' EQUAL');
else
disp('conj(Empty) * Empty.'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(10000,1));
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1));
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000));
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1));
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000));
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000));
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000));
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1));
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000));
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000));
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex).''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGT('conj(Scalar) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGT('conj(Vector) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGT('conj(Array) * Scalar.'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffGT('conj(Vector) i Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffGT('conj(Vector) o Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGT('conj(Vector) * Matrix.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffGT('conj(Matrix) * Vector.'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGT('conj(Matrix) * Matrix.'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * (real)''');
disp(' ');
if( isequal(conj([])*[]',mtimesx([],'G',[],'C')) )
disp('conj(Empty) * Empty'' EQUAL');
else
disp('conj(Empty) * Empty'' NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(10000,1));
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1));
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1));
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000));
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1));
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000));
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000));
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (real)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1));
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000));
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1));
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000));
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000));
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex) * (complex)''');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGC('conj(Scalar) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(10000,1)+ rand(10000,1)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGC('conj(Vector) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGC('conj(Array) * Scalar'' ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(1,10000000) + rand(1,10000000)*1i);
maxdiffGC('conj(Vector) i Vector'' ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(2500,1) + rand(2500,1)*1i);
maxdiffGC('conj(Vector) o Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGC('conj(Vector) * Matrix'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1,1000) + rand(1,1000)*1i);
maxdiffGC('conj(Matrix) * Vector'' ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGC('conj(Matrix) * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ...');
disp(' ');
disp('conj(real) * conj(real)');
disp(' ');
if( isequal(conj([])*conj([]),mtimesx([],'G',[],'G')) )
disp('conj(Empty) * conj(Empty) EQUAL');
else
disp('conj(Empty) * conj(Empty) NOT EQUAL <---');
end
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000));
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = single(rand(1,1));
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40));
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1));
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1));
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500));
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000));
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1));
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000));
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(real) * conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1));
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1));
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40));
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000));
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1));
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000));
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(real)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000));
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = single(rand(1,1));
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40));
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1));
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1));
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500));
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000));
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1));
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000));
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
%--------------------------------------------------------------------------
disp(' ');
disp('conj(complex)* conj(complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(1,10000) + rand(1,10000)*1i);
maxdiffGG('conj(Scalar) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,10000)+ rand(1,10000)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGG('conj(Vector) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,1) + rand(1,1)*1i);
B = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
maxdiffGG('conj(Scalar) * conj(Array) ',A,B,r);
r = r + 1;
A = single(rand(10,20,30,40) + rand(10,20,30,40)*1i);
B = single(rand(1,1) + rand(1,1)*1i);
maxdiffGG('conj(Array) * conj(Scalar) ',A,B,r);
r = r + 1;
A = single(rand(1,10000000) + rand(1,10000000)*1i);
B = single(rand(10000000,1) + rand(10000000,1)*1i);
maxdiffGG('conj(Vector) i conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(2500,1) + rand(2500,1)*1i);
B = single(rand(1,2500) + rand(1,2500)*1i);
maxdiffGG('conj(Vector) o conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1,1000) + rand(1,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGG('conj(Vector) * conj(Matrix) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1) + rand(1000,1)*1i);
maxdiffGG('conj(Matrix) * conj(Vector) ',A,B,r);
r = r + 1;
A = single(rand(1000,1000) + rand(1000,1000)*1i);
B = single(rand(1000,1000) + rand(1000,1000)*1i);
maxdiffGG('conj(Matrix) * conj(Matrix) ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp('----------------------------------');
disp(' ');
disp('Numerical Comparison Tests ... symmetric cases op(A) * op(A)');
disp(' ');
disp('real');
r = r + 1;
mtimesx_dtable(r,:) = RC;
rsave = r;
r = r + 1;
A = single(rand(2000));
maxdiffsymCN('Matrix'' * Same ',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymNC('Matrix * Same''',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymTN('Matrix.'' * Same ',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymNT('Matrix * Same.''',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymGC('conj(Matrix) * Same''',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymCG('Matrix'' * conj(Same)',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymGT('conj(Matrix) * Same.'' ',A,r);
r = r + 1;
A = single(rand(2000));
maxdiffsymTG('Matrix.'' * conj(Same)',A,r);
r = rsave;
disp(' ');
disp('complex');
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymCN('Matrix'' * Same ',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymNC('Matrix * Same''',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymTN('Matrix.'' * Same ',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymNT('Matrix * Same.''',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymGC('conj(Matrix) * Same''',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymCG('Matrix'' * conj(Same)',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymGT('conj(Matrix) * Same.''',A,r);
r = r + 1;
A = single(rand(2000) + rand(2000)*1i);
maxdiffsymTG('Matrix.'' * conj(Same)',A,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%end % debug jump
disp(' ');
disp('Numerical Comparison Tests ... special scalar cases');
disp(' ');
disp('(scalar) * (real)');
disp(' ');
r = r + 1;
mtimesx_dtable(r,:) = ' Real*Real Real*Cplx Cplx*Real Cplx*Cplx';
rsave = r;
r = r + 1;
A = single(1);
B = single(rand(2500));
maxdiffNN('( 1+0i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500));
maxdiffNN('( 1+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500));
maxdiffNN('( 1-1i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500));
maxdiffNN('( 1+2i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1);
B = single(rand(2500));
maxdiffNN('(-1+0i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500));
maxdiffNN('(-1+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500));
maxdiffNN('(-1-1i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500));
maxdiffNN('(-1+2i) * Matrix ',A,B,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500));
maxdiffNN('( 2+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500));
maxdiffNN('( 2-1i) * Matrix ',A,B,r);
disp(' ');
disp('(scalar) * (complex)');
disp(' ');
r = rsave;
r = r + 1;
A = single(1);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 1+0i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 1+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 1-1i) * Matrix ',A,B,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 1+2i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('(-1+0i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('(-1+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('(-1-1i) * Matrix ',A,B,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('(-1+2i) * Matrix ',A,B,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 2+1i) * Matrix ',A,B,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNN('( 2-1i) * Matrix ',A,B,r);
disp(' ');
disp('(scalar) * (complex)''');
disp(' ');
%r = rsave;
r = r + 1;
A = single(1);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 1+0i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 1+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 1-1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 1+2i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(-1);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('(-1+0i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(-1 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('(-1+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(-1 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('(-1-1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(-1 + 2i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('(-1+2i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(2 + 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 2+1i) * Matrix'' ',A,B,r);
r = r + 1;
A = single(2 - 1i);
B = single(rand(2500) + rand(2500)*1i);
maxdiffNC('( 2-1i) * Matrix'' ',A,B,r);
running_time(datenum(clock) - start_time);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
disp(' ');
disp(' --- DONE ! ---');
disp(' ');
disp('Summary of Numerical Comparison Tests, max relative element difference:');
disp(' ');
mtimesx_dtable(1,1:k) = compver;
disp(mtimesx_dtable);
disp(' ');
dtable = mtimesx_dtable;
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNN(T,A,B,r)
Cm = A*B;
Cx = mtimesx(A,B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCN(T,A,B,r)
Cm = A'*B;
Cx = mtimesx(A,'C',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTN(T,A,B,r)
Cm = A.'*B;
Cx = mtimesx(A,'T',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGN(T,A,B,r)
Cm = conj(A)*B;
Cx = mtimesx(A,'G',B);
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNC(T,A,B,r)
Cm = A*B';
Cx = mtimesx(A,B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCC(T,A,B,r)
Cm = A'*B';
Cx = mtimesx(A,'C',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTC(T,A,B,r)
Cm = A.'*B';
Cx = mtimesx(A,'T',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGC(T,A,B,r)
Cm = conj(A)*B';
Cx = mtimesx(A,'G',B,'C');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNT(T,A,B,r)
Cm = A*B.';
Cx = mtimesx(A,B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCT(T,A,B,r)
Cm = A'*B.';
Cx = mtimesx(A,'C',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTT(T,A,B,r)
Cm = A.'*B.';
Cx = mtimesx(A,'T',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGT(T,A,B,r)
Cm = conj(A)*B.';
Cx = mtimesx(A,'G',B,'T');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffNG(T,A,B,r)
Cm = A*conj(B);
Cx = mtimesx(A,B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffCG(T,A,B,r)
Cm = A'*conj(B);
Cx = mtimesx(A,'C',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffTG(T,A,B,r)
Cm = A.'*conj(B);
Cx = mtimesx(A,'T',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffGG(T,A,B,r)
Cm = conj(A)*conj(B);
Cx = mtimesx(A,'G',B,'G');
maxdiffout(T,A,B,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymCN(T,A,r)
Cm = A'*A;
Cx = mtimesx(A,'C',A);
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymNC(T,A,r)
Cm = A*A';
Cx = mtimesx(A,A,'C');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymTN(T,A,r)
Cm = A.'*A;
Cx = mtimesx(A,'T',A);
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymNT(T,A,r)
Cm = A*A.';
Cx = mtimesx(A,A,'T');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymTG(T,A,r)
Cm = A.'*conj(A);
Cx = mtimesx(A,'T',A,'G');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymGT(T,A,r)
Cm = conj(A)*A.';
Cx = mtimesx(A,'G',A,'T');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymCG(T,A,r)
Cm = A'*conj(A);
Cx = mtimesx(A,'C',A,'G');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymGC(T,A,r)
Cm = conj(A)*A';
Cx = mtimesx(A,'G',A,'C');
maxdiffsymout(T,A,Cm,Cx,r);
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffout(T,A,B,Cm,Cx,r)
global mtimesx_dtable
lt = length(T);
b = repmat(' ',1,30-lt);
if( isequal(Cm,Cx) )
disp([T b ' EQUAL']);
d = 0;
else
Cm = Cm(:);
Cx = Cx(:);
if( isreal(Cm) && isreal(Cx) )
rx = Cx ~= Cm;
d = max(abs((Cx(rx)-Cm(rx))./Cm(rx)));
else
Cmr = real(Cm);
Cmi = imag(Cm);
Cxr = real(Cx);
Cxi = imag(Cx);
rx = Cxr ~= Cmr;
ix = Cxi ~= Cmi;
dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx)))));
di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix)))));
if( isempty(dr) )
d = di;
elseif( isempty(di) )
d = dr;
else
d = max(dr,di);
end
end
disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]);
end
mtimesx_dtable(r,1:length(T)) = T;
if( isreal(A) && isreal(B) )
if( d == 0 )
x = [T b ' 0'];
else
x = [T b sprintf('%11.2e',d)];
end
mtimesx_dtable(r,1:length(x)) = x;
elseif( isreal(A) && ~isreal(B) )
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,42:41+length(x)) = x;
elseif( ~isreal(A) && isreal(B) )
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,53:52+length(x)) = x;
else
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function maxdiffsymout(T,A,Cm,Cx,r)
global mtimesx_dtable
lt = length(T);
b = repmat(' ',1,30-lt);
if( isequal(Cm,Cx) )
disp([T b ' EQUAL']);
d = 0;
else
Cm = Cm(:);
Cx = Cx(:);
if( isreal(Cm) && isreal(Cx) )
rx = Cx ~= Cm;
d = max(abs((Cx(rx)-Cm(rx))./Cm(rx)));
else
Cmr = real(Cm);
Cmi = imag(Cm);
Cxr = real(Cx);
Cxi = imag(Cx);
rx = Cxr ~= Cmr;
ix = Cxi ~= Cmi;
dr = max(abs((Cxr(rx)-Cmr(rx))./max(abs(Cmr(rx)),abs(Cmr(rx)))));
di = max(abs((Cxi(ix)-Cmi(ix))./max(abs(Cmi(ix)),abs(Cxi(ix)))));
if( isempty(dr) )
d = di;
elseif( isempty(di) )
d = dr;
else
d = max(dr,di);
end
end
disp([T b ' NOT EQUAL <--- Max relative difference: ' num2str(d)]);
end
if( isreal(A) )
if( d == 0 )
x = [T b ' 0'];
else
x = [T b sprintf('%11.2e',d)];
end
mtimesx_dtable(r,1:length(x)) = x;
else
if( d == 0 )
x = ' 0';
else
x = sprintf('%11.2e',d);
end
mtimesx_dtable(r,1:length(T)) = T;
mtimesx_dtable(r,64:63+length(x)) = x;
end
return
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
function running_time(d)
h = 24*d;
hh = floor(h);
m = 60*(h - hh);
mm = floor(m);
s = 60*(m - mm);
ss = floor(s);
disp(' ');
rt = sprintf('Running time hh:mm:ss = %2.0f:%2.0f:%2.0f',hh,mm,ss);
if( rt(28) == ' ' )
rt(28) = '0';
end
if( rt(31) == ' ' )
rt(31) = '0';
end
disp(rt);
disp(' ');
return
end
|
github
|
arun1993/mmWave-interference-mapping-master
|
getTH.m
|
.m
|
mmWave-interference-mapping-master/getTH.m
| 1,611 |
utf_8
|
2f3e49c97e988ca3fd3c3803f61f572e
|
function th = getTH(d, selSender)
th = [];
for ii = 1:length(selSender)
th(ii) = getTH_(d(ii, :), selSender(ii));
end
for ii = 1:length(selSender)
th(ii) = th(ii)/sum(selSender == selSender(ii));
end
end
function th = getTH_(d, activeSender)
global traces1 traces1N traces2 traces2N traces3 traces3N
persistent thidx1 thidx2 thidx3
if isempty(thidx1)
thidx1 = 0;
thidx2 = 0;
thidx3 = 0;
end
if activeSender == 1
traceTH = traces1;
traceTHN = traces1N;
thidxTH = thidx1;
elseif activeSender == 2
traceTH = traces2;
traceTHN = traces2N;
thidxTH = thidx2;
elseif activeSender == 3
traceTH = traces3;
traceTHN = traces3N;
thidxTH = thidx3;
else
error('outside')
end
targetMCS = d(8);
th = 0;
if sum(d) == 0
th = prctile(traceTH.data{activeSender}(:, 14), 10);
end
while th < 5
if targetMCS == -1
th = 5;
break;
end
for thidx = thidxTH+1:traceTHN
if traceTH.data{activeSender}(thidx, 8) == targetMCS
th = traceTH.data{activeSender}(thidx, 14);
thidxTH = thidx;
break;
end
end
if th < 5
for thidx = 1:thidxTH
if traceTH.data{activeSender}(thidx, 8) == targetMCS
th = traceTH.data{activeSender}(thidx, 14);
thidxTH = thidx;
break;
end
end
end
end
if th < 5
error('fail to get throughput');
end
if activeSender == 1
thidx1 = thidxTH;
elseif activeSender == 2
thidx2 = thidxTH;
elseif activeSender == 3
thidx3 = thidxTH;
else
error('outside')
end
end
|
github
|
arun1993/mmWave-interference-mapping-master
|
vectorplot.m
|
.m
|
mmWave-interference-mapping-master/vectorplot.m
| 2,089 |
utf_8
|
ddca7ddc73c603be0bd73dbb2e39824a
|
% ########### ########### ########## ##########
% ############ ############ ############ ############
% ## ## ## ## ## ## ##
% ## ## ## ## ## ## ##
% ########### #### ###### ## ## ## ## ######
% ########### #### # ## ## ## ## # #
% ## ## ###### ## ## ## ## # #
% ## ## # ## ## ## ## # #
% ############ ##### ###### ## ## ## ##### ######
% ########### ########### ## ## ## ##########
%
% S E C U R E M O B I L E N E T W O R K I N G
function [ output_args ] = vectorplot( xbin, ybin, histvalues, scaled )
%vectorplot - Generate a Vector Plot Diagram
%
% Syntax: [ output_args ] = vectorplot( xbin, ybin, histvalues, scaled )
%
% Inputs:
% xbin - Description
% ybin - Description
% histvalues - Description
% scaled - Description
%
% Outputs:
% output_args - Description
%
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
%
% Author: Matthias Schulz
% email address: [email protected]
% Website: https://ww.seemoo.de
% Date: 2017
%------------- BEGIN CODE --------------
map = colormap;
histvalues = histvalues.';
if (scaled == true)
histvalues_sc = round(histvalues / max(max(histvalues)) * (size(map,1) - 1) + 1);
else
histvalues_sc = histvalues;
end
rectangle('Position',[xbin(1),ybin(1),max(xbin)-min(xbin),max(ybin)-min(ybin)],'FaceColor',map(1,:),'LineStyle','none')
for x = 1:(length(xbin)-1)
for y = 1:(length(ybin)-1)
%if (histvalues_sc(x,y) >= 0)
if (histvalues_sc(x,y) > 1)
rectangle('Position',[xbin(x),ybin(y),xbin(x+1)-xbin(x),ybin(y+1)-ybin(y)],'FaceColor',map(histvalues_sc(x,y),:),'LineStyle','none')
end
end
end
axis([min(xbin) max(xbin) min(ybin) max(ybin)]);
end
%------------- END OF CODE --------------
|
github
|
yinizhizhu/PKULessons-master
|
LMgist.m
|
.m
|
PKULessons-master/GITST/gistdescriptor/LMgist.m
| 8,240 |
utf_8
|
bfdf40d00f3439f3864ce453bfce69d6
|
function [gist, param] = LMgist(D, HOMEIMAGES, param, HOMEGIST)
%
% [gist, param] = LMgist(D, HOMEIMAGES, param);
% [gist, param] = LMgist(filename, HOMEIMAGES, param);
% [gist, param] = LMgist(filename, HOMEIMAGES, param, HOMEGIST);
%
% For a set of images:
% gist = LMgist(img, [], param);
%
% When calling LMgist with a fourth argument it will store the gists in a
% new folder structure mirroring the folder structure of the images. Then,
% when called again, if the gist files already exist, it will just read
% them without recomputing them:
%
% [gist, param] = LMgist(filename, HOMEIMAGES, param, HOMEGIST);
% [gist, param] = LMgist(D, HOMEIMAGES, param, HOMEGIST);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Modeling the shape of the scene: a holistic representation of the spatial envelope
% Aude Oliva, Antonio Torralba
% International Journal of Computer Vision, Vol. 42(3): 145-175, 2001.
if nargin==4
precomputed = 1;
% get list of folders and create non-existing ones
%listoffolders = {D(:).annotation.folder};
%for i = 1:length(D);
% f{i} = D(i).annotation.folder;
%end
%[categories,b,class] = unique(f);
else
precomputed = 0;
HOMEGIST = '';
end
% select type of input
if isstruct(D)
% [gist, param] = LMgist(D, HOMEIMAGES, param);
Nscenes = length(D);
typeD = 1;
end
if iscell(D)
% [gist, param] = LMgist(filename, HOMEIMAGES, param);
Nscenes = length(D);
typeD = 2;
end
if isnumeric(D)
% [gist, param] = LMgist(img, HOMEIMAGES, param);
Nscenes = size(D,4);
typeD = 3;
if ~isfield(param, 'imageSize')
param.imageSize = [size(D,1) size(D,2)];
end
end
param.boundaryExtension = 32; % number of pixels to pad
if nargin<3
% Default parameters
param.imageSize = 128;
param.orientationsPerScale = [8 8 8 8];
param.numberBlocks = 4;
param.fc_prefilt = 4;
param.G = createGabor(param.orientationsPerScale, param.imageSize+2*param.boundaryExtension);
else
if ~isfield(param, 'G')
param.G = createGabor(param.orientationsPerScale, param.imageSize+2*param.boundaryExtension);
end
end
% Precompute filter transfert functions (only need to do this once, unless
% image size is changes):
Nfeatures = size(param.G,3)*param.numberBlocks^2;
% Loop: Compute gist features for all scenes
gist = zeros([Nscenes Nfeatures], 'single');
for n = 1:Nscenes
g = [];
todo = 1;
% if gist has already been computed, just read the file
if precomputed==1
filegist = fullfile(HOMEGIST, D(n).annotation.folder, [D(n).annotation.filename(1:end-4) '.mat']);
if exist(filegist, 'file')
load(filegist, 'g');
todo = 0;
end
end
% otherwise compute gist
if todo==1
if Nscenes>1 disp([n Nscenes]); end
% load image
try
switch typeD
case 1
img = LMimread(D, n, HOMEIMAGES);
case 2
img = imread(fullfile(HOMEIMAGES, D{n}));
case 3
img = D(:,:,:,n);
end
catch
disp(D(n).annotation.folder)
disp(D(n).annotation.filename)
rethrow(lasterror)
end
% convert to gray scale
img = single(mean(img,3));
% resize and crop image to make it square
img = imresizecrop(img, param.imageSize, 'bilinear');
%img = imresize(img, param.imageSize, 'bilinear'); %jhhays
% scale intensities to be in the range [0 255]
img = img-min(img(:));
img = 255*img/max(img(:));
if Nscenes>1
imshow(uint8(img))
title(n)
end
% prefiltering: local contrast scaling
output = prefilt(img, param.fc_prefilt);
% get gist:
g = gistGabor(output, param);
% save gist if a HOMEGIST file is provided
if precomputed
mkdir(fullfile(HOMEGIST, D(n).annotation.folder))
save (filegist, 'g')
end
end
gist(n,:) = g;
drawnow
end
function output = prefilt(img, fc)
% ima = prefilt(img, fc);
% fc = 4 (default)
%
% Input images are double in the range [0, 255];
% You can also input a block of images [ncols nrows 3 Nimages]
%
% For color images, normalization is done by dividing by the local
% luminance variance.
if nargin == 1
fc = 4; % 4 cycles/image
end
w = 5;
s1 = fc/sqrt(log(2));
% Pad images to reduce boundary artifacts
img = log(img+1);
img = padarray(img, [w w], 'symmetric');
[sn, sm, c, N] = size(img);
n = max([sn sm]);
n = n + mod(n,2);
img = padarray(img, [n-sn n-sm], 'symmetric','post');
% Filter
[fx, fy] = meshgrid(-n/2:n/2-1);
gf = fftshift(exp(-(fx.^2+fy.^2)/(s1^2)));
gf = repmat(gf, [1 1 c N]);
% Whitening
output = img - real(ifft2(fft2(img).*gf));
clear img
% Local contrast normalization
localstd = repmat(sqrt(abs(ifft2(fft2(mean(output,3).^2).*gf(:,:,1,:)))), [1 1 c 1]);
output = output./(.2+localstd);
% Crop output to have same size than the input
output = output(w+1:sn-w, w+1:sm-w,:,:);
function g = gistGabor(img, param)
%
% Input:
% img = input image (it can be a block: [nrows, ncols, c, Nimages])
% param.w = number of windows (w*w)
% param.G = precomputed transfer functions
%
% Output:
% g: are the global features = [Nfeatures Nimages],
% Nfeatures = w*w*Nfilters*c
img = single(img);
w = param.numberBlocks;
G = param.G;
be = param.boundaryExtension;
if ndims(img)==2
c = 1;
N = 1;
[nrows ncols c] = size(img);
end
if ndims(img)==3
[nrows ncols c] = size(img);
N = c;
end
if ndims(img)==4
[nrows ncols c N] = size(img);
img = reshape(img, [nrows ncols c*N]);
N = c*N;
end
[ny nx Nfilters] = size(G);
W = w*w;
g = zeros([W*Nfilters N]);
% pad image
img = padarray(img, [be be], 'symmetric');
img = single(fft2(img));
k=0;
for n = 1:Nfilters
ig = abs(ifft2(img.*repmat(G(:,:,n), [1 1 N])));
ig = ig(be+1:ny-be, be+1:nx-be, :);
v = downN(ig, w);
g(k+1:k+W,:) = reshape(v, [W N]);
k = k + W;
drawnow
end
if c == 3
% If the input was a color image, then reshape 'g' so that one column
% is one images output:
g = reshape(g, [size(g,1)*3 size(g,2)/3]);
end
function y=downN(x, N)
%
% averaging over non-overlapping square image blocks
%
% Input
% x = [nrows ncols nchanels]
% Output
% y = [N N nchanels]
nx = fix(linspace(0,size(x,1),N+1));
ny = fix(linspace(0,size(x,2),N+1));
y = zeros(N, N, size(x,3));
for xx=1:N
for yy=1:N
v=mean(mean(x(nx(xx)+1:nx(xx+1), ny(yy)+1:ny(yy+1),:),1),2);
y(xx,yy,:)=v(:);
end
end
function G = createGabor(or, n)
%
% G = createGabor(numberOfOrientationsPerScale, n);
%
% Precomputes filter transfer functions. All computations are done on the
% Fourier domain.
%
% If you call this function without output arguments it will show the
% tiling of the Fourier domain.
%
% Input
% numberOfOrientationsPerScale = vector that contains the number of
% orientations at each scale (from HF to BF)
% n = imagesize = [nrows ncols]
%
% output
% G = transfer functions for a jet of gabor filters
Nscales = length(or);
Nfilters = sum(or);
if length(n) == 1
n = [n(1) n(1)];
end
l=0;
for i=1:Nscales
for j=1:or(i)
l=l+1;
param(l,:)=[.35 .3/(1.85^(i-1)) 16*or(i)^2/32^2 pi/(or(i))*(j-1)];
end
end
% Frequencies:
%[fx, fy] = meshgrid(-n/2:n/2-1);
[fx, fy] = meshgrid(-n(2)/2:n(2)/2-1, -n(1)/2:n(1)/2-1);
fr = fftshift(sqrt(fx.^2+fy.^2));
t = fftshift(angle(fx+sqrt(-1)*fy));
% Transfer functions:
G=zeros([n(1) n(2) Nfilters]);
for i=1:Nfilters
tr=t+param(i,4);
tr=tr+2*pi*(tr<-pi)-2*pi*(tr>pi);
G(:,:,i)=exp(-10*param(i,1)*(fr/n(2)/param(i,2)-1).^2-2*param(i,3)*pi*tr.^2);
end
if nargout == 0
figure
for i=1:Nfilters
contour(fx, fy, fftshift(G(:,:,i)),[1 .7 .6],'r');
hold on
end
axis('on')
axis('equal')
axis([-n(2)/2 n(2)/2 -n(1)/2 n(1)/2])
axis('ij')
xlabel('f_x (cycles per image)')
ylabel('f_y (cycles per image)')
grid on
end
|
github
|
yinizhizhu/PKULessons-master
|
showGist.m
|
.m
|
PKULessons-master/GITST/gistdescriptor/showGist.m
| 1,954 |
utf_8
|
926839f0ab3e7182c10a1b52d06e5e31
|
function showGist(gist, param)
%
% Visualization of the gist descriptor
% showGist(gist, param)
%
% The plot is color coded, with one color per scale
%
% Example:
% img = zeros(256,256);
% img(64:128,64:128) = 255;
% gist = LMgist(img, '', param);
% showGist(gist, param)
[Nimages, Ndim] = size(gist);
nx = ceil(sqrt(Nimages)); ny = ceil(Nimages/nx);
Nblocks = param.numberBlocks;
Nfilters = sum(param.orientationsPerScale);
Nscales = length(param.orientationsPerScale);
C = hsv(Nscales);
colors = [];
for s = 1:Nscales
colors = [colors; repmat(C(s,:), [param.orientationsPerScale(s) 1])];
end
colors = colors';
[nrows ncols Nfilters] = size(param.G);
Nfeatures = Nblocks^2*Nfilters;
if Ndim~=Nfeatures
error('Missmatch between gist descriptors and the parameters');
end
G = param.G(1:2:end,1:2:end,:);
[nrows ncols Nfilters] = size(G);
G = G + flipdim(flipdim(G,1),2);
G = reshape(G, [ncols*nrows Nfilters]);
if Nimages>1
figure;
end
for j = 1:Nimages
g = reshape(gist(j,:), [Nblocks Nblocks Nfilters]);
g = permute(g,[2 1 3]);
g = reshape(g, [Nblocks*Nblocks Nfilters]);
for c = 1:3
mosaic(:,c,:) = G*(repmat(colors(c,:), [Nblocks^2 1]).*g)';
end
mosaic = reshape(mosaic, [nrows ncols 3 Nblocks*Nblocks]);
mosaic = fftshift(fftshift(mosaic,1),2);
mosaic = uint8(mosaic/max(mosaic(:))*255);
mosaic(1,:,:,:) = 255;
mosaic(end,:,:,:) = 255;
mosaic(:,1,:,:) = 255;
mosaic(:,end,:,:) = 255;
if Nimages>1
subplottight(ny,nx,j,0.01);
end
montage(mosaic, 'size', [Nblocks Nblocks])
end
function h=subplottight(Ny, Nx, j, margin)
% General utility function
%
% This function is like subplot but it removes the spacing between axes.
%
% subplottight(Ny, Nx, j)
if nargin <4
margin = 0;
end
j = j-1;
x = mod(j,Nx)/Nx;
y = (Ny-fix(j/Nx)-1)/Ny;
h=axes('position', [x+margin/Nx y+margin/Ny 1/Nx-2*margin/Nx 1/Ny-2*margin/Ny]);
|
github
|
yinizhizhu/PKULessons-master
|
colorFilter.m
|
.m
|
PKULessons-master/Experimental_Statistics/SI_RGB/colorFilter.m
| 684 |
utf_8
|
413027f6fce44c81ddf288c35b9650ef
|
function [gColor, stdDeviration] = colorFilter(f)
hx=[-1 -2 -1;0 0 0 ;1 2 1];
hy=hx';
R = f(:,:,1);
G = f(:,:,2);
B = f(:,:,3);
Rxy = filterSobel(R, hx, hy);
Gxy = filterSobel(G, hx, hy);
Bxy = filterSobel(B, hx, hy);
rgbx = cat(3,Rxy,Gxy,Bxy);
gColor = rgb2gray(rgbx);
stdDeviration = std2(gColor);
show(Rxy, Gxy, Bxy, rgbx, gColor);
end
function show(Rxy, Gxy, Bxy, rgbx, gColor)
figure('numbertitle','off','name','Rxy');
imshow(Rxy);
figure('numbertitle','off','name','Gxy');
imshow(Gxy);
figure('numbertitle','off','name','Bxy');
imshow(Bxy);
figure('numbertitle','off','name','rgbx');
imshow(rgbx);
figure('numbertitle','off','name','rgb2gray');
imshow(255-gColor);
end
|
github
|
yinizhizhu/PKULessons-master
|
LMgist.m
|
.m
|
PKULessons-master/Experimental_Statistics/Gist/LMgist.m
| 8,279 |
utf_8
|
b710337dae3fc4dfdbfeca2f94fcaa63
|
function [gist, param] = LMgist(D, HOMEIMAGES, param, HOMEGIST)
%
% [gist, param] = LMgist(D, HOMEIMAGES, param);
% [gist, param] = LMgist(filename, HOMEIMAGES, param);
% [gist, param] = LMgist(filename, HOMEIMAGES, param, HOMEGIST);
%
% For a set of images:
% gist = LMgist(img, [], param);
%
% When calling LMgist with a fourth argument it will store the gists in a
% new folder structure mirroring the folder structure of the images. Then,
% when called again, if the gist files already exist, it will just read
% them without recomputing them:
%
% [gist, param] = LMgist(filename, HOMEIMAGES, param, HOMEGIST);
% [gist, param] = LMgist(D, HOMEIMAGES, param, HOMEGIST);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Modeling the shape of the scene: a holistic representation of the spatial envelope
% Aude Oliva, Antonio Torralba
% International Journal of Computer Vision, Vol. 42(3): 145-175, 2001.
if nargin==4
precomputed = 1;
% get list of folders and create non-existing ones
%listoffolders = {D(:).annotation.folder};
%for i = 1:length(D);
% f{i} = D(i).annotation.folder;
%end
%[categories,b,class] = unique(f);
else
precomputed = 0;
HOMEGIST = '';
end
% select type of input
if isstruct(D)
% [gist, param] = LMgist(D, HOMEIMAGES, param);
Nscenes = length(D);
typeD = 1;
end
if iscell(D)
% [gist, param] = LMgist(filename, HOMEIMAGES, param);
Nscenes = length(D);
typeD = 2;
end
if isnumeric(D)
% [gist, param] = LMgist(img, HOMEIMAGES, param);
Nscenes = size(D,4);
typeD = 3;
if ~isfield(param, 'imageSize')
param.imageSize = [size(D,1) size(D,2)];
end
end
param.boundaryExtension = 32; % number of pixels to pad
if nargin<3
% Default parameters
param.imageSize = 128;
param.orientationsPerScale = [8 8 8 8];
param.numberBlocks = 4;
param.fc_prefilt = 4;
param.G = createGabor(param.orientationsPerScale, param.imageSize+2*param.boundaryExtension);
else
if ~isfield(param, 'G')
param.G = createGabor(param.orientationsPerScale, param.imageSize+2*param.boundaryExtension);
end
end
% Precompute filter transfert functions (only need to do this once, unless
% image size is changes):
Nfeatures = size(param.G,3)*param.numberBlocks^2;
% Loop: Compute gist features for all scenes
gist = zeros([Nscenes Nfeatures], 'single');
for n = 1:Nscenes
g = [];
todo = 1;
% if gist has already been computed, just read the file
if precomputed==1
filegist = fullfile(HOMEGIST, D(n).annotation.folder, [D(n).annotation.filename(1:end-4) '.mat']);
if exist(filegist, 'file')
load(filegist, 'g');
todo = 0;
end
end
% otherwise compute gist
if todo==1
if Nscenes>1 disp([n Nscenes]); end
% load image
try
switch typeD
case 1
img = LMimread(D, n, HOMEIMAGES);
case 2
img = imread(fullfile(HOMEIMAGES, D{n}));
case 3
img = D(:,:,:,n);
end
catch
disp(D(n).annotation.folder)
disp(D(n).annotation.filename)
rethrow(lasterror)
end
% convert to gray scale
% img = single(mean(img,3));
img = single(rgb2gray(img));
% resize and crop image to make it square
img = imresizecrop(img, param.imageSize, 'bilinear');
%img = imresize(img, param.imageSize, 'bilinear'); %jhhays
% scale intensities to be in the range [0 255]
img = img-min(img(:));
img = 255*img/max(img(:));
if Nscenes>1
imshow(uint8(img))
title(n)
end
% prefiltering: local contrast scaling
output = prefilt(img, param.fc_prefilt);
% get gist:
g = gistGabor(output, param);
% save gist if a HOMEGIST file is provided
if precomputed
mkdir(fullfile(HOMEGIST, D(n).annotation.folder))
save (filegist, 'g')
end
end
gist(n,:) = g;
drawnow
end
function output = prefilt(img, fc)
% ima = prefilt(img, fc);
% fc = 4 (default)
%
% Input images are double in the range [0, 255];
% You can also input a block of images [ncols nrows 3 Nimages]
%
% For color images, normalization is done by dividing by the local
% luminance variance.
if nargin == 1
fc = 4; % 4 cycles/image
end
w = 5;
s1 = fc/sqrt(log(2));
% Pad images to reduce boundary artifacts
img = log(img+1);
img = padarray(img, [w w], 'symmetric');
[sn, sm, c, N] = size(img);
n = max([sn sm]);
n = n + mod(n,2);
img = padarray(img, [n-sn n-sm], 'symmetric','post');
% Filter
[fx, fy] = meshgrid(-n/2:n/2-1);
gf = fftshift(exp(-(fx.^2+fy.^2)/(s1^2)));
gf = repmat(gf, [1 1 c N]);
% Whitening
output = img - real(ifft2(fft2(img).*gf));
clear img
% Local contrast normalization
localstd = repmat(sqrt(abs(ifft2(fft2(mean(output,3).^2).*gf(:,:,1,:)))), [1 1 c 1]);
output = output./(.2+localstd);
% Crop output to have same size than the input
output = output(w+1:sn-w, w+1:sm-w,:,:);
function g = gistGabor(img, param)
%
% Input:
% img = input image (it can be a block: [nrows, ncols, c, Nimages])
% param.w = number of windows (w*w)
% param.G = precomputed transfer functions
%
% Output:
% g: are the global features = [Nfeatures Nimages],
% Nfeatures = w*w*Nfilters*c
img = single(img);
w = param.numberBlocks;
G = param.G;
be = param.boundaryExtension;
if ndims(img)==2
c = 1;
N = 1;
[nrows ncols c] = size(img);
end
if ndims(img)==3
[nrows ncols c] = size(img);
N = c;
end
if ndims(img)==4
[nrows ncols c N] = size(img);
img = reshape(img, [nrows ncols c*N]);
N = c*N;
end
[ny nx Nfilters] = size(G);
W = w*w;
g = zeros([W*Nfilters N]);
% pad image
img = padarray(img, [be be], 'symmetric');
img = single(fft2(img));
k=0;
for n = 1:Nfilters
ig = abs(ifft2(img.*repmat(G(:,:,n), [1 1 N])));
ig = ig(be+1:ny-be, be+1:nx-be, :);
v = downN(ig, w);
g(k+1:k+W,:) = reshape(v, [W N]);
k = k + W;
drawnow
end
if c == 3
% If the input was a color image, then reshape 'g' so that one column
% is one images output:
g = reshape(g, [size(g,1)*3 size(g,2)/3]);
end
function y=downN(x, N)
%
% averaging over non-overlapping square image blocks
%
% Input
% x = [nrows ncols nchanels]
% Output
% y = [N N nchanels]
nx = fix(linspace(0,size(x,1),N+1));
ny = fix(linspace(0,size(x,2),N+1));
y = zeros(N, N, size(x,3));
for xx=1:N
for yy=1:N
v=mean(mean(x(nx(xx)+1:nx(xx+1), ny(yy)+1:ny(yy+1),:),1),2);
y(xx,yy,:)=v(:);
end
end
function G = createGabor(or, n)
%
% G = createGabor(numberOfOrientationsPerScale, n);
%
% Precomputes filter transfer functions. All computations are done on the
% Fourier domain.
%
% If you call this function without output arguments it will show the
% tiling of the Fourier domain.
%
% Input
% numberOfOrientationsPerScale = vector that contains the number of
% orientations at each scale (from HF to BF)
% n = imagesize = [nrows ncols]
%
% output
% G = transfer functions for a jet of gabor filters
Nscales = length(or);
Nfilters = sum(or);
if length(n) == 1
n = [n(1) n(1)];
end
l=0;
for i=1:Nscales
for j=1:or(i)
l=l+1;
param(l,:)=[.35 .3/(1.85^(i-1)) 16*or(i)^2/32^2 pi/(or(i))*(j-1)];
end
end
% Frequencies:
%[fx, fy] = meshgrid(-n/2:n/2-1);
[fx, fy] = meshgrid(-n(2)/2:n(2)/2-1, -n(1)/2:n(1)/2-1);
fr = fftshift(sqrt(fx.^2+fy.^2));
t = fftshift(angle(fx+sqrt(-1)*fy));
% Transfer functions:
G=zeros([n(1) n(2) Nfilters]);
for i=1:Nfilters
tr=t+param(i,4);
tr=tr+2*pi*(tr<-pi)-2*pi*(tr>pi);
G(:,:,i)=exp(-10*param(i,1)*(fr/n(2)/param(i,2)-1).^2-2*param(i,3)*pi*tr.^2);
end
if nargout == 0
figure
for i=1:Nfilters
contour(fx, fy, fftshift(G(:,:,i)),[1 .7 .6],'r');
hold on
end
axis('on')
axis('equal')
axis([-n(2)/2 n(2)/2 -n(1)/2 n(1)/2])
axis('ij')
xlabel('f_x (cycles per image)')
ylabel('f_y (cycles per image)')
grid on
end
|
github
|
yinizhizhu/PKULessons-master
|
showGist.m
|
.m
|
PKULessons-master/Experimental_Statistics/Gist/showGist.m
| 1,954 |
utf_8
|
926839f0ab3e7182c10a1b52d06e5e31
|
function showGist(gist, param)
%
% Visualization of the gist descriptor
% showGist(gist, param)
%
% The plot is color coded, with one color per scale
%
% Example:
% img = zeros(256,256);
% img(64:128,64:128) = 255;
% gist = LMgist(img, '', param);
% showGist(gist, param)
[Nimages, Ndim] = size(gist);
nx = ceil(sqrt(Nimages)); ny = ceil(Nimages/nx);
Nblocks = param.numberBlocks;
Nfilters = sum(param.orientationsPerScale);
Nscales = length(param.orientationsPerScale);
C = hsv(Nscales);
colors = [];
for s = 1:Nscales
colors = [colors; repmat(C(s,:), [param.orientationsPerScale(s) 1])];
end
colors = colors';
[nrows ncols Nfilters] = size(param.G);
Nfeatures = Nblocks^2*Nfilters;
if Ndim~=Nfeatures
error('Missmatch between gist descriptors and the parameters');
end
G = param.G(1:2:end,1:2:end,:);
[nrows ncols Nfilters] = size(G);
G = G + flipdim(flipdim(G,1),2);
G = reshape(G, [ncols*nrows Nfilters]);
if Nimages>1
figure;
end
for j = 1:Nimages
g = reshape(gist(j,:), [Nblocks Nblocks Nfilters]);
g = permute(g,[2 1 3]);
g = reshape(g, [Nblocks*Nblocks Nfilters]);
for c = 1:3
mosaic(:,c,:) = G*(repmat(colors(c,:), [Nblocks^2 1]).*g)';
end
mosaic = reshape(mosaic, [nrows ncols 3 Nblocks*Nblocks]);
mosaic = fftshift(fftshift(mosaic,1),2);
mosaic = uint8(mosaic/max(mosaic(:))*255);
mosaic(1,:,:,:) = 255;
mosaic(end,:,:,:) = 255;
mosaic(:,1,:,:) = 255;
mosaic(:,end,:,:) = 255;
if Nimages>1
subplottight(ny,nx,j,0.01);
end
montage(mosaic, 'size', [Nblocks Nblocks])
end
function h=subplottight(Ny, Nx, j, margin)
% General utility function
%
% This function is like subplot but it removes the spacing between axes.
%
% subplottight(Ny, Nx, j)
if nargin <4
margin = 0;
end
j = j-1;
x = mod(j,Nx)/Nx;
y = (Ny-fix(j/Nx)-1)/Ny;
h=axes('position', [x+margin/Nx y+margin/Ny 1/Nx-2*margin/Nx 1/Ny-2*margin/Ny]);
|
github
|
nervehammer/asuswrt-master
|
echo_diagnostic.m
|
.m
|
asuswrt-master/release/src/router/asusnatnl/pjproject-1.12/third_party/speex/libspeex/echo_diagnostic.m
| 2,076 |
utf_8
|
8d5e7563976fbd9bd2eda26711f7d8dc
|
% Attempts to diagnose AEC problems from recorded samples
%
% out = echo_diagnostic(rec_file, play_file, out_file, tail_length)
%
% Computes the full matrix inversion to cancel echo from the
% recording 'rec_file' using the far end signal 'play_file' using
% a filter length of 'tail_length'. The output is saved to 'out_file'.
function out = echo_diagnostic(rec_file, play_file, out_file, tail_length)
F=fopen(rec_file,'rb');
rec=fread(F,Inf,'short');
fclose (F);
F=fopen(play_file,'rb');
play=fread(F,Inf,'short');
fclose (F);
rec = [rec; zeros(1024,1)];
play = [play; zeros(1024,1)];
N = length(rec);
corr = real(ifft(fft(rec).*conj(fft(play))));
acorr = real(ifft(fft(play).*conj(fft(play))));
[a,b] = max(corr);
if b > N/2
b = b-N;
end
printf ("Far end to near end delay is %d samples\n", b);
if (b > .3*tail_length)
printf ('This is too much delay, try delaying the far-end signal a bit\n');
else if (b < 0)
printf ('You have a negative delay, the echo canceller has no chance to cancel anything!\n');
else
printf ('Delay looks OK.\n');
end
end
end
N2 = round(N/2);
corr1 = real(ifft(fft(rec(1:N2)).*conj(fft(play(1:N2)))));
corr2 = real(ifft(fft(rec(N2+1:end)).*conj(fft(play(N2+1:end)))));
[a,b1] = max(corr1);
if b1 > N2/2
b1 = b1-N2;
end
[a,b2] = max(corr2);
if b2 > N2/2
b2 = b2-N2;
end
drift = (b1-b2)/N2;
printf ('Drift estimate is %f%% (%d samples)\n', 100*drift, b1-b2);
if abs(b1-b2) < 10
printf ('A drift of a few (+-10) samples is normal.\n');
else
if abs(b1-b2) < 30
printf ('There may be (not sure) excessive clock drift. Is the capture and playback done on the same soundcard?\n');
else
printf ('Your clock is drifting! No way the AEC will be able to do anything with that. Most likely, you''re doing capture and playback from two different cards.\n');
end
end
end
acorr(1) = .001+1.00001*acorr(1);
AtA = toeplitz(acorr(1:tail_length));
bb = corr(1:tail_length);
h = AtA\bb;
out = (rec - filter(h, 1, play));
F=fopen(out_file,'w');
fwrite(F,out,'short');
fclose (F);
|
github
|
khanhnamle1994/machine-learning-master
|
submit.m
|
.m
|
machine-learning-master/machine-learning-ex2/ex2/submit.m
| 1,605 |
utf_8
|
9b63d386e9bd7bcca66b1a3d2fa37579
|
function submit()
addpath('./lib');
conf.assignmentSlug = 'logistic-regression';
conf.itemName = 'Logistic Regression';
conf.partArrays = { ...
{ ...
'1', ...
{ 'sigmoid.m' }, ...
'Sigmoid Function', ...
}, ...
{ ...
'2', ...
{ 'costFunction.m' }, ...
'Logistic Regression Cost', ...
}, ...
{ ...
'3', ...
{ 'costFunction.m' }, ...
'Logistic Regression Gradient', ...
}, ...
{ ...
'4', ...
{ 'predict.m' }, ...
'Predict', ...
}, ...
{ ...
'5', ...
{ 'costFunctionReg.m' }, ...
'Regularized Logistic Regression Cost', ...
}, ...
{ ...
'6', ...
{ 'costFunctionReg.m' }, ...
'Regularized Logistic Regression Gradient', ...
}, ...
};
conf.output = @output;
submitWithConfiguration(conf);
end
function out = output(partId, auxstring)
% Random Test Cases
X = [ones(20,1) (exp(1) * sin(1:1:20))' (exp(0.5) * cos(1:1:20))'];
y = sin(X(:,1) + X(:,2)) > 0;
if partId == '1'
out = sprintf('%0.5f ', sigmoid(X));
elseif partId == '2'
out = sprintf('%0.5f ', costFunction([0.25 0.5 -0.5]', X, y));
elseif partId == '3'
[cost, grad] = costFunction([0.25 0.5 -0.5]', X, y);
out = sprintf('%0.5f ', grad);
elseif partId == '4'
out = sprintf('%0.5f ', predict([0.25 0.5 -0.5]', X));
elseif partId == '5'
out = sprintf('%0.5f ', costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1));
elseif partId == '6'
[cost, grad] = costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1);
out = sprintf('%0.5f ', grad);
end
end
|
github
|
khanhnamle1994/machine-learning-master
|
submitWithConfiguration.m
|
.m
|
machine-learning-master/machine-learning-ex2/ex2/lib/submitWithConfiguration.m
| 5,562 |
utf_8
|
4ac719ea6570ac228ea6c7a9c919e3f5
|
function submitWithConfiguration(conf)
addpath('./lib/jsonlab');
parts = parts(conf);
fprintf('== Submitting solutions | %s...\n', conf.itemName);
tokenFile = 'token.mat';
if exist(tokenFile, 'file')
load(tokenFile);
[email token] = promptToken(email, token, tokenFile);
else
[email token] = promptToken('', '', tokenFile);
end
if isempty(token)
fprintf('!! Submission Cancelled\n');
return
end
try
response = submitParts(conf, email, token, parts);
catch
e = lasterror();
fprintf('\n!! Submission failed: %s\n', e.message);
fprintf('\n\nFunction: %s\nFileName: %s\nLineNumber: %d\n', ...
e.stack(1,1).name, e.stack(1,1).file, e.stack(1,1).line);
fprintf('\nPlease correct your code and resubmit.\n');
return
end
if isfield(response, 'errorMessage')
fprintf('!! Submission failed: %s\n', response.errorMessage);
elseif isfield(response, 'errorCode')
fprintf('!! Submission failed: %s\n', response.message);
else
showFeedback(parts, response);
save(tokenFile, 'email', 'token');
end
end
function [email token] = promptToken(email, existingToken, tokenFile)
if (~isempty(email) && ~isempty(existingToken))
prompt = sprintf( ...
'Use token from last successful submission (%s)? (Y/n): ', ...
email);
reenter = input(prompt, 's');
if (isempty(reenter) || reenter(1) == 'Y' || reenter(1) == 'y')
token = existingToken;
return;
else
delete(tokenFile);
end
end
email = input('Login (email address): ', 's');
token = input('Token: ', 's');
end
function isValid = isValidPartOptionIndex(partOptions, i)
isValid = (~isempty(i)) && (1 <= i) && (i <= numel(partOptions));
end
function response = submitParts(conf, email, token, parts)
body = makePostBody(conf, email, token, parts);
submissionUrl = submissionUrl();
responseBody = getResponse(submissionUrl, body);
jsonResponse = validateResponse(responseBody);
response = loadjson(jsonResponse);
end
function body = makePostBody(conf, email, token, parts)
bodyStruct.assignmentSlug = conf.assignmentSlug;
bodyStruct.submitterEmail = email;
bodyStruct.secret = token;
bodyStruct.parts = makePartsStruct(conf, parts);
opt.Compact = 1;
body = savejson('', bodyStruct, opt);
end
function partsStruct = makePartsStruct(conf, parts)
for part = parts
partId = part{:}.id;
fieldName = makeValidFieldName(partId);
outputStruct.output = conf.output(partId);
partsStruct.(fieldName) = outputStruct;
end
end
function [parts] = parts(conf)
parts = {};
for partArray = conf.partArrays
part.id = partArray{:}{1};
part.sourceFiles = partArray{:}{2};
part.name = partArray{:}{3};
parts{end + 1} = part;
end
end
function showFeedback(parts, response)
fprintf('== \n');
fprintf('== %43s | %9s | %-s\n', 'Part Name', 'Score', 'Feedback');
fprintf('== %43s | %9s | %-s\n', '---------', '-----', '--------');
for part = parts
score = '';
partFeedback = '';
partFeedback = response.partFeedbacks.(makeValidFieldName(part{:}.id));
partEvaluation = response.partEvaluations.(makeValidFieldName(part{:}.id));
score = sprintf('%d / %3d', partEvaluation.score, partEvaluation.maxScore);
fprintf('== %43s | %9s | %-s\n', part{:}.name, score, partFeedback);
end
evaluation = response.evaluation;
totalScore = sprintf('%d / %d', evaluation.score, evaluation.maxScore);
fprintf('== --------------------------------\n');
fprintf('== %43s | %9s | %-s\n', '', totalScore, '');
fprintf('== \n');
end
% use urlread or curl to send submit results to the grader and get a response
function response = getResponse(url, body)
% try using urlread() and a secure connection
params = {'jsonBody', body};
[response, success] = urlread(url, 'post', params);
if (success == 0)
% urlread didn't work, try curl & the peer certificate patch
if ispc
% testing note: use 'jsonBody =' for a test case
json_command = sprintf('echo jsonBody=%s | curl -k -X POST -d @- %s', body, url);
else
% it's linux/OS X, so use the other form
json_command = sprintf('echo ''jsonBody=%s'' | curl -k -X POST -d @- %s', body, url);
end
% get the response body for the peer certificate patch method
[code, response] = system(json_command);
% test the success code
if (code ~= 0)
fprintf('[error] submission with curl() was not successful\n');
end
end
end
% validate the grader's response
function response = validateResponse(resp)
% test if the response is json or an HTML page
isJson = length(resp) > 0 && resp(1) == '{';
isHtml = findstr(lower(resp), '<html');
if (isJson)
response = resp;
elseif (isHtml)
% the response is html, so it's probably an error message
printHTMLContents(resp);
error('Grader response is an HTML message');
else
error('Grader sent no response');
end
end
% parse a HTML response and print it's contents
function printHTMLContents(response)
strippedResponse = regexprep(response, '<[^>]+>', ' ');
strippedResponse = regexprep(strippedResponse, '[\t ]+', ' ');
fprintf(strippedResponse);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Service configuration
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function submissionUrl = submissionUrl()
submissionUrl = 'https://www-origin.coursera.org/api/onDemandProgrammingImmediateFormSubmissions.v1';
end
|
github
|
khanhnamle1994/machine-learning-master
|
savejson.m
|
.m
|
machine-learning-master/machine-learning-ex2/ex2/lib/jsonlab/savejson.m
| 17,462 |
utf_8
|
861b534fc35ffe982b53ca3ca83143bf
|
function json=savejson(rootname,obj,varargin)
%
% json=savejson(rootname,obj,filename)
% or
% json=savejson(rootname,obj,opt)
% json=savejson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a JSON (JavaScript
% Object Notation) string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09
%
% $Id: savejson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array).
% filename: a string for the file name to save the output JSON data.
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.FloatFormat ['%.10g'|string]: format to show each numeric element
% of a 1D/2D array;
% opt.ArrayIndent [1|0]: if 1, output explicit data array with
% precedent indentation; if 0, no indentation
% opt.ArrayToStruct[0|1]: when set to 0, savejson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [0|1]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, savejson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.Inf ['"$1_Inf_"'|string]: a customized regular expression pattern
% to represent +/-Inf. The matched pattern is '([-+]*)Inf'
% and $1 represents the sign. For those who want to use
% 1e999 to represent Inf, they can set opt.Inf to '$11e999'
% opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern
% to represent NaN
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSONP='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
% opt.SaveBinary [0|1]: 1 - save the JSON file in binary mode; 0 - text mode.
% opt.Compact [0|1]: 1- out compact JSON format (remove all newlines and tabs)
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a string in the JSON format (see http://json.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% savejson('jmesh',jsonmesh)
% savejson('',jsonmesh,'ArrayIndent',0,'FloatFormat','\t%.5g')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
whitespaces=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
if(jsonopt('Compact',0,opt)==1)
whitespaces=struct('tab','','newline','','sep',',');
end
if(~isfield(opt,'whitespaces_'))
opt.whitespaces_=whitespaces;
end
nl=whitespaces.newline;
json=obj2json(rootname,obj,rootlevel,opt);
if(rootisarray)
json=sprintf('%s%s',json,nl);
else
json=sprintf('{%s%s%s}\n',nl,json,nl);
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=sprintf('%s(%s);%s',jsonp,json,nl);
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
if(jsonopt('SaveBinary',0,opt)==1)
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
else
fid = fopen(opt.FileName, 'wt');
fwrite(fid,json,'char');
end
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2json(name,item,level,varargin)
if(iscell(item))
txt=cell2json(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2json(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2json(name,item,level,varargin{:});
else
txt=mat2json(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2json(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=jsonopt('whitespaces_',struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n')),varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
nl=ws.newline;
if(len>1)
if(~isempty(name))
txt=sprintf('%s"%s": [%s',padding0, checkname(name,varargin{:}),nl); name='';
else
txt=sprintf('%s[%s',padding0,nl);
end
elseif(len==0)
if(~isempty(name))
txt=sprintf('%s"%s": []',padding0, checkname(name,varargin{:})); name='';
else
txt=sprintf('%s[]',padding0);
end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
txt=sprintf('%s%s',txt,obj2json(name,item{i,j},level+(dim(1)>1)+1,varargin{:}));
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
%if(j==dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=struct2json(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
padding1=repmat(ws.tab,1,level+(dim(1)>1)+(len>1));
nl=ws.newline;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding0,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding0,nl); end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=sprintf('%s%s"%s": {%s',txt,padding1, checkname(name,varargin{:}),nl);
else
txt=sprintf('%s%s{%s',txt,padding1,nl);
end
if(~isempty(names))
for e=1:length(names)
txt=sprintf('%s%s',txt,obj2json(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:}));
if(e<length(names)) txt=sprintf('%s%s',txt,','); end
txt=sprintf('%s%s',txt,nl);
end
end
txt=sprintf('%s%s}',txt,padding1);
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=str2json(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding1,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding1,nl); end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
if(isoct)
val=regexprep(item(e,:),'\\','\\');
val=regexprep(val,'"','\"');
val=regexprep(val,'^"','\"');
else
val=regexprep(item(e,:),'\\','\\\\');
val=regexprep(val,'"','\\"');
val=regexprep(val,'^"','\\"');
end
val=escapejsonstring(val);
if(len==1)
obj=['"' checkname(name,varargin{:}) '": ' '"',val,'"'];
if(isempty(name)) obj=['"',val,'"']; end
txt=sprintf('%s%s%s%s',txt,padding1,obj);
else
txt=sprintf('%s%s%s%s',txt,padding0,['"',val,'"']);
end
if(e==len) sep=''; end
txt=sprintf('%s%s',txt,sep);
end
if(len>1) txt=sprintf('%s%s%s%s',txt,nl,padding1,']'); end
%%-------------------------------------------------------------------------
function txt=mat2json(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) ||jsonopt('ArrayToStruct',0,varargin{:}))
if(isempty(name))
txt=sprintf('%s{%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
else
txt=sprintf('%s"%s": {%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,checkname(name,varargin{:}),nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
end
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1 && level>0)
numtxt=regexprep(regexprep(matdata2json(item,level+1,varargin{:}),'^\[',''),']','');
else
numtxt=matdata2json(item,level+1,varargin{:});
end
if(isempty(name))
txt=sprintf('%s%s',padding1,numtxt);
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
else
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
end
end
return;
end
dataformat='%s%s%s%s%s';
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsSparse_": ','1', sep);
if(size(item,1)==1)
% Row vector, store only column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([iy(:),data'],level+2,varargin{:}), nl);
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,data],level+2,varargin{:}), nl);
else
% General case, store row and column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,iy,data],level+2,varargin{:}), nl);
end
else
if(isreal(item))
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json(item(:)',level+2,varargin{:}), nl);
else
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([real(item(:)) imag(item(:))],level+2,varargin{:}), nl);
end
end
txt=sprintf('%s%s%s',txt,padding1,'}');
%%-------------------------------------------------------------------------
function txt=matdata2json(mat,level,varargin)
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
tab=ws.tab;
nl=ws.newline;
if(size(mat,1)==1)
pre='';
post='';
level=level-1;
else
pre=sprintf('[%s',nl);
post=sprintf('%s%s]',nl,repmat(tab,1,level-1));
end
if(isempty(mat))
txt='null';
return;
end
floatformat=jsonopt('FloatFormat','%.10g',varargin{:});
%if(numel(mat)>1)
formatstr=['[' repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf('],%s',nl)]];
%else
% formatstr=[repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf(',\n')]];
%end
if(nargin>=2 && size(mat,1)>1 && jsonopt('ArrayIndent',1,varargin{:})==1)
formatstr=[repmat(tab,1,level) formatstr];
end
txt=sprintf(formatstr,mat');
txt(end-length(nl):end)=[];
if(islogical(mat) && jsonopt('ParseLogical',0,varargin{:})==1)
txt=regexprep(txt,'1','true');
txt=regexprep(txt,'0','false');
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],\n['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
txt=[pre txt post];
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function newstr=escapejsonstring(str)
newstr=str;
isoct=exist('OCTAVE_VERSION','builtin');
if(isoct)
vv=sscanf(OCTAVE_VERSION,'%f');
if(vv(1)>=3.8) isoct=0; end
end
if(isoct)
escapechars={'\a','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},escapechars{i});
end
else
escapechars={'\a','\b','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},regexprep(escapechars{i},'\\','\\\\'));
end
end
|
github
|
khanhnamle1994/machine-learning-master
|
loadjson.m
|
.m
|
machine-learning-master/machine-learning-ex2/ex2/lib/jsonlab/loadjson.m
| 18,732 |
ibm852
|
ab98cf173af2d50bbe8da4d6db252a20
|
function data = loadjson(fname,varargin)
%
% data=loadjson(fname,opt)
% or
% data=loadjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09, including previous works from
%
% Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
% created on 2009/11/02
% François Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393
% created on 2009/03/22
% Joel Feenstra:
% http://www.mathworks.com/matlabcentral/fileexchange/20565
% created on 2008/07/03
%
% $Id: loadjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a JSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.FastArrayParser [1|0 or integer]: if set to 1, use a
% speed-optimized array parser when loading an
% array object. The fast array parser may
% collapse block arrays into a single large
% array similar to rules defined in cell2mat; 0 to
% use a legacy parser; if set to a larger-than-1
% value, this option will specify the minimum
% dimension to enable the fast array parser. For
% example, if the input is a 3D array, setting
% FastArrayParser to 1 will return a 3D array;
% setting to 2 will return a cell array of 2D
% arrays; setting to 3 will return to a 2D cell
% array of 1D vectors; setting to 4 will return a
% 3D cell array.
% opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% dat=loadjson('{"obj":{"string":"value","array":[1,2,3]}}')
% dat=loadjson(['examples' filesep 'example1.json'])
% dat=loadjson(['examples' filesep 'example1.json'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
if(jsonopt('ShowProgress',0,opt)==1)
opt.progressbar_=waitbar(0,'loading ...');
end
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
if(isfield(opt,'progressbar_'))
close(opt.progressbar_);
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=data(j).x0x5F_ArraySize_;
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
if next_char ~= '}'
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
parse_char(':');
val = parse_value(varargin{:});
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}'
break;
end
parse_char(',');
end
end
parse_char('}');
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim2=[];
arraydepth=jsonopt('JSONLAB_ArrayDepth_',1,varargin{:});
pbar=jsonopt('progressbar_',-1,varargin{:});
if next_char ~= ']'
if(jsonopt('FastArrayParser',1,varargin{:})>=1 && arraydepth>=jsonopt('FastArrayParser',1,varargin{:}))
[endpos, e1l, e1r, maxlevel]=matching_bracket(inStr,pos);
arraystr=['[' inStr(pos:endpos)];
arraystr=regexprep(arraystr,'"_NaN_"','NaN');
arraystr=regexprep(arraystr,'"([-+]*)_Inf_"','$1Inf');
arraystr(arraystr==sprintf('\n'))=[];
arraystr(arraystr==sprintf('\r'))=[];
%arraystr=regexprep(arraystr,'\s*,',','); % this is slow,sometimes needed
if(~isempty(e1l) && ~isempty(e1r)) % the array is in 2D or higher D
astr=inStr((e1l+1):(e1r-1));
astr=regexprep(astr,'"_NaN_"','NaN');
astr=regexprep(astr,'"([-+]*)_Inf_"','$1Inf');
astr(astr==sprintf('\n'))=[];
astr(astr==sprintf('\r'))=[];
astr(astr==' ')='';
if(isempty(find(astr=='[', 1))) % array is 2D
dim2=length(sscanf(astr,'%f,',[1 inf]));
end
else % array is 1D
astr=arraystr(2:end-1);
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',[1,inf]);
if(nextidx>=length(astr)-1)
object=obj;
pos=endpos;
parse_char(']');
return;
end
end
if(~isempty(dim2))
astr=arraystr;
astr(astr=='[')='';
astr(astr==']')='';
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',inf);
if(nextidx>=length(astr)-1)
object=reshape(obj,dim2,numel(obj)/dim2)';
pos=endpos;
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
return;
end
end
arraystr=regexprep(arraystr,'\]\s*,','];');
else
arraystr='[';
end
try
if(isoct && regexp(arraystr,'"','once'))
error('Octave eval can produce empty cells for JSON-like input');
end
object=eval(arraystr);
pos=endpos;
catch
while 1
newopt=varargin2struct(varargin{:},'JSONLAB_ArrayDepth_',arraydepth+1);
val = parse_value(newopt);
object{end+1} = val;
if next_char == ']'
break;
end
parse_char(',');
end
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr len esc index_esc len_esc
% len, ns = length(inStr), keyboard
if inStr(pos) ~= '"'
error_pos('String starting with " expected at position %d');
else
pos = pos + 1;
end
str = '';
while pos <= len
while index_esc <= len_esc && esc(index_esc) < pos
index_esc = index_esc + 1;
end
if index_esc > len_esc
str = [str inStr(pos:len)];
pos = len + 1;
break;
else
str = [str inStr(pos:esc(index_esc)-1)];
pos = esc(index_esc);
end
nstr = length(str); switch inStr(pos)
case '"'
pos = pos + 1;
if(~isempty(str))
if(strcmp(str,'_Inf_'))
str=Inf;
elseif(strcmp(str,'-_Inf_'))
str=-Inf;
elseif(strcmp(str,'_NaN_'))
str=NaN;
end
end
return;
case '\'
if pos+1 > len
error_pos('End of file reached right after escape character');
end
pos = pos + 1;
switch inStr(pos)
case {'"' '\' '/'}
str(nstr+1) = inStr(pos);
pos = pos + 1;
case {'b' 'f' 'n' 'r' 't'}
str(nstr+1) = sprintf(['\' inStr(pos)]);
pos = pos + 1;
case 'u'
if pos+4 > len
error_pos('End of file reached in escaped unicode character');
end
str(nstr+(1:6)) = inStr(pos-1:pos+4);
pos = pos + 5;
end
otherwise % should never happen
str(nstr+1) = inStr(pos), keyboard
pos = pos + 1;
end
end
error_pos('End of file while expecting end of inStr');
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct
currstr=inStr(pos:end);
numstr=0;
if(isoct~=0)
numstr=regexp(currstr,'^\s*-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?','end');
[num, one] = sscanf(currstr, '%f', 1);
delta=numstr+1;
else
[num, one, err, delta] = sscanf(currstr, '%f', 1);
if ~isempty(err)
error_pos('Error reading number at position %d');
end
end
pos = pos + delta-1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
pbar=jsonopt('progressbar_',-1,varargin{:});
if(pbar>0)
waitbar(pos/len,pbar,'loading ...');
end
switch(inStr(pos))
case '"'
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'-','0','1','2','3','4','5','6','7','8','9'}
val = parse_number(varargin{:});
return;
case 't'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'true')
val = true;
pos = pos + 4;
return;
end
case 'f'
if pos+4 <= len && strcmpi(inStr(pos:pos+4), 'false')
val = false;
pos = pos + 5;
return;
end
case 'n'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'null')
val = [];
pos = pos + 4;
return;
end
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos, e1l, e1r, maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
khanhnamle1994/machine-learning-master
|
loadubjson.m
|
.m
|
machine-learning-master/machine-learning-ex2/ex2/lib/jsonlab/loadubjson.m
| 15,574 |
utf_8
|
5974e78e71b81b1e0f76123784b951a4
|
function data = loadubjson(fname,varargin)
%
% data=loadubjson(fname,opt)
% or
% data=loadubjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/01
%
% $Id: loadubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a UBJSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadubjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.IntEndian [B|L]: specify the endianness of the integer fields
% in the UBJSON input data. B - Big-Endian format for
% integers (as required in the UBJSON specification);
% L - input integer fields are in Little-Endian order.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% obj=struct('string','value','array',[1 2 3]);
% ubjdata=saveubjson('obj',obj);
% dat=loadubjson(ubjdata)
% dat=loadubjson(['examples' filesep 'example1.ubj'])
% dat=loadubjson(['examples' filesep 'example1.ubj'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken fileendian systemendian
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
fileendian=upper(jsonopt('IntEndian','B',opt));
[os,maxelem,systemendian]=computer;
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
%%
function newdata=parse_collection(id,data,obj)
if(jsoncount>0 && exist('data','var'))
if(~iscell(data))
newdata=cell(1);
newdata{1}=data;
data=newdata;
end
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=double(data(j).x0x5F_ArraySize_);
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1); % TODO
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
count=double(parse_number());
end
if next_char ~= '}'
num=0;
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
%parse_char(':');
val = parse_value(varargin{:});
num=num+1;
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}' || (count>=0 && num>=count)
break;
end
%parse_char(',');
end
end
if(count==-1)
parse_char('}');
end
%%-------------------------------------------------------------------------
function [cid,len]=elem_info(type)
id=strfind('iUIlLdD',type);
dataclass={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
if(id>0)
cid=dataclass{id};
len=bytelen(id);
else
error_pos('unsupported type at position %d');
end
%%-------------------------------------------------------------------------
function [data adv]=parse_block(type,count,varargin)
global pos inStr isoct fileendian systemendian
[cid,len]=elem_info(type);
datastr=inStr(pos:pos+len*count-1);
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
id=strfind('iUIlLdD',type);
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,cid));
end
data=typecast(newdata,cid);
adv=double(len*count);
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim=[];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1);
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
if(next_char=='[')
dim=parse_array(varargin{:});
count=prod(double(dim));
else
count=double(parse_number());
end
end
if(~isempty(type))
if(count>=0)
[object adv]=parse_block(type,count,varargin{:});
if(~isempty(dim))
object=reshape(object,dim);
end
pos=pos+adv;
return;
else
endpos=matching_bracket(inStr,pos);
[cid,len]=elem_info(type);
count=(endpos-pos)/len;
[object adv]=parse_block(type,count,varargin{:});
pos=pos+adv;
parse_char(']');
return;
end
end
if next_char ~= ']'
while 1
val = parse_value(varargin{:});
object{end+1} = val;
if next_char == ']'
break;
end
%parse_char(',');
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
if(count==-1)
parse_char(']');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr esc index_esc len_esc
% len, ns = length(inStr), keyboard
type=inStr(pos);
if type ~= 'S' && type ~= 'C' && type ~= 'H'
error_pos('String starting with S expected at position %d');
else
pos = pos + 1;
end
if(type == 'C')
str=inStr(pos);
pos=pos+1;
return;
end
bytelen=double(parse_number());
if(length(inStr)>=pos+bytelen-1)
str=inStr(pos:pos+bytelen-1);
pos=pos+bytelen;
else
error_pos('End of file while expecting end of inStr');
end
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct fileendian systemendian
id=strfind('iUIlLdD',inStr(pos));
if(isempty(id))
error_pos('expecting a number at position %d');
end
type={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
datastr=inStr(pos+1:pos+bytelen(id));
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,type{id}));
end
num=typecast(newdata,type{id});
pos = pos + bytelen(id)+1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
switch(inStr(pos))
case {'S','C','H'}
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'i','U','I','l','L','d','D'}
val = parse_number(varargin{:});
return;
case 'T'
val = true;
pos = pos + 1;
return;
case 'F'
val = false;
pos = pos + 1;
return;
case {'Z','N'}
val = [];
pos = pos + 1;
return;
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos e1l e1r maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
khanhnamle1994/machine-learning-master
|
saveubjson.m
|
.m
|
machine-learning-master/machine-learning-ex2/ex2/lib/jsonlab/saveubjson.m
| 16,123 |
utf_8
|
61d4f51010aedbf97753396f5d2d9ec0
|
function json=saveubjson(rootname,obj,varargin)
%
% json=saveubjson(rootname,obj,filename)
% or
% json=saveubjson(rootname,obj,opt)
% json=saveubjson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a Universal
% Binary JSON (UBJSON) binary string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/17
%
% $Id: saveubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array)
% filename: a string for the file name to save the output UBJSON data
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.ArrayToStruct[0|1]: when set to 0, saveubjson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [1|0]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, saveubjson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSON='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a binary string in the UBJSON format (see http://ubjson.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% saveubjson('jsonmesh',jsonmesh)
% saveubjson('jsonmesh',jsonmesh,'meshdata.ubj')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
json=obj2ubjson(rootname,obj,rootlevel,opt);
if(~rootisarray)
json=['{' json '}'];
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=[jsonp '(' json ')'];
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2ubjson(name,item,level,varargin)
if(iscell(item))
txt=cell2ubjson(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2ubjson(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2ubjson(name,item,level,varargin{:});
else
txt=mat2ubjson(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2ubjson(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item); % let's handle 1D cell first
if(len>1)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) '[']; name='';
else
txt='[';
end
elseif(len==0)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) 'Z']; name='';
else
txt='Z';
end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
txt=[txt obj2ubjson(name,item{i,j},level+(len>1),varargin{:})];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=struct2ubjson(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=[txt S_(checkname(name,varargin{:})) '{'];
else
txt=[txt '{'];
end
if(~isempty(names))
for e=1:length(names)
txt=[txt obj2ubjson(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:})];
end
end
txt=[txt '}'];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=str2ubjson(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
val=item(e,:);
if(len==1)
obj=['' S_(checkname(name,varargin{:})) '' '',S_(val),''];
if(isempty(name)) obj=['',S_(val),'']; end
txt=[txt,'',obj];
else
txt=[txt,'',['',S_(val),'']];
end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=mat2ubjson(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) || jsonopt('ArrayToStruct',0,varargin{:}))
cid=I_(uint32(max(size(item))));
if(isempty(name))
txt=['{' S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1)) ];
else
if(isempty(item))
txt=[S_(checkname(name,varargin{:})),'Z'];
return;
else
txt=[S_(checkname(name,varargin{:})),'{',S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1))];
end
end
else
if(isempty(name))
txt=matdata2ubjson(item,level+1,varargin{:});
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
numtxt=regexprep(regexprep(matdata2ubjson(item,level+1,varargin{:}),'^\[',''),']','');
txt=[S_(checkname(name,varargin{:})) numtxt];
else
txt=[S_(checkname(name,varargin{:})),matdata2ubjson(item,level+1,varargin{:})];
end
end
return;
end
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=[txt,S_('_ArrayIsComplex_'),'T'];
end
txt=[txt,S_('_ArrayIsSparse_'),'T'];
if(size(item,1)==1)
% Row vector, store only column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([iy(:),data'],level+2,varargin{:})];
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,data],level+2,varargin{:})];
else
% General case, store row and column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,iy,data],level+2,varargin{:})];
end
else
if(isreal(item))
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson(item(:)',level+2,varargin{:})];
else
txt=[txt,S_('_ArrayIsComplex_'),'T'];
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([real(item(:)) imag(item(:))],level+2,varargin{:})];
end
end
txt=[txt,'}'];
%%-------------------------------------------------------------------------
function txt=matdata2ubjson(mat,level,varargin)
if(isempty(mat))
txt='Z';
return;
end
if(size(mat,1)==1)
level=level-1;
end
type='';
hasnegtive=(mat<0);
if(isa(mat,'integer') || isinteger(mat) || (isfloat(mat) && all(mod(mat(:),1) == 0)))
if(isempty(hasnegtive))
if(max(mat(:))<=2^8)
type='U';
end
end
if(isempty(type))
% todo - need to consider negative ones separately
id= histc(abs(max(mat(:))),[0 2^7 2^15 2^31 2^63]);
if(isempty(find(id)))
error('high-precision data is not yet supported');
end
key='iIlL';
type=key(find(id));
end
txt=[I_a(mat(:),type,size(mat))];
elseif(islogical(mat))
logicalval='FT';
if(numel(mat)==1)
txt=logicalval(mat+1);
else
txt=['[$U#' I_a(size(mat),'l') typecast(swapbytes(uint8(mat(:)')),'uint8')];
end
else
if(numel(mat)==1)
txt=['[' D_(mat) ']'];
else
txt=D_a(mat(:),'D',size(mat));
end
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function val=S_(str)
if(length(str)==1)
val=['C' str];
else
val=['S' I_(int32(length(str))) str];
end
%%-------------------------------------------------------------------------
function val=I_(num)
if(~isinteger(num))
error('input is not an integer');
end
if(num>=0 && num<255)
val=['U' data2byte(swapbytes(cast(num,'uint8')),'uint8')];
return;
end
key='iIlL';
cid={'int8','int16','int32','int64'};
for i=1:4
if((num>0 && num<2^(i*8-1)) || (num<0 && num>=-2^(i*8-1)))
val=[key(i) data2byte(swapbytes(cast(num,cid{i})),'uint8')];
return;
end
end
error('unsupported integer');
%%-------------------------------------------------------------------------
function val=D_(num)
if(~isfloat(num))
error('input is not a float');
end
if(isa(num,'single'))
val=['d' data2byte(num,'uint8')];
else
val=['D' data2byte(num,'uint8')];
end
%%-------------------------------------------------------------------------
function data=I_a(num,type,dim,format)
id=find(ismember('iUIlL',type));
if(id==0)
error('unsupported integer array');
end
% based on UBJSON specs, all integer types are stored in big endian format
if(id==1)
data=data2byte(swapbytes(int8(num)),'uint8');
blen=1;
elseif(id==2)
data=data2byte(swapbytes(uint8(num)),'uint8');
blen=1;
elseif(id==3)
data=data2byte(swapbytes(int16(num)),'uint8');
blen=2;
elseif(id==4)
data=data2byte(swapbytes(int32(num)),'uint8');
blen=4;
elseif(id==5)
data=data2byte(swapbytes(int64(num)),'uint8');
blen=8;
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/blen)) data(:)'];
end
data=['[' data(:)'];
else
data=reshape(data,blen,numel(data)/blen);
data(2:blen+1,:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function data=D_a(num,type,dim,format)
id=find(ismember('dD',type));
if(id==0)
error('unsupported float array');
end
if(id==1)
data=data2byte(single(num),'uint8');
elseif(id==2)
data=data2byte(double(num),'uint8');
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/(id*4))) data(:)'];
end
data=['[' data];
else
data=reshape(data,(id*4),length(data)/(id*4));
data(2:(id*4+1),:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function bytes=data2byte(varargin)
bytes=typecast(varargin{:});
bytes=bytes(:)';
|
github
|
khanhnamle1994/machine-learning-master
|
submit.m
|
.m
|
machine-learning-master/machine-learning-ex4/ex4/submit.m
| 1,635 |
utf_8
|
ae9c236c78f9b5b09db8fbc2052990fc
|
function submit()
addpath('./lib');
conf.assignmentSlug = 'neural-network-learning';
conf.itemName = 'Neural Networks Learning';
conf.partArrays = { ...
{ ...
'1', ...
{ 'nnCostFunction.m' }, ...
'Feedforward and Cost Function', ...
}, ...
{ ...
'2', ...
{ 'nnCostFunction.m' }, ...
'Regularized Cost Function', ...
}, ...
{ ...
'3', ...
{ 'sigmoidGradient.m' }, ...
'Sigmoid Gradient', ...
}, ...
{ ...
'4', ...
{ 'nnCostFunction.m' }, ...
'Neural Network Gradient (Backpropagation)', ...
}, ...
{ ...
'5', ...
{ 'nnCostFunction.m' }, ...
'Regularized Gradient', ...
}, ...
};
conf.output = @output;
submitWithConfiguration(conf);
end
function out = output(partId, auxstring)
% Random Test Cases
X = reshape(3 * sin(1:1:30), 3, 10);
Xm = reshape(sin(1:32), 16, 2) / 5;
ym = 1 + mod(1:16,4)';
t1 = sin(reshape(1:2:24, 4, 3));
t2 = cos(reshape(1:2:40, 4, 5));
t = [t1(:) ; t2(:)];
if partId == '1'
[J] = nnCostFunction(t, 2, 4, 4, Xm, ym, 0);
out = sprintf('%0.5f ', J);
elseif partId == '2'
[J] = nnCostFunction(t, 2, 4, 4, Xm, ym, 1.5);
out = sprintf('%0.5f ', J);
elseif partId == '3'
out = sprintf('%0.5f ', sigmoidGradient(X));
elseif partId == '4'
[J, grad] = nnCostFunction(t, 2, 4, 4, Xm, ym, 0);
out = sprintf('%0.5f ', J);
out = [out sprintf('%0.5f ', grad)];
elseif partId == '5'
[J, grad] = nnCostFunction(t, 2, 4, 4, Xm, ym, 1.5);
out = sprintf('%0.5f ', J);
out = [out sprintf('%0.5f ', grad)];
end
end
|
github
|
khanhnamle1994/machine-learning-master
|
submitWithConfiguration.m
|
.m
|
machine-learning-master/machine-learning-ex4/ex4/lib/submitWithConfiguration.m
| 5,562 |
utf_8
|
4ac719ea6570ac228ea6c7a9c919e3f5
|
function submitWithConfiguration(conf)
addpath('./lib/jsonlab');
parts = parts(conf);
fprintf('== Submitting solutions | %s...\n', conf.itemName);
tokenFile = 'token.mat';
if exist(tokenFile, 'file')
load(tokenFile);
[email token] = promptToken(email, token, tokenFile);
else
[email token] = promptToken('', '', tokenFile);
end
if isempty(token)
fprintf('!! Submission Cancelled\n');
return
end
try
response = submitParts(conf, email, token, parts);
catch
e = lasterror();
fprintf('\n!! Submission failed: %s\n', e.message);
fprintf('\n\nFunction: %s\nFileName: %s\nLineNumber: %d\n', ...
e.stack(1,1).name, e.stack(1,1).file, e.stack(1,1).line);
fprintf('\nPlease correct your code and resubmit.\n');
return
end
if isfield(response, 'errorMessage')
fprintf('!! Submission failed: %s\n', response.errorMessage);
elseif isfield(response, 'errorCode')
fprintf('!! Submission failed: %s\n', response.message);
else
showFeedback(parts, response);
save(tokenFile, 'email', 'token');
end
end
function [email token] = promptToken(email, existingToken, tokenFile)
if (~isempty(email) && ~isempty(existingToken))
prompt = sprintf( ...
'Use token from last successful submission (%s)? (Y/n): ', ...
email);
reenter = input(prompt, 's');
if (isempty(reenter) || reenter(1) == 'Y' || reenter(1) == 'y')
token = existingToken;
return;
else
delete(tokenFile);
end
end
email = input('Login (email address): ', 's');
token = input('Token: ', 's');
end
function isValid = isValidPartOptionIndex(partOptions, i)
isValid = (~isempty(i)) && (1 <= i) && (i <= numel(partOptions));
end
function response = submitParts(conf, email, token, parts)
body = makePostBody(conf, email, token, parts);
submissionUrl = submissionUrl();
responseBody = getResponse(submissionUrl, body);
jsonResponse = validateResponse(responseBody);
response = loadjson(jsonResponse);
end
function body = makePostBody(conf, email, token, parts)
bodyStruct.assignmentSlug = conf.assignmentSlug;
bodyStruct.submitterEmail = email;
bodyStruct.secret = token;
bodyStruct.parts = makePartsStruct(conf, parts);
opt.Compact = 1;
body = savejson('', bodyStruct, opt);
end
function partsStruct = makePartsStruct(conf, parts)
for part = parts
partId = part{:}.id;
fieldName = makeValidFieldName(partId);
outputStruct.output = conf.output(partId);
partsStruct.(fieldName) = outputStruct;
end
end
function [parts] = parts(conf)
parts = {};
for partArray = conf.partArrays
part.id = partArray{:}{1};
part.sourceFiles = partArray{:}{2};
part.name = partArray{:}{3};
parts{end + 1} = part;
end
end
function showFeedback(parts, response)
fprintf('== \n');
fprintf('== %43s | %9s | %-s\n', 'Part Name', 'Score', 'Feedback');
fprintf('== %43s | %9s | %-s\n', '---------', '-----', '--------');
for part = parts
score = '';
partFeedback = '';
partFeedback = response.partFeedbacks.(makeValidFieldName(part{:}.id));
partEvaluation = response.partEvaluations.(makeValidFieldName(part{:}.id));
score = sprintf('%d / %3d', partEvaluation.score, partEvaluation.maxScore);
fprintf('== %43s | %9s | %-s\n', part{:}.name, score, partFeedback);
end
evaluation = response.evaluation;
totalScore = sprintf('%d / %d', evaluation.score, evaluation.maxScore);
fprintf('== --------------------------------\n');
fprintf('== %43s | %9s | %-s\n', '', totalScore, '');
fprintf('== \n');
end
% use urlread or curl to send submit results to the grader and get a response
function response = getResponse(url, body)
% try using urlread() and a secure connection
params = {'jsonBody', body};
[response, success] = urlread(url, 'post', params);
if (success == 0)
% urlread didn't work, try curl & the peer certificate patch
if ispc
% testing note: use 'jsonBody =' for a test case
json_command = sprintf('echo jsonBody=%s | curl -k -X POST -d @- %s', body, url);
else
% it's linux/OS X, so use the other form
json_command = sprintf('echo ''jsonBody=%s'' | curl -k -X POST -d @- %s', body, url);
end
% get the response body for the peer certificate patch method
[code, response] = system(json_command);
% test the success code
if (code ~= 0)
fprintf('[error] submission with curl() was not successful\n');
end
end
end
% validate the grader's response
function response = validateResponse(resp)
% test if the response is json or an HTML page
isJson = length(resp) > 0 && resp(1) == '{';
isHtml = findstr(lower(resp), '<html');
if (isJson)
response = resp;
elseif (isHtml)
% the response is html, so it's probably an error message
printHTMLContents(resp);
error('Grader response is an HTML message');
else
error('Grader sent no response');
end
end
% parse a HTML response and print it's contents
function printHTMLContents(response)
strippedResponse = regexprep(response, '<[^>]+>', ' ');
strippedResponse = regexprep(strippedResponse, '[\t ]+', ' ');
fprintf(strippedResponse);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Service configuration
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function submissionUrl = submissionUrl()
submissionUrl = 'https://www-origin.coursera.org/api/onDemandProgrammingImmediateFormSubmissions.v1';
end
|
github
|
khanhnamle1994/machine-learning-master
|
savejson.m
|
.m
|
machine-learning-master/machine-learning-ex4/ex4/lib/jsonlab/savejson.m
| 17,462 |
utf_8
|
861b534fc35ffe982b53ca3ca83143bf
|
function json=savejson(rootname,obj,varargin)
%
% json=savejson(rootname,obj,filename)
% or
% json=savejson(rootname,obj,opt)
% json=savejson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a JSON (JavaScript
% Object Notation) string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09
%
% $Id: savejson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array).
% filename: a string for the file name to save the output JSON data.
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.FloatFormat ['%.10g'|string]: format to show each numeric element
% of a 1D/2D array;
% opt.ArrayIndent [1|0]: if 1, output explicit data array with
% precedent indentation; if 0, no indentation
% opt.ArrayToStruct[0|1]: when set to 0, savejson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [0|1]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, savejson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.Inf ['"$1_Inf_"'|string]: a customized regular expression pattern
% to represent +/-Inf. The matched pattern is '([-+]*)Inf'
% and $1 represents the sign. For those who want to use
% 1e999 to represent Inf, they can set opt.Inf to '$11e999'
% opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern
% to represent NaN
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSONP='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
% opt.SaveBinary [0|1]: 1 - save the JSON file in binary mode; 0 - text mode.
% opt.Compact [0|1]: 1- out compact JSON format (remove all newlines and tabs)
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a string in the JSON format (see http://json.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% savejson('jmesh',jsonmesh)
% savejson('',jsonmesh,'ArrayIndent',0,'FloatFormat','\t%.5g')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
whitespaces=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
if(jsonopt('Compact',0,opt)==1)
whitespaces=struct('tab','','newline','','sep',',');
end
if(~isfield(opt,'whitespaces_'))
opt.whitespaces_=whitespaces;
end
nl=whitespaces.newline;
json=obj2json(rootname,obj,rootlevel,opt);
if(rootisarray)
json=sprintf('%s%s',json,nl);
else
json=sprintf('{%s%s%s}\n',nl,json,nl);
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=sprintf('%s(%s);%s',jsonp,json,nl);
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
if(jsonopt('SaveBinary',0,opt)==1)
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
else
fid = fopen(opt.FileName, 'wt');
fwrite(fid,json,'char');
end
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2json(name,item,level,varargin)
if(iscell(item))
txt=cell2json(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2json(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2json(name,item,level,varargin{:});
else
txt=mat2json(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2json(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=jsonopt('whitespaces_',struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n')),varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
nl=ws.newline;
if(len>1)
if(~isempty(name))
txt=sprintf('%s"%s": [%s',padding0, checkname(name,varargin{:}),nl); name='';
else
txt=sprintf('%s[%s',padding0,nl);
end
elseif(len==0)
if(~isempty(name))
txt=sprintf('%s"%s": []',padding0, checkname(name,varargin{:})); name='';
else
txt=sprintf('%s[]',padding0);
end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
txt=sprintf('%s%s',txt,obj2json(name,item{i,j},level+(dim(1)>1)+1,varargin{:}));
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
%if(j==dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=struct2json(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
padding1=repmat(ws.tab,1,level+(dim(1)>1)+(len>1));
nl=ws.newline;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding0,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding0,nl); end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=sprintf('%s%s"%s": {%s',txt,padding1, checkname(name,varargin{:}),nl);
else
txt=sprintf('%s%s{%s',txt,padding1,nl);
end
if(~isempty(names))
for e=1:length(names)
txt=sprintf('%s%s',txt,obj2json(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:}));
if(e<length(names)) txt=sprintf('%s%s',txt,','); end
txt=sprintf('%s%s',txt,nl);
end
end
txt=sprintf('%s%s}',txt,padding1);
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=str2json(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding1,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding1,nl); end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
if(isoct)
val=regexprep(item(e,:),'\\','\\');
val=regexprep(val,'"','\"');
val=regexprep(val,'^"','\"');
else
val=regexprep(item(e,:),'\\','\\\\');
val=regexprep(val,'"','\\"');
val=regexprep(val,'^"','\\"');
end
val=escapejsonstring(val);
if(len==1)
obj=['"' checkname(name,varargin{:}) '": ' '"',val,'"'];
if(isempty(name)) obj=['"',val,'"']; end
txt=sprintf('%s%s%s%s',txt,padding1,obj);
else
txt=sprintf('%s%s%s%s',txt,padding0,['"',val,'"']);
end
if(e==len) sep=''; end
txt=sprintf('%s%s',txt,sep);
end
if(len>1) txt=sprintf('%s%s%s%s',txt,nl,padding1,']'); end
%%-------------------------------------------------------------------------
function txt=mat2json(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) ||jsonopt('ArrayToStruct',0,varargin{:}))
if(isempty(name))
txt=sprintf('%s{%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
else
txt=sprintf('%s"%s": {%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,checkname(name,varargin{:}),nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
end
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1 && level>0)
numtxt=regexprep(regexprep(matdata2json(item,level+1,varargin{:}),'^\[',''),']','');
else
numtxt=matdata2json(item,level+1,varargin{:});
end
if(isempty(name))
txt=sprintf('%s%s',padding1,numtxt);
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
else
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
end
end
return;
end
dataformat='%s%s%s%s%s';
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsSparse_": ','1', sep);
if(size(item,1)==1)
% Row vector, store only column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([iy(:),data'],level+2,varargin{:}), nl);
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,data],level+2,varargin{:}), nl);
else
% General case, store row and column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,iy,data],level+2,varargin{:}), nl);
end
else
if(isreal(item))
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json(item(:)',level+2,varargin{:}), nl);
else
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([real(item(:)) imag(item(:))],level+2,varargin{:}), nl);
end
end
txt=sprintf('%s%s%s',txt,padding1,'}');
%%-------------------------------------------------------------------------
function txt=matdata2json(mat,level,varargin)
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
tab=ws.tab;
nl=ws.newline;
if(size(mat,1)==1)
pre='';
post='';
level=level-1;
else
pre=sprintf('[%s',nl);
post=sprintf('%s%s]',nl,repmat(tab,1,level-1));
end
if(isempty(mat))
txt='null';
return;
end
floatformat=jsonopt('FloatFormat','%.10g',varargin{:});
%if(numel(mat)>1)
formatstr=['[' repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf('],%s',nl)]];
%else
% formatstr=[repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf(',\n')]];
%end
if(nargin>=2 && size(mat,1)>1 && jsonopt('ArrayIndent',1,varargin{:})==1)
formatstr=[repmat(tab,1,level) formatstr];
end
txt=sprintf(formatstr,mat');
txt(end-length(nl):end)=[];
if(islogical(mat) && jsonopt('ParseLogical',0,varargin{:})==1)
txt=regexprep(txt,'1','true');
txt=regexprep(txt,'0','false');
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],\n['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
txt=[pre txt post];
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function newstr=escapejsonstring(str)
newstr=str;
isoct=exist('OCTAVE_VERSION','builtin');
if(isoct)
vv=sscanf(OCTAVE_VERSION,'%f');
if(vv(1)>=3.8) isoct=0; end
end
if(isoct)
escapechars={'\a','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},escapechars{i});
end
else
escapechars={'\a','\b','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},regexprep(escapechars{i},'\\','\\\\'));
end
end
|
github
|
khanhnamle1994/machine-learning-master
|
loadjson.m
|
.m
|
machine-learning-master/machine-learning-ex4/ex4/lib/jsonlab/loadjson.m
| 18,732 |
ibm852
|
ab98cf173af2d50bbe8da4d6db252a20
|
function data = loadjson(fname,varargin)
%
% data=loadjson(fname,opt)
% or
% data=loadjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09, including previous works from
%
% Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
% created on 2009/11/02
% François Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393
% created on 2009/03/22
% Joel Feenstra:
% http://www.mathworks.com/matlabcentral/fileexchange/20565
% created on 2008/07/03
%
% $Id: loadjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a JSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.FastArrayParser [1|0 or integer]: if set to 1, use a
% speed-optimized array parser when loading an
% array object. The fast array parser may
% collapse block arrays into a single large
% array similar to rules defined in cell2mat; 0 to
% use a legacy parser; if set to a larger-than-1
% value, this option will specify the minimum
% dimension to enable the fast array parser. For
% example, if the input is a 3D array, setting
% FastArrayParser to 1 will return a 3D array;
% setting to 2 will return a cell array of 2D
% arrays; setting to 3 will return to a 2D cell
% array of 1D vectors; setting to 4 will return a
% 3D cell array.
% opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% dat=loadjson('{"obj":{"string":"value","array":[1,2,3]}}')
% dat=loadjson(['examples' filesep 'example1.json'])
% dat=loadjson(['examples' filesep 'example1.json'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
if(jsonopt('ShowProgress',0,opt)==1)
opt.progressbar_=waitbar(0,'loading ...');
end
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
if(isfield(opt,'progressbar_'))
close(opt.progressbar_);
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=data(j).x0x5F_ArraySize_;
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
if next_char ~= '}'
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
parse_char(':');
val = parse_value(varargin{:});
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}'
break;
end
parse_char(',');
end
end
parse_char('}');
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim2=[];
arraydepth=jsonopt('JSONLAB_ArrayDepth_',1,varargin{:});
pbar=jsonopt('progressbar_',-1,varargin{:});
if next_char ~= ']'
if(jsonopt('FastArrayParser',1,varargin{:})>=1 && arraydepth>=jsonopt('FastArrayParser',1,varargin{:}))
[endpos, e1l, e1r, maxlevel]=matching_bracket(inStr,pos);
arraystr=['[' inStr(pos:endpos)];
arraystr=regexprep(arraystr,'"_NaN_"','NaN');
arraystr=regexprep(arraystr,'"([-+]*)_Inf_"','$1Inf');
arraystr(arraystr==sprintf('\n'))=[];
arraystr(arraystr==sprintf('\r'))=[];
%arraystr=regexprep(arraystr,'\s*,',','); % this is slow,sometimes needed
if(~isempty(e1l) && ~isempty(e1r)) % the array is in 2D or higher D
astr=inStr((e1l+1):(e1r-1));
astr=regexprep(astr,'"_NaN_"','NaN');
astr=regexprep(astr,'"([-+]*)_Inf_"','$1Inf');
astr(astr==sprintf('\n'))=[];
astr(astr==sprintf('\r'))=[];
astr(astr==' ')='';
if(isempty(find(astr=='[', 1))) % array is 2D
dim2=length(sscanf(astr,'%f,',[1 inf]));
end
else % array is 1D
astr=arraystr(2:end-1);
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',[1,inf]);
if(nextidx>=length(astr)-1)
object=obj;
pos=endpos;
parse_char(']');
return;
end
end
if(~isempty(dim2))
astr=arraystr;
astr(astr=='[')='';
astr(astr==']')='';
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',inf);
if(nextidx>=length(astr)-1)
object=reshape(obj,dim2,numel(obj)/dim2)';
pos=endpos;
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
return;
end
end
arraystr=regexprep(arraystr,'\]\s*,','];');
else
arraystr='[';
end
try
if(isoct && regexp(arraystr,'"','once'))
error('Octave eval can produce empty cells for JSON-like input');
end
object=eval(arraystr);
pos=endpos;
catch
while 1
newopt=varargin2struct(varargin{:},'JSONLAB_ArrayDepth_',arraydepth+1);
val = parse_value(newopt);
object{end+1} = val;
if next_char == ']'
break;
end
parse_char(',');
end
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr len esc index_esc len_esc
% len, ns = length(inStr), keyboard
if inStr(pos) ~= '"'
error_pos('String starting with " expected at position %d');
else
pos = pos + 1;
end
str = '';
while pos <= len
while index_esc <= len_esc && esc(index_esc) < pos
index_esc = index_esc + 1;
end
if index_esc > len_esc
str = [str inStr(pos:len)];
pos = len + 1;
break;
else
str = [str inStr(pos:esc(index_esc)-1)];
pos = esc(index_esc);
end
nstr = length(str); switch inStr(pos)
case '"'
pos = pos + 1;
if(~isempty(str))
if(strcmp(str,'_Inf_'))
str=Inf;
elseif(strcmp(str,'-_Inf_'))
str=-Inf;
elseif(strcmp(str,'_NaN_'))
str=NaN;
end
end
return;
case '\'
if pos+1 > len
error_pos('End of file reached right after escape character');
end
pos = pos + 1;
switch inStr(pos)
case {'"' '\' '/'}
str(nstr+1) = inStr(pos);
pos = pos + 1;
case {'b' 'f' 'n' 'r' 't'}
str(nstr+1) = sprintf(['\' inStr(pos)]);
pos = pos + 1;
case 'u'
if pos+4 > len
error_pos('End of file reached in escaped unicode character');
end
str(nstr+(1:6)) = inStr(pos-1:pos+4);
pos = pos + 5;
end
otherwise % should never happen
str(nstr+1) = inStr(pos), keyboard
pos = pos + 1;
end
end
error_pos('End of file while expecting end of inStr');
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct
currstr=inStr(pos:end);
numstr=0;
if(isoct~=0)
numstr=regexp(currstr,'^\s*-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?','end');
[num, one] = sscanf(currstr, '%f', 1);
delta=numstr+1;
else
[num, one, err, delta] = sscanf(currstr, '%f', 1);
if ~isempty(err)
error_pos('Error reading number at position %d');
end
end
pos = pos + delta-1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
pbar=jsonopt('progressbar_',-1,varargin{:});
if(pbar>0)
waitbar(pos/len,pbar,'loading ...');
end
switch(inStr(pos))
case '"'
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'-','0','1','2','3','4','5','6','7','8','9'}
val = parse_number(varargin{:});
return;
case 't'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'true')
val = true;
pos = pos + 4;
return;
end
case 'f'
if pos+4 <= len && strcmpi(inStr(pos:pos+4), 'false')
val = false;
pos = pos + 5;
return;
end
case 'n'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'null')
val = [];
pos = pos + 4;
return;
end
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos, e1l, e1r, maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
khanhnamle1994/machine-learning-master
|
loadubjson.m
|
.m
|
machine-learning-master/machine-learning-ex4/ex4/lib/jsonlab/loadubjson.m
| 15,574 |
utf_8
|
5974e78e71b81b1e0f76123784b951a4
|
function data = loadubjson(fname,varargin)
%
% data=loadubjson(fname,opt)
% or
% data=loadubjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/01
%
% $Id: loadubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a UBJSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadubjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.IntEndian [B|L]: specify the endianness of the integer fields
% in the UBJSON input data. B - Big-Endian format for
% integers (as required in the UBJSON specification);
% L - input integer fields are in Little-Endian order.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% obj=struct('string','value','array',[1 2 3]);
% ubjdata=saveubjson('obj',obj);
% dat=loadubjson(ubjdata)
% dat=loadubjson(['examples' filesep 'example1.ubj'])
% dat=loadubjson(['examples' filesep 'example1.ubj'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken fileendian systemendian
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
fileendian=upper(jsonopt('IntEndian','B',opt));
[os,maxelem,systemendian]=computer;
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
%%
function newdata=parse_collection(id,data,obj)
if(jsoncount>0 && exist('data','var'))
if(~iscell(data))
newdata=cell(1);
newdata{1}=data;
data=newdata;
end
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=double(data(j).x0x5F_ArraySize_);
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1); % TODO
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
count=double(parse_number());
end
if next_char ~= '}'
num=0;
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
%parse_char(':');
val = parse_value(varargin{:});
num=num+1;
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}' || (count>=0 && num>=count)
break;
end
%parse_char(',');
end
end
if(count==-1)
parse_char('}');
end
%%-------------------------------------------------------------------------
function [cid,len]=elem_info(type)
id=strfind('iUIlLdD',type);
dataclass={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
if(id>0)
cid=dataclass{id};
len=bytelen(id);
else
error_pos('unsupported type at position %d');
end
%%-------------------------------------------------------------------------
function [data adv]=parse_block(type,count,varargin)
global pos inStr isoct fileendian systemendian
[cid,len]=elem_info(type);
datastr=inStr(pos:pos+len*count-1);
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
id=strfind('iUIlLdD',type);
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,cid));
end
data=typecast(newdata,cid);
adv=double(len*count);
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim=[];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1);
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
if(next_char=='[')
dim=parse_array(varargin{:});
count=prod(double(dim));
else
count=double(parse_number());
end
end
if(~isempty(type))
if(count>=0)
[object adv]=parse_block(type,count,varargin{:});
if(~isempty(dim))
object=reshape(object,dim);
end
pos=pos+adv;
return;
else
endpos=matching_bracket(inStr,pos);
[cid,len]=elem_info(type);
count=(endpos-pos)/len;
[object adv]=parse_block(type,count,varargin{:});
pos=pos+adv;
parse_char(']');
return;
end
end
if next_char ~= ']'
while 1
val = parse_value(varargin{:});
object{end+1} = val;
if next_char == ']'
break;
end
%parse_char(',');
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
if(count==-1)
parse_char(']');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr esc index_esc len_esc
% len, ns = length(inStr), keyboard
type=inStr(pos);
if type ~= 'S' && type ~= 'C' && type ~= 'H'
error_pos('String starting with S expected at position %d');
else
pos = pos + 1;
end
if(type == 'C')
str=inStr(pos);
pos=pos+1;
return;
end
bytelen=double(parse_number());
if(length(inStr)>=pos+bytelen-1)
str=inStr(pos:pos+bytelen-1);
pos=pos+bytelen;
else
error_pos('End of file while expecting end of inStr');
end
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct fileendian systemendian
id=strfind('iUIlLdD',inStr(pos));
if(isempty(id))
error_pos('expecting a number at position %d');
end
type={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
datastr=inStr(pos+1:pos+bytelen(id));
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,type{id}));
end
num=typecast(newdata,type{id});
pos = pos + bytelen(id)+1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
switch(inStr(pos))
case {'S','C','H'}
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'i','U','I','l','L','d','D'}
val = parse_number(varargin{:});
return;
case 'T'
val = true;
pos = pos + 1;
return;
case 'F'
val = false;
pos = pos + 1;
return;
case {'Z','N'}
val = [];
pos = pos + 1;
return;
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos e1l e1r maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
khanhnamle1994/machine-learning-master
|
saveubjson.m
|
.m
|
machine-learning-master/machine-learning-ex4/ex4/lib/jsonlab/saveubjson.m
| 16,123 |
utf_8
|
61d4f51010aedbf97753396f5d2d9ec0
|
function json=saveubjson(rootname,obj,varargin)
%
% json=saveubjson(rootname,obj,filename)
% or
% json=saveubjson(rootname,obj,opt)
% json=saveubjson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a Universal
% Binary JSON (UBJSON) binary string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/17
%
% $Id: saveubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array)
% filename: a string for the file name to save the output UBJSON data
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.ArrayToStruct[0|1]: when set to 0, saveubjson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [1|0]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, saveubjson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSON='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a binary string in the UBJSON format (see http://ubjson.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% saveubjson('jsonmesh',jsonmesh)
% saveubjson('jsonmesh',jsonmesh,'meshdata.ubj')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
json=obj2ubjson(rootname,obj,rootlevel,opt);
if(~rootisarray)
json=['{' json '}'];
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=[jsonp '(' json ')'];
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2ubjson(name,item,level,varargin)
if(iscell(item))
txt=cell2ubjson(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2ubjson(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2ubjson(name,item,level,varargin{:});
else
txt=mat2ubjson(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2ubjson(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item); % let's handle 1D cell first
if(len>1)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) '[']; name='';
else
txt='[';
end
elseif(len==0)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) 'Z']; name='';
else
txt='Z';
end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
txt=[txt obj2ubjson(name,item{i,j},level+(len>1),varargin{:})];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=struct2ubjson(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=[txt S_(checkname(name,varargin{:})) '{'];
else
txt=[txt '{'];
end
if(~isempty(names))
for e=1:length(names)
txt=[txt obj2ubjson(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:})];
end
end
txt=[txt '}'];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=str2ubjson(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
val=item(e,:);
if(len==1)
obj=['' S_(checkname(name,varargin{:})) '' '',S_(val),''];
if(isempty(name)) obj=['',S_(val),'']; end
txt=[txt,'',obj];
else
txt=[txt,'',['',S_(val),'']];
end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=mat2ubjson(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) || jsonopt('ArrayToStruct',0,varargin{:}))
cid=I_(uint32(max(size(item))));
if(isempty(name))
txt=['{' S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1)) ];
else
if(isempty(item))
txt=[S_(checkname(name,varargin{:})),'Z'];
return;
else
txt=[S_(checkname(name,varargin{:})),'{',S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1))];
end
end
else
if(isempty(name))
txt=matdata2ubjson(item,level+1,varargin{:});
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
numtxt=regexprep(regexprep(matdata2ubjson(item,level+1,varargin{:}),'^\[',''),']','');
txt=[S_(checkname(name,varargin{:})) numtxt];
else
txt=[S_(checkname(name,varargin{:})),matdata2ubjson(item,level+1,varargin{:})];
end
end
return;
end
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=[txt,S_('_ArrayIsComplex_'),'T'];
end
txt=[txt,S_('_ArrayIsSparse_'),'T'];
if(size(item,1)==1)
% Row vector, store only column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([iy(:),data'],level+2,varargin{:})];
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,data],level+2,varargin{:})];
else
% General case, store row and column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,iy,data],level+2,varargin{:})];
end
else
if(isreal(item))
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson(item(:)',level+2,varargin{:})];
else
txt=[txt,S_('_ArrayIsComplex_'),'T'];
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([real(item(:)) imag(item(:))],level+2,varargin{:})];
end
end
txt=[txt,'}'];
%%-------------------------------------------------------------------------
function txt=matdata2ubjson(mat,level,varargin)
if(isempty(mat))
txt='Z';
return;
end
if(size(mat,1)==1)
level=level-1;
end
type='';
hasnegtive=(mat<0);
if(isa(mat,'integer') || isinteger(mat) || (isfloat(mat) && all(mod(mat(:),1) == 0)))
if(isempty(hasnegtive))
if(max(mat(:))<=2^8)
type='U';
end
end
if(isempty(type))
% todo - need to consider negative ones separately
id= histc(abs(max(mat(:))),[0 2^7 2^15 2^31 2^63]);
if(isempty(find(id)))
error('high-precision data is not yet supported');
end
key='iIlL';
type=key(find(id));
end
txt=[I_a(mat(:),type,size(mat))];
elseif(islogical(mat))
logicalval='FT';
if(numel(mat)==1)
txt=logicalval(mat+1);
else
txt=['[$U#' I_a(size(mat),'l') typecast(swapbytes(uint8(mat(:)')),'uint8')];
end
else
if(numel(mat)==1)
txt=['[' D_(mat) ']'];
else
txt=D_a(mat(:),'D',size(mat));
end
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function val=S_(str)
if(length(str)==1)
val=['C' str];
else
val=['S' I_(int32(length(str))) str];
end
%%-------------------------------------------------------------------------
function val=I_(num)
if(~isinteger(num))
error('input is not an integer');
end
if(num>=0 && num<255)
val=['U' data2byte(swapbytes(cast(num,'uint8')),'uint8')];
return;
end
key='iIlL';
cid={'int8','int16','int32','int64'};
for i=1:4
if((num>0 && num<2^(i*8-1)) || (num<0 && num>=-2^(i*8-1)))
val=[key(i) data2byte(swapbytes(cast(num,cid{i})),'uint8')];
return;
end
end
error('unsupported integer');
%%-------------------------------------------------------------------------
function val=D_(num)
if(~isfloat(num))
error('input is not a float');
end
if(isa(num,'single'))
val=['d' data2byte(num,'uint8')];
else
val=['D' data2byte(num,'uint8')];
end
%%-------------------------------------------------------------------------
function data=I_a(num,type,dim,format)
id=find(ismember('iUIlL',type));
if(id==0)
error('unsupported integer array');
end
% based on UBJSON specs, all integer types are stored in big endian format
if(id==1)
data=data2byte(swapbytes(int8(num)),'uint8');
blen=1;
elseif(id==2)
data=data2byte(swapbytes(uint8(num)),'uint8');
blen=1;
elseif(id==3)
data=data2byte(swapbytes(int16(num)),'uint8');
blen=2;
elseif(id==4)
data=data2byte(swapbytes(int32(num)),'uint8');
blen=4;
elseif(id==5)
data=data2byte(swapbytes(int64(num)),'uint8');
blen=8;
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/blen)) data(:)'];
end
data=['[' data(:)'];
else
data=reshape(data,blen,numel(data)/blen);
data(2:blen+1,:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function data=D_a(num,type,dim,format)
id=find(ismember('dD',type));
if(id==0)
error('unsupported float array');
end
if(id==1)
data=data2byte(single(num),'uint8');
elseif(id==2)
data=data2byte(double(num),'uint8');
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/(id*4))) data(:)'];
end
data=['[' data];
else
data=reshape(data,(id*4),length(data)/(id*4));
data(2:(id*4+1),:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function bytes=data2byte(varargin)
bytes=typecast(varargin{:});
bytes=bytes(:)';
|
github
|
khanhnamle1994/machine-learning-master
|
submit.m
|
.m
|
machine-learning-master/machine-learning-ex6/ex6/submit.m
| 1,318 |
utf_8
|
bfa0b4ffb8a7854d8e84276e91818107
|
function submit()
addpath('./lib');
conf.assignmentSlug = 'support-vector-machines';
conf.itemName = 'Support Vector Machines';
conf.partArrays = { ...
{ ...
'1', ...
{ 'gaussianKernel.m' }, ...
'Gaussian Kernel', ...
}, ...
{ ...
'2', ...
{ 'dataset3Params.m' }, ...
'Parameters (C, sigma) for Dataset 3', ...
}, ...
{ ...
'3', ...
{ 'processEmail.m' }, ...
'Email Preprocessing', ...
}, ...
{ ...
'4', ...
{ 'emailFeatures.m' }, ...
'Email Feature Extraction', ...
}, ...
};
conf.output = @output;
submitWithConfiguration(conf);
end
function out = output(partId, auxstring)
% Random Test Cases
x1 = sin(1:10)';
x2 = cos(1:10)';
ec = 'the quick brown fox jumped over the lazy dog';
wi = 1 + abs(round(x1 * 1863));
wi = [wi ; wi];
if partId == '1'
sim = gaussianKernel(x1, x2, 2);
out = sprintf('%0.5f ', sim);
elseif partId == '2'
load('ex6data3.mat');
[C, sigma] = dataset3Params(X, y, Xval, yval);
out = sprintf('%0.5f ', C);
out = [out sprintf('%0.5f ', sigma)];
elseif partId == '3'
word_indices = processEmail(ec);
out = sprintf('%d ', word_indices);
elseif partId == '4'
x = emailFeatures(wi);
out = sprintf('%d ', x);
end
end
|
github
|
khanhnamle1994/machine-learning-master
|
porterStemmer.m
|
.m
|
machine-learning-master/machine-learning-ex6/ex6/porterStemmer.m
| 9,902 |
utf_8
|
7ed5acd925808fde342fc72bd62ebc4d
|
function stem = porterStemmer(inString)
% Applies the Porter Stemming algorithm as presented in the following
% paper:
% Porter, 1980, An algorithm for suffix stripping, Program, Vol. 14,
% no. 3, pp 130-137
% Original code modeled after the C version provided at:
% http://www.tartarus.org/~martin/PorterStemmer/c.txt
% The main part of the stemming algorithm starts here. b is an array of
% characters, holding the word to be stemmed. The letters are in b[k0],
% b[k0+1] ending at b[k]. In fact k0 = 1 in this demo program (since
% matlab begins indexing by 1 instead of 0). k is readjusted downwards as
% the stemming progresses. Zero termination is not in fact used in the
% algorithm.
% To call this function, use the string to be stemmed as the input
% argument. This function returns the stemmed word as a string.
% Lower-case string
inString = lower(inString);
global j;
b = inString;
k = length(b);
k0 = 1;
j = k;
% With this if statement, strings of length 1 or 2 don't go through the
% stemming process. Remove this conditional to match the published
% algorithm.
stem = b;
if k > 2
% Output displays per step are commented out.
%disp(sprintf('Word to stem: %s', b));
x = step1ab(b, k, k0);
%disp(sprintf('Steps 1A and B yield: %s', x{1}));
x = step1c(x{1}, x{2}, k0);
%disp(sprintf('Step 1C yields: %s', x{1}));
x = step2(x{1}, x{2}, k0);
%disp(sprintf('Step 2 yields: %s', x{1}));
x = step3(x{1}, x{2}, k0);
%disp(sprintf('Step 3 yields: %s', x{1}));
x = step4(x{1}, x{2}, k0);
%disp(sprintf('Step 4 yields: %s', x{1}));
x = step5(x{1}, x{2}, k0);
%disp(sprintf('Step 5 yields: %s', x{1}));
stem = x{1};
end
% cons(j) is TRUE <=> b[j] is a consonant.
function c = cons(i, b, k0)
c = true;
switch(b(i))
case {'a', 'e', 'i', 'o', 'u'}
c = false;
case 'y'
if i == k0
c = true;
else
c = ~cons(i - 1, b, k0);
end
end
% mseq() measures the number of consonant sequences between k0 and j. If
% c is a consonant sequence and v a vowel sequence, and <..> indicates
% arbitrary presence,
% <c><v> gives 0
% <c>vc<v> gives 1
% <c>vcvc<v> gives 2
% <c>vcvcvc<v> gives 3
% ....
function n = measure(b, k0)
global j;
n = 0;
i = k0;
while true
if i > j
return
end
if ~cons(i, b, k0)
break;
end
i = i + 1;
end
i = i + 1;
while true
while true
if i > j
return
end
if cons(i, b, k0)
break;
end
i = i + 1;
end
i = i + 1;
n = n + 1;
while true
if i > j
return
end
if ~cons(i, b, k0)
break;
end
i = i + 1;
end
i = i + 1;
end
% vowelinstem() is TRUE <=> k0,...j contains a vowel
function vis = vowelinstem(b, k0)
global j;
for i = k0:j,
if ~cons(i, b, k0)
vis = true;
return
end
end
vis = false;
%doublec(i) is TRUE <=> i,(i-1) contain a double consonant.
function dc = doublec(i, b, k0)
if i < k0+1
dc = false;
return
end
if b(i) ~= b(i-1)
dc = false;
return
end
dc = cons(i, b, k0);
% cvc(j) is TRUE <=> j-2,j-1,j has the form consonant - vowel - consonant
% and also if the second c is not w,x or y. this is used when trying to
% restore an e at the end of a short word. e.g.
%
% cav(e), lov(e), hop(e), crim(e), but
% snow, box, tray.
function c1 = cvc(i, b, k0)
if ((i < (k0+2)) || ~cons(i, b, k0) || cons(i-1, b, k0) || ~cons(i-2, b, k0))
c1 = false;
else
if (b(i) == 'w' || b(i) == 'x' || b(i) == 'y')
c1 = false;
return
end
c1 = true;
end
% ends(s) is TRUE <=> k0,...k ends with the string s.
function s = ends(str, b, k)
global j;
if (str(length(str)) ~= b(k))
s = false;
return
end % tiny speed-up
if (length(str) > k)
s = false;
return
end
if strcmp(b(k-length(str)+1:k), str)
s = true;
j = k - length(str);
return
else
s = false;
end
% setto(s) sets (j+1),...k to the characters in the string s, readjusting
% k accordingly.
function so = setto(s, b, k)
global j;
for i = j+1:(j+length(s))
b(i) = s(i-j);
end
if k > j+length(s)
b((j+length(s)+1):k) = '';
end
k = length(b);
so = {b, k};
% rs(s) is used further down.
% [Note: possible null/value for r if rs is called]
function r = rs(str, b, k, k0)
r = {b, k};
if measure(b, k0) > 0
r = setto(str, b, k);
end
% step1ab() gets rid of plurals and -ed or -ing. e.g.
% caresses -> caress
% ponies -> poni
% ties -> ti
% caress -> caress
% cats -> cat
% feed -> feed
% agreed -> agree
% disabled -> disable
% matting -> mat
% mating -> mate
% meeting -> meet
% milling -> mill
% messing -> mess
% meetings -> meet
function s1ab = step1ab(b, k, k0)
global j;
if b(k) == 's'
if ends('sses', b, k)
k = k-2;
elseif ends('ies', b, k)
retVal = setto('i', b, k);
b = retVal{1};
k = retVal{2};
elseif (b(k-1) ~= 's')
k = k-1;
end
end
if ends('eed', b, k)
if measure(b, k0) > 0;
k = k-1;
end
elseif (ends('ed', b, k) || ends('ing', b, k)) && vowelinstem(b, k0)
k = j;
retVal = {b, k};
if ends('at', b, k)
retVal = setto('ate', b(k0:k), k);
elseif ends('bl', b, k)
retVal = setto('ble', b(k0:k), k);
elseif ends('iz', b, k)
retVal = setto('ize', b(k0:k), k);
elseif doublec(k, b, k0)
retVal = {b, k-1};
if b(retVal{2}) == 'l' || b(retVal{2}) == 's' || ...
b(retVal{2}) == 'z'
retVal = {retVal{1}, retVal{2}+1};
end
elseif measure(b, k0) == 1 && cvc(k, b, k0)
retVal = setto('e', b(k0:k), k);
end
k = retVal{2};
b = retVal{1}(k0:k);
end
j = k;
s1ab = {b(k0:k), k};
% step1c() turns terminal y to i when there is another vowel in the stem.
function s1c = step1c(b, k, k0)
global j;
if ends('y', b, k) && vowelinstem(b, k0)
b(k) = 'i';
end
j = k;
s1c = {b, k};
% step2() maps double suffices to single ones. so -ization ( = -ize plus
% -ation) maps to -ize etc. note that the string before the suffix must give
% m() > 0.
function s2 = step2(b, k, k0)
global j;
s2 = {b, k};
switch b(k-1)
case {'a'}
if ends('ational', b, k) s2 = rs('ate', b, k, k0);
elseif ends('tional', b, k) s2 = rs('tion', b, k, k0); end;
case {'c'}
if ends('enci', b, k) s2 = rs('ence', b, k, k0);
elseif ends('anci', b, k) s2 = rs('ance', b, k, k0); end;
case {'e'}
if ends('izer', b, k) s2 = rs('ize', b, k, k0); end;
case {'l'}
if ends('bli', b, k) s2 = rs('ble', b, k, k0);
elseif ends('alli', b, k) s2 = rs('al', b, k, k0);
elseif ends('entli', b, k) s2 = rs('ent', b, k, k0);
elseif ends('eli', b, k) s2 = rs('e', b, k, k0);
elseif ends('ousli', b, k) s2 = rs('ous', b, k, k0); end;
case {'o'}
if ends('ization', b, k) s2 = rs('ize', b, k, k0);
elseif ends('ation', b, k) s2 = rs('ate', b, k, k0);
elseif ends('ator', b, k) s2 = rs('ate', b, k, k0); end;
case {'s'}
if ends('alism', b, k) s2 = rs('al', b, k, k0);
elseif ends('iveness', b, k) s2 = rs('ive', b, k, k0);
elseif ends('fulness', b, k) s2 = rs('ful', b, k, k0);
elseif ends('ousness', b, k) s2 = rs('ous', b, k, k0); end;
case {'t'}
if ends('aliti', b, k) s2 = rs('al', b, k, k0);
elseif ends('iviti', b, k) s2 = rs('ive', b, k, k0);
elseif ends('biliti', b, k) s2 = rs('ble', b, k, k0); end;
case {'g'}
if ends('logi', b, k) s2 = rs('log', b, k, k0); end;
end
j = s2{2};
% step3() deals with -ic-, -full, -ness etc. similar strategy to step2.
function s3 = step3(b, k, k0)
global j;
s3 = {b, k};
switch b(k)
case {'e'}
if ends('icate', b, k) s3 = rs('ic', b, k, k0);
elseif ends('ative', b, k) s3 = rs('', b, k, k0);
elseif ends('alize', b, k) s3 = rs('al', b, k, k0); end;
case {'i'}
if ends('iciti', b, k) s3 = rs('ic', b, k, k0); end;
case {'l'}
if ends('ical', b, k) s3 = rs('ic', b, k, k0);
elseif ends('ful', b, k) s3 = rs('', b, k, k0); end;
case {'s'}
if ends('ness', b, k) s3 = rs('', b, k, k0); end;
end
j = s3{2};
% step4() takes off -ant, -ence etc., in context <c>vcvc<v>.
function s4 = step4(b, k, k0)
global j;
switch b(k-1)
case {'a'}
if ends('al', b, k) end;
case {'c'}
if ends('ance', b, k)
elseif ends('ence', b, k) end;
case {'e'}
if ends('er', b, k) end;
case {'i'}
if ends('ic', b, k) end;
case {'l'}
if ends('able', b, k)
elseif ends('ible', b, k) end;
case {'n'}
if ends('ant', b, k)
elseif ends('ement', b, k)
elseif ends('ment', b, k)
elseif ends('ent', b, k) end;
case {'o'}
if ends('ion', b, k)
if j == 0
elseif ~(strcmp(b(j),'s') || strcmp(b(j),'t'))
j = k;
end
elseif ends('ou', b, k) end;
case {'s'}
if ends('ism', b, k) end;
case {'t'}
if ends('ate', b, k)
elseif ends('iti', b, k) end;
case {'u'}
if ends('ous', b, k) end;
case {'v'}
if ends('ive', b, k) end;
case {'z'}
if ends('ize', b, k) end;
end
if measure(b, k0) > 1
s4 = {b(k0:j), j};
else
s4 = {b(k0:k), k};
end
% step5() removes a final -e if m() > 1, and changes -ll to -l if m() > 1.
function s5 = step5(b, k, k0)
global j;
j = k;
if b(k) == 'e'
a = measure(b, k0);
if (a > 1) || ((a == 1) && ~cvc(k-1, b, k0))
k = k-1;
end
end
if (b(k) == 'l') && doublec(k, b, k0) && (measure(b, k0) > 1)
k = k-1;
end
s5 = {b(k0:k), k};
|
github
|
khanhnamle1994/machine-learning-master
|
submitWithConfiguration.m
|
.m
|
machine-learning-master/machine-learning-ex6/ex6/lib/submitWithConfiguration.m
| 5,562 |
utf_8
|
4ac719ea6570ac228ea6c7a9c919e3f5
|
function submitWithConfiguration(conf)
addpath('./lib/jsonlab');
parts = parts(conf);
fprintf('== Submitting solutions | %s...\n', conf.itemName);
tokenFile = 'token.mat';
if exist(tokenFile, 'file')
load(tokenFile);
[email token] = promptToken(email, token, tokenFile);
else
[email token] = promptToken('', '', tokenFile);
end
if isempty(token)
fprintf('!! Submission Cancelled\n');
return
end
try
response = submitParts(conf, email, token, parts);
catch
e = lasterror();
fprintf('\n!! Submission failed: %s\n', e.message);
fprintf('\n\nFunction: %s\nFileName: %s\nLineNumber: %d\n', ...
e.stack(1,1).name, e.stack(1,1).file, e.stack(1,1).line);
fprintf('\nPlease correct your code and resubmit.\n');
return
end
if isfield(response, 'errorMessage')
fprintf('!! Submission failed: %s\n', response.errorMessage);
elseif isfield(response, 'errorCode')
fprintf('!! Submission failed: %s\n', response.message);
else
showFeedback(parts, response);
save(tokenFile, 'email', 'token');
end
end
function [email token] = promptToken(email, existingToken, tokenFile)
if (~isempty(email) && ~isempty(existingToken))
prompt = sprintf( ...
'Use token from last successful submission (%s)? (Y/n): ', ...
email);
reenter = input(prompt, 's');
if (isempty(reenter) || reenter(1) == 'Y' || reenter(1) == 'y')
token = existingToken;
return;
else
delete(tokenFile);
end
end
email = input('Login (email address): ', 's');
token = input('Token: ', 's');
end
function isValid = isValidPartOptionIndex(partOptions, i)
isValid = (~isempty(i)) && (1 <= i) && (i <= numel(partOptions));
end
function response = submitParts(conf, email, token, parts)
body = makePostBody(conf, email, token, parts);
submissionUrl = submissionUrl();
responseBody = getResponse(submissionUrl, body);
jsonResponse = validateResponse(responseBody);
response = loadjson(jsonResponse);
end
function body = makePostBody(conf, email, token, parts)
bodyStruct.assignmentSlug = conf.assignmentSlug;
bodyStruct.submitterEmail = email;
bodyStruct.secret = token;
bodyStruct.parts = makePartsStruct(conf, parts);
opt.Compact = 1;
body = savejson('', bodyStruct, opt);
end
function partsStruct = makePartsStruct(conf, parts)
for part = parts
partId = part{:}.id;
fieldName = makeValidFieldName(partId);
outputStruct.output = conf.output(partId);
partsStruct.(fieldName) = outputStruct;
end
end
function [parts] = parts(conf)
parts = {};
for partArray = conf.partArrays
part.id = partArray{:}{1};
part.sourceFiles = partArray{:}{2};
part.name = partArray{:}{3};
parts{end + 1} = part;
end
end
function showFeedback(parts, response)
fprintf('== \n');
fprintf('== %43s | %9s | %-s\n', 'Part Name', 'Score', 'Feedback');
fprintf('== %43s | %9s | %-s\n', '---------', '-----', '--------');
for part = parts
score = '';
partFeedback = '';
partFeedback = response.partFeedbacks.(makeValidFieldName(part{:}.id));
partEvaluation = response.partEvaluations.(makeValidFieldName(part{:}.id));
score = sprintf('%d / %3d', partEvaluation.score, partEvaluation.maxScore);
fprintf('== %43s | %9s | %-s\n', part{:}.name, score, partFeedback);
end
evaluation = response.evaluation;
totalScore = sprintf('%d / %d', evaluation.score, evaluation.maxScore);
fprintf('== --------------------------------\n');
fprintf('== %43s | %9s | %-s\n', '', totalScore, '');
fprintf('== \n');
end
% use urlread or curl to send submit results to the grader and get a response
function response = getResponse(url, body)
% try using urlread() and a secure connection
params = {'jsonBody', body};
[response, success] = urlread(url, 'post', params);
if (success == 0)
% urlread didn't work, try curl & the peer certificate patch
if ispc
% testing note: use 'jsonBody =' for a test case
json_command = sprintf('echo jsonBody=%s | curl -k -X POST -d @- %s', body, url);
else
% it's linux/OS X, so use the other form
json_command = sprintf('echo ''jsonBody=%s'' | curl -k -X POST -d @- %s', body, url);
end
% get the response body for the peer certificate patch method
[code, response] = system(json_command);
% test the success code
if (code ~= 0)
fprintf('[error] submission with curl() was not successful\n');
end
end
end
% validate the grader's response
function response = validateResponse(resp)
% test if the response is json or an HTML page
isJson = length(resp) > 0 && resp(1) == '{';
isHtml = findstr(lower(resp), '<html');
if (isJson)
response = resp;
elseif (isHtml)
% the response is html, so it's probably an error message
printHTMLContents(resp);
error('Grader response is an HTML message');
else
error('Grader sent no response');
end
end
% parse a HTML response and print it's contents
function printHTMLContents(response)
strippedResponse = regexprep(response, '<[^>]+>', ' ');
strippedResponse = regexprep(strippedResponse, '[\t ]+', ' ');
fprintf(strippedResponse);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Service configuration
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function submissionUrl = submissionUrl()
submissionUrl = 'https://www-origin.coursera.org/api/onDemandProgrammingImmediateFormSubmissions.v1';
end
|
github
|
khanhnamle1994/machine-learning-master
|
savejson.m
|
.m
|
machine-learning-master/machine-learning-ex6/ex6/lib/jsonlab/savejson.m
| 17,462 |
utf_8
|
861b534fc35ffe982b53ca3ca83143bf
|
function json=savejson(rootname,obj,varargin)
%
% json=savejson(rootname,obj,filename)
% or
% json=savejson(rootname,obj,opt)
% json=savejson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a JSON (JavaScript
% Object Notation) string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09
%
% $Id: savejson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array).
% filename: a string for the file name to save the output JSON data.
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.FloatFormat ['%.10g'|string]: format to show each numeric element
% of a 1D/2D array;
% opt.ArrayIndent [1|0]: if 1, output explicit data array with
% precedent indentation; if 0, no indentation
% opt.ArrayToStruct[0|1]: when set to 0, savejson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [0|1]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, savejson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.Inf ['"$1_Inf_"'|string]: a customized regular expression pattern
% to represent +/-Inf. The matched pattern is '([-+]*)Inf'
% and $1 represents the sign. For those who want to use
% 1e999 to represent Inf, they can set opt.Inf to '$11e999'
% opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern
% to represent NaN
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSONP='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
% opt.SaveBinary [0|1]: 1 - save the JSON file in binary mode; 0 - text mode.
% opt.Compact [0|1]: 1- out compact JSON format (remove all newlines and tabs)
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a string in the JSON format (see http://json.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% savejson('jmesh',jsonmesh)
% savejson('',jsonmesh,'ArrayIndent',0,'FloatFormat','\t%.5g')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
whitespaces=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
if(jsonopt('Compact',0,opt)==1)
whitespaces=struct('tab','','newline','','sep',',');
end
if(~isfield(opt,'whitespaces_'))
opt.whitespaces_=whitespaces;
end
nl=whitespaces.newline;
json=obj2json(rootname,obj,rootlevel,opt);
if(rootisarray)
json=sprintf('%s%s',json,nl);
else
json=sprintf('{%s%s%s}\n',nl,json,nl);
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=sprintf('%s(%s);%s',jsonp,json,nl);
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
if(jsonopt('SaveBinary',0,opt)==1)
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
else
fid = fopen(opt.FileName, 'wt');
fwrite(fid,json,'char');
end
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2json(name,item,level,varargin)
if(iscell(item))
txt=cell2json(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2json(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2json(name,item,level,varargin{:});
else
txt=mat2json(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2json(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=jsonopt('whitespaces_',struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n')),varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
nl=ws.newline;
if(len>1)
if(~isempty(name))
txt=sprintf('%s"%s": [%s',padding0, checkname(name,varargin{:}),nl); name='';
else
txt=sprintf('%s[%s',padding0,nl);
end
elseif(len==0)
if(~isempty(name))
txt=sprintf('%s"%s": []',padding0, checkname(name,varargin{:})); name='';
else
txt=sprintf('%s[]',padding0);
end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
txt=sprintf('%s%s',txt,obj2json(name,item{i,j},level+(dim(1)>1)+1,varargin{:}));
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
%if(j==dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=struct2json(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
padding1=repmat(ws.tab,1,level+(dim(1)>1)+(len>1));
nl=ws.newline;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding0,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding0,nl); end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=sprintf('%s%s"%s": {%s',txt,padding1, checkname(name,varargin{:}),nl);
else
txt=sprintf('%s%s{%s',txt,padding1,nl);
end
if(~isempty(names))
for e=1:length(names)
txt=sprintf('%s%s',txt,obj2json(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:}));
if(e<length(names)) txt=sprintf('%s%s',txt,','); end
txt=sprintf('%s%s',txt,nl);
end
end
txt=sprintf('%s%s}',txt,padding1);
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=str2json(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding1,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding1,nl); end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
if(isoct)
val=regexprep(item(e,:),'\\','\\');
val=regexprep(val,'"','\"');
val=regexprep(val,'^"','\"');
else
val=regexprep(item(e,:),'\\','\\\\');
val=regexprep(val,'"','\\"');
val=regexprep(val,'^"','\\"');
end
val=escapejsonstring(val);
if(len==1)
obj=['"' checkname(name,varargin{:}) '": ' '"',val,'"'];
if(isempty(name)) obj=['"',val,'"']; end
txt=sprintf('%s%s%s%s',txt,padding1,obj);
else
txt=sprintf('%s%s%s%s',txt,padding0,['"',val,'"']);
end
if(e==len) sep=''; end
txt=sprintf('%s%s',txt,sep);
end
if(len>1) txt=sprintf('%s%s%s%s',txt,nl,padding1,']'); end
%%-------------------------------------------------------------------------
function txt=mat2json(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) ||jsonopt('ArrayToStruct',0,varargin{:}))
if(isempty(name))
txt=sprintf('%s{%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
else
txt=sprintf('%s"%s": {%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,checkname(name,varargin{:}),nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
end
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1 && level>0)
numtxt=regexprep(regexprep(matdata2json(item,level+1,varargin{:}),'^\[',''),']','');
else
numtxt=matdata2json(item,level+1,varargin{:});
end
if(isempty(name))
txt=sprintf('%s%s',padding1,numtxt);
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
else
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
end
end
return;
end
dataformat='%s%s%s%s%s';
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsSparse_": ','1', sep);
if(size(item,1)==1)
% Row vector, store only column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([iy(:),data'],level+2,varargin{:}), nl);
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,data],level+2,varargin{:}), nl);
else
% General case, store row and column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,iy,data],level+2,varargin{:}), nl);
end
else
if(isreal(item))
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json(item(:)',level+2,varargin{:}), nl);
else
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([real(item(:)) imag(item(:))],level+2,varargin{:}), nl);
end
end
txt=sprintf('%s%s%s',txt,padding1,'}');
%%-------------------------------------------------------------------------
function txt=matdata2json(mat,level,varargin)
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
tab=ws.tab;
nl=ws.newline;
if(size(mat,1)==1)
pre='';
post='';
level=level-1;
else
pre=sprintf('[%s',nl);
post=sprintf('%s%s]',nl,repmat(tab,1,level-1));
end
if(isempty(mat))
txt='null';
return;
end
floatformat=jsonopt('FloatFormat','%.10g',varargin{:});
%if(numel(mat)>1)
formatstr=['[' repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf('],%s',nl)]];
%else
% formatstr=[repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf(',\n')]];
%end
if(nargin>=2 && size(mat,1)>1 && jsonopt('ArrayIndent',1,varargin{:})==1)
formatstr=[repmat(tab,1,level) formatstr];
end
txt=sprintf(formatstr,mat');
txt(end-length(nl):end)=[];
if(islogical(mat) && jsonopt('ParseLogical',0,varargin{:})==1)
txt=regexprep(txt,'1','true');
txt=regexprep(txt,'0','false');
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],\n['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
txt=[pre txt post];
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function newstr=escapejsonstring(str)
newstr=str;
isoct=exist('OCTAVE_VERSION','builtin');
if(isoct)
vv=sscanf(OCTAVE_VERSION,'%f');
if(vv(1)>=3.8) isoct=0; end
end
if(isoct)
escapechars={'\a','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},escapechars{i});
end
else
escapechars={'\a','\b','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},regexprep(escapechars{i},'\\','\\\\'));
end
end
|
github
|
khanhnamle1994/machine-learning-master
|
loadjson.m
|
.m
|
machine-learning-master/machine-learning-ex6/ex6/lib/jsonlab/loadjson.m
| 18,732 |
ibm852
|
ab98cf173af2d50bbe8da4d6db252a20
|
function data = loadjson(fname,varargin)
%
% data=loadjson(fname,opt)
% or
% data=loadjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09, including previous works from
%
% Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
% created on 2009/11/02
% François Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393
% created on 2009/03/22
% Joel Feenstra:
% http://www.mathworks.com/matlabcentral/fileexchange/20565
% created on 2008/07/03
%
% $Id: loadjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a JSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.FastArrayParser [1|0 or integer]: if set to 1, use a
% speed-optimized array parser when loading an
% array object. The fast array parser may
% collapse block arrays into a single large
% array similar to rules defined in cell2mat; 0 to
% use a legacy parser; if set to a larger-than-1
% value, this option will specify the minimum
% dimension to enable the fast array parser. For
% example, if the input is a 3D array, setting
% FastArrayParser to 1 will return a 3D array;
% setting to 2 will return a cell array of 2D
% arrays; setting to 3 will return to a 2D cell
% array of 1D vectors; setting to 4 will return a
% 3D cell array.
% opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% dat=loadjson('{"obj":{"string":"value","array":[1,2,3]}}')
% dat=loadjson(['examples' filesep 'example1.json'])
% dat=loadjson(['examples' filesep 'example1.json'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
if(jsonopt('ShowProgress',0,opt)==1)
opt.progressbar_=waitbar(0,'loading ...');
end
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
if(isfield(opt,'progressbar_'))
close(opt.progressbar_);
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=data(j).x0x5F_ArraySize_;
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
if next_char ~= '}'
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
parse_char(':');
val = parse_value(varargin{:});
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}'
break;
end
parse_char(',');
end
end
parse_char('}');
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim2=[];
arraydepth=jsonopt('JSONLAB_ArrayDepth_',1,varargin{:});
pbar=jsonopt('progressbar_',-1,varargin{:});
if next_char ~= ']'
if(jsonopt('FastArrayParser',1,varargin{:})>=1 && arraydepth>=jsonopt('FastArrayParser',1,varargin{:}))
[endpos, e1l, e1r, maxlevel]=matching_bracket(inStr,pos);
arraystr=['[' inStr(pos:endpos)];
arraystr=regexprep(arraystr,'"_NaN_"','NaN');
arraystr=regexprep(arraystr,'"([-+]*)_Inf_"','$1Inf');
arraystr(arraystr==sprintf('\n'))=[];
arraystr(arraystr==sprintf('\r'))=[];
%arraystr=regexprep(arraystr,'\s*,',','); % this is slow,sometimes needed
if(~isempty(e1l) && ~isempty(e1r)) % the array is in 2D or higher D
astr=inStr((e1l+1):(e1r-1));
astr=regexprep(astr,'"_NaN_"','NaN');
astr=regexprep(astr,'"([-+]*)_Inf_"','$1Inf');
astr(astr==sprintf('\n'))=[];
astr(astr==sprintf('\r'))=[];
astr(astr==' ')='';
if(isempty(find(astr=='[', 1))) % array is 2D
dim2=length(sscanf(astr,'%f,',[1 inf]));
end
else % array is 1D
astr=arraystr(2:end-1);
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',[1,inf]);
if(nextidx>=length(astr)-1)
object=obj;
pos=endpos;
parse_char(']');
return;
end
end
if(~isempty(dim2))
astr=arraystr;
astr(astr=='[')='';
astr(astr==']')='';
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',inf);
if(nextidx>=length(astr)-1)
object=reshape(obj,dim2,numel(obj)/dim2)';
pos=endpos;
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
return;
end
end
arraystr=regexprep(arraystr,'\]\s*,','];');
else
arraystr='[';
end
try
if(isoct && regexp(arraystr,'"','once'))
error('Octave eval can produce empty cells for JSON-like input');
end
object=eval(arraystr);
pos=endpos;
catch
while 1
newopt=varargin2struct(varargin{:},'JSONLAB_ArrayDepth_',arraydepth+1);
val = parse_value(newopt);
object{end+1} = val;
if next_char == ']'
break;
end
parse_char(',');
end
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr len esc index_esc len_esc
% len, ns = length(inStr), keyboard
if inStr(pos) ~= '"'
error_pos('String starting with " expected at position %d');
else
pos = pos + 1;
end
str = '';
while pos <= len
while index_esc <= len_esc && esc(index_esc) < pos
index_esc = index_esc + 1;
end
if index_esc > len_esc
str = [str inStr(pos:len)];
pos = len + 1;
break;
else
str = [str inStr(pos:esc(index_esc)-1)];
pos = esc(index_esc);
end
nstr = length(str); switch inStr(pos)
case '"'
pos = pos + 1;
if(~isempty(str))
if(strcmp(str,'_Inf_'))
str=Inf;
elseif(strcmp(str,'-_Inf_'))
str=-Inf;
elseif(strcmp(str,'_NaN_'))
str=NaN;
end
end
return;
case '\'
if pos+1 > len
error_pos('End of file reached right after escape character');
end
pos = pos + 1;
switch inStr(pos)
case {'"' '\' '/'}
str(nstr+1) = inStr(pos);
pos = pos + 1;
case {'b' 'f' 'n' 'r' 't'}
str(nstr+1) = sprintf(['\' inStr(pos)]);
pos = pos + 1;
case 'u'
if pos+4 > len
error_pos('End of file reached in escaped unicode character');
end
str(nstr+(1:6)) = inStr(pos-1:pos+4);
pos = pos + 5;
end
otherwise % should never happen
str(nstr+1) = inStr(pos), keyboard
pos = pos + 1;
end
end
error_pos('End of file while expecting end of inStr');
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct
currstr=inStr(pos:end);
numstr=0;
if(isoct~=0)
numstr=regexp(currstr,'^\s*-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?','end');
[num, one] = sscanf(currstr, '%f', 1);
delta=numstr+1;
else
[num, one, err, delta] = sscanf(currstr, '%f', 1);
if ~isempty(err)
error_pos('Error reading number at position %d');
end
end
pos = pos + delta-1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
pbar=jsonopt('progressbar_',-1,varargin{:});
if(pbar>0)
waitbar(pos/len,pbar,'loading ...');
end
switch(inStr(pos))
case '"'
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'-','0','1','2','3','4','5','6','7','8','9'}
val = parse_number(varargin{:});
return;
case 't'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'true')
val = true;
pos = pos + 4;
return;
end
case 'f'
if pos+4 <= len && strcmpi(inStr(pos:pos+4), 'false')
val = false;
pos = pos + 5;
return;
end
case 'n'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'null')
val = [];
pos = pos + 4;
return;
end
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos, e1l, e1r, maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
khanhnamle1994/machine-learning-master
|
loadubjson.m
|
.m
|
machine-learning-master/machine-learning-ex6/ex6/lib/jsonlab/loadubjson.m
| 15,574 |
utf_8
|
5974e78e71b81b1e0f76123784b951a4
|
function data = loadubjson(fname,varargin)
%
% data=loadubjson(fname,opt)
% or
% data=loadubjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/01
%
% $Id: loadubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a UBJSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadubjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.IntEndian [B|L]: specify the endianness of the integer fields
% in the UBJSON input data. B - Big-Endian format for
% integers (as required in the UBJSON specification);
% L - input integer fields are in Little-Endian order.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% obj=struct('string','value','array',[1 2 3]);
% ubjdata=saveubjson('obj',obj);
% dat=loadubjson(ubjdata)
% dat=loadubjson(['examples' filesep 'example1.ubj'])
% dat=loadubjson(['examples' filesep 'example1.ubj'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken fileendian systemendian
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
fileendian=upper(jsonopt('IntEndian','B',opt));
[os,maxelem,systemendian]=computer;
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
%%
function newdata=parse_collection(id,data,obj)
if(jsoncount>0 && exist('data','var'))
if(~iscell(data))
newdata=cell(1);
newdata{1}=data;
data=newdata;
end
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=double(data(j).x0x5F_ArraySize_);
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1); % TODO
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
count=double(parse_number());
end
if next_char ~= '}'
num=0;
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
%parse_char(':');
val = parse_value(varargin{:});
num=num+1;
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}' || (count>=0 && num>=count)
break;
end
%parse_char(',');
end
end
if(count==-1)
parse_char('}');
end
%%-------------------------------------------------------------------------
function [cid,len]=elem_info(type)
id=strfind('iUIlLdD',type);
dataclass={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
if(id>0)
cid=dataclass{id};
len=bytelen(id);
else
error_pos('unsupported type at position %d');
end
%%-------------------------------------------------------------------------
function [data adv]=parse_block(type,count,varargin)
global pos inStr isoct fileendian systemendian
[cid,len]=elem_info(type);
datastr=inStr(pos:pos+len*count-1);
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
id=strfind('iUIlLdD',type);
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,cid));
end
data=typecast(newdata,cid);
adv=double(len*count);
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim=[];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1);
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
if(next_char=='[')
dim=parse_array(varargin{:});
count=prod(double(dim));
else
count=double(parse_number());
end
end
if(~isempty(type))
if(count>=0)
[object adv]=parse_block(type,count,varargin{:});
if(~isempty(dim))
object=reshape(object,dim);
end
pos=pos+adv;
return;
else
endpos=matching_bracket(inStr,pos);
[cid,len]=elem_info(type);
count=(endpos-pos)/len;
[object adv]=parse_block(type,count,varargin{:});
pos=pos+adv;
parse_char(']');
return;
end
end
if next_char ~= ']'
while 1
val = parse_value(varargin{:});
object{end+1} = val;
if next_char == ']'
break;
end
%parse_char(',');
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
if(count==-1)
parse_char(']');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr esc index_esc len_esc
% len, ns = length(inStr), keyboard
type=inStr(pos);
if type ~= 'S' && type ~= 'C' && type ~= 'H'
error_pos('String starting with S expected at position %d');
else
pos = pos + 1;
end
if(type == 'C')
str=inStr(pos);
pos=pos+1;
return;
end
bytelen=double(parse_number());
if(length(inStr)>=pos+bytelen-1)
str=inStr(pos:pos+bytelen-1);
pos=pos+bytelen;
else
error_pos('End of file while expecting end of inStr');
end
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct fileendian systemendian
id=strfind('iUIlLdD',inStr(pos));
if(isempty(id))
error_pos('expecting a number at position %d');
end
type={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
datastr=inStr(pos+1:pos+bytelen(id));
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,type{id}));
end
num=typecast(newdata,type{id});
pos = pos + bytelen(id)+1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
switch(inStr(pos))
case {'S','C','H'}
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'i','U','I','l','L','d','D'}
val = parse_number(varargin{:});
return;
case 'T'
val = true;
pos = pos + 1;
return;
case 'F'
val = false;
pos = pos + 1;
return;
case {'Z','N'}
val = [];
pos = pos + 1;
return;
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos e1l e1r maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
khanhnamle1994/machine-learning-master
|
saveubjson.m
|
.m
|
machine-learning-master/machine-learning-ex6/ex6/lib/jsonlab/saveubjson.m
| 16,123 |
utf_8
|
61d4f51010aedbf97753396f5d2d9ec0
|
function json=saveubjson(rootname,obj,varargin)
%
% json=saveubjson(rootname,obj,filename)
% or
% json=saveubjson(rootname,obj,opt)
% json=saveubjson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a Universal
% Binary JSON (UBJSON) binary string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/17
%
% $Id: saveubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array)
% filename: a string for the file name to save the output UBJSON data
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.ArrayToStruct[0|1]: when set to 0, saveubjson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [1|0]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, saveubjson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSON='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a binary string in the UBJSON format (see http://ubjson.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% saveubjson('jsonmesh',jsonmesh)
% saveubjson('jsonmesh',jsonmesh,'meshdata.ubj')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
json=obj2ubjson(rootname,obj,rootlevel,opt);
if(~rootisarray)
json=['{' json '}'];
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=[jsonp '(' json ')'];
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2ubjson(name,item,level,varargin)
if(iscell(item))
txt=cell2ubjson(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2ubjson(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2ubjson(name,item,level,varargin{:});
else
txt=mat2ubjson(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2ubjson(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item); % let's handle 1D cell first
if(len>1)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) '[']; name='';
else
txt='[';
end
elseif(len==0)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) 'Z']; name='';
else
txt='Z';
end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
txt=[txt obj2ubjson(name,item{i,j},level+(len>1),varargin{:})];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=struct2ubjson(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=[txt S_(checkname(name,varargin{:})) '{'];
else
txt=[txt '{'];
end
if(~isempty(names))
for e=1:length(names)
txt=[txt obj2ubjson(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:})];
end
end
txt=[txt '}'];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=str2ubjson(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
val=item(e,:);
if(len==1)
obj=['' S_(checkname(name,varargin{:})) '' '',S_(val),''];
if(isempty(name)) obj=['',S_(val),'']; end
txt=[txt,'',obj];
else
txt=[txt,'',['',S_(val),'']];
end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=mat2ubjson(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) || jsonopt('ArrayToStruct',0,varargin{:}))
cid=I_(uint32(max(size(item))));
if(isempty(name))
txt=['{' S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1)) ];
else
if(isempty(item))
txt=[S_(checkname(name,varargin{:})),'Z'];
return;
else
txt=[S_(checkname(name,varargin{:})),'{',S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1))];
end
end
else
if(isempty(name))
txt=matdata2ubjson(item,level+1,varargin{:});
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
numtxt=regexprep(regexprep(matdata2ubjson(item,level+1,varargin{:}),'^\[',''),']','');
txt=[S_(checkname(name,varargin{:})) numtxt];
else
txt=[S_(checkname(name,varargin{:})),matdata2ubjson(item,level+1,varargin{:})];
end
end
return;
end
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=[txt,S_('_ArrayIsComplex_'),'T'];
end
txt=[txt,S_('_ArrayIsSparse_'),'T'];
if(size(item,1)==1)
% Row vector, store only column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([iy(:),data'],level+2,varargin{:})];
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,data],level+2,varargin{:})];
else
% General case, store row and column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,iy,data],level+2,varargin{:})];
end
else
if(isreal(item))
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson(item(:)',level+2,varargin{:})];
else
txt=[txt,S_('_ArrayIsComplex_'),'T'];
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([real(item(:)) imag(item(:))],level+2,varargin{:})];
end
end
txt=[txt,'}'];
%%-------------------------------------------------------------------------
function txt=matdata2ubjson(mat,level,varargin)
if(isempty(mat))
txt='Z';
return;
end
if(size(mat,1)==1)
level=level-1;
end
type='';
hasnegtive=(mat<0);
if(isa(mat,'integer') || isinteger(mat) || (isfloat(mat) && all(mod(mat(:),1) == 0)))
if(isempty(hasnegtive))
if(max(mat(:))<=2^8)
type='U';
end
end
if(isempty(type))
% todo - need to consider negative ones separately
id= histc(abs(max(mat(:))),[0 2^7 2^15 2^31 2^63]);
if(isempty(find(id)))
error('high-precision data is not yet supported');
end
key='iIlL';
type=key(find(id));
end
txt=[I_a(mat(:),type,size(mat))];
elseif(islogical(mat))
logicalval='FT';
if(numel(mat)==1)
txt=logicalval(mat+1);
else
txt=['[$U#' I_a(size(mat),'l') typecast(swapbytes(uint8(mat(:)')),'uint8')];
end
else
if(numel(mat)==1)
txt=['[' D_(mat) ']'];
else
txt=D_a(mat(:),'D',size(mat));
end
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function val=S_(str)
if(length(str)==1)
val=['C' str];
else
val=['S' I_(int32(length(str))) str];
end
%%-------------------------------------------------------------------------
function val=I_(num)
if(~isinteger(num))
error('input is not an integer');
end
if(num>=0 && num<255)
val=['U' data2byte(swapbytes(cast(num,'uint8')),'uint8')];
return;
end
key='iIlL';
cid={'int8','int16','int32','int64'};
for i=1:4
if((num>0 && num<2^(i*8-1)) || (num<0 && num>=-2^(i*8-1)))
val=[key(i) data2byte(swapbytes(cast(num,cid{i})),'uint8')];
return;
end
end
error('unsupported integer');
%%-------------------------------------------------------------------------
function val=D_(num)
if(~isfloat(num))
error('input is not a float');
end
if(isa(num,'single'))
val=['d' data2byte(num,'uint8')];
else
val=['D' data2byte(num,'uint8')];
end
%%-------------------------------------------------------------------------
function data=I_a(num,type,dim,format)
id=find(ismember('iUIlL',type));
if(id==0)
error('unsupported integer array');
end
% based on UBJSON specs, all integer types are stored in big endian format
if(id==1)
data=data2byte(swapbytes(int8(num)),'uint8');
blen=1;
elseif(id==2)
data=data2byte(swapbytes(uint8(num)),'uint8');
blen=1;
elseif(id==3)
data=data2byte(swapbytes(int16(num)),'uint8');
blen=2;
elseif(id==4)
data=data2byte(swapbytes(int32(num)),'uint8');
blen=4;
elseif(id==5)
data=data2byte(swapbytes(int64(num)),'uint8');
blen=8;
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/blen)) data(:)'];
end
data=['[' data(:)'];
else
data=reshape(data,blen,numel(data)/blen);
data(2:blen+1,:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function data=D_a(num,type,dim,format)
id=find(ismember('dD',type));
if(id==0)
error('unsupported float array');
end
if(id==1)
data=data2byte(single(num),'uint8');
elseif(id==2)
data=data2byte(double(num),'uint8');
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/(id*4))) data(:)'];
end
data=['[' data];
else
data=reshape(data,(id*4),length(data)/(id*4));
data(2:(id*4+1),:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function bytes=data2byte(varargin)
bytes=typecast(varargin{:});
bytes=bytes(:)';
|
github
|
khanhnamle1994/machine-learning-master
|
submit.m
|
.m
|
machine-learning-master/machine-learning-ex7/ex7/submit.m
| 1,438 |
utf_8
|
665ea5906aad3ccfd94e33a40c58e2ce
|
function submit()
addpath('./lib');
conf.assignmentSlug = 'k-means-clustering-and-pca';
conf.itemName = 'K-Means Clustering and PCA';
conf.partArrays = { ...
{ ...
'1', ...
{ 'findClosestCentroids.m' }, ...
'Find Closest Centroids (k-Means)', ...
}, ...
{ ...
'2', ...
{ 'computeCentroids.m' }, ...
'Compute Centroid Means (k-Means)', ...
}, ...
{ ...
'3', ...
{ 'pca.m' }, ...
'PCA', ...
}, ...
{ ...
'4', ...
{ 'projectData.m' }, ...
'Project Data (PCA)', ...
}, ...
{ ...
'5', ...
{ 'recoverData.m' }, ...
'Recover Data (PCA)', ...
}, ...
};
conf.output = @output;
submitWithConfiguration(conf);
end
function out = output(partId, auxstring)
% Random Test Cases
X = reshape(sin(1:165), 15, 11);
Z = reshape(cos(1:121), 11, 11);
C = Z(1:5, :);
idx = (1 + mod(1:15, 3))';
if partId == '1'
idx = findClosestCentroids(X, C);
out = sprintf('%0.5f ', idx(:));
elseif partId == '2'
centroids = computeCentroids(X, idx, 3);
out = sprintf('%0.5f ', centroids(:));
elseif partId == '3'
[U, S] = pca(X);
out = sprintf('%0.5f ', abs([U(:); S(:)]));
elseif partId == '4'
X_proj = projectData(X, Z, 5);
out = sprintf('%0.5f ', X_proj(:));
elseif partId == '5'
X_rec = recoverData(X(:,1:5), Z, 5);
out = sprintf('%0.5f ', X_rec(:));
end
end
|
github
|
khanhnamle1994/machine-learning-master
|
submitWithConfiguration.m
|
.m
|
machine-learning-master/machine-learning-ex7/ex7/lib/submitWithConfiguration.m
| 5,562 |
utf_8
|
4ac719ea6570ac228ea6c7a9c919e3f5
|
function submitWithConfiguration(conf)
addpath('./lib/jsonlab');
parts = parts(conf);
fprintf('== Submitting solutions | %s...\n', conf.itemName);
tokenFile = 'token.mat';
if exist(tokenFile, 'file')
load(tokenFile);
[email token] = promptToken(email, token, tokenFile);
else
[email token] = promptToken('', '', tokenFile);
end
if isempty(token)
fprintf('!! Submission Cancelled\n');
return
end
try
response = submitParts(conf, email, token, parts);
catch
e = lasterror();
fprintf('\n!! Submission failed: %s\n', e.message);
fprintf('\n\nFunction: %s\nFileName: %s\nLineNumber: %d\n', ...
e.stack(1,1).name, e.stack(1,1).file, e.stack(1,1).line);
fprintf('\nPlease correct your code and resubmit.\n');
return
end
if isfield(response, 'errorMessage')
fprintf('!! Submission failed: %s\n', response.errorMessage);
elseif isfield(response, 'errorCode')
fprintf('!! Submission failed: %s\n', response.message);
else
showFeedback(parts, response);
save(tokenFile, 'email', 'token');
end
end
function [email token] = promptToken(email, existingToken, tokenFile)
if (~isempty(email) && ~isempty(existingToken))
prompt = sprintf( ...
'Use token from last successful submission (%s)? (Y/n): ', ...
email);
reenter = input(prompt, 's');
if (isempty(reenter) || reenter(1) == 'Y' || reenter(1) == 'y')
token = existingToken;
return;
else
delete(tokenFile);
end
end
email = input('Login (email address): ', 's');
token = input('Token: ', 's');
end
function isValid = isValidPartOptionIndex(partOptions, i)
isValid = (~isempty(i)) && (1 <= i) && (i <= numel(partOptions));
end
function response = submitParts(conf, email, token, parts)
body = makePostBody(conf, email, token, parts);
submissionUrl = submissionUrl();
responseBody = getResponse(submissionUrl, body);
jsonResponse = validateResponse(responseBody);
response = loadjson(jsonResponse);
end
function body = makePostBody(conf, email, token, parts)
bodyStruct.assignmentSlug = conf.assignmentSlug;
bodyStruct.submitterEmail = email;
bodyStruct.secret = token;
bodyStruct.parts = makePartsStruct(conf, parts);
opt.Compact = 1;
body = savejson('', bodyStruct, opt);
end
function partsStruct = makePartsStruct(conf, parts)
for part = parts
partId = part{:}.id;
fieldName = makeValidFieldName(partId);
outputStruct.output = conf.output(partId);
partsStruct.(fieldName) = outputStruct;
end
end
function [parts] = parts(conf)
parts = {};
for partArray = conf.partArrays
part.id = partArray{:}{1};
part.sourceFiles = partArray{:}{2};
part.name = partArray{:}{3};
parts{end + 1} = part;
end
end
function showFeedback(parts, response)
fprintf('== \n');
fprintf('== %43s | %9s | %-s\n', 'Part Name', 'Score', 'Feedback');
fprintf('== %43s | %9s | %-s\n', '---------', '-----', '--------');
for part = parts
score = '';
partFeedback = '';
partFeedback = response.partFeedbacks.(makeValidFieldName(part{:}.id));
partEvaluation = response.partEvaluations.(makeValidFieldName(part{:}.id));
score = sprintf('%d / %3d', partEvaluation.score, partEvaluation.maxScore);
fprintf('== %43s | %9s | %-s\n', part{:}.name, score, partFeedback);
end
evaluation = response.evaluation;
totalScore = sprintf('%d / %d', evaluation.score, evaluation.maxScore);
fprintf('== --------------------------------\n');
fprintf('== %43s | %9s | %-s\n', '', totalScore, '');
fprintf('== \n');
end
% use urlread or curl to send submit results to the grader and get a response
function response = getResponse(url, body)
% try using urlread() and a secure connection
params = {'jsonBody', body};
[response, success] = urlread(url, 'post', params);
if (success == 0)
% urlread didn't work, try curl & the peer certificate patch
if ispc
% testing note: use 'jsonBody =' for a test case
json_command = sprintf('echo jsonBody=%s | curl -k -X POST -d @- %s', body, url);
else
% it's linux/OS X, so use the other form
json_command = sprintf('echo ''jsonBody=%s'' | curl -k -X POST -d @- %s', body, url);
end
% get the response body for the peer certificate patch method
[code, response] = system(json_command);
% test the success code
if (code ~= 0)
fprintf('[error] submission with curl() was not successful\n');
end
end
end
% validate the grader's response
function response = validateResponse(resp)
% test if the response is json or an HTML page
isJson = length(resp) > 0 && resp(1) == '{';
isHtml = findstr(lower(resp), '<html');
if (isJson)
response = resp;
elseif (isHtml)
% the response is html, so it's probably an error message
printHTMLContents(resp);
error('Grader response is an HTML message');
else
error('Grader sent no response');
end
end
% parse a HTML response and print it's contents
function printHTMLContents(response)
strippedResponse = regexprep(response, '<[^>]+>', ' ');
strippedResponse = regexprep(strippedResponse, '[\t ]+', ' ');
fprintf(strippedResponse);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Service configuration
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function submissionUrl = submissionUrl()
submissionUrl = 'https://www-origin.coursera.org/api/onDemandProgrammingImmediateFormSubmissions.v1';
end
|
github
|
khanhnamle1994/machine-learning-master
|
savejson.m
|
.m
|
machine-learning-master/machine-learning-ex7/ex7/lib/jsonlab/savejson.m
| 17,462 |
utf_8
|
861b534fc35ffe982b53ca3ca83143bf
|
function json=savejson(rootname,obj,varargin)
%
% json=savejson(rootname,obj,filename)
% or
% json=savejson(rootname,obj,opt)
% json=savejson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a JSON (JavaScript
% Object Notation) string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09
%
% $Id: savejson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array).
% filename: a string for the file name to save the output JSON data.
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.FloatFormat ['%.10g'|string]: format to show each numeric element
% of a 1D/2D array;
% opt.ArrayIndent [1|0]: if 1, output explicit data array with
% precedent indentation; if 0, no indentation
% opt.ArrayToStruct[0|1]: when set to 0, savejson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [0|1]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, savejson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.Inf ['"$1_Inf_"'|string]: a customized regular expression pattern
% to represent +/-Inf. The matched pattern is '([-+]*)Inf'
% and $1 represents the sign. For those who want to use
% 1e999 to represent Inf, they can set opt.Inf to '$11e999'
% opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern
% to represent NaN
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSONP='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
% opt.SaveBinary [0|1]: 1 - save the JSON file in binary mode; 0 - text mode.
% opt.Compact [0|1]: 1- out compact JSON format (remove all newlines and tabs)
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a string in the JSON format (see http://json.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% savejson('jmesh',jsonmesh)
% savejson('',jsonmesh,'ArrayIndent',0,'FloatFormat','\t%.5g')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
whitespaces=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
if(jsonopt('Compact',0,opt)==1)
whitespaces=struct('tab','','newline','','sep',',');
end
if(~isfield(opt,'whitespaces_'))
opt.whitespaces_=whitespaces;
end
nl=whitespaces.newline;
json=obj2json(rootname,obj,rootlevel,opt);
if(rootisarray)
json=sprintf('%s%s',json,nl);
else
json=sprintf('{%s%s%s}\n',nl,json,nl);
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=sprintf('%s(%s);%s',jsonp,json,nl);
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
if(jsonopt('SaveBinary',0,opt)==1)
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
else
fid = fopen(opt.FileName, 'wt');
fwrite(fid,json,'char');
end
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2json(name,item,level,varargin)
if(iscell(item))
txt=cell2json(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2json(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2json(name,item,level,varargin{:});
else
txt=mat2json(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2json(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=jsonopt('whitespaces_',struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n')),varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
nl=ws.newline;
if(len>1)
if(~isempty(name))
txt=sprintf('%s"%s": [%s',padding0, checkname(name,varargin{:}),nl); name='';
else
txt=sprintf('%s[%s',padding0,nl);
end
elseif(len==0)
if(~isempty(name))
txt=sprintf('%s"%s": []',padding0, checkname(name,varargin{:})); name='';
else
txt=sprintf('%s[]',padding0);
end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
txt=sprintf('%s%s',txt,obj2json(name,item{i,j},level+(dim(1)>1)+1,varargin{:}));
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
%if(j==dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=struct2json(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding0=repmat(ws.tab,1,level);
padding2=repmat(ws.tab,1,level+1);
padding1=repmat(ws.tab,1,level+(dim(1)>1)+(len>1));
nl=ws.newline;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding0,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding0,nl); end
end
for j=1:dim(2)
if(dim(1)>1) txt=sprintf('%s%s[%s',txt,padding2,nl); end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=sprintf('%s%s"%s": {%s',txt,padding1, checkname(name,varargin{:}),nl);
else
txt=sprintf('%s%s{%s',txt,padding1,nl);
end
if(~isempty(names))
for e=1:length(names)
txt=sprintf('%s%s',txt,obj2json(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:}));
if(e<length(names)) txt=sprintf('%s%s',txt,','); end
txt=sprintf('%s%s',txt,nl);
end
end
txt=sprintf('%s%s}',txt,padding1);
if(i<dim(1)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(dim(1)>1) txt=sprintf('%s%s%s]',txt,nl,padding2); end
if(j<dim(2)) txt=sprintf('%s%s',txt,sprintf(',%s',nl)); end
end
if(len>1) txt=sprintf('%s%s%s]',txt,nl,padding0); end
%%-------------------------------------------------------------------------
function txt=str2json(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(~isempty(name))
if(len>1) txt=sprintf('%s"%s": [%s',padding1,checkname(name,varargin{:}),nl); end
else
if(len>1) txt=sprintf('%s[%s',padding1,nl); end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
if(isoct)
val=regexprep(item(e,:),'\\','\\');
val=regexprep(val,'"','\"');
val=regexprep(val,'^"','\"');
else
val=regexprep(item(e,:),'\\','\\\\');
val=regexprep(val,'"','\\"');
val=regexprep(val,'^"','\\"');
end
val=escapejsonstring(val);
if(len==1)
obj=['"' checkname(name,varargin{:}) '": ' '"',val,'"'];
if(isempty(name)) obj=['"',val,'"']; end
txt=sprintf('%s%s%s%s',txt,padding1,obj);
else
txt=sprintf('%s%s%s%s',txt,padding0,['"',val,'"']);
end
if(e==len) sep=''; end
txt=sprintf('%s%s',txt,sep);
end
if(len>1) txt=sprintf('%s%s%s%s',txt,nl,padding1,']'); end
%%-------------------------------------------------------------------------
function txt=mat2json(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
padding1=repmat(ws.tab,1,level);
padding0=repmat(ws.tab,1,level+1);
nl=ws.newline;
sep=ws.sep;
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) ||jsonopt('ArrayToStruct',0,varargin{:}))
if(isempty(name))
txt=sprintf('%s{%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
else
txt=sprintf('%s"%s": {%s%s"_ArrayType_": "%s",%s%s"_ArraySize_": %s,%s',...
padding1,checkname(name,varargin{:}),nl,padding0,class(item),nl,padding0,regexprep(mat2str(size(item)),'\s+',','),nl);
end
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1 && level>0)
numtxt=regexprep(regexprep(matdata2json(item,level+1,varargin{:}),'^\[',''),']','');
else
numtxt=matdata2json(item,level+1,varargin{:});
end
if(isempty(name))
txt=sprintf('%s%s',padding1,numtxt);
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
else
txt=sprintf('%s"%s": %s',padding1,checkname(name,varargin{:}),numtxt);
end
end
return;
end
dataformat='%s%s%s%s%s';
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
end
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsSparse_": ','1', sep);
if(size(item,1)==1)
% Row vector, store only column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([iy(:),data'],level+2,varargin{:}), nl);
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,data],level+2,varargin{:}), nl);
else
% General case, store row and column indices.
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([ix,iy,data],level+2,varargin{:}), nl);
end
else
if(isreal(item))
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json(item(:)',level+2,varargin{:}), nl);
else
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
txt=sprintf(dataformat,txt,padding0,'"_ArrayData_": ',...
matdata2json([real(item(:)) imag(item(:))],level+2,varargin{:}), nl);
end
end
txt=sprintf('%s%s%s',txt,padding1,'}');
%%-------------------------------------------------------------------------
function txt=matdata2json(mat,level,varargin)
ws=struct('tab',sprintf('\t'),'newline',sprintf('\n'),'sep',sprintf(',\n'));
ws=jsonopt('whitespaces_',ws,varargin{:});
tab=ws.tab;
nl=ws.newline;
if(size(mat,1)==1)
pre='';
post='';
level=level-1;
else
pre=sprintf('[%s',nl);
post=sprintf('%s%s]',nl,repmat(tab,1,level-1));
end
if(isempty(mat))
txt='null';
return;
end
floatformat=jsonopt('FloatFormat','%.10g',varargin{:});
%if(numel(mat)>1)
formatstr=['[' repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf('],%s',nl)]];
%else
% formatstr=[repmat([floatformat ','],1,size(mat,2)-1) [floatformat sprintf(',\n')]];
%end
if(nargin>=2 && size(mat,1)>1 && jsonopt('ArrayIndent',1,varargin{:})==1)
formatstr=[repmat(tab,1,level) formatstr];
end
txt=sprintf(formatstr,mat');
txt(end-length(nl):end)=[];
if(islogical(mat) && jsonopt('ParseLogical',0,varargin{:})==1)
txt=regexprep(txt,'1','true');
txt=regexprep(txt,'0','false');
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],\n['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
txt=[pre txt post];
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function newstr=escapejsonstring(str)
newstr=str;
isoct=exist('OCTAVE_VERSION','builtin');
if(isoct)
vv=sscanf(OCTAVE_VERSION,'%f');
if(vv(1)>=3.8) isoct=0; end
end
if(isoct)
escapechars={'\a','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},escapechars{i});
end
else
escapechars={'\a','\b','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,escapechars{i},regexprep(escapechars{i},'\\','\\\\'));
end
end
|
github
|
khanhnamle1994/machine-learning-master
|
loadjson.m
|
.m
|
machine-learning-master/machine-learning-ex7/ex7/lib/jsonlab/loadjson.m
| 18,732 |
ibm852
|
ab98cf173af2d50bbe8da4d6db252a20
|
function data = loadjson(fname,varargin)
%
% data=loadjson(fname,opt)
% or
% data=loadjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2011/09/09, including previous works from
%
% Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
% created on 2009/11/02
% François Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393
% created on 2009/03/22
% Joel Feenstra:
% http://www.mathworks.com/matlabcentral/fileexchange/20565
% created on 2008/07/03
%
% $Id: loadjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a JSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.FastArrayParser [1|0 or integer]: if set to 1, use a
% speed-optimized array parser when loading an
% array object. The fast array parser may
% collapse block arrays into a single large
% array similar to rules defined in cell2mat; 0 to
% use a legacy parser; if set to a larger-than-1
% value, this option will specify the minimum
% dimension to enable the fast array parser. For
% example, if the input is a 3D array, setting
% FastArrayParser to 1 will return a 3D array;
% setting to 2 will return a cell array of 2D
% arrays; setting to 3 will return to a 2D cell
% array of 1D vectors; setting to 4 will return a
% 3D cell array.
% opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% dat=loadjson('{"obj":{"string":"value","array":[1,2,3]}}')
% dat=loadjson(['examples' filesep 'example1.json'])
% dat=loadjson(['examples' filesep 'example1.json'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
if(jsonopt('ShowProgress',0,opt)==1)
opt.progressbar_=waitbar(0,'loading ...');
end
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
if(isfield(opt,'progressbar_'))
close(opt.progressbar_);
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=data(j).x0x5F_ArraySize_;
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
if next_char ~= '}'
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
parse_char(':');
val = parse_value(varargin{:});
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}'
break;
end
parse_char(',');
end
end
parse_char('}');
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim2=[];
arraydepth=jsonopt('JSONLAB_ArrayDepth_',1,varargin{:});
pbar=jsonopt('progressbar_',-1,varargin{:});
if next_char ~= ']'
if(jsonopt('FastArrayParser',1,varargin{:})>=1 && arraydepth>=jsonopt('FastArrayParser',1,varargin{:}))
[endpos, e1l, e1r, maxlevel]=matching_bracket(inStr,pos);
arraystr=['[' inStr(pos:endpos)];
arraystr=regexprep(arraystr,'"_NaN_"','NaN');
arraystr=regexprep(arraystr,'"([-+]*)_Inf_"','$1Inf');
arraystr(arraystr==sprintf('\n'))=[];
arraystr(arraystr==sprintf('\r'))=[];
%arraystr=regexprep(arraystr,'\s*,',','); % this is slow,sometimes needed
if(~isempty(e1l) && ~isempty(e1r)) % the array is in 2D or higher D
astr=inStr((e1l+1):(e1r-1));
astr=regexprep(astr,'"_NaN_"','NaN');
astr=regexprep(astr,'"([-+]*)_Inf_"','$1Inf');
astr(astr==sprintf('\n'))=[];
astr(astr==sprintf('\r'))=[];
astr(astr==' ')='';
if(isempty(find(astr=='[', 1))) % array is 2D
dim2=length(sscanf(astr,'%f,',[1 inf]));
end
else % array is 1D
astr=arraystr(2:end-1);
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',[1,inf]);
if(nextidx>=length(astr)-1)
object=obj;
pos=endpos;
parse_char(']');
return;
end
end
if(~isempty(dim2))
astr=arraystr;
astr(astr=='[')='';
astr(astr==']')='';
astr(astr==' ')='';
[obj, count, errmsg, nextidx]=sscanf(astr,'%f,',inf);
if(nextidx>=length(astr)-1)
object=reshape(obj,dim2,numel(obj)/dim2)';
pos=endpos;
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
return;
end
end
arraystr=regexprep(arraystr,'\]\s*,','];');
else
arraystr='[';
end
try
if(isoct && regexp(arraystr,'"','once'))
error('Octave eval can produce empty cells for JSON-like input');
end
object=eval(arraystr);
pos=endpos;
catch
while 1
newopt=varargin2struct(varargin{:},'JSONLAB_ArrayDepth_',arraydepth+1);
val = parse_value(newopt);
object{end+1} = val;
if next_char == ']'
break;
end
parse_char(',');
end
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
parse_char(']');
if(pbar>0)
waitbar(pos/length(inStr),pbar,'loading ...');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr len esc index_esc len_esc
% len, ns = length(inStr), keyboard
if inStr(pos) ~= '"'
error_pos('String starting with " expected at position %d');
else
pos = pos + 1;
end
str = '';
while pos <= len
while index_esc <= len_esc && esc(index_esc) < pos
index_esc = index_esc + 1;
end
if index_esc > len_esc
str = [str inStr(pos:len)];
pos = len + 1;
break;
else
str = [str inStr(pos:esc(index_esc)-1)];
pos = esc(index_esc);
end
nstr = length(str); switch inStr(pos)
case '"'
pos = pos + 1;
if(~isempty(str))
if(strcmp(str,'_Inf_'))
str=Inf;
elseif(strcmp(str,'-_Inf_'))
str=-Inf;
elseif(strcmp(str,'_NaN_'))
str=NaN;
end
end
return;
case '\'
if pos+1 > len
error_pos('End of file reached right after escape character');
end
pos = pos + 1;
switch inStr(pos)
case {'"' '\' '/'}
str(nstr+1) = inStr(pos);
pos = pos + 1;
case {'b' 'f' 'n' 'r' 't'}
str(nstr+1) = sprintf(['\' inStr(pos)]);
pos = pos + 1;
case 'u'
if pos+4 > len
error_pos('End of file reached in escaped unicode character');
end
str(nstr+(1:6)) = inStr(pos-1:pos+4);
pos = pos + 5;
end
otherwise % should never happen
str(nstr+1) = inStr(pos), keyboard
pos = pos + 1;
end
end
error_pos('End of file while expecting end of inStr');
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct
currstr=inStr(pos:end);
numstr=0;
if(isoct~=0)
numstr=regexp(currstr,'^\s*-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+\-]?\d+)?','end');
[num, one] = sscanf(currstr, '%f', 1);
delta=numstr+1;
else
[num, one, err, delta] = sscanf(currstr, '%f', 1);
if ~isempty(err)
error_pos('Error reading number at position %d');
end
end
pos = pos + delta-1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
pbar=jsonopt('progressbar_',-1,varargin{:});
if(pbar>0)
waitbar(pos/len,pbar,'loading ...');
end
switch(inStr(pos))
case '"'
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'-','0','1','2','3','4','5','6','7','8','9'}
val = parse_number(varargin{:});
return;
case 't'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'true')
val = true;
pos = pos + 4;
return;
end
case 'f'
if pos+4 <= len && strcmpi(inStr(pos:pos+4), 'false')
val = false;
pos = pos + 5;
return;
end
case 'n'
if pos+3 <= len && strcmpi(inStr(pos:pos+3), 'null')
val = [];
pos = pos + 4;
return;
end
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos, e1l, e1r, maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
khanhnamle1994/machine-learning-master
|
loadubjson.m
|
.m
|
machine-learning-master/machine-learning-ex7/ex7/lib/jsonlab/loadubjson.m
| 15,574 |
utf_8
|
5974e78e71b81b1e0f76123784b951a4
|
function data = loadubjson(fname,varargin)
%
% data=loadubjson(fname,opt)
% or
% data=loadubjson(fname,'param1',value1,'param2',value2,...)
%
% parse a JSON (JavaScript Object Notation) file or string
%
% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/01
%
% $Id: loadubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% fname: input file name, if fname contains "{}" or "[]", fname
% will be interpreted as a UBJSON string
% opt: a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% opt.SimplifyCell [0|1]: if set to 1, loadubjson will call cell2mat
% for each element of the JSON data, and group
% arrays based on the cell2mat rules.
% opt.IntEndian [B|L]: specify the endianness of the integer fields
% in the UBJSON input data. B - Big-Endian format for
% integers (as required in the UBJSON specification);
% L - input integer fields are in Little-Endian order.
%
% output:
% dat: a cell array, where {...} blocks are converted into cell arrays,
% and [...] are converted to arrays
%
% examples:
% obj=struct('string','value','array',[1 2 3]);
% ubjdata=saveubjson('obj',obj);
% dat=loadubjson(ubjdata)
% dat=loadubjson(['examples' filesep 'example1.ubj'])
% dat=loadubjson(['examples' filesep 'example1.ubj'],'SimplifyCell',1)
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
global pos inStr len esc index_esc len_esc isoct arraytoken fileendian systemendian
if(regexp(fname,'[\{\}\]\[]','once'))
string=fname;
elseif(exist(fname,'file'))
fid = fopen(fname,'rb');
string = fread(fid,inf,'uint8=>char')';
fclose(fid);
else
error('input file does not exist');
end
pos = 1; len = length(string); inStr = string;
isoct=exist('OCTAVE_VERSION','builtin');
arraytoken=find(inStr=='[' | inStr==']' | inStr=='"');
jstr=regexprep(inStr,'\\\\',' ');
escquote=regexp(jstr,'\\"');
arraytoken=sort([arraytoken escquote]);
% String delimiters and escape chars identified to improve speed:
esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]');
index_esc = 1; len_esc = length(esc);
opt=varargin2struct(varargin{:});
fileendian=upper(jsonopt('IntEndian','B',opt));
[os,maxelem,systemendian]=computer;
jsoncount=1;
while pos <= len
switch(next_char)
case '{'
data{jsoncount} = parse_object(opt);
case '['
data{jsoncount} = parse_array(opt);
otherwise
error_pos('Outer level structure must be an object or an array');
end
jsoncount=jsoncount+1;
end % while
jsoncount=length(data);
if(jsoncount==1 && iscell(data))
data=data{1};
end
if(~isempty(data))
if(isstruct(data)) % data can be a struct array
data=jstruct2array(data);
elseif(iscell(data))
data=jcell2array(data);
end
end
%%
function newdata=parse_collection(id,data,obj)
if(jsoncount>0 && exist('data','var'))
if(~iscell(data))
newdata=cell(1);
newdata{1}=data;
data=newdata;
end
end
%%
function newdata=jcell2array(data)
len=length(data);
newdata=data;
for i=1:len
if(isstruct(data{i}))
newdata{i}=jstruct2array(data{i});
elseif(iscell(data{i}))
newdata{i}=jcell2array(data{i});
end
end
%%-------------------------------------------------------------------------
function newdata=jstruct2array(data)
fn=fieldnames(data);
newdata=data;
len=length(data);
for i=1:length(fn) % depth-first
for j=1:len
if(isstruct(getfield(data(j),fn{i})))
newdata(j)=setfield(newdata(j),fn{i},jstruct2array(getfield(data(j),fn{i})));
end
end
end
if(~isempty(strmatch('x0x5F_ArrayType_',fn)) && ~isempty(strmatch('x0x5F_ArrayData_',fn)))
newdata=cell(len,1);
for j=1:len
ndata=cast(data(j).x0x5F_ArrayData_,data(j).x0x5F_ArrayType_);
iscpx=0;
if(~isempty(strmatch('x0x5F_ArrayIsComplex_',fn)))
if(data(j).x0x5F_ArrayIsComplex_)
iscpx=1;
end
end
if(~isempty(strmatch('x0x5F_ArrayIsSparse_',fn)))
if(data(j).x0x5F_ArrayIsSparse_)
if(~isempty(strmatch('x0x5F_ArraySize_',fn)))
dim=double(data(j).x0x5F_ArraySize_);
if(iscpx && size(ndata,2)==4-any(dim==1))
ndata(:,end-1)=complex(ndata(:,end-1),ndata(:,end));
end
if isempty(ndata)
% All-zeros sparse
ndata=sparse(dim(1),prod(dim(2:end)));
elseif dim(1)==1
% Sparse row vector
ndata=sparse(1,ndata(:,1),ndata(:,2),dim(1),prod(dim(2:end)));
elseif dim(2)==1
% Sparse column vector
ndata=sparse(ndata(:,1),1,ndata(:,2),dim(1),prod(dim(2:end)));
else
% Generic sparse array.
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3),dim(1),prod(dim(2:end)));
end
else
if(iscpx && size(ndata,2)==4)
ndata(:,3)=complex(ndata(:,3),ndata(:,4));
end
ndata=sparse(ndata(:,1),ndata(:,2),ndata(:,3));
end
end
elseif(~isempty(strmatch('x0x5F_ArraySize_',fn)))
if(iscpx && size(ndata,2)==2)
ndata=complex(ndata(:,1),ndata(:,2));
end
ndata=reshape(ndata(:),data(j).x0x5F_ArraySize_);
end
newdata{j}=ndata;
end
if(len==1)
newdata=newdata{1};
end
end
%%-------------------------------------------------------------------------
function object = parse_object(varargin)
parse_char('{');
object = [];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1); % TODO
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
count=double(parse_number());
end
if next_char ~= '}'
num=0;
while 1
str = parseStr(varargin{:});
if isempty(str)
error_pos('Name of value at position %d cannot be empty');
end
%parse_char(':');
val = parse_value(varargin{:});
num=num+1;
eval( sprintf( 'object.%s = val;', valid_field(str) ) );
if next_char == '}' || (count>=0 && num>=count)
break;
end
%parse_char(',');
end
end
if(count==-1)
parse_char('}');
end
%%-------------------------------------------------------------------------
function [cid,len]=elem_info(type)
id=strfind('iUIlLdD',type);
dataclass={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
if(id>0)
cid=dataclass{id};
len=bytelen(id);
else
error_pos('unsupported type at position %d');
end
%%-------------------------------------------------------------------------
function [data adv]=parse_block(type,count,varargin)
global pos inStr isoct fileendian systemendian
[cid,len]=elem_info(type);
datastr=inStr(pos:pos+len*count-1);
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
id=strfind('iUIlLdD',type);
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,cid));
end
data=typecast(newdata,cid);
adv=double(len*count);
%%-------------------------------------------------------------------------
function object = parse_array(varargin) % JSON array is written in row-major order
global pos inStr isoct
parse_char('[');
object = cell(0, 1);
dim=[];
type='';
count=-1;
if(next_char == '$')
type=inStr(pos+1);
pos=pos+2;
end
if(next_char == '#')
pos=pos+1;
if(next_char=='[')
dim=parse_array(varargin{:});
count=prod(double(dim));
else
count=double(parse_number());
end
end
if(~isempty(type))
if(count>=0)
[object adv]=parse_block(type,count,varargin{:});
if(~isempty(dim))
object=reshape(object,dim);
end
pos=pos+adv;
return;
else
endpos=matching_bracket(inStr,pos);
[cid,len]=elem_info(type);
count=(endpos-pos)/len;
[object adv]=parse_block(type,count,varargin{:});
pos=pos+adv;
parse_char(']');
return;
end
end
if next_char ~= ']'
while 1
val = parse_value(varargin{:});
object{end+1} = val;
if next_char == ']'
break;
end
%parse_char(',');
end
end
if(jsonopt('SimplifyCell',0,varargin{:})==1)
try
oldobj=object;
object=cell2mat(object')';
if(iscell(oldobj) && isstruct(object) && numel(object)>1 && jsonopt('SimplifyCellArray',1,varargin{:})==0)
object=oldobj;
elseif(size(object,1)>1 && ndims(object)==2)
object=object';
end
catch
end
end
if(count==-1)
parse_char(']');
end
%%-------------------------------------------------------------------------
function parse_char(c)
global pos inStr len
skip_whitespace;
if pos > len || inStr(pos) ~= c
error_pos(sprintf('Expected %c at position %%d', c));
else
pos = pos + 1;
skip_whitespace;
end
%%-------------------------------------------------------------------------
function c = next_char
global pos inStr len
skip_whitespace;
if pos > len
c = [];
else
c = inStr(pos);
end
%%-------------------------------------------------------------------------
function skip_whitespace
global pos inStr len
while pos <= len && isspace(inStr(pos))
pos = pos + 1;
end
%%-------------------------------------------------------------------------
function str = parseStr(varargin)
global pos inStr esc index_esc len_esc
% len, ns = length(inStr), keyboard
type=inStr(pos);
if type ~= 'S' && type ~= 'C' && type ~= 'H'
error_pos('String starting with S expected at position %d');
else
pos = pos + 1;
end
if(type == 'C')
str=inStr(pos);
pos=pos+1;
return;
end
bytelen=double(parse_number());
if(length(inStr)>=pos+bytelen-1)
str=inStr(pos:pos+bytelen-1);
pos=pos+bytelen;
else
error_pos('End of file while expecting end of inStr');
end
%%-------------------------------------------------------------------------
function num = parse_number(varargin)
global pos inStr len isoct fileendian systemendian
id=strfind('iUIlLdD',inStr(pos));
if(isempty(id))
error_pos('expecting a number at position %d');
end
type={'int8','uint8','int16','int32','int64','single','double'};
bytelen=[1,1,2,4,8,4,8];
datastr=inStr(pos+1:pos+bytelen(id));
if(isoct)
newdata=int8(datastr);
else
newdata=uint8(datastr);
end
if(id<=5 && fileendian~=systemendian)
newdata=swapbytes(typecast(newdata,type{id}));
end
num=typecast(newdata,type{id});
pos = pos + bytelen(id)+1;
%%-------------------------------------------------------------------------
function val = parse_value(varargin)
global pos inStr len
true = 1; false = 0;
switch(inStr(pos))
case {'S','C','H'}
val = parseStr(varargin{:});
return;
case '['
val = parse_array(varargin{:});
return;
case '{'
val = parse_object(varargin{:});
if isstruct(val)
if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
val=jstruct2array(val);
end
elseif isempty(val)
val = struct;
end
return;
case {'i','U','I','l','L','d','D'}
val = parse_number(varargin{:});
return;
case 'T'
val = true;
pos = pos + 1;
return;
case 'F'
val = false;
pos = pos + 1;
return;
case {'Z','N'}
val = [];
pos = pos + 1;
return;
end
error_pos('Value expected at position %d');
%%-------------------------------------------------------------------------
function error_pos(msg)
global pos inStr len
poShow = max(min([pos-15 pos-1 pos pos+20],len),1);
if poShow(3) == poShow(2)
poShow(3:4) = poShow(2)+[0 -1]; % display nothing after
end
msg = [sprintf(msg, pos) ': ' ...
inStr(poShow(1):poShow(2)) '<error>' inStr(poShow(3):poShow(4)) ];
error( ['JSONparser:invalidFormat: ' msg] );
%%-------------------------------------------------------------------------
function str = valid_field(str)
global isoct
% From MATLAB doc: field names must begin with a letter, which may be
% followed by any combination of letters, digits, and underscores.
% Invalid characters will be converted to underscores, and the prefix
% "x0x[Hex code]_" will be added if the first character is not a letter.
pos=regexp(str,'^[^A-Za-z]','once');
if(~isempty(pos))
if(~isoct)
str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
else
str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
end
end
if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) return; end
if(~isoct)
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
pos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(pos)) return; end
str0=str;
pos0=[0 pos(:)' length(str)];
str='';
for i=1:length(pos)
str=[str str0(pos0(i)+1:pos(i)-1) sprintf('_0x%X_',str0(pos(i)))];
end
if(pos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
end
%str(~isletter(str) & ~('0' <= str & str <= '9')) = '_';
%%-------------------------------------------------------------------------
function endpos = matching_quote(str,pos)
len=length(str);
while(pos<len)
if(str(pos)=='"')
if(~(pos>1 && str(pos-1)=='\'))
endpos=pos;
return;
end
end
pos=pos+1;
end
error('unmatched quotation mark');
%%-------------------------------------------------------------------------
function [endpos e1l e1r maxlevel] = matching_bracket(str,pos)
global arraytoken
level=1;
maxlevel=level;
endpos=0;
bpos=arraytoken(arraytoken>=pos);
tokens=str(bpos);
len=length(tokens);
pos=1;
e1l=[];
e1r=[];
while(pos<=len)
c=tokens(pos);
if(c==']')
level=level-1;
if(isempty(e1r)) e1r=bpos(pos); end
if(level==0)
endpos=bpos(pos);
return
end
end
if(c=='[')
if(isempty(e1l)) e1l=bpos(pos); end
level=level+1;
maxlevel=max(maxlevel,level);
end
if(c=='"')
pos=matching_quote(tokens,pos+1);
end
pos=pos+1;
end
if(endpos==0)
error('unmatched "]"');
end
|
github
|
khanhnamle1994/machine-learning-master
|
saveubjson.m
|
.m
|
machine-learning-master/machine-learning-ex7/ex7/lib/jsonlab/saveubjson.m
| 16,123 |
utf_8
|
61d4f51010aedbf97753396f5d2d9ec0
|
function json=saveubjson(rootname,obj,varargin)
%
% json=saveubjson(rootname,obj,filename)
% or
% json=saveubjson(rootname,obj,opt)
% json=saveubjson(rootname,obj,'param1',value1,'param2',value2,...)
%
% convert a MATLAB object (cell, struct or array) into a Universal
% Binary JSON (UBJSON) binary string
%
% author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
% created on 2013/08/17
%
% $Id: saveubjson.m 460 2015-01-03 00:30:45Z fangq $
%
% input:
% rootname: the name of the root-object, when set to '', the root name
% is ignored, however, when opt.ForceRootName is set to 1 (see below),
% the MATLAB variable name will be used as the root name.
% obj: a MATLAB object (array, cell, cell array, struct, struct array)
% filename: a string for the file name to save the output UBJSON data
% opt: a struct for additional options, ignore to use default values.
% opt can have the following fields (first in [.|.] is the default)
%
% opt.FileName [''|string]: a file name to save the output JSON data
% opt.ArrayToStruct[0|1]: when set to 0, saveubjson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [1|0]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, saveubjson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSON='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
%
% opt can be replaced by a list of ('param',value) pairs. The param
% string is equivallent to a field in opt and is case sensitive.
% output:
% json: a binary string in the UBJSON format (see http://ubjson.org)
%
% examples:
% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],...
% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;...
% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],...
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
% 'SpecialData',[nan, inf, -inf]);
% saveubjson('jsonmesh',jsonmesh)
% saveubjson('jsonmesh',jsonmesh,'meshdata.ubj')
%
% license:
% BSD, see LICENSE_BSD.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%
if(nargin==1)
varname=inputname(1);
obj=rootname;
if(isempty(varname))
varname='root';
end
rootname=varname;
else
varname=inputname(2);
end
if(length(varargin)==1 && ischar(varargin{1}))
opt=struct('FileName',varargin{1});
else
opt=varargin2struct(varargin{:});
end
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
rootisarray=0;
rootlevel=1;
forceroot=jsonopt('ForceRootName',0,opt);
if((isnumeric(obj) || islogical(obj) || ischar(obj) || isstruct(obj) || iscell(obj)) && isempty(rootname) && forceroot==0)
rootisarray=1;
rootlevel=0;
else
if(isempty(rootname))
rootname=varname;
end
end
if((isstruct(obj) || iscell(obj))&& isempty(rootname) && forceroot)
rootname='root';
end
json=obj2ubjson(rootname,obj,rootlevel,opt);
if(~rootisarray)
json=['{' json '}'];
end
jsonp=jsonopt('JSONP','',opt);
if(~isempty(jsonp))
json=[jsonp '(' json ')'];
end
% save to a file if FileName is set, suggested by Patrick Rapin
if(~isempty(jsonopt('FileName','',opt)))
fid = fopen(opt.FileName, 'wb');
fwrite(fid,json);
fclose(fid);
end
%%-------------------------------------------------------------------------
function txt=obj2ubjson(name,item,level,varargin)
if(iscell(item))
txt=cell2ubjson(name,item,level,varargin{:});
elseif(isstruct(item))
txt=struct2ubjson(name,item,level,varargin{:});
elseif(ischar(item))
txt=str2ubjson(name,item,level,varargin{:});
else
txt=mat2ubjson(name,item,level,varargin{:});
end
%%-------------------------------------------------------------------------
function txt=cell2ubjson(name,item,level,varargin)
txt='';
if(~iscell(item))
error('input is not a cell');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item); % let's handle 1D cell first
if(len>1)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) '[']; name='';
else
txt='[';
end
elseif(len==0)
if(~isempty(name))
txt=[S_(checkname(name,varargin{:})) 'Z']; name='';
else
txt='Z';
end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
txt=[txt obj2ubjson(name,item{i,j},level+(len>1),varargin{:})];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=struct2ubjson(name,item,level,varargin)
txt='';
if(~isstruct(item))
error('input is not a struct');
end
dim=size(item);
if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now
item=reshape(item,dim(1),numel(item)/dim(1));
dim=size(item);
end
len=numel(item);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
for j=1:dim(2)
if(dim(1)>1) txt=[txt '[']; end
for i=1:dim(1)
names = fieldnames(item(i,j));
if(~isempty(name) && len==1)
txt=[txt S_(checkname(name,varargin{:})) '{'];
else
txt=[txt '{'];
end
if(~isempty(names))
for e=1:length(names)
txt=[txt obj2ubjson(names{e},getfield(item(i,j),...
names{e}),level+(dim(1)>1)+1+(len>1),varargin{:})];
end
end
txt=[txt '}'];
end
if(dim(1)>1) txt=[txt ']']; end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=str2ubjson(name,item,level,varargin)
txt='';
if(~ischar(item))
error('input is not a string');
end
item=reshape(item, max(size(item),[1 0]));
len=size(item,1);
if(~isempty(name))
if(len>1) txt=[S_(checkname(name,varargin{:})) '[']; end
else
if(len>1) txt='['; end
end
isoct=jsonopt('IsOctave',0,varargin{:});
for e=1:len
val=item(e,:);
if(len==1)
obj=['' S_(checkname(name,varargin{:})) '' '',S_(val),''];
if(isempty(name)) obj=['',S_(val),'']; end
txt=[txt,'',obj];
else
txt=[txt,'',['',S_(val),'']];
end
end
if(len>1) txt=[txt ']']; end
%%-------------------------------------------------------------------------
function txt=mat2ubjson(name,item,level,varargin)
if(~isnumeric(item) && ~islogical(item))
error('input is not an array');
end
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
isempty(item) || jsonopt('ArrayToStruct',0,varargin{:}))
cid=I_(uint32(max(size(item))));
if(isempty(name))
txt=['{' S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1)) ];
else
if(isempty(item))
txt=[S_(checkname(name,varargin{:})),'Z'];
return;
else
txt=[S_(checkname(name,varargin{:})),'{',S_('_ArrayType_'),S_(class(item)),S_('_ArraySize_'),I_a(size(item),cid(1))];
end
end
else
if(isempty(name))
txt=matdata2ubjson(item,level+1,varargin{:});
else
if(numel(item)==1 && jsonopt('NoRowBracket',1,varargin{:})==1)
numtxt=regexprep(regexprep(matdata2ubjson(item,level+1,varargin{:}),'^\[',''),']','');
txt=[S_(checkname(name,varargin{:})) numtxt];
else
txt=[S_(checkname(name,varargin{:})),matdata2ubjson(item,level+1,varargin{:})];
end
end
return;
end
if(issparse(item))
[ix,iy]=find(item);
data=full(item(find(item)));
if(~isreal(item))
data=[real(data(:)),imag(data(:))];
if(size(item,1)==1)
% Kludge to have data's 'transposedness' match item's.
% (Necessary for complex row vector handling below.)
data=data';
end
txt=[txt,S_('_ArrayIsComplex_'),'T'];
end
txt=[txt,S_('_ArrayIsSparse_'),'T'];
if(size(item,1)==1)
% Row vector, store only column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([iy(:),data'],level+2,varargin{:})];
elseif(size(item,2)==1)
% Column vector, store only row indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,data],level+2,varargin{:})];
else
% General case, store row and column indices.
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([ix,iy,data],level+2,varargin{:})];
end
else
if(isreal(item))
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson(item(:)',level+2,varargin{:})];
else
txt=[txt,S_('_ArrayIsComplex_'),'T'];
txt=[txt,S_('_ArrayData_'),...
matdata2ubjson([real(item(:)) imag(item(:))],level+2,varargin{:})];
end
end
txt=[txt,'}'];
%%-------------------------------------------------------------------------
function txt=matdata2ubjson(mat,level,varargin)
if(isempty(mat))
txt='Z';
return;
end
if(size(mat,1)==1)
level=level-1;
end
type='';
hasnegtive=(mat<0);
if(isa(mat,'integer') || isinteger(mat) || (isfloat(mat) && all(mod(mat(:),1) == 0)))
if(isempty(hasnegtive))
if(max(mat(:))<=2^8)
type='U';
end
end
if(isempty(type))
% todo - need to consider negative ones separately
id= histc(abs(max(mat(:))),[0 2^7 2^15 2^31 2^63]);
if(isempty(find(id)))
error('high-precision data is not yet supported');
end
key='iIlL';
type=key(find(id));
end
txt=[I_a(mat(:),type,size(mat))];
elseif(islogical(mat))
logicalval='FT';
if(numel(mat)==1)
txt=logicalval(mat+1);
else
txt=['[$U#' I_a(size(mat),'l') typecast(swapbytes(uint8(mat(:)')),'uint8')];
end
else
if(numel(mat)==1)
txt=['[' D_(mat) ']'];
else
txt=D_a(mat(:),'D',size(mat));
end
end
%txt=regexprep(mat2str(mat),'\s+',',');
%txt=regexprep(txt,';',sprintf('],['));
% if(nargin>=2 && size(mat,1)>1)
% txt=regexprep(txt,'\[',[repmat(sprintf('\t'),1,level) '[']);
% end
if(any(isinf(mat(:))))
txt=regexprep(txt,'([-+]*)Inf',jsonopt('Inf','"$1_Inf_"',varargin{:}));
end
if(any(isnan(mat(:))))
txt=regexprep(txt,'NaN',jsonopt('NaN','"_NaN_"',varargin{:}));
end
%%-------------------------------------------------------------------------
function newname=checkname(name,varargin)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname=name;
if(isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
return
end
if(isunpack)
isoct=jsonopt('IsOctave',0,varargin{:});
if(~isoct)
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${native2unicode(hex2dec($2))}');
else
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos)) return; end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
end
end
end
%%-------------------------------------------------------------------------
function val=S_(str)
if(length(str)==1)
val=['C' str];
else
val=['S' I_(int32(length(str))) str];
end
%%-------------------------------------------------------------------------
function val=I_(num)
if(~isinteger(num))
error('input is not an integer');
end
if(num>=0 && num<255)
val=['U' data2byte(swapbytes(cast(num,'uint8')),'uint8')];
return;
end
key='iIlL';
cid={'int8','int16','int32','int64'};
for i=1:4
if((num>0 && num<2^(i*8-1)) || (num<0 && num>=-2^(i*8-1)))
val=[key(i) data2byte(swapbytes(cast(num,cid{i})),'uint8')];
return;
end
end
error('unsupported integer');
%%-------------------------------------------------------------------------
function val=D_(num)
if(~isfloat(num))
error('input is not a float');
end
if(isa(num,'single'))
val=['d' data2byte(num,'uint8')];
else
val=['D' data2byte(num,'uint8')];
end
%%-------------------------------------------------------------------------
function data=I_a(num,type,dim,format)
id=find(ismember('iUIlL',type));
if(id==0)
error('unsupported integer array');
end
% based on UBJSON specs, all integer types are stored in big endian format
if(id==1)
data=data2byte(swapbytes(int8(num)),'uint8');
blen=1;
elseif(id==2)
data=data2byte(swapbytes(uint8(num)),'uint8');
blen=1;
elseif(id==3)
data=data2byte(swapbytes(int16(num)),'uint8');
blen=2;
elseif(id==4)
data=data2byte(swapbytes(int32(num)),'uint8');
blen=4;
elseif(id==5)
data=data2byte(swapbytes(int64(num)),'uint8');
blen=8;
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/blen)) data(:)'];
end
data=['[' data(:)'];
else
data=reshape(data,blen,numel(data)/blen);
data(2:blen+1,:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function data=D_a(num,type,dim,format)
id=find(ismember('dD',type));
if(id==0)
error('unsupported float array');
end
if(id==1)
data=data2byte(single(num),'uint8');
elseif(id==2)
data=data2byte(double(num),'uint8');
end
if(nargin>=3 && length(dim)>=2 && prod(dim)~=dim(2))
format='opt';
end
if((nargin<4 || strcmp(format,'opt')) && numel(num)>1)
if(nargin>=3 && (length(dim)==1 || (length(dim)>=2 && prod(dim)~=dim(2))))
cid=I_(uint32(max(dim)));
data=['$' type '#' I_a(dim,cid(1)) data(:)'];
else
data=['$' type '#' I_(int32(numel(data)/(id*4))) data(:)'];
end
data=['[' data];
else
data=reshape(data,(id*4),length(data)/(id*4));
data(2:(id*4+1),:)=data;
data(1,:)=type;
data=data(:)';
data=['[' data(:)' ']'];
end
%%-------------------------------------------------------------------------
function bytes=data2byte(varargin)
bytes=typecast(varargin{:});
bytes=bytes(:)';
|
github
|
khanhnamle1994/machine-learning-master
|
submit.m
|
.m
|
machine-learning-master/machine-learning-ex5/ex5/submit.m
| 1,765 |
utf_8
|
b1804fe5854d9744dca981d250eda251
|
function submit()
addpath('./lib');
conf.assignmentSlug = 'regularized-linear-regression-and-bias-variance';
conf.itemName = 'Regularized Linear Regression and Bias/Variance';
conf.partArrays = { ...
{ ...
'1', ...
{ 'linearRegCostFunction.m' }, ...
'Regularized Linear Regression Cost Function', ...
}, ...
{ ...
'2', ...
{ 'linearRegCostFunction.m' }, ...
'Regularized Linear Regression Gradient', ...
}, ...
{ ...
'3', ...
{ 'learningCurve.m' }, ...
'Learning Curve', ...
}, ...
{ ...
'4', ...
{ 'polyFeatures.m' }, ...
'Polynomial Feature Mapping', ...
}, ...
{ ...
'5', ...
{ 'validationCurve.m' }, ...
'Validation Curve', ...
}, ...
};
conf.output = @output;
submitWithConfiguration(conf);
end
function out = output(partId, auxstring)
% Random Test Cases
X = [ones(10,1) sin(1:1.5:15)' cos(1:1.5:15)'];
y = sin(1:3:30)';
Xval = [ones(10,1) sin(0:1.5:14)' cos(0:1.5:14)'];
yval = sin(1:10)';
if partId == '1'
[J] = linearRegCostFunction(X, y, [0.1 0.2 0.3]', 0.5);
out = sprintf('%0.5f ', J);
elseif partId == '2'
[J, grad] = linearRegCostFunction(X, y, [0.1 0.2 0.3]', 0.5);
out = sprintf('%0.5f ', grad);
elseif partId == '3'
[error_train, error_val] = ...
learningCurve(X, y, Xval, yval, 1);
out = sprintf('%0.5f ', [error_train(:); error_val(:)]);
elseif partId == '4'
[X_poly] = polyFeatures(X(2,:)', 8);
out = sprintf('%0.5f ', X_poly);
elseif partId == '5'
[lambda_vec, error_train, error_val] = ...
validationCurve(X, y, Xval, yval);
out = sprintf('%0.5f ', ...
[lambda_vec(:); error_train(:); error_val(:)]);
end
end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.