Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/NetFabric.Numerics.Tensors.Benchmarks/AddBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AddBenchmarks
float[]? sourceFloat, otherFloat, resultFloat;
double[]? sourceDouble, otherDouble, resultDouble;

[Params(100)]
[Params(1_000)]
public int Count { get; set; }

[GlobalSetup]
Expand Down Expand Up @@ -75,7 +75,7 @@ public void System_Short()
[BenchmarkCategory("Short")]
[Benchmark]
public void NetFabric_Short()
=> TensorOperations.Add<short>(sourceShort!, otherShort!, resultShort!);
=> TensorOperations.Add(sourceShort!, otherShort!, resultShort!);

[BenchmarkCategory("Int")]
[Benchmark(Baseline = true)]
Expand All @@ -90,7 +90,7 @@ public void System_Int()
[BenchmarkCategory("Int")]
[Benchmark]
public void NetFabric_Int()
=> TensorOperations.Add<int>(sourceInt!, otherInt!, resultInt!);
=> TensorOperations.Add(sourceInt!, otherInt!, resultInt!);

[BenchmarkCategory("Long")]
[Benchmark(Baseline = true)]
Expand All @@ -105,7 +105,7 @@ public void System_Long()
[BenchmarkCategory("Long")]
[Benchmark]
public void NetFabric_Long()
=> TensorOperations.Add<long>(sourceLong!, otherLong!, resultLong!);
=> TensorOperations.Add(sourceLong!, otherLong!, resultLong!);

[BenchmarkCategory("Half")]
[Benchmark(Baseline = true)]
Expand All @@ -120,7 +120,7 @@ public void System_Half()
[BenchmarkCategory("Half")]
[Benchmark]
public void NetFabric_Half()
=> TensorOperations.Add<Half>(sourceHalf!, otherHalf!, resultHalf!);
=> TensorOperations.Add(sourceHalf!, otherHalf!, resultHalf!);

[BenchmarkCategory("Float")]
[Benchmark(Baseline = true)]
Expand All @@ -135,7 +135,7 @@ public void System_Float()
[BenchmarkCategory("Float")]
[Benchmark]
public void NetFabric_Float()
=> TensorOperations.Add<float>(sourceFloat!, otherFloat!, resultFloat!);
=> TensorOperations.Add(sourceFloat!, otherFloat!, resultFloat!);

[BenchmarkCategory("Double")]
[Benchmark(Baseline = true)]
Expand All @@ -150,5 +150,5 @@ public void System_Double()
[BenchmarkCategory("Double")]
[Benchmark]
public void NetFabric_Double()
=> TensorOperations.Add<double>(sourceDouble!, otherDouble!, resultDouble!);
=> TensorOperations.Add(sourceDouble!, otherDouble!, resultDouble!);
}
154 changes: 77 additions & 77 deletions src/NetFabric.Numerics.Tensors.Benchmarks/NegateBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class NegateBenchmarks
float[]? sourceFloat, resultFloat;
double[]? sourceDouble, resultDouble;

[Params(100)]
[Params(1_000)]
public int Count { get; set; }

[GlobalSetup]
Expand Down Expand Up @@ -63,80 +63,80 @@ public void System_Short()
[BenchmarkCategory("Short")]
[Benchmark]
public void NetFabric_Short()
=> TensorOperations.Negate<short>(sourceShort!, resultShort!);

[BenchmarkCategory("Int")]
[Benchmark(Baseline = true)]
public void Baseline_Int()
=> Baseline.Negate<int>(sourceInt!, resultInt!);

[BenchmarkCategory("Int")]
[Benchmark]
public void System_Int()
=> TensorPrimitives.Negate<int>(sourceInt!, resultInt!);

[BenchmarkCategory("Int")]
[Benchmark]
public void NetFabric_Int()
=> TensorOperations.Negate<int>(sourceInt!, resultInt!);

[BenchmarkCategory("Long")]
[Benchmark(Baseline = true)]
public void Baseline_Long()
=> Baseline.Negate<long>(sourceLong!, resultLong!);

[BenchmarkCategory("Long")]
[Benchmark]
public void System_Long()
=> TensorPrimitives.Negate<long>(sourceLong!, resultLong!);

[BenchmarkCategory("Long")]
[Benchmark]
public void NetFabric_Long()
=> TensorOperations.Negate<long>(sourceLong!, resultLong!);

[BenchmarkCategory("Half")]
[Benchmark(Baseline = true)]
public void Baseline_Half()
=> Baseline.Negate<Half>(sourceHalf!, resultHalf!);

[BenchmarkCategory("Half")]
[Benchmark]
public void System_Half()
=> TensorPrimitives.Negate<Half>(sourceHalf!, resultHalf!);

[BenchmarkCategory("Half")]
[Benchmark]
public void NetFabric_Half()
=> TensorOperations.Negate<Half>(sourceHalf!, resultHalf!);

