Skip to content

Commit c0eafb5

Browse files
committed
Workaround an issue where the TensorPrimitives net8 tests are not running on net8
1 parent 61a327b commit c0eafb5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libraries/System.Numerics.Tensors/tests/TensorPrimitives.Generic.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,17 @@ public static IEnumerable<object[]> SpanDestinationFunctionsToTest()
386386
yield return Create(TensorPrimitives.Reciprocal, f => T.One / f);
387387
yield return Create(TensorPrimitives.ReciprocalEstimate, T.ReciprocalEstimate, T.CreateTruncating(Helpers.DefaultToleranceForEstimates));
388388
yield return Create(TensorPrimitives.ReciprocalSqrt, f => T.One / T.Sqrt(f));
389-
yield return Create(TensorPrimitives.ReciprocalSqrtEstimate, T.ReciprocalSqrtEstimate, T.CreateTruncating(Helpers.DefaultToleranceForEstimates));
389+
390+
ReadOnlySpan<float> src = [-float.Epsilon];
391+
Span<float> dst = stackalloc float[1];
392+
TensorPrimitives.ReciprocalSqrtEstimate(src, dst);
393+
394+
if (Helpers.IsEqualWithTolerance(float.ReciprocalSqrtEstimate(src[0]), dst[0], (float)Helpers.DefaultToleranceForEstimates))
395+
{
396+
// We need to ensure the state is consistent to avoid an issue with roll forward: https://github.com/dotnet/runtime/issues/101846
397+
yield return Create(TensorPrimitives.ReciprocalSqrtEstimate, T.ReciprocalSqrtEstimate, T.CreateTruncating(Helpers.DefaultToleranceForEstimates));
398+
}
399+
390400
yield return Create(TensorPrimitives.Round, T.Round);
391401
yield return Create(TensorPrimitives.Sin, T.Sin, trigTolerance);
392402
yield return Create(TensorPrimitives.Sinh, T.Sinh, Helpers.DetermineTolerance<T>(doubleTolerance: 1e-14));

0 commit comments

Comments
 (0)