Browse Source

LA: SetSubMatrix overloads (one more convenient, one more flexible) #133

optimization-1
Christoph Ruegg 13 years ago
parent
commit
cc4a4e57ce
  1. 47
      src/Numerics/LinearAlgebra/Matrix.cs
  2. 2
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs

47
src/Numerics/LinearAlgebra/Matrix.cs

@ -872,6 +872,23 @@ namespace MathNet.Numerics.LinearAlgebra
new DenseVectorStorage<T>(row.Length, row).CopyToRow(Storage, rowIndex);
}
/// <summary>
/// Copies the values of a given matrix into a region in this matrix.
/// </summary>
/// <param name="rowIndex">The row to start copying to.</param>
/// <param name="columnIndex">The column to start copying to.</param>
/// <param name="subMatrix">The sub-matrix to copy from.</param>
/// <exception cref="ArgumentOutOfRangeException">If: <list><item><paramref name="rowIndex"/> is
/// negative, or greater than or equal to the number of rows.</item>
/// <item><paramref name="columnIndex"/> is negative, or greater than or equal to the number
/// of columns.</item>
/// <item><c>(columnIndex + columnLength) &gt;= Columns</c></item>
/// <item><c>(rowIndex + rowLength) &gt;= Rows</c></item></list></exception>
public void SetSubMatrix(int rowIndex, int columnIndex, Matrix<T> subMatrix)
{
subMatrix.Storage.CopySubMatrixTo(Storage, 0, rowIndex, subMatrix.RowCount, 0, columnIndex, subMatrix.ColumnCount);
}
/// <summary>
/// Copies the values of a given matrix into a region in this matrix.
/// </summary>
@ -886,20 +903,38 @@ namespace MathNet.Numerics.LinearAlgebra
/// of columns.</item>
/// <item><c>(columnIndex + columnLength) &gt;= Columns</c></item>
/// <item><c>(rowIndex + rowLength) &gt;= Rows</c></item></list></exception>
/// <exception cref="ArgumentNullException">If <paramref name="subMatrix"/> is <see langword="null" /></exception>
/// <item>the size of <paramref name="subMatrix"/> is not at least <paramref name="rowCount"/> x <paramref name="columnCount"/>.</item>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowCount"/> or <paramref name="columnCount"/>
/// is not positive.</exception>
public void SetSubMatrix(int rowIndex, int rowCount, int columnIndex, int columnCount, Matrix<T> subMatrix)
{
if (subMatrix == null)
{
throw new ArgumentNullException("subMatrix");
}
subMatrix.Storage.CopySubMatrixTo(Storage, 0, rowIndex, rowCount, 0, columnIndex, columnCount);
}
/// <summary>
/// Copies the values of a given matrix into a region in this matrix.
/// </summary>
/// <param name="rowIndex">The row to start copying to.</param>
/// <param name="sorceRowIndex">The row of the sub-matrix to start copying from.</param>
/// <param name="rowCount">The number of rows to copy. Must be positive.</param>
/// <param name="columnIndex">The column to start copying to.</param>
/// <param name="sourceColumnIndex">The column of the sub-matrix to start copying from.</param>
/// <param name="columnCount">The number of columns to copy. Must be positive.</param>
/// <param name="subMatrix">The sub-matrix to copy from.</param>
/// <exception cref="ArgumentOutOfRangeException">If: <list><item><paramref name="rowIndex"/> is
/// negative, or greater than or equal to the number of rows.</item>
/// <item><paramref name="columnIndex"/> is negative, or greater than or equal to the number
/// of columns.</item>
/// <item><c>(columnIndex + columnLength) &gt;= Columns</c></item>
/// <item><c>(rowIndex + rowLength) &gt;= Rows</c></item></list></exception>
/// <item>the size of <paramref name="subMatrix"/> is not at least <paramref name="rowCount"/> x <paramref name="columnCount"/>.</item>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowCount"/> or <paramref name="columnCount"/>
/// is not positive.</exception>
public void SetSubMatrix(int rowIndex, int sorceRowIndex, int rowCount, int columnIndex, int sourceColumnIndex, int columnCount, Matrix<T> subMatrix)
{
subMatrix.Storage.CopySubMatrixTo(Storage, sorceRowIndex, rowIndex, rowCount, sourceColumnIndex, columnIndex, columnCount);
}
/// <summary>
/// Copies the values of the given Vector to the diagonal.
/// </summary>

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

@ -653,7 +653,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
// Invalid
m = matrix.Clone();
Assert.That(() => m.SetSubMatrix(0, 1, 0, 1, default(Matrix<T>)), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => m.SetSubMatrix(0, 1, 0, 1, default(Matrix<T>)), Throws.InstanceOf<NullReferenceException>());
Assert.That(() => m.SetSubMatrix(-1, 1, 0, 1, CreateDenseZero(1,1)), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => m.SetSubMatrix(matrix.RowCount, 1, 0, 1, CreateDenseZero(1, 1)), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => m.SetSubMatrix(0, 0, 0, 1, CreateDenseZero(1, 1)), Throws.InstanceOf<ArgumentOutOfRangeException>());

Loading…
Cancel
Save