§
    ’©ºjÌ¹  ã                   ó:  — d dl mZ d dlmZmZmZ d dlZd dlmZmZ d dl	m
Z d dlmZ d dlmZ d dlmZmZ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eef                  dedeeeef         f
d„Z	 d;deeeee         ef                  deej                  dee         fd„Z!	 	 d;deeeee         ef                  dee         ddfd„Z"	 d<dededee         ddfd„Z#	 	 	 d=dededeeeee         ef                  dee         deed                  deeeee         f         fd„Z$dededee         deeeeef         f         fd„Z%dedededeeeeef         f         fd„Z&dedededeeeeef         f         fd„Z'	 d>d eeeeef         f         dee         dedeeeef         fd!„Z(	 	 	 d?dededeeeee         ef                  dee         d#e)deeeef         fd$„Z*	 	 	 d@d%edeeeee         ef                  dee         d&eed'                  ddf
d(„Z+	 d<deded%edee         ddf
d)„Z,	 	 	 d@deded%edeeeee         ef                  dee         d&eed'                  deeeee         f         fd*„Z-	 d<deded%edee         d&eed'                  deeeeef         f         fd+„Z.deded%ededeeeeef         f         f
d,„Z/deded%ededeeeeef         f         f
d-„Z0	 d<d eeeeef         f         d%edee         d&eed'                  deeeeef         eee         ee         ee         f         f         f
d.„Z1	 	 	 	 dAdeded%edeeeee         ef                  d&eed'                  dee         d#e)deeeeef         eee         ee         ee         f         f         fd/„Z2	 	 d;d0edeeeee         ef                  dee         ddfd1„Z3	 d<deded0edee         ddf
d2„Z4	 	 d;deded0edeeeee         ef                  dee         deeeee         f         fd3„Z5deded0edee         deeeeef         f         f
d4„Z6	 d<d eeeeef         f         d0edee         dee         deeeeef         eee         ee         ee         f         f         f
d5„Z7	 	 	 d?deded0edeeeee         ef                  dee         d#e)deeeeef         eee         ee         ee         f         f         fd6„Z8	 	 	 	 	 	 dBdeded7ed8         deeeee         ef                  d%ee         d0ee         d&eed'                  dee         d#e)deeeeef         eee         ee         ee         f         f         fd9„Z9dS )Cé    )ÚSequence)ÚListÚOptionalÚUnionN)ÚTensorÚtensor)Ú
functional)ÚLiteral)Ú_check_same_shape)Ú_safe_divideÚinterpÚnormalize_logits_if_needed)Ú	_bincountÚ_cumsum)ÚClassificationTask)Úrank_zero_warné   ÚpredsÚtargetÚsample_weightsÚ	pos_labelÚreturnc                 ó   — t          j        ¦   «         5  |�6t          |t          ¦  «        s!t	          || j        t           j        ¬¦  «        }| j        |j        k    r| dd…df         } t          j        | d¬¦  «        }| |         } ||         }|�||         nd}t          j	        | dd…         | dd…         z
  ¦  «        d         }t          j        |ddg|                     d¦  «        dz
  ¬	¦  «        }||k                         t           j        ¦  «        }t          ||z  d¬
¦  «        |         }|�t          d|z
  |z  d¬
¦  «        |         }	nd|z   |z
  }	|	|| |         fcddd¦  «         S # 1 swxY w Y   dS )a•  Calculate the TPs and false positives for all unique thresholds in the preds tensor.

    Adapted from
    https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/metrics/_ranking.py.

    Args:
        preds: 1d tensor with predictions
        target: 1d tensor with true values
        sample_weights: a 1d tensor with a weight per sample
        pos_label: integer determining what the positive class in target tensor is

    Returns:
        fps: 1d tensor with false positives for different thresholds
        tps: 1d tensor with true positives for different thresholds
        thresholds: the unique thresholds use for calculating fps and tps

    N)ÚdeviceÚdtyper   T)Ú
descendingg      ð?r   éÿÿÿÿ)Úvalue©Údim)ÚtorchÚno_gradÚ
isinstancer   r   r   ÚfloatÚndimÚargsortÚwhereÚFÚpadÚsizeÚtoÚlongr   )
r   r   r   r   Údesc_score_indicesÚweightÚdistinct_value_indicesÚthreshold_idxsÚtpsÚfpss
             ú�/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/classification/precision_recall_curve.pyÚ_binary_clf_curver4      sÙ  € õ. 
Œ‰Œð /ð /ØÐ%­j¸ÍÑ.PÔ.PÐ%Ý# N¸5¼<ÍuÌ{Ð[Ñ[Ô[ˆNð Œ:˜œÒ#Ð#Ø˜!˜!˜!˜Q˜$”KˆEÝ"œ]¨5¸TÐBÑBÔBÐàÐ(Ô)ˆØÐ*Ô+ˆà7EÐ7Q�Ð 2Ô3Ð3ÐWZˆõ
 "'¤¨U°1°2°2¬Y¸¸sÀ¸s¼Ñ-CÑ!DÔ!DÀQÔ!GÐÝœÐ5¸¸1°vÀVÇ[Â[ÐQRÁ^Ä^ÐVWÑEWÐXÑXÔXˆØ˜IÒ%×)Ò)­%¬*Ñ5Ô5ˆÝ�f˜v‘o¨1Ð-Ñ-Ô-¨nÔ=ˆàÐ%õ ˜1˜v™:¨Ñ/°QÐ7Ñ7Ô7¸ÔGˆCˆCà�nÑ$ sÑ*ˆCà�C˜˜~Ô.Ð.ð;/ð /ð /ð /ñ /ô /ð /ð /ð /ð /ð /ð /øøøð /ð /ð /ð /ð /ð /s   ”EE3Å3E7Å:E7Ú
thresholdsr   c                 ó¶   — t          | t          ¦  «        rt          j        dd| |¬¦  «        S t          | t          ¦  «        rt          j        | |¬¦  «        S | S )z8Convert threshold arg for list and int to tensor format.r   r   ©r   )r#   Úintr!   ÚlinspaceÚlistr   )r5   r   s     r3   Ú_adjust_threshold_argr;   U   s\   € õ �*�cÑ"Ô"ð ?ÝŒ~˜a  J°vÐ>Ñ>Ô>Ð>Ý�*�dÑ#Ô#ð 7ÝŒ|˜J¨vÐ6Ñ6Ô6Ð6ØÐó    Úignore_indexc                 ó   — | �4t          | t          t          t          f¦  «        st	          d| › �¦  «        ‚t          | t          ¦  «        r| dk     rt	          d| › �¦  «        ‚t          | t          ¦  «        r+t          d„ | D ¦   «         ¦  «        st	          d| › �¦  «        ‚t          | t          ¦  «        r| j        dk    st	          d¦  «        ‚|�'t          |t          ¦  «        st	          d	|› �¦  «        ‚dS dS )
z®Validate non tensor input.

    - ``threshold`` has to be None | a 1d tensor | a list of floats in the [0,1] range | an int
    - ``ignore_index`` has to be None or int

    NzdExpected argument `thresholds` to either be an integer, list of floats or tensor of floats, but got é   zQIf argument `thresholds` is an integer, expected it to be larger than 1, but got c              3   ó`   K  — | ])}t          |t          ¦  «        od |cxk    odk    nc V — Œ*dS )r   r   N)r#   r$   )Ú.0Úts     r3   ú	<genexpr>z@_binary_precision_recall_curve_arg_validation.<locals>.<genexpr>s   sG   è è € Ð/iÐ/iÐYZµ
¸1½eÑ0DÔ0DÐ0TÈÈaÈÈÊÈÐSTÊÈÈÈÐ/iÐ/iÐ/iÐ/iÐ/iÐ/ir<   zcIf argument `thresholds` is a list, expected all elements to be floats in the [0,1] range, but got r   zCIf argument `thresholds` is an tensor, expected the tensor to be 1dzLExpected argument `ignore_index` to either be `None` or an integer, but got )r#   r:   r8   r   Ú
ValueErrorÚallr%   )r5   r=   s     r3   Ú-_binary_precision_recall_curve_arg_validationrF   `   s@  € ð Ð¥j°½dÅCÍÐ=PÑ&QÔ&QÐÝð7Ø*4ð7ð 7ñ
ô 
ð 	
õ �*�cÑ"Ô"ð 
 z°A¢~ ~ÝØlÐ`jÐlÐlñ
ô 
ð 	
õ �*�dÑ#Ô#ð 
­CÐ/iÐ/iÐ^hÐ/iÑ/iÔ/iÑ,iÔ,ið 
Ýð%Ø"ð%ð %ñ
ô 
ð 	
õ �*�fÑ%Ô%ð `¨j¬oÀÒ.BÐ.BÝÐ^Ñ_Ô_Ð_àÐ­
°<ÅÑ(EÔ(EÐÝÐvÐhtÐvÐvÑwÔwÐwð  ÐÐÐr<   c                 óÌ  — t          | |¦  «         |                     ¦   «         rt          d|j        › �¦  «        ‚|                      ¦   «         st          d| j        › �¦  «        ‚t	          j        |d¬¦  «        }|€ t	          j        |dk    |dk    z  ¦  «        }n&t	          j        |dk    |dk    z  ||k    z  ¦  «        }|rt          d|› d|€ddgn|g› d	�¦  «        ‚dS )
z½Validate tensor input.

    - tensors have to be of same shape
    - all values in target tensor that are not ignored have to be in {0, 1}
    - that the pred tensor is floating point

    zjExpected argument `target` to be an int or long tensor with ground truth labels but got tensor with dtype zlExpected argument `preds` to be an floating tensor with probability/logit scores, but got tensor with dtype Nr   r   r   z+Detected the following values in `target`: z( but expected only the following values ú.)r   Úis_floating_pointrD   r   r!   ÚuniqueÚanyÚRuntimeError)r   r   r=   Úunique_valuesÚchecks        r3   Ú0_binary_precision_recall_curve_tensor_validationrO      sK  € õ �e˜VÑ$Ô$Ð$à×ÒÑ!Ô!ð 
