diff --git a/src/MSUnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs b/src/MSUnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs deleted file mode 100644 index 127b9a73..00000000 --- a/src/MSUnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs +++ /dev/null @@ -1,402 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://numerics.mathdotnet.com -// http://github.com/mathnet/mathnet-numerics -// http://mathnetnumerics.codeplex.com -// -// Copyright (c) 2009-2010 Math.NET -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double -{ - using System; - using System.Collections.Generic; - using Algorithms.LinearAlgebra; - using LinearAlgebra.Double; - using Microsoft.VisualStudio.TestTools.UnitTesting; - - /// - /// Base class for linear algebra provider tests. - /// - [TestClass] - public abstract class LinearAlgebraProviderTests - { - /// - /// Gets or sets linear algebra provider to test. - /// - protected static ILinearAlgebraProvider Provider - { - get; - set; - } - - /// - /// The Y double test vector. - /// - private readonly double[] _y = new[] { 1.1, 2.2, 3.3, 4.4, 5.5 }; - - /// - /// The X double test vector. - /// - private readonly double[] _x = new[] { 6.6, 7.7, 8.8, 9.9, 10.1 }; - - /// - /// Test matrix to use. - /// - private readonly IDictionary _matrices = new Dictionary - { - { "Singular3x3", new DenseMatrix(new[,] { { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 } }) }, - { "Square3x3", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3 }, { 0.0, 1.1, 2.2 }, { -4.4, 5.5, 6.6 } }) }, - { "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 } }) } - }; - - /// - /// Can add a vector to scaled vector - /// - [TestMethod] - public void CanAddVectorToScaledVectorDouble() - { - var result = new double[_y.Length]; - Array.Copy(_y, result, _y.Length); - - Provider.AddVectorToScaledVector(result, 0, _x); - for (var i = 0; i < _y.Length; i++) - { - Assert.AreEqual(_y[i], result[i]); - } - - Array.Copy(_y, result, _y.Length); - Provider.AddVectorToScaledVector(result, 1, _x); - for (var i = 0; i < _y.Length; i++) - { - Assert.AreEqual(_y[i] + _x[i], result[i]); - } - - Array.Copy(_y, result, _y.Length); - Provider.AddVectorToScaledVector(result, Math.PI, _x); - for (var i = 0; i < _y.Length; i++) - { - Assert.AreEqual(_y[i] + (Math.PI * _x[i]), result[i]); - } - } - - /// - /// Can scale an array. - /// - [TestMethod] - public void CanScaleArray() - { - var result = new double[_y.Length]; - - Array.Copy(_y, result, _y.Length); - Provider.ScaleArray(1, result); - for (var i = 0; i < _y.Length; i++) - { - Assert.AreEqual(_y[i], result[i]); - } - - Array.Copy(_y, result, _y.Length); - Provider.ScaleArray(Math.PI, result); - for (var i = 0; i < _y.Length; i++) - { - Assert.AreEqual(_y[i] * Math.PI, result[i]); - } - } - - /// - /// Can compute the dot product. - /// - [TestMethod] - public void CanComputeDotProduct() - { - var result = Provider.DotProduct(_x, _y); - AssertHelpers.AlmostEqual(152.35, result, 15); - } - - /// - /// Can add two arrays. - /// - [TestMethod] - public void CanAddArrays() - { - var result = new double[_y.Length]; - Provider.AddArrays(_x, _y, result); - for (var i = 0; i < result.Length; i++) - { - Assert.AreEqual(_x[i] + _y[i], result[i]); - } - } - - /// - /// Can subtract two arrays. - /// - [TestMethod] - public void CanSubtractArrays() - { - var result = new double[_y.Length]; - Provider.SubtractArrays(_x, _y, result); - for (var i = 0; i < result.Length; i++) - { - Assert.AreEqual(_x[i] - _y[i], result[i]); - } - } - - /// - /// Can pointwise multiply two arrays. - /// - [TestMethod] - public void CanPointWiseMultiplyArrays() - { - var result = new double[_y.Length]; - Provider.PointWiseMultiplyArrays(_x, _y, result); - for (var i = 0; i < result.Length; i++) - { - Assert.AreEqual(_x[i] * _y[i], result[i]); - } - } - - /// - /// Can compute L1 norm. - /// - [TestMethod] - public void CanComputeMatrixL1Norm() - { - var matrix = _matrices["Square3x3"]; - var work = new double[matrix.RowCount]; - var norm = Provider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data, work); - AssertHelpers.AlmostEqual(12.1, norm, 6); - } - - /// - /// Can compute Frobenius norm. - /// - [TestMethod] - public void CanComputeMatrixFrobeniusNorm() - { - var matrix = _matrices["Square3x3"]; - var work = new double[matrix.RowCount]; - var norm = Provider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data, work); - AssertHelpers.AlmostEqual(10.777754868246, norm, 8); - } - - /// - /// Can compute Infinity norm. - /// - [TestMethod] - public void CanComputeMatrixInfinityNorm() - { - var matrix = _matrices["Square3x3"]; - var work = new double[matrix.RowCount]; - var norm = Provider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data, work); - Assert.AreEqual(16.5, norm); - } - - /// - /// Can compute L1 norm using a work array. - /// - [TestMethod] - public void CanComputeMatrixL1NormWithWorkArray() - { - var matrix = _matrices["Square3x3"]; - var norm = Provider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data); - AssertHelpers.AlmostEqual(12.1, norm, 6); - } - - /// - /// Can compute Frobenius norm using a work array. - /// - [TestMethod] - public void CanComputeMatrixFrobeniusNormWithWorkArray() - { - var matrix = _matrices["Square3x3"]; - var norm = Provider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data); - AssertHelpers.AlmostEqual(10.777754868246, norm, 8); - } - - /// - /// Can compute Infinity norm using a work array. - /// - [TestMethod] - public void CanComputeMatrixInfinityNormWithWorkArray() - { - var matrix = _matrices["Square3x3"]; - var norm = Provider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data); - Assert.AreEqual(16.5, norm); - } - - /// - /// Can multiply two square matrices. - /// - [TestMethod] - public void CanMultiplySquareMatrices() - { - var x = _matrices["Singular3x3"]; - var y = _matrices["Square3x3"]; - var c = new DenseMatrix(x.RowCount, y.ColumnCount); - - Provider.MatrixMultiply(x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, c.Data); - - for (var i = 0; i < c.RowCount; i++) - { - for (var j = 0; j < c.ColumnCount; j++) - { - AssertHelpers.AlmostEqual(x.Row(i) * y.Column(j), c[i, j], 15); - } - } - } - - /// - /// Can multiply a wide and tall matrix. - /// - [TestMethod] - public void CanMultiplyWideAndTallMatrices() - { - var x = _matrices["Wide2x3"]; - var y = _matrices["Tall3x2"]; - var c = new DenseMatrix(x.RowCount, y.ColumnCount); - - Provider.MatrixMultiply(x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, c.Data); - - for (var i = 0; i < c.RowCount; i++) - { - for (var j = 0; j < c.ColumnCount; j++) - { - AssertHelpers.AlmostEqual(x.Row(i) * y.Column(j), c[i, j], 15); - } - } - } - - /// - /// Can multiply a tall and wide matrix. - /// - [TestMethod] - public void CanMultiplyTallAndWideMatrices() - { - var x = _matrices["Tall3x2"]; - var y = _matrices["Wide2x3"]; - var c = new DenseMatrix(x.RowCount, y.ColumnCount); - - Provider.MatrixMultiply(x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, c.Data); - - for (var i = 0; i < c.RowCount; i++) - { - for (var j = 0; j < c.ColumnCount; j++) - { - AssertHelpers.AlmostEqual(x.Row(i) * y.Column(j), c[i, j], 15); - } - } - } - - /// - /// Can multiply two square matrices. - /// - [TestMethod] - public void CanMultiplySquareMatricesWithUpdate() - { - var x = _matrices["Singular3x3"]; - var y = _matrices["Square3x3"]; - var c = new DenseMatrix(x.RowCount, y.ColumnCount); - - Provider.MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 2.2, x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, 1.0, c.Data); - - for (var i = 0; i < c.RowCount; i++) - { - for (var j = 0; j < c.ColumnCount; j++) - { - AssertHelpers.AlmostEqual(2.2 * x.Row(i) * y.Column(j), c[i, j], 15); - } - } - } - - /// - /// Can multiply a wide and tall matrix. - /// - [TestMethod] - public void CanMultiplyWideAndTallMatricesWithUpdate() - { - var x = _matrices["Wide2x3"]; - var y = _matrices["Tall3x2"]; - var c = new DenseMatrix(x.RowCount, y.ColumnCount); - - Provider.MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 2.2, x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, 1.0, c.Data); - - for (var i = 0; i < c.RowCount; i++) - { - for (var j = 0; j < c.ColumnCount; j++) - { - AssertHelpers.AlmostEqual(2.2 * x.Row(i) * y.Column(j), c[i, j], 15); - } - } - } - - /// - /// Can multiply a tall and wide matrix. - /// - [TestMethod] - public void CanMultiplyTallAndWideMatricesWithUpdate() - { - var x = _matrices["Tall3x2"]; - var y = _matrices["Wide2x3"]; - var c = new DenseMatrix(x.RowCount, y.ColumnCount); - - Provider.MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 2.2, x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, 1.0, c.Data); - - for (var i = 0; i < c.RowCount; i++) - { - for (var j = 0; j < c.ColumnCount; j++) - { - AssertHelpers.AlmostEqual(2.2 * x.Row(i) * y.Column(j), c[i, j], 15); - } - } - } - - /// - /// Can compute the Cholesky factorization. - /// - [TestMethod] - public void CanComputeCholeskyFactor() - { - var matrix = new double[] { 1, 1, 1, 1, 1, 5, 5, 5, 1, 5, 14, 14, 1, 5, 14, 15 }; - Provider.CholeskyFactor(matrix, 4); - Assert.AreEqual(matrix[0], 1); - Assert.AreEqual(matrix[1], 1); - Assert.AreEqual(matrix[2], 1); - Assert.AreEqual(matrix[3], 1); - Assert.AreEqual(matrix[4], 0); - Assert.AreEqual(matrix[5], 2); - Assert.AreEqual(matrix[6], 2); - Assert.AreEqual(matrix[7], 2); - Assert.AreEqual(matrix[8], 0); - Assert.AreEqual(matrix[9], 0); - Assert.AreEqual(matrix[10], 3); - Assert.AreEqual(matrix[11], 3); - Assert.AreEqual(matrix[12], 0); - Assert.AreEqual(matrix[13], 0); - Assert.AreEqual(matrix[14], 0); - Assert.AreEqual(matrix[15], 1); - } - } -} \ No newline at end of file diff --git a/src/MSUnitTests/LinearAlgebraProviderTests/Double/ManagedLinearAlgebraProviderTests.cs b/src/MSUnitTests/LinearAlgebraProviderTests/Double/ManagedLinearAlgebraProviderTests.cs deleted file mode 100644 index ac1e5223..00000000 --- a/src/MSUnitTests/LinearAlgebraProviderTests/Double/ManagedLinearAlgebraProviderTests.cs +++ /dev/null @@ -1,51 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://numerics.mathdotnet.com -// http://github.com/mathnet/mathnet-numerics -// http://mathnetnumerics.codeplex.com -// -// Copyright (c) 2009-2010 Math.NET -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double -{ - using Microsoft.VisualStudio.TestTools.UnitTesting; - - /// - /// Unit test container for the managed linear algebra provider. - /// - [TestClass] - public class ManagedLinearAlgebraProviderTests : LinearAlgebraProviderTests - { - /// - /// Sets the linear algebra provider to the managed one. - /// - /// The test context to use. - [ClassInitialize] - public static void SetProvider(TestContext context) - { - Provider = new Algorithms.LinearAlgebra.ManagedLinearAlgebraProvider(); - } - } -} diff --git a/src/MSUnitTests/MSUnitTests.csproj b/src/MSUnitTests/MSUnitTests.csproj index 0392e84f..3258e705 100644 --- a/src/MSUnitTests/MSUnitTests.csproj +++ b/src/MSUnitTests/MSUnitTests.csproj @@ -47,8 +47,8 @@ - - + + diff --git a/src/MathNet.Numerics.sln b/src/MathNet.Numerics.sln index 935903e9..0df10e2f 100644 --- a/src/MathNet.Numerics.sln +++ b/src/MathNet.Numerics.sln @@ -28,6 +28,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{4D50FB34 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{49EE74BD-301F-4C3B-B76A-07F90CC88CE7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilverlightUnitTests", "SilverlightUnitTests\SilverlightUnitTests.csproj", "{6271AB18-BFD3-4CC5-81E4-55E1F4BC10FB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilverlightUnitTests.Web", "SilverlightUnitTests.Web\SilverlightUnitTests.Web.csproj", "{477CCFEB-B5BF-496D-9449-6C8AD5A782AE}" +EndProject Global GlobalSection(TestCaseManagementSettings) = postSolution CategoryFile = MathNet.Numerics.vsmdi @@ -69,6 +73,14 @@ Global {624FB757-A724-4B0D-85EB-F0563CE43A33}.Debug|Any CPU.Build.0 = Debug|Any CPU {624FB757-A724-4B0D-85EB-F0563CE43A33}.Release|Any CPU.ActiveCfg = Release|Any CPU {624FB757-A724-4B0D-85EB-F0563CE43A33}.Release|Any CPU.Build.0 = Release|Any CPU + {6271AB18-BFD3-4CC5-81E4-55E1F4BC10FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6271AB18-BFD3-4CC5-81E4-55E1F4BC10FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6271AB18-BFD3-4CC5-81E4-55E1F4BC10FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6271AB18-BFD3-4CC5-81E4-55E1F4BC10FB}.Release|Any CPU.Build.0 = Release|Any CPU + {477CCFEB-B5BF-496D-9449-6C8AD5A782AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {477CCFEB-B5BF-496D-9449-6C8AD5A782AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {477CCFEB-B5BF-496D-9449-6C8AD5A782AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {477CCFEB-B5BF-496D-9449-6C8AD5A782AE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -79,5 +91,7 @@ Global {F2F8032B-A31D-4E33-A05E-F2CDCBFAA75D} = {4D50FB34-10BC-495A-8B2F-482E34B4D771} {624FB757-A724-4B0D-85EB-F0563CE43A33} = {4D50FB34-10BC-495A-8B2F-482E34B4D771} {8C9A5D3F-A20C-4D24-A09C-98E187A8D720} = {4D50FB34-10BC-495A-8B2F-482E34B4D771} + {6271AB18-BFD3-4CC5-81E4-55E1F4BC10FB} = {4D50FB34-10BC-495A-8B2F-482E34B4D771} + {477CCFEB-B5BF-496D-9449-6C8AD5A782AE} = {4D50FB34-10BC-495A-8B2F-482E34B4D771} EndGlobalSection EndGlobal