§
    ’©ºj‰l  ã                   ó  — d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d d	lmZ 	 d/d
edeed                  defd„Z	 	 	 d0dedee         deed                  ddfd„Z	 d/dededee         ddfd„Z	 	 	 d1dedededee         dedeeef         fd„Zdededefd„Z	 d/d
edeed                  defd„Z	 	 	 	 d2dedededeed                  dee         dedefd„Z	 	 d3de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	 	 d4dededee         dedeeef         f
d „Zdedededefd!„Z	 d/d
edeed                  defd"„Z	 	 	 d5dedededeed                  dee         dedefd#„Z 	 	 	 d0d$ede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"	 	 	 d1deded$ededee         d'edeeef         fd(„Z#deded$edefd)„Z$	 d/d
edeed                  defd*„Z%	 	 	 	 d2deded$ededeed                  dee         dedefd+„Z&	 	 	 	 	 	 d6deded,ed-         dedee         d$ee         deed                  dee         dedefd.„Z'dS )7é    )ÚOptionalN)ÚTensor)ÚLiteral)Ú_check_same_shape)Únormalize_logits_if_needed)Ú	_bincount)ÚClassificationTask)Úrank_zero_warnÚconfmatÚ	normalize)ÚtrueÚpredÚallÚnoneÚreturnc                 ó  — d}||vrt          d|› �¦  «        ‚|�ë|dk    rå|                      ¦   «         s|                      ¦   «         n| } |dk    r| |                      dd¬¦  «        z  } nC|d	k    r| |                      d
d¬¦  «        z  } n"|dk    r| |                      d
dgd¬¦  «        z  } | t	          j        | ¦  «                                      ¦   «         }|r)d| t	          j        | ¦  «        <   t          |› d�¦  «         | S )aÊ  Reduce an un-normalized confusion matrix.

    Args:
        confmat: un-normalized confusion matrix
        normalize: normalization method.
            - `"true"` will divide by the sum of the column dimension.
            - `"pred"` will divide by the sum of the row dimension.
            - `"all"` will divide by the sum of the full matrix
            - `"none"` or `None` will apply no reduction.

    Returns:
        Normalized confusion matrix

    ©r   r   r   r   Nz4Argument `normalize` needs to one of the following: Nr   r   éÿÿÿÿT)ÚdimÚkeepdimr   éþÿÿÿr   r   zD NaN values found in confusion matrix have been replaced with zeros.)Ú
