def cosine_distance(f1, f2, cos_meas_max=2.0, cos_meas_min=1.0):
    """For all pairs of vectors f1' and f2' in f1 and f2, computes 1 - (f1.f2),
    where '.' is the dot product, and rescales the results to lie in the
    range [cos_meas_min, cos_meas_max].
    Corresponds to regular cosine distance if f1' and f2' are normalized and
    cos_meas_min==0.0 and cos_meas_max==1.0."""
    return (1 - f1.T @ f2) * (cos_meas_max - cos_meas_min) + cos_meas_min