function tf = hIsDiagonallyDominant(A)
%Check if a matrix is diagonally-dominant
%   


%   Copyright 2020-2022 The MathWorks, Inc.

assert(ismatrix(A) && ~isvector(A), "Input must be 2D.");

% Get from metadata to avoid recalculation.
if ~A.Metadata.IsDiagonallyDominant.isKnown()
    [lo, up] = bandwidth(A);
    bandA = abs(spdiags(A, -lo:up));
    lpBandA = getLocalPart(bandA);
    tf = spmdReduce(@and, all(lpBandA(:, lo+1) >= lpBandA(:, 1:lo) + lpBandA(:, lo+2:end)));
    A.Metadata.IsDiagonallyDominant.set(tf);
end

tf = A.Metadata.IsDiagonallyDominant.get();

end
