From a53c66df5660344d3a090d45bf170bce2635b362 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sun, 24 Sep 2023 23:03:02 -0400 Subject: [PATCH] Reduce some boilerplate in TensorPrimitive's IBinaryOperator Change a few of the static abstract interface methods to be virtual, as most implementations throw from these methods; we can consolidate that throwing to the base. --- .../Tensors/TensorPrimitives.netcore.cs | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netcore.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netcore.cs index 0eaa0681036eb1..085419207b6c08 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netcore.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netcore.cs @@ -1099,12 +1099,6 @@ private static Vector512 FusedMultiplyAdd(Vector512 x, Vector512 Invoke(Vector512 x, Vector512 y) => x - y; #endif - - public static float Invoke(Vector128 x) => throw new NotSupportedException(); - public static float Invoke(Vector256 x) => throw new NotSupportedException(); -#if NET8_0_OR_GREATER - public static float Invoke(Vector512 x) => throw new NotSupportedException(); -#endif } private readonly struct SubtractSquaredOperator : IBinaryOperator @@ -1134,12 +1128,6 @@ public static Vector512 Invoke(Vector512 x, Vector512 y) return tmp * tmp; } #endif - - public static float Invoke(Vector128 x) => throw new NotSupportedException(); - public static float Invoke(Vector256 x) => throw new NotSupportedException(); -#if NET8_0_OR_GREATER - public static float Invoke(Vector512 x) => throw new NotSupportedException(); -#endif } private readonly struct MultiplyOperator : IBinaryOperator @@ -1195,12 +1183,6 @@ public static float Invoke(Vector512 x) #if NET8_0_OR_GREATER public static Vector512 Invoke(Vector512 x, Vector512 y) => x / y; #endif - - public static float Invoke(Vector128 x) => throw new NotSupportedException(); - public static float Invoke(Vector256 x) => throw new NotSupportedException(); -#if NET8_0_OR_GREATER - public static float Invoke(Vector512 x) => throw new NotSupportedException(); -#endif } private readonly struct NegateOperator : IUnaryOperator @@ -1294,14 +1276,18 @@ private interface IUnaryOperator private interface IBinaryOperator { static abstract float Invoke(float x, float y); - static abstract Vector128 Invoke(Vector128 x, Vector128 y); - static abstract float Invoke(Vector128 x); static abstract Vector256 Invoke(Vector256 x, Vector256 y); - static abstract float Invoke(Vector256 x); #if NET8_0_OR_GREATER static abstract Vector512 Invoke(Vector512 x, Vector512 y); - static abstract float Invoke(Vector512 x); +#endif + + // Operations for aggregating all lanes in a vector into a single value. + // These are not supported on most implementations. + static virtual float Invoke(Vector128 x) => throw new NotSupportedException(); + static virtual float Invoke(Vector256 x) => throw new NotSupportedException(); +#if NET8_0_OR_GREATER + static virtual float Invoke(Vector512 x) => throw new NotSupportedException(); #endif }