o
    Ÿôjàn  ã                   @   s   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sNg d¢ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZ dS )é    )ÚSequence)ÚAnyÚCallableÚOptionalÚUnionN)ÚTensor)ÚLiteral)ÚMetric)Úrank_zero_warn)Údim_zero_cat)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPE)ÚRunning)úSumMetric.plotúMeanMetric.plotúMaxMetric.plotúMinMetric.plotc                       sÐ   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d„Z	dde	eef dee	eef  deeef fdd„Zde	eef ddfdd„Zdefdd„Z‡  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ÚerrorÚvalueÚfnÚdefault_valueÚnan_strategy©r   ÚwarnÚignoreÚdisableÚ
state_nameÚkwargsÚreturnc                    s^   t ƒ jdi |¤Ž d}||vrt|tƒstd|› d|› d�ƒ‚|| _| j|||d� || _d S )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    Zallowed_nan_strategy©Ú	__class__r&   úk/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torchmetrics/aggregation.pyr(   :   s   ÿ
zBaseAggregator.__init__ÚxÚweightc                 C   s<  t |tƒstj|| j| jd�}|dur"t |tƒs"tj|| j| jd�}| jdkr�t |¡}|dur6t |¡}nt |¡ 	¡ }t 
|¡}| ¡ sJ| ¡ rŒ| jdkrStdƒ‚| jdv rq| jdkrbtdtƒ |||B   }|||B   }n!t | jtƒstd	| j› �ƒ‚| j|||B < d
|||B < nt 
|¡}| | j¡| | j¡fS )z3Convert input ``x`` to a tensor and check for Nans.©ÚdtypeÚdeviceNr   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_tensorr4   r5   r   ÚisnanÚ
zeros_likeÚboolÚ	ones_likeÚanyÚRuntimeErrorr
   ÚUserWarningr*   r+   Úto)r-   r1   r2   ÚnansZnans_weightr&   r&   r0   Ú_cast_and_nan_check_inputM   s2   







€
z(BaseAggregator._cast_and_nan_check_inputc                 C   s   dS )zOverwrite in child class.Nr&   )r-   r   r&   r&   r0   Úupdaten   s    zBaseAggregator.updatec                 C   s   t | | jƒS ©zCompute the aggregated value.)Úgetattrr   ©r-   r&   r&   r0   Úcomputeq   ó   zBaseAggregator.compute)r   r   ©N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_differentiableÚhigher_is_betterr   r;   Ú__annotations__r   r   Ústrr   Úlistr   r*   r   r(   r   ÚtuplerB   rC   rG   Ú__classcell__r&   r&   r.   r0   r       s<   
 û
þ
ýüûúùÿ
ÿÿ

þ!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d„Zdee
ef d	d
fdd„Z	
ddeeeee f  dee d	efdd„Z‡  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    r!   Nc                    s4   t ƒ jdtjtdƒt ¡ d� |fddi|¤Ž d S )NÚmaxÚinf©r4   r   rW   ©r'   r(   r7   Útensorr*   Úget_default_dtype©r-   r   r    r.   r&   r0   r(   ž   s   ýü
ûzMaxMetric.__init__r   c                 C   ó4   |   |¡\}}| ¡ rt | jt |¡¡| _dS dS ©z¬Update state with data.

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

        N)rB   Únumelr7   rX   rW   ©r-   r   Ú_r&   r&   r0   rC   «   ó   ÿzMaxMetric.updateÚvalÚaxc                 C   ó   |   ||¡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-   re   rf   r&   r&   r0   Úplot·   ó   &r   ©r   ©NN©rJ   rK   rL   rM   r   r;   rP   r   r   r   r*   r   r(   rC   r   r   r   r   rk   rT   r&   r&   r.   r0   rV   v   ó*   
 $þþýüÿÿÿþrV   c                       rU   )Ú	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    r!   Nc                    s2   t ƒ jdtjtdƒt ¡ d�|fddi|¤Ž d S )NÚminrY   rZ   r   rr   r[   r^   r.   r&   r0   r(     s   ýü
ûzMinMetric.__init__r   c                 C   r_   r`   )rB   ra   r7   rs   rr   rb   r&   r&   r0   rC     rd   zMinMetric.updatere   rf   c                 C   rg   )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)

        rh   rj   r&   r&   r0   rk   !  rl   r   rm   rn   ro   r&   r&   r.   r0   rq   à   rp   rq   c                       s�   e Zd ZU dZeed< 	ddeed ef de	ddf‡ fd	d
„Z
deeef ddfdd„Z	ddeeeee f  dee defdd„Z‡  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    r!   Nc                    s.   t ƒ jdtjdt ¡ d�|fddi|¤Ž d S )NÚsumç        rZ   r   ru   )r'   r(   r7   r\   r]   r^   r.   r&   r0   r(   q  s   ýü
ûzSumMetric.__init__r   c                 C   s0   |   |¡\}}| ¡ r|  j| ¡ 7  _dS dS r`   )rB   ra   ru   rv   rb   r&   r&   r0   rC   ~  s   ÿzSumMetric.updatere   rf   c                 C   rg   )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)

        rh   rj   r&   r&   r0   rk   Š  s   'r   rm   rn   )rJ   rK   rL   rM   r   rP   r   r   r*   r   r(   rC   r   r   r   r   rk   rT   r&   r&   r.   r0   rt   J  s(   
 $þþýüÿÿÿþrt   c                       sp   e Zd ZU dZeed< 	ddeed ef de	ddf‡ fd	d
„Z
deeef ddfdd„Zdefdd„Z‡  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    r!   Nc                    s   t ƒ jdg |fi |¤Ž d S )NÚcat)r'   r(   r^   r.   r&   r0   r(   Û  s   zCatMetric.__init__c                 C   s*   |   |¡\}}| ¡ r| j |¡ dS dS r`   )rB   ra   r   Úappendrb   r&   r&   r0   rC   â  s   ÿzCatMetric.updatec                 C   s"   t | jtƒr| jrt| jƒS | jS rD   )r)   r   rR   r   rF   r&   r&   r0   rG   î  s   
zCatMetric.computerm   )rJ   rK   rL   rM   r   rP   r   r   r*   r   r(   rC   rG   rT   r&   r&   r.   r0   rx   ´  s   
 $þþýürx   c                       s¶   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
d„Z
ddeeef deeed	f dd	fdd„Zdefdd„Z		ddeeeee f  dee defdd„Z‡  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    r!   Nc                    sL   t ƒ jdtjdt ¡ d�|fddi|¤Ž | jdtjdt ¡ d�dd� d S )Nrv   rw   rZ   r   r|   r2   r#   )r'   r(   r7   r\   r]   r,   r^   r.   r&   r0   r(     s   ýüû"zMeanMetric.__init__r   c                 C   sª   t |tƒstj|| j| jd�}|du rt |¡}nt |tƒs(tj|| j| jd�}t ||j¡}|  	||¡\}}| 
¡ dkr?dS |  j||  ¡ 7  _|  j| ¡ 7  _dS )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.

        r3   Nr   )r)   r   r7   r8   r4   r5   r<   Úbroadcast_toÚshaperB   ra   r|   rv   r2   )r-   r   r2   r&   r&   r0   rC   ,  s   

zMeanMetric.updatec                 C   s   | j | j S rD   )r|   r2   rF   r&   r&   r0   rG   G  rH   zMeanMetric.computere   rf   c                 C   rg   )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)

        rh   rj   r&   r&   r0   rk   K  rl   r   rm   rI   rn   )rJ   rK   rL   rM   r   rP   r   r   r*   r   r(   rC   rG   r   r   r   r   rk   rT   r&   r&   r.   r0   r{   õ  s,   
 %þþýü*ÿÿÿþr{   c                	       óD   e Zd ZdZ		ddedeed ef dedd	f‡ fd
d„Z	‡  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)

    é   r   Úwindowr   r   r    r!   Nc                    ó"   t ƒ jtdd|i|¤Ž|d� d S ©Nr   )Zbase_metricr‚   r&   )r'   r(   r{   ©r-   r‚   r   r    r.   r&   r0   r(   ¤  ó   "zRunningMean.__init__©r�   r   ©rJ   rK   rL   rM   Úintr   r   r*   r   r(   rT   r&   r&   r.   r0   r€   t  s    1ýþýüûr€   c                	       r   )Ú
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   r    r!   Nc                    rƒ   r„   )r'   r(   rt   r…   r.   r&   r0   r(   Þ  r†   zRunningSum.__init__r‡   rˆ   r&   r&   r.   r0   rŠ   ­  s    2ýþýüûrŠ   )!Úcollections.abcr   Útypingr   r   r   r   r7   r   Útyping_extensionsr   Útorchmetrics.metricr	   Útorchmetrics.utilitiesr
   Útorchmetrics.utilities.datar   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ztorchmetrics.wrappers.runningr   Ú__doctest_skip__r   rV   rq   rt   rx   r{   r€   rŠ   r&   r&   r&   r0   Ú<module>   s*   VjjjA9