Browse Source

Tests: replace matrix structural tests with theory (part 7) - Apped, Stack

pull/47/head
Christoph Ruegg 14 years ago
parent
commit
9df3c13295
  1. 2
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  2. 2
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  3. 2
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  4. 51
      src/Numerics/LinearAlgebra/Generic/Matrix.cs
  5. 2
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  6. 32
      src/UnitTests/LinearAlgebraTests/Complex/DiagonalMatrixTests.cs
  7. 236
      src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs
  8. 32
      src/UnitTests/LinearAlgebraTests/Complex32/DiagonalMatrixTests.cs
  9. 236
      src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.cs
  10. 32
      src/UnitTests/LinearAlgebraTests/Double/DiagonalMatrixTests.cs
  11. 236
      src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs
  12. 157
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs
  13. 32
      src/UnitTests/LinearAlgebraTests/Single/DiagonalMatrixTests.cs
  14. 236
      src/UnitTests/LinearAlgebraTests/Single/MatrixTests.cs

2
src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs

@ -1372,7 +1372,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
// Copy the lower matrix into the result matrix.
CommonParallel.For(0, lower.RowCount, i => CommonParallel.For(0, lower.ColumnCount, j => result.At(i + RowCount, j + ColumnCount, lower.At(i, j))));
result.SetSubMatrix(RowCount, lower.RowCount, ColumnCount, lower.ColumnCount, lower);
}
/// <summary>

2
src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs

@ -1372,7 +1372,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
// Copy the lower matrix into the result matrix.
CommonParallel.For(0, lower.RowCount, i => CommonParallel.For(0, lower.ColumnCount, j => result.At(i + RowCount, j + ColumnCount, lower.At(i, j))));
result.SetSubMatrix(RowCount, lower.RowCount, ColumnCount, lower.ColumnCount, lower);
}
/// <summary>

2
src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs

@ -1366,7 +1366,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
// Copy the lower matrix into the result matrix.
CommonParallel.For(0, lower.RowCount, i => CommonParallel.For(0, lower.ColumnCount, j => result.At(i + RowCount, j + ColumnCount, lower.At(i, j))));
result.SetSubMatrix(RowCount, lower.RowCount, ColumnCount, lower.ColumnCount, lower);
}
/// <summary>

51
src/Numerics/LinearAlgebra/Generic/Matrix.cs

@ -1577,21 +1577,8 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new ArgumentException(Resources.ArgumentMatrixSameColumnDimension);
}
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
result.At(i, j, At(i, j));
}
}
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < right.ColumnCount; j++)
{
result.At(i, j + ColumnCount, right.At(i, j));
}
}
result.SetSubMatrix(0, RowCount, 0, ColumnCount, this);
result.SetSubMatrix(0, right.RowCount, ColumnCount, right.ColumnCount, right);
}
/// <summary>
@ -1647,21 +1634,8 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
}
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
result.At(i, j, At(i, j));
}
}
for (var i = 0; i < lower.RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
result.At(i + RowCount, j, lower.At(i, j));
}
}
result.SetSubMatrix(0, RowCount, 0, ColumnCount, this);
result.SetSubMatrix(RowCount, lower.RowCount, 0, lower.ColumnCount, lower);
}
/// <summary>
@ -1709,21 +1683,8 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
}
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
result.At(i, j, At(i, j));
}
}
for (var i = 0; i < lower.RowCount; i++)
{
for (var j = 0; j < lower.ColumnCount; j++)
{
result.At(i + RowCount, j + ColumnCount, lower.At(i, j));
}
}
result.SetSubMatrix(0, RowCount, 0, ColumnCount, this);
result.SetSubMatrix(RowCount, lower.RowCount, ColumnCount, lower.ColumnCount, lower);
}
/// <summary>Calculates the L1 norm.</summary>

2
src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs

@ -1366,7 +1366,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
// Copy the lower matrix into the result matrix.
CommonParallel.For(0, lower.RowCount, i => CommonParallel.For(0, lower.ColumnCount, j => result.At(i + RowCount, j + ColumnCount, lower.At(i, j))));
result.SetSubMatrix(RowCount, lower.RowCount, ColumnCount, lower.ColumnCount, lower);
}
/// <summary>

32
src/UnitTests/LinearAlgebraTests/Complex/DiagonalMatrixTests.cs

@ -202,38 +202,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
Assert.Throws<ArgumentOutOfRangeException>(() => DiagonalMatrix.Identity(order));
}
/// <summary>
/// Can diagonally stack matrices into a result matrix.
/// </summary>
public override void CanDiagonallyStackMatricesIntoResult()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = new SparseMatrix(top.RowCount + bottom.RowCount, top.ColumnCount + bottom.ColumnCount);
top.DiagonalStack(bottom, result);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(Complex.Zero, result[i, j]);
}
}
}
}
/// <summary>
/// Can multiply a matrix with matrix.
/// </summary>

236
src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs

@ -152,242 +152,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
}
}
/// <summary>
/// Can append matrices.
/// </summary>
[Test]
public void CanAppendMatrices()
{
var left = CreateMatrix(TestData2D["Singular3x3"]);
var right = CreateMatrix(TestData2D["Tall3x2"]);
var result = left.Append(right);
Assert.AreEqual(left.ColumnCount + right.ColumnCount, result.ColumnCount);
Assert.AreEqual(left.RowCount, right.RowCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.AreEqual(j < left.ColumnCount ? left[i, j] : right[i, j - left.ColumnCount], result[i, j]);
}
}
}
/// <summary>
/// Append with right <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void AppendWithRightNullThrowsArgumentNullException()
{
var left = TestMatrices["Square3x3"];
Matrix<Complex> right = null;
Assert.Throws<ArgumentNullException>(() => left.Append(right));
}
/// <summary>
/// Append with result <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void AppendWithResultNullThrowsArgumentNullException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Tall3x2"];
Matrix<Complex> result = null;
Assert.Throws<ArgumentNullException>(() => left.Append(right, result));
}
/// <summary>
/// Appending two matrices with different row count throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void AppendWithDifferentRowCountThrowsArgumentException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Wide2x3"];
Assert.Throws<ArgumentException>(() => { var result = left.Append(right); });
}
/// <summary>
/// Appending with invalid result matrix columns throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void AppendWithInvalidResultMatrixColumnsThrowsArgumentException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Tall3x2"];
var result = CreateMatrix(3, 2);
Assert.Throws<ArgumentException>(() => left.Append(right, result));
}
/// <summary>
/// Can stack matrices.
/// </summary>
[Test]
public void CanStackMatrices()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Wide2x3"];
var result = top.Stack(bottom);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.AreEqual(result[i, j], i < top.RowCount ? top[i, j] : bottom[i - top.RowCount, j]);
}
}
}
/// <summary>
/// Stacking with a bottom <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void StackWithBottomNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
Matrix<Complex> bottom = null;
var result = CreateMatrix(top.RowCount + top.RowCount, top.ColumnCount);
Assert.Throws<ArgumentNullException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Stacking with a result <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void StackWithResultNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Square3x3"];
Matrix<Complex> result = null;
Assert.Throws<ArgumentNullException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Stacking matrices with different columns throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void StackMatricesWithDifferentColumnsThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Tall3x2"];
var result = CreateMatrix(top.RowCount + lower.RowCount, top.ColumnCount);
Assert.Throws<ArgumentException>(() => top.Stack(lower, result));
}
/// <summary>
/// Stacking with invalid result matrix rows throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void StackWithInvalidResultMatrixRowsThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Wide2x3"];
var result = CreateMatrix(1, 3);
Assert.Throws<ArgumentException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Can diagonally stack matrices.
/// </summary>
[Test]
public void CanDiagonallyStackMatrices()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = top.DiagonalStack(bottom);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(Complex.Zero, result[i, j]);
}
}
}
}
/// <summary>
/// Diagonal stack with lower <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void DiagonalStackWithLowerNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
Matrix<Complex> lower = null;
Assert.Throws<ArgumentNullException>(() => top.DiagonalStack(lower));
}
/// <summary>
/// Can diagonally stack matrices into a result matrix.
/// </summary>
[Test]
public virtual void CanDiagonallyStackMatricesIntoResult()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = CreateMatrix(top.RowCount + bottom.RowCount, top.ColumnCount + bottom.ColumnCount);
top.DiagonalStack(bottom, result);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(Complex.Zero, result[i, j]);
}
}
}
}
/// <summary>
/// Diagonal stack into <c>null</c> result throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void DiagonalStackIntoResultNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Wide2x3"];
Matrix<Complex> result = null;
Assert.Throws<ArgumentNullException>(() => top.DiagonalStack(lower, result));
}
/// <summary>
/// Diagonal stack into invalid result matrix throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void DiagonalStackIntoInvalidResultMatrixThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Wide2x3"];
var result = CreateMatrix(top.RowCount + lower.RowCount + 2, top.ColumnCount + lower.ColumnCount);
Assert.Throws<ArgumentException>(() => top.DiagonalStack(lower, result));
}
/// <summary>
/// Can compute Frobenius norm.
/// </summary>

