d2array
Creates a 2D array of the given shape, where each element is computed by a flat-index init function. Elements are filled in row-major order. For per-element (i, j) indices, use d2arrayIndices.
Signature
inline fun <reified T : Any> Multik.d2array(
sizeD1: Int,
sizeD2: Int,
noinline init: (Int) -> T
): D2Array<T>
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Number of rows. Must be positive. |
|
| Number of columns. Must be positive. |
|
| Lambda that receives a flat index (0 to |
Returns: D2Array<T>
Example
val m = mk.d2array<Int>(2, 3) { it }
// [[0, 1, 2],
// [3, 4, 5]]
val identity = mk.d2array<Double>(3, 3) { if (it / 3 == it % 3) 1.0 else 0.0 }
28 February 2026