code: def _test_sample_neighbors_topk(hypersparse):
      g, hg = _gen_neighbor_topk_test_graph(hypersparse, False)
  
      def _test1():
          subg = dgl.sampling.select_topk(g, -1, "weight", [0, 1])
          assert subg.num_nodes() == g.num_nodes()
          u, v = subg.edges()
          u_ans, v_ans = subg.in_edges([0, 1])
          uv = set(zip(F.asnumpy(u), F.asnumpy(v)))
          uv_ans = set(zip(F.asnumpy(u_ans), F.asnumpy(v_ans)))
          assert uv == uv_ans
  
          subg = dgl.sampling.select_topk(g, 2, "weight", [0, 1])
          assert subg.num_nodes() == g.num_nodes()
          assert subg.num_edges() == 4
          u, v = subg.edges()
          edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
          assert F.array_equal(g.edge_ids(u, v), subg.edata[dgl.EID])
          assert edge_set == {(2, 0), (1, 0), (2, 1), (3, 1)}
  
      _test1()
  
      def _test2():  # k > #neighbors
          subg = dgl.sampling.select_topk(g, -1, "weight", [0, 2])
          assert subg.num_nodes() == g.num_nodes()
          u, v = subg.edges()
          u_ans, v_ans = subg.in_edges([0, 2])
          uv = set(zip(F.asnumpy(u), F.asnumpy(v)))
          uv_ans = set(zip(F.asnumpy(u_ans), F.asnumpy(v_ans)))
          assert uv == uv_ans
  
          subg = dgl.sampling.select_topk(g, 2, "weight", [0, 2])
          assert subg.num_nodes() == g.num_nodes()
          assert subg.num_edges() == 3
          u, v = subg.edges()
          assert F.array_equal(g.edge_ids(u, v), subg.edata[dgl.EID])
          edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
          assert edge_set == {(2, 0), (1, 0), (0, 2)}
  
      _test2()
  
      def _test3():
          subg = dgl.sampling.select_topk(
              hg, 2, "weight", {"user": [0, 1], "game": 0}
          )
          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 F.array_equal(
              hg["follow"].edge_ids(u, v), subg["follow"].edata[dgl.EID]
          )
          assert edge_set == {(2, 0), (1, 0), (2, 1), (3, 1)}
          u, v = subg["play"].edges()
          edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
          assert F.array_equal(
              hg["play"].edge_ids(u, v), subg["play"].edata[dgl.EID]
          )
          assert edge_set == {(0, 0)}
          u, v = subg["liked-by"].edges()
          edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
          assert F.array_equal(
              hg["liked-by"].edge_ids(u, v),
              subg["liked-by"].edata[dgl.EID],
          )
          assert edge_set == {(2, 0), (2, 1), (1, 0)}
          assert subg["flips"].num_edges() == 0
  
      _test3()
  
      # test different k for different relations
      subg = dgl.sampling.select_topk(
          hg,
          {"follow": 1, "play": 2, "liked-by": 0, "flips": -1},
          "weight",
          {"user": [0, 1], "game": 0, "coin": 0},
      )
      assert len(subg.ntypes) == 3
      assert len(subg.etypes) == 4
      assert subg["follow"].num_edges() == 2
      assert subg["play"].num_edges() == 1
      assert subg["liked-by"].num_edges() == 0
      assert subg["flips"].num_edges() == 4
  
imports: import unittest
  import warnings
  import backend
  import dgl
  import numpy
  import pytest
label_desc: Use image node_id 12 for calling a global function with example usage: _test_sample_neighbors_topk(hypersparse) without return types