class_docstr: TopKRetrievalAggFn aggregate.
  
  Attributes:
    k_list: topk list, default to None, which means all outputs are considered.
    metrics: The metrics to be computed.
    input_type: input encoding type, must be `multiclass` or
      `multiclass-multioutput`.
docstr: Compute all true positive related metrics.
docstr_tok: ["Compute","all","true","positive","related","metrics","."]
code: def _compute_metric_states(self, y_trues, y_preds):
      """Compute all true positive related metrics."""
      k_list = (
          list(sorted(self.k_list)) if self.k_list else [float("inf")]
      )
      y_pred_count = np.asarray([len(row) for row in y_preds])
      y_true_count = np.asarray([len(row) for row in y_trues])
      max_pred_count = max(y_pred_count)
      max_pred_count = min(max_pred_count, max(k_list))
      tp = []
      for y_pred, y_true in zip(y_preds, y_trues):
          tp.append(
              [
                  int(y_pred[i] in y_true) if i < len(y_pred) else 0
                  for i in range(max_pred_count)
              ]
          )
      tp = np.asarray(tp)
      # True positives at TopK is of a dimension of Examples x K as the following:
      # The first dimension is always batch dimension (# examples), the second
      # dimension can be either 0D (single-output) or 1D (multioutput) array.
      # E.g., provided one multioutput prediction and its true positive:
      # topk:         [1,    2,     3]
      # true-positive: [True, False, True]
      # We will get the true positives at topKs:
      # topk:     [top1, top2, top3]
      # tp_topks: [1,     1,      2]
      tp_at_topks = np.cumsum(tp, axis=1)
      # Truncates the k_list with maximum length of the predictions.
      k_list = np.asarray(
          [k for k in k_list if k < max_pred_count] + [max_pred_count]
      )
  
      # A consecutive K list that is useful to calculate average-over-Ks metrics
      # such as mean average precision.
      k_range = np.arange(max_pred_count) + 1
  
      result = {}
      if "accuracy" in self.metrics:
          accuracy = (tp_at_topks[:, k_list - 1] > 0).astype(np.int32)
          result["accuracy"] = MeanState(
              accuracy.sum(axis=0), accuracy.shape[0]
          )
  
      precision, recall = None, None
      if "precision" in self.metrics:
          precision = _precision(tp_at_topks, k_list, y_pred_count)
          result["precision"] = MeanState(
              precision.sum(axis=0), precision.shape[0]
          )
  
      if "recall" in self.metrics:
          recall = _recall(tp_at_topks, k_list, y_true_count)
          result["recall"] = MeanState(
              recall.sum(axis=0), recall.shape[0]
          )
  
      if "f1_score" in self.metrics:
          if precision is None:
              precision = _precision(tp_at_topks, k_list, y_pred_count)
          if recall is None:
              recall = _recall(tp_at_topks, k_list, y_true_count)
          f1 = _f1_score(precision, recall)
          result["f1_score"] = MeanState(f1.sum(axis=0), f1.shape[0])
  
      if "mean_average_precision" in self.metrics:
          mean_average_precision = _mean_average_precision(
              tp, tp_at_topks, k_range, k_list, y_true_count
          )
          result["mean_average_precision"] = MeanState(
              mean_average_precision.sum(axis=0),
              mean_average_precision.shape[0],
          )
  
      if "mean_reciprocal_rank" in self.metrics:
          reciprocal_ranks = _mean_reciprocal_rank(tp_at_topks, k_list)
          result["mean_reciprocal_rank"] = MeanState(
              reciprocal_ranks.sum(axis=0), reciprocal_ranks.shape[0]
          )
  
      if "miss_rate" in self.metrics:
          miss_rate = _miss_rate(tp_at_topks, k_list, y_true_count)
          result["miss_rate"] = MeanState(
              miss_rate.sum(axis=0), miss_rate.shape[0]
          )
  
      if "false_discovery_rate" in self.metrics:
          false_discovery_rate = _false_discovery_rate(
              tp_at_topks, k_list, y_pred_count
          )
          result["false_discovery_rate"] = MeanState(
              false_discovery_rate.sum(axis=0),
              false_discovery_rate.shape[0],
          )
  
      if "threat_score" in self.metrics:
          threat_score = _threat_score(
              tp_at_topks, k_list, y_true_count
          )
          result["threat_score"] = MeanState(
              threat_score.sum(axis=0), threat_score.shape[0]
          )
  
      if "fowlkes_mallows_index" in self.metrics:
          fowlkes_mallows_index = _fowlkes_mallows_index(
              tp_at_topks, k_list, y_true_count, y_pred_count
          )
          result["fowlkes_mallows_index"] = MeanState(
              fowlkes_mallows_index.sum(axis=0),
              fowlkes_mallows_index.shape[0],
          )
  
      if "dcg_score" in self.metrics:
          dcg = _dcg_score(tp, k_range, k_list)
          result["dcg_score"] = MeanState(dcg.sum(axis=0), dcg.shape[0])
  
      if "ndcg_score" in self.metrics:
          ndcg = _ndcg_score(tp, k_range, k_list, y_true_count)
          result["ndcg_score"] = MeanState(
              ndcg.sum(axis=0), ndcg.shape[0]
          )
      return result
  
imports: from collections.abc import Sequence
  import dataclasses
  from typing import Any
  import numpy
  from numpy import typing
  from tensorflow_model_analysis.experimental.lazytf import api
  from tensorflow_model_analysis.experimental.metrics.aggregates import _classification
label_desc: Use image node_id 1 for calling the TopKRetrievalAggFn obj's underlying member method code with example usage: obj._compute_metric_states(y_trues, y_preds) and returns: result