-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathVectorFunctions.cs
More file actions
51 lines (44 loc) · 1.74 KB
/
VectorFunctions.cs
File metadata and controls
51 lines (44 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 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.
using System;
using Apache.Arrow;
namespace Tpch
{
internal static class VectorFunctions
{
internal static DoubleArray ComputeTotal(DoubleArray price, DoubleArray discount, DoubleArray tax)
{
if ((price.Length != discount.Length) || (price.Length != tax.Length))
{
throw new ArgumentException("Arrays need to be the same length");
}
int length = price.Length;
var builder = new DoubleArray.Builder().Reserve(length);
ReadOnlySpan<double> prices = price.Values;
ReadOnlySpan<double> discounts = discount.Values;
ReadOnlySpan<double> taxes = tax.Values;
for (int i = 0; i < length; ++i)
{
builder.Append(prices[i] * (1 - discounts[i]) * (1 + taxes[i]));
}
return builder.Build();
}
internal static DoubleArray ComputeDiscountPrice(DoubleArray price, DoubleArray discount)
{
if (price.Length != discount.Length)
{
throw new ArgumentException("Arrays need to be the same length");
}
int length = price.Length;
var builder = new DoubleArray.Builder().Reserve(length);
ReadOnlySpan<double> prices = price.Values;
ReadOnlySpan<double> discounts = discount.Values;
for (int i = 0; i < length; ++i)
{
builder.Append(prices[i] * (1 - discounts[i]));
}
return builder.Build();
}
}
}