From 9317328dc86a7e2f46325700dd805f1605732f37 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Tue, 3 Oct 2023 10:05:19 -0700 Subject: [PATCH] Adding Log2 tests covering some special values --- .../tests/TensorPrimitivesTests.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/libraries/System.Numerics.Tensors/tests/TensorPrimitivesTests.cs b/src/libraries/System.Numerics.Tensors/tests/TensorPrimitivesTests.cs index 137f2fd9070de..20a07f297566c 100644 --- a/src/libraries/System.Numerics.Tensors/tests/TensorPrimitivesTests.cs +++ b/src/libraries/System.Numerics.Tensors/tests/TensorPrimitivesTests.cs @@ -1056,6 +1056,41 @@ public static void Log2_InPlace(int tensorLength) } } + [Theory] + [MemberData(nameof(TensorLengths))] + public static void Log2_SpecialValues(int tensorLength) + { + using BoundedMemory x = CreateAndFillTensor(tensorLength); + using BoundedMemory destination = CreateTensor(tensorLength); + + // NaN + x[s_random.Next(x.Length)] = float.NaN; + + // +Infinity + x[s_random.Next(x.Length)] = float.PositiveInfinity; + + // -Infinity + x[s_random.Next(x.Length)] = float.NegativeInfinity; + + // +Zero + x[s_random.Next(x.Length)] = +0.0f; + + // -Zero + x[s_random.Next(x.Length)] = -0.0f; + + // +Epsilon + x[s_random.Next(x.Length)] = +float.Epsilon; + + // -Epsilon + x[s_random.Next(x.Length)] = -float.Epsilon; + + TensorPrimitives.Log2(x, destination); + for (int i = 0; i < tensorLength; i++) + { + Assert.Equal(MathF.Log(x[i], 2), destination[i], Tolerance); + } + } + [Theory] [MemberData(nameof(TensorLengths))] public static void Log2_ThrowsForTooShortDestination(int tensorLength)