docstr: Helper function to test `loss_fn`.
code: def _check_pairwise_loss(
      self, loss_fn
  ):  # pylint: disable=g-unreachable-test-method
      """Helper function to test `loss_fn`."""
      scores = [[1.0, 3.0, 2.0], [1.0, 2.0, 3.0]]
      labels = [[0.0, 0.0, 1.0], [0.0, 0.0, 2.0]]
      listwise_weights = [[2.0], [1.0]]
      listwise_weights_expanded = [[2.0] * 3, [1.0] * 3]
      itemwise_weights = [[2.0, 3.0, 4.0], [1.0, 1.0, 1.0]]
      default_weights = [1.0] * 3
      list_size = 3.0
      loss_form_dict = {
          ranking_losses._pairwise_hinge_loss: ranking_losses.RankingLossKey.PAIRWISE_HINGE_LOSS,
          ranking_losses._pairwise_logistic_loss: ranking_losses.RankingLossKey.PAIRWISE_LOGISTIC_LOSS,
          ranking_losses._pairwise_soft_zero_one_loss: ranking_losses.RankingLossKey.PAIRWISE_SOFT_ZERO_ONE_LOSS,
      }
      loss_form = loss_form_dict[loss_fn]
      # Individual lists.
      self.assertAlmostEqual(
          loss_fn([labels[0]], [scores[0]]).numpy(),
          _batch_aggregation(
              [
                  _pairwise_loss(
                      labels[0], scores[0], default_weights, loss_form
                  )
              ]
          ),
          places=5,
      )
      self.assertAlmostEqual(
          loss_fn([labels[1]], [scores[1]]).numpy(),
          _batch_aggregation(
              [
                  _pairwise_loss(
                      labels[1], scores[1], default_weights, loss_form
                  )
              ]
          ),
          places=5,
      )
  
      # Itemwise weights.
      self.assertAlmostEqual(
          loss_fn(
              [labels[0]], [scores[0]], weights=[itemwise_weights[0]]
          ).numpy(),
          _batch_aggregation(
              [
                  _pairwise_loss(
                      labels[0],
                      scores[0],
                      itemwise_weights[0],
                      loss_form,
                  )
              ]
          ),
          places=5,
      )
  
      self.assertAlmostEqual(
          loss_fn(
              [labels[1]], [scores[1]], weights=[itemwise_weights[1]]
          ).numpy(),
          _batch_aggregation(
              [
                  _pairwise_loss(
                      labels[1],
                      scores[1],
                      itemwise_weights[1],
                      loss_form,
                  )
              ]
          ),
          places=5,
      )
  
      # Multiple lists.
      self.assertAlmostEqual(
          loss_fn(labels, scores, weights=listwise_weights).numpy(),
          _batch_aggregation(
              [
                  _pairwise_loss(
                      labels[0],
                      scores[0],
                      listwise_weights_expanded[0],
                      loss_form,
                  ),
                  _pairwise_loss(
                      labels[1],
                      scores[1],
                      listwise_weights_expanded[1],
                      loss_form,
                  ),
              ]
          ),
          places=5,
      )
  
      # Test LambdaWeight.
      lambda_weight = losses_impl.DCGLambdaWeight(
          rank_discount_fn=lambda r: 1.0 / tf.math.log1p(r),
          smooth_fraction=1.0,
      )
      self.assertAlmostEqual(
          loss_fn(
              labels,
              scores,
              weights=listwise_weights,
              lambda_weight=lambda_weight,
          ).numpy(),
          _batch_aggregation(
              [
                  _pairwise_loss(
                      labels[0],
                      scores[0],
                      listwise_weights_expanded[0],
                      loss_form,
                      rank_discount_form="LOG",
                  ),
                  _pairwise_loss(
                      labels[1],
                      scores[1],
                      listwise_weights_expanded[1],
                      loss_form,
                      rank_discount_form="LOG",
                  ),
              ]
          )
          * list_size,
          places=5,
      )
  
      # Test loss reduction method.
      # Two reduction methods should return different loss values.
      reduced_1 = loss_fn(
          labels, scores, reduction=tf.compat.v1.losses.Reduction.SUM
      ).numpy()
      reduced_2 = loss_fn(
          labels, scores, reduction=tf.compat.v1.losses.Reduction.MEAN
      ).numpy()
      self.assertNotAlmostEqual(reduced_1, reduced_2)
  
imports: import math
  import tensorflow
  from tensorflow_ranking.python import losses
  from tensorflow_ranking.python import losses_impl
label_desc: Use image node_id 1 for calling the LossesTest obj's underlying member method code with example usage: obj._check_pairwise_loss(loss_fn) without return types