code: def test_gaussian_distribution(event_inputs, batch_inputs):
      num_samples = 100000
      sample_inputs = OrderedDict(particle=Bint[num_samples])
      be_inputs = OrderedDict(batch_inputs + event_inputs)
      batch_inputs = OrderedDict(batch_inputs)
      event_inputs = OrderedDict(event_inputs)
      sampled_vars = frozenset(event_inputs)
      p = random_gaussian(be_inputs)
  
      rng_key = (
          None
          if get_backend() == "torch"
          else np.array([0, 0], dtype=np.uint32)
      )
      q = p.sample(sampled_vars, sample_inputs, rng_key=rng_key)
      q -= math.log(num_samples)
      p_vars = sampled_vars
      q_vars = sampled_vars | frozenset(["particle"])
      # Check zeroth moment.
      assert_close(
          q.reduce(ops.logaddexp, q_vars),
          p.reduce(ops.logaddexp, p_vars),
          atol=1e-6,
          rtol=None,
      )
      for k1, d1 in event_inputs.items():
          x = Variable(k1, d1)
          # Check first moments.
          assert_close(
              Integrate(q, x, q_vars),
              Integrate(p, x, p_vars),
              atol=0.5,
              rtol=0.2,
          )
          for k2, d2 in event_inputs.items():
              y = Variable(k2, d2)
              # Check second moments.
              continue  # FIXME: Quadratic integration is not supported:
              assert_close(
                  Integrate(q, x * y, q_vars),
                  Integrate(p, x * y, p_vars),
                  atol=1e-2,
              )
  
imports: import itertools
  import math
  from collections import OrderedDict
  from importlib import import_module
  import numpy
  import pytest
  import funsor.ops
  from funsor.cnf import Contraction
  from funsor.delta import Delta
  from funsor.distribution import BACKEND_TO_DISTRIBUTIONS_BACKEND
  from funsor.domains import Bint, Real, Reals
  from funsor.integrate import Integrate
  from funsor.montecarlo import MonteCarlo
  from funsor.tensor import Tensor, align_tensors
  from funsor.terms import Variable
  from funsor.testing import assert_close, excludes_backend, id_from_inputs, randn, random_gaussian, random_tensor, xfail_if_not_implemented
  from funsor.util import get_backend
label_desc: Use image node_id 6 for calling a global function with example usage: test_gaussian_distribution(event_inputs, batch_inputs) without return types