32
src/UnitTests/LinearAlgebraTests/Complex32/DiagonalMatrixTests.cs

@ -202,38 +202,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
Assert.Throws<ArgumentOutOfRangeException>(() => DiagonalMatrix.Identity(order));
}
/// <summary>
/// Can diagonally stack matrices into a result matrix.
/// </summary>
public override void CanDiagonallyStackMatricesIntoResult()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = new SparseMatrix(top.RowCount + bottom.RowCount, top.ColumnCount + bottom.ColumnCount);
top.DiagonalStack(bottom, result);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(Complex32.Zero, result[i, j]);
}
}
}
}
/// <summary>
/// Can multiply a matrix with matrix.
/// </summary>

236
src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.cs

@ -152,242 +152,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
}
}
/// <summary>
/// Can append matrices.
/// </summary>
[Test]
public void CanAppendMatrices()
{
var left = CreateMatrix(TestData2D["Singular3x3"]);
var right = CreateMatrix(TestData2D["Tall3x2"]);
var result = left.Append(right);
Assert.AreEqual(left.ColumnCount + right.ColumnCount, result.ColumnCount);
Assert.AreEqual(left.RowCount, right.RowCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.AreEqual(j < left.ColumnCount ? left[i, j] : right[i, j - left.ColumnCount], result[i, j]);
}
}
}
/// <summary>
/// Append with right <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void AppendWithRightNullThrowsArgumentNullException()
{
var left = TestMatrices["Square3x3"];
Matrix<Complex32> right = null;
Assert.Throws<ArgumentNullException>(() => left.Append(right));
}
/// <summary>
/// Append with result <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void AppendWithResultNullThrowsArgumentNullException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Tall3x2"];
Matrix<Complex32> result = null;
Assert.Throws<ArgumentNullException>(() => left.Append(right, result));
}
/// <summary>
/// Appending two matrices with different row count throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void AppendWithDifferentRowCountThrowsArgumentException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Wide2x3"];
Assert.Throws<ArgumentException>(() => { var result = left.Append(right); });
}
/// <summary>
/// Appending with invalid result matrix columns throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void AppendWithInvalidResultMatrixColumnsThrowsArgumentException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Tall3x2"];
var result = CreateMatrix(3, 2);
Assert.Throws<ArgumentException>(() => left.Append(right, result));
}
/// <summary>
/// Can stack matrices.
/// </summary>
[Test]
public void CanStackMatrices()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Wide2x3"];
var result = top.Stack(bottom);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.AreEqual(result[i, j], i < top.RowCount ? top[i, j] : bottom[i - top.RowCount, j]);
}
}
}
/// <summary>
/// Stacking with a bottom <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void StackWithBottomNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
Matrix<Complex32> bottom = null;
var result = CreateMatrix(top.RowCount + top.RowCount, top.ColumnCount);
Assert.Throws<ArgumentNullException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Stacking with a result <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void StackWithResultNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Square3x3"];
Matrix<Complex32> result = null;
Assert.Throws<ArgumentNullException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Stacking matrices with different columns throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void StackMatricesWithDifferentColumnsThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Tall3x2"];
var result = CreateMatrix(top.RowCount + lower.RowCount, top.ColumnCount);
Assert.Throws<ArgumentException>(() => top.Stack(lower, result));
}
/// <summary>
/// Stacking with invalid result matrix rows throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void StackWithInvalidResultMatrixRowsThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Wide2x3"];
var result = CreateMatrix(1, 3);
Assert.Throws<ArgumentException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Can diagonally stack matrices.
/// </summary>
[Test]
public void CanDiagonallyStackMatrices()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = top.DiagonalStack(bottom);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(Complex32.Zero, result[i, j]);
}
}
}
}
/// <summary>
/// Diagonal stack with lower <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void DiagonalStackWithLowerNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
Matrix<Complex32> lower = null;
Assert.Throws<ArgumentNullException>(() => top.DiagonalStack(lower));
}
/// <summary>
/// Can diagonally stack matrices into a result matrix.
/// </summary>
[Test]
public virtual void CanDiagonallyStackMatricesIntoResult()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = CreateMatrix(top.RowCount + bottom.RowCount, top.ColumnCount + bottom.ColumnCount);
top.DiagonalStack(bottom, result);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(Complex32.Zero, result[i, j]);
}
}
}
}
/// <summary>
/// Diagonal stack into <c>null</c> result throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void DiagonalStackIntoResultNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Wide2x3"];
Matrix<Complex32> result = null;
Assert.Throws<ArgumentNullException>(() => top.DiagonalStack(lower, result));
}
/// <summary>
/// Diagonal stack into invalid result matrix throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void DiagonalStackIntoInvalidResultMatrixThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Wide2x3"];
var result = CreateMatrix(top.RowCount + lower.RowCount + 2, top.ColumnCount + lower.ColumnCount);
Assert.Throws<ArgumentException>(() => top.DiagonalStack(lower, result));
}
/// <summary>
/// Can compute Frobenius norm.
/// </summary>

