code: def test_partition(inputs, dims, expected_num_components):
      sizes = dict(zip("abc", [2, 3, 4]))
      terms = [
          random_tensor(
              OrderedDict((s, Bint[sizes[s]]) for s in input_)
          )
          for input_ in inputs
      ]
      components = list(_partition(terms, dims))
  
      # Check that result is a partition.
      expected_terms = sorted(terms, key=id)
      actual_terms = sorted(
          (x for c in components for x in c[0]), key=id
      )
      assert actual_terms == expected_terms
      assert dims == set.union(set(), *(c[1] for c in components))
  
      # Check that the partition is not too coarse.
      assert len(components) == expected_num_components
  
      # Check that partition is not too fine.
      component_dict = {
          x: i for i, (terms, _) in enumerate(components) for x in terms
      }
      for x in terms:
          for y in terms:
              if x is not y:
                  if dims.intersection(x.inputs, y.inputs):
                      assert component_dict[x] == component_dict[y]
  
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 1 for calling a global function with example usage: test_partition(inputs, dims, expected_num_components) without return types