dnarray
Creates an N-dimensional array where each element is computed by a flat-index init function. Use the explicit-dimensions overload for 5+ dimensions, or the shape-based overload to create arrays of any dimension from a dynamically computed shape.
Signatures
From explicit dimensions (5+)
inline fun <reified T : Any> Multik.dnarray(
sizeD1: Int,
sizeD2: Int,
sizeD3: Int,
sizeD4: Int,
vararg dims: Int,
noinline init: (Int) -> T
): NDArray<T, DN>
From shape array
inline fun <reified T : Any, reified D : Dimension> Multik.dnarray(
shape: IntArray,
noinline init: (Int) -> T
): NDArray<T, D>
Parameters
Parameter | Type | Description |
|---|---|---|
|
| First four axis sizes. Must be positive. |
|
| Additional axis sizes beyond the fourth. |
|
| Complete shape array. All elements must be positive. |
|
| Lambda that receives a flat index. Elements are filled in row-major order. |
Returns: NDArray<T, DN> (varargs version) or NDArray<T, D> (shape version)
Example
// 5D array
val a = mk.dnarray<Int>(2, 3, 4, 5, 6) { it }
// shape (2, 3, 4, 5, 6), 720 elements
// Using shape array with reified dimension
val b = mk.dnarray<Double, D3>(intArrayOf(2, 3, 4)) { it.toDouble() }
// shape (2, 3, 4)
28 February 2026