32
src/UnitTests/LinearAlgebraTests/Double/DiagonalMatrixTests.cs

@ -202,38 +202,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
Assert.Throws<ArgumentOutOfRangeException>(() => DiagonalMatrix.Identity(order));
}
/// <summary>
/// Can diagonally stack matrices into a result matrix.
/// </summary>
public override void CanDiagonallyStackMatricesIntoResult()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = new SparseMatrix(top.RowCount + bottom.RowCount, top.ColumnCount + bottom.ColumnCount);
top.DiagonalStack(bottom, result);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(0, result[i, j]);
}
}
}
}
/// <summary>
/// Can multiply a matrix with matrix.
/// </summary>

236
src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs

@ -125,242 +125,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
}
}
/// <summary>
/// Can append matrices.
/// </summary>
[Test]
public void CanAppendMatrices()
{
var left = CreateMatrix(TestData2D["Singular3x3"]);
var right = CreateMatrix(TestData2D["Tall3x2"]);
var result = left.Append(right);
Assert.AreEqual(left.ColumnCount + right.ColumnCount, result.ColumnCount);
Assert.AreEqual(left.RowCount, right.RowCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.AreEqual(j < left.ColumnCount ? left[i, j] : right[i, j - left.ColumnCount], result[i, j]);
}
}
}
/// <summary>
/// Append with right <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void AppendWithRightNullThrowsArgumentNullException()
{
var left = TestMatrices["Square3x3"];
Matrix<double> right = null;
Assert.Throws<ArgumentNullException>(() => left.Append(right));
}
/// <summary>
/// Append with result <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void AppendWithResultNullThrowsArgumentNullException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Tall3x2"];
Matrix<double> result = null;
Assert.Throws<ArgumentNullException>(() => left.Append(right, result));
}
/// <summary>
/// Appending two matrices with different row count throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void AppendWithDifferentRowCountThrowsArgumentException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Wide2x3"];
Assert.Throws<ArgumentException>(() => { var result = left.Append(right); });
}
/// <summary>
/// Appending with invalid result matrix columns throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void AppendWithInvalidResultMatrixColumnsThrowsArgumentException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Tall3x2"];
var result = CreateMatrix(3, 2);
Assert.Throws<ArgumentException>(() => left.Append(right, result));
}
/// <summary>
/// Can stack matrices.
/// </summary>
[Test]
public void CanStackMatrices()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Wide2x3"];
var result = top.Stack(bottom);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.AreEqual(result[i, j], i < top.RowCount ? top[i, j] : bottom[i - top.RowCount, j]);
}
}
}
/// <summary>
/// Stacking with a bottom <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void StackWithBottomNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
Matrix<double> bottom = null;
var result = CreateMatrix(top.RowCount + top.RowCount, top.ColumnCount);
Assert.Throws<ArgumentNullException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Stacking with a result <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void StackWithResultNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Square3x3"];
Matrix<double> result = null;
Assert.Throws<ArgumentNullException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Stacking matrices with different columns throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void StackMatricesWithDifferentColumnsThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Tall3x2"];
var result = CreateMatrix(top.RowCount + lower.RowCount, top.ColumnCount);
Assert.Throws<ArgumentException>(() => top.Stack(lower, result));
}
/// <summary>
/// Stacking with invalid result matrix rows throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void StackWithInvalidResultMatrixRowsThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Wide2x3"];
var result = CreateMatrix(1, 3);
Assert.Throws<ArgumentException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Can diagonally stack matrices.
/// </summary>
[Test]
public void CanDiagonallyStackMatrices()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = top.DiagonalStack(bottom);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(0, result[i, j]);
}
}
}
}
/// <summary>
/// Diagonal stack with lower <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void DiagonalStackWithLowerNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
Matrix<double> lower = null;
Assert.Throws<ArgumentNullException>(() => top.DiagonalStack(lower));
}
/// <summary>
/// Can diagonally stack matrices into a result matrix.
/// </summary>
[Test]
public virtual void CanDiagonallyStackMatricesIntoResult()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = CreateMatrix(top.RowCount + bottom.RowCount, top.ColumnCount + bottom.ColumnCount);
top.DiagonalStack(bottom, result);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(0, result[i, j]);
}
}
}
}
/// <summary>
/// Diagonal stack into <c>null</c> result throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void DiagonalStackIntoResultNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Wide2x3"];
Matrix<double> result = null;
Assert.Throws<ArgumentNullException>(() => top.DiagonalStack(lower, result));
}
/// <summary>
/// Diagonal stack into invalid result matrix throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void DiagonalStackIntoInvalidResultMatrixThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Wide2x3"];
var result = CreateMatrix(top.RowCount + lower.RowCount + 2, top.ColumnCount + lower.ColumnCount);
Assert.Throws<ArgumentException>(() => top.DiagonalStack(lower, result));
}
/// <summary>
/// Can compute Frobenius norm.
/// </summary>

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

