code: def _baseline_sam(
      preds: Tensor,
      target: Tensor,
      reduction: str = "elementwise_mean",
  ) -> Tensor:
      """Baseline implementation of spectral angle mapper."""
      reduction_options = ("elementwise_mean", "sum", "none")
      if reduction not in reduction_options:
          raise ValueError(
              f"reduction has to be one of {reduction_options}, got: {reduction}."
          )
      similarity = F.cosine_similarity(preds, target)
      sam_score = torch.clamp(similarity, -1, 1).acos()
      # reduction
      if reduction == "sum":
          return torch.sum(sam_score)
      if reduction == "elementwise_mean":
          return torch.mean(sam_score)
      return sam_score
  
imports: from functools import partial
  import pytest
  import torch
  from torch import Tensor
  from torch.nn import functional
  from torchmetrics.functional.image.sam import spectral_angle_mapper
  from torchmetrics.image.sam import SpectralAngleMapper
  from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_2_1
  from unittests import BATCH_SIZE, NUM_BATCHES, _Input
  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_sam(preds, target, reduction) and returns: sam_score, torch, torch