
    in                     P   d dl mZ d dlmZmZmZmZ d dl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 d d
lmZmZ d dlmZ esg dZ G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z y)    )Sequence)AnyCallableOptionalUnionN)Tensor)Literal)Metric)rank_zero_warn)dim_zero_cat)_MATPLOTLIB_AVAILABLE)_AX_TYPE_PLOT_OUT_TYPE)Running)zSumMetric.plotzMeanMetric.plotzMaxMetric.plotzMinMetric.plotc                        e Zd ZU dZdZdZdZeed<   	 	 dde	e
ef   de	eef   de	ed	   ef   d
ededdf fdZ	 dde	eef   dee	eef      deeef   fdZde	eef   ddfdZdefdZ xZS )BaseAggregatorae  Base class for aggregation metrics.

    Args:
        fn: string specifying the reduction function
        default_value: default tensor value to use for the metric state
        nan_strategy: options:
            - ``'error'``: if any `nan` values are encountered will give a RuntimeError
            - ``'warn'``: if any `nan` values are encountered will give a warning and continue
            - ``'ignore'``: all `nan` values are silently removed
            - ``'disable'``: disable all `nan` checks
            - a float: if a float is provided will impute any `nan` values with this value

        state_name: name of the metric state
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError:
            If ``nan_strategy`` is not one of ``error``, ``warn``, ``ignore``, ``disable`` or a float

    NFfull_state_updatevaluefndefault_valuenan_strategyerrorwarnignoredisable
state_namekwargsreturnc                     t        |   di | d}||vr"t        |t              st	        d| d| d      || _        | j                  |||       || _        y )Nr   z6Arg `nan_strategy` should either be a float or one of z	 but got .defaultdist_reduce_fx )super__init__
isinstancefloat
ValueErrorr   	add_stater   )selfr   r   r   r   r   allowed_nan_strategy	__class__s          m/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torchmetrics/aggregation.pyr'   zBaseAggregator.__init__:   sv     	"6"E33J|UZ<[HI]H^^ghtguuvw  )z=L$    xweightc                    t        |t              s,t        j                  || j                  | j
                        }|<t        |t              s,t        j                  || j                  | j
                        }| j                  dk7  r,t        j                  |      }|t        j                  |      }n8t        j                  |      j                         }t        j                  |      }|j                         s|j                         r| j                  dk(  rt        d      | j                  dv r2| j                  dk(  rt        dt               |||z      }|||z      }nbt        | j                  t              st!        d| j                         | j                  |||z  <   d	|||z  <   nt        j                  |      }|j#                  | j                        |j#                  | j                        fS )
z3Convert input ``x`` to a tensor and check for Nans.dtypedevicer   r   z"Encountered `nan` values in tensor)r   r   r   z4Encountered `nan` values in tensor. Will be removed.z+`nan_strategy` shall be float but you pass    )r(   r   torch	as_tensorr5   r6   r   isnan
zeros_likebool	ones_likeanyRuntimeErrorr   UserWarningr)   r*   to)r,   r1   r2   nansnans_weights        r/   _cast_and_nan_check_inputz(BaseAggregator._cast_and_nan_check_inputM   s    !V$DKKHAj&@__V4::dkkRF	);;q>D!#kk&1#..t499;+xxz[__.$$/&'KLL$$(::((F2&']_jkD;./0A#d[&8$9:F%d&7&7?(+VW[WhWhVi)jkk,0,=,=Ad[()12F4+-.__Q'FttDJJ4::!666r0   c                      y)zOverwrite in child class.Nr%   )r,   r   s     r/   updatezBaseAggregator.updaten   s    r0   c                 .    t        | | j                        S zCompute the aggregated value.)getattrr   r,   s    r/   computezBaseAggregator.computeq   s    tT__--r0   )r   r   N)__name__
__module____qualname____doc__is_differentiablehigher_is_betterr   r<   __annotations__r   r   strr   listr	   r)   r   r'   r   tuplerD   rF   rK   __classcell__r.   s   @r/   r   r       s    * #t# U\!%(C- % VT\*% G$HI5PQ	%
 % % 
%( QU7uf}%7/7eVm8L/M7	vv~	7B(E%-0 (T (. .r0   r   c                        e Zd ZU dZdZeed<   eed<   	 ddee	d   e
f   dedd	f fd
Zdee
ef   dd	fdZ	 ddeeeee   f      dee   defdZ xZS )	MaxMetrica}  Aggregate a stream of value into their maximum value.

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

    - ``value`` (:class:`~float` or :class:`~torch.Tensor`): a single float or an tensor of float values with
      arbitrary shape ``(...,)``.

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

    - ``agg`` (:class:`~torch.Tensor`): scalar float tensor with aggregated maximum value over all inputs received

    Args:
        nan_strategy: options:
            - ``'error'``: if any `nan` values are encountered will give a RuntimeError
            - ``'warn'``: if any `nan` values are encountered will give a warning and continue
            - ``'ignore'``: all `nan` values are silently removed
            - ``'disable'``: disable all `nan` checks
            - a float: if a float is provided will impute any `nan` values with this value

        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError:
            If ``nan_strategy`` is not one of ``error``, ``warn``, ``ignore``, ``disable`` or a float

    Example:
        >>> from torch import tensor
        >>> from torchmetrics.aggregation import MaxMetric
        >>> metric = MaxMetric()
        >>> metric.update(1)
        >>> metric.update(tensor([2, 3]))
        >>> metric.compute()
        tensor(3.)

    Tr   	max_valuer   r   r   r   Nc                     t        |   dt        j                  t	        d      t        j
                                |fddi| y )Nmaxinfr5   r   r[   r&   r'   r8   tensorr)   get_default_dtyper,   r   r   r.   s      r/   r'   zMaxMetric.__init__   sJ    
 	\\%,e.E.E.GHH	
 #		

 	
r0   r   c                     | j                  |      \  }}|j                         r9t        j                  | j                  t        j                  |            | _        yyzUpdate state with data.

        Args:
            value: Either a float or tensor containing data. Additional tensor
                dimensions will be flattened

        N)rD   numelr8   r]   r[   r,   r   _s      r/   rF   zMaxMetric.update   E     11%8q;;="YYt~~uyy7GHDN r0   valaxc                 &    | j                  ||      S )a  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
            >>> from torchmetrics.aggregation import MaxMetric
            >>> metric = MaxMetric()
            >>> metric.update([1, 2, 3])
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> from torchmetrics.aggregation import MaxMetric
            >>> metric = MaxMetric()
            >>> values = [ ]
            >>> for i in range(10):
            ...     values.append(metric(i))
            >>> fig_, ax_ = metric.plot(values)

        _plotr,   rj   rk   s      r/   plotzMaxMetric.plot       L zz#r""r0   r   NNrM   rN   rO   rP   r   r<   rS   r   r   r	   r)   r   r'   rF   r   r   r   r   rp   rW   rX   s   @r/   rZ   rZ   v       "H #t" U[
G$HI5PQ
 
 
	

IE%-0 
IT 
I _c&#E&(6*:":;<&#IQRZI[&#	&#r0   rZ   c                        e Zd ZU dZdZeed<   eed<   	 ddee	d   e
f   dedd	f fd
Zdee
ef   dd	fdZ	 ddeeeee   f      dee   defdZ xZS )	MinMetrica}  Aggregate a stream of value into their minimum value.

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

    - ``value`` (:class:`~float` or :class:`~torch.Tensor`): a single float or an tensor of float values with
      arbitrary shape ``(...,)``.

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

    - ``agg`` (:class:`~torch.Tensor`): scalar float tensor with aggregated minimum value over all inputs received

    Args:
        nan_strategy: options:
            - ``'error'``: if any `nan` values are encountered will give a RuntimeError
            - ``'warn'``: if any `nan` values are encountered will give a warning and continue
            - ``'ignore'``: all `nan` values are silently removed
            - ``'disable'``: disable all `nan` checks
            - a float: if a float is provided will impute any `nan` values with this value

        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError:
            If ``nan_strategy`` is not one of ``error``, ``warn``, ``ignore``, ``disable`` or a float

    Example:
        >>> from torch import tensor
        >>> from torchmetrics.aggregation import MinMetric
        >>> metric = MinMetric()
        >>> metric.update(1)
        >>> metric.update(tensor([2, 3]))
        >>> metric.compute()
        tensor(1.)

    Tr   	min_valuer   r   r   r   Nc                     t        |   dt        j                  t	        d      t        j
                               |fddi| y )Nminr^   r_   r   rx   r`   rc   s      r/   r'   zMinMetric.__init__  sG    
 	LLuU-D-D-FG	
 #		

 	
r0   r   c                     | j                  |      \  }}|j                         r9t        j                  | j                  t        j                  |            | _        yyre   )rD   rf   r8   rz   rx   rg   s      r/   rF   zMinMetric.update  ri   r0   rj   rk   c                 &    | j                  ||      S )a  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
            >>> from torchmetrics.aggregation import MinMetric
            >>> metric = MinMetric()
            >>> metric.update([1, 2, 3])
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> from torchmetrics.aggregation import MinMetric
            >>> metric = MinMetric()
            >>> values = [ ]
            >>> for i in range(10):
            ...     values.append(metric(i))
            >>> fig_, ax_ = metric.plot(values)

        rm   ro   s      r/   rp   zMinMetric.plot!  rq   r0   rr   rs   rt   rX   s   @r/   rw   rw      ru   r0   rw   c                        e Zd ZU dZeed<   	 ddeed   ef   de	ddf fdZ
d	eeef   ddfd
Z	 ddeeeee   f      dee   defdZ xZS )	SumMetricai  Aggregate a stream of value into their sum.

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

    - ``value`` (:class:`~float` or :class:`~torch.Tensor`): a single float or an tensor of float values with
      arbitrary shape ``(...,)``.

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

    - ``agg`` (:class:`~torch.Tensor`): scalar float tensor with aggregated sum over all inputs received

    Args:
        nan_strategy: options:
            - ``'error'``: if any `nan` values are encountered will give a RuntimeError
            - ``'warn'``: if any `nan` values are encountered will give a warning and continue
            - ``'ignore'``: all `nan` values are silently removed
            - ``'disable'``: disable all `nan` checks
            - a float: if a float is provided will impute any `nan` values with this value

        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError:
            If ``nan_strategy`` is not one of ``error``, ``warn``, ``ignore``, ``disable`` or a float

    Example:
        >>> from torch import tensor
        >>> from torchmetrics.aggregation import SumMetric
        >>> metric = SumMetric()
        >>> metric.update(1)
        >>> metric.update(tensor([2, 3]))
        >>> metric.compute()
        tensor(6.)

    	sum_valuer   r   r   r   Nc                 |    t        |   dt        j                  dt        j                               |fddi| y )Nsum        r_   r   r   )r&   r'   r8   ra   rb   rc   s      r/   r'   zSumMetric.__init__q  sC    
 	LLE$;$;$=>	
 #		

 	
r0   r   c                     | j                  |      \  }}|j                         r$| xj                  |j                         z  c_        yyre   )rD   rf   r   r   rg   s      r/   rF   zSumMetric.update~  s:     11%8q;;=NNeiik)N r0   rj   rk   c                 &    | j                  ||      S )a  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
            >>> from torchmetrics.aggregation import SumMetric
            >>> metric = SumMetric()
            >>> metric.update([1, 2, 3])
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> from torch import rand, randint
            >>> from torchmetrics.aggregation import SumMetric
            >>> metric = SumMetric()
            >>> values = [ ]
            >>> for i in range(10):
            ...     values.append(metric([i, i+1]))
            >>> fig_, ax_ = metric.plot(values)

        rm   ro   s      r/   rp   zSumMetric.plot  s    N zz#r""r0   rr   rs   )rM   rN   rO   rP   r   rS   r   r	   r)   r   r'   rF   r   r   r   r   rp   rW   rX   s   @r/   r~   r~   J  s    "H  U[
G$HI5PQ
 
 
	

*E%-0 
*T 
* _c'#E&(6*:":;<'#IQRZI['#	'#r0   r~   c                   v     e Zd ZU dZeed<   	 ddeed   ef   de	ddf fdZ
deeef   ddfd	Zdefd
Z xZS )	CatMetricak  Concatenate a stream of values.

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

    - ``value`` (:class:`~float` or :class:`~torch.Tensor`): a single float or an tensor of float values with
      arbitrary shape ``(...,)``.

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

    - ``agg`` (:class:`~torch.Tensor`): scalar float tensor with concatenated values over all input received

    Args:
        nan_strategy: options:
            - ``'error'``: if any `nan` values are encountered will give a RuntimeError
            - ``'warn'``: if any `nan` values are encountered will give a warning and continue
            - ``'ignore'``: all `nan` values are silently removed
            - ``'disable'``: disable all `nan` checks
            - a float: if a float is provided will impute any `nan` values with this value

        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError:
            If ``nan_strategy`` is not one of ``error``, ``warn``, ``ignore``, ``disable`` or a float

    Example:
        >>> from torch import tensor
        >>> from torchmetrics.aggregation import CatMetric
        >>> metric = CatMetric()
        >>> metric.update(1)
        >>> metric.update(tensor([2, 3]))
        >>> metric.compute()
        tensor([1., 2., 3.])

    r   r   r   r   r   Nc                 *    t        |   dg |fi | y )Ncat)r&   r'   rc   s      r/   r'   zCatMetric.__init__  s    
 	L;F;r0   c                     | j                  |      \  }}|j                         r| j                  j                  |       yyre   )rD   rf   r   appendrg   s      r/   rF   zCatMetric.update  s8     11%8q;;=JJe$ r0   c                     t        | j                  t              r!| j                  rt        | j                        S | j                  S rH   )r(   r   rU   r   rJ   s    r/   rK   zCatMetric.compute  s/    djj$'DJJ

++zzr0   rr   )rM   rN   rO   rP   r   rS   r   r	   r)   r   r'   rF   rK   rW   rX   s   @r/   r   r     sp    "H M U[<G$HI5PQ< < 
	<
%E%-0 
%T 
% r0   r   c                        e Zd ZU dZeed<   eed<   	 ddeed   ef   de	ddf fd	Z
dd
eeef   deeedf   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 )
MeanMetrica-  Aggregate a stream of value into their mean value.

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

    - ``value`` (:class:`~float` or :class:`~torch.Tensor`): a single float or an tensor of float values with
      arbitrary shape ``(...,)``.
    - ``weight`` (:class:`~float` or :class:`~torch.Tensor`): a single float or an tensor of float value with
      arbitrary shape ``(...,)``. Needs to be broadcastable with the shape of ``value`` tensor.

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

    - ``agg`` (:class:`~torch.Tensor`): scalar float tensor with aggregated (weighted) mean over all inputs received

    Args:
        nan_strategy: options:
            - ``'error'``: if any `nan` values are encountered will give a RuntimeError
            - ``'warn'``: if any `nan` values are encountered will give a warning and continue
            - ``'ignore'``: all `nan` values are silently removed
            - ``'disable'``: disable all `nan` checks
            - a float: if a float is provided will impute any `nan` values with this value

        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError:
            If ``nan_strategy`` is not one of ``error``, ``warn``, ``ignore``, ``disable`` or a float

    Example:
        >>> from torchmetrics.aggregation import MeanMetric
        >>> metric = MeanMetric()
        >>> metric.update(1)
        >>> metric.update(torch.tensor([2, 3]))
        >>> metric.compute()
        tensor(2.)

    
mean_valuer2   r   r   r   r   Nc                     t        |   dt        j                  dt        j                               |fddi| | j                  dt        j                  dt        j                               d       y )Nr   r   r_   r   r   r2   r"   )r&   r'   r8   ra   rb   r+   rc   s      r/   r'   zMeanMetric.__init__  sl    
 	LLE$;$;$=>	
 $		

 	
 	xcAXAXAZ)[lqrr0   r   c                 H   t        |t              s,t        j                  || j                  | j
                        }|t        j                  |      }n<t        |t              s,t        j                  || j                  | j
                        }t        j                  ||j                        }| j                  ||      \  }}|j                         dk(  ry| xj                  ||z  j                         z  c_        | xj                  |j                         z  c_        y)a  Update state with data.

        Args:
            value: Either a float or tensor containing data. Additional tensor
                dimensions will be flattened
            weight: Either a float or tensor containing weights for calculating
                the average. Shape of weight should be able to broadcast with
                the shape of `value`. Default to None corresponding to simple
                harmonic average.

        r4   Nr   )r(   r   r8   r9   r5   r6   r=   broadcast_toshaperD   rf   r   r   r2   )r,   r   r2   s      r/   rF   zMeanMetric.update,  s     %(OOEDKKPE>__U+FFF+__V4::dkkRF##FEKK866ufEv;;=AEFN//11vzz|#r0   c                 4    | j                   | j                  z  S rH   )r   r2   rJ   s    r/   rK   zMeanMetric.computeG  s    ,,r0   rj   rk   c                 &    | j                  ||      S )a  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
            >>> from torchmetrics.aggregation import MeanMetric
            >>> metric = MeanMetric()
            >>> metric.update([1, 2, 3])
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> from torchmetrics.aggregation import MeanMetric
            >>> metric = MeanMetric()
            >>> values = [ ]
            >>> for i in range(10):
            ...     values.append(metric([i, i+1]))
            >>> fig_, ax_ = metric.plot(values)

        rm   ro   s      r/   rp   zMeanMetric.plotK  rq   r0   rr   rL   rs   )rM   rN   rO   rP   r   rS   r   r	   r)   r   r'   rF   rK   r   r   r   r   rp   rW   rX   s   @r/   r   r     s    #J N U[sG$HI5PQs s 
	s$E%-0 $%vt@S:T $`d $6- -
 _c&#E&(6*:":;<&#IQRZI[&#	&#r0   r   c            	       J     e Zd ZdZ	 	 d	dedeed   ef   deddf fdZ	 xZ
S )
RunningMeanai	  Aggregate a stream of value into their mean over a running window.

    Using this metric compared to `MeanMetric` allows for calculating metrics over a running window of values, instead
    of the whole history of values. This is beneficial when you want to get a better estimate of the metric during
    training and don't want to wait for the whole training to finish to get epoch level estimates.

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

    - ``value`` (:class:`~float` or :class:`~torch.Tensor`): a single float or an tensor of float values with
      arbitrary shape ``(...,)``.

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

    - ``agg`` (:class:`~torch.Tensor`): scalar float tensor with aggregated sum over all inputs received

    Args:
        nan_strategy: options:
            - ``'error'``: if any `nan` values are encountered will give a RuntimeError
            - ``'warn'``: if any `nan` values are encountered will give a warning and continue
            - ``'ignore'``: all `nan` values are silently removed
            - ``'disable'``: disable all `nan` checks
            - a float: if a float is provided will impute any `nan` values with this value

        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError:
            If ``nan_strategy`` is not one of ``error``, ``warn``, ``ignore``, ``disable`` or a float

    Example:
        >>> from torch import tensor
        >>> from torchmetrics.aggregation import RunningMean
        >>> metric = RunningMean(window=3)
        >>> for i in range(6):
        ...     current_val = metric(tensor([i]))
        ...     running_val = metric.compute()
        ...     total_val = tensor(sum(list(range(i+1)))) / (i+1)  # total mean over all samples
        ...     print(f"{current_val=}, {running_val=}, {total_val=}")
        current_val=tensor(0.), running_val=tensor(0.), total_val=tensor(0.)
        current_val=tensor(1.), running_val=tensor(0.5000), total_val=tensor(0.5000)
        current_val=tensor(2.), running_val=tensor(1.), total_val=tensor(1.)
        current_val=tensor(3.), running_val=tensor(2.), total_val=tensor(1.5000)
        current_val=tensor(4.), running_val=tensor(3.), total_val=tensor(2.)
        current_val=tensor(5.), running_val=tensor(4.), total_val=tensor(2.5000)

    windowr   r   r   r   Nc                 >    t         |   t        dd|i||       y Nr   )base_metricr   r%   )r&   r'   r   r,   r   r   r   r.   s       r/   r'   zRunningMean.__init__  s%     	Z%T\%TV%T]cdr0      r   rM   rN   rO   rP   intr   r	   r)   r   r'   rW   rX   s   @r/   r   r   t  sW    -b TZee G$HI5PQe 	e
 
e er0   r   c            	       J     e Zd ZdZ	 	 d	dedeed   ef   deddf fdZ	 xZ
S )

RunningSumay	  Aggregate a stream of value into their sum over a running window.

    Using this metric compared to `SumMetric` allows for calculating metrics over a running window of values, instead
    of the whole history of values. This is beneficial when you want to get a better estimate of the metric during
    training and don't want to wait for the whole training to finish to get epoch level estimates.

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

    - ``value`` (:class:`~float` or :class:`~torch.Tensor`): a single float or an tensor of float values with
      arbitrary shape ``(...,)``.

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

    - ``agg`` (:class:`~torch.Tensor`): scalar float tensor with aggregated sum over all inputs received

    Args:
        window: The size of the running window.
        nan_strategy: options:
            - ``'error'``: if any `nan` values are encountered will give a RuntimeError
            - ``'warn'``: if any `nan` values are encountered will give a warning and continue
            - ``'ignore'``: all `nan` values are silently removed
            - ``'disable'``: disable all `nan` checks
            - a float: if a float is provided will impute any `nan` values with this value

        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError:
            If ``nan_strategy`` is not one of ``error``, ``warn``, ``ignore``, ``disable`` or a float

    Example:
        >>> from torch import tensor
        >>> from torchmetrics.aggregation import RunningSum
        >>> metric = RunningSum(window=3)
        >>> for i in range(6):
        ...     current_val = metric(tensor([i]))
        ...     running_val = metric.compute()
        ...     total_val = tensor(sum(list(range(i+1))))  # total sum over all samples
        ...     print(f"{current_val=}, {running_val=}, {total_val=}")
        current_val=tensor(0.), running_val=tensor(0.), total_val=tensor(0)
        current_val=tensor(1.), running_val=tensor(1.), total_val=tensor(1)
        current_val=tensor(2.), running_val=tensor(3.), total_val=tensor(3)
        current_val=tensor(3.), running_val=tensor(6.), total_val=tensor(6)
        current_val=tensor(4.), running_val=tensor(9.), total_val=tensor(10)
        current_val=tensor(5.), running_val=tensor(12.), total_val=tensor(15)

    r   r   r   r   r   Nc                 >    t         |   t        dd|i||       y r   )r&   r'   r~   r   s       r/   r'   zRunningSum.__init__  s%     	Y%SL%SF%S\bcr0   r   r   rX   s   @r/   r   r     sW    .d TZdd G$HI5PQd 	d
 
d dr0   r   )!collections.abcr   typingr   r   r   r   r8   r   typing_extensionsr	   torchmetrics.metricr
   torchmetrics.utilitiesr   torchmetrics.utilities.datar   torchmetrics.utilities.importsr   torchmetrics.utilities.plotr   r   torchmetrics.wrappers.runningr   __doctest_skip__r   rZ   rw   r~   r   r   r   r   r%   r0   r/   <module>r      s    % 1 1   % & 1 4 @ @ 1`S.V S.lg# g#Tg# g#Tg# g#T> >B|# |#~6e' 6er7d 7dr0   