o
    .wi'                  
   @   s   d dl mZ d dlZd dlmZ d dlmZ dedededeeef fd	d
Zdedeeef defddZ	ddedededefddZ
dS )    )UnionN)Tensor)_check_same_shapepredstargetnum_outputsreturnc                 C   sp   t | | |dkr| d} |d}| jr| n|  } |jr!|n| }tjt| | dd}||jd fS )a  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
        num_outputs: Number of outputs in multioutput setting

       r   )dim)r   viewis_floating_pointfloattorchsumabsshape)r   r   r   sum_abs_error r   c/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/torchmetrics/functional/regression/mae.py_mean_absolute_error_update   s   


r   r   num_obsc                 C   s   | | S )a  Compute Mean Absolute Error.

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

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

    r   )r   r   r   r   r   _mean_absolute_error_compute+   s   r   r	   c                 C   s   t | ||d\}}t||S )a  Compute mean absolute error.

    Args:
        preds: estimated labels
        target: ground truth labels
        num_outputs: Number of outputs in multioutput setting

    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   r   r   r   r   r   mean_absolute_error=   s   
r   )r	   )typingr   r   r   torchmetrics.utilities.checksr   inttupler   r   r   r   r   r   r   <module>   s   " 