Function cosine_similarity
pub fn cosine_similarity<const D: usize>(
x1: Tensor<D>,
x2: Tensor<D>,
dim: impl AsIndex,
eps: Option<f64>,
) -> Tensor<D>Expand description
Computes the cosine similarity between two tensors along a specified dimension.
Calculates the cosine of the angle between inputs as their dot product divided by the product of their L2 norms.
§Arguments
x1- First input tensorx2- Second input tensordim- Dimension along which to compute the similarity. Negative dimensions are supported and count from the end.eps- Small value to avoid division by zero (default: dtype’s smallest positive normal)
§Returns
Tensor containing the cosine similarity between x1 and x2