|
|
|
@ -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>
|
|
|
|
|