import tensorflow as tf

    if pairwise_reduction == common.DISTANCE_REDUCTION_NEG_LOG_MEAN:
      return lambda x: -tf.math.log(tf.math.reduce_mean(x, axis=[-2, -1]))

    if pairwise_reduction == common.DISTANCE_REDUCTION_LOWER_HALF_NEG_LOG_MEAN:

      def compute_lower_half_negative_log_mean(x):
        return -tf.math.log(
            data_utils.compute_lower_percentile_means(x, axis=[-2, -1], q=50))

      return compute_lower_half_negative_log_mean

    if pairwise_reduction == common.DISTANCE_REDUCTION_ONE_MINUS_MEAN:
      return lambda x: 1.0 - tf.math.reduce_mean(x, axis=[-2, -1])

    return pairwise_reduction

  def get_componentwise_distance_reduction_fn():
    """Selects component-wise distance reduction function."""
    if componentwise_reduction == common.DISTANCE_REDUCTION_MEAN:
      return functools.partial(tf.math.reduce_mean, axis=[-1])

    return componentwise_reduction

  def sample_distance_fn(lhs, rhs):
