§
    åóÉjàn  ã                   ó‚  — 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 dS )é    )Ú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ÚerrorÚvalueÚfnÚdefault_valueÚnan_strategy©r   ÚwarnÚignoreÚdisableÚ
state_nameÚkwargsÚreturnc                 óè   •—  t          ¦   «         j        di |¤Ž d}||vr+t          |t          ¦  «        st	          d|› d|› 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   Úallowed_nan_strategyÚ	__class__s          €ú{/home/lighthouse/badge-speaker-benchmark/.benchmark-venv-community/lib/python3.11/site-packages/torchmetrics/aggregation.pyr'   zBaseAggregator.__init__:   s›   ø€ ð 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"ØEÐØÐ3Ð3Ð3½JÀ|ÕUZÑ<[Ô<[Ð3ÝØwÐI]ÐwÐwÐhtÐwÐwÐwñô ð ð )ˆÔØ�Š�z¨=ÈˆÑLÔLÐLØ$ˆŒˆˆó    ÚxÚweightc                 óæ  — t          |t          ¦  «        s!t          j        || j        | j        ¬¦  «        }|�6t          |t          ¦  «        s!t          j        || j        | j        ¬¦  «        }| j        dk    �r0t          j        |¦  «        }|�t          j        |¦  «        }n:t          j        |¦  «         	                    ¦   «         }t          j
        |¦  «        }|                     ¦   «         s|                     ¦   «         r¢| j        dk    rt          d¦  «        ‚| j        dv r9| j        dk    rt          dt          ¦  «         |||z            }|||z            }n[t          | j        t          ¦  «        st!          d	| j        › �¦  «        ‚| j        |||z  <   d
|||z  <   nt          j
        |¦  «        }|                     | 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_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Ñ$Ô$ð 	IÝ” ¨¬¸D¼KÐHÑHÔHˆAØÐ¥j°½Ñ&@Ô&@ÐÝ”_ V°4´:ÀdÄkÐRÑRÔRˆFàÔ 	Ò)Ñ)Ý”;˜q‘>”>ˆDØÐ!Ý#œk¨&Ñ1Ô1��å#Ô.¨tÑ4Ô4×9Ò9Ñ;Ô;�Ýœ¨Ñ+Ô+�Ø�xŠx‰zŒzð 3˜[Ÿ_š_Ñ.Ô.ð 3ØÔ$¨Ò/Ð/Ý&Ð'KÑLÔLÐLØÔ$Ð(:Ð:Ð:ØÔ(¨FÒ2Ð2Ý&Ð']Õ_jÑkÔkÐkØ˜D ;Ñ.Ð/Ô0�AØ# d¨[Ñ&8Ð$9Ô:�F�Få% dÔ&7½Ñ?Ô?ð lÝ(Ð)jÐW[ÔWhÐ)jÐ)jÑkÔkÐkØ,0Ô,=�A�d˜[Ñ(Ñ)Ø12�F˜4 +Ñ-Ñ.øå”_ QÑ'Ô'ˆFØ�tŠt�D”JÑÔ §¢¨4¬:Ñ!6Ô!6Ð6Ð6r0   c                 ó   — dS )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   € å�t˜Tœ_Ñ-Ô-Ð-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       sr  ø€ € € € € € ðð ð* ÐØÐØ#Ð�tÐ#Ð#Ñ#ð U\Ø!ð%ð %à�(˜C�-Ô ð%ð ˜V T˜\Ô*ð%ð ˜GÐ$HÔIÈ5ÐPÔQð	%ð
 ð%ð ð%ð 
