9 if ~isequal(size(SX),size(SY))
11 reportStr={
'sizes are different'};
15 nReports=length(reportStrList);
17 reportStrList(1:end-1)=cellfun(@(x)horzcat(x,sprintf(
'\n')),...
18 reportStrList(1:end-1),
'UniformOutput',
false);
21 reportStr=[reportStrList{:}];
29 [isEqualList,reportStrList]=arrayfun(@(x,y)
structcomparescalar(x,y,absTol,relTol),SX,SY,
'UniformOutput',
false);
30 nReportsList=
num2cell(cellfun(
'prodofsize',reportStrList));
31 isEqualVec=[isEqualList{:}];
32 isEqualList=cellfun(@(x,y)
repmat(x,1,y),isEqualList,nReportsList,
'UniformOutput',
false);
33 itemIndList=cellfun(@(x,y)
repmat(x,1,y),
num2cell(1:nElem).
',nReportsList,'UniformOutput
',false); 34 nReports=sum([nReportsList{:}]); 35 reportStrList=[reportStrList{:}]; 36 itemIndVec=[itemIndList{:}]; 37 isnEqualVec=~[isEqualList{:}]; 38 for iReport=1:nReports 39 if isnEqualVec(iReport) 40 reportStrList{iReport}=sprintf('(%d)%s
',itemIndVec(iReport),reportStrList{iReport}); 46 function [isEqual,reportStrList]= structcomparescalar(SX,SY,absTol,relTol) 47 import mxberry.core.cell.cell2tablestr; 48 import mxberry.core.throwerror; 49 if ~mxberry.core.checksize(SX,SY,[1 1]) 50 throwerror('wrongInput
','both inputs are expected to be of size [1,1]
'); 53 if ~(isstruct(SX)&&isstruct(SY)) 54 throwerror('wrongInput
','both inputs are expected to be structures
'); 58 fieldXList=sort(fieldnames(SX).');
59 fieldYList=sort(fieldnames(SY).
'); 60 isEqual=isequal(fieldXList,fieldYList); 63 fieldXMinusYList=setdiff(fieldXList,fieldYList); 64 fieldYMinusXList=setdiff(fieldYList,fieldXList); 66 reportStrList={['Field names are different, left-right:
',... 67 cell2tablestr('',fieldXMinusYList,'|
'),... 68 ', right-left:
',cell2tablestr('',fieldYMinusXList,'|
')]}; 72 nFields=length(fieldXList); 73 reportAddList=cell(1,nFields); 75 fieldName=fieldXList{iField}; 76 [isEqualCur,reportStrCurList]=compfun(SX.(fieldName),SY.(fieldName),absTol,relTol); 77 isEqual=isEqual&&isEqualCur; 79 if ~isstruct(SX.(fieldName)) 80 reportStrCurList=strcat('-->
',reportStrCurList); 82 reportStrCurList=strcat('.
',fieldName,reportStrCurList); 83 reportAddList{iField}=reportStrCurList; 86 reportStrList=[reportStrList,reportAddList{:}]; 89 function [isEqual,reportStr]=compfun(x,y,absTol,relTol) 90 import mxberry.core.absrelcompare; 97 if ~isequal(xClass,yClass) 98 reportStr='Different types
'; 105 if ~isequal(xSizeVec,ySizeVec) 106 reportStr=sprintf('Different sizes (left: %s, right: %s)
',... 107 mat2str(xSizeVec),mat2str(ySizeVec)); 110 x=toNumericSupportingMinus(x); 111 y=toNumericSupportingMinus(y); 112 if ismember(xClass,{'double','single
'}) 115 if ~isequal(isNanX,isNanY) 116 reportStr='Nans are on the different places
'; 121 if ~isequal(isMinusInfX,isMinusInfY) 122 reportStr='-Infs are on the different places
'; 127 if ~isequal(isInfX,isInfY) 128 reportStr='-Inf are on the different places
'; 131 isCompX=~(isNanX|isMinusInfX|isInfX); 132 isCompY=~(isNanY|isMinusInfY|isInfY); 134 isCompX=true(size(x)); 135 isCompY=true(size(y)); 138 [isEqual, ~, ~, ~, ~, reportStr] = absrelcompare(x(isCompX), ... 139 y(isCompY), absTol, relTol, @abs); 142 reportStr = horzcat('Max.
', reportStr); 146 [isEqual,reportStr]=mxberry.core.struct.structcompare(x,y,absTol,relTol); 150 elseif iscell(x)&&~iscellstr(x) 157 [isEqual,reportStr]=compfun(x{iElem},y{iElem},absTol,relTol); 163 reportStr=strcat('{
',num2str(iElem),'}
',reportStr); 166 elseif isa(x,'function_handle
') 167 isEqual=isequal(func2str(x),func2str(y)); 169 reportStr='values are different
'; 173 reportStr='values are different
'; 178 function x=toNumericSupportingMinus(x) 179 if isa(x,'uint64
')||isa(x,'int64
') function num2cell(in inpArray, in varargin)
NUM2CELL is an extension of Matlab built-in function "num2cell" designed to work correctly with empty...
function structcompare1darray(in SX, in SY, in absTol, in relTol)
STRUCTCOMPARE1D compares 1-dimentional structural arrays.
function repmat(in inpArray, in varargin)
function structcomparescalar(in SX, in SY, in absTol, in relTol)
STRUCTCOMPARE1D compares the scalar structures.
function structcomparevec(in SX, in SY, in absTol, in relTol)
STRUCTCOMPARE compares two structures using the specified tolerance.