nodes: 0, module; 1, function_definition; 2, function_name:get_subgraph; 3, parameters; 4, block; 5, identifier:self; 6, identifier:subvertices; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, return_statement; 11, identifier:normalize; 12, False; 13, comment:"""Constructs a subgraph of the current graph
  
             Arguments:
              | ``subvertices`` -- The vertices that should be retained.
              | ``normalize`` -- Whether or not the vertices should renumbered and
                   reduced to the given set of subvertices. When True, also the
                   edges are sorted. It the end, this means that new order of the
                   edges does not depend on the original order, but only on the
                   order of the argument subvertices.
                   This option is False by default. When False, only edges will be
                   discarded, but the retained data remain unchanged. Also the
                   parameter num_vertices is not affected.
  
             The returned graph will have an attribute ``old_edge_indexes`` that
             relates the positions of the new and the old edges as follows::
  
               >>> self.edges[result._old_edge_indexes[i]] = result.edges[i]
  
             In derived classes, the following should be supported::
  
               >>> self.edge_property[result._old_edge_indexes[i]] = result.edge_property[i]
  
             When ``normalize==True``, also the vertices are affected and the
             derived classes should make sure that the following works::
  
               >>> self.vertex_property[result._old_vertex_indexes[i]] = result.vertex_property[i]
  
             The attribute ``old_vertex_indexes`` is only constructed when
             ``normalize==True``.
          """; 14, identifier:normalize; 15, block; 16, else_clause; 17, identifier:result; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, for_statement; 22, comment:# sort the edges; 23, expression_statement; 24, comment:# argsort in pure python; 25, expression_statement; 26, expression_statement; 27, expression_statement; 28, expression_statement; 29, expression_statement; 30, comment:#result.new_vertex_indexes = revorder; 31, expression_statement; 32, block; 33, assignment; 34, assignment; 35, assignment; 36, pattern_list; 37, call; 38, block; 39, assignment; 40, call; 41, assignment; 42, assignment; 43, assignment; 44, assignment; 45, assignment; 46, expression_statement; 47, expression_statement; 48, expression_statement; 49, expression_statement; 50, expression_statement; 51, comment:# no need for old and new vertex_indexes because they remain the; 52, comment:# same.; 53, identifier:revorder; 54, call; 55, identifier:new_edges; 56, list; 57, identifier:old_edge_indexes; 58, list; 59, identifier:counter; 60, tuple_pattern; 61, identifier:enumerate; 62, argument_list; 63, expression_statement; 64, if_statement; 65, expression_statement; 66, if_statement; 67, expression_statement; 68, expression_statement; 69, identifier:order; 70, call; 71, attribute; 72, argument_list; 73, identifier:new_edges; 74, list_comprehension; 75, identifier:old_edge_indexes; 76, list_comprehension; 77, identifier:result; 78, call; 79, attribute; 80, call; 81, attribute; 82, call; 83, assignment; 84, assignment; 85, assignment; 86, assignment; 87, assignment; 88, identifier:dict; 89, generator_expression; 90, identifier:i; 91, identifier:j; 92, attribute; 93, assignment; 94, comparison_operator:new_i is None; 95, block; 96, assignment; 97, comparison_operator:new_j is None; 98, block; 99, call; 100, call; 101, identifier:list; 102, argument_list; 103, identifier:order; 104, identifier:sort; 105, keyword_argument; 106, subscript; 107, for_in_clause; 108, subscript; 109, for_in_clause; 110, identifier:Graph; 111, argument_list; 112, identifier:result; 113, identifier:_old_vertex_indexes; 114, attribute; 115, argument_list; 116, identifier:result; 117, identifier:_old_edge_indexes; 118, attribute; 119, argument_list; 120, identifier:subvertices; 121, call; 122, identifier:old_edge_indexes; 123, call; 124, identifier:new_edges; 125, call; 126, identifier:result; 127, call; 128, attribute; 129, identifier:old_edge_indexes; 130, tuple; 131, for_in_clause; 132, identifier:self; 133, identifier:edges; 134, identifier:new_i; 135, call; 136, identifier:new_i; 137, None; 138, continue_statement; 139, identifier:new_j; 140, call; 141, identifier:new_j; 142, None; 143, continue_statement; 144, attribute; 145, argument_list; 146, attribute; 147, argument_list; 148, call; 149, identifier:key; 150, parenthesized_expression; 151, identifier:new_edges; 152, identifier:i; 153, identifier:i; 154, identifier:order; 155, identifier:old_edge_indexes; 156, identifier:i; 157, identifier:i; 158, identifier:order; 159, identifier:new_edges; 160, keyword_argument; 161, identifier:np; 162, identifier:array; 163, identifier:subvertices; 164, keyword_argument; 165, identifier:np; 166, identifier:array; 167, identifier:old_edge_indexes; 168, keyword_argument; 169, identifier:set; 170, argument_list; 171, attribute; 172, argument_list; 173, identifier:tuple; 174, generator_expression; 175, identifier:Graph; 176, argument_list; 177, identifier:result; 178, identifier:_old_edge_indexes; 179, identifier:j; 180, identifier:i; 181, pattern_list; 182, call; 183, attribute; 184, argument_list; 185, attribute; 186, argument_list; 187, identifier:new_edges; 188, identifier:append; 189, tuple; 190, identifier:old_edge_indexes; 191, identifier:append; 192, identifier:counter; 193, identifier:range; 194, argument_list; 195, lambda; 196, identifier:num_vertices; 197, call; 198, identifier:dtype; 199, identifier:int; 200, identifier:dtype; 201, identifier:int; 202, identifier:subvertices; 203, identifier:np; 204, identifier:array; 205, list_comprehension; 206, keyword_argument; 207, subscript; 208, for_in_clause; 209, identifier:new_edges; 210, attribute; 211, identifier:i; 212, identifier:j; 213, identifier:enumerate; 214, argument_list; 215, identifier:revorder; 216, identifier:get; 217, identifier:i; 218, identifier:revorder; 219, identifier:get; 220, identifier:j; 221, identifier:new_i; 222, identifier:new_j; 223, call; 224, lambda_parameters; 225, call; 226, identifier:len; 227, argument_list; 228, identifier:i; 229, for_in_clause; 230, if_clause; 231, identifier:dtype; 232, identifier:int; 233, attribute; 234, identifier:i; 235, identifier:i; 236, identifier:old_edge_indexes; 237, identifier:self; 238, identifier:num_vertices; 239, identifier:subvertices; 240, identifier:len; 241, argument_list; 242, identifier:i; 243, identifier:tuple; 244, argument_list; 245, identifier:subvertices; 246, pattern_list; 247, call; 248, call; 249, identifier:self; 250, identifier:edges; 251, identifier:new_edges; 252, call; 253, identifier:i; 254, identifier:edge; 255, identifier:enumerate; 256, argument_list; 257, attribute; 258, argument_list; 259, identifier:sorted; 260, argument_list; 261, attribute; 262, identifier:edge; 263, identifier:issubset; 264, identifier:subvertices; 265, subscript; 266, identifier:self; 267, identifier:edges; 268, identifier:new_edges; 269, identifier:i