ValueErrorÚis_floating_pointÚfloatÚsumÚtorchÚisnanÚnelementr
   )r   r   Úallowed_normalizeÚnan_elementss       ú‡/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/classification/confusion_matrix.pyÚ_confusion_matrix_reducer"      s0  € ð" >ÐØÐ)Ð)Ð)ÝÐcÐPaÐcÐcÑdÔdÐdØÐ ¨fÒ!4Ð!4Ø)0×)BÒ)BÑ)DÔ)DÐQ�'—-’-‘/”/�/È'ˆØ˜ÒÐØ §¢°¸D Ñ AÔ AÑAˆGˆGØ˜&Ò Ð Ø §¢°¸D Ñ AÔ AÑAˆGˆGØ˜%ÒÐØ §¢°°R°À$ Ñ GÔ GÑGˆGà�uœ{¨7Ñ3Ô3Ô4×=Ò=Ñ?Ô?ˆØð 	rØ,-ˆG•E”K Ñ(Ô(Ñ)Ý˜lÐpÐpÐpÑqÔqÐqØ€Nó    ç      à?Ú	thresholdÚignore_indexc                 óþ   — t          | t          ¦  «        rd| cxk    rdk    sn t          d| › d�¦  «        ‚|�'t          |t          ¦  «        st          d|› �¦  «        ‚d}||vrt          d|› d	|› d�¦  «        ‚dS )
zÍValidate non tensor input.

    - ``threshold`` has to be a float in the [0,1] range
    - ``ignore_index`` has to be None or int
    - ``normalize`` has to be "true" | "pred" | "all" | "none" | None

    r   é   zHExpected argument `threshold` to be a float in the [0,1] range, but got ú.NúLExpected argument `ignore_index` to either be `None` or an integer, but got r   ú+Expected argument `normalize` to be one of ú
, but got )Ú
isinstancer   r   Úint)r%   r&   r   r   s       r!   Ú'_binary_confusion_matrix_arg_validationr/   ?   s»   € õ �y¥%Ñ(Ô(ð r¨a°9Ð.AÐ.AÒ.AÐ.AÀÒ.AÐ.AÐ.AÐ.AÝÐpÐdmÐpÐpÐpÑqÔqÐqØÐ­
°<ÅÑ(EÔ(EÐÝÐvÐhtÐvÐvÑwÔwÐwØ=ÐØÐ)Ð)Ð)ÝÐpÐGXÐpÐpÐdmÐpÐpÐpÑqÔqÐqð *Ð)r#   ÚpredsÚtargetc                 óÜ  — t          | |¦  «         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�¦  «        ‚|                      ¦   «         sHt          j        | d¬¦  «        }t          j        |dk    |dk    z  ¦  «        rt	          d|› d	�¦  «        ‚dS 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}
    - if pred tensor is not floating point, then all values also have to be in {0, 1}

    N©r   r   r(   ú+Detected the following values in `target`: ú( but expected only the following values r)   ú*Detected the following values in `preds`: úL but expected only the following values [0,1] since preds is a label tensor.)r   r   ÚuniqueÚanyÚRuntimeErrorr   )r0   r1   r&   Úunique_valuesÚchecks        r!   Ú*_binary_confusion_matrix_tensor_validationr=   T   sV  € õ �e˜VÑ$Ô$Ð$õ ”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È,Èð[ð [ð [ñ
ô 
ð 	
ð ×"Ò"Ñ$Ô$ð Ýœ U°Ð5Ñ5Ô5ˆÝŒ9�m qÒ(¨]¸aÒ-?Ñ@ÑAÔAð 	ÝðM¸]ð Mð Mð Mñô ð ðð ð	ð 	r#   TÚconvert_to_labelsc                 óâ   — |                       ¦   «         } |                      ¦   «         }|�||k    }| |         } ||         }|                      ¦   «         rt          | d¦  «        } |r| |k    } | |fS )zöConvert all input to label format.

    - Remove all datapoints that should be ignored
    - If preds tensor is floating point, applies sigmoid if pred tensor not in [0,1] range
    - If preds tensor is floating point, thresholds afterwards

    NÚsigmoid)Úflattenr   r   )r0   r1   r%   r&   r>   Úidxs         r!   Ú_binary_confusion_matrix_formatrC   w   s�   € ð �MŠM‰OŒO€EØ�^Š^ÑÔ€FØÐØ˜Ò$ˆØ�c”
