From 9fced6726678317e7033022c881081c8017fcc5b Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Thu, 4 Apr 2013 00:35:53 +0200 Subject: [PATCH] Alter parallelisation of matrix multiplication II - Unit Tests --- .../Complex/LinearAlgebraProviderTests.cs | 25 +++++++++++++++--- .../Complex32/LinearAlgebraProviderTests.cs | 26 +++++++++++++++---- .../Double/LinearAlgebraProviderTests.cs | 26 +++++++++++++++---- .../Single/LinearAlgebraProviderTests.cs | 26 +++++++++++++++---- 4 files changed, 84 insertions(+), 19 deletions(-) diff --git a/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs index cdd11c21..0ddbdaa1 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs @@ -26,14 +26,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex { - using System; - using System.Collections.Generic; - using System.Numerics; using Algorithms.LinearAlgebra; + using Distributions; using LinearAlgebra.Complex; using LinearAlgebra.Generic; using LinearAlgebra.Generic.Factorization; using NUnit.Framework; + using System; + using System.Collections.Generic; + using System.Numerics; /// /// Base class for linear algebra provider tests. @@ -51,6 +52,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex /// private readonly Complex[] _x = new[] { new Complex(6.6, 0), 7.7, 8.8, 9.9, 10.1 }; + private static readonly IContinuousDistribution Dist = new Normal(); + /// /// Test matrix to use. /// @@ -61,7 +64,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex { "Square4x4", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3, -4.4 }, { 0.0, 1.1, 2.2, 3.3 }, { 1.0, 2.1, 6.2, 4.3 }, { -4.4, 5.5, 6.6, -7.7 } }) }, { "Singular4x4", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 } }) }, { "Tall3x2", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2 }, { 0.0, 1.1 }, { -4.4, 5.5 } }) }, - { "Wide2x3", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3 }, { 0.0, 1.1, 2.2 } }) } + { "Wide2x3", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3 }, { 0.0, 1.1, 2.2 } }) }, + { "Tall50000x10", DenseMatrix.CreateRandom(50000, 10, Dist) }, + { "Wide10x50000", DenseMatrix.CreateRandom(10, 50000, Dist) }, + { "Square1000x1000", DenseMatrix.CreateRandom(1000, 1000, Dist) } }; /// @@ -1682,6 +1688,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex AssertHelpers.AlmostEqual(test[1, 1], x[3], 14); } + [TestCase("Wide10x50000", "Tall50000x10")] + [TestCase("Square1000x1000", "Square1000x1000")] + [Timeout(1000 * 10)] + public void IsMatrixMultiplicationPerformant(string leftMatrixKey, string rightMatrixKey) + { + var leftMatrix = _matrices[leftMatrixKey]; + var rightMatrix = _matrices[rightMatrixKey]; + var result = leftMatrix * rightMatrix; + Assert.That(result, Is.Not.Null); + } + /// /// Checks to see if a matrix and array contain the same values. /// diff --git a/src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs index cbec627a..2c95c04f 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs @@ -24,17 +24,17 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra.Generic.Factorization; - namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32 { - using System; - using System.Collections.Generic; using Algorithms.LinearAlgebra; + using Distributions; using LinearAlgebra.Complex32; using LinearAlgebra.Generic; + using LinearAlgebra.Generic.Factorization; using Numerics; using NUnit.Framework; + using System; + using System.Collections.Generic; /// /// Base class for linear algebra provider tests. @@ -52,6 +52,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32 /// private readonly Complex32[] _x = new[] { new Complex32(6.6f, 0f), 7.7f, 8.8f, 9.9f, 10.1f }; + private static readonly IContinuousDistribution Dist = new Normal(); + /// /// Test matrix to use. /// @@ -62,7 +64,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32 { "Square4x4", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f, -4.4f }, { 0.0f, 1.1f, 2.2f, 3.3f }, { 1.0f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }) }, { "Singular4x4", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }) }, { "Tall3x2", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f }, { 0.0f, 1.1f }, { -4.4f, 5.5f } }) }, - { "Wide2x3", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f } }) } + { "Wide2x3", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f } }) }, + { "Tall50000x10", DenseMatrix.CreateRandom(50000, 10, Dist) }, + { "Wide10x50000", DenseMatrix.CreateRandom(10, 50000, Dist) }, + { "Square1000x1000", DenseMatrix.CreateRandom(1000, 1000, Dist) } }; /// @@ -1692,6 +1697,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32 AssertHelpers.AlmostEqual(test[1, 1], x[3], 5); } + [TestCase("Wide10x50000", "Tall50000x10")] + [TestCase("Square1000x1000", "Square1000x1000")] + [Timeout(1000 * 10)] + public void IsMatrixMultiplicationPerformant(string leftMatrixKey, string rightMatrixKey) + { + var leftMatrix = _matrices[leftMatrixKey]; + var rightMatrix = _matrices[rightMatrixKey]; + var result = leftMatrix * rightMatrix; + Assert.That(result, Is.Not.Null); + } + /// /// Checks to see if a matrix and array contain the same values. /// diff --git a/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs index 77ee4b27..5951e573 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs @@ -24,16 +24,16 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra.Generic.Factorization; - namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double { - using System; - using System.Collections.Generic; using Algorithms.LinearAlgebra; + using Distributions; using LinearAlgebra.Double; using LinearAlgebra.Generic; + using LinearAlgebra.Generic.Factorization; using NUnit.Framework; + using System; + using System.Collections.Generic; /// /// Base class for linear algebra provider tests. @@ -51,6 +51,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double /// private readonly double[] _x = new[] { 6.6, 7.7, 8.8, 9.9, 10.1 }; + private static readonly IContinuousDistribution Dist = new Normal(); + /// /// Test matrix to use. /// @@ -61,7 +63,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double { "Square4x4", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3, -4.4 }, { 0.0, 1.1, 2.2, 3.3 }, { 1.0, 2.1, 6.2, 4.3 }, { -4.4, 5.5, 6.6, -7.7 } }) }, { "Singular4x4", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 } }) }, { "Tall3x2", new DenseMatrix(new[,] { { -1.1, -2.2 }, { 0.0, 1.1 }, { -4.4, 5.5 } }) }, - { "Wide2x3", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3 }, { 0.0, 1.1, 2.2 } }) } + { "Wide2x3", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3 }, { 0.0, 1.1, 2.2 } }) }, + { "Tall50000x10", DenseMatrix.CreateRandom(50000, 10, Dist) }, + { "Wide10x50000", DenseMatrix.CreateRandom(10, 50000, Dist) }, + { "Square1000x1000", DenseMatrix.CreateRandom(1000, 1000, Dist) } }; /// @@ -1684,6 +1689,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double AssertHelpers.AlmostEqual(test[1, 1], x[3], 14); } + [TestCase("Wide10x50000", "Tall50000x10")] + [TestCase("Square1000x1000", "Square1000x1000")] + [Timeout(1000 * 10)] + public void IsMatrixMultiplicationPerformant(string leftMatrixKey, string rightMatrixKey) + { + var leftMatrix = _matrices[leftMatrixKey]; + var rightMatrix = _matrices[rightMatrixKey]; + var result = leftMatrix*rightMatrix; + Assert.That(result, Is.Not.Null); + } + /// /// Checks to see if a matrix and array contain the same values. /// diff --git a/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs index 67332a91..c7ebac4d 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs @@ -24,16 +24,16 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra.Generic.Factorization; - namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single { - using System; - using System.Collections.Generic; using Algorithms.LinearAlgebra; + using Distributions; using LinearAlgebra.Generic; + using LinearAlgebra.Generic.Factorization; using LinearAlgebra.Single; using NUnit.Framework; + using System; + using System.Collections.Generic; /// /// Base class for linear algebra provider tests. @@ -51,6 +51,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single /// private readonly float[] _x = new[] { 6.6f, 7.7f, 8.8f, 9.9f, 10.1f }; + private static readonly IContinuousDistribution Dist = new Normal(); + /// /// Test matrix to use. /// @@ -61,7 +63,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single { "Square4x4", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { 0.0f, 1.1f, 2.2f, 3.3f }, { 1.0f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }) }, { "Singular4x4", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }) }, { "Tall3x2", new DenseMatrix(new[,] { { -1.1f, -2.2f }, { 0.0f, 1.1f }, { -4.4f, 5.5f } }) }, - { "Wide2x3", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f } }) } + { "Wide2x3", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f } }) }, + { "Tall50000x10", DenseMatrix.CreateRandom(50000, 10, Dist) }, + { "Wide10x50000", DenseMatrix.CreateRandom(10, 50000, Dist) }, + { "Square1000x1000", DenseMatrix.CreateRandom(1000, 1000, Dist) } }; /// @@ -1691,6 +1696,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single AssertHelpers.AlmostEqual(test[1, 1], x[3], 6); } + [TestCase("Wide10x50000", "Tall50000x10")] + [TestCase("Square1000x1000", "Square1000x1000")] + [Timeout(1000 * 10)] + public void IsMatrixMultiplicationPerformant(string leftMatrixKey, string rightMatrixKey) + { + var leftMatrix = _matrices[leftMatrixKey]; + var rightMatrix = _matrices[rightMatrixKey]; + var result = leftMatrix * rightMatrix; + Assert.That(result, Is.Not.Null); + } + /// /// Checks to see if a matrix and array contain the same values. ///