Ýð9Ø*0¬,ð9ð 9ñ
ô 
ð 	
ð
 ×"Ò"Ñ$Ô$ð 
Ýð8Ø*/¬+ð8ð 8ñ
ô 
ð 	
õ ”L ¨TÐ2Ñ2Ô2€MØÐÝ”	˜=¨AÒ-°-À1Ò2DÑEÑFÔFˆˆå”	˜=¨AÒ-°-À1Ò2DÑEÈÐZfÒIfÑgÑhÔhˆØð 
Ýð[¸-ð [ð [Ø/;Ð/C a¨ V VÈ,Èð[ð [ð [ñ
ô 
ð 	
ð
ð 
r<   ÚsigmoidÚnormalization)rP   Úsoftmaxc                 óÖ   — |                       ¦   «         } |                      ¦   «         }|�||k    }| |         } ||         }t          | |¦  «        } t          || j        ¦  «        }| ||fS )zèConvert all input to the right format.

    - flattens additional dimensions
    - Remove all datapoints that should be ignored
    - Applies sigmoid if pred tensor not in [0,1] range
    - Format thresholds arg to be a tensor

    )Úflattenr   r;   r   )r   r   r5   r=   rQ   Úidxs         r3   Ú%_binary_precision_recall_curve_formatrV   ¤   so   € ð �MŠM‰OŒO€EØ�^Š^ÑÔ€FØÐØ˜Ò$ˆØ�c”
ˆØ˜”ˆå& u¨mÑ<Ô<€Eå& z°5´<Ñ@Ô@€JØ�&˜*Ð$Ð$r<   c                 óv   — |€| |fS |                       ¦   «         dk    rt          }nt          } || ||¦  «        S )úÉReturn the state to calculate the pr-curve with.

    If thresholds is `None` the direct preds and targets are used. If thresholds is not `None` we compute a multi
    threshold confusion matrix.

    NiPÃ  )ÚnumelÚ0_binary_precision_recall_curve_update_vectorizedÚ*_binary_precision_recall_curve_update_loop)r   r   r5   Ú	update_fns       r3   Ú%_binary_precision_recall_curve_updater]   À   sG   € ð ÐØ�fˆ}ÐØ‡{‚{�}„}˜ÒÐÝDˆ	ˆ	å>ˆ	Øˆ9�U˜F JÑ/Ô/Ð/r<   c                 ó®  — t          |¦  «        }|                      d¦  «        |                     d¦  «        k                         ¦   «         }|d|                     ¦   «                              d¦  «        z  z   dt          j        ||j        ¬¦  «        z  z   }t          |                     ¦   «         d|z  ¬¦  «        }|                     |dd¦  «        S )a  Return the multi-threshold confusion matrix to calculate the pr-curve with.

    This implementation is vectorized and faster than `_binary_precision_recall_curve_update_loop` for small
    numbers of samples (up to 50k) but less memory- and time-efficient for more samples.

    r   r   r?   é   r7   ©Ú	minlength)	ÚlenÚ	unsqueezer,   r!   Úaranger   r   rT   Úreshape)r   r   r5   Úlen_tÚpreds_tÚunique_mappingÚbinss          r3   rZ   rZ   Ô   sº   € õ �
‰OŒO€EØ�Š˜rÑ"Ô" j×&:Ò&:¸1Ñ&=Ô&=Ò=×CÒCÑEÔE€GØ˜q 6§;¢;¡=¤=×#:Ò#:¸2Ñ#>Ô#>Ñ>Ñ>ÀÅUÄ\ÐRWÐ`fÔ`mÐEnÑEnÔEnÑAnÑn€NÝ�^×+Ò+Ñ-Ô-¸¸U¹ÐCÑCÔC€DØ�<Š<˜˜q !Ñ$Ô$Ð$r<   c                 óè  — t          |¦  «        }|dk    }|                     |ddft          j        ¬¦  «        }t	          |¦  «        D ]g}| ||         k    }||z                       ¦   «         ||ddf<   | |z                       ¦   «         ||ddf<   || z                       ¦   «         ||ddf<   Œht          |¦  «        |dd…ddf         z
  |dd…ddf         z
  |dd…ddf         z
  |dd…ddf<   |S )a  Return the multi-threshold confusion matrix to calculate the pr-curve with.

    This implementation loops over thresholds and is more memory-efficient than
    `_binary_precision_recall_curve_update_vectorized`. However, it is slowwer for small
    numbers of samples (up to 50k).

    r   r?   ©r   r   N)rb   Ú	new_emptyr!   Úint64ÚrangeÚsum)r   r   r5   rf   ÚconfmatÚirg   s          r3   r[   r[   æ   s&  € õ �
‰OŒO€EØ�qŠ[€FØ×"Ò" E¨1¨a =½¼Ð"ÑDÔD€Gå�5‰\Œ\ð 7ð 7ˆØ˜: aœ=Ò(ˆØ" WÑ,×1Ò1Ñ3Ô3ˆ��1�a�ÑØ$˜W¨Ñ/×4Ò4Ñ6Ô6ˆ��1�a�ÑØ" w hÑ/×4Ò4Ñ6Ô6ˆ��1�a�ÑÐÝ˜7‘|”| g¨a¨a¨a°°A¨gÔ&6Ñ6¸ÀÀÀÀAÀqÀÔ9IÑIÈGÐTUÐTUÐTUÐWXÐZ[ÐT[ÔL\Ñ\€GˆAˆAˆAˆq�!ˆGÑØ€Nr<   Ústatec                 óD  — t          | t          ¦  «        rÂ|�À| dd…ddf         }| dd…ddf         }| dd…ddf         }t          |||z   d¬¦  «        }t          |||z   d¬¦  «        }t          j        |t          j        d|j        |j        ¬¦  «        g¦  «        }t          j        |t          j        d|j        |j        ¬¦  «        g¦  «        }|||fS t          | d         | d         |¬¦  «        \  }}}|||z   z  }||d         z  }| d         dk     
                    ¦   «         r)t          d	t          ¦  «         t          j        |¦  «        }t          j        |                     d¦  «        t          j        d|j        |j        ¬¦  «        g¦  «        }t          j        |                     d¦  «        t          j        d|j        |j        ¬¦  «        g¦  «        }|                     d¦  «                             ¦   «                              ¦   «         }|||fS )