@ -18,7 +18,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
{
m.PermuteRows(permutation);
}
catch(InvalidOperationException)
catch (InvalidOperationException)
{
Assert.Ignore("Matrix type {0} does not support permutations", matrix.GetType().FullName);
}
@ -136,5 +136,160 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
Assert.That(() => matrix.InsertColumn(0, CreateVector(matrix.RowCount - 1)), Throws.ArgumentException);
Assert.That(() => matrix.InsertColumn(0, CreateVector(matrix.RowCount + 1)), Throws.ArgumentException);
}
[Theory, Timeout(200)]
public void CanAppend(Matrix<T> left, Matrix<T> right)
{
// IF
Assume.That(left.RowCount, Is.EqualTo(right.RowCount));
// THEN
var result = left.Append(right);
Assert.That(result.ColumnCount, Is.EqualTo(left.ColumnCount + right.ColumnCount));
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.That(result[i, j], Is.EqualTo(j < left.ColumnCount ? left[i, j] : right[i, j - left.ColumnCount]));
}
}
// Invalid
Assert.That(() => left.Append(default(Matrix<T>)), Throws.InstanceOf<ArgumentNullException>());
}
[Theory, Timeout(200)]
public void CanAppendIntoResult(Matrix<T> left, Matrix<T> right)
{
// IF
Assume.That(left.RowCount, Is.EqualTo(right.RowCount));
// THEN
var result = CreateDense(left.RowCount, left.ColumnCount + right.ColumnCount);
left.Append(right, result);
Assert.That(result.ColumnCount, Is.EqualTo(left.ColumnCount + right.ColumnCount));
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.That(result[i, j], Is.EqualTo(j < left.ColumnCount ? left[i, j] : right[i, j - left.ColumnCount]));
}
}
// Invalid
Assert.That(() => left.Append(right, default(Matrix<T>)), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => left.Append(right, CreateDense(left.RowCount + 1, left.ColumnCount + right.ColumnCount)), Throws.ArgumentException);
Assert.That(() => left.Append(right, CreateDense(left.RowCount - 1, left.ColumnCount + right.ColumnCount)), Throws.ArgumentException);
Assert.That(() => left.Append(right, CreateDense(left.RowCount, left.ColumnCount + right.ColumnCount + 1)), Throws.ArgumentException);
Assert.That(() => left.Append(right, CreateDense(left.RowCount, left.ColumnCount + right.ColumnCount - 1)), Throws.ArgumentException);
}
[Theory, Timeout(200)]
public void CanStack(Matrix<T> top, Matrix<T> bottom)
{
// IF
Assume.That(top.ColumnCount, Is.EqualTo(bottom.ColumnCount));
// THEN
var result = top.Stack(bottom);
Assert.That(result.RowCount, Is.EqualTo(top.RowCount + bottom.RowCount));
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.That(result[i, j], Is.EqualTo(i < top.RowCount ? top[i, j] : bottom[i - top.RowCount, j]));
}
}
// Invalid
Assert.That(() => top.Stack(default(Matrix<T>)), Throws.InstanceOf<ArgumentNullException>());
}
[Theory, Timeout(200)]
public void CanStackIntoResult(Matrix<T> top, Matrix<T> bottom)
{
// IF
Assume.That(top.ColumnCount, Is.EqualTo(bottom.ColumnCount));
// THEN
var result = CreateDense(top.RowCount + bottom.RowCount, top.ColumnCount);
top.Stack(bottom, result);
Assert.That(result.RowCount, Is.EqualTo(top.RowCount + bottom.RowCount));
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.That(result[i, j], Is.EqualTo(i < top.RowCount ? top[i, j] : bottom[i - top.RowCount, j]));
}
}
// Invalid
Assert.That(() => top.Stack(bottom, default(Matrix<T>)), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => top.Stack(bottom, CreateDense(top.RowCount + bottom.RowCount + 1, top.ColumnCount)), Throws.ArgumentException);
Assert.That(() => top.Stack(bottom, CreateDense(top.RowCount + bottom.RowCount - 1, top.ColumnCount)), Throws.ArgumentException);
Assert.That(() => top.Stack(bottom, CreateDense(top.RowCount + bottom.RowCount, top.ColumnCount + 1)), Throws.ArgumentException);
Assert.That(() => top.Stack(bottom, CreateDense(top.RowCount + bottom.RowCount, top.ColumnCount - 1)), Throws.ArgumentException);
}
[Theory, Timeout(200)]
public void CanDiagonalStack(Matrix<T> left, Matrix<T> right)
{
var result = left.DiagonalStack(right);
Assert.That(result.RowCount, Is.EqualTo(left.RowCount + right.RowCount));
Assert.That(result.ColumnCount, Is.EqualTo(left.ColumnCount + right.ColumnCount));
for (var i = 0; i < left.RowCount; i++)
{
for (var j = 0; j < left.ColumnCount; j++)
{
Assert.That(result[i, j], Is.EqualTo(left[i, j]), "{0}+{1}->{2}", left.GetType(), right.GetType(), result.GetType());
}
}
for (var i = 0; i < right.RowCount; i++)
{
for (var j = 0; j < right.ColumnCount; j++)
{
Assert.That(result[left.RowCount + i, left.ColumnCount + j], Is.EqualTo(right[i, j]), "{0}+{1}->{2}", left.GetType(), right.GetType(), result.GetType());
}
}
// Invalid
Assert.That(() => left.DiagonalStack(default(Matrix<T>)), Throws.InstanceOf<ArgumentNullException>(), "{0}+{1}->{2}", left.GetType(), right.GetType(), result.GetType());
}
[Theory, Timeout(200)]
public void CanDiagonalStackIntoResult(Matrix<T> left, Matrix<T> right)
{
var result = CreateDense(left.RowCount + right.RowCount, left.ColumnCount + right.ColumnCount);
left.DiagonalStack(right, result);
Assert.That(result.RowCount, Is.EqualTo(left.RowCount + right.RowCount));
Assert.That(result.ColumnCount, Is.EqualTo(left.ColumnCount + right.ColumnCount));
for (var i = 0; i < left.RowCount; i++)
{
for (var j = 0; j < left.ColumnCount; j++)
{
Assert.That(result[i, j], Is.EqualTo(left[i, j]));
}
}
for (var i = 0; i < right.RowCount; i++)
{
for (var j = 0; j < right.ColumnCount; j++)
{
Assert.That(result[left.RowCount + i, left.ColumnCount + j], Is.EqualTo(right[i, j]));
}
}
// Invalid
Assert.That(() => left.DiagonalStack(right, default(Matrix<T>)), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => left.DiagonalStack(right, CreateDense(left.RowCount + right.RowCount + 1, left.ColumnCount + right.ColumnCount)), Throws.ArgumentException);
Assert.That(() => left.DiagonalStack(right, CreateDense(left.RowCount + right.RowCount - 1, left.ColumnCount + right.ColumnCount)), Throws.ArgumentException);
Assert.That(() => left.DiagonalStack(right, CreateDense(left.RowCount + right.RowCount, left.ColumnCount + right.ColumnCount + 1)), Throws.ArgumentException);
Assert.That(() => left.DiagonalStack(right, CreateDense(left.RowCount + right.RowCount, left.ColumnCount + right.ColumnCount - 1)), Throws.ArgumentException);
}
}
}

