Skip to content

Commit b9e0145

Browse files
Adding Log2 tests covering some special values (#92946)
1 parent 9ac07e8 commit b9e0145

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/libraries/System.Numerics.Tensors/tests/TensorPrimitivesTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,41 @@ public static void Log2_InPlace(int tensorLength)
10561056
}
10571057
}
10581058

1059+
[Theory]
1060+
[MemberData(nameof(TensorLengths))]
1061+
public static void Log2_SpecialValues(int tensorLength)
1062+
{
1063+
using BoundedMemory<float> x = CreateAndFillTensor(tensorLength);
1064+
using BoundedMemory<float> destination = CreateTensor(tensorLength);
1065+
1066+
// NaN
1067+
x[s_random.Next(x.Length)] = float.NaN;
1068+
1069+
// +Infinity
1070+
x[s_random.Next(x.Length)] = float.PositiveInfinity;
1071+
1072+
// -Infinity
1073+
x[s_random.Next(x.Length)] = float.NegativeInfinity;
1074+
1075+
// +Zero
1076+
x[s_random.Next(x.Length)] = +0.0f;
1077+
1078+
// -Zero
1079+
x[s_random.Next(x.Length)] = -0.0f;
1080+
1081+
// +Epsilon
1082+
x[s_random.Next(x.Length)] = +float.Epsilon;
1083+
1084+
// -Epsilon
1085+
x[s_random.Next(x.Length)] = -float.Epsilon;
1086+
1087+
TensorPrimitives.Log2(x, destination);
1088+
for (int i = 0; i < tensorLength; i++)
1089+
{
1090+
Assert.Equal(MathF.Log(x[i], 2), destination[i], Tolerance);
1091+
}
1092+
}
1093+
10591094
[Theory]
10601095
[MemberData(nameof(TensorLengths))]
10611096
public static void Log2_ThrowsForTooShortDestination(int tensorLength)

0 commit comments

Comments
 (0)