This is a static copy of a profile report

Home

ismember>ismemberR2012a (Calls: 200, Time: 0.133 s)
Generated 16-Jul-2020 17:08:52 using performance time.
subfunction in file /Applications/MATLAB_R2020a.app/toolbox/matlab/ops/ismember.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
ismemberfunction200
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
204
lia = ismemberClassTypes(a,b);
1700.102 s76.9%
181
if isempty(rootClassA) || ~isa...
1700.006 s4.9%
177
if ~(isa(a,'handle.handle') ||...
2000.006 s4.7%
192
if ~(isa(a,'opaque') || isa(b,...
2000.004 s3.0%
197
lia = ismemberBuiltinTypes(a,b...
300.003 s2.2%
All other lines  0.011 s8.3%
Totals  0.133 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
ismember>ismemberClassTypessubfunction1700.100 s75.0%
ismember>ismemberBuiltinTypessubfunction300.002 s1.7%
Self time (built-ins, overhead, etc.)  0.031 s23.3%
Totals  0.133 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 run28
Code lines that did not run76
Coverage (did run/can run)26.92 %
Function listing
time 
Calls 
 line
 163 
function [lia,locb] = ismemberR2012a(a,b,options)
 164 
% 'R2012a' flag implementation
 165 

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

< 0.001 
    200 
 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.006 
    200 
 177
if ~(isa(a,'handle.handle') || isa(b,'handle.handle')) 
  0.002 
    200 
 178
    if ~strcmpi(class(a),class(b)) 
  0.002 
    170 
 179
        if isa(a,'matlab.mixin.Heterogeneous') && isa(b,'matlab.mixin.Heterogeneous') 
  0.003 
    170 
 180
            rootClassA = meta.internal.findHeterogeneousRootClass(a); 
  0.006 
    170 
 181
            if isempty(rootClassA) || ~isa(b,rootClassA.Name) 
 182 
                error(message('MATLAB:ISMEMBER:InvalidInputsDataType',class(a),class(b)));
< 0.001 
    170 
 183
            end 
< 0.001 
    170 
 184
            doBuiltinTypes = false; 
 185 
        elseif ~(strcmpi(class(a),'double') || strcmpi(class(b),'double'))
 186 
            error(message('MATLAB:ISMEMBER:InvalidInputsDataType',class(a),class(b)));
< 0.001 
    170 
 187
        end 
< 0.001 
    200 
 188
    end 
< 0.001 
    200 
 189
end 
 190 

< 0.001 
    200 
 191
if ~byrow 
  0.004 
    200 
 192
    if ~(isa(a,'opaque') || isa(b,'opaque')) && doBuiltinTypes 
 193 
        % Builtin types
< 0.001 
     30 
 194
        if nargout > 1 
 195 
            [lia,locb] = ismemberBuiltinTypes(a,b);
< 0.001 
     30 
 196
        else 
  0.003 
     30 
 197
            lia = ismemberBuiltinTypes(a,b); 
< 0.001 
     30 
 198
        end 
< 0.001 
    170 
 199
    else 
 200 
        % Handle objects
< 0.001 
    170 
 201
        if nargout > 1 
 202 
            [lia,locb] = ismemberClassTypes(a,b);
< 0.001 
    170 
 203
        else 
  0.102 
    170 
 204
            lia = ismemberClassTypes(a,b); 
< 0.001 
    170 
 205
        end 
< 0.001 
    200 
 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 
    200 
 298
end 
< 0.001 
    200 
 299
end 

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