code: def _binary_clf_curve(
      y_true,
      y_score,
      pos_label=None,
      sample_weight=None,
      session=None,
      run_kwargs=None,
  ):
      """Calculate true and false positives per binary classification threshold.
  
      Parameters
      ----------
      y_true : tensor, shape = [n_samples]
          True targets of binary classification
  
      y_score : tensor, shape = [n_samples]
          Estimated probabilities or decision function
  
      pos_label : int or str, default=None
          The label of the positive class
  
      sample_weight : array-like of shape (n_samples,), default=None
          Sample weights.
  
      Returns
      -------
      fps : tensor, shape = [n_thresholds]
          A count of false positives, at index i being the number of negative
          samples assigned a score >= thresholds[i]. The total number of
          negative samples is equal to fps[-1] (thus true negatives are given by
          fps[-1] - fps).
  
      tps : tensor, shape = [n_thresholds <= len(mt.unique(y_score))]
          An increasing count of true positives, at index i being the number
          of positive samples assigned a score >= thresholds[i]. The total
          number of positive samples is equal to tps[-1] (thus false negatives
          are given by tps[-1] - tps).
  
      thresholds : tensor, shape = [n_thresholds]
          Decreasing score values.
      """
      y_type = type_of_target(y_true).to_numpy(
          session=session, **(run_kwargs or dict())
      )
      if not (
          y_type == "binary"
          or (y_type == "multiclass" and pos_label is not None)
      ):
          raise ValueError(f"{y_type} format is not supported")
  
      check_consistent_length(
          y_true,
          y_score,
          sample_weight,
          session=session,
          **(run_kwargs or dict()),
      )
      y_true = column_or_1d(y_true)
      y_score = column_or_1d(y_score)
      y_true = assert_all_finite(y_true, check_only=False)
      y_score = assert_all_finite(y_score, check_only=False)
  
      cache_tileables(y_true, y_score)
  
      if sample_weight is not None:
          sample_weight = column_or_1d(sample_weight)
  
      # ensure binary classification if pos_label is not specified
      # classes.dtype.kind in ('O', 'U', 'S') is required to avoid
      # triggering a FutureWarning by calling np.array_equal(a, b)
      # when elements in the two arrays are not comparable.
      classes = mt.unique(y_true, aggregate_size=1).to_numpy(
          session=session, **(run_kwargs or dict())
      )
      if pos_label is None and (
          classes.dtype.kind in ("O", "U", "S")
          or not (
              np.array_equal(classes, [0, 1])
              or np.array_equal(classes, [-1, 1])
              or np.array_equal(classes, [0])
              or np.array_equal(classes, [-1])
              or np.array_equal(classes, [1])
          )
      ):
          classes_repr = ", ".join(repr(c) for c in classes)
          raise ValueError(
              f"y_true takes value in {{{classes_repr}}} and "
              "pos_label is not specified: either make y_true "
              "take value in {{0, 1}} or {{-1, 1}} or "
              "pass pos_label explicitly."
          )
      elif pos_label is None:
          pos_label = 1.0
  
      # make y_true a boolean vector
      y_true = y_true == pos_label
  
      # sort scores and corresponding truth values
      # original implementation adopted from sklearn:
      # """
      # desc_score_indices = mt.argsort(y_score, kind="mergesort")[::-1]
      # y_score = y_score[desc_score_indices]
      # y_true = y_true[desc_score_indices]
      # if sample_weight is not None:
      #     weight = sample_weight[desc_score_indices]
      # else:
      #     weight = 1.0
      # """
      # since fancy indexing is a heavy operation, we try to use DataFrame to sort
      to_sort = [y_score, y_true]
      if sample_weight is not None:
          to_sort.append(sample_weight)
      to_sort = sort_by(to_sort, y_score, ascending=False)
      y_score, y_true = to_sort[:2]
      if sample_weight is not None:
          weight = to_sort[-1]
      else:
          weight = 1.0
  
      # y_score 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 = mt.where(mt.diff(y_score))[0]
      threshold_idxs = mt.r_[distinct_value_indices, y_true.size - 1]
  
      # accumulate the true positives with decreasing threshold
      # raw tps from sklearn implementation
      # we try to perform only one fancy index
      # tps = (y_true * weight).cumsum()[threshold_idxs]
      temp_tps = (y_true * weight).cumsum()
      if sample_weight is not None:
          # express fps as a cumsum to ensure fps is increasing even in
          # the presence of floating point errors
          # fps = ((1 - y_true) * weight).cumsum()[threshold_idxs]
          temp_fps = ((1 - y_true) * weight).cumsum()
          tps, fps, thresholds = mt.stack(
              [temp_tps, temp_fps, y_score]
          )[:, threshold_idxs]
  
      else:
          tps, thresholds = mt.stack([temp_tps, y_score])[
              :, threshold_idxs
          ]
          fps = 1 + threshold_idxs - tps
      return _execute(
          [fps, tps, thresholds],
          session=session,
          **(run_kwargs or dict()),
      )
  
file_path: mars/mars/learn/metrics/_ranking.py
imports: import warnings
  from functools import partial
  import numpy
  from ...None import execute, fetch
  from ...None import tensor
  from ...utils import cache_tileables
  from ..preprocessing import label_binarize
  from ..utils._encode import _encode, _unique
  from ..utils.checks import assert_all_finite
  from ..utils.core import sort_by
  from ..utils.multiclass import type_of_target
  from ..utils.validation import check_array, check_consistent_length, column_or_1d
  from ._base import _average_binary_score, _average_multiclass_ovo_score
label_desc: Use image node_id 2 for calling a global function with example usage: _binary_clf_curve(y_true, y_score, pos_label, sample_weight, session, run_kwargs) and returns: _execute