code: def naive_contract_einsum(eqn, *terms, **kwargs):
      """
      Use for testing Contract against einsum
      """
      assert "plates" not in kwargs
  
      backend = kwargs.pop("backend", "torch")
      if backend in BACKEND_OPS:
          sum_op, prod_op = BACKEND_OPS[backend]
      else:
          raise ValueError("{} backend not implemented".format(backend))
  
      assert isinstance(eqn, str)
      assert all(isinstance(term, Funsor) for term in terms)
      inputs, output = eqn.split("->")
      inputs = inputs.split(",")
      assert len(inputs) == len(terms)
      assert len(output.split(",")) == 1
      input_dims = frozenset(d for inp in inputs for d in inp)
      output_dims = frozenset(d for d in output)
      all_inputs = {
          k: v for term in terms for k, v in term.inputs.items()
      }
      reduced_vars = frozenset(
          Variable(k, all_inputs[k]) for k in input_dims - output_dims
      )
      return Contraction(sum_op, prod_op, reduced_vars, *terms)
  
file_path: funsor/funsor/einsum/__init__.py
imports: from functools import reduce
  import funsor.ops
  from funsor.cnf import Contraction
  from funsor.optimizer import apply_optimizer
  from funsor.sum_product import sum_product
  from funsor.terms import Funsor, Variable, lazy
label_desc: Use image node_id 1 for calling a global function with example usage: naive_contract_einsum(eqn) and returns: Contraction