-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
1,807 additions
and
1,255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 31 additions & 67 deletions
98
src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,64 @@ | ||
using System.Linq; | ||
|
||
namespace NetFabric.Numerics.Tensors.UnitTests; | ||
namespace NetFabric.Numerics.Tensors.UnitTests; | ||
|
||
public class AddMultiplyTests | ||
{ | ||
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 }; | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Short_Should_Succeed(int count) | ||
static void AddMultiply_Should_Succeed<T>(int count) | ||
where T : struct, INumber<T> | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (short)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (short)(value + 1)).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => (short)(value + 2)).ToArray(); | ||
var result = new short[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (short)((value + value + 1) * (value + 2))).ToArray(); | ||
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<short>(x, y, z, result); | ||
Tensor.AddMultiply<T>(x, y, z, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Int_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => value + 1).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => value + 2).ToArray(); | ||
var result = new int[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (value + value + 1) * (value + 2)).ToArray(); | ||
|
||
// act | ||
Tensor.AddMultiply<int>(x, y, z, result); | ||
public void AddMultiply_Short_Should_Succeed(int count) | ||
=> AddMultiply_Should_Succeed<short>(count); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Int_Should_Succeed(int count) | ||
=> AddMultiply_Should_Succeed<int>(count); | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Long_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (long)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (long)(value + 1)).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => (long)(value + 2)).ToArray(); | ||
var result = new long[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (long)((value + value + 1) * (value + 2))).ToArray(); | ||
=> AddMultiply_Should_Succeed<long>(count); | ||
|
||
// act | ||
Tensor.AddMultiply<long>(x, y, z, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Half_Should_Succeed(int count) | ||
=> AddMultiply_Should_Succeed<Half>(count); | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Float_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (float)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (float)(value + 1)).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => (float)(value + 2)).ToArray(); | ||
var result = new float[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (float)((value + value + 1) * (value + 2))).ToArray(); | ||
|
||
// act | ||
Tensor.AddMultiply<float>(x, y, z, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
=> AddMultiply_Should_Succeed<float>(count); | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Double_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (double)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (double)(value + 1)).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => (double)(value + 2)).ToArray(); | ||
var result = new double[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (double)((value + value + 1) * (value + 2))).ToArray(); | ||
|
||
// act | ||
Tensor.AddMultiply<double>(x, y, z, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
=> AddMultiply_Should_Succeed<double>(count); | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTripletsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace NetFabric.Numerics.Tensors.UnitTests; | ||
|
||
public class AddMultiplyTripletsTests | ||
{ | ||
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 }; | ||
|
||
static void AddMultiply_Should_Succeed<T>(int count) | ||
where T : struct, INumber<T> | ||
{ | ||
// arrange | ||
var source = Enumerable.Range(0, count); | ||
var x = source | ||
.Select(value => new MyVector3<T>(T.CreateChecked(value), T.CreateChecked(value + 1), T.CreateChecked(value + 2))) | ||
.ToArray(); | ||
var y = source | ||
.Select(value => new MyVector3<T>(T.CreateChecked(value + 2), T.CreateChecked(value + 3), T.CreateChecked(value + 4))) | ||
.ToArray(); | ||
var z = source | ||
.Select(value => new MyVector3<T>(T.CreateChecked(value + 4), T.CreateChecked(value + 5), T.CreateChecked(value + 6))) | ||
.ToArray(); | ||
var result = new MyVector3<T>[count]; | ||
var expected = source | ||
.Select(value => new MyVector3<T>(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<MyVector3<T>, T>(x), | ||
MemoryMarshal.Cast<MyVector3<T>, T>(y), | ||
MemoryMarshal.Cast<MyVector3<T>, T>(z), | ||
MemoryMarshal.Cast<MyVector3<T>, T>(result)); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Short_Should_Succeed(int count) | ||
=> AddMultiply_Should_Succeed<short>(count); | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Int_Should_Succeed(int count) | ||
=> AddMultiply_Should_Succeed<int>(count); | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Long_Should_Succeed(int count) | ||
=> AddMultiply_Should_Succeed<long>(count); | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Half_Should_Succeed(int count) | ||
=> AddMultiply_Should_Succeed<Half>(count); | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Float_Should_Succeed(int count) | ||
=> AddMultiply_Should_Succeed<float>(count); | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Double_Should_Succeed(int count) | ||
=> AddMultiply_Should_Succeed<double>(count); | ||
|
||
} |
Oops, something went wrong.