class_docstr: Clusters/partitions a graph data object into multiple subgraphs, as
  motivated by the `"Cluster-GCN: An Efficient Algorithm for Training Deep
  and Large Graph Convolutional Networks"
  <https://arxiv.org/abs/1905.07953>`_ paper.
  
  .. note::
      The underlying METIS algorithm requires undirected graphs as input.
  
  Args:
      data (torch_geometric.data.Data): The graph data object.
      num_parts (int): The number of partitions.
      recursive (bool, optional): If set to :obj:`True`, will use multilevel
          recursive bisection instead of multilevel k-way partitioning.
          (default: :obj:`False`)
      save_dir (str, optional): If set, will save the partitioned data to the
          :obj:`save_dir` directory for faster re-use. (default: :obj:`None`)
      log (bool, optional): If set to :obj:`False`, will not log any
          progress. (default: :obj:`True`)
      keep_inter_cluster_edges (bool, optional): If set to :obj:`True`,
          will keep inter-cluster edge connections. (default: :obj:`False`)
      sparse_format (str, optional): The sparse format to use for computing
          partitions. (default: :obj:`"csr"`)
class_docstr_tok: ["Clusters\/partitions","a","graph","data","object","into","multiple","subgraphs",",","as","motivated","by","the","`","``","Cluster-GCN",":","An","Efficient","Algorithm","for","Training","Deep","and","Large","Graph","Convolutional","Networks","''","<","https",":","\/\/arxiv.org\/abs\/1905.07953",">","`","_","paper",".","..","note",":",":","The","underlying","METIS","algorithm","requires","undirected","graphs","as","input",".","Args",":","data","(","torch_geometric.data.Data",")",":","The","graph","data","object",".","num_parts","(","int",")",":","The","number","of","partitions",".","recursive","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","True","`",",","will","use","multilevel","recursive","bisection","instead","of","multilevel","k-way","partitioning",".","(","default",":",":","obj",":","`","False","`",")","save_dir","(","str",",","optional",")",":","If","set",",","will","save","the","partitioned","data","to","the",":","obj",":","`","save_dir","`","directory","for","faster","re-use",".","(","default",":",":","obj",":","`","None","`",")","log","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","False","`",",","will","not","log","any","progress",".","(","default",":",":","obj",":","`","True","`",")","keep_inter_cluster_edges","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","True","`",",","will","keep","inter-cluster","edge","connections",".","(","default",":",":","obj",":","`","False","`",")","sparse_format","(","str",",","optional",")",":","The","sparse","format","to","use","for","computing","partitions",".","(","default",":",":","obj",":","`","``","csr","''","`",")"]
code: def _partition(
      self, edge_index: Tensor, cluster: Tensor
  ) -> Partition:
      # Computes node-level and edge-level permutations and permutes the edge
      # connectivity accordingly:
  
      # Sort `cluster` and compute boundaries `partptr`:
      cluster, node_perm = index_sort(cluster, max_value=self.num_parts)
      partptr = index2ptr(cluster, size=self.num_parts)
  
      # Permute `edge_index` based on node permutation:
      edge_perm = torch.arange(
          edge_index.size(1), device=edge_index.device
      )
      arange = torch.empty_like(node_perm)
      arange[node_perm] = torch.arange(
          cluster.numel(), device=cluster.device
      )
      edge_index = arange[edge_index]
  
      # Compute final CSR representation:
      (row, col), edge_perm = sort_edge_index(
          edge_index,
          edge_attr=edge_perm,
          num_nodes=cluster.numel(),
          sort_by_row=self.sparse_format == "csr",
      )
      if self.sparse_format == "csr":
          indptr, index = index2ptr(row, size=cluster.numel()), col
      else:
          indptr, index = index2ptr(col, size=cluster.numel()), row
  
      return Partition(
          indptr,
          index,
          partptr,
          node_perm,
          edge_perm,
          self.sparse_format,
      )
  
imports: import copy
  import os.path
  import sys
  from dataclasses import dataclass
  from typing import List, Literal, Optional
  import torch
  import torch.utils.data
  from torch import Tensor
  import torch_geometric.typing
  from torch_geometric.data import Data
  from torch_geometric.typing import pyg_lib
  from torch_geometric.utils import index_sort, narrow, select, sort_edge_index
  from torch_geometric.utils.map import map_index
  from torch_geometric.utils.sparse import index2ptr, ptr2index
label_desc: Use image node_id 3 for calling the ClusterData obj's underlying member method code with example usage: obj._partition(edge_index, cluster) and returns: Partition