import tensorflow as tf

    indicators &= (
        anchor_match_mining_distance_matrix > anchor_positive_mining_distances)

  def find_hard_distances(distance_matrix, indicator_matrix):
    distance_matrix = tf.where(
        tf.stop_gradient(indicator_matrix), distance_matrix,
        tf.fill(tf.shape(distance_matrix), distance_matrix.dtype.max))
    hard_distances = tf.math.reduce_min(distance_matrix, axis=-1)
    return hard_distances

  hard_negative_mining_distances = find_hard_distances(
      anchor_match_mining_distance_matrix, indicators)
