o
    .wig
                     @   sb   d dl mZ d dlmZmZ d dlmZ d dlmZ 	ddededee	 d	ee
 d
ef
ddZdS )    )Optional)Tensortensor)binary_auroc)"_check_retrieval_functional_inputsNpredstargettop_kmax_fprreturnc                 C   s   t | |\} }|p| jd }t|tr|dkstd| jt|| jd dddd }|| }d|vs7d|vr@td| j| j	dS | | } t
| | |d	S )
a  Compute area under the receiver operating characteristic curve (AUROC) for information retrieval.

    ``preds`` and ``target`` should be of the same shape and live on the same device. If no ``target`` is ``True``,
    ``0`` is returned. ``target`` must be either `bool` or `integers` and ``preds`` must be ``float``,
    otherwise an error is raised.

    Args:
        preds: estimated probabilities of each document to be relevant.
        target: ground truth about each document being relevant or not.
        top_k: consider only the top k elements (default: ``None``, which considers them all)
        max_fpr: If not ``None``, calculates standardized partial AUC over the range ``[0, max_fpr]``.

    Return:
        a single-value tensor with the auroc value of the predictions ``preds`` w.r.t. the labels ``target``.

    Raises:
        ValueError:
            If ``top_k`` is not ``None`` or an integer larger than 0.

    Example:
        >>> from torchmetrics.functional.retrieval import retrieval_auroc
        >>> preds = tensor([0.2, 0.3, 0.5])
        >>> target = tensor([True, False, True])
        >>> retrieval_auroc(preds, target)
        tensor(0.5000)

    r   z,`top_k` has to be a positive integer or NoneT)sorteddim   g        )devicedtype)r
   )r   shape
isinstanceint
ValueErrortopkminr   r   r   r   )r   r   r	   r
   	top_k_idx r   d/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/torchmetrics/functional/retrieval/auroc.pyretrieval_auroc   s    r   )NN)typingr   torchr   r   ,torchmetrics.functional.classification.aurocr   torchmetrics.utilities.checksr   r   floatr   r   r   r   r   <module>   s    