code: def get_subgraph(self, subvertices, normalize=False):
          """Constructs a subgraph of the current graph
  
             Arguments:
              | ``subvertices`` -- The vertices that should be retained.
              | ``normalize`` -- Whether or not the vertices should renumbered and
                   reduced to the given set of subvertices. When True, also the
                   edges are sorted. It the end, this means that new order of the
                   edges does not depend on the original order, but only on the
                   order of the argument subvertices.
                   This option is False by default. When False, only edges will be
                   discarded, but the retained data remain unchanged. Also the
                   parameter num_vertices is not affected.
  
             The returned graph will have an attribute ``old_edge_indexes`` that
             relates the positions of the new and the old edges as follows::
  
               >>> self.edges[result._old_edge_indexes[i]] = result.edges[i]
  
             In derived classes, the following should be supported::
  
               >>> self.edge_property[result._old_edge_indexes[i]] = result.edge_property[i]
  
             When ``normalize==True``, also the vertices are affected and the
             derived classes should make sure that the following works::
  
               >>> self.vertex_property[result._old_vertex_indexes[i]] = result.vertex_property[i]
  
             The attribute ``old_vertex_indexes`` is only constructed when
             ``normalize==True``.
          """
          if normalize:
              revorder = dict((j, i) for i, j in enumerate(subvertices))
              new_edges = []
              old_edge_indexes = []
              for counter, (i, j) in enumerate(self.edges):
                  new_i = revorder.get(i)
                  if new_i is None:
                      continue
                  new_j = revorder.get(j)
                  if new_j is None:
                      continue
                  new_edges.append((new_i, new_j))
                  old_edge_indexes.append(counter)
              # sort the edges
              order = list(range(len(new_edges)))
              # argsort in pure python
              order.sort( key=(lambda i: tuple(sorted(new_edges[i]))) )
              new_edges = [new_edges[i] for i in order]
              old_edge_indexes = [old_edge_indexes[i] for i in order]
  
              result = Graph(new_edges, num_vertices=len(subvertices))
              result._old_vertex_indexes = np.array(subvertices, dtype=int)
              #result.new_vertex_indexes = revorder
              result._old_edge_indexes = np.array(old_edge_indexes, dtype=int)
          else:
              subvertices = set(subvertices)
              old_edge_indexes = np.array([
                  i for i, edge in enumerate(self.edges)
                  if edge.issubset(subvertices)
              ], dtype=int)
              new_edges = tuple(self.edges[i] for i in old_edge_indexes)
              result = Graph(new_edges, self.num_vertices)
              result._old_edge_indexes = old_edge_indexes
              # no need for old and new vertex_indexes because they remain the
              # same.
          return result