Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve DataFrame Arithmetics implementation #6763

Merged
merged 6 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,7 @@
{
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);
Expand Down Expand Up @@ -406,15 +400,13 @@
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}<bool> ret";
return $"{dataFrameType}<{genericType}> {Op1Name}, {genericType} {Op2Name}";
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}<bool> ret";
return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}";
case MethodType.Contraction:
return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}, int[] leftAxes, int[] rightAxes";
case MethodType.ElementwiseComputation:
Expand All @@ -432,20 +424,16 @@
case MethodType.Unary:
case MethodType.UnaryInPlace:
throw new ArgumentException();
return $"{dataFrameType}<{genericType}> {Op1Name}";
case MethodType.BinaryScalar:
asmirnov82 marked this conversation as resolved.
Show resolved Hide resolved
return $"{genericType} {Op2Name}";
case MethodType.ComparisonScalar:
return $"{genericType} {Op2Name}, {dataFrameType}<bool> ret";
return $"{genericType} {Op2Name}";
case MethodType.BinaryInt:
return $"int {Op2Name}";
case MethodType.Binary:
return $"{dataFrameType}<{genericType}> {Op2Name}";
case MethodType.Comparison:
return $"{dataFrameType}<{genericType}> {Op2Name}, {dataFrameType}<bool> ret";
return $"{dataFrameType}<{genericType}> {Op2Name}";
case MethodType.Contraction:
throw new ArgumentException();
return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}, int[] leftAxes, int[] rightAxes";
default:
throw new ArgumentException();
}
Expand All @@ -456,4 +444,4 @@
public bool HasReturnValue { get; }
public bool SupportsRowSubsets { get; }
}
#>
#>
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,4 @@ public virtual PrimitiveDataFrameColumn<bool> ElementwiseIsNotNull()
throw new NotImplementedException();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,20 @@ namespace Microsoft.Data.Analysis

<# } #>
<# } #>
/// <summary>
/// Performs an element-wise equal to Null on each value in the column
/// </summary>
public virtual PrimitiveDataFrameColumn<bool> ElementwiseIsNull()
{
throw new NotImplementedException();
}

