This is a static copy of a profile report

Home

setdiff>setdiffR2012a (Calls: 108, Time: 0.137 s)
Generated 16-Jul-2020 17:08:54 using performance time.
subfunction in file /Applications/MATLAB_R2020a.app/toolbox/matlab/ops/setdiff.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
setdifffunction108
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
221
logUA = ~(ismember(a,b));
1080.096 s70.6%
226
c = unique(c,order);
1080.022 s16.0%
192
if isempty(rootClassA) || ~isa...
1080.005 s3.3%
188
if ~(isa(a,'handle.handle') ||...
1080.004 s2.9%
191
rootClassA = meta.internal.fin...
1080.002 s1.5%
All other lines  0.008 s5.7%
Totals  0.137 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
ismemberfunction1080.095 s69.9%
uniquefunction1080.020 s14.7%
Self time (built-ins, overhead, etc.)  0.021 s15.4%
Totals  0.137 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function164
Non-code lines (comments, blank lines)46
Code lines (lines that can run)118
Code lines that did run36
Code lines that did not run82
Coverage (did run/can run)30.51 %
Function listing
time 
Calls 
 line
 169 
function [c,ia] = setdiffR2012a(a,b,options)
 170 
% 'R2012a' flag implementation
 171 

 172 
% flagvals = {'rows' 'sorted' 'stable'};
< 0.001 
    108 
 173
if nargin == 2 
 174 
    byrow = false;
 175 
    order = 'sorted';
< 0.001 
    108 
 176
else 
< 0.001 
    108 
 177
    byrow = (options(1) > 0); 
< 0.001 
    108 
 178
    if options(3) > 0 
< 0.001 
    108 
 179
        order = 'stable'; 
 180 
    else % if options(2) > 0 || sum(options(2:3)) == 0)
 181 
        order = 'sorted';
< 0.001 
    108 
 182
    end 
< 0.001 
    108 
 183
end 
 184 

 185 
% Check that one of A and B is double if A and B are non-homogeneous. Do a
 186 
% separate check if A is a heterogeneous object and only allow a B
 187 
% that is of the same root class.  
  0.004 
    108 
 188
if ~(isa(a,'handle.handle') || isa(b,'handle.handle')) 
< 0.001 
    108 
 189
    if ~strcmpi(class(a),class(b)) 
< 0.001 
    108 
 190
        if isa(a,'matlab.mixin.Heterogeneous') && isa(b,'matlab.mixin.Heterogeneous') 
  0.002 
    108 
 191
            rootClassA = meta.internal.findHeterogeneousRootClass(a); 
  0.005 
    108 
 192
            if isempty(rootClassA) || ~isa(b,rootClassA.Name) 
 193 
                error(message('MATLAB:SETDIFF:InvalidInputsDataType',class(a),class(b)));
< 0.001 
    108 
 194
            end 
 195 
        elseif ~(strcmpi(class(a),'double') || strcmpi(class(b),'double'))
 196 
            error(message('MATLAB:SETDIFF:InvalidInputsDataType',class(a),class(b)));
< 0.001 
    108 
 197
        end 
< 0.001 
    108 
 198
    end 
< 0.001 
    108 
 199
end 
 200 

 201 
% Determine if A is a row vector.
  0.001 
    108 
 202
rowvec = isrow(a); 
 203 

< 0.001 
    108 
 204
sparseA = false; 
 205 

 206 
% Determine if A is sparse
< 0.001 
    108 
 207
if issparse(a) 
 208 
    sparseA = true;
 209 
    a = full(a);
< 0.001 
    108 
 210
end 
< 0.001 
    108 
 211
if issparse(b) 
 212 
    b = full(b);
< 0.001 
    108 
 213
end 
 214 

< 0.001 
    108 
 215
if ~byrow 
 216 
    % Convert to columns.
  0.001 
    108 
 217
    a = a(:); 
< 0.001 
    108 
 218
    b = b(:); 
 219 
    
 220 
    % Call ISMEMBER to determine list of non-matching elements of A.
  0.096 
    108 
 221
    logUA = ~(ismember(a,b)); 
  0.001 
    108 
 222
    c = a(logUA); 
 223 
    
 224 
    % Call UNIQUE to remove duplicates from list of non-matches.
< 0.001 
    108 
 225
    if nargout <= 1 
  0.022 
    108 
 226
        c = unique(c,order); 
 227 
    else
 228 
        [c,ndx] = unique(c,order);
 229 
        
 230 
        % Find indices by using logUA and NDX.
 231 
        indlogUA = find(logUA);
 232 
        ia = indlogUA(ndx);
