code: def test_sample_neighbors_biased_homogeneous():
      g = create_test_graph(100, 30)
  
      def check_num(nodes, tag):
          nodes, tag = F.asnumpy(nodes), F.asnumpy(tag)
          cnt = [sum(tag[nodes] == i) for i in range(4)]
          # No tag 0
          assert cnt[0] == 0
  
          # very rare tag 1
          assert cnt[2] > 2 * cnt[1]
          assert cnt[3] > 2 * cnt[1]
  
      tag = F.tensor(np.random.choice(4, 100))
      bias = F.tensor([0, 0.1, 10, 10], dtype=F.float32)
      # inedge / without replacement
      g_sorted = dgl.sort_csc_by_tag(g, tag)
      for _ in range(5):
          subg = dgl.sampling.sample_neighbors_biased(
              g_sorted, g.nodes(), 5, bias, replace=False
          )
          check_num(subg.edges()[0], tag)
          u, v = subg.edges()
          edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
          assert len(edge_set) == subg.num_edges()
  
      # inedge / with replacement
      for _ in range(5):
          subg = dgl.sampling.sample_neighbors_biased(
              g_sorted, g.nodes(), 5, bias, replace=True
          )
          check_num(subg.edges()[0], tag)
  
      # outedge / without replacement
      g_sorted = dgl.sort_csr_by_tag(g, tag)
      for _ in range(5):
          subg = dgl.sampling.sample_neighbors_biased(
              g_sorted,
              g.nodes(),
              5,
              bias,
              edge_dir="out",
              replace=False,
          )
          check_num(subg.edges()[1], tag)
          u, v = subg.edges()
          edge_set = set(zip(list(F.asnumpy(u)), list(F.asnumpy(v))))
          assert len(edge_set) == subg.num_edges()
  
      # outedge / with replacement
      for _ in range(5):
          subg = dgl.sampling.sample_neighbors_biased(
              g_sorted, g.nodes(), 5, bias, edge_dir="out", replace=True
          )
          check_num(subg.edges()[1], tag)
  
imports: import unittest
  import warnings
  import backend
  import dgl
  import numpy
  import pytest
label_desc: Use image node_id 25 for calling a global function with example usage: test_sample_neighbors_biased_homogeneous() without return types