|
|
|
@ -36,350 +36,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 |
|
|
|
/// </summary>
|
|
|
|
public abstract partial class MatrixTests : MatrixLoader |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Can set a row.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rowIndex">Row index.</param>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
[TestCase(0, "Singular3x3")] |
|
|
|
[TestCase(1, "Square3x3")] |
|
|
|
[TestCase(2, "Square3x3")] |
|
|
|
public void CanSetRow(int rowIndex, string name) |
|
|
|
{ |
|
|
|
var matrix = TestMatrices[name].Clone(); |
|
|
|
matrix.SetRow(rowIndex, CreateVector(matrix.ColumnCount)); |
|
|
|
|
|
|
|
for (var i = 0; i < matrix.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < matrix.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(i == rowIndex ? Complex32.Zero : TestMatrices[name][i, j], matrix[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can set a column.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="colIndex">Column index.</param>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
[TestCase(0, "Singular3x3")] |
|
|
|
[TestCase(1, "Square3x3")] |
|
|
|
[TestCase(2, "Square3x3")] |
|
|
|
public void CanSetColumn(int colIndex, string name) |
|
|
|
{ |
|
|
|
var matrix = TestMatrices[name].Clone(); |
|
|
|
matrix.SetColumn(colIndex, CreateVector(matrix.ColumnCount)); |
|
|
|
|
|
|
|
for (var i = 0; i < matrix.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < matrix.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(j == colIndex ? Complex32.Zero : TestMatrices[name][i, j], matrix[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get an upper triangle matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
[TestCase("Singular3x3")] |
|
|
|
[TestCase("Square3x3")] |
|
|
|
[TestCase("Square4x4")] |
|
|
|
[TestCase("Tall3x2")] |
|
|
|
[TestCase("Wide2x3")] |
|
|
|
public void CanUpperTriangle(string name) |
|
|
|
{ |
|
|
|
var data = TestMatrices[name]; |
|
|
|
var upper = data.UpperTriangle(); |
|
|
|
for (var i = 0; i < data.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < data.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(i <= j ? data[i, j] : Complex32.Zero, upper[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get an upper triangle matrix into a result matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
[TestCase("Singular3x3")] |
|
|
|
[TestCase("Square3x3")] |
|
|
|
[TestCase("Square4x4")] |
|
|
|
[TestCase("Tall3x2")] |
|
|
|
[TestCase("Wide2x3")] |
|
|
|
public void CanUpperTriangleIntoResult(string name) |
|
|
|
{ |
|
|
|
var data = TestMatrices[name]; |
|
|
|
var result = CreateMatrix(data.RowCount, data.ColumnCount); |
|
|
|
data.UpperTriangle(result); |
|
|
|
for (var i = 0; i < data.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < data.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(i <= j ? data[i, j] : Complex32.Zero, result[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get an upper triangle matrix into <c>null</c> result matrix throws <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void UpperTriangleIntoResultNullThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
Matrix<Complex32> result = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => data.UpperTriangle(result)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get an upper triangle into a result matrix with unequal rows throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void UpperTriangleIntoResultWithUnEqualRowsThrowsArgumentException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
var result = CreateMatrix(data.RowCount + 1, data.ColumnCount); |
|
|
|
Assert.Throws<ArgumentException>(() => data.UpperTriangle(result)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get an upper triangle into a result matrix with unequal columns throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void UpperTriangleIntoResultWithUnEqualColumnsThrowsArgumentException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
var result = CreateMatrix(data.RowCount, data.ColumnCount + 1); |
|
|
|
Assert.Throws<ArgumentException>(() => data.UpperTriangle(result)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a lower triangle matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
[TestCase("Singular3x3")] |
|
|
|
[TestCase("Square3x3")] |
|
|
|
[TestCase("Square4x4")] |
|
|
|
[TestCase("Tall3x2")] |
|
|
|
[TestCase("Wide2x3")] |
|
|
|
public void CanLowerTriangle(string name) |
|
|
|
{ |
|
|
|
var data = TestMatrices[name]; |
|
|
|
var lower = data.LowerTriangle(); |
|
|
|
for (var i = 0; i < data.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < data.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(i >= j ? data[i, j] : Complex32.Zero, lower[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a lower triangle matrix into a result matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
[TestCase("Singular3x3")] |
|
|
|
[TestCase("Square3x3")] |
|
|
|
[TestCase("Square4x4")] |
|
|
|
[TestCase("Tall3x2")] |
|
|
|
[TestCase("Wide2x3")] |
|
|
|
public void CanLowerTriangleIntoResult(string name) |
|
|
|
{ |
|
|
|
var data = TestMatrices[name]; |
|
|
|
var result = CreateMatrix(data.RowCount, data.ColumnCount); |
|
|
|
data.LowerTriangle(result); |
|
|
|
for (var i = 0; i < data.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < data.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(i >= j ? data[i, j] : Complex32.Zero, result[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a lower triangle matrix into <c>null</c> result matrix throws <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void LowerTriangleIntoResultNullThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
Matrix<Complex32> result = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => data.LowerTriangle(result)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a lower triangle into a result matrix with unequal rows throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void LowerTriangleIntoResultWithUnEqualRowsThrowsArgumentException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
var result = CreateMatrix(data.RowCount + 1, data.ColumnCount); |
|
|
|
Assert.Throws<ArgumentException>(() => data.LowerTriangle(result)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a lower triangle into a result matrix with unequal columns throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void LowerTriangleIntoResultWithUnEqualColumnsThrowsArgumentException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
var result = CreateMatrix(data.RowCount, data.ColumnCount + 1); |
|
|
|
Assert.Throws<ArgumentException>(() => data.LowerTriangle(result)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly lower triangle.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void CanStrictlyLowerTriangle() |
|
|
|
{ |
|
|
|
foreach (var data in TestMatrices.Values) |
|
|
|
{ |
|
|
|
var lower = data.StrictlyLowerTriangle(); |
|
|
|
for (var i = 0; i < data.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < data.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(i > j ? data[i, j] : Complex32.Zero, lower[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly lower triangle into a result matrix.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void CanStrictlyLowerTriangleIntoResult() |
|
|
|
{ |
|
|
|
foreach (var data in TestMatrices.Values) |
|
|
|
{ |
|
|
|
var lower = CreateMatrix(data.RowCount, data.ColumnCount); |
|
|
|
data.StrictlyLowerTriangle(lower); |
|
|
|
for (var i = 0; i < data.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < data.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(i > j ? data[i, j] : Complex32.Zero, lower[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly lower triangle with <c>null</c> parameter throws <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void StrictlyLowerTriangleWithNullParameterThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
Matrix<Complex32> lower = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => data.StrictlyLowerTriangle(lower)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly lower triangle into result with unequal column number throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void StrictlyLowerTriangleIntoResultWithUnequalColumnNumberThrowsArgumentException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
var lower = CreateMatrix(data.RowCount, data.ColumnCount + 1); |
|
|
|
Assert.Throws<ArgumentException>(() => data.StrictlyLowerTriangle(lower)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly lower triangle into result with unequal row number throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void StrictlyLowerTriangleIntoResultWithUnequalRowNumberThrowsArgumentException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
var lower = CreateMatrix(data.RowCount + 1, data.ColumnCount); |
|
|
|
Assert.Throws<ArgumentException>(() => data.StrictlyLowerTriangle(lower)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly upper triangle.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void CanStrictlyUpperTriangle() |
|
|
|
{ |
|
|
|
foreach (var data in TestMatrices.Values) |
|
|
|
{ |
|
|
|
var lower = data.StrictlyUpperTriangle(); |
|
|
|
for (var i = 0; i < data.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < data.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(i < j ? data[i, j] : Complex32.Zero, lower[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly upper triangle into a result matrix.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void CanStrictlyUpperTriangleIntoResult() |
|
|
|
{ |
|
|
|
foreach (var data in TestMatrices.Values) |
|
|
|
{ |
|
|
|
var lower = CreateMatrix(data.RowCount, data.ColumnCount); |
|
|
|
data.StrictlyUpperTriangle(lower); |
|
|
|
for (var i = 0; i < data.RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < data.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(i < j ? data[i, j] : Complex32.Zero, lower[i, j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly upper triangle with <c>null</c> parameter throws <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void StrictlyUpperTriangleWithNullParameterThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
Matrix<Complex32> lower = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => data.StrictlyUpperTriangle(lower)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly upper triangle into a result matrix with unequal column number throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void StrictlyUpperTriangleIntoResultWithUnequalColumnNumberThrowsArgumentException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
var lower = CreateMatrix(data.RowCount, data.ColumnCount + 1); |
|
|
|
Assert.Throws<ArgumentException>(() => data.StrictlyUpperTriangle(lower)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a strictly upper triangle into a result matrix with unequal row number throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void StrictlyUpperTriangleIntoResultWithUnequalRowNumberThrowsArgumentException() |
|
|
|
{ |
|
|
|
var data = TestMatrices["Square3x3"]; |
|
|
|
var lower = CreateMatrix(data.RowCount + 1, data.ColumnCount); |
|
|
|
Assert.Throws<ArgumentException>(() => data.StrictlyUpperTriangle(lower)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can transpose a matrix.
|
|
|
|
/// </summary>
|
|
|
|
@ -432,129 +88,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can set a column with an array.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
/// <param name="real">Column real values array.</param>
|
|
|
|
[TestCase("Singular3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Square3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Tall3x2", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Wide2x3", new float[] { 1, 2 })] |
|
|
|
public virtual void CanSetColumnWithArray(string name, float[] real) |
|
|
|
{ |
|
|
|
var column = new Complex32[real.Length]; |
|
|
|
for (var i = 0; i < real.Length; i++) |
|
|
|
{ |
|
|
|
column[i] = new Complex32(real[i], 1); |
|
|
|
} |
|
|
|
|
|
|
|
var matrix = TestMatrices[name]; |
|
|
|
for (var i = 0; i < matrix.ColumnCount; i++) |
|
|
|
{ |
|
|
|
matrix.SetColumn(i, column); |
|
|
|
for (var j = 0; j < matrix.RowCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(matrix[j, i], column[j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a column with <c>null</c> array throws <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public virtual void SetColumnWithNullArrayThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
Complex32[] vec = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => TestMatrices["Singular3x3"].SetColumn(1, vec)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a column with unequal array length throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public virtual void SetColumnWithArrayUnequalLengthThrowsArgumentException() |
|
|
|
{ |
|
|
|
var array = new Complex32[] { 1, 2, 3, 4, 5 }; |
|
|
|
Assert.Throws<ArgumentException>(() => TestMatrices["Singular3x3"].SetColumn(1, array)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a column array with invalid column index throws <c>ArgumentOutOfRangeException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetColumnWithArrayWithInvalidColumnIndexThrowsArgumentOutOfRangeException() |
|
|
|
{ |
|
|
|
var matrix = TestMatrices["Square3x3"]; |
|
|
|
Complex32[] column = { 1, 2, 3 }; |
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.SetColumn(matrix.ColumnCount + 1, column)); |
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.SetColumn(-1, column)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can set a column with a vector.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
/// <param name="real">Column real values.</param>
|
|
|
|
[TestCase("Singular3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Square3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Tall3x2", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Wide2x3", new float[] { 1, 2 })] |
|
|
|
public virtual void CanSetColumnWithVector(string name, float[] real) |
|
|
|
{ |
|
|
|
var column = new Complex32[real.Length]; |
|
|
|
for (var i = 0; i < real.Length; i++) |
|
|
|
{ |
|
|
|
column[i] = new Complex32(real[i], 1); |
|
|
|
} |
|
|
|
|
|
|
|
var matrix = TestMatrices[name]; |
|
|
|
var columnVector = CreateVector(column); |
|
|
|
for (var i = 0; i < matrix.ColumnCount; i++) |
|
|
|
{ |
|
|
|
matrix.SetColumn(i, column); |
|
|
|
for (var j = 0; j < matrix.RowCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(matrix[j, i], columnVector[j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a column with vector with wrong length throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public virtual void SetColumnWithVectorWithUnequalLengthThrowsArgumentException() |
|
|
|
{ |
|
|
|
var matrix = TestMatrices["Singular3x3"]; |
|
|
|
var columnVector = CreateVector(new Complex32[] { 1, 2, 3, 4, 5 }); |
|
|
|
Assert.Throws<ArgumentException>(() => matrix.SetColumn(1, columnVector)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a column with <c>null</c> vector throw <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetColumnWithNullVectorThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
var matrix = TestMatrices["Square3x3"]; |
|
|
|
Vector<Complex32> columnVector = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => matrix.SetColumn(1, columnVector)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set column vector with invalid column index throws <c>ArgumentOutOfRangeException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetColumnWithVectorWithInvalidColumnIndexThrowsArgumentOutOfRangeException() |
|
|
|
{ |
|
|
|
var matrix = TestMatrices["Square3x3"]; |
|
|
|
var column = CreateVector(new Complex32[] { 1, 2, 3 }); |
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.SetColumn(-1, column)); |
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.SetColumn(matrix.ColumnCount + 1, column)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can insert a column.
|
|
|
|
/// </summary>
|
|
|
|
@ -615,118 +148,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 |
|
|
|
Assert.Throws<ArgumentException>(() => matrix.InsertColumn(0, column)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can set a row with an array.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
/// <param name="real">Row index.</param>
|
|
|
|
[TestCase("Singular3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Square3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Tall3x2", new float[] { 1, 2 })] |
|
|
|
[TestCase("Wide2x3", new float[] { 1, 2, 3 })] |
|
|
|
public virtual void CanSetRowWithArray(string name, float[] real) |
|
|
|
{ |
|
|
|
var row = new Complex32[real.Length]; |
|
|
|
for (var i = 0; i < real.Length; i++) |
|
|
|
{ |
|
|
|
row[i] = new Complex32(real[i], 1); |
|
|
|
} |
|
|
|
|
|
|
|
var matrix = TestMatrices[name]; |
|
|
|
for (var i = 0; i < matrix.RowCount; i++) |
|
|
|
{ |
|
|
|
matrix.SetRow(i, row); |
|
|
|
for (var j = 0; j < matrix.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(matrix[i, j], row[j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a row with <c>null</c> array throws <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public virtual void SetRowWithNullArrayThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
Complex32[] arr = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => TestMatrices["Square3x3"].SetRow(1, arr)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a row with an array with invalid row index throws <c>ArgumentOutOfRangeException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetRowWithArrayWithInvalidRowIndexThrowsArgumentOutOfRangeException() |
|
|
|
{ |
|
|
|
var matrix = TestMatrices["Square3x3"]; |
|
|
|
Complex32[] row = { 1, 2, 3 }; |
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.SetRow(-1, row)); |
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.SetRow(matrix.RowCount + 1, row)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can set a row with a vector.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
/// <param name="real">Row real values.</param>
|
|
|
|
[TestCase("Singular3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Square3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Tall3x2", new float[] { 1, 2 })] |
|
|
|
[TestCase("Wide2x3", new float[] { 1, 2, 3 })] |
|
|
|
public virtual void CanSetRowWithVector(string name, float[] real) |
|
|
|
{ |
|
|
|
var row = new Complex32[real.Length]; |
|
|
|
for (var i = 0; i < real.Length; i++) |
|
|
|
{ |
|
|
|
row[i] = new Complex32(real[i], 1); |
|
|
|
} |
|
|
|
|
|
|
|
var matrix = TestMatrices[name]; |
|
|
|
var rowVector = CreateVector(row); |
|
|
|
for (var i = 0; i < matrix.RowCount; i++) |
|
|
|
{ |
|
|
|
matrix.SetRow(i, row); |
|
|
|
for (var j = 0; j < matrix.ColumnCount; j++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(matrix[i, j], rowVector[j]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a row with a vector of unequal length throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public virtual void SetRowWithVectorWithUnequalLengthThrowsArgumentException() |
|
|
|
{ |
|
|
|
var vec = CreateVector(new Complex32[] { 1, 2, 3, 4, 5 }); |
|
|
|
Assert.Throws<ArgumentException>(() => TestMatrices["Square3x3"].SetRow(1, vec)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a row with a <c>null</c> vector throws <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetRowWithNullVectorThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
var matrix = TestMatrices["Square3x3"]; |
|
|
|
Vector<Complex32> rowVector = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => matrix.SetRow(1, rowVector)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a row with a vector with invalid row index throws <c>ArgumentOutOfRangeException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetRowWithVectorWithInvalidRowIndexThrowsArgumentOutOfRangeException() |
|
|
|
{ |
|
|
|
var matrix = TestMatrices["Square3x3"]; |
|
|
|
var row = CreateVector(new Complex32[] { 1, 2, 3 }); |
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.SetRow(-1, row)); |
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.SetRow(matrix.RowCount + 1, row)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can set a submatrix.
|
|
|
|
/// </summary>
|
|
|
|
@ -809,103 +230,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 |
|
|
|
Assert.Throws<ArgumentNullException>(() => TestMatrices["Square3x3"].SetSubMatrix(0, 2, 0, 2, subMatrix)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can set a diagonal vector.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
/// <param name="real">Diagonal real values.</param>
|
|
|
|
[TestCase("Square3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Wide2x3", new float[] { 1, 2 })] |
|
|
|
[TestCase("Tall3x2", new float[] { 1, 2 })] |
|
|
|
public void CanSetDiagonalVector(string name, float[] real) |
|
|
|
{ |
|
|
|
var diagonal = new Complex32[real.Length]; |
|
|
|
for (var i = 0; i < real.Length; i++) |
|
|
|
{ |
|
|
|
diagonal[i] = new Complex32(real[i], 1); |
|
|
|
} |
|
|
|
|
|
|
|
var matrix = TestMatrices[name]; |
|
|
|
var vector = CreateVector(diagonal); |
|
|
|
matrix.SetDiagonal(vector); |
|
|
|
|
|
|
|
var min = Math.Min(matrix.ColumnCount, matrix.RowCount); |
|
|
|
Assert.AreEqual(diagonal.Length, min); |
|
|
|
|
|
|
|
for (var i = 0; i < vector.Count; i++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(vector[i], matrix[i, i]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a diagonal vector with unequal length throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetDiagonalVectorWithUnequalLengthThrowsArgumentException() |
|
|
|
{ |
|
|
|
var vector = CreateVector(new Complex32[] { 1, 2, 3 }); |
|
|
|
Assert.Throws<ArgumentException>(() => TestMatrices["Wide2x3"].SetDiagonal(vector)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a diagonal with <c>null</c> vector throws <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetDiagonalWithNullVectorThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
Vector<Complex32> vector = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => TestMatrices["Square3x3"].SetDiagonal(vector)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can set a diagonal array.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Matrix name.</param>
|
|
|
|
/// <param name="real">Diagonal real values.</param>
|
|
|
|
[TestCase("Square3x3", new float[] { 1, 2, 3 })] |
|
|
|
[TestCase("Wide2x3", new float[] { 1, 2 })] |
|
|
|
[TestCase("Tall3x2", new float[] { 1, 2 })] |
|
|
|
public void CanSetDiagonalArray(string name, float[] real) |
|
|
|
{ |
|
|
|
var diagonal = new Complex32[real.Length]; |
|
|
|
for (var i = 0; i < real.Length; i++) |
|
|
|
{ |
|
|
|
diagonal[i] = new Complex32(real[i], 1); |
|
|
|
} |
|
|
|
|
|
|
|
var matrix = TestMatrices[name]; |
|
|
|
matrix.SetDiagonal(diagonal); |
|
|
|
|
|
|
|
var min = Math.Min(matrix.ColumnCount, matrix.RowCount); |
|
|
|
Assert.AreEqual(diagonal.Length, min); |
|
|
|
|
|
|
|
for (var i = 0; i < diagonal.Length; i++) |
|
|
|
{ |
|
|
|
Assert.AreEqual(diagonal[i], matrix[i, i]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a diagonal array with unequal length throws <c>ArgumentException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetDiagonalArrayWithUnequalLengthThrowsArgumentException() |
|
|
|
{ |
|
|
|
var array = new Complex32[] { 1, 2, 3 }; |
|
|
|
Assert.Throws<ArgumentException>(() => TestMatrices["Wide2x3"].SetDiagonal(array)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a diagonal with <c>null</c> array throws <c>ArgumentNullException</c>.
|
|
|
|
/// </summary>
|
|
|
|
[Test] |
|
|
|
public void SetDiagonalWithNullArrayThrowsArgumentNullException() |
|
|
|
{ |
|
|
|
Complex32[] array = null; |
|
|
|
Assert.Throws<ArgumentNullException>(() => TestMatrices["Square3x3"].SetDiagonal(array)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Can insert a row.
|
|
|
|
/// </summary>
|
|
|
|
|