This is a static copy of a profile report

Home

ismember>ismemberR2012a (Calls: 13, Time: 0.023 s)
Generated 04-Jun-2021 04:11:21 using performance time.
subfunction in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\ops\ismember.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
ismemberfunction13
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
204
lia = ismemberClassTypes(a,b);
20.013 s57.8%
202
[lia,locb] = ismemberClassType...
10.004 s15.9%
197
lia = ismemberBuiltinTypes(a,b...
80.001 s6.0%
195
[lia,locb] = ismemberBuiltinTy...
20.001 s6.0%
191
if ~byrow
130.001 s2.7%
All other lines  0.003 s11.6%
Totals  0.023 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
ismember>ismemberClassTypessubfunction30.016 s70.8%
ismember>ismemberBuiltinTypessubfunction100.002 s8.7%
Self time (built-ins, overhead, etc.)  0.005 s20.6%
Totals  0.023 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function137
Non-code lines (comments, blank lines)33
Code lines (lines that can run)104
Code lines that did run26
Code lines that did not run78
Coverage (did run/can run)25.00 %
Function listing
time 
Calls 
 line
 163 
function [lia,locb] = ismemberR2012a(a,b,options)
 164 
% 'R2012a' flag implementation
 165 

 166 
% Error check flag
< 0.001 
     13 
 167
if nargin == 2 
< 0.001 
      9 
 168
    byrow = false; 
< 0.001 
      4 
 169
else 
< 0.001 
      4 
 170
    byrow = options > 0; 
< 0.001 
     13 
 171
end 
 172 

< 0.001 
     13 
 173
doBuiltinTypes = true; 
 174 
% Check that one of A and B is double if A and B are non-homogeneous. Do a
 175 
% separate check if A is a heterogeneous object and only allow a B
 176 
% that is of the same root class.
< 0.001 
     13 
 177
if ~(isa(a,'handle.handle') || isa(b,'handle.handle')) 
< 0.001 
     13 
 178
    if ~strcmpi(class(a),class(b)) 
 179 
        if isa(a,'matlab.mixin.Heterogeneous') && isa(b,'matlab.mixin.Heterogeneous')
 180 
            rootClassA = meta.internal.findHeterogeneousRootClass(a);
 181 
            if isempty(rootClassA) || ~isa(b,rootClassA.Name)
 182 
                error(message('MATLAB:ISMEMBER:InvalidInputsDataType',class(a),class(b)));
 183 
            end
 184 
            doBuiltinTypes = false;
 185 
        elseif ~(strcmpi(class(a),'double') || strcmpi(class(b),'double'))
 186 
            error(message('MATLAB:ISMEMBER:InvalidInputsDataType',class(a),class(b)));
 187 
        end
< 0.001 
     13 
 188
    end 
< 0.001 
     13 
 189
end 
 190 

< 0.001 
     13 
 191
if ~byrow 
< 0.001 
     13 
 192
    if ~(isa(a,'opaque') || isa(b,'opaque')) && doBuiltinTypes 
 193 
        % Builtin types
< 0.001 
     10 
 194
        if nargout > 1 
  0.001 
      2 
 195
            [lia,locb] = ismemberBuiltinTypes(a,b); 
< 0.001 
      8 
 196
        else 
  0.001 
      8 
 197
            lia = ismemberBuiltinTypes(a,b); 
< 0.001 
     10 
 198
        end 
< 0.001 
      3 
 199
    else 
 200 
        % Handle objects
< 0.001 
      3 
 201
        if nargout > 1 
  0.004 
      1 
 202
            [lia,locb] = ismemberClassTypes(a,b); 
      2 
 203
        else 
  0.013 
      2 
 204
            lia = ismemberClassTypes(a,b); 
< 0.001 
      3 
 205
        end 
< 0.001 
     13 
 206
    end 
 207 
else    % 'rows' case
 208 
    if ~(ismatrix(a) && ismatrix(b))
 209 
        error(message('MATLAB:ISMEMBER:NotAMatrix'));
 210 
    end
 211 
    
 212 
    [rowsA,colsA] = size(a);
 213 
    [rowsB,colsB] = size(b);
 214 
    
 215 
    % Automatically pad strings with spaces
 216 
    if ischar(a) && ischar(b)
 217 
        b = [b repmat(' ',rowsB,colsA-colsB)];
 218 
        a = [a repmat(' ',rowsA,colsB-colsA)];
 219 
    elseif colsA ~= colsB
 220 
        error(message('MATLAB:ISMEMBER:AandBColnumAgree'));
 221 
    end
 222 
    
 223 
    % Empty check for 'rows'.
 224 
    if rowsA == 0 || rowsB == 0
 225 
        lia = false(rowsA,1);
 226 
        locb = zeros(rowsA,1);
 227 
        return
 228 
    end
 229 
    
 230 
    % General handling for 'rows'.
 231 
    [checkCast, cls] = needsCastingChecks(a, b);
 232 
    needLocb = (nargout > 1) || checkCast;
 233 
    
 234 
    % Duplicates within the sets are eliminated
 235 
    if (rowsA == 1)
 236 
        uA = repmat(a,rowsB,1);
 237 
        d = uA(1:end,:)==b(1:end,:);
 238 
        d = all(d,2);
 239 
        lia = any(d);
 240 
        if nargout > 1
 241 
            if lia
 242 
                locb = find(d, 1, 'first');
 243 
            else
 244 
                locb = 0;
 245 
            end
 246 
        end
 247 
        return;
 248 
    else
 249 
        if checkCast
 250 
            [uA,~,icA] = unique(cast(a, cls),'rows','sorted');
 251 
        else
 252 
            [uA,~,icA] = unique(a,'rows','sorted');
 253 
        end
 254 
    end
 255 
    if ~needLocb
 256 
        uB = unique(b,'rows','sorted');
 257 
    elseif checkCast && ~strcmp(cls, class(b))
 258 
        % Find rows of B that do not change when cast.
 259 
        ibC = find(all(cast(b, cls) == b, 2));
 260 
        % Find the unique rows within those rows.
 261 
        [uB,ib] = unique(b(ibC,:), 'rows','sorted');
 262 
        % Adjust the indices to account for the removed rows.
 263 
        ib = ibC(ib);
 264 
    else
 265 
        [uB,ib] = unique(b, 'rows','sorted');
 266 
    end
 267 
    
 268 
    % Sort the unique elements of A and B, duplicate entries are adjacent
 269 
    [sortuAuB,IndSortuAuB] = sortrows([uA;uB]);
 270 
    
 271 
    % Find matching entries
 272 
    d = sortuAuB(1:end-1,:)==sortuAuB(2:end,:);     % d indicates matching entries
 273 
    d = all(d,2);                                   % Finds the index of matching entries
 274 
    ndx1 = IndSortuAuB(d);                          % NDX1 are locations of repeats in C
 275 
    
 276 
    if ~needLocb
 277 
        lia = ismemberBuiltinTypes(icA,ndx1);           % Find repeats among original list
 278 
    else
 279 
        szuA = size(uA,1);
 280 
        [lia,locb] = ismemberBuiltinTypes(icA,ndx1);    % Find locb by using given indices
 281 
        d = find(d);
 282 
        newd = d(locb(lia));                    % NEWD is D for non-unique A
 283 
        where = ib(IndSortuAuB(newd+1)-szuA);   % Index values of uB through UNIQUE
 284 
        locb(lia) = where;                      % Return first or last occurrence of A within B
 285 
    end
 286 
    if checkCast
 287 
        % Post-processing step: if we matched anything in a to b only
 288 
        % because of casting during the concatenation, we need to fix it.
 289 
        if ~strcmp(cls, class(a))
 290 
            % a may have lost precision in the concatenation.
 291 
            % Find all rows that have an entry that changed in the cast.
 292 
            rmA = any(cast(a, cls) ~= a, 2);
 293 
            % Remove these rows from elibility.
 294 
            lia(rmA) = false;
 295 
            locb(rmA) = 0;
 296 
        end
 297 
    end
< 0.001 
     13 
 298
end 
< 0.001 
     13 
 299
end 

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