code: def test_global_uniform_negative_sampling(dtype):
      warnings.simplefilter("ignore", np.ComplexWarning)
      g = dgl.graph(([], []), num_nodes=1000).to(F.ctx())
      src, dst = dgl.sampling.global_uniform_negative_sampling(
          g, 2000, False, True
      )
      assert len(src) == 2000
      assert len(dst) == 2000
  
      g = dgl.graph(
          (
              np.random.randint(0, 20, (300,)),
              np.random.randint(0, 20, (300,)),
          )
      ).to(F.ctx())
      src, dst = dgl.sampling.global_uniform_negative_sampling(
          g, 20, False, True
      )
      assert not F.asnumpy(g.has_edges_between(src, dst)).any()
  
      src, dst = dgl.sampling.global_uniform_negative_sampling(
          g, 20, False, False
      )
      assert not F.asnumpy(g.has_edges_between(src, dst)).any()
      src = F.asnumpy(src)
      dst = F.asnumpy(dst)
      s = set(zip(src.tolist(), dst.tolist()))
      assert len(s) == len(src)
  
      g = dgl.graph(([0], [1])).to(F.ctx())
      src, dst = dgl.sampling.global_uniform_negative_sampling(
          g, 20, True, False, redundancy=10
      )
      src = F.asnumpy(src)
      dst = F.asnumpy(dst)
      # should have either no element or (1, 0)
      assert len(src) < 2
      assert len(dst) < 2
      if len(src) == 1:
          assert src[0] == 1
          assert dst[0] == 0
  
      g = dgl.heterograph(
          {
              ("A", "AB", "B"): (
                  np.random.randint(0, 20, (300,)),
                  np.random.randint(0, 40, (300,)),
              ),
              ("B", "BA", "A"): (
                  np.random.randint(0, 40, (200,)),
                  np.random.randint(0, 20, (200,)),
              ),
          }
      ).to(F.ctx())
      src, dst = dgl.sampling.global_uniform_negative_sampling(
          g, 20, False, etype="AB"
      )
      assert not F.asnumpy(
          g.has_edges_between(src, dst, etype="AB")
      ).any()
  
imports: import unittest
  import warnings
  import backend
  import dgl
  import numpy
  import pytest
label_desc: Use image node_id 31 for calling a global function with example usage: test_global_uniform_negative_sampling(dtype) without return types