Browse Source

Tests: cleanup, simplifications

pull/303/head
Christoph Ruegg 12 years ago
parent
commit
36b568c5f1
  1. 1
      MathNet.Numerics.sln.DotSettings
  2. 73
      src/UnitTests/LinearAlgebraTests/Build.cs
  3. 4
      src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs
  4. 4
      src/UnitTests/LinearAlgebraTests/Complex/TestData.cs
  5. 7
      src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs
  6. 4
      src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs
  7. 4
      src/UnitTests/LinearAlgebraTests/Complex32/TestData.cs
  8. 7
      src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs
  9. 4
      src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs
  10. 4
      src/UnitTests/LinearAlgebraTests/Double/TestData.cs
  11. 7
      src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs
  12. 52
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs
  13. 20
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs
  14. 64
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs
  15. 42
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs
  16. 4
      src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs
  17. 4
      src/UnitTests/LinearAlgebraTests/Single/TestData.cs
  18. 7
      src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs
  19. 48
      src/UnitTests/LinearAlgebraTests/TestData.cs
  20. 61
      src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs
  21. 72
      src/UnitTests/LinearAlgebraTests/VectorStorageCombinatorsTests.cs
  22. 1
      src/UnitTests/UnitTests.csproj

1
MathNet.Numerics.sln.DotSettings

@ -102,6 +102,7 @@ OTHER DEALINGS IN THE SOFTWARE.
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SVD/@EntryIndexedValue">SVD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TFQMR/@EntryIndexedValue">TFQMR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WH/@EntryIndexedValue">WH</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>

73
src/UnitTests/LinearAlgebraTests/Build.cs

@ -1,73 +0,0 @@
// <copyright file="Build.cs" company="Math.NET">
// 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-2014 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.
// </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra.Storage;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
{
public enum VectorStorageType
{
DenseVector = 1,
SparseVector = 2
}
public static class Build
{
public static VectorStorage<T> VectorStorage<T>(VectorStorageType type, IEnumerable<T> data)
where T : struct, IEquatable<T>, IFormattable
{
switch (type)
{
case VectorStorageType.DenseVector:
return DenseVectorStorage<T>.OfEnumerable(data);
case VectorStorageType.SparseVector:
return SparseVectorStorage<T>.OfEnumerable(data);
default:
throw new NotSupportedException();
}
}
public static VectorStorage<T> VectorStorage<T>(VectorStorageType type, int length)
where T : struct, IEquatable<T>, IFormattable
{
switch (type)
{
case VectorStorageType.DenseVector:
return new DenseVectorStorage<T>(length);
case VectorStorageType.SparseVector:
return new SparseVectorStorage<T>(length);
default:
throw new NotSupportedException();
}
}
}
}

4
src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs

@ -42,9 +42,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
[TestFixture, Category("LA")]
public class MatrixStructureTheory : MatrixStructureTheory<Complex>
{
protected override Matrix<Complex> GetMatrix(TestMatrix matrix)
protected override Matrix<Complex> Get(TestMatrix matrix)
{
return TestData.GetMatrix(matrix);
return TestData.Matrix(matrix);
}
[Datapoints]

4
src/UnitTests/LinearAlgebraTests/Complex/TestData.cs

@ -44,7 +44,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
static readonly MatrixBuilder<Complex> M = Matrix<Complex>.Build;
static readonly VectorBuilder<Complex> V = Vector<Complex>.Build;
public static Matrix<Complex> GetMatrix(TestMatrix matrix)
public static Matrix<Complex> Matrix(TestMatrix matrix)
{
switch (matrix)
{
@ -68,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
}
}
public static Vector<Complex> GetVector(TestVector vector)
public static Vector<Complex> Vector(TestVector vector)
{
switch (vector)
{

7
src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs

@ -42,14 +42,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
[TestFixture, Category("LA")]
public class VectorArithmeticTheory : VectorArithmeticTheory<Complex>
{
protected override Vector<Complex> GetVector(TestVector vector)
protected override Vector<Complex> Get(TestVector vector)
{
return TestData.GetVector(vector);
return TestData.Vector(vector);
}
protected override Complex Minus(Complex value) { return -value; }
protected override Complex Add(Complex first, Complex second) { return first + second; }
[Datapoints]
TestVector[] _vectors =
{

4
src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs

@ -38,9 +38,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
[TestFixture, Category("LA")]
public class MatrixStructureTheory : MatrixStructureTheory<Complex32>
{
protected override Matrix<Complex32> GetMatrix(TestMatrix matrix)
protected override Matrix<Complex32> Get(TestMatrix matrix)
{
return TestData.GetMatrix(matrix);
return TestData.Matrix(matrix);
}
[Datapoints]

4
src/UnitTests/LinearAlgebraTests/Complex32/TestData.cs

@ -40,7 +40,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
static readonly MatrixBuilder<Complex32> M = Matrix<Complex32>.Build;
static readonly VectorBuilder<Complex32> V = Vector<Complex32>.Build;
public static Matrix<Complex32> GetMatrix(TestMatrix matrix)
public static Matrix<Complex32> Matrix(TestMatrix matrix)
{
switch (matrix)
{
@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
}
}
public static Vector<Complex32> GetVector(TestVector vector)
public static Vector<Complex32> Vector(TestVector vector)
{
switch (vector)
{

7
src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs

@ -38,14 +38,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
[TestFixture, Category("LA")]
public class VectorArithmeticTheory : VectorArithmeticTheory<Complex32>
{
protected override Vector<Complex32> GetVector(TestVector vector)
protected override Vector<Complex32> Get(TestVector vector)
{
return TestData.GetVector(vector);
return TestData.Vector(vector);
}
protected override Complex32 Minus(Complex32 value) { return -value; }
protected override Complex32 Add(Complex32 first, Complex32 second) { return first + second; }
[Datapoints]
TestVector[] _vectors =
{

4
src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs

@ -36,9 +36,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
[TestFixture, Category("LA")]
public class MatrixStructureTheory : MatrixStructureTheory<double>
{
protected override Matrix<double> GetMatrix(TestMatrix matrix)
protected override Matrix<double> Get(TestMatrix matrix)
{
return TestData.GetMatrix(matrix);
return TestData.Matrix(matrix);
}
[Datapoints]

4
src/UnitTests/LinearAlgebraTests/Double/TestData.cs

@ -38,7 +38,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
static readonly MatrixBuilder<double> M = Matrix<double>.Build;
static readonly VectorBuilder<double> V = Vector<double>.Build;
public static Matrix<double> GetMatrix(TestMatrix matrix)
public static Matrix<double> Matrix(TestMatrix matrix)
{
switch (matrix)
{
@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
}
}
public static Vector<double> GetVector(TestVector vector)
public static Vector<double> Vector(TestVector vector)
{
switch (vector)
{

7
src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs

@ -36,14 +36,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
[TestFixture, Category("LA")]
public class VectorArithmeticTheory : VectorArithmeticTheory<double>
{
protected override Vector<double> GetVector(TestVector vector)
protected override Vector<double> Get(TestVector vector)
{
return TestData.GetVector(vector);
return TestData.Vector(vector);
}
protected override double Minus(double value) { return -value; }
protected override double Add(double first, double second) { return first + second; }
[Datapoints]
TestVector[] _vectors =
{

52
src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs

@ -39,7 +39,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetFieldsByIndex(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Assert.That(() => matrix[0, 0], Throws.Nothing);
Assert.That(() => matrix[0, matrix.ColumnCount - 1], Throws.Nothing);
@ -53,7 +53,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetRow(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// First Row
var firstrow = matrix.Row(0);
@ -79,7 +79,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetRowIntoResult(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var row = Vector<T>.Build.Dense(matrix.ColumnCount);
matrix.Row(0, row);
@ -97,7 +97,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetRowWithRange(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// First Row, Columns 0..1
var firstrow = matrix.Row(0, 0, 2);
@ -134,7 +134,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetRowWithRangeIntoResult(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var row = Vector<T>.Build.Dense(matrix.ColumnCount - 1);
matrix.Row(0, 1, matrix.ColumnCount - 1, row);
@ -153,7 +153,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetColumn(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// First Column
var firstcol = matrix.Column(0);
@ -179,7 +179,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetColumnIntoResult(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var col = Vector<T>.Build.Dense(matrix.RowCount);
matrix.Column(0, col);
@ -197,7 +197,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetColumnWithRange(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// First Column, Rows 0..1
var firstcol = matrix.Column(0, 0, 2);
@ -234,7 +234,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetColumnWithRangeIntoResult(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var col = Vector<T>.Build.Dense(matrix.RowCount - 1);
matrix.Column(0, 1, matrix.RowCount - 1, col);
@ -253,7 +253,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanSetRow(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// First Row
var m = matrix.Clone();
@ -290,7 +290,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanSetRowArray(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// First Row
var m = matrix.Clone();
@ -325,7 +325,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanSetColumn(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// First Column
var m = matrix.Clone();
@ -362,7 +362,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanSetColumnArray(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// First Column
var m = matrix.Clone();
@ -397,7 +397,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetUpperTriangle(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var upper = matrix.UpperTriangle();
for (var i = 0; i < matrix.RowCount; i++)
@ -412,7 +412,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetUpperTriangleIntoResult(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var dense = Matrix<T>.Build.Dense(matrix.RowCount, matrix.ColumnCount);
matrix.UpperTriangle(dense);
@ -442,7 +442,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetLowerTriangle(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var upper = matrix.LowerTriangle();
for (var i = 0; i < matrix.RowCount; i++)
@ -457,7 +457,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetLowerTriangleIntoResult(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var dense = Matrix<T>.Build.Dense(matrix.RowCount, matrix.ColumnCount);
matrix.LowerTriangle(dense);
@ -487,7 +487,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetStrictlyUpperTriangle(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var upper = matrix.StrictlyUpperTriangle();
for (var i = 0; i < matrix.RowCount; i++)
@ -502,7 +502,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetStrictlyUpperTriangleIntoResult(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var dense = Matrix<T>.Build.Dense(matrix.RowCount, matrix.ColumnCount);
matrix.StrictlyUpperTriangle(dense);
@ -532,7 +532,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetStrictlyLowerTriangle(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var upper = matrix.StrictlyLowerTriangle();
for (var i = 0; i < matrix.RowCount; i++)
@ -547,7 +547,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetStrictlyLowerTriangleIntoResult(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var dense = Matrix<T>.Build.Dense(matrix.RowCount, matrix.ColumnCount);
matrix.StrictlyLowerTriangle(dense);
@ -577,7 +577,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetDiagonal(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var diag = matrix.Diagonal();
Assert.That(diag.Count, Is.EqualTo(Math.Min(matrix.RowCount, matrix.ColumnCount)));
@ -590,7 +590,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanSetDiagonal(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var m = matrix.Clone();
var v = CreateVectorFor(m, Math.Min(matrix.RowCount, matrix.ColumnCount));
@ -612,7 +612,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanSetDiagonalArray(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var m = matrix.Clone();
m.SetDiagonal(new T[Math.Min(matrix.RowCount, matrix.ColumnCount)]);
@ -633,7 +633,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetSubmatrix(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// Top Left Corner 2x2
var topleft = matrix.SubMatrix(0, 2, 0, 2);
@ -677,7 +677,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanSetSubmatrix(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// Top Left Corner 2x2
var topleft = CreateDenseFor(matrix, 2, 2);

20
src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs

@ -39,7 +39,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanMap(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Matrix<T> a = matrix.Map(x => x, Zeros.AllowSkip);
Assert.That(a, Is.EqualTo(matrix));
Assert.That(a.Storage.IsDense, Is.EqualTo(matrix.Storage.IsDense));
@ -68,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanMapIndexed(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Matrix<T> a = matrix.MapIndexed((i, j, x) =>
{
if (i != 0 || j != 1) Assert.That(matrix.At(i, j), Is.EqualTo(x));
@ -105,7 +105,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanMapInplace(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var a = matrix.Clone();
a.MapInplace(x => x, Zeros.AllowSkip);
Assert.That(a, Is.EqualTo(matrix));
@ -124,7 +124,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanMapIndexedInplace(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var a = matrix.Clone();
a.MapIndexedInplace((i, j, x) =>
{
@ -152,7 +152,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanMapSubMatrixToSame(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
T one = Matrix<T>.Build.One;
// Full Range - not forced
@ -176,7 +176,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanMapSubMatrixToDense(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
T one = Matrix<T>.Build.One;
// Full Range - not forced
@ -217,7 +217,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanMapSubMatrixToSparse(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
T one = Matrix<T>.Build.One;
// Full Range - filled, not forced
@ -267,7 +267,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanFoldRows(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// not forced
T[] rowSum = matrix.FoldByRow((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.AllowSkip);
@ -290,7 +290,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanFoldColumns(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
// not forced
T[] colSum = matrix.FoldByColumn((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.AllowSkip);
@ -313,7 +313,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanFold2(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var other = -matrix;
other.Multiply(Operator.Convert<int, T>(2), other);

64
src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs

@ -40,19 +40,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanPermuteRows(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Assume.That(matrix.Storage.IsFullyMutable);
var m = matrix.Clone();
var rnd = new System.Random(0);
var permutation = new Permutation(Enumerable.Range(0, matrix.RowCount).OrderBy(i => rnd.Next()).ToArray());
try
{
m.PermuteRows(permutation);
}
catch (InvalidOperationException)
{
Assert.Ignore("Matrix type {0} does not support permutations", matrix.GetType().FullName);
}
m.PermuteRows(permutation);
Assert.That(m, Is.Not.SameAs(matrix));
Assert.That(m.RowCount, Is.EqualTo(matrix.RowCount));
@ -70,19 +65,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanPermuteColumns(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Assume.That(matrix.Storage.IsFullyMutable);
var m = matrix.Clone();
var rnd = new System.Random(0);
var permutation = new Permutation(Enumerable.Range(0, matrix.ColumnCount).OrderBy(i => rnd.Next()).ToArray());
try
{
m.PermuteColumns(permutation);
}
catch (InvalidOperationException)
{
Assert.Ignore("Matrix type {0} does not support permutations", matrix.GetType().FullName);
}
m.PermuteColumns(permutation);
Assert.That(m, Is.Not.SameAs(matrix));
Assert.That(m.RowCount, Is.EqualTo(matrix.RowCount));
@ -100,7 +90,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanInsertRow(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var row = Vector<T>.Build.Random(matrix.ColumnCount, 0);
for (var position = 0; position < matrix.RowCount + 1; position++)
{
@ -137,7 +127,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanRemoveRow(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
for (var position = 0; position < matrix.RowCount; position++)
{
var result = matrix.RemoveRow(position);
@ -162,7 +152,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanInsertColumn(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var column = Vector<T>.Build.Random(matrix.RowCount, 0);
for (var position = 0; position < matrix.ColumnCount + 1; position++)
{
@ -199,7 +189,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanRemoveColumn(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
for (var position = 0; position < matrix.ColumnCount; position++)
{
var result = matrix.RemoveColumn(position);
@ -225,10 +215,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanAppend(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix)
{
Matrix<T> left = GetMatrix(leftTestMatrix);
Matrix<T> right = GetMatrix(rightTestMatrix);
// IF
Matrix<T> left = Get(leftTestMatrix);
Matrix<T> right = Get(rightTestMatrix);
Assume.That(left.RowCount, Is.EqualTo(right.RowCount));
// THEN
@ -250,10 +238,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanAppendIntoResult(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix)
{
Matrix<T> left = GetMatrix(leftTestMatrix);
Matrix<T> right = GetMatrix(rightTestMatrix);
// IF
Matrix<T> left = Get(leftTestMatrix);
Matrix<T> right = Get(rightTestMatrix);
Assume.That(left.RowCount, Is.EqualTo(right.RowCount));
// THEN
@ -280,8 +266,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanStack(TestMatrix topTestMatrix, TestMatrix bottomTestMatrix)
{
Matrix<T> top = GetMatrix(topTestMatrix);
Matrix<T> bottom = GetMatrix(bottomTestMatrix);
Matrix<T> top = Get(topTestMatrix);
Matrix<T> bottom = Get(bottomTestMatrix);
// IF
Assume.That(top.ColumnCount, Is.EqualTo(bottom.ColumnCount));
@ -305,10 +291,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanStackIntoResult(TestMatrix topTestMatrix, TestMatrix bottomTestMatrix)
{
Matrix<T> top = GetMatrix(topTestMatrix);
Matrix<T> bottom = GetMatrix(bottomTestMatrix);
// IF
Matrix<T> top = Get(topTestMatrix);
Matrix<T> bottom = Get(bottomTestMatrix);
Assume.That(top.ColumnCount, Is.EqualTo(bottom.ColumnCount));
// THEN
@ -335,8 +319,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanDiagonalStack(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix)
{
Matrix<T> left = GetMatrix(leftTestMatrix);
Matrix<T> right = GetMatrix(rightTestMatrix);
Matrix<T> left = Get(leftTestMatrix);
Matrix<T> right = Get(rightTestMatrix);
var result = left.DiagonalStack(right);
@ -364,8 +348,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanDiagonalStackIntoResult(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix)
{
Matrix<T> left = GetMatrix(leftTestMatrix);
Matrix<T> right = GetMatrix(rightTestMatrix);
Matrix<T> left = Get(leftTestMatrix);
Matrix<T> right = Get(rightTestMatrix);
var result = Matrix<T>.Build.Dense(left.RowCount + right.RowCount, left.ColumnCount + right.ColumnCount);
left.DiagonalStack(right, result);

42
src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs

@ -39,7 +39,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
public abstract partial class MatrixStructureTheory<T>
where T : struct, IEquatable<T>, IFormattable
{
protected abstract Matrix<T> GetMatrix(TestMatrix matrix);
protected abstract Matrix<T> Get(TestMatrix matrix);
protected readonly T Zero = Matrix<T>.Build.Zero;
@ -60,7 +60,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void IsEqualToItself(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Assert.That(matrix, Is.EqualTo(matrix));
Assert.IsTrue(matrix.Equals(matrix));
Assert.IsTrue(matrix.Equals((object)matrix));
@ -72,10 +72,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void IsNotEqualToOthers(TestMatrix leftTestMatrix, TestMatrix rightTestmatrix)
{
Matrix<T> left = GetMatrix(leftTestMatrix);
Matrix<T> right = GetMatrix(rightTestmatrix);
// IF (assuming we don't have duplicate data points)
Matrix<T> left = Get(leftTestMatrix);
Matrix<T> right = Get(rightTestmatrix);
Assume.That(leftTestMatrix, Is.Not.EqualTo(rightTestmatrix));
// THEN
@ -90,7 +88,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void IsNotEqualToPermutation(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
if (!matrix.Storage.IsFullyMutable)
{
return;
@ -123,7 +121,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void IsNotEqualToNonMatrixType(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Assert.That(matrix, Is.Not.EqualTo(2));
Assert.IsFalse(matrix.Equals(2));
Assert.IsFalse(matrix.Equals((object)2));
@ -134,7 +132,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanClone(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var clone = matrix.Clone();
Assert.That(clone, Is.Not.SameAs(matrix));
Assert.That(clone, Is.EqualTo(matrix));
@ -146,7 +144,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanCloneUsingICloneable(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var clone = (Matrix<T>)((ICloneable)matrix).Clone();
Assert.That(clone, Is.Not.SameAs(matrix));
Assert.That(clone, Is.EqualTo(matrix));
@ -158,7 +156,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanCopyTo(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var dense = Matrix<T>.Build.Dense(matrix.RowCount, matrix.ColumnCount);
matrix.CopyTo(dense);
Assert.That(dense, Is.EqualTo(matrix));
@ -178,14 +176,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanGetHashCode(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Assert.That(matrix.GetHashCode(), Is.Not.EqualTo(Matrix<T>.Build.SameAs(matrix).GetHashCode()));
}
[Theory]
public void CanClear(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var cleared = matrix.Clone();
cleared.Clear();
Assert.That(cleared, Is.EqualTo(Matrix<T>.Build.SameAs(matrix)));
@ -194,7 +192,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanClearSubMatrix(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Assume.That(matrix.RowCount, Is.GreaterThanOrEqualTo(2));
Assume.That(matrix.ColumnCount, Is.GreaterThanOrEqualTo(2));
@ -209,7 +207,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanClearRows(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Assume.That(matrix.RowCount, Is.GreaterThanOrEqualTo(2));
var cleared = matrix.Clone();
@ -221,7 +219,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanClearColumns(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
Assume.That(matrix.ColumnCount, Is.GreaterThanOrEqualTo(2));
var cleared = matrix.Clone();
@ -233,7 +231,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanToArray(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var array = matrix.ToArray();
Assert.That(array.GetLength(0), Is.EqualTo(matrix.RowCount));
Assert.That(array.GetLength(1), Is.EqualTo(matrix.ColumnCount));
@ -249,7 +247,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanToColumnArrays(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var columnArrays = matrix.ToColumnArrays();
Assert.That(columnArrays.Length, Is.EqualTo(matrix.ColumnCount));
Assert.That(columnArrays[0].Length, Is.EqualTo(matrix.RowCount));
@ -265,7 +263,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanToRowArrays(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var rowArrays = matrix.ToRowArrays();
Assert.That(rowArrays.Length, Is.EqualTo(matrix.RowCount));
Assert.That(rowArrays[0].Length, Is.EqualTo(matrix.ColumnCount));
@ -281,7 +279,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanToColumnWiseArray(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var array = matrix.ToColumnWiseArray();
Assert.That(array.Length, Is.EqualTo(matrix.RowCount*matrix.ColumnCount));
for (int i = 0; i < array.Length; i++)
@ -293,7 +291,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanToRowWiseArray(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var array = matrix.ToRowWiseArray();
Assert.That(array.Length, Is.EqualTo(matrix.RowCount*matrix.ColumnCount));
for (int i = 0; i < array.Length; i++)
@ -305,7 +303,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
[Theory]
public void CanCreateSameKind(TestMatrix testMatrix)
{
Matrix<T> matrix = GetMatrix(testMatrix);
Matrix<T> matrix = Get(testMatrix);
var empty = Matrix<T>.Build.SameAs(matrix, 5, 6);
Assert.That(empty, Is.EqualTo(Matrix<T>.Build.Dense(5, 6)));
Assert.That(empty.Storage.IsDense, Is.EqualTo(matrix.Storage.IsDense));

4
src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs

@ -36,9 +36,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
[TestFixture, Category("LA")]
public class MatrixStructureTheory : MatrixStructureTheory<float>
{
protected override Matrix<float> GetMatrix(TestMatrix matrix)
protected override Matrix<float> Get(TestMatrix matrix)
{
return TestData.GetMatrix(matrix);
return TestData.Matrix(matrix);
}
[Datapoints]

4
src/UnitTests/LinearAlgebraTests/Single/TestData.cs

@ -38,7 +38,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
static readonly MatrixBuilder<float> M = Matrix<float>.Build;
static readonly VectorBuilder<float> V = Vector<float>.Build;
public static Matrix<float> GetMatrix(TestMatrix matrix)
public static Matrix<float> Matrix(TestMatrix matrix)
{
switch (matrix)
{
@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
}
}
public static Vector<float> GetVector(TestVector vector)
public static Vector<float> Vector(TestVector vector)
{
switch (vector)
{

7
src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs

@ -36,14 +36,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
[TestFixture, Category("LA")]
public class VectorArithmeticTheory : VectorArithmeticTheory<float>
{
protected override Vector<float> GetVector(TestVector vector)
protected override Vector<float> Get(TestVector vector)
{
return TestData.GetVector(vector);
return TestData.Vector(vector);
}
protected override float Minus(float value) { return -value; }
protected override float Add(float first, float second) { return first + second; }
[Datapoints]
TestVector[] _vectors =
{

48
src/UnitTests/LinearAlgebraTests/TestData.cs

@ -28,6 +28,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra.Storage;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
{
public enum TestMatrix
@ -50,6 +54,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
UserSquare3x3
}
public enum TestMatrixStorage
{
DenseMatrix = 1,
SparseMatrix = 2,
DiagonalMatrix = 3
}
public enum TestVector
{
Dense5,
@ -60,4 +71,41 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
Sparse5AllZeros,
SparseMaxLengthAllZeros
}
public enum TestVectorStorage
{
DenseVector = 1,
SparseVector = 2
}
public static class TestData
{
public static VectorStorage<T> VectorStorage<T>(TestVectorStorage type, IEnumerable<T> data)
where T : struct, IEquatable<T>, IFormattable
{
switch (type)
{
case TestVectorStorage.DenseVector:
return DenseVectorStorage<T>.OfEnumerable(data);
case TestVectorStorage.SparseVector:
return SparseVectorStorage<T>.OfEnumerable(data);
default:
throw new NotSupportedException();
}
}
public static VectorStorage<T> VectorStorage<T>(TestVectorStorage type, int length)
where T : struct, IEquatable<T>, IFormattable
{
switch (type)
{
case TestVectorStorage.DenseVector:
return new DenseVectorStorage<T>(length);
case TestVectorStorage.SparseVector:
return new SparseVectorStorage<T>(length);
default:
throw new NotSupportedException();
}
}
}
}

61
src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs

@ -28,10 +28,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System.Globalization;
using System;
using MathNet.Numerics.LinearAlgebra;
using NUnit.Framework;
using System;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
{
@ -39,16 +38,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
public abstract class VectorArithmeticTheory<T>
where T : struct, IEquatable<T>, IFormattable
{
protected abstract Vector<T> GetVector(TestVector vector);
protected abstract T Minus(T value);
protected abstract T Add(T first, T second);
private T Subtract(T first, T second) { return Add(first, Minus(second)); }
protected abstract Vector<T> Get(TestVector vector);
[Theory, Timeout(200)]
[Theory]
public void CanEqualVector(TestVector testVector, T scalar)
{
Vector<T> vector = GetVector(testVector);
Vector<T> vector = Get(testVector);
Assert.That(vector.Equals(vector));
@ -80,10 +75,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
Assert.That(c.Equals(Vector<T>.Build.SameAs(vector)));
}
[Theory, Timeout(200)]
[Theory]
public void CanNegateVector(TestVector testVector)
{
Vector<T> vector = GetVector(testVector);
Vector<T> vector = Get(testVector);
var hash = vector.GetHashCode();
@ -99,16 +94,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
for (var i = 0; i < Math.Min(vector.Count, 20); i++)
{
Assert.That(result1[i], Is.EqualTo(Minus(vector[i])), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result2[i], Is.EqualTo(Minus(vector[i])), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result1[i], Is.EqualTo(Operator.Negate(vector[i])));
Assert.That(result2[i], Is.EqualTo(Operator.Negate(vector[i])));
}
}
[Theory, Timeout(200)]
[Theory]
public void CanAddTwoVectors(TestVector testVectorA, TestVector testVectorB)
{
Vector<T> a = GetVector(testVectorA);
Vector<T> b = GetVector(testVectorB);
Vector<T> a = Get(testVectorA);
Vector<T> b = Get(testVectorB);
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
@ -132,16 +127,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result1[i], Is.EqualTo(Add(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result2[i], Is.EqualTo(Add(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result3[i], Is.EqualTo(Add(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result1[i], Is.EqualTo(Operator.Add(a[i], b[i])));
Assert.That(result2[i], Is.EqualTo(Operator.Add(a[i], b[i])));
Assert.That(result3[i], Is.EqualTo(Operator.Add(a[i], b[i])));
}
}
[Theory, Timeout(200)]
[Theory]
public void CanAddScalarToVector(TestVector testVector, T scalar)
{
Vector<T> vector = GetVector(testVector);
Vector<T> vector = Get(testVector);
Assume.That(vector.Count, Is.LessThan(100));
var hash = vector.GetHashCode();
@ -157,16 +152,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
for (var i = 0; i < Math.Min(vector.Count, 20); i++)
{
Assert.That(result1[i], Is.EqualTo(Add(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result2[i], Is.EqualTo(Add(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result1[i], Is.EqualTo(Operator.Add(vector[i], scalar)));
Assert.That(result2[i], Is.EqualTo(Operator.Add(vector[i], scalar)));
}
}
[Theory, Timeout(200)]
[Theory]
public void CanSubtractTwoVectors(TestVector testVectorA, TestVector testVectorB)
{
Vector<T> a = GetVector(testVectorA);
Vector<T> b = GetVector(testVectorB);
Vector<T> a = Get(testVectorA);
Vector<T> b = Get(testVectorB);
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
@ -190,16 +185,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result1[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result2[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result3[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result1[i], Is.EqualTo(Operator.Subtract(a[i], b[i])));
Assert.That(result2[i], Is.EqualTo(Operator.Subtract(a[i], b[i])));
Assert.That(result3[i], Is.EqualTo(Operator.Subtract(a[i], b[i])));
}
}
[Theory, Timeout(200)]
[Theory]
public void CanSubtractScalarFromVector(TestVector testVector, T scalar)
{
Vector<T> vector = GetVector(testVector);
Vector<T> vector = Get(testVector);
Assume.That(vector.Count, Is.LessThan(100));
var hash = vector.GetHashCode();
@ -215,8 +210,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
for (var i = 0; i < Math.Min(vector.Count, 20); i++)
{
Assert.That(result1[i], Is.EqualTo(Subtract(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result2[i], Is.EqualTo(Subtract(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture));
Assert.That(result1[i], Is.EqualTo(Operator.Subtract(vector[i], scalar)));
Assert.That(result2[i], Is.EqualTo(Operator.Subtract(vector[i], scalar)));
}
}
}

72
src/UnitTests/LinearAlgebraTests/VectorStorageCombinatorsTests.cs

@ -39,40 +39,40 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
public class VectorStorageCombinatorsTests
{
[Theory]
public void MapToSkipZeros(VectorStorageType aType, VectorStorageType resultType)
public void MapToSkipZeros(TestVectorStorage aType, TestVectorStorage resultType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = Build.VectorStorage<double>(resultType, 4);
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = TestData.VectorStorage<double>(resultType, 4);
var expected = new DenseVectorStorage<double>(4, new[] { -1.0, -2.0, 0.0, -4.0 });
a.MapTo(result, u => -u, Zeros.AllowSkip);
Assert.That(result.Equals(expected));
}
[Theory]
public void MapToForceIncludeZeros(VectorStorageType aType, VectorStorageType resultType)
public void MapToForceIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = Build.VectorStorage<double>(resultType, 4);
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = TestData.VectorStorage<double>(resultType, 4);
var expected = new DenseVectorStorage<double>(4, new[] { 0.0, -1.0, 1.0, -3.0 });
a.MapTo(result, u => -u + 1.0, Zeros.Include);
Assert.That(result.Equals(expected));
}
[Theory]
public void MapToAutoIncludeZeros(VectorStorageType aType, VectorStorageType resultType)
public void MapToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = Build.VectorStorage<double>(resultType, 4);
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = TestData.VectorStorage<double>(resultType, 4);
var expected = new DenseVectorStorage<double>(4, new[] { 0.0, -1.0, 1.0, -3.0 });
a.MapTo(result, u => -u + 1.0, Zeros.AllowSkip);
Assert.That(result.Equals(expected));
}
[Theory]
public void MapIndexedToSkipZeros(VectorStorageType aType, VectorStorageType resultType)
public void MapIndexedToSkipZeros(TestVectorStorage aType, TestVectorStorage resultType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = Build.VectorStorage<double>(resultType, 4);
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = TestData.VectorStorage<double>(resultType, 4);
var expected = new DenseVectorStorage<double>(4, new[] { -1.0, -2.0, 0.0, -4.0 });
int badValueCount = 0; // one time is OK for zero-check
a.MapIndexedTo(result, (i, u) => { if (a.At(i) != u) Interlocked.Increment(ref badValueCount); return -u; }, Zeros.AllowSkip);
@ -81,10 +81,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
[Theory]
public void MapIndexedToForceIncludeZeros(VectorStorageType aType, VectorStorageType resultType)
public void MapIndexedToForceIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = Build.VectorStorage<double>(resultType, 4);
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = TestData.VectorStorage<double>(resultType, 4);
var expected = new DenseVectorStorage<double>(4, new[] { 0.0, -1.0, 1.0, -3.0 });
int badValueCount = 0; // one time is OK for zero-check
a.MapIndexedTo(result, (i, u) => { if (a.At(i) != u) Interlocked.Increment(ref badValueCount); return -u + 1.0; }, Zeros.Include);
@ -93,10 +93,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
[Theory]
public void MapIndexedToAutoIncludeZeros(VectorStorageType aType, VectorStorageType resultType)
public void MapIndexedToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = Build.VectorStorage<double>(resultType, 4);
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
var result = TestData.VectorStorage<double>(resultType, 4);
var expected = new DenseVectorStorage<double>(4, new[] { 0.0, -1.0, 1.0, -3.0 });
int badValueCount = 0; // one time is OK for zero-check
a.MapIndexedTo(result, (i, u) => { if (a.At(i) != u) Interlocked.Increment(ref badValueCount); return -u + 1.0; }, Zeros.AllowSkip);
@ -105,52 +105,52 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
[Theory]
public void Map2ToSkipZeros(VectorStorageType aType, VectorStorageType bType, VectorStorageType resultType)
public void Map2ToSkipZeros(TestVectorStorage aType, TestVectorStorage bType, TestVectorStorage resultType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var result = Build.VectorStorage<double>(resultType, 6);
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var result = TestData.VectorStorage<double>(resultType, 6);
var expected = new DenseVectorStorage<double>(6, new[] { 12.0, 14.0, 13.0, 4.0, 0.0, 22.0 });
a.Map2To(result, b, (u, v) => u + v, Zeros.AllowSkip);
Assert.That(result.Equals(expected));
}
[Theory]
public void Map2ToForceIncludeZeros(VectorStorageType aType, VectorStorageType bType, VectorStorageType resultType)
public void Map2ToForceIncludeZeros(TestVectorStorage aType, TestVectorStorage bType, TestVectorStorage resultType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var result = Build.VectorStorage<double>(resultType, 6);
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var result = TestData.VectorStorage<double>(resultType, 6);
var expected = new DenseVectorStorage<double>(6, new[] { 13.0, 15.0, 14.0, 5.0, 1.0, 23.0 });
a.Map2To(result, b, (u, v) => u + v + 1.0, Zeros.Include);
Assert.That(result.Equals(expected));
}
[Theory]
public void Map2ToAutoIncludeZeros(VectorStorageType aType, VectorStorageType bType, VectorStorageType resultType)
public void Map2ToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage bType, TestVectorStorage resultType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var result = Build.VectorStorage<double>(resultType, 6);
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var result = TestData.VectorStorage<double>(resultType, 6);
var expected = new DenseVectorStorage<double>(6, new[] { 13.0, 15.0, 14.0, 5.0, 1.0, 23.0 });
a.Map2To(result, b, (u, v) => u + v + 1.0, Zeros.AllowSkip);
Assert.That(result.Equals(expected));
}
[Theory]
public void Fold2SkipZeros(VectorStorageType aType, VectorStorageType bType)
public void Fold2SkipZeros(TestVectorStorage aType, TestVectorStorage bType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var result = a.Fold2(b, (acc, u, v) => acc + u + v, 0.0, Zeros.AllowSkip);
Assert.That(result, Is.EqualTo(65));
}
[Theory]
public void Fold2ForceIncludeZeros(VectorStorageType aType, VectorStorageType bType)
public void Fold2ForceIncludeZeros(TestVectorStorage aType, TestVectorStorage bType)
{
var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
var result = a.Fold2(b, (acc, u, v) => acc + u + v + 1.0, 0.0, Zeros.Include);
Assert.That(result, Is.EqualTo(71));
}

1
src/UnitTests/UnitTests.csproj

@ -148,7 +148,6 @@
<Compile Include="LinearAlgebraProviderTests\Complex\LinearAlgebraProviderTests.cs" />
<Compile Include="LinearAlgebraProviderTests\Double\LinearAlgebraProviderTests.cs" />
<Compile Include="LinearAlgebraProviderTests\Single\LinearAlgebraProviderTests.cs" />
<Compile Include="LinearAlgebraTests\Build.cs" />
<Compile Include="LinearAlgebraTests\Complex32\DenseMatrixTests.cs" />
<Compile Include="LinearAlgebraTests\Complex32\DenseVectorTests.cs" />
<Compile Include="LinearAlgebraTests\Complex32\DiagonalMatrixTests.cs" />

Loading…
Cancel
Save