zèCompute the final pr-curve.

    If state is a single tensor, then we calculate the pr-curve from a multi threshold confusion matrix. If state is
    original input, then we dynamically compute the binary classification curve.

    Nr   r   Únan©Úzero_division©r   r   )r   r   zcNo positive samples found in target, recall is undefined. Setting recall to one for all thresholds.)r#   r   r   r!   ÚcatÚonesr   r   Úzerosr4   rE   r   ÚUserWarningÚ	ones_likeÚflipÚdetachÚclone)rr   r5   r   r1   r2   ÚfnsÚ	precisionÚrecalls           r3   Ú&_binary_precision_recall_curve_computerƒ   ÿ   s  € õ �%�Ñ Ô ð - ZÐ%;Ø�A�A�A�q˜!�GŒnˆØ�A�A�A�q˜!�GŒnˆØ�A�A�A�q˜!�GŒnˆÝ   c¨C¡i¸uÐEÑEÔEˆ	Ý˜c 3¨¡9¸EÐBÑBÔBˆÝ”I˜y­%¬*°Q¸i¼oÐV_ÔVfÐ*gÑ*gÔ*gÐhÑiÔiˆ	Ý”˜F¥E¤K°¸¼ÈfÌmÐ$\Ñ$\Ô$\Ð]Ñ^Ô^ˆØ˜& *Ð,Ð,å,¨U°1¬X°u¸Q´xÈ9ÐUÑUÔUÑ€CˆˆjØ�s˜S‘yÑ!€IØ�3�r”7‰]€FØˆaŒ�AŠ×ÒÑÔð )ÝØqÝñ	
ô 	
ð 	
õ ” Ñ(Ô(ˆõ ”	˜9Ÿ>š>¨!Ñ,Ô,­e¬j¸À)Ä/ÐZcÔZjÐ.kÑ.kÔ.kÐlÑmÔm€IÝŒY˜Ÿš A™œ­¬°A¸V¼\ÐRXÔR_Ð(`Ñ(`Ô(`ÐaÑbÔb€FØ—’ Ñ#Ô#×*Ò*Ñ,Ô,×2Ò2Ñ4Ô4€JØ�f˜jÐ(Ð(r<   TÚvalidate_argsc                 ó¶   — |r!t          ||¦  «         t          | ||¦  «         t          | |||¦  «        \  } }}t          | ||¦  «        }t	          ||¦  «        S )aŒ  Compute the precision-recall curve for binary tasks.

    The curve consist of multiple pairs of precision and recall values evaluated at different thresholds, such that the
    tradeoff between the two values can been seen.

    Accepts the following input tensors:

    - ``preds`` (float tensor): ``(N, ...)``. Preds should be a tensor containing probabilities or logits for each
      observation. If preds has values outside [0,1] range we consider the input to be logits and will auto apply
      sigmoid per element.
    - ``target`` (int tensor): ``(N, ...)``. Target should be a tensor containing ground truth labels, and therefore
      only contain {0,1} values (except if `ignore_index` is specified). The value 1 always encodes the positive class.

    Additional dimension ``...`` will be flattened into the batch dimension.

    The implementation both supports calculating the metric in a non-binned but accurate version and a binned version
    that is less accurate but more memory efficient. Setting the `thresholds` argument to `None` will activate the
    non-binned  version that uses memory of size :math:`\mathcal{O}(n_{samples})` whereas setting the `thresholds`
    argument to either an integer, list or a 1d tensor will use a binned version that uses memory of
    size :math:`\mathcal{O}(n_{thresholds})` (constant memory).

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        thresholds:
            Can be one of:

            - If set to `None`, will use a non-binned approach where thresholds are dynamically calculated from
              all the data. Most accurate but also most memory consuming approach.
            - If set to an `int` (larger than 1), will use that number of thresholds linearly spaced from
              0 to 1 as bins for the calculation.
            - If set to an `list` of floats, will use the indicated thresholds in the list as bins for the calculation
            - If set to an 1d `tensor` of floats, will use the indicated thresholds in the tensor as
              bins for the calculation.

        ignore_index:
            Specifies a target value that is ignored and does not contribute to the metric calculation
        validate_args: bool indicating if input arguments and tensors should be validated for correctness.
            Set to ``False`` for faster computations.

    Returns:
        (tuple): a tuple of 3 tensors containing:

        - precision: an 1d tensor of size (n_thresholds+1, ) with precision values
        - recall: an 1d tensor of size (n_thresholds+1, ) with recall values
        - thresholds: an 1d tensor of size (n_thresholds, ) with increasing threshold values

    Example:
        >>> from torchmetrics.functional.classification import binary_precision_recall_curve
        >>> preds = torch.tensor([0, 0.5, 0.7, 0.8])
        >>> target = torch.tensor([0, 1, 1, 0])
        >>> binary_precision_recall_curve(preds, target, thresholds=None)  # doctest: +NORMALIZE_WHITESPACE
        (tensor([0.5000, 0.6667, 0.5000, 0.0000, 1.0000]),
         tensor([1.0000, 1.0000, 0.5000, 0.0000, 0.0000]),
         tensor([0.0000, 0.5000, 0.7000, 0.8000]))
        >>> binary_precision_recall_curve(preds, target, thresholds=5)  # doctest: +NORMALIZE_WHITESPACE
        (tensor([0.5000, 0.6667, 0.6667, 0.0000, nan, 1.0000]),
         tensor([1., 1., 1., 0., 0., 0.]),
         tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000]))

    )rF   rO   rV   r]   rƒ   )r   r   r5   r=   r„   rr   s         r3   Úbinary_precision_recall_curver†   &  sm   € ðH ð VÝ5°jÀ,ÑOÔOÐOÝ8¸ÀÈÑUÔUÐUÝ EÀeÈVÐU_ÐamÑ nÔ nÑ€Eˆ6�:Ý1°%¸ÀÑLÔL€EÝ1°%¸ÑDÔDÐDr<   Únum_classesÚaverage)ÚmicroÚmacroc                 ó¬   — t          | t          ¦  «        r| dk     rt          d| › �¦  «        ‚|dvrt          d|› �¦  «        ‚t          ||¦  «         dS )zãValidate non tensor input.

    - ``num_classes`` has to be an int larger than 1
    - ``threshold`` has to be None | a 1d tensor | a list of floats in the [0,1] range | an int
    - ``ignore_index`` has to be None or int

    r?   zHExpected argument `num_classes` to be an integer larger than 1, but got )Nr‰   rŠ   zKExpected argument `average` to be one of None, 'micro' or 'macro', but got N)r#   r8   rD   rF   )r‡   r5   r=   rˆ   s       r3   Ú1_multiclass_precision_recall_curve_arg_validationrŒ   r  sq   € õ �k¥3Ñ'Ô'ð s¨;¸ª?¨?ÝÐqÐdoÐqÐqÑrÔrÐrØÐ.Ð.Ð.ÝÐpÐgnÐpÐpÑqÔqÐqÝ1°*¸lÑKÔKÐKÐKÐKr<   c                 óÖ  — | j         |j         dz   k    st          d| j         › d|j         › �¦  «        ‚|                     ¦   «         rt          d|j        › �¦  «        ‚|                      ¦   «         st          d| j        › �¦  «        ‚| j        d         |k    r!t          d| j        d         › d|› d�¦  «        ‚| j        d         |j        d         k    s | j        d	d
…         |j        dd
…         k    rt          d| j        › d|j        › �¦  «        ‚t          t          j        |d
¬¦  «        ¦  «        }|€||k    n||dz   k    }|rt          d|€|n|dz   › d|› d�¦  «        ‚d
S )a"  Validate tensor input.

    - target should have one more dimension than preds and all dimensions except for preds.shape[1] should match
    exactly. preds.shape[1] should have size equal to number of classes
    - all values in target tensor that are not ignored have to be in {0, 1}

    r   zBExpected `preds` to have one more dimension than `target` but got z and zRExpected argument `target` to be an int or long tensor, but got tensor with dtype z/Expected `preds` to be a float tensor, but got zGExpected `preds.shape[1]` to be equal to the number of classes but got rH   r   r?   NziExpected the shape of `preds` should be (N, C, ...) and the shape of `target` should be (N, ...) but got r   zJDetected more unique values in `target` than `num_classes`. Expected only z but found z in `target`.)	r%   rD   rI   r   Úshaperb   r!   rJ   rL   )r   r   r‡   r=   Únum_unique_valuesrN   s         r3   Ú4_multiclass_precision_recall_curve_tensor_validationr�   †  sû  € ð Œ:˜œ q™Ò(Ð(ÝØoÐQVÔQ[ÐoÐoÐbhÔbmÐoÐoñ
ô 
ð 	
ð ×ÒÑ!Ô!ð 
ÝØoÐagÔamÐoÐoñ
ô 
ð 	
ð ×"Ò"Ñ$Ô$ð ZÝÐXÈ5Ì;ÐXÐXÑYÔYÐYØ„{�1„~˜Ò$Ð$Ýð8Ø”K ”Nð8ð 8Ø)4ð8ð 8ð 8ñ
ô 
ð 	
ð „{�1„~˜œ aœÒ(Ð(¨E¬K¸¸¸¬O¸v¼|ÈAÈBÈBÔ?OÒ,OÐ,OÝð9Øœð9ð 9Ø*0¬,ð9ð 9ñ
ô 
ð 	
õ
 �EœL¨°TÐ:Ñ:Ô:Ñ;Ô;ÐØ/;Ð/CÐ Ò+Ð+ÐIZÐ]hÐklÑ]lÒIl€EØð 
Ýð0Ø*Ð2ˆ{ˆ{¸Àa¹ð0ð 0à ð0ð 0ð 0ñ
ô 
ð 	
ð
ð 
r<   c                 ó°  — |                       dd¦  «                             |d¦  «        j        } |                     ¦   «         }|�||k    }| |         } ||         }t	          | d¦  «        } |dk    rL|                      ¦   «         } t
          j        j                             ||¬¦  «                             ¦   «         }t          || j
        ¦  «        }| ||fS )zèConvert all input to the right format.

    - flattens additional dimensions
    - Remove all datapoints that should be ignored
    - Applies softmax if pred tensor not in [0,1] range
    - Format thresholds arg to be a tensor

    r   r   r   NrR   r‰   ©r‡   )Ú	transposere   ÚTrT   r   r!   Únnr	   Úone_hotr;   r   )r   r   r‡   r5   r=   rˆ   rU   s          r3   Ú)_multiclass_precision_recall_curve_formatr—   ¯  sÉ   € ð  �OŠO˜A˜qÑ!Ô!×)Ò)¨+°rÑ:Ô:Ô<€EØ�^Š^ÑÔ€FàÐØ˜Ò$ˆØ�c”
ˆØ˜”ˆå& u¨iÑ8Ô8€Eà�'ÒÐØ—’‘”ˆÝ”Ô$×,Ò,¨VÀÐ,ÑMÔM×UÒUÑWÔWˆå& z°5´<Ñ@Ô@€JØ�&˜*Ð$Ð$r<   c                 ó¬   — |€| |fS |dk    rt          | ||¦  «        S |                      ¦   «         |z  dk    rt          }nt          } || |||¦  «        S )rX   Nr‰   i@B )r]   rY   Ú4_multiclass_precision_recall_curve_update_vectorizedÚ._multiclass_precision_recall_curve_update_loop)r   r   r‡   r5   rˆ   r\   s         r3   Ú)_multiclass_precision_recall_curve_updater›   Ñ  sk   € ð ÐØ�fˆ}ÐØ�'ÒÐÝ4°U¸FÀJÑOÔOÐOØ‡{‚{�}„}�{Ñ" iÒ/Ð/ÝHˆ	ˆ	åBˆ	Øˆ9�U˜F K°Ñ<Ô<Ð<r<   c                 óÀ  — t          |¦  «        }|                      d¦  «        |                     d¦  «                             d¦  «        k                         ¦   «         }t          j        j                             ||¬¦  «        }|d|                     ¦   «                              d¦  «        z  z   }|dt          j        || j        ¬¦  «                             d¦  «                             d¦  «        z  z  }|d|z  t          j        || j        ¬¦  «        z  z  }t          | 
                    ¦   «         d|z  |z  ¬¦  «        }|                     ||dd¦  «        S )a  Return the multi-threshold confusion matrix to calculate the pr-curve with.

    This implementation is vectorized and faster than `_binary_precision_recall_curve_update_loop` for small
    numbers of samples but less memory- and time-efficient for more samples.

    r   r   r’   r?   r_   r7   r`   )rb   rc   r,   r!   r•   r	   r–   rd   r   r   rT   re   )	r   r   r‡   r5   rf   rg   Útarget_trh   ri   s	            r3   r™   r™   é  s0  € õ �
‰OŒO€EØ�Š˜rÑ"Ô" j×&:Ò&:¸1Ñ&=Ô&=×&GÒ&GÈÑ&JÔ&JÒJ×PÒPÑRÔR€GÝŒxÔ"×*Ò*¨6¸{Ð*ÑKÔK€HØ˜q 8§=¢=¡?¤?×#<Ò#<¸RÑ#@Ô#@Ñ@Ñ@€NØ�a�%œ, {¸5¼<ÐHÑHÔH×RÒRÐSTÑUÔU×_Ò_Ð`bÑcÔcÑcÑc€NØ�a˜+‘o­¬°UÀ5Ä<Ð(PÑ(PÔ(PÑPÑP€NÝ�^×+Ò+Ñ-Ô-¸¸[¹È5Ñ9PÐQÑQÔQ€DØ�<Š<˜˜{¨A¨qÑ1Ô1Ð1r<   c                 ó`  — t          |¦  «        }t          j        j                             ||¬¦  «        }|                     ||ddft          j        ¬¦  «        }t          |¦  «        D ]v}| ||         k    }||z                       d¬¦  «        ||dd…ddf<   | |z                       d¬¦  «        ||dd…ddf<   || z                       d¬¦  «        ||dd…ddf<   Œwt          |¦  «        |dd…dd…ddf         z
  |dd…dd…ddf         z
  |dd…dd…ddf         z
  |dd…dd…ddf<   |S )zøReturn the state to calculate the pr-curve with.

    This implementation loops over thresholds and is more memory-efficient than
    `_binary_precision_recall_curve_update_vectorized`. However, it is slowwer for small
    numbers of samples.

    r’   r?   rk   r   r   Nr   )	rb   r!   r•   r	   r–   rl   rm   rn   ro   )	r   r   r‡   r5   rf   r�   rp   rq   rg   s	            r3   rš   rš   ÿ  s}  € õ �
