
    3j                     n    S SK r S SKJr  S\ R                  S\ R                  S\S\ R                  4S jrg)    N)mse_lossimagetargetmax_valreturnc           
         [        U [        R                  5      (       d  [        S[	        U 5       S35      e[        U[        R                  5      (       d  [        S[	        U5       S35      eU R
                  UR
                  :w  a%  [        SU R
                   SUR
                   35      eS[        R                  " US-  [        XSS9-  5      -  $ )	a  Create a function that calculates the PSNR between 2 images.

PSNR is Peek Signal to Noise Ratio, which is similar to mean squared error.
Given an m x n image, the PSNR is:

.. math::

    \text{PSNR} = 10 \log_{10} \bigg(\frac{\text{MAX}_I^2}{MSE(I,T)}\bigg)

where

.. math::

    \text{MSE}(I,T) = \frac{1}{mn}\sum_{i=0}^{m-1}\sum_{j=0}^{n-1} [I(i,j) - T(i,j)]^2

and :math:`\text{MAX}_I` is the maximum possible input value
(e.g for floating point images :math:`\text{MAX}_I=1`).

Args:
    image: the input image with arbitrary shape :math:`(*)`.
    target: the labels image with arbitrary shape :math:`(*)`.
    max_val: The maximum value in the input tensor.

Return:
    the computed loss as a scalar.

Examples:
    >>> ones = torch.ones(1)
    >>> psnr(ones, 1.2 * ones, 2.) # 10 * log(4/((1.2-1)**2)) / log(10)
    tensor(20.0000)

Reference:
    https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio#Definition

zExpected torch.Tensor but got .z*Expected tensors of equal shapes, but got z and g      $@   mean)	reduction)
isinstancetorchTensor	TypeErrortypeshapelog10mse)r   r   r   s      M/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/metrics/psnr.pypsnrr      s    H eU\\**8eQGHHfell++8faHII{{fll"DU[[MQVW]WcWcVdeff%++gqj3u+OOPPP    )r   torch.nn.functionalr   r   r   floatr    r   r   <module>r      s?   $  /-Q -Qell -QU -Qu|| -Qr   