code: def test_make_bpref_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], [1.0, 0.0, 2.0]]
          weights = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
          weights_feature_name = "weights"
          features = {weights_feature_name: weights}
          # BPref = 1 / R SUM_r(1- |n ranked higher than r| / min(R, N))
  
          m = metrics_lib.make_ranking_metric_fn(
              metrics_lib.RankingMetricKey.BPREF
          )
          m_w = metrics_lib.make_ranking_metric_fn(
              metrics_lib.RankingMetricKey.BPREF,
              weights_feature_name=weights_feature_name,
          )
          m_2 = metrics_lib.make_ranking_metric_fn(
              metrics_lib.RankingMetricKey.BPREF, topn=1
          )
          m_alt = metrics_lib.make_ranking_metric_fn(
              metrics_lib.RankingMetricKey.BPREF, use_trec_version=False
          )
          self._check_metrics(
              [
                  (
                      m([labels[0]], [scores[0]], features),
                      1.0 / 2.0 * (1.0 - 1.0 / 1.0),
                  ),  # = 0.
                  (
                      m(labels, scores, features),
                      (
                          1.0 / 2.0 * (1.0 - 1.0 / 1.0)
                          + (
                              1.0
                              / 2.0
                              * ((1.0 - 0.0 / 1.0) + (1.0 - 1.0 / 1.0))
                          )
                      )
                      / 2,
                  ),  # = 0.25
                  (
                      m_w(labels, scores, features),
                      (
                          3.0 * (1.0 / 2.0 * (1.0 - 1.0 / 1.0))
                          + 5.0
                          * (
                              1.0
                              / 2.0
                              * ((1.0 - 0.0 / 1.0) + (1.0 - 1.0 / 1.0))
                          )
                      )
                      / (3.0 + 5.0),
                  ),
                  (
                      m_2(labels, scores, features),
                      (0.0 + (1.0 / 2.0 * (1.0 - 0.0 / 1.0))) / 2.0,
                  ),
                  (
                      m_alt(labels, scores, features),
                      (
                          1.0 / 2.0 * (1.0 - 1.0 / 1.0)
                          + (
                              1.0
                              / 2.0
                              * ((1.0 - 0.0 / 2.0) + (1.0 - 1.0 / 2.0))
                          )
                      )
                      / 2,
                  ),  # = 0.5
              ]
          )
  
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 15 for calling the MetricsTest obj's underlying member method code with example usage: obj.test_make_bpref_fn() without return types