From eb447c43e0842ce198fad5043db144816bab0dd9 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sat, 6 Jan 2024 12:21:15 +0000 Subject: [PATCH] Spinoff NetFabric.Numerics.Tensors to a dedicated repository --- NetFabric.Numerics.sln | 18 - .../NetFabric.Numerics.Angle.csproj | 5 +- .../AddBenchmarks.cs | 63 --- .../AddValueBenchmarks.cs | 63 --- ...tFabric.Numerics.Tensors.Benchmarks.csproj | 19 - .../Program.cs | 36 -- .../SumBenchmarks.cs | 63 --- .../SumPairsBenchmarks.cs | 65 --- .../AddMultiplyPairsTests.cs | 70 --- .../AddMultiplyTests.cs | 64 --- .../AddMultiplyTripletsTests.cs | 70 --- .../AddMultiplyValuePairsTests.cs | 184 ------- .../AddMultiplyValueTests.cs | 153 ------ .../AddMultiplyValueTripletsTests.cs | 182 ------ .../AddPairsTests.cs | 66 --- .../AddTests.cs | 55 -- .../AddTripletsTests.cs | 65 --- .../AddValuePairsTests.cs | 61 -- .../AddValueTests.cs | 59 -- .../AddValueTripletsTests.cs | 61 -- .../MyVector.cs | 35 -- ...etFabric.Numerics.Tensors.UnitTests.csproj | 35 -- .../SquareTests.cs | 54 -- .../SumPairsTests.cs | 56 -- .../SumTests.cs | 54 -- .../SumTripletsTests.cs | 56 -- src/NetFabric.Numerics.Tensors/Add.cs | 62 --- src/NetFabric.Numerics.Tensors/AddMultiply.cs | 162 ------ src/NetFabric.Numerics.Tensors/Aggregate.cs | 49 -- .../AggregatePairs.cs | 65 --- .../AggregateTriplets.cs | 33 -- src/NetFabric.Numerics.Tensors/ApplyBinary.cs | 189 ------- .../ApplyTernary.cs | 519 ------------------ src/NetFabric.Numerics.Tensors/ApplyUnary.cs | 50 -- src/NetFabric.Numerics.Tensors/Average.cs | 19 - src/NetFabric.Numerics.Tensors/Divide.cs | 58 -- .../ITensorOperation.cs | 141 ----- src/NetFabric.Numerics.Tensors/Multiply.cs | 58 -- src/NetFabric.Numerics.Tensors/Negate.cs | 16 - .../NetFabric.Numerics.Tensors.csproj | 53 -- .../Operators/AddMultiplyOperator.cs | 30 - .../Operators/AddOperator.cs | 28 - .../Operators/DivideOperator.cs | 28 - .../Operators/MultiplyAddOperator.cs | 30 - .../Operators/MultiplyOperator.cs | 28 - .../Operators/NegateOperator.cs | 26 - .../Operators/SquareOperator.cs | 26 - .../Operators/SubtractOperator.cs | 28 - .../Operators/SumOperator.cs | 111 ---- src/NetFabric.Numerics.Tensors/README.md | 3 - src/NetFabric.Numerics.Tensors/Square.cs | 16 - src/NetFabric.Numerics.Tensors/Subtract.cs | 58 -- src/NetFabric.Numerics.Tensors/Sum.cs | 45 -- src/NetFabric.Numerics.Tensors/Tensor.cs | 22 - 54 files changed, 1 insertion(+), 3664 deletions(-) delete mode 100644 src/NetFabric.Numerics.Tensors.Benchmarks/AddBenchmarks.cs delete mode 100644 src/NetFabric.Numerics.Tensors.Benchmarks/AddValueBenchmarks.cs delete mode 100644 src/NetFabric.Numerics.Tensors.Benchmarks/NetFabric.Numerics.Tensors.Benchmarks.csproj delete mode 100644 src/NetFabric.Numerics.Tensors.Benchmarks/Program.cs delete mode 100644 src/NetFabric.Numerics.Tensors.Benchmarks/SumBenchmarks.cs delete mode 100644 src/NetFabric.Numerics.Tensors.Benchmarks/SumPairsBenchmarks.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyPairsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTripletsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValuePairsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValueTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValueTripletsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddPairsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddTripletsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddValuePairsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddValueTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/AddValueTripletsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/MyVector.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/NetFabric.Numerics.Tensors.UnitTests.csproj delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/SquareTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/SumPairsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/SumTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors.UnitTests/SumTripletsTests.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Add.cs delete mode 100644 src/NetFabric.Numerics.Tensors/AddMultiply.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Aggregate.cs delete mode 100644 src/NetFabric.Numerics.Tensors/AggregatePairs.cs delete mode 100644 src/NetFabric.Numerics.Tensors/AggregateTriplets.cs delete mode 100644 src/NetFabric.Numerics.Tensors/ApplyBinary.cs delete mode 100644 src/NetFabric.Numerics.Tensors/ApplyTernary.cs delete mode 100644 src/NetFabric.Numerics.Tensors/ApplyUnary.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Average.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Divide.cs delete mode 100644 src/NetFabric.Numerics.Tensors/ITensorOperation.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Multiply.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Negate.cs delete mode 100644 src/NetFabric.Numerics.Tensors/NetFabric.Numerics.Tensors.csproj delete mode 100644 src/NetFabric.Numerics.Tensors/Operators/AddMultiplyOperator.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Operators/AddOperator.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Operators/DivideOperator.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Operators/MultiplyAddOperator.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Operators/MultiplyOperator.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Operators/NegateOperator.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Operators/SquareOperator.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Operators/SubtractOperator.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Operators/SumOperator.cs delete mode 100644 src/NetFabric.Numerics.Tensors/README.md delete mode 100644 src/NetFabric.Numerics.Tensors/Square.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Subtract.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Sum.cs delete mode 100644 src/NetFabric.Numerics.Tensors/Tensor.cs diff --git a/NetFabric.Numerics.sln b/NetFabric.Numerics.sln index 896d007..d8f40f3 100644 --- a/NetFabric.Numerics.sln +++ b/NetFabric.Numerics.sln @@ -56,12 +56,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Geodesy" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Geodesy.UnitTests", "src\NetFabric.Numerics.Geodesy.UnitTests\NetFabric.Numerics.Geodesy.UnitTests.csproj", "{4E4414C1-E5CF-4679-9016-7C3F70F13110}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Tensors", "src\NetFabric.Numerics.Tensors\NetFabric.Numerics.Tensors.csproj", "{8D2EE0A5-32A2-4019-AD55-7E9B70B76D67}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Tensors.UnitTests", "src\NetFabric.Numerics.Tensors.UnitTests\NetFabric.Numerics.Tensors.UnitTests.csproj", "{31E6CCB0-E04A-4947-BF74-E8E70D5594E5}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Tensors.Benchmarks", "src\NetFabric.Numerics.Tensors.Benchmarks\NetFabric.Numerics.Tensors.Benchmarks.csproj", "{A8467A84-F9DD-4B6C-91BB-CF39029331A4}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -96,18 +90,6 @@ Global {4E4414C1-E5CF-4679-9016-7C3F70F13110}.Debug|Any CPU.Build.0 = Debug|Any CPU {4E4414C1-E5CF-4679-9016-7C3F70F13110}.Release|Any CPU.ActiveCfg = Release|Any CPU {4E4414C1-E5CF-4679-9016-7C3F70F13110}.Release|Any CPU.Build.0 = Release|Any CPU - {8D2EE0A5-32A2-4019-AD55-7E9B70B76D67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8D2EE0A5-32A2-4019-AD55-7E9B70B76D67}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8D2EE0A5-32A2-4019-AD55-7E9B70B76D67}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8D2EE0A5-32A2-4019-AD55-7E9B70B76D67}.Release|Any CPU.Build.0 = Release|Any CPU - {31E6CCB0-E04A-4947-BF74-E8E70D5594E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {31E6CCB0-E04A-4947-BF74-E8E70D5594E5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {31E6CCB0-E04A-4947-BF74-E8E70D5594E5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {31E6CCB0-E04A-4947-BF74-E8E70D5594E5}.Release|Any CPU.Build.0 = Release|Any CPU - {A8467A84-F9DD-4B6C-91BB-CF39029331A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A8467A84-F9DD-4B6C-91BB-CF39029331A4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A8467A84-F9DD-4B6C-91BB-CF39029331A4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A8467A84-F9DD-4B6C-91BB-CF39029331A4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/NetFabric.Numerics.Angle/NetFabric.Numerics.Angle.csproj b/src/NetFabric.Numerics.Angle/NetFabric.Numerics.Angle.csproj index a96be0e..27fd8a5 100644 --- a/src/NetFabric.Numerics.Angle/NetFabric.Numerics.Angle.csproj +++ b/src/NetFabric.Numerics.Angle/NetFabric.Numerics.Angle.csproj @@ -40,6 +40,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -50,8 +51,4 @@ - - - - \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors.Benchmarks/AddBenchmarks.cs b/src/NetFabric.Numerics.Tensors.Benchmarks/AddBenchmarks.cs deleted file mode 100644 index ede20ab..0000000 --- a/src/NetFabric.Numerics.Tensors.Benchmarks/AddBenchmarks.cs +++ /dev/null @@ -1,63 +0,0 @@ -using BenchmarkDotNet.Attributes; - -namespace NetFabric.Numerics.Tensors.Benchmarks; - -public class AddBenchmarks -{ - short[]? arrayShort; - int[]? arrayInt; - long[]? arrayLong; - Half[]? arrayHalf; - float[]? arrayFloat; - double[]? arrayDouble; - - [Params(10_000)] - public int Count { get; set; } - - [GlobalSetup] - public void GlobalSetup() - { - var range = Enumerable.Range(0, Count); - arrayShort = range - .Select(value => (short)value) - .ToArray(); - arrayInt = range - .ToArray(); - arrayLong = range - .Select(value => (long)value) - .ToArray(); - arrayHalf = range - .Select(value => (Half)value) - .ToArray(); - arrayFloat = range - .Select(value => (float)value) - .ToArray(); - arrayDouble = range - .Select(value => (double)value) - .ToArray(); - } - - [Benchmark] - public void Add_Short() - => Tensor.Add(arrayShort!, arrayShort!, arrayShort!); - - [Benchmark] - public void Add_Int() - => Tensor.Add(arrayInt!, arrayInt!, arrayInt!); - - [Benchmark] - public void Add_Long() - => Tensor.Add(arrayLong!, arrayLong!, arrayLong!); - - [Benchmark] - public void Add_Half() - => Tensor.Add(arrayHalf!, arrayHalf!, arrayHalf!); - - [Benchmark] - public void Add_Float() - => Tensor.Add(arrayFloat!, arrayFloat!, arrayFloat!); - - [Benchmark] - public void Add_Double() - => Tensor.Add(arrayDouble!, arrayDouble!, arrayDouble!); -} diff --git a/src/NetFabric.Numerics.Tensors.Benchmarks/AddValueBenchmarks.cs b/src/NetFabric.Numerics.Tensors.Benchmarks/AddValueBenchmarks.cs deleted file mode 100644 index c559135..0000000 --- a/src/NetFabric.Numerics.Tensors.Benchmarks/AddValueBenchmarks.cs +++ /dev/null @@ -1,63 +0,0 @@ -using BenchmarkDotNet.Attributes; - -namespace NetFabric.Numerics.Tensors.Benchmarks; - -public class AddValueBenchmarks -{ - short[]? arrayShort; - int[]? arrayInt; - long[]? arrayLong; - Half[]? arrayHalf; - float[]? arrayFloat; - double[]? arrayDouble; - - [Params(10_000)] - public int Count { get; set; } - - [GlobalSetup] - public void GlobalSetup() - { - var range = Enumerable.Range(0, Count); - arrayShort = range - .Select(value => (short)value) - .ToArray(); - arrayInt = range - .ToArray(); - arrayLong = range - .Select(value => (long)value) - .ToArray(); - arrayHalf = range - .Select(value => (Half)value) - .ToArray(); - arrayFloat = range - .Select(value => (float)value) - .ToArray(); - arrayDouble = range - .Select(value => (double)value) - .ToArray(); - } - - [Benchmark] - public void Add_Short() - => Tensor.Add(arrayShort!, 42, arrayShort!); - - [Benchmark] - public void Add_Int() - => Tensor.Add(arrayInt!, 42, arrayInt!); - - [Benchmark] - public void Add_Long() - => Tensor.Add(arrayLong!, 42, arrayLong!); - - [Benchmark] - public void Add_Half() - => Tensor.Add(arrayHalf!, (Half)42, arrayHalf!); - - [Benchmark] - public void Add_Float() - => Tensor.Add(arrayFloat!, 42, arrayFloat!); - - [Benchmark] - public void Add_Double() - => Tensor.Add(arrayDouble!, 42, arrayDouble!); -} diff --git a/src/NetFabric.Numerics.Tensors.Benchmarks/NetFabric.Numerics.Tensors.Benchmarks.csproj b/src/NetFabric.Numerics.Tensors.Benchmarks/NetFabric.Numerics.Tensors.Benchmarks.csproj deleted file mode 100644 index f35cf89..0000000 --- a/src/NetFabric.Numerics.Tensors.Benchmarks/NetFabric.Numerics.Tensors.Benchmarks.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - Exe - net8.0 - - false - NetFabric.Numerics.Tensors.Benchmarks - - - - - - - - - - - diff --git a/src/NetFabric.Numerics.Tensors.Benchmarks/Program.cs b/src/NetFabric.Numerics.Tensors.Benchmarks/Program.cs deleted file mode 100644 index e9c9373..0000000 --- a/src/NetFabric.Numerics.Tensors.Benchmarks/Program.cs +++ /dev/null @@ -1,36 +0,0 @@ -using BenchmarkDotNet.Columns; -using BenchmarkDotNet.Configs; -using BenchmarkDotNet.Jobs; -using BenchmarkDotNet.Reports; -using BenchmarkDotNet.Running; -using System.Runtime.Intrinsics; - -var config = DefaultConfig.Instance - .WithSummaryStyle(SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend)) - .HideColumns(Column.EnvironmentVariables, Column.RatioSD, Column.Error) - // .AddDiagnoser(new DisassemblyDiagnoser(new DisassemblyDiagnoserConfig - // (exportGithubMarkdown: true, printInstructionAddresses: false))) - .AddJob(Job.Default.WithId("Scalar") - .WithEnvironmentVariable("DOTNET_EnableHWIntrinsic", "0") - .AsBaseline()); - -if (Vector128.IsHardwareAccelerated) -{ - config = config - .AddJob(Job.Default.WithId("Vector128") - .WithEnvironmentVariable("DOTNET_EnableAVX2", "0") - .WithEnvironmentVariable("DOTNET_EnableAVX512F", "0")); -} -if (Vector256.IsHardwareAccelerated) -{ - config = config - .AddJob(Job.Default.WithId("Vector256") - .WithEnvironmentVariable("DOTNET_EnableAVX512F", "0")); -} -if (Vector512.IsHardwareAccelerated) -{ - config = config - .AddJob(Job.Default.WithId("Vector512")); -} - -BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors.Benchmarks/SumBenchmarks.cs b/src/NetFabric.Numerics.Tensors.Benchmarks/SumBenchmarks.cs deleted file mode 100644 index 6c8d6bc..0000000 --- a/src/NetFabric.Numerics.Tensors.Benchmarks/SumBenchmarks.cs +++ /dev/null @@ -1,63 +0,0 @@ -using BenchmarkDotNet.Attributes; - -namespace NetFabric.Numerics.Tensors.Benchmarks; - -public class SumBenchmarks -{ - short[]? arrayShort; - int[]? arrayInt; - long[]? arrayLong; - Half[]? arrayHalf; - float[]? arrayFloat; - double[]? arrayDouble; - - [Params(10_000)] - public int Count { get; set; } - - [GlobalSetup] - public void GlobalSetup() - { - var range = Enumerable.Range(0, Count); - arrayShort = range - .Select(value => (short)value) - .ToArray(); - arrayInt = range - .ToArray(); - arrayLong = range - .Select(value => (long)value) - .ToArray(); - arrayHalf = range - .Select(value => (Half)value) - .ToArray(); - arrayFloat = range - .Select(value => (float)value) - .ToArray(); - arrayDouble = range - .Select(value => (double)value) - .ToArray(); - } - - [Benchmark] - public short Sum_Short() - => Tensor.Sum(arrayShort!); - - [Benchmark] - public int Sum_Int() - => Tensor.Sum(arrayInt!); - - [Benchmark] - public long Sum_Long() - => Tensor.Sum(arrayLong!); - - [Benchmark] - public Half Sum_Half() - => Tensor.Sum(arrayHalf!); - - [Benchmark] - public float Sum_Float() - => Tensor.Sum(arrayFloat!); - - [Benchmark] - public double Sum_Double() - => Tensor.Sum(arrayDouble); -} diff --git a/src/NetFabric.Numerics.Tensors.Benchmarks/SumPairsBenchmarks.cs b/src/NetFabric.Numerics.Tensors.Benchmarks/SumPairsBenchmarks.cs deleted file mode 100644 index 4b156e8..0000000 --- a/src/NetFabric.Numerics.Tensors.Benchmarks/SumPairsBenchmarks.cs +++ /dev/null @@ -1,65 +0,0 @@ -using BenchmarkDotNet.Attributes; -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.Benchmarks; - -public class SumPairsBenchmarks -{ - ValueTuple[]? arrayShort; - ValueTuple[]? arrayInt; - ValueTuple[]? arrayLong; - ValueTuple[]? arrayHalf; - ValueTuple[]? arrayFloat; - ValueTuple[]? arrayDouble; - - [Params(10_000)] - public int Count { get; set; } - - [GlobalSetup] - public void GlobalSetup() - { - var range = Enumerable.Range(0, Count); - arrayShort = range - .Select(value => ((short)value, (short)(value + 1))) - .ToArray(); - arrayInt = range - .Select(value => ((int)value, (int)(value + 1))) - .ToArray(); - arrayLong = range - .Select(value => ((long)value, (long)(value + 1))) - .ToArray(); - arrayHalf = range - .Select(value => ((Half)value, (Half)(value + 1))) - .ToArray(); - arrayFloat = range - .Select(value => ((float)value, (float)(value + 1))) - .ToArray(); - arrayDouble = range - .Select(value => ((double)value, (double)(value + 1))) - .ToArray(); - } - - [Benchmark] - public ValueTuple Sum_Short() - => Tensor.SumPairs(MemoryMarshal.Cast, short>(arrayShort!)); - - [Benchmark] - public ValueTuple Sum_Int() - => Tensor.SumPairs(MemoryMarshal.Cast, int>(arrayInt!)); - - [Benchmark] - public ValueTuple Sum_Long() - => Tensor.SumPairs(MemoryMarshal.Cast, long>(arrayLong!)); - - [Benchmark] - public ValueTuple Sum_Half() - => Tensor.SumPairs(MemoryMarshal.Cast, Half>(arrayHalf!)); - - [Benchmark] - public ValueTuple Sum_Float() - => Tensor.SumPairs(MemoryMarshal.Cast, float>(arrayFloat!)); - - [Benchmark] - public ValueTuple Sum_Double() - => Tensor.SumPairs(MemoryMarshal.Cast, double>(arrayDouble!)); -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyPairsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyPairsTests.cs deleted file mode 100644 index b326227..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyPairsTests.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddMultiplyPairsTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void AddMultiply_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector2(T.CreateChecked(value), T.CreateChecked(value + 1))) - .ToArray(); - var y = source - .Select(value => new MyVector2(T.CreateChecked(value + 2), T.CreateChecked(value + 3))) - .ToArray(); - var z = source - .Select(value => new MyVector2(T.CreateChecked(value + 4), T.CreateChecked(value + 5))) - .ToArray(); - var result = new MyVector2[count]; - var expected = source - .Select(value => new MyVector2(T.CreateChecked((value + value + 2) * (value + 4)), T.CreateChecked((value + value + 4) * (value + 5)))) - .ToArray(); - - // act - Tensor.AddMultiply( - MemoryMarshal.Cast, T>(x), - MemoryMarshal.Cast, T>(y), - MemoryMarshal.Cast, T>(z), - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Short_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Int_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Long_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Half_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Float_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Double_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTests.cs deleted file mode 100644 index 742aac2..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTests.cs +++ /dev/null @@ -1,64 +0,0 @@ -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddMultiplyTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void AddMultiply_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => T.CreateChecked(value)) - .ToArray(); - var y = source - .Select(value => T.CreateChecked(value + 1)) - .ToArray(); - var z = source - .Select(value => T.CreateChecked(value + 2)) - .ToArray(); - var result = new T[count]; - var expected = source - .Select(value => T.CreateChecked((value + value + 1) * (value + 2))) - .ToArray(); - - // act - Tensor.AddMultiply(x, y, z, result); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Short_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Int_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Long_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Half_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Float_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Double_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTripletsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTripletsTests.cs deleted file mode 100644 index fea6828..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTripletsTests.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddMultiplyTripletsTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void AddMultiply_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector3(T.CreateChecked(value), T.CreateChecked(value + 1), T.CreateChecked(value + 2))) - .ToArray(); - var y = source - .Select(value => new MyVector3(T.CreateChecked(value + 2), T.CreateChecked(value + 3), T.CreateChecked(value + 4))) - .ToArray(); - var z = source - .Select(value => new MyVector3(T.CreateChecked(value + 4), T.CreateChecked(value + 5), T.CreateChecked(value + 6))) - .ToArray(); - var result = new MyVector3[count]; - var expected = source - .Select(value => new MyVector3(T.CreateChecked((value + value + 2) * (value + 4)), T.CreateChecked((value + value + 4) * (value + 5)), T.CreateChecked((value + value + 6) * (value + 6)))) - .ToArray(); - - // act - Tensor.AddMultiply( - MemoryMarshal.Cast, T>(x), - MemoryMarshal.Cast, T>(y), - MemoryMarshal.Cast, T>(z), - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Short_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Int_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Long_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Half_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Float_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Double_Should_Succeed(int count) - => AddMultiply_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValuePairsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValuePairsTests.cs deleted file mode 100644 index 0ed4136..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValuePairsTests.cs +++ /dev/null @@ -1,184 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddMultiplyValuePairsTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void AddMultiply_First_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector2(T.CreateChecked(value), T.CreateChecked(value + 1))) - .ToArray(); - var y = (T.CreateChecked(24), T.CreateChecked(25)); - var z = source - .Select(value => new MyVector2(T.CreateChecked(value + 2), T.CreateChecked(value + 3))) - .ToArray(); - var result = new MyVector2[count]; - var expected = source - .Select(value => new MyVector2(T.CreateChecked((value + 24) * (value + 2)), T.CreateChecked((value + 26) * (value + 3)))) - .ToArray(); - - // act - Tensor.AddMultiply( - MemoryMarshal.Cast, T>(x), - y, - MemoryMarshal.Cast, T>(z), - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - - static void AddMultiply_Second_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector2(T.CreateChecked(value), T.CreateChecked(value + 1))) - .ToArray(); - var y = source - .Select(value => new MyVector2(T.CreateChecked(value + 2), T.CreateChecked(value + 3))) - .ToArray(); - var z = (T.CreateChecked(42), T.CreateChecked(43)); - var result = new MyVector2[count]; - var expected = source - .Select(value => new MyVector2(T.CreateChecked((value + value + 2) * 42), T.CreateChecked((value + value + 4) * 43))) - .ToArray(); - - // act - Tensor.AddMultiply( - MemoryMarshal.Cast, T>(x), - MemoryMarshal.Cast, T>(y), - z, - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - static void AddMultiply_Both_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector2(T.CreateChecked(value), T.CreateChecked(value + 1))) - .ToArray(); - var y = (T.CreateChecked(24), T.CreateChecked(25)); - var z = (T.CreateChecked(42), T.CreateChecked(43)); - var result = new MyVector2[count]; - var expected = source - .Select(value => new MyVector2(T.CreateChecked((value + 24) * 42), T.CreateChecked((value + 26) * 43))) - .ToArray(); - - // act - Tensor.AddMultiply( - MemoryMarshal.Cast, T>(x), - y, - z, - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Short_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Short_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Short_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Int_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Int_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Int_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Long_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Long_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Long_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Half_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Half_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Half_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Float_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Float_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Float_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Double_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Double_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Double_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValueTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValueTests.cs deleted file mode 100644 index 015f70e..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValueTests.cs +++ /dev/null @@ -1,153 +0,0 @@ -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddMultiplyValueTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void AddMultiply_First_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => T.CreateChecked(value)) - .ToArray(); - var y = T.CreateChecked(24); - var z = source - .Select(value => T.CreateChecked(value + 2)) - .ToArray(); - var result = new T[count]; - var expected = source - .Select(value => T.CreateChecked((value + 24) * (value + 2))) - .ToArray(); - - // act - Tensor.AddMultiply(x, y, z, result); - - // assert - result.Should().Equal(expected); - } - - static void AddMultiply_Second_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => T.CreateChecked(value)) - .ToArray(); - var y = source - .Select(value => T.CreateChecked(value + 1)) - .ToArray(); - var z = T.CreateChecked(42); - var result = new T[count]; - var expected = source - .Select(value => T.CreateChecked((value + value + 1) * 42)) - .ToArray(); - - // act - Tensor.AddMultiply(x, y, z, result); - - // assert - result.Should().Equal(expected); - } - - static void AddMultiply_Both_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => T.CreateChecked(value)) - .ToArray(); - var y = T.CreateChecked(24); - var z = T.CreateChecked(42); - var result = new T[count]; - var expected = source - .Select(value => T.CreateChecked((value + 24) * 42)) - .ToArray(); - - // act - Tensor.AddMultiply(x, y, z, result); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Short_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Short_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Short_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Int_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Int_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Int_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Long_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Long_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Long_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Float_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Float_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Float_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Double_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Double_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Double_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValueTripletsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValueTripletsTests.cs deleted file mode 100644 index 4f78290..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyValueTripletsTests.cs +++ /dev/null @@ -1,182 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddMultiplyValueTripletsTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void AddMultiply_First_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector3(T.CreateChecked(value), T.CreateChecked(value + 1), T.CreateChecked(value + 2))) - .ToArray(); - var y = (T.CreateChecked(24), T.CreateChecked(25), T.CreateChecked(26)); - var z = source - .Select(value => new MyVector3(T.CreateChecked(value + 2), T.CreateChecked(value + 3), T.CreateChecked(value + 4))) - .ToArray(); - var result = new MyVector3[count]; - var expected = source - .Select(value => new MyVector3(T.CreateChecked((value + 24) * (value + 2)), T.CreateChecked((value + 26) * (value + 3)), T.CreateChecked((value + 28) * (value + 4)))) - .ToArray(); - - // act - Tensor.AddMultiply( - MemoryMarshal.Cast, T>(x), - y, - MemoryMarshal.Cast, T>(z), - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - static void AddMultiply_Second_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector3(T.CreateChecked(value), T.CreateChecked(value + 1), T.CreateChecked(value + 2))) - .ToArray(); - var y = source - .Select(value => new MyVector3(T.CreateChecked(value + 2), T.CreateChecked(value + 3), T.CreateChecked(value + 4))) - .ToArray(); - var z = (T.CreateChecked(42), T.CreateChecked(43), T.CreateChecked(44)); - var result = new MyVector3[count]; - var expected = source - .Select(value => new MyVector3(T.CreateChecked((value + value + 2) * 42), T.CreateChecked((value + value + 4) * 43), T.CreateChecked((value + value + 6) * 44))) - .ToArray(); - - // act - Tensor.AddMultiply( - MemoryMarshal.Cast, T>(x), - MemoryMarshal.Cast, T>(y), - z, - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - static void AddMultiply_Both_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector3(T.CreateChecked(value), T.CreateChecked(value + 1), T.CreateChecked(value + 2))) - .ToArray(); - var y = (T.CreateChecked(24), T.CreateChecked(25), T.CreateChecked(26)); - var z = (T.CreateChecked(42), T.CreateChecked(43), T.CreateChecked(44)); - var result = new MyVector3[count]; - var expected = source - .Select(value => new MyVector3(T.CreateChecked((value + 24) * 42), T.CreateChecked((value + 26) * 43), T.CreateChecked((value + 28) * 44))) - .ToArray(); - - // act - Tensor.AddMultiply( - MemoryMarshal.Cast, T>(x), - y, - z, - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Short_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Short_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Short_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Int_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Int_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Int_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Long_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Long_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Long_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Half_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Half_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Half_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Float_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Float_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Float_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_First_Double_Should_Succeed(int count) - => AddMultiply_First_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Second_Double_Should_Succeed(int count) - => AddMultiply_Second_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void AddMultiply_Both_Double_Should_Succeed(int count) - => AddMultiply_Both_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddPairsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddPairsTests.cs deleted file mode 100644 index 3c12c75..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddPairsTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddPairsTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void Add_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector2(T.CreateChecked(value), T.CreateChecked(value + 1))) - .ToArray(); - var y = source - .Select(value => new MyVector2(T.CreateChecked(value + 2), T.CreateChecked(value + 3))) - .ToArray(); - var result = new MyVector2[count]; - var expected = source - .Select(value => new MyVector2(T.CreateChecked(value + value + 2), T.CreateChecked(value + value + 4))) - .ToArray(); - - // act - Tensor.Add( - MemoryMarshal.Cast, T>(x), - MemoryMarshal.Cast, T>(y), - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Short_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Int_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Long_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Half_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Float_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Double_Should_Succeed(int count) - => Add_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddTests.cs deleted file mode 100644 index 6a3c1b5..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddTests.cs +++ /dev/null @@ -1,55 +0,0 @@ -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void Add_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source.Select(value => T.CreateChecked(value)).ToArray(); - var y = source.Select(value => T.CreateChecked(value + 1)).ToArray(); - var result = new T[count]; - var expected = source.Select(value => T.CreateChecked(value + value + 1)).ToArray(); - - // act - Tensor.Add(x, y, result); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Short_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Int_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Long_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Half_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Float_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Double_Should_Succeed(int count) - => Add_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddTripletsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddTripletsTests.cs deleted file mode 100644 index 857a51b..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddTripletsTests.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddTripletsTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void Add_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector3(T.CreateChecked(value), T.CreateChecked(value + 1), T.CreateChecked(value + 2))) - .ToArray(); - var y = source - .Select(value => new MyVector3(T.CreateChecked(value + 2), T.CreateChecked(value + 3), T.CreateChecked(value + 4))) - .ToArray(); - var result = new MyVector3[count]; - var expected = source - .Select(value => new MyVector3(T.CreateChecked(value + value + 2), T.CreateChecked(value + value + 4), T.CreateChecked(value + value + 6))) - .ToArray(); - - // act - Tensor.Add( - MemoryMarshal.Cast, T>(x), - MemoryMarshal.Cast, T>(y), - MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Short_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Int_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Long_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Half_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Float_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Double_Should_Succeed(int count) - => Add_Should_Succeed(count); -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddValuePairsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddValuePairsTests.cs deleted file mode 100644 index c783dd9..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddValuePairsTests.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddValuePairsTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void Add_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector2(T.CreateChecked(value), T.CreateChecked(value + 1))) - .ToArray(); - var y = (T.CreateChecked(42), T.CreateChecked(24)); - var result = new MyVector2[count]; - var expected = source - .Select(value => new MyVector2(T.CreateChecked(value) + y.Item1, T.CreateChecked(value + 1) + y.Item2)) - .ToArray(); - - // act - Tensor.Add(MemoryMarshal.Cast, T>(x), y, MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Short_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Int_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Long_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Half_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Float_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Double_Should_Succeed(int count) - => Add_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddValueTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddValueTests.cs deleted file mode 100644 index 98d6905..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddValueTests.cs +++ /dev/null @@ -1,59 +0,0 @@ -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddValueTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void Add_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => T.CreateChecked(value)) - .ToArray(); - var y = T.CreateChecked(42); - var result = new T[count]; - var expected = source - .Select(value => T.CreateChecked(value) + y) - .ToArray(); - - // act - Tensor.Add(x, y, result); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Short_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Int_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Long_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Half_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Float_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Double_Should_Succeed(int count) - => Add_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/AddValueTripletsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/AddValueTripletsTests.cs deleted file mode 100644 index a160760..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/AddValueTripletsTests.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class AddValueTripletsTests -{ - public static TheoryData AddData - => new() { 0, 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 }; - - static void Add_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source - .Select(value => new MyVector3(T.CreateChecked(value), T.CreateChecked(value + 1), T.CreateChecked(value + 2))) - .ToArray(); - var y = (T.CreateChecked(42), T.CreateChecked(43), T.CreateChecked(44)); - var result = new MyVector3[count]; - var expected = source - .Select(value => new MyVector3(T.CreateChecked(value) + y.Item1, T.CreateChecked(value + 1) + y.Item2, T.CreateChecked(value + 2) + y.Item3)) - .ToArray(); - - // act - Tensor.Add(MemoryMarshal.Cast, T>(x), y, MemoryMarshal.Cast, T>(result)); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Short_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Int_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Long_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Half_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Float_Should_Succeed(int count) - => Add_Should_Succeed(count); - - [Theory] - [MemberData(nameof(AddData))] - public void Add_Double_Should_Succeed(int count) - => Add_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/MyVector.cs b/src/NetFabric.Numerics.Tensors.UnitTests/MyVector.cs deleted file mode 100644 index b366ec5..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/MyVector.cs +++ /dev/null @@ -1,35 +0,0 @@ -namespace NetFabric.Numerics.Tensors.UnitTests; - -readonly record struct MyVector2(T X, T Y) - : IAdditiveIdentity, MyVector2> - , IAdditionOperators, MyVector2, MyVector2> - where T : struct, IAdditiveIdentity, IAdditionOperators -{ - public MyVector2(ValueTuple tuple) - : this(tuple.Item1, tuple.Item2) - { - } - - public static MyVector2 AdditiveIdentity - => new(T.AdditiveIdentity, T.AdditiveIdentity); - - public static MyVector2 operator +(MyVector2 left, MyVector2 right) - => new(left.X + right.X, left.Y + right.Y); -} - -readonly record struct MyVector3(T X, T Y, T Z) - : IAdditiveIdentity, MyVector3> - , IAdditionOperators, MyVector3, MyVector3> - where T : struct, IAdditiveIdentity, IAdditionOperators -{ - public MyVector3(ValueTuple tuple) - : this(tuple.Item1, tuple.Item2, tuple.Item3) - { - } - - public static MyVector3 AdditiveIdentity - => new(T.AdditiveIdentity, T.AdditiveIdentity, T.AdditiveIdentity); - - public static MyVector3 operator +(MyVector3 left, MyVector3 right) - => new(left.X + right.X, left.Y + right.Y, left.Z + right.Z); -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/NetFabric.Numerics.Tensors.UnitTests.csproj b/src/NetFabric.Numerics.Tensors.UnitTests/NetFabric.Numerics.Tensors.UnitTests.csproj deleted file mode 100644 index 897a6c3..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/NetFabric.Numerics.Tensors.UnitTests.csproj +++ /dev/null @@ -1,35 +0,0 @@ - - - - net8.0 - - false - true - NetFabric.Numerics.Tensors.UnitTests - - - - - - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/SquareTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/SquareTests.cs deleted file mode 100644 index 0c81d14..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/SquareTests.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class SquareTests -{ - public static TheoryData SquareData - => new() { 0, 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 }; - - static void Square_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count); - var x = source.Select(value => T.CreateChecked(value)).ToArray(); - var result = new T[count]; - var expected = source.Select(value => T.CreateChecked(value * value)).ToArray(); - - // act - Tensor.Square(x, result); - - // assert - result.Should().Equal(expected); - } - - [Theory] - [MemberData(nameof(SquareData))] - public void Square_Short_Should_Succeed(int count) - => Square_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SquareData))] - public void Square_Int_Should_Succeed(int count) - => Square_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SquareData))] - public void Square_Long_Should_Succeed(int count) - => Square_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SquareData))] - public void Square_Half_Should_Succeed(int count) - => Square_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SquareData))] - public void Square_Float_Should_Succeed(int count) - => Square_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SquareData))] - public void Square_Double_Should_Succeed(int count) - => Square_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/SumPairsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/SumPairsTests.cs deleted file mode 100644 index 8070074..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/SumPairsTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class SumPairsTests -{ - public static TheoryData SumData - => new() { 0, 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 }; - - static void SumPairs_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count) - .Select(value => new MyVector2(T.CreateChecked(value), T.CreateChecked(value + 1))) - .ToArray(); - var expected = source - .Aggregate(MyVector2.AdditiveIdentity, (sum, value) => sum + value); - - // act - var result = new MyVector2(Tensor.SumPairs(MemoryMarshal.Cast, T>(source))); - - // assert - result.Should().Be(expected); - } - - [Theory] - [MemberData(nameof(SumData))] - public void SumPairs_Short_Should_Succeed(int count) - => SumPairs_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumPairs_Int_Should_Succeed(int count) - => SumPairs_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumPairs_Long_Should_Succeed(int count) - => SumPairs_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumPairs_Half_Should_Succeed(int count) - => SumPairs_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumPairs_Float_Should_Succeed(int count) - => SumPairs_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumPairs_Double_Should_Succeed(int count) - => SumPairs_Should_Succeed(count); -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/SumTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/SumTests.cs deleted file mode 100644 index a7f3957..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/SumTests.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class SumTests -{ - public static TheoryData SumData - => new() { 0, 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 }; - - static void Sum_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count) - .Select(value => T.CreateChecked(value)) - .ToArray(); - var expected = source.Aggregate(T.AdditiveIdentity, (sum, value) => sum + value); - - // act - var result = Tensor.Sum(source); - - // assert - result.Should().Be(T.CreateChecked(expected)); - } - - [Theory] - [MemberData(nameof(SumData))] - public void Sum_Short_Should_Succeed(int count) - => Sum_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void Sum_Int_Should_Succeed(int count) - => Sum_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void Sum_Long_Should_Succeed(int count) - => Sum_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void Sum_Half_Should_Succeed(int count) - => Sum_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void Sum_Float_Should_Succeed(int count) - => Sum_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void Sum_Double_Should_Succeed(int count) - => Sum_Should_Succeed(count); - -} diff --git a/src/NetFabric.Numerics.Tensors.UnitTests/SumTripletsTests.cs b/src/NetFabric.Numerics.Tensors.UnitTests/SumTripletsTests.cs deleted file mode 100644 index 3211fba..0000000 --- a/src/NetFabric.Numerics.Tensors.UnitTests/SumTripletsTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Numerics.Tensors.UnitTests; - -public class SumTripletsTests -{ - public static TheoryData SumData - => new() { 0, 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 }; - - static void SumTriplets_Should_Succeed(int count) - where T : struct, INumber - { - // arrange - var source = Enumerable.Range(0, count) - .Select(value => new MyVector3(T.CreateChecked(value), T.CreateChecked(value + 1), T.CreateChecked(value + 2))) - .ToArray(); - var expected = source - .Aggregate(MyVector3.AdditiveIdentity, (sum, value) => sum + value); - - // act - var result = new MyVector3(Tensor.SumTriplets(MemoryMarshal.Cast, T>(source))); - - // assert - result.Should().Be(expected); - } - - [Theory] - [MemberData(nameof(SumData))] - public void SumTriplets_Short_Should_Succeed(int count) - => SumTriplets_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumTriplets_Int_Should_Succeed(int count) - => SumTriplets_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumTriplets_Long_Should_Succeed(int count) - => SumTriplets_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumTriplets_Half_Should_Succeed(int count) - => SumTriplets_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumTriplets_Float_Should_Succeed(int count) - => SumTriplets_Should_Succeed(count); - - [Theory] - [MemberData(nameof(SumData))] - public void SumTriplets_Double_Should_Succeed(int count) - => SumTriplets_Should_Succeed(count); -} diff --git a/src/NetFabric.Numerics.Tensors/Add.cs b/src/NetFabric.Numerics.Tensors/Add.cs deleted file mode 100644 index fa14774..0000000 --- a/src/NetFabric.Numerics.Tensors/Add.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - /// - /// Adds a scalar value to each element of the source span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The scalar value to add. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - public static void Add(ReadOnlySpan x, T y, Span destination) - where T : struct, IAdditionOperators - => Apply>(x, y, destination); - - /// - /// Adds a scalar value to each element of the source span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The tuple of two values to add. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - /// - /// This method can be used to calculate the addition of 2D vectors. - /// - public static void Add(ReadOnlySpan x, ValueTuple y, Span destination) - where T : struct, IAdditionOperators - => Apply>(x, y, destination); - - /// - /// Adds a scalar value to each element of the source span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The tuple of three values to add. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - /// - /// This method can be used to calculate the addition of 3D vectors. - /// - public static void Add(ReadOnlySpan x, ValueTuple y, Span destination) - where T : struct, IAdditionOperators - => Apply>(x, y, destination); - - /// - /// Adds corresponding elements of two source spans and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The first source span. - /// The second source span. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - public static void Add(ReadOnlySpan x, ReadOnlySpan y, Span destination) - where T : struct, IAdditionOperators - => Apply>(x, y, destination); -} diff --git a/src/NetFabric.Numerics.Tensors/AddMultiply.cs b/src/NetFabric.Numerics.Tensors/AddMultiply.cs deleted file mode 100644 index c0475d2..0000000 --- a/src/NetFabric.Numerics.Tensors/AddMultiply.cs +++ /dev/null @@ -1,162 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - /// - /// Adds each element of a span to a scalar value then multiply by another scalar value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The scalar value to add. - /// The scalar value to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - public static void AddMultiply(ReadOnlySpan x, T y, T z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); - - /// - /// Adds each element of a span to a scalar value then multiply by another scalar value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The tuple of two values to add. - /// The tuple of two values to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - /// - /// This method can be used to calculate the addition and multiplication of 2D vectors. - /// - public static void AddMultiply(ReadOnlySpan x, ValueTuple y, ValueTuple z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); - - /// - /// Adds each element of a span to a scalar value then multiply by another scalar value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The tuple of three values to add. - /// The tuple of three values to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - /// - /// This method can be used to calculate the addition and multiplication of 3D vectors. - /// - public static void AddMultiply(ReadOnlySpan x, ValueTuple y, ValueTuple z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); - - /// - /// Adds each element of a span to a scalar value then multiply by then respective element of another span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The scalar value to add. - /// The span of values to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - public static void AddMultiply(ReadOnlySpan x, T y, ReadOnlySpan z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); - - /// - /// Adds each element of a span to a scalar value then multiply by then respective element of another span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The tuple of two values to add. - /// The span of values to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - /// - /// This method can be used to calculate the addition and multiplication of 2D vectors. - /// - public static void AddMultiply(ReadOnlySpan x, ValueTuple y, ReadOnlySpan z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); - - /// - /// Adds each element of a span to a scalar value then multiply by then respective element of another span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The tuple of three values to add. - /// The span of values to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - /// - /// This method can be used to calculate the addition and multiplication of 3D vectors. - /// - public static void AddMultiply(ReadOnlySpan x, ValueTuple y, ReadOnlySpan z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); - - /// - /// Adds each element of a span to the respective element of another span then multiply by a scalar value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The span of values to add. - /// The scalar value to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - public static void AddMultiply(ReadOnlySpan x, ReadOnlySpan y, T z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); - - /// - /// Adds each element of a span to the respective element of another span then multiply by a scalar value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The span of values to add. - /// The tuple of two values to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - /// - /// This method can be used to calculate the addition and multiplication of 2D vectors. - /// - public static void AddMultiply(ReadOnlySpan x, ReadOnlySpan y, ValueTuple z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); - - /// - /// Adds each element of a span to the respective element of another span then multiply by a scalar value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The span of values to add. - /// The tuple of three values to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - /// - /// This method can be used to calculate the addition and multiplication of 3D vectors. - /// - public static void AddMultiply(ReadOnlySpan x, ReadOnlySpan y, ValueTuple z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); - - /// - /// Adds each element of a span to respective element on a second span then multiply by the respective element of a third element and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The span of values to add. - /// The span of values to multiply. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the addition operation is not defined for the type . - public static void AddMultiply(ReadOnlySpan x, ReadOnlySpan y, ReadOnlySpan z, Span destination) - where T : struct, IAdditionOperators, IMultiplyOperators - => Apply>(x, y, z, destination); -} diff --git a/src/NetFabric.Numerics.Tensors/Aggregate.cs b/src/NetFabric.Numerics.Tensors/Aggregate.cs deleted file mode 100644 index 56ac8e2..0000000 --- a/src/NetFabric.Numerics.Tensors/Aggregate.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - - /// - /// Aggregates the elements of a using the specified . - /// - /// The type of the elements in the . - /// The type of the aggregation operator. - /// The to aggregate. - /// The aggregated value. - public static T Aggregate(ReadOnlySpan source) - where T : struct - where TOperator : struct, IAggregationOperator - { - var result = TOperator.Identity; - ref var sourceRef = ref MemoryMarshal.GetReference(source); - - if (Vector.IsHardwareAccelerated && Vector.IsSupported) - { - var resultVector = new Vector(TOperator.Identity); - nint index = 0; - - if (source.Length >= Vector.Count) - { - var sourceVectors = MemoryMarshal.Cast>(source); - - ref var sourceVectorsRef = ref MemoryMarshal.GetReference(sourceVectors); - for (nint indexVector = 0; indexVector < sourceVectors.Length; indexVector++) - resultVector = TOperator.Invoke(resultVector, Unsafe.Add(ref sourceVectorsRef, indexVector)); - - index = source.Length - (source.Length % Vector.Count); - } - - for (; index < source.Length; index++) - result = TOperator.Invoke(result, Unsafe.Add(ref sourceRef, index)); - - return TOperator.ResultSelector(result, resultVector); - } - else - { - for (nint index = 0; index < source.Length; index++) - result = TOperator.Invoke(result, Unsafe.Add(ref sourceRef, index)); - - return result; - } - } -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/AggregatePairs.cs b/src/NetFabric.Numerics.Tensors/AggregatePairs.cs deleted file mode 100644 index 3d1f032..0000000 --- a/src/NetFabric.Numerics.Tensors/AggregatePairs.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; - -namespace NetFabric.Numerics -{ - public static partial class Tensor - { - - /// - /// Aggregates pairs of elements in a using the specified . - /// - /// The type of the elements in the . - /// The type of the aggregation operator. - /// The containing the elements to aggregate. - /// A representing the aggregated pairs. - /// Thrown when the span does not have an even size. - public static ValueTuple AggregatePairs(ReadOnlySpan source) - where T : struct - where TOperator : struct, IAggregationPairsOperator - { - if (source.Length % 2 is not 0) - Throw.ArgumentException(nameof(source), "source span must have an even size."); - - var result = TOperator.Identity; - ref var sourceRef = ref MemoryMarshal.GetReference(source); - - if (Vector.IsHardwareAccelerated && Vector.IsSupported) - { - var resultVector = GetVector(TOperator.Identity); - - nint index = 0; - - if (Vector.Count > 2 && - Vector.Count % 2 is 0 && - source.Length >= Vector.Count) - { - var sourceVectors = MemoryMarshal.Cast>(source); - - ref var sourceVectorsRef = ref MemoryMarshal.GetReference(sourceVectors); - for (nint indexVector = 0; indexVector < sourceVectors.Length; indexVector++) - resultVector = TOperator.Invoke(resultVector, Unsafe.Add(ref sourceVectorsRef, indexVector)); - - index = source.Length - (source.Length % Vector.Count); - } - - for (; index < source.Length; index += 2) - { - result.Item1 = TOperator.Invoke(result.Item1, Unsafe.Add(ref sourceRef, index)); - result.Item2 = TOperator.Invoke(result.Item2, Unsafe.Add(ref sourceRef, index + 1)); - } - - return TOperator.ResultSelector(result, resultVector); - } - else - { - for (nint index = 0; index < source.Length; index += 2) - { - result.Item1 = TOperator.Invoke(result.Item1, Unsafe.Add(ref sourceRef, index)); - result.Item2 = TOperator.Invoke(result.Item2, Unsafe.Add(ref sourceRef, index + 1)); - } - - return result; - } - } - } -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/AggregateTriplets.cs b/src/NetFabric.Numerics.Tensors/AggregateTriplets.cs deleted file mode 100644 index 69611f1..0000000 --- a/src/NetFabric.Numerics.Tensors/AggregateTriplets.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace NetFabric.Numerics -{ - public static partial class Tensor - { - /// - /// Aggregates triplets of elements from a using the specified . - /// - /// The type of the elements in the . - /// The type of the aggregation operator. - /// The to aggregate triplets from. - /// A containing the aggregated triplets. - /// Thrown when the size of the span is not a multiple of 3. - public static ValueTuple AggregateTriplets(ReadOnlySpan source) - where T : struct - where TOperator : struct, IAggregationTripletsOperator - { - if (source.Length % 3 is not 0) - Throw.ArgumentException(nameof(source), "source span must have a size multiple of 3."); - - var result = TOperator.Seed; - - ref var sourceRef = ref MemoryMarshal.GetReference(source); - for (nint index = 0; index < source.Length; index += 3) - { - result.Item1 = TOperator.Invoke(result.Item1, Unsafe.Add(ref sourceRef, index)); - result.Item2 = TOperator.Invoke(result.Item2, Unsafe.Add(ref sourceRef, index + 1)); - result.Item3 = TOperator.Invoke(result.Item3, Unsafe.Add(ref sourceRef, index + 2)); - } - - return result; - } - } -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/ApplyBinary.cs b/src/NetFabric.Numerics.Tensors/ApplyBinary.cs deleted file mode 100644 index 020126d..0000000 --- a/src/NetFabric.Numerics.Tensors/ApplyBinary.cs +++ /dev/null @@ -1,189 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - public static void Apply(ReadOnlySpan x, ReadOnlySpan y, Span destination) - where T : struct - where TOperator : struct, IBinaryOperator - { - if(x.Length != y.Length) - Throw.ArgumentException(nameof(y), "x and y spans must have the same length."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if(SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - if(SpansOverlapAndAreNotSame(y, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with y."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var yVectors = MemoryMarshal.Cast>(y); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var yVectorsRef = ref MemoryMarshal.GetReference(yVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - Unsafe.Add(ref yVectorsRef, indexVector)); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var yRef = ref MemoryMarshal.GetReference(y); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index++) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - Unsafe.Add(ref yRef, index)); - } - } - - public static void Apply(ReadOnlySpan x, T y, Span destination) - where T : struct - where TOperator : struct, IBinaryOperator - { - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if(SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var valueVector = new Vector(y); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - valueVector); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index++) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - y); - } - } - - public static void Apply(ReadOnlySpan x, ValueTuple y, Span destination) - where T : struct - where TOperator : struct, IBinaryOperator - { - if (x.Length % 2 is not 0) - Throw.ArgumentException(nameof(x), "x span must have an even size."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if (SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - Vector.Count > 2 && - Vector.Count % 2 is 0 && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var valueVector = GetVector(y); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - valueVector); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index += 2) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - y.Item1); - Unsafe.Add(ref destinationRef, index + 1) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 1), - y.Item2); - } - } - - public static void Apply(ReadOnlySpan x, ValueTuple y, Span destination) - where T : struct - where TOperator : struct, IBinaryOperator - { - if (x.Length % 3 is not 0) - Throw.ArgumentException(nameof(x), "x span must have a size multiple of 3."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if (SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (nint index = 0; index < x.Length; index += 3) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - y.Item1); - Unsafe.Add(ref destinationRef, index + 1) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 1), - y.Item2); - Unsafe.Add(ref destinationRef, index + 2) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 2), - y.Item3); - } - } - -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/ApplyTernary.cs b/src/NetFabric.Numerics.Tensors/ApplyTernary.cs deleted file mode 100644 index f8a0e64..0000000 --- a/src/NetFabric.Numerics.Tensors/ApplyTernary.cs +++ /dev/null @@ -1,519 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - public static void Apply(ReadOnlySpan x, ReadOnlySpan y, ReadOnlySpan z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if(x.Length != y.Length || x.Length != z.Length) - Throw.ArgumentException(nameof(x), "x, y and z spans must have the same length."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if(SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - if(SpansOverlapAndAreNotSame(y, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with y."); - if(SpansOverlapAndAreNotSame(z, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with z."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var yVectors = MemoryMarshal.Cast>(y); - var zVectors = MemoryMarshal.Cast>(z); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var yVectorsRef = ref MemoryMarshal.GetReference(yVectors); - ref var zVectorsRef = ref MemoryMarshal.GetReference(zVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - Unsafe.Add(ref yVectorsRef, indexVector), - Unsafe.Add(ref zVectorsRef, indexVector)); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var yRef = ref MemoryMarshal.GetReference(y); - ref var zRef = ref MemoryMarshal.GetReference(z); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index++) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - Unsafe.Add(ref yRef, index), - Unsafe.Add(ref zRef, index)); - } - } - - public static void Apply(ReadOnlySpan x, T y, ReadOnlySpan z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if(x.Length != z.Length) - Throw.ArgumentException(nameof(x), "x and z spans must have the same length."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if(SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - if(SpansOverlapAndAreNotSame(z, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with z."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var yVector = new Vector(y); - var zVectors = MemoryMarshal.Cast>(z); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var zVectorsRef = ref MemoryMarshal.GetReference(zVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - yVector, - Unsafe.Add(ref zVectorsRef, indexVector)); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var zRef = ref MemoryMarshal.GetReference(z); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index++) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - y, - Unsafe.Add(ref zRef, index)); - } - } - - public static void Apply(ReadOnlySpan x, ValueTuple y, ReadOnlySpan z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if (x.Length % 2 is not 0) - Throw.ArgumentException(nameof(x), "x span must have an even size."); - if (x.Length != z.Length) - Throw.ArgumentException(nameof(x), "x and z spans must have the same length."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if (SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - if (SpansOverlapAndAreNotSame(z, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with z."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - Vector.Count > 2 && - Vector.Count % 2 is 0 && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var yVector = GetVector(y); - var zVectors = MemoryMarshal.Cast>(z); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var zVectorsRef = ref MemoryMarshal.GetReference(zVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - yVector, - Unsafe.Add(ref zVectorsRef, indexVector)); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var zRef = ref MemoryMarshal.GetReference(z); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index += 2) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - y.Item1, - Unsafe.Add(ref zRef, index)); - Unsafe.Add(ref destinationRef, index + 1) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 1), - y.Item2, - Unsafe.Add(ref zRef, index + 1)); - } - } - - public static void Apply(ReadOnlySpan x, ValueTuple y, ReadOnlySpan z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if (x.Length % 3 is not 0) - Throw.ArgumentException(nameof(x), "x span must have a size multiple of 3."); - if (x.Length != z.Length) - Throw.ArgumentException(nameof(x), "x and z spans must have the same length."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if (SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - if (SpansOverlapAndAreNotSame(z, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with z."); - - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var zRef = ref MemoryMarshal.GetReference(z); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (nint index = 0; index < x.Length; index += 3) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - y.Item1, - Unsafe.Add(ref zRef, index)); - Unsafe.Add(ref destinationRef, index + 1) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 1), - y.Item2, - Unsafe.Add(ref zRef, index + 1)); - Unsafe.Add(ref destinationRef, index + 2) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 2), - y.Item3, - Unsafe.Add(ref zRef, index + 2)); - } - } - - public static void Apply(ReadOnlySpan x, ReadOnlySpan y, T z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if(x.Length != y.Length) - Throw.ArgumentException(nameof(x), "x and y spans must have the same length."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if(SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - if(SpansOverlapAndAreNotSame(y, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with y."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var yVectors = MemoryMarshal.Cast>(y); - var zVector = new Vector(z); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var yVectorsRef = ref MemoryMarshal.GetReference(yVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - Unsafe.Add(ref yVectorsRef, indexVector), - zVector); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var yRef = ref MemoryMarshal.GetReference(y); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index++) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - Unsafe.Add(ref yRef, index), - z); - } - } - - public static void Apply(ReadOnlySpan x, ReadOnlySpan y, ValueTuple z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if (x.Length % 2 is not 0) - Throw.ArgumentException(nameof(x), "x span must have an even size."); - if (x.Length != y.Length) - Throw.ArgumentException(nameof(x), "x and y spans must have the same length."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if (SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - if (SpansOverlapAndAreNotSame(y, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with y."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - Vector.Count > 2 && - Vector.Count % 2 is 0 && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var yVectors = MemoryMarshal.Cast>(y); - var zVector = GetVector(z); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var yVectorsRef = ref MemoryMarshal.GetReference(yVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - Unsafe.Add(ref yVectorsRef, indexVector), - zVector); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var yRef = ref MemoryMarshal.GetReference(y); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index += 2) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - Unsafe.Add(ref yRef, index), - z.Item1); - Unsafe.Add(ref destinationRef, index + 1) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 1), - Unsafe.Add(ref yRef, index + 1), - z.Item2); - } - } - - public static void Apply(ReadOnlySpan x, ReadOnlySpan y, ValueTuple z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if (x.Length % 3 is not 0) - Throw.ArgumentException(nameof(x), "x span must have a size multiple of 3."); - if (x.Length != y.Length) - Throw.ArgumentException(nameof(x), "x and y spans must have the same length."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if (SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - if (SpansOverlapAndAreNotSame(y, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with y."); - - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var yRef = ref MemoryMarshal.GetReference(y); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (nint index = 0; index < x.Length; index += 3) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - Unsafe.Add(ref yRef, index), - z.Item1); - Unsafe.Add(ref destinationRef, index + 1) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 1), - Unsafe.Add(ref yRef, index + 1), - z.Item2); - Unsafe.Add(ref destinationRef, index + 2) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 2), - Unsafe.Add(ref yRef, index + 2), - z.Item3); - } - } - - public static void Apply(ReadOnlySpan x, T y, T z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if(SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var yVector = new Vector(y); - var zVector = new Vector(z); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - yVector, - zVector); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index++) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - y, - z); - } - } - - public static void Apply(ReadOnlySpan x, ValueTuple y, ValueTuple z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if (x.Length % 2 is not 0) - Throw.ArgumentException(nameof(x), "x span must have an even size."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if (SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - Vector.Count > 2 && - Vector.Count % 2 is 0 && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var xVectors = MemoryMarshal.Cast>(x); - var yVector = GetVector(y); - var zVector = GetVector(z); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < xVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref xVectorsRef, indexVector), - yVector, - zVector); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index += 2) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - y.Item1, - z.Item1); - Unsafe.Add(ref destinationRef, index + 1) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 1), - y.Item2, - z.Item2); - } - } - - public static void Apply(ReadOnlySpan x, ValueTuple y, ValueTuple z, Span destination) - where T : struct - where TOperator : struct, ITernaryOperator - { - if (x.Length % 3 is not 0) - Throw.ArgumentException(nameof(x), "x span must have a size multiple of 3."); - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if (SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - - ref var xRef = ref MemoryMarshal.GetReference(x); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (nint index = 0; index < x.Length; index += 3) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref xRef, index), - y.Item1, - z.Item1); - Unsafe.Add(ref destinationRef, index + 1) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 1), - y.Item2, - z.Item2); - Unsafe.Add(ref destinationRef, index + 2) = TOperator.Invoke( - Unsafe.Add(ref xRef, index + 2), - y.Item3, - z.Item3); - } - } -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/ApplyUnary.cs b/src/NetFabric.Numerics.Tensors/ApplyUnary.cs deleted file mode 100644 index 94cf166..0000000 --- a/src/NetFabric.Numerics.Tensors/ApplyUnary.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - public static void Apply(ReadOnlySpan x, Span destination) - where T : struct - where TOperator : struct, IUnaryOperator - { - if (x.Length > destination.Length) - Throw.ArgumentException(nameof(destination), "Destination span is too small."); - if(SpansOverlapAndAreNotSame(x, destination)) - Throw.ArgumentException(nameof(destination), "Destination span overlaps with x."); - - // Initialize the index to 0. - nint index = 0; - - // Check if hardware acceleration and Vector support are available, - // and if the length of the x is greater than the Vector.Count. - if (Vector.IsHardwareAccelerated && - Vector.IsSupported && - x.Length >= Vector.Count) - { - // Cast the spans to vectors for hardware acceleration. - var sourceVectors = MemoryMarshal.Cast>(x); - var destinationVectors = MemoryMarshal.Cast>(destination); - - // Iterate through the vectors. - ref var sourceVectorsRef = ref MemoryMarshal.GetReference(sourceVectors); - ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors); - for (nint indexVector = 0; indexVector < sourceVectors.Length; indexVector++) - { - Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke( - Unsafe.Add(ref sourceVectorsRef, indexVector)); - } - - // Update the index to the end of the last complete vector. - index = x.Length - (x.Length % Vector.Count); - } - - // Iterate through the remaining elements. - ref var sourceRef = ref MemoryMarshal.GetReference(x); - ref var destinationRef = ref MemoryMarshal.GetReference(destination); - for (; index < x.Length; index++) - { - Unsafe.Add(ref destinationRef, index) = TOperator.Invoke( - Unsafe.Add(ref sourceRef, index)); - } - } - -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Average.cs b/src/NetFabric.Numerics.Tensors/Average.cs deleted file mode 100644 index 2a4dc1a..0000000 --- a/src/NetFabric.Numerics.Tensors/Average.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - /// - /// Computes the average of a span of values. - /// - /// The type of the values in the span. - /// The span of values. - /// The average value. - /// - /// The span must contain at least one value. - /// - public static T? Average(ReadOnlySpan source) - where T : struct, INumberBase, IAdditionOperators, IAdditiveIdentity, IDivisionOperators - => source.Length is 0 - ? null - : Sum(source) / T.CreateChecked(source.Length); -} diff --git a/src/NetFabric.Numerics.Tensors/Divide.cs b/src/NetFabric.Numerics.Tensors/Divide.cs deleted file mode 100644 index 5728446..0000000 --- a/src/NetFabric.Numerics.Tensors/Divide.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - /// - /// Divides each element of the left span by the right value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the left operands. - /// The right operand. - /// The span to store the result. - /// Thrown when the right value is zero. - public static void Divide(ReadOnlySpan left, T right, Span destination) - where T : struct, IDivisionOperators - => Apply>(left, right, destination); - - /// - /// Divides each element of the left span by the right value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the left operands. - /// The right operand tuple. - /// The span to store the result. - /// Thrown when any component of the right tuple is zero. /// - /// - /// This method can be used to calculate the division of 2D vectors. - /// - public static void Divide(ReadOnlySpan left, ValueTuple right, Span destination) - where T : struct, IDivisionOperators - => Apply>(left, right, destination); - - /// - /// Divides each element of the left span by the right value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the left operands. - /// The right operand tuple. - /// The span to store the result. - /// Thrown when any component of the right tuple is zero. - /// - /// This method can be used to calculate the division of 3D vectors. - /// - public static void Divide(ReadOnlySpan left, ValueTuple right, Span destination) - where T : struct, IDivisionOperators - => Apply>(left, right, destination); - - /// - /// Divides each element of the left span by the corresponding element of the right span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the left operands. - /// The span containing the right operands. - /// The span to store the result. - /// Thrown when any element of the right span is zero. - public static void Divide(ReadOnlySpan left, ReadOnlySpan right, Span destination) - where T : struct, IDivisionOperators - => Apply>(left, right, destination); -} diff --git a/src/NetFabric.Numerics.Tensors/ITensorOperation.cs b/src/NetFabric.Numerics.Tensors/ITensorOperation.cs deleted file mode 100644 index 7eec5db..0000000 --- a/src/NetFabric.Numerics.Tensors/ITensorOperation.cs +++ /dev/null @@ -1,141 +0,0 @@ -namespace NetFabric.Numerics; - -/// -/// Represents a unary operator that operates on a single value or vector. -/// -/// The type of the value or vector. -public interface IUnaryOperator - where T : struct -{ - /// - /// Applies the unary operator to the specified value. - /// - /// The value to apply the operator to. - /// The result of applying the operator to the value. - static abstract T Invoke(T x); - - /// - /// Applies the unary operator to the specified vector. - /// - /// The vector to apply the operator to. - /// The result of applying the operator to the vector. - static abstract Vector Invoke(Vector x); -} - -/// -/// Represents a binary operator that operates on two values or vectors. -/// -/// The type of the values or vectors. -public interface IBinaryOperator - where T : struct -{ - /// - /// Applies the binary operator to the specified values. - /// - /// The first value to apply the operator to. - /// The second value to apply the operator to. - /// The result of applying the operator to the values. - static abstract T Invoke(T x, T y); - - /// - /// Applies the binary operator to the specified vectors. - /// - /// The first vector to apply the operator to. - /// The second vector to apply the operator to. - /// The result of applying the operator to the vectors. - static abstract Vector Invoke(Vector x, Vector y); -} - -/// -/// Represents a ternary operator that operates on three values or vectors. -/// -/// The type of the values or vectors. -public interface ITernaryOperator - where T : struct -{ - /// - /// Applies the ternary operator to the specified values. - /// - /// The first value to apply the operator to. - /// The second value to apply the operator to. - /// The third value to apply the operator to. - /// The result of applying the operator to the values. - static abstract T Invoke(T x, T y, T z); - - /// - /// Applies the ternary operator to the specified vectors. - /// - /// The first vector to apply the operator to. - /// The second vector to apply the operator to. - /// The third vector to apply the operator to. - /// The result of applying the operator to the vectors. - static abstract Vector Invoke(Vector x, Vector y, Vector z); -} - -/// -/// Represents an aggregation operator that operates on two values or vectors and produces a single result. -/// -/// The type of the values or vectors. -public interface IAggregationOperator - : IBinaryOperator - where T : struct -{ - /// - /// Gets the identity value for the type and operation to be performed. - /// - static virtual T Identity - => Throw.NotSupportedException(); - - /// - /// Combines the specified value with the vector to produce a new value. - /// - /// The current value. - /// The vector to combine with the value. - /// The result of combining the value with the vector. - static abstract T ResultSelector(T value, Vector vector); -} - -/// -/// Represents an aggregation operator that operates on two values or vectors and produces a pair of results. -/// -/// The type of the values or vectors. -public interface IAggregationPairsOperator : IBinaryOperator - where T : struct -{ - /// - /// Gets the identity value for the type and operation to be performed. - /// - static virtual ValueTuple Identity - => Throw.NotSupportedException>(); - - /// - /// Combines the specified values with the vector to produce a new pair of values. - /// - /// The current pair of values. - /// The vector to combine with the values. - /// The result of combining the values with the vector. - static abstract ValueTuple ResultSelector(ValueTuple value, Vector vector); -} - -/// -/// Represents an aggregation operator that operates on two values or vectors and produces a triplet of results. -/// -/// The type of the values or vectors. -public interface IAggregationTripletsOperator - : IBinaryOperator - where T : struct -{ - /// - /// Gets the seed value for the aggregation operation. - /// - static virtual ValueTuple Seed - => Throw.NotSupportedException>(); - - /// - /// Combines the specified values with the vector to produce a new triplet of values. - /// - /// The current triplet of values. - /// The vector to combine with the values. - /// The result of combining the values with the vector. - static abstract ValueTuple ResultSelector(ValueTuple value, Vector vector); -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Multiply.cs b/src/NetFabric.Numerics.Tensors/Multiply.cs deleted file mode 100644 index 919568c..0000000 --- a/src/NetFabric.Numerics.Tensors/Multiply.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - /// - /// Multiplies each element of the left span by the right value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the left operands. - /// The right operand. - /// The span to store the result. - /// Thrown when the spans have different lengths. - public static void Multiply(ReadOnlySpan left, T right, Span destination) - where T : struct, IMultiplyOperators - => Apply>(left, right, destination); - - /// - /// Multiplies each element of the left span by the right value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the left operands. - /// The right tuple operand. - /// The span to store the result. - /// Thrown when the spans have different lengths. - /// - /// This method can be used to calculate the division of 2D vectors. - /// - public static void Multiply(ReadOnlySpan left, ValueTuple right, Span destination) - where T : struct, IMultiplyOperators - => Apply>(left, right, destination); - - /// - /// Multiplies each element of the left span by the right value and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the left operands. - /// The right tuple operand. - /// The span to store the result. - /// Thrown when the spans have different lengths. - /// - /// This method can be used to calculate the division of 3D vectors. - /// - public static void Multiply(ReadOnlySpan left, ValueTuple right, Span destination) - where T : struct, IMultiplyOperators - => Apply>(left, right, destination); - - /// - /// Multiplies each element of the left span by the corresponding element of the right span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the left operands. - /// The span containing the right operands. - /// The span to store the result. - /// Thrown when the spans have different lengths. - public static void Multiply(ReadOnlySpan left, ReadOnlySpan right, Span destination) - where T : struct, IMultiplyOperators - => Apply>(left, right, destination); -} diff --git a/src/NetFabric.Numerics.Tensors/Negate.cs b/src/NetFabric.Numerics.Tensors/Negate.cs deleted file mode 100644 index ce2e44f..0000000 --- a/src/NetFabric.Numerics.Tensors/Negate.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - /// - /// Negates the each element in the source span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the type does not implement the interface. - public static void Negate(ReadOnlySpan left, Span destination) - where T : struct, IUnaryNegationOperators - => Apply>(left, destination); -} diff --git a/src/NetFabric.Numerics.Tensors/NetFabric.Numerics.Tensors.csproj b/src/NetFabric.Numerics.Tensors/NetFabric.Numerics.Tensors.csproj deleted file mode 100644 index 110689c..0000000 --- a/src/NetFabric.Numerics.Tensors/NetFabric.Numerics.Tensors.csproj +++ /dev/null @@ -1,53 +0,0 @@ - - - - NetFabric.Numerics.Tensors - net8.0 - true - - Provides methods for performing mathematical operations over tensors represented as spans. - These methods are accelerated to use SIMD (Single instruction, multiple data) operations supported by the CPU where available. - - 1.0.0 - Icon.png - LICENSE - README.md - intrinsics, tensors - https://netfabric.github.io/NetFabric.Numerics/ - - - NetFabric.Numerics - true - true - snupkg - - - - - - - - - - true - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Operators/AddMultiplyOperator.cs b/src/NetFabric.Numerics.Tensors/Operators/AddMultiplyOperator.cs deleted file mode 100644 index 123670f..0000000 --- a/src/NetFabric.Numerics.Tensors/Operators/AddMultiplyOperator.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace NetFabric.Numerics -{ - /// - /// Represents an operator that performs addition and multiplication operations on three operands. - /// - /// The type of the operands. - public readonly struct AddMultiplyOperator : ITernaryOperator - where T : struct, IAdditionOperators, IMultiplyOperators - { - /// - /// Invokes the operator on three operands. - /// - /// The first operand. - /// The second operand. - /// The third operand. - /// The result of the addition and multiplication operations. - public static T Invoke(T x, T y, T z) - => (x + y) * z; - - /// - /// Invokes the operator on three vector operands. - /// - /// The first vector operand. - /// The second vector operand. - /// The third vector operand. - /// The result of the addition and multiplication operations. - public static Vector Invoke(Vector x, Vector y, Vector z) - => (x + y) * z; - } -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Operators/AddOperator.cs b/src/NetFabric.Numerics.Tensors/Operators/AddOperator.cs deleted file mode 100644 index b28174a..0000000 --- a/src/NetFabric.Numerics.Tensors/Operators/AddOperator.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace NetFabric.Numerics; - -/// -/// Represents an add operator for a specified type. -/// -/// The type of the values to add. -public readonly struct AddOperator - : IBinaryOperator - where T : struct, IAdditionOperators -{ - /// - /// Adds two values of type . - /// - /// The first value to add. - /// The second value to add. - /// The sum of and . - public static T Invoke(T x, T y) - => x + y; - - /// - /// Adds two vectors of type . - /// - /// The first vector to add. - /// The second vector to add. - /// The sum of and . - public static Vector Invoke(Vector x, Vector y) - => x + y; -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Operators/DivideOperator.cs b/src/NetFabric.Numerics.Tensors/Operators/DivideOperator.cs deleted file mode 100644 index 3cfc468..0000000 --- a/src/NetFabric.Numerics.Tensors/Operators/DivideOperator.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace NetFabric.Numerics; - -/// -/// Represents a divide operator for a specified type. -/// -/// The type of the operands. -public readonly struct DivideOperator - : IBinaryOperator - where T : struct, IDivisionOperators -{ - /// - /// Divides two values of type T. - /// - /// The dividend. - /// The divisor. - /// The result of the division. - public static T Invoke(T x, T y) - => x / y; - - /// - /// Divides two vectors of type T. - /// - /// The dividend vector. - /// The divisor vector. - /// The result of the division. - public static Vector Invoke(Vector x, Vector y) - => x / y; -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Operators/MultiplyAddOperator.cs b/src/NetFabric.Numerics.Tensors/Operators/MultiplyAddOperator.cs deleted file mode 100644 index 5eca120..0000000 --- a/src/NetFabric.Numerics.Tensors/Operators/MultiplyAddOperator.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace NetFabric.Numerics; - -/// -/// Represents a multiply-add operator for a given type. -/// -/// The type of the values. -public readonly struct MultiplyAddOperator - : ITernaryOperator - where T : struct, IAdditionOperators, IMultiplyOperators -{ - /// - /// Computes the result of multiplying two values and adding a third value. - /// - /// The first value to multiply. - /// The second value to multiply. - /// The value to add. - /// The result of multiplying and and adding . - public static T Invoke(T x, T y, T z) - => (x * y) + z; - - /// - /// Computes the result of multiplying two vectors element-wise and adding a third vector element-wise. - /// - /// The first vector to multiply. - /// The second vector to multiply. - /// The vector to add. - /// The result of multiplying and element-wise and adding element-wise. - public static Vector Invoke(Vector x, Vector y, Vector z) - => (x * y) + z; -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Operators/MultiplyOperator.cs b/src/NetFabric.Numerics.Tensors/Operators/MultiplyOperator.cs deleted file mode 100644 index c0ace69..0000000 --- a/src/NetFabric.Numerics.Tensors/Operators/MultiplyOperator.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace NetFabric.Numerics; - -/// -/// Represents a multiply operator for a specified type. -/// -/// The type of the operands and result. -public readonly struct MultiplyOperator - : IBinaryOperator - where T : struct, IMultiplyOperators -{ - /// - /// Multiplies two values of type . - /// - /// The first value. - /// The second value. - /// The result of multiplying and . - public static T Invoke(T x, T y) - => x * y; - - /// - /// Multiplies two vectors of type . - /// - /// The first vector. - /// The second vector. - /// The result of multiplying and . - public static Vector Invoke(Vector x, Vector y) - => x * y; -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Operators/NegateOperator.cs b/src/NetFabric.Numerics.Tensors/Operators/NegateOperator.cs deleted file mode 100644 index 890e371..0000000 --- a/src/NetFabric.Numerics.Tensors/Operators/NegateOperator.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace NetFabric.Numerics; - -/// -/// Represents a unary negate operator. -/// -/// The type of the operand. -public readonly struct NegateOperator - : IUnaryOperator - where T : struct, IUnaryNegationOperators -{ - /// - /// Negates the specified value. - /// - /// The value to negate. - /// The negated value. - public static T Invoke(T x) - => -x; - - /// - /// Negates the specified vector. - /// - /// The vector to negate. - /// The negated vector. - public static Vector Invoke(Vector x) - => -x; -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Operators/SquareOperator.cs b/src/NetFabric.Numerics.Tensors/Operators/SquareOperator.cs deleted file mode 100644 index 007ee79..0000000 --- a/src/NetFabric.Numerics.Tensors/Operators/SquareOperator.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace NetFabric.Numerics; - -/// -/// Represents a square operator that performs squaring operations on values of type . -/// -/// The type of values to square. -public readonly struct SquareOperator - : IUnaryOperator - where T : struct, IMultiplyOperators -{ - /// - /// Squares the specified value. - /// - /// The value to square. - /// The squared value. - public static T Invoke(T x) - => x * x; - - /// - /// Squares each element of the specified vector. - /// - /// The vector to square. - /// A new vector with each element squared. - public static Vector Invoke(Vector x) - => x * x; -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Operators/SubtractOperator.cs b/src/NetFabric.Numerics.Tensors/Operators/SubtractOperator.cs deleted file mode 100644 index 93d7358..0000000 --- a/src/NetFabric.Numerics.Tensors/Operators/SubtractOperator.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace NetFabric.Numerics; - -/// -/// Represents a subtract operator for a specified type. -/// -/// The type of the operands. -public readonly struct SubtractOperator - : IBinaryOperator - where T : struct, ISubtractionOperators -{ - /// - /// Subtracts two values of type T. - /// - /// The first value. - /// The second value. - /// The result of the subtraction. - public static T Invoke(T x, T y) - => x - y; - - /// - /// Subtracts two vectors of type T. - /// - /// The first vector. - /// The second vector. - /// The result of the subtraction. - public static Vector Invoke(Vector x, Vector y) - => x - y; -} diff --git a/src/NetFabric.Numerics.Tensors/Operators/SumOperator.cs b/src/NetFabric.Numerics.Tensors/Operators/SumOperator.cs deleted file mode 100644 index d5b4b63..0000000 --- a/src/NetFabric.Numerics.Tensors/Operators/SumOperator.cs +++ /dev/null @@ -1,111 +0,0 @@ -namespace NetFabric.Numerics -{ - /// - /// Represents an operator that performs the sum aggregation operation on a tensor. - /// - /// The type of the tensor elements. - public readonly struct SumOperator : IAggregationOperator - where T : struct, IAdditiveIdentity, IAdditionOperators - { - /// - /// Gets the seed value for the sum operation. - /// - public static T Identity => T.AdditiveIdentity; - - /// - /// Computes the result of the sum operation for a single value and a vector. - /// - /// The value to be added to the sum. - /// The vector to be summed. - /// The result of the sum operation. - public static T ResultSelector(T value, Vector vector) - => Vector.Sum(vector) + value; - - /// - /// Computes the sum of two values. - /// - /// The first value to be added. - /// The second value to be added. - /// The sum of the two values. - public static T Invoke(T x, T y) - => x + y; - - /// - /// Computes the sum of two vectors. - /// - /// The first vector to be added. - /// The second vector to be added. - /// The sum of the two vectors. - public static Vector Invoke(Vector x, Vector y) - => x + y; - } - - /// - /// Represents an operator that performs the sum aggregation operation on pairs of elements in a tensor. - /// - /// The type of the tensor elements. - public readonly struct SumPairsOperator : IAggregationPairsOperator - where T : struct, IAdditiveIdentity, IAdditionOperators - { - /// - /// Gets the seed value for the sum operation on pairs. - /// - public static ValueTuple Identity => (T.AdditiveIdentity, T.AdditiveIdentity); - - /// - /// Computes the result of the sum operation on pairs for a value and a vector. - /// - /// The value to be added to the sum. - /// The vector to be summed. - /// The result of the sum operation on pairs. - public static ValueTuple ResultSelector(ValueTuple value, Vector vector) - { - for (var index = 0; index < Vector.Count; index += 2) - { - value.Item1 += vector[index]; - value.Item2 += vector[index + 1]; - } - return value; - } - - /// - /// Computes the sum of two values. - /// - /// The first value to be added. - /// The second value to be added. - /// The sum of the two values. - public static T Invoke(T x, T y) - => x + y; - - /// - /// Computes the sum of two vectors. - /// - /// The first vector to be added. - /// The second vector to be added. - /// The sum of the two vectors. - public static Vector Invoke(Vector x, Vector y) - => x + y; - } - - public readonly struct SumTripletsOperator : IAggregationTripletsOperator - where T : struct, IAdditiveIdentity, IAdditionOperators - { - public static ValueTuple Seed => (T.AdditiveIdentity, T.AdditiveIdentity, T.AdditiveIdentity); - - public static ValueTuple ResultSelector(ValueTuple value, Vector vector) - { - // for (var index = 0; index < Vector.Count; index += 3) - // { - // value.Item1 += vector[index]; - // value.Item2 += vector[index + 1]; - // } - return value; - } - - public static T Invoke(T x, T y) - => x + y; - - public static Vector Invoke(Vector x, Vector y) - => x + y; - } -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/README.md b/src/NetFabric.Numerics.Tensors/README.md deleted file mode 100644 index 277730b..0000000 --- a/src/NetFabric.Numerics.Tensors/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# NetFabric.Numerics.Tensors - -This project is a part of the NetFabric.Numerics library and focuses on tensors. Tensors are multi-dimensional arrays commonly used in mathematical and scientific computations. diff --git a/src/NetFabric.Numerics.Tensors/Square.cs b/src/NetFabric.Numerics.Tensors/Square.cs deleted file mode 100644 index 42a7a73..0000000 --- a/src/NetFabric.Numerics.Tensors/Square.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - /// - /// Squares each element in the source span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The source span. - /// The destination span. - /// Thrown when the source and destination spans have different lengths. - /// Thrown when the type does not implement the interface. - public static void Square(ReadOnlySpan left, Span destination) - where T : struct, IMultiplyOperators - => Apply>(left, destination); -} \ No newline at end of file diff --git a/src/NetFabric.Numerics.Tensors/Subtract.cs b/src/NetFabric.Numerics.Tensors/Subtract.cs deleted file mode 100644 index c7aef97..0000000 --- a/src/NetFabric.Numerics.Tensors/Subtract.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - /// - /// Subtracts a scalar value from each element of the left span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the elements to subtract from. - /// The scalar value to subtract from each element. - /// The span to store the result in. - /// Thrown when the subtraction operation is not supported for the specified type. - public static void Subtract(ReadOnlySpan left, T right, Span destination) - where T : struct, ISubtractionOperators - => Apply>(left, right, destination); - - /// - /// Subtracts a scalar value from each element of the left span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the elements to subtract from. - /// The tuple of two values to subtract from each element. - /// The span to store the result in. - /// Thrown when the subtraction operation is not supported for the specified type. - /// - /// This method can be used to calculate the division of 2D vectors. - /// - public static void Subtract(ReadOnlySpan left, ValueTuple right, Span destination) - where T : struct, ISubtractionOperators - => Apply>(left, right, destination); - - /// - /// Subtracts a scalar value from each element of the left span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the elements to subtract from. - /// The tuple of three values to subtract from each element. - /// The span to store the result in. - /// Thrown when the subtraction operation is not supported for the specified type. - /// - /// This method can be used to calculate the division of 3D vectors. - /// - public static void Subtract(ReadOnlySpan left, ValueTuple right, Span destination) - where T : struct, ISubtractionOperators - => Apply>(left, right, destination); - - /// - /// Subtracts each element of the right span from the corresponding element of the left span and stores the result in the destination span. - /// - /// The type of the elements in the spans. - /// The span containing the elements to subtract from. - /// The span containing the elements to subtract. - /// The span to store the result in. - /// Thrown when the subtraction operation is not supported for the specified type. - public static void Subtract(ReadOnlySpan left, ReadOnlySpan right, Span destination) - where T : struct, ISubtractionOperators - => Apply>(left, right, destination); -} diff --git a/src/NetFabric.Numerics.Tensors/Sum.cs b/src/NetFabric.Numerics.Tensors/Sum.cs deleted file mode 100644 index 7803cb6..0000000 --- a/src/NetFabric.Numerics.Tensors/Sum.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - /// - /// Computes the sum of a span of values. - /// - /// The type of the elements in the span. - /// The input span. - /// The sum of the elements. - /// - /// This method requires the type to implement the and interfaces. - /// - public static T Sum(ReadOnlySpan source) - where T : struct, IAdditionOperators, IAdditiveIdentity - => Aggregate>(source); - - /// - /// Computes the sum of pairs of values in a span. - /// - /// The type of the elements in the span. - /// The input span. - /// A tuple containing the sum of pairs of elements. - /// - /// This method can be used to calculate the sum of 2D vectors. - /// This method requires the type to implement the and interfaces. - /// - public static ValueTuple SumPairs(ReadOnlySpan source) - where T : struct, IAdditionOperators, IAdditiveIdentity - => AggregatePairs>(source); - - /// - /// Computes the sum of triplets of values in a span. - /// - /// The type of the elements in the span. - /// The input span. - /// A tuple containing the sum of triplets of elements. - /// - /// This method can be used to calculate the sum of 3D vectors. - /// This method requires the type to implement the and interfaces. - /// - public static ValueTuple SumTriplets(ReadOnlySpan source) - where T : struct, IAdditionOperators, IAdditiveIdentity - => AggregateTriplets>(source); -} diff --git a/src/NetFabric.Numerics.Tensors/Tensor.cs b/src/NetFabric.Numerics.Tensors/Tensor.cs deleted file mode 100644 index 1c26bec..0000000 --- a/src/NetFabric.Numerics.Tensors/Tensor.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace NetFabric.Numerics; - -public static partial class Tensor -{ - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool SpansOverlapAndAreNotSame(ReadOnlySpan span1, ReadOnlySpan span2) - => !Unsafe.AreSame(ref MemoryMarshal.GetReference(span1), ref MemoryMarshal.GetReference(span2)) && span1.Overlaps(span2); - - static Vector GetVector(ValueTuple tuple) - where T : struct - { - var array = new T[Vector.Count]; - ref var resultRef = ref MemoryMarshal.GetReference(array); - for (nint indexVector = 0; indexVector(array); - } - -} \ No newline at end of file