Skip to content

Commit

Permalink
Implements Basic.RemoveColumns() method
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmcmullin committed Aug 2, 2018
1 parent d84fb2b commit 35256f2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion csMatrix/RowColumnOperations/Basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,22 @@ public Matrix RemoveColumns(Matrix m, int column, int count)
if (column > m.Columns - 1 || column < 0)
throw new IndexOutOfRangeException($"Cannot remove a column at index {column}.");
Matrix result = new Matrix(m.Rows, m.Columns - count);

int index = 0, resultIndex = 0, columnIndex;
while (resultIndex < result.Size)
{
columnIndex = 0;
while (columnIndex < m.Columns)
{
if (columnIndex++ < column || columnIndex > column + count)
{
result[resultIndex++] = m[index++];
}
else
{
index++;
}
}
}

return result;
}
Expand Down

0 comments on commit 35256f2

Please sign in to comment.