old_contents: from matchzoo import engine
  from .discounted_cumulative_gain import DiscountedCumulativeGain
  
  
  class NormalizedDiscountedCumulativeGain(engine.BaseMetric):
      """Normalized discounted cumulative gain metric."""
  
      ALIAS = ['normalized_discounted_cumulative_gain', 'ndcg']
  
      def __init__(self, k=1, threshold=0):
          """
          Normalized discounted cumulative gain metric.
  
          :param k: Number of results to consider
          :param threshold: the label threshold of relevance degree.
          """
          self._k = k
          self._threshold = threshold
  
      def __repr__(self):
          """:return: Formated string representation of the metric."""
          return f"{self.ALIAS[0]}@{self._k}({self._threshold})"
  
      def __call__(self, y_true, y_pred):
          """
          Calculate normalized discounted cumulative gain (ndcg).
  
          Relevance is positive real values or binary values.
  
          Example:
              >>> y_true = [0, 1, 2, 0]
              >>> y_pred = [0.4, 0.2, 0.5, 0.7]
              >>> ndcg = NormalizedDiscountedCumulativeGain
              >>> ndcg(k=1)(y_true, y_pred)
              0.0
              >>> round(ndcg(k=2)(y_true, y_pred), 2)
              0.52
              >>> round(ndcg(k=3)(y_true, y_pred), 2)
              0.52
              >>> type(ndcg()(y_true, y_pred))
              <class 'float'>
  
          :param y_true: The ground true label of each document.
          :param y_pred: The predicted scores of each document.
  
          :return: Normalized discounted cumulative gain.
          """
          dcg_metric = DiscountedCumulativeGain(k=self._k,
                                                threshold=self._threshold)
          idcg_val = dcg_metric(y_true, y_true)
          dcg_val = dcg_metric(y_true, y_pred)
          return dcg_val / idcg_val
  
new_contents: from matchzoo import engine
  from .discounted_cumulative_gain import DiscountedCumulativeGain
  
  
  class NormalizedDiscountedCumulativeGain(engine.BaseMetric):
      """Normalized discounted cumulative gain metric."""
  
      ALIAS = ['normalized_discounted_cumulative_gain', 'ndcg']
  
      def __init__(self, k=1, threshold=0):
          """
          Normalized discounted cumulative gain metric.
  
          :param k: Number of results to consider
          :param threshold: the label threshold of relevance degree.
          """
          self._k = k
          self._threshold = threshold
  
      def __repr__(self):
          """:return: Formated string representation of the metric."""
          return f"{self.ALIAS[0]}@{self._k}({self._threshold})"
  
      def __call__(self, y_true, y_pred):
          """
          Calculate normalized discounted cumulative gain (ndcg).
  
          Relevance is positive real values or binary values.
  
          Example:
              >>> y_true = [0, 1, 2, 0]
              >>> y_pred = [0.4, 0.2, 0.5, 0.7]
              >>> ndcg = NormalizedDiscountedCumulativeGain
              >>> ndcg(k=1)(y_true, y_pred)
              0.0
              >>> round(ndcg(k=2)(y_true, y_pred), 2)
              0.52
              >>> round(ndcg(k=3)(y_true, y_pred), 2)
              0.52
              >>> type(ndcg()(y_true, y_pred))
              <class 'float'>
  
          :param y_true: The ground true label of each document.
          :param y_pred: The predicted scores of each document.
  
          :return: Normalized discounted cumulative gain.
          """
          dcg_metric = DiscountedCumulativeGain(k=self._k,
                                                threshold=self._threshold)
          idcg_val = dcg_metric(y_true, y_true)
          dcg_val = dcg_metric(y_true, y_pred)
          return dcg_val / idcg_val if idcg_val != 0 else 0
  
subject: Fix ndcg divide by zero bug