This is a static copy of a profile report

Home

Function details for ismember>ismemberBuiltinTypesThis is a static copy of a profile report

Home

ismember>ismemberBuiltinTypes (Calls: 7, Time: 0.002 s)
Generated 07-Jul-2019 01:13:14 using performance time.
subfunction in file C:\Program Files\MATLAB\R2019a\toolbox\matlab\ops\ismember.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
ismember>ismemberR2012asubfunction7
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
319
for i=1:numelA
40.000 s11.6%
303
if numelA > 0 && nu...
30.000 s9.5%
321
end
40.000 s8.1%
317
lia = false(size(a));
40.000 s8.1%
302
if numelA == 0 || numelB <=...
70.000 s5.5%
All other lines  0.001 s57.2%
Totals  0.002 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 run19
Code lines that did not run65
Coverage (did run/can run)22.62 %
Function listing
time 
Calls 
 line
 293 
function [lia,locb] = ismemberBuiltinTypes(a,b)
 294 
% General handling.
 295 
% Use FIND method for very small sizes of the input vector to avoid SORT.
< 0.001 
      7 
 296
if nargout > 1 
 297 
    locb = zeros(size(a));
 298 
end
 299 
% Handle empty arrays and scalars.  
< 0.001 
      7 
 300
numelA = numel(a); 
      7 
 301
numelB = numel(b); 
< 0.001 
      7 
 302
if numelA == 0 || numelB <= 1 
< 0.001 
      3 
 303
    if numelA > 0 && numelB == 1 
< 0.001 
      3 
 304
        lia = (a == b); 
      3 
 305
        if nargout > 1 
 306 
            % Use DOUBLE to convert logical "1" index to double "1" index.
 307 
            locb = double(lia);
 308 
        end
 309 
    else
 310 
        lia = false(size(a));
< 0.001 
      3 
 311
    end 
< 0.001 
      3 
 312
    return 
 313 
end
 314 

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

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