Ë
    þÍ:jŠ  ã            	       óx   — 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	y)é    N)ÚTensor©Ú'scale_invariant_signal_distortion_ratio)Ú_check_same_shapeÚpredsÚtargetÚ	zero_meanÚreturnc                 óŒ  — t        | |«       t        j                  | j                  «      j                  }|r6|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         úv/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torchmetrics/functional/audio/snr.pyÚsignal_noise_ratior      s¨   € ô: �e˜VÔ$Ü
�+‰+�e—k‘kÓ
"×
&Ñ
&€CáØœ%Ÿ*™* V°¸TÔBÑBˆØœŸ
™
 5¨b¸$Ô?Ñ?ˆà�U‰N€Eä—‘˜6 1™9¨"Ô-°Ñ3¼¿	¹	À%ÈÁ(ÐPRÔ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                 ó  — | j                  «       rt        j                  | «      } |j                  «       rt        j                  |«      }| j                  dk  s3| j                  d   dk7  s!|j                  dk  s|j                  d   dk7  r&t        d| j                  › d|j                  › d�«      ‚ | j                  g | j                  dd ¢d‘­Ž }  |j                  g |j                  dd ¢d‘­Ž }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±KÀ!²OÀvÇ|Á|ÐTVÑGWÐ[\ÒG\ÜðØŸ™�} E¨&¯,©,¨°qð:ó
ð 	
ð
 ˆE�M‰MÐ0˜5Ÿ;™; s¨Ð+Ð0¨RÒ0€EØˆV�^‰^Ð3˜VŸ\™\¨#¨2Ð.Ð3°Ò3€Fä2¸ÀvÐYbÔcÐcr   )F)
r   r   Ú!torchmetrics.functional.audio.sdrr   Útorchmetrics.utilities.checksr   Úboolr   r   r*   © r   r   ú<module>r/      s|   ðó Ý å UÝ ;ñ''˜fð ''¨fð ''Àð ''ÐRXó ''ðT_¨fð _¸fð _Èó _ñ4)d°fð )dÀfð )dÐY]ð )dÐjpô )dr   