< 0.001 
    108 
 233
    end 
 234 
    
 235 
    % If a is a row vector, return c as a row vector.
< 0.001 
    108 
 236
    if rowvec 
 237 
        c = c.';
< 0.001 
    108 
 238
    end 
 239 
    % If a is sparse then c is sparse.
< 0.001 
    108 
 240
    if sparseA 
 241 
        c = sparse(c);
< 0.001 
    108 
 242
    end 
 243 
    
 244 
else    % 'rows' case
 245 
    if ~(ismatrix(a) && ismatrix(b))
 246 
        error(message('MATLAB:SETDIFF:NotAMatrix'));
 247 
    end
 248 
    
 249 
    [rowsA,colsA] = size(a);
 250 
    [rowsB,colsB] = size(b);
 251 
    
 252 
    % Automatically pad strings with spaces
 253 
    if ischar(a) && ischar(b)
 254 
        if colsA > colsB
 255 
            b = [b repmat(' ',rowsB,colsA-colsB)];
 256 
        elseif colsA < colsB
 257 
            a = [a repmat(' ',rowsA,colsB-colsA)];
 258 
            colsA = colsB;
 259 
        end
 260 
    elseif colsA ~= colsB
 261 
        error(message('MATLAB:SETDIFF:AandBColnumAgree'));
 262 
    end
 263 
    
 264 
    % Handle empty arrays
 265 
    if rowsA == 0
 266 
        c = cat(1, zeros(rowsA,colsA), a(1:0,1:0));
 267 
        ia = zeros(0,1);
 268 
    elseif colsA == 0
 269 
        c = cat(1, [], a(1:0,1:0));
 270 
        ia = zeros(0,1);
 271 
    % General handling
 272 
    else
 273 
        % Remove duplicates from A; get indices only if needed
 274 
        if nargout > 1
 275 
            [uA,ia] = unique(a,'rows',order);
 276 
        else
 277 
            uA = unique(a,'rows',order);
 278 
        end
 279 
        
 280 
        if needsCastingCheck(a, b)
 281 
            % Set the output to be the unique entries of the input.
 282 
            c = uA;
 283 
            % Find all rows of b that are elements of the unique rows of A.
 284 
            [~,locuA] = ismember(b, uA, 'rows');
 285 
            % Take the unique set of indices of rows of uA that were found
 286 
            % within b.
 287 
            rmidx = unique(locuA(locuA ~= 0));
 288 
            % Remove these rows from c and, if requested, ia.
 289 
            c(rmidx,:) = [];
 290 
            if nargout > 1
 291 
                ia(rmidx,:) = [];
 292 
            end
 293 
        else
 294 
            % Create sorted list of unique A and B; want non-matching entries
 295 
            [sortuAB,ndx] = sortrows([uA;b]);
 296 
            [rowsC,colsC] = size(sortuAB);
 297 

 298 
            if rowsC > 1 && colsC ~= 0
 299 
                % d indicates the location of non-matching entries
 300 
                d = sortuAB(1:rowsC-1,:) ~= sortuAB(2:rowsC,:);
 301 
            else
 302 
                d = zeros(rowsC-1,0);
 303 
            end
 304 

 305 
            d = any(d,2);
 306 
            d(rowsC,1) = 1;   % Final entry always included.
 307 
            numRowsUA = size(uA,1);
 308 
            d = d & ndx <= numRowsUA; % Now find only the ones in A.
 309 

 310 
            if strcmp(order, 'stable') % 'stable'
 311 
                d = sort(ndx(d));   % Sort ndx(d) to maintain 'stable' order
 312 
                c = uA(d,:);
 313 
            else
 314 
                c = sortuAB(d,:);
 315 
            end
 316 

 317 
            % Find IA only if needed.
 318 
            if nargout > 1
 319 
                if strcmp(order, 'stable') % 'stable'
 320 
                    ia = ia(d);
 321 
                else
 322 
                    ia = ia(ndx(d));
 323 
                end
 324 
            end
 325 
        end
 326 
    end
 327 
    % If a is sparse then c is sparse.
 328 
    if sparseA
 329 
        c = sparse(c);
 330 
    end
< 0.001 
    108 
 331
end 
< 0.001 
    108 
 332
end 

Other subfunctions in this file are not included in this listing.