function out = collapseIntoLogicalColumn(in)
%MATLAB Code Generation Private Function

%   Copyright 2019 The MathWorks, Inc.
%
% Takes a matrix of logicals (in) and collapses it into a single column.
% This is the equivalent of any(in,2). 

%#codegen
coder.inline('always');
ONE = coder.internal.indexInt(1);
if ~iscolumn(in)
    numRows = coder.internal.indexInt(size(in,1));
    modOffset = max(coder.internal.indexInt(0),numRows - ONE);
    % Prevents modOffset from being -1 in the case where IA is empty
    out = coder.nullcopy(false(numRows,1));
    for ii = ONE:numel(in)
        if in(ii) || ii<=numRows
            out(mod(ii+modOffset,numRows)+ONE) = in(ii);
            % This approach ensures unit stride and scales to n dimensions,
            % but does not short-circuit when a 'true' value is found for a
            % particular row
        end
    end
else
    out = in;
end