‰OŒO€EÝŒxÔ"×*Ò*¨6¸{Ð*ÑKÔK€HØ×"Ò" E¨;¸¸1Ð#=ÅUÄ[Ð"ÑQÔQ€Gå�5‰\Œ\ð Að AˆØ˜: aœ=Ò(ˆØ'¨'Ñ1×6Ò6¸1Ð6Ñ=Ô=ˆ��1�1�1�a˜�
ÑØ!) 	¨WÑ4×9Ò9¸aÐ9Ñ@Ô@ˆ��1�1�1�a˜�
ÑØ'¨G¨8Ñ4×9Ò9¸aÐ9Ñ@Ô@ˆ��1�1�1�a˜�
ÑÐÝ˜g™,œ,¨°°°°A°A°A°q¸!°Ô)<Ñ<¸wÀqÀqÀqÈ!È!È!ÈQÐPQÀzÔ?RÑRÐU\Ð]^Ð]^Ð]^Ð`aÐ`aÐ`aÐcdÐfgÐ]gÔUhÑh€GˆAˆAˆAˆqˆqˆq�!�QˆJÑØ€Nr<   c           	      ó6  — |dk    rt          | |¦  «        S t          | t          ¦  «        rÛ|�Ù| dd…dd…ddf         }| dd…dd…ddf         }| dd…dd…ddf         }t          |||z   d¬¦  «        }t          |||z   d¬¦  «        }t	          j        |t	          j        d||j        |j        ¬¦  «        g¦  «        }t	          j        |t	          j	        d||j        |j        ¬¦  «        g¦  «        }|j
        }|j
        }|}	d}
n•g g g }}}t          |¦  «        D ]}}t          | d         dd…|f         | d         fd|¬	¦  «        }|                     |d         ¦  «         |                     |d         ¦  «         |                     |d
         ¦  «         Œ~d}
|dk    rí|
r|	                     |¦  «        nt	          j        |d¦  «        }	|	                     ¦   «         j        }	|
r|                     ¦   «         nt	          j        |d¦  «        }|                     ¦   «         j        }t	          j        |¦  «        }t          |¦  «        D ]6}|t%          ||
r||         n||         |
r||         n||         ¦  «        z  }Œ7||z  }|||	fS |
r|||	fS |||fS )úüCompute the final pr-curve.

    If state is a single tensor, then we calculate the pr-curve from a multi threshold confusion matrix. If state is
    original input, then we dynamically compute the binary classification curve in an iterative way.

    r‰   Nr   r   rt   ru   rw   T©r5   r   r?   FrŠ   )rƒ   r#   r   r   r!   rx   ry   r   r   rz   r”   rn   ÚappendÚrepeatÚsortÚvaluesrT   Ú
zeros_liker   )rr   r‡   r5   rˆ   r1   r2   r€   r�   r‚   ÚthresÚtensor_stateÚprecision_listÚrecall_listÚ
thres_listrq   ÚresÚmean_precisionÚmean_recalls                     r3   Ú*_multiclass_precision_recall_curve_computer¯     sñ  € ð �'ÒÐÝ5°e¸ZÑHÔHÐHå�%�Ñ Ô ð  ZÐ%;Ø�A�A�A�q�q�q˜!˜Q�JÔˆØ�A�A�A�q�q�q˜!˜Q�JÔˆØ�A�A�A�q�q�q˜!˜Q�JÔˆÝ   c¨C¡i¸uÐEÑEÔEˆ	Ý˜c 3¨¡9¸EÐBÑBÔBˆÝ”I˜y­%¬*°Q¸È9Ì?ÐclÔcsÐ*tÑ*tÔ*tÐuÑvÔvˆ	Ý”˜F¥E¤K°°;ÀfÄlÐ[aÔ[hÐ$iÑ$iÔ$iÐjÑkÔkˆØ”Kˆ	Ø”ˆØˆØˆˆà24°b¸" Z˜ˆÝ�{Ñ#Ô#ð 	&ð 	&ˆAÝ8¸%À¼(À1À1À1ÀaÀ4¼.È%ÐPQÌ(Ð9SÐ`dÐpqÐrÑrÔrˆCØ×!Ò! # a¤&Ñ)Ô)Ð)Ø×Ò˜s 1œvÑ&Ô&Ð&Ø×Ò˜c !œfÑ%Ô%Ð%Ð%Øˆà�'ÒÐØ-9ÐW�—’˜[Ñ)Ô)Ð)½u¼yÈÐUVÑ?WÔ?WˆØ—
’
‘”Ô#ˆØ0<Ð^˜×*Ò*Ñ,Ô,Ð,Å%Ä)ÈNÐ\]ÑB^ÔB^ˆØ'×,Ò,Ñ.Ô.Ô5ˆÝÔ& ~Ñ6Ô6ˆÝ�{Ñ#Ô#ð 	ð 	ˆAØ�6ØØ ,ÐC�	˜!”�°.ÀÔ2CØ)Ð=��q”	�	¨{¸1¬~ñô ñ ˆKˆKð
 	�{Ñ"ˆØ˜{¨EÐ1Ð1àð (Ø˜& %Ð'Ð'Ø˜;¨
Ð2Ð2r<   c                 óÈ   — |r$t          ||||¦  «         t          | |||¦  «         t          | |||||¦  «        \  } }}t          | ||||¦  «        }t	          ||||¦  «        S )aù  Compute the precision-recall curve for multiclass tasks.

    The curve consist of multiple pairs of precision and recall values evaluated at different thresholds, such that the
    tradeoff between the two values can been seen.

    Accepts the following input tensors:

    - ``preds`` (float tensor): ``(N, C, ...)``. Preds should be a tensor containing probabilities or logits for each
      observation. If preds has values outside [0,1] range we consider the input to be logits and will auto apply
      softmax per sample.
    - ``target`` (int tensor): ``(N, ...)``. Target should be a tensor containing ground truth labels, and therefore
      only contain values in the [0, n_classes-1] range (except if `ignore_index` is specified).

    Additional dimension ``...`` will be flattened into the batch dimension.

    The implementation both supports calculating the metric in a non-binned but accurate version and a binned version
    that is less accurate but more memory efficient. Setting the `thresholds` argument to `None` will activate the
    non-binned  version that uses memory of size :math:`\mathcal{O}(n_{samples})` whereas setting the `thresholds`
    argument to either an integer, list or a 1d tensor will use a binned version that uses memory of
    size :math:`\mathcal{O}(n_{thresholds} \times n_{classes})` (constant memory).

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        num_classes: Integer specifying the number of classes
        thresholds:
            Can be one of:

            - If set to `None`, will use a non-binned approach where thresholds are dynamically calculated from
              all the data. Most accurate but also most memory consuming approach.
            - If set to an `int` (larger than 1), will use that number of thresholds linearly spaced from
              0 to 1 as bins for the calculation.
            - If set to an `list` of floats, will use the indicated thresholds in the list as bins for the calculation
            - If set to an 1d `tensor` of floats, will use the indicated thresholds in the tensor as
              bins for the calculation.

        average:
            If aggregation of curves should be applied. By default, the curves are not aggregated and a curve for
            each class is returned. If `average` is set to ``"micro"``, the metric will aggregate the curves by one hot
            encoding the targets and flattening the predictions, considering all classes jointly as a binary problem.
            If `average` is set to ``"macro"``, the metric will aggregate the curves by first interpolating the curves
            from each class at a combined set of thresholds and then average over the classwise interpolated curves.
            See `averaging curve objects`_ for more info on the different averaging methods.
        ignore_index:
            Specifies a target value that is ignored and does not contribute to the metric calculation
        validate_args: bool indicating if input arguments and tensors should be validated for correctness.
            Set to ``False`` for faster computations.

    Returns:
        (tuple): a tuple of either 3 tensors or 3 lists containing

        - precision: if `thresholds=None` a list for each class is returned with an 1d tensor of size (n_thresholds+1, )
          with precision values (length may differ between classes). If `thresholds` is set to something else,
          then a single 2d tensor of size (n_classes, n_thresholds+1) with precision values is returned.
        - recall: if `thresholds=None` a list for each class is returned with an 1d tensor of size (n_thresholds+1, )
          with recall values (length may differ between classes). If `thresholds` is set to something else,
          then a single 2d tensor of size (n_classes, n_thresholds+1) with recall values is returned.
        - thresholds: if `thresholds=None` a list for each class is returned with an 1d tensor of size (n_thresholds, )
          with increasing threshold values (length may differ between classes). If `threshold` is set to something else,
          then a single 1d tensor of size (n_thresholds, ) is returned with shared threshold values for all classes.

    Example:
        >>> from torchmetrics.functional.classification import multiclass_precision_recall_curve
        >>> preds = torch.tensor([[0.75, 0.05, 0.05, 0.05, 0.05],
        ...                       [0.05, 0.75, 0.05, 0.05, 0.05],
        ...                       [0.05, 0.05, 0.75, 0.05, 0.05],
        ...                       [0.05, 0.05, 0.05, 0.75, 0.05]])
        >>> target = torch.tensor([0, 1, 3, 2])
        >>> precision, recall, thresholds = multiclass_precision_recall_curve(
        ...    preds, target, num_classes=5, thresholds=None
        ... )
        >>> precision  # doctest: +NORMALIZE_WHITESPACE
        [tensor([0.2500, 1.0000, 1.0000]), tensor([0.2500, 1.0000, 1.0000]), tensor([0.2500, 0.0000, 1.0000]),
         tensor([0.2500, 0.0000, 1.0000]), tensor([0., 1.])]
        >>> recall
        [tensor([1., 1., 0.]), tensor([1., 1., 0.]), tensor([1., 0., 0.]), tensor([1., 0., 0.]), tensor([nan, 0.])]
        >>> thresholds
        [tensor([0.0500, 0.7500]), tensor([0.0500, 0.7500]), tensor([0.0500, 0.7500]), tensor([0.0500, 0.7500]),
         tensor([0.0500])]
        >>> multiclass_precision_recall_curve(
        ...     preds, target, num_classes=5, thresholds=5
        ... )  # doctest: +NORMALIZE_WHITESPACE
        (tensor([[0.2500, 1.0000, 1.0000, 1.0000,    nan, 1.0000],
                 [0.2500, 1.0000, 1.0000, 1.0000,    nan, 1.0000],
                 [0.2500, 0.0000, 0.0000, 0.0000,    nan, 1.0000],
                 [0.2500, 0.0000, 0.0000, 0.0000,    nan, 1.0000],
                 [0.0000,    nan,    nan,    nan,    nan, 1.0000]]),
         tensor([[1., 1., 1., 1., 0., 0.],
                 [1., 1., 1., 1., 0., 0.],
                 [1., 0., 0., 0., 0., 0.],
                 [1., 0., 0., 0., 0., 0.],
                 [nan, nan, nan, nan, nan, 0.]]),
         tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000]))

    )rŒ   r�   r—   r›   r¯   )r   r   r‡   r5   rˆ   r=   r„   rr   s           r3   Ú!multiclass_precision_recall_curver±   Q  s�   € ðP ð gÝ9¸+ÀzÐS_ÐahÑiÔiÐiÝ<¸UÀFÈKÐYeÑfÔfÐfÝ IØØØØØØñ!ô !Ñ€Eˆ6�:õ 6°e¸VÀ[ÐR\Ð^eÑfÔf€EÝ5°e¸[È*ÐV]Ñ^Ô^Ð^r<   Ú
num_labelsc                 ó(   — t          | ||¦  «         dS )zâValidate non tensor input.

    - ``num_labels`` has to be an int larger than 1
    - ``threshold`` has to be None | a 1d tensor | a list of floats in the [0,1] range | an int
    - ``ignore_index`` has to be None or int

    N)rŒ   )r²   r5   r=   s      r3   Ú1_multilabel_precision_recall_curve_arg_validationr´   È  s   € õ 6°jÀ*ÈlÑ[Ô[Ð[Ð[Ð[r<   c                 óŠ   — t          | ||¦  «         | j        d         |k    r t          d| j        d         › d|› �¦  «        ‚dS )zóValidate tensor input.

    - tensors have to be of same shape
    - preds.shape[1] is equal to the number of labels
    - all values in target tensor that are not ignored have to be in {0, 1}
    - that the pred tensor is floating point

    r   zaExpected both `target.shape[1]` and `preds.shape[1]` to be equal to the number of labels but got z and expected N)rO   rŽ   rD   )r   r   r²   r=   s       r3   Ú4_multilabel_precision_recall_curve_tensor_validationr¶   ×  sk   € õ 5°U¸FÀLÑQÔQÐQØ„{�1„~˜Ò#Ð#ÝðCØœ AœðCð CØ6@ðCð Cñ
ô 
ð 	
ð $Ð#r<   c                 óæ  — |                       dd¦  «                             |d¦  «        j        } |                      dd¦  «                             |d¦  «        j        }t          | d¦  «        } t	          || j        ¦  «        }|�h|�f|                      ¦   «         } |                     ¦   «         }||k    }d|z  |�t          |¦  «        ndz  | |<   d|z  |�t          |¦  «        ndz  ||<   | ||fS )zûConvert all input to the right format.

    - flattens additional dimensions
    - Mask all datapoints that should be ignored with negative values
    - Applies sigmoid if pred tensor not in [0,1] range
    - Format thresholds arg to be a tensor

    r   r   r   rP   Néüÿÿÿ)r“   re   r”   r   r;   r   r   rb   )r   r   r²   r5   r=   rU   s         r3   Ú)_multilabel_precision_recall_curve_formatr¹   ê  sò   € ð �OŠO˜A˜qÑ!Ô!×)Ò)¨*°bÑ9Ô9Ô;€EØ×Ò˜a Ñ#Ô#×+Ò+¨J¸Ñ;Ô;Ô=€Få& u¨iÑ8Ô8€Eå& z°5´<Ñ@Ô@€JØÐ JÐ$:Ø—’‘”ˆØ—’‘”ˆà˜Ò$ˆØ˜*‘_¸:Ð;Q­¨J©¬¨ÐWXÑYˆˆc‰
