code: def _scipy_kendall(preds, target, alternative, variant):
      metric_args = {}
      if _SCIPY_GREATER_EQUAL_1_8:
          metric_args = {
              "alternative": alternative or "two-sided"
          }  # scipy cannot accept `None`
      if preds.ndim == 2:
          out = [
              kendalltau(
                  p.numpy(),
                  t.numpy(),
                  method="asymptotic",
                  variant=variant,
                  **metric_args,
              )
              for p, t in zip(preds.T, target.T)
          ]
          tau = torch.cat(
              [torch.tensor(o[0]).unsqueeze(0) for o in out]
          )
          p_value = torch.cat(
              [torch.tensor(o[1]).unsqueeze(0) for o in out]
          )
          if alternative is not None:
              return tau, p_value
          return tau
  
      tau, p_value = kendalltau(
          preds.numpy(),
          target.numpy(),
          method="asymptotic",
          variant=variant,
          **metric_args,
      )
  
      if alternative is not None:
          return torch.tensor(tau), torch.tensor(p_value)
      return torch.tensor(tau)
  
file_path: torchmetrics/tests/unittests/regression/test_kendall.py
imports: import operator
  import sys
  from functools import partial
  import pytest
  import torch
  from lightning_utilities.core.imports import compare_version
  from scipy.stats import kendalltau
  from torchmetrics.functional.regression.kendall import kendall_rank_corrcoef
  from torchmetrics.regression.kendall import KendallRankCorrCoef
  from torchmetrics.utilities.imports import _SCIPY_GREATER_EQUAL_1_8, _TORCH_LOWER_2_0
  from unittests import BATCH_SIZE, EXTRA_DIM, NUM_BATCHES, _Input
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester
label_desc: Use image node_id 1 for calling a global function with example usage: _scipy_kendall(preds, target, alternative, variant) and returns: torch, tau, torch,  torch, tau,  p_value