Skip to content

Commit

Permalink
Revise a number of TP precision tolerances (#99831)
Browse files Browse the repository at this point in the history
* Revise tolerances

* Remove TODOs from methods with custom tolerances.
  • Loading branch information
eiriktsarpalis authored Mar 15, 2024
1 parent 4a69553 commit 0960bfb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,24 +363,17 @@ public static IEnumerable<object[]> SpanDestinationFunctionsToTest()
yield return Create(TensorPrimitives.Atanh, T.Atanh);
yield return Create(TensorPrimitives.AtanPi, T.AtanPi);
yield return Create(TensorPrimitives.Atan, T.Atan);
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Cbrt, T.Cbrt, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13));
yield return Create(TensorPrimitives.Ceiling, T.Ceiling);
yield return Create(TensorPrimitives.Cos, T.Cos, trigTolerance);
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Cosh, T.Cosh, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-14));
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.CosPi, T.CosPi, trigTolerance ?? Helpers.DetermineTolerance<T>(floatTolerance: 1e-5f));
yield return Create(TensorPrimitives.DegreesToRadians, T.DegreesToRadians);
yield return Create(TensorPrimitives.Exp, T.Exp);
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Exp2, T.Exp2, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-14, floatTolerance: 1e-5f));
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Exp10, T.Exp10, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13, floatTolerance: 1e-5f));
yield return Create(TensorPrimitives.ExpM1, T.ExpM1);
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Exp2M1, T.Exp2M1, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-14, floatTolerance: 1e-5f));
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Exp10M1, T.Exp10M1, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13, floatTolerance: 1e-5f));
yield return Create(TensorPrimitives.Floor, T.Floor);
yield return Create(TensorPrimitives.Log, T.Log);
Expand All @@ -396,9 +389,7 @@ public static IEnumerable<object[]> SpanDestinationFunctionsToTest()
yield return Create(TensorPrimitives.ReciprocalSqrtEstimate, T.ReciprocalSqrtEstimate, T.CreateTruncating(Helpers.DefaultToleranceForEstimates));
yield return Create(TensorPrimitives.Round, T.Round);
yield return Create(TensorPrimitives.Sin, T.Sin, trigTolerance);
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Sinh, T.Sinh, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-14));
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.SinPi, T.SinPi, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13, floatTolerance: 1e-4f));
yield return Create(TensorPrimitives.Sqrt, T.Sqrt);
yield return Create(TensorPrimitives.Tan, T.Tan, trigTolerance);
Expand Down Expand Up @@ -520,8 +511,7 @@ public static IEnumerable<object[]> SpanSpanDestinationFunctionsToTest()
yield return Create(TensorPrimitives.Hypot, T.Hypot);
yield return Create(TensorPrimitives.Ieee754Remainder, T.Ieee754Remainder);
yield return Create(TensorPrimitives.Log, T.Log);
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Pow, T.Pow, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13, floatTolerance: 1e-4f));
yield return Create(TensorPrimitives.Pow, T.Pow, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13, floatTolerance: 1e-5f));

static object[] Create(SpanSpanDestinationDelegate tensorPrimitivesMethod, Func<T, T, T> expectedMethod, T? tolerance = null)
=> new object[] { tensorPrimitivesMethod, expectedMethod, tolerance };
Expand Down Expand Up @@ -650,8 +640,7 @@ public static IEnumerable<object[]> SpanScalarDestinationFunctionsToTest()
yield return Create(TensorPrimitives.Atan2Pi, T.Atan2Pi);
yield return Create(TensorPrimitives.CopySign, T.CopySign);
yield return Create(TensorPrimitives.Ieee754Remainder, T.Ieee754Remainder);
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Pow, T.Pow, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13, floatTolerance: 1e-4f));
yield return Create(TensorPrimitives.Pow, T.Pow, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13, floatTolerance: 1e-5f));
yield return Create(TensorPrimitives.Log, T.Log);
yield return Create(TensorPrimitives.Max, T.Max);
yield return Create(TensorPrimitives.MaxMagnitude, T.MaxMagnitude);
Expand Down Expand Up @@ -755,8 +744,7 @@ public static IEnumerable<object[]> ScalarSpanFloatDestinationFunctionsToTest()
{
yield return Create(TensorPrimitives.Atan2, T.Atan2);
yield return Create(TensorPrimitives.Atan2Pi, T.Atan2Pi);
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.Pow, T.Pow, Helpers.DetermineTolerance<T>(floatTolerance: 1e-4f));
yield return Create(TensorPrimitives.Pow, T.Pow, Helpers.DetermineTolerance<T>(floatTolerance: 1e-5f));
yield return Create(TensorPrimitives.Ieee754Remainder, T.Ieee754Remainder);

