code: def _calculate(y_pred: torch.Tensor, y: torch.Tensor) -> float:
      if not (
          y.ndimension() == y_pred.ndimension() == 1
          and len(y) == len(y_pred)
      ):
          raise AssertionError(
              "y and y_pred must be 1 dimension data with same length."
          )
      y_unique = y.unique()
      if len(y_unique) == 1:
          warnings.warn(
              f"y values can not be all {y_unique.item()}, skip AUC computation and return `Nan`."
          )
          return float("nan")
      if not y_unique.equal(
          torch.tensor([0, 1], dtype=y.dtype, device=y.device)
      ):
          warnings.warn(
              f"y values must be 0 or 1, but in {y_unique.tolist()}, skip AUC computation and return `Nan`."
          )
          return float("nan")
  
      n = len(y)
      indices = y_pred.argsort()
      y = y[indices].cpu().numpy()
      y_pred = y_pred[indices].cpu().numpy()
      nneg = auc = tmp_pos = tmp_neg = 0.0
  
      for i in range(n):
          y_i = cast(float, y[i])
          if i + 1 < n and y_pred[i] == y_pred[i + 1]:
              tmp_pos += y_i
              tmp_neg += 1 - y_i
              continue
          if tmp_pos + tmp_neg > 0:
              tmp_pos += y_i
              tmp_neg += 1 - y_i
              nneg += tmp_neg
              auc += tmp_pos * (nneg - tmp_neg / 2)
              tmp_pos = tmp_neg = 0
              continue
          if y_i == 1:
              auc += nneg
          else:
              nneg += 1
      return auc / (nneg * (n - nneg))
  
file_path: MONAI/monai/metrics/rocauc.py
imports: from __future__ import annotations
  import warnings
  from typing import TYPE_CHECKING, cast
  import numpy
  import torch
  from monai.utils import Average, look_up_option
  from .metric import CumulativeIterationMetric
label_desc: Use image node_id 1 for calling a global function with example usage: _calculate(y_pred, y) and returns: unknown, float, float