a
    þdY  ã                   @   s6   d dl mZ d dlZdejejeej dœdd„ZdS )é    )ÚListN©é   )ÚinputÚtargetÚreturnc                    sj   t t|ƒ|  ¡ d ƒ‰| d¡‰ |  ˆddd¡\}}| ¡ }| | dd¡ |¡¡‰‡ ‡‡fdd„|D ƒS )aŸ  Computes the accuracy over the k top predictions for the specified values of k.

    Args:
        input: the input tensor with the logits to evaluate.
        target: the tensor containing the ground truth.
        topk: the expected topk ranking.

    Example:
        >>> logits = torch.tensor([[0, 1, 0]])
        >>> target = torch.tensor([[1]])
        >>> accuracy(logits, target)
        [tensor(100.)]
    r   r   Téÿÿÿÿc                    s6   g | ].}ˆd t |ˆƒ…  d¡ ¡  d¡d ˆ  ‘qS )Nr   r   g      Y@)ÚminÚreshapeÚfloatÚsum)Ú.0Úk©Z
batch_sizeÚcorrectZmaxk© ú`/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/kornia/metrics/accuracy.pyÚ
<listcomp>   ó    zaccuracy.<locals>.<listcomp>)r	   ÚmaxÚsizeÚtopkÚtÚeqr
   Z	expand_as)r   r   r   Ú_Úpredr   r   r   Úaccuracy   s    
r   )r   )Útypingr   ZtorchZTensorr   r   r   r   r   Ú<module>   s   