Repository: Lightning-AI/pytorch-lightning
File: pytorch_lightning/metrics/classification/auroc.py (Python)

Code before:
           this argument should not be set as we iteratively change it in the
           range [0,num_classes-1]
       average:
           - ``'macro'`` computes metric for each class and uniformly averages them
           - ``'weighted'`` computes metric for each class and does a weighted-average,
             where each class is weighted by their support (accounts for class imbalance)
           - ``None`` computes and returns the metric per class
       max_fpr:
           If not ``None``, calculates standardized partial AUC over the
           range [0, max_fpr]. Should be a float between 0 and 1.
       compute_on_step:
           Forward only calls ``update()`` and return None if this is set to False. default: True
       dist_sync_on_step:
           Synchronize metric state across processes at each ``forward()``
           before returning the value at the step.
       process_group:
           Specify the process group on which synchronization is called. default: None (which selects the entire world)
       dist_sync_fn:
           Callback that performs the allgather operation on the metric state. When ``None``, DDP
           will be used to perform the allgather

    Raises:
        ValueError:
            If ``average`` is none of ``None``, ``"macro"`` or ``"weighted"``.
        ValueError:
            If max_fpr is not a ``float`` in the range ``0`` < ``max_fpr`` <= ``1``.
        RuntimeError:
            If ``PyTorch version`` is ``below 1.6`` since max_fpr requires ``torch.bucketize``
            which is not available below 1.6.
        ValueError:
            If the mode of data (binary, multi-label, multi-class) changes between batches.

    Example (binary case):

        >>> from pytorch_lightning.metrics import AUROC
        >>> preds = torch.tensor([0.13, 0.26, 0.08, 0.19, 0.34])
        >>> target = torch.tensor([0, 0, 1, 1, 1])
        >>> auroc = AUROC(pos_label=1)
        >>> auroc(preds, target)
        tensor(0.5000)

    Example (multiclass case):

        >>> from pytorch_lightning.metrics import AUROC
        >>> preds = torch.tensor([[0.90, 0.05, 0.05],
        ...                       [0.05, 0.90, 0.05],
        ...                       [0.05, 0.05, 0.90],
        ...                       [0.85, 0.05, 0.10],
        ...                       [0.10, 0.10, 0.80]])
        >>> target = torch.tensor([0, 1, 1, 2, 2])
        >>> auroc = AUROC(num_classes=3)

Review comment (suggestion):
@dipam7 Great addition! Could you follow @rohitgr7's suggestion in https://github.com/PyTorchLightning/pytorch-lightning/pull/6273#discussion_r585467010?
```suggestion
            If ``max_fpr`` is not a ``float`` in the range ``(0, 1]``.
```

Code after:
           this argument should not be set as we iteratively change it in the
           range [0,num_classes-1]
       average:
           - ``'macro'`` computes metric for each class and uniformly averages them
           - ``'weighted'`` computes metric for each class and does a weighted-average,
             where each class is weighted by their support (accounts for class imbalance)
           - ``None`` computes and returns the metric per class
       max_fpr:
           If not ``None``, calculates standardized partial AUC over the
           range [0, max_fpr]. Should be a float between 0 and 1.
       compute_on_step:
           Forward only calls ``update()`` and return None if this is set to False. default: True
       dist_sync_on_step:
           Synchronize metric state across processes at each ``forward()``
           before returning the value at the step.
       process_group:
           Specify the process group on which synchronization is called. default: None (which selects the entire world)
       dist_sync_fn:
           Callback that performs the allgather operation on the metric state. When ``None``, DDP
           will be used to perform the allgather

    Raises:
        ValueError:
            If ``average`` is none of ``None``, ``"macro"`` or ``"weighted"``.
        ValueError:
            If ``max_fpr`` is not a ``float`` in the range ``(0, 1]``.
        RuntimeError:
            If ``PyTorch version`` is ``below 1.6`` since max_fpr requires ``torch.bucketize``
            which is not available below 1.6.
        ValueError:
            If the mode of data (binary, multi-label, multi-class) changes between batches.

    Example (binary case):

        >>> from pytorch_lightning.metrics import AUROC
        >>> preds = torch.tensor([0.13, 0.26, 0.08, 0.19, 0.34])
        >>> target = torch.tensor([0, 0, 1, 1, 1])
        >>> auroc = AUROC(pos_label=1)
        >>> auroc(preds, target)
        tensor(0.5000)

    Example (multiclass case):

        >>> from pytorch_lightning.metrics import AUROC
        >>> preds = torch.tensor([[0.90, 0.05, 0.05],
        ...                       [0.05, 0.90, 0.05],
        ...                       [0.05, 0.05, 0.90],
        ...                       [0.85, 0.05, 0.10],
        ...                       [0.10, 0.10, 0.80]])
        >>> target = torch.tensor([0, 1, 1, 2, 2])
        >>> auroc = AUROC(num_classes=3)