Dimension
Overview
Multik uses sealed dimension types as the second type parameter of NDArray<T, D>. This gives compile-time safety for array rank: a D2Array<Double> cannot be accidentally passed where a D1Array<Double> is expected.
Dimension interface
All dimension types implement Dimension. The d property holds the numeric rank.
Hierarchy
Each concrete type extends a marker interface chain: Dim1 ⊂ Dim2 ⊂ Dim3 ⊂ Dim4 ⊂ DimN. This means a function accepting DimN will also accept D1–D4.
Concrete types
D1
Singleton companion: D1. Used for vectors.
D2
Singleton companion: D2. Used for matrices.
D3
Singleton companion: D3. Used for 3D tensors.
D4
Singleton companion: D4. Used for 4D tensors.
DN
General N-dimensional type. Unlike D1–D4, DN is not sealed — the rank is stored in the d property and checked at runtime.
Type aliases
Alias | Meaning |
|---|---|
|
|
|
|
|
|
|
|
Helper functions
dimensionOf
Returns the dimension instance matching the given integer. Throws IllegalArgumentException if dim does not match the reified type.
dimensionClassOf
Resolves a dimension class by reified type parameter. When dim is provided, creates a DN with that rank.
Usage
Dimension changes
Operations that change rank return a different dimension type: