code: def matrix_and_mvn_to_gaussian(matrix, mvn):
      """
      Convert a noisy affine function to a Gaussian. The noisy affine function is defined as::
  
          y = x @ matrix + mvn.sample()
  
      :param ~torch.Tensor matrix: A matrix with rightmost shape ``(x_dim, y_dim)``.
      :param ~torch.distributions.MultivariateNormal mvn: A multivariate normal distribution.
      :return: A Gaussian with broadcasted batch shape and ``.dim() == x_dim + y_dim``.
      :rtype: ~pyro.ops.gaussian.Gaussian
      """
      assert isinstance(
          mvn, torch.distributions.MultivariateNormal
      ) or (
          isinstance(mvn, torch.distributions.Independent)
          and isinstance(mvn.base_dist, torch.distributions.Normal)
      )
      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)
  
      # Handle diagonal normal distributions as an efficient special case.
      if isinstance(mvn, torch.distributions.Independent):
          return AffineNormal(
              matrix, mvn.base_dist.loc, mvn.base_dist.scale
          )
  
      y_gaussian = mvn_to_gaussian(mvn)
      result = matrix_and_gaussian_to_gaussian(matrix, y_gaussian)
      assert result.batch_shape == batch_shape
      assert result.dim() == x_dim + y_dim
      return result
  
imports: import math
  from typing import Optional, Tuple, Union
  import torch
  from torch.distributions.utils import lazy_property
  from torch.nn.functional import pad
  from pyro.distributions.util import broadcast_shape
  from pyro.ops.tensor_utils import matmul, matvecmul, safe_cholesky, triangular_solve
label_desc: Use image node_id 3 for calling a global function with example usage: matrix_and_mvn_to_gaussian(matrix, mvn) and returns: result, AffineNormal