class_docstr: Wrap a base metric to enable it to support multiple outputs.
  
  Several torchmetrics metrics, such as :class:`~torchmetrics.regression.spearman.SpearmanCorrCoef` lack support for
  multioutput mode. This class wraps such metrics to support computing one metric per output.
  Unlike specific torchmetric metrics, it doesn't support any aggregation across outputs.
  This means if you set ``num_outputs`` to 2, ``.compute()`` will return a Tensor of dimension
  ``(2, ...)`` where ``...`` represents the dimensions the metric returns when not wrapped.
  
  In addition to enabling multioutput support for metrics that lack it, this class also supports, albeit in a crude
  fashion, dealing with missing labels (or other data). When ``remove_nans`` is passed, the class will remove the
  intersection of NaN containing "rows" upon each update for each output. For example, suppose a user uses
  `MultioutputWrapper` to wrap :class:`torchmetrics.regression.r2.R2Score` with 2 outputs, one of which occasionally
  has missing labels for classes like ``R2Score`` is that this class supports removing ``NaN`` values
  (parameter ``remove_nans``) on a per-output basis. When ``remove_nans`` is passed the wrapper will remove all rows
  
  Args:
      base_metric: Metric being wrapped.
      num_outputs: Expected dimensionality of the output dimension.
          This parameter is used to determine the number of distinct metrics we need to track.
      output_dim:
          Dimension on which output is expected. Note that while this provides some flexibility, the output dimension
          must be the same for all inputs to update. This applies even for metrics such as `Accuracy` where the labels
          can have a different number of dimensions than the predictions. This can be worked around if the output
          dimension can be set to -1 for both, even if -1 corresponds to different dimensions in different inputs.
      remove_nans:
          Whether to remove the intersection of rows containing NaNs from the values passed through to each underlying
          metric. Proper operation requires all tensors passed to update to have dimension ``(N, ...)`` where N
          represents the length of the batch or dataset being passed in.
      squeeze_outputs:
          If ``True``, will squeeze the 1-item dimensions left after ``index_select`` is applied.
          This is sometimes unnecessary but harmless for metrics such as `R2Score` but useful
          for certain classification metrics that can't handle additional 1-item dimensions.
  
  Example:
       >>> # Mimic R2Score in `multioutput`, `raw_values` mode:
       >>> import torch
       >>> from torchmetrics.wrappers import MultioutputWrapper
       >>> from torchmetrics.regression import R2Score
       >>> target = torch.tensor([[0.5, 1], [-1, 1], [7, -6]])
       >>> preds = torch.tensor([[0, 2], [-1, 2], [8, -5]])
       >>> r2score = MultioutputWrapper(R2Score(), 2)
       >>> r2score(preds, target)
       tensor([0.9654, 0.9082])
class_docstr_tok: ["Wrap","a","base","metric","to","enable","it","to","support","multiple","outputs",".","Several","torchmetrics","metrics",",","such","as",":","class",":","`","~torchmetrics.regression.spearman.SpearmanCorrCoef","`","lack","support","for","multioutput","mode",".","This","class","wraps","such","metrics","to","support","computing","one","metric","per","output",".","Unlike","specific","torchmetric","metrics",",","it","does","n't","support","any","aggregation","across","outputs",".","This","means","if","you","set","``","num_outputs","``","to","2",",","``",".compute","(",")","``","will","return","a","Tensor","of","dimension","``","(","2",",","...",")","``","where","``","...","``","represents","the","dimensions","the","metric","returns","when","not","wrapped",".","In","addition","to","enabling","multioutput","support","for","metrics","that","lack","it",",","this","class","also","supports",",","albeit","in","a","crude","fashion",",","dealing","with","missing","labels","(","or","other","data",")",".","When","``","remove_nans","``","is","passed",",","the","class","will","remove","the","intersection","of","NaN","containing","``","rows","''","upon","each","update","for","each","output",".","For","example",",","suppose","a","user","uses","`","MultioutputWrapper","`","to","wrap",":","class",":","`","torchmetrics.regression.r2.R2Score","`","with","2","outputs",",","one","of","which","occasionally","has","missing","labels","for","classes","like","``","R2Score","``","is","that","this","class","supports","removing","``","NaN","``","values","(","parameter","``","remove_nans","``",")","on","a","per-output","basis",".","When","``","remove_nans","``","is","passed","the","wrapper","will","remove","all","rows","Args",":","base_metric",":","Metric","being","wrapped",".","num_outputs",":","Expected","dimensionality","of","the","output","dimension",".","This","parameter","is","used","to","determine","the","number","of","distinct","metrics","we","need","to","track",".","output_dim",":","Dimension","on","which","output","is","expected",".","Note","that","while","this","provides","some","flexibility",",","the","output","dimension","must","be","the","same","for","all","inputs","to","update",".","This","applies","even","for","metrics","such","as","`","Accuracy","`","where","the","labels","can","have","a","different","number","of","dimensions","than","the","predictions",".","This","can","be","worked","around","if","the","output","dimension","can","be","set","to","-1","for","both",",","even","if","-1","corresponds","to","different","dimensions","in","different","inputs",".","remove_nans",":","Whether","to","remove","the","intersection","of","rows","containing","NaNs","from","the","values","passed","through","to","each","underlying","metric",".","Proper","operation","requires","all","tensors","passed","to","update","to","have","dimension","``","(","N",",","...",")","``","where","N","represents","the","length","of","the","batch","or","dataset","being","passed","in",".","squeeze_outputs",":","If","``","True","``",",","will","squeeze","the","1-item","dimensions","left","after","``","index_select","``","is","applied",".","This","is","sometimes","unnecessary","but","harmless","for","metrics","such","as","`","R2Score","`","but","useful","for","certain","classification","metrics","that","ca","n't","handle","additional","1-item","dimensions",".","Example",":",">",">",">","#","Mimic","R2Score","in","`","multioutput","`",",","`","raw_values","`","mode",":",">",">",">","import","torch",">",">",">","from","torchmetrics.wrappers","import","MultioutputWrapper",">",">",">","from","torchmetrics.regression","import","R2Score",">",">",">","target","=","torch.tensor","(","[","[","0.5",",","1","]",",","[","-1",",","1","]",",","[","7",",","-6","]","]",")",">",">",">","preds","=","torch.tensor","(","[","[","0",",","2","]",",","[","-1",",","2","]",",","[","8",",","-5","]","]",")",">",">",">","r2score","=","MultioutputWrapper","(","R2Score","(",")",",","2",")",">",">",">","r2score","(","preds",",","target",")","tensor","(","[","0.9654",",","0.9082","]",")"]
docstr: Update each underlying metric with the corresponding output.
docstr_tok: ["Update","each","underlying","metric","with","the","corresponding","output","."]
code: def update(self, *args: Any, **kwargs: Any) -> None:
      """Update each underlying metric with the corresponding output."""
      reshaped_args_kwargs = self._get_args_kwargs_by_output(
          *args, **kwargs
      )
      for metric, (selected_args, selected_kwargs) in zip(
          self.metrics, reshaped_args_kwargs
      ):
          metric.update(*selected_args, **selected_kwargs)
  
file_path: torchmetrics/src/torchmetrics/wrappers/multioutput.py
imports: from copy import deepcopy
  from typing import Any, List, Optional, Sequence, Tuple, Union
  import torch
  from lightning_utilities import apply_to_collection
  from torch import Tensor
  from torch.nn import ModuleList
  from torchmetrics.metric import Metric
  from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE
  from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE
  from torchmetrics.wrappers.abstract import WrapperMetric
label_desc: Use image node_id 3 for calling the MultioutputWrapper obj's underlying member method code with example usage: obj.update() without return types