From 62d7e357f454522792c5c4fe26ff9753f301c830 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sun, 25 Nov 2012 05:19:40 +0200 Subject: [PATCH] [SymmetricMatrix] Override Insert/SetRow/Column Signed-off-by: Alexander Karatarakis --- .../LinearAlgebra/Double/SymmetricMatrix.cs | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/src/Numerics/LinearAlgebra/Double/SymmetricMatrix.cs b/src/Numerics/LinearAlgebra/Double/SymmetricMatrix.cs index c6c94332..33dea414 100644 --- a/src/Numerics/LinearAlgebra/Double/SymmetricMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/SymmetricMatrix.cs @@ -5,6 +5,7 @@ using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra.Generic; using MathNet.Numerics.LinearAlgebra.Storage; + using MathNet.Numerics.Properties; /// /// Abstract class for symmetric matrices. @@ -376,5 +377,167 @@ } } } + + /// + /// Creates a new matrix and inserts the given column at the given index. + /// + /// The index of where to insert the column. + /// The column to insert. + /// A new matrix with the inserted column. + /// If is . + /// If is < zero or > the number of columns. + /// If the size of != the number of rows. + public override Matrix InsertColumn(int columnIndex, Vector column) + { + throw new InvalidOperationException("Inserting a column is not supported on a symmetric matrix. Symmetric matrices are square"); + } + + /// + /// Copies the values of the given array to the specified column. The changes retain the symmetry of the matrix. + /// + /// The column to copy the values to. + /// The array 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. + /// If the size of does not + /// equal the number of rows of this Matrix. + public override void SetColumn(int columnIndex, double[] column) + { + if (columnIndex < 0 || columnIndex >= ColumnCount) + { + throw new ArgumentOutOfRangeException("columnIndex"); + } + + if (column == null) + { + throw new ArgumentNullException("column"); + } + + if (column.Length != RowCount) + { + throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension, "column"); + } + + for (var i = 0; i < columnIndex; i++) + { + At(i, columnIndex, column[i]); + } + } + + /// + /// Copies the values of the given Vector to the specified column. The changes retain the symmetry of the matrix. + /// + /// The column to copy the values to. + /// 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 override void SetColumn(int columnIndex, Vector column) + { + if (columnIndex < 0 || columnIndex >= ColumnCount) + { + throw new ArgumentOutOfRangeException("columnIndex"); + } + + if (column == null) + { + throw new ArgumentNullException("column"); + } + + if (column.Count != RowCount) + { + throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension, "column"); + } + + for (var i = 0; i < columnIndex; i++) + { + At(i, columnIndex, column[i]); + } + } + + /// + /// Creates a new matrix and inserts the given row at the given index. + /// + /// The index of where to insert the row. + /// The row to insert. + /// A new matrix with the inserted column. + /// If is . + /// If is < zero or > the number of rows. + /// If the size of != the number of columns. + public override Matrix InsertRow(int rowIndex, Vector row) + { + throw new InvalidOperationException("Inserting a row is not supported on a symmetric matrix. Symmetric matrices are square"); + } + + /// + /// Copies the values of the given Vector to the specified row. + /// + /// The row to copy the values to. + /// 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 override void SetRow(int rowIndex, Vector row) + { + if (rowIndex < 0 || rowIndex >= RowCount) + { + throw new ArgumentOutOfRangeException("rowIndex"); + } + + if (row == null) + { + throw new ArgumentNullException("row"); + } + + if (row.Count != ColumnCount) + { + throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension, "row"); + } + + for (var i = rowIndex; i < ColumnCount; i++) + { + At(rowIndex, i, row[i]); + } + } + + /// + /// Copies the values of the given array to the specified row. + /// + /// The row to copy the values to. + /// The array 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 override void SetRow(int rowIndex, double[] row) + { + if (rowIndex < 0 || rowIndex >= RowCount) + { + throw new ArgumentOutOfRangeException("rowIndex"); + } + + if (row == null) + { + throw new ArgumentNullException("row"); + } + + if (row.Length != ColumnCount) + { + throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension, "row"); + } + + for (var i = rowIndex; i < ColumnCount; i++) + { + At(rowIndex, i, row[i]); + } + } } }