code: def test_generic_sample(case, sample_shape):
      raw_dist = case.get_dist()
  
      dim_to_name, name_to_dim = _default_dim_to_name(
          sample_shape + raw_dist.batch_shape
      )
      with eager_no_dists:
          with xfail_if_not_implemented(match="try upgrading backend"):
              funsor_dist = to_funsor(
                  raw_dist, output=funsor.Real, dim_to_name=dim_to_name
              )
  
      sample_inputs = OrderedDict(
          (
              dim_to_name[dim - len(raw_dist.batch_shape)],
              funsor.Bint[sample_shape[dim]],
          )
          for dim in range(-len(sample_shape), 0)
      )
      rng_key = (
          None
          if get_backend() == "torch"
          else np.array([0, 0], dtype=np.uint32)
      )
      sample_value = funsor_dist.sample(
          frozenset(["value"]), sample_inputs, rng_key=rng_key
      )
      expected_inputs = OrderedDict(
          tuple(sample_inputs.items())
          + tuple(funsor_dist.inputs.items())
      )
      # TODO compare sample values on jax backend
      check_funsor(sample_value, expected_inputs, funsor.Real)
  
imports: import re
  from collections import OrderedDict, namedtuple
  from importlib import import_module
  import numpy
  import pytest
  import funsor
  import funsor.ops
  from funsor.distribution import BACKEND_TO_DISTRIBUTIONS_BACKEND
  from funsor.interpretations import CallableInterpretation, eager, lazy, normalize, reflect
  from funsor.terms import to_data, to_funsor
  from funsor.testing import assert_close, check_funsor, excludes_backend, rand, randint, randn, random_scale_tril, xfail_if_not_found, xfail_if_not_implemented, xfail_param
  from funsor.util import get_backend
label_desc: Use image node_id 6 for calling a global function with example usage: test_generic_sample(case, sample_shape) without return types