ˆØ˜”ˆà×ÒÑ Ô ð &Ý*¨5°)Ñ<Ô<ˆØð 	&Ø˜IÒ%ˆEà�&ˆ=Ðr#   c                 óš   — |dz  | z                         t          j        ¦  «        }t          |d¬¦  «        }|                     dd¦  «        S )ú5Compute the bins to update the confusion matrix with.é   é   ©Ú	minlength©Útor   Úlongr   Úreshape)r0   r1   Úunique_mappingÚbinss       r!   Ú_binary_confusion_matrix_updaterP   ”   sF   € à˜q‘j 5Ñ(×,Ò,­U¬ZÑ8Ô8€NÝ�^¨qÐ1Ñ1Ô1€DØ�<Š<˜˜1ÑÔÐr#   c                 ó"   — t          | |¦  «        S ©zsReduces the confusion matrix to it's final form.

    Normalization technique can be chosen by ``normalize``.

    ©r"   ©r   r   s     r!   Ú _binary_confusion_matrix_computerU   ›   ó   € õ $ G¨YÑ7Ô7Ð7r#   Úvalidate_argsc                 ó´   — |r"t          |||¦  «         t          | ||¦  «         t          | |||¦  «        \  } }t          | |¦  «        }t	          ||¦  «        S )aê  Compute the `confusion matrix`_ for binary tasks.

    Accepts the following input tensors:

    - ``preds`` (int or float tensor): ``(N, ...)``. If preds is a floating point tensor with values outside
      [0,1] range we consider the input to be logits and will auto apply sigmoid per element. Additionally,
      we convert to int tensor with thresholding using the value in ``threshold``.
    - ``target`` (int tensor): ``(N, ...)``

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

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        threshold: Threshold for transforming probability to binary (0,1) predictions
        normalize: Normalization mode for confusion matrix. Choose from:

            - ``None`` or ``'none'``: no normalization (default)
            - ``'true'``: normalization over the targets (most commonly used)
            - ``'pred'``: normalization over the predictions
            - ``'all'``: normalization over the whole matrix
        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:
        A ``[2, 2]`` tensor

    Example (preds is int tensor):
        >>> from torch import tensor
        >>> from torchmetrics.functional.classification import binary_confusion_matrix
        >>> target = tensor([1, 1, 0, 0])
        >>> preds = tensor([0, 1, 0, 0])
        >>> binary_confusion_matrix(preds, target)
        tensor([[2, 0],
                [1, 1]])

    Example (preds is float tensor):
        >>> from torchmetrics.functional.classification import binary_confusion_matrix
        >>> target = tensor([1, 1, 0, 0])
        >>> preds = tensor([0.35, 0.85, 0.48, 0.01])
        >>> binary_confusion_matrix(preds, target)
        tensor([[2, 0],
                [1, 1]])

    )r/   r=   rC   rP   rU   )r0   r1   r%   r   r&   rW   r   s          r!   Úbinary_confusion_matrixrY   ¦   sh   € ðn ð PÝ/°	¸<ÈÑSÔSÐSÝ2°5¸&À,ÑOÔOÐOÝ3°E¸6À9ÈlÑ[Ô[�M€Eˆ6Ý-¨e°VÑ<Ô<€GÝ+¨G°YÑ?Ô?Ð?r#   Únum_classesc                 óê   — t          | t          ¦  «        r| dk     rt          d| › �¦  «        ‚|�'t          |t          ¦  «        st          d|› �¦  «        ‚d}||vrt          d|› d|› d�¦  «        ‚dS )	zÈValidate non tensor input.

    - ``num_classes`` has to be a int larger than 1
    - ``ignore_index`` has to be None or int
    - ``normalize`` has to be "true" | "pred" | "all" | "none" | None

    rF   zHExpected argument `num_classes` to be an integer larger than 1, but got Nr*   r   r+   r,   r)   )r-   r.   r   )rZ   r&   r   r   s       r!   Ú+_multiclass_confusion_matrix_arg_validationr\   å   s¢   € õ �k¥3Ñ'Ô'ð s¨;¸ª?¨?ÝÐqÐdoÐqÐqÑrÔrÐrØÐ­
°<ÅÑ(EÔ(EÐÝÐvÐhtÐvÐvÑwÔwÐwØ=ÐØÐ)Ð)Ð)ÝÐpÐGXÐpÐpÐdmÐpÐpÐpÑqÔqÐqð *Ð)r#   c           
      ó˜  — | j         |j         dz   k    rs|                      ¦   «         st          d¦  «        ‚| j        d         |k    rt          d¦  «        ‚| j        dd…         |j        dd…         k    rt          d¦  «        ‚nQ| j         |j         k    r2| j        |j        k    r!t          dd| j        › d	|j        › d
