nodes: 0, module; 1, function_definition; 2, function_name:sorted_dependencies; 3, parameters; 4, block; 5, identifier:dist; 6, default_parameter; 7, expression_statement; 8, import_from_statement; 9, expression_statement; 10, comment:# create DAG as list of nodes and edges:; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, while_statement; 15, comment:# temporary stores used by depth first algorith.; 16, expression_statement; 17, expression_statement; 18, function_definition; 19, comment:# kickstart algorithm.; 20, while_statement; 21, if_statement; 22, return_statement; 23, identifier:reverse; 24, False; 25, comment:"""
      Extract all underlying dependencies from a distribution sorted
      topologically.
  
      Uses depth-first algorithm. See more here:
  
      Args:
          dist (Dist):
              Distribution to extract dependencies from.
          reverse (bool):
              If True, place dependencies in reverse order.
  
      Returns:
          dependencies (List[Dist]):
              All distribution that ``dist`` is dependent on, sorted
              topologically, including itself.
  
      Examples:
          >>> dist1 = chaospy.Uniform()
          >>> dist2 = chaospy.Normal(dist1)
          >>> print(sorted_dependencies(dist1))
          [Uniform(lower=0, upper=1), Mul(uniform(), 0.5), uniform()]
          >>> print(sorted_dependencies(dist2)) # doctest: +NORMALIZE_WHITESPACE
          [Normal(mu=Uniform(lower=0, upper=1), sigma=1),
           Uniform(lower=0, upper=1),
           Mul(uniform(), 0.5),
           uniform(),
           Mul(normal(), 1),
           normal()]
          >>> dist1 in sorted_dependencies(dist2)
          True
          >>> dist2 in sorted_dependencies(dist1)
          False
  
      Raises:
          DependencyError:
              If the dependency DAG is cyclic, dependency resolution is not
              possible.
  
      See also:
          Depth-first algorithm section:
          https://en.wikipedia.org/wiki/Topological_sorting
      """; 26, relative_import; 27, dotted_name; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, identifier:pool; 33, block; 34, assignment; 35, assignment; 36, function_name:visit; 37, parameters; 38, block; 39, identifier:nodes; 40, block; 41, not_operator; 42, block; 43, identifier:pool; 44, import_prefix; 45, identifier:baseclass; 46, identifier:collection; 47, list; 48, identifier:nodes; 49, list; 50, identifier:edges; 51, list; 52, identifier:pool; 53, list; 54, expression_statement; 55, for_statement; 56, identifier:permanent_marks; 57, call; 58, identifier:temporary_marks; 59, call; 60, identifier:node; 61, expression_statement; 62, if_statement; 63, if_statement; 64, expression_statement; 65, expression_statement; 66, for_statement; 67, expression_statement; 68, expression_statement; 69, expression_statement; 70, expression_statement; 71, expression_statement; 72, identifier:reverse; 73, expression_statement; 74, identifier:dist; 75, identifier:dist; 76, identifier:dist; 77, assignment; 78, identifier:key; 79, call; 80, block; 81, identifier:set; 82, argument_list; 83, identifier:set; 84, argument_list; 85, comment:"""Depth-first topological sort algorithm."""; 86, comparison_operator:node in permanent_marks; 87, block; 88, comparison_operator:node in temporary_marks; 89, block; 90, call; 91, call; 92, pattern_list; 93, identifier:edges; 94, block; 95, call; 96, call; 97, call; 98, assignment; 99, call; 100, assignment; 101, identifier:dist; 102, call; 103, identifier:sorted; 104, argument_list; 105, expression_statement; 106, if_statement; 107, if_statement; 108, if_statement; 109, identifier:node; 110, identifier:permanent_marks; 111, return_statement; 112, identifier:node; 113, identifier:temporary_marks; 114, raise_statement; 115, attribute; 116, argument_list; 117, attribute; 118, argument_list; 119, identifier:node1; 120, identifier:node2; 121, if_statement; 122, attribute; 123, argument_list; 124, attribute; 125, argument_list; 126, attribute; 127, argument_list; 128, identifier:node; 129, subscript; 130, identifier:visit; 131, argument_list; 132, identifier:pool; 133, call; 134, attribute; 135, argument_list; 136, attribute; 137, assignment; 138, not_operator; 139, block; 140, comparison_operator:(dist, value) not in edges; 141, block; 142, comparison_operator:value not in nodes; 143, block; 144, call; 145, identifier:nodes; 146, identifier:remove; 147, identifier:node; 148, identifier:temporary_marks; 149, identifier:add; 150, identifier:node; 151, comparison_operator:node1 is node; 152, block; 153, identifier:temporary_marks; 154, identifier:remove; 155, identifier:node; 156, identifier:permanent_marks; 157, identifier:add; 158, identifier:node; 159, identifier:pool; 160, identifier:append; 161, identifier:node; 162, identifier:nodes; 163, integer:0; 164, identifier:node; 165, identifier:list; 166, argument_list; 167, identifier:pool; 168, identifier:pop; 169, identifier:dist; 170, identifier:prm; 171, identifier:value; 172, subscript; 173, call; 174, continue_statement; 175, tuple; 176, identifier:edges; 177, expression_statement; 178, identifier:value; 179, identifier:nodes; 180, expression_statement; 181, expression_statement; 182, identifier:DependencyError; 183, argument_list; 184, identifier:node1; 185, identifier:node; 186, expression_statement; 187, call; 188, attribute; 189, identifier:key; 190, identifier:isinstance; 191, argument_list; 192, identifier:dist; 193, identifier:value; 194, call; 195, call; 196, call; 197, string:"cycles in dependency structure."; 198, call; 199, identifier:reversed; 200, argument_list; 201, identifier:dist; 202, identifier:prm; 203, identifier:value; 204, attribute; 205, attribute; 206, argument_list; 207, attribute; 208, argument_list; 209, attribute; 210, argument_list; 211, identifier:visit; 212, argument_list; 213, identifier:pool; 214, identifier:baseclass; 215, identifier:Dist; 216, identifier:edges; 217, identifier:append; 218, tuple; 219, identifier:nodes; 220, identifier:append; 221, identifier:value; 222, identifier:pool; 223, identifier:append; 224, identifier:value; 225, identifier:node2; 226, identifier:dist; 227, identifier:value
code: def sorted_dependencies(dist, reverse=False):
      """
      Extract all underlying dependencies from a distribution sorted
      topologically.
  
      Uses depth-first algorithm. See more here:
  
      Args:
          dist (Dist):
              Distribution to extract dependencies from.
          reverse (bool):
              If True, place dependencies in reverse order.
  
      Returns:
          dependencies (List[Dist]):
              All distribution that ``dist`` is dependent on, sorted
              topologically, including itself.
  
      Examples:
          >>> dist1 = chaospy.Uniform()
          >>> dist2 = chaospy.Normal(dist1)
          >>> print(sorted_dependencies(dist1))
          [Uniform(lower=0, upper=1), Mul(uniform(), 0.5), uniform()]
          >>> print(sorted_dependencies(dist2)) # doctest: +NORMALIZE_WHITESPACE
          [Normal(mu=Uniform(lower=0, upper=1), sigma=1),
           Uniform(lower=0, upper=1),
           Mul(uniform(), 0.5),
           uniform(),
           Mul(normal(), 1),
           normal()]
          >>> dist1 in sorted_dependencies(dist2)
          True
          >>> dist2 in sorted_dependencies(dist1)
          False
  
      Raises:
          DependencyError:
              If the dependency DAG is cyclic, dependency resolution is not
              possible.
  
      See also:
          Depth-first algorithm section:
          https://en.wikipedia.org/wiki/Topological_sorting
      """
      from .. import baseclass
  
      collection = [dist]
  
      # create DAG as list of nodes and edges:
      nodes = [dist]
      edges = []
      pool = [dist]
      while pool:
          dist = pool.pop()
          for key in sorted(dist.prm):
              value = dist.prm[key]
              if not isinstance(value, baseclass.Dist):
                  continue
              if (dist, value) not in edges:
                  edges.append((dist, value))
              if value not in nodes:
                  nodes.append(value)
                  pool.append(value)
  
      # temporary stores used by depth first algorith.
      permanent_marks = set()
      temporary_marks = set()
  
      def visit(node):
          """Depth-first topological sort algorithm."""
          if node in permanent_marks:
              return
          if node in temporary_marks:
              raise DependencyError("cycles in dependency structure.")
  
          nodes.remove(node)
          temporary_marks.add(node)
  
          for node1, node2 in edges:
              if node1 is node:
                  visit(node2)
  
          temporary_marks.remove(node)
          permanent_marks.add(node)
          pool.append(node)
  
      # kickstart algorithm.
      while nodes:
          node = nodes[0]
          visit(node)
  
      if not reverse:
          pool = list(reversed(pool))
  
      return pool