diff --git a/src/FSharp/LinearAlgebra.fs b/src/FSharp/LinearAlgebra.fs index ce12ce3b..18fcd581 100644 --- a/src/FSharp/LinearAlgebra.fs +++ b/src/FSharp/LinearAlgebra.fs @@ -94,22 +94,22 @@ module FSharpExtensions = x.Row(r, cstart, cfinish - cstart + 1) /// Gets a column subvector using a specified row index and column range. - /// This method can be used via the x.[r, c1 .. c2] syntax (F#3.1) + /// This method can be used via the x.[r1 .. r2, c] syntax (F#3.1) member x.GetSlice(rstart, rfinish, c) = let rstart = defaultArg rstart 0 let rfinish = defaultArg rfinish (x.RowCount - 1) x.Column(c, rstart, rfinish - rstart + 1) -// /// Sets a row subvector using a specified row index and column range. -// /// This method can be used via the x.[r, c1 .. c2] <- v syntax (F#3.1) -// member x.GetSlice(r, cstart, cfinish, values) = -// let cstart = defaultArg cstart 0 -// let cfinish = defaultArg cfinish (x.ColumnCount - 1) -// x.SetRow(r, cstart, cfinish - cstart + 1, values) -// -// /// Sets a column subvector using a specified row index and column range. -// /// This method can be used via the x.[r, c1 .. c2] <- v syntax (F#3.1) -// member x.GetSlice(rstart, rfinish, c, values) = -// let rstart = defaultArg rstart 0 -// let rfinish = defaultArg rfinish (x.RowCount - 1) -// x.SetColumn(c, rstart, rfinish - rstart + 1, values) + /// Sets a row subvector using a specified row index and column range. + /// This method can be used via the x.[r, c1 .. c2] <- v syntax (F#3.1) + member x.SetSlice(r, cstart, cfinish, values) = + let cstart = defaultArg cstart 0 + let cfinish = defaultArg cfinish (x.ColumnCount - 1) + x.SetRow(r, cstart, cfinish - cstart + 1, values) + + /// Sets a column subvector using a specified row index and column range. + /// This method can be used via the x.[r1 .. r2, c] <- v syntax (F#3.1) + member x.SetSlice(rstart, rfinish, c, values) = + let rstart = defaultArg rstart 0 + let rfinish = defaultArg rfinish (x.RowCount - 1) + x.SetColumn(c, rstart, rfinish - rstart + 1, values) diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.cs index beaec8f5..18354f33 100644 --- a/src/Numerics/LinearAlgebra/Generic/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Generic/Matrix.cs @@ -803,6 +803,28 @@ namespace MathNet.Numerics.LinearAlgebra.Generic column.Storage.CopyToColumn(Storage, columnIndex); } + /// + /// Copies the values of the given Vector to the specified sub-column. + /// + /// The column to copy the values to. + /// The row to start copying to. + /// The number of elements to copy. + /// The vector to copy the values from. + /// If is . + /// If is less than zero, + /// or greater than or equal to the number of columns. + /// If the size of does not + /// equal the number of rows of this Matrix. + public void SetColumn(int columnIndex, int rowIndex, int length, Vector column) + { + if (column == null) + { + throw new ArgumentNullException("column"); + } + + column.Storage.CopyToSubColumn(Storage, columnIndex, 0, rowIndex, length); + } + /// /// Copies the values of the given array to the specified column. /// @@ -888,6 +910,29 @@ namespace MathNet.Numerics.LinearAlgebra.Generic row.Storage.CopyToRow(Storage, rowIndex); } + /// + /// Copies the values of the given Vector to the specified sub-row. + /// + /// The row to copy the values to. + /// The column to start copying to. + /// The number of elements to copy. + /// The vector to copy the values from. + /// If is . + /// If is less than zero, + /// or greater than or equal to the number of rows. + /// If the size of does not + /// equal the number of columns of this Matrix. + public void SetRow(int rowIndex, int columnIndex, int length, Vector row) + { + if (row == null) + { + throw new ArgumentNullException("row"); + } + + row.Storage.CopyToSubRow(Storage, rowIndex, 0, columnIndex, length); + } + + /// /// Copies the values of the given array to the specified row. ///