class_docstr: Batch GraphData class
  
  Attributes
  ----------
  node_features: np.ndarray
      Concatenated node feature matrix with shape [num_nodes, num_node_features].
      `num_nodes` is total number of nodes in the batch graph.
  edge_index: np.ndarray, dtype int
      Concatenated graph connectivity in COO format with shape [2, num_edges].
      `num_edges` is total number of edges in the batch graph.
  edge_features: np.ndarray, optional (default None)
      Concatenated edge feature matrix with shape [num_edges, num_edge_features].
      `num_edges` is total number of edges in the batch graph.
  node_pos_features: np.ndarray, optional (default None)
      Concatenated node position matrix with shape [num_nodes, num_dimensions].
      `num_nodes` is total number of edges in the batch graph.
  num_nodes: int
      The number of nodes in the batch graph.
  num_node_features: int
      The number of features per node in the graph.
  num_edges: int
      The number of edges in the batch graph.
  num_edges_features: int, optional (default None)
      The number of features per edge in the graph.
  graph_index: np.ndarray, dtype int
      This vector indicates which graph the node belongs with shape [num_nodes,].
  
  Examples
  --------
  >>> import numpy as np
  >>> from deepchem.feat.graph_data import GraphData
  >>> node_features_list = np.random.rand(2, 5, 10)
  >>> edge_index_list = np.array([
  ...    [[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]],
  ...    [[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]],
  ... ], dtype=int)
  >>> user_defined_attribute = np.array([0, 1])
  >>> graph_list = [GraphData(node_features, edge_index, attribute=user_defined_attribute)
  ...     for node_features, edge_index in zip(node_features_list, edge_index_list)]
  >>> batch_graph = BatchGraphData(graph_list=graph_list)
class_docstr_tok: ["Batch","GraphData","class","Attributes","--","--","--","--","--","node_features",":","np.ndarray","Concatenated","node","feature","matrix","with","shape","[","num_nodes",",","num_node_features","]",".","`","num_nodes","`","is","total","number","of","nodes","in","the","batch","graph",".","edge_index",":","np.ndarray",",","dtype","int","Concatenated","graph","connectivity","in","COO","format","with","shape","[","2",",","num_edges","]",".","`","num_edges","`","is","total","number","of","edges","in","the","batch","graph",".","edge_features",":","np.ndarray",",","optional","(","default","None",")","Concatenated","edge","feature","matrix","with","shape","[","num_edges",",","num_edge_features","]",".","`","num_edges","`","is","total","number","of","edges","in","the","batch","graph",".","node_pos_features",":","np.ndarray",",","optional","(","default","None",")","Concatenated","node","position","matrix","with","shape","[","num_nodes",",","num_dimensions","]",".","`","num_nodes","`","is","total","number","of","edges","in","the","batch","graph",".","num_nodes",":","int","The","number","of","nodes","in","the","batch","graph",".","num_node_features",":","int","The","number","of","features","per","node","in","the","graph",".","num_edges",":","int","The","number","of","edges","in","the","batch","graph",".","num_edges_features",":","int",",","optional","(","default","None",")","The","number","of","features","per","edge","in","the","graph",".","graph_index",":","np.ndarray",",","dtype","int","This","vector","indicates","which","graph","the","node","belongs","with","shape","[","num_nodes",",","]",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","deepchem.feat.graph_data","import","GraphData",">",">",">","node_features_list","=","np.random.rand","(","2",",","5",",","10",")",">",">",">","edge_index_list","=","np.array","(","[","...","[","[","0",",","1",",","2",",","3",",","4","]",",","[","1",",","2",",","3",",","4",",","0","]","]",",","...","[","[","0",",","1",",","2",",","3",",","4","]",",","[","1",",","2",",","3",",","4",",","0","]","]",",","...","]",",","dtype=int",")",">",">",">","user_defined_attribute","=","np.array","(","[","0",",","1","]",")",">",">",">","graph_list","=","[","GraphData","(","node_features",",","edge_index",",","attribute=user_defined_attribute",")","...","for","node_features",",","edge_index","in","zip","(","node_features_list",",","edge_index_list",")","]",">",">",">","batch_graph","=","BatchGraphData","(","graph_list=graph_list",")"]
docstr: Parameters
  ----------
  graph_list: Sequence[GraphData]
      List of GraphData
docstr_tok: ["Parameters","--","--","--","--","--","graph_list",":","Sequence","[","GraphData","]","List","of","GraphData"]
code: def __init__(self, graph_list: Sequence[GraphData]):
      """
      Parameters
      ----------
      graph_list: Sequence[GraphData]
          List of GraphData
      """
      # stack features
      batch_node_features = np.vstack(
          [graph.node_features for graph in graph_list]
      )
  
      # before stacking edge_features or node_pos_features,
      # we should check whether these are None or not
      if graph_list[0].edge_features is not None:
          batch_edge_features: Optional[np.ndarray] = np.vstack(
              [graph.edge_features for graph in graph_list]
          )  # type: ignore
      else:
          batch_edge_features = None
  
      if graph_list[0].node_pos_features is not None:
          batch_node_pos_features: Optional[np.ndarray] = np.vstack(
              [
                  graph.node_pos_features for graph in graph_list  # type: ignore
              ]
          )
  
      else:
          batch_node_pos_features = None
  
      # create new edge index
      # number of nodes in each graph
      num_nodes_list = [graph.num_nodes for graph in graph_list]
      # cumulative number of nodes for each graph. This is necessary because the values in edge_index are node indices of all of the graphs in graph_list and so we need to offset the indices by the number of nodes in the previous graphs.
      cum_num_nodes_list = np.cumsum([0] + num_nodes_list)[:-1]
      # columns are the edge index, values are the node index
      batch_edge_index = np.hstack(
          [
              graph.edge_index + cum_num_nodes
              for cum_num_nodes, graph in zip(
                  cum_num_nodes_list, graph_list
              )
          ]
      )
  
      # graph_index indicates which nodes belong to which graph
      graph_index = []
      for i, num_nodes in enumerate(num_nodes_list):
          graph_index.extend([i] * num_nodes)
      self.graph_index = np.array(graph_index)
  
      # Batch user defined attributes
      kwargs = {}
      user_defined_attribute_names = self._get_user_defined_attributes(
          graph_list[0]
      )
      for name in user_defined_attribute_names:
          kwargs[name] = np.vstack(
              [getattr(graph, name) for graph in graph_list]
          )
  
      super().__init__(
          node_features=batch_node_features,
          edge_index=batch_edge_index,
          edge_features=batch_edge_features,
          node_pos_features=batch_node_pos_features,
          **kwargs,
      )
  
file_path: deepchem/deepchem/feat/graph_data.py
imports: from typing import Optional, Sequence
  import numpy
label_desc: Use image node_id 1 to create a new BatchGraphData object from inherited base classes: GraphData with example: obj = BatchGraphData(graph_list)