Multik 0.3.0 Help

Scalars

Supported types

Multik arrays store elements of a single scalar type. All scalars implement Kotlin's Number or the Complex interface.

Type

Size (bytes)

Range / Precision

DataType constant

Byte

1

-128 to 127

ByteDataType

Short

2

-32 768 to 32 767

ShortDataType

Int

4

-231 to 231-1

IntDataType

Long

8

-263 to 263-1

LongDataType

Float

4

~7 decimal digits

FloatDataType

Double

8

~15 decimal digits

DoubleDataType

ComplexFloat

8

Two Float parts (re, im)

ComplexFloatDataType

ComplexDouble

16

Two Double parts (re, im)

ComplexDoubleDataType

Numeric types

The first six types map directly to Kotlin primitives. Arithmetic operators (+, -, *, /) and in-place variants (+=, -=, *=, /=) are supported element-wise on arrays of these types.

val a = mk.ndarray(mk[1, 2, 3]) // Int val b = mk.ndarray(mk[1.0, 2.0, 3.0]) // Double

Complex types

ComplexFloat

@JvmInline public value class ComplexFloat(private val number: Long) : Complex

Property / Method

Type

Description

re

Float

Real part.

im

Float

Imaginary part.

conjugate()

ComplexFloat

Returns a - bi.

abs()

Float

Magnitude sqrt(re² + im²).

angle()

Float

Phase angle in radians.

component1()/component2()

Float

Destructuring support: val (r, i) = c.

Constants: ComplexFloat.zero, ComplexFloat.one, ComplexFloat.NaN

ComplexDouble

public interface ComplexDouble : Complex

Same API as ComplexFloat but with Double precision.

Constants: ComplexDouble.zero, ComplexDouble.one, ComplexDouble.NaN

Creating complex values

val c1 = ComplexFloat(1.0f, 2.0f) // 1.0 + 2.0i val c2 = ComplexDouble(3.0, -1.0) // 3.0 - 1.0i // Factory helpers on Complex companion val real = Complex.r(5.0) // 5.0 + 0.0i val imag = Complex.i(3.0) // 0.0 + 3.0i

ComplexFloatArray / ComplexDoubleArray

Backing storage for complex arrays. Each element occupies two primitive slots internally.

val arr = ComplexFloatArray(3) { ComplexFloat(it.toFloat(), 0f) } arr[0] // ComplexFloat(0.0, 0.0)

Type conversion

Use asType<T>() or toType<T>() to convert between scalar types. Converting a numeric type to a complex type sets the imaginary part to zero. See Type for DataType details and NDArray for conversion methods.

19 February 2026