
    iQ                         d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZ esd	gZ G d
 de      Zy)    )Sequence)AnyListOptionalUnion)Tensor)relative_average_spectral_error)Metric)dim_zero_cat)_MATPLOTLIB_AVAILABLE)_AX_TYPE_PLOT_OUT_TYPEz!RelativeAverageSpectralError.plotc                        e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	e
ed<   ee   ed	<   ee   ed
<   	 ddedeeef   ddf fdZd	ed
eddfdZdefdZ	 ddeeeee   f      dee   defdZ xZS )RelativeAverageSpectralErrora+  Computes Relative Average Spectral Error (RASE) (RelativeAverageSpectralError_).

    As input to ``forward`` and ``update`` the metric accepts the following input

    - ``preds`` (:class:`~torch.Tensor`): Predictions from model of shape ``(N,C,H,W)``
    - ``target`` (:class:`~torch.Tensor`): Ground truth values of shape ``(N,C,H,W)``

    As output of `forward` and `compute` the metric returns the following output

    - ``rase`` (:class:`~torch.Tensor`): returns float scalar tensor with average RASE value over sample

    Args:
        window_size: Sliding window used for rmse calculation
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Return:
        Relative Average Spectral Error (RASE)

    Example:
        >>> from torch import rand
        >>> preds = rand(4, 3, 16, 16)
        >>> target = rand(4, 3, 16, 16)
        >>> rase = RelativeAverageSpectralError()
        >>> rase(preds, target)
        tensor(5326.40...)

    Raises:
        ValueError: If ``window_size`` is not a positive integer.

    Fhigher_is_betterTis_differentiablefull_state_updateg        plot_lower_boundpredstargetwindow_sizekwargsreturnNc                     t        |   di | t        |t              rt        |t              r|dk  rt	        d|       || _        | j                  dg d       | j                  dg d       y )N   zEArgument `window_size` is expected to be a positive integer, but got r   cat)defaultdist_reduce_fxr    )super__init__
isinstanceint
ValueErrorr   	add_state)selfr   r   	__class__s      l/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torchmetrics/image/rase.pyr!   z%RelativeAverageSpectralError.__init__F   sr    
 	"6"+s+
;0LQ\_`Q`depdqrss&w5AxEB    c                 p    | j                   j                  |       | j                  j                  |       y)z*Update state with predictions and targets.N)r   appendr   r&   r   r   s      r(   updatez#RelativeAverageSpectralError.updateT   s&    

% 6"r)   c                     t        | j                        }t        | j                        }t        ||| j                        S )z/Compute Relative Average Spectral Error (RASE).)r   r   r   r	   r   r,   s      r(   computez$RelativeAverageSpectralError.computeY   s3    TZZ(dkk*.ufd>N>NOOr)   valaxc                 &    | j                  ||      S )aX  Plot a single or multiple values from the metric.

        Args:
            val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
                If no value is provided, will automatically call `metric.compute` and plot that result.
            ax: An matplotlib axis object. If provided will add plot to that axis

        Returns:
            Figure and Axes object

        Raises:
            ModuleNotFoundError:
                If `matplotlib` is not installed

        .. plot::
            :scale: 75

            >>> # Example plotting a single value
            >>> import torch
            >>> from torchmetrics.image import RelativeAverageSpectralError
            >>> metric = RelativeAverageSpectralError()
            >>> metric.update(torch.rand(4, 3, 16, 16), torch.rand(4, 3, 16, 16))
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> from torch import rand
            >>> from torchmetrics.image import RelativeAverageSpectralError
            >>> metric = RelativeAverageSpectralError()
            >>> values = [ ]
            >>> for _ in range(10):
            ...     values.append(metric(rand(4, 3, 16, 16), rand(4, 3, 16, 16)))
            >>> fig_, ax_ = metric.plot(values)

        )_plot)r&   r0   r1   s      r(   plotz!RelativeAverageSpectralError.plot_   s    P zz#r""r)   )   )NN)__name__
__module____qualname____doc__r   bool__annotations__r   r   r   floatr   r   r#   dictstrr   r!   r-   r/   r   r   r   r   r   r4   __classcell__)r'   s   @r(   r   r      s    > #d""t"#t#!e!<L CC sCx.C 
	C#F #F #t #
P P _c(#E&(6*:":;<(#IQRZI[(#	(#r)   r   N)collections.abcr   typingr   r   r   r   torchr   "torchmetrics.functional.image.raser	   torchmetrics.metricr
   torchmetrics.utilities.datar   torchmetrics.utilities.importsr   torchmetrics.utilities.plotr   r   __doctest_skip__r   r   r)   r(   <module>rI      s<    % - -  N & 4 @ @;<i#6 i#r)   