ð%ð %ð %ð %ð %ð %ð( QUð7ð 7Ø�u˜f�}Ô%ð7Ø/7¸¸eÀV¸mÔ8LÔ/Mð7à	ˆv�vˆ~Ô	ð7ð 7ð 7ð 7ðB(˜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   r   Nc                 óª   •—  t          ¦   «         j        dt          j        t	          d¦  «        t          j        ¦   «         ¬¦  «         |fddi|¤Ž d S )NÚmaxÚinf©r5   r   r[   ©r&   r'   r8   Útensorr)   Úget_default_dtype©r,   r   r   r.   s      €r/   r'   zMaxMetric.__init__ž   sm   ø€ ð
 	�‰ŒÔØÝŒ\�% ™,œ,­eÔ.EÑ.GÔ.GÐHÑHÔHÐHØð	
ð 	
ð #ð		
ð
 ð	
ð 	
ð 	
ð 	
ð 	
r0   r   c                 óÄ   — |                       |¦  «        \  }}|                     ¦   «         r3t          j        | j        t          j        |¦  «        ¦  «        | _        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)rD   Únumelr8   r]   r[   ©r,   r   Ú_s      r/   rF   zMaxMetric.update«   ó[   € ð ×1Ò1°%Ñ8Ô8‰ˆˆqØ�;Š;‰=Œ=ð 	IÝ"œY t¤~µu´yÀÑ7GÔ7GÑHÔHˆDŒNˆNˆNð	Ið 	Ir0   ÚvalÚaxc                 ó.   — |                       ||¦  «        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 �zŠz˜#˜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ÔIÈ5ÐPÔQð
ð ð
ð 
ð	
ð 
ð 
ð 
ð 
ð 
ð
I˜E %¨ -Ô0ð 
I°Tð 
Ið 
Ið 
Ið 
Ið _cð&#ð &#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð&#ØIQÐRZÔI[ð&#à	ð&#ð &#ð &#ð &#ð &#ð &#ð &#ð &#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   r   Nc                 ó¨   •—  t          ¦   «         j        dt          j        t	          d¦  «        t          j        ¦   «         ¬¦  «        |fddi|¤Ž d S )NÚminr^   r_   r   rx   r`   rc   s      €r/   r'   zMinMetric.__init__  sj   ø€ ð
 	�‰ŒÔØÝŒL�˜u™œ­UÔ-DÑ-FÔ-FÐGÑGÔGØð	
ð 	
ð #ð		
ð
 ð	
ð 	
ð 	
ð 	
ð 	
r0   r   c                 óÄ   — |                       |¦  «        \  }}|                     ¦   «         r3t          j        | j        t          j        |¦  «        ¦  «        | _        dS dS re   )rD   rf   r8   rz   rx   rg   s      r/   rF   zMinMetric.update  ri   r0   rj   rk   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 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   r   Nc                 óŽ   •—  t          ¦   «         j        dt          j        dt          j        ¦   «         ¬¦  «        |fddi|¤Ž d S )NÚsumç        r_   r   r   )r&   r'   r8   ra   rb   rc   s      €r/   r'   zSumMetric.__init__q  sd   ø€ ð
 	�‰ŒÔØÝŒL˜¥EÔ$;Ñ$=Ô$=Ð>Ñ>Ô>Øð	
ð 	
ð #ð		
ð
 ð	
ð 	
ð 	
ð 	
ð 	
r0   r   c                 ó¦   — |                       |¦  «        \  }}|                     ¦   «         r$| xj        |                     ¦   «         z  c_        dS dS re   )rD   rf   r   r�   rg   s      r/   rF   zSumMetric.update~  sQ   € ð ×1Ò1°%Ñ8Ô8‰ˆˆqØ�;Š;‰=Œ=ð 	*ØˆNŒN˜eŸiši™kœkÑ)ˆNŒNˆNˆNð	*ð 	*r0   rj   rk   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 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 �zŠz˜#˜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ÔIÈ5ÐPÔQð
ð ð
ð 
ð	
ð 
ð 
ð 
ð 
ð 
ð
*˜E %¨ -Ô0ð 
*°Tð 
*ð 
*ð 
*ð 
*ð _cð'#ð '#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð'#ØIQÐRZÔI[ð'#à	ð'#ð '#ð '#ð '#ð '#ð '#ð '#ð '#r0   r~   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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   r   Nc                 ó@   •—  t          ¦   «         j        dg |fi |¤Ž d S )NÚcat)r&   r'   rc   s      €r/   r'   zCatMetric.__init__Û  s.   ø€ ð
 	�‰ŒÔ˜  LÐ;Ð;°FÐ;Ð;Ð;Ð;Ð;r0   c                 ó–   — |                       |¦  «        \  }}|                     ¦   «         r| j                             |¦  «         dS dS re   )rD   rf   r   Úappendrg   s      r/   rF   zCatMetric.updateâ  sQ   € ð ×1Ò1°%Ñ8Ô8‰ˆˆqØ�;Š;‰=Œ=ð 	%ØŒJ×Ò˜eÑ$Ô$Ð$Ð$Ð$ð	%ð 	%r0   c                 óz   — t          | j        t          ¦  «        r| j        rt          | j        ¦  «        S | j        S rH   )r(   r   rU   r   rJ   s    r/   rK   zCatMetric.computeî  s7   € å�d”j¥$Ñ'Ô'ð 	,¨D¬Jð 	,Ý ¤
Ñ+Ô+Ð+ØŒzÐr0   rr   )rM   rN   rO   rP   r   rS   r   r	   r)   r   r'   rF   rK   rW   rX   s   @r/   r†   r†   ´  sÓ   ø€ € € € € € ð"ð "ðH €M€M�Mð U[ð<ð <à˜GÐ$HÔIÈ5Ð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   r   Nc                 ó  •—  t          ¦   «         j        dt          j        dt          j        ¦   «         ¬¦  «        |fddi|¤Ž |                      dt          j        dt          j        ¦   «         ¬¦  «        d¬¦  «         d S )Nr�   r‚   r_   r   rŽ   r2   r"   )r&   r'   r8   ra   rb   r+   rc   s      €r/   r'   zMeanMetric.__init__  s“   ø€ ð
 	�‰ŒÔØÝŒL˜¥EÔ$;Ñ$=Ô$=Ð>Ñ>Ô>Øð	
