Skip to content

Commit 3f246e3

Browse files
stephentoubmichaelgsharp
authored andcommitted
Reduce some boilerplate in TensorPrimitive's IBinaryOperator (dotnet#92576)
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.
1 parent 4afeb64 commit 3f246e3

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,6 @@ private static Vector512<float> FusedMultiplyAdd(Vector512<float> x, Vector512<f
10991099
#if NET8_0_OR_GREATER
11001100
public static Vector512<float> Invoke(Vector512<float> x, Vector512<float> y) => x - y;
11011101
#endif
1102-
1103-
public static float Invoke(Vector128<float> x) => throw new NotSupportedException();
1104-
public static float Invoke(Vector256<float> x) => throw new NotSupportedException();
1105-
#if NET8_0_OR_GREATER
1106-
public static float Invoke(Vector512<float> x) => throw new NotSupportedException();
1107-
#endif
11081102
}
11091103

11101104
private readonly struct SubtractSquaredOperator : IBinaryOperator
@@ -1134,12 +1128,6 @@ public static Vector512<float> Invoke(Vector512<float> x, Vector512<float> y)
11341128
return tmp * tmp;
11351129
}
11361130
#endif
1137-
1138-
public static float Invoke(Vector128<float> x) => throw new NotSupportedException();
1139-
public static float Invoke(Vector256<float> x) => throw new NotSupportedException();
1140-
#if NET8_0_OR_GREATER
1141-
public static float Invoke(Vector512<float> x) => throw new NotSupportedException();
1142-
#endif
11431131
}
11441132

11451133
private readonly struct MultiplyOperator : IBinaryOperator
@@ -1195,12 +1183,6 @@ public static float Invoke(Vector512<float> x)
11951183
#if NET8_0_OR_GREATER
11961184
public static Vector512<float> Invoke(Vector512<float> x, Vector512<float> y) => x / y;
11971185
#endif
1198-
1199-
public static float Invoke(Vector128<float> x) => throw new NotSupportedException();
1200-
public static float Invoke(Vector256<float> x) => throw new NotSupportedException();
1201-
#if NET8_0_OR_GREATER
1202-
public static float Invoke(Vector512<float> x) => throw new NotSupportedException();
1203-
#endif
12041186
}
12051187

12061188
private readonly struct NegateOperator : IUnaryOperator
@@ -1276,14 +1258,18 @@ private interface IUnaryOperator
12761258
private interface IBinaryOperator
12771259
{
12781260
static abstract float Invoke(float x, float y);
1279-
12801261
static abstract Vector128<float> Invoke(Vector128<float> x, Vector128<float> y);
1281-
static abstract float Invoke(Vector128<float> x);
12821262
static abstract Vector256<float> Invoke(Vector256<float> x, Vector256<float> y);
1283-
static abstract float Invoke(Vector256<float> x);
12841263
#if NET8_0_OR_GREATER
12851264
static abstract Vector512<float> Invoke(Vector512<float> x, Vector512<float> y);
1286-
static abstract float Invoke(Vector512<float> x);
1265+
#endif
1266+
1267+
// Operations for aggregating all lanes in a vector into a single value.
1268+
// These are not supported on most implementations.
1269+
static virtual float Invoke(Vector128<float> x) => throw new NotSupportedException();
1270+
static virtual float Invoke(Vector256<float> x) => throw new NotSupportedException();
1271+
#if NET8_0_OR_GREATER
1272+
static virtual float Invoke(Vector512<float> x) => throw new NotSupportedException();
12871273
#endif
12881274
}
12891275

0 commit comments

Comments
 (0)