import torch


def psnr_calc(noisy, real):
    """Calculates PSNR between noisy and real data
    Inputs
    - noisy; batch of noisy data
    - real; batch of clean data, in correspondence with noisy
    Outputs
    - psnrs; full list of psnrs
    - mean and std of list of psnrs
    """
    numpix = noisy.size(1)*noisy.size(2)*noisy.size(3)
    bs = noisy.size(0)
    avg_sq_norm = (1/numpix)*torch.norm(0.5*(noisy.view(bs, -1)- real.view(bs,-1)), dim = 1)**2#multiplication by 0.5 because vals between [-1,1]
    psnrs = -10*torch.log10(avg_sq_norm)
    return psnrs, torch.tensor([torch.mean(psnrs), torch.std(psnrs)])