code: def test_sum_product():
      def fn(f, g, h):
          # This function only uses Funsors internally.
          factors = [
              Tensor(f)["x"],
              Tensor(g)["x", "y"],
              Tensor(h)["y", "z", "i"],
          ]
          eliminate = frozenset({"x", "y", "z", "i"})
          plates = frozenset({"i"})
          with reflect:
              expr = sum_product(
                  ops.logaddexp, ops.add, factors, eliminate, plates
              )
              expr = apply_optimizer(expr)
          expr = reinterpret(expr)
          return expr.data
  
      data = dict(f=randn(5), g=randn(5, 4), h=randn(4, 3, 2))
      expected = fn(**data)
  
      traced_fn = trace_function(fn, data)
      actual = traced_fn(**data)
      assert_close(actual, expected)
  
imports: from collections import OrderedDict
  import pytest
  import funsor.ops
  from funsor.domains import Real, Reals
  from funsor.gaussian import Gaussian
  from funsor.interpretations import reflect
  from funsor.interpreter import reinterpret
  from funsor.op_factory import make_op
  from funsor.ops.tracer import trace_function
  from funsor.optimizer import apply_optimizer
  from funsor.sum_product import sum_product
  from funsor.tensor import Tensor
  from funsor.terms import to_data, to_funsor
  from funsor.testing import assert_close, randn
label_desc: Use image node_id 8 for calling a global function with example usage: test_sum_product() and returns: expr