Multi-dimensonal arrays are a pain point in Kotlin

You should track this issue: https://youtrack.jetbrains.com/issue/KT-21670. Multi-dimensional arrays are not that simple. Java arrays are quite easy to use, but are not what you need in terms of performance. Lightweight 2-dim array builders are quite easy to add in you project like this:

typealias DoubleArray2D = Array<DoubleArray>
fun doubleArray2D(rows: Int, cols: Int, block: (i: Int, j: Int) -> Double): DoubleArray2D{
  return Array(rows){ i ->
      DoubleArray(cols){ j ->
          block(i,j)
      }
  }
}
1 Like