Skip to content

Commit

Permalink
Use the tuple parenthesis syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed Mar 21, 2024
1 parent 4da6da1 commit a06114f
Show file tree
Hide file tree
Showing 29 changed files with 176 additions and 176 deletions.
6 changes: 3 additions & 3 deletions src/NetFabric.Numerics.Tensors.Benchmarks/MyVectors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public readonly record struct MyVector2<T>(T X, T Y)
: IAdditiveIdentity<MyVector2<T>, MyVector2<T>>, IAdditionOperators<MyVector2<T>, MyVector2<T>, MyVector2<T>>
where T : struct, IAdditiveIdentity<T, T>, IAdditionOperators<T, T, T>
{
public MyVector2(ValueTuple<T, T> tuple)
public MyVector2((T, T) tuple)
: this(tuple.Item1, tuple.Item2)
{ }

Expand All @@ -21,7 +21,7 @@ public readonly record struct MyVector3<T>(T X, T Y, T Z)
: IAdditiveIdentity<MyVector3<T>, MyVector3<T>>, IAdditionOperators<MyVector3<T>, MyVector3<T>, MyVector3<T>>
where T : struct, IAdditiveIdentity<T, T>, IAdditionOperators<T, T, T>
{
public MyVector3(ValueTuple<T, T, T> tuple)
public MyVector3((T, T, T) tuple)
: this(tuple.Item1, tuple.Item2, tuple.Item3)
{ }

Expand All @@ -36,7 +36,7 @@ public readonly record struct MyVector4<T>(T X, T Y, T Z, T W)
: IAdditiveIdentity<MyVector4<T>, MyVector4<T>>, IAdditionOperators<MyVector4<T>, MyVector4<T>, MyVector4<T>>
where T : struct, IAdditiveIdentity<T, T>, IAdditionOperators<T, T, T>
{
public MyVector4(ValueTuple<T, T, T, T> tuple)
public MyVector4((T, T, T, T) tuple)
: this(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4)
{ }

Expand Down
6 changes: 3 additions & 3 deletions src/NetFabric.Numerics.Tensors.UnitTests/MyVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public MyVector2(ReadOnlySpan<T> tuple)
{
}

public MyVector2(ValueTuple<T, T> tuple)
public MyVector2((T, T) tuple)
: this(tuple.Item1, tuple.Item2)
{
}
Expand All @@ -32,7 +32,7 @@ public MyVector3(ReadOnlySpan<T> tuple)
{
}

public MyVector3(ValueTuple<T, T, T> tuple)
public MyVector3((T, T, T) tuple)
: this(tuple.Item1, tuple.Item2, tuple.Item3)
{
}
Expand All @@ -54,7 +54,7 @@ public MyVector4(ReadOnlySpan<T> tuple)
{
}

public MyVector4(ValueTuple<T, T, T, T> tuple)
public MyVector4((T, T, T, T) tuple)
: this(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
namespace NetFabric.Numerics.Tensors.UnitTests;

public class ProductOfAdditionsTuple3DTests
{
public static TheoryData<int> ProductOfAdditions3DData
=> new() {
{ 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 }, { 10 }, { 100 },
};

[Theory]
[MemberData(nameof(ProductOfAdditions3DData))]
static void ProductOfAdditions4D_Using_Tuple3D_Should_Succeed(int count)
{
// arrange
var x = new ValueTuple<int, int, int>[count];
var y = new ValueTuple<int, int, int>[count];
var expected = new ValueTuple<int, int, int, int>(1, 1, 1, 0);
var random = new Random(42);
for (var index = 0; index < x.Length; index++)
{
var value = new ValueTuple<int, int, int>(random.Next(10), random.Next(10), random.Next(10));
var value2 = new ValueTuple<int, int, int>(random.Next(10), random.Next(10), random.Next(10));
x[index] = value;
y[index] = value2;
expected = new ((value.Item1 + value2.Item1) * expected.Item1, (value.Item2 + value2.Item2) * expected.Item2, (value.Item3 + value2.Item3) * expected.Item3, 0);
}

// act
var result = TensorOperations.ProductOfAdditions4D<int>(
MemoryMarshal.Cast<ValueTuple<int, int, int>, int>(x),
MemoryMarshal.Cast<ValueTuple<int, int, int>, int>(y));

// assert
Assert.Equal(expected, Assert.NotNull(result));
}
namespace NetFabric.Numerics.Tensors.UnitTests;

public class ProductOfAdditionsTuple3DTests
{
public static TheoryData<int> ProductOfAdditions3DData
=> new() {
{ 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 }, { 10 }, { 100 },
};

[Theory]
[MemberData(nameof(ProductOfAdditions3DData))]
static void ProductOfAdditions4D_Using_Tuple3D_Should_Succeed(int count)
{
// arrange
var x = new ValueTuple<int, int, int>[count];
var y = new ValueTuple<int, int, int>[count];
var expected = new ValueTuple<int, int, int, int>(1, 1, 1, 0);
var random = new Random(42);
for (var index = 0; index < x.Length; index++)
{
var value = new ValueTuple<int, int, int>(random.Next(10), random.Next(10), random.Next(10));
var value2 = new ValueTuple<int, int, int>(random.Next(10), random.Next(10), random.Next(10));
x[index] = value;
y[index] = value2;
expected = new ((value.Item1 + value2.Item1) * expected.Item1, (value.Item2 + value2.Item2) * expected.Item2, (value.Item3 + value2.Item3) * expected.Item3, 0);
}

// act
var result = TensorOperations.ProductOfAdditions4D<int>(
MemoryMarshal.Cast<ValueTuple<int, int, int>, int>(x),
MemoryMarshal.Cast<ValueTuple<int, int, int>, int>(y));

// assert
Assert.Equal(expected, Assert.NotNull(result));
}
}
8 changes: 4 additions & 4 deletions src/NetFabric.Numerics.Tensors/Aggregate2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static partial class Tensor
/// <typeparam name="TAggregateOperator">The type of the aggregation operator that must implement the <see cref="IAggregationOperator{T, T}"/> interface.</typeparam>
/// <param name="source">The source span containing contiguous 2D data to aggregate.</param>
/// <returns>A tuple containing the aggregated results.</returns>
public static ValueTuple<T, T> Aggregate2D<T, TAggregateOperator>(ReadOnlySpan<T> source)
public static (T, T) Aggregate2D<T, TAggregateOperator>(ReadOnlySpan<T> source)
where T : struct
where TAggregateOperator : struct, IAggregationOperator<T, T>
=> Aggregate2D<T, T, T, IdentityOperator<T>, TAggregateOperator>(source);
Expand All @@ -25,7 +25,7 @@ public static ValueTuple<T, T> Aggregate2D<T, TAggregateOperator>(ReadOnlySpan<T
/// <param name="source">The source span containing contiguous 2D data to transform and aggregate.</param>
/// <returns>A tuple containing the transformed and aggregated results.</returns>
/// <remarks>The transform operator is applied to the source elements before the aggregation operator.</remarks>
public static ValueTuple<TResult, TResult> Aggregate2D<TSource, TTransformed, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<TSource> source)
public static (TResult, TResult) Aggregate2D<TSource, TTransformed, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<TSource> source)
where TSource : struct
where TTransformed : struct
where TResult : struct
Expand Down Expand Up @@ -124,7 +124,7 @@ public static ValueTuple<TResult, TResult> Aggregate2D<TSource, TTransformed, TR
/// <param name="y">The source span containing the second set of contiguous 2D data to transform and aggregate.</param>
/// <returns>The result of the aggregation.</returns>
/// <remarks>The transform operator is applied to the source elements before the aggregation operator.</remarks>
public static ValueTuple<T, T> Aggregate2D<T, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y)
public static (T, T) Aggregate2D<T, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y)
where T : struct
where TTransformOperator : struct, IBinaryOperator<T, T, T>
where TAggregateOperator : struct, IAggregationOperator<T, T>
Expand All @@ -143,7 +143,7 @@ public static ValueTuple<T, T> Aggregate2D<T, TTransformOperator, TAggregateOper
/// <param name="y">The source span containing the second set of contiguous 2D data to transform and aggregate.</param>
/// <returns>A tuple containing the transformed and aggregated results.</returns>
/// <remarks>The transform operator is applied to the source elements before the aggregation operator.</remarks>
public static ValueTuple<TResult, TResult> Aggregate2D<T1, T2, TTransformed, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> x, ReadOnlySpan<T2> y)
public static (TResult, TResult) Aggregate2D<T1, T2, TTransformed, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> x, ReadOnlySpan<T2> y)
where T1 : struct
where T2 : struct
where TTransformed : struct
Expand Down
8 changes: 4 additions & 4 deletions src/NetFabric.Numerics.Tensors/Aggregate3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static partial class Tensor
/// <typeparam name="TAggregateOperator">The type of the aggregation operator that must implement the <see cref="IAggregationOperator{T, T}"/> interface.</typeparam>
/// <param name="source">The source span containing the 3D data to aggregate.</param>
/// <returns>A tuple containing the aggregated values.</returns>
public static ValueTuple<T, T, T> Aggregate3D<T, TAggregateOperator>(ReadOnlySpan<T> source)
public static (T, T, T) Aggregate3D<T, TAggregateOperator>(ReadOnlySpan<T> source)
where T : struct
where TAggregateOperator : struct, IAggregationOperator<T, T>
=> Aggregate3D<T, T, T, IdentityOperator<T>, TAggregateOperator>(source);
Expand All @@ -25,7 +25,7 @@ public static ValueTuple<T, T, T> Aggregate3D<T, TAggregateOperator>(ReadOnlySpa
/// <param name="source">The source span containing the 3D data to aggregate.</param>
/// <returns>A tuple containing the transformed and aggregated results.</returns>
/// <remarks>The transform operator is applied to the source elements before the aggregation operator.</remarks>
public static ValueTuple<TResult, TResult, TResult> Aggregate3D<T1, T2, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> source)
public static (TResult, TResult, TResult) Aggregate3D<T1, T2, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> source)
where T1 : struct
where T2 : struct
where TResult : struct
Expand Down Expand Up @@ -121,7 +121,7 @@ public static ValueTuple<TResult, TResult, TResult> Aggregate3D<T1, T2, TResult,
/// <param name="y">The source span containing the second set of contiguous 3D data to transform and aggregate.</param>
/// <returns>A tuple containing the transformed and aggregated results.</returns>
/// <remarks>The transform operator is applied to the source elements before the aggregation operator.</remarks>
public static ValueTuple<T, T, T> Aggregate3D<T, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y)
public static (T, T, T) Aggregate3D<T, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y)
where T : struct
where TTransformOperator : struct, IBinaryOperator<T, T, T>
where TAggregateOperator : struct, IAggregationOperator<T, T>
Expand All @@ -140,7 +140,7 @@ public static ValueTuple<T, T, T> Aggregate3D<T, TTransformOperator, TAggregateO
/// <param name="y">The source span containing the second set of contiguous 3D data to transform and aggregate.</param>
/// <returns>A tuple containing the transformed and aggregated results.</returns>
/// <remarks>The transform operator is applied to the source elements before the aggregation operator.</remarks>
public static ValueTuple<TResult, TResult, TResult> Aggregate3D<T1, T2, TTransformed, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> x, ReadOnlySpan<T2> y)
public static (TResult, TResult, TResult) Aggregate3D<T1, T2, TTransformed, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> x, ReadOnlySpan<T2> y)
where T1 : struct
where T2 : struct
where TTransformed : struct
Expand Down
8 changes: 4 additions & 4 deletions src/NetFabric.Numerics.Tensors/Aggregate4D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static partial class Tensor
/// <typeparam name="TAggregateOperator">The type of the aggregation operator that must implement the <see cref="IAggregationOperator{T, T}"/> interface.</typeparam>
/// <param name="source">The source span containing the 4D data to aggregate.</param>
/// <returns>A tuple containing the aggregated values.</returns>
public static ValueTuple<T, T, T, T> Aggregate4D<T, TAggregateOperator>(ReadOnlySpan<T> source)
public static (T, T, T, T) Aggregate4D<T, TAggregateOperator>(ReadOnlySpan<T> source)
where T : struct
where TAggregateOperator : struct, IAggregationOperator<T, T>
=> Aggregate4D<T, T, T, IdentityOperator<T>, TAggregateOperator>(source);
Expand All @@ -24,7 +24,7 @@ public static ValueTuple<T, T, T, T> Aggregate4D<T, TAggregateOperator>(ReadOnly
/// <typeparam name="TAggregateOperator">The type of the aggregation operator that must implement the <see cref="IAggregationOperator{T, T}"/> interface.</typeparam>
/// <param name="source">The source span containing the 4D data to aggregate.</param>
/// <remarks>The transform operator is applied to the source elements before the aggregation operator.</remarks>
public static ValueTuple<TResult, TResult, TResult, TResult> Aggregate4D<T1, T2, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> source)
public static (TResult, TResult, TResult, TResult) Aggregate4D<T1, T2, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> source)
where T1 : struct
where T2 : struct
where TResult : struct
Expand Down Expand Up @@ -139,7 +139,7 @@ public static ValueTuple<TResult, TResult, TResult, TResult> Aggregate4D<T1, T2,
/// <param name="y">The source span containing the second set of contiguous 4D data to transform and aggregate.</param>
/// <returns>A tuple containing the transformed and aggregated results.</returns>
/// <remarks>The transform operator is applied to the source elements before the aggregation operator.</remarks>
public static ValueTuple<T, T, T, T> Aggregate4D<T, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y)
public static (T, T, T, T) Aggregate4D<T, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y)
where T : struct
where TTransformOperator : struct, IBinaryOperator<T, T, T>
where TAggregateOperator : struct, IAggregationOperator<T, T>
Expand All @@ -158,7 +158,7 @@ public static ValueTuple<T, T, T, T> Aggregate4D<T, TTransformOperator, TAggrega
/// <param name="y">The source span containing the second set of contiguous 4D data to transform and aggregate.</param>
/// <returns>A tuple containing the transformed and aggregated results.</returns>
/// <remarks>The transform operator is applied to the source elements before the aggregation operator.</remarks>
public static ValueTuple<TResult, TResult, TResult, TResult> Aggregate4D<T1, T2, TTransformed, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> x, ReadOnlySpan<T2> y)
public static (TResult, TResult, TResult, TResult) Aggregate4D<T1, T2, TTransformed, TResult, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T1> x, ReadOnlySpan<T2> y)
where T1 : struct
where T2 : struct
where TTransformed : struct
Expand Down
2 changes: 1 addition & 1 deletion src/NetFabric.Numerics.Tensors/AggregatePropagateNaN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static T AggregatePropagateNaN<T, TAggregateOperator>(ReadOnlySpan<T> sou
/// The two operators are applied in parallel to the source elements, allowing two operations to be performed on a single pass of the source elements.
/// If any of the elements is NaN, the result is NaN.
/// </remarks>
public static ValueTuple<T, T> AggregatePropagateNaN2<T, TAggregateOperator1, TAggregateOperator2>(ReadOnlySpan<T> source)
public static (T, T) AggregatePropagateNaN2<T, TAggregateOperator1, TAggregateOperator2>(ReadOnlySpan<T> source)
where T : struct, INumberBase<T>
where TAggregateOperator1 : struct, IAggregationOperator<T, T>
where TAggregateOperator2 : struct, IAggregationOperator<T, T>
Expand Down
8 changes: 4 additions & 4 deletions src/NetFabric.Numerics.Tensors/ApplyBinary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ ref Unsafe.Add(ref xVectorsRef, indexVector),
/// <param name="destination">The span to store the result of the operation.</param>
/// <exception cref="ArgumentException">The destination is too small, or the length of the source span is not even, or the source span overlaps with the destination but they are not identical.</exception>
/// <remarks>If the destination is the same as the source span, the operation is performed in-place.</remarks>
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ValueTuple<T, T> y, Span<T> destination)
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, (T, T) y, Span<T> destination)
where T : struct
where TOperator : struct, IBinaryOperator<T, T, T>
{
Expand All @@ -253,7 +253,7 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ValueTuple<T, T> y, Sp
/// <param name="destination">The span to store the result of the operation.</param>
/// <exception cref="ArgumentException">The destination is too small or the length of the source span is not even.</exception>
/// <remarks>If the destination is the same as the source span, the operation is performed in-place.</remarks>
public static void Apply<T1, T2, TResult, TOperator>(ReadOnlySpan<T1> x, ValueTuple<T2, T2> y, Span<TResult> destination)
public static void Apply<T1, T2, TResult, TOperator>(ReadOnlySpan<T1> x, (T2, T2) y, Span<TResult> destination)
where T1 : struct
where T2 : struct
where TResult : struct
Expand Down Expand Up @@ -334,7 +334,7 @@ ref Unsafe.Add(ref xVectorsRef, indexVector),
/// <param name="destination">The span to store the result of the operation.</param>
/// <exception cref="ArgumentException">The destination is too small, or the length of the source span is not a multiple of 3, or the source span overlaps with the destination but they are not identical.</exception>
/// <remarks>If the destination is the same as the source span, the operation is performed in-place.</remarks>
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ValueTuple<T, T, T> y, Span<T> destination)
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, (T, T, T) y, Span<T> destination)
where T : struct
where TOperator : struct, IBinaryOperator<T, T, T>
{
Expand All @@ -356,7 +356,7 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ValueTuple<T, T, T> y,
/// <param name="destination">The span to store the result of the operation.</param>
/// <exception cref="ArgumentException">The destination is too small or the length of the source span is not a multiple of 3.</exception>
/// <remarks>If the destination is the same as the source span, the operation is performed in-place.</remarks>
public static void Apply<T1, T2, TResult, TOperator>(ReadOnlySpan<T1> x, ValueTuple<T2, T2, T2> y, Span<TResult> destination)
public static void Apply<T1, T2, TResult, TOperator>(ReadOnlySpan<T1> x, (T2, T2, T2) y, Span<TResult> destination)
where T1 : struct
where T2 : struct
where TResult : struct
Expand Down
Loading

0 comments on commit a06114f

Please sign in to comment.