function tf = hasNaN(A)
% Common implementation to check for NaNs in A.
% For codistributed inputs, check meta data for information and create it
% if necessary.

%   Copyright 2016-2019 The MathWorks, Inc.

if isa(A, "codistributed")
    if ~A.Metadata.HasNaN.isKnown()
        getFillPattern(A); % Force recalculation of fill-related metadata
    end
    tf = A.Metadata.HasNaN.get();
else
    tf = any(isnan(A), "all") == true;
end
end
