§
    ’©ºjŠ  ã            	       óz   — d dl Z d dl mZ d dlmZ d dlmZ ddededed	efd
„Zdeded	efd„Zddededed	efd„Z	dS )é    N)ÚTensor©Ú'scale_invariant_signal_distortion_ratio)Ú_check_same_shapeFÚpredsÚtargetÚ	zero_meanÚreturnc                 ót  — t          | |¦  «         t          j        | j        ¦  «        j        }|r4|t          j        |dd¬¦  «        z
  }| t          j        | dd¬¦  «        z
  } || z
  }t          j        |dz  d¬¦  «        |z   t          j        |dz  d¬¦  «        |z   z  }dt          j        |¦  «        z  S )aå  Calculate `Signal-to-noise ratio`_ (SNR_) meric for evaluating quality of audio.

    .. math::
        \text{SNR} = \frac{P_{signal}}{P_{noise}}

    where  :math:`P` denotes the power of each signal. The SNR metric compares the level of the desired signal to
    the level of background noise. Therefore, a high value of SNR means that the audio is clear.

    Args:
        preds: float tensor with shape ``(...,time)``
        target: float tensor with shape ``(...,time)``
        zero_mean: if to zero mean target and preds or not

    Returns:
        Float tensor with shape ``(...,)`` of SNR values per sample

    Raises:
        RuntimeError:
            If ``preds`` and ``target`` does not have the same shape

    Example:
        >>> from torchmetrics.functional.audio import signal_noise_ratio
        >>> target = torch.tensor([3.0, -0.5, 2.0, 7.0])
        >>> preds = torch.tensor([2.5, 0.0, 2.0, 8.0])
        >>> signal_noise_ratio(preds, target)
        tensor(16.1805)

    éÿÿÿÿT)ÚdimÚkeepdimé   )r   é
   )r   ÚtorchÚfinfoÚdtypeÚepsÚmeanÚsumÚlog10)r   r   r	   r   ÚnoiseÚ	snr_values         úq/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/audio/snr.pyÚsignal_noise_ratior      sÁ   € õ: �e˜VÑ$Ô$Ð$Ý
Œ+�e”kÑ
"Ô
"Ô
&€Càð @Ø�%œ* V°¸TÐBÑBÔBÑBˆØ�œ
 5¨b¸$Ð?Ñ?Ô?Ñ?ˆà�U‰N€Eå”˜6 1™9¨"Ð-Ñ-Ô-°Ñ3½¼	À%ÈÁ(ÐPRÐ8SÑ8SÔ8SÐVYÑ8YÑZ€IØ•”˜IÑ&Ô&Ñ&Ð&ó    c                 ó&   — t          | |d¬¦  «        S )a´  `Scale-invariant signal-to-noise ratio`_ (SI-SNR).

    Args:
        preds: float tensor with shape ``(...,time)``
        target: float tensor with shape ``(...,time)``

    Returns:
         Float tensor with shape ``(...,)`` of SI-SNR values per sample

    Raises:
        RuntimeError:
            If ``preds`` and ``target`` does not have the same shape

    Example:
        >>> import torch
        >>> from torchmetrics.functional.audio import scale_invariant_signal_noise_ratio
        >>> target = torch.tensor([3.0, -0.5, 2.0, 7.0])
        >>> preds = torch.tensor([2.5, 0.0, 2.0, 8.0])
        >>> scale_invariant_signal_noise_ratio(preds, target)
        tensor(15.0918)

    T©r   r   r	   r   )r   r   s     r   Ú"scale_invariant_signal_noise_ratior   @   s   € õ. 3¸ÀvÐY]Ð^Ñ^Ô^Ð^r   c                 óæ  — |                       ¦   «         rt          j        | ¦  «        } |                      ¦   «         rt          j        |¦  «        }| j        dk     s-| j        d         dk    s|j        dk     s|j        d         dk    r t          d| j        › d|j        › d�¦  «        ‚ | j        g | j        dd…         ¢d‘R Ž }  |j        g |j        dd…         ¢d‘R Ž }t          | ||¬	¦  «        S )
aX  `Complex scale-invariant signal-to-noise ratio`_ (C-SI-SNR).

    Args:
        preds: real float tensor with shape ``(...,frequency,time,2)`` or complex float tensor with
            shape ``(..., frequency,time)``
        target: real float tensor with shape ``(...,frequency,time,2)`` or complex float tensor with
            shape ``(..., frequency,time)``
        zero_mean: When set to True, the mean of all signals is subtracted prior to computation of the metrics

    Returns:
         Float tensor with shape ``(...,)`` of C-SI-SNR values per sample

    Raises:
        RuntimeError:
            If ``preds`` is not the shape (...,frequency,time,2) (after being converted to real if it is complex).
            If ``preds`` and ``target`` does not have the same shape.

    Example:
        >>> from torch import randn
        >>> from torchmetrics.functional.audio import complex_scale_invariant_signal_noise_ratio
        >>> preds = randn((1,257,100,2))
        >>> target = randn((1,257,100,2))
        >>> complex_scale_invariant_signal_noise_ratio(preds, target)
        tensor([-38.8832])

    é   r   r   zZPredictions and targets are expected to have the shape (..., frequency, time, 2), but got z and ú.Néýÿÿÿr   )Ú
is_complexr   Úview_as_realÚndimÚshapeÚRuntimeErrorÚreshaper   r   s      r   Ú*complex_scale_invariant_signal_noise_ratior*   Z   s$  € ð6 ×ÒÑÔð *ÝÔ" 5Ñ)Ô)ˆØ×ÒÑÔð ,ÝÔ# FÑ+Ô+ˆàŒ
�QŠˆ˜%œ+ bœ/¨QÒ.Ð.°F´KÀ!²O°OÀvÄ|ÐTVÔGWÐ[\ÒG\ÐG\Ýð:Øœð:ð :Ø*0¬,ð:ð :ð :ñ
ô 
ð 	
ð
 ˆEŒMÐ0˜5œ; s¨ sÔ+Ð0¨RÐ0Ð0Ð0€EØˆVŒ^Ð3˜Vœ\¨#¨2¨#Ô.Ð3°Ð3Ð3Ð3€Få2¸ÀvÐYbÐcÑcÔcÐcr   )F)
r   r   Ú!torchmetrics.functional.audio.sdrr   Útorchmetrics.utilities.checksr   Úboolr   r   r*   © r   r   ú<module>r/      sù   ðð €€€Ø Ð Ð Ð Ð Ð à UÐ UÐ UÐ UÐ UÐ UØ ;Ð ;Ð ;Ð ;Ð ;Ð ;ð''ð ''˜fð ''¨fð ''Àð ''ÐRXð ''ð ''ð ''ð ''ðT_¨fð _¸fð _Èð _ð _ð _ð _ð4)dð )d°fð )dÀfð )dÐY]ð )dÐjpð )dð )dð )dð )dð )dð )dr   