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
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={})
    
python/dgl/batch.py