This is a static copy of a profile report

Home

ismember>ismemberBuiltinTypes (Calls: 138, Time: 0.005 s)
Generated 16-Jul-2020 17:08:53 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
ismember>ismemberR2012asubfunction30
ismember>ismemberClassTypessubfunction108
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
318
lia = false(size(a));
1080.001 s10.9%
327
for i=1:numelA
300.000 s7.9%
325
lia = false(size(a));
300.000 s7.3%
320
return
1080.000 s5.3%
329
end
300.000 s5.3%
All other lines  0.003 s63.3%
Totals  0.005 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 run21
Code lines that did not run63
Coverage (did run/can run)25.00 %
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 
    138 
 304
if nargout > 1 
 305 
    locb = zeros(size(a));
< 0.001 
    138 
 306
end 
 307 
% Handle empty arrays and scalars.  
< 0.001 
    138 
 308
numelA = numel(a); 
< 0.001 
    138 
 309
numelB = numel(b); 
< 0.001 
    138 
 310
if numelA == 0 || numelB <= 1 
< 0.001 
    108 
 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 
    108 
 317
    else 
< 0.001 
    108 
 318
        lia = false(size(a)); 
< 0.001 
    108 
 319
    end 
< 0.001 
    108 
 320
    return 
< 0.001 
     30 
 321
end 
 322 

< 0.001 
     30 
 323
scalarcut = 5; 
< 0.001 
     30 
 324
if numelA <= scalarcut 
< 0.001 
     30 
 325
    lia = false(size(a)); 
< 0.001 
     30 
 326
    if nargout <= 1 
< 0.001 
     30 
 327
        for i=1:numelA 
< 0.001 
     30 
 328
            lia(i) = any(a(i)==b(:)); 
< 0.001 
     30 
 329
        end 
 330 
    else
 331 
        for i=1:numelA
 332 
            found = a(i)==b(:);
 333 
            if any(found)
 334 
                lia(i) = true;
 335 
                locb(i) = find(found,1);
 336 
            end
 337 
        end
< 0.001 
     30 
 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 
     30 
 402
end 
< 0.001 
     30 
 403
end 

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