class_docstr: Single piece of global state to keep track of the mapping between names and dimensions.
  
  Replaces the plate :class:`~pyro.poutine.runtime._DimAllocator`,
  the enum :class:`~pyro.poutine.runtime._EnumAllocator`, the ``stack`` in :class:`~MarkovMessenger`,
  ``_param_dims`` and ``_value_dims`` in :class:`~EnumMessenger`, and ``dim_to_symbol`` in ``msg['infer']``
class_docstr_tok: ["Single","piece","of","global","state","to","keep","track","of","the","mapping","between","names","and","dimensions",".","Replaces","the","plate",":","class",":","`","~pyro.poutine.runtime._DimAllocator","`",",","the","enum",":","class",":","`","~pyro.poutine.runtime._EnumAllocator","`",",","the","``","stack","``","in",":","class",":","`","~MarkovMessenger","`",",","``","_param_dims","``","and","``","_value_dims","``","in",":","class",":","`","~EnumMessenger","`",",","and","``","dim_to_symbol","``","in","``","msg","[","'infer","'","]","``"]
docstr: Given proposed values for a fresh (name, dim) pair, computes a new, possibly
  identical (name, dim) pair consistent with the current name <--> dim mapping.
  This function is pure and does not update the name <--> dim mapping itself.
  
  The implementation here is only one of several possibilities, and was chosen
  to match the behavior of Pyro's old enumeration machinery as closely as possible.
docstr_tok: ["Given","proposed","values","for","a","fresh","(","name",",","dim",")","pair",",","computes","a","new",",","possibly","identical","(","name",",","dim",")","pair","consistent","with","the","current","name","<","--",">","dim","mapping",".","This","function","is","pure","and","does","not","update","the","name","<","--",">","dim","mapping","itself",".","The","implementation","here","is","only","one","of","several","possibilities",",","and","was","chosen","to","match","the","behavior","of","Pyro","'s","old","enumeration","machinery","as","closely","as","possible","."]
code: def _genvalue(self, key, value_request):
      """
      Given proposed values for a fresh (name, dim) pair, computes a new, possibly
      identical (name, dim) pair consistent with the current name <--> dim mapping.
      This function is pure and does not update the name <--> dim mapping itself.
  
      The implementation here is only one of several possibilities, and was chosen
      to match the behavior of Pyro's old enumeration machinery as closely as possible.
      """
      if isinstance(key, int):
          dim, name = key, value_request.value
          fresh_name = (
              "_pyro_dim_{}".format(-key) if name is None else name
          )
          return dim, fresh_name
  
      elif isinstance(key, str):
          name, dim, dim_type = (
              key,
              value_request.value,
              value_request.dim_type,
          )
          if dim_type == DimType.VISIBLE:
              fresh_dim = -1 if dim is None else dim
          else:
              fresh_dim = self._first_available_dim  # discard input...
  
          while any(fresh_dim in p for p in self.current_read_env):
              fresh_dim -= 1
  
          if fresh_dim < self.MAX_DIM or (
              dim_type == DimType.VISIBLE
              and fresh_dim <= self._first_available_dim
          ):
              raise ValueError(
                  "Ran out of free dims during allocation for {}".format(
                      name
                  )
              )
  
          return name, fresh_dim
      raise ValueError(
          "{} and {} not a valid name-dim pair".format(
              key, value_request
          )
      )
  
imports: from collections import Counter, OrderedDict, namedtuple
  from enum import Enum
label_desc: Use image node_id 13 for calling the DimStack obj's underlying member method code with example usage: obj._genvalue(key, value_request) and returns: dim,  fresh_name, name,  fresh_dim