code: def mvn_to_gaussian(mvn):
      """
      Convert a MultivariateNormal distribution to a Gaussian.
  
      :param ~torch.distributions.MultivariateNormal mvn: A multivariate normal distribution.
      :return: An equivalent Gaussian object.
      :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)
      )
      if isinstance(mvn, torch.distributions.Independent):
          mvn = mvn.base_dist
          precision_diag = mvn.scale.pow(-2)
          precision = precision_diag.diag_embed()
          info_vec = mvn.loc * precision_diag
          scale_diag = mvn.scale
      else:
          precision = mvn.precision_matrix
          info_vec = matvecmul(precision, mvn.loc)
          scale_diag = mvn.scale_tril.diagonal(dim1=-2, dim2=-1)
  
      n = mvn.loc.size(-1)
      log_normalizer = (
          -0.5 * n * math.log(2 * math.pi)
          + -0.5 * (info_vec * mvn.loc).sum(-1)
          - scale_diag.log().sum(-1)
      )
      return Gaussian(log_normalizer, info_vec, precision)
  
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 1 for calling a global function with example usage: mvn_to_gaussian(mvn) and returns: Gaussian