diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.cs index f9191108f1d67..a400095b08ad3 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.cs @@ -271,18 +271,7 @@ public static float CosineSimilarity(ReadOnlySpan x, ReadOnlySpan 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); } ///