Skip to content

Commit 67036d0

Browse files
committed
Merge remote-tracking branch 'origin/main' into avoid_boxing_for_vbuffer_column
2 parents f0ac954 + 766569b commit 67036d0

23 files changed

+8252
-5707
lines changed

src/Microsoft.Data.Analysis/BitUtility.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@ public static void SetBits(Span<byte> data, long index, long length, bool value)
137137
}
138138
}
139139

140-
public static void ElementwiseAnd(ReadOnlySpan<byte> left, ReadOnlySpan<byte> right, Span<byte> result)
141-
{
142-
for (var i = 0; i < left.Length; i++)
143-
result[i] = (byte)(left[i] & right[i]);
144-
}
145-
146140
/// <summary>
147141
/// Returns the population count (number of bits set) in a span of bytes starting
148142
/// at 0 bit and limiting to length of bits.
@@ -167,7 +161,7 @@ public static long GetBitCount(ReadOnlySpan<byte> span, long length)
167161
var partialByte = span[endByteIndex];
168162
for (var j = 0; j < endBitOffset; j++)
169163
{
170-
count += GetBit(partialByte, j) ? 0 : 1;
164+
count += GetBit(partialByte, j) ? 1 : 0;
171165
}
172166
}
173167

src/Microsoft.Data.Analysis/ColumnArithmetic.OperationEnums.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ internal enum BinaryOperation
1818
Xor,
1919
}
2020

21-
internal enum BinaryScalarOperation
22-
{
23-
Add,
24-
Subtract,
25-
Multiply,
26-
Divide,
27-
Modulo,
28-
And,
29-
Or,
30-
Xor,
31-
}
32-
3321
internal enum BinaryIntOperation
3422
{
3523
LeftShift,
@@ -45,14 +33,4 @@ internal enum ComparisonOperation
4533
ElementwiseGreaterThan,
4634
ElementwiseLessThan,
4735
}
48-
49-
internal enum ComparisonScalarOperation
50-
{
51-
ElementwiseEquals,
52-
ElementwiseNotEquals,
53-
ElementwiseGreaterThanOrEqual,
54-
ElementwiseLessThanOrEqual,
55-
ElementwiseGreaterThan,
56-
ElementwiseLessThan,
57-
}
5836
}

src/Microsoft.Data.Analysis/ColumnArithmetic.OperationEnums.tt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ namespace Microsoft.Data.Analysis
2121
<# } #>
2222
}
2323

24-
internal enum BinaryScalarOperation
25-
{
26-
<# foreach (MethodConfiguration method in methodConfiguration) { #>
27-
<# if (method.MethodType == MethodType.BinaryScalar) { #>
28-
<#=method.MethodName#>,
29-
<# } #>
30-
<# } #>
31-
}
32-
3324
internal enum BinaryIntOperation
3425
{
3526
<# foreach (MethodConfiguration method in methodConfiguration) { #>
@@ -45,15 +36,6 @@ namespace Microsoft.Data.Analysis
4536
<# if (method.MethodType == MethodType.Comparison) { #>
4637
<#=method.MethodName#>,
4738
<# } #>
48-
<# } #>
49-
}
50-
51-
internal enum ComparisonScalarOperation
52-
{
53-
<# foreach (MethodConfiguration method in methodConfiguration) { #>
54-
<# if (method.MethodType == MethodType.ComparisonScalar) { #>
55-
<#=method.MethodName#>,
56-
<# } #>
5739
<# } #>
5840
}
5941
}

