code: def _ssim_single_channel(
      x: Tensor,
      y: Tensor,
      data_range: float,
      window_size: int,
      k1: float,
      k2: float,
      gaussian_std: float,
  ) -> Tensor:
      """
      Computes the SSIM and contrast-structure product on a single channel image.
  
      At the lowest resolution, the entire SSIM score is used in MS-SSIM
      calculations, while at all other resolutions only the constrast-structure
      product is used.
  
      Args:
          x: a batch of single-channel images with shape [batch_size, 1,
              height, width].
          y: a batch of single-channel images with shape [batch_size, 1,
              height, width].
          data_range: dynamic range of the input tensors.
          window_size: window size for SSIM calculation.
          k1: k1 parameter for SSIM calculation.
          k2: k2 parameter for SSIM calculation.
          gaussian_std: standard deviation of Gaussian filter to use in SSIM
              calculations.
  
      Returns:
          Tensor of shape [batch_size, 2], where output[:,0] is SSIM scores
          and output[:,1] is constrast-structure product scores.
      """
  
      window = _gaussian_window(
          window_size, gaussian_std, device=x.device, dtype=x.dtype
      )
  
      c1 = (k1 * data_range) ** 2
      c2 = (k2 * data_range) ** 2
  
      ux = F.conv2d(x, window)
      uy = F.conv2d(y, window)
  
      uxx = F.conv2d(x * x, window)
      uyy = F.conv2d(y * y, window)
      uxy = F.conv2d(x * y, window)
  
      vx = uxx - ux * ux
      vy = uyy - uy * uy
      vxy = uxy - ux * uy
  
      # Equation (6) in MS-SSIM paper.
      a1, a2, b1, b2 = (
          2 * ux * uy + c1,
          2 * vxy + c2,
          ux**2 + uy**2 + c1,
          vx + vy + c2,
      )
  
      luminance = a1 / b1
      contrast_structure = a2 / b2
  
      batch_size = luminance.size(0)
      ssim = (
          (luminance * contrast_structure)
          .view(batch_size, -1)
          .mean(dim=1)
      )
      cs = contrast_structure.view(batch_size, -1).mean(dim=1)
  
      return torch.stack([ssim, cs])
  
file_path: NeuralCompression/neuralcompression/functional/_multiscale_structural_similarity.py
imports: from typing import Callable, Optional, Sequence
  import torch
  from torch import Tensor
  from torch.nn import functional
label_desc: Use image node_id 3 for calling a global function with example usage: _ssim_single_channel(x, y, data_range, window_size, k1, k2, gaussian_std) and returns: torch