code: def test_uniform_random_walk(use_uva):
      if use_uva and F.ctx() == F.cpu():
          pytest.skip("UVA random walk requires a GPU.")
      g1 = dgl.heterograph(
          {("user", "follow", "user"): ([0, 1, 2], [1, 2, 0])}
      )
      g2 = dgl.heterograph(
          {
              ("user", "follow", "user"): (
                  [0, 1, 1, 2, 3],
                  [1, 2, 3, 0, 0],
              )
          }
      )
      g3 = dgl.heterograph(
          {
              ("user", "follow", "user"): ([0, 1, 2], [1, 2, 0]),
              ("user", "view", "item"): ([0, 1, 2], [0, 1, 2]),
              ("item", "viewed-by", "user"): ([0, 1, 2], [0, 1, 2]),
          }
      )
      g4 = dgl.heterograph(
          {
              ("user", "follow", "user"): (
                  [0, 1, 1, 2, 3],
                  [1, 2, 3, 0, 0],
              ),
              ("user", "view", "item"): (
                  [0, 0, 1, 2, 3, 3],
                  [0, 1, 1, 2, 2, 1],
              ),
              ("item", "viewed-by", "user"): (
                  [0, 1, 1, 2, 2, 1],
                  [0, 0, 1, 2, 3, 3],
              ),
          }
      )
  
      if use_uva:
          for g in (g1, g2, g3, g4):
              g.create_formats_()
              g.pin_memory_()
      elif F._default_context_str == "gpu":
          g1 = g1.to(F.ctx())
          g2 = g2.to(F.ctx())
          g3 = g3.to(F.ctx())
          g4 = g4.to(F.ctx())
  
      try:
          traces, eids, ntypes = dgl.sampling.random_walk(
              g1,
              F.tensor([0, 1, 2, 0, 1, 2], dtype=g1.idtype),
              length=4,
              return_eids=True,
          )
          check_random_walk(
              g1, ["follow"] * 4, traces, ntypes, trace_eids=eids
          )
          if F._default_context_str == "cpu":
              with pytest.raises(dgl.DGLError):
                  dgl.sampling.random_walk(
                      g1,
                      F.tensor([0, 1, 2, 10], dtype=g1.idtype),
                      length=4,
                      return_eids=True,
                  )
          traces, eids, ntypes = dgl.sampling.random_walk(
              g1,
              F.tensor([0, 1, 2, 0, 1, 2], dtype=g1.idtype),
              length=4,
              restart_prob=0.0,
              return_eids=True,
          )
          check_random_walk(
              g1, ["follow"] * 4, traces, ntypes, trace_eids=eids
          )
          traces, ntypes = dgl.sampling.random_walk(
              g1,
              F.tensor([0, 1, 2, 0, 1, 2], dtype=g1.idtype),
              length=4,
              restart_prob=F.zeros((4,), F.float32),
          )
          check_random_walk(g1, ["follow"] * 4, traces, ntypes)
          traces, ntypes = dgl.sampling.random_walk(
              g1,
              F.tensor([0, 1, 2, 0, 1, 2], dtype=g1.idtype),
              length=5,
              restart_prob=F.tensor([0, 0, 0, 0, 1], dtype=F.float32),
          )
          check_random_walk(
              g1,
              ["follow"] * 4,
              F.slice_axis(traces, 1, 0, 5),
              F.slice_axis(ntypes, 0, 0, 5),
          )
          assert (F.asnumpy(traces)[:, 5] == -1).all()
  
          traces, eids, ntypes = dgl.sampling.random_walk(
              g2,
              F.tensor([0, 1, 2, 3, 0, 1, 2, 3], dtype=g2.idtype),
              length=4,
              return_eids=True,
          )
          check_random_walk(
              g2, ["follow"] * 4, traces, ntypes, trace_eids=eids
          )
  
          metapath = ["follow", "view", "viewed-by"] * 2
          traces, eids, ntypes = dgl.sampling.random_walk(
              g3,
              F.tensor([0, 1, 2, 0, 1, 2], dtype=g3.idtype),
              metapath=metapath,
              return_eids=True,
          )
          check_random_walk(
              g3, metapath, traces, ntypes, trace_eids=eids
          )
  
          metapath = ["follow", "view", "viewed-by"] * 2
          traces, eids, ntypes = dgl.sampling.random_walk(
              g4,
              F.tensor([0, 1, 2, 3, 0, 1, 2, 3], dtype=g4.idtype),
              metapath=metapath,
              return_eids=True,
          )
          check_random_walk(
              g4, metapath, traces, ntypes, trace_eids=eids
          )
  
          traces, eids, ntypes = dgl.sampling.random_walk(
              g4,
              F.tensor([0, 1, 2, 0, 1, 2], dtype=g4.idtype),
              metapath=metapath,
              return_eids=True,
          )
          check_random_walk(
              g4, metapath, traces, ntypes, trace_eids=eids
          )
      finally:  # make sure to unpin the graphs even if some test fails
          for g in (g1, g2, g3, g4):
              if g.is_pinned():
                  g.unpin_memory_()
  
imports: import unittest
  import warnings
  import backend
  import dgl
  import numpy
  import pytest
label_desc: Use image node_id 3 for calling a global function with example usage: test_uniform_random_walk(use_uva) without return types