Multik 0.3.0 Help

d4array

Creates a 4D 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, k, m) indices, use d4arrayIndices.

Signature

inline fun <reified T : Any> Multik.d4array( sizeD1: Int, sizeD2: Int, sizeD3: Int, sizeD4: Int, noinline init: (Int) -> T ): D4Array<T>

Parameters

Parameter

Type

Description

sizeD1

Int

Size of the first axis. Must be positive.

sizeD2

Int

Size of the second axis. Must be positive.

sizeD3

Int

Size of the third axis. Must be positive.

sizeD4

Int

Size of the fourth axis. Must be positive.

init

(Int) -> T

Lambda that receives a flat index (0 to sizeD1 * sizeD2 * sizeD3 * sizeD4 - 1). Elements are filled in row-major order.

Returns: D4Array<T>

Example

val a = mk.d4array<Double>(2, 3, 4, 5) { it.toDouble() } // shape (2, 3, 4, 5), 120 elements
28 February 2026