code: def slice_batch(g, gid, store_ids=False):
      """Get a particular graph from a batch of graphs.
  
      Parameters
      ----------
      g : DGLGraph
          Input batched graph.
      gid : int
          The ID of the graph to retrieve.
      store_ids : bool
          If True, it will store the raw IDs of the extracted nodes and edges in the ``ndata`` and
          ``edata`` of the resulting graph under name ``dgl.NID`` and ``dgl.EID``, respectively.
  
      Returns
      -------
      DGLGraph
          Retrieved graph.
  
      Examples
      --------
  
      The following example uses PyTorch backend.
  
      >>> import dgl
      >>> import torch
  
      Create a batched graph.
  
      >>> g1 = dgl.graph(([0, 1], [2, 3]))
      >>> g2 = dgl.graph(([1], [2]))
      >>> bg = dgl.batch([g1, g2])
  
      Get the second component graph.
  
      >>> g = dgl.slice_batch(bg, 1)
      >>> print(g)
      Graph(num_nodes=3, num_edges=1,
            ndata_schemes={}
            edata_schemes={})
      """
      start_nid = []
      num_nodes = []
      for ntype in g.ntypes:
          batch_num_nodes = g.batch_num_nodes(ntype)
          num_nodes.append(F.as_scalar(batch_num_nodes[gid]))
          if gid == 0:
              start_nid.append(0)
          else:
              start_nid.append(
                  F.as_scalar(
                      F.sum(F.slice_axis(batch_num_nodes, 0, 0, gid), 0)
                  )
              )
  
      start_eid = []
      num_edges = []
      for etype in g.canonical_etypes:
          batch_num_edges = g.batch_num_edges(etype)
          num_edges.append(F.as_scalar(batch_num_edges[gid]))
          if gid == 0:
              start_eid.append(0)
          else:
              start_eid.append(
                  F.as_scalar(
                      F.sum(F.slice_axis(batch_num_edges, 0, 0, gid), 0)
                  )
              )
  
      # Slice graph structure
      gidx = slice_gidx(
          g._graph,
          utils.toindex(num_nodes),
          utils.toindex(start_nid),
          utils.toindex(num_edges),
          utils.toindex(start_eid),
      )
      retg = DGLGraph(gidx, g.ntypes, g.etypes)
  
      # Slice node features
      for ntid, ntype in enumerate(g.ntypes):
          stnid = start_nid[ntid]
          for key, feat in g.nodes[ntype].data.items():
              subfeats = F.slice_axis(
                  feat, 0, stnid, stnid + num_nodes[ntid]
              )
              retg.nodes[ntype].data[key] = subfeats
  
          if store_ids:
              retg.nodes[ntype].data[NID] = F.arange(
                  stnid,
                  stnid + num_nodes[ntid],
                  retg.idtype,
                  retg.device,
              )
  
      # Slice edge features
      for etid, etype in enumerate(g.canonical_etypes):
          steid = start_eid[etid]
          for key, feat in g.edges[etype].data.items():
              subfeats = F.slice_axis(
                  feat, 0, steid, steid + num_edges[etid]
              )
              retg.edges[etype].data[key] = subfeats
  
          if store_ids:
              retg.edges[etype].data[EID] = F.arange(
                  steid,
                  steid + num_edges[etid],
                  retg.idtype,
                  retg.device,
              )
  
      return retg
  
file_path: dgl/python/dgl/batch.py
imports: from collections.abc import Mapping
  from .None import backend, convert, utils
  from .base import ALL, DGLError, EID, is_all, NID
  from .heterograph import DGLGraph
  from .heterograph_index import disjoint_union, slice_gidx
label_desc: Use image node_id 4 for calling a global function with example usage: slice_batch(g, gid, store_ids) and returns: retg