function tf = hCatCheck(obj, catdim, codistrs, LPs)
; %#ok<NOSEM> % Undocumented
%   Implementation of hCatCheck for codistributor2dbc.  It only handles
%   concatenation that can be performed trivially and without any 
%   communication.

%   Copyright 2009-2022 The MathWorks, Inc.

if catdim > 2
    tf  = false;
    return
end

% All codistributors must have the same WorkerGrid, BlockSize and Orientation.
% Size in catdim must be a multiple of WorkerGrid(dim)*BlockSize.
isReplicated = cellfun(@isempty, codistrs); 
samePropVals = @(c) isequal(c.Orientation, obj.Orientation) ...
    && isequal(c.WorkerGrid, obj.WorkerGrid) ...
    && isequal(c.BlockSize, obj.BlockSize);
tf = all(cellfun(samePropVals, codistrs(~isReplicated)));

% Verify that all workers have the same number of blocks and that the
% blocks are all of full size.
szMultiple = obj.WorkerGrid(catdim)*obj.BlockSize;
sizesOk = @(c) mod(c.Cached.GlobalSize(catdim), szMultiple) == 0;
tf = tf && all(cellfun(sizesOk, codistrs(~isReplicated)));

% Verify that the replicated arrays also lead to the workers having the
% same number of blocks and that the blocks are of full size.
sizesOk = @(LP) mod(size(LP, catdim), szMultiple) == 0;
tf = tf && all(cellfun(sizesOk, LPs(isReplicated)));

% Note that the preconditions of this method state that the sizes of the input
% arrays must be consistent for concatenation.  Thus, we know that the
% replicated arrays are either vectors or matrices, because they are consistent
% with the 2DBC array that obj represents.

end % End of hCatCheck.
