code: def _baseline_d_lambda(
      preds: np.ndarray, target: np.ndarray, p: int = 1
  ) -> float:
      """NumPy based implementation of Spectral Distortion Index, which uses UQI of TorchMetrics."""
      target, preds = torch.from_numpy(target), torch.from_numpy(preds)
      # Permute to ensure B x C x H x W (Pillow/NumPy stores in B x H x W x C)
      target = target.permute(0, 3, 1, 2)
      preds = preds.permute(0, 3, 1, 2)
  
      length = preds.shape[1]
      m1 = np.zeros((length, length), dtype=np.float32)
      m2 = np.zeros((length, length), dtype=np.float32)
  
      # Convert target and preds to Torch Tensors, pass them to metrics UQI
      # this is mainly because reference repo (sewar) uses uniform distribution
      # in their implementation of UQI, and we use gaussian distribution
      # and they have different default values for some kwargs like window size.
      for k in range(length):
          for r in range(k, length):
              m1[k, r] = m1[r, k] = universal_image_quality_index(
                  target[:, k : k + 1, :, :], target[:, r : r + 1, :, :]
              )
              m2[k, r] = m2[r, k] = universal_image_quality_index(
                  preds[:, k : k + 1, :, :], preds[:, r : r + 1, :, :]
              )
      diff = np.abs(m1 - m2) ** p
  
      # Special case: when number of channels (L) is 1, there will be only one element in M1 and M2. Hence no need to sum.
      if length == 1:
          return diff[0][0] ** (1.0 / p)
      return (1.0 / (length * (length - 1)) * np.sum(diff)) ** (1.0 / p)
  
imports: from functools import partial
  from typing import NamedTuple
  import numpy
  import pytest
  import torch
  from torch import Tensor
  from torchmetrics.functional.image.d_lambda import spectral_distortion_index
  from torchmetrics.functional.image.uqi import universal_image_quality_index
  from torchmetrics.image.d_lambda import SpectralDistortionIndex
  from unittests import BATCH_SIZE, NUM_BATCHES
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester
label_desc: Use image node_id 1 for calling a global function with example usage: _baseline_d_lambda(preds, target, p) and returns: unknown, unknown