Browse Source

LA: Diagonal matrices: clean up some pointless null-checks

pull/184/head
Christoph Ruegg 13 years ago
parent
commit
465a2c2bd8
  1. 46
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  2. 45
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  3. 46
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  4. 46
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  5. 10
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs
  6. 4
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs

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

@ -199,7 +199,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </summary>
/// <param name="other">The matrix to add to this matrix.</param>
/// <param name="result">The matrix to store the result of the addition.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected override void DoAdd(Matrix<Complex> other, Matrix<Complex> result)
{
@ -221,7 +220,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </summary>
/// <param name="other">The matrix to subtract.</param>
/// <param name="result">The matrix to store the result of the subtraction.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected override void DoSubtract(Matrix<Complex> other, Matrix<Complex> result)
{
@ -243,18 +241,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </summary>
/// <param name="source">The array to copy the values from. The length of the vector should be
/// Min(Rows, Columns).</param>
/// <exception cref="ArgumentNullException">If <paramref name="source"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the length of <paramref name="source"/> does not
/// equal Min(Rows, Columns).</exception>
/// <remarks>For non-square matrices, the elements of <paramref name="source"/> are copied to
/// this[i,i].</remarks>
public override void SetDiagonal(Complex[] source)
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (source.Length != _data.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
@ -268,7 +260,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </summary>
/// <param name="source">The vector to copy the values from. The length of the vector should be
/// Min(Rows, Columns).</param>
/// <exception cref="ArgumentNullException">If <paramref name="source"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the length of <paramref name="source"/> does not
/// equal Min(Rows, Columns).</exception>
/// <remarks>For non-square matrices, the elements of <paramref name="source"/> are copied to
@ -295,7 +286,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </summary>
/// <param name="scalar">The scalar to multiply the matrix with.</param>
/// <param name="result">The matrix to store the result of the multiplication.</param>
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
protected override void DoMultiply(Complex scalar, Matrix<Complex> result)
{
@ -640,15 +630,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// Puts the lower triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void LowerTriangle(Matrix<Complex> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -680,15 +664,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// Puts the strictly lower triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void StrictlyLowerTriangle(Matrix<Complex> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -710,15 +688,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// Puts the upper triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void UpperTriangle(Matrix<Complex> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -745,15 +717,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// Puts the strictly upper triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void StrictlyUpperTriangle(Matrix<Complex> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -794,16 +760,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <param name="columnIndex">The index of where to insert the column.</param>
/// <param name="column">The column to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="column "/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> is &lt; zero or &gt; the number of columns.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="column"/> != the number of rows.</exception>
public override Matrix<Complex> InsertColumn(int columnIndex, Vector<Complex> column)
{
if (column == null)
{
throw new ArgumentNullException("column");
}
if (columnIndex < 0 || columnIndex > ColumnCount)
{
throw new ArgumentOutOfRangeException("columnIndex");
@ -837,16 +797,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <param name="rowIndex">The index of where to insert the row.</param>
/// <param name="row">The row to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="row"/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> is &lt; zero or &gt; the number of rows.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="row"/> != the number of columns.</exception>
public override Matrix<Complex> InsertRow(int rowIndex, Vector<Complex> row)
{
if (row == null)
{
throw new ArgumentNullException("row");
}
if (rowIndex < 0 || rowIndex > RowCount)
{
throw new ArgumentOutOfRangeException("rowIndex");

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

@ -194,7 +194,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </summary>
/// <param name="other">The matrix to add to this matrix.</param>
/// <param name="result">The matrix to store the result of the addition.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected override void DoAdd(Matrix<Complex32> other, Matrix<Complex32> result)
{
@ -216,7 +215,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </summary>
/// <param name="other">The matrix to subtract.</param>
/// <param name="result">The matrix to store the result of the subtraction.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected override void DoSubtract(Matrix<Complex32> other, Matrix<Complex32> result)
{
@ -238,18 +236,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </summary>
/// <param name="source">The array to copy the values from. The length of the vector should be
/// Min(Rows, Columns).</param>
/// <exception cref="ArgumentNullException">If <paramref name="source"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the length of <paramref name="source"/> does not
/// equal Min(Rows, Columns).</exception>
/// <remarks>For non-square matrices, the elements of <paramref name="source"/> are copied to
/// this[i,i].</remarks>
public override void SetDiagonal(Complex32[] source)
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (source.Length != _data.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
@ -263,7 +255,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </summary>
/// <param name="source">The vector to copy the values from. The length of the vector should be
/// Min(Rows, Columns).</param>
/// <exception cref="ArgumentNullException">If <paramref name="source"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the length of <paramref name="source"/> does not
/// equal Min(Rows, Columns).</exception>
/// <remarks>For non-square matrices, the elements of <paramref name="source"/> are copied to
@ -633,15 +624,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Puts the lower triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void LowerTriangle(Matrix<Complex32> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -673,15 +658,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Puts the strictly lower triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void StrictlyLowerTriangle(Matrix<Complex32> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -703,15 +682,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Puts the upper triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void UpperTriangle(Matrix<Complex32> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -738,15 +711,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Puts the strictly upper triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void StrictlyUpperTriangle(Matrix<Complex32> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -787,16 +754,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <param name="columnIndex">The index of where to insert the column.</param>
/// <param name="column">The column to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="column "/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> is &lt; zero or &gt; the number of columns.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="column"/> != the number of rows.</exception>
public override Matrix<Complex32> InsertColumn(int columnIndex, Vector<Complex32> column)
{
if (column == null)
{
throw new ArgumentNullException("column");
}
if (columnIndex < 0 || columnIndex > ColumnCount)
{
throw new ArgumentOutOfRangeException("columnIndex");
@ -830,16 +791,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <param name="rowIndex">The index of where to insert the row.</param>
/// <param name="row">The row to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="row"/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> is &lt; zero or &gt; the number of rows.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="row"/> != the number of columns.</exception>
public override Matrix<Complex32> InsertRow(int rowIndex, Vector<Complex32> row)
{
if (row == null)
{
throw new ArgumentNullException("row");
}
if (rowIndex < 0 || rowIndex > RowCount)
{
throw new ArgumentOutOfRangeException("rowIndex");

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

@ -193,7 +193,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </summary>
/// <param name="other">The matrix to add to this matrix.</param>
/// <param name="result">The matrix to store the result of the addition.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected override void DoAdd(Matrix<double> other, Matrix<double> result)
{
@ -215,7 +214,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </summary>
/// <param name="other">The matrix to subtract.</param>
/// <param name="result">The matrix to store the result of the subtraction.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected override void DoSubtract(Matrix<double> other, Matrix<double> result)
{
@ -237,18 +235,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </summary>
/// <param name="source">The array to copy the values from. The length of the vector should be
/// Min(Rows, Columns).</param>
/// <exception cref="ArgumentNullException">If <paramref name="source"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the length of <paramref name="source"/> does not
/// equal Min(Rows, Columns).</exception>
/// <remarks>For non-square matrices, the elements of <paramref name="source"/> are copied to
/// this[i,i].</remarks>
public override void SetDiagonal(double[] source)
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (source.Length != _data.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
@ -262,7 +254,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </summary>
/// <param name="source">The vector to copy the values from. The length of the vector should be
/// Min(Rows, Columns).</param>
/// <exception cref="ArgumentNullException">If <paramref name="source"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the length of <paramref name="source"/> does not
/// equal Min(Rows, Columns).</exception>
/// <remarks>For non-square matrices, the elements of <paramref name="source"/> are copied to
@ -289,7 +280,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </summary>
/// <param name="scalar">The scalar to multiply the matrix with.</param>
/// <param name="result">The matrix to store the result of the multiplication.</param>
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
protected override void DoMultiply(double scalar, Matrix<double> result)
{
@ -634,15 +624,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// Puts the lower triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void LowerTriangle(Matrix<double> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -674,15 +658,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// Puts the strictly lower triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void StrictlyLowerTriangle(Matrix<double> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -704,15 +682,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// Puts the upper triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void UpperTriangle(Matrix<double> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -739,15 +711,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// Puts the strictly upper triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void StrictlyUpperTriangle(Matrix<double> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -788,16 +754,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <param name="columnIndex">The index of where to insert the column.</param>
/// <param name="column">The column to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="column "/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> is &lt; zero or &gt; the number of columns.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="column"/> != the number of rows.</exception>
public override Matrix<double> InsertColumn(int columnIndex, Vector<double> column)
{
if (column == null)
{
throw new ArgumentNullException("column");
}
if (columnIndex < 0 || columnIndex > ColumnCount)
{
throw new ArgumentOutOfRangeException("columnIndex");
@ -831,16 +791,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <param name="rowIndex">The index of where to insert the row.</param>
/// <param name="row">The row to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="row"/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> is &lt; zero or &gt; the number of rows.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="row"/> != the number of columns.</exception>
public override Matrix<double> InsertRow(int rowIndex, Vector<double> row)
{
if (row == null)
{
throw new ArgumentNullException("row");
}
if (rowIndex < 0 || rowIndex > RowCount)
{
throw new ArgumentOutOfRangeException("rowIndex");

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

@ -193,7 +193,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </summary>
/// <param name="other">The matrix to add to this matrix.</param>
/// <param name="result">The matrix to store the result of the addition.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected override void DoAdd(Matrix<float> other, Matrix<float> result)
{
@ -215,7 +214,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </summary>
/// <param name="other">The matrix to subtract.</param>
/// <param name="result">The matrix to store the result of the subtraction.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected override void DoSubtract(Matrix<float> other, Matrix<float> result)
{
@ -237,18 +235,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </summary>
/// <param name="source">The array to copy the values from. The length of the vector should be
/// Min(Rows, Columns).</param>
/// <exception cref="ArgumentNullException">If <paramref name="source"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the length of <paramref name="source"/> does not
/// equal Min(Rows, Columns).</exception>
/// <remarks>For non-square matrices, the elements of <paramref name="source"/> are copied to
/// this[i,i].</remarks>
public override void SetDiagonal(float[] source)
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (source.Length != _data.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
@ -262,7 +254,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </summary>
/// <param name="source">The vector to copy the values from. The length of the vector should be
/// Min(Rows, Columns).</param>
/// <exception cref="ArgumentNullException">If <paramref name="source"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the length of <paramref name="source"/> does not
/// equal Min(Rows, Columns).</exception>
/// <remarks>For non-square matrices, the elements of <paramref name="source"/> are copied to
@ -289,7 +280,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </summary>
/// <param name="scalar">The scalar to multiply the matrix with.</param>
/// <param name="result">The matrix to store the result of the multiplication.</param>
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
protected override void DoMultiply(float scalar, Matrix<float> result)
{
@ -634,15 +624,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// Puts the lower triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void LowerTriangle(Matrix<float> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -674,15 +658,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// Puts the strictly lower triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void StrictlyLowerTriangle(Matrix<float> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -704,15 +682,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// Puts the upper triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void UpperTriangle(Matrix<float> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -739,15 +711,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// Puts the strictly upper triangle of this matrix into the result matrix.
/// </summary>
/// <param name="result">Where to store the lower triangle.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
public override void StrictlyUpperTriangle(Matrix<float> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
@ -788,16 +754,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <param name="columnIndex">The index of where to insert the column.</param>
/// <param name="column">The column to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="column "/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> is &lt; zero or &gt; the number of columns.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="column"/> != the number of rows.</exception>
public override Matrix<float> InsertColumn(int columnIndex, Vector<float> column)
{
if (column == null)
{
throw new ArgumentNullException("column");
}
if (columnIndex < 0 || columnIndex > ColumnCount)
{
throw new ArgumentOutOfRangeException("columnIndex");
@ -831,16 +791,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <param name="rowIndex">The index of where to insert the row.</param>
/// <param name="row">The row to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="row"/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> is &lt; zero or &gt; the number of rows.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="row"/> != the number of columns.</exception>
public override Matrix<float> InsertRow(int rowIndex, Vector<float> row)
{
if (row == null)
{
throw new ArgumentNullException("row");
}
if (rowIndex < 0 || rowIndex > RowCount)
{
throw new ArgumentOutOfRangeException("rowIndex");

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

@ -404,7 +404,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
}
Assert.That(() => matrix.UpperTriangle(null), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.UpperTriangle(null), Throws.Exception);
Assert.That(() => matrix.UpperTriangle(CreateSparseZero(matrix.RowCount + 1, matrix.ColumnCount)), Throws.ArgumentException);
Assert.That(() => matrix.UpperTriangle(CreateDenseZero(matrix.RowCount, matrix.ColumnCount + 1)), Throws.ArgumentException);
}
@ -445,7 +445,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
}
Assert.That(() => matrix.LowerTriangle(null), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.LowerTriangle(null), Throws.Exception);
Assert.That(() => matrix.LowerTriangle(CreateSparseZero(matrix.RowCount + 1, matrix.ColumnCount)), Throws.ArgumentException);
Assert.That(() => matrix.LowerTriangle(CreateDenseZero(matrix.RowCount, matrix.ColumnCount + 1)), Throws.ArgumentException);
}
@ -486,7 +486,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
}
Assert.That(() => matrix.StrictlyUpperTriangle(null), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.StrictlyUpperTriangle(null), Throws.Exception);
Assert.That(() => matrix.StrictlyUpperTriangle(CreateSparseZero(matrix.RowCount + 1, matrix.ColumnCount)), Throws.ArgumentException);
Assert.That(() => matrix.StrictlyUpperTriangle(CreateDenseZero(matrix.RowCount, matrix.ColumnCount + 1)), Throws.ArgumentException);
}
@ -527,7 +527,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
}
Assert.That(() => matrix.StrictlyLowerTriangle(null), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.StrictlyLowerTriangle(null), Throws.Exception);
Assert.That(() => matrix.StrictlyLowerTriangle(CreateSparseZero(matrix.RowCount + 1, matrix.ColumnCount)), Throws.ArgumentException);
Assert.That(() => matrix.StrictlyLowerTriangle(CreateDenseZero(matrix.RowCount, matrix.ColumnCount + 1)), Throws.ArgumentException);
}
@ -577,7 +577,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
// Invalid
Assert.That(() => matrix.SetDiagonal(default(T[])), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.SetDiagonal(default(T[])), Throws.Exception);
Assert.That(() => matrix.SetDiagonal(new T[Math.Min(matrix.RowCount, matrix.ColumnCount) - 1]), Throws.ArgumentException);
Assert.That(() => matrix.SetDiagonal(new T[Math.Min(matrix.RowCount, matrix.ColumnCount) + 1]), Throws.ArgumentException);
}

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

@ -124,7 +124,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
// Invalid
Assert.That(() => matrix.InsertRow(0, default(Vector<T>)), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.InsertRow(0, default(Vector<T>)), Throws.Exception);
Assert.That(() => matrix.InsertRow(-1, CreateVectorZero(matrix.ColumnCount)), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.InsertRow(matrix.RowCount + 1, CreateVectorZero(matrix.ColumnCount)), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.InsertRow(0, CreateVectorZero(matrix.ColumnCount - 1)), Throws.ArgumentException);
@ -160,7 +160,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
// Invalid
Assert.That(() => matrix.InsertColumn(0, default(Vector<T>)), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.InsertColumn(0, default(Vector<T>)), Throws.Exception);
Assert.That(() => matrix.InsertColumn(-1, CreateVectorZero(matrix.RowCount)), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.InsertColumn(matrix.ColumnCount + 1, CreateVectorZero(matrix.RowCount)), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.InsertColumn(0, CreateVectorZero(matrix.RowCount - 1)), Throws.ArgumentException);

Loading…
Cancel
Save