/// <summary> /// Creates a new <see cref="SparseMatrix"/> and inserts the given column at the given index. /// </summary> /// <param name="columnIndex">The index of where to insert the column.</param> /// <param name="column">The column to insert.</param> /// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns> /// <exception cref="ArgumentNullException">If <paramref name="column "/> is <see langword="null" />. </exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> is < zero or > the number of columns.</exception> /// <exception cref="ArgumentException">If the size of <paramref name="column"/> != the number of rows.</exception> public override Matrix <double> InsertColumn(int columnIndex, Vector <double> column) { if (column == null) { throw new ArgumentNullException("column"); } if (columnIndex < 0 || columnIndex > ColumnCount) { throw new ArgumentOutOfRangeException("columnIndex"); } if (column.Count != RowCount) { throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension, "column"); } var result = new SparseMatrix(RowCount, ColumnCount + 1); for (var i = 0; i < columnIndex; i++) { result.SetColumn(i, Column(i)); } result.SetColumn(columnIndex, column); for (var i = columnIndex + 1; i < ColumnCount + 1; i++) { result.SetColumn(i, Column(i - 1)); } return(result); }
/// <summary> /// Creates a new <see cref="SparseMatrix"/> and inserts the given column at the given index. /// </summary> /// <param name="columnIndex">The index of where to insert the column.</param> /// <param name="column">The column to insert.</param> /// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns> /// <exception cref="ArgumentNullException">If <paramref name="column "/> is <see langword="null" />. </exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> is < zero or > the number of columns.</exception> /// <exception cref="ArgumentException">If the size of <paramref name="column"/> != the number of rows.</exception> public override Matrix<double> InsertColumn(int columnIndex, Vector<double> column) { if (column == null) { throw new ArgumentNullException("column"); } if (columnIndex < 0 || columnIndex > ColumnCount) { throw new ArgumentOutOfRangeException("columnIndex"); } if (column.Count != RowCount) { throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension, "column"); } var result = new SparseMatrix(RowCount, ColumnCount + 1); for (var i = 0; i < columnIndex; i++) { result.SetColumn(i, Column(i)); } result.SetColumn(columnIndex, column); for (var i = columnIndex + 1; i < ColumnCount + 1; i++) { result.SetColumn(i, Column(i - 1)); } return result; }