This is a static copy of a profile report

Home

ismember>ismemberBuiltinTypes (Calls: 13, Time: 0.004 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
ismember>ismemberClassTypessubfunction3
ismember>ismemberR2012asubfunction10
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
305
locb = zeros(size(a));
30.001 s12.2%
310
if numelA == 0 || numelB <=...
130.000 s8.6%
329
end
180.000 s7.9%
337
end
60.000 s7.4%
327
for i=1:numelA
60.000 s5.3%
All other lines  0.003 s58.6%
Totals  0.004 s100% 
Children (called functions)
No children
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function103
Non-code lines (comments, blank lines)19
Code lines (lines that can run)84
Code lines that did run30
Code lines that did not run54
Coverage (did run/can run)35.71 %
Function listing
time 
Calls 
 line
 301 
function [lia,locb] = ismemberBuiltinTypes(a,b)
 302 
% General handling.
 303 
% Use FIND method for very small sizes of the input vector to avoid SORT.
< 0.001 
     13 
 304
if nargout > 1 
< 0.001 
      3 
 305
    locb = zeros(size(a)); 
< 0.001 
     13 
 306
end 
 307 
% Handle empty arrays and scalars.
< 0.001 
     13 
 308
numelA = numel(a); 
< 0.001 
     13 
 309
numelB = numel(b); 
< 0.001 
     13 
 310
if numelA == 0 || numelB <= 1 
< 0.001 
      5 
 311
    if numelA > 0 && numelB == 1 
 312 
        lia = (a == b);
 313 
        if nargout > 1
 314 
            % Use DOUBLE to convert logical "1" index to double "1" index.
 315 
            locb = double(lia);
 316 
        end
< 0.001 
      5 
 317
    else 
< 0.001 
      5 
 318
        lia = false(size(a)); 
< 0.001 
      5 
 319
    end 
< 0.001 
      5 
 320
    return 
< 0.001 
      8 
 321
end 
 322 

< 0.001 
      8 
 323
scalarcut = 5; 
< 0.001 
      8 
 324
if numelA <= scalarcut 
< 0.001 
      8 
 325
    lia = false(size(a)); 
< 0.001 
      8 
 326
    if nargout <= 1 
< 0.001 
      6 
 327
        for i=1:numelA 
< 0.001 
     18 
 328
            lia(i) = any(a(i)==b(:)); 
< 0.001 
     18 
 329
        end 
< 0.001 
      2 
 330
    else 
< 0.001 
      2 
 331
        for i=1:numelA 
< 0.001 
      6 
 332
            found = a(i)==b(:); 
< 0.001 
      6 
 333
            if any(found) 
< 0.001 
      6 
 334
                lia(i) = true; 
< 0.001 
      6 
 335
                locb(i) = find(found,1); 
< 0.001 
      6 
 336
            end 
< 0.001 
      6 
 337
        end 
< 0.001 
      8 
 338
    end 
 339 
else
 340 
    % Use method which sorts list, then performs binary search.
 341 
    % Convert to full to work in C helper.
 342 
    if issparse(a)
 343 
        a = full(a);
 344 
    end
 345 
    if issparse(b)
 346 
        b = full(b);
 347 
    end
 348 
    
 349 
    if (isreal(b))
 350 
        % Find out whether list is presorted before sort
 351 
        sortedlist = issorted(b(:));
 352 
        if nargout > 1
 353 
            if ~sortedlist
 354 
                [b,idx] = sort(b(:));
 355 
            end
 356 
        elseif ~sortedlist
 357 
            b = sort(b(:));
 358 
        end
 359 
    else
 360 
        sortedlist = 0;
 361 
        [~,idx] = sort(real(b(:)));
 362 
        b = b(idx);
 363 
    end
 364 
    
 365 
    % Use builtin helper function ISMEMBERHELPER:
 366 
    % [LIA,LOCB] = ISMEMBERHELPER(A,B) Returns logical array LIA indicating
 367 
    % which elements of A occur in B and a double array LOCB with the
 368 
    % locations of the elements of A occurring in B. If multiple instances
 369 
    % occur, the first occurrence is returned. B must be already sorted.
 370 
    
 371 
    if ~isobject(a) && ~isobject(b) && (isnumeric(a) || ischar(a) || islogical(a))
 372 
        if (isnan(b(end)))
 373 
            % If NaNs detected, remove NaNs from B.
 374 
            b = b(~isnan(b(:)));
 375 
        end
 376 
        if nargout <= 1
 377 
            lia = builtin('_ismemberhelper',a,b);
 378 
        else
 379 
            [lia, locb] = builtin('_ismemberhelper',a,b);
 380 
        end
 381 
    else % a,b, are some other class like gpuArray, sym object.
 382 
        lia = false(size(a));
 383 
        if nargout <= 1
 384 
            for i=1:numelA
 385 
                lia(i) = any(a(i)==b(:));   % ANY returns logical.
 386 
            end
 387 
        else
 388 
            for i=1:numelA
 389 
                found = a(i)==b(:); % FIND returns indices for LOCB.
 390 
                if any(found)
 391 
                    lia(i) = true;
 392 
                    found = find(found);
 393 
                    locb(i) = found(1);
 394 
                end
 395 
            end
 396 
        end
 397 
    end
 398 
    if nargout > 1 && ~sortedlist
 399 
        % Re-reference locb to original list if it was unsorted
 400 
        locb(lia) = idx(locb(lia));
 401 
    end
< 0.001 
      8 
 402
end 
< 0.001 
      8 
 403
end 

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