Skip to content

Instantly share code, notes, and snippets.

@dionsaputra
Created November 22, 2020 16:58
Show Gist options
  • Save dionsaputra/e68d97202f7e4282708c5ebb8a0d0ccd to your computer and use it in GitHub Desktop.
Save dionsaputra/e68d97202f7e4282708c5ebb8a0d0ccd to your computer and use it in GitHub Desktop.
// matrix cross-product
infix fun x(other: Matrix): Matrix {
require(cols == other.rows)
val res = Matrix(rows, other.cols, Array(rows * other.cols) { 0.0 })
for (i in 0 until rows) {
for (j in 0 until other.cols) {
for (k in 0 until cols) res[i,j] += (this[i,k] * other[k,j])
}
}
return res
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment