function [g2,h2,K2] = enter_evidence_canonical(g1,h1,K1, X, Y, dom, y, sizes)
% ENTER_EVIDENCE_CANONICAL Compute can. chars. of Pr(X,Y=y) where X and Y are jointly Gaussian.
% [g2,h2,K2] = enter_evidence_canonical(g1,h1,K1, X, Y, dom, y, sizes)
%
% The moment version of this is 'condition_gaussian'.

assert(isequal(union(X, Y), dom));
assert(length(sizes) == length(dom));

if isempty(y)
  g2 = g1; h2 = h1; K2 = K1;
  return;
end

[hx, hy, KXX, KXY, KYX, KYY] = partition_matrix_vec(h1, K1, X, Y, dom, sizes);
y = y(:);
g2 = g1 + hy'*y - 0.5*y'*KYY*y;
if length(hx)==0 % isempty(X) % i.e., we have instantiated everything away
  h2 = [];
  K2 = [];
else
  h2 = hx - KXY*y;
  K2 = KXX;
end

