-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from gfoidl/simd-reduction
Better Simd reduction
- Loading branch information
Showing
15 changed files
with
174 additions
and
19 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
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<add key="dotnet-myget" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" /> | ||
</packageSources> | ||
</configuration> |
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
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
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
40 changes: 40 additions & 0 deletions
40
tests/gfoidl.Stochastics.Tests/VectorHelperTests/ReduceMinMax.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,40 @@ | ||
using System; | ||
using System.Numerics; | ||
using NUnit.Framework; | ||
|
||
namespace gfoidl.Stochastics.Tests.VectorHelperTests | ||
{ | ||
[TestFixture] | ||
public class ReduceMinMax | ||
{ | ||
[Test, Repeat(10)] | ||
public void Min_Max_Vectors_given___correct_Min_Max() | ||
{ | ||
var rnd = new Random(); | ||
var minArr = new double[Vector<double>.Count]; | ||
var maxArr = new double[Vector<double>.Count]; | ||
double min = double.MaxValue; | ||
double max = double.MinValue; | ||
|
||
for (int j = 0; j < Vector<double>.Count; ++j) | ||
{ | ||
minArr[j] = rnd.NextDouble(); | ||
maxArr[j] = rnd.NextDouble(); | ||
|
||
if (minArr[j] < min) min = minArr[j]; | ||
if (maxArr[j] > max) max = maxArr[j]; | ||
} | ||
|
||
double expectedMin = min; | ||
double expectedMax = max; | ||
|
||
var minVec = new Vector<double>(minArr); | ||
var maxVec = new Vector<double>(maxArr); | ||
|
||
VectorHelper.ReduceMinMax(minVec, maxVec, ref min, ref max); | ||
|
||
Assert.AreEqual(expectedMin, min, 1e-10); | ||
Assert.AreEqual(expectedMax, max, 1e-10); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/gfoidl.Stochastics.Tests/VectorHelperTests/ReduceSum.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,37 @@ | ||
using System; | ||
using System.Numerics; | ||
using NUnit.Framework; | ||
|
||
namespace gfoidl.Stochastics.Tests.VectorHelperTests | ||
{ | ||
[TestFixture] | ||
public class ReduceSum | ||
{ | ||
[Test, Repeat(10)] | ||
public void Random_Vector_given___Correct_Sum_Reduction() | ||
{ | ||
if (Vector.IsHardwareAccelerated) | ||
{ | ||
var rnd = new Random(); | ||
var arr = new double[Vector<double>.Count]; | ||
double expected = 0; | ||
|
||
for (int j = 0; j < arr.Length; ++j) | ||
{ | ||
arr[j] = rnd.NextDouble(); | ||
expected += arr[j]; | ||
} | ||
|
||
var vector = new Vector<double>(arr); | ||
|
||
double actual = vector.ReduceSum(); | ||
|
||
Assert.AreEqual(expected, actual, 1e-10); | ||
} | ||
else | ||
{ | ||
Assert.Ignore("Vector.IsHardwareAccelerated is false"); | ||
} | ||
} | ||
} | ||
} |
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