diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Single.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Single.cs index 9e3a2944c49820..2a3842ebd05f11 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Single.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Single.cs @@ -858,7 +858,7 @@ public static void SoftMax(ReadOnlySpan x, Span destination) InvokeSpanIntoSpan(x, destination); float expSum = Sum(destination); - InvokeSpanScalarIntoSpan(destination, expSum, destination); + InvokeSpanScalarIntoSpan(destination, 1f / expSum, destination); } /// Computes the element-wise difference between single-precision floating-point numbers in the specified tensors. diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.SoftMax.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.SoftMax.cs index af0e7be409654e..e25d39d30e86ed 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.SoftMax.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.SoftMax.cs @@ -38,7 +38,7 @@ public static void SoftMax(ReadOnlySpan x, Span destination) InvokeSpanIntoSpan>(x, destination); T expSum = Sum(destination); - InvokeSpanScalarIntoSpan>(destination, expSum, destination); + InvokeSpanScalarIntoSpan>(destination, T.One / expSum, destination); } } }