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 performance of DataFrame binary comparison operations #6869

Merged
merged 3 commits into from
Oct 23, 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
2 changes: 1 addition & 1 deletion src/Microsoft.Data.Analysis/ArrowStringDataFrameColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private int GetBufferIndexContainingRowIndex(long rowIndex, out int indexInBuffe
{
if (rowIndex >= Length)
{
throw new ArgumentOutOfRangeException(Strings.ColumnIndexOutOfRange, nameof(rowIndex));
throw new ArgumentOutOfRangeException(Strings.IndexIsGreaterThanColumnLength, nameof(rowIndex));
}

// Since the strings here could be of variable length, scan linearly
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Data.Analysis/BitUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static long GetBitCount(ReadOnlySpan<byte> span, long length)
{
var endByteIndex = (int)(length / 8);

Debug.Assert(span.Length > endByteIndex);
Debug.Assert(span.Length >= endByteIndex);

long count = 0;
for (var i = 0; i < endByteIndex; i++)
Expand Down
52 changes: 26 additions & 26 deletions src/Microsoft.Data.Analysis/Computations/Arithmetic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,52 +192,52 @@ public void HandleOperation(BinaryIntOperation operation, ReadOnlySpan<T> x, int

//Comparison operations

public void HandleOperation(ComparisonOperation operation, ReadOnlySpan<T> x, ReadOnlySpan<T> y, PrimitiveColumnContainer<bool> result, long offset)
public void HandleOperation(ComparisonOperation operation, ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<bool> destination)
{
switch (operation)
{
case ComparisonOperation.ElementwiseEquals:
ElementwiseEquals(x, y, result, offset);
ElementwiseEquals(x, y, destination);
break;
case ComparisonOperation.ElementwiseNotEquals:
ElementwiseNotEquals(x, y, result, offset);
ElementwiseNotEquals(x, y, destination);
break;
case ComparisonOperation.ElementwiseGreaterThanOrEqual:
ElementwiseGreaterThanOrEqual(x, y, result, offset);
ElementwiseGreaterThanOrEqual(x, y, destination);
break;
case ComparisonOperation.ElementwiseLessThanOrEqual:
ElementwiseLessThanOrEqual(x, y, result, offset);
ElementwiseLessThanOrEqual(x, y, destination);
break;
case ComparisonOperation.ElementwiseGreaterThan:
ElementwiseGreaterThan(x, y, result, offset);
ElementwiseGreaterThan(x, y, destination);
break;
case ComparisonOperation.ElementwiseLessThan:
ElementwiseLessThan(x, y, result, offset);
ElementwiseLessThan(x, y, destination);
break;
}
}

public void HandleOperation(ComparisonOperation operation, ReadOnlySpan<T> x, T y, PrimitiveColumnContainer<bool> result, long offset)
public void HandleOperation(ComparisonOperation operation, ReadOnlySpan<T> x, T y, Span<bool> destination)
{
switch (operation)
{
case ComparisonOperation.ElementwiseEquals:
ElementwiseEquals(x, y, result, offset);
ElementwiseEquals(x, y, destination);
break;
case ComparisonOperation.ElementwiseNotEquals:
ElementwiseNotEquals(x, y, result, offset);
ElementwiseNotEquals(x, y, destination);
break;
case ComparisonOperation.ElementwiseGreaterThanOrEqual:
ElementwiseGreaterThanOrEqual(x, y, result, offset);
ElementwiseGreaterThanOrEqual(x, y, destination);
break;
case ComparisonOperation.ElementwiseLessThanOrEqual:
ElementwiseLessThanOrEqual(x, y, result, offset);
ElementwiseLessThanOrEqual(x, y, destination);
break;
case ComparisonOperation.ElementwiseGreaterThan:
ElementwiseGreaterThan(x, y, result, offset);
ElementwiseGreaterThan(x, y, destination);
break;
case ComparisonOperation.ElementwiseLessThan:
ElementwiseLessThan(x, y, result, offset);
ElementwiseLessThan(x, y, destination);
break;
}
}
Expand Down Expand Up @@ -297,29 +297,29 @@ public void HandleOperation(ComparisonOperation operation, ReadOnlySpan<T> x, T

protected virtual void RightShift(ReadOnlySpan<T> x, int y, Span<T> destination) => throw new NotSupportedException();

protected virtual void ElementwiseEquals(ReadOnlySpan<T> x, ReadOnlySpan<T> y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseEquals(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseEquals(ReadOnlySpan<T> x, T y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseEquals(ReadOnlySpan<T> x, T y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseNotEquals(ReadOnlySpan<T> x, ReadOnlySpan<T> y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseNotEquals(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseNotEquals(ReadOnlySpan<T> x, T y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseNotEquals(ReadOnlySpan<T> x, T y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseGreaterThanOrEqual(ReadOnlySpan<T> x, ReadOnlySpan<T> y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseGreaterThanOrEqual(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseGreaterThanOrEqual(ReadOnlySpan<T> x, T y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseGreaterThanOrEqual(ReadOnlySpan<T> x, T y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseLessThanOrEqual(ReadOnlySpan<T> x, ReadOnlySpan<T> y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseLessThanOrEqual(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseLessThanOrEqual(ReadOnlySpan<T> x, T y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseLessThanOrEqual(ReadOnlySpan<T> x, T y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseGreaterThan(ReadOnlySpan<T> x, ReadOnlySpan<T> y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseGreaterThan(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseGreaterThan(ReadOnlySpan<T> x, T y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseGreaterThan(ReadOnlySpan<T> x, T y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseLessThan(ReadOnlySpan<T> x, ReadOnlySpan<T> y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseLessThan(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<bool> destination) => throw new NotSupportedException();

protected virtual void ElementwiseLessThan(ReadOnlySpan<T> x, T y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void ElementwiseLessThan(ReadOnlySpan<T> x, T y, Span<bool> destination) => throw new NotSupportedException();

protected virtual T Divide(T x, T y) => throw new NotSupportedException();

Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.Data.Analysis/Computations/Arithmetic.tt
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,28 @@ namespace Microsoft.Data.Analysis

//Comparison operations

public void HandleOperation(ComparisonOperation operation, ReadOnlySpan<T> x, ReadOnlySpan<T> y, PrimitiveColumnContainer<bool> result, long offset)
public void HandleOperation(ComparisonOperation operation, ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<bool> destination)
{
switch (operation)
{
<# foreach (MethodConfiguration method in methodConfiguration) { #>
<# if (method.MethodType == MethodType.Comparison) { #>
case ComparisonOperation.<#=method.MethodName#>:
<#=method.MethodName#>(x, y, result, offset);
<#=method.MethodName#>(x, y, destination);
break;
<# } #>
<# } #>
}
}

public void HandleOperation(ComparisonOperation operation, ReadOnlySpan<T> x, T y, PrimitiveColumnContainer<bool> result, long offset)
public void HandleOperation(ComparisonOperation operation, ReadOnlySpan<T> x, T y, Span<bool> destination)
{
switch (operation)
{
<# foreach (MethodConfiguration method in methodConfiguration) { #>
<# if (method.MethodType == MethodType.ComparisonScalar) { #>
case ComparisonOperation.<#=method.MethodName#>:
<#=method.MethodName#>(x, y, result, offset);
<#=method.MethodName#>(x, y, destination);
break;
<# } #>
<# } #>
Expand All @@ -158,11 +158,11 @@ namespace Microsoft.Data.Analysis
<# foreach (MethodConfiguration method in methodConfiguration) { #>
<# if (method.MethodType == MethodType.Comparison) { #>

protected virtual void <#=method.MethodName#>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void <#=method.MethodName#>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<bool> destination) => throw new NotSupportedException();
<# } #>
<# else if (method.MethodType == MethodType.ComparisonScalar) { #>

protected virtual void <#=method.MethodName#>(ReadOnlySpan<T> x, T y, PrimitiveColumnContainer<bool> result, long offset) => throw new NotSupportedException();
protected virtual void <#=method.MethodName#>(ReadOnlySpan<T> x, T y, Span<bool> destination) => throw new NotSupportedException();
<# } #>
<# else if (method.MethodType == MethodType.Binary) { #>

Expand Down
Loading