src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
<#+
77
public class TypeConfiguration
88
{
9-
public TypeConfiguration(string typeName, string classPrefix = null, string oneLiteral = "1", string zeroLiteral = "0", bool supportsNumeric = true, bool supportsBitwise = true, IEnumerable<string> unsupportedMethods = null)
9+
public TypeConfiguration(string typeName, string classPrefix = null, string oneLiteral = "1", string zeroLiteral = "0", bool supportsNumeric = true, bool supportsBitwise = true, IEnumerable<string> unsupportedMethods = null, bool supportsVectorization = false)
1010
{
1111
TypeName = typeName;
1212
ClassPrefix = classPrefix ?? char.ToUpper(typeName[0]) + typeName.Substring(1);
1313
OneLiteral = oneLiteral;
1414
ZeroLiteral = zeroLiteral;
1515
SupportsNumeric = supportsNumeric;
1616
SupportsBitwise = supportsBitwise;
17+
SupportsVectorization = supportsVectorization;
1718
UnsupportedMethods = new HashSet<string>(unsupportedMethods ?? Enumerable.Empty<string>());
1819
}
1920

@@ -24,14 +25,11 @@
2425

2526
public bool SupportsNumeric { get; }
2627
public bool SupportsBitwise { get; }
27-
public ISet<string> UnsupportedMethods { get; }
28-
}
28+
public bool SupportsVectorization { get; }
2929

30-
public string GenerateInPlaceStatement(string trueCondition, string falseCondition)
31-
{
32-
return $"inPlace ? {trueCondition} : {falseCondition}";
30+
public ISet<string> UnsupportedMethods { get; }
3331
}
34-
32+
3533
public string GenerateIfStatementHeader(TypeConfiguration type)
3634
{
3735
string keyword = (type == typeConfiguration[0]) ? "if" : "else if";
@@ -139,18 +137,18 @@
139137
public TypeConfiguration[] typeConfiguration = new []
140138
{
141139
new TypeConfiguration("bool", oneLiteral:"true", zeroLiteral:"false", supportsNumeric: false, unsupportedMethods: new[] {"LeftShift", "RightShift"}),
142-
new TypeConfiguration("byte", unsupportedMethods: new[] {"All", "Any"}),
143-
new TypeConfiguration("char", oneLiteral:"(char)1", zeroLiteral:"(char)0", unsupportedMethods: new[] {"All", "Any"}),
140+
new TypeConfiguration("byte", unsupportedMethods: new[] {"All", "Any"}, supportsVectorization: true),
141+
new TypeConfiguration("char", oneLiteral:"(char)1", zeroLiteral:"(char)0", unsupportedMethods: new[] {"All", "Any"}, supportsVectorization: true),
144142
new TypeConfiguration("decimal", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}),
145-
new TypeConfiguration("double", oneLiteral:"1.0", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}),
146-
new TypeConfiguration("float", oneLiteral:"1.0f", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}),
147-
new TypeConfiguration("int", unsupportedMethods: new[] {"All", "Any"}),
148-
new TypeConfiguration("long", unsupportedMethods: new[] {"All", "Any"}),
149-
new TypeConfiguration("sbyte", classPrefix:"SByte", unsupportedMethods: new[] {"All", "Any"}),
150-
new TypeConfiguration("short", unsupportedMethods: new[] {"All", "Any"}),
151-
new TypeConfiguration("uint", classPrefix:"UInt", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}),
152-
new TypeConfiguration("ulong", classPrefix:"ULong", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}),
153-
new TypeConfiguration("ushort", classPrefix:"UShort", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}),
143+
new TypeConfiguration("double", oneLiteral:"1.0", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}, supportsVectorization: true),
144+
new TypeConfiguration("float", oneLiteral:"1.0f", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}, supportsVectorization: true),
145+
new TypeConfiguration("int", unsupportedMethods: new[] {"All", "Any"}, supportsVectorization: true),
146+
new TypeConfiguration("long", unsupportedMethods: new[] {"All", "Any"}, supportsVectorization: true),
147+
new TypeConfiguration("sbyte", classPrefix:"SByte", unsupportedMethods: new[] {"All", "Any"}, supportsVectorization: true),
148+
new TypeConfiguration("short", unsupportedMethods: new[] {"All", "Any"}, supportsVectorization: true),
149+
new TypeConfiguration("uint", classPrefix:"UInt", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}, supportsVectorization: true),
150+
new TypeConfiguration("ulong", classPrefix:"ULong", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}, supportsVectorization: true),
151+
new TypeConfiguration("ushort", classPrefix:"UShort", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}, supportsVectorization: true),
154152
new TypeConfiguration("DateTime", supportsBitwise: false, supportsNumeric: false, unsupportedMethods: new[] {"And", "Or", "Xor"})
155153
};
156154

