Skip to content

Commit

Permalink
Merge pull request #123 from Kotlin/develop
Browse files Browse the repository at this point in the history
release 0.2.0
  • Loading branch information
devcrocod authored Jul 25, 2022
2 parents ad39af8 + 82c36a6 commit 87540d8
Show file tree
Hide file tree
Showing 200 changed files with 7,939 additions and 3,700 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ _deps
*.tar.gz
*.rar

# Kotlin/JS
kotlin-js-store/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

Expand Down Expand Up @@ -124,3 +127,5 @@ out/

# mpeltonen/sbt-idea plugin
.idea_modules/

.DS_Store
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2000-2021 JetBrains s.r.o.
Copyright 2000-2022 JetBrains s.r.o.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
125 changes: 95 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
[![Kotlin Alpha](https://kotl.in/badges/alpha.svg)](https://kotlinlang.org/docs/components-stability.html)
[![JetBrains incubator project](https://jb.gg/badges/incubator.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
[![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlinx/multik-api)](https://mvnrepository.com/artifact/org.jetbrains.kotlinx/multik-api)
[![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlinx/multik-core)](https://mvnrepository.com/artifact/org.jetbrains.kotlinx/multik-core)
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)

# Multik

Multidimensional array library for Kotlin.

## Modules
* multik-api — contains ndarrays, methods called on them and [math], [stat] and [linalg] interfaces.
* multik-default — implementation including `jvm` and `native` for performance.
* multik-jvm — implementation of [math], [stat] and [linalg] interfaces on JVM.
* multik-native — implementation of [math], [stat] and [linalg] interfaces in native code using OpenBLAS.
* `multik-core` — contains ndarrays, methods called on them and [math], [stat] and [linalg] interfaces.
* `multik-default` — implementation including `multik-kotlin` and `multik-openblas` for performance.
* `multik-kotlin` — implementation of [math], [stat] and [linalg] interfaces on JVM.
* `multik-openblas` — implementation of [math], [stat] and [linalg] interfaces in native code using OpenBLAS.

## Using in your projects
### Gradle
In your Gradle build script:
1. Add the Maven Central Repository.
2. Add the `org.jetbrains.kotlinx:multik-api:$multik_version` api dependency.
2. Add the `org.jetbrains.kotlinx:multik-core:$multik_version` api dependency.
3. Add an implementation dependency: `org.jetbrains.kotlinx:multik-default:$multik_version`,
`org.jetbrains.kotlinx:multik-jvm:$multik_version` or `org.jetbrains.kotlinx:multik-native:$multik_version`.
`org.jetbrains.kotlinx:multik-kotlin:$multik_version` or `org.jetbrains.kotlinx:multik-openblas:$multik_version`.

`build.gradle`:
```groovy
Expand All @@ -26,8 +28,8 @@ repositories {
}
dependencies {
implementation "org.jetbrains.kotlinx:multik-api:0.1.1"
implementation "org.jetbrains.kotlinx:multik-default:0.1.1"
implementation "org.jetbrains.kotlinx:multik-core:0.2.0"
implementation "org.jetbrains.kotlinx:multik-default:0.2.0"
}
```

Expand All @@ -38,11 +40,73 @@ repositories {
}

dependencies {
implementation("org.jetbrains.kotlinx:multik-api:0.1.1")
implementation("org.jetbrains.kotlinx:multik-default:0.1.1")
implementation("org.jetbrains.kotlinx:multik-core:0.2.0")
implementation("org.jetbrains.kotlinx:multik-default:0.2.0")
}
```

For a multiplatform project, set the dependency in a common block:

```kotlin
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:multik-core:0.2.0")
}
}
}
}
```

or in a platform-specific block:

```kotlin
kotlin {
sourceSets {
val jvmName by getting {
dependencies {
implementation("org.jetbrains.kotlinx:multik-core-jvm:0.2.0")
}
}
}
}
```

### Jupyter Notebook
Install [Kotlin kernel](https://github.com/Kotlin/kotlin-jupyter) for
[Jupyter](https://jupyter.org/)
or just visit to [Datalore](https://datalore.jetbrains.com/).

Import stable `multik` version into notebook:
```
%use multik
```

## Support platforms

| Platforms | `multik-core` | `multik-kotlin` | `multik-openblas` | `multik-default` |
|:---------------------:|:------------------:|:------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| **JS** | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| **linuxX64** | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **mingwX64** | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **macosX64** | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **macosArm64** | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **iosArm64** | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| **iosX64** | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| **iosSimulatorArm64** | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| **JVM** | :white_check_mark: | :white_check_mark: | linuxX64 - :white_check_mark:<br/>mingwX64 - :white_check_mark:<br/>macosX64 - :white_check_mark:<br/>macosArm64 - :white_check_mark:<br/>androidArm64 - :white_check_mark: | linuxX64 - :white_check_mark:<br/>mingwX64 - :white_check_mark:<br/>macosX64 - :white_check_mark:<br/>macosArm64 - :white_check_mark:<br/>androidArm64 - :white_check_mark: |

For Kotlin/JS, we use the new [IR](https://kotlinlang.org/docs/js-ir-compiler.html).
We also use the [new memory model](https://blog.jetbrains.com/kotlin/2021/08/try-the-new-kotlin-native-memory-manager-development-preview/)
in Kotlin/Native. Keep this in mind when using Multik in your multiplatform projects.

**Note**:
* on ubuntu 18.04 and older `multik-openblas` doesn't work due to older versions of _**glibc**_.
* `multik-openblas` for desktop targets (_linuxX64_, _mingwX64_, _macosX64_, _macosArm64_) is experimental and unstable.
We will improve stability and perfomance as _Kotlin/Native_ evolves.
* JVM target `multik-openblas` for Android only supports **arm64-v8a** processors.

## Quickstart

Visit [Multik documentation](https://kotlin.github.io/multik) for a detailed feature overview.
Expand Down Expand Up @@ -101,7 +165,7 @@ mk.d2arrayIndices(3, 3) { i, j -> ComplexFloat(i, j) }
[2.0+(0.0)i, 2.0+(1.0)i, 2.0+(2.0)i]]
*/

mk.arange<Long>(10, 25, 5) // creare an array with elements in the interval [19, 25) with step 5
mk.arange<Long>(10, 25, 5) // creare an array with elements in the interval [10, 25) with step 5
/* [10, 15, 20] */

mk.linspace<Double>(0, 2, 9) // create an array of 9 elements in the interval [0, 2]
Expand Down Expand Up @@ -152,6 +216,12 @@ f * d // multiplication
```

#### Array mathematics

See documentation for other methods of
[mathematics](https://kotlin.github.io/multik/multik-core/org.jetbrains.kotlinx.multik.api.math/index.html),
[linear algebra](https://kotlin.github.io/multik/multik-core/org.jetbrains.kotlinx.multik.api.linalg/index.html),
[statistics](https://kotlin.github.io/multik/multik-core/org.jetbrains.kotlinx.multik.api.stat/index.html).

```kotlin
a.sin() // element-wise sin, equivalent to mk.math.sin(a)
a.cos() // element-wise cos, equivalent to mk.math.cos(a)
Expand All @@ -160,8 +230,6 @@ b.exp() // element-wise exp, equivalent to mk.math.exp(b)
d dot e // dot product, equivalent to mk.linalg.dot(d, e)
```

See [documentation](https://kotlin.github.io/multik) for other linear algebra methods.

#### Aggregate functions
```kotlin
mk.math.sum(c) // array-wise sum
Expand Down Expand Up @@ -229,24 +297,21 @@ a.inplace {
```

## Building
Multik uses BLAS and LAPACK for implementing algebraic operations.
Therefore, you would need a C ++ compiler and gfortran.
Run `./gradlew assemble` to build all modules.
* To build api module run `./gradlew multik-api:assemble`.
* To build jvm module run `./gradlew multik-jvm:assemble`.
* To build native module run `./gradlew multik-native:assemble`.
To reuse `multik-native` in the future, you must first build `multik_jni` and place the native library in
`multik-native/build/libs`
* To build default module run `./gradlew multik-native:assemble` then `./gradlew multik-default:assemble`.
To build the entire project, you need to set up an environment for building `multik-openblas`:
* JDK 1.8 or higher
* _JAVA_HOME_ environment - to search for jni files
* Compilers _gcc_, _g++_, _gfortran_ version 8 or higher.
It is important that they are of the same version.

## Testing
`./gradlew test`
Run `./gradlew assemble` to build all modules.
If you don't need to build `multik-openblas`,
just disable the `cmake_build` task and build the module you need.

## Contributing
There is an opportunity to contribute to the project:
1. Implement [math](multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/math/Math.kt),
[linalg](multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/LinAlg.kt),
[stat](multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/Statistics.kt) interfaces.
2. Create your own engine successor from [Engine](multik-api/src/main/kotlin/org/jetbrains/kotlinx/multik/api/Engine.kt), for example - [JvmEngine](multik-jvm/src/main/kotlin/org/jetbrains/kotlinx/multik/jvm/JvmEngine.kt).
3. Use [mk.addEngine](https://github.com/devcrocod/multik/blob/972b18cfd2952abd811fabf34461d238e55c5587/multik-api/src/main/kotlin/org/jetbrains/multik/api/Multik.kt#L23) and [mk.setEngine](https://github.com/devcrocod/multik/blob/972b18cfd2952abd811fabf34461d238e55c5587/multik-api/src/main/kotlin/org/jetbrains/multik/api/Multik.kt#L27)
1. Implement [math](multik-core/src/main/kotlin/org/jetbrains/kotlinx/multik/api/math/Math.kt),
[linalg](multik-core/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/LinAlg.kt),
[stat](multik-core/src/main/kotlin/org/jetbrains/kotlinx/multik/api/Statistics.kt) interfaces.
2. Create your own engine successor from [Engine](multik-core/src/main/kotlin/org/jetbrains/kotlinx/multik/api/Engine.kt), for example - [JvmEngine](multik-kotlin/src/main/kotlin/org/jetbrains/kotlinx/multik/jvm/JvmEngine.kt).
3. Use [mk.addEngine](https://github.com/devcrocod/multik/blob/972b18cfd2952abd811fabf34461d238e55c5587/multik-core/src/main/kotlin/org/jetbrains/multik/api/Multik.kt#L23) and [mk.setEngine](https://github.com/devcrocod/multik/blob/972b18cfd2952abd811fabf34461d238e55c5587/multik-core/src/main/kotlin/org/jetbrains/multik/api/Multik.kt#L27)
to use your implementation.
40 changes: 22 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2020-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.time.Duration

buildscript {
repositories {
Expand All @@ -14,13 +13,13 @@ plugins {
val kotlin_version: String by System.getProperties()
val nexus_version: String by System.getProperties()

kotlin("jvm") version kotlin_version
id("io.codearte.nexus-staging") version nexus_version
kotlin("multiplatform") version kotlin_version apply false
id("io.github.gradle-nexus.publish-plugin") version nexus_version
}

val kotlin_version: String by System.getProperties()
val multik_version: String by project
val unpublished = listOf("multik", "multik_jni")
val unpublished = listOf("multik")

allprojects {
repositories {
Expand All @@ -30,22 +29,27 @@ allprojects {
group = "org.jetbrains.kotlinx"
version = multik_version

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
}

subprojects {
if (!this.name.contains("jni")) {
apply(plugin = "kotlin")
configure(subprojects.filter { it.name !in unpublished }) {
apply("$rootDir/gradle/publish.gradle")
}

val sonatypeUser: String = System.getenv("SONATYPE_USER") ?: ""
val sonatypePassword: String = System.getenv("SONATYPE_PASSWORD") ?: ""

dependencies {
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit"))
nexusPublishing {
packageGroup.set(project.group.toString())
repositories {
sonatype {
username.set(sonatypeUser)
password.set(sonatypePassword)
repositoryDescription.set("kotlinx.multik staging repository, version: $version")
}
}
}

configure(subprojects.filter { it.name !in unpublished }) {
apply("$rootDir/gradle/publish.gradle")
transitionCheckOptions {
maxRetries.set(100)
delayBetween.set(Duration.ofSeconds(5))
}
}
35 changes: 29 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
kotlin.code.style=official
multik_version=0.2.0

multik_version=0.1.1
# Kotlin
systemProp.kotlin_version=1.7.10
group=org.jetbrains.kotlinx

systemProp.kotlin_version=1.5.31
systemProp.nexus_version=0.22.0
systemProp.dokka_version=1.5.31

openblas_version=0.3.18
# Dependencies
systemProp.nexus_version=1.1.0
systemProp.dokka_version=1.7.10
openblas_version=0.3.19
common_csv_version=1.9.0

# Gradle
org.gradle.parallel=true
org.gradle.caching=true

# MPP
kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableCInteropCommonization=true

# Native
kotlin.native.cacheKind.linuxX64=static
kotlin.native.cacheKind.iosArm64=static
kotlin.native.binary.memoryModel=experimental

# Settings
kotlin.incremental.multiplatform=true
kotlin.native.ignoreDisabledTargets=true

# JS IR backend sometimes crashes with out-of-memory
# Check KT-37187
org.gradle.jvmargs=-Xmx3g
Loading

0 comments on commit 87540d8

Please sign in to comment.