code: def ordering(signatures):
      """A sane ordering of signatures to check, first to last
      Topological sort of edges as given by ``edge`` and ``supercedes``
      """
      signatures = list(map(tuple, signatures))
      edges = [
          (a, b) for a in signatures for b in signatures if edge(a, b)
      ]
      edges = groupby(first, edges)
      for s in signatures:
          if s not in edges:
              edges[s] = []
      edges = {k: [b for a, b in v] for k, v in edges.items()}  # type: ignore[attr-defined, assignment]
      return _toposort(edges)
  
file_path: pytorch/torch/fx/experimental/unification/match.py
imports: from .core import unify, reify
  from .variable import isvar
  from .utils import _toposort, freeze
  from .unification_tools import groupby, first
label_desc: Use image node_id 4 for calling a global function with example usage: ordering(signatures) and returns: _toposort