def fits(A, B, temp, cos_distance):
    """Exponentiated pairwise distance between each element of A and
    all those of B.
    :param A: a matrix.
    :param B: a matrix.
    :param temp: Temperature
    :cos_distance: Boolean for using cosine or Euclidean distance.

    :returns: A tensor for the exponentiated pairwise distance between
    each element and A and all those of B.
    """
    if cos_distance:
      distance_matrix = SNNLCrossEntropy.pairwise_cos_distance(A, B)
    else:
      distance_matrix = SNNLCrossEntropy.pairwise_euclid_distance(A, B)
    return tf.exp(-(distance_matrix / temp))