code: def _compute_sklearn_metric(
      preds: Union[Tensor, array],
      target: Union[Tensor, array],
      indexes: Optional[np.ndarray] = None,
      metric: Optional[Callable] = None,
      empty_target_action: str = "skip",
      ignore_index: Optional[int] = None,
      reverse: bool = False,
      aggregation: Union[
          Literal["mean", "median", "min", "max"], Callable
      ] = "mean",
      **kwargs: Any,
  ) -> Tensor:
      """Compute metric with multiple iterations over every query predictions set."""
      if indexes is None:
          indexes = np.full_like(preds, fill_value=0, dtype=np.int64)
      if isinstance(indexes, Tensor):
          indexes = indexes.cpu().numpy()
      if isinstance(preds, Tensor):
          preds = preds.cpu().numpy()
      if isinstance(target, Tensor):
          target = target.cpu().numpy()
  
      assert isinstance(indexes, np.ndarray)
      assert isinstance(preds, np.ndarray)
      assert isinstance(target, np.ndarray)
  
      if ignore_index is not None:
          valid_positions = target != ignore_index
          indexes, preds, target = (
              indexes[valid_positions],
              preds[valid_positions],
              target[valid_positions],
          )
  
      indexes = indexes.flatten()
      preds = preds.flatten()
      target = target.flatten()
      groups = get_group_indexes(indexes)
  
      sk_results = []
      for group in groups:
          trg, pds = target[group], preds[group]
  
          if ((1 - trg) if reverse else trg).sum() == 0:
              if empty_target_action == "skip":
                  pass
              elif empty_target_action == "pos":
                  sk_results.append(1.0)
              else:
                  sk_results.append(0.0)
          else:
              res = metric(trg, pds, **kwargs)
              sk_results.append(res)
  
      sk_results = np.array(sk_results)
      sk_results[
          np.isnan(sk_results)
      ] = 0.0  # this is needed with old versions of sklearn
  
      if len(sk_results) > 0:
          return _retrieval_aggregate(
              torch.from_numpy(sk_results), aggregation=aggregation
          ).numpy()
      return np.array(0.0)
  
imports: from functools import partial
  from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
  import numpy
  import pytest
  import torch
  from numpy import array
  from torch import Tensor, tensor
  from torchmetrics.retrieval.base import _retrieval_aggregate
  from typing_extensions import Literal
  from unittests.helpers import seed_all
  from unittests.helpers.testers import Metric, MetricTester
  from unittests.retrieval.inputs import _input_retrieval_scores
  from unittests.retrieval.inputs import _input_retrieval_scores_all_target
  from unittests.retrieval.inputs import _input_retrieval_scores_empty
  from unittests.retrieval.inputs import _input_retrieval_scores_extra
  from unittests.retrieval.inputs import _input_retrieval_scores_float_target
  from unittests.retrieval.inputs import _input_retrieval_scores_for_adaptive_k
  from unittests.retrieval.inputs import _input_retrieval_scores_int_target
  from unittests.retrieval.inputs import _input_retrieval_scores_mismatching_sizes
  from unittests.retrieval.inputs import _input_retrieval_scores_mismatching_sizes_func
  from unittests.retrieval.inputs import _input_retrieval_scores_no_target
  from unittests.retrieval.inputs import _input_retrieval_scores_with_ignore_index
  from unittests.retrieval.inputs import _input_retrieval_scores_wrong_targets
label_desc: Use image node_id 3 for calling a global function with example usage: _compute_sklearn_metric(preds, target, indexes, metric, empty_target_action, ignore_index, reverse, aggregation) and returns: np, _retrieval_aggregate