Ø˜:‘o¸JÐ<R­¨Z©¬¨ÐXYÑZˆˆs‰à�&˜*Ð$Ð$r<   c                 ót  — |€| |fS t          |¦  «        }|                      d¦  «        |                     d¦  «                             d¦  «        k                         ¦   «         }|d|                     ¦   «                              d¦  «        z  z   }|dt          j        || j        ¬¦  «                             d¦  «                             d¦  «        z  z  }|d|z  t          j        || j        ¬¦  «        z  z  }||dk             }t          |d|z  |z  ¬¦  «        }|                     ||dd¦  «        S )rX   Nr   r   r?   r_   r7   r`   )rb   rc   r,   r!   rd   r   r   re   )r   r   r²   r5   rf   rg   rh   ri   s           r3   Ú)_multilabel_precision_recall_curve_updater»   
  s&  € ð ÐØ�fˆ}ÐÝ�
‰OŒO€Eà�Š˜rÑ"Ô" j×&:Ò&:¸1Ñ&=Ô&=×&GÒ&GÈÑ&JÔ&JÒJ×PÒPÑRÔR€GØ˜q 6§;¢;¡=¤=×#:Ò#:¸2Ñ#>Ô#>Ñ>Ñ>€NØ�a�%œ, z¸%¼,ÐGÑGÔG×QÒQÐRSÑTÔT×^Ò^Ð_aÑbÔbÑbÑb€NØ�a˜*‘n¥u¤|°EÀ%Ä,Ð'OÑ'OÔ'OÑOÑO€NØ# N°aÒ$7Ô8€NÝ�^¨q°:©~ÀÑ/EÐFÑFÔF€DØ�<Š<˜˜z¨1¨aÑ0Ô0Ð0r<   c           	      óZ  — t          | t          ¦  «        r×|�Õ| dd…dd…ddf         }| dd…dd…ddf         }| dd…dd…ddf         }t          |||z   d¬¦  «        }t          |||z   d¬¦  «        }t          j        |t          j        d||j        |j        ¬¦  «        g¦  «        }t          j        |t          j        d||j        |j        ¬¦  «        g¦  «        }|j	        |j	        |fS g g g }}
}	t          |¦  «        D ]¥}| d         dd…|f         }| d         dd…|f         }|�||k    }||          }||          }t          ||fdd¬¦  «        }|	                     |d         ¦  «         |
                     |d         ¦  «         |                     |d         ¦  «         Œ¦|	|
|fS )	r    Nr   r   rt   ru   rw   r¡   r?   )r#   r   r   r!   rx   ry   r   r   rz   r”   rn   rƒ   r¢   )rr   r²   r5   r=   r1   r2   r€   r�   r‚   r©   rª   r«   rq   r   r   rU   r¬   s                    r3   Ú*_multilabel_precision_recall_curve_computer½   #  sê  € õ �%�Ñ Ô ð 1 ZÐ%;Ø�A�A�A�q�q�q˜!˜Q�JÔˆØ�A�A�A�q�q�q˜!˜Q�JÔˆØ�A�A�A�q�q�q˜!˜Q�JÔˆÝ   c¨C¡i¸uÐEÑEÔEˆ	Ý˜c 3¨¡9¸EÐBÑBÔBˆÝ”I˜y­%¬*°Q¸
È)Ì/ÐbkÔbrÐ*sÑ*sÔ*sÐtÑuÔuˆ	Ý”˜F¥E¤K°°:ÀVÄ\ÐZ`ÔZgÐ$hÑ$hÔ$hÐiÑjÔjˆØŒ{˜FœH jÐ0Ð0à.0°"°b �K€NÝ�:ÑÔð 
"ð 
"ˆØ�a”˜˜˜˜A˜”ˆØ�q”˜!˜!˜!˜Q˜$”ˆØÐ#Ø˜LÒ(ˆCØ˜3˜$”KˆEØ˜S˜D”\ˆFÝ4°e¸V°_ÐQUÐabÐcÑcÔcˆØ×Ò˜c !œfÑ%Ô%Ð%Ø×Ò˜3˜qœ6Ñ"Ô"Ð"Ø×Ò˜#˜aœ&Ñ!Ô!Ð!Ð!Ø˜;¨
Ð2Ð2r<   c                 óÂ   — |r#t          |||¦  «         t          | |||¦  «         t          | ||||¦  «        \  } }}t          | |||¦  «        }t	          ||||¦  «        S )a  Compute the precision-recall curve for multilabel tasks.

    The curve consist of multiple pairs of precision and recall values evaluated at different thresholds, such that the
    tradeoff between the two values can been seen.

    Accepts the following input tensors:

    - ``preds`` (float tensor): ``(N, C, ...)``. Preds should be a tensor containing probabilities or logits for each
      observation. If preds has values outside [0,1] range we consider the input to be logits and will auto apply
      sigmoid per element.
    - ``target`` (int tensor): ``(N, C, ...)``. Target should be a tensor containing ground truth labels, and therefore
      only contain {0,1} values (except if `ignore_index` is specified).

    Additional dimension ``...`` will be flattened into the batch dimension.

    The implementation both supports calculating the metric in a non-binned but accurate version and a binned version
    that is less accurate but more memory efficient. Setting the `thresholds` argument to `None` will activate the
    non-binned  version that uses memory of size :math:`\mathcal{O}(n_{samples})` whereas setting the `thresholds`
    argument to either an integer, list or a 1d tensor will use a binned version that uses memory of
    size :math:`\mathcal{O}(n_{thresholds} \times n_{labels})` (constant memory).

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        num_labels: Integer specifying the number of labels
        thresholds:
            Can be one of:

            - If set to `None`, will use a non-binned approach where thresholds are dynamically calculated from
              all the data. Most accurate but also most memory consuming approach.
            - If set to an `int` (larger than 1), will use that number of thresholds linearly spaced from
              0 to 1 as bins for the calculation.
            - If set to an `list` of floats, will use the indicated thresholds in the list as bins for the calculation
            - If set to an 1d `tensor` of floats, will use the indicated thresholds in the tensor as
              bins for the calculation.

        ignore_index:
            Specifies a target value that is ignored and does not contribute to the metric calculation
        validate_args: bool indicating if input arguments and tensors should be validated for correctness.
            Set to ``False`` for faster computations.

    Returns:
        (tuple): a tuple of either 3 tensors or 3 lists containing

        - precision: if `thresholds=None` a list for each label is returned with an 1d tensor of size (n_thresholds+1, )
          with precision values (length may differ between labels). If `thresholds` is set to something else,
          then a single 2d tensor of size (n_labels, n_thresholds+1) with precision values is returned.
        - recall: if `thresholds=None` a list for each label is returned with an 1d tensor of size (n_thresholds+1, )
          with recall values (length may differ between labels). If `thresholds` is set to something else,
          then a single 2d tensor of size (n_labels, n_thresholds+1) with recall values is returned.
        - thresholds: if `thresholds=None` a list for each label is returned with an 1d tensor of size (n_thresholds, )
          with increasing threshold values (length may differ between labels). If `threshold` is set to something else,
          then a single 1d tensor of size (n_thresholds, ) is returned with shared threshold values for all labels.

    Example:
        >>> from torchmetrics.functional.classification import multilabel_precision_recall_curve
        >>> preds = torch.tensor([[0.75, 0.05, 0.35],
        ...                       [0.45, 0.75, 0.05],
        ...                       [0.05, 0.55, 0.75],
        ...                       [0.05, 0.65, 0.05]])
        >>> target = torch.tensor([[1, 0, 1],
        ...                        [0, 0, 0],
        ...                        [0, 1, 1],
        ...                        [1, 1, 1]])
        >>> precision, recall, thresholds = multilabel_precision_recall_curve(
        ...    preds, target, num_labels=3, thresholds=None
        ... )
        >>> precision  # doctest: +NORMALIZE_WHITESPACE
        [tensor([0.5000, 0.5000, 1.0000, 1.0000]), tensor([0.5000, 0.6667, 0.5000, 0.0000, 1.0000]),
         tensor([0.7500, 1.0000, 1.0000, 1.0000])]
        >>> recall  # doctest: +NORMALIZE_WHITESPACE
        [tensor([1.0000, 0.5000, 0.5000, 0.0000]), tensor([1.0000, 1.0000, 0.5000, 0.0000, 0.0000]),
         tensor([1.0000, 0.6667, 0.3333, 0.0000])]
        >>> thresholds  # doctest: +NORMALIZE_WHITESPACE
        [tensor([0.0500, 0.4500, 0.7500]), tensor([0.0500, 0.5500, 0.6500, 0.7500]), tensor([0.0500, 0.3500, 0.7500])]
        >>> multilabel_precision_recall_curve(
        ...     preds, target, num_labels=3, thresholds=5
        ... )  # doctest: +NORMALIZE_WHITESPACE
        (tensor([[0.5000, 0.5000, 1.0000, 1.0000,    nan, 1.0000],
                 [0.5000, 0.6667, 0.6667, 0.0000,    nan, 1.0000],
                 [0.7500, 1.0000, 1.0000, 1.0000,    nan, 1.0000]]),
         tensor([[1.0000, 0.5000, 0.5000, 0.5000, 0.0000, 0.0000],
                 [1.0000, 1.0000, 1.0000, 0.0000, 0.0000, 0.0000],
                 [1.0000, 0.6667, 0.3333, 0.3333, 0.0000, 0.0000]]),
         tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000]))

    )r´   r¶   r¹   r»   r½   )r   r   r²   r5   r=   r„   rr   s          r3   Ú!multilabel_precision_recall_curver¿   H  s‚   € ð~ ð fÝ9¸*ÀjÐR^Ñ_Ô_Ð_Ý<¸UÀFÈJÐXdÑeÔeÐeÝ IØˆv�z :¨|ñ!ô !Ñ€Eˆ6�:õ 6°e¸VÀZÐQ[Ñ\Ô\€EÝ5°e¸ZÈÐUaÑbÔbÐbr<   Útask)ÚbinaryÚ
