code: def deepwalk_sample(
      graph, nodes, max_depth, alias_name=None, events_name=None
  ):
      """Implement of random walk.
  
      This function get random walks path for given nodes and depth.
  
      Args:
          nodes: Walk starting from nodes
          max_depth: Max walking depth
  
      Return:
          A list of walks.
      """
      walk = []
      # init
      for node in nodes:
          walk.append([node])
  
      cur_walk_ids = np.arange(0, len(nodes))
      cur_nodes = np.array(nodes)
      for l in range(max_depth):
          # select the walks not end
          cur_succs = graph.successor(cur_nodes)
          mask = [len(succ) > 0 for succ in cur_succs]
  
          if np.any(mask):
              cur_walk_ids = cur_walk_ids[mask]
              cur_nodes = cur_nodes[mask]
              cur_succs = cur_succs[mask]
          else:
              # stop when all nodes have no successor
              break
  
          if alias_name is not None and events_name is not None:
              sample_index = [
                  alias_sample(
                      [1],
                      graph.node_feat[alias_name][node],
                      graph.node_feat[events_name][node],
                  )[0]
                  for node in cur_nodes
              ]
          else:
              outdegree = [len(cur_succ) for cur_succ in cur_succs]
              sample_index = np.floor(
                  np.random.rand(cur_succs.shape[0]) * outdegree
              ).astype("int64")
  
          nxt_cur_nodes = []
          for s, ind, walk_id in zip(
              cur_succs, sample_index, cur_walk_ids
          ):
              walk[walk_id].append(s[ind])
              nxt_cur_nodes.append(s[ind])
          cur_nodes = np.array(nxt_cur_nodes)
      return walk
  
file_path: PGL/legacy/pgl/sample.py
imports: import time
  import copy
  import numpy
  import pgl
  from pgl.utils.logger import log
  from pgl import graph_kernel
label_desc: Use image node_id 7 for calling a global function with example usage: deepwalk_sample(graph, nodes, max_depth, alias_name, events_name) and returns: walk