code: def test_partial_sum_product(
      impl, sum_op, prod_op, inputs, plates, vars1, vars2
  ):
      inputs = inputs.split(",")
      factors = [
          random_tensor(OrderedDict((d, Bint[2]) for d in ds))
          for ds in inputs
      ]
      vars1 = frozenset(vars1)
      vars2 = frozenset(vars2)
  
      plate_to_step = {k: {} for k in plates}
      if impl is partial_sum_product:
          plates = frozenset(plates)
      else:
          plates = {k: {} for k in plates}
  
      factors1 = impl(sum_op, prod_op, factors, vars1, plates)
      factors2 = impl(sum_op, prod_op, factors1, vars2, plates)
      actual = reduce(prod_op, factors2)
  
      expected = sum_product(
          sum_op, prod_op, factors, vars1 | vars2, frozenset(plates)
      )
      assert_close(actual, expected)
  
      with lazy:
          (
              unrolled_factors,
              unrolled_vars,
              remaining_plates,
          ) = partial_unroll(factors, vars1 | vars2, plate_to_step)
          unrolled_expected = reduce(prod_op, unrolled_factors).reduce(
              sum_op, unrolled_vars
          )
      unrolled_expected = apply_optimizer(unrolled_expected)
      assert_close(actual, unrolled_expected)
  
imports: import os
  import re
  from collections import OrderedDict
  from functools import partial, reduce
  import pytest
  import funsor.ops
  from funsor.domains import Bint, Real, Reals
  from funsor.interpretations import compress_gaussians, eager, eager_or_die, lazy, moment_matching, reflect
  from funsor.interpreter import reinterpret
  from funsor.optimizer import apply_optimizer
  from funsor.sum_product import MarkovProduct, _partition, dynamic_partial_sum_product, mixed_sequential_sum_product, modified_partial_sum_product, naive_sarkka_bilmes_product, naive_sequential_sum_product, partial_sum_product, partial_unroll, sarkka_bilmes_product, sequential_sum_product, sum_product
  from funsor.tensor import Tensor, get_default_prototype
  from funsor.terms import Cat, Variable
  from funsor.testing import assert_close, random_gaussian, random_tensor
  from funsor.util import get_backend
label_desc: Use image node_id 2 for calling a global function with example usage: test_partial_sum_product(impl, sum_op, prod_op, inputs, plates, vars1, vars2) without return types