
    i7
              	       r    d dl Z d dl mZ d dlmZ dededeeef   fdZ	 dded	ed
edefdZdededefdZy)    N)Tensor)_check_same_shapepredstargetreturnc                     t        | |       | |z
  j                         j                         }|j                         j                         }||fS )zUpdate and returns variables required to compute Weighted Absolute Percentage Error.

    Check for same shape of input tensors.

    Args:
        preds: Predicted tensor
        target: Ground truth tensor

    )r   abssumr   r   sum_abs_error	sum_scales       }/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torchmetrics/functional/regression/wmape.py/_weighted_mean_absolute_percentage_error_updater      sH     eV$V^((*..0M

  "I)##    r   r   epsilonc                 6    | t        j                  ||      z  S )zCompute Weighted Absolute Percentage Error.

    Args:
        sum_abs_error: scalar with sum of absolute errors
        sum_scale: scalar with sum of target values
        epsilon: small float to prevent division by zero

    )min)torchclamp)r   r   r   s      r   0_weighted_mean_absolute_percentage_error_computer   *   s     5;;yg>>>r   c                 8    t        | |      \  }}t        ||      S )a  Compute weighted mean absolute percentage error (`WMAPE`_).

    The output of WMAPE metric is a non-negative floating point, where the optimal value is 0. It is computes as:

    .. math::
        \text{WMAPE} = \frac{\sum_{t=1}^n | y_t - \hat{y}_t | }{\sum_{t=1}^n |y_t| }

    Where :math:`y` is a tensor of target values, and :math:`\hat{y}` is a tensor of predictions.

    Args:
        preds: estimated labels
        target: ground truth labels

    Return:
        Tensor with WMAPE.

    Example:
        >>> from torch import randn
        >>> preds = randn(20,)
        >>> target = randn(20,)
        >>> weighted_mean_absolute_percentage_error(preds, target)
        tensor(1.3967)

    )r   r   r   s       r   'weighted_mean_absolute_percentage_errorr   :   s$    2  OuV\]M9;M9UUr   )g-`>)	r   r   torchmetrics.utilities.checksr   tupler   floatr   r    r   r   <module>r      s      ;$$$ 66>$0 ??? ? 	? V6 V6 Vf Vr   