a
    þd
  ã                   @   sz   d dl mZmZ d dlZd dlmZ d dlmZ eeeeef dœdd„Zeeeef edœd	d
„Z	eeedœdd„Z
dS )é    )ÚTupleÚUnionN)ÚTensor)Ú_check_same_shape)ÚpredsÚtargetÚreturnc                 C   sR   t | |ƒ | jr| n|  ¡ } |jr&|n| ¡ }t t | | ¡¡}| ¡ }||fS )zÆUpdate and returns variables required to compute Mean Absolute Error.

    Check for same shape of input tensors.

    Args:
        preds: Predicted tensor
        target: Ground truth tensor

    )r   Zis_floating_pointÚfloatÚtorchÚsumÚabsZnumel©r   r   Úsum_abs_errorÚn_obs© r   úo/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torchmetrics/functional/regression/mae.pyÚ_mean_absolute_error_update   s    

r   )r   r   r   c                 C   s   | | S )aÂ  Compute Mean Absolute Error.

    Args:
        sum_abs_error: Sum of absolute value of errors over all observations
        n_obs: Number of predictions or observations

    Example:
        >>> preds = torch.tensor([0., 1, 2, 3])
        >>> target = torch.tensor([0., 1, 2, 2])
        >>> sum_abs_error, n_obs = _mean_absolute_error_update(preds, target)
        >>> _mean_absolute_error_compute(sum_abs_error, n_obs)
        tensor(0.2500)

    r   )r   r   r   r   r   Ú_mean_absolute_error_compute(   s    r   c                 C   s   t | |ƒ\}}t||ƒS )aˆ  Compute mean absolute error.

    Args:
        preds: estimated labels
        target: ground truth labels

    Return:
        Tensor with MAE

    Example:
        >>> from torchmetrics.functional.regression import mean_absolute_error
        >>> x = torch.tensor([0., 1, 2, 3])
        >>> y = torch.tensor([0., 1, 2, 2])
        >>> mean_absolute_error(x, y)
        tensor(0.2500)

    )r   r   r   r   r   r   Úmean_absolute_error:   s    r   )Útypingr   r   r
   r   Ztorchmetrics.utilities.checksr   Úintr   r   r   r   r   r   r   Ú<module>   s   