code: def _calc_bc_subset(
      G, Gnx, normalized, weight, k, seed, result_dtype
  ):
      # NOTE: Networkx API does not allow passing a list of vertices
      # And the sampling is operated on Gnx.nodes() directly
      # We first mimic acquisition of the nodes to compare with same sources
      random.seed(seed)  # It will be called again in nx's call
      sources = random.sample(list(Gnx.nodes()), k)
  
      # NOTE: Since we sampled the Networkx graph, the sources are already
      # external ids, so we don't need to translate to external ids for
      # cugraph
  
      df = cugraph.edge_betweenness_centrality(
          G,
          k=sources,
          normalized=normalized,
          weight=weight,
          result_dtype=result_dtype,
      )
  
      nx_bc_dict = nx.edge_betweenness_centrality(
          Gnx, k=k, normalized=normalized, weight=weight, seed=seed
      )
  
      if normalized or not Gnx.is_directed():
          if k is not None:
              nx_bc_dict = _rescale_e(nx_bc_dict, len(Gnx.nodes()), k)
  
      nx_df = generate_nx_result(
          nx_bc_dict, type(Gnx) is nx.DiGraph
      ).rename(columns={"betweenness_centrality": "ref_bc"}, copy=False)
  
      merged_df = (
          df.merge(nx_df, on=["src", "dst"])
          .rename(
              columns={"betweenness_centrality": "cu_bc"}, copy=False
          )
          .reset_index(drop=True)
      )
  
      return merged_df
  
imports: import gc
  import pytest
  import random
  import networkx
  import numpy
  import cupy
  import cudf
  import cugraph
  from cugraph.datasets import karate_disjoint
  from cugraph.testing import utils, SMALL_DATASETS
label_desc: Use image node_id 4 for calling a global function with example usage: _calc_bc_subset(G, Gnx, normalized, weight, k, seed, result_dtype) and returns: merged_df