code: def random_gamma_gaussian(batch_shape, dim, rank=None):
      """
      Generate a random Gaussian for testing.
      """
      if rank is None:
          rank = dim + dim
      log_normalizer = torch.randn(batch_shape)
      loc = torch.randn(batch_shape + (dim,))
      samples = torch.randn(batch_shape + (dim, rank))
      precision = torch.matmul(samples, samples.transpose(-2, -1))
      if dim > 0:
          info_vec = precision.matmul(loc.unsqueeze(-1)).squeeze(-1)
      else:
          info_vec = loc
      alpha = torch.randn(batch_shape).exp() + 0.5 * dim - 1
      beta = torch.randn(batch_shape).exp() + 0.5 * (
          info_vec * loc
      ).sum(-1)
      result = GammaGaussian(
          log_normalizer, info_vec, precision, alpha, beta
      )
      assert result.dim() == dim
      assert result.batch_shape == batch_shape
      return result
  
imports: import torch
  import pyro.distributions
  from pyro.ops.gamma_gaussian import GammaGaussian
  from tests.common import assert_close
label_desc: Use image node_id 1 for calling a global function with example usage: random_gamma_gaussian(batch_shape, dim, rank) and returns: result