code: def _ssim_loss_fn(
      source: Tensor,
      reference: Tensor,
      kernel: Tensor,
      eps: float = 1e-8,
      c1: float = 0.01**2,
      c2: float = 0.03**2,
      use_padding: bool = False,
  ) -> Tensor:
      # ref: Algorithm section: https://en.wikipedia.org/wiki/Structural_similarity
      # ref: Alternative implementation: https://kornia.readthedocs.io/en/latest/_modules/kornia/metrics/ssim.html#ssim
  
      torch._assert(
          source.ndim == reference.ndim == 4,
          "SSIM: `source` and `reference` must be 4-dimensional tensors",
      )
  
      torch._assert(
          source.shape == reference.shape,
          "SSIM: `source` and `reference` must have the same shape, but got {} and {}".format(
              source.shape, reference.shape
          ),
      )
  
      B, C, H, W = source.shape
      kernel = kernel.unsqueeze(0).unsqueeze(0).repeat(C, 1, 1, 1)
      if use_padding:
          pad_size = kernel.shape[2] // 2
          source = F.pad(
              source,
              (pad_size, pad_size, pad_size, pad_size),
              "reflect",
          )
          reference = F.pad(
              reference,
              (pad_size, pad_size, pad_size, pad_size),
              "reflect",
          )
  
      mu1 = F.conv2d(source, kernel, groups=C)
      mu2 = F.conv2d(reference, kernel, groups=C)
  
      mu1_sq = mu1.pow(2)
      mu2_sq = mu2.pow(2)
  
      mu1_mu2 = mu1 * mu2
      mu_img1_sq = F.conv2d(source.pow(2), kernel, groups=C)
      mu_img2_sq = F.conv2d(reference.pow(2), kernel, groups=C)
      mu_img1_mu2 = F.conv2d(source * reference, kernel, groups=C)
  
      sigma1_sq = mu_img1_sq - mu1_sq
      sigma2_sq = mu_img2_sq - mu2_sq
      sigma12 = mu_img1_mu2 - mu1_mu2
  
      numerator = (2 * mu1_mu2 + c1) * (2 * sigma12 + c2)
      denominator = (mu1_sq + mu2_sq + c1) * (
          sigma1_sq + sigma2_sq + c2
      )
      ssim = numerator / (denominator + eps)
  
      # doing 1 - ssim because we want to maximize the ssim
      return 1 - ssim.mean(dim=(1, 2, 3))
  
imports: from typing import List, Optional
  import torch
  from torch import nn, Tensor
  from torch.nn import functional
  from torchvision.prototype.models.depth.stereo.raft_stereo import grid_sample, make_coords_grid
label_desc: Use image node_id 3 for calling a global function with example usage: _ssim_loss_fn(source, reference, kernel, eps, c1, c2, use_padding) and returns: unknown