ð 	
ð $ð		
ð
 ð	
ð 	
ð 	
ð 	�Š�x­¬°cÅÔAXÑAZÔAZÐ)[Ñ)[Ô)[ÐlqˆÑrÔrÐrÐrÐrr0   r   c                 ó4  — t          |t          ¦  «        s!t          j        || j        | j        ¬¦  «        }|€t          j        |¦  «        }n6t          |t          ¦  «        s!t          j        || j        | j        ¬¦  «        }t          j        ||j        ¦  «        }|  	                    ||¦  «        \  }}| 
                    ¦   «         dk    rdS | xj        ||z                       ¦   «         z  c_        | xj        |                     ¦   «         z  c_        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.

        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õ   € õ ˜%¥Ñ(Ô(ð 	QÝ”O E°´ÀDÄKÐPÑPÔPˆEØˆ>Ý”_ UÑ+Ô+ˆFˆFÝ˜F¥FÑ+Ô+ð 	SÝ”_ V°4´:ÀdÄkÐRÑRÔRˆFÝÔ# F¨E¬KÑ8Ô8ˆØ×6Ò6°u¸fÑEÔE‰ˆˆvà�;Š;‰=Œ=˜AÒÐØˆFØˆŒ˜E F™N×/Ò/Ñ1Ô1Ñ1ˆŒØˆŒ�v—z’z‘|”|Ñ#ˆŒˆˆr0   c                 ó    — | j         | j        z  S rH   )rŽ   r2   rJ   s    r/   rK   zMeanMetric.computeG  s   € àŒ ¤Ñ,Ð,r0   rj   rk   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 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�   õ  sT  ø€ € € € € € ð#ð #ðJ ÐÐÑØ€N€N�Nð U[ðsð sà˜GÐ$HÔIÈ5ÐPÔQðsð ðsð 
ð	sð sð sð sð sð sð$ð $˜E %¨ -Ô0ð $¸%ÀÀvÈtÐ@SÔ:Tð $Ð`dð $ð $ð $ð $ð6-˜ð -ð -ð -ð -ð
 _cð&#ð &#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð&#ØIQÐRZÔI[ð&#à	ð&#ð &#ð &#ð &#ð &#ð &#ð &#ð &#r0   r�   c            	       óV   ‡ — 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)

    é   r   Úwindowr   r   r   r   Nc                 óf   •— t          ¦   «                              t          dd|i|¤Ž|¬¦  «         d S ©Nr   )Úbase_metricr˜   r%   )r&   r'   r�   ©r,   r˜   r   r   r.   s       €r/   r'   zRunningMean.__init__¤  s<   ø€ õ 	‰Œ×Ò¥ZÐ%TÐ%T¸\Ð%TÈVÐ%TÐ%TÐ]cÐÑdÔdÐdÐdÐdr0   ©r—   r   ©rM   rN   rO   rP   Úintr   r	   r)   r   r'   rW   rX   s   @r/   r–   r–   t  sš   ø€ € € € € ð-ð -ðb ØTZðeð eàðeð ˜GÐ$HÔIÈ5ÐPÔQðeð ð	eð
 
ðeð eð eð eð eð eð eð eð eð er0   r–   c            	       óV   ‡ — 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   r   r   Nc                 óf   •— t          ¦   «                              t          dd|i|¤Ž|¬¦  «         d S rš   )r&   r'   r~   rœ   s       €r/   r'   zRunningSum.__init__Þ  s<   ø€ õ 	‰Œ×Ò¥YÐ%SÐ%S¸LÐ%SÈFÐ%SÐ%SÐ\bÐÑcÔcÐcÐcÐcr0   r�   rž   rX   s   @r/   r¡   r¡   ­  sš   ø€ € € € € ð.ð .ðd ØTZðdð dàðdð ˜GÐ$HÔIÈ5ÐPÔQðdð ð	dð
 
ðdð dð dð dð dð dð 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Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1à €€€Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à &Ð &Ð &Ð &Ð &Ð &Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1àð aØ`Ð`Ð`ÐðS.ð S.ð S.ð S.ð S.�Vñ S.ô S.ð S.ðlg#ð g#ð g#ð g#ð g#�ñ g#ô g#ð g#ðTg#ð g#ð g#ð g#ð g#�ñ g#ô g#ð g#ðTg#ð g#ð g#ð g#ð g#�ñ g#ô g#ð g#ðT>ð >ð >ð >ð >�ñ >ô >ð >ðB|#ð |#ð |#ð |#ð |#�ñ |#ô |#ð |#ð~6eð 6eð 6eð 6eð 6e�'ñ 6eô 6eð 6eðr7dð 7dð 7dð 7dð 7d�ñ 7dô 7dð 7dð 7dð 7dr0   