code: def _enum_strategy_diagonal(dist, msg):
      sample_dim_name = "{}__PARTICLES".format(msg["name"])
      sample_inputs = OrderedDict(
          {sample_dim_name: funsor.Bint[msg["infer"]["num_samples"]]}
      )
      plate_names = frozenset(
          f.name for f in msg["cond_indep_stack"] if f.vectorized
      )
      ancestor_names = frozenset(
          k
          for k, v in dist.inputs.items()
          if v.dtype != "real"
          and k != msg["name"]
          and k not in plate_names
      )
      # TODO should the ancestor_indices be pyro.observed?
      ancestor_indices = {
          name: sample_dim_name for name in ancestor_names
      }
      denom = (
          sum([math.log(v.size) for v in sample_inputs.values()], 0)
          if not ancestor_indices
          else math.log(msg["infer"]["num_samples"])
      )
      sampled_dist = dist(**ancestor_indices).sample(
          msg["name"], sample_inputs if not ancestor_indices else None
      )
      sampled_dist -= denom
      return sampled_dist
  
imports: import functools
  import math
  from collections import OrderedDict
  import funsor
  import torch
  import pyro.poutine.runtime
  import pyro.poutine.util
  from pyro.contrib.funsor.handlers.named_messenger import NamedMessenger
  from pyro.contrib.funsor.handlers.primitives import to_data, to_funsor
  from pyro.contrib.funsor.handlers.replay_messenger import ReplayMessenger
  from pyro.contrib.funsor.handlers.trace_messenger import TraceMessenger
  from pyro.poutine.escape_messenger import EscapeMessenger
  from pyro.poutine.subsample_messenger import _Subsample
label_desc: Use image node_id 7 for calling a global function with example usage: _enum_strategy_diagonal(dist, msg) and returns: sampled_dist