/viktor

Efficient f64-only ndarray in Kotlin

Primary LanguageKotlinMIT LicenseMIT

JetBrains Research tests

Maven Central

viktor

viktor implements a restricted subset of NumPy ndarray features in Kotlin. Here are some highlights:

  • A single core data type --- F64Array, an n-dimensional primitive array.

  • Efficient vectorized operations, which are accelerated using SIMD whenever possible.

  • Semi-sweet syntax.

    val m = F64Array(4, 3)
    m.V[0] = F64Array.full(3, 42.0)  // row-view.
    m.V[_I, 0]                       // column-view.
    m.V[0] = 42.0                    // broadcasting.
    m + 0.5 * m                      // arithmetic operations.
    m.V[0].exp() + 1.0               // math functions.

Installation

The latest version of viktor is available on Maven Central. If you're using Gradle, just add the following to your build.gradle dependencies:

implementation 'org.jetbrains.bio:viktor:1.2.0'

or, equivalently, add the following to your build.gradle.kts dependencies:

implementation("org.jetbrains.bio:viktor:1.2.0")

With Maven, use the dependency

<dependency>
    <groupId>org.jetbrains.bio</groupId>
    <artifactId>viktor</artifactId>
    <version>1.2.0</version>
</dependency>

Versions older than 1.1.0 can be downloaded from GitHub Releases.

The JAR available on Maven Central currently targets only:

  • SSE2 and AVX,
  • amd64 / x86-64,
  • Linux, Windows and MacOS.

For any other setup viktor would fall back to pure-Kotlin implementations. If you are interested in SIMD accelerations for a different architecture, instruction set, or operating system feel free to file an issue to the bug tracker.

Logging

viktor uses slf4j logging API to provide error messages. To see them, you have to add a slf4j implementation (also called a binding) to your project. For example, add the following Gradle dependency to use log4j:

dependencies {
    compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
}

Building from source

viktor relies on boost.simd for implementing SIMD accelerations. Therefore, you would need a C++11 compiler, but otherwise the build process is as simple as:

./gradlew jar

Note: don't use ./gradlew assemble, since it includes the signing of the artifacts and will fail if the correct credentials are not provided.

Testing

No extra configuration is required for running the tests from Gradle:

./gradlew test

However, you might need to alter java.library.path to run the tests from the IDE. The following Java command line option should work for IDEA

-Djava.library.path=./build/libs

Publishing

Publishing to Maven Central is currently done via a dedicated build configuration of an internal TeamCity server. This allows us to deploy a cross-platform version.

Documentation

Visit viktor Documentation for an extensive feature overview, instructive code examples and benchmarking data.