function TF = allConstraintsSatisfied(this, Xcanon, ConstraintModels, ErrorModel)
% Return true for every row of Xcanon that satisfies all of the
% constraints to their required tolerances. Empty constraints
% are never satisfied. XCanon is canonicalized: It is
% well-formed and has NaNs filled with LBs.
%

%   Copyright 2016-2022 The MathWorks, Inc.

if numel(ConstraintModels) == 0
    Sat = true;
else
    for i = numel(ConstraintModels):-1:1
        if isempty(ConstraintModels{i})
            Sat(1:size(Xcanon,1), i) = false;
        else
            [means, ysds] = predict(ConstraintModels{i}, Xcanon);
            fsds = bayesoptim.funStd(ysds, ConstraintModels{i}.Sigma);
            Sat(:,i) = normcdf(0, means, fsds) >= 1-this.PrivOptions.CoupledConstraintTolerances(i);
        end
    end
end
if isempty(ErrorModel)
    % Assume no error if no error GP
    ErrorConstraintSat(1:size(Xcanon,1), 1) = true;
else
    [means, ysds] = predict(ErrorModel, Xcanon);
    fsds = bayesoptim.funStd(ysds, ErrorModel.Sigma);
    ErrorConstraintSat = normcdf(0, means, fsds) >= 1-this.PrivOptions.ErrorConstraintTol;
end
TF = all(Sat, 2) & ErrorConstraintSat;
end
