Re:Embeddings: What they are and why they matter
by dist-epoch on Wednesday October 25, 2023 @06:54AM
(#38011445)
This code is written to be easy to understand. Otherwise you would replace it with some low-level SIMD code.
def cosine_similarity(a, b):
If you compare your cosines, you might as well compare their squares and avoid costly root computation.Similarly, in elliptic curve crypto certain expensive operations, such as inversion (x^-1 mod n) are delayed as much as possible down the computation pipeline or even avoided completely when you need to compare two points instead of computing their canonical values.