public static MatrixBase <T> SwapRows( MatrixBase <T> matrix, int i, int j) { if (!matrix.RowRange.Contains(i)) { throw new ArgumentOutOfRangeException("rowRange"); } if (!matrix.RowRange.Contains(j)) { throw new ArgumentOutOfRangeException("rowRange"); } if (i == j) { return(matrix.Clone()); } var result = matrix.Clone(); for (var col = 0; col < matrix.ColumnCount; col++) { var temp = result.Data[i, col]; result.Data[i, col] = result.Data[j, col]; result.Data[j, col] = temp; } return(result); }
public static MatrixBase <T> SwapColumns( MatrixBase <T> matrix, int i, int j) { if (!matrix.ColumnRange.Contains(i)) { throw new ArgumentOutOfRangeException("columnRange"); } if (!matrix.ColumnRange.Contains(j)) { throw new ArgumentOutOfRangeException("columnRange"); } if (i == j) { return(matrix.Clone()); } var result = matrix.Clone(); for (var row = 0; row < matrix.RowCount; row++) { var temp = result.Data[row, i]; result.Data[row, i] = result.Data[row, j]; result.Data[row, j] = temp; } return(result); }