code: def test_extract_affine(expr):
      x = eval(expr)
      assert is_affine(x)
      assert isinstance(x, (Unary, Contraction, Finitary))
      real_inputs = OrderedDict(
          (k, d) for k, d in x.inputs.items() if d.dtype == "real"
      )
  
      const, coeffs = extract_affine(x)
      assert isinstance(const, Tensor)
      assert const.shape == x.shape
      assert list(coeffs) == list(real_inputs)
      for name, (coeff, eqn) in coeffs.items():
          assert isinstance(name, str)
          assert isinstance(coeff, Tensor)
          assert isinstance(eqn, str)
  
      subs = {
          k: random_tensor(OrderedDict(), d)
          for k, d in real_inputs.items()
      }
      expected = x(**subs)
      assert isinstance(expected, Tensor)
  
      actual = const + sum(
          Einsum(eqn, coeff, subs[k])
          for k, (coeff, eqn) in coeffs.items()
      )
      assert isinstance(actual, Tensor)
      assert_close(actual, expected)
  
file_path: funsor/test/test_affine.py
imports: from collections import OrderedDict
  import pytest
  from funsor.affine import extract_affine, is_affine
  from funsor.cnf import Contraction
  from funsor.domains import Bint, Real, Reals
  from funsor.tensor import Einsum, Tensor
  from funsor.terms import Finitary, Number, Unary, Variable
  from funsor.testing import assert_close, check_funsor, ones, randn, random_gaussian, random_tensor
label_desc: Use image node_id 3 for calling a global function with example usage: test_extract_affine(expr) without return types