code: def compute_roc_auc(
      y_pred: torch.Tensor,
      y: torch.Tensor,
      average: Average | str = Average.MACRO,
  ) -> np.ndarray | float | npt.ArrayLike:
      """Computes Area Under the Receiver Operating Characteristic Curve (ROC AUC). Referring to:
      `sklearn.metrics.roc_auc_score <https://scikit-learn.org/stable/modules/generated/
      sklearn.metrics.roc_auc_score.html#sklearn.metrics.roc_auc_score>`_.
  
      Args:
          y_pred: input data to compute, typical classification model output.
              the first dim must be batch, if multi-classes, it must be in One-Hot format.
              for example: shape `[16]` or `[16, 1]` for a binary data, shape `[16, 2]` for 2 classes data.
          y: ground truth to compute ROC AUC metric, the first dim must be batch.
              if multi-classes, it must be in One-Hot format.
              for example: shape `[16]` or `[16, 1]` for a binary data, shape `[16, 2]` for 2 classes data.
          average: {``"macro"``, ``"weighted"``, ``"micro"``, ``"none"``}
              Type of averaging performed if not binary classification.
              Defaults to ``"macro"``.
  
              - ``"macro"``: calculate metrics for each label, and find their unweighted mean.
                  This does not take label imbalance into account.
              - ``"weighted"``: calculate metrics for each label, and find their average,
                  weighted by support (the number of true instances for each label).
              - ``"micro"``: calculate metrics globally by considering each element of the label
                  indicator matrix as a label.
              - ``"none"``: the scores for each class are returned.
  
      Raises:
          ValueError: When ``y_pred`` dimension is not one of [1, 2].
          ValueError: When ``y`` dimension is not one of [1, 2].
          ValueError: When ``average`` is not one of ["macro", "weighted", "micro", "none"].
  
      Note:
          ROCAUC expects y to be comprised of 0's and 1's. `y_pred` must be either prob. estimates or confidence values.
  
      """
      y_pred_ndim = y_pred.ndimension()
      y_ndim = y.ndimension()
      if y_pred_ndim not in (1, 2):
          raise ValueError(
              f"Predictions should be of shape (batch_size, num_classes) or (batch_size, ), got {y_pred.shape}."
          )
      if y_ndim not in (1, 2):
          raise ValueError(
              f"Targets should be of shape (batch_size, num_classes) or (batch_size, ), got {y.shape}."
          )
      if y_pred_ndim == 2 and y_pred.shape[1] == 1:
          y_pred = y_pred.squeeze(dim=-1)
          y_pred_ndim = 1
      if y_ndim == 2 and y.shape[1] == 1:
          y = y.squeeze(dim=-1)
  
      if y_pred_ndim == 1:
          return _calculate(y_pred, y)
  
      if y.shape != y_pred.shape:
          raise ValueError(
              f"data shapes of y_pred and y do not match, got {y_pred.shape} and {y.shape}."
          )
  
      average = look_up_option(average, Average)
      if average == Average.MICRO:
          return _calculate(y_pred.flatten(), y.flatten())
      y, y_pred = y.transpose(0, 1), y_pred.transpose(0, 1)
      auc_values = [
          _calculate(y_pred_, y_) for y_pred_, y_ in zip(y_pred, y)
      ]
      if average == Average.NONE:
          return auc_values
      if average == Average.MACRO:
          return np.mean(auc_values)
      if average == Average.WEIGHTED:
          weights = [sum(y_) for y_ in y]
          return np.average(auc_values, weights=weights)  # type: ignore[no-any-return]
      raise ValueError(
          f'Unsupported average: {average}, available options are ["macro", "weighted", "micro", "none"].'
      )
  
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 2 for calling a global function with example usage: compute_roc_auc(y_pred, y, average) and returns: _calculate, _calculate, auc_values, np, np