multiclassÚ
multilabelc	           	      óü  — t          j        |¦  «        }|t           j        k    rt          | ||||¦  «        S |t           j        k    rJt          |t          ¦  «        s t          dt          |¦  «        › d�¦  «        ‚t          | ||||||¦  «        S |t           j
        k    rIt          |t          ¦  «        s t          dt          |¦  «        › d�¦  «        ‚t          | |||||¦  «        S t          d|› d�¦  «        ‚)aR  Compute the precision-recall curve.

    The curve consist of multiple pairs of precision and recall values evaluated at different thresholds, such that the
    tradeoff between the two values can been seen.

    This function is a simple wrapper to get the task specific versions of this metric, which is done by setting the
    ``task`` argument to either ``'binary'``, ``'multiclass'`` or ``'multilabel'``. See the documentation of
    :func:`~torchmetrics.functional.classification.binary_precision_recall_curve`,
    :func:`~torchmetrics.functional.classification.multiclass_precision_recall_curve` and
    :func:`~torchmetrics.functional.classification.multilabel_precision_recall_curve` for the specific details of each
    argument influence and examples.

    Legacy Example:
        >>> pred = torch.tensor([0, 0.1, 0.8, 0.4])
        >>> target = torch.tensor([0, 1, 1, 0])
        >>> precision, recall, thresholds = precision_recall_curve(pred, target, task='binary')
        >>> precision
        tensor([0.5000, 0.6667, 0.5000, 1.0000, 1.0000])
        >>> recall
        tensor([1.0000, 1.0000, 0.5000, 0.5000, 0.0000])
        >>> thresholds
        tensor([0.0000, 0.1000, 0.4000, 0.8000])

        >>> pred = torch.tensor([[0.75, 0.05, 0.05, 0.05, 0.05],
        ...                      [0.05, 0.75, 0.05, 0.05, 0.05],
        ...                      [0.05, 0.05, 0.75, 0.05, 0.05],
        ...                      [0.05, 0.05, 0.05, 0.75, 0.05]])
        >>> target = torch.tensor([0, 1, 3, 2])
        >>> precision, recall, thresholds = precision_recall_curve(pred, target, task='multiclass', num_classes=5)
        >>> precision
        [tensor([0.2500, 1.0000, 1.0000]), tensor([0.2500, 1.0000, 1.0000]), tensor([0.2500, 0.0000, 1.0000]),
         tensor([0.2500, 0.0000, 1.0000]), tensor([0., 1.])]
        >>> recall
        [tensor([1., 1., 0.]), tensor([1., 1., 0.]), tensor([1., 0., 0.]), tensor([1., 0., 0.]), tensor([nan, 0.])]
        >>> thresholds
        [tensor([0.0500, 0.7500]), tensor([0.0500, 0.7500]), tensor([0.0500, 0.7500]), tensor([0.0500, 0.7500]),
         tensor([0.0500])]

    z+`num_classes` is expected to be `int` but `z was passed.`z*`num_labels` is expected to be `int` but `zTask z not supported.)r   Úfrom_strÚBINARYr†   Ú
MULTICLASSr#   r8   rD   Útyper±   Ú
MULTILABELr¿   )	r   r   rÀ   r5   r‡   r²   rˆ   r=   r„   s	            r3   Úprecision_recall_curverÊ   ±  s  € õd Ô& tÑ,Ô,€DØÕ!Ô(Ò(Ð(Ý,¨U°F¸JÈÐVcÑdÔdÐdØÕ!Ô,Ò,Ð,Ý˜+¥sÑ+Ô+ð 	mÝÐkÍ4ÐP[ÑK\ÔK\ÐkÐkÐkÑlÔlÐlÝ0Ø�6˜;¨
°G¸\È=ñ
ô 
ð 	
ð Õ!Ô,Ò,Ð,Ý˜*¥cÑ*Ô*ð 	kÝÐiÍ$ÈzÑJZÔJZÐiÐiÐiÑjÔjÐjÝ0°¸À
ÈJÐXdÐfsÑtÔtÐtÝ
Ð2˜TÐ2Ð2Ð2Ñ
3Ô
3Ð3r<   )Nr   )NN)N)NNrP   )r   )NNT)NNN)NNNT)NNNNNT):Úcollections.abcr   Útypingr   r   r   r!   r   r   Útorch.nnr	   r(   Útyping_extensionsr
   Útorchmetrics.utilities.checksr   Útorchmetrics.utilities.computer   r   r   Útorchmetrics.utilities.datar   r   Útorchmetrics.utilities.enumsr   Útorchmetrics.utilities.printsr   r8   Útupler4   r:   r$   r   r;   rF   rO   rV   r]   rZ   r[   rƒ   Úboolr†   rŒ   r�   r—   r›   r™   rš   r¯   r±   r´   r¶   r¹   r»   r½   r¿   rÊ   © r<   r3   ú<module>r×      sÄ  ðð %Ð $Ð $Ð $Ð $Ð $Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (à €€€Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  Ø $Ð $Ð $Ð $Ð $Ð $Ø %Ð %Ð %Ð %Ð %Ð %à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8ð 9=Øð	4/ð 4/Øð4/àð4/ð ˜U 8¨VÐ#3Ô4Ô5ð4/ð ð	4/ð
 ˆ6�6˜6Ð!Ô"ð4/ð 4/ð 4/ð 4/ðp dhðð Ø˜˜s D¨¤K°Ð7Ô8Ô9ðØJRÐSXÔS_ÔJ`ðàˆfÔðð ð ð ð =AØ"&ðxð xØ˜˜s D¨¤K°Ð7Ô8Ô9ðxà˜3”-ðxð 
