class_docstr: `Spectral Angle Mapper`_ determines the spectral similarity between image spectra and reference spectra.
  
  It works by calculating the angle between the spectra, where small angles between indicate high similarity and
  high angles indicate low similarity.
  
  As input to ``forward`` and ``update`` the metric accepts the following input
  
  - ``preds`` (:class:`~torch.Tensor`): Predictions from model of shape ``(N,C,H,W)``
  - ``target`` (:class:`~torch.Tensor`): Ground truth values of shape ``(N,C,H,W)``
  
  As output of `forward` and `compute` the metric returns the following output
  
  - ``sam`` (:class:`~torch.Tensor`): if ``reduction!='none'`` returns float scalar tensor with average SAM value
    over sample else returns tensor of shape ``(N,)`` with SAM values per sample
  
  Args:
      reduction: a method to reduce metric score over labels.
  
          - ``'elementwise_mean'``: takes the mean (default)
          - ``'sum'``: takes the sum
          - ``'none'`` or ``None``: no reduction will be applied
  
      kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.
  
  Return:
      Tensor with SpectralAngleMapper score
  
  Example:
      >>> import torch
      >>> from torchmetrics.image import SpectralAngleMapper
      >>> gen = torch.manual_seed(42)
      >>> preds = torch.rand([16, 3, 16, 16], generator=gen)
      >>> target = torch.rand([16, 3, 16, 16], generator=gen)
      >>> sam = SpectralAngleMapper()
      >>> sam(preds, target)
      tensor(0.5914)
class_docstr_tok: ["`","Spectral","Angle","Mapper","`","_","determines","the","spectral","similarity","between","image","spectra","and","reference","spectra",".","It","works","by","calculating","the","angle","between","the","spectra",",","where","small","angles","between","indicate","high","similarity","and","high","angles","indicate","low","similarity",".","As","input","to","``","forward","``","and","``","update","``","the","metric","accepts","the","following","input","-","``","preds","``","(",":","class",":","`","~torch.Tensor","`",")",":","Predictions","from","model","of","shape","``","(","N",",","C",",","H",",","W",")","``","-","``","target","``","(",":","class",":","`","~torch.Tensor","`",")",":","Ground","truth","values","of","shape","``","(","N",",","C",",","H",",","W",")","``","As","output","of","`","forward","`","and","`","compute","`","the","metric","returns","the","following","output","-","``","sam","``","(",":","class",":","`","~torch.Tensor","`",")",":","if","``","reduction","!","='none","'","``","returns","float","scalar","tensor","with","average","SAM","value","over","sample","else","returns","tensor","of","shape","``","(","N",",",")","``","with","SAM","values","per","sample","Args",":","reduction",":","a","method","to","reduce","metric","score","over","labels",".","-","``","'elementwise_mean","'","``",":","takes","the","mean","(","default",")","-","``","'sum","'","``",":","takes","the","sum","-","``","'none","'","``","or","``","None","``",":","no","reduction","will","be","applied","kwargs",":","Additional","keyword","arguments",",","see",":","ref",":","`","Metric","kwargs","`","for","more","info",".","Return",":","Tensor","with","SpectralAngleMapper","score","Example",":",">",">",">","import","torch",">",">",">","from","torchmetrics.image","import","SpectralAngleMapper",">",">",">","gen","=","torch.manual_seed","(","42",")",">",">",">","preds","=","torch.rand","(","[","16",",","3",",","16",",","16","]",",","generator=gen",")",">",">",">","target","=","torch.rand","(","[","16",",","3",",","16",",","16","]",",","generator=gen",")",">",">",">","sam","=","SpectralAngleMapper","(",")",">",">",">","sam","(","preds",",","target",")","tensor","(","0.5914",")"]
docstr: Compute spectra over state.
docstr_tok: ["Compute","spectra","over","state","."]
code: def compute(self) -> Tensor:
      """Compute spectra over state."""
      if self.reduction == "none" or self.reduction is None:
          preds = dim_zero_cat(self.preds)
          target = dim_zero_cat(self.target)
          return _sam_compute(preds, target, self.reduction)
      return (
          self.sum_sam / self.numel
          if self.reduction == "elementwise_mean"
          else self.sum_sam
      )
  
file_path: torchmetrics/src/torchmetrics/image/sam.py
imports: from typing import Any, List, Optional, Sequence, Union
  from torch import Tensor, tensor
  from typing_extensions import Literal
  from torchmetrics.functional.image.sam import _sam_compute, _sam_update
  from torchmetrics.metric import Metric
  from torchmetrics.utilities import rank_zero_warn
  from torchmetrics.utilities.data import dim_zero_cat
  from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE
  from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE
label_desc: Use image node_id 3 for calling the SpectralAngleMapper obj's underlying member method code with example usage: obj.compute() and returns: unknown, _sam_compute