diff --git a/src/Numerics/LinearAlgebra/Matrix.cs b/src/Numerics/LinearAlgebra/Matrix.cs index cea09b3a..9d167aa7 100644 --- a/src/Numerics/LinearAlgebra/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Matrix.cs @@ -872,6 +872,23 @@ namespace MathNet.Numerics.LinearAlgebra new DenseVectorStorage(row.Length, row).CopyToRow(Storage, rowIndex); } + /// + /// Copies the values of a given matrix into a region in this matrix. + /// + /// The row to start copying to. + /// The column to start copying to. + /// The sub-matrix to copy from. + /// If: is + /// negative, or greater than or equal to the number of rows. + /// is negative, or greater than or equal to the number + /// of columns. + /// (columnIndex + columnLength) >= Columns + /// (rowIndex + rowLength) >= Rows + public void SetSubMatrix(int rowIndex, int columnIndex, Matrix subMatrix) + { + subMatrix.Storage.CopySubMatrixTo(Storage, 0, rowIndex, subMatrix.RowCount, 0, columnIndex, subMatrix.ColumnCount); + } + /// /// Copies the values of a given matrix into a region in this matrix. /// @@ -886,20 +903,38 @@ namespace MathNet.Numerics.LinearAlgebra /// of columns. /// (columnIndex + columnLength) >= Columns /// (rowIndex + rowLength) >= Rows - /// If is /// the size of is not at least x . /// If or /// is not positive. public void SetSubMatrix(int rowIndex, int rowCount, int columnIndex, int columnCount, Matrix subMatrix) { - if (subMatrix == null) - { - throw new ArgumentNullException("subMatrix"); - } - subMatrix.Storage.CopySubMatrixTo(Storage, 0, rowIndex, rowCount, 0, columnIndex, columnCount); } + /// + /// Copies the values of a given matrix into a region in this matrix. + /// + /// The row to start copying to. + /// The row of the sub-matrix to start copying from. + /// The number of rows to copy. Must be positive. + /// The column to start copying to. + /// The column of the sub-matrix to start copying from. + /// The number of columns to copy. Must be positive. + /// The sub-matrix to copy from. + /// If: is + /// negative, or greater than or equal to the number of rows. + /// is negative, or greater than or equal to the number + /// of columns. + /// (columnIndex + columnLength) >= Columns + /// (rowIndex + rowLength) >= Rows + /// the size of is not at least x . + /// If or + /// is not positive. + public void SetSubMatrix(int rowIndex, int sorceRowIndex, int rowCount, int columnIndex, int sourceColumnIndex, int columnCount, Matrix subMatrix) + { + subMatrix.Storage.CopySubMatrixTo(Storage, sorceRowIndex, rowIndex, rowCount, sourceColumnIndex, columnIndex, columnCount); + } + /// /// Copies the values of the given Vector to the diagonal. /// diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs index 53e6131f..a724cfc4 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs +++ b/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)), Throws.InstanceOf()); + Assert.That(() => m.SetSubMatrix(0, 1, 0, 1, default(Matrix)), Throws.InstanceOf()); Assert.That(() => m.SetSubMatrix(-1, 1, 0, 1, CreateDenseZero(1,1)), Throws.InstanceOf()); Assert.That(() => m.SetSubMatrix(matrix.RowCount, 1, 0, 1, CreateDenseZero(1, 1)), Throws.InstanceOf()); Assert.That(() => m.SetSubMatrix(0, 0, 0, 1, CreateDenseZero(1, 1)), Throws.InstanceOf());