code: def matrix_and_mvn_to_gamma_gaussian(matrix, mvn):
      """
      Convert a noisy affine function to a GammaGaussian, where the noise precision
      is scaled by an auxiliary variable `s`. The noisy affine function (conditioned
      on `s`) is defined as::
  
          y = x @ matrix + scale(mvn, s).sample()
  
      :param ~torch.Tensor matrix: A matrix with rightmost shape ``(x_dim, y_dim)``.
      :param ~pyro.distributions.MultivariateNormal mvn: A multivariate normal distribution.
      :return: A GammaGaussian with broadcasted batch shape and ``.dim() == x_dim + y_dim``.
      :rtype: ~pyro.ops.gaussian_gamma.GammaGaussian
      """
      assert isinstance(mvn, torch.distributions.MultivariateNormal)
      assert isinstance(matrix, torch.Tensor)
      x_dim, y_dim = matrix.shape[-2:]
      assert mvn.event_shape == (y_dim,)
      batch_shape = broadcast_shape(matrix.shape[:-2], mvn.batch_shape)
      matrix = matrix.expand(batch_shape + (x_dim, y_dim))
      mvn = mvn.expand(batch_shape)
  
      P_yy = mvn.precision_matrix
      neg_P_xy = matrix.matmul(P_yy)
      P_xy = -neg_P_xy
      P_yx = P_xy.transpose(-1, -2)
      P_xx = neg_P_xy.matmul(matrix.transpose(-1, -2))
      precision = torch.cat(
          [torch.cat([P_xx, P_xy], -1), torch.cat([P_yx, P_yy], -1)], -2
      )
      info_y = P_yy.matmul(mvn.loc.unsqueeze(-1)).squeeze(-1)
      info_x = -matrix.matmul(info_y.unsqueeze(-1)).squeeze(-1)
      info_vec = torch.cat([info_x, info_y], -1)
      log_normalizer = -0.5 * y_dim * math.log(
          2 * math.pi
      ) - mvn.scale_tril.diagonal(dim1=-2, dim2=-1).log().sum(-1)
      beta = 0.5 * (info_y * mvn.loc).sum(-1)
      alpha = beta.new_full(beta.shape, 0.5 * y_dim)
  
      result = GammaGaussian(
          log_normalizer, info_vec, precision, alpha, beta
      )
      assert result.batch_shape == batch_shape
      assert result.dim() == x_dim + y_dim
      return result
  
imports: import math
  import torch
  from torch.distributions.utils import lazy_property
  from torch.nn.functional import pad
  from pyro.distributions.multivariate_studentt import MultivariateStudentT
  from pyro.distributions.torch import MultivariateNormal
  from pyro.distributions.util import broadcast_shape
  from pyro.ops.tensor_utils import precision_to_scale_tril
label_desc: Use image node_id 3 for calling a global function with example usage: matrix_and_mvn_to_gamma_gaussian(matrix, mvn) and returns: result