function [LP, codistr] = hNonzerosImpl(codistr, LP)
% hNonzerosImpl:  Implementation of nonzeros for codistributor1d 

%   Copyright 2009-2022 The MathWorks, Inc.
    
% if codistributor is 1D but not distributed in the appropriate 
% dimension to allow trivial computation, fix it
    if codistr.Dimension ~= length(codistr.Cached.GlobalSize) 
        destCodistr = codistributor1d(length(codistr.Cached.GlobalSize), ...
                                      codistributor1d.defaultPartition(codistr.Cached.GlobalSize(end)), ...
                                      codistr.Cached.GlobalSize);
        LP = distributedutil.Redistributor.redistribute(codistr, LP, destCodistr);
    end
    % perform trivial nonzeros computation and send results back as a column vector
    LP = nonzeros(LP);
            
    part = spmdCat(length(LP));
    sz = [sum(part), 1];
    dim = 1;
    codistr = codistributor1d(dim, part, sz);
end % End of hNonzerosImpl.
