code: def test_non_uniform_random_walk(use_uva):
      if use_uva:
          if F.ctx() == F.cpu():
              pytest.skip("UVA biased random walk requires a GPU.")
          if dgl.backend.backend_name != "pytorch":
              pytest.skip(
                  "UVA biased random walk is only supported with PyTorch."
              )
      g2 = dgl.heterograph(
          {
              ("user", "follow", "user"): (
                  [0, 1, 1, 2, 3],
                  [1, 2, 3, 0, 0],
              )
          }
      )
      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],
              ),
          }
      )
  
      g2.edata["p"] = F.copy_to(
          F.tensor([3, 0, 3, 3, 3], dtype=F.float32), F.cpu()
      )
      g2.edata["p2"] = F.copy_to(
          F.tensor([[3], [0], [3], [3], [3]], dtype=F.float32), F.cpu()
      )
      g4.edges["follow"].data["p"] = F.copy_to(
          F.tensor([3, 0, 3, 3, 3], dtype=F.float32), F.cpu()
      )
      g4.edges["viewed-by"].data["p"] = F.copy_to(
          F.tensor([1, 1, 1, 1, 1, 1], dtype=F.float32), F.cpu()
      )
  
      if use_uva:
          for g in (g2, g4):
              g.create_formats_()
              g.pin_memory_()
      elif F._default_context_str == "gpu":
          g2 = g2.to(F.ctx())
          g4 = g4.to(F.ctx())
  
      try:
          traces, eids, ntypes = dgl.sampling.random_walk(
              g2,
              F.tensor([0, 1, 2, 3, 0, 1, 2, 3], dtype=g2.idtype),
              length=4,
              prob="p",
              return_eids=True,
          )
          check_random_walk(
              g2, ["follow"] * 4, traces, ntypes, "p", trace_eids=eids
          )
  
          with pytest.raises(dgl.DGLError):
              traces, ntypes = dgl.sampling.random_walk(
                  g2,
                  F.tensor([0, 1, 2, 3, 0, 1, 2, 3], dtype=g2.idtype),
                  length=4,
                  prob="p2",
              )
  
          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,
              prob="p",
              return_eids=True,
          )
          check_random_walk(
              g4, metapath, traces, ntypes, "p", trace_eids=eids
          )
          traces, eids, ntypes = dgl.sampling.random_walk(
              g4,
              F.tensor([0, 1, 2, 3, 0, 1, 2, 3], dtype=g4.idtype),
              metapath=metapath,
              prob="p",
              restart_prob=0.0,
              return_eids=True,
          )
          check_random_walk(
              g4, metapath, traces, ntypes, "p", trace_eids=eids
          )
          traces, eids, ntypes = dgl.sampling.random_walk(
              g4,
              F.tensor([0, 1, 2, 3, 0, 1, 2, 3], dtype=g4.idtype),
              metapath=metapath,
              prob="p",
              restart_prob=F.zeros((6,), F.float32, F.ctx()),
              return_eids=True,
          )
          check_random_walk(
              g4, metapath, traces, ntypes, "p", trace_eids=eids
          )
          traces, eids, ntypes = dgl.sampling.random_walk(
              g4,
              F.tensor([0, 1, 2, 3, 0, 1, 2, 3], dtype=g4.idtype),
              metapath=metapath + ["follow"],
              prob="p",
              restart_prob=F.tensor([0, 0, 0, 0, 0, 0, 1], F.float32),
              return_eids=True,
          )
          check_random_walk(
              g4,
              metapath,
              traces[:, :7],
              ntypes[:7],
              "p",
              trace_eids=eids,
          )
          assert (F.asnumpy(traces[:, 7]) == -1).all()
      finally:
          for g in (g2, g4):
              g.unpin_memory_()
  
imports: import unittest
  import warnings
  import backend
  import dgl
  import numpy
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: test_non_uniform_random_walk(use_uva) without return types