code: def test_make_discounted_cumulative_gain_fn(self):
      with tf.Graph().as_default():
          scores = [[1.0, 3.0, 2.0], [1.0, 2.0, 3.0]]
          # Note that scores are ranked in descending order.
          ranks = [[3, 1, 2], [3, 2, 1]]
          labels = [[0.0, 0.0, 1.0], [0.0, 1.0, 2.0]]
          weights = [[1.0, 1.0, 1.0], [2.0, 2.0, 1.0]]
          weights_feature_name = "weights"
          features = {weights_feature_name: weights}
          m = metrics_lib.make_ranking_metric_fn(
              metrics_lib.RankingMetricKey.DCG
          )
          m_w = metrics_lib.make_ranking_metric_fn(
              metrics_lib.RankingMetricKey.DCG,
              weights_feature_name=weights_feature_name,
          )
          expected_dcg_1 = _dcg(0.0, 1) + _dcg(1.0, 2) + _dcg(0.0, 3)
          self._check_metrics(
              [
                  (
                      m([labels[0]], [scores[0]], features),
                      expected_dcg_1,
                  ),
              ]
          )
          expected_dcg_2 = _dcg(2.0, 1) + _dcg(1.0, 2)
          expected_dcg_2_weighted = _dcg(2.0, 1) + _dcg(1.0, 2) * 2.0
          expected_weight_2 = ((4 - 1) * 1.0 + (2 - 1) * 2.0) / (
              4 - 1 + 2 - 1
          )
          self._check_metrics(
              [
                  (
                      m(labels, scores, features),
                      (expected_dcg_1 + expected_dcg_2) / 2.0,
                  ),
                  (
                      m_w(labels, scores, features),
                      (expected_dcg_1 + expected_dcg_2_weighted)
                      / (1.0 + expected_weight_2),
                  ),
              ]
          )
          # Test different gain and discount functions.
          gain_fn = lambda rel: rel
          rank_discount_fn = lambda rank: 1.0 / rank
  
          def mod_dcg_fn(l, r):
              return _dcg(
                  l,
                  r,
                  gain_fn=gain_fn,
                  rank_discount_fn=rank_discount_fn,
              )
  
          m_mod = metrics_lib.make_ranking_metric_fn(
              metrics_lib.RankingMetricKey.DCG,
              gain_fn=gain_fn,
              rank_discount_fn=rank_discount_fn,
          )
          list_size = len(scores[0])
          expected_modified_dcg_1 = sum(
              [
                  mod_dcg_fn(labels[0][ind], ranks[0][ind])
                  for ind in range(list_size)
              ]
          )
          self._check_metrics(
              [
                  (
                      m_mod([labels[0]], [scores[0]], features),
                      expected_modified_dcg_1,
                  ),
              ]
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import math
  import tensorflow
  from tensorflow_ranking.python import metrics
label_desc: Use image node_id 12 for calling the MetricsTest obj's underlying member method code with example usage: obj.test_make_discounted_cumulative_gain_fn() and returns: _dcg