Skip to content

Commit f106038

Browse files
committed
Disable TensorPrimitives vectorization of Log, Cbrt, Pow, and RootN
We had a test bug that was hiding cases where one of the expected / actual was NaN and the other wasn't.
1 parent 92ca5f3 commit f106038

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.Cbrt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void Cbrt<T>(ReadOnlySpan<T> x, Span<T> destination)
2626
private readonly struct CbrtOperator<T> : IUnaryOperator<T, T>
2727
where T : IRootFunctions<T>
2828
{
29-
public static bool Vectorizable => typeof(T) == typeof(float) || typeof(T) == typeof(double);
29+
public static bool Vectorizable => false; // typeof(T) == typeof(float) || typeof(T) == typeof(double); // TODO: https://github.com/dotnet/runtime/issues/100535
3030

3131
public static T Invoke(T x) => T.Cbrt(x);
3232

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.Log.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static Vector512<T> Invoke(Vector512<T> x)
161161
private readonly struct LogBaseOperator<T> : IBinaryOperator<T>
162162
where T : ILogarithmicFunctions<T>
163163
{
164-
public static bool Vectorizable => LogOperator<T>.Vectorizable;
164+
public static bool Vectorizable => false; //LogOperator<T>.Vectorizable; // TODO: https://github.com/dotnet/runtime/issues/100535
165165
public static T Invoke(T x, T y) => T.Log(x, y);
166166
public static Vector128<T> Invoke(Vector128<T> x, Vector128<T> y) => LogOperator<T>.Invoke(x) / LogOperator<T>.Invoke(y);
167167
public static Vector256<T> Invoke(Vector256<T> x, Vector256<T> y) => LogOperator<T>.Invoke(x) / LogOperator<T>.Invoke(y);

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.Pow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static void Pow<T>(T x, ReadOnlySpan<T> y, Span<T> destination)
5959
private readonly struct PowOperator<T> : IBinaryOperator<T>
6060
where T : IPowerFunctions<T>
6161
{
62-
public static bool Vectorizable => typeof(T) == typeof(float) || typeof(T) == typeof(double);
62+
public static bool Vectorizable => false; // typeof(T) == typeof(float) || typeof(T) == typeof(double); // TODO: https://github.com/dotnet/runtime/issues/100535
6363

6464
public static T Invoke(T x, T y) => T.Pow(x, y);
6565

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.RootN.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private readonly struct RootNOperator<T>(int n) : IStatefulUnaryOperator<T> wher
2828
{
2929
private readonly int _n = n;
3030

31-
public static bool Vectorizable => typeof(T) == typeof(float) || typeof(T) == typeof(double);
31+
public static bool Vectorizable => false; // typeof(T) == typeof(float) || typeof(T) == typeof(double); // TODO: https://github.com/dotnet/runtime/issues/100535
3232

3333
public T Invoke(T x) => T.RootN(x, _n);
3434

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ private static class DefaultTolerance<T> where T : unmanaged, INumber<T>
2828

2929
public static bool IsEqualWithTolerance<T>(T expected, T actual, T? tolerance = null) where T : unmanaged, INumber<T>
3030
{
31+
if (T.IsNaN(expected) != T.IsNaN(actual))
32+
{
33+
return false;
34+
}
35+
3136
tolerance = tolerance ?? DefaultTolerance<T>.Value;
3237
T diff = T.Abs(expected - actual);
3338
return !(diff > tolerance && diff > T.Max(T.Abs(expected), T.Abs(actual)) * tolerance);
3439
}
3540
#else
3641
public static bool IsEqualWithTolerance(float expected, float actual, float? tolerance = null)
3742
{
43+
if (float.IsNaN(expected) != float.IsNaN(actual))
44+
{
45+
return false;
46+
}
47+
3848
tolerance ??= DefaultFloatTolerance;
3949
float diff = MathF.Abs(expected - actual);
4050
return !(diff > tolerance && diff > MathF.Max(MathF.Abs(expected), MathF.Abs(actual)) * tolerance);

0 commit comments

Comments
 (0)