code: def test_generic_stats(case, statistic):
      raw_dist = case.get_dist()
  
      dim_to_name, name_to_dim = _default_dim_to_name(
          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
              )
  
      with xfail_if_not_implemented(
          msg="entropy not implemented for some distributions"
      ), xfail_if_not_found(
          msg="stats not implemented yet for TransformedDist"
      ):
          actual_stat = getattr(funsor_dist, statistic)()
  
      with xfail_if_not_implemented():
          expected_stat_raw = getattr(raw_dist, statistic)
      if statistic == "entropy":
          expected_stat = to_funsor(
              expected_stat_raw(),
              output=funsor.Real,
              dim_to_name=dim_to_name,
          )
      else:
          expected_stat = to_funsor(
              expected_stat_raw,
              output=case.expected_value_domain,
              dim_to_name=dim_to_name,
          )
  
      check_funsor(
          actual_stat, expected_stat.inputs, expected_stat.output
      )
      if ops.isnan(expected_stat.data).all():
          pytest.xfail(reason="base stat returns nan")
      else:
          assert_close(
              to_data(actual_stat, name_to_dim),
              to_data(expected_stat, name_to_dim),
              rtol=1e-4,
          )
  
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 7 for calling a global function with example usage: test_generic_stats(case, statistic) without return types