§
    ’©ºjt
  ã            	       ó\   — d dl mZ d dlZd dlmZmZ d dlmZ d
dededee         defd	„ZdS )é    )ÚOptionalN)ÚTensorÚtensor)Ú"_check_retrieval_functional_inputsÚpredsÚtargetÚtop_kÚreturnc                 ó   — t          | |¦  «        \  } }|p| j        d         }t          |t          ¦  «        s|dk    rt	          d|› d�¦  «        ‚t          j        | dk    |t          j        |¦  «        ¦  «        }||                      t          || j        d         ¦  «        dd¬¦  «        d                  }| 
                    ¦   «         st          d| j        ¬	¦  «        S t          j        dt          |¦  «        dz   |j        t
          j        ¬
¦  «        |dk             }t          j        t          j        t          |¦  «        |j        t
          j        ¬
¦  «        dz   |¦  «                             ¦   «         S )aX  Compute average precision (for information retrieval), as explained in `IR Average precision`_.

    ``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)

    Return:
        a single-value tensor with the average precision (AP) 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_average_precision
        >>> preds = tensor([0.2, 0.3, 0.5])
        >>> target = tensor([True, False, True])
        >>> retrieval_average_precision(preds, target)
        tensor(0.8333)

    éÿÿÿÿr   zAArgument ``top_k`` has to be a positive integer or None, but got ú.T)ÚsortedÚdimé   g        )Údevice)r   Údtype)r   ÚshapeÚ
isinstanceÚintÚ
ValueErrorÚtorchÚwhereÚ
zeros_likeÚtopkÚminÚsumr   r   ÚarangeÚlenÚfloat32ÚdivÚmean)r   r   r	   Ú	positionss       úƒ/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/retrieval/average_precision.pyÚretrieval_average_precisionr$      sK  € õ6 7°u¸fÑEÔE�M€Eˆ6àÐ$�U”[ ”_€EÝ�e�SÑ!Ô!ð g e¨q¢j jÝÐeÐ]bÐeÐeÐeÑfÔfÐfåŒ[˜ š F­EÔ,<¸VÑ,DÔ,DÑEÔE€FØ�E—J’J�s 5¨%¬+°b¬/Ñ:Ô:À4ÈR�JÑPÔPÐQRÔSÔT€Fà�:Š:‰<Œ<ð 0Ý�c %¤,Ð/Ñ/Ô/Ð/å”˜Q¥ F¡¤¨a¡¸¼ÍUÌ]Ð[Ñ[Ô[Ð\bÐefÒ\fÔg€IÝŒ9•e”l¥3 y¡>¤>¸)Ô:JÕRWÔR_Ð`Ñ`Ô`ÐcdÑdÐgpÑqÔq×vÒvÑxÔxÐxó    )N)	Útypingr   r   r   r   Útorchmetrics.utilities.checksr   r   r$   © r%   r#   ú<module>r)      s›   ðð Ð Ð Ð Ð Ð à €€€Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à LÐ LÐ LÐ LÐ LÐ Lð(yð (y vð (y°vð (yÀhÈsÄmð (yÐ_eð (yð (yð (yð (yð (yð (yr%   