code: def add_self_loops(graph, copy_node_feat=True, copy_edge_feat=False):
      """Add self-loops to the given graph.
  
      Args:
  
          graph (pgl.Graph): The input graph, should be in numpy format.
  
          copy_node_feat (bool): Whether to copy node feature in return graph. Default: True.
  
          copy_edge_feat (bool): [Alternate input] Whether to copy edge feature in return graph.
  
      Returns:
  
          g (pgl.Graph): Returns a graph with self-loops.
  
      """
  
      if graph.is_tensor():
          raise TypeError("The input graph should be numpy format.")
  
      self_loop_edges = np.zeros((graph.num_nodes, 2))
      self_loop_edges[:, 0] = self_loop_edges[:, 1] = np.arange(
          graph.num_nodes
      )
      edges = np.vstack((graph.edges, self_loop_edges))
      g = pgl.graph.Graph(num_nodes=graph.num_nodes, edges=edges)
  
      if copy_node_feat:
          for k, v in graph._node_feat.items():
              g._node_feat[k] = v
  
      if copy_edge_feat:
          # TODO(daisiming): Generate edge_feature of self-loops.
          raise NotImplementedError(
              "The copy of edge feature is not implemented currently."
          )
  
      return g
  
file_path: PGL/pgl/utils/transform.py
imports: import numpy
  import pgl
  import paddle
  from pgl.math import segment_sum
  from pgl.utils.helper import maybe_num_nodes
label_desc: Use image node_id 2 for calling a global function with example usage: add_self_loops(graph, copy_node_feat, copy_edge_feat) and returns: g