a
    dV                     @   s   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ef dddZdeeeef e	ed	d
dZ
deee	eedddZdS )    )TupleUnionN)Tensor)_check_same_shape)predstargetnum_outputsreturnc                 C   sR   t | | |dkr&| d} |d}| | }tj|| dd}|jd }||fS )a  Update and returns variables required to compute Mean Squared 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   )Zdim)r   viewtorchsumshape)r   r   r   diffsum_squared_errorn_obs r   o/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torchmetrics/functional/regression/mse.py_mean_squared_error_update   s    



r   T)r   r   squaredr	   c                 C   s   |r| | S t | | S )a  Compute Mean Squared Error.

    Args:
        sum_squared_error: Sum of square of errors over all observations
        n_obs: Number of predictions or observations
        squared: Returns RMSE value if set to False.

    Example:
        >>> preds = torch.tensor([0., 1, 2, 3])
        >>> target = torch.tensor([0., 1, 2, 2])
        >>> sum_squared_error, n_obs = _mean_squared_error_update(preds, target, num_outputs=1)
        >>> _mean_squared_error_compute(sum_squared_error, n_obs)
        tensor(0.2500)

    )r   sqrt)r   r   r   r   r   r   _mean_squared_error_compute+   s    r   r
   )r   r   r   r   r	   c                 C   s    t | ||d\}}t|||dS )a  Compute mean squared error.

    Args:
        preds: estimated labels
        target: ground truth labels
        squared: returns RMSE value if set to False
        num_outputs: Number of outputs in multioutput setting

    Return:
        Tensor with MSE

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

    )r   )r   )r   r   )r   r   r   r   r   r   r   r   r   mean_squared_error>   s    r   )T)Tr
   )typingr   r   r   r   Ztorchmetrics.utilities.checksr   intr   boolr   r   r   r   r   r   <module>   s   