static object[] Create(ScalarSpanDestinationDelegate tensorPrimitivesMethod, Func<T, T, T> expectedMethod, T? tolerance = null)
Expand Down Expand Up @@ -854,7 +842,6 @@ public void SpanScalarFloatDestination_ThrowsForOverlapppingInputsWithOutputs(Sc
#region Span,Int,Span -> Destination
public static IEnumerable<object[]> SpanIntDestinationFunctionsToTest()
{
// TODO https://github.com/dotnet/runtime/issues/98861
yield return Create(TensorPrimitives.RootN, T.RootN, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13));
yield return Create(TensorPrimitives.ScaleB, T.ScaleB);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ public void Cosh_ValueRange()
{
if (!IsFloatingPoint) return;

// TODO https://github.com/dotnet/runtime/issues/98861
T? tolerance = Helpers.DetermineTolerance<T>(doubleTolerance: 1e-14);

Assert.All(VectorLengthAndIteratedRange(ConvertFromSingle(-100f), ConvertFromSingle(100f), ConvertFromSingle(3f)), arg =>
Expand Down Expand Up @@ -955,8 +954,7 @@ public void Dot_ThrowsForMismatchedLengths_x_y()
[Fact]
public void Dot_AllLengths()
{
// TODO https://github.com/dotnet/runtime/issues/98861
T? tolerance = Helpers.DetermineTolerance<T>(doubleTolerance: 1e-14f, floatTolerance: 1e-3f);
T? tolerance = Helpers.DetermineTolerance<T>(doubleTolerance: 1e-14f, floatTolerance: 1e-5f);

Assert.All(Helpers.TensorLengthsIncluding0, tensorLength =>
{
Expand Down Expand Up @@ -2885,7 +2883,6 @@ public void Sinh_ValueRange()
{
if (!IsFloatingPoint) return;

// TODO https://github.com/dotnet/runtime/issues/98861
T? tolerance = Helpers.DetermineTolerance<T>(doubleTolerance: 1e-14);

Assert.All(VectorLengthAndIteratedRange(ConvertFromSingle(-100f), ConvertFromSingle(100f), ConvertFromSingle(3f)), args =>
Expand Down Expand Up @@ -3148,7 +3145,6 @@ public void Subtract_TensorScalar_ThrowsForOverlapppingInputsWithOutputs()
[Fact]
public void Sum_AllLengths()
{
// TODO https://github.com/dotnet/runtime/issues/98861
T? tolerance = Helpers.DetermineTolerance<T>(doubleTolerance: 1e-13, floatTolerance: 1e-5f);

Assert.All(Helpers.TensorLengths, tensorLength =>
Expand All @@ -3169,7 +3165,6 @@ public void Sum_AllLengths()
[Fact]
public void SumOfMagnitudes_AllLengths()
{
// TODO https://github.com/dotnet/runtime/issues/98861
T? tolerance = Helpers.DetermineTolerance<T>(doubleTolerance: 1e-12, floatTolerance: 1e-6f);

Assert.All(Helpers.TensorLengths, tensorLength =>
Expand All @@ -3191,7 +3186,6 @@ public void SumOfMagnitudes_AllLengths()
[Fact]
public void SumOfSquares_AllLengths()
{
// TODO https://github.com/dotnet/runtime/issues/98861
T? tolerance = Helpers.DetermineTolerance<T>(doubleTolerance: 1e-12, floatTolerance: 1e-6f);

Assert.All(Helpers.TensorLengths, tensorLength =>
Expand Down

0 comments on commit 0960bfb

Please sign in to comment.