Module
View source
distance.py
import goldener.distance
Distance functions between vectors used by the selection algorithms.
def
cosine_distance(x1: torch.Tensor, x2: torch.Tensor) -> torch.Tensor:
Computes cosine distance between each pair of the two collections of row vectors.
Arguments:
- x1: A tensor of shape (n, d) representing n vectors of dimension d.
- x2: A tensor of shape (m, d) representing m vectors of dimension d.
Returns:
A tensor of shape (n, m) where the entry at (i, j) is the cosine distance between x1[i] and x2[j].
Raises:
- ValueError: If
x1orx2is not a 2D tensor. - ValueError: If
x1andx2do not have the same number of channels (feature dimension).