ðxð xð xð xð@ BFð"
ð "
Øð"
Ø!ð"
Ø19¸#´ð"
à	ð"
ð "
ð "
ð "
ðP =AØ"&Ø=Fð%ð %Øð%àð%ð ˜˜s D¨¤K°Ð7Ô8Ô9ð%ð ˜3”-ð	%ð
 ˜GÐ$8Ô9Ô:ð%ð ˆ6�6˜8 FÔ+Ð+Ô,ð%ð %ð %ð %ð80Øð0àð0ð ˜Ô ð0ð ˆ6�5˜ ˜Ô(Ð(Ô)ð	0ð 0ð 0ð 0ð(%Øð%àð%ð ð%ð ˆ6�5˜ ˜Ô(Ð(Ô)ð	%ð %ð %ð %ð$Øðàðð ðð ˆ6�5˜ ˜Ô(Ð(Ô)ð	ð ð ð ð8 ð$)ð $)Ø�˜˜v v˜~Ô.Ð.Ô/ð$)à˜Ô ð$)ð ð$)ð ˆ6�6˜6Ð!Ô"ð	$)ð $)ð $)ð $)ðT =AØ"&ØðIEð IEØðIEàðIEð ˜˜s D¨¤K°Ð7Ô8Ô9ðIEð ˜3”-ð	IEð
 ðIEð ˆ6�6˜6Ð!Ô"ðIEð IEð IEð IEð\ =AØ"&Ø37ð	Lð LØðLà˜˜s D¨¤K°Ð7Ô8Ô9ðLð ˜3”-ðLð �gÐ.Ô/Ô0ð	Lð
 
