code: def test_slice_batch(idtype):
      g1 = dgl.heterograph(
          {
              ("user", "follows", "user"): ([0, 1], [1, 2]),
              ("user", "plays", "game"): ([], []),
              ("user", "follows", "game"): ([0, 0], [1, 4]),
          },
          idtype=idtype,
          device=F.ctx(),
      )
      g2 = dgl.heterograph(
          {
              ("user", "follows", "user"): ([0, 1], [1, 2]),
              ("user", "plays", "game"): ([0, 1], [0, 0]),
              ("user", "follows", "game"): ([0, 1], [1, 4]),
          },
          num_nodes_dict={"user": 4, "game": 6},
          idtype=idtype,
          device=F.ctx(),
      )
      g3 = dgl.heterograph(
          {
              ("user", "follows", "user"): ([0], [2]),
              ("user", "plays", "game"): ([1, 2], [3, 4]),
              ("user", "follows", "game"): ([], []),
          },
          idtype=idtype,
          device=F.ctx(),
      )
      g_list = [g1, g2, g3]
      bg = dgl.batch(g_list)
      bg.nodes["user"].data["h1"] = F.randn((bg.num_nodes("user"), 2))
      bg.nodes["user"].data["h2"] = F.randn((bg.num_nodes("user"), 5))
      bg.edges[("user", "follows", "user")].data["h1"] = F.randn(
          (bg.num_edges(("user", "follows", "user")), 2)
      )
      for fmat in ["coo", "csr", "csc"]:
          bg = bg.formats(fmat)
          for i in range(len(g_list)):
              g_i = g_list[i]
              g_slice = dgl.slice_batch(bg, i)
              assert g_i.ntypes == g_slice.ntypes
              assert g_i.canonical_etypes == g_slice.canonical_etypes
              assert g_i.idtype == g_slice.idtype
              assert g_i.device == g_slice.device
              for nty in g_i.ntypes:
                  assert g_i.num_nodes(nty) == g_slice.num_nodes(nty)
                  for feat in g_i.nodes[nty].data:
                      assert F.allclose(
                          g_i.nodes[nty].data[feat],
                          g_slice.nodes[nty].data[feat],
                      )
  
              for ety in g_i.canonical_etypes:
                  assert g_i.num_edges(ety) == g_slice.num_edges(ety)
                  for feat in g_i.edges[ety].data:
                      assert F.allclose(
                          g_i.edges[ety].data[feat],
                          g_slice.edges[ety].data[feat],
                      )
  
file_path: dgl/tests/python/common/test_batch-heterograph.py
imports: import unittest
  import backend
  import dgl
  import pytest
  from dgl.base import ALL
  from utils import check_graph_equal, get_cases, parametrize_idtype
label_desc: Use image node_id 7 for calling a global function with example usage: test_slice_batch(idtype) without return types