tensorflow_probability/python/distributions/joint_distribution_named.py
def _best_order(g):
  """Creates tuple of str tuple-str pairs representing resolved & sorted DAG."""
  def _explore(u):
    """Recursive function to ascend up through unvisited dependencies."""
    if u.depth < 0:
      return  # Already visited.
    if not u.parents:
      result.append((u.name, u.parents))
      u.depth = -1  # Mark visited.
      return
    b = (u.name, [])
    result.append(b)
    u.depth = -1  # Mark visited.
    d = 0
    for v in sorted((g.get(p) for p in u.parents), key=lambda v: v.depth):
      n0 = len(result)
      _explore(v)
      n1 = len(result)
      b[1].extend(['_']*d + [v.name])
      d = n1 - n0 - 1
  g = _depth(g)
  result = []
  for u in sorted(g.values(), key=lambda v: v.depth, reverse=True):
    _explore(u)
  return tuple(reversed(result))
def _best_order(g):
  """Creates tuple of str tuple-str pairs representing resolved & sorted DAG."""
  def _explore(u):
    """Recursive function to ascend up through unvisited dependencies."""
    if u.depth < 0:
      return  # Already visited.
    if not u.parents:
      result.append((u.name, u.parents))
      u.depth = -1  # Mark visited.
      return
    b = (u.name, [])
    result.append(b)
    u.depth = -1  # Mark visited.
    d = 0
    for v in sorted((g.get(p) for p in u.parents), key=lambda v: v.depth):
      n0 = len(result)
      _explore(v)
      n1 = len(result)
      b[1].extend(['_']*d + [v.name])
      d = n1 - n0 - 1
  g = _depth(g)
  result = []
  for u in sorted(g.values(), key=lambda v: v.depth, reverse=True):
    _explore(u)
  return tuple(reversed(result))
Creates tuple of str tuple-str pairs representing resolved & sorted DAG.