class_docstr: GraphData class
  
  This data class is almost same as `torch_geometric.data.Data
  <https://pytorch-geometric.readthedocs.io/en/latest/modules/data.html#torch_geometric.data.Data>`_.
  
  Attributes
  ----------
  node_features: np.ndarray
      Node feature matrix with shape [num_nodes, num_node_features]
  edge_index: np.ndarray, dtype int
      Graph connectivity in COO format with shape [2, num_edges]
  edge_features: np.ndarray, optional (default None)
      Edge feature matrix with shape [num_edges, num_edge_features]
  node_pos_features: np.ndarray, optional (default None)
      Node position matrix with shape [num_nodes, num_dimensions].
  num_nodes: int
      The number of nodes in the graph
  num_node_features: int
      The number of features per node in the graph
  num_edges: int
      The number of edges in the graph
  num_edges_features: int, optional (default None)
      The number of features per edge in the graph
  
  Examples
  --------
  >>> import numpy as np
  >>> node_features = np.random.rand(5, 10)
  >>> edge_index = np.array([[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]], dtype=np.int64)
  >>> edge_features = np.random.rand(5, 5)
  >>> global_features = np.random.random(5)
  >>> graph = GraphData(node_features, edge_index, edge_features, z=global_features)
  >>> graph
  GraphData(node_features=[5, 10], edge_index=[2, 5], edge_features=[5, 5], z=[5])
class_docstr_tok: ["GraphData","class","This","data","class","is","almost","same","as","`","torch_geometric.data.Data","<","https",":","\/\/pytorch-geometric.readthedocs.io\/en\/latest\/modules\/data.html","#","torch_geometric.data.Data",">","`","_",".","Attributes","--","--","--","--","--","node_features",":","np.ndarray","Node","feature","matrix","with","shape","[","num_nodes",",","num_node_features","]","edge_index",":","np.ndarray",",","dtype","int","Graph","connectivity","in","COO","format","with","shape","[","2",",","num_edges","]","edge_features",":","np.ndarray",",","optional","(","default","None",")","Edge","feature","matrix","with","shape","[","num_edges",",","num_edge_features","]","node_pos_features",":","np.ndarray",",","optional","(","default","None",")","Node","position","matrix","with","shape","[","num_nodes",",","num_dimensions","]",".","num_nodes",":","int","The","number","of","nodes","in","the","graph","num_node_features",":","int","The","number","of","features","per","node","in","the","graph","num_edges",":","int","The","number","of","edges","in","the","graph","num_edges_features",":","int",",","optional","(","default","None",")","The","number","of","features","per","edge","in","the","graph","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","node_features","=","np.random.rand","(","5",",","10",")",">",">",">","edge_index","=","np.array","(","[","[","0",",","1",",","2",",","3",",","4","]",",","[","1",",","2",",","3",",","4",",","0","]","]",",","dtype=np.int64",")",">",">",">","edge_features","=","np.random.rand","(","5",",","5",")",">",">",">","global_features","=","np.random.random","(","5",")",">",">",">","graph","=","GraphData","(","node_features",",","edge_index",",","edge_features",",","z=global_features",")",">",">",">","graph","GraphData","(","node_features=","[","5",",","10","]",",","edge_index=","[","2",",","5","]",",","edge_features=","[","5",",","5","]",",","z=","[","5","]",")"]
docstr: Convert numpy arrays to torch tensors. This may be useful when you are using PyTorch Geometric with GraphData objects.
  
  Parameters
  ----------
  device : str
      Device to store the tensors. Default to 'cpu'.
  
  Example
  -------
  >>> num_nodes, num_node_features = 5, 32
  >>> num_edges, num_edge_features = 6, 32
  >>> node_features = np.random.random_sample((num_nodes, num_node_features))
  >>> edge_features = np.random.random_sample((num_edges, num_edge_features))
  >>> edge_index = np.random.randint(0, num_nodes, (2, num_edges))
  >>> graph_data = GraphData(node_features, edge_index, edge_features)
  >>> graph_data = graph_data.numpy_to_torch()
  >>> print(type(graph_data.node_features))
  <class 'torch.Tensor'>
docstr_tok: ["Convert","numpy","arrays","to","torch","tensors",".","This","may","be","useful","when","you","are","using","PyTorch","Geometric","with","GraphData","objects",".","Parameters","--","--","--","--","--","device",":","str","Device","to","store","the","tensors",".","Default","to","'cpu","'",".","Example","--","--","--","-",">",">",">","num_nodes",",","num_node_features","=","5",",","32",">",">",">","num_edges",",","num_edge_features","=","6",",","32",">",">",">","node_features","=","np.random.random_sample","(","(","num_nodes",",","num_node_features",")",")",">",">",">","edge_features","=","np.random.random_sample","(","(","num_edges",",","num_edge_features",")",")",">",">",">","edge_index","=","np.random.randint","(","0",",","num_nodes",",","(","2",",","num_edges",")",")",">",">",">","graph_data","=","GraphData","(","node_features",",","edge_index",",","edge_features",")",">",">",">","graph_data","=","graph_data.numpy_to_torch","(",")",">",">",">","print","(","type","(","graph_data.node_features",")",")","<","class","'torch.Tensor","'",">"]
code: def numpy_to_torch(self, device: str = "cpu"):
      """Convert numpy arrays to torch tensors. This may be useful when you are using PyTorch Geometric with GraphData objects.
  
      Parameters
      ----------
      device : str
          Device to store the tensors. Default to 'cpu'.
  
      Example
      -------
      >>> num_nodes, num_node_features = 5, 32
      >>> num_edges, num_edge_features = 6, 32
      >>> node_features = np.random.random_sample((num_nodes, num_node_features))
      >>> edge_features = np.random.random_sample((num_edges, num_edge_features))
      >>> edge_index = np.random.randint(0, num_nodes, (2, num_edges))
      >>> graph_data = GraphData(node_features, edge_index, edge_features)
      >>> graph_data = graph_data.numpy_to_torch()
      >>> print(type(graph_data.node_features))
      <class 'torch.Tensor'>
      """
      import copy
  
      import torch
  
      graph_copy = copy.deepcopy(self)
  
      graph_copy.node_features = (
          torch.from_numpy(self.node_features)  # type: ignore
          .float()
          .to(device)
      )
      graph_copy.edge_index = (
          torch.from_numpy(self.edge_index)  # type: ignore
          .long()
          .to(device)
      )
      if self.edge_features is not None:
          graph_copy.edge_features = (
              torch.from_numpy(self.edge_features)  # type: ignore
              .float()
              .to(device)
          )
      else:
          graph_copy.edge_features = None
      if self.node_pos_features is not None:
          graph_copy.node_pos_features = (
              torch.from_numpy(self.node_pos_features)  # type: ignore
              .float()
              .to(device)
          )
      else:
          graph_copy.node_pos_features = None
  
      graph_copy.kwargs = {}
      for key, value in self.kwargs.items():
          if isinstance(value, np.ndarray):
              value = torch.from_numpy(value).to(device)
              graph_copy.kwargs[key] = value
              setattr(graph_copy, key, value)
  
      return graph_copy
  
file_path: deepchem/deepchem/feat/graph_data.py
imports: from typing import Optional, Sequence
  import numpy
label_desc: Use image node_id 5 for calling the GraphData obj's underlying member method code with example usage: obj.numpy_to_torch(device) and returns: graph_copy