latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.nn.functional.cosine_similarity
- tensorplay.nn.functional.cosine_similarity(x1: Tensor, x2: Tensor, dim: int = 1, eps: float = 1e-08) Tensor[source]
Returns cosine similarity between x1 and x2, computed along dim.
The inputs are normalized before the dot product, and the per-row norms are accumulated in a wider dtype (float32 for half-precision inputs, float64 for float32), so that squaring large values cannot overflow the accumulator and turn the result into NaN.
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

