code: def to_networkit(
      edge_index: Tensor,
      edge_weight: Optional[Tensor] = None,
      num_nodes: Optional[int] = None,
      directed: bool = True,
  ) -> Any:
      r"""Converts a :obj:`(edge_index, edge_weight)` tuple to a
      :class:`networkit.Graph`.
  
      Args:
          edge_index (torch.Tensor): The edge indices of the graph.
          edge_weight (torch.Tensor, optional): The edge weights of the graph.
              (default: :obj:`None`)
          num_nodes (int, optional): The number of nodes in the graph.
              (default: :obj:`None`)
          directed (bool, optional): If set to :obj:`False`, the graph will be
              undirected. (default: :obj:`True`)
      """
      import networkit as nk
  
      num_nodes = maybe_num_nodes(edge_index, num_nodes)
  
      g = nk.graph.Graph(
          num_nodes,
          weighted=edge_weight is not None,
          directed=directed,
      )
  
      if edge_weight is None:
          edge_weight = torch.ones(edge_index.size(1))
  
      if not directed:
          mask = edge_index[0] <= edge_index[1]
          edge_index = edge_index[:, mask]
          edge_weight = edge_weight[mask]
  
      for (u, v), w in zip(
          edge_index.t().tolist(), edge_weight.tolist()
      ):
          g.addEdge(u, v, w)
  
      return g
  
file_path: pytorch_geometric/torch_geometric/utils/convert.py
imports: from collections import defaultdict
  from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple, Union
  import scipy.sparse
  import torch
  from torch import Tensor
  from torch.utils.dlpack import from_dlpack, to_dlpack
  import torch_geometric
  from torch_geometric.utils.num_nodes import maybe_num_nodes
label_desc: Use image node_id 5 for calling a global function with example usage: to_networkit(edge_index, edge_weight, num_nodes, directed) and returns: g