code: def test_marginal(equation):
      inputs, output = equation.split("->")
      inputs = inputs.split(",")
      operands = [
          torch.randn(torch.Size((2,) * len(input_)))
          for input_ in inputs
      ]
      for input_, x in zip(inputs, operands):
          x._pyro_dims = input_
  
      # check forward pass
      for x in operands:
          require_backward(x)
      actual = contract(
          equation, *operands, backend="pyro.ops.einsum.torch_marginal"
      )
      expected = contract(
          equation, *operands, backend="pyro.ops.einsum.torch_log"
      )
      assert_equal(expected, actual)
  
      # check backward pass
      actual._pyro_backward()
      for input_, operand in zip(inputs, operands):
          marginal_equation = ",".join(inputs) + "->" + input_
          expected = contract(
              marginal_equation,
              *operands,
              backend="pyro.ops.einsum.torch_log",
          )
          actual = operand._pyro_backward_result
          assert_equal(expected, actual)
  
file_path: pyro/tests/ops/einsum/test_adjoint.py
imports: import gc
  import itertools
  import pytest
  import torch
  from pyro.ops.einsum import contract
  from pyro.ops.einsum.adjoint import require_backward
  from tests.common import assert_equal
label_desc: Use image node_id 2 for calling a global function with example usage: test_marginal(equation) without return types