code: def _rand_score_compute(contingency: Tensor) -> Tensor:
      """Compute the rand score based on the contingency matrix.
  
      Args:
          contingency: contingency matrix
  
      Returns:
          rand_score: rand score
  
      """
      pair_matrix = calculate_pair_cluster_confusion_matrix(
          contingency=contingency
      )
  
      numerator = pair_matrix.diagonal().sum()
      denominator = pair_matrix.sum()
      if numerator == denominator or denominator == 0:
          # Special limit cases: no clustering since the data is not split;
          # or trivial clustering where each document is assigned a unique
          # cluster. These are perfect matches hence return 1.0.
          return torch.ones_like(numerator, dtype=torch.float32)
  
      return numerator / denominator
  
imports: import torch
  from torch import Tensor
  from torchmetrics.functional.clustering.utils import calculate_contingency_matrix, calculate_pair_cluster_confusion_matrix, check_cluster_labels
label_desc: Use image node_id 2 for calling a global function with example usage: _rand_score_compute(contingency) and returns: unknown, torch