class_docstr: Implementation of graph structure in pgl.
  
  This is a simple implementation of graph structure in pgl.
  
  Args:
      num_nodes: number of nodes in a graph
      edges: list of (u, v) tuples
      node_feat (optional): a dict of numpy array as node features
      edge_feat (optional): a dict of numpy array as edge features (should
                              have consistent order with edges)
  
  Examples:
  
      .. code-block:: python
  
          import numpy as np
          num_nodes = 5
          edges = [ (0, 1), (1, 2), (3, 4)]
          feature = np.random.randn(5, 100)
          edge_feature = np.random.randn(3, 100)
          graph = Graph(num_nodes=num_nodes,
                      edges=edges,
                      node_feat={
                          "feature": feature
                      },
                      edge_feat={
                          "edge_feature": edge_feature
                      })
class_docstr_tok: ["Implementation","of","graph","structure","in","pgl",".","This","is","a","simple","implementation","of","graph","structure","in","pgl",".","Args",":","num_nodes",":","number","of","nodes","in","a","graph","edges",":","list","of","(","u",",","v",")","tuples","node_feat","(","optional",")",":","a","dict","of","numpy","array","as","node","features","edge_feat","(","optional",")",":","a","dict","of","numpy","array","as","edge","features","(","should","have","consistent","order","with","edges",")","Examples",":","..","code-block",":",":","python","import","numpy","as","np","num_nodes","=","5","edges","=","[","(","0",",","1",")",",","(","1",",","2",")",",","(","3",",","4",")","]","feature","=","np.random.randn","(","5",",","100",")","edge_feature","=","np.random.randn","(","3",",","100",")","graph","=","Graph","(","num_nodes=num_nodes",",","edges=edges",",","node_feat=","{","``","feature","''",":","feature","}",",","edge_feat=","{","``","edge_feature","''",":","edge_feature","}",")"]
docstr: Generate subgraph with nodes and edge ids.
  
  This function will generate a :code:`pgl.graph.Subgraph` object and
  copy all corresponding node and edge features. Nodes and edges will
  be reindex from 0. Eid and edges can't both be None.
  
  WARNING: ALL NODES IN EID MUST BE INCLUDED BY NODES
  
  Args:
      nodes: Node ids which will be included in the subgraph.
  
      eid (optional): Edge ids which will be included in the subgraph.
  
      edges (optional): Edge(src, dst) list which will be included in the subgraph.
  
      with_node_feat: Whether to inherit node features from parent graph.
  
      with_edge_feat: Whether to inherit edge features from parent graph.
  
  Return:
      A :code:`pgl.graph.Subgraph` object.
code: def subgraph(
      self,
      nodes,
      eid=None,
      edges=None,
      edge_feats=None,
      with_node_feat=True,
      with_edge_feat=True,
  ):
      """Generate subgraph with nodes and edge ids.
  
      This function will generate a :code:`pgl.graph.Subgraph` object and
      copy all corresponding node and edge features. Nodes and edges will
      be reindex from 0. Eid and edges can't both be None.
  
      WARNING: ALL NODES IN EID MUST BE INCLUDED BY NODES
  
      Args:
          nodes: Node ids which will be included in the subgraph.
  
          eid (optional): Edge ids which will be included in the subgraph.
  
          edges (optional): Edge(src, dst) list which will be included in the subgraph.
  
          with_node_feat: Whether to inherit node features from parent graph.
  
          with_edge_feat: Whether to inherit edge features from parent graph.
  
      Return:
          A :code:`pgl.graph.Subgraph` object.
      """
      reindex = {}
  
      for ind, node in enumerate(nodes):
          reindex[node] = ind
  
      if eid is None and edges is None:
          raise ValueError(
              "Eid and edges can't be None at the same time."
          )
  
      sub_edge_feat = {}
      if edges is None:
          edges = self._edges[eid]
      else:
          edges = np.array(edges, dtype="int64")
  
      if with_edge_feat:
          for key, value in self._edge_feat.items():
              if eid is None:
                  raise ValueError(
                      "Eid can not be None with edge features."
                  )
              sub_edge_feat[key] = value[eid]
  
      if edge_feats is not None:
          sub_edge_feat.update(edge_feats)
  
      sub_edges = graph_kernel.map_edges(
          np.arange(len(edges), dtype="int64"), edges, reindex
      )
  
      sub_node_feat = {}
      if with_node_feat:
          for key, value in self._node_feat.items():
              sub_node_feat[key] = value[nodes]
  
      subgraph = SubGraph(
          num_nodes=len(nodes),
          edges=sub_edges,
          node_feat=sub_node_feat,
          edge_feat=sub_edge_feat,
          reindex=reindex,
      )
      return subgraph
  
imports: import os
  import numpy
  import pickle
  import time
  import pgl.graph_kernel
  from collections import defaultdict
label_desc: Use image node_id 20 for calling the Graph obj's underlying member method code with example usage: obj.subgraph(nodes, eid, edges, edge_feats, with_node_feat, with_edge_feat) and returns: subgraph