32
src/UnitTests/LinearAlgebraTests/Single/DiagonalMatrixTests.cs

@ -201,38 +201,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
Assert.Throws<ArgumentOutOfRangeException>(() => DiagonalMatrix.Identity(order));
}
/// <summary>
/// Can diagonally stack matrices into a result matrix.
/// </summary>
public override void CanDiagonallyStackMatricesIntoResult()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = new SparseMatrix(top.RowCount + bottom.RowCount, top.ColumnCount + bottom.ColumnCount);
top.DiagonalStack(bottom, result);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(0, result[i, j]);
}
}
}
}
/// <summary>
/// Can multiply a matrix with matrix.
/// </summary>

236
src/UnitTests/LinearAlgebraTests/Single/MatrixTests.cs

@ -125,242 +125,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
}
}
/// <summary>
/// Can append matrices.
/// </summary>
[Test]
public void CanAppendMatrices()
{
var left = CreateMatrix(TestData2D["Singular3x3"]);
var right = CreateMatrix(TestData2D["Tall3x2"]);
var result = left.Append(right);
Assert.AreEqual(left.ColumnCount + right.ColumnCount, result.ColumnCount);
Assert.AreEqual(left.RowCount, right.RowCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.AreEqual(j < left.ColumnCount ? left[i, j] : right[i, j - left.ColumnCount], result[i, j]);
}
}
}
/// <summary>
/// Append with right <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void AppendWithRightNullThrowsArgumentNullException()
{
var left = TestMatrices["Square3x3"];
Matrix<float> right = null;
Assert.Throws<ArgumentNullException>(() => left.Append(right));
}
/// <summary>
/// Append with result <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void AppendWithResultNullThrowsArgumentNullException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Tall3x2"];
Matrix<float> result = null;
Assert.Throws<ArgumentNullException>(() => left.Append(right, result));
}
/// <summary>
/// Appending two matrices with different row count throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void AppendWithDifferentRowCountThrowsArgumentException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Wide2x3"];
Assert.Throws<ArgumentException>(() => { var result = left.Append(right); });
}
/// <summary>
/// Appending with invalid result matrix columns throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void AppendWithInvalidResultMatrixColumnsThrowsArgumentException()
{
var left = TestMatrices["Square3x3"];
var right = TestMatrices["Tall3x2"];
var result = CreateMatrix(3, 2);
Assert.Throws<ArgumentException>(() => left.Append(right, result));
}
/// <summary>
/// Can stack matrices.
/// </summary>
[Test]
public void CanStackMatrices()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Wide2x3"];
var result = top.Stack(bottom);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
Assert.AreEqual(result[i, j], i < top.RowCount ? top[i, j] : bottom[i - top.RowCount, j]);
}
}
}
/// <summary>
/// Stacking with a bottom <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void StackWithBottomNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
Matrix<float> bottom = null;
var result = CreateMatrix(top.RowCount + top.RowCount, top.ColumnCount);
Assert.Throws<ArgumentNullException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Stacking with a result <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void StackWithResultNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Square3x3"];
Matrix<float> result = null;
Assert.Throws<ArgumentNullException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Stacking matrices with different columns throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void StackMatricesWithDifferentColumnsThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Tall3x2"];
var result = CreateMatrix(top.RowCount + lower.RowCount, top.ColumnCount);
Assert.Throws<ArgumentException>(() => top.Stack(lower, result));
}
/// <summary>
/// Stacking with invalid result matrix rows throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void StackWithInvalidResultMatrixRowsThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var bottom = TestMatrices["Wide2x3"];
var result = CreateMatrix(1, 3);
Assert.Throws<ArgumentException>(() => top.Stack(bottom, result));
}
/// <summary>
/// Can diagonally stack matrices.
/// </summary>
[Test]
public void CanDiagonallyStackMatrices()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = top.DiagonalStack(bottom);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(0, result[i, j]);
}
}
}
}
/// <summary>
/// Diagonal stack with lower <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void DiagonalStackWithLowerNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
Matrix<float> lower = null;
Assert.Throws<ArgumentNullException>(() => top.DiagonalStack(lower));
}
/// <summary>
/// Can diagonally stack matrices into a result matrix.
/// </summary>
[Test]
public virtual void CanDiagonallyStackMatricesIntoResult()
{
var top = TestMatrices["Tall3x2"];
var bottom = TestMatrices["Wide2x3"];
var result = CreateMatrix(top.RowCount + bottom.RowCount, top.ColumnCount + bottom.ColumnCount);
top.DiagonalStack(bottom, result);
Assert.AreEqual(top.RowCount + bottom.RowCount, result.RowCount);
Assert.AreEqual(top.ColumnCount + bottom.ColumnCount, result.ColumnCount);
for (var i = 0; i < result.RowCount; i++)
{
for (var j = 0; j < result.ColumnCount; j++)
{
if (i < top.RowCount && j < top.ColumnCount)
{
Assert.AreEqual(top[i, j], result[i, j]);
}
else if (i >= top.RowCount && j >= top.ColumnCount)
{
Assert.AreEqual(bottom[i - top.RowCount, j - top.ColumnCount], result[i, j]);
}
else
{
Assert.AreEqual(0, result[i, j]);
}
}
}
}
/// <summary>
/// Diagonal stack into <c>null</c> result throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void DiagonalStackIntoResultNullThrowsArgumentNullException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Wide2x3"];
Matrix<float> result = null;
Assert.Throws<ArgumentNullException>(() => top.DiagonalStack(lower, result));
}
/// <summary>
/// Diagonal stack into invalid result matrix throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void DiagonalStackIntoInvalidResultMatrixThrowsArgumentException()
{
var top = TestMatrices["Square3x3"];
var lower = TestMatrices["Wide2x3"];
var result = CreateMatrix(top.RowCount + lower.RowCount + 2, top.ColumnCount + lower.ColumnCount);
Assert.Throws<ArgumentException>(() => top.DiagonalStack(lower, result));
}
/// <summary>
/// Can compute Frobenius norm.
/// </summary>

Loading…
Cancel
Save