�¦  «        ‚nt          d¦  «        ‚|€|n|dz   }|                      ¦   «         s|dff| dffz   ndD ]G\  }}t	          t          j        |d¬¦  «        ¦  «        }||k    rt          d|› d|› d|› d�¦  «        ‚ŒHdS )aí  Validate tensor input.

    - if target has one more dimension than preds, then all dimensions except for preds.shape[1] should match
    exactly. preds.shape[1] should have size equal to number of classes
    - if preds and target have same number of dims, then all dimensions should match
    - all values in target tensor that are not ignored have to be {0, ..., num_classes - 1}
    - if pred tensor is not floating point, then all values also have to be in {0, ..., num_classes - 1}

    r(   zSIf `preds` have one dimension more than `target`, `preds` should be a float tensor.zhIf `preds` have one dimension more than `target`, `preds.shape[1]` should be equal to number of classes.rF   Nz‹If `preds` have one dimension more than `target`, the shape of `preds` should be (N, C, ...), and the shape of `target` should be (N, ...).z4The `preds` and `target` should have the same shape,z got `preds` with shape=z and `target` with shape=r)   z‰Either `preds` and `target` both should have the (same) shape (N, ...), or `target` should be (N, ...) and `preds` should be (N, C, ...).r1   r0   © r3   z Detected more unique values in `z` than expected. Expected only z but found z in `target`.)Úndimr   r   ÚshapeÚlenr   r8   r:   )r0   r1   rZ   r&   Úcheck_valueÚtÚnameÚnum_unique_valuess           r!   Ú._multiclass_confusion_matrix_tensor_validationrf   ú   sÝ  € ð „z�V”[ 1‘_Ò$Ð$Ø×&Ò&Ñ(Ô(ð 	tÝÐrÑsÔsÐsØŒ;�qŒ>˜[Ò(Ð(Ýð/ñô ð ð Œ;�q�r�rŒ?˜fœl¨1¨2¨2Ô.Ò.Ð.ÝðNñô ð ð /ð
 
Œ�v”{Ò	"Ð	"ØŒ;˜&œ,Ò&Ð&ÝØFØ`¨5¬;Ð`Ð`ÐQWÔQ]Ð`Ð`Ð`ñô ð ð 'õ ð2ñ
ô 
ð 	
ð
 ".Ð!5�+�+¸;È¹?€KØFK×F]ÒF]ÑF_ÔF_Ðg�V˜XÐ&Ð(¨U°GÐ,<Ð+>Ñ>Ð>Ðegð ð ‰ˆˆ4Ý¥¤¨Q°DÐ 9Ñ 9Ô 9Ñ:Ô:ÐØ˜{Ò*Ð*Ýð5°4ð 5ð 5ÐXcð 5ð 5Ø%ð5ð 5ð 5ñô ð ð +ðð r#   c                 óN  — | j         |j         dz   k    r|r|                      d¬¦  «        } |r|                      ¦   «         n4t          j        | dd¦  «                             d| j        d         ¦  «        } |                     ¦   «         }|�||k    }| |         } ||         }| |fS )zžConvert all input to label format.

    - Applies argmax if preds have one more dimension than target
    - Remove all datapoints that should be ignored

    r(   r3   r   )r_   ÚargmaxrA   r   ÚmovedimrM   r`   )r0   r1   r&   r>   rB   s        r!   Ú#_multiclass_confusion_matrix_formatrj   )  sª   € ð „z�V”[ 1‘_Ò$Ð$Ð):Ð$Ø—’ �Ñ#Ô#ˆà0ÐmˆE�MŠM‰OŒOˆOµe´mÀEÈ1ÈbÑ6QÔ6Q×6YÒ6YÐZ\Ð^cÔ^iÐjkÔ^lÑ6mÔ6m€EØ�^Š^ÑÔ€FàÐØ˜Ò$ˆØ�c”
ˆØ˜”ˆà�&ˆ=Ðr#   c                 óÚ   — |                      t          j        ¦  «        |z  |                       t          j        ¦  «        z   }t          ||dz  ¬¦  «        }|                     ||¦  «        S )rE   rF   rH   rJ   )r0   r1   rZ   rN   rO   s        r!   Ú#_multiclass_confusion_matrix_updaterl   D  sW   € à—Y’Y�uœzÑ*Ô*¨[Ñ8¸5¿8º8ÅEÄJÑ;OÔ;OÑO€NÝ�^¨{¸A©~Ð>Ñ>Ô>€DØ�<Š<˜ [Ñ1Ô1Ð1r#   c                 ó"   — t          | |¦  «        S rR   rS   rT   s     r!   Ú$_multiclass_confusion_matrix_computern   K  rV   r#   c                 ó¶   — |r#t          |||¦  «         t          | |||¦  «         t          | ||¦  «        \  } }t          | ||¦  «        }t	          ||¦  «        S )a¨  Compute the `confusion matrix`_ for multiclass tasks.

    Accepts the following input tensors:

    - ``preds``: ``(N, ...)`` (int tensor) or ``(N, C, ..)`` (float tensor). If preds is a floating point
      we apply ``torch.argmax`` along the ``C`` dimension to automatically convert probabilities/logits into
      an int tensor.
    - ``target`` (int tensor): ``(N, ...)``

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

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        num_classes: Integer specifying the number of classes
        normalize: Normalization mode for confusion matrix. Choose from:

            - ``None`` or ``'none'``: no normalization (default)
            - ``'true'``: normalization over the targets (most commonly used)
            - ``'pred'``: normalization over the predictions
            - ``'all'``: normalization over the whole matrix
        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:
        A ``[num_classes, num_classes]`` tensor

    Example (pred is integer tensor):
        >>> from torch import tensor
        >>> from torchmetrics.functional.classification import multiclass_confusion_matrix
        >>> target = tensor([2, 1, 0, 0])
        >>> preds = tensor([2, 1, 0, 1])
        >>> multiclass_confusion_matrix(preds, target, num_classes=3)
        tensor([[1, 1, 0],
                [0, 1, 0],
                [0, 0, 1]])

    Example (pred is float tensor):
        >>> from torchmetrics.functional.classification import multiclass_confusion_matrix
        >>> target = tensor([2, 1, 0, 0])
        >>> preds = tensor([[0.16, 0.26, 0.58],
        ...                 [0.22, 0.61, 0.17],
        ...                 [0.71, 0.09, 0.20],
        ...                 [0.05, 0.82, 0.13]])
        >>> multiclass_confusion_matrix(preds, target, num_classes=3)
        tensor([[1, 1, 0],
                [0, 1, 0],
                [0, 0, 1]])

    )r\   rf   rj   rl   rn   )r0   r1   rZ   r   r&   rW   r   s          r!   Úmulticlass_confusion_matrixrp   V  sk   € ðx ð aÝ3°KÀÈyÑYÔYÐYÝ6°u¸fÀkÐS_Ñ`Ô`Ð`Ý7¸¸vÀ|ÑTÔT�M€Eˆ6Ý1°%¸ÀÑMÔM€GÝ/°¸ÑCÔCÐCr#   Ú
num_labelsc                 óX  — t          | t          ¦  «        r| dk     rt          d| › �¦  «        ‚t          |t          ¦  «        rd|cxk    rdk    sn t          d|› d�¦  «        ‚|�'t          |t          ¦  «        st          d|› �¦  «        ‚d	}||vrt          d
|› d|› d�¦  «        ‚dS )a  Validate non tensor input.

    - ``num_labels`` should be an int larger than 1
    - ``threshold`` has to be a float in the [0,1] range
    - ``ignore_index`` has to be None or int
    - ``normalize`` has to be "true" | "pred" | "all" | "none" | None

    rF   zGExpected argument `num_labels` to be an integer larger than 1, but got r   r(   z5Expected argument `threshold` to be a float, but got r)   Nr*   r   r+   r,   )r-   r.   r   r   )rq   r%   r&   r   r   s        r!   Ú+_multilabel_confusion_matrix_arg_validationrs   š  sî   € õ �j¥#Ñ&Ô&ð q¨*°qª.¨.ÝÐoÐcmÐoÐoÑpÔpÐpÝ�y¥%Ñ(Ô(ð _¨a°9Ð.AÐ.AÒ.AÐ.AÀÒ.AÐ.AÐ.AÐ.AÝÐ]ÐQZÐ]Ð]Ð]Ñ^Ô^Ð^ØÐ­
°<ÅÑ(EÔ(EÐÝÐvÐhtÐvÐvÑwÔwÐwØ=ÐØÐ)Ð)Ð)ÝÐpÐGXÐpÐpÐdmÐpÐpÐpÑqÔqÐqð *Ð)r#   c                 ó>  — t          | |¦  «         | j        d         |k    r t          d| j        d         › d|› �¦  «        ‚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	�¦  «        ‚|                      ¦   «         sHt          j        | d¬¦  «        }t          j        |dk    |dk    z  ¦  «        rt          d
|› d�¦  «        ‚dS dS )a:  Validate tensor input.

    - tensors have to be of same shape
    - the second dimension of both tensors need to be equal to the number of labels
    - all values in target tensor that are not ignored have to be in {0, 1}
    - if pred tensor is not floating point, then all values also have to be in {0, 1}

    r(   zaExpected both `target.shape[1]` and `preds.shape[1]` to be equal to the number of labels but got z and expected Nr3   r   r4   r5   r)   r6   r7   )r   r`   r   r   r8   r9   r:   r   )r0   r1   rq   r&   r;   r<   s         r!   Ú._multilabel_confusion_matrix_tensor_validationru   ³  s£  € õ �e˜VÑ$Ô$Ð$à„{�1„~˜Ò#Ð#ÝðCØœ AœðCð CØ6@ðCð Cñ
ô 
ð 	
õ ”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È,Èð[ð [ð [ñ
ô 
ð 	
ð ×"Ò"Ñ$Ô$ð Ýœ U°Ð5Ñ5Ô5ˆÝŒ9�m qÒ(¨]¸aÒ-?Ñ@ÑAÔAð 	ÝðM¸]ð Mð Mð Mñô ð ðð ð	ð 	r#   Úshould_thresholdc                 óŠ  — |                       ¦   «         rt          | d¦  «        } |r| |k    } t          j        | dd¦  «                             d|¦  «        } t          j        |dd¦  «                             d|¦  «        }|�>|                      ¦   «         } |                     ¦   «         }||k    }d|z  | |<   d|z  ||<   | |fS )a  Convert all input to label format.

    - If preds tensor is floating point, applies sigmoid if pred tensor not in [0,1] range
    - If preds tensor is floating point, thresholds afterwards
    - Mask all elements that should be ignored with negative numbers for later filtration

    r@   r(   r   Néüÿÿÿ)r   r   r   ri   rM   Úclone)r0   r1   rq   r%   r&   rv   rB   s          r!   Ú#_multilabel_confusion_matrix_formatrz   Ý  sÏ   € ð ×ÒÑ Ô ð &Ý*¨5°)Ñ<Ô<ˆØð 	&Ø˜IÒ%ˆEÝŒM˜%  BÑ'Ô'×/Ò/°°JÑ?Ô?€EÝŒ]˜6 1 bÑ)Ô)×1Ò1°"°jÑAÔA€FàÐØ—’‘”ˆØ—’‘”ˆð ˜Ò$ˆØ˜*‘_ˆˆc‰
Ø˜:‘oˆˆs‰à�&ˆ=Ðr#   c                 óâ   — d|z  | z   dt          j        || j        ¬¦  «        z  z                        ¦   «         }||dk             }t	          |d|z  ¬¦  «        }|                     |dd¦  «        S )rE   rF   rG   )Údevicer   rH   )r   Úaranger|   rA   r   rM   )r0   r1   rq   rN   rO   s        r!   Ú#_multilabel_confusion_matrix_updater~   ÿ  st   € à˜6‘z EÑ)¨Qµ´¸jÐQVÔQ]Ð1^Ñ1^Ô1^Ñ-^Ñ^×gÒgÑiÔi€NØ# N°aÒ$7Ô8€NÝ�^¨q°:©~Ð>Ñ>Ô>€DØ�<Š<˜
 A qÑ)Ô)Ð)r#   c                 ó"   — t          | |¦  «        S rR   rS   rT   s     r!   Ú$_multilabel_confusion_matrix_computer€     rV   r#   c                 ó¼   — |r$t          ||||¦  «         t          | |||¦  «         t          | ||||¦  «        \  } }t          | ||¦  «        }t	          ||¦  «        S )a	  Compute the `confusion matrix`_ for multilabel tasks.

    Accepts the following input tensors:

    - ``preds`` (int or float tensor): ``(N, C, ...)``. If preds is a floating point tensor with values outside
      [0,1] range we consider the input to be logits and will auto apply sigmoid per element. Additionally,
      we convert to int tensor with thresholding using the value in ``threshold``.
    - ``target`` (int tensor): ``(N, C, ...)``

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

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        num_labels: Integer specifying the number of labels
        threshold: Threshold for transforming probability to binary (0,1) predictions
        normalize: Normalization mode for confusion matrix. Choose from:

            - ``None`` or ``'none'``: no normalization (default)
            - ``'true'``: normalization over the targets (most commonly used)
            - ``'pred'``: normalization over the predictions
            - ``'all'``: normalization over the whole matrix
        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:
        A ``[num_labels, 2, 2]`` tensor

    Example (preds is int tensor):
        >>> from torch import tensor
        >>> from torchmetrics.functional.classification import multilabel_confusion_matrix
        >>> target = tensor([[0, 1, 0], [1, 0, 1]])
        >>> preds = tensor([[0, 0, 1], [1, 0, 1]])
        >>> multilabel_confusion_matrix(preds, target, num_labels=3)
        tensor([[[1, 0], [0, 1]],
                [[1, 0], [1, 0]],
                [[0, 1], [0, 1]]])

    Example (preds is float tensor):
        >>> from torchmetrics.functional.classification import multilabel_confusion_matrix
        >>> target = tensor([[0, 1, 0], [1, 0, 1]])
        >>> preds = tensor([[0.11, 0.22, 0.84], [0.73, 0.33, 0.92]])
        >>> multilabel_confusion_matrix(preds, target, num_labels=3)
        tensor([[[1, 0], [0, 1]],
                [[1, 0], [1, 0]],
                [[0, 1], [0, 1]]])

    )rs   ru   rz   r~   r€   )r0   r1   rq   r%   r   r&   rW   r   s           r!   Úmultilabel_confusion_matrixr‚     st   € ðv ð `Ý3°JÀ	È<ÐYbÑcÔcÐcÝ6°u¸fÀjÐR^Ñ_Ô_Ð_Ý7¸¸vÀzÐS\Ð^jÑkÔk�M€Eˆ6Ý1°%¸ÀÑLÔL€GÝ/°¸ÑCÔCÐCr#   Útask)ÚbinaryÚ