/// <summary>
/// Performs an element-wise not equal to Null on each value in the column
/// </summary>
public virtual PrimitiveDataFrameColumn<bool> ElementwiseIsNotNull()
{
throw new NotImplementedException();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.Data.Analysis
internal partial class PrimitiveColumnContainer<T>
where T : unmanaged
{

public PrimitiveColumnContainer<T> Add(PrimitiveColumnContainer<T> right)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.Add(this, right);
Expand Down Expand Up @@ -118,117 +119,112 @@ public PrimitiveColumnContainer<T> RightShift(int value)
return this;
}

public PrimitiveColumnContainer<T> ElementwiseEquals(PrimitiveColumnContainer<T> right, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseEquals(PrimitiveColumnContainer<T> right)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseEquals(this, right, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseEquals(this, right);
}

public PrimitiveColumnContainer<T> ElementwiseEquals(T scalar, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseEquals(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseEquals(this, scalar, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseEquals(this, scalar);
}

public PrimitiveColumnContainer<T> ElementwiseNotEquals(PrimitiveColumnContainer<T> right, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseNotEquals(PrimitiveColumnContainer<T> right)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseNotEquals(this, right, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseNotEquals(this, right);
}

public PrimitiveColumnContainer<T> ElementwiseNotEquals(T scalar, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseNotEquals(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseNotEquals(this, scalar, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseNotEquals(this, scalar);
}

public PrimitiveColumnContainer<T> ElementwiseGreaterThanOrEqual(PrimitiveColumnContainer<T> right, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseGreaterThanOrEqual(PrimitiveColumnContainer<T> right)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseGreaterThanOrEqual(this, right, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseGreaterThanOrEqual(this, right);
}

public PrimitiveColumnContainer<T> ElementwiseGreaterThanOrEqual(T scalar, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseGreaterThanOrEqual(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseGreaterThanOrEqual(this, scalar, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseGreaterThanOrEqual(this, scalar);
}

public PrimitiveColumnContainer<T> ElementwiseLessThanOrEqual(PrimitiveColumnContainer<T> right, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseLessThanOrEqual(PrimitiveColumnContainer<T> right)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseLessThanOrEqual(this, right, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseLessThanOrEqual(this, right);
}

public PrimitiveColumnContainer<T> ElementwiseLessThanOrEqual(T scalar, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseLessThanOrEqual(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseLessThanOrEqual(this, scalar, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseLessThanOrEqual(this, scalar);
}

public PrimitiveColumnContainer<T> ElementwiseGreaterThan(PrimitiveColumnContainer<T> right, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseGreaterThan(PrimitiveColumnContainer<T> right)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseGreaterThan(this, right, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseGreaterThan(this, right);
}

public PrimitiveColumnContainer<T> ElementwiseGreaterThan(T scalar, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseGreaterThan(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseGreaterThan(this, scalar, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseGreaterThan(this, scalar);
}

public PrimitiveColumnContainer<T> ElementwiseLessThan(PrimitiveColumnContainer<T> right, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseLessThan(PrimitiveColumnContainer<T> right)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseLessThan(this, right, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseLessThan(this, right);
}

public PrimitiveColumnContainer<T> ElementwiseLessThan(T scalar, PrimitiveColumnContainer<bool> ret)
public PrimitiveColumnContainer<bool> ElementwiseLessThan(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseLessThan(this, scalar, ret);
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.ElementwiseLessThan(this, scalar);
}

public PrimitiveColumnContainer<T> ReverseAdd(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.Add(scalar, this);
return this;
}

public PrimitiveColumnContainer<T> ReverseSubtract(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.Subtract(scalar, this);
return this;
}

public PrimitiveColumnContainer<T> ReverseMultiply(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.Multiply(scalar, this);
return this;
}

public PrimitiveColumnContainer<T> ReverseDivide(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.Divide(scalar, this);
return this;
}

public PrimitiveColumnContainer<T> ReverseModulo(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.Modulo(scalar, this);
return this;
}

public PrimitiveColumnContainer<T> ReverseAnd(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.And(scalar, this);
return this;
}

public PrimitiveColumnContainer<T> ReverseOr(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.Or(scalar, this);
return this;
}

public PrimitiveColumnContainer<T> ReverseXor(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.Xor(scalar, this);
return this;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
namespace Microsoft.Data.Analysis
{
internal partial class PrimitiveColumnContainer<T>
where T : struct
where T : unmanaged
{
<# foreach (MethodConfiguration method in methodConfiguration) { #>
<# if (method.MethodType == MethodType.Comparison || method.MethodType == MethodType.ComparisonScalar) { #>
public <#= method.GetSingleArgumentMethodSignature("PrimitiveColumnContainer", "T") #>

<# if (method.MethodType == MethodType.Comparison) { #>
public PrimitiveColumnContainer<bool> <#=method.MethodName#>(PrimitiveColumnContainer<T> right)
{
<# if (method.MethodType == MethodType.ComparisonScalar ) { #>
PrimitiveDataFrameColumnArithmetic<T>.Instance.<#=method.MethodName#>(this, scalar, ret);
<# } else { #>
PrimitiveDataFrameColumnArithmetic<T>.Instance.<#=method.MethodName#>(this, right, ret);
<# } #>
return this;
return PrimitiveDataFrameColumnArithmetic<T>.Instance.<#=method.MethodName#>(this, right);
}
<# } else if (method.MethodType == MethodType.ComparisonScalar ) { #>
public PrimitiveColumnContainer<bool> <#=method.MethodName#>(T scalar)
{
return PrimitiveDataFrameColumnArithmetic<T>.Instance.<#=method.MethodName#>(this, scalar);
}

<# } else { #>
public <#= method.GetSingleArgumentMethodSignature("PrimitiveColumnContainer", "T")#>
{
Expand All @@ -40,11 +40,11 @@ namespace Microsoft.Data.Analysis
<# } #>
return this;
}

<# } #>
<# } #>
<# foreach (MethodConfiguration method in methodConfiguration) { #>
<# if (method.MethodType == MethodType.BinaryScalar) { #>

public PrimitiveColumnContainer<T> Reverse<#=method.MethodName#>(T scalar)
{
PrimitiveDataFrameColumnArithmetic<T>.Instance.<#=method.MethodName#>(scalar, this);
Expand All @@ -53,4 +53,4 @@ namespace Microsoft.Data.Analysis
<# } #>
<# } #>
}
}
}
Loading