class_docstr: 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
  :class:`~torchmetrics.classification.BinaryConfusionMatrix`,
  :class:`~torchmetrics.classification.MulticlassConfusionMatrix` and
  :class:`~torchmetrics.classification.MultilabelConfusionMatrix` for the specific details of each argument influence
  and examples.
  
  Legacy Example:
      >>> from torch import tensor
      >>> target = tensor([1, 1, 0, 0])
      >>> preds = tensor([0, 1, 0, 0])
      >>> confmat = ConfusionMatrix(task="binary", num_classes=2)
      >>> 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]]])
class_docstr_tok: ["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",":","class",":","`","~torchmetrics.classification.BinaryConfusionMatrix","`",",",":","class",":","`","~torchmetrics.classification.MulticlassConfusionMatrix","`","and",":","class",":","`","~torchmetrics.classification.MultilabelConfusionMatrix","`","for","the","specific","details","of","each","argument","influence","and","examples",".","Legacy","Example",":",">",">",">","from","torch","import","tensor",">",">",">","target","=","tensor","(","[","1",",","1",",","0",",","0","]",")",">",">",">","preds","=","tensor","(","[","0",",","1",",","0",",","0","]",")",">",">",">","confmat","=","ConfusionMatrix","(","task=","''","binary","''",",","num_classes=2",")",">",">",">","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","]","]","]",")"]
docstr: Initialize task metric.
docstr_tok: ["Initialize","task","metric","."]
code: def __new__(  # type: ignore[misc]
      cls: Type["ConfusionMatrix"],
      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,
      **kwargs: Any,
  ) -> Metric:
      """Initialize task metric."""
      task = ClassificationTask.from_str(task)
      kwargs.update(
          {
              "normalize": normalize,
              "ignore_index": ignore_index,
              "validate_args": validate_args,
          }
      )
      if task == ClassificationTask.BINARY:
          return BinaryConfusionMatrix(threshold, **kwargs)
      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 MulticlassConfusionMatrix(num_classes, **kwargs)
      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 MultilabelConfusionMatrix(
              num_labels, threshold, **kwargs
          )
      raise ValueError(f"Task {task} not supported!")
  
imports: from typing import Any, List, Optional, Type
  import torch
  from torch import Tensor
  from typing_extensions import Literal
  from torchmetrics.classification.base import _ClassificationTaskWrapper
  from torchmetrics.functional.classification.confusion_matrix import _binary_confusion_matrix_arg_validation, _binary_confusion_matrix_compute, _binary_confusion_matrix_format, _binary_confusion_matrix_tensor_validation, _binary_confusion_matrix_update, _multiclass_confusion_matrix_arg_validation, _multiclass_confusion_matrix_compute, _multiclass_confusion_matrix_format, _multiclass_confusion_matrix_tensor_validation, _multiclass_confusion_matrix_update, _multilabel_confusion_matrix_arg_validation, _multilabel_confusion_matrix_compute, _multilabel_confusion_matrix_format, _multilabel_confusion_matrix_tensor_validation, _multilabel_confusion_matrix_update
  from torchmetrics.metric import Metric
  from torchmetrics.utilities.enums import ClassificationTask
  from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE
  from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE, plot_confusion_matrix
label_desc: Use image node_id 1 for calling the ConfusionMatrix obj's underlying member method code with example usage: obj.__new__(cls, task, threshold, num_classes, num_labels, normalize, ignore_index, validate_args) and returns: BinaryConfusionMatrix, MulticlassConfusionMatrix, MultilabelConfusionMatrix