Skip to content

Commit

Permalink
Fix TensorPrimitives.CosineSimilarity to use vectorized implementatio…
Browse files Browse the repository at this point in the history
…ns (#92204)
stephentoub authored Sep 18, 2023
1 parent d054157 commit 84ec7b4
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
@@ -271,18 +271,7 @@ public static float CosineSimilarity(ReadOnlySpan<float> x, ReadOnlySpan<float>
ThrowHelper.ThrowArgument_SpansMustHaveSameLength();
}

float dotprod = 0f;
float magx = 0f;
float magy = 0f;

for (int i = 0; i < x.Length; i++)
{
dotprod += x[i] * y[i];
magx += x[i] * x[i];
magy += y[i] * y[i];
}

return dotprod / (MathF.Sqrt(magx) * MathF.Sqrt(magy));
return CosineSimilarityCore(x, y);
}

/// <summary>

0 comments on commit 84ec7b4

Please sign in to comment.