code: def _binary_clf_curve(
      preds: Tensor,
      target: Tensor,
      sample_weights: Optional[Union[Sequence, Tensor]] = None,
      pos_label: int = 1,
  ) -> Tuple[Tensor, Tensor, Tensor]:
      """Calculate the TPs and false positives for all unique thresholds in the preds tensor.
  
      Adapted from
      https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/metrics/_ranking.py.
  
      Args:
          preds: 1d tensor with predictions
          target: 1d tensor with true values
          sample_weights: a 1d tensor with a weight per sample
          pos_label: integer determining what the positive class in target tensor is
  
      Returns:
          fps: 1d tensor with false positives for different thresholds
          tps: 1d tensor with true positives for different thresholds
          thresholds: the unique thresholds use for calculating fps and tps
  
      """
      with torch.no_grad():
          if sample_weights is not None and not isinstance(
              sample_weights, Tensor
          ):
              sample_weights = tensor(
                  sample_weights, device=preds.device, dtype=torch.float
              )
  
          # remove class dimension if necessary
          if preds.ndim > target.ndim:
              preds = preds[:, 0]
          desc_score_indices = torch.argsort(preds, descending=True)
  
          preds = preds[desc_score_indices]
          target = target[desc_score_indices]
  
          weight = (
              sample_weights[desc_score_indices]
              if sample_weights is not None
              else 1.0
          )
  
          # pred typically has many tied values. Here we extract
          # the indices associated with the distinct values. We also
          # concatenate a value for the end of the curve.
          distinct_value_indices = torch.where(preds[1:] - preds[:-1])[
              0
          ]
          threshold_idxs = F.pad(
              distinct_value_indices, [0, 1], value=target.size(0) - 1
          )
          target = (target == pos_label).to(torch.long)
          tps = _cumsum(target * weight, dim=0)[threshold_idxs]
  
          if sample_weights is not None:
              # express fps as a cumsum to ensure fps is increasing even in
              # the presence of floating point errors
              fps = _cumsum((1 - target) * weight, dim=0)[
                  threshold_idxs
              ]
          else:
              fps = 1 + threshold_idxs - tps
  
          return fps, tps, preds[threshold_idxs]
  
imports: from typing import List, Optional, Sequence, Tuple, Union
  import torch
  from torch import Tensor, tensor
  from torch.nn import functional
  from typing_extensions import Literal
  from torchmetrics.utilities.checks import _check_same_shape
  from torchmetrics.utilities.compute import _safe_divide, interp
  from torchmetrics.utilities.data import _bincount, _cumsum
  from torchmetrics.utilities.enums import ClassificationTask
label_desc: Use image node_id 1 for calling a global function with example usage: _binary_clf_curve(preds, target, sample_weights, pos_label) and returns: fps,  tps,  preds