multiclassÚ
multilabelc	           	      óþ  — t          j        |¦  «        }|t           j        k    rt          | |||||¦  «        S |t           j        k    rIt          |t          ¦  «        s t          dt          |¦  «        › d�¦  «        ‚t          | |||||¦  «        S |t           j
        k    rJt          |t          ¦  «        s t          dt          |¦  «        › d�¦  «        ‚t          | ||||||¦  «        S t          d|› d�¦  «        ‚)aä  Compute the `confusion matrix`_.

    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_confusion_matrix`,
    :func:`~torchmetrics.functional.classification.multiclass_confusion_matrix` and
    :func:`~torchmetrics.functional.classification.multilabel_confusion_matrix` for
    the specific details of each argument influence and examples.

    Legacy Example:
        >>> from torch import tensor
        >>> from torchmetrics.classification import ConfusionMatrix
        >>> target = tensor([1, 1, 0, 0])
        >>> preds = tensor([0, 1, 0, 0])
        >>> confmat = ConfusionMatrix(task="binary")
        >>> confmat(preds, target)
        tensor([[2, 0],
                [1, 1]])

        >>> target = tensor([2, 1, 0, 0])
        >>> preds = tensor([2, 1, 0, 1])
        >>> confmat = ConfusionMatrix(task="multiclass", num_classes=3)
        >>> confmat(preds, target)
        tensor([[1, 1, 0],
                [0, 1, 0],
                [0, 0, 1]])

        >>> target = tensor([[0, 1, 0], [1, 0, 1]])
        >>> preds = tensor([[0, 0, 1], [1, 0, 1]])
        >>> confmat = ConfusionMatrix(task="multilabel", num_labels=3)
        >>> confmat(preds, target)
        tensor([[[1, 0], [0, 1]],
                [[1, 0], [1, 0]],
                [[0, 1], [0, 1]]])

    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ÚBINARYrY   Ú
MULTICLASSr-   r.   r   Útyperp   Ú
MULTILABELr‚   )	r0   r1   rƒ   r%   rZ   rq   r   r&   rW   s	            r!   Úconfusion_matrixr�   U  s  € õ^ Ô& tÑ,Ô,€DØÕ!Ô(Ò(Ð(Ý& u¨f°iÀÈLÐZgÑhÔhÐhØÕ!Ô,Ò,Ð,Ý˜+¥sÑ+Ô+ð 	mÝÐkÍ4ÐP[ÑK\ÔK\ÐkÐkÐkÑlÔlÐlÝ*¨5°&¸+ÀyÐR^Ð`mÑnÔnÐnØÕ!Ô,Ò,Ð,Ý˜*¥cÑ*Ô*ð 	kÝÐiÍ$ÈzÑJZÔJZÐiÐiÐiÑjÔjÐjÝ*¨5°&¸*ÀiÐQZÐ\hÐjwÑxÔxÐxÝ
Ð2˜TÐ2Ð2Ð2Ñ
3Ô
3Ð3r#   )N)r$   NN)r$   NT)r$   NNT)NN)NT)NNT)r$   NNNNT)(Útypingr   r   r   Útyping_extensionsr   Útorchmetrics.utilities.checksr   Útorchmetrics.utilities.computer   Útorchmetrics.utilities.datar   Útorchmetrics.utilities.enumsr	   Útorchmetrics.utilities.printsr
   r"   r   r.   r/   r=   ÚboolÚtuplerC   rP   rU   rY   r\   rf   rj   rl   rn   rp   rs   ru   rz   r~   r€   r‚   r�   r^   r#   r!   ú<module>r—      sà  ðð Ð Ð Ð Ð Ð à €€€Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø EÐ EÐ EÐ EÐ EÐ EØ 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8ð TXð!ð !Øð!Ø (¨Ð1NÔ)OÔ Pð!àð!ð !ð !ð !ðJ Ø"&ØBFðrð rØðrà˜3”-ðrð ˜Ð =Ô>Ô?ðrð 
