<@U0HUJ25V1> Well, I would not call it correct usa...
# mathematics
a
@thomasnield Well, I would not call it correct usage.
VirtualMatrix
should not be used without good reason, because it calls a lambda, which could not be inlined on each call and is general a performance sink. Also if you implement operations with it, you can get nested lambdas, which are event worse. The operations, you propose already exist. But they are not top-level, you should use
MatrixContext.real.run{...}
to access them inside the braces. It is done so by design so you could interpret a
Matrix
which is just a 2d-structure type-alias in different ways depending on the context. You can create a shortcut for context wrapper or run your functions with
MatrixContext
receiver to avoid duplication of that line. In order to create new operations, you can just extend `MatrixContext`:
Copy code
kotlin
fun <T: Any> MatrixContext<T>.appendBottom(other: Matrix<T>) = produce(rowNum + other.rowNum, colNum) { row, col ->
    when {
        row < this@appendBottom.rowNum -> this@appendBottom[row,col]
        else -> other[row - this@appendBottom.rowNum, col]
    }
}