ðLð Lð Lð Lð* TXð&
ð &
Øð&
Ø!ð&
Ø03ð&
ØCKÈCÄ=ð&
à	ð&
ð &
ð &
ð &
ðZ =AØ"&Ø37ð%ð %Øð%àð%ð ð%ð ˜˜s D¨¤K°Ð7Ô8Ô9ð	%ð
 ˜3”-ð%ð �gÐ.Ô/Ô0ð%ð ˆ6�6˜8 FÔ+Ð+Ô,ð%ð %ð %ð %ðN 48ð=ð =Øð=àð=ð ð=ð ˜Ô ð	=ð
 �gÐ.Ô/Ô0ð=ð ˆ6�5˜ ˜Ô(Ð(Ô)ð=ð =ð =ð =ð02Øð2àð2ð ð2ð ð	2ð
 ˆ6�5˜ ˜Ô(Ð(Ô)ð2ð 2ð 2ð 2ð,Øðàðð ðð ð	ð
 ˆ6�5˜ ˜Ô(Ð(Ô)ðð ð ð ð< 48ð	53ð 53Ø�˜˜v v˜~Ô.Ð.Ô/ð53àð53ð ˜Ô ð53ð �gÐ.Ô/Ô0ð	53ð
 ˆ5�˜ Ð'Ô(¨%°°V´¸dÀ6¼lÈDÐQWÌLÐ0XÔ*YÐYÔZð53ð 53ð 53ð 53ðx =AØ37Ø"&Øðt_ð t_Øðt_àðt_ð ðt_ð ˜˜s D¨¤K°Ð7Ô8Ô9ð	t_ð
 �gÐ.Ô/Ô0ðt_ð ˜3”-ðt_ð ðt_ð ˆ5�˜ Ð'Ô(¨%°°V´¸dÀ6¼lÈDÐQWÌLÐ0XÔ*YÐYÔZðt_ð t_ð t_ð t_ðr =AØ"&ð\ð \Øð\à˜˜s D¨¤K°Ð7Ô8Ô9ð\ð ˜3”-ð\ð 
ð	\ð \ð \ð \ð  SWð
ð 
Øð
Ø!ð
Ø/2ð
ØBJÈ3Ä-ð
à	ð
ð 
ð 
ð 
ð. =AØ"&ð%ð %Øð%àð%ð ð%ð ˜˜s D¨¤K°Ð7Ô8Ô9ð	%ð
 ˜3”-ð%ð ˆ6�6˜8 FÔ+Ð+Ô,ð%ð %ð %ð %ð@1Øð1àð1ð ð1ð ˜Ô ð	1ð
 ˆ6�5˜ ˜Ô(Ð(Ô)ð1ð 1ð 1ð 1ð: #'ð	"3ð "3Ø�˜˜v v˜~Ô.Ð.Ô/ð"3àð"3ð ˜Ô ð"3ð ˜3”-ð	"3ð
 ˆ5�˜ Ð'Ô(¨%°°V´¸dÀ6¼lÈDÐQWÌLÐ0XÔ*YÐYÔZð"3ð "3ð "3ð "3ðR =AØ"&Øðfcð fcØðfcàðfcð ðfcð ˜˜s D¨¤K°Ð7Ô8Ô9ð	fcð
 ˜3”-ðfcð ðfcð ˆ5�˜ Ð'Ô(¨%°°V´¸dÀ6¼lÈDÐQWÌLÐ0XÔ*YÐYÔZðfcð fcð fcð fcðZ =AØ!%Ø $Ø37Ø"&Øð?4ð ?4Øð?4àð?4ð Ð6Ô
7ð?4ð ˜˜s D¨¤K°Ð7Ô8Ô9ð	?4ð
 ˜#”ð?4ð ˜”ð?4ð �gÐ.Ô/Ô0ð?4ð ˜3”-ð?4ð ð?4ð ˆ5�˜ Ð'Ô(¨%°°V´¸dÀ6¼lÈDÐQWÌLÐ0XÔ*YÐYÔZð?4ð ?4ð ?4ð ?4ð ?4ð ?4r<   