code: def test_out_subgraph(idtype):
      hg = dgl.heterograph(
          {
              ("user", "follow", "user"): (
                  [1, 2, 3, 0, 2, 3, 0],
                  [0, 0, 0, 1, 1, 1, 2],
              ),
              ("user", "play", "game"): ([0, 0, 1, 3], [0, 1, 2, 2]),
              ("game", "liked-by", "user"): (
                  [2, 2, 2, 1, 1, 0],
                  [0, 1, 2, 0, 3, 0],
              ),
              ("user", "flips", "coin"): ([0, 1, 2, 3], [0, 0, 0, 0]),
          },
          idtype=idtype,
      ).to(F.ctx())
      subg = dgl.out_subgraph(hg, {"user": [0, 1], "game": 0})
      assert subg.idtype == idtype
      assert len(subg.ntypes) == 3
      assert len(subg.etypes) == 4
      u, v = subg["follow"].edges()
      edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
      assert edge_set == {(1, 0), (0, 1), (0, 2)}
      assert F.array_equal(
          hg["follow"].edge_ids(u, v), subg["follow"].edata[dgl.EID]
      )
      u, v = subg["play"].edges()
      edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
      assert edge_set == {(0, 0), (0, 1), (1, 2)}
      assert F.array_equal(
          hg["play"].edge_ids(u, v), subg["play"].edata[dgl.EID]
      )
      u, v = subg["liked-by"].edges()
      edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
      assert edge_set == {(0, 0)}
      assert F.array_equal(
          hg["liked-by"].edge_ids(u, v), subg["liked-by"].edata[dgl.EID]
      )
      u, v = subg["flips"].edges()
      edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
      assert edge_set == {(0, 0), (1, 0)}
      assert F.array_equal(
          hg["flips"].edge_ids(u, v), subg["flips"].edata[dgl.EID]
      )
      for ntype in subg.ntypes:
          assert dgl.NID not in subg.nodes[ntype].data
  
      # Test store_ids
      subg = dgl.out_subgraph(
          hg, {"user": [0, 1], "game": 0}, store_ids=False
      )
      for etype in subg.canonical_etypes:
          assert dgl.EID not in subg.edges[etype].data
      for ntype in subg.ntypes:
          assert dgl.NID not in subg.nodes[ntype].data
  
      # Test relabel nodes
      subg = dgl.out_subgraph(
          hg, {"user": [1], "game": 0}, relabel_nodes=True
      )
      assert subg.idtype == idtype
      assert len(subg.ntypes) == 3
      assert len(subg.etypes) == 4
  
      u, v = subg["follow"].edges()
      old_u = F.gather_row(subg.nodes["user"].data[dgl.NID], u)
      old_v = F.gather_row(subg.nodes["user"].data[dgl.NID], v)
      edge_set = set(
          zip(list(F.asnumpy(old_u)), list(F.asnumpy(old_v)))
      )
      assert edge_set == {(1, 0)}
      assert F.array_equal(
          hg["follow"].edge_ids(old_u, old_v),
          subg["follow"].edata[dgl.EID],
      )
  
      u, v = subg["play"].edges()
      old_u = F.gather_row(subg.nodes["user"].data[dgl.NID], u)
      old_v = F.gather_row(subg.nodes["game"].data[dgl.NID], v)
      edge_set = set(
          zip(list(F.asnumpy(old_u)), list(F.asnumpy(old_v)))
      )
      assert edge_set == {(1, 2)}
      assert F.array_equal(
          hg["play"].edge_ids(old_u, old_v), subg["play"].edata[dgl.EID]
      )
  
      u, v = subg["liked-by"].edges()
      old_u = F.gather_row(subg.nodes["game"].data[dgl.NID], u)
      old_v = F.gather_row(subg.nodes["user"].data[dgl.NID], v)
      edge_set = set(
          zip(list(F.asnumpy(old_u)), list(F.asnumpy(old_v)))
      )
      assert edge_set == {(0, 0)}
      assert F.array_equal(
          hg["liked-by"].edge_ids(old_u, old_v),
          subg["liked-by"].edata[dgl.EID],
      )
  
      u, v = subg["flips"].edges()
      old_u = F.gather_row(subg.nodes["user"].data[dgl.NID], u)
      old_v = F.gather_row(subg.nodes["coin"].data[dgl.NID], v)
      edge_set = set(
          zip(list(F.asnumpy(old_u)), list(F.asnumpy(old_v)))
      )
      assert edge_set == {(1, 0)}
      assert F.array_equal(
          hg["flips"].edge_ids(old_u, old_v),
          subg["flips"].edata[dgl.EID],
      )
      assert subg.num_nodes("user") == 2
      assert subg.num_nodes("game") == 2
      assert subg.num_nodes("coin") == 1
  
imports: import unittest
  import backend
  import dgl
  import networkx
  import numpy
  import pytest
  import scipy.sparse
  from utils import parametrize_idtype
label_desc: Use image node_id 10 for calling a global function with example usage: test_out_subgraph(idtype) without return types