class_docstr: The data loader scheme from the `"Cluster-GCN: An Efficient Algorithm
  for Training Deep and Large Graph Convolutional Networks"
  <https://arxiv.org/abs/1905.07953>`_ paper which merges partioned subgraphs
  and their between-cluster links from a large-scale graph data object to
  form a mini-batch.
  
  .. note::
  
      Use :class:`~torch_geometric.loader.ClusterData` and
      :class:`~torch_geometric.loader.ClusterLoader` in conjunction to
      form mini-batches of clusters.
      For an example of using Cluster-GCN, see
      `examples/cluster_gcn_reddit.py <https://github.com/pyg-team/
      pytorch_geometric/blob/master/examples/cluster_gcn_reddit.py>`_ or
      `examples/cluster_gcn_ppi.py <https://github.com/pyg-team/
      pytorch_geometric/blob/master/examples/cluster_gcn_ppi.py>`_.
  
  Args:
      cluster_data (torch_geometric.loader.ClusterData): The already
          partioned data object.
      **kwargs (optional): Additional arguments of
          :class:`torch.utils.data.DataLoader`, such as :obj:`batch_size`,
          :obj:`shuffle`, :obj:`drop_last` or :obj:`num_workers`.
class_docstr_tok: ["The","data","loader","scheme","from","the","`","``","Cluster-GCN",":","An","Efficient","Algorithm","for","Training","Deep","and","Large","Graph","Convolutional","Networks","''","<","https",":","\/\/arxiv.org\/abs\/1905.07953",">","`","_","paper","which","merges","partioned","subgraphs","and","their","between-cluster","links","from","a","large-scale","graph","data","object","to","form","a","mini-batch",".","..","note",":",":","Use",":","class",":","`","~torch_geometric.loader.ClusterData","`","and",":","class",":","`","~torch_geometric.loader.ClusterLoader","`","in","conjunction","to","form","mini-batches","of","clusters",".","For","an","example","of","using","Cluster-GCN",",","see","`","examples\/cluster_gcn_reddit.py","<","https",":","\/\/github.com\/pyg-team\/","pytorch_geometric\/blob\/master\/examples\/cluster_gcn_reddit.py",">","`","_","or","`","examples\/cluster_gcn_ppi.py","<","https",":","\/\/github.com\/pyg-team\/","pytorch_geometric\/blob\/master\/examples\/cluster_gcn_ppi.py",">","`","_",".","Args",":","cluster_data","(","torch_geometric.loader.ClusterData",")",":","The","already","partioned","data","object",".","*","*","kwargs","(","optional",")",":","Additional","arguments","of",":","class",":","`","torch.utils.data.DataLoader","`",",","such","as",":","obj",":","`","batch_size","`",",",":","obj",":","`","shuffle","`",",",":","obj",":","`","drop_last","`","or",":","obj",":","`","num_workers","`","."]
code: def _collate(self, batch: List[int]) -> Data:
      if not isinstance(batch, torch.Tensor):
          batch = torch.tensor(batch)
  
      global_indptr = self.cluster_data.partition.indptr
      global_index = self.cluster_data.partition.index
  
      # Get all node-level and edge-level start and end indices for the
      # current mini-batch:
      node_start = self.cluster_data.partition.partptr[batch]
      node_end = self.cluster_data.partition.partptr[batch + 1]
      edge_start = global_indptr[node_start]
      edge_end = global_indptr[node_end]
  
      # Iterate over each partition in the batch and calculate new edge
      # connectivity. This is done by slicing the corresponding source and
      # destination indices for each partition and adjusting their indices to
      # start from zero:
      rows, cols, nodes, cumsum = [], [], [], 0
      for i in range(batch.numel()):
          nodes.append(torch.arange(node_start[i], node_end[i]))
          indptr = global_indptr[node_start[i] : node_end[i] + 1]
          indptr = indptr - edge_start[i]
          if self.cluster_data.partition.sparse_format == "csr":
              row = ptr2index(indptr) + cumsum
              col = global_index[edge_start[i] : edge_end[i]]
  
          else:
              col = ptr2index(indptr) + cumsum
              row = global_index[edge_start[i] : edge_end[i]]
  
          rows.append(row)
          cols.append(col)
          cumsum += indptr.numel() - 1
  
      node = torch.cat(nodes, dim=0)
      row = torch.cat(rows, dim=0)
      col = torch.cat(cols, dim=0)
  
      # Map `col` vector to valid entries and remove any entries that do not
      # connect two nodes within the same mini-batch:
      if self.cluster_data.partition.sparse_format == "csr":
          col, edge_mask = map_index(col, node)
          row = row[edge_mask]
      else:
          row, edge_mask = map_index(row, node)
          col = col[edge_mask]
      out = copy.copy(self.cluster_data.data)
  
      # Slice node-level and edge-level attributes according to its offsets:
      for key, value in self.cluster_data.data.items():
          if key == "num_nodes":
              out.num_nodes = cumsum
          elif self.cluster_data.data.is_node_attr(key):
              cat_dim = self.cluster_data.data.__cat_dim__(key, value)
              out[key] = torch.cat(
                  [
                      narrow(out[key], cat_dim, s, e - s)
                      for s, e in zip(node_start, node_end)
                  ],
                  dim=cat_dim,
              )
          elif self.cluster_data.data.is_edge_attr(key):
              cat_dim = self.cluster_data.data.__cat_dim__(key, value)
              value = torch.cat(
                  [
                      narrow(out[key], cat_dim, s, e - s)
                      for s, e in zip(edge_start, edge_end)
                  ],
                  dim=cat_dim,
              )
              out[key] = select(value, edge_mask, dim=cat_dim)
  
      out.edge_index = torch.stack([row, col], dim=0)
  
      return out
  
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 2 for calling the ClusterLoader obj's underlying member method code with example usage: obj._collate(batch) and returns: out