Module

distance.py

import goldener.distance
View source

Distance functions between vectors used by the selection algorithms.

On this page 1 function
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 x1 or x2 is not a 2D tensor.
  • ValueError: If x1 and x2 do not have the same number of channels (feature dimension).