Multik 0.3.0 Help

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

sizeD1

Int

Number of rows. Must be positive.

sizeD2

Int

Number of columns. Must be positive.

init

(Int) -> T

Lambda that receives a flat index (0 to sizeD1 * sizeD2 - 1) and returns the element value. Elements are filled in row-major order.

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