Skip to content

Instantly share code, notes, and snippets.

@dionsaputra
Created November 22, 2020 13:53
Show Gist options
  • Save dionsaputra/12ae0f0dc3a40163b8f37c4ca40e03b9 to your computer and use it in GitHub Desktop.
Save dionsaputra/12ae0f0dc3a40163b8f37c4ca40e03b9 to your computer and use it in GitHub Desktop.
data class Matrix(val rows: Int, val cols: Int) {
lateinit var elements: DoubleArray
private fun index(r: Int, c: Int) = r * cols + c
operator fun get(r: Int, c: Int) = elements[index(r,c)]
operator fun set(r: Int, c: Int, element: Double) {
elements[index(r,c)] = element
}
constructor(rows: Int, cols: Int, elements: DoubleArray) : this(rows, cols) {
this.elements = elements;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment