a
    d                     @   sH  d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlmZmZ d dlmZ d+ed	 eeeeeed
  ed eed	ddZd,eeeed ee eedddZd-eeeeed  eed ee eed	ddZd.eeeeeed  ed ee eed	ddZd/eeeed ee eedddZd0eeeeed  eed ee eed	d d!Z d1eeeeeed  ed ee eed	d"d#Z!d2eeed% eee ee eed  eed  ee ee eed&d'd(Z"d3eeed% eee ee eed  eed  ee ee eed&d)d*Z#dS )4    )Optional)Tensor)Literal)"_binary_stat_scores_arg_validation_binary_stat_scores_format%_binary_stat_scores_tensor_validation_binary_stat_scores_update&_multiclass_stat_scores_arg_validation_multiclass_stat_scores_format)_multiclass_stat_scores_tensor_validation_multiclass_stat_scores_update&_multilabel_stat_scores_arg_validation_multilabel_stat_scores_format)_multilabel_stat_scores_tensor_validation_multilabel_stat_scores_update)_adjust_weights_safe_divide_safe_divide)ClassificationTaskglobalF)	precisionrecall)binarymicromacroweightednone)r   Z
samplewise)	stattpfptnfnaveragemultidim_average
multilabelreturnc           
      C   s   | dkr|n|}|dkr&t ||| S |dkr|j|dkr>dndd}|j|dkrVdndd}|j|dkrndndd}t ||| S t ||| }	t|	|||||S )Nr   r   r   r   r      )Zdim)r   sumr   )
r   r   r   r   r    r!   r"   r#   Zdifferent_statZscore r'   /var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torchmetrics/functional/classification/precision_recall.py_precision_recall_reduce%   s    
r)         ?NT)predstarget	thresholdr"   ignore_indexvalidate_argsr$   c           
   	   C   sZ   |rt ||| t| ||| t| |||\} }t| ||\}}}}	td||||	d|dS )a
  Compute `Precision`_ for binary tasks.

    .. math:: \text{Precision} = \frac{\text{TP}}{\text{TP} + \text{FP}}

    Where :math:`\text{TP}` and :math:`\text{FP}` represent the number of true positives and
    false positives respecitively.

    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. Addtionally,
      we convert to int tensor with thresholding using the value in ``threshold``.
    - ``target`` (int tensor): ``(N, ...)``

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        threshold: Threshold for transforming probability to binary {0,1} predictions
        multidim_average:
            Defines how additionally dimensions ``...`` should be handled. Should be one of the following:

            - ``global``: Additional dimensions are flatted along the batch dimension
            - ``samplewise``: Statistic will be calculated independently for each sample on the ``N`` axis.
              The statistics in this case are calculated over the additional dimensions.

        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:
        If ``multidim_average`` is set to ``global``, the metric returns a scalar value. If ``multidim_average``
        is set to ``samplewise``, the metric returns ``(N,)`` vector consisting of a scalar value per sample.

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

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

    Example (multidim tensors):
        >>> from torchmetrics.functional.classification import binary_precision
        >>> target = tensor([[[0, 1], [1, 0], [0, 1]], [[1, 1], [0, 0], [1, 0]]])
        >>> preds = tensor([[[0.59, 0.91], [0.91, 0.99], [0.63, 0.04]],
        ...                 [[0.38, 0.04], [0.86, 0.780], [0.45, 0.37]]])
        >>> binary_precision(preds, target, multidim_average='samplewise')
        tensor([0.4000, 0.0000])

    r   r   r!   r"   r   r   r   r   r)   
r+   r,   r-   r"   r.   r/   r   r   r   r    r'   r'   r(   binary_precision<   s    Br3   r   r%   )r   r   r   r   )	r+   r,   num_classesr!   top_kr"   r.   r/   r$   c              	   C   sf   |r$t ||||| t| |||| t| ||\} }t| ||||||\}}	}
}td||	|
|||dS )az  Compute `Precision`_ for multiclass tasks.

    .. math:: \text{Precision} = \frac{\text{TP}}{\text{TP} + \text{FP}}

    Where :math:`\text{TP}` and :math:`\text{FP}` represent the number of true positives and
    false positives respecitively.

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

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        num_classes: Integer specifing the number of classes
        average:
            Defines the reduction that is applied over labels. Should be one of the following:

            - ``micro``: Sum statistics over all labels
            - ``macro``: Calculate statistics for each label and average them
            - ``weighted``: calculates statistics for each label and computes weighted average using their support
            - ``"none"`` or ``None``: calculates statistic for each label and applies no reduction

        top_k:
            Number of highest probability or logit score predictions considered to find the correct label.
            Only works when ``preds`` contain probabilities/logits.
        multidim_average:
            Defines how additionally dimensions ``...`` should be handled. Should be one of the following:

            - ``global``: Additional dimensions are flatted along the batch dimension
            - ``samplewise``: Statistic will be calculated independently for each sample on the ``N`` axis.
              The statistics in this case are calculated over the additional dimensions.

        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:
        The returned shape depends on the ``average`` and ``multidim_average`` arguments:

        - If ``multidim_average`` is set to ``global``:

          - If ``average='micro'/'macro'/'weighted'``, the output will be a scalar tensor
          - If ``average=None/'none'``, the shape will be ``(C,)``

        - If ``multidim_average`` is set to ``samplewise``:

          - If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
          - If ``average=None/'none'``, the shape will be ``(N, C)``

    Example (preds is int tensor):
        >>> from torch import tensor
        >>> from torchmetrics.functional.classification import multiclass_precision
        >>> target = tensor([2, 1, 0, 0])
        >>> preds = tensor([2, 1, 0, 1])
        >>> multiclass_precision(preds, target, num_classes=3)
        tensor(0.8333)
        >>> multiclass_precision(preds, target, num_classes=3, average=None)
        tensor([1.0000, 0.5000, 1.0000])

    Example (preds is float tensor):
        >>> from torchmetrics.functional.classification import multiclass_precision
        >>> 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_precision(preds, target, num_classes=3)
        tensor(0.8333)
        >>> multiclass_precision(preds, target, num_classes=3, average=None)
        tensor([1.0000, 0.5000, 1.0000])

    Example (multidim tensors):
        >>> from torchmetrics.functional.classification import multiclass_precision
        >>> target = tensor([[[0, 1], [2, 1], [0, 2]], [[1, 1], [2, 0], [1, 2]]])
        >>> preds = tensor([[[0, 2], [2, 0], [0, 1]], [[2, 2], [2, 1], [1, 0]]])
        >>> multiclass_precision(preds, target, num_classes=3, multidim_average='samplewise')
        tensor([0.3889, 0.2778])
        >>> multiclass_precision(preds, target, num_classes=3, multidim_average='samplewise', average=None)
        tensor([[0.6667, 0.0000, 0.5000],
                [0.0000, 0.5000, 0.3333]])

    r   r0   r	   r   r
   r   r)   r+   r,   r4   r!   r5   r"   r.   r/   r   r   r   r    r'   r'   r(   multiclass_precision   s    ar8   )	r+   r,   
num_labelsr-   r!   r"   r.   r/   r$   c              
   C   sd   |r$t ||||| t| |||| t| ||||\} }t| ||\}}	}
}td||	|
|||ddS )a2  Compute `Precision`_ for multilabel tasks.

    .. math:: \text{Precision} = \frac{\text{TP}}{\text{TP} + \text{FP}}

    Where :math:`\text{TP}` and :math:`\text{FP}` represent the number of true positives and
    false positives respecitively.

    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. Addtionally,
      we convert to int tensor with thresholding using the value in ``threshold``.
    - ``target`` (int tensor): ``(N, C, ...)``

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        num_labels: Integer specifing the number of labels
        threshold: Threshold for transforming probability to binary (0,1) predictions
        average:
            Defines the reduction that is applied over labels. Should be one of the following:

            - ``micro``: Sum statistics over all labels
            - ``macro``: Calculate statistics for each label and average them
            - ``weighted``: calculates statistics for each label and computes weighted average using their support
            - ``"none"`` or ``None``: calculates statistic for each label and applies no reduction

        multidim_average:
            Defines how additionally dimensions ``...`` should be handled. Should be one of the following:

            - ``global``: Additional dimensions are flatted along the batch dimension
            - ``samplewise``: Statistic will be calculated independently for each sample on the ``N`` axis.
              The statistics in this case are calculated over the additional dimensions.

        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:
        The returned shape depends on the ``average`` and ``multidim_average`` arguments:

        - If ``multidim_average`` is set to ``global``:

          - If ``average='micro'/'macro'/'weighted'``, the output will be a scalar tensor
          - If ``average=None/'none'``, the shape will be ``(C,)``

        - If ``multidim_average`` is set to ``samplewise``:

          - If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
          - If ``average=None/'none'``, the shape will be ``(N, C)``

    Example (preds is int tensor):
        >>> from torch import tensor
        >>> from torchmetrics.functional.classification import multilabel_precision
        >>> target = tensor([[0, 1, 0], [1, 0, 1]])
        >>> preds = tensor([[0, 0, 1], [1, 0, 1]])
        >>> multilabel_precision(preds, target, num_labels=3)
        tensor(0.5000)
        >>> multilabel_precision(preds, target, num_labels=3, average=None)
        tensor([1.0000, 0.0000, 0.5000])

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

    Example (multidim tensors):
        >>> from torchmetrics.functional.classification import multilabel_precision
        >>> target = tensor([[[0, 1], [1, 0], [0, 1]], [[1, 1], [0, 0], [1, 0]]])
        >>> preds = tensor([[[0.59, 0.91], [0.91, 0.99], [0.63, 0.04]],
        ...                 [[0.38, 0.04], [0.86, 0.780], [0.45, 0.37]]])
        >>> multilabel_precision(preds, target, num_labels=3, multidim_average='samplewise')
        tensor([0.3333, 0.0000])
        >>> multilabel_precision(preds, target, num_labels=3, multidim_average='samplewise', average=None)
        tensor([[0.5000, 0.5000, 0.0000],
                [0.0000, 0.0000, 0.0000]])

    r   Tr!   r"   r#   r   r   r   r   r)   r+   r,   r9   r-   r!   r"   r.   r/   r   r   r   r    r'   r'   r(   multilabel_precision   s    ]r=   c           
   	   C   sZ   |rt ||| t| ||| t| |||\} }t| ||\}}}}	td||||	d|dS )a
  Compute `Recall`_ for binary tasks.

    .. math:: \text{Recall} = \frac{\text{TP}}{\text{TP} + \text{FN}}

    Where :math:`\text{TP}` and :math:`\text{FN}` represent the number of true positives and
    false negatives respecitively.

    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. Addtionally,
      we convert to int tensor with thresholding using the value in ``threshold``.
    - ``target`` (int tensor): ``(N, ...)``

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        threshold: Threshold for transforming probability to binary {0,1} predictions
        multidim_average:
            Defines how additionally dimensions ``...`` should be handled. Should be one of the following:

            - ``global``: Additional dimensions are flatted along the batch dimension
            - ``samplewise``: Statistic will be calculated independently for each sample on the ``N`` axis.
              The statistics in this case are calculated over the additional dimensions.

        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:
        If ``multidim_average`` is set to ``global``, the metric returns a scalar value. If ``multidim_average``
        is set to ``samplewise``, the metric returns ``(N,)`` vector consisting of a scalar value per sample.

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

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

    Example (multidim tensors):
        >>> from torchmetrics.functional.classification import binary_recall
        >>> target = tensor([[[0, 1], [1, 0], [0, 1]], [[1, 1], [0, 0], [1, 0]]])
        >>> preds = tensor([[[0.59, 0.91], [0.91, 0.99], [0.63, 0.04]],
        ...                 [[0.38, 0.04], [0.86, 0.780], [0.45, 0.37]]])
        >>> binary_recall(preds, target, multidim_average='samplewise')
        tensor([0.6667, 0.0000])

    r   r   r0   r1   r2   r'   r'   r(   binary_recallX  s    Br>   c              	   C   sf   |r$t ||||| t| |||| t| ||\} }t| ||||||\}}	}
}td||	|
|||dS )aY  Compute `Recall`_ for multiclass tasks.

    .. math:: \text{Recall} = \frac{\text{TP}}{\text{TP} + \text{FN}}

    Where :math:`\text{TP}` and :math:`\text{FN}` represent the number of true positives and
    false negatives respecitively.

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

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        num_classes: Integer specifing the number of classes
        average:
            Defines the reduction that is applied over labels. Should be one of the following:

            - ``micro``: Sum statistics over all labels
            - ``macro``: Calculate statistics for each label and average them
            - ``weighted``: calculates statistics for each label and computes weighted average using their support
            - ``"none"`` or ``None``: calculates statistic for each label and applies no reduction

        top_k:
            Number of highest probability or logit score predictions considered to find the correct label.
            Only works when ``preds`` contain probabilities/logits.
        multidim_average:
            Defines how additionally dimensions ``...`` should be handled. Should be one of the following:

            - ``global``: Additional dimensions are flatted along the batch dimension
            - ``samplewise``: Statistic will be calculated independently for each sample on the ``N`` axis.
              The statistics in this case are calculated over the additional dimensions.

        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:
        The returned shape depends on the ``average`` and ``multidim_average`` arguments:

        - If ``multidim_average`` is set to ``global``:

          - If ``average='micro'/'macro'/'weighted'``, the output will be a scalar tensor
          - If ``average=None/'none'``, the shape will be ``(C,)``

        - If ``multidim_average`` is set to ``samplewise``:

          - If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
          - If ``average=None/'none'``, the shape will be ``(N, C)``

    Example (preds is int tensor):
        >>> from torch import tensor
        >>> from torchmetrics.functional.classification import multiclass_recall
        >>> target = tensor([2, 1, 0, 0])
        >>> preds = tensor([2, 1, 0, 1])
        >>> multiclass_recall(preds, target, num_classes=3)
        tensor(0.8333)
        >>> multiclass_recall(preds, target, num_classes=3, average=None)
        tensor([0.5000, 1.0000, 1.0000])

    Example (preds is float tensor):
        >>> from torchmetrics.functional.classification import multiclass_recall
        >>> 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_recall(preds, target, num_classes=3)
        tensor(0.8333)
        >>> multiclass_recall(preds, target, num_classes=3, average=None)
        tensor([0.5000, 1.0000, 1.0000])

    Example (multidim tensors):
        >>> from torchmetrics.functional.classification import multiclass_recall
        >>> target = tensor([[[0, 1], [2, 1], [0, 2]], [[1, 1], [2, 0], [1, 2]]])
        >>> preds = tensor([[[0, 2], [2, 0], [0, 1]], [[2, 2], [2, 1], [1, 0]]])
        >>> multiclass_recall(preds, target, num_classes=3, multidim_average='samplewise')
        tensor([0.5000, 0.2778])
        >>> multiclass_recall(preds, target, num_classes=3, multidim_average='samplewise', average=None)
        tensor([[1.0000, 0.0000, 0.5000],
                [0.0000, 0.3333, 0.5000]])

    r   r0   r6   r7   r'   r'   r(   multiclass_recall  s    ar?   c              
   C   sd   |r$t ||||| t| |||| t| ||||\} }t| ||\}}	}
}td||	|
|||ddS )a  Compute `Recall`_ for multilabel tasks.

    .. math:: \text{Recall} = \frac{\text{TP}}{\text{TP} + \text{FN}}

    Where :math:`\text{TP}` and :math:`\text{FN}` represent the number of true positives and
    false negatives respecitively.

    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. Addtionally,
      we convert to int tensor with thresholding using the value in ``threshold``.
    - ``target`` (int tensor): ``(N, C, ...)``

    Args:
        preds: Tensor with predictions
        target: Tensor with true labels
        num_labels: Integer specifing the number of labels
        threshold: Threshold for transforming probability to binary (0,1) predictions
        average:
            Defines the reduction that is applied over labels. Should be one of the following:

            - ``micro``: Sum statistics over all labels
            - ``macro``: Calculate statistics for each label and average them
            - ``weighted``: calculates statistics for each label and computes weighted average using their support
            - ``"none"`` or ``None``: calculates statistic for each label and applies no reduction

        multidim_average:
            Defines how additionally dimensions ``...`` should be handled. Should be one of the following:

            - ``global``: Additional dimensions are flatted along the batch dimension
            - ``samplewise``: Statistic will be calculated independently for each sample on the ``N`` axis.
              The statistics in this case are calculated over the additional dimensions.

        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:
        The returned shape depends on the ``average`` and ``multidim_average`` arguments:

        - If ``multidim_average`` is set to ``global``:

          - If ``average='micro'/'macro'/'weighted'``, the output will be a scalar tensor
          - If ``average=None/'none'``, the shape will be ``(C,)``

        - If ``multidim_average`` is set to ``samplewise``:

          - If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
          - If ``average=None/'none'``, the shape will be ``(N, C)``

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

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

    Example (multidim tensors):
        >>> from torchmetrics.functional.classification import multilabel_recall
        >>> target = tensor([[[0, 1], [1, 0], [0, 1]], [[1, 1], [0, 0], [1, 0]]])
        >>> preds = tensor([[[0.59, 0.91], [0.91, 0.99], [0.63, 0.04]],
        ...                 [[0.38, 0.04], [0.86, 0.780], [0.45, 0.37]]])
        >>> multilabel_recall(preds, target, num_labels=3, multidim_average='samplewise')
        tensor([0.6667, 0.0000])
        >>> multilabel_recall(preds, target, num_labels=3, multidim_average='samplewise', average=None)
        tensor([[1., 1., 0.],
                [0., 0., 0.]])

    r   Tr:   r;   r<   r'   r'   r(   multilabel_recall  s    ]r@   r   )r   Z
multiclassr#   )r+   r,   taskr-   r4   r9   r!   r"   r5   r.   r/   r$   c              	   C   s   |dusJ |t jkr(t| ||||	|
S |t jkrt|tsPtdt| dt|tsntdt| dt| ||||||	|
S |t j	krt|tstdt| dt
| ||||||	|
S td| dS )aU  Compute `Precision`_.

    .. math:: \text{Precision} = \frac{\text{TP}}{\text{TP} + \text{FP}}

    Where :math:`\text{TP}` and :math:`\text{FP}` represent the number of true positives and
    false positives respecitively.

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

    Legacy Example:
        >>> from torch import tensor
        >>> preds  = tensor([2, 0, 2, 1])
        >>> target = tensor([1, 1, 2, 0])
        >>> precision(preds, target, task="multiclass", average='macro', num_classes=3)
        tensor(0.1667)
        >>> precision(preds, target, task="multiclass", average='micro', num_classes=3)
        tensor(0.2500)

    N+`num_classes` is expected to be `int` but ` was passed.`%`top_k` is expected to be `int` but `*`num_labels` is expected to be `int` but `z[Expected argument `task` to either be `'binary'`, `'multiclass'` or `'multilabel'` but got )r   BINARYr3   
MULTICLASS
isinstanceint
ValueErrortyper8   
MULTILABELr=   r+   r,   rA   r-   r4   r9   r!   r"   r5   r.   r/   r'   r'   r(   r   t  s(    %





r   c              	   C   s   t |}|dusJ |t jkr2t| ||||	|
S |t jkrt|tsZtdt| dt|tsxtdt| dt	| ||||||	|
S |t j
krt|tstdt| dt| ||||||	|
S td| dS )a@  Compute `Recall`_.

    .. math:: \text{Recall} = \frac{\text{TP}}{\text{TP} + \text{FN}}

    Where :math:`\text{TP}` and :math:`\text{FN}` represent the number of true positives and
    false negatives respecitively.

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

    Legacy Example:
        >>> from torch import tensor
        >>> preds  = tensor([2, 0, 2, 1])
        >>> target = tensor([1, 1, 2, 0])
        >>> recall(preds, target, task="multiclass", average='macro', num_classes=3)
        tensor(0.3333)
        >>> recall(preds, target, task="multiclass", average='micro', num_classes=3)
        tensor(0.2500)

    NrB   rC   rD   rE   zNot handled value: )r   Zfrom_strrF   r>   rG   rH   rI   rJ   rK   r?   rL   r@   rM   r'   r'   r(   r     s&    %






r   )r   F)r*   r   NT)r   r%   r   NT)r*   r   r   NT)r*   r   NT)r   r%   r   NT)r*   r   r   NT)r*   NNr   r   r%   NT)r*   NNr   r   r%   NT)$typingr   Ztorchr   Ztyping_extensionsr   Z2torchmetrics.functional.classification.stat_scoresr   r   r   r   r	   r
   r   r   r   r   r   r   Ztorchmetrics.utilities.computer   r   Ztorchmetrics.utilities.enumsr   boolr)   floatrI   r3   r8   r=   r>   r?   r@   r   r   r'   r'   r'   r(   <module>   s0  8
  
    N     
o     
j    N     
o     
k        

?        

