Function cosine_similarity
pub fn cosine_similarity<B, const D: usize>(
x1: Tensor<B, D>,
x2: Tensor<B, D>,
dim: i32,
eps: Option<<B as Backend>::FloatElem>,
) -> Tensor<B, D>where
B: Backend,
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 indices allowed: -1 for last dimension)eps
- Small value to avoid division by zero (default: 1e-8)
§Returns
Tensor containing the cosine similarity between x1 and x2