@@ -227,16 +225,16 @@
227225
new MethodConfiguration("Sum", MethodType.Reduction, "+", isNumeric:true, hasReturnValue:true, supportsRowSubsets: true, methodComments: "Returns the sum of the values at the rowIndices"),
228226
new MethodConfiguration("Round", MethodType.ElementwiseComputation, "Math.Round", isNumeric:true, methodComments: "Calls Math.Round on each value in a column"),
229227
};
230-
228+
231229
public MethodConfiguration[] methodConfiguration = new []
232230
{
233-
new MethodConfiguration("Add", MethodType.Binary, "+", isNumeric:true, methodComments: "Performs element-wise addition"),
231+
new MethodConfiguration("Add", MethodType.Binary, "+", isNumeric:true, methodComments: "Performs element-wise addition", supportsVectorization: true),
234232
new MethodConfiguration("Add", MethodType.BinaryScalar, "+", isNumeric:true, methodComments: "Performs an element-wise addition on each column"),
235-
new MethodConfiguration("Subtract", MethodType.Binary, "-", isNumeric:true, methodComments: "Performs element-wise subtraction"),
233+
new MethodConfiguration("Subtract", MethodType.Binary, "-", isNumeric:true, methodComments: "Performs element-wise subtraction", supportsVectorization: true),
236234
new MethodConfiguration("Subtract", MethodType.BinaryScalar, "-", isNumeric:true, methodComments: "Performs an element-wise subtraction on each column"),
237-
new MethodConfiguration("Multiply", MethodType.Binary, "*", isNumeric:true, methodComments: "Performs element-wise multiplication"), // element-wise product, not matrix product
235+
new MethodConfiguration("Multiply", MethodType.Binary, "*", isNumeric:true, methodComments: "Performs element-wise multiplication", supportsVectorization: true),
238236
new MethodConfiguration("Multiply", MethodType.BinaryScalar, "*", isNumeric:true, methodComments: "Performs an element-wise multiplication on each column"),
239-
new MethodConfiguration("Divide", MethodType.Binary, "/", isNumeric:true, methodComments: "Performs element-wise division"),
237+
new MethodConfiguration("Divide", MethodType.Binary, "/", isNumeric:true, methodComments: "Performs element-wise division", supportsVectorization: true),
240238
new MethodConfiguration("Divide", MethodType.BinaryScalar, "/", isNumeric:true, methodComments: "Performs an element-wise division on each column"),
241239
new MethodConfiguration("Modulo", MethodType.Binary, "%", isNumeric:true, methodComments: "Performs element-wise modulus"),
242240
new MethodConfiguration("Modulo", MethodType.BinaryScalar, "%", isNumeric:true, methodComments: "Performs an element-wise modulus operation on each column"),
@@ -265,7 +263,7 @@
265263

266264
public class MethodConfiguration
267265
{
268-
public MethodConfiguration(string methodName, MethodType methodType, string op = null, bool isNumeric = false, bool isBitwise = false, bool hasReturnValue = false, bool supportsRowSubsets = false, string methodComments = null)
266+
public MethodConfiguration(string methodName, MethodType methodType, string op = null, bool isNumeric = false, bool isBitwise = false, bool hasReturnValue = false, bool supportsRowSubsets = false, string methodComments = null, bool supportsVectorization = false)
269267
{
270268
MethodName = methodName;
271269
MethodType = methodType;
@@ -275,6 +273,7 @@
275273
HasReturnValue = hasReturnValue;
276274
SupportsRowSubsets = supportsRowSubsets;
277275
MethodComments = methodComments;
276+
SupportsVectorization = supportsVectorization;
278277
}
279278

280279
public string ResultName => "result";
@@ -330,7 +329,7 @@
330329
public MethodType MethodType { get; }
331330
public string Operator { get; }
332331
public string MethodComments { get; }
333-
332+
public bool SupportsVectorization { get; }
334333
public string GetColumnSpecificMethodComments()
335334
{
336335
var str = MethodComments;

0 commit comments

Comments
 (0)