From bf569e10f9be41d3aea1ed30d0a547e0f6d44310 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 21 Sep 2020 15:47:47 +0300 Subject: [PATCH 01/12] Implementation for #139 --- README.md | 29 ++++- build.gradle.kts | 81 ++++++++++++- doc/features.md | 14 --- docs/README-STUB.md | 110 ++++++++++++++++++ {doc => docs}/algebra.md | 0 {doc => docs}/buffers.md | 0 {doc => docs}/codestyle.md | 0 {doc => docs}/contexts.md | 0 {doc => docs}/expressions.md | 0 docs/features.md | 14 +++ {doc => docs}/histograms.md | 0 {doc => docs}/linear.md | 0 {doc => docs}/nd-structure.md | 0 kmath-core/{README.md => docs/README-STUB.md} | 14 +-- kmath-core/docs/kscience-module.json | 36 ++++++ settings.gradle.kts | 3 +- 16 files changed, 271 insertions(+), 30 deletions(-) delete mode 100644 doc/features.md create mode 100644 docs/README-STUB.md rename {doc => docs}/algebra.md (100%) rename {doc => docs}/buffers.md (100%) rename {doc => docs}/codestyle.md (100%) rename {doc => docs}/contexts.md (100%) rename {doc => docs}/expressions.md (100%) create mode 100644 docs/features.md rename {doc => docs}/histograms.md (100%) rename {doc => docs}/linear.md (100%) rename {doc => docs}/nd-structure.md (100%) rename kmath-core/{README.md => docs/README-STUB.md} (62%) create mode 100644 kmath-core/docs/kscience-module.json diff --git a/README.md b/README.md index c2e67e815..44363b27a 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ The Kotlin MATHematics library is intended as a Kotlin-based analog to Python's ## Features -Actual feature list is [here](doc/features.md) +Actual feature list is [here](docs/features.md) * **Algebra** * Algebraic structures like rings, spaces and field (**TODO** add example to wiki) @@ -66,6 +66,29 @@ can be used for a wide variety of purposes from high performance calculations to * **Fitting** Non-linear curve fitting facilities +## Modules + +### [kmath-core](kmath-core) + - [algebras](kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Algebraic structures: contexts and elements + - [nd](kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Many-dimensional structures + - [buffers](kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : One-dimensional structure + - [expressions](kmath-core/src/commonMain/kotlin/kscience/kmath/expressions) : Functional Expressions + - [domains](kmath-core/src/commonMain/kotlin/kscience/kmath/domains) : Domains + - [autodif](kmath-core/src/commonMain/kotlin/kscience/kmath/misc/AutoDiff.kt) : Automatic differentiation + +### [kmath-coroutines](kmath-coroutines) +### [kmath-viktor](kmath-viktor) +### [kmath-prob](kmath-prob) +### [kmath-ast](kmath-ast) +### [kmath-commons](kmath-commons) +### [kmath-memory](kmath-memory) +### [kmath-for-real](kmath-for-real) +### [kmath-functions](kmath-functions) +### [kmath-dimensions](kmath-dimensions) +### [kmath-histograms](kmath-histograms) +### [kmath-geometry](kmath-geometry) + + ## Multi-platform support KMath is developed as a multi-platform library, which means that most of interfaces are declared in the [common module](kmath-core/src/commonMain). Implementation is also done in the common module wherever possible. In some cases, features are delegated to platform-specific implementations even if they could be done in the common module for performance reasons. Currently, the JVM is the main focus of development, however Kotlin/Native and Kotlin/JS contributions are also welcome. @@ -84,8 +107,8 @@ repositories{ } dependencies{ - api("kscience.kmath:kmath-core:${kmathVersion}") - //api("kscience.kmath:kmath-core-jvm:${kmathVersion}") for jvm-specific version + api("kscience.kmath:kmath-core:0.2.0-dev-1") + //api("kscience.kmath:kmath-core-jvm:0.2.0-dev-1") for jvm-specific version } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 838a05771..ed3317bf8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,4 +18,83 @@ allprojects { version = kmathVersion } -subprojects { if (name.startsWith("kmath")) apply(plugin = "ru.mipt.npm.publish") } +subprojects { + if (name.startsWith("kmath")) apply() +} + +/** + * TODO move to base plugin + */ +val generateReadme by tasks.creating { + group = "documentation" + + fun List>.generateFeatureString(pathPrefix: String): String = buildString { + this@generateFeatureString.forEach { feature -> + val id by feature + val description by feature + val ref by feature + appendln(" - [$id]($pathPrefix$ref) : $description") + } + } + + doLast { + val reader = groovy.json.JsonSlurper() + val projects = HashMap>() + + project.subprojects { + var properties: Map = mapOf( + "name" to this.name, + "group" to this.group, + "version" to this.version + ) + + val projectProperties = this.file("docs/kscience-module.json") + + @Suppress("UNCHECKED_CAST") + if (projectProperties.exists()) { + val customProperties: Map = + (reader.parse(projectProperties) as? Map ?: emptyMap()).withDefault { null } + val features: List>? by customProperties + val featureString = features?.generateFeatureString("") + properties = customProperties + properties + ("featuresString" to featureString) + } + + projects[name] = properties.withDefault { null } + + val readmeStub = this.file("docs/README-STUB.md") + if (readmeStub.exists()) { + val readmeFile = this.file("README.md") + readmeFile.writeText( + groovy.text.SimpleTemplateEngine().createTemplate(readmeStub).make(properties).toString() + ) + } + } + + val rootReadmeStub = project.file("docs/README-STUB.md") + + val modulesString = buildString { + projects.filter { it.key.startsWith("kmath") }.forEach { (name, properties) -> + appendln("### [$name]($name)") + val features: List>? by properties + if (features != null) { + appendln(features!!.generateFeatureString("$name/")) + } + } + } + + val rootReadmeProperties: Map = mapOf( + "name" to project.name, + "group" to project.group, + "version" to project.version, + "modulesString" to modulesString + ) + + if (rootReadmeStub.exists()) { + val readmeFile = project.file("README.md") + readmeFile.writeText( + groovy.text.SimpleTemplateEngine().createTemplate(rootReadmeStub).make(rootReadmeProperties).toString() + ) + } + + } +} \ No newline at end of file diff --git a/doc/features.md b/doc/features.md deleted file mode 100644 index 0f2c4203f..000000000 --- a/doc/features.md +++ /dev/null @@ -1,14 +0,0 @@ -# Features - -* [Algebra](./algebra.md) - [Context-based](./contexts.md) operations on different primitives and structures. - -* [NDStructures](./nd-structure.md) - -* [Linear algebra](./linear.md) - Matrices, operations and linear equations solving. To be moved to separate module. Currently supports basic -api and multiple library back-ends. - -* [Histograms](./histograms.md) - Multidimensional histogram calculation and operations. - -* [Expressions](./expressions.md) - -* Commons math integration diff --git a/docs/README-STUB.md b/docs/README-STUB.md new file mode 100644 index 000000000..1c6a1f6e0 --- /dev/null +++ b/docs/README-STUB.md @@ -0,0 +1,110 @@ +[![JetBrains Research](https://jb.gg/badges/research.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) +[![DOI](https://zenodo.org/badge/129486382.svg)](https://zenodo.org/badge/latestdoi/129486382) + +![Gradle build](https://github.com/mipt-npm/kmath/workflows/Gradle%20build/badge.svg) + +Bintray: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-core/_latestVersion) + +Bintray-dev: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-core/_latestVersion) + +# KMath +Could be pronounced as `key-math`. +The Kotlin MATHematics library is intended as a Kotlin-based analog to Python's `numpy` library. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. + +## Publications +* [A conceptual article about context-oriented design](https://proandroiddev.com/an-introduction-context-oriented-programming-in-kotlin-2e79d316b0a2) +* [Another article about context-oriented design](https://proandroiddev.com/diving-deeper-into-context-oriented-programming-in-kotlin-3ecb4ec38814) +* [ACAT 2019 conference paper](https://aip.scitation.org/doi/abs/10.1063/1.5130103) + +# Goal +* Provide a flexible and powerful API to work with mathematics abstractions in Kotlin-multiplatform (JVM and JS for now and Native in future). +* Provide basic multiplatform implementations for those abstractions (without significant performance optimization). +* Provide bindings and wrappers with those abstractions for popular optimized platform libraries. + +## Non-goals +* Be like Numpy. It was the idea at the beginning, but we decided that we can do better in terms of API. +* Provide best performance out of the box. We have specialized libraries for that. Need only API wrappers for them. +* Cover all cases as immediately and in one bundle. We will modularize everything and add new features gradually. +* Provide specialized behavior in the core. API is made generic on purpose, so one needs to specialize for types, like for `Double` in the core. For that we will have specialization modules like `for-real`, which will give better experience for those, who want to work with specific types. + +## Features + +Actual feature list is [here](docs/features.md) + +* **Algebra** + * Algebraic structures like rings, spaces and field (**TODO** add example to wiki) + * Basic linear algebra operations (sums, products, etc.), backed by the `Space` API. + * Complex numbers backed by the `Field` API (meaning that they will be usable in any structure like vectors and N-dimensional arrays). + * Advanced linear algebra operations like matrix inversion and LU decomposition. + +* **Array-like structures** Full support of many-dimensional array-like structures +including mixed arithmetic operations and function operations over arrays and numbers (with the added benefit of static type checking). + +* **Expressions** By writing a single mathematical expression +once, users will be able to apply different types of objects to the expression by providing a context. Expressions +can be used for a wide variety of purposes from high performance calculations to code generation. + +* **Histograms** Fast multi-dimensional histograms. + +* **Streaming** Streaming operations on mathematical objects and objects buffers. + +* **Type-safe dimensions** Type-safe dimensions for matrix operations. + +* **Commons-math wrapper** It is planned to gradually wrap most parts of [Apache commons-math](http://commons.apache.org/proper/commons-math/) + library in Kotlin code and maybe rewrite some parts to better suit the Kotlin programming paradigm, however there is no fixed roadmap for that. Feel free + to submit a feature request if you want something to be done first. + +## Planned features + +* **Messaging** A mathematical notation to support multi-language and multi-node communication for mathematical tasks. + +* **Array statistics** + +* **Integration** Univariate and multivariate integration framework. + +* **Probability and distributions** + +* **Fitting** Non-linear curve fitting facilities + +## Modules + +$modulesString + +## Multi-platform support + +KMath is developed as a multi-platform library, which means that most of interfaces are declared in the [common module](kmath-core/src/commonMain). Implementation is also done in the common module wherever possible. In some cases, features are delegated to platform-specific implementations even if they could be done in the common module for performance reasons. Currently, the JVM is the main focus of development, however Kotlin/Native and Kotlin/JS contributions are also welcome. + +## Performance + +Calculation performance is one of major goals of KMath in the future, but in some cases it is not possible to achieve both performance and flexibility. We expect to focus on creating convenient universal API first and then work on increasing performance for specific cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be better than SciPy. + +### Dependency + +Release artifacts are accessible from bintray with following configuration (see documentation for [kotlin-multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html) form more details): + +```kotlin +repositories{ + maven("https://dl.bintray.com/mipt-npm/kscience") +} + +dependencies{ + api("kscience.kmath:kmath-core:$version") + //api("kscience.kmath:kmath-core-jvm:$version") for jvm-specific version +} +``` + +Gradle `6.0+` is required for multiplatform artifacts. + +### Development + +Development builds are accessible from the reposirtory +```kotlin +repositories{ + maven("https://dl.bintray.com/mipt-npm/dev") +} +``` +with the same artifact names. + +## Contributing + +The project requires a lot of additional work. Please feel free to contribute in any way and propose new features. diff --git a/doc/algebra.md b/docs/algebra.md similarity index 100% rename from doc/algebra.md rename to docs/algebra.md diff --git a/doc/buffers.md b/docs/buffers.md similarity index 100% rename from doc/buffers.md rename to docs/buffers.md diff --git a/doc/codestyle.md b/docs/codestyle.md similarity index 100% rename from doc/codestyle.md rename to docs/codestyle.md diff --git a/doc/contexts.md b/docs/contexts.md similarity index 100% rename from doc/contexts.md rename to docs/contexts.md diff --git a/doc/expressions.md b/docs/expressions.md similarity index 100% rename from doc/expressions.md rename to docs/expressions.md diff --git a/docs/features.md b/docs/features.md new file mode 100644 index 000000000..1068a4417 --- /dev/null +++ b/docs/features.md @@ -0,0 +1,14 @@ +# Features + +* [Algebra](algebra.md) - [Context-based](contexts.md) operations on different primitives and structures. + +* [NDStructures](nd-structure.md) + +* [Linear algebra](linear.md) - Matrices, operations and linear equations solving. To be moved to separate module. Currently supports basic +api and multiple library back-ends. + +* [Histograms](histograms.md) - Multidimensional histogram calculation and operations. + +* [Expressions](expressions.md) + +* Commons math integration diff --git a/doc/histograms.md b/docs/histograms.md similarity index 100% rename from doc/histograms.md rename to docs/histograms.md diff --git a/doc/linear.md b/docs/linear.md similarity index 100% rename from doc/linear.md rename to docs/linear.md diff --git a/doc/nd-structure.md b/docs/nd-structure.md similarity index 100% rename from doc/nd-structure.md rename to docs/nd-structure.md diff --git a/kmath-core/README.md b/kmath-core/docs/README-STUB.md similarity index 62% rename from kmath-core/README.md rename to kmath-core/docs/README-STUB.md index 9d05331f9..c2e8f661f 100644 --- a/kmath-core/README.md +++ b/kmath-core/docs/README-STUB.md @@ -1,16 +1,10 @@ # The Core Module (`kmath-core`) The core features of KMath: - -- Algebraic structures: contexts and elements. -- ND structures. -- Buffers. -- Functional Expressions. -- Domains. -- Automatic differentiation. +$featuresString > #### Artifact: -> This module is distributed in the artifact `kscience.kmath:kmath-core:0.1.4-dev-8`. +> This module artifact: `$group:kmath-core:$version`. > > **Gradle:** > @@ -22,7 +16,7 @@ The core features of KMath: > } > > dependencies { -> implementation 'kscience.kmath:kmath-core:0.1.4-dev-8' +> implementation '$group:kmath-core:$version' > } > ``` > **Gradle Kotlin DSL:** @@ -35,6 +29,6 @@ The core features of KMath: > } > > dependencies { -> implementation("kscience.kmath:kmath-core:0.1.4-dev-8") +> implementation("$group:kmath-core:$version") > } > ``` diff --git a/kmath-core/docs/kscience-module.json b/kmath-core/docs/kscience-module.json new file mode 100644 index 000000000..c7ac4f082 --- /dev/null +++ b/kmath-core/docs/kscience-module.json @@ -0,0 +1,36 @@ +{ + "description": "Core classes, algebra definitions, basic linear algebra", + "maturity": "development", + "features": [ + { + "id": "algebras", + "description": "Algebraic structures: contexts and elements", + "ref": "src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt" + }, + { + "id": "nd", + "description": "Many-dimensional structures", + "ref": "src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt" + }, + { + "id": "buffers", + "description": "One-dimensional structure", + "ref": "src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt" + }, + { + "id": "expressions", + "description": "Functional Expressions", + "ref": "src/commonMain/kotlin/kscience/kmath/expressions" + }, + { + "id": "domains", + "description": "Domains", + "ref": "src/commonMain/kotlin/kscience/kmath/domains" + }, + { + "id": "autodif", + "description": "Automatic differentiation", + "ref": "src/commonMain/kotlin/kscience/kmath/misc/AutoDiff.kt" + } + ] +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index c0d729c32..fe0ee6c5d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -32,9 +32,8 @@ include( ":kmath-histograms", ":kmath-commons", ":kmath-viktor", - ":kmath-koma", ":kmath-prob", - ":kmath-io", +// ":kmath-io", ":kmath-dimensions", ":kmath-for-real", ":kmath-geometry", From 1e50587da4cf4f88387bf8bc2895b4a27d32d309 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 21 Sep 2020 15:53:11 +0300 Subject: [PATCH 02/12] Update CHANGELOG.md --- CHANGELOG.md | 1 + kmath-core/README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 kmath-core/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index bd9d0c2aa..e017fe565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - `fun` annotation for SAM interfaces in library - Explicit `public` visibility for all public APIs - Better trigonometric and hyperbolic functions for `AutoDiffField` (https://github.com/mipt-npm/kmath/pull/140). +- Automatic documentation generation for features (#139) ### Changed - Package changed from `scientifik` to `kscience.kmath`. diff --git a/kmath-core/README.md b/kmath-core/README.md new file mode 100644 index 000000000..1fcd9edc9 --- /dev/null +++ b/kmath-core/README.md @@ -0,0 +1,40 @@ +# The Core Module (`kmath-core`) + +The core features of KMath: + - [algebras](src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Algebraic structures: contexts and elements + - [nd](src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Many-dimensional structures + - [buffers](src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : One-dimensional structure + - [expressions](src/commonMain/kotlin/kscience/kmath/expressions) : Functional Expressions + - [domains](src/commonMain/kotlin/kscience/kmath/domains) : Domains + - [autodif](src/commonMain/kotlin/kscience/kmath/misc/AutoDiff.kt) : Automatic differentiation + + +> #### Artifact: +> This module artifact: `kscience.kmath:kmath-core:0.2.0-dev-1`. +> +> **Gradle:** +> +> ```gradle +> repositories { +> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } +> maven { url 'https://dl.bintray.com/mipt-npm/dev' } +> maven { url https://dl.bintray.com/hotkeytlt/maven' } +> } +> +> dependencies { +> implementation 'kscience.kmath:kmath-core:0.2.0-dev-1' +> } +> ``` +> **Gradle Kotlin DSL:** +> +> ```kotlin +> repositories { +> maven("https://dl.bintray.com/mipt-npm/kscience") +> maven("https://dl.bintray.com/mipt-npm/dev") +> maven("https://dl.bintray.com/hotkeytlt/maven") +> } +> +> dependencies { +> implementation("kscience.kmath:kmath-core:0.2.0-dev-1") +> } +> ``` From 28137e44e150944f5b7758f008dd1d441585aea7 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 25 Sep 2020 10:13:38 +0300 Subject: [PATCH 03/12] Readme auto-generation via plugin --- README.md | 29 +++++-- build.gradle.kts | 81 +------------------ docs/templates/ARTIFACT-TEMPLATE.md | 29 +++++++ .../README-TEMPLATE.md} | 10 +-- kmath-core/build.gradle.kts | 39 ++++++++- .../{README-STUB.md => README-TEMPLATE.md} | 8 +- kmath-core/docs/kscience-module.json | 36 --------- settings.gradle.kts | 23 +++--- 8 files changed, 112 insertions(+), 143 deletions(-) create mode 100644 docs/templates/ARTIFACT-TEMPLATE.md rename docs/{README-STUB.md => templates/README-TEMPLATE.md} (85%) rename kmath-core/docs/{README-STUB.md => README-TEMPLATE.md} (77%) delete mode 100644 kmath-core/docs/kscience-module.json diff --git a/README.md b/README.md index 44363b27a..4d89337b5 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,12 @@ can be used for a wide variety of purposes from high performance calculations to ## Modules +### [examples](examples) + +### [kmath-ast](kmath-ast) + +### [kmath-commons](kmath-commons) + ### [kmath-core](kmath-core) - [algebras](kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Algebraic structures: contexts and elements - [nd](kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Many-dimensional structures @@ -77,17 +83,24 @@ can be used for a wide variety of purposes from high performance calculations to - [autodif](kmath-core/src/commonMain/kotlin/kscience/kmath/misc/AutoDiff.kt) : Automatic differentiation ### [kmath-coroutines](kmath-coroutines) -### [kmath-viktor](kmath-viktor) -### [kmath-prob](kmath-prob) -### [kmath-ast](kmath-ast) -### [kmath-commons](kmath-commons) -### [kmath-memory](kmath-memory) -### [kmath-for-real](kmath-for-real) -### [kmath-functions](kmath-functions) + ### [kmath-dimensions](kmath-dimensions) -### [kmath-histograms](kmath-histograms) + +### [kmath-for-real](kmath-for-real) + +### [kmath-functions](kmath-functions) + ### [kmath-geometry](kmath-geometry) +### [kmath-histograms](kmath-histograms) + +### [kmath-memory](kmath-memory) + +### [kmath-prob](kmath-prob) + +### [kmath-viktor](kmath-viktor) + + ## Multi-platform support diff --git a/build.gradle.kts b/build.gradle.kts index ed3317bf8..81e0cb973 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("ru.mipt.npm.base") - id("org.jetbrains.changelog") version "0.4.0" + //id("ru.mipt.npm.publish") apply false + id("ru.mipt.npm.project") } val kmathVersion by extra("0.2.0-dev-1") @@ -22,79 +22,6 @@ subprojects { if (name.startsWith("kmath")) apply() } -/** - * TODO move to base plugin - */ -val generateReadme by tasks.creating { - group = "documentation" - - fun List>.generateFeatureString(pathPrefix: String): String = buildString { - this@generateFeatureString.forEach { feature -> - val id by feature - val description by feature - val ref by feature - appendln(" - [$id]($pathPrefix$ref) : $description") - } - } - - doLast { - val reader = groovy.json.JsonSlurper() - val projects = HashMap>() - - project.subprojects { - var properties: Map = mapOf( - "name" to this.name, - "group" to this.group, - "version" to this.version - ) - - val projectProperties = this.file("docs/kscience-module.json") - - @Suppress("UNCHECKED_CAST") - if (projectProperties.exists()) { - val customProperties: Map = - (reader.parse(projectProperties) as? Map ?: emptyMap()).withDefault { null } - val features: List>? by customProperties - val featureString = features?.generateFeatureString("") - properties = customProperties + properties + ("featuresString" to featureString) - } - - projects[name] = properties.withDefault { null } - - val readmeStub = this.file("docs/README-STUB.md") - if (readmeStub.exists()) { - val readmeFile = this.file("README.md") - readmeFile.writeText( - groovy.text.SimpleTemplateEngine().createTemplate(readmeStub).make(properties).toString() - ) - } - } - - val rootReadmeStub = project.file("docs/README-STUB.md") - - val modulesString = buildString { - projects.filter { it.key.startsWith("kmath") }.forEach { (name, properties) -> - appendln("### [$name]($name)") - val features: List>? by properties - if (features != null) { - appendln(features!!.generateFeatureString("$name/")) - } - } - } - - val rootReadmeProperties: Map = mapOf( - "name" to project.name, - "group" to project.group, - "version" to project.version, - "modulesString" to modulesString - ) - - if (rootReadmeStub.exists()) { - val readmeFile = project.file("README.md") - readmeFile.writeText( - groovy.text.SimpleTemplateEngine().createTemplate(rootReadmeStub).make(rootReadmeProperties).toString() - ) - } - - } +readme{ + readmeTemplate = file("docs/template/README-TEMPLATE.md") } \ No newline at end of file diff --git a/docs/templates/ARTIFACT-TEMPLATE.md b/docs/templates/ARTIFACT-TEMPLATE.md new file mode 100644 index 000000000..1b354e022 --- /dev/null +++ b/docs/templates/ARTIFACT-TEMPLATE.md @@ -0,0 +1,29 @@ +> #### Artifact: +> This module artifact: `${group}:${name}:${version}`. +> +> **Gradle:** +> +> ```gradle +> repositories { +> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } +> maven { url 'https://dl.bintray.com/mipt-npm/dev' } +> maven { url https://dl.bintray.com/hotkeytlt/maven' } +> } +> +> dependencies { +> implementation '${group}:${name}:${version}' +> } +> ``` +> **Gradle Kotlin DSL:** +> +> ```kotlin +> repositories { +> maven("https://dl.bintray.com/mipt-npm/kscience") +> maven("https://dl.bintray.com/mipt-npm/dev") +> maven("https://dl.bintray.com/hotkeytlt/maven") +> } +> +> dependencies { +> implementation("${group}:${name}:${version}") +> } +> ``` \ No newline at end of file diff --git a/docs/README-STUB.md b/docs/templates/README-TEMPLATE.md similarity index 85% rename from docs/README-STUB.md rename to docs/templates/README-TEMPLATE.md index 1c6a1f6e0..f451adb24 100644 --- a/docs/README-STUB.md +++ b/docs/templates/README-TEMPLATE.md @@ -9,9 +9,9 @@ Bintray-dev: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmat # KMath Could be pronounced as `key-math`. -The Kotlin MATHematics library is intended as a Kotlin-based analog to Python's `numpy` library. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. +The Kotlin MATHematics library was initially intended as a Kotlin-based analog to Python's `numpy` library. Later we found that kotlin is much more flexible language and allows superior architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could be achieved with [kmath-for-real](/kmath-for-real) extension module. -## Publications +## Publications and talks * [A conceptual article about context-oriented design](https://proandroiddev.com/an-introduction-context-oriented-programming-in-kotlin-2e79d316b0a2) * [Another article about context-oriented design](https://proandroiddev.com/diving-deeper-into-context-oriented-programming-in-kotlin-3ecb4ec38814) * [ACAT 2019 conference paper](https://aip.scitation.org/doi/abs/10.1063/1.5130103) @@ -29,7 +29,7 @@ The Kotlin MATHematics library is intended as a Kotlin-based analog to Python's ## Features -Actual feature list is [here](docs/features.md) +Actual feature list is [here](/docs/features.md) * **Algebra** * Algebraic structures like rings, spaces and field (**TODO** add example to wiki) @@ -68,11 +68,11 @@ can be used for a wide variety of purposes from high performance calculations to ## Modules -$modulesString +$modules ## Multi-platform support -KMath is developed as a multi-platform library, which means that most of interfaces are declared in the [common module](kmath-core/src/commonMain). Implementation is also done in the common module wherever possible. In some cases, features are delegated to platform-specific implementations even if they could be done in the common module for performance reasons. Currently, the JVM is the main focus of development, however Kotlin/Native and Kotlin/JS contributions are also welcome. +KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the [common module](/kmath-core/src/commonMain). Implementation is also done in the common module wherever possible. In some cases, features are delegated to platform-specific implementations even if they could be done in the common module for performance reasons. Currently, the JVM is the main focus of development, however Kotlin/Native and Kotlin/JS contributions are also welcome. ## Performance diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index e315e1640..31a16e20b 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -1,7 +1,44 @@ -plugins { id("ru.mipt.npm.mpp") } +plugins { + id("ru.mipt.npm.mpp") +} kotlin.sourceSets.commonMain { dependencies { api(project(":kmath-memory")) } } + +readme { + description = "Core classes, algebra definitions, basic linear algebra" + maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT + feature( + id = "algebras", + description = "Algebraic structures: contexts and elements", + ref = "src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt" + ) + feature( + id = "nd", + description = "Many-dimensional structures", + ref = "src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt" + ) + feature( + id = "buffers", + description = "One-dimensional structure", + ref = "src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt" + ) + feature( + id = "expressions", + description = "Functional Expressions", + ref = "src/commonMain/kotlin/kscience/kmath/expressions" + ) + feature( + id = "domains", + description = "Domains", + ref = "src/commonMain/kotlin/kscience/kmath/domains" + ) + feature( + id = "autodif", + description = "Automatic differentiation", + ref = "src/commonMain/kotlin/kscience/kmath/misc/AutoDiff.kt" + ) +} \ No newline at end of file diff --git a/kmath-core/docs/README-STUB.md b/kmath-core/docs/README-TEMPLATE.md similarity index 77% rename from kmath-core/docs/README-STUB.md rename to kmath-core/docs/README-TEMPLATE.md index c2e8f661f..183f300ac 100644 --- a/kmath-core/docs/README-STUB.md +++ b/kmath-core/docs/README-TEMPLATE.md @@ -1,10 +1,10 @@ # The Core Module (`kmath-core`) The core features of KMath: -$featuresString +$features > #### Artifact: -> This module artifact: `$group:kmath-core:$version`. +> This module artifact: `${group}:${name}:${version}`. > > **Gradle:** > @@ -16,7 +16,7 @@ $featuresString > } > > dependencies { -> implementation '$group:kmath-core:$version' +> implementation '${group}:${name}:${version}' > } > ``` > **Gradle Kotlin DSL:** @@ -29,6 +29,6 @@ $featuresString > } > > dependencies { -> implementation("$group:kmath-core:$version") +> implementation("${group}:${name}:${version}") > } > ``` diff --git a/kmath-core/docs/kscience-module.json b/kmath-core/docs/kscience-module.json deleted file mode 100644 index c7ac4f082..000000000 --- a/kmath-core/docs/kscience-module.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "description": "Core classes, algebra definitions, basic linear algebra", - "maturity": "development", - "features": [ - { - "id": "algebras", - "description": "Algebraic structures: contexts and elements", - "ref": "src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt" - }, - { - "id": "nd", - "description": "Many-dimensional structures", - "ref": "src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt" - }, - { - "id": "buffers", - "description": "One-dimensional structure", - "ref": "src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt" - }, - { - "id": "expressions", - "description": "Functional Expressions", - "ref": "src/commonMain/kotlin/kscience/kmath/expressions" - }, - { - "id": "domains", - "description": "Domains", - "ref": "src/commonMain/kotlin/kscience/kmath/domains" - }, - { - "id": "autodif", - "description": "Automatic differentiation", - "ref": "src/commonMain/kotlin/kscience/kmath/misc/AutoDiff.kt" - } - ] -} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index fe0ee6c5d..ad9014e56 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,15 +1,4 @@ pluginManagement { - val toolsVersion = "0.6.0" - - plugins { - id("kotlinx.benchmark") version "0.2.0-dev-20" - id("ru.mipt.npm.base") version toolsVersion - id("ru.mipt.npm.mpp") version toolsVersion - id("ru.mipt.npm.jvm") version toolsVersion - id("ru.mipt.npm.publish") version toolsVersion - kotlin("plugin.allopen") - } - repositories { mavenLocal() jcenter() @@ -20,6 +9,17 @@ pluginManagement { maven("https://dl.bintray.com/kotlin/kotlinx") maven("https://dl.bintray.com/kotlin/kotlin-dev/") } + + val toolsVersion = "0.6.1" + + plugins { + id("kotlinx.benchmark") version "0.2.0-dev-20" + id("ru.mipt.npm.project") version toolsVersion + id("ru.mipt.npm.mpp") version toolsVersion + id("ru.mipt.npm.jvm") version toolsVersion + id("ru.mipt.npm.publish") version toolsVersion + kotlin("plugin.allopen") + } } rootProject.name = "kmath" @@ -33,7 +33,6 @@ include( ":kmath-commons", ":kmath-viktor", ":kmath-prob", -// ":kmath-io", ":kmath-dimensions", ":kmath-for-real", ":kmath-geometry", From 8014b3df0bec4acc3e9d0dabbe6422b325329968 Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Fri, 25 Sep 2020 20:49:08 +0700 Subject: [PATCH 04/12] Simplify asm.kt --- .../jvmMain/kotlin/kscience/kmath/asm/asm.kt | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/asm.kt b/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/asm.kt index edfe7f01d..53425e7e3 100644 --- a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/asm.kt +++ b/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/asm.kt @@ -19,39 +19,37 @@ import kotlin.reflect.KClass * @author Alexander Nozik */ public fun MST.compileWith(type: KClass, algebra: Algebra): Expression { - fun AsmBuilder.visit(node: MST) { - when (node) { - is MST.Symbolic -> { - val symbol = try { - algebra.symbol(node.value) - } catch (ignored: Throwable) { - null - } - - if (symbol != null) - loadTConstant(symbol) - else - loadVariable(node.value) + fun AsmBuilder.visit(node: MST): Unit = when (node) { + is MST.Symbolic -> { + val symbol = try { + algebra.symbol(node.value) + } catch (ignored: Throwable) { + null } - is MST.Numeric -> loadNumeric(node.value) + if (symbol != null) + loadTConstant(symbol) + else + loadVariable(node.value) + } - is MST.Unary -> buildAlgebraOperationCall( - context = algebra, - name = node.operation, - fallbackMethodName = "unaryOperation", - parameterTypes = arrayOf(MstType.fromMst(node.value)) - ) { visit(node.value) } + is MST.Numeric -> loadNumeric(node.value) - is MST.Binary -> buildAlgebraOperationCall( - context = algebra, - name = node.operation, - fallbackMethodName = "binaryOperation", - parameterTypes = arrayOf(MstType.fromMst(node.left), MstType.fromMst(node.right)) - ) { - visit(node.left) - visit(node.right) - } + is MST.Unary -> buildAlgebraOperationCall( + context = algebra, + name = node.operation, + fallbackMethodName = "unaryOperation", + parameterTypes = arrayOf(MstType.fromMst(node.value)) + ) { visit(node.value) } + + is MST.Binary -> buildAlgebraOperationCall( + context = algebra, + name = node.operation, + fallbackMethodName = "binaryOperation", + parameterTypes = arrayOf(MstType.fromMst(node.left), MstType.fromMst(node.right)) + ) { + visit(node.left) + visit(node.right) } } From 4043df7f24d9671aac9d606fa41688d966f2cc56 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 26 Sep 2020 12:15:11 +0300 Subject: [PATCH 05/12] Documentation auto-generation update --- README.md | 102 ++++++++++++++---- build.gradle.kts | 5 +- docs/templates/ARTIFACT-TEMPLATE.md | 2 +- .../commons/expressions/DiffExpression.kt | 2 +- kmath-core/build.gradle.kts | 1 + kmath-core/docs/README-TEMPLATE.md | 33 +----- 6 files changed, 87 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 4d89337b5..8bc85bf2b 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ Bintray-dev: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmat # KMath Could be pronounced as `key-math`. -The Kotlin MATHematics library is intended as a Kotlin-based analog to Python's `numpy` library. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. +The Kotlin MATHematics library was initially intended as a Kotlin-based analog to Python's `numpy` library. Later we found that kotlin is much more flexible language and allows superior architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could be achieved with [kmath-for-real](/kmath-for-real) extension module. -## Publications +## Publications and talks * [A conceptual article about context-oriented design](https://proandroiddev.com/an-introduction-context-oriented-programming-in-kotlin-2e79d316b0a2) * [Another article about context-oriented design](https://proandroiddev.com/diving-deeper-into-context-oriented-programming-in-kotlin-3ecb4ec38814) * [ACAT 2019 conference paper](https://aip.scitation.org/doi/abs/10.1063/1.5130103) @@ -29,7 +29,7 @@ The Kotlin MATHematics library is intended as a Kotlin-based analog to Python's ## Features -Actual feature list is [here](docs/features.md) +Actual feature list is [here](/docs/features.md) * **Algebra** * Algebraic structures like rings, spaces and field (**TODO** add example to wiki) @@ -68,43 +68,99 @@ can be used for a wide variety of purposes from high performance calculations to ## Modules -### [examples](examples) +
-### [kmath-ast](kmath-ast) +* ### [examples](examples) +> +> +> **Maturity**: EXPERIMENTAL +
-### [kmath-commons](kmath-commons) +* ### [kmath-ast](kmath-ast) +> +> +> **Maturity**: EXPERIMENTAL +
-### [kmath-core](kmath-core) - - [algebras](kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Algebraic structures: contexts and elements - - [nd](kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Many-dimensional structures - - [buffers](kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : One-dimensional structure - - [expressions](kmath-core/src/commonMain/kotlin/kscience/kmath/expressions) : Functional Expressions - - [domains](kmath-core/src/commonMain/kotlin/kscience/kmath/domains) : Domains - - [autodif](kmath-core/src/commonMain/kotlin/kscience/kmath/misc/AutoDiff.kt) : Automatic differentiation +* ### [kmath-commons](kmath-commons) +> +> +> **Maturity**: EXPERIMENTAL +
-### [kmath-coroutines](kmath-coroutines) +* ### [kmath-core](kmath-core) +> Core classes, algebra definitions, basic linear algebra +> +> **Maturity**: DEVELOPMENT +> +> **Features:** +> - [algebras](kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Algebraic structures: contexts and elements +> - [nd](kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Many-dimensional structures +> - [buffers](kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : One-dimensional structure +> - [expressions](kmath-core/src/commonMain/kotlin/kscience/kmath/expressions) : Functional Expressions +> - [domains](kmath-core/src/commonMain/kotlin/kscience/kmath/domains) : Domains +> - [autodif](kmath-core/src/commonMain/kotlin/kscience/kmath/misc/AutoDiff.kt) : Automatic differentiation -### [kmath-dimensions](kmath-dimensions) +
-### [kmath-for-real](kmath-for-real) +* ### [kmath-coroutines](kmath-coroutines) +> +> +> **Maturity**: EXPERIMENTAL +
-### [kmath-functions](kmath-functions) +* ### [kmath-dimensions](kmath-dimensions) +> +> +> **Maturity**: EXPERIMENTAL +
-### [kmath-geometry](kmath-geometry) +* ### [kmath-for-real](kmath-for-real) +> +> +> **Maturity**: EXPERIMENTAL +
-### [kmath-histograms](kmath-histograms) +* ### [kmath-functions](kmath-functions) +> +> +> **Maturity**: EXPERIMENTAL +
-### [kmath-memory](kmath-memory) +* ### [kmath-geometry](kmath-geometry) +> +> +> **Maturity**: EXPERIMENTAL +
-### [kmath-prob](kmath-prob) +* ### [kmath-histograms](kmath-histograms) +> +> +> **Maturity**: EXPERIMENTAL +
-### [kmath-viktor](kmath-viktor) +* ### [kmath-memory](kmath-memory) +> +> +> **Maturity**: EXPERIMENTAL +
+* ### [kmath-prob](kmath-prob) +> +> +> **Maturity**: EXPERIMENTAL +
+ +* ### [kmath-viktor](kmath-viktor) +> +> +> **Maturity**: EXPERIMENTAL +
## Multi-platform support -KMath is developed as a multi-platform library, which means that most of interfaces are declared in the [common module](kmath-core/src/commonMain). Implementation is also done in the common module wherever possible. In some cases, features are delegated to platform-specific implementations even if they could be done in the common module for performance reasons. Currently, the JVM is the main focus of development, however Kotlin/Native and Kotlin/JS contributions are also welcome. +KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the [common module](/kmath-core/src/commonMain). Implementation is also done in the common module wherever possible. In some cases, features are delegated to platform-specific implementations even if they could be done in the common module for performance reasons. Currently, the JVM is the main focus of development, however Kotlin/Native and Kotlin/JS contributions are also welcome. ## Performance diff --git a/build.gradle.kts b/build.gradle.kts index 81e0cb973..87862ae8e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,4 @@ plugins { - //id("ru.mipt.npm.publish") apply false id("ru.mipt.npm.project") } @@ -23,5 +22,5 @@ subprojects { } readme{ - readmeTemplate = file("docs/template/README-TEMPLATE.md") -} \ No newline at end of file + readmeTemplate = file("docs/templates/README-TEMPLATE.md") +} diff --git a/docs/templates/ARTIFACT-TEMPLATE.md b/docs/templates/ARTIFACT-TEMPLATE.md index 1b354e022..8630b4b97 100644 --- a/docs/templates/ARTIFACT-TEMPLATE.md +++ b/docs/templates/ARTIFACT-TEMPLATE.md @@ -7,7 +7,7 @@ > repositories { > maven { url 'https://dl.bintray.com/mipt-npm/kscience' } > maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url https://dl.bintray.com/hotkeytlt/maven' } +> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } > } > > dependencies { diff --git a/kmath-commons/src/main/kotlin/kscience/kmath/commons/expressions/DiffExpression.kt b/kmath-commons/src/main/kotlin/kscience/kmath/commons/expressions/DiffExpression.kt index 3ac908536..8a09cc793 100644 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/expressions/DiffExpression.kt +++ b/kmath-commons/src/main/kotlin/kscience/kmath/commons/expressions/DiffExpression.kt @@ -94,7 +94,7 @@ public class DiffExpression(public val function: DerivativeStructureField.() -> * TODO make result [DiffExpression] */ public fun derivative(orders: Map): Expression = Expression { arguments -> - (DerivativeStructureField(orders.values.max() ?: 0, arguments)) { function().deriv(orders) } + (DerivativeStructureField(orders.values.maxOrNull() ?: 0, arguments)) { function().deriv(orders) } } //TODO add gradient and maybe other vector operators diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 31a16e20b..d64a4d8a5 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -11,6 +11,7 @@ kotlin.sourceSets.commonMain { readme { description = "Core classes, algebra definitions, basic linear algebra" maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT + propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature( id = "algebras", description = "Algebraic structures: contexts and elements", diff --git a/kmath-core/docs/README-TEMPLATE.md b/kmath-core/docs/README-TEMPLATE.md index 183f300ac..83d1ebdce 100644 --- a/kmath-core/docs/README-TEMPLATE.md +++ b/kmath-core/docs/README-TEMPLATE.md @@ -1,34 +1,7 @@ # The Core Module (`kmath-core`) The core features of KMath: -$features -> #### Artifact: -> This module artifact: `${group}:${name}:${version}`. -> -> **Gradle:** -> -> ```gradle -> repositories { -> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } -> maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url https://dl.bintray.com/hotkeytlt/maven' } -> } -> -> dependencies { -> implementation '${group}:${name}:${version}' -> } -> ``` -> **Gradle Kotlin DSL:** -> -> ```kotlin -> repositories { -> maven("https://dl.bintray.com/mipt-npm/kscience") -> maven("https://dl.bintray.com/mipt-npm/dev") -> maven("https://dl.bintray.com/hotkeytlt/maven") -> } -> -> dependencies { -> implementation("${group}:${name}:${version}") -> } -> ``` +${features} + +${artifact} From b734136b82d09532c61adba08e4c9a058bd19547 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 26 Sep 2020 12:21:08 +0300 Subject: [PATCH 06/12] Add images --- docs/images/KM.svg | 59 ++++++ docs/images/KM_mono.svg | 55 ++++++ docs/images/KMath.svg | 91 +++++++++ docs/images/KMath_mono.svg | 371 +++++++++++++++++++++++++++++++++++++ kmath-core/README.md | 5 +- 5 files changed, 579 insertions(+), 2 deletions(-) create mode 100644 docs/images/KM.svg create mode 100644 docs/images/KM_mono.svg create mode 100644 docs/images/KMath.svg create mode 100644 docs/images/KMath_mono.svg diff --git a/docs/images/KM.svg b/docs/images/KM.svg new file mode 100644 index 000000000..50126cbc5 --- /dev/null +++ b/docs/images/KM.svg @@ -0,0 +1,59 @@ + +image/svg+xml \ No newline at end of file diff --git a/docs/images/KM_mono.svg b/docs/images/KM_mono.svg new file mode 100644 index 000000000..3b6890b6b --- /dev/null +++ b/docs/images/KM_mono.svg @@ -0,0 +1,55 @@ + +image/svg+xml \ No newline at end of file diff --git a/docs/images/KMath.svg b/docs/images/KMath.svg new file mode 100644 index 000000000..d88cfe7b0 --- /dev/null +++ b/docs/images/KMath.svg @@ -0,0 +1,91 @@ + +image/svg+xml \ No newline at end of file diff --git a/docs/images/KMath_mono.svg b/docs/images/KMath_mono.svg new file mode 100644 index 000000000..3a62ac383 --- /dev/null +++ b/docs/images/KMath_mono.svg @@ -0,0 +1,371 @@ + +image/svg+xml \ No newline at end of file diff --git a/kmath-core/README.md b/kmath-core/README.md index 1fcd9edc9..3482502b9 100644 --- a/kmath-core/README.md +++ b/kmath-core/README.md @@ -1,6 +1,7 @@ # The Core Module (`kmath-core`) The core features of KMath: + - [algebras](src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Algebraic structures: contexts and elements - [nd](src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Many-dimensional structures - [buffers](src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : One-dimensional structure @@ -11,14 +12,14 @@ The core features of KMath: > #### Artifact: > This module artifact: `kscience.kmath:kmath-core:0.2.0-dev-1`. -> +> > **Gradle:** > > ```gradle > repositories { > maven { url 'https://dl.bintray.com/mipt-npm/kscience' } > maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url https://dl.bintray.com/hotkeytlt/maven' } +> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } > } > > dependencies { From 6b1eb4cfd7bd0e8520a9e49b11eedaa7daf75fde Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 26 Sep 2020 13:57:24 +0300 Subject: [PATCH 07/12] Fix artifact template --- docs/templates/ARTIFACT-TEMPLATE.md | 5 +++++ kmath-core/README.md | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/docs/templates/ARTIFACT-TEMPLATE.md b/docs/templates/ARTIFACT-TEMPLATE.md index 8630b4b97..cbdd98218 100644 --- a/docs/templates/ARTIFACT-TEMPLATE.md +++ b/docs/templates/ARTIFACT-TEMPLATE.md @@ -1,6 +1,11 @@ > #### Artifact: +> > This module artifact: `${group}:${name}:${version}`. > +> Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/${name}/images/download.svg) ](https://bintray.com/mipt-npm/kscience/${name}/_latestVersion) +> +> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/${name}/images/download.svg) ](https://bintray.com/mipt-npm/dev/${name}/_latestVersion) +> > **Gradle:** > > ```gradle diff --git a/kmath-core/README.md b/kmath-core/README.md index 3482502b9..2cf7ed5dc 100644 --- a/kmath-core/README.md +++ b/kmath-core/README.md @@ -11,8 +11,13 @@ The core features of KMath: > #### Artifact: +> > This module artifact: `kscience.kmath:kmath-core:0.2.0-dev-1`. > +> Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-core/_latestVersion) +> +> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-core/_latestVersion) +> > **Gradle:** > > ```gradle From 7d315e37d172d7726ec93e211ba323328cb6049e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 27 Sep 2020 11:13:30 +0300 Subject: [PATCH 08/12] native memory --- .gitignore | 2 - CHANGELOG.md | 2 +- gradle.properties | 9 ++ kmath-core/build.gradle.kts | 1 + .../kscience/kmath/operations/Complex.kt | 6 +- .../kscience/kmath/structures/MemoryBuffer.kt | 2 +- kmath-memory/build.gradle.kts | 5 +- .../kmath}/memory/Memory.kt | 2 +- .../kmath}/memory/MemorySpec.kt | 2 +- .../kmath}/memory/DataViewMemory.kt | 2 +- .../kmath}/memory/ByteBufferMemory.kt | 2 +- .../kscience/kmath/memory/NativeMemory.kt | 93 +++++++++++++++++++ 12 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 gradle.properties rename kmath-memory/src/commonMain/kotlin/{scientifik => kscience/kmath}/memory/Memory.kt (99%) rename kmath-memory/src/commonMain/kotlin/{scientifik => kscience/kmath}/memory/MemorySpec.kt (98%) rename kmath-memory/src/jsMain/kotlin/{scientifik => kscience/kmath}/memory/DataViewMemory.kt (99%) rename kmath-memory/src/jvmMain/kotlin/{scientifik => kscience/kmath}/memory/ByteBufferMemory.kt (99%) create mode 100644 kmath-memory/src/nativeMain/kotlin/kscience/kmath/memory/NativeMemory.kt diff --git a/.gitignore b/.gitignore index a9294eff9..bade7f08c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,3 @@ out/ # Cache of project .gradletasknamecache - -gradle.properties \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e017fe565..09c6274df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - `fun` annotation for SAM interfaces in library - Explicit `public` visibility for all public APIs - Better trigonometric and hyperbolic functions for `AutoDiffField` (https://github.com/mipt-npm/kmath/pull/140). -- Automatic documentation generation for features (#139) +- Automatic README generation for features (#139) ### Changed - Package changed from `scientifik` to `kscience.kmath`. diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 000000000..930bba550 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,9 @@ +kotlin.code.style=official +kotlin.parallel.tasks.in.project=true +kotlin.mpp.enableGranularSourceSetsMetadata=true +kotlin.native.enableDependencyPropagation=false +kotlin.mpp.stability.nowarn=true + +org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m +org.gradle.parallel=true +systemProp.org.gradle.internal.publish.checksums.insecure=true \ No newline at end of file diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index d64a4d8a5..b56151abe 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("ru.mipt.npm.mpp") + id("ru.mipt.npm.native") } kotlin.sourceSets.commonMain { diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Complex.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Complex.kt index c0faf5dc5..24bfec054 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Complex.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Complex.kt @@ -1,11 +1,11 @@ package kscience.kmath.operations +import kscience.kmath.memory.MemoryReader +import kscience.kmath.memory.MemorySpec +import kscience.kmath.memory.MemoryWriter import kscience.kmath.structures.Buffer import kscience.kmath.structures.MemoryBuffer import kscience.kmath.structures.MutableBuffer -import kscience.memory.MemoryReader -import kscience.memory.MemorySpec -import kscience.memory.MemoryWriter import kotlin.math.* /** diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/MemoryBuffer.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/MemoryBuffer.kt index b7e6a8218..c171e7c1d 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/MemoryBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/MemoryBuffer.kt @@ -1,6 +1,6 @@ package kscience.kmath.structures -import kscience.memory.* +import kscience.kmath.memory.* /** * A non-boxing buffer over [Memory] object. diff --git a/kmath-memory/build.gradle.kts b/kmath-memory/build.gradle.kts index 94527a6a3..9f92cca92 100644 --- a/kmath-memory/build.gradle.kts +++ b/kmath-memory/build.gradle.kts @@ -1 +1,4 @@ -plugins { id("ru.mipt.npm.mpp") } +plugins { + id("ru.mipt.npm.mpp") + id("ru.mipt.npm.native") +} diff --git a/kmath-memory/src/commonMain/kotlin/scientifik/memory/Memory.kt b/kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/Memory.kt similarity index 99% rename from kmath-memory/src/commonMain/kotlin/scientifik/memory/Memory.kt rename to kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/Memory.kt index 8de9a7a0c..344a1f1d3 100644 --- a/kmath-memory/src/commonMain/kotlin/scientifik/memory/Memory.kt +++ b/kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/Memory.kt @@ -1,4 +1,4 @@ -package kscience.memory +package kscience.kmath.memory import kotlin.contracts.InvocationKind import kotlin.contracts.contract diff --git a/kmath-memory/src/commonMain/kotlin/scientifik/memory/MemorySpec.kt b/kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/MemorySpec.kt similarity index 98% rename from kmath-memory/src/commonMain/kotlin/scientifik/memory/MemorySpec.kt rename to kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/MemorySpec.kt index d2cbb32fd..572dab0fa 100644 --- a/kmath-memory/src/commonMain/kotlin/scientifik/memory/MemorySpec.kt +++ b/kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/MemorySpec.kt @@ -1,4 +1,4 @@ -package kscience.memory +package kscience.kmath.memory /** * A specification to read or write custom objects with fixed size in bytes. diff --git a/kmath-memory/src/jsMain/kotlin/scientifik/memory/DataViewMemory.kt b/kmath-memory/src/jsMain/kotlin/kscience/kmath/memory/DataViewMemory.kt similarity index 99% rename from kmath-memory/src/jsMain/kotlin/scientifik/memory/DataViewMemory.kt rename to kmath-memory/src/jsMain/kotlin/kscience/kmath/memory/DataViewMemory.kt index d6b8841e4..2146cd4e1 100644 --- a/kmath-memory/src/jsMain/kotlin/scientifik/memory/DataViewMemory.kt +++ b/kmath-memory/src/jsMain/kotlin/kscience/kmath/memory/DataViewMemory.kt @@ -1,4 +1,4 @@ -package kscience.memory +package kscience.kmath.memory import org.khronos.webgl.ArrayBuffer import org.khronos.webgl.DataView diff --git a/kmath-memory/src/jvmMain/kotlin/scientifik/memory/ByteBufferMemory.kt b/kmath-memory/src/jvmMain/kotlin/kscience/kmath/memory/ByteBufferMemory.kt similarity index 99% rename from kmath-memory/src/jvmMain/kotlin/scientifik/memory/ByteBufferMemory.kt rename to kmath-memory/src/jvmMain/kotlin/kscience/kmath/memory/ByteBufferMemory.kt index c912b28ff..7a75b423e 100644 --- a/kmath-memory/src/jvmMain/kotlin/scientifik/memory/ByteBufferMemory.kt +++ b/kmath-memory/src/jvmMain/kotlin/kscience/kmath/memory/ByteBufferMemory.kt @@ -1,4 +1,4 @@ -package kscience.memory +package kscience.kmath.memory import java.io.IOException import java.nio.ByteBuffer diff --git a/kmath-memory/src/nativeMain/kotlin/kscience/kmath/memory/NativeMemory.kt b/kmath-memory/src/nativeMain/kotlin/kscience/kmath/memory/NativeMemory.kt new file mode 100644 index 000000000..0e007a8ab --- /dev/null +++ b/kmath-memory/src/nativeMain/kotlin/kscience/kmath/memory/NativeMemory.kt @@ -0,0 +1,93 @@ +package kscience.kmath.memory + +@PublishedApi +internal class NativeMemory( + val array: ByteArray, + val startOffset: Int = 0, + override val size: Int = array.size +) : Memory { + @Suppress("NOTHING_TO_INLINE") + private inline fun position(o: Int): Int = startOffset + o + + override fun view(offset: Int, length: Int): Memory { + require(offset >= 0) { "offset shouldn't be negative: $offset" } + require(length >= 0) { "length shouldn't be negative: $length" } + require(offset + length <= size) { "Can't view memory outside the parent region." } + return NativeMemory(array, position(offset), length) + } + + override fun copy(): Memory { + val copy = array.copyOfRange(startOffset, startOffset + size) + return NativeMemory(copy) + } + + private val reader: MemoryReader = object : MemoryReader { + override val memory: Memory get() = this@NativeMemory + + override fun readDouble(offset: Int) = array.getDoubleAt(position(offset)) + + override fun readFloat(offset: Int) = array.getFloatAt(position(offset)) + + override fun readByte(offset: Int) = array[position(offset)] + + override fun readShort(offset: Int) = array.getShortAt(position(offset)) + + override fun readInt(offset: Int) = array.getIntAt(position(offset)) + + override fun readLong(offset: Int) = array.getLongAt(position(offset)) + + override fun release() { + // does nothing on JVM + } + } + + override fun reader(): MemoryReader = reader + + private val writer: MemoryWriter = object : MemoryWriter { + override val memory: Memory get() = this@NativeMemory + + override fun writeDouble(offset: Int, value: Double) { + array.setDoubleAt(position(offset), value) + } + + override fun writeFloat(offset: Int, value: Float) { + array.setFloatAt(position(offset), value) + } + + override fun writeByte(offset: Int, value: Byte) { + array.set(position(offset), value) + } + + override fun writeShort(offset: Int, value: Short) { + array.setShortAt(position(offset), value) + } + + override fun writeInt(offset: Int, value: Int) { + array.setIntAt(position(offset), value) + } + + override fun writeLong(offset: Int, value: Long) { + array.setLongAt(position(offset), value) + } + + override fun release() { + // does nothing on JVM + } + } + + override fun writer(): MemoryWriter = writer +} + +/** + * Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied + * and could be mutated independently from the resulting [Memory]. + */ +public actual fun Memory.Companion.wrap(array: ByteArray): Memory = NativeMemory(array) + +/** + * Allocates the most effective platform-specific memory. + */ +public actual fun Memory.Companion.allocate(length: Int): Memory { + val array = ByteArray(length) + return NativeMemory(array) +} \ No newline at end of file From 0a71c7196d596fc4bc6d0002a933083c5838da39 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 27 Sep 2020 11:43:03 +0300 Subject: [PATCH 09/12] Fix caches on native --- .../commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt | 2 ++ .../commonMain/kotlin/kscience/kmath/structures/NDStructure.kt | 2 ++ .../commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt index 28eaef2f1..03c601717 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt @@ -4,6 +4,7 @@ import kscience.kmath.operations.Complex import kscience.kmath.operations.Field import kscience.kmath.operations.Ring import kscience.kmath.operations.Space +import kotlin.native.concurrent.ThreadLocal /** * An exception is thrown when the expected ans actual shape of NDArray differs @@ -115,6 +116,7 @@ public interface NDField, N : NDStructure> : Field, NDRing public operator fun T.div(arg: N): N = map(arg) { divide(it, this@div) } + @ThreadLocal public companion object { private val realNDFieldCache: MutableMap = hashMapOf() diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt index 4ab49c9bc..fd679d073 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt @@ -1,6 +1,7 @@ package kscience.kmath.structures import kotlin.jvm.JvmName +import kotlin.native.concurrent.ThreadLocal import kotlin.reflect.KClass /** @@ -230,6 +231,7 @@ public class DefaultStrides private constructor(override val shape: IntArray) : override fun hashCode(): Int = shape.contentHashCode() + @ThreadLocal public companion object { private val defaultStridesCache = HashMap() diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt b/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt index f8b9b7262..456e41467 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt +++ b/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt @@ -2,6 +2,7 @@ package kscience.kmath.operations import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue internal class ComplexTest { @Test @@ -13,7 +14,7 @@ internal class ComplexTest { @Test fun reciprocal() { - assertEquals(Complex(0.5, -0.0), 2.toComplex().reciprocal) + assertTrue { (Complex(0.5, -0.0) - 2.toComplex().reciprocal).r < 1e-10} } @Test From 53ea704bae1c67536627b0b7967c56a5184518a7 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 27 Sep 2020 19:57:30 +0300 Subject: [PATCH 10/12] Finishing migration to 1.4.20-M1 --- build.gradle.kts | 3 ++- docs/templates/ARTIFACT-TEMPLATE.md | 3 +++ examples/build.gradle.kts | 11 +++++----- kmath-dimensions/build.gradle.kts | 5 ++++- .../kmath/dimensions/{dim.kt => dimJs.kt} | 0 .../kmath/dimensions/{dim.kt => dimJvm.kt} | 0 .../kscience/kmath/dimensions/dimNative.kt | 20 +++++++++++++++++++ settings.gradle.kts | 6 ++++-- 8 files changed, 38 insertions(+), 10 deletions(-) rename kmath-dimensions/src/jsMain/kotlin/kscience/kmath/dimensions/{dim.kt => dimJs.kt} (100%) rename kmath-dimensions/src/jvmMain/kotlin/kscience/kmath/dimensions/{dim.kt => dimJvm.kt} (100%) create mode 100644 kmath-dimensions/src/nativeMain/kotlin/kscience/kmath/dimensions/dimNative.kt diff --git a/build.gradle.kts b/build.gradle.kts index 87862ae8e..499f49d1d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,13 +2,14 @@ plugins { id("ru.mipt.npm.project") } -val kmathVersion by extra("0.2.0-dev-1") +val kmathVersion by extra("0.2.0-dev-2") val bintrayRepo by extra("kscience") val githubProject by extra("kmath") allprojects { repositories { jcenter() + maven("https://dl.bintray.com/kotlin/kotlin-eap") maven("https://dl.bintray.com/kotlin/kotlinx") maven("https://dl.bintray.com/hotkeytlt/maven") } diff --git a/docs/templates/ARTIFACT-TEMPLATE.md b/docs/templates/ARTIFACT-TEMPLATE.md index cbdd98218..c77948d4b 100644 --- a/docs/templates/ARTIFACT-TEMPLATE.md +++ b/docs/templates/ARTIFACT-TEMPLATE.md @@ -10,9 +10,11 @@ > > ```gradle > repositories { +> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } > maven { url 'https://dl.bintray.com/mipt-npm/kscience' } > maven { url 'https://dl.bintray.com/mipt-npm/dev' } > maven { url 'https://dl.bintray.com/hotkeytlt/maven' } + > } > > dependencies { @@ -23,6 +25,7 @@ > > ```kotlin > repositories { +> maven("https://dl.bintray.com/kotlin/kotlin-eap") > maven("https://dl.bintray.com/mipt-npm/kscience") > maven("https://dl.bintray.com/mipt-npm/dev") > maven("https://dl.bintray.com/hotkeytlt/maven") diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 3d193efce..3f18d3cf3 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -3,8 +3,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { java kotlin("jvm") - kotlin("plugin.allopen") version "1.4.20-dev-3898-14" - id("kotlinx.benchmark") version "0.2.0-dev-20" + kotlin("plugin.allopen") + id("kotlinx.benchmark") } allOpen.annotation("org.openjdk.jmh.annotations.State") @@ -26,7 +26,7 @@ dependencies { implementation(project(":kmath-prob")) implementation(project(":kmath-viktor")) implementation(project(":kmath-dimensions")) - implementation("org.jetbrains.kotlinx:kotlinx-io-jvm:0.2.0-npm-dev-6") + implementation("org.jetbrains.kotlinx:kotlinx-io:0.2.0-npm-dev-11") implementation("org.jetbrains.kotlinx:kotlinx.benchmark.runtime:0.2.0-dev-20") "benchmarksCompile"(sourceSets.main.get().output + sourceSets.main.get().compileClasspath) //sourceSets.main.output + sourceSets.main.runtimeClasspath } @@ -34,9 +34,8 @@ dependencies { // Configure benchmark benchmark { // Setup configurations - targets - // This one matches sourceSet name above - .register("benchmarks") + targets.register("benchmarks") + // This one matches sourceSet name above configurations.register("fast") { warmups = 5 // number of warmup iterations diff --git a/kmath-dimensions/build.gradle.kts b/kmath-dimensions/build.gradle.kts index 0a36e4435..412d7162f 100644 --- a/kmath-dimensions/build.gradle.kts +++ b/kmath-dimensions/build.gradle.kts @@ -1,4 +1,7 @@ -plugins { id("ru.mipt.npm.mpp") } +plugins { + id("ru.mipt.npm.mpp") + id("ru.mipt.npm.native") +} description = "A proof of concept module for adding type-safe dimensions to structures" diff --git a/kmath-dimensions/src/jsMain/kotlin/kscience/kmath/dimensions/dim.kt b/kmath-dimensions/src/jsMain/kotlin/kscience/kmath/dimensions/dimJs.kt similarity index 100% rename from kmath-dimensions/src/jsMain/kotlin/kscience/kmath/dimensions/dim.kt rename to kmath-dimensions/src/jsMain/kotlin/kscience/kmath/dimensions/dimJs.kt diff --git a/kmath-dimensions/src/jvmMain/kotlin/kscience/kmath/dimensions/dim.kt b/kmath-dimensions/src/jvmMain/kotlin/kscience/kmath/dimensions/dimJvm.kt similarity index 100% rename from kmath-dimensions/src/jvmMain/kotlin/kscience/kmath/dimensions/dim.kt rename to kmath-dimensions/src/jvmMain/kotlin/kscience/kmath/dimensions/dimJvm.kt diff --git a/kmath-dimensions/src/nativeMain/kotlin/kscience/kmath/dimensions/dimNative.kt b/kmath-dimensions/src/nativeMain/kotlin/kscience/kmath/dimensions/dimNative.kt new file mode 100644 index 000000000..aeaeaf759 --- /dev/null +++ b/kmath-dimensions/src/nativeMain/kotlin/kscience/kmath/dimensions/dimNative.kt @@ -0,0 +1,20 @@ +package kscience.kmath.dimensions + +import kotlin.native.concurrent.ThreadLocal +import kotlin.reflect.KClass + +@ThreadLocal +private val dimensionMap: MutableMap = hashMapOf(1u to D1, 2u to D2, 3u to D3) + +@Suppress("UNCHECKED_CAST") +public actual fun Dimension.Companion.resolve(type: KClass): D = dimensionMap + .entries + .map(MutableMap.MutableEntry::value) + .find { it::class == type } as? D + ?: error("Can't resolve dimension $type") + +public actual fun Dimension.Companion.of(dim: UInt): Dimension = dimensionMap.getOrPut(dim) { + object : Dimension { + override val dim: UInt get() = dim + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index ad9014e56..844fa0d6c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,7 +10,8 @@ pluginManagement { maven("https://dl.bintray.com/kotlin/kotlin-dev/") } - val toolsVersion = "0.6.1" + val toolsVersion = "0.6.1-dev-1.4.20-M1" + val kotlinVersion = "1.4.20-M1" plugins { id("kotlinx.benchmark") version "0.2.0-dev-20" @@ -18,7 +19,8 @@ pluginManagement { id("ru.mipt.npm.mpp") version toolsVersion id("ru.mipt.npm.jvm") version toolsVersion id("ru.mipt.npm.publish") version toolsVersion - kotlin("plugin.allopen") + kotlin("jvm") version kotlinVersion + kotlin("plugin.allopen") version kotlinVersion } } From 1f6834d4188a31c13aa0f5d812f08cca880b9dd6 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 27 Sep 2020 20:05:31 +0300 Subject: [PATCH 11/12] Update readme --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09c6274df..496d961d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Gradle version: 6.6 -> 6.6.1 - Minor exceptions refactor (throwing `IllegalArgumentException` by argument checks instead of `IllegalStateException`) - `Polynomial` secondary constructor made function. +- Kotlin version: 1.3.72 -> 1.4.20-M1 ### Deprecated From 431b574544b231a59d256b6d4fba037cb8a547c9 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 27 Sep 2020 20:09:46 +0300 Subject: [PATCH 12/12] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 496d961d8..f3fe37b6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Explicit `public` visibility for all public APIs - Better trigonometric and hyperbolic functions for `AutoDiffField` (https://github.com/mipt-npm/kmath/pull/140). - Automatic README generation for features (#139) +- Native support for `memory`, `core` and `dimensions` ### Changed - Package changed from `scientifik` to `kscience.kmath`. @@ -18,6 +19,7 @@ ### Removed - `kmath-koma` module because it doesn't support Kotlin 1.4. +- Support of `legacy` JS backend (we will support only IR) ### Fixed - `symbol` method in `MstExtendedField` (https://github.com/mipt-npm/kmath/pull/140)