code: def confusion_matrix(
      preds: Tensor,
      target: Tensor,
      task: Literal["binary", "multiclass", "multilabel"],
      threshold: float = 0.5,
      num_classes: Optional[int] = None,
      num_labels: Optional[int] = None,
      normalize: Optional[
          Literal["true", "pred", "all", "none"]
      ] = None,
      ignore_index: Optional[int] = None,
      validate_args: bool = True,
  ) -> Tensor:
      r"""Compute the `confusion matrix`_.
  
      This function is a simple wrapper to get the task specific versions of this metric, which is done by setting the
      ``task`` argument to either ``'binary'``, ``'multiclass'`` or ``multilabel``. See the documentation of
      :func:`~torchmetrics.functional.classification.binary_confusion_matrix`,
      :func:`~torchmetrics.functional.classification.multiclass_confusion_matrix` and
      :func:`~torchmetrics.functional.classification.multilabel_confusion_matrix` for
      the specific details of each argument influence and examples.
  
      Legacy Example:
          >>> from torch import tensor
          >>> from torchmetrics.classification import ConfusionMatrix
          >>> target = tensor([1, 1, 0, 0])
          >>> preds = tensor([0, 1, 0, 0])
          >>> confmat = ConfusionMatrix(task="binary")
          >>> confmat(preds, target)
          tensor([[2, 0],
                  [1, 1]])
  
          >>> target = tensor([2, 1, 0, 0])
          >>> preds = tensor([2, 1, 0, 1])
          >>> confmat = ConfusionMatrix(task="multiclass", num_classes=3)
          >>> confmat(preds, target)
          tensor([[1, 1, 0],
                  [0, 1, 0],
                  [0, 0, 1]])
  
          >>> target = tensor([[0, 1, 0], [1, 0, 1]])
          >>> preds = tensor([[0, 0, 1], [1, 0, 1]])
          >>> confmat = ConfusionMatrix(task="multilabel", num_labels=3)
          >>> confmat(preds, target)
          tensor([[[1, 0], [0, 1]],
                  [[1, 0], [1, 0]],
                  [[0, 1], [0, 1]]])
  
      """
      task = ClassificationTask.from_str(task)
      if task == ClassificationTask.BINARY:
          return binary_confusion_matrix(
              preds,
              target,
              threshold,
              normalize,
              ignore_index,
              validate_args,
          )
      if task == ClassificationTask.MULTICLASS:
          if not isinstance(num_classes, int):
              raise ValueError(
                  f"`num_classes` is expected to be `int` but `{type(num_classes)} was passed.`"
              )
          return multiclass_confusion_matrix(
              preds,
              target,
              num_classes,
              normalize,
              ignore_index,
              validate_args,
          )
      if task == ClassificationTask.MULTILABEL:
          if not isinstance(num_labels, int):
              raise ValueError(
                  f"`num_labels` is expected to be `int` but `{type(num_labels)} was passed.`"
              )
          return multilabel_confusion_matrix(
              preds,
              target,
              num_labels,
              threshold,
              normalize,
              ignore_index,
              validate_args,
          )
      raise ValueError(f"Task {task} not supported.")
  
imports: from typing import Optional, Tuple
  import torch
  from torch import Tensor
  from typing_extensions import Literal
  from torchmetrics.utilities.checks import _check_same_shape
  from torchmetrics.utilities.data import _bincount
  from torchmetrics.utilities.enums import ClassificationTask
  from torchmetrics.utilities.prints import rank_zero_warn
label_desc: Use image node_id 20 for calling a global function with example usage: confusion_matrix(preds, target, task, threshold, num_classes, num_labels, normalize, ignore_index, validate_args) and returns: binary_confusion_matrix, multiclass_confusion_matrix, multilabel_confusion_matrix