[BenchmarkCategory("Float")]
[Benchmark(Baseline = true)]
public void Baseline_Float()
=> Baseline.Negate<float>(sourceFloat!, resultFloat!);

[BenchmarkCategory("Float")]
[Benchmark]
public void System_Float()
=> TensorPrimitives.Negate(sourceFloat!, resultFloat!);

[BenchmarkCategory("Float")]
[Benchmark]
public void NetFabric_Float()
=> TensorOperations.Negate<float>(sourceFloat!, resultFloat!);

[BenchmarkCategory("Double")]
[Benchmark(Baseline = true)]
public void Baseline_Double()
=> Baseline.Negate<double>(sourceDouble!, resultDouble!);

[BenchmarkCategory("Double")]
[Benchmark]
public void System_Double()
=> TensorPrimitives.Negate<double>(sourceDouble!, resultDouble!);

[BenchmarkCategory("Double")]
[Benchmark]
public void NetFabric_Double()
=> TensorOperations.Negate<double>(sourceDouble!, resultDouble!);
=> TensorOperations.Negate(sourceShort!, resultShort!);

// [BenchmarkCategory("Int")]
// [Benchmark(Baseline = true)]
// public void Baseline_Int()
// => Baseline.Negate<int>(sourceInt!, resultInt!);

// [BenchmarkCategory("Int")]
// [Benchmark]
// public void System_Int()
// => TensorPrimitives.Negate<int>(sourceInt!, resultInt!);

// [BenchmarkCategory("Int")]
// [Benchmark]
// public void NetFabric_Int()
// => TensorOperations.Negate(sourceInt!, resultInt!);

// [BenchmarkCategory("Long")]
// [Benchmark(Baseline = true)]
// public void Baseline_Long()
// => Baseline.Negate<long>(sourceLong!, resultLong!);

// [BenchmarkCategory("Long")]
// [Benchmark]
// public void System_Long()
// => TensorPrimitives.Negate<long>(sourceLong!, resultLong!);

// [BenchmarkCategory("Long")]
// [Benchmark]
// public void NetFabric_Long()
// => TensorOperations.Negate(sourceLong!, resultLong!);

// [BenchmarkCategory("Half")]
// [Benchmark(Baseline = true)]
// public void Baseline_Half()
// => Baseline.Negate<Half>(sourceHalf!, resultHalf!);

// [BenchmarkCategory("Half")]
// [Benchmark]
// public void System_Half()
// => TensorPrimitives.Negate<Half>(sourceHalf!, resultHalf!);

// [BenchmarkCategory("Half")]
// [Benchmark]
// public void NetFabric_Half()
// => TensorOperations.Negate(sourceHalf!, resultHalf!);

// [BenchmarkCategory("Float")]
// [Benchmark(Baseline = true)]
// public void Baseline_Float()
// => Baseline.Negate<float>(sourceFloat!, resultFloat!);

// [BenchmarkCategory("Float")]
// [Benchmark]
// public void System_Float()
// => TensorPrimitives.Negate(sourceFloat!, resultFloat!);

// [BenchmarkCategory("Float")]
// [Benchmark]
// public void NetFabric_Float()
// => TensorOperations.Negate(sourceFloat!, resultFloat!);

// [BenchmarkCategory("Double")]
// [Benchmark(Baseline = true)]
// public void Baseline_Double()
// => Baseline.Negate<double>(sourceDouble!, resultDouble!);

// [BenchmarkCategory("Double")]
// [Benchmark]
// public void System_Double()
// => TensorPrimitives.Negate<double>(sourceDouble!, resultDouble!);

// [BenchmarkCategory("Double")]
// [Benchmark]
// public void NetFabric_Double()
// => TensorOperations.Negate(sourceDouble!, resultDouble!);
}
13 changes: 7 additions & 6 deletions src/NetFabric.Numerics.Tensors.UnitTests/AddTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class AddTests
{
public static TheoryData<int> 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 };
=> 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, 1_001 };

static void Add_Should_Succeed<T>(int count)
where T : struct, INumber<T>
Expand All @@ -16,14 +16,15 @@ static void Add_Should_Succeed<T>(int count)
var random = new Random(42);
for (var index = 0; index < count; index++)
{
var value = random.Next(100);
x[index] = T.CreateChecked(value);
y[index] = T.CreateChecked(value + 1);
expected[index] = T.CreateChecked(value + value + 1);
var value1 = random.Next(100);
var value2 = random.Next(100);
x[index] = T.CreateChecked(value1);
y[index] = T.CreateChecked(value2);
expected[index] = T.CreateChecked(value1 + value2);
}

// act
TensorOperations.Add<T>(x, y, result);
TensorOperations.Add(x, y, result);

// assert
Assert.Equal(expected, result);
Expand Down
Loading