Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public static void ResizeTo<T>(scoped in System.Numerics.Tensors.Tensor<T> tenso
public static ref readonly System.Numerics.Tensors.TensorSpan<T> StackAlongDimension<T>(scoped System.ReadOnlySpan<System.Numerics.Tensors.Tensor<T>> tensors, in System.Numerics.Tensors.TensorSpan<T> destination, int dimension) { throw null; }
public static System.Numerics.Tensors.Tensor<T> Stack<T>(params scoped System.ReadOnlySpan<System.Numerics.Tensors.Tensor<T>> tensors) { throw null; }
public static ref readonly System.Numerics.Tensors.TensorSpan<T> Stack<T>(scoped in System.ReadOnlySpan<System.Numerics.Tensors.Tensor<T>> tensors, in System.Numerics.Tensors.TensorSpan<T> destination) { throw null; }
public static T StdDev<T>(in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x) where T : System.Numerics.IFloatingPoint<T>, System.Numerics.IPowerFunctions<T>, System.Numerics.IAdditionOperators<T, T, T>, System.Numerics.IAdditiveIdentity<T, T> { throw null; }
public static T StdDev<T>(in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x) where T : System.Numerics.IFloatingPoint<T>, System.Numerics.IPowerFunctions<T>, System.Numerics.IAdditionOperators<T, T, T>, System.Numerics.IAdditiveIdentity<T, T>, System.Numerics.IRootFunctions<T> { throw null; }
public static System.Numerics.Tensors.Tensor<T> Subtract<T>(in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x, in System.Numerics.Tensors.ReadOnlyTensorSpan<T> y) where T : System.Numerics.ISubtractionOperators<T, T, T> { throw null; }
public static ref readonly System.Numerics.Tensors.TensorSpan<T> Subtract<T>(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x, scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> y, in System.Numerics.Tensors.TensorSpan<T> destination) where T : System.Numerics.ISubtractionOperators<T, T, T> { throw null; }
public static System.Numerics.Tensors.Tensor<T> Subtract<T>(in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x, T y) where T : System.Numerics.ISubtractionOperators<T, T, T> { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3512,7 +3512,7 @@ public static ref readonly TensorSpan<T> StackAlongDimension<T>(scoped ReadOnlyS
/// <param name="x">The <see cref="TensorSpan{T}"/> to take the standard deviation of.</param>
/// <returns><typeparamref name="T"/> representing the standard deviation.</returns>
public static T StdDev<T>(in ReadOnlyTensorSpan<T> x)
where T : IFloatingPoint<T>, IPowerFunctions<T>, IAdditionOperators<T, T, T>, IAdditiveIdentity<T, T>
where T : IFloatingPoint<T>, IPowerFunctions<T>, IAdditionOperators<T, T, T>, IAdditiveIdentity<T, T>, IRootFunctions<T>
{
T mean = Average(x);
Span<T> span = MemoryMarshal.CreateSpan(ref x._reference, (int)x._shape._memoryLength);
Expand All @@ -3522,16 +3522,7 @@ public static T StdDev<T>(in ReadOnlyTensorSpan<T> x)
TensorPrimitives.Pow((ReadOnlySpan<T>)output, T.CreateChecked(2), output);
T sum = TensorPrimitives.Sum((ReadOnlySpan<T>)output);
T variance = sum / T.CreateChecked(x._shape._memoryLength);

if (typeof(T) == typeof(float))
{
return T.CreateChecked(MathF.Sqrt(float.CreateChecked(variance)));
}
if (typeof(T) == typeof(double))
{
return T.CreateChecked(Math.Sqrt(double.CreateChecked(variance)));
}
return T.Pow(variance, T.CreateChecked(0.5));
return T.Sqrt(variance);
}
#endregion

Expand Down
Loading