code: def _sklearn_precision_recall_binary(
      preds, target, sk_fn, ignore_index, multidim_average
  ):
      if multidim_average == "global":
          preds = preds.view(-1).numpy()
          target = target.view(-1).numpy()
      else:
          preds = preds.numpy()
          target = target.numpy()
  
      if np.issubdtype(preds.dtype, np.floating):
          if not ((preds > 0) & (preds < 1)).all():
              preds = sigmoid(preds)
          preds = (preds >= THRESHOLD).astype(np.uint8)
  
      if multidim_average == "global":
          target, preds = remove_ignore_index(
              target, preds, ignore_index
          )
          return sk_fn(target, preds)
  
      res = []
      for pred, true in zip(preds, target):
          pred = pred.flatten()
          true = true.flatten()
          true, pred = remove_ignore_index(true, pred, ignore_index)
          res.append(sk_fn(true, pred))
      return np.stack(res)
  
imports: from functools import partial
  import numpy
  import pytest
  import torch
  from scipy.special import expit
  from sklearn.metrics import confusion_matrix
  from sklearn.metrics import precision_score
  from sklearn.metrics import recall_score
  from torch import Tensor, tensor
  from torchmetrics.classification.precision_recall import BinaryPrecision, BinaryRecall, MulticlassPrecision, MulticlassRecall, MultilabelPrecision, MultilabelRecall, Precision, Recall
  from torchmetrics.functional.classification.precision_recall import binary_precision, binary_recall, multiclass_precision, multiclass_recall, multilabel_precision, multilabel_recall
  from torchmetrics.metric import Metric
  from unittests import NUM_CLASSES, THRESHOLD
  from unittests.classification.inputs import _binary_cases, _multiclass_cases, _multilabel_cases
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester, inject_ignore_index, remove_ignore_index
label_desc: Use image node_id 1 for calling a global function with example usage: _sklearn_precision_recall_binary(preds, target, sk_fn, ignore_index, multidim_average) and returns: np, sk_fn