{"id":13537862,"url":"https://github.com/Kotlin/multik","last_synced_at":"2025-04-02T04:31:58.797Z","repository":{"id":38185334,"uuid":"265785552","full_name":"Kotlin/multik","owner":"Kotlin","description":"Multidimensional array library for Kotlin","archived":false,"fork":false,"pushed_at":"2024-12-18T13:59:57.000Z","size":3008,"stargazers_count":666,"open_issues_count":67,"forks_count":41,"subscribers_count":17,"default_branch":"develop","last_synced_at":"2025-03-01T09:33:42.715Z","etag":null,"topics":["kotlin","matrix","multiplatform","ndarray"],"latest_commit_sha":null,"homepage":"https://kotlin.github.io/multik/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kotlin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-21T07:37:29.000Z","updated_at":"2025-02-28T11:46:48.000Z","dependencies_parsed_at":"2024-02-08T22:14:10.058Z","dependency_job_id":"9ea0aa68-ec96-41f8-912f-7775898a1dad","html_url":"https://github.com/Kotlin/multik","commit_stats":{"total_commits":486,"total_committers":16,"mean_commits":30.375,"dds":0.3477366255144033,"last_synced_commit":"509b3493dfabf4cdf9f5b79b20676191accb05ba"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kotlin%2Fmultik","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kotlin%2Fmultik/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kotlin%2Fmultik/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kotlin%2Fmultik/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kotlin","download_url":"https://codeload.github.com/Kotlin/multik/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246757525,"owners_count":20828914,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kotlin","matrix","multiplatform","ndarray"],"created_at":"2024-08-01T09:01:04.396Z","updated_at":"2025-04-02T04:31:53.777Z","avatar_url":"https://github.com/Kotlin.png","language":"Kotlin","funding_links":[],"categories":["Libraries","Kotlin"],"sub_categories":[],"readme":"[![Kotlin Alpha](https://kotl.in/badges/alpha.svg)](https://kotlinlang.org/docs/components-stability.html)\n[![JetBrains incubator project](https://jb.gg/badges/incubator.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)\n[![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlinx/multik-core)](https://mvnrepository.com/artifact/org.jetbrains.kotlinx/multik-core)\n[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)\n\n# Multik\n\nMultidimensional array library for Kotlin.\n\n## Modules\n* `multik-core` \u0026mdash; contains ndarrays, methods called on them and [math], [stat] and [linalg] interfaces.\n* `multik-default` \u0026mdash; implementation including `multik-kotlin` and `multik-openblas` for performance.\n* `multik-kotlin` \u0026mdash; implementation of [math], [stat] and [linalg] interfaces on JVM.\n* `multik-openblas` \u0026mdash; implementation of [math], [stat] and [linalg] interfaces in native code using OpenBLAS.\n\n## Using in your projects\n### Gradle\nIn your Gradle build script:\n1. Add the Maven Central Repository.\n2. Add the `org.jetbrains.kotlinx:multik-core:$multik_version` api dependency.\n3. Add an implementation dependency: `org.jetbrains.kotlinx:multik-default:$multik_version`,\n`org.jetbrains.kotlinx:multik-kotlin:$multik_version` or `org.jetbrains.kotlinx:multik-openblas:$multik_version`.\n\n`build.gradle`:\n```groovy\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation \"org.jetbrains.kotlinx:multik-core:0.2.3\"\n    implementation \"org.jetbrains.kotlinx:multik-default:0.2.3\"\n}\n```\n\n`build.gradle.kts`:\n```kotlin\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"org.jetbrains.kotlinx:multik-core:0.2.3\")\n    implementation(\"org.jetbrains.kotlinx:multik-default:0.2.3\")\n}\n```\n\nFor a multiplatform project, set the dependency in a common block:\n\n```kotlin\nkotlin {\n    sourceSets {\n        val commonMain by getting {\n            dependencies {\n                implementation(\"org.jetbrains.kotlinx:multik-core:0.2.3\")\n            }\n        }\n    }\n}\n```\n\nor in a platform-specific block:\n\n```kotlin\nkotlin {\n    sourceSets {\n        val jvmName by getting {\n            dependencies {\n                implementation(\"org.jetbrains.kotlinx:multik-core-jvm:0.2.3\")\n            }\n        }\n    }\n}\n```\n\n### Jupyter Notebook\nInstall [Kotlin kernel](https://github.com/Kotlin/kotlin-jupyter) for\n[Jupyter](https://jupyter.org/)\nor just visit to [Datalore](https://datalore.jetbrains.com/).\n\nImport stable `multik` version into notebook:\n```\n%use multik\n```\n\n## Support platforms\n\n|       Platforms       |   `multik-core`    |  `multik-kotlin`   |                                                                              `multik-openblas`                                                                              |                       `multik-default`                       |\n|:---------------------:|:------------------:|:------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------:|\n|        **JS**         | :white_check_mark: | :white_check_mark: |                                                                                     :x:                                                                                     |                      :white_check_mark:                      |\n|     **linuxX64**      | :white_check_mark: | :white_check_mark: |                                                                             :white_check_mark:                                                                              |                      :white_check_mark:                      |\n|     **mingwX64**      | :white_check_mark: | :white_check_mark: |                                                                             :white_check_mark:                                                                              |                      :white_check_mark:                      |\n|     **macosX64**      | :white_check_mark: | :white_check_mark: |                                                                             :white_check_mark:                                                                              |                      :white_check_mark:                      |\n|    **macosArm64**     | :white_check_mark: | :white_check_mark: |                                                                             :white_check_mark:                                                                              |                      :white_check_mark:                      |\n|     **iosArm64**      | :white_check_mark: | :white_check_mark: |                                                                                     :x:                                                                                     |                      :white_check_mark:                      |\n|      **iosX64**       | :white_check_mark: | :white_check_mark: |                                                                                     :x:                                                                                     |                      :white_check_mark:                      |\n| **iosSimulatorArm64** | :white_check_mark: | :white_check_mark: |                                                                                     :x:                                                                                     |                      :white_check_mark:                      |\n|        **JVM**        | :white_check_mark: | :white_check_mark: | linuxX64 - :white_check_mark:\u003cbr/\u003emingwX64 - :white_check_mark:\u003cbr/\u003emacosX64 - :white_check_mark:\u003cbr/\u003emacosArm64 - :white_check_mark:\u003cbr/\u003eandroidArm64 - :white_check_mark: | androidArm32 - :x:\u003cbr/\u003eandroidX86 - :x:\u003cbr/\u003eandroidX64 - :x: |\n\nFor Kotlin/JS, we use the new [IR](https://kotlinlang.org/docs/js-ir-compiler.html).\nWe also use the [new memory model](https://blog.jetbrains.com/kotlin/2021/08/try-the-new-kotlin-native-memory-manager-development-preview/)\nin Kotlin/Native. Keep this in mind when using Multik in your multiplatform projects.\n\n**Note**:\n* on ubuntu 18.04 and older `multik-openblas` doesn't work due to older versions of _**glibc**_.\n* `multik-openblas` for desktop targets (_linuxX64_, _mingwX64_, _macosX64_, _macosArm64_) is experimental and unstable.\nWe will improve stability and perfomance as _Kotlin/Native_ evolves.\n* JVM target `multik-openblas` for Android only supports **arm64-v8a** processors.\n\n## Quickstart\n\nVisit [Multik documentation](https://kotlin.github.io/multik) for a detailed feature overview.\n\n#### Creating arrays\n\n```kotlin\nval a = mk.ndarray(mk[1, 2, 3])\n/* [1, 2, 3] */\n\nval b = mk.ndarray(mk[mk[1.5, 2.1, 3.0], mk[4.0, 5.0, 6.0]])\n/*\n[[1.5, 2.1, 3.0],\n[4.0, 5.0, 6.0]]\n*/\n\nval c = mk.ndarray(mk[mk[mk[1.5f, 2f, 3f], mk[4f, 5f, 6f]], mk[mk[3f, 2f, 1f], mk[4f, 5f, 6f]]])\n/*\n[[[1.5, 2.0, 3.0],\n[4.0, 5.0, 6.0]],\n\n[[3.0, 2.0, 1.0],\n[4.0, 5.0, 6.0]]]\n*/\n\n\nmk.zeros\u003cDouble\u003e(3, 4) // create an array of zeros\n/*\n[[0.0, 0.0, 0.0, 0.0],\n[0.0, 0.0, 0.0, 0.0],\n[0.0, 0.0, 0.0, 0.0]]\n*/\nmk.ndarray\u003cFloat, D2\u003e(setOf(30f, 2f, 13f, 12f), intArrayOf(2, 2)) // create an array from a collection\n/*\n[[30.0, 2.0],\n[13.0, 12.0]]\n*/\nval d = mk.ndarray(doubleArrayOf(1.0, 1.3, 3.0, 4.0, 9.5, 5.0), 2, 3) // create an array of shape(2, 3) from a primitive array\n/*\n[[1.0, 1.3, 3.0],\n[4.0, 9.5, 5.0]]\n*/\nmk.d3array(2, 2, 3) { it * it } // create an array of 3 dimension\n/*\n[[[0, 1, 4],\n[9, 16, 25]],\n\n[[36, 49, 64],\n[81, 100, 121]]]\n*/\n\nmk.d2arrayIndices(3, 3) { i, j -\u003e ComplexFloat(i, j) }\n/*\n[[0.0+(0.0)i, 0.0+(1.0)i, 0.0+(2.0)i],\n[1.0+(0.0)i, 1.0+(1.0)i, 1.0+(2.0)i],\n[2.0+(0.0)i, 2.0+(1.0)i, 2.0+(2.0)i]]\n */\n\nmk.arange\u003cLong\u003e(10, 25, 5) // creare an array with elements in the interval [10, 25) with step 5\n/* [10, 15, 20] */\n\nmk.linspace\u003cDouble\u003e(0, 2, 9) // create an array of 9 elements in the interval [0, 2]\n/* [0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0] */\n\nval e = mk.identity\u003cDouble\u003e(3) // create an identity array of shape (3, 3)\n/*\n[[1.0, 0.0, 0.0],\n[0.0, 1.0, 0.0],\n[0.0, 0.0, 1.0]]\n*/\n```\n\n#### Array properties\n```kotlin\na.shape // Array dimensions\na.size // Size of array\na.dim // object Dimension\na.dim.d // number of array dimensions\na.dtype // Data type of array elements\n```\n\n#### Arithmetic operations\n```kotlin\nval f = b - d // subtraction\n/*\n[[0.5, 0.8, 0.0],\n[0.0, -4.5, 1.0]]\n*/\n\nd + f // addition\n/*\n[[1.5, 2.1, 3.0],\n[4.0, 5.0, 6.0]]\n*/\n\nb / d // division\n/*\n[[1.5, 1.6153846153846154, 1.0],\n[1.0, 0.5263157894736842, 1.2]]\n*/\n\nf * d // multiplication\n/*\n[[0.5, 1.04, 0.0],\n[0.0, -42.75, 5.0]]\n*/\n```\n\n#### Array mathematics\n\nSee documentation for other methods of\n[mathematics](https://kotlin.github.io/multik/multik-core/org.jetbrains.kotlinx.multik.api.math/index.html),\n[linear algebra](https://kotlin.github.io/multik/multik-core/org.jetbrains.kotlinx.multik.api.linalg/index.html),\n[statistics](https://kotlin.github.io/multik/multik-core/org.jetbrains.kotlinx.multik.api.stat/index.html).\n\n```kotlin\na.sin() // element-wise sin, equivalent to mk.math.sin(a)\na.cos() // element-wise cos, equivalent to mk.math.cos(a)\nb.log() // element-wise natural logarithm, equivalent to mk.math.log(b)\nb.exp() // element-wise exp, equivalent to mk.math.exp(b)\nd dot e // dot product, equivalent to mk.linalg.dot(d, e)\n```\n\n#### Aggregate functions\n```kotlin\nmk.math.sum(c) // array-wise sum\nmk.math.min(c) // array-wise minimum elements\nmk.math.maxD3(c, axis=0) // maximum value of an array along axis 0\nmk.math.cumSum(b, axis=1) // cumulative sum of the elements\nmk.stat.mean(a) // mean\nmk.stat.median(b) // meadian\n```\n\n#### Copying arrays\n```kotlin\nval f = a.copy() // create a copy of the array and its data\nval h = b.deepCopy() // create a copy of the array and copy the meaningful data\n```\n\n#### Operations of Iterable\n```kotlin\nc.filter { it \u003c 3 } // select all elements less than 3\nb.map { (it * it).toInt() } // return squares\nc.groupNDArrayBy { it % 2 } // group elements by condition\nc.sorted() // sort elements\n```\n\n#### Indexing/Slicing/Iterating\n```kotlin\na[2] // select the element at the 2 index\nb[1, 2] // select the element at row 1 column 2\nb[1] // select row 1 \nb[0..1, 1] // select elements at rows 0 to 1 in column 1\nb[0, 0..2..1] // select elements at row 0 in columns 0 to 2 with step 1\n\nfor (el in b) {\n    print(\"$el, \") // 1.5, 2.1, 3.0, 4.0, 5.0, 6.0, \n}\n\n// for n-dimensional\nval q = b.asDNArray()\nfor (index in q.multiIndices) {\n    print(\"${q[index]}, \") // 1.5, 2.1, 3.0, 4.0, 5.0, 6.0, \n}\n```\n\n#### Inplace\n\n```kotlin\nval a = mk.linspace\u003cFloat\u003e(0, 1, 10)\n/*\na = [0.0, 0.1111111111111111, 0.2222222222222222, 0.3333333333333333, 0.4444444444444444, 0.5555555555555556, \n0.6666666666666666, 0.7777777777777777, 0.8888888888888888, 1.0]\n*/\nval b = mk.linspace\u003cFloat\u003e(8, 9, 10)\n/*\nb = [8.0, 8.11111111111111, 8.222222222222221, 8.333333333333334, 8.444444444444445, 8.555555555555555,\n8.666666666666666, 8.777777777777779, 8.88888888888889, 9.0]\n*/\n\na.inplace { \n    math { \n        (this - b) * b\n         abs()\n    }\n}\n// a = [64.0, 64.88888, 65.77778, 66.66666, 67.55556, 68.44444, 69.333336, 70.22222, 71.111115, 72.0]\n```\n\n## Building\nTo build the entire project, you need to set up an environment for building `multik-openblas`:\n* JDK 1.8 or higher\n* _JAVA_HOME_ environment - to search for jni files\n* Compilers _gcc_, _g++_, _gfortran_ version 8 or higher.\nIt is important that they are of the same version.\n\nRun `./gradlew assemble` to build all modules.\nIf you don't need to build `multik-openblas`,\njust disable the `cmake_build` task and build the module you need.\n\n## Contributing\nThere is an opportunity to contribute to the project:\n1. Implement [math](multik-core/src/main/kotlin/org/jetbrains/kotlinx/multik/api/math/Math.kt),\n[linalg](multik-core/src/main/kotlin/org/jetbrains/kotlinx/multik/api/linalg/LinAlg.kt),\n[stat](multik-core/src/main/kotlin/org/jetbrains/kotlinx/multik/api/Statistics.kt) interfaces.\n2. 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).\n3. 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)\nto use your implementation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKotlin%2Fmultik","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKotlin%2Fmultik","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKotlin%2Fmultik/lists"}