From c42c1e2882a27c032f30c45c166e6731e4797ee1 Mon Sep 17 00:00:00 2001 From: Jake Radzikowski Date: Tue, 9 May 2023 23:48:28 -0700 Subject: [PATCH] Remove all TT files. --- .../ColumnArithmeticTemplate.ttinclude | 459 ------------- .../DataFrame.BinaryOperations.tt | 136 ---- .../DataFrame.BinaryOperators.tt | 52 -- .../DataFrameColumn.BinaryOperations.tt | 82 --- .../DataFrameColumn.BinaryOperators.tt | 67 -- .../DataFrameColumn.Computations.tt | 44 -- .../Microsoft.Data.Analysis.csproj | 111 +--- ...imitiveColumnContainer.BinaryOperations.tt | 56 -- ...ameColumn.BinaryOperations.Combinations.tt | 121 ---- ...mn.BinaryOperations.Combinations.ttinclude | 272 -------- ...imitiveDataFrameColumn.BinaryOperations.tt | 388 ----------- .../PrimitiveDataFrameColumn.Computations.tt | 69 -- ...ataFrameColumn.ReversedBinaryOperations.tt | 116 ---- .../DataFrameColumn.BinaryOperationTests.tt | 626 ------------------ .../Microsoft.Data.Analysis.Tests.csproj | 24 - ...imitiveDataFrameColumnComputationsTests.tt | 73 -- 16 files changed, 1 insertion(+), 2695 deletions(-) delete mode 100644 src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude delete mode 100644 src/Microsoft.Data.Analysis/DataFrame.BinaryOperations.tt delete mode 100644 src/Microsoft.Data.Analysis/DataFrame.BinaryOperators.tt delete mode 100644 src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt delete mode 100644 src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperators.tt delete mode 100644 src/Microsoft.Data.Analysis/DataFrameColumn.Computations.tt delete mode 100644 src/Microsoft.Data.Analysis/PrimitiveColumnContainer.BinaryOperations.tt delete mode 100644 src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.tt delete mode 100644 src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.ttinclude delete mode 100644 src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.tt delete mode 100644 src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.Computations.tt delete mode 100644 src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.tt delete mode 100644 test/Microsoft.Data.Analysis.Tests/DataFrameColumn.BinaryOperationTests.tt delete mode 100644 test/Microsoft.Data.Analysis.Tests/PrimitiveDataFrameColumnComputationsTests.tt diff --git a/src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude b/src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude deleted file mode 100644 index bb31da6a94..0000000000 --- a/src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude +++ /dev/null @@ -1,459 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#+ - public class TypeConfiguration - { - public TypeConfiguration(string typeName, string classPrefix = null, string oneLiteral = "1", string zeroLiteral = "0", bool supportsNumeric = true, bool supportsBitwise = true, IEnumerable unsupportedMethods = null) - { - TypeName = typeName; - ClassPrefix = classPrefix ?? char.ToUpper(typeName[0]) + typeName.Substring(1); - OneLiteral = oneLiteral; - ZeroLiteral = zeroLiteral; - SupportsNumeric = supportsNumeric; - SupportsBitwise = supportsBitwise; - UnsupportedMethods = new HashSet(unsupportedMethods ?? Enumerable.Empty()); - } - - public string TypeName { get; } - public string ClassPrefix { get; } - public string OneLiteral { get; } - public string ZeroLiteral { get; } - - public bool SupportsNumeric { get; } - public bool SupportsBitwise { get; } - public ISet UnsupportedMethods { get; } - } - - public string GenerateInPlaceStatement(string trueCondition, string falseCondition) - { - return $"inPlace ? {trueCondition} : {falseCondition}"; - } - - public string GenerateIfStatementHeader(TypeConfiguration type) - { - string keyword = (type == typeConfiguration[0]) ? "if" : "else if"; - return $"{keyword} (typeof(T) == typeof({type.TypeName}))"; - } - - // A way to discern implicit conversions. For ex: short has primitivitty 2. int has primitivitty 3. primitivitty(short) + primitivitty(int) > 2 * primitivitty(short) implying that a conversion has to take place - public Dictionary primitiveTypeToPrimitivityLevelMap = new Dictionary { - {"byte", 1}, - {"sbyte", 1}, - {"short", 2}, - {"ushort", 2}, - {"int", 3}, - {"uint", 3}, - {"long", 4}, - {"ulong", 4}, - {"float", 5}, - {"double", 6}, - {"decimal", 7} - }; - - public string GetCapitalizedPrimitiveTypes(string type) - { - string typeFirstCharUpper; - if (type.First() == 'u' || type == "sbyte") - { - typeFirstCharUpper = type[0].ToString().ToUpper() + type[1].ToString().ToUpper() + type.Substring(2); - } - else - { - typeFirstCharUpper = type[0].ToString().ToUpper() + type.Substring(1); - } - if (typeFirstCharUpper == "Bool") - { - return "Boolean"; - } - else if (typeFirstCharUpper == "Float") - { - return "Single"; - } - else if (typeFirstCharUpper == "Int") - { - return "Int32"; - } - else if (typeFirstCharUpper == "Short") - { - return "Int16"; - } - else if (typeFirstCharUpper == "Long") - { - return "Int64"; - } - else if (typeFirstCharUpper == "UInt") - { - return "UInt32"; - } - else if (typeFirstCharUpper == "UShort") - { - return "UInt16"; - } - else if (typeFirstCharUpper == "ULong") - { - return "UInt64"; - } - return typeFirstCharUpper; - } - - public bool IsMixedSignedAndUnsignedTypePair(string t1, string t2) - { - if (t1 == "byte" && t2 == "sbyte") - { - return true; - } - if (t2 == "byte" && t1 == "sbyte") - { - return true; - } - if (("u" + t1) == t2) - { - return true; - } - if (("u" + t2) == t1) - { - return true; - } - return false; - } - - // These are a subset of the implicit conversions allowed in C#. They are used to generate the return type for binary ops - // https://github.com/dotnet/csharplang/blob/master/spec/conversions.md#implicit-numeric-conversions - public Dictionary> primitiveTypeToImplicitConversions = new Dictionary> { - {"sbyte", new List {"int", "long", "float", "double", "decimal"}}, - {"byte", new List {"int", "uint", "long", "ulong", "float", "double", "decimal"}}, - {"short", new List {"int", "long", "float", "double", "decimal"}}, - {"ushort", new List {"int", "uint", "long", "ulong", "float", "double", "decimal"}}, - {"int", new List {"int", "long", "float", "double", "decimal"}}, - {"uint", new List {"uint", "long", "ulong", "float", "double", "decimal"}}, - {"long", new List {"long", "float", "double", "decimal"}}, - {"ulong", new List {"ulong", "float", "double", "decimal"}}, - {"float", new List {"float", "double"}}, - {"double", new List {"double"}}, - {"decimal", new List {"decimal"}}, - }; - - public TypeConfiguration[] typeConfiguration = new [] - { - new TypeConfiguration("bool", oneLiteral:"true", zeroLiteral:"false", supportsNumeric: false, unsupportedMethods: new[] {"LeftShift", "RightShift"}), - new TypeConfiguration("byte", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("char", oneLiteral:"(char)1", zeroLiteral:"(char)0", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("decimal", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("double", oneLiteral:"1.0", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("float", oneLiteral:"1.0f", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("int", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("long", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("sbyte", classPrefix:"SByte", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("short", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("uint", classPrefix:"UInt", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}), - new TypeConfiguration("ulong", classPrefix:"ULong", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}), - new TypeConfiguration("ushort", classPrefix:"UShort", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}), - new TypeConfiguration("DateTime", supportsBitwise: false, supportsNumeric: false, unsupportedMethods: new[] {"And", "Or", "Xor"}) - }; - - public string GetBinaryShiftOperationReturnType(TypeConfiguration t1) - { - primitiveTypeToImplicitConversions.TryGetValue(t1.TypeName, out IReadOnlyList t1ImplicitConversions); - return t1ImplicitConversions.First() ?? string.Empty; - } - - public string GetBinaryOperationReturnType(string t1, string t2) - { - if (t1 == "long" && t2 == "ulong" || t1 == "ulong" && t2 == "long") - { - return string.Empty; - } - primitiveTypeToImplicitConversions.TryGetValue(t1, out IReadOnlyList t1ImplicitConversions); - primitiveTypeToImplicitConversions.TryGetValue(t2, out IReadOnlyList t2ImplicitConversions); - var intersection = t1ImplicitConversions.Intersect(t2ImplicitConversions); - string ret; - if (intersection.Count() == 0) - { - ret = string.Empty; - } - else - { - ret = intersection.First(); - } - return ret; - } - - // Returns an empty string for binary ops that are not valid: For ex: float + decimal is NOT allowed. - // Special case: long + ulong is NOT allowed. The other mixed signed and unsigned are valid - public string GetBinaryOperationReturnType(TypeConfiguration t1, TypeConfiguration t2) - { - string t1Type = t1.TypeName; - string t2Type = t2.TypeName; - return GetBinaryOperationReturnType(t1Type, t2Type); - } - - public enum MethodType - { - Unary, - UnaryInPlace, - BinaryScalar, - BinaryInt, - Binary, - Comparison, - ComparisonScalar, - Contraction, - ElementwiseComputation, - Reduction - } - - public MethodConfiguration[] computationMethodConfiguration = new [] - { - new MethodConfiguration("Abs", MethodType.ElementwiseComputation, "Math.Abs", isNumeric: true, methodComments: "Updates each numeric element with its absolute numeric value"), - new MethodConfiguration("All", MethodType.Reduction, "", isBitwise: true, methodComments: "Returns whether all the elements are True"), - new MethodConfiguration("Any", MethodType.Reduction, "", isBitwise: true, methodComments: "Returns whether any element is True"), - new MethodConfiguration("CumulativeMax", MethodType.ElementwiseComputation, "", isNumeric:true, methodComments: "Updates each element with its cumulative maximum"), - new MethodConfiguration("CumulativeMax", MethodType.ElementwiseComputation, "", isNumeric:true, supportsRowSubsets: true, methodComments: "Updates column values at rowIndices with its cumulative rowIndices maximum"), - new MethodConfiguration("CumulativeMin", MethodType.ElementwiseComputation, "", isNumeric:true, methodComments: "Updates each element with its cumulative minimum"), - new MethodConfiguration("CumulativeMin", MethodType.ElementwiseComputation, "", isNumeric:true, supportsRowSubsets: true, methodComments: "Updates column values at rowIndices with its cumulative rowIndices minimum"), - new MethodConfiguration("CumulativeProduct", MethodType.ElementwiseComputation, "", isNumeric:true, methodComments: "Updates each element with its cumulative product"), - new MethodConfiguration("CumulativeProduct", MethodType.ElementwiseComputation, "", isNumeric:true, supportsRowSubsets: true, methodComments: "Updates column values at rowIndices with its cumulative rowIndices product"), - new MethodConfiguration("CumulativeSum", MethodType.ElementwiseComputation, "", isNumeric:true, methodComments: "Updates each element with its cumulative sum"), - new MethodConfiguration("CumulativeSum", MethodType.ElementwiseComputation, "", isNumeric:true, supportsRowSubsets: true, methodComments: "Updates column values at rowIndices with its cumulative rowIndices sum"), - new MethodConfiguration("Max", MethodType.Reduction, "", isNumeric:true, hasReturnValue:true, methodComments: "Returns the maximum of the values in the column"), - new MethodConfiguration("Max", MethodType.Reduction, "", isNumeric:true, hasReturnValue:true, supportsRowSubsets: true, methodComments: "Returns the maximum of the values at rowIndices"), - new MethodConfiguration("Min", MethodType.Reduction, "", isNumeric:true, hasReturnValue:true, methodComments: "Returns the minimum of the values in the column"), - new MethodConfiguration("Min", MethodType.Reduction, "", isNumeric:true, hasReturnValue:true, supportsRowSubsets: true, methodComments: "Returns the minimum of the values at the rowIndices"), - new MethodConfiguration("Product", MethodType.Reduction, "*", isNumeric:true, hasReturnValue:true, methodComments: "Returns the product of the values in the column"), - new MethodConfiguration("Product", MethodType.Reduction, "*", isNumeric:true, hasReturnValue:true, supportsRowSubsets: true, methodComments: "Returns the product of the values at the rowIndices"), - new MethodConfiguration("Sum", MethodType.Reduction, "+", isNumeric:true, hasReturnValue:true, methodComments: "Returns the sum of the values in the column"), - new MethodConfiguration("Sum", MethodType.Reduction, "+", isNumeric:true, hasReturnValue:true, supportsRowSubsets: true, methodComments: "Returns the sum of the values at the rowIndices"), - new MethodConfiguration("Round", MethodType.ElementwiseComputation, "Math.Round", isNumeric:true, methodComments: "Calls Math.Round on each value in a column"), - }; - - public MethodConfiguration[] methodConfiguration = new [] - { - new MethodConfiguration("Add", MethodType.Binary, "+", isNumeric:true, methodComments: "Performs element-wise addition"), - new MethodConfiguration("Add", MethodType.BinaryScalar, "+", isNumeric:true, methodComments: "Performs an element-wise addition on each column"), - new MethodConfiguration("Subtract", MethodType.Binary, "-", isNumeric:true, methodComments: "Performs element-wise subtraction"), - new MethodConfiguration("Subtract", MethodType.BinaryScalar, "-", isNumeric:true, methodComments: "Performs an element-wise subtraction on each column"), - new MethodConfiguration("Multiply", MethodType.Binary, "*", isNumeric:true, methodComments: "Performs element-wise multiplication"), // element-wise product, not matrix product - new MethodConfiguration("Multiply", MethodType.BinaryScalar, "*", isNumeric:true, methodComments: "Performs an element-wise multiplication on each column"), - new MethodConfiguration("Divide", MethodType.Binary, "/", isNumeric:true, methodComments: "Performs element-wise division"), - new MethodConfiguration("Divide", MethodType.BinaryScalar, "/", isNumeric:true, methodComments: "Performs an element-wise division on each column"), - new MethodConfiguration("Modulo", MethodType.Binary, "%", isNumeric:true, methodComments: "Performs element-wise modulus"), - new MethodConfiguration("Modulo", MethodType.BinaryScalar, "%", isNumeric:true, methodComments: "Performs an element-wise modulus operation on each column"), - new MethodConfiguration("And", MethodType.Binary, "&", isBitwise: true, methodComments: "Performs element-wise boolean And"), - new MethodConfiguration("And", MethodType.BinaryScalar, "&", isBitwise: true, methodComments: "Performs an element-wise boolean And on each column"), - new MethodConfiguration("Or", MethodType.Binary, "|", isBitwise: true, methodComments: "Performs element-wise boolean Or"), - new MethodConfiguration("Or", MethodType.BinaryScalar, "|", isBitwise: true, methodComments: "Performs an element-wise boolean Or on each column"), - new MethodConfiguration("Xor", MethodType.Binary, "^", isBitwise: true, methodComments: "Performs element-wise boolean Xor"), - new MethodConfiguration("Xor", MethodType.BinaryScalar, "^", isBitwise: true, methodComments: "Performs an element-wise boolean Xor on each column"), - new MethodConfiguration("LeftShift", MethodType.BinaryInt, "<<", isBitwise: true, methodComments: "Performs an element-wise left shift on each column"), - new MethodConfiguration("RightShift", MethodType.BinaryInt, ">>", isBitwise: true, methodComments: "Performs an element-wise right shift on each column"), - - new MethodConfiguration("ElementwiseEquals", MethodType.Comparison, "==", methodComments: "Performs element-wise equals"), - new MethodConfiguration("ElementwiseEquals", MethodType.ComparisonScalar, "==", methodComments: "Performs an element-wise equals on each column"), - new MethodConfiguration("ElementwiseNotEquals", MethodType.Comparison, "!=", methodComments: "Performs element-wise not-equals"), - new MethodConfiguration("ElementwiseNotEquals", MethodType.ComparisonScalar, "!=", methodComments: "Performs an element-wise not-equals on each column"), - new MethodConfiguration("ElementwiseGreaterThanOrEqual", MethodType.Comparison, ">=", isNumeric:true, methodComments: "Performs element-wise greater than or equal"), - new MethodConfiguration("ElementwiseGreaterThanOrEqual", MethodType.ComparisonScalar, ">=", isNumeric:true, methodComments: "Performs an element-wise greater than or equal on each column"), - new MethodConfiguration("ElementwiseLessThanOrEqual", MethodType.Comparison, "<=", isNumeric:true, methodComments: "Performs element-wise less than or equal"), - new MethodConfiguration("ElementwiseLessThanOrEqual", MethodType.ComparisonScalar, "<=", isNumeric:true, methodComments: "Performs an element-wise less than or equal on each column"), - new MethodConfiguration("ElementwiseGreaterThan", MethodType.Comparison, ">", isNumeric:true, methodComments: "Performs element-wise greater than"), - new MethodConfiguration("ElementwiseGreaterThan", MethodType.ComparisonScalar, ">", isNumeric:true, methodComments: "Performs an element-wise greater than on each column"), - new MethodConfiguration("ElementwiseLessThan", MethodType.Comparison, "<", isNumeric:true, methodComments: "Performs element-wise less than"), - new MethodConfiguration("ElementwiseLessThan", MethodType.ComparisonScalar, "<", isNumeric:true, methodComments: "Performs an element-wise less than on each column"), - }; - - public class MethodConfiguration - { - public MethodConfiguration(string methodName, MethodType methodType, string op = null, bool isNumeric = false, bool isBitwise = false, bool hasReturnValue = false, bool supportsRowSubsets = false, string methodComments = null) - { - MethodName = methodName; - MethodType = methodType; - Operator = op; - IsNumeric = isNumeric; - IsBitwise = isBitwise; - HasReturnValue = hasReturnValue; - SupportsRowSubsets = supportsRowSubsets; - MethodComments = methodComments; - } - - public string ResultName => "result"; - - public string Op1Name - { - get - { - switch (MethodType) - { - case MethodType.Unary: - case MethodType.UnaryInPlace: - case MethodType.BinaryScalar: - case MethodType.BinaryInt: - case MethodType.ComparisonScalar: - case MethodType.ElementwiseComputation: - case MethodType.Reduction: - return "column"; - case MethodType.Binary: - case MethodType.Comparison: - case MethodType.Contraction: - return "left"; - default: - throw new ArgumentException(); - }; - } - } - - public string Op2Name - { - get - { - switch (MethodType) - { - case MethodType.BinaryScalar: - case MethodType.ComparisonScalar: - return "scalar"; - case MethodType.BinaryInt: - return "value"; - case MethodType.Binary: - case MethodType.Comparison: - case MethodType.Contraction: - return "right"; - case MethodType.Unary: - case MethodType.UnaryInPlace: - default: - throw new ArgumentException(); - }; - } - } - - public string MethodName { get; } - public MethodType MethodType { get; } - public string Operator { get; } - public string MethodComments { get; } - - public string GetColumnSpecificMethodComments() - { - var str = MethodComments; - return str.Replace("column", "value in the column"); - } - - public string GetReverseMethodComments() - { - var str = MethodComments; - return str.Replace(" an", " a reversed"); - } - - public string GetColumnSpecificBinaryMethodComments() - { - var str = MethodComments; - str = str.Replace("column", ""); - return str.Replace(" an", " "); - } - - public string GetColumnSpecificReverseMethodComments() - { - return GetColumnSpecificMethodComments().Replace(" an", " a reversed"); - } - - public string GetMethodSignature(string columnType, string genericType) - { - var arguments = GetMethodArguments(columnType, genericType); - return $"void {MethodName}({arguments})"; - } - - public string GetInvertedMethodSignatureForBinaryScalarsOps(string columnType, string genericType) - { - var arguments = GetInvertedMethodArguments(columnType, genericType); - return $"void {MethodName}({arguments})"; - } - - public string GetSingleArgumentMethodSignature(string columnType, string genericType) - { - var arguments = GetSingleParameterMethodArguments(columnType, genericType); - return $"PrimitiveColumnContainer {MethodName}({arguments})"; - } - - public string GetComputationOrReductionMethodSignature(string columnType, string genericType) - { - var arguments = GetMethodArguments(columnType, genericType); - switch (MethodType) - { - case MethodType.ElementwiseComputation: - return $"{columnType}<{genericType}> {MethodName}({arguments})"; - case MethodType.Reduction: - return $"{genericType} {MethodName}({arguments})"; - default: - throw new ArgumentException(); - } - } - - public string GetInvertedMethodArguments(string dataFrameType, string genericType) - { - switch (MethodType) - { - case MethodType.BinaryScalar: - return $"{genericType} {Op2Name}, {dataFrameType}<{genericType}> {Op1Name}"; - default: - throw new ArgumentException(); - } - } - - public string GetMethodArguments(string dataFrameType, string genericType) - { - switch (MethodType) - { - case MethodType.Unary: - case MethodType.UnaryInPlace: - return $"{dataFrameType}<{genericType}> {Op1Name}"; - case MethodType.BinaryScalar: - return $"{dataFrameType}<{genericType}> {Op1Name}, {genericType} {Op2Name}"; - case MethodType.ComparisonScalar: - return $"{dataFrameType}<{genericType}> {Op1Name}, {genericType} {Op2Name}, {dataFrameType} ret"; - case MethodType.BinaryInt: - return $"{dataFrameType}<{genericType}> {Op1Name}, int {Op2Name}"; - case MethodType.Binary: - return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}"; - case MethodType.Comparison: - return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}, {dataFrameType} ret"; - case MethodType.Contraction: - return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}, int[] leftAxes, int[] rightAxes"; - case MethodType.ElementwiseComputation: - case MethodType.Reduction: - return $""; - default: - throw new ArgumentException(); - } - } - - public string GetSingleParameterMethodArguments(string dataFrameType, string genericType) - { - switch (MethodType) - { - case MethodType.Unary: - case MethodType.UnaryInPlace: - throw new ArgumentException(); - return $"{dataFrameType}<{genericType}> {Op1Name}"; - case MethodType.BinaryScalar: - return $"{genericType} {Op2Name}"; - case MethodType.ComparisonScalar: - return $"{genericType} {Op2Name}, {dataFrameType} ret"; - case MethodType.BinaryInt: - return $"int {Op2Name}"; - case MethodType.Binary: - return $"{dataFrameType}<{genericType}> {Op2Name}"; - case MethodType.Comparison: - return $"{dataFrameType}<{genericType}> {Op2Name}, {dataFrameType} ret"; - case MethodType.Contraction: - throw new ArgumentException(); - return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}, int[] leftAxes, int[] rightAxes"; - default: - throw new ArgumentException(); - } - } - - public bool IsNumeric { get; } - public bool IsBitwise { get; } - public bool HasReturnValue { get; } - public bool SupportsRowSubsets { get; } - } -#> diff --git a/src/Microsoft.Data.Analysis/DataFrame.BinaryOperations.tt b/src/Microsoft.Data.Analysis/DataFrame.BinaryOperations.tt deleted file mode 100644 index cbd854109e..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrame.BinaryOperations.tt +++ /dev/null @@ -1,136 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameBinaryOperations.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public partial class DataFrame - { -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - /// - /// <#=method.MethodComments#> - /// - public DataFrame <#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - /// <#=method.MethodComments#> - /// - public DataFrame <#=method.MethodName#>(T value, bool inPlace = false) - where T : unmanaged -<# } #> -<# } #> -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - /// - /// <#=method.MethodComments#> - /// - public DataFrame <#=method.MethodName#>(T value) - where T : unmanaged -<# } #> -<# if (method.MethodType == MethodType.Binary) {#> -<# if (method.IsBitwise == true) { #> - public DataFrame <#=method.MethodName#>(IReadOnlyList values, bool inPlace = false) -<# } else { #> - public DataFrame <#=method.MethodName#>(IReadOnlyList values, bool inPlace = false) - where T : unmanaged -<# } #> -<# } #> -<# if (method.MethodType == MethodType.Comparison) {#> - public DataFrame <#=method.MethodName#>(IReadOnlyList values) - where T : unmanaged -<# } #> -<# if (method.MethodType == MethodType.BinaryInt ) {#> - /// - /// <#=method.MethodComments#> - /// - public DataFrame <#=method.MethodName#>(int value, bool inPlace = false) -<# } #> - { -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.BinaryInt) {#> -<# } else { #> - if (values.Count != Columns.Count) - { - throw new ArgumentException(Strings.MismatchedColumnLengths, nameof(values)); - } -<# } #> -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.Binary || method.MethodType == MethodType.BinaryInt) {#> - DataFrame retDataFrame = inPlace ? this : new DataFrame(); -<# } else { #> - DataFrame retDataFrame = new DataFrame(); -<# } #> - -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.Binary || method.MethodType == MethodType.BinaryInt) {#> - for (int i = 0; i < Columns.Count; i++) - { - DataFrameColumn baseColumn = _columnCollection[i]; -<# } else { #> - for (int i = 0; i < Columns.Count; i++) - { - DataFrameColumn baseColumn = _columnCollection[i]; -<# } #> -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.BinaryInt) {#> - DataFrameColumn newColumn = baseColumn.<#=method.MethodName#>(value, inPlace); -<# } else if (method.MethodType == MethodType.Binary) { #> - DataFrameColumn newColumn = baseColumn.<#=method.MethodName#>(values[i], inPlace); -<# } else if (method.MethodType == MethodType.ComparisonScalar) { #> - DataFrameColumn newColumn = baseColumn.<#=method.MethodName#>(value); -<# } else { #> - DataFrameColumn newColumn = baseColumn.<#=method.MethodName#>(values[i]); -<# } #> -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.Binary || method.MethodType == MethodType.BinaryInt) {#> - if (inPlace) - retDataFrame.Columns[i] = newColumn; - else - retDataFrame.Columns.Insert(i, newColumn); -<# } else { #> - retDataFrame.Columns.Insert(i, newColumn); -<# } #> - } - return retDataFrame; - } -<# } #> - -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - /// - /// <#=method.GetReverseMethodComments()#> - /// - public DataFrame Reverse<#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - /// <#=method.GetReverseMethodComments()#> - /// - public DataFrame Reverse<#=method.MethodName#>(T value, bool inPlace = false) - where T : unmanaged -<# } #> - { - DataFrame retDataFrame = inPlace ? this : new DataFrame(); - for (int i = 0; i < Columns.Count; i++) - { - DataFrameColumn baseColumn = _columnCollection[i]; - DataFrameColumn newColumn = baseColumn.Reverse<#=method.MethodName#>(value, inPlace); - if (inPlace) - retDataFrame.Columns[i] = newColumn; - else - retDataFrame.Columns.Insert(i, newColumn); - } - return retDataFrame; - } -<# } #> -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/DataFrame.BinaryOperators.tt b/src/Microsoft.Data.Analysis/DataFrame.BinaryOperators.tt deleted file mode 100644 index f2c525b8f7..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrame.BinaryOperators.tt +++ /dev/null @@ -1,52 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameBinaryOperators.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public partial class DataFrame - { -#pragma warning disable 1591 -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> -<# // There seem to be very few use cases for an API such as df.And/Or/Xor(true). #> -<# continue; #> -<# } else { #> -<# foreach (TypeConfiguration type in typeConfiguration) { #> -<# if (method.IsNumeric != type.SupportsNumeric) continue; #> -<# if (method.IsNumeric && type.TypeName == "char") continue; #> - public static DataFrame operator <#=method.Operator#>(DataFrame df, <#=type.TypeName#> value) - { - return df.<#=method.MethodName#>(value); - } - - public static DataFrame operator <#=method.Operator#>(<#=type.TypeName#> value, DataFrame df) - { - return df.Reverse<#=method.MethodName#>(value); - } - -<# } #> -<# } #> -<# } else if (method.MethodType == MethodType.BinaryInt) {#> - public static DataFrame operator <#=method.Operator#>(DataFrame df, int value) - { - return df.<#=method.MethodName#>(value); - } - -<# } #> -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt deleted file mode 100644 index d2e289195c..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt +++ /dev/null @@ -1,82 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude"#> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameColumn.BinaryOperations.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public abstract partial class DataFrameColumn - { -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - /// - /// <#=method.GetColumnSpecificMethodComments()#> - /// - public virtual PrimitiveDataFrameColumn <#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - /// <#=method.GetColumnSpecificMethodComments()#> - /// - public virtual DataFrameColumn <#=method.MethodName#>(T value, bool inPlace = false) -<# } #> -<# } #> -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - /// - /// <#=method.GetColumnSpecificMethodComments()#> - /// - public virtual PrimitiveDataFrameColumn <#=method.MethodName#>(T value) -<# } #> -<# if (method.MethodType == MethodType.Binary) {#> - /// - /// <#=method.MethodComments#> - /// - public virtual DataFrameColumn <#=method.MethodName#>(DataFrameColumn column, bool inPlace = false) -<# } #> -<# if (method.MethodType == MethodType.Comparison) {#> - /// - /// <#=method.MethodComments#> - /// - public virtual PrimitiveDataFrameColumn <#=method.MethodName#>(DataFrameColumn column) -<# } #> -<# if (method.MethodType == MethodType.BinaryInt ) {#> - /// - /// <#=method.GetColumnSpecificMethodComments()#> - /// - public virtual DataFrameColumn <#=method.MethodName#>(int value, bool inPlace = false) -<# } #> - { - throw new NotImplementedException(); - } - -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - /// - /// <#=method.GetColumnSpecificReverseMethodComments()#> - /// - public virtual PrimitiveDataFrameColumn Reverse<#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - /// <#=method.GetColumnSpecificReverseMethodComments()#> - /// - public virtual DataFrameColumn Reverse<#=method.MethodName#>(T value, bool inPlace = false) -<# } #> - { - throw new NotImplementedException(); - } - -<# } #> -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperators.tt b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperators.tt deleted file mode 100644 index e55c8249df..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperators.tt +++ /dev/null @@ -1,67 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameColumn.BinaryOperators.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public abstract partial class DataFrameColumn - { -#pragma warning disable 1591 -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - public static DataFrameColumn operator <#=method.Operator#>(DataFrameColumn column, bool value) - { - return column.<#=method.MethodName#>(value); - } - - public static DataFrameColumn operator <#=method.Operator#>(bool value, DataFrameColumn column) - { - return column.Reverse<#=method.MethodName#>(value); - } - -<# } else { #> -<# foreach (TypeConfiguration type in typeConfiguration) { #> -<# if (method.IsNumeric != type.SupportsNumeric) continue; #> -<# if (method.IsNumeric && type.TypeName == "char") continue; #> - public static DataFrameColumn operator <#=method.Operator#>(DataFrameColumn column, <#=type.TypeName#> value) - { - return column.<#=method.MethodName#>(value); - } - - public static DataFrameColumn operator <#=method.Operator#>(<#=type.TypeName#> value, DataFrameColumn column) - { - return column.Reverse<#=method.MethodName#>(value); - } - -<# } #> - -<# } #> -<# } else if (method.MethodType == MethodType.BinaryInt) {#> - public static DataFrameColumn operator <#=method.Operator#>(DataFrameColumn column, int value) - { - return column.<#=method.MethodName#>(value); - } - -<# } else if (method.MethodType == MethodType.Binary) { #> - public static DataFrameColumn operator <#=method.Operator#>(DataFrameColumn left, DataFrameColumn right) - { - return left.<#=method.MethodName#>(right); - } - -<# } #> -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.Computations.tt b/src/Microsoft.Data.Analysis/DataFrameColumn.Computations.tt deleted file mode 100644 index ebe4785ae7..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.Computations.tt +++ /dev/null @@ -1,44 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude"#> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameColumn.Computations.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public abstract partial class DataFrameColumn - { -<# foreach (MethodConfiguration compMethod in computationMethodConfiguration) { #> - /// - /// <#=compMethod.MethodComments#> - /// -<# if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == false && compMethod.SupportsRowSubsets == true) {#> - public virtual DataFrameColumn <#=compMethod.MethodName#>(IEnumerable rowIndices, bool inPlace = false) -<# } else if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == false) {#> - public virtual DataFrameColumn <#=compMethod.MethodName#>(bool inPlace = false) -<# } else if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == true) {#> - public virtual object <#=compMethod.MethodName#>() -<# } else if (compMethod.MethodType == MethodType.Reduction && compMethod.IsNumeric == true && compMethod.SupportsRowSubsets == true) { #> - public virtual object <#=compMethod.MethodName#>(IEnumerable rowIndices) -<# } else if (compMethod.MethodType == MethodType.Reduction && compMethod.IsNumeric == true) { #> - public virtual object <#=compMethod.MethodName#>() -<# } else { #> - public virtual bool <#=compMethod.MethodName#>() -<# } #> - { - throw new NotImplementedException(); - } - -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/Microsoft.Data.Analysis.csproj b/src/Microsoft.Data.Analysis/Microsoft.Data.Analysis.csproj index b9992feda1..0b2333c442 100644 --- a/src/Microsoft.Data.Analysis/Microsoft.Data.Analysis.csproj +++ b/src/Microsoft.Data.Analysis/Microsoft.Data.Analysis.csproj @@ -44,122 +44,13 @@ - - - TextTemplatingFileGenerator - DataFrameColumn.BinaryOperations.cs - - - TextTemplatingFileGenerator - DataFrameColumn.BinaryOperators.cs - - - TextTemplatingFileGenerator - DataFrameColumn.Computations.cs - - - TextTemplatingFileGenerator - DataFrame.BinaryOperations.cs - - - TextTemplatingFileGenerator - DataFrame.BinaryOperators.cs - - - TextTemplatingFileGenerator - DataFrameBinaryOperators.cs - - - TextTemplatingFileGenerator - PrimitiveDataFrameColumn.BinaryOperations.Combinations.ttinclude - - - True - True - PrimitiveDataFrameColumn.BinaryOperations.Combinations.tt - - - TextTemplatingFileGenerator - PrimitiveDataFrameColumn.BinaryOperations.cs - - - TextTemplatingFileGenerator - PrimitiveDataFrameColumn.Computations.cs - - - TextTemplatingFileGenerator - PrimitiveDataFrameColumn.ReversedBinaryOperations.cs - - - TextTemplatingFileGenerator - PrimitiveColumnContainer.BinaryOperations.cs - - - TextTemplatingFileGenerator - PrimitiveColumnContainer.BinaryOperations.cs - - + - - True - True - DataFrameColumn.BinaryOperations.tt - - - True - True - DataFrameColumn.BinaryOperators.tt - - - True - True - DataFrameColumn.Computations.tt - - - True - True - DataFrame.BinaryOperations.tt - - - True - True - DataFrame.BinaryOperators.tt - - - True - True - DataFrameBinaryOperators.tt - - - True - True - PrimitiveDataFrameColumn.BinaryOperations.tt - - - True - True - PrimitiveDataFrameColumn.Computations.tt - - - True - True - PrimitiveDataFrameColumn.ReversedBinaryOperations.tt - - - True - True - PrimitiveColumnContainer.BinaryOperations.tt - - - True - True - PrimitiveColumnContainer.BinaryOperations.tt - True True diff --git a/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.BinaryOperations.tt b/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.BinaryOperations.tt deleted file mode 100644 index 95fc73b176..0000000000 --- a/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.BinaryOperations.tt +++ /dev/null @@ -1,56 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from PrimitiveColumnContainer.BinaryOperations.tt. Do not modify directly - -namespace Microsoft.Data.Analysis -{ - internal partial class PrimitiveColumnContainer - where T : struct - { -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.Comparison || method.MethodType == MethodType.ComparisonScalar) { #> - public <#= method.GetSingleArgumentMethodSignature("PrimitiveColumnContainer", "T") #> - { -<# if (method.MethodType == MethodType.ComparisonScalar ) { #> - PrimitiveDataFrameColumnArithmetic.Instance.<#=method.MethodName#>(this, scalar, ret); -<# } else { #> - PrimitiveDataFrameColumnArithmetic.Instance.<#=method.MethodName#>(this, right, ret); -<# } #> - return this; - } - -<# } else { #> - public <#= method.GetSingleArgumentMethodSignature("PrimitiveColumnContainer", "T")#> - { -<# if (method.MethodType == MethodType.BinaryScalar) { #> - PrimitiveDataFrameColumnArithmetic.Instance.<#=method.MethodName#>(this, scalar); -<# } else if (method.MethodType == MethodType.BinaryInt) { #> - PrimitiveDataFrameColumnArithmetic.Instance.<#=method.MethodName#>(this, value); -<# } else { #> - PrimitiveDataFrameColumnArithmetic.Instance.<#=method.MethodName#>(this, right); -<# } #> - return this; - } - -<# } #> -<# } #> -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> - public PrimitiveColumnContainer Reverse<#=method.MethodName#>(T scalar) - { - PrimitiveDataFrameColumnArithmetic.Instance.<#=method.MethodName#>(scalar, this); - return this; - } -<# } #> -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.tt b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.tt deleted file mode 100644 index b1ea4e40bb..0000000000 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.tt +++ /dev/null @@ -1,121 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic"#> -<#@ output extension=".ttinclude"#> -<#@ include file="ColumnArithmeticTemplate.ttinclude"#> -\<#+ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from PrimitiveDataFrameColumn.BinaryOperations.Combinations.tt. Do not modify directly - -public class TypeCombination -{ - private string _thisColumnType; - private string _otherColumnType; - private string _returnColumnType; - - public TypeCombination(string thisColumnType, string otherColumnType, string returnColumnType) - { - _thisColumnType = thisColumnType; - _otherColumnType = otherColumnType; - _returnColumnType = returnColumnType; - } - public string ThisColumnType => _thisColumnType; - public string OtherColumnType => _otherColumnType; - public string ReturnColumnType => _returnColumnType; -} - -public static class BinaryOperationCombinations -{ - - public static List binaryOperationCombinations = new List - { -<# -foreach (TypeConfiguration type in typeConfiguration) -{ - if(!type.SupportsNumeric || type.TypeName == "char") - { - continue; - } - foreach (TypeConfiguration type2 in typeConfiguration) - { - if (!type2.SupportsNumeric || type2.TypeName == "char") - { - continue; - } -#> -<# -// We won't support binary operations on pairs of signed and unsigned types yet. For users, there is a simple work around of cloning the columns to higher types(short -> int, int -> long etc) and then performing binary ops on them -if (IsMixedSignedAndUnsignedTypePair(type.TypeName, type2.TypeName)) { - // continue; -} - -// If the C# spec doesn't allow some implicit conversions, don't define that API -string returnType = GetBinaryOperationReturnType(type, type2); -if (returnType == string.Empty) -{ - continue; -} -#> - new TypeCombination("<#=type.TypeName#>", "<#=type2.TypeName#>", "<#=returnType#>"), -<# - } -} -#> - }; -} - -public static class ComparisonOperationCombinations -{ - public static List comparisonOperationCombinations = new List - { -<# - foreach (TypeConfiguration type in typeConfiguration) - { - if (type.TypeName == "char") - { - continue; - } - foreach (TypeConfiguration innerType in typeConfiguration) - { - if (innerType.TypeName == "char") - { - continue; - } - // Bool should only compare with bool, DateTime only with DateTime - if (type.TypeName == "bool" && innerType.TypeName != "bool") - { - continue; - } - if (type.TypeName == "DateTime" && innerType.TypeName != "DateTime") - { - continue; - } - if (type.SupportsNumeric != innerType.SupportsNumeric) - { - continue; - } - // For comparison, we don't exclude mixed signed and unsigned types since the result is always a bool - - if (type.SupportsNumeric) - { - // If the C# spec doesn't allow some implicit conversions, don't define that API. For ex: float == decimal or long == ulong are not allowed - string returnType = GetBinaryOperationReturnType(type, innerType); - if (returnType == string.Empty) - { - continue; - } - } -#> - new TypeCombination("<#=type.TypeName#>", "<#=innerType.TypeName#>", "bool"), -<# - } - } -#> - }; -} -\#> diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.ttinclude b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.ttinclude deleted file mode 100644 index 946e0a7e12..0000000000 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.ttinclude +++ /dev/null @@ -1,272 +0,0 @@ - -<#+ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from PrimitiveDataFrameColumn.BinaryOperations.Combinations.tt. Do not modify directly - -public class TypeCombination -{ - private string _thisColumnType; - private string _otherColumnType; - private string _returnColumnType; - - public TypeCombination(string thisColumnType, string otherColumnType, string returnColumnType) - { - _thisColumnType = thisColumnType; - _otherColumnType = otherColumnType; - _returnColumnType = returnColumnType; - } - public string ThisColumnType => _thisColumnType; - public string OtherColumnType => _otherColumnType; - public string ReturnColumnType => _returnColumnType; -} - -public static class BinaryOperationCombinations -{ - - public static List binaryOperationCombinations = new List - { - new TypeCombination("byte", "byte", "int"), - new TypeCombination("byte", "decimal", "decimal"), - new TypeCombination("byte", "double", "double"), - new TypeCombination("byte", "float", "float"), - new TypeCombination("byte", "int", "int"), - new TypeCombination("byte", "long", "long"), - new TypeCombination("byte", "sbyte", "int"), - new TypeCombination("byte", "short", "int"), - new TypeCombination("byte", "uint", "uint"), - new TypeCombination("byte", "ulong", "ulong"), - new TypeCombination("byte", "ushort", "int"), - new TypeCombination("decimal", "byte", "decimal"), - new TypeCombination("decimal", "decimal", "decimal"), - new TypeCombination("decimal", "int", "decimal"), - new TypeCombination("decimal", "long", "decimal"), - new TypeCombination("decimal", "sbyte", "decimal"), - new TypeCombination("decimal", "short", "decimal"), - new TypeCombination("decimal", "uint", "decimal"), - new TypeCombination("decimal", "ulong", "decimal"), - new TypeCombination("decimal", "ushort", "decimal"), - new TypeCombination("double", "byte", "double"), - new TypeCombination("double", "double", "double"), - new TypeCombination("double", "float", "double"), - new TypeCombination("double", "int", "double"), - new TypeCombination("double", "long", "double"), - new TypeCombination("double", "sbyte", "double"), - new TypeCombination("double", "short", "double"), - new TypeCombination("double", "uint", "double"), - new TypeCombination("double", "ulong", "double"), - new TypeCombination("double", "ushort", "double"), - new TypeCombination("float", "byte", "float"), - new TypeCombination("float", "double", "double"), - new TypeCombination("float", "float", "float"), - new TypeCombination("float", "int", "float"), - new TypeCombination("float", "long", "float"), - new TypeCombination("float", "sbyte", "float"), - new TypeCombination("float", "short", "float"), - new TypeCombination("float", "uint", "float"), - new TypeCombination("float", "ulong", "float"), - new TypeCombination("float", "ushort", "float"), - new TypeCombination("int", "byte", "int"), - new TypeCombination("int", "decimal", "decimal"), - new TypeCombination("int", "double", "double"), - new TypeCombination("int", "float", "float"), - new TypeCombination("int", "int", "int"), - new TypeCombination("int", "long", "long"), - new TypeCombination("int", "sbyte", "int"), - new TypeCombination("int", "short", "int"), - new TypeCombination("int", "uint", "long"), - new TypeCombination("int", "ulong", "float"), - new TypeCombination("int", "ushort", "int"), - new TypeCombination("long", "byte", "long"), - new TypeCombination("long", "decimal", "decimal"), - new TypeCombination("long", "double", "double"), - new TypeCombination("long", "float", "float"), - new TypeCombination("long", "int", "long"), - new TypeCombination("long", "long", "long"), - new TypeCombination("long", "sbyte", "long"), - new TypeCombination("long", "short", "long"), - new TypeCombination("long", "uint", "long"), - new TypeCombination("long", "ushort", "long"), - new TypeCombination("sbyte", "byte", "int"), - new TypeCombination("sbyte", "decimal", "decimal"), - new TypeCombination("sbyte", "double", "double"), - new TypeCombination("sbyte", "float", "float"), - new TypeCombination("sbyte", "int", "int"), - new TypeCombination("sbyte", "long", "long"), - new TypeCombination("sbyte", "sbyte", "int"), - new TypeCombination("sbyte", "short", "int"), - new TypeCombination("sbyte", "uint", "long"), - new TypeCombination("sbyte", "ulong", "float"), - new TypeCombination("sbyte", "ushort", "int"), - new TypeCombination("short", "byte", "int"), - new TypeCombination("short", "decimal", "decimal"), - new TypeCombination("short", "double", "double"), - new TypeCombination("short", "float", "float"), - new TypeCombination("short", "int", "int"), - new TypeCombination("short", "long", "long"), - new TypeCombination("short", "sbyte", "int"), - new TypeCombination("short", "short", "int"), - new TypeCombination("short", "uint", "long"), - new TypeCombination("short", "ulong", "float"), - new TypeCombination("short", "ushort", "int"), - new TypeCombination("uint", "byte", "uint"), - new TypeCombination("uint", "decimal", "decimal"), - new TypeCombination("uint", "double", "double"), - new TypeCombination("uint", "float", "float"), - new TypeCombination("uint", "int", "long"), - new TypeCombination("uint", "long", "long"), - new TypeCombination("uint", "sbyte", "long"), - new TypeCombination("uint", "short", "long"), - new TypeCombination("uint", "uint", "uint"), - new TypeCombination("uint", "ulong", "ulong"), - new TypeCombination("uint", "ushort", "uint"), - new TypeCombination("ulong", "byte", "ulong"), - new TypeCombination("ulong", "decimal", "decimal"), - new TypeCombination("ulong", "double", "double"), - new TypeCombination("ulong", "float", "float"), - new TypeCombination("ulong", "int", "float"), - new TypeCombination("ulong", "sbyte", "float"), - new TypeCombination("ulong", "short", "float"), - new TypeCombination("ulong", "uint", "ulong"), - new TypeCombination("ulong", "ulong", "ulong"), - new TypeCombination("ulong", "ushort", "ulong"), - new TypeCombination("ushort", "byte", "int"), - new TypeCombination("ushort", "decimal", "decimal"), - new TypeCombination("ushort", "double", "double"), - new TypeCombination("ushort", "float", "float"), - new TypeCombination("ushort", "int", "int"), - new TypeCombination("ushort", "long", "long"), - new TypeCombination("ushort", "sbyte", "int"), - new TypeCombination("ushort", "short", "int"), - new TypeCombination("ushort", "uint", "uint"), - new TypeCombination("ushort", "ulong", "ulong"), - new TypeCombination("ushort", "ushort", "int"), - }; -} - -public static class ComparisonOperationCombinations -{ - public static List comparisonOperationCombinations = new List - { - new TypeCombination("bool", "bool", "bool"), - new TypeCombination("byte", "byte", "bool"), - new TypeCombination("byte", "decimal", "bool"), - new TypeCombination("byte", "double", "bool"), - new TypeCombination("byte", "float", "bool"), - new TypeCombination("byte", "int", "bool"), - new TypeCombination("byte", "long", "bool"), - new TypeCombination("byte", "sbyte", "bool"), - new TypeCombination("byte", "short", "bool"), - new TypeCombination("byte", "uint", "bool"), - new TypeCombination("byte", "ulong", "bool"), - new TypeCombination("byte", "ushort", "bool"), - new TypeCombination("decimal", "byte", "bool"), - new TypeCombination("decimal", "decimal", "bool"), - new TypeCombination("decimal", "int", "bool"), - new TypeCombination("decimal", "long", "bool"), - new TypeCombination("decimal", "sbyte", "bool"), - new TypeCombination("decimal", "short", "bool"), - new TypeCombination("decimal", "uint", "bool"), - new TypeCombination("decimal", "ulong", "bool"), - new TypeCombination("decimal", "ushort", "bool"), - new TypeCombination("double", "byte", "bool"), - new TypeCombination("double", "double", "bool"), - new TypeCombination("double", "float", "bool"), - new TypeCombination("double", "int", "bool"), - new TypeCombination("double", "long", "bool"), - new TypeCombination("double", "sbyte", "bool"), - new TypeCombination("double", "short", "bool"), - new TypeCombination("double", "uint", "bool"), - new TypeCombination("double", "ulong", "bool"), - new TypeCombination("double", "ushort", "bool"), - new TypeCombination("float", "byte", "bool"), - new TypeCombination("float", "double", "bool"), - new TypeCombination("float", "float", "bool"), - new TypeCombination("float", "int", "bool"), - new TypeCombination("float", "long", "bool"), - new TypeCombination("float", "sbyte", "bool"), - new TypeCombination("float", "short", "bool"), - new TypeCombination("float", "uint", "bool"), - new TypeCombination("float", "ulong", "bool"), - new TypeCombination("float", "ushort", "bool"), - new TypeCombination("int", "byte", "bool"), - new TypeCombination("int", "decimal", "bool"), - new TypeCombination("int", "double", "bool"), - new TypeCombination("int", "float", "bool"), - new TypeCombination("int", "int", "bool"), - new TypeCombination("int", "long", "bool"), - new TypeCombination("int", "sbyte", "bool"), - new TypeCombination("int", "short", "bool"), - new TypeCombination("int", "uint", "bool"), - new TypeCombination("int", "ulong", "bool"), - new TypeCombination("int", "ushort", "bool"), - new TypeCombination("long", "byte", "bool"), - new TypeCombination("long", "decimal", "bool"), - new TypeCombination("long", "double", "bool"), - new TypeCombination("long", "float", "bool"), - new TypeCombination("long", "int", "bool"), - new TypeCombination("long", "long", "bool"), - new TypeCombination("long", "sbyte", "bool"), - new TypeCombination("long", "short", "bool"), - new TypeCombination("long", "uint", "bool"), - new TypeCombination("long", "ushort", "bool"), - new TypeCombination("sbyte", "byte", "bool"), - new TypeCombination("sbyte", "decimal", "bool"), - new TypeCombination("sbyte", "double", "bool"), - new TypeCombination("sbyte", "float", "bool"), - new TypeCombination("sbyte", "int", "bool"), - new TypeCombination("sbyte", "long", "bool"), - new TypeCombination("sbyte", "sbyte", "bool"), - new TypeCombination("sbyte", "short", "bool"), - new TypeCombination("sbyte", "uint", "bool"), - new TypeCombination("sbyte", "ulong", "bool"), - new TypeCombination("sbyte", "ushort", "bool"), - new TypeCombination("short", "byte", "bool"), - new TypeCombination("short", "decimal", "bool"), - new TypeCombination("short", "double", "bool"), - new TypeCombination("short", "float", "bool"), - new TypeCombination("short", "int", "bool"), - new TypeCombination("short", "long", "bool"), - new TypeCombination("short", "sbyte", "bool"), - new TypeCombination("short", "short", "bool"), - new TypeCombination("short", "uint", "bool"), - new TypeCombination("short", "ulong", "bool"), - new TypeCombination("short", "ushort", "bool"), - new TypeCombination("uint", "byte", "bool"), - new TypeCombination("uint", "decimal", "bool"), - new TypeCombination("uint", "double", "bool"), - new TypeCombination("uint", "float", "bool"), - new TypeCombination("uint", "int", "bool"), - new TypeCombination("uint", "long", "bool"), - new TypeCombination("uint", "sbyte", "bool"), - new TypeCombination("uint", "short", "bool"), - new TypeCombination("uint", "uint", "bool"), - new TypeCombination("uint", "ulong", "bool"), - new TypeCombination("uint", "ushort", "bool"), - new TypeCombination("ulong", "byte", "bool"), - new TypeCombination("ulong", "decimal", "bool"), - new TypeCombination("ulong", "double", "bool"), - new TypeCombination("ulong", "float", "bool"), - new TypeCombination("ulong", "int", "bool"), - new TypeCombination("ulong", "sbyte", "bool"), - new TypeCombination("ulong", "short", "bool"), - new TypeCombination("ulong", "uint", "bool"), - new TypeCombination("ulong", "ulong", "bool"), - new TypeCombination("ulong", "ushort", "bool"), - new TypeCombination("ushort", "byte", "bool"), - new TypeCombination("ushort", "decimal", "bool"), - new TypeCombination("ushort", "double", "bool"), - new TypeCombination("ushort", "float", "bool"), - new TypeCombination("ushort", "int", "bool"), - new TypeCombination("ushort", "long", "bool"), - new TypeCombination("ushort", "sbyte", "bool"), - new TypeCombination("ushort", "short", "bool"), - new TypeCombination("ushort", "uint", "bool"), - new TypeCombination("ushort", "ulong", "bool"), - new TypeCombination("ushort", "ushort", "bool"), - new TypeCombination("DateTime", "DateTime", "bool"), - }; -} -#> diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.tt b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.tt deleted file mode 100644 index bbe3cdbb0f..0000000000 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.tt +++ /dev/null @@ -1,388 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from PrimitiveDataFrameColumn.BinaryOperations.tt. Do not modify directly - -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace Microsoft.Data.Analysis -{ - public partial class PrimitiveDataFrameColumn : DataFrameColumn - where T : unmanaged - { -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.Binary || method.MethodType == MethodType.Comparison) {#> -<# if (method.MethodType == MethodType.Binary) {#> - /// - public override DataFrameColumn <#=method.MethodName#>(DataFrameColumn column, bool inPlace = false) -<# } else { #> - /// - public override PrimitiveDataFrameColumn <#=method.MethodName#>(DataFrameColumn column) -<# } #> - { - switch (column) - { -<# foreach (TypeConfiguration type in typeConfiguration) { #> - case PrimitiveDataFrameColumn<<#=type.TypeName#>> <#=type.TypeName#>Column: -<# if (method.MethodType == MethodType.Binary) {#> - return <#=method.MethodName#>Implementation(column as PrimitiveDataFrameColumn<<#=type.TypeName#>>, inPlace); -<# } else { #> - return <#=method.MethodName#>Implementation(column as PrimitiveDataFrameColumn<<#=type.TypeName#>>); -<# } #> -<# } #> - default: - throw new NotSupportedException(); - } - } -<# } #> -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.ComparisonScalar) {#> -<# if (method.MethodType == MethodType.BinaryScalar) {#> -<# if (method.IsBitwise == true) { #> - /// - public override PrimitiveDataFrameColumn <#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - public override DataFrameColumn <#=method.MethodName#>(U value, bool inPlace = false) -<# } #> -<# } else {#> - /// - public override PrimitiveDataFrameColumn <#=method.MethodName#>(U value) -<# } #> - { -<# if (method.MethodType == MethodType.BinaryScalar) {#> -<# if (method.IsBitwise == true) { #> - return <#=method.MethodName#>Implementation(value, inPlace); -<# } else { #> - DataFrameColumn column = value as DataFrameColumn; - if (column != null) - { - return <#=method.MethodName#>(column, inPlace); - } - return <#=method.MethodName#>Implementation(value, inPlace); -<# } #> -<# } else {#> - DataFrameColumn column = value as DataFrameColumn; - if (column != null) - { - return <#=method.MethodName#>(column); - } - return <#=method.MethodName#>Implementation(value); -<# } #> - } -<# } #> -<# if (method.MethodType == MethodType.BinaryInt ) {#> - /// - public override DataFrameColumn <#=method.MethodName#>(int value, bool inPlace = false) - { - return <#=method.MethodName#>Implementation(value, inPlace); - } -<# } #> -<# } #> - -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.ComparisonScalar) {#> -<# if (method.MethodType == MethodType.BinaryScalar) {#> -<# if (method.IsBitwise == true) { #> - internal PrimitiveDataFrameColumn <#=method.MethodName#>Implementation(U value, bool inPlace) -<# } else { #> - internal DataFrameColumn <#=method.MethodName#>Implementation(U value, bool inPlace) -<# } #> -<# } else {#> - internal PrimitiveDataFrameColumn <#=method.MethodName#>Implementation(U value) -<# } #> -<# } #> -<# if (method.MethodType == MethodType.Binary || method.MethodType == MethodType.Comparison) {#> -<# if (method.MethodType == MethodType.Binary) {#> - internal DataFrameColumn <#=method.MethodName#>Implementation(PrimitiveDataFrameColumn column, bool inPlace) -<# } else { #> - internal PrimitiveDataFrameColumn <#=method.MethodName#>Implementation(PrimitiveDataFrameColumn column) -<# } #> - where U : unmanaged -<# } #> -<# if (method.MethodType == MethodType.BinaryInt ) {#> - internal DataFrameColumn <#=method.MethodName#>Implementation(int value, bool inPlace) -<# } #> - { -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.BinaryInt) {#> -<# } else { #> - if (column.Length != Length) - { - throw new ArgumentException(Strings.MismatchedColumnLengths, nameof(column)); - } -<# } #> -<# if (method.MethodType == MethodType.BinaryInt ) {#> - switch (typeof(T)) - { -<# foreach (TypeConfiguration type in typeConfiguration) { #> - case Type <#=type.TypeName#>Type when <#=type.TypeName#>Type == typeof(<#=type.TypeName#>): -<# if (type.TypeName == "bool" || type.SupportsBitwise == false) { #> - throw new NotSupportedException(); -<# } else { #> - PrimitiveDataFrameColumn<<#=type.TypeName#>> <#=type.TypeName#>Column = this as PrimitiveDataFrameColumn<<#=type.TypeName#>>; - PrimitiveDataFrameColumn<<#=type.TypeName#>> new<#=type.TypeName#>Column = inPlace ? <#=type.TypeName#>Column : <#=type.TypeName#>Column.Clone(); - new<#=type.TypeName#>Column._columnContainer.<#=method.MethodName#>(value); - return new<#=type.TypeName#>Column; -<# } #> -<# } #> - default: - throw new NotSupportedException(); - } -<# } else if (method.IsBitwise == true && method.IsNumeric == false) { #> - switch (typeof(T)) - { - case Type boolType when boolType == typeof(bool): - if (typeof(U) != typeof(bool)) - { - throw new NotSupportedException(); - } -<# if (method.MethodType == MethodType.BinaryScalar) {#> - PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn retColumn = <#=GenerateInPlaceStatement("typedColumn", "typedColumn.Clone()")#>; - retColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value)); - return retColumn as PrimitiveDataFrameColumn; -<# } else { #> - PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn retColumn = <#=GenerateInPlaceStatement("typedColumn", "typedColumn.Clone()")#>; - retColumn._columnContainer.<#=method.MethodName#>(column._columnContainer); - return retColumn; -<# } #> -<# foreach (TypeConfiguration type in typeConfiguration) { #> -<# if (type.TypeName == "bool") { #> -<# } else { #> - case Type <#=type.TypeName#>Type when <#=type.TypeName#>Type == typeof(<#=type.TypeName#>): -<# } #> -<# } #> - default: - throw new NotSupportedException(); - } -<# } else { #> - switch (typeof(T)) - { -<# foreach (TypeConfiguration type in typeConfiguration) { #> -<# if (type.TypeName == "bool" || type.TypeName == "DateTime") { #> - case Type <#=type.TypeName#>Type when <#=type.TypeName#>Type == typeof(<#=type.TypeName#>): -<# if (method.IsNumeric == true) { #> - throw new NotSupportedException(); -<# } else { #> - if (typeof(U) != typeof(<#=type.TypeName#>)) - { - throw new NotSupportedException(); - } -<# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #> - PrimitiveDataFrameColumn ret<#=type.TypeName#>Column = CloneAsBooleanColumn(); -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - (this as PrimitiveDataFrameColumn)._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value), ret<#=type.TypeName#>Column._columnContainer); -<# } else { #> - (this as PrimitiveDataFrameColumn)._columnContainer.<#=method.MethodName#>(column._columnContainer, ret<#=type.TypeName#>Column._columnContainer); -<# } #> -<# } else if (method.MethodType == MethodType.BinaryScalar) {#> - PrimitiveDataFrameColumn column = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn ret<#=type.TypeName#>Column = <#=GenerateInPlaceStatement("column", "column.Clone()")#>; - ret<#=type.TypeName#>Column._columnContainer.<#=method.MethodName#>(value); -<# } else { #> - PrimitiveDataFrameColumn column = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn ret<#=type.TypeName#>Column = <#=GenerateInPlaceStatement("column", "column.Clone()")#>; - ret<#=type.TypeName#>Column._columnContainer.<#=method.MethodName#>(column._columnContainer); -<# } #> - return ret<#=type.TypeName#>Column; -<# } #> -<# } else if (type.TypeName == "decimal") { #> - case Type <#=type.TypeName#>Type when <#=type.TypeName#>Type == typeof(<#=type.TypeName#>): - if (typeof(U) == typeof(bool)) - { - throw new NotSupportedException(); - } - if (typeof(U) == typeof(T)) - { - // No conversions -<# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #> -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - PrimitiveDataFrameColumn primitiveColumn = this; - PrimitiveDataFrameColumn newColumn = CloneAsBooleanColumn(); - primitiveColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value), newColumn._columnContainer); - return newColumn; -<# } else { #> - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = CloneAsBooleanColumn(); - primitiveColumn._columnContainer.<#=method.MethodName#>(column._columnContainer, newColumn._columnContainer); - return newColumn; -<# } #> -<# } else if (method.IsBitwise == true ) { #> - throw new NotSupportedException(); -<# } else if (method.MethodType == MethodType.BinaryScalar ) { #> - PrimitiveDataFrameColumn primitiveColumn = this; - PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; - newColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value)); - return newColumn; -<# } else { #> - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; - newColumn._columnContainer.<#=method.MethodName#>(column._columnContainer); - return newColumn; -<# } #> - } - else - { -<# if (method.MethodType == MethodType.BinaryScalar) { #> - if (inPlace) - { - throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value)); - } -<# } else if (method.MethodType == MethodType.Binary) { #> - if (inPlace) - { - throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column)); - } -<# } #> -<# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #> - PrimitiveDataFrameColumn newColumn = CloneAsBooleanColumn(); -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - PrimitiveDataFrameColumn decimalColumn = CloneAsDecimalColumn(); - decimalColumn._columnContainer.<#=method.MethodName#>(DecimalConverter.Instance.GetDecimal(value), newColumn._columnContainer); - return newColumn; -<# } else { #> - PrimitiveDataFrameColumn decimalColumn = CloneAsDecimalColumn(); - decimalColumn._columnContainer.<#=method.MethodName#>(column.CloneAsDecimalColumn()._columnContainer, newColumn._columnContainer); - return newColumn; -<# } #> -<# } else if (method.IsBitwise == true) { #> - throw new NotSupportedException(); -<# } else if (method.MethodType == MethodType.BinaryScalar) { #> - PrimitiveDataFrameColumn decimalColumn = CloneAsDecimalColumn(); - decimalColumn._columnContainer.<#=method.MethodName#>(DecimalConverter.Instance.GetDecimal(value)); - return decimalColumn; -<# } else { #> - PrimitiveDataFrameColumn decimalColumn = CloneAsDecimalColumn(); - decimalColumn._columnContainer.<#=method.MethodName#>(column.CloneAsDecimalColumn()._columnContainer); - return decimalColumn; -<# } #> - } -<# } else { #> -<# } #> -<# } #> - case Type byteType when byteType == typeof(byte): - case Type charType when charType == typeof(char): - case Type doubleType when doubleType == typeof(double): - case Type floatType when floatType == typeof(float): - case Type intType when intType == typeof(int): - case Type longType when longType == typeof(long): - case Type sbyteType when sbyteType == typeof(sbyte): - case Type shortType when shortType == typeof(short): - case Type uintType when uintType == typeof(uint): - case Type ulongType when ulongType == typeof(ulong): - case Type ushortType when ushortType == typeof(ushort): - if (typeof(U) == typeof(bool)) - { - throw new NotSupportedException(); - } - if (typeof(U) == typeof(T)) - { - // No conversions -<# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #> -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - PrimitiveDataFrameColumn primitiveColumn = this; - PrimitiveDataFrameColumn newColumn = CloneAsBooleanColumn(); - primitiveColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value), newColumn._columnContainer); - return newColumn; -<# } else { #> - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = CloneAsBooleanColumn(); - primitiveColumn._columnContainer.<#=method.MethodName#>(column._columnContainer, newColumn._columnContainer); - return newColumn; -<# } #> -<# } else if (method.IsBitwise == true ) { #> - throw new NotSupportedException(); -<# } else if (method.MethodType == MethodType.BinaryScalar ) { #> - PrimitiveDataFrameColumn primitiveColumn = this; - PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; - newColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value)); - return newColumn; -<# } else { #> - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; - newColumn._columnContainer.<#=method.MethodName#>(column._columnContainer); - return newColumn; -<# } #> - } - else - { -<# if (method.MethodType == MethodType.BinaryScalar) { #> - if (inPlace) - { - throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value)); - } -<# } else if (method.MethodType == MethodType.Binary) { #> - if (inPlace) - { - throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column)); - } -<# } #> - if (typeof(U) == typeof(decimal)) - { -<# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #> - PrimitiveDataFrameColumn newColumn = CloneAsBooleanColumn(); -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - PrimitiveDataFrameColumn decimalColumn = CloneAsDecimalColumn(); - decimalColumn._columnContainer.<#=method.MethodName#>(DecimalConverter.Instance.GetDecimal(value), newColumn._columnContainer); - return newColumn; -<# } else { #> - PrimitiveDataFrameColumn decimalColumn = CloneAsDecimalColumn(); - decimalColumn._columnContainer.<#=method.MethodName#>((column as PrimitiveDataFrameColumn)._columnContainer, newColumn._columnContainer); - return newColumn; -<# } #> -<# } else if (method.IsBitwise == true) { #> - throw new NotSupportedException(); -<# } else if (method.MethodType == MethodType.BinaryScalar) { #> - PrimitiveDataFrameColumn decimalColumn = CloneAsDecimalColumn(); - decimalColumn._columnContainer.<#=method.MethodName#>(DecimalConverter.Instance.GetDecimal(value)); - return decimalColumn; -<# } else { #> - PrimitiveDataFrameColumn decimalColumn = CloneAsDecimalColumn(); - decimalColumn._columnContainer.<#=method.MethodName#>((column as PrimitiveDataFrameColumn)._columnContainer); - return decimalColumn; -<# } #> - } - else - { -<# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #> - PrimitiveDataFrameColumn newColumn = CloneAsBooleanColumn(); -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - PrimitiveDataFrameColumn doubleColumn = CloneAsDoubleColumn(); - doubleColumn._columnContainer.<#=method.MethodName#>(DoubleConverter.Instance.GetDouble(value), newColumn._columnContainer); - return newColumn; -<# } else { #> - PrimitiveDataFrameColumn doubleColumn = CloneAsDoubleColumn(); - doubleColumn._columnContainer.<#=method.MethodName#>(column.CloneAsDoubleColumn()._columnContainer, newColumn._columnContainer); - return newColumn; -<# } #> -<# } else if (method.IsBitwise == true) { #> - throw new NotSupportedException(); -<# } else if (method.MethodType == MethodType.BinaryScalar ) { #> - PrimitiveDataFrameColumn doubleColumn = CloneAsDoubleColumn(); - doubleColumn._columnContainer.<#=method.MethodName#>(DoubleConverter.Instance.GetDouble(value)); - return doubleColumn; -<# } else { #> - PrimitiveDataFrameColumn doubleColumn = CloneAsDoubleColumn(); - doubleColumn._columnContainer.<#=method.MethodName#>(column.CloneAsDoubleColumn()._columnContainer); - return doubleColumn; -<# } #> - } - } - default: - throw new NotSupportedException(); - } -<# } #> - } -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.Computations.tt b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.Computations.tt deleted file mode 100644 index 0d09ea3e37..0000000000 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.Computations.tt +++ /dev/null @@ -1,69 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> - -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from PrimitiveDataFrameColumn.Computations.tt. Do not modify directly - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class PrimitiveDataFrameColumn : DataFrameColumn - where T : unmanaged - { -<# foreach (MethodConfiguration compMethod in computationMethodConfiguration) { #> -<# if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == false && compMethod.SupportsRowSubsets == true) {#> - /// - public override DataFrameColumn <#=compMethod.MethodName#>(IEnumerable rowIndices, bool inPlace = false) -<# } else if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == false) {#> - /// - public override DataFrameColumn <#=compMethod.MethodName#>(bool inPlace = false) -<# } else if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == true) {#> - /// - public override object <#=compMethod.MethodName#>() -<# } else if (compMethod.MethodType == MethodType.Reduction && compMethod.IsNumeric == true && compMethod.SupportsRowSubsets == true) { #> - /// - public override object <#=compMethod.MethodName#>(IEnumerable rowIndices) -<# } else if (compMethod.MethodType == MethodType.Reduction && compMethod.IsNumeric == true) { #> - /// - public override object <#=compMethod.MethodName#>() -<# } else { #> - /// - public override bool <#=compMethod.MethodName#>() -<# } #> - { -<# if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == false && compMethod.SupportsRowSubsets == true) {#> - PrimitiveDataFrameColumn ret = <#=GenerateInPlaceStatement("this", "Clone()")#>; - PrimitiveColumnComputation.Instance.<#=compMethod.MethodName#>(ret._columnContainer, rowIndices); - return ret; -<# } else if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == false) {#> - PrimitiveDataFrameColumn ret = <#=GenerateInPlaceStatement("this", "Clone()")#>; - PrimitiveColumnComputation.Instance.<#=compMethod.MethodName#>(ret._columnContainer); - return ret; -<# } else if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == true) {#> - PrimitiveColumnComputation.Instance.<#=compMethod.MethodName#>(_columnContainer, out T ret); - return ret; -<# } else if (compMethod.MethodType == MethodType.Reduction && compMethod.IsNumeric == true && compMethod.SupportsRowSubsets == true) { #> - PrimitiveColumnComputation.Instance.<#=compMethod.MethodName#>(_columnContainer, rowIndices, out T ret); - return ret; -<# } else if (compMethod.MethodType == MethodType.Reduction && compMethod.IsNumeric == true) { #> - PrimitiveColumnComputation.Instance.<#=compMethod.MethodName#>(_columnContainer, out T ret); - return ret; -<# } else { #> - PrimitiveColumnComputation.Instance.<#=compMethod.MethodName#>(_columnContainer, out bool ret); - return ret; -<# } #> - } -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.tt b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.tt deleted file mode 100644 index 6bb592486e..0000000000 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.tt +++ /dev/null @@ -1,116 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from PrimitiveDataFrameColumn.ReversedBinaryOperations.tt. Do not modify directly - -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace Microsoft.Data.Analysis -{ - public partial class PrimitiveDataFrameColumn : DataFrameColumn - where T : unmanaged - { - -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) {#> -<# if (method.IsBitwise == true) { #> - /// - public override PrimitiveDataFrameColumn Reverse<#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - public override DataFrameColumn Reverse<#=method.MethodName#>(U value, bool inPlace = false) -<# } #> - { -<# if (method.IsBitwise == true) { #> - switch (this) - { - case PrimitiveDataFrameColumn boolColumn: - PrimitiveDataFrameColumn retColumn = inPlace ? boolColumn : boolColumn.Clone(); - retColumn._columnContainer.Reverse<#=method.MethodName#>(value); - return retColumn; - default: - throw new NotSupportedException(); - } -<# } else { #> - switch (this) - { - case PrimitiveDataFrameColumn boolColumn: - throw new NotSupportedException(); - case PrimitiveDataFrameColumn decimalColumn: - if (typeof(U) == typeof(bool)) - { - throw new NotSupportedException(); - } - if (typeof(U) == typeof(T)) - { - // No conversions - PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); - newColumn._columnContainer.Reverse<#=method.MethodName#>(Unsafe.As(ref value)); - return newColumn; - } - else - { - if (inPlace) - { - throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value)); - } - PrimitiveDataFrameColumn clonedDecimalColumn = CloneAsDecimalColumn(); - clonedDecimalColumn._columnContainer.Reverse<#=method.MethodName#>(DecimalConverter.Instance.GetDecimal(value)); - return clonedDecimalColumn; - } -<# foreach (TypeConfiguration type in typeConfiguration) { #> -<# if (type.TypeName == "bool") { #> -<# } else if (type.TypeName == "decimal") { #> -<# } else { #> - case PrimitiveDataFrameColumn<<#=type.TypeName#>> <#=type.TypeName#>Column: -<# } #> -<# } #> - if (typeof(U) == typeof(bool)) - { - throw new NotSupportedException(); - } - if (typeof(U) == typeof(T)) - { - // No conversions - PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); - newColumn._columnContainer.Reverse<#=method.MethodName#>(Unsafe.As(ref value)); - return newColumn; - } - else - { - if (inPlace) - { - throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value)); - } - if (typeof(U) == typeof(decimal)) - { - PrimitiveDataFrameColumn decimalColumn = CloneAsDecimalColumn(); - decimalColumn._columnContainer.Reverse<#=method.MethodName#>(DecimalConverter.Instance.GetDecimal(value)); - return decimalColumn; - } - else - { - PrimitiveDataFrameColumn clonedDoubleColumn = CloneAsDoubleColumn(); - clonedDoubleColumn._columnContainer.Reverse<#=method.MethodName#>(DoubleConverter.Instance.GetDouble(value)); - return clonedDoubleColumn; - } - } - default: - throw new NotSupportedException(); - } -<# } #> - } -<# } #> -<# } #> - } -} diff --git a/test/Microsoft.Data.Analysis.Tests/DataFrameColumn.BinaryOperationTests.tt b/test/Microsoft.Data.Analysis.Tests/DataFrameColumn.BinaryOperationTests.tt deleted file mode 100644 index 768ae1c2e1..0000000000 --- a/test/Microsoft.Data.Analysis.Tests/DataFrameColumn.BinaryOperationTests.tt +++ /dev/null @@ -1,626 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="..\..\src\Microsoft.Data.Analysis\ColumnArithmeticTemplate.ttinclude"#> -<#@ include file="..\..\src\Microsoft.Data.Analysis\PrimitiveDataFrameColumn.BinaryOperations.Combinations.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameColumn.BinaryOperationTests.tt. Do not modify directly - -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace Microsoft.Data.Analysis.Tests -{ - public partial class DataFrameColumnTests - { -<# -bool supportedInPlace(string type1, string type2) -{ - primitiveTypeToPrimitivityLevelMap.TryGetValue(type1, out int columnTypeLevel); - primitiveTypeToPrimitivityLevelMap.TryGetValue(type2, out int otherColumnTypeLevel); - if (columnTypeLevel < otherColumnTypeLevel) - { - return false; - } - return true; -} -#> -<# -void GenerateBinaryVerify(string methodName, string fullReturnType, string returnType) -{ -#> -<# - if (methodName == "Add") - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)(2 * x)); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName == "Subtract") - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)0); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName == "Multiply") - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)(x * x)); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName == "Divide") - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)(1)); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName == "Modulo") - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)(0)); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } -#> -<# -} -#> -<# -// Only generate the tests for ByteDataFrameColumn. It exercises all the possible paths since it includes cloning the non byte columns and keeps the number of tests low enough. -void GenerateAllBinaryTestsForMethod(string methodName, string methodOperator) -{ - foreach (TypeCombination types in BinaryOperationCombinations.binaryOperationCombinations) -{ - string returnType = types.ReturnColumnType; - string columnType = types.ThisColumnType; - if (columnType != "byte") - { - continue; - } - string otherColumnType = types.OtherColumnType; - - string fullColumnType = "PrimitiveDataFrameColumn<" + columnType +">"; - string fullReturnType = "PrimitiveDataFrameColumn<" + returnType +">"; - string fullOtherColumnType = "PrimitiveDataFrameColumn<" + otherColumnType +">"; - - string capitalizedReturnType = GetCapitalizedPrimitiveTypes(returnType); - string capitalizedColumnType = GetCapitalizedPrimitiveTypes(columnType); - string capitalizedOtherColumnType = GetCapitalizedPrimitiveTypes(otherColumnType); -#> - [Fact] - public void <#=methodName#><#=capitalizedOtherColumnType#>DataFrameColumnTo<#=capitalizedColumnType#>DataFrameColumn() - { - var columnEnumerable = Enumerable.Range(1, 10).Select(x => (<#=columnType#>)x); - <#=fullColumnType#> column = new <#=fullColumnType#>("<#=capitalizedColumnType#>", columnEnumerable); - var otherColumnEnumerable = Enumerable.Range(1, 10).Select(x => (<#=otherColumnType#>)x); - <#=fullOtherColumnType#> otherColumn = new <#=fullOtherColumnType#>("<#=capitalizedOtherColumnType#>", otherColumnEnumerable); - DataFrameColumn columnResult = column <#=methodOperator#> otherColumn; -<#GenerateBinaryVerify(methodName, fullReturnType, returnType); #> - Assert.Equal(columnResult.Length, verify.Count()); - Assert.True(columnResult.ElementwiseEquals(verifyColumn).All()); - } -<# -} -} -#> -<# -void GenerateBinaryScalarVerify(string methodName, string fullReturnType, string returnType, int value, bool isReverse) -{ - if (methodName.Contains("Add")) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x + (<#=returnType#>)value)); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Subtract")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x - (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value - (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Multiply")) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x * (<#=returnType#>)value)); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Divide")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x / (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value / (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Modulo")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x % (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value % (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } -#> -<# -} -#> -<# -void GenerateBinaryComparisonScalarVerify(string methodName, string fullReturnType, string returnType, int value, bool isReverse) -{ - if (methodName.Contains("ElementwiseEquals")) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)(false)); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("ElementwiseNotEquals")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)(false)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)(false)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Multiply")) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x * (<#=returnType#>)value)); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Divide")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x / (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value / (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Modulo")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x % (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value % (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } -#> -<# -} -#> -<# -void GenerateBinaryComparisonVerify(string methodName, string fullReturnType, string returnType, int value, bool isReverse) -{ - if (methodName.Contains("ElementwiseEquals")) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => true); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("ElementwiseNotEquals")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => true); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => true); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Multiply")) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x * (<#=returnType#>)value)); - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Divide")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x / (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value / (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Modulo")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x % (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value % (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } -#> -<# -} -#> -<# -void GenerateBinaryBitwiseScalarVerify(string methodName, string fullReturnType, string returnType, bool value, bool isReverse) -{ - if (methodName.Contains("And")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x & (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value & (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Or")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x | (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value | (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } - else if (methodName.Contains("Xor")) - { - if (!isReverse) - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)x ^ (<#=returnType#>)value)); -<# - } - else - { -#> - var verify = Enumerable.Range(1, 10).Select(x => (<#=returnType#>)((<#=returnType#>)value ^ (<#=returnType#>)x)); -<# - } -#> - var verifyColumn = new <#=fullReturnType#>("Verify", verify); -<# - } -#> -<# -} -#> -<# -// Only generate the tests for ByteDataFrameColumn. It exercises all the possible paths since it includes cloning the non byte columns and keeps the number of tests low enough. -void GenerateAllBinaryScalarTestsForMethod(string methodName, string methodOperator) -{ - foreach (TypeCombination types in BinaryOperationCombinations.binaryOperationCombinations) -{ - string returnType = types.ReturnColumnType; - string columnType = types.ThisColumnType; - if (columnType != "byte") - { - continue; - } - string otherColumnType = types.OtherColumnType; - - string fullColumnType = "PrimitiveDataFrameColumn<" + columnType +">"; - string fullReturnType = "PrimitiveDataFrameColumn<" + returnType +">"; - string fullOtherColumnType = "PrimitiveDataFrameColumn<" + otherColumnType +">"; - - string capitalizedReturnType = GetCapitalizedPrimitiveTypes(returnType); - string capitalizedColumnType = GetCapitalizedPrimitiveTypes(columnType); - string capitalizedOtherColumnType = GetCapitalizedPrimitiveTypes(otherColumnType); -#> - [Fact] - public void <#=methodName#><#=capitalizedOtherColumnType#>To<#=capitalizedColumnType#>DataFrameColumn() - { - var columnEnumerable = Enumerable.Range(1, 10).Select(x => (<#=columnType#>)x); - <#=fullColumnType#> column = new <#=fullColumnType#>("<#=capitalizedColumnType#>", columnEnumerable); - <#=otherColumnType#> value = 5; -<# - if (methodName.Contains("Reverse")) - { -#> - DataFrameColumn columnResult = value <#=methodOperator#> column; -<# - } - else - { -#> - DataFrameColumn columnResult = column <#=methodOperator#> value; -<# - } -#> -<#GenerateBinaryScalarVerify(methodName, fullReturnType, returnType, (byte)5, methodName.Contains("Reverse") ? true : false); #> - Assert.Equal(columnResult.Length, verify.Count()); - Assert.True(columnResult.ElementwiseEquals(verifyColumn).All()); - } -<# -} -} -#> -<# -// Only generate the tests for PrimitiveDataFrameColumn. -void GenerateAllBinaryScalarBitwiseTestsForMethod(string methodName, string methodOperator) -{ - foreach (TypeCombination types in BinaryOperationCombinations.binaryOperationCombinations) -{ - string returnType = types.ReturnColumnType; - string columnType = types.ThisColumnType; - if (columnType != "byte") - { - continue; - } - string otherColumnType = types.OtherColumnType; - - string fullColumnType = "PrimitiveDataFrameColumn<" + columnType +">"; - string fullReturnType = "PrimitiveDataFrameColumn<" + returnType +">"; - string fullOtherColumnType = "PrimitiveDataFrameColumn<" + otherColumnType +">"; - - string capitalizedReturnType = GetCapitalizedPrimitiveTypes(returnType); - string capitalizedColumnType = GetCapitalizedPrimitiveTypes(columnType); - string capitalizedOtherColumnType = GetCapitalizedPrimitiveTypes(otherColumnType); -#> - [Fact] - public void TestScalar<#=methodName#>On<#=columnType#>DataFrameColumn() - { - var columnEnumerable = Enumerable.Range(1, 10).Select(x => (<#=columnType#>)false); - <#=fullColumnType#> column = new <#=fullColumnType#>("<#=capitalizedColumnType#>", columnEnumerable); - <#=otherColumnType#> value = true; -<# - if (methodName.Contains("Reverse")) - { -#> - <#=fullReturnType#> columnResult = value <#=methodOperator#> column; -<# - } - else - { -#> - <#=fullReturnType#> columnResult = column <#=methodOperator#> value; -<# - } -#> -<#GenerateBinaryBitwiseScalarVerify(methodName, fullReturnType, returnType, true, methodName.Contains("Reverse") ? true : false); #> - Assert.Equal(columnResult.Length, verify.Count()); - Assert.True(columnResult.ElementwiseEquals(verifyColumn).All()); - } -<# -} -} -#> -<# -// Only generate the tests for ByteDataFrameColumn. It exercises all the possible paths since it includes cloning the non byte columns and keeps the number of tests low enough. -void GenerateAllBinaryScalarComparisonTestsForMethod(string methodName, string methodOperator) -{ - foreach (TypeCombination types in ComparisonOperationCombinations.comparisonOperationCombinations) -{ - string returnType = types.ReturnColumnType; - string columnType = types.ThisColumnType; - if (columnType != "byte") - { - continue; - } - string otherColumnType = types.OtherColumnType; - - string fullColumnType = "PrimitiveDataFrameColumn<" + columnType +">"; - string fullReturnType = "PrimitiveDataFrameColumn<" + returnType +">"; - string fullOtherColumnType = "PrimitiveDataFrameColumn<" + otherColumnType +">"; - - string capitalizedReturnType = GetCapitalizedPrimitiveTypes(returnType); - string capitalizedColumnType = GetCapitalizedPrimitiveTypes(columnType); - string capitalizedOtherColumnType = GetCapitalizedPrimitiveTypes(otherColumnType); -#> - [Fact] - public void <#=methodName#><#=capitalizedReturnType#>ToScalar<#=capitalizedOtherColumnType#>() - { - var columnEnumerable = Enumerable.Range(1, 10).Select(x => (<#=columnType#>)x); - <#=fullColumnType#> column = new <#=fullColumnType#>("<#=capitalizedColumnType#>", columnEnumerable); - <#=otherColumnType#> value = 100; - PrimitiveDataFrameColumn columnResult = column.<#=methodName#>(value); -<#GenerateBinaryComparisonScalarVerify(methodName, fullReturnType, returnType, (byte)5, methodName.Contains("Reverse") ? true : false); #> - Assert.Equal(columnResult.Length, verify.Count()); -<# if (!methodName.Contains("Not")) { #> - Assert.True(columnResult.ElementwiseEquals(verifyColumn).All()); -<# } else { #> - Assert.True(columnResult.ElementwiseNotEquals(verifyColumn).All()); -<# } #> - } -<# -} -} -#> -<# -// Only generate the tests for ByteDataFrameColumn. It exercises all the possible paths since it includes cloning the non byte columns and keeps the number of tests low enough. -void GenerateAllBinaryComparisonTestsForMethod(string methodName, string methodOperator) -{ - foreach (TypeCombination types in ComparisonOperationCombinations.comparisonOperationCombinations) -{ - string returnType = types.ReturnColumnType; - string columnType = types.ThisColumnType; - if (columnType != "byte") - { - continue; - } - string otherColumnType = types.OtherColumnType; - - string fullColumnType = "PrimitiveDataFrameColumn<" + columnType +">"; - string fullReturnType = "PrimitiveDataFrameColumn<" + returnType +">"; - string fullOtherColumnType = "PrimitiveDataFrameColumn<" + otherColumnType +">"; - - string capitalizedReturnType = GetCapitalizedPrimitiveTypes(returnType); - string capitalizedColumnType = GetCapitalizedPrimitiveTypes(columnType); - string capitalizedOtherColumnType = GetCapitalizedPrimitiveTypes(otherColumnType); -#> - [Fact] - public void <#=methodName#><#=capitalizedReturnType#>To<#=capitalizedOtherColumnType#>() - { - var columnEnumerable = Enumerable.Range(1, 10).Select(x => (<#=columnType#>)x); - <#=fullColumnType#> column = new <#=fullColumnType#>("<#=capitalizedColumnType#>", columnEnumerable); - var otherColumnEnumerable = Enumerable.Range(1, 10).Select(x => (<#=otherColumnType#>)x); - <#=fullOtherColumnType#> otherColumn = new <#=fullOtherColumnType#>("<#=capitalizedOtherColumnType#>", otherColumnEnumerable); - PrimitiveDataFrameColumn columnResult = column.<#=methodName#>(otherColumn); -<#GenerateBinaryComparisonVerify(methodName, fullReturnType, returnType, (byte)5, methodName.Contains("Reverse") ? true : false); #> - Assert.Equal(columnResult.Length, verify.Count()); - - // If this is equals, change thisx to false -<# if (!methodName.Contains("Not")) { #> - Assert.True(columnResult.ElementwiseEquals(verifyColumn).All()); -<# } else { #> - Assert.True(columnResult.ElementwiseNotEquals(verifyColumn).All()); -<# } #> - } -<# -} -} -#> -<# - foreach (MethodConfiguration method in methodConfiguration) - { - if (method.MethodType == MethodType.Binary && method.IsNumeric) - { - GenerateAllBinaryTestsForMethod(method.MethodName, method.Operator); - } - else if (method.MethodType == MethodType.BinaryScalar && method.IsNumeric) - { - GenerateAllBinaryScalarTestsForMethod(method.MethodName, method.Operator); - GenerateAllBinaryScalarTestsForMethod("Reverse" + method.MethodName, method.Operator); - } - else if (method.MethodType == MethodType.ComparisonScalar) - { - // Test only the ElementwiseEquals and ElementwiseNotEquals methods to reduce the number of unit tests - if ((method.MethodName == "ElementwiseEquals") || (method.MethodName == "ElementwiseNotEquals")) - { - GenerateAllBinaryScalarComparisonTestsForMethod(method.MethodName, method.Operator); - } - } - else if (method.MethodType == MethodType.Comparison) - { - // Test only the ElementwiseEquals and ElementwiseNotEquals methods to reduce the number of unit tests - if ((method.MethodName == "ElementwiseEquals") || (method.MethodName == "ElementwiseNotEquals")) - { - GenerateAllBinaryComparisonTestsForMethod(method.MethodName, method.Operator); - } - } - /* - else if (method.MethodType == MethodType.BinaryScalar && method.IsBitwise) - { - GenerateAllBinaryScalarBitwiseTestsForMethod(method.MethodName, method.Operator); - } - */ - } -#> - } -} diff --git a/test/Microsoft.Data.Analysis.Tests/Microsoft.Data.Analysis.Tests.csproj b/test/Microsoft.Data.Analysis.Tests/Microsoft.Data.Analysis.Tests.csproj index 2e28f215e8..8a59c78efe 100644 --- a/test/Microsoft.Data.Analysis.Tests/Microsoft.Data.Analysis.Tests.csproj +++ b/test/Microsoft.Data.Analysis.Tests/Microsoft.Data.Analysis.Tests.csproj @@ -13,34 +13,10 @@ - - - TextTemplatingFileGenerator - DataFrameColumn.BinaryOperationTests.cs - - - TextTemplatingFileGenerator - PrimitiveDataFrameColumnComputationsTests.cs - - - - - - True - True - DataFrameColumn.BinaryOperationTests.tt - - - True - True - PrimitiveDataFrameColumnComputationsTests.tt - - - diff --git a/test/Microsoft.Data.Analysis.Tests/PrimitiveDataFrameColumnComputationsTests.tt b/test/Microsoft.Data.Analysis.Tests/PrimitiveDataFrameColumnComputationsTests.tt deleted file mode 100644 index df9e465358..0000000000 --- a/test/Microsoft.Data.Analysis.Tests/PrimitiveDataFrameColumnComputationsTests.tt +++ /dev/null @@ -1,73 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="..\..\src\Microsoft.Data.Analysis\ColumnArithmeticTemplate.ttinclude"#> -<#@ include file="..\..\src\Microsoft.Data.Analysis\PrimitiveDataFrameColumn.BinaryOperations.Combinations.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from PrimitiveDataFrameColumnComputationsTests.tt. Do not modify directly - - -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace Microsoft.Data.Analysis.Tests -{ - public partial class DataFrameColumnTests - { - IEnumerable ByteValues = new byte?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable CharValues = new char?[] { (char)1, null, (char)2, (char)3, (char)4, null, (char)6, (char)7 }; - IEnumerable DecimalValues = new decimal?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable DoubleValues = new double?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable SingleValues = new float?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable Int32Values = new int?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable Int64Values = new long?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable SByteValues = new sbyte?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable Int16Values = new short?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable UInt32Values = new uint?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable UInt64Values = new ulong?[] { 1, null, 2, 3, 4, null, 6, 7 }; - IEnumerable UInt16Values = new ushort?[] { 1, null, 2, 3, 4, null, 6, 7 }; - - -<# - foreach (TypeConfiguration type in typeConfiguration) - { - if (type.TypeName == "bool" || type.TypeName == "DateTime") continue; -#> - [Fact] - public void <#=GetCapitalizedPrimitiveTypes(type.TypeName)#>ColumnComputationsTests() - { - - var column = new <#=GetCapitalizedPrimitiveTypes(type.TypeName)#>DataFrameColumn("<#=type.TypeName#>Values", <#=GetCapitalizedPrimitiveTypes(type.TypeName)#>Values); - -<# - foreach (MethodConfiguration method in computationMethodConfiguration) - { -#> -<# if (method.MethodType == MethodType.Reduction && method.MethodName != "Product" && method.IsNumeric && type.SupportsNumeric && !type.UnsupportedMethods.Contains(method.MethodName) ) { - - if(method.SupportsRowSubsets){ -#> -<# - } - else - { -#> - Assert.Equal(Enumerable.<#=method.MethodName#>(Int32Values), Convert.ToInt32(column.<#=method.MethodName#>())); -<# } #> -<# } #> -<# } #> - } -<# } #> - } -} - - -