def _precision_recall(predictions, targets, k):  # pylint: disable=invalid-name
  """Returns precision, recall, and intermediate values for the category `k`.

  A support function for calculating precision, recall,
  and intermediate values for the single category `k`
  for future use in metric layers.

  Args:
    predictions: predicted categories.
    targets: target categories.
    k: a category number.

  Returns a tuple:
    n_correct: a number of correct (or true) examples.
    n_k_predictions: a number of predictions of the `k` category.
    n_k_targets: a number of targets for the `k` category.
    precision: a precision score.
    recall: a recall score.
  """
  n_correct = sum((predictions == k) & (targets == k))
  n_k_predictions = sum(predictions == k)
  precision = _non_nan(n_correct / n_k_predictions)
  n_k_targets = sum(targets == k)
  recall = _non_nan(n_correct / n_k_targets)
  return (n_correct, n_k_predictions, n_k_targets, precision, recall)
Returns precision, recall, and intermediate values for the category `k`.

  A support function for calculating precision, recall,
  and intermediate values for the single category `k`
  for future use in metric layers.

  Args:
    predictions: predicted categories.
    targets: target categories.
    k: a category number.

  Returns a tuple:
    n_correct: a number of correct (or true) examples.
    n_k_predictions: a number of predictions of the `k` category.
    n_k_targets: a number of targets for the `k` category.
    precision: a precision score.
    recall: a recall score.
  
trax/layers/metrics.py