code: def _dcg_sample_scores(
      target: Tensor, preds: Tensor, top_k: int, ignore_ties: bool
  ) -> Tensor:
      """Translated version of sklearns `_dcg_sample_scores` function.
  
      Args:
          target: ground truth about each document relevance.
          preds: estimated probabilities of each document to be relevant.
          top_k: consider only the top k elements
          ignore_ties: If True, ties are ignored. If False, ties are averaged.
  
      Returns:
          The cumulative gain
  
      """
      discount = 1.0 / (
          torch.log2(
              torch.arange(target.shape[-1], device=target.device) + 2.0
          )
      )
      discount[top_k:] = 0.0
  
      if ignore_ties:
          ranking = preds.argsort(descending=True)
          ranked = target[ranking]
          cumulative_gain = (discount * ranked).sum()
      else:
          discount_cumsum = discount.cumsum(dim=-1)
          cumulative_gain = _tie_average_dcg(
              target, preds, discount_cumsum
          )
      return cumulative_gain
  
imports: from typing import Optional
  import torch
  from torch import Tensor
  from torchmetrics.utilities.checks import _check_retrieval_functional_inputs
label_desc: Use image node_id 2 for calling a global function with example usage: _dcg_sample_scores(target, preds, top_k, ignore_ties) and returns: cumulative_gain