Overview
Multik, a multiplatform library, is a powerful tool for handling multidimensional arrays in a versatile and efficient manner. It equips developers with high-speed mathematical and arithmetic operations, comprehensive linear algebra functionalities, and robust statistical procedures, along with an arsenal of transformation and sorting utilities.
Multik has been developed adhering to the following principles:
An intuitive and straightforward API
A statically typed API for error prevention and clarity
Optimized for high performance
Flexibility and effortless startup for ease of use
In the Multik library, the pivotal element is the multidimensional array. It encapsulates homogeneous data in a versatile multidimensional framework, enabling streamlined computations and transformations. In Kotlin, developers can create their own multidimensional arrays and perform a spectrum of data manipulations using iterative procedures. Here's a simple illustration of managing a matrix using Kotlin's standard library and Multik:
While Kotlin does provide a robust API for handling such tasks, employing Multik minimizes code complexity and enhances the readability of the implementation. Moreover, Multik's performance is considerably superior compared to Kotlin's standard library.
One unique aspect of Multik's multidimensional arrays is their support for static typing and dimensions. This feature enables detection of a data type and dimensional inconsistencies at the compile-time itself, ensuring the production of more robust and dependable code.
Core concepts
The central type in Multik is NDArray, a container for dense, homogeneous numeric data. Key terms:
Dimension (
dim) — number of axes (1D, 2D, 3D, 4D, or ND).Shape (
shape) — size of each axis, for example(2, 3).Strides (
strides) — steps in storage needed to move along each axis.DType (
dtype) — the element type, such asInt,Double, or complex numbers.Engine — the execution backend for math, linear algebra, and statistics operations.
Architecture
Multik separates the API from execution engines, organized into four modules:
multik-core— defines ndarray types and the API surface. All platforms.multik-kotlin— pure Kotlin engine. JVM, JS, Native, and WASM.multik-openblas— native engine backed by OpenBLAS for high performance. JVM and desktop Native.multik-default— bundles the Kotlin and OpenBLAS engines, choosing the best one at runtime.
This lets you pick the best engine for your platform and performance needs without changing your code.

Performance
Performance is a pivotal factor in Multik, but what gives it this edge? At the core of a ndarray lies a primitive array. When you create a three-dimensional array or a matrix, under the hood, there is a single primitive array of the corresponding type. This means that your data resides as a contiguous memory block, resulting in faster iteration-based operations compared to an array of objects scattered across different memory locations.
But that's not all. While the JVM is continually improving and getting faster, many users still use older versions. That's why we've crafted a special implementation where operations are pushed to native code and the time-tested OpenBLAS library is used. This implementation truly offers stunning performance.