Improve the numerical stability of cosine similarity #134
Labels
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
Related: pytorch/pytorch#31378
Current implementation:
pytorch_cluster/csrc/cuda/knn_cuda.cu
Line 56 in dbcafbe
As introduced in the linked PR for PyTorch, normalizing the vectors first and then doing the inner product could prevent overflow for vectors with large norms. In addition, this could ensure the calculated cosine similarity is within the range
[-1, +1]
.The text was updated successfully, but these errors were encountered: