Browse Source

FSharp: support new F#3.1 slicing setters on matrices

v2
Christoph Ruegg 13 years ago
parent
commit
a1e46dff86
  1. 28
      src/FSharp/LinearAlgebra.fs
  2. 45
      src/Numerics/LinearAlgebra/Generic/Matrix.cs

28
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)

45
src/Numerics/LinearAlgebra/Generic/Matrix.cs

@ -803,6 +803,28 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
column.Storage.CopyToColumn(Storage, columnIndex);
}
/// <summary>
/// Copies the values of the given Vector to the specified sub-column.
/// </summary>
/// <param name="columnIndex">The column to copy the values to.</param>
/// <param name="rowIndex">The row to start copying to.</param>
/// <param name="length">The number of elements to copy.</param>
/// <param name="column">The vector to copy the values from.</param>
/// <exception cref="ArgumentNullException">If <paramref name="column"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> is less than zero,
/// or greater than or equal to the number of columns.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="column"/> does not
/// equal the number of rows of this <strong>Matrix</strong>.</exception>
public void SetColumn(int columnIndex, int rowIndex, int length, Vector<T> column)
{
if (column == null)
{
throw new ArgumentNullException("column");
}
column.Storage.CopyToSubColumn(Storage, columnIndex, 0, rowIndex, length);
}
/// <summary>
/// Copies the values of the given array to the specified column.
/// </summary>
@ -888,6 +910,29 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
row.Storage.CopyToRow(Storage, rowIndex);
}
/// <summary>
/// Copies the values of the given Vector to the specified sub-row.
/// </summary>
/// <param name="rowIndex">The row to copy the values to.</param>
/// <param name="columnIndex">The column to start copying to.</param>
/// <param name="length">The number of elements to copy.</param>
/// <param name="row">The vector to copy the values from.</param>
/// <exception cref="ArgumentNullException">If <paramref name="row"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> is less than zero,
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="row"/> does not
/// equal the number of columns of this <strong>Matrix</strong>.</exception>
public void SetRow(int rowIndex, int columnIndex, int length, Vector<T> row)
{
if (row == null)
{
throw new ArgumentNullException("row");
}
row.Storage.CopyToSubRow(Storage, rowIndex, 0, columnIndex, length);
}
/// <summary>
/// Copies the values of the given array to the specified row.
/// </summary>

Loading…
Cancel
Save