ð	rð rð rð rð, BFð ð  Øð Ø!ð Ø19¸#´ð à	ð ð  ð  ð  ðL Ø"&Ø"ðð Øðàðð ðð ˜3”-ð	ð
 ðð ˆ6�6ˆ>Ôðð ð ð ð:¨6ð ¸6ð Àfð ð ð ð ð TXð8ð 8Øð8Ø (¨Ð1NÔ)OÔ Pð8àð8ð 8ð 8ð 8ð ØBFØ"&Øð<@ð <@Øð<@àð<@ð ð<@ð ˜Ð =Ô>Ô?ð	<@ð
 ˜3”-ð<@ð ð<@ð ð<@ð <@ð <@ð <@ðB #'ØBFðrð rØðrà˜3”-ðrð ˜Ð =Ô>Ô?ðrð 
ð	rð rð rð rð, TXð,ð ,Øð,Ø!ð,Ø03ð,ØCKÈCÄ=ð,à	ð,ð ,ð ,ð ,ðd #'Ø"ð	ð Øðàðð ˜3”-ðð ð	ð
 ˆ6�6ˆ>Ôðð ð ð ð62¨vð 2¸vð 2ÐTWð 2Ð\bð 2ð 2ð 2ð 2ð TXð8ð 8Øð8Ø (¨Ð1NÔ)OÔ Pð8àð8ð 8ð 8ð 8ð CGØ"&ØðADð ADØðADàðADð ðADð ˜Ð =Ô>Ô?ð	ADð
 ˜3”-ðADð ðADð ðADð ADð ADð ADðL Ø"&ØBFð	rð rØðràðrð ˜3”-ðrð ˜Ð =Ô>Ô?ð	rð
 
ðrð rð rð rð4 SWð'ð 'Øð'Ø!ð'Ø/2ð'ØBJÈ3Ä-ð'à	ð'ð 'ð 'ð 'ð\ Ø"&Ø!ðð Øðàðð ðð ð	ð
 ˜3”-ðð ðð ˆ6�6ˆ>Ôðð ð ð ðD*¨vð *¸vð *ÐSVð *Ð[að *ð *ð *ð *ð TXð8ð 8Øð8Ø (¨Ð1NÔ)OÔ Pð8àð8ð 8ð 8ð 8ð ØBFØ"&Øð@Dð @DØð@Dàð@Dð ð@Dð ð	@Dð
 ˜Ð =Ô>Ô?ð@Dð ˜3”-ð@Dð ð@Dð ð@Dð @Dð @Dð @DðN Ø!%Ø $ØBFØ"&Øð:4ð :4Øð:4àð:4ð Ð6Ô
7ð:4ð ð	:4ð
 ˜#”ð:4ð ˜”ð:4ð ˜Ð =Ô>Ô?ð:4ð ˜3”-ð:4ð ð:4ð ð:4ð :4ð :4ð :4ð :4ð :4r#   