code: def _test_sample_neighbors(hypersparse, prob, fused):
      g, hg = _gen_neighbor_sampling_test_graph(hypersparse, False)
  
      def _test1(p, replace):
          subg = sample_neighbors_fusing_mode[fused](
              g, [0, 1], -1, prob=p, replace=replace
          )
          if not fused:
              assert subg.num_nodes() == g.num_nodes()
          u, v = subg.edges()
          if fused:
              u, v = subg.srcdata[dgl.NID][u], subg.dstdata[dgl.NID][v]
          u_ans, v_ans, e_ans = g.in_edges([0, 1], form="all")
          if p is not None:
              emask = F.gather_row(g.edata[p], e_ans)
              if p == "prob":
                  emask = emask != 0
              u_ans = F.boolean_mask(u_ans, emask)
              v_ans = F.boolean_mask(v_ans, emask)
          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
  
          for i in range(10):
              subg = sample_neighbors_fusing_mode[fused](
                  g, [0, 1], 2, prob=p, replace=replace
              )
              if not fused:
                  assert subg.num_nodes() == g.num_nodes()
  
              assert subg.num_edges() == 4
              u, v = subg.edges()
              if fused:
                  u, v = (
                      subg.srcdata[dgl.NID][u],
                      subg.dstdata[dgl.NID][v],
                  )
  
              assert set(F.asnumpy(F.unique(v))) == {0, 1}
              assert F.array_equal(
                  F.astype(g.has_edges_between(u, v), F.int64),
                  F.ones((4,), dtype=F.int64),
              )
              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)))
              )
              if not replace:
                  # check no duplication
                  assert len(edge_set) == 4
              if p is not None:
                  assert not (3, 0) in edge_set
                  assert not (3, 1) in edge_set
  
      _test1(prob, True)  # w/ replacement, uniform
      _test1(prob, False)  # w/o replacement, uniform
  
      def _test2(p, replace):  # fanout > #neighbors
          subg = sample_neighbors_fusing_mode[fused](
              g, [0, 2], -1, prob=p, replace=replace
          )
          if not fused:
              assert subg.num_nodes() == g.num_nodes()
          u, v = subg.edges()
          if fused:
              u, v = subg.srcdata[dgl.NID][u], subg.dstdata[dgl.NID][v]
          u_ans, v_ans, e_ans = g.in_edges([0, 2], form="all")
          if p is not None:
              emask = F.gather_row(g.edata[p], e_ans)
              if p == "prob":
                  emask = emask != 0
              u_ans = F.boolean_mask(u_ans, emask)
              v_ans = F.boolean_mask(v_ans, emask)
          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
  
          for i in range(10):
              subg = sample_neighbors_fusing_mode[fused](
                  g, [0, 2], 2, prob=p, replace=replace
              )
              if not fused:
                  assert subg.num_nodes() == g.num_nodes()
              num_edges = 4 if replace else 3
              assert subg.num_edges() == num_edges
              u, v = subg.edges()
              if fused:
                  u, v = (
                      subg.srcdata[dgl.NID][u],
                      subg.dstdata[dgl.NID][v],
                  )
              assert set(F.asnumpy(F.unique(v))) == {0, 2}
              assert F.array_equal(
                  F.astype(g.has_edges_between(u, v), F.int64),
                  F.ones((num_edges,), dtype=F.int64),
              )
              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)))
              )
              if not replace:
                  # check no duplication
                  assert len(edge_set) == num_edges
              if p is not None:
                  assert not (3, 0) in edge_set
  
      _test2(prob, True)  # w/ replacement, uniform
      _test2(prob, False)  # w/o replacement, uniform
  
      def _test3(p, replace):
          subg = sample_neighbors_fusing_mode[fused](
              hg,
              {"user": [0, 1], "game": 0},
              -1,
              prob=p,
              replace=replace,
          )
          if not fused:
              assert len(subg.ntypes) == 3
          assert len(subg.srctypes) == 3
          assert len(subg.dsttypes) == 3
          assert len(subg.etypes) == 4
          assert subg["follow"].num_edges() == 6 if p is None else 4
          assert subg["play"].num_edges() == 1
          assert subg["liked-by"].num_edges() == 4
          assert subg["flips"].num_edges() == 0
  
          for i in range(10):
              subg = sample_neighbors_fusing_mode[fused](
                  hg,
                  {"user": [0, 1], "game": 0},
                  2,
                  prob=p,
                  replace=replace,
              )
              if not fused:
                  assert len(subg.ntypes) == 3
              assert len(subg.srctypes) == 3
              assert len(subg.dsttypes) == 3
              assert len(subg.etypes) == 4
              assert subg["follow"].num_edges() == 4
              assert subg["play"].num_edges() == 2 if replace else 1
              assert subg["liked-by"].num_edges() == 4 if replace else 3
              assert subg["flips"].num_edges() == 0
  
      _test3(prob, True)  # w/ replacement, uniform
      _test3(prob, False)  # w/o replacement, uniform
  
      # test different fanouts for different relations
      for i in range(10):
          subg = sample_neighbors_fusing_mode[fused](
              hg,
              {"user": [0, 1], "game": 0, "coin": 0},
              {"follow": 1, "play": 2, "liked-by": 0, "flips": -1},
              replace=True,
          )
          if not fused:
              assert len(subg.ntypes) == 3
          assert len(subg.srctypes) == 3
          assert len(subg.dsttypes) == 3
          assert len(subg.etypes) == 4
          assert subg["follow"].num_edges() == 2
          assert subg["play"].num_edges() == 2
          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 9 for calling a global function with example usage: _test_sample_neighbors(hypersparse, prob, fused) without return types