Skip to content

Instantly share code, notes, and snippets.

@Caellian
Created September 13, 2018 13:00
Show Gist options
  • Select an option

  • Save Caellian/dcd22f3ade50d7e4432cca3008c66b9f to your computer and use it in GitHub Desktop.

Select an option

Save Caellian/dcd22f3ade50d7e4432cca3008c66b9f to your computer and use it in GitHub Desktop.
Example of dense and uncommented code.
/**
* Creates a new matrix without specified rows & columns.
*
* @param deletedRows rows to exclude from submatrix.
* @param deletedColumns columns to exclude from submatrix.
* @return defined submatrix.
*/
def submatrix(deletedRows: Array[Int], deletedColumns: Array[Int]): MatrixF = {
val result = Array.ofDim[Float](rowCount - deletedRows.count(rowCount >= _), columnCount - deletedColumns.count(columnCount >= _))
data.indices.filterNot(deletedRows contains _ + 1).zipWithIndex.foreach { case (row, i) =>
data(0).indices.filterNot(deletedColumns contains _ + 1).zipWithIndex.foreach { case (col, j) =>
result(i)(j) = data(row)(col)
}
}
new MatrixF(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment