class_docstr: Base class for metrics computation at the iteration level, that is, on a min-batch of samples
  usually using the model outcome of one iteration.
  
  `__call__` is designed to handle `y_pred` and `y` (optional) in torch tensors or a list/tuple of tensors.
  
  Subclasses typically implement the `_compute_tensor` function for the actual tensor computation logic.
class_docstr_tok: ["Base","class","for","metrics","computation","at","the","iteration","level",",","that","is",",","on","a","min-batch","of","samples","usually","using","the","model","outcome","of","one","iteration",".","`","__call__","`","is","designed","to","handle","`","y_pred","`","and","`","y","`","(","optional",")","in","torch","tensors","or","a","list\/tuple","of","tensors",".","Subclasses","typically","implement","the","`","_compute_tensor","`","function","for","the","actual","tensor","computation","logic","."]
docstr: Execute the metric computation for `y_pred` and `y` in a list of "channel-first" tensors.
  
  The return value is a "batch-first" tensor, or a list of "batch-first" tensors.
  When it's a list of tensors, each item in the list can represent a specific type of metric values.
  
  For example, `self._compute_tensor` may be implemented as returning a list of `batch_size` items,
  where each item is a tuple of three values `tp`, `fp`, `fn` for true positives, false positives,
  and false negatives respectively. This function will return a list of three items,
  (`tp_batched`, `fp_batched`, `fn_batched`), where each item is a `batch_size`-length tensor.
  
  Note: subclass may enhance the operation to have multi-thread support.
docstr_tok: ["Execute","the","metric","computation","for","`","y_pred","`","and","`","y","`","in","a","list","of","``","channel-first","''","tensors",".","The","return","value","is","a","``","batch-first","''","tensor",",","or","a","list","of","``","batch-first","''","tensors",".","When","it","'s","a","list","of","tensors",",","each","item","in","the","list","can","represent","a","specific","type","of","metric","values",".","For","example",",","`","self._compute_tensor","`","may","be","implemented","as","returning","a","list","of","`","batch_size","`","items",",","where","each","item","is","a","tuple","of","three","values","`","tp","`",",","`","fp","`",",","`","fn","`","for","true","positives",",","false","positives",",","and","false","negatives","respectively",".","This","function","will","return","a","list","of","three","items",",","(","`","tp_batched","`",",","`","fp_batched","`",",","`","fn_batched","`",")",",","where","each","item","is","a","`","batch_size","`","-length","tensor",".","Note",":","subclass","may","enhance","the","operation","to","have","multi-thread","support","."]
code: def _compute_list(
      self,
      y_pred: TensorOrList,
      y: TensorOrList | None = None,
      **kwargs: Any,
  ) -> torch.Tensor | list[torch.Tensor | Sequence[torch.Tensor]]:
      """
      Execute the metric computation for `y_pred` and `y` in a list of "channel-first" tensors.
  
      The return value is a "batch-first" tensor, or a list of "batch-first" tensors.
      When it's a list of tensors, each item in the list can represent a specific type of metric values.
  
      For example, `self._compute_tensor` may be implemented as returning a list of `batch_size` items,
      where each item is a tuple of three values `tp`, `fp`, `fn` for true positives, false positives,
      and false negatives respectively. This function will return a list of three items,
      (`tp_batched`, `fp_batched`, `fn_batched`), where each item is a `batch_size`-length tensor.
  
      Note: subclass may enhance the operation to have multi-thread support.
      """
      if y is not None:
          ret = [
              self._compute_tensor(
                  p.detach().unsqueeze(0),
                  y_.detach().unsqueeze(0),
                  **kwargs,
              )
              for p, y_ in zip(y_pred, y)
          ]
      else:
          ret = [
              self._compute_tensor(
                  p_.detach().unsqueeze(0), None, **kwargs
              )
              for p_ in y_pred
          ]
  
      # concat the list of results (e.g. a batch of evaluation scores)
      if isinstance(ret[0], torch.Tensor):
          return torch.cat(ret, dim=0)  # type: ignore[arg-type]
      # the result is a list of sequence of tensors (e.g. a batch of multi-class results)
      if isinstance(ret[0], (list, tuple)) and all(
          isinstance(i, torch.Tensor) for i in ret[0]
      ):
          return [torch.cat(batch_i, dim=0) for batch_i in zip(*ret)]
      return ret
  
imports: from __future__ import annotations
  from abc import ABC, abstractmethod
  from collections.abc import Sequence
  from typing import Any
  import torch
  from monai.config import TensorOrList
  from monai.utils import convert_data_type, evenly_divisible_all_gather
label_desc: Use image node_id 2 for calling the IterationMetric obj's underlying member method code with example usage: obj._compute_list(y_pred, y) and returns: ret, torch, unknown