code: def test_node2vec(
      graph_file,
      directed,
      compress,
  ):
      dataset_path = graph_file.get_path()
      cu_M = utils.read_csv_file(dataset_path)
  
      G = cugraph.Graph(directed=directed)
  
      G.from_cudf_edgelist(
          cu_M,
          source="0",
          destination="1",
          edge_attr="2",
          renumber=False,
      )
      num_verts = G.number_of_vertices()
      k = random.randint(6, 12)
      start_vertices = cudf.Series(
          random.sample(range(num_verts), k), dtype="int32"
      )
      max_depth = 5
      result, seeds = calc_node2vec(
          G,
          start_vertices,
          max_depth,
          compress_result=compress,
          p=0.8,
          q=0.5,
      )
      vertex_paths, edge_weights, vertex_path_sizes = result
  
      if compress:
          # Paths are coalesced, meaning vertex_path_sizes is nonempty. It's
          # necessary to use in order to track starts of paths
          assert vertex_paths.size == vertex_path_sizes.sum()
          if directed:
              # directed graphs may be coalesced at any point
              assert vertex_paths.size - k == edge_weights.size
              # This part is for checking to make sure each of the edges
              # in all of the paths are valid and are accurate
              idx = 0
              for path_idx in range(vertex_path_sizes.size):
                  for _ in range(vertex_path_sizes[path_idx] - 1):
                      weight = edge_weights[idx]
                      u = vertex_paths[idx + path_idx]
                      v = vertex_paths[idx + path_idx + 1]
                      # Corresponding weight to edge is not correct
                      expr = "(src == {} and dst == {})".format(u, v)
                      edge_query = G.edgelist.edgelist_df.query(expr)
                      if edge_query.empty:
                          raise ValueError(
                              "edge_query didn't find:({},{})".format(
                                  u, v
                              )
                          )
                      else:
                          if edge_query["weights"].values[0] != weight:
                              raise ValueError(
                                  "edge_query weight incorrect"
                              )
                      idx += 1
  
          else:
              # undirected graphs should never be coalesced
              assert vertex_paths.size == max_depth * k
              assert edge_weights.size == (max_depth - 1) * k
              # This part is for checking to make sure each of the edges
              # in all of the paths are valid and are accurate
              for path_idx in range(k):
                  for idx in range(max_depth - 1):
                      weight = edge_weights[
                          path_idx * (max_depth - 1) + idx
                      ]
                      u = vertex_paths[path_idx * max_depth + idx]
                      v = vertex_paths[path_idx * max_depth + idx + 1]
                      # Corresponding weight to edge is not correct
                      expr = "(src == {} and dst == {})".format(u, v)
                      edge_query = G.edgelist.edgelist_df.query(expr)
                      if edge_query.empty:
                          raise ValueError(
                              "edge_query didn't find:({},{})".format(
                                  u, v
                              )
                          )
                      else:
                          if edge_query["weights"].values[0] != weight:
                              raise ValueError(
                                  "edge_query weight incorrect"
                              )
      else:
          # Paths are padded, meaning a formula can be used to track starts of
          # paths. Check that output sizes are as expected
          assert vertex_paths.size == max_depth * k
          assert edge_weights.size == (max_depth - 1) * k
          assert vertex_path_sizes.size == 0
          if directed:
              blanks = vertex_paths.isna()
          # This part is for checking to make sure each of the edges
          # in all of the paths are valid and are accurate
          for i in range(k):
              path_at_end, j = False, 0
              weight_idx = 0
              while not path_at_end:
                  src_idx = i * max_depth + j
                  dst_idx = i * max_depth + j + 1
                  if directed:
                      invalid_src = blanks[src_idx] or (
                          src_idx >= num_verts
                      )
                      invalid_dst = blanks[dst_idx] or (
                          dst_idx >= num_verts
                      )
                      if invalid_src or invalid_dst:
                          break
                  weight = edge_weights[weight_idx]
                  u = vertex_paths[src_idx]
                  v = vertex_paths[dst_idx]
                  # Corresponding weight to edge is not correct
                  expr = "(src == {} and dst == {})".format(u, v)
                  edge_query = G.edgelist.edgelist_df.query(expr)
                  if edge_query.empty:
                      raise ValueError(
                          "edge_query didn't find:({},{})".format(u, v)
                      )
                  else:
                      if edge_query["weights"].values[0] != weight:
                          raise ValueError(
                              "edge_query weight incorrect"
                          )
  
                  # Only increment if the current indices are valid
                  j += 1
                  weight_idx += 1
                  if j >= max_depth - 1:
                      path_at_end = True
              # Check that path sizes matches up correctly with paths
              if vertex_paths[i * max_depth] != seeds[i]:
                  raise ValueError(
                      "vertex_path start did not match seed \
                                   vertex:{}".format(
                          vertex_paths.values
                      )
                  )
  
file_path: cugraph/python/cugraph/cugraph/tests/sampling/test_node2vec.py
imports: import gc
  import random
  import pytest
  import cudf
  import cugraph
  from cugraph.datasets import small_line, karate
  from cugraph.testing import utils, SMALL_DATASETS
label_desc: Use image node_id 6 for calling a global function with example usage: test_node2vec(graph_file, directed, compress) without return types