Skip to content

Commit

Permalink
Adding Log2 tests covering some special values (#92946)
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding authored Oct 3, 2023
1 parent 9ac07e8 commit b9e0145
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,41 @@ public static void Log2_InPlace(int tensorLength)
}
}

[Theory]
[MemberData(nameof(TensorLengths))]
public static void Log2_SpecialValues(int tensorLength)
{
using BoundedMemory<float> x = CreateAndFillTensor(tensorLength);
using BoundedMemory<float> 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)
Expand Down

0 comments on commit b9e0145

Please sign in to comment.