ó
    Ü“,jàn  ã                   óZ  • S SK Jr  S SKJrJrJrJr  S SKrS SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJrJr  S SKJr  \(       d  / SQr " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r g)é    )Ú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                   óö   ^ • \ rS rSr% SrSrSrSr\\	S'     SS\
\\4   S\
\\4   S	\
\S
   \4   S\S\SS4U 4S jjjr SS\
\\4   S\\
\\4      S\\\4   4S jjrS\
\\4   SS4S jrS\4S jrSrU =r$ )ÚBaseAggregatoré    a)  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U ]  " S0 UD6  SnX6;  a'  [        U[        5      (       d  [	        SU SU S35      eX0l        U R                  XBUS9  X@l        g )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          €Ú¦C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\torchmetrics/aggregation.pyr(   ÚBaseAggregator.__init__:   sp   ø€ ô 	‰ÒÑ"˜6Ò"ØEÐØÓ3¼JÀ|ÔUZ×<[Ñ<[ÜØHÐI]ÐH^Ð^gÐhtÐguÐuvÐwóð ð )ÔØ�‰�zÈˆÑLØ$�ó    ÚxÚweightc                 ó:  • [        U[        5      (       d)  [        R                  " XR                  U R
                  S9nUb>  [        U[        5      (       d)  [        R                  " X R                  U R
                  S9nU R                  S:w  Ga@  [        R                  " U5      nUb  [        R                  " U5      nO:[        R                  " U5      R                  5       n[        R                  " U5      nUR                  5       (       d  UR                  5       (       a«  U R                  S:X  a  [        S5      eU R                  S;   a1  U R                  S:X  a  [        S[        5        XU-  )    nX#U-  )    nOf[        U R                  [        5      (       d  [!        SU R                   35      eU R                  XU-  '   S	X#U-  '   O[        R                  " U5      nUR#                  U R                  5      UR#                  U R                  5      4$ )
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_tensorr7   r8   r   ÚisnanÚ
zeros_likeÚboolÚ	ones_likeÚanyÚRuntimeErrorr   ÚUserWarningr*   r+   Úto)r-   r3   r4   ÚnansÚnans_weights        r0   Ú_cast_and_nan_check_inputÚ(BaseAggregator._cast_and_nan_check_inputM   s¥  € ô ˜!œV×$Ñ$Ü—’ ¯©¸D¿K¹KÑHˆAØÑ¤j°¼×&@Ñ&@Ü—_’_ V·:±:ÀdÇkÁkÑRˆFà×Ñ 	Ô)Ü—;’;˜q“>ˆDØÑ!Ü#Ÿkšk¨&Ó1‘ä#×.Ò.¨tÓ4×9Ñ9Ó;�ÜŸš¨Ó+�Ø�x‰x�z‰z˜[Ÿ_™_×.Ñ.Ø×$Ñ$¨Ó/Ü&Ð'KÓLÐLØ×$Ñ$Ð(:Ó:Ø×(Ñ(¨FÓ2Ü&Ð']Ô_jÔkØ ;Ñ.Ð/Ñ0�AØ#¨[Ñ&8Ð$9Ñ:‘Fä% d×&7Ñ&7¼×?Ñ?Ü(Ð+VÐW[×WhÑWhÐViÐ)jÓkÐkØ,0×,=Ñ,=�A˜[Ñ(Ñ)Ø12�F +Ñ-Ñ.øä—_’_ QÓ'ˆFØ�t‰t�D—J‘JÓ §¡¨4¯:©:Ó!6Ð6Ð6r2   c                 ó   • g)zOverwrite in child class.Nr&   )r-   r   s     r0   ÚupdateÚBaseAggregator.updaten   s   � r2   c                 ó,   • [        X R                  5      $ ©zCompute the aggregated value.)Úgetattrr   ©r-   s    r0   ÚcomputeÚBaseAggregator.computeq   s   € ä�tŸ_™_Ó-Ð-r2   )r   r   )r   r   ©N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úis_differentiableÚhigher_is_betterr   r>   Ú__annotations__r   r   Ústrr   Úlistr	   r*   r   r(   r   ÚtuplerF   rI   rO   Ú__static_attributes__Ú__classcell__©r/   s   @r0   r   r       s  ø‡ ñð* ÐØÐØ#Ð�tÓ#ð U\Ø!ñ%à�(˜C�-Ñ ð%ð ˜V T˜\Ñ*ð%ð ˜GÐ$HÑIÈ5ÐPÑQð	%ð
 ð%ð ð%ð 
÷%ð %ð( QUñ7Ø�u˜f�}Ñ%ð7Ø/7¸¸eÀV¸mÑ8LÑ/Mð7à	ˆv�vˆ~Ñ	õ7ðB(˜E %¨ -Ñ0ð (°Tô (ð.˜÷ .ò .r2   r   c                   óÀ   ^ • \ rS rSr% SrSr\\S'   \\S'    SS\	\
S   \4   S\S	S
4U 4S jjjrS\	\\4   S	S
4S jr SS\\	\\\   4      S\\   S	\4S jjrSrU =r$ )Ú	MaxMetricév   a  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U ]  " S[        R                  " [	        S5      [        R
                  " 5       S9* U4SS0UD6  g )NÚmaxÚinf©r7   r   rc   ©r'   r(   r:   Útensorr*   Úget_default_dtype©r-   r   r   r/   s      €r0   r(   ÚMaxMetric.__init__ž   sJ   ø€ ô
 	‰ÒØÜ�\Š\œ% ›,¬e×.EÒ.EÓ.GÑHÐHØñ	
ð #ð		
ð
 ó	
r2   r   c                 óÊ   • U R                  U5      u  pUR                  5       (       a;  [        R                  " U R                  [        R                  " U5      5      U l        gg©zŒUpdate state with data.

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

N)rF   Únumelr:   re   rc   ©r-   r   Ú_s      r0   rI   ÚMaxMetric.update«   óE   € ð ×1Ñ1°%Ó8‰ˆØ�;‰;�=‰=Ü"ŸYšY t§~¡~´u·y²yÀÓ7GÓHˆD�Nð r2   ÚvalÚaxc                 ó$   • U R                  X5      $ )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-   rt   ru   s      r0   ÚplotÚMaxMetric.plot·   ó   € ðL �z‰z˜#Ó"Ð"r2   )rc   ©r   ©NN©rR   rS   rT   rU   rV   r   r>   rY   r   r   r	   r*   r   r(   rI   r   r   r   r   rz   r]   r^   r_   s   @r0   ra   ra   v   ó»   ø‡ ñ"ðH #Ð�tÓ"ØÓð U[ñ
à˜GÐ$HÑIÈ5ÐPÑQð
ð ð
ð 
÷	
ð 
ð
I˜E %¨ -Ñ0ð 
I°Tô 
Ið _cñ&#Ø˜E &¨(°6Ñ*:Ð":Ñ;Ñ<ð&#ØIQÐRZÑI[ð&#à	÷&#ó &#r2   ra   c                   óÀ   ^ • \ rS rSr% SrSr\\S'   \\S'    SS\	\
S   \4   S\S	S
4U 4S jjjrS\	\\4   S	S
4S jr SS\\	\\\   4      S\\   S	\4S jjrSrU =r$ )Ú	MinMetricéà   a  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U ]  " S[        R                  " [	        S5      [        R
                  " 5       S9U4SS0UD6  g )NÚminrf   rg   r   r„   rh   rk   s      €r0   r(   ÚMinMetric.__init__  sG   ø€ ô
 	‰ÒØÜ�LŠLœ˜u›¬U×-DÒ-DÓ-FÑGØñ	
ð #ð		
ð
 ó	
r2   r   c                 óÊ   • U R                  U5      u  pUR                  5       (       a;  [        R                  " U R                  [        R                  " U5      5      U l        ggrn   )rF   ro   r:   r†   r„   rp   s      r0   rI   ÚMinMetric.update  rs   r2   rt   ru   c                 ó$   • U R                  X5      $ )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)

rw   ry   s      r0   rz   ÚMinMetric.plot!  r|   r2   )r„   r}   r~   r   r_   s   @r0   r‚   r‚   à   r€   r2   r‚   c                   ó²   ^ • \ rS rSr% Sr\\S'    SS\\S   \	4   S\
SS4U 4S	 jjjrS
\\	\4   SS4S jr SS\\\\\   4      S\\   S\4S jjrSrU =r$ )Ú	SumMetriciJ  a  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U ]  " S[        R                  " S[        R                  " 5       S9U4SS0UD6  g )NÚsumç        rg   r   rŽ   )r'   r(   r:   ri   rj   rk   s      €r0   r(   ÚSumMetric.__init__q  sC   ø€ ô
 	‰ÒØÜ�LŠL˜¤E×$;Ò$;Ó$=Ñ>Øñ	
ð #ð		
ð
 ó	
r2   r   c                 óœ   • U R                  U5      u  pUR                  5       (       a$  U =R                  UR                  5       -  sl        ggrn   )rF   ro   rŽ   r�   rp   s      r0   rI   ÚSumMetric.update~  s:   € ð ×1Ñ1°%Ó8‰ˆØ�;‰;�=‰=Ø�NŠN˜eŸi™i›kÑ)ŽNð r2   rt   ru   c                 ó$   • U R                  X5      $ )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)

rw   ry   s      r0   rz   ÚSumMetric.plotŠ  s   € ðN �z‰z˜#Ó"Ð"r2   r&   r}   r~   )rR   rS   rT   rU   rV   r   rY   r   r	   r*   r   r(   rI   r   r   r   r   rz   r]   r^   r_   s   @r0   r�   r�   J  s­   ø‡ ñ"ðH Óð U[ñ
à˜GÐ$HÑIÈ5ÐPÑQð
ð ð
ð 
÷	
ð 
ð
*˜E %¨ -Ñ0ð 
*°Tô 
*ð _cñ'#Ø˜E &¨(°6Ñ*:Ð":Ñ;Ñ<ð'#ØIQÐRZÑI[ð'#à	÷'#ó '#r2   r�   c                   óˆ   ^ • \ rS rSr% Sr\\S'    SS\\S   \	4   S\
SS4U 4S	 jjjrS\\	\4   SS4S
 jrS\4S jrSrU =r$ )Ú	CatMetrici´  a  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U ]  " S/ U40 UD6  g )NÚcat)r'   r(   rk   s      €r0   r(   ÚCatMetric.__init__Û  s   ø€ ô
 	‰Ò˜  LÑ;°FÓ;r2   c                 óŒ   • U R                  U5      u  pUR                  5       (       a  U R                  R                  U5        ggrn   )rF   ro   r   Úappendrp   s      r0   rI   ÚCatMetric.updateâ  s8   € ð ×1Ñ1°%Ó8‰ˆØ�;‰;�=‰=Ø�J‰J×Ñ˜eÕ$ð r2   c                 ó¤   • [        U R                  [        5      (       a&  U R                  (       a  [        U R                  5      $ U R                  $ rL   )r)   r   r[   r   rN   s    r0   rO   ÚCatMetric.computeî  s2   € ä�d—j‘j¤$×'Ñ'¨D¯J¯JÜ §
¡
Ó+Ð+Ø�z‰zÐr2   r&   r}   )rR   rS   rT   rU   rV   r   rY   r   r	   r*   r   r(   rI   rO   r]   r^   r_   s   @r0   r˜   r˜   ´  sz   ø‡ ñ"ðH ƒMð U[ñ<à˜GÐ$HÑIÈ5ÐPÑQð<ð ð<ð 
÷	<ð <ð
%˜E %¨ -Ñ0ð 
%°Tô 
%ð˜÷ ò r2   r˜   c                   óÞ   ^ • \ rS rSr% Sr\\S'   \\S'    SS\\S   \	4   S\
SS	4U 4S
 jjjrSS\\	\4   S\\	\S	4   SS	4S jjrS\4S jr SS\\\\\   4      S\\   S\4S jjrSrU =r$ )Ú
MeanMetriciõ  aÅ  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_valuer4   r   r   r   r    Nc                 óê   >• [         TU ]  " S[        R                  " S[        R                  " 5       S9U4SS0UD6  U R                  S[        R                  " S[        R                  " 5       S9SS9  g )Nr�   r‘   rg   r   r£   r4   r#   )r'   r(   r:   ri   rj   r,   rk   s      €r0   r(   ÚMeanMetric.__init__  sl   ø€ ô
 	‰ÒØÜ�LŠL˜¤E×$;Ò$;Ó$=Ñ>Øñ	
ð $ð		
ð
 ò	
ð 	�‰�x¬¯ª°cÄ×AXÒAXÓAZÑ)[ÐlqˆÒrr2   r   c                 óP  • [        U[        5      (       d)  [        R                  " XR                  U R
                  S9nUc  [        R                  " U5      nO>[        U[        5      (       d)  [        R                  " X R                  U R
                  S9n[        R                  " X!R                  5      nU R                  X5      u  pUR                  5       S:X  a  gU =R                  X-  R                  5       -  sl        U =R                  UR                  5       -  sl        g)az  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.

r6   Nr   )r)   r   r:   r;   r7   r8   r?   Úbroadcast_toÚshaperF   ro   r£   r�   r4   )r-   r   r4   s      r0   rI   ÚMeanMetric.update,  sÅ   € ô ˜%¤×(Ñ(Ü—O’O E·±ÀDÇKÁKÑPˆEØ‰>Ü—_’_ UÓ+‰FÜ˜F¤F×+Ñ+Ü—_’_ V·:±:ÀdÇkÁkÑRˆFÜ×#Ò# F¯K©KÓ8ˆØ×6Ñ6°uÓE‰ˆà�;‰;‹=˜AÓØØ�Š˜E™N×/Ñ/Ó1Ñ1�Ø�Š�v—z‘z“|Ñ#Žr2   c                 ó4   • U R                   U R                  -  $ rL   )r£   r4   rN   s    r0   rO   ÚMeanMetric.computeG  s   € à�‰ §¡Ñ,Ð,r2   rt   ru   c                 ó$   • U R                  X5      $ )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)

rw   ry   s      r0   rz   ÚMeanMetric.plotK  r|   r2   r&   r}   rQ   r~   )rR   rS   rT   rU   rV   r   rY   r   r	   r*   r   r(   rI   rO   r   r   r   r   rz   r]   r^   r_   s   @r0   r¢   r¢   õ  s×   ø‡ ñ#ðJ ÓØƒNð U[ñsà˜GÐ$HÑIÈ5ÐPÑQðsð ðsð 
÷	sð sñ$˜E %¨ -Ñ0ð $¸%ÀÀvÈtÐ@SÑ:Tð $Ð`dõ $ð6-˜ô -ð
 _cñ&#Ø˜E &¨(°6Ñ*:Ð":Ñ;Ñ<ð&#ØIQÐRZÑI[ð&#à	÷&#ó &#r2   r¢   c            	       óX   ^ • \ rS rSrSr  SS\S\\S   \4   S\	SS4U 4S	 jjjr
S
rU =r$ )ÚRunningMeanit  aÝ  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                 ó8   >• [         TU ]  [        SSU0UD6US9  g ©Nr   )Úbase_metricr°   r&   )r'   r(   r¢   ©r-   r°   r   r   r/   s       €r0   r(   ÚRunningMean.__init__¤  s%   ø€ ô 	‰Ñ¤ZÑ%T¸\Ð%TÈVÑ%TÐ]cÐÒdr2   r&   ©é   r   ©rR   rS   rT   rU   rV   Úintr   r	   r*   r   r(   r]   r^   r_   s   @r0   r¯   r¯   t  sW   ø† ñ-ðb ØTZñeàðeð ˜GÐ$HÑIÈ5ÐPÑQðeð ð	eð
 
÷eö er2   r¯   c            	       óX   ^ • \ rS rSrSr  SS\S\\S   \4   S\	SS4U 4S	 jjjr
S
rU =r$ )Ú
RunningSumi­  aé  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                 ó8   >• [         TU ]  [        SSU0UD6US9  g r²   )r'   r(   r�   r´   s       €r0   r(   ÚRunningSum.__init__Þ  s%   ø€ ô 	‰Ñ¤YÑ%S¸LÐ%SÈFÑ%SÐ\bÐÒcr2   r&   r¶   r¸   r_   s   @r0   r»   r»   ­  sW   ø† ñ.ðd ØTZñdàðdð ˜GÐ$HÑIÈ5ÐPÑQðdð ð	dð
 
÷dö dr2   r»   )!Úcollections.abcr   Útypingr   r   r   r   r:   r   Útyping_extensionsr	   Útorchmetrics.metricr
   Útorchmetrics.utilitiesr   Útorchmetrics.utilities.datar   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Útorchmetrics.wrappers.runningr   Ú__doctest_skip__r   ra   r‚   r�   r˜   r¢   r¯   r»   r&   r2   r0   Ú<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r2   