code: def topk(
      x: Tensor,
      ratio: Optional[Union[float, int]],
      batch: Tensor,
      min_score: Optional[float] = None,
      tol: float = 1e-7,
  ) -> Tensor:
      if min_score is not None:
          # Make sure that we do not drop all nodes in a graph.
          scores_max = scatter(x, batch, reduce="max")[batch] - tol
          scores_min = scores_max.clamp(max=min_score)
  
          perm = (x > scores_min).nonzero().view(-1)
          return perm
  
      if ratio is not None:
          num_nodes = scatter(
              batch.new_ones(x.size(0)), batch, reduce="sum"
          )
  
          if ratio >= 1:
              k = num_nodes.new_full((num_nodes.size(0),), int(ratio))
          else:
              k = (
                  (float(ratio) * num_nodes.to(x.dtype))
                  .ceil()
                  .to(torch.long)
              )
  
          x, x_perm = torch.sort(x.view(-1), descending=True)
          batch = batch[x_perm]
          batch, batch_perm = torch.sort(
              batch, descending=False, stable=True
          )
  
          arange = torch.arange(
              x.size(0), dtype=torch.long, device=x.device
          )
          ptr = cumsum(num_nodes)
          batched_arange = arange - ptr[batch]
          mask = batched_arange < k[batch]
  
          return x_perm[batch_perm[mask]]
  
      raise ValueError(
          "At least one of the 'ratio' and 'min_score' parameters "
          "must be specified"
      )
  
file_path: pytorch_geometric/torch_geometric/nn/pool/select/topk.py
imports: from typing import Callable, Optional, Union
  import torch
  from torch import Tensor
  from torch_geometric.nn.inits import uniform
  from torch_geometric.nn.pool.select import Select, SelectOutput
  from torch_geometric.nn.resolver import activation_resolver
  from torch_geometric.utils import cumsum, scatter, softmax
label_desc: Use image node_id 1 for calling a global function with example usage: topk(x, ratio, batch, min_score, tol) and returns: perm, x_perm