diff --git a/.github/workflows/gradle.yml b/.github/workflows/build.yml similarity index 91% rename from .github/workflows/gradle.yml rename to .github/workflows/build.yml index 467a867bc..626062abf 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 + - name: Grant execute permission for gradlew + run: chmod +x gradlew - name: Install Chrome run: | sudo apt install -y libappindicator1 fonts-liberation @@ -47,6 +49,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 + - name: Grant execute permission for gradlew + run: chmod +x gradlew - name: Cache gradle uses: actions/cache@v2 with: @@ -77,6 +81,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 + - name: Grant execute permission for gradlew + run: chmod +x gradlew - name: Add msys to path run: SETX PATH "%PATH%;C:\msys64\mingw64\bin" - name: Cache gradle diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 0d472b1b9..000000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Bintray Publish - -on: - release: - types: - - created - -jobs: - build-on-windows: - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Gradle clean - run: ./gradlew clean - - name: Gradle build - run: ./gradlew build - - name: Run release task - run: ./gradlew release -PbintrayUser=${{ secrets.BINTRAY_USER }} -PbintrayApiKey=${{ secrets.BINTRAY_KEY }} - build-on-macos: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Gradle clean - run: ./gradlew clean - - name: Gradle build - run: ./gradlew build - - name: Run release task - run: ./gradlew release -PbintrayUser=${{ secrets.BINTRAY_USER }} -PbintrayApiKey=${{ secrets.BINTRAY_KEY }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..743520885 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,117 @@ +name: Gradle release + +on: + release: + types: + - created + +jobs: + build-ubuntu: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Install Chrome + run: | + sudo apt install -y libappindicator1 fonts-liberation + wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb + sudo dpkg -i google-chrome*.deb + - name: Cache gradle + uses: actions/cache@v2 + with: + path: | + .gradle + build + ~/.gradle + key: gradle + restore-keys: gradle + + - name: Cache konan + uses: actions/cache@v2 + with: + path: | + ~/.konan/dependencies + ~/.konan/kotlin-native-prebuilt-linux-* + key: ${{ runner.os }}-konan + restore-keys: ${{ runner.os }}-konan + - name: Build with Gradle + run: ./gradlew -Dorg.gradle.daemon=false --build-cache build + - name: Run release task + run: ./gradlew release -PbintrayUser=${{ secrets.BINTRAY_USER }} -PbintrayApiKey=${{ secrets.BINTRAY_KEY }} + + build-osx: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Cache gradle + uses: actions/cache@v2 + with: + path: | + .gradle + build + ~/.gradle + key: gradle + restore-keys: gradle + + - name: Cache konan + uses: actions/cache@v2 + with: + path: | + ~/.konan/dependencies + ~/.konan/kotlin-native-prebuilt-macos-* + key: ${{ runner.os }}-konan + restore-keys: ${{ runner.os }}-konan + - name: Build with Gradle + run: sudo ./gradlew -Dorg.gradle.daemon=false --build-cache build + - name: Run release task + run: ./gradlew release -PbintrayUser=${{ secrets.BINTRAY_USER }} -PbintrayApiKey=${{ secrets.BINTRAY_KEY }} + + build-windows: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Add msys to path + run: SETX PATH "%PATH%;C:\msys64\mingw64\bin" + - name: Cache gradle + uses: actions/cache@v2 + with: + path: | + .gradle + build + ~/.gradle + key: ${{ runner.os }}-gradle + restore-keys: ${{ runner.os }}-gradle + + - name: Cache konan + uses: actions/cache@v2 + with: + path: | + ~/.konan/dependencies + ~/.konan/kotlin-native-prebuilt-mingw-* + key: ${{ runner.os }}-konan + restore-keys: ${{ runner.os }}-konan + - name: Build with Gradle + run: ./gradlew --build-cache build + - name: Run release task + run: ./gradlew release -PbintrayUser=${{ secrets.BINTRAY_USER }} -PbintrayApiKey=${{ secrets.BINTRAY_KEY }} + diff --git a/CHANGELOG.md b/CHANGELOG.md index aa70e6116..c7033df7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ ## [Unreleased] ### Added + +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## [0.2.0] +### Added - `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) @@ -18,13 +31,14 @@ - Some minor utilities to `kmath-for-real` - Generic operation result parameter to `MatrixContext` - New `MatrixFeature` interfaces for matrix decompositions +- Basic Quaternion vector support in `kmath-complex`. ### Changed -- Package changed from `scientifik` to `kscience.kmath` -- Gradle version: 6.6 -> 6.8 +- Package changed from `scientifik` to `space.kscience` +- Gradle version: 6.6 -> 6.8.2 - Minor exceptions refactor (throwing `IllegalArgumentException` by argument checks instead of `IllegalStateException`) - `Polynomial` secondary constructor made function -- Kotlin version: 1.3.72 -> 1.4.21 +- Kotlin version: 1.3.72 -> 1.4.30 - `kmath-ast` doesn't depend on heavy `kotlin-reflect` library - Full autodiff refactoring based on `Symbol` - `kmath-prob` renamed to `kmath-stat` @@ -32,9 +46,16 @@ - Use `Point` instead of specialized type in `kmath-for-real` - Optimized dot product for buffer matrices moved to `kmath-for-real` - EjmlMatrix context is an object -- Matrix LUP `inverse` renamed to `inverseWithLUP` +- Matrix LUP `inverse` renamed to `inverseWithLup` - `NumericAlgebra` moved outside of regular algebra chain (`Ring` no longer implements it). - Features moved to NDStructure and became transparent. +- Capitalization of LUP in many names changed to Lup. +- Refactored `NDStructure` algebra to be more simple, preferring under-the-hood conversion to explicit NDStructure types +- Refactor histograms. They are marked as prototype +- `Complex` and related features moved to a separate module `kmath-complex` +- Refactor AlgebraElement +- `symbol` method in `Algebra` renamed to `bindSymbol` to avoid ambiguity +- Add `out` projection to `Buffer` generic ### Deprecated @@ -43,6 +64,7 @@ - Support of `legacy` JS backend (we will support only IR) - `toGrid` method. - Public visibility of `BufferAccessor2D` +- `Real` class ### Fixed - `symbol` method in `MstExtendedField` (https://github.com/mipt-npm/kmath/pull/140) diff --git a/README.md b/README.md index 7d2a46c92..7b8e11109 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Bintray-dev: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmat # KMath -Could be pronounced as `key-math`. The Kotlin MATHematics library was initially intended as a Kotlin-based analog to +Could be pronounced as `key-math`. The **K**otlin **Math**ematics 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. @@ -32,49 +32,46 @@ be achieved with [kmath-for-real](/kmath-for-real) extension module. * Provide the 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 +for `Double` in the core. For that we will have specialization modules like `kmath-for-real`, which will give better experience for those, who want to work with specific types. -## Features +## Features and stability -Current feature list is [here](/docs/features.md) +KMath is a modular library. Different modules provide different features with different API stability guarantees. All core modules are released with the same version, but with different API change policy. The features are described in module definitions below. The module stability could have following levels: -* **Algebra** - * Algebraic structures like rings, spaces and fields (**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 they will be usable in any structure like vectors and - N-dimensional arrays). - * Advanced linear algebra operations like matrix inversion and LU decomposition. +* **PROTOTYPE**. On this level there are no compatibility guarantees. All methods and classes form those modules could break any moment. You can still use it, but be sure to fix the specific version. +* **EXPERIMENTAL**. The general API is decided, but some changes could be made. Volatile API is marked with `@UnstableKmathAPI` or other stability warning annotations. +* **DEVELOPMENT**. API breaking genrally follows semantic versioning ideology. There could be changes in minor versions, but not in patch versions. API is protected with [binary-compatibility-validator](https://github.com/Kotlin/binary-compatibility-validator) tool. +* **STABLE**. The API stabilized. Breaking changes are allowed only in major releases. -* **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 established roadmap for that. Feel free to -submit a feature request if you want something to be implemented 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 @@ -107,16 +104,30 @@ submit a feature request if you want something to be implemented first. > **Maturity**: EXPERIMENTAL
+* ### [kmath-complex](kmath-complex) +> Complex numbers and quaternions. +> +> **Maturity**: PROTOTYPE +> +> **Features:** +> - [complex](kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/Complex.kt) : Complex Numbers +> - [quaternion](kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/Quaternion.kt) : Quaternions + +
+ * ### [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 +> - [algebras](kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Algebraic structures like rings, spaces and fields. +> - [nd](kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Many-dimensional structures and operations on them. +> - [linear](kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Basic linear algebra operations (sums, products, etc.), backed by the `Space` API. Advanced linear algebra operations like matrix inversion and LU decomposition. > - [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 +> - [expressions](kmath-core/src/commonMain/kotlin/kscience/kmath/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. > - [domains](kmath-core/src/commonMain/kotlin/kscience/kmath/domains) : Domains > - [autodif](kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/SimpleAutoDiff.kt) : Automatic differentiation @@ -137,7 +148,7 @@ submit a feature request if you want something to be implemented first. * ### [kmath-ejml](kmath-ejml) > > -> **Maturity**: EXPERIMENTAL +> **Maturity**: PROTOTYPE
* ### [kmath-for-real](kmath-for-real) @@ -155,33 +166,40 @@ One can still use generic algebras though.
* ### [kmath-functions](kmath-functions) -> +> Functions and interpolation > -> **Maturity**: EXPERIMENTAL +> **Maturity**: PROTOTYPE +> +> **Features:** +> - [piecewise](kmath-functions/Piecewise functions.) : src/commonMain/kotlin/kscience/kmath/functions/Piecewise.kt +> - [polynomials](kmath-functions/Polynomial functions.) : src/commonMain/kotlin/kscience/kmath/functions/Polynomial.kt +> - [linear interpolation](kmath-functions/Linear XY interpolator.) : src/commonMain/kotlin/kscience/kmath/interpolation/LinearInterpolator.kt +> - [spline interpolation](kmath-functions/Cubic spline XY interpolator.) : src/commonMain/kotlin/kscience/kmath/interpolation/SplineInterpolator.kt +
* ### [kmath-geometry](kmath-geometry) > > -> **Maturity**: EXPERIMENTAL +> **Maturity**: PROTOTYPE
* ### [kmath-histograms](kmath-histograms) > > -> **Maturity**: EXPERIMENTAL +> **Maturity**: PROTOTYPE
* ### [kmath-kotlingrad](kmath-kotlingrad) > > -> **Maturity**: EXPERIMENTAL +> **Maturity**: PROTOTYPE
* ### [kmath-memory](kmath-memory) -> +> An API and basic implementation for arranging objects in a continous memory block. > -> **Maturity**: EXPERIMENTAL +> **Maturity**: DEVELOPMENT
* ### [kmath-nd4j](kmath-nd4j) @@ -205,7 +223,7 @@ One can still use generic algebras though. * ### [kmath-viktor](kmath-viktor) > > -> **Maturity**: EXPERIMENTAL +> **Maturity**: DEVELOPMENT
@@ -239,8 +257,8 @@ repositories { } dependencies { - api("kscience.kmath:kmath-core:0.2.0-dev-5") - // api("kscience.kmath:kmath-core-jvm:0.2.0-dev-5") for jvm-specific version + api("kscience.kmath:kmath-core:0.2.0") + // api("kscience.kmath:kmath-core-jvm:0.2.0") for jvm-specific version } ``` diff --git a/build.gradle.kts b/build.gradle.kts index d171bd608..83123765d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,7 @@ -import ru.mipt.npm.gradle.KSciencePublishPlugin - plugins { - id("ru.mipt.npm.project") + id("ru.mipt.npm.gradle.project") } -internal val kmathVersion: String by extra("0.2.0-dev-5") -internal val bintrayRepo: String by extra("kscience") -internal val githubProject: String by extra("kmath") - allprojects { repositories { jcenter() @@ -23,22 +17,24 @@ allprojects { mavenCentral() } - group = "kscience.kmath" - version = kmathVersion + group = "space.kscience" + version = "0.2.0" } subprojects { - if (name.startsWith("kmath")) apply() + if (name.startsWith("kmath")) apply() } readme { readmeTemplate = file("docs/templates/README-TEMPLATE.md") } -apiValidation { - validationDisabled = true -} - ksciencePublish { spaceRepo = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven" + bintrayRepo = "kscience" + githubProject = "kmath" } + +apiValidation{ + nonPublicMarkers.add("space.kscience.kmath.misc.UnstableKMathAPI") +} \ No newline at end of file diff --git a/docs/algebra.md b/docs/algebra.md index c3227517f..6bfcde043 100644 --- a/docs/algebra.md +++ b/docs/algebra.md @@ -5,7 +5,7 @@ operation, say `+`, one needs two objects of a type `T` and an algebra context, say `Space`. Next one needs to run the actual operation in the context: ```kotlin -import kscience.kmath.operations.* +import space.kscience.kmath.operations.* val a: T = ... val b: T = ... @@ -47,7 +47,7 @@ but it also holds reference to the `ComplexField` singleton, which allows perfor numbers without explicit involving the context like: ```kotlin -import kscience.kmath.operations.* +import space.kscience.kmath.operations.* // Using elements val c1 = Complex(1.0, 1.0) @@ -82,7 +82,7 @@ operations in all performance-critical places. The performance of element operat KMath submits both contexts and elements for builtin algebraic structures: ```kotlin -import kscience.kmath.operations.* +import space.kscience.kmath.operations.* val c1 = Complex(1.0, 2.0) val c2 = ComplexField.i @@ -95,7 +95,7 @@ val c3 = ComplexField { c1 + c2 } Also, `ComplexField` features special operations to mix complex and real numbers, for example: ```kotlin -import kscience.kmath.operations.* +import space.kscience.kmath.operations.* val c1 = Complex(1.0, 2.0) val c2 = ComplexField { c1 - 1.0 } // Returns: Complex(re=0.0, im=2.0) diff --git a/docs/templates/ARTIFACT-TEMPLATE.md b/docs/templates/ARTIFACT-TEMPLATE.md index d46a431bd..8ac71193f 100644 --- a/docs/templates/ARTIFACT-TEMPLATE.md +++ b/docs/templates/ARTIFACT-TEMPLATE.md @@ -10,11 +10,12 @@ > > ```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://repo.kotlin.link' } > maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> +> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } // include for builds based on kotlin-eap +>// Uncomment if repo.kotlin.link is unavailable +>// maven { url 'https://dl.bintray.com/mipt-npm/kscience' } +>// maven { url 'https://dl.bintray.com/mipt-npm/dev' } > } > > dependencies { @@ -25,10 +26,12 @@ > > ```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") +> maven("https://repo.kotlin.link") +> maven("https://dl.bintray.com/kotlin/kotlin-eap") // include for builds based on kotlin-eap +> maven("https://dl.bintray.com/hotkeytlt/maven") // required for a +>// Uncomment if repo.kotlin.link is unavailable +>// maven("https://dl.bintray.com/mipt-npm/kscience") +>// maven("https://dl.bintray.com/mipt-npm/dev") > } > > dependencies { diff --git a/docs/templates/README-TEMPLATE.md b/docs/templates/README-TEMPLATE.md index 82b0c0514..ec65c2db0 100644 --- a/docs/templates/README-TEMPLATE.md +++ b/docs/templates/README-TEMPLATE.md @@ -9,7 +9,7 @@ Bintray-dev: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmat # KMath -Could be pronounced as `key-math`. The Kotlin MATHematics library was initially intended as a Kotlin-based analog to +Could be pronounced as `key-math`. The **K**otlin **Math**ematics 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. @@ -32,49 +32,46 @@ be achieved with [kmath-for-real](/kmath-for-real) extension module. * Provide the 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 +for `Double` in the core. For that we will have specialization modules like `kmath-for-real`, which will give better experience for those, who want to work with specific types. -## Features +## Features and stability -Current feature list is [here](/docs/features.md) +KMath is a modular library. Different modules provide different features with different API stability guarantees. All core modules are released with the same version, but with different API change policy. The features are described in module definitions below. The module stability could have following levels: -* **Algebra** - * Algebraic structures like rings, spaces and fields (**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 they will be usable in any structure like vectors and - N-dimensional arrays). - * Advanced linear algebra operations like matrix inversion and LU decomposition. +* **PROTOTYPE**. On this level there are no compatibility guarantees. All methods and classes form those modules could break any moment. You can still use it, but be sure to fix the specific version. +* **EXPERIMENTAL**. The general API is decided, but some changes could be made. Volatile API is marked with `@UnstableKmathAPI` or other stability warning annotations. +* **DEVELOPMENT**. API breaking genrally follows semantic versioning ideology. There could be changes in minor versions, but not in patch versions. API is protected with [binary-compatibility-validator](https://github.com/Kotlin/binary-compatibility-validator) tool. +* **STABLE**. The API stabilized. Breaking changes are allowed only in major releases. -* **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 established roadmap for that. Feel free to -submit a feature request if you want something to be implemented 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 diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index c079eaa84..77152dc0a 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -1,7 +1,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - java kotlin("jvm") kotlin("plugin.allopen") id("kotlinx.benchmark") @@ -12,6 +11,7 @@ sourceSets.register("benchmarks") repositories { jcenter() + maven("https://repo.kotlin.link") maven("https://clojars.org/repo") maven("https://dl.bintray.com/egor-bogomolov/astminer/") maven("https://dl.bintray.com/hotkeytlt/maven") @@ -30,6 +30,7 @@ dependencies { implementation(project(":kmath-core")) implementation(project(":kmath-coroutines")) implementation(project(":kmath-commons")) + implementation(project(":kmath-complex")) implementation(project(":kmath-stat")) implementation(project(":kmath-viktor")) implementation(project(":kmath-dimensions")) @@ -68,11 +69,28 @@ benchmark { targets.register("benchmarks") // This one matches sourceSet name above - configurations.register("fast") { + configurations.register("buffer") { warmups = 1 // number of warmup iterations iterations = 3 // number of iterations iterationTime = 500 // time in seconds per iteration iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds + include("BufferBenchmark") + } + + configurations.register("dot") { + warmups = 1 // number of warmup iterations + iterations = 3 // number of iterations + iterationTime = 500 // time in seconds per iteration + iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds + include("DotBenchmark") + } + + configurations.register("expressions") { + warmups = 1 // number of warmup iterations + iterations = 3 // number of iterations + iterationTime = 500 // time in seconds per iteration + iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds + include("ExpressionsInterpretersBenchmark") } } @@ -86,3 +104,7 @@ kotlin.sourceSets.all { tasks.withType { kotlinOptions.jvmTarget = "11" } + +readme{ + maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL +} diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ArrayBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ArrayBenchmark.kt deleted file mode 100644 index ebf31a590..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ArrayBenchmark.kt +++ /dev/null @@ -1,34 +0,0 @@ -package kscience.kmath.benchmarks - -import org.openjdk.jmh.annotations.Benchmark -import org.openjdk.jmh.annotations.Scope -import org.openjdk.jmh.annotations.State -import java.nio.IntBuffer - -@State(Scope.Benchmark) -internal class ArrayBenchmark { - @Benchmark - fun benchmarkArrayRead() { - var res = 0 - for (i in 1..size) res += array[size - i] - } - - @Benchmark - fun benchmarkBufferRead() { - var res = 0 - for (i in 1..size) res += arrayBuffer[size - i] - } - - @Benchmark - fun nativeBufferRead() { - var res = 0 - for (i in 1..size) res += nativeBuffer[size - i] - } - - companion object { - const val size: Int = 1000 - val array: IntArray = IntArray(size) { it } - val arrayBuffer: IntBuffer = IntBuffer.wrap(array) - val nativeBuffer: IntBuffer = IntBuffer.allocate(size).also { for (i in 0 until size) it.put(i, i) } - } -} diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/NDFieldBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/NDFieldBenchmark.kt deleted file mode 100644 index 1be8e7236..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/NDFieldBenchmark.kt +++ /dev/null @@ -1,50 +0,0 @@ -package kscience.kmath.benchmarks - -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke -import kscience.kmath.structures.* -import org.openjdk.jmh.annotations.Benchmark -import org.openjdk.jmh.annotations.Scope -import org.openjdk.jmh.annotations.State - -@State(Scope.Benchmark) -internal class NDFieldBenchmark { - @Benchmark - fun autoFieldAdd() { - bufferedField { - var res: NDBuffer = one - repeat(n) { res += one } - } - } - - @Benchmark - fun autoElementAdd() { - var res = genericField.one - repeat(n) { res += 1.0 } - } - - @Benchmark - fun specializedFieldAdd() { - specializedField { - var res: NDBuffer = one - repeat(n) { res += 1.0 } - } - } - - - @Benchmark - fun boxingFieldAdd() { - genericField { - var res: NDBuffer = one - repeat(n) { res += one } - } - } - - companion object { - const val dim: Int = 1000 - const val n: Int = 100 - val bufferedField: BufferedNDField = NDField.auto(RealField, dim, dim) - val specializedField: RealNDField = NDField.real(dim, dim) - val genericField: BoxingNDField = NDField.boxing(RealField, dim, dim) - } -} \ No newline at end of file diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt deleted file mode 100644 index 8663e353c..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt +++ /dev/null @@ -1,64 +0,0 @@ -package kscience.kmath.benchmarks - -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke -import kscience.kmath.structures.BufferedNDField -import kscience.kmath.structures.NDField -import kscience.kmath.structures.RealNDField -import kscience.kmath.viktor.ViktorNDField -import org.jetbrains.bio.viktor.F64Array -import org.openjdk.jmh.annotations.Benchmark -import org.openjdk.jmh.annotations.Scope -import org.openjdk.jmh.annotations.State - -@State(Scope.Benchmark) -internal class ViktorBenchmark { - final val dim: Int = 1000 - final val n: Int = 100 - - // automatically build context most suited for given type. - final val autoField: BufferedNDField = NDField.auto(RealField, dim, dim) - final val realField: RealNDField = NDField.real(dim, dim) - final val viktorField: ViktorNDField = ViktorNDField(intArrayOf(dim, dim)) - - @Benchmark - fun automaticFieldAddition() { - autoField { - var res = one - repeat(n) { res += one } - } - } - - @Benchmark - fun viktorFieldAddition() { - viktorField { - var res = one - repeat(n) { res += one } - } - } - - @Benchmark - fun rawViktor() { - val one = F64Array.full(init = 1.0, shape = intArrayOf(dim, dim)) - var res = one - repeat(n) { res = res + one } - } - - @Benchmark - fun realFieldLog() { - realField { - val fortyTwo = produce { 42.0 } - var res = one - repeat(n) { res = ln(fortyTwo) } - } - } - - @Benchmark - fun rawViktorLog() { - val fortyTwo = F64Array.full(dim, dim, init = 42.0) - var res: F64Array - repeat(n) { - res = fortyTwo.log() - } - } -} \ No newline at end of file diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt new file mode 100644 index 000000000..535778844 --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt @@ -0,0 +1,34 @@ +package space.kscience.kmath.benchmarks + +import org.openjdk.jmh.annotations.Benchmark +import org.openjdk.jmh.annotations.Scope +import org.openjdk.jmh.annotations.State +import java.nio.IntBuffer + +@State(Scope.Benchmark) +internal class ArrayBenchmark { + @Benchmark + fun benchmarkArrayRead() { + var res = 0 + for (i in 1..space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) res += space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.array[space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size - i] + } + + @Benchmark + fun benchmarkBufferRead() { + var res = 0 + for (i in 1..space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) res += space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.arrayBuffer[space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size - i] + } + + @Benchmark + fun nativeBufferRead() { + var res = 0 + for (i in 1..space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) res += space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.nativeBuffer[space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size - i] + } + + companion object { + const val size: Int = 1000 + val array: IntArray = IntArray(space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) { it } + val arrayBuffer: IntBuffer = IntBuffer.wrap(space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.array) + val nativeBuffer: IntBuffer = IntBuffer.allocate(space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size).also { for (i in 0 until space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) it.put(i, i) } + } +} diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/BufferBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt similarity index 73% rename from examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/BufferBenchmark.kt rename to examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt index 4c64517f1..1afb4e52c 100644 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/BufferBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt @@ -1,12 +1,12 @@ -package kscience.kmath.benchmarks +package space.kscience.kmath.benchmarks -import kscience.kmath.operations.Complex -import kscience.kmath.operations.complex -import kscience.kmath.structures.MutableBuffer -import kscience.kmath.structures.RealBuffer import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.State +import space.kscience.kmath.complex.Complex +import space.kscience.kmath.complex.complex +import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.RealBuffer @State(Scope.Benchmark) internal class BufferBenchmark { @@ -31,4 +31,4 @@ internal class BufferBenchmark { companion object { const val size: Int = 100 } -} \ No newline at end of file +} diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/DotBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt similarity index 61% rename from examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/DotBenchmark.kt rename to examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt index 5c59afaee..39eeb24d3 100644 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/DotBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt @@ -1,22 +1,20 @@ -package kscience.kmath.benchmarks +package space.kscience.kmath.benchmarks import kotlinx.benchmark.Benchmark -import kscience.kmath.commons.linear.CMMatrixContext -import kscience.kmath.ejml.EjmlMatrixContext - -import kscience.kmath.linear.BufferMatrixContext -import kscience.kmath.linear.RealMatrixContext -import kscience.kmath.linear.real -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.Matrix import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.State +import space.kscience.kmath.commons.linear.CMMatrixContext +import space.kscience.kmath.ejml.EjmlMatrixContext +import space.kscience.kmath.linear.BufferMatrixContext +import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.linear.RealMatrixContext +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.Buffer import kotlin.random.Random @State(Scope.Benchmark) -class DotBenchmark { +internal class DotBenchmark { companion object { val random = Random(12224) val dim = 1000 @@ -33,40 +31,37 @@ class DotBenchmark { } @Benchmark - fun commonsMathMultiplication() { + fun cmDot() { CMMatrixContext { cmMatrix1 dot cmMatrix2 } } @Benchmark - fun ejmlMultiplication() { + fun ejmlDot() { EjmlMatrixContext { ejmlMatrix1 dot ejmlMatrix2 } } @Benchmark - fun ejmlMultiplicationwithConversion() { + fun ejmlDotWithConversion() { EjmlMatrixContext { - val ejmlMatrix1 = matrix1.toEjml() - val ejmlMatrix2 = matrix2.toEjml() - - ejmlMatrix1 dot ejmlMatrix2 + matrix1 dot matrix2 } } @Benchmark - fun bufferedMultiplication() { + fun bufferedDot() { BufferMatrixContext(RealField, Buffer.Companion::real).invoke { matrix1 dot matrix2 } } @Benchmark - fun realMultiplication() { + fun realDot() { RealMatrixContext { matrix1 dot matrix2 } } -} \ No newline at end of file +} diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/ast/ExpressionsInterpretersBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt similarity index 50% rename from examples/src/benchmarks/kotlin/kscience/kmath/ast/ExpressionsInterpretersBenchmark.kt rename to examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt index c5edcdedf..a9c0fe703 100644 --- a/examples/src/benchmarks/kotlin/kscience/kmath/ast/ExpressionsInterpretersBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt @@ -1,25 +1,29 @@ -package kscience.kmath.ast +package space.kscience.kmath.benchmarks -import kscience.kmath.asm.compile -import kscience.kmath.expressions.Expression -import kscience.kmath.expressions.expressionInField -import kscience.kmath.expressions.invoke -import kscience.kmath.expressions.symbol -import kscience.kmath.operations.Field -import kscience.kmath.operations.RealField import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.State +import space.kscience.kmath.asm.compile +import space.kscience.kmath.ast.mstInField +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.expressionInField +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.expressions.symbol +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.bindSymbol import kotlin.random.Random @State(Scope.Benchmark) internal class ExpressionsInterpretersBenchmark { private val algebra: Field = RealField + val x by symbol @Benchmark fun functionalExpression() { val expr = algebra.expressionInField { - symbol("x") * const(2.0) + const(2.0) / symbol("x") - const(16.0) + val x = bindSymbol(x) + x * const(2.0) + const(2.0) / x - const(16.0) } invokeAndSum(expr) @@ -28,7 +32,8 @@ internal class ExpressionsInterpretersBenchmark { @Benchmark fun mstExpression() { val expr = algebra.mstInField { - symbol("x") * 2.0 + 2.0 / symbol("x") - 16.0 + val x = bindSymbol(x) + x * 2.0 + 2.0 / x - 16.0 } invokeAndSum(expr) @@ -37,7 +42,8 @@ internal class ExpressionsInterpretersBenchmark { @Benchmark fun asmExpression() { val expr = algebra.mstInField { - symbol("x") * 2.0 + 2.0 / symbol("x") - 16.0 + val x = bindSymbol(x) + x * 2.0 + 2.0 / x - 16.0 }.compile() invokeAndSum(expr) @@ -45,8 +51,10 @@ internal class ExpressionsInterpretersBenchmark { @Benchmark fun rawExpression() { - val x by symbol - val expr = Expression { args -> args.getValue(x) * 2.0 + 2.0 / args.getValue(x) - 16.0 } + val expr = Expression { args -> + val x = args.getValue(x) + x * 2.0 + 2.0 / x - 16.0 + } invokeAndSum(expr) } @@ -55,7 +63,7 @@ internal class ExpressionsInterpretersBenchmark { var sum = 0.0 repeat(1000000) { - sum += expr("x" to random.nextDouble()) + sum += expr(x to random.nextDouble()) } println(sum) diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt similarity index 50% rename from examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt rename to examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt index 5ff43ef80..22e735e12 100644 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt @@ -1,20 +1,21 @@ -package kscience.kmath.linear - +package space.kscience.kmath.benchmarks import kotlinx.benchmark.Benchmark -import kscience.kmath.commons.linear.CMMatrixContext -import kscience.kmath.commons.linear.CMMatrixContext.dot -import kscience.kmath.commons.linear.inverse -import kscience.kmath.ejml.EjmlMatrixContext -import kscience.kmath.ejml.inverse -import kscience.kmath.operations.invoke -import kscience.kmath.structures.Matrix import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.State +import space.kscience.kmath.commons.linear.CMMatrixContext +import space.kscience.kmath.commons.linear.CMMatrixContext.dot +import space.kscience.kmath.commons.linear.inverse +import space.kscience.kmath.ejml.EjmlMatrixContext +import space.kscience.kmath.ejml.inverse +import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.linear.MatrixContext +import space.kscience.kmath.linear.inverseWithLup +import space.kscience.kmath.linear.real import kotlin.random.Random @State(Scope.Benchmark) -class LinearAlgebraBenchmark { +internal class LinearAlgebraBenchmark { companion object { val random = Random(1224) val dim = 100 @@ -26,21 +27,21 @@ class LinearAlgebraBenchmark { } @Benchmark - fun kmathLUPInversion() { - MatrixContext.real.inverseWithLUP(matrix) + fun kmathLupInversion() { + MatrixContext.real.inverseWithLup(matrix) } @Benchmark fun cmLUPInversion() { - CMMatrixContext { + with(CMMatrixContext) { inverse(matrix) } } @Benchmark fun ejmlInverse() { - EjmlMatrixContext { + with(EjmlMatrixContext) { inverse(matrix) } } -} \ No newline at end of file +} diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt new file mode 100644 index 000000000..5bcc09cdb --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt @@ -0,0 +1,44 @@ +package space.kscience.kmath.benchmarks + +import org.openjdk.jmh.annotations.Benchmark +import org.openjdk.jmh.annotations.Scope +import org.openjdk.jmh.annotations.State +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.structures.Buffer + +@State(Scope.Benchmark) +internal class NDFieldBenchmark { + @Benchmark + fun autoFieldAdd() { + with(autoField) { + var res: NDStructure = one + repeat(n) { res += one } + } + } + + @Benchmark + fun specializedFieldAdd() { + with(specializedField) { + var res: NDStructure = one + repeat(n) { res += 1.0 } + } + } + + + @Benchmark + fun boxingFieldAdd() { + with(genericField) { + var res: NDStructure = one + repeat(n) { res += 1.0 } + } + } + + companion object { + const val dim: Int = 1000 + const val n: Int = 100 + val autoField = NDAlgebra.auto(RealField, dim, dim) + val specializedField: RealNDField = NDAlgebra.real(dim, dim) + val genericField = NDAlgebra.field(RealField, Buffer.Companion::boxing, dim, dim) + } +} diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt new file mode 100644 index 000000000..370258bc6 --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt @@ -0,0 +1,51 @@ +package space.kscience.kmath.benchmarks + +import org.jetbrains.bio.viktor.F64Array +import org.openjdk.jmh.annotations.Benchmark +import org.openjdk.jmh.annotations.Scope +import org.openjdk.jmh.annotations.State +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.viktor.ViktorNDField + +@State(Scope.Benchmark) +internal class ViktorBenchmark { + final val dim: Int = 1000 + final val n: Int = 100 + + // automatically build context most suited for given type. + final val autoField: NDField = NDAlgebra.auto(RealField, dim, dim) + final val realField: RealNDField = NDAlgebra.real(dim, dim) + final val viktorField: ViktorNDField = ViktorNDField(dim, dim) + + @Benchmark + fun automaticFieldAddition() { + with(autoField) { + var res: NDStructure = one + repeat(n) { res += 1.0 } + } + } + + @Benchmark + fun realFieldAddition() { + with(realField) { + var res: NDStructure = one + repeat(n) { res += 1.0 } + } + } + + @Benchmark + fun viktorFieldAddition() { + with(viktorField) { + var res = one + repeat(n) { res += 1.0 } + } + } + + @Benchmark + fun rawViktor() { + val one = F64Array.full(init = 1.0, shape = intArrayOf(dim, dim)) + var res = one + repeat(n) { res = res + one } + } +} diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt new file mode 100644 index 000000000..9f99b002a --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt @@ -0,0 +1,48 @@ +package space.kscience.kmath.benchmarks + +import org.jetbrains.bio.viktor.F64Array +import org.openjdk.jmh.annotations.Benchmark +import org.openjdk.jmh.annotations.Scope +import org.openjdk.jmh.annotations.State +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.viktor.ViktorNDField + +@State(Scope.Benchmark) +internal class ViktorLogBenchmark { + final val dim: Int = 1000 + final val n: Int = 100 + + // automatically build context most suited for given type. + final val autoField: NDField = NDAlgebra.auto(RealField, dim, dim) + final val realField: RealNDField = NDAlgebra.real(dim, dim) + final val viktorField: ViktorNDField = ViktorNDField(intArrayOf(dim, dim)) + + + @Benchmark + fun realFieldLog() { + with(realField) { + val fortyTwo = produce { 42.0 } + var res = one + repeat(n) { res = ln(fortyTwo) } + } + } + + @Benchmark + fun viktorFieldLog() { + with(viktorField) { + val fortyTwo = produce { 42.0 } + var res = one + repeat(n) { res = ln(fortyTwo) } + } + } + + @Benchmark + fun rawViktorLog() { + val fortyTwo = F64Array.full(dim, dim, init = 42.0) + var res: F64Array + repeat(n) { + res = fortyTwo.log() + } + } +} diff --git a/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt b/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt new file mode 100644 index 000000000..ee0f4a492 --- /dev/null +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt @@ -0,0 +1,15 @@ +package space.kscience.kmath.ast + +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.RealField + +fun main() { + val expr = RealField.mstInField { + val x = bindSymbol("x") + x * 2.0 + 2.0 / x - 16.0 + } + + repeat(10000000){ + expr.invoke("x" to 1.0) + } +} \ No newline at end of file diff --git a/examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt b/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt similarity index 60% rename from examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt rename to examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt index b3c827503..16304a458 100644 --- a/examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt @@ -1,11 +1,11 @@ -package kscience.kmath.ast +package space.kscience.kmath.ast -import kscience.kmath.asm.compile -import kscience.kmath.expressions.derivative -import kscience.kmath.expressions.invoke -import kscience.kmath.expressions.symbol -import kscience.kmath.kotlingrad.differentiable -import kscience.kmath.operations.RealField +import space.kscience.kmath.asm.compile +import space.kscience.kmath.expressions.derivative +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.expressions.symbol +import space.kscience.kmath.kotlingrad.differentiable +import space.kscience.kmath.operations.RealField /** * In this example, x^2-4*x-44 function is differentiated with Kotlin∇, and the autodiff result is compared with diff --git a/examples/src/main/kotlin/kscience/kmath/commons/fit/fitWithAutoDiff.kt b/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt similarity index 83% rename from examples/src/main/kotlin/kscience/kmath/commons/fit/fitWithAutoDiff.kt rename to examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt index c0cd9dc5c..63b819dc9 100644 --- a/examples/src/main/kotlin/kscience/kmath/commons/fit/fitWithAutoDiff.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt @@ -1,19 +1,19 @@ -package kscience.kmath.commons.fit +package space.kscience.kmath.commons.fit import kotlinx.html.br import kotlinx.html.h3 -import kscience.kmath.commons.optimization.chiSquared -import kscience.kmath.commons.optimization.minimize -import kscience.kmath.expressions.symbol -import kscience.kmath.real.RealVector -import kscience.kmath.real.map -import kscience.kmath.real.step -import kscience.kmath.stat.* -import kscience.kmath.structures.asIterable -import kscience.kmath.structures.toList import kscience.plotly.* import kscience.plotly.models.ScatterMode import kscience.plotly.models.TraceValues +import space.kscience.kmath.commons.optimization.chiSquared +import space.kscience.kmath.commons.optimization.minimize +import space.kscience.kmath.expressions.symbol +import space.kscience.kmath.real.RealVector +import space.kscience.kmath.real.map +import space.kscience.kmath.real.step +import space.kscience.kmath.stat.* +import space.kscience.kmath.structures.asIterable +import space.kscience.kmath.structures.toList import kotlin.math.pow import kotlin.math.sqrt @@ -63,7 +63,7 @@ fun main() { val a = bind(a) val b = bind(b) //Include default value for c if it is not provided as a parameter - val c = bindOrNull(c) ?: one + val c = bindSymbolOrNull(c) ?: one a * x1.pow(2) + b * x1 + c } diff --git a/examples/src/main/kotlin/kscience/kmath/operations/BigIntDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/operations/BigIntDemo.kt similarity index 67% rename from examples/src/main/kotlin/kscience/kmath/operations/BigIntDemo.kt rename to examples/src/main/kotlin/space/kscience/kmath/operations/BigIntDemo.kt index 0e9811ff8..6d5903cae 100644 --- a/examples/src/main/kotlin/kscience/kmath/operations/BigIntDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/operations/BigIntDemo.kt @@ -1,4 +1,4 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations fun main() { val res = BigIntField { number(1) * 2 } diff --git a/examples/src/main/kotlin/kscience/kmath/operations/ComplexDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/operations/ComplexDemo.kt similarity index 53% rename from examples/src/main/kotlin/kscience/kmath/operations/ComplexDemo.kt rename to examples/src/main/kotlin/space/kscience/kmath/operations/ComplexDemo.kt index e84fd8df3..5330d9e40 100644 --- a/examples/src/main/kotlin/kscience/kmath/operations/ComplexDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/operations/ComplexDemo.kt @@ -1,23 +1,24 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations -import kscience.kmath.structures.NDElement -import kscience.kmath.structures.NDField -import kscience.kmath.structures.complex +import space.kscience.kmath.complex.Complex +import space.kscience.kmath.complex.complex +import space.kscience.kmath.nd.NDAlgebra fun main() { // 2d element - val element = NDElement.complex(2, 2) { (i,j) -> + val element = NDAlgebra.complex(2, 2).produce { (i, j) -> Complex(i.toDouble() - j.toDouble(), i.toDouble() + j.toDouble()) } println(element) // 1d element operation - val result = with(NDField.complex(8)) { + val result = with(NDAlgebra.complex(8)) { val a = produce { (it) -> i * it - it.toDouble() } val b = 3 val c = Complex(1.0, 1.0) (a pow b) + c } + println(result) } diff --git a/examples/src/main/kotlin/kscience/kmath/stat/DistributionBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt similarity index 98% rename from examples/src/main/kotlin/kscience/kmath/stat/DistributionBenchmark.kt rename to examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt index 99d3cd504..1761ed1b5 100644 --- a/examples/src/main/kotlin/kscience/kmath/stat/DistributionBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt @@ -3,9 +3,9 @@ package kscience.kmath.commons.prob import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking -import kscience.kmath.stat.* import org.apache.commons.rng.sampling.distribution.ZigguratNormalizedGaussianSampler import org.apache.commons.rng.simple.RandomSource +import space.kscience.kmath.stat.* import java.time.Duration import java.time.Instant diff --git a/examples/src/main/kotlin/kscience/kmath/stat/DistributionDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt similarity index 85% rename from examples/src/main/kotlin/kscience/kmath/stat/DistributionDemo.kt rename to examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt index 24a4cb1a7..47b8d8111 100644 --- a/examples/src/main/kotlin/kscience/kmath/stat/DistributionDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt @@ -1,8 +1,8 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.runBlocking -import kscience.kmath.chains.Chain -import kscience.kmath.chains.collectWithState +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.chains.collectWithState /** * The state of distribution averager diff --git a/examples/src/main/kotlin/kscience/kmath/structures/ComplexND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt similarity index 62% rename from examples/src/main/kotlin/kscience/kmath/structures/ComplexND.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt index b69590473..b8cbc9a57 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/ComplexND.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt @@ -1,21 +1,26 @@ -package kscience.kmath.structures +@file:Suppress("unused") -import kscience.kmath.linear.transpose -import kscience.kmath.operations.Complex -import kscience.kmath.operations.ComplexField -import kscience.kmath.operations.invoke +package space.kscience.kmath.structures + +import space.kscience.kmath.complex.* +import space.kscience.kmath.linear.transpose +import space.kscience.kmath.nd.NDAlgebra +import space.kscience.kmath.nd.NDStructure +import space.kscience.kmath.nd.as2D +import space.kscience.kmath.nd.real +import space.kscience.kmath.operations.invoke import kotlin.system.measureTimeMillis fun main() { val dim = 1000 val n = 1000 - val realField = NDField.real(dim, dim) - val complexField: ComplexNDField = NDField.complex(dim, dim) + val realField = NDAlgebra.real(dim, dim) + val complexField: ComplexNDField = NDAlgebra.complex(dim, dim) val realTime = measureTimeMillis { realField { - var res: NDBuffer = one + var res: NDStructure = one repeat(n) { res += 1.0 } @@ -26,8 +31,10 @@ fun main() { val complexTime = measureTimeMillis { complexField { - var res: NDBuffer = one - repeat(n) { res += 1.0 } + var res: NDStructure = one + repeat(n) { + res += 1.0 + } } } diff --git a/examples/src/main/kotlin/kscience/kmath/structures/NDField.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt similarity index 51% rename from examples/src/main/kotlin/kscience/kmath/structures/NDField.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt index b5130c92b..10fb3cb3d 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/NDField.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt @@ -1,10 +1,12 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures import kotlinx.coroutines.GlobalScope -import kscience.kmath.nd4j.Nd4jArrayField -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke import org.nd4j.linalg.factory.Nd4j +import space.kscience.kmath.nd.* +import space.kscience.kmath.nd4j.Nd4jArrayField +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.viktor.ViktorNDField import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.system.measureTimeMillis @@ -22,42 +24,62 @@ fun main() { val n = 1000 // automatically build context most suited for given type. - val autoField = NDField.auto(RealField, dim, dim) + val autoField = NDAlgebra.auto(RealField, dim, dim) // specialized nd-field for Double. It works as generic Double field as well - val specializedField = NDField.real(dim, dim) + val realField = NDAlgebra.real(dim, dim) //A generic boxing field. It should be used for objects, not primitives. - val genericField = NDField.boxing(RealField, dim, dim) + val boxingField = NDAlgebra.field(RealField, Buffer.Companion::boxing, dim, dim) // Nd4j specialized field. val nd4jField = Nd4jArrayField.real(dim, dim) + //viktor field + val viktorField = ViktorNDField(dim,dim) + //parallel processing based on Java Streams + val parallelField = NDAlgebra.realWithStream(dim,dim) - measureAndPrint("Automatic field addition") { - autoField { - var res: NDBuffer = one + measureAndPrint("Boxing addition") { + boxingField { + var res: NDStructure = one repeat(n) { res += 1.0 } } } - measureAndPrint("Element addition") { - var res = genericField.one - repeat(n) { res += 1.0 } - } - measureAndPrint("Specialized addition") { - specializedField { - var res: NDBuffer = one + realField { + var res: NDStructure = one repeat(n) { res += 1.0 } } } measureAndPrint("Nd4j specialized addition") { nd4jField { - var res = one + var res: NDStructure = one + repeat(n) { res += 1.0 } + } + } + + measureAndPrint("Viktor addition") { + viktorField { + var res: NDStructure = one + repeat(n) { res += 1.0 } + } + } + + measureAndPrint("Parallel stream addition") { + parallelField { + var res: NDStructure = one + repeat(n) { res += 1.0 } + } + } + + measureAndPrint("Automatic field addition") { + autoField { + var res: NDStructure = one repeat(n) { res += 1.0 } } } measureAndPrint("Lazy addition") { - val res = specializedField.one.mapAsync(GlobalScope) { + val res = realField.one.mapAsync(GlobalScope) { var c = 0.0 repeat(n) { c += 1.0 @@ -67,14 +89,4 @@ fun main() { res.elements().forEach { it.second } } - - measureAndPrint("Generic addition") { - //genericField.run(action) - genericField { - var res: NDBuffer = one - repeat(n) { - res += 1.0 // couldn't avoid using `one` due to resolution ambiguity } - } - } - } } diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/ParallelRealNDField.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/ParallelRealNDField.kt new file mode 100644 index 000000000..111cfec80 --- /dev/null +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/ParallelRealNDField.kt @@ -0,0 +1,103 @@ +package space.kscience.kmath.structures + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.RingWithNumbers +import java.util.* +import java.util.stream.IntStream + +/** + * A demonstration implementation of NDField over Real using Java [DoubleStream] for parallel execution + */ +@OptIn(UnstableKMathAPI::class) +class StreamRealNDField( + override val shape: IntArray, +) : NDField, + RingWithNumbers>, + ExtendedField> { + + private val strides = DefaultStrides(shape) + override val elementContext: RealField get() = RealField + override val zero: NDBuffer by lazy { produce { zero } } + override val one: NDBuffer by lazy { produce { one } } + + override fun number(value: Number): NDBuffer { + val d = value.toDouble() // minimize conversions + return produce { d } + } + + private val NDStructure.buffer: RealBuffer + get() = when { + !shape.contentEquals(this@StreamRealNDField.shape) -> throw ShapeMismatchException( + this@StreamRealNDField.shape, + shape + ) + this is NDBuffer && this.strides == this@StreamRealNDField.strides -> this.buffer as RealBuffer + else -> RealBuffer(strides.linearSize) { offset -> get(strides.index(offset)) } + } + + + override fun produce(initializer: RealField.(IntArray) -> Double): NDBuffer { + val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> + val index = strides.index(offset) + RealField.initializer(index) + }.toArray() + + return NDBuffer(strides, array.asBuffer()) + } + + override fun NDStructure.map( + transform: RealField.(Double) -> Double, + ): NDBuffer { + val array = Arrays.stream(buffer.array).parallel().map { RealField.transform(it) }.toArray() + return NDBuffer(strides, array.asBuffer()) + } + + override fun NDStructure.mapIndexed( + transform: RealField.(index: IntArray, Double) -> Double, + ): NDBuffer { + val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> + RealField.transform( + strides.index(offset), + buffer.array[offset] + ) + }.toArray() + + return NDBuffer(strides, array.asBuffer()) + } + + override fun combine( + a: NDStructure, + b: NDStructure, + transform: RealField.(Double, Double) -> Double, + ): NDBuffer { + val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> + RealField.transform(a.buffer.array[offset], b.buffer.array[offset]) + }.toArray() + return NDBuffer(strides, array.asBuffer()) + } + + override fun power(arg: NDStructure, pow: Number): NDBuffer = arg.map() { power(it, pow) } + + override fun exp(arg: NDStructure): NDBuffer = arg.map() { exp(it) } + + override fun ln(arg: NDStructure): NDBuffer = arg.map() { ln(it) } + + override fun sin(arg: NDStructure): NDBuffer = arg.map() { sin(it) } + override fun cos(arg: NDStructure): NDBuffer = arg.map() { cos(it) } + override fun tan(arg: NDStructure): NDBuffer = arg.map() { tan(it) } + override fun asin(arg: NDStructure): NDBuffer = arg.map() { asin(it) } + override fun acos(arg: NDStructure): NDBuffer = arg.map() { acos(it) } + override fun atan(arg: NDStructure): NDBuffer = arg.map() { atan(it) } + + override fun sinh(arg: NDStructure): NDBuffer = arg.map() { sinh(it) } + override fun cosh(arg: NDStructure): NDBuffer = arg.map() { cosh(it) } + override fun tanh(arg: NDStructure): NDBuffer = arg.map() { tanh(it) } + override fun asinh(arg: NDStructure): NDBuffer = arg.map() { asinh(it) } + override fun acosh(arg: NDStructure): NDBuffer = arg.map() { acosh(it) } + override fun atanh(arg: NDStructure): NDBuffer = arg.map() { atanh(it) } +} + +fun NDAlgebra.Companion.realWithStream(vararg shape: Int): StreamRealNDField = StreamRealNDField(shape) \ No newline at end of file diff --git a/examples/src/main/kotlin/kscience/kmath/structures/StructureReadBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt similarity index 79% rename from examples/src/main/kotlin/kscience/kmath/structures/StructureReadBenchmark.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt index 51fd4f956..7f6d73394 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/StructureReadBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt @@ -1,13 +1,16 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures +import space.kscience.kmath.nd.DefaultStrides +import space.kscience.kmath.nd.NDBuffer import kotlin.system.measureTimeMillis +@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") fun main() { val n = 6000 val array = DoubleArray(n * n) { 1.0 } val buffer = RealBuffer(array) val strides = DefaultStrides(intArrayOf(n, n)) - val structure = BufferNDStructure(strides, buffer) + val structure = NDBuffer(strides, buffer) measureTimeMillis { var res = 0.0 diff --git a/examples/src/main/kotlin/kscience/kmath/structures/StructureWriteBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt similarity index 85% rename from examples/src/main/kotlin/kscience/kmath/structures/StructureWriteBenchmark.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt index db55b454f..13d6f00e4 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/StructureWriteBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt @@ -1,7 +1,10 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures +import space.kscience.kmath.nd.NDStructure +import space.kscience.kmath.nd.mapToBuffer import kotlin.system.measureTimeMillis +@Suppress("UNUSED_VARIABLE") fun main() { val n = 6000 val structure = NDStructure.build(intArrayOf(n, n), Buffer.Companion::auto) { 1.0 } diff --git a/examples/src/main/kotlin/kscience/kmath/structures/typeSafeDimensions.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt similarity index 73% rename from examples/src/main/kotlin/kscience/kmath/structures/typeSafeDimensions.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt index 96684f7dc..fdd631238 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/typeSafeDimensions.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt @@ -1,9 +1,9 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures -import kscience.kmath.dimensions.D2 -import kscience.kmath.dimensions.D3 -import kscience.kmath.dimensions.DMatrixContext -import kscience.kmath.dimensions.Dimension +import space.kscience.kmath.dimensions.D2 +import space.kscience.kmath.dimensions.D3 +import space.kscience.kmath.dimensions.DMatrixContext +import space.kscience.kmath.dimensions.Dimension private fun DMatrixContext.simple() { val m1 = produce { i, j -> (i + j).toDouble() } diff --git a/gradle.properties b/gradle.properties index 930bba550..88b90f27b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,8 @@ kotlin.code.style=official -kotlin.parallel.tasks.in.project=true kotlin.mpp.enableGranularSourceSetsMetadata=true -kotlin.native.enableDependencyPropagation=false kotlin.mpp.stability.nowarn=true - +kotlin.native.enableDependencyPropagation=false +kotlin.parallel.tasks.in.project=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 +systemProp.org.gradle.internal.publish.checksums.insecure=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index da9702f9e..2a563242c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/kmath-ast/README.md b/kmath-ast/README.md index e6200d3ef..e52f0fa96 100644 --- a/kmath-ast/README.md +++ b/kmath-ast/README.md @@ -12,7 +12,7 @@ This subproject implements the following features: > #### Artifact: > -> This module artifact: `kscience.kmath:kmath-ast:0.2.0-dev-5`. +> This module artifact: `space.kscience:kmath-ast:0.2.0`. > > Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-ast/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-ast/_latestVersion) > @@ -22,29 +22,32 @@ This subproject implements the following features: > > ```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://repo.kotlin.link' } > maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> +> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } // include for builds based on kotlin-eap +>// Uncomment if repo.kotlin.link is unavailable +>// maven { url 'https://dl.bintray.com/mipt-npm/kscience' } +>// maven { url 'https://dl.bintray.com/mipt-npm/dev' } > } > > dependencies { -> implementation 'kscience.kmath:kmath-ast:0.2.0-dev-5' +> implementation 'space.kscience:kmath-ast:0.2.0' > } > ``` > **Gradle Kotlin DSL:** > > ```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") +> maven("https://repo.kotlin.link") +> maven("https://dl.bintray.com/kotlin/kotlin-eap") // include for builds based on kotlin-eap +> maven("https://dl.bintray.com/hotkeytlt/maven") // required for a +>// Uncomment if repo.kotlin.link is unavailable +>// maven("https://dl.bintray.com/mipt-npm/kscience") +>// maven("https://dl.bintray.com/mipt-npm/dev") > } > > dependencies { -> implementation("kscience.kmath:kmath-ast:0.2.0-dev-5") +> implementation("space.kscience:kmath-ast:0.2.0") > } > ``` @@ -64,18 +67,18 @@ RealField.mstInField { symbol("x") + 2 }.compile() … leads to generation of bytecode, which can be decompiled to the following Java class: ```java -package kscience.kmath.asm.generated; +package space.kscience.kmath.asm.generated; import java.util.Map; import kotlin.jvm.functions.Function2; -import kscience.kmath.asm.internal.MapIntrinsics; -import kscience.kmath.expressions.Expression; -import kscience.kmath.expressions.Symbol; +import space.kscience.kmath.asm.internal.MapIntrinsics; +import space.kscience.kmath.expressions.Expression; +import space.kscience.kmath.expressions.Symbol; public final class AsmCompiledExpression_45045_0 implements Expression { private final Object[] constants; - public final Double invoke(Map arguments) { + public final Double invoke(Map arguments) { return (Double)((Function2)this.constants[0]).invoke((Double)MapIntrinsics.getOrFail(arguments, "x"), 2); } diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index 39de4256d..894279695 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -1,7 +1,7 @@ import ru.mipt.npm.gradle.Maturity plugins { - id("ru.mipt.npm.mpp") + id("ru.mipt.npm.gradle.mpp") } kotlin.js { @@ -25,6 +25,12 @@ kotlin.sourceSets { } } + commonTest { + dependencies { + implementation(project(":kmath-complex")) + } + } + jsMain { dependencies { implementation(npm("astring", "1.4.3")) @@ -40,6 +46,9 @@ kotlin.sourceSets { } } +//Workaround for https://github.com/Kotlin/dokka/issues/1455 +tasks.getByName("dokkaHtml").dependsOn(tasks.getByName("build")) + readme { maturity = Maturity.PROTOTYPE propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) diff --git a/kmath-ast/docs/README-TEMPLATE.md b/kmath-ast/docs/README-TEMPLATE.md index 3227a2ad3..2712cba75 100644 --- a/kmath-ast/docs/README-TEMPLATE.md +++ b/kmath-ast/docs/README-TEMPLATE.md @@ -22,18 +22,18 @@ RealField.mstInField { symbol("x") + 2 }.compile() … leads to generation of bytecode, which can be decompiled to the following Java class: ```java -package kscience.kmath.asm.generated; +package space.kscience.kmath.asm.generated; import java.util.Map; import kotlin.jvm.functions.Function2; -import kscience.kmath.asm.internal.MapIntrinsics; -import kscience.kmath.expressions.Expression; -import kscience.kmath.expressions.Symbol; +import space.kscience.kmath.asm.internal.MapIntrinsics; +import space.kscience.kmath.expressions.Expression; +import space.kscience.kmath.expressions.Symbol; public final class AsmCompiledExpression_45045_0 implements Expression { private final Object[] constants; - public final Double invoke(Map arguments) { + public final Double invoke(Map arguments) { return (Double)((Function2)this.constants[0]).invoke((Double)MapIntrinsics.getOrFail(arguments, "x"), 2); } diff --git a/kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MST.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt similarity index 93% rename from kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MST.kt rename to kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt index 212fd0d0b..c459d7ff5 100644 --- a/kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MST.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt @@ -1,7 +1,7 @@ -package kscience.kmath.ast +package space.kscience.kmath.ast -import kscience.kmath.operations.Algebra -import kscience.kmath.operations.NumericAlgebra +import space.kscience.kmath.operations.Algebra +import space.kscience.kmath.operations.NumericAlgebra /** * A Mathematical Syntax Tree (MST) node for mathematical expressions. @@ -55,7 +55,7 @@ public fun Algebra.evaluate(node: MST): T = when (node) { is MST.Numeric -> (this as? NumericAlgebra)?.number(node.value) ?: error("Numeric nodes are not supported by $this") - is MST.Symbolic -> symbol(node.value) + is MST.Symbolic -> bindSymbol(node.value) is MST.Unary -> when { this is NumericAlgebra && node.value is MST.Numeric -> unaryOperationFunction(node.operation)(number(node.value.value)) diff --git a/kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MstAlgebra.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt similarity index 92% rename from kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MstAlgebra.kt rename to kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt index eadbc85ee..7bea65684 100644 --- a/kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MstAlgebra.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt @@ -1,14 +1,14 @@ -package kscience.kmath.ast +package space.kscience.kmath.ast -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.* /** * [Algebra] over [MST] nodes. */ public object MstAlgebra : NumericAlgebra { public override fun number(value: Number): MST.Numeric = MST.Numeric(value) - public override fun symbol(value: String): MST.Symbolic = MST.Symbolic(value) + public override fun bindSymbol(value: String): MST.Symbolic = MST.Symbolic(value) public override fun unaryOperationFunction(operation: String): (arg: MST) -> MST.Unary = { arg -> MST.Unary(operation, arg) } @@ -24,7 +24,7 @@ public object MstSpace : Space, NumericAlgebra { public override val zero: MST.Numeric by lazy { number(0.0) } public override fun number(value: Number): MST.Numeric = MstAlgebra.number(value) - public override fun symbol(value: String): MST.Symbolic = MstAlgebra.symbol(value) + public override fun bindSymbol(value: String): MST.Symbolic = MstAlgebra.bindSymbol(value) public override fun add(a: MST, b: MST): MST.Binary = binaryOperationFunction(SpaceOperations.PLUS_OPERATION)(a, b) public override operator fun MST.unaryPlus(): MST.Unary = unaryOperationFunction(SpaceOperations.PLUS_OPERATION)(this) @@ -56,7 +56,7 @@ public object MstRing : Ring, RingWithNumbers { public override val one: MST.Numeric by lazy { number(1.0) } public override fun number(value: Number): MST.Numeric = MstSpace.number(value) - public override fun symbol(value: String): MST.Symbolic = MstSpace.symbol(value) + public override fun bindSymbol(value: String): MST.Symbolic = MstSpace.bindSymbol(value) public override fun add(a: MST, b: MST): MST.Binary = MstSpace.add(a, b) public override fun multiply(a: MST, k: Number): MST.Binary = MstSpace.multiply(a, k) public override fun multiply(a: MST, b: MST): MST.Binary = @@ -84,7 +84,7 @@ public object MstField : Field, RingWithNumbers { public override val one: MST.Numeric get() = MstRing.one - public override fun symbol(value: String): MST.Symbolic = MstRing.symbol(value) + public override fun bindSymbol(value: String): MST.Symbolic = MstRing.bindSymbol(value) public override fun number(value: Number): MST.Numeric = MstRing.number(value) public override fun add(a: MST, b: MST): MST.Binary = MstRing.add(a, b) public override fun multiply(a: MST, k: Number): MST.Binary = MstRing.multiply(a, k) @@ -113,7 +113,7 @@ public object MstExtendedField : ExtendedField, NumericAlgebra { public override val one: MST.Numeric get() = MstField.one - public override fun symbol(value: String): MST.Symbolic = MstField.symbol(value) + public override fun bindSymbol(value: String): MST.Symbolic = MstField.bindSymbol(value) public override fun number(value: Number): MST.Numeric = MstRing.number(value) public override fun sin(arg: MST): MST.Unary = unaryOperationFunction(TrigonometricOperations.SIN_OPERATION)(arg) public override fun cos(arg: MST): MST.Unary = unaryOperationFunction(TrigonometricOperations.COS_OPERATION)(arg) diff --git a/kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MstExpression.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstExpression.kt similarity index 86% rename from kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MstExpression.kt rename to kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstExpression.kt index 03d33aa2b..412dde32c 100644 --- a/kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MstExpression.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstExpression.kt @@ -1,7 +1,7 @@ -package kscience.kmath.ast +package space.kscience.kmath.ast -import kscience.kmath.expressions.* -import kscience.kmath.operations.* +import space.kscience.kmath.expressions.* +import space.kscience.kmath.operations.* import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -15,14 +15,23 @@ import kotlin.contracts.contract */ public class MstExpression>(public val algebra: A, public val mst: MST) : Expression { private inner class InnerAlgebra(val arguments: Map) : NumericAlgebra { - override fun symbol(value: String): T = try { - algebra.symbol(value) + override fun bindSymbol(value: String): T = try { + algebra.bindSymbol(value) } catch (ignored: IllegalStateException) { null } ?: arguments.getValue(StringSymbol(value)) - override fun unaryOperationFunction(operation: String): (arg: T) -> T = algebra.unaryOperationFunction(operation) - override fun binaryOperationFunction(operation: String): (left: T, right: T) -> T = algebra.binaryOperationFunction(operation) + override fun unaryOperation(operation: String, arg: T): T = + algebra.unaryOperation(operation, arg) + + override fun binaryOperation(operation: String, left: T, right: T): T = + algebra.binaryOperation(operation, left, right) + + override fun unaryOperationFunction(operation: String): (arg: T) -> T = + algebra.unaryOperationFunction(operation) + + override fun binaryOperationFunction(operation: String): (left: T, right: T) -> T = + algebra.binaryOperationFunction(operation) @Suppress("UNCHECKED_CAST") override fun number(value: Number): T = if (algebra is NumericAlgebra<*>) diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/astring/astring.typealises.kt b/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/astring/astring.typealises.kt deleted file mode 100644 index 5a7fe4f16..000000000 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/astring/astring.typealises.kt +++ /dev/null @@ -1,3 +0,0 @@ -package kscience.kmath.estree.internal.astring - -internal typealias Generator = Any diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/stream/stream.kt b/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/stream/stream.kt deleted file mode 100644 index b3c65a758..000000000 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/stream/stream.kt +++ /dev/null @@ -1,7 +0,0 @@ -package kscience.kmath.estree.internal.stream - -import kscience.kmath.estree.internal.emitter.Emitter - -internal open external class Stream : Emitter { - open fun pipe(dest: Any, options: Any): Any -} diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt similarity index 82% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/estree.kt rename to kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt index 5c08ada31..0bd9a386d 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/estree.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt @@ -1,20 +1,20 @@ -package kscience.kmath.estree +package space.kscience.kmath.estree -import kscience.kmath.ast.MST -import kscience.kmath.ast.MST.* -import kscience.kmath.ast.MstExpression -import kscience.kmath.estree.internal.ESTreeBuilder -import kscience.kmath.estree.internal.estree.BaseExpression -import kscience.kmath.expressions.Expression -import kscience.kmath.operations.Algebra -import kscience.kmath.operations.NumericAlgebra +import space.kscience.kmath.ast.MST +import space.kscience.kmath.ast.MST.* +import space.kscience.kmath.ast.MstExpression +import space.kscience.kmath.estree.internal.ESTreeBuilder +import space.kscience.kmath.estree.internal.estree.BaseExpression +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.operations.Algebra +import space.kscience.kmath.operations.NumericAlgebra @PublishedApi internal fun MST.compileWith(algebra: Algebra): Expression { fun ESTreeBuilder.visit(node: MST): BaseExpression = when (node) { is Symbolic -> { val symbol = try { - algebra.symbol(node.value) + algebra.bindSymbol(node.value) } catch (ignored: IllegalStateException) { null } diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/ESTreeBuilder.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt similarity index 90% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/ESTreeBuilder.kt rename to kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt index e1823813a..b4de9968d 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/ESTreeBuilder.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt @@ -1,9 +1,9 @@ -package kscience.kmath.estree.internal +package space.kscience.kmath.estree.internal -import kscience.kmath.estree.internal.astring.generate -import kscience.kmath.estree.internal.estree.* -import kscience.kmath.expressions.Expression -import kscience.kmath.expressions.Symbol +import space.kscience.kmath.estree.internal.astring.generate +import space.kscience.kmath.estree.internal.estree.* +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.Symbol internal class ESTreeBuilder(val bodyCallback: ESTreeBuilder.() -> BaseExpression) { private class GeneratedExpression(val executable: dynamic, val constants: Array) : Expression { diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/astring/astring.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.kt similarity index 88% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/astring/astring.kt rename to kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.kt index cf0a8de25..1b7500ddb 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/astring/astring.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.kt @@ -1,9 +1,9 @@ @file:JsModule("astring") @file:JsNonModule -package kscience.kmath.estree.internal.astring +package space.kscience.kmath.estree.internal.astring -import kscience.kmath.estree.internal.estree.BaseNode +import space.kscience.kmath.estree.internal.estree.BaseNode internal external interface Options { var indent: String? diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt new file mode 100644 index 000000000..9e75a97c7 --- /dev/null +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt @@ -0,0 +1,3 @@ +package space.kscience.kmath.estree.internal.astring + +internal typealias Generator = Any diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/emitter/emitter.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/emitter/emitter.kt similarity index 87% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/emitter/emitter.kt rename to kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/emitter/emitter.kt index 1e0a95a16..3028656f5 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/emitter/emitter.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/emitter/emitter.kt @@ -1,4 +1,4 @@ -package kscience.kmath.estree.internal.emitter +package space.kscience.kmath.estree.internal.emitter internal open external class Emitter { constructor(obj: Any) diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/estree/estree.extensions.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/estree/estree.extensions.kt similarity index 97% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/estree/estree.extensions.kt rename to kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/estree/estree.extensions.kt index 5bc197d0c..0e088c717 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/estree/estree.extensions.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/estree/estree.extensions.kt @@ -1,4 +1,4 @@ -package kscience.kmath.estree.internal.estree +package space.kscience.kmath.estree.internal.estree internal fun Program(sourceType: String, vararg body: dynamic) = object : Program { override var type = "Program" diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/estree/estree.kt similarity index 99% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/estree/estree.kt rename to kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/estree/estree.kt index a5385d1ee..4dc1bfc10 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/estree/estree.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/estree/estree.kt @@ -1,4 +1,4 @@ -package kscience.kmath.estree.internal.estree +package space.kscience.kmath.estree.internal.estree import kotlin.js.RegExp diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/stream/stream.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/stream/stream.kt new file mode 100644 index 000000000..c3477c482 --- /dev/null +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/stream/stream.kt @@ -0,0 +1,7 @@ +package space.kscience.kmath.estree.internal.stream + +import space.kscience.kmath.estree.internal.emitter.Emitter + +internal open external class Stream : Emitter { + open fun pipe(dest: Any, options: Any): Any +} diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/tsstdlib/lib.es2015.iterable.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/tsstdlib/lib.es2015.iterable.kt similarity index 93% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/tsstdlib/lib.es2015.iterable.kt rename to kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/tsstdlib/lib.es2015.iterable.kt index 22d4dd8e0..7f2975219 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/tsstdlib/lib.es2015.iterable.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/tsstdlib/lib.es2015.iterable.kt @@ -1,4 +1,4 @@ -package kscience.kmath.estree.internal.tsstdlib +package space.kscience.kmath.estree.internal.tsstdlib internal external interface IteratorYieldResult { var done: Boolean? diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/tsstdlib/lib.es5.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/tsstdlib/lib.es5.kt similarity index 97% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/tsstdlib/lib.es5.kt rename to kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/tsstdlib/lib.es5.kt index 70f6d9702..7286b4a20 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/internal/tsstdlib/lib.es5.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/tsstdlib/lib.es5.kt @@ -1,6 +1,6 @@ @file:Suppress("UNUSED_TYPEALIAS_PARAMETER", "DEPRECATION") -package kscience.kmath.estree.internal.tsstdlib +package space.kscience.kmath.estree.internal.tsstdlib import kotlin.js.RegExp diff --git a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt similarity index 76% rename from kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt rename to kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt index b9be02d49..492a5d11f 100644 --- a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt @@ -1,11 +1,11 @@ -package kscience.kmath.estree +package space.kscience.kmath.estree -import kscience.kmath.ast.* -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.ByteRing -import kscience.kmath.operations.ComplexField -import kscience.kmath.operations.RealField -import kscience.kmath.operations.toComplex +import space.kscience.kmath.ast.* +import space.kscience.kmath.complex.ComplexField +import space.kscience.kmath.complex.toComplex +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.ByteRing +import space.kscience.kmath.operations.RealField import kotlin.test.Test import kotlin.test.assertEquals @@ -22,7 +22,7 @@ internal class TestESTreeConsistencyWithInterpreter { ), number(1) - ) + symbol("x") + zero + ) + bindSymbol("x") + zero }("x" to MST.Numeric(2)) val res2 = MstSpace.mstInSpace { @@ -35,7 +35,7 @@ internal class TestESTreeConsistencyWithInterpreter { ), number(1) - ) + symbol("x") + zero + ) + bindSymbol("x") + zero }.compile()("x" to MST.Numeric(2)) assertEquals(res1, res2) @@ -46,7 +46,7 @@ internal class TestESTreeConsistencyWithInterpreter { val res1 = ByteRing.mstInRing { binaryOperationFunction("+")( unaryOperationFunction("+")( - (symbol("x") - (2.toByte() + (multiply( + (bindSymbol("x") - (2.toByte() + (multiply( add(number(1), number(1)), 2 ) + 1.toByte()))) * 3.0 - 1.toByte() @@ -59,7 +59,7 @@ internal class TestESTreeConsistencyWithInterpreter { val res2 = ByteRing.mstInRing { binaryOperationFunction("+")( unaryOperationFunction("+")( - (symbol("x") - (2.toByte() + (multiply( + (bindSymbol("x") - (2.toByte() + (multiply( add(number(1), number(1)), 2 ) + 1.toByte()))) * 3.0 - 1.toByte() @@ -75,7 +75,7 @@ internal class TestESTreeConsistencyWithInterpreter { fun realField() { val res1 = RealField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( - (3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero @@ -83,7 +83,7 @@ internal class TestESTreeConsistencyWithInterpreter { val res2 = RealField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( - (3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero @@ -96,7 +96,7 @@ internal class TestESTreeConsistencyWithInterpreter { fun complexField() { val res1 = ComplexField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( - (3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero @@ -104,7 +104,7 @@ internal class TestESTreeConsistencyWithInterpreter { val res2 = ComplexField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( - (3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero diff --git a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeOperationsSupport.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt similarity index 50% rename from kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeOperationsSupport.kt rename to kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt index 72a4669d9..6e2f85327 100644 --- a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeOperationsSupport.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt @@ -1,10 +1,10 @@ -package kscience.kmath.estree +package space.kscience.kmath.estree -import kscience.kmath.ast.mstInExtendedField -import kscience.kmath.ast.mstInField -import kscience.kmath.ast.mstInSpace -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.RealField +import space.kscience.kmath.ast.mstInExtendedField +import space.kscience.kmath.ast.mstInField +import space.kscience.kmath.ast.mstInSpace +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.RealField import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals @@ -12,27 +12,27 @@ import kotlin.test.assertEquals internal class TestESTreeOperationsSupport { @Test fun testUnaryOperationInvocation() { - val expression = RealField.mstInSpace { -symbol("x") }.compile() + val expression = RealField.mstInSpace { -bindSymbol("x") }.compile() val res = expression("x" to 2.0) assertEquals(-2.0, res) } @Test fun testBinaryOperationInvocation() { - val expression = RealField.mstInSpace { -symbol("x") + number(1.0) }.compile() + val expression = RealField.mstInSpace { -bindSymbol("x") + number(1.0) }.compile() val res = expression("x" to 2.0) assertEquals(-1.0, res) } @Test fun testConstProductInvocation() { - val res = RealField.mstInField { symbol("x") * 2 }("x" to 2.0) + val res = RealField.mstInField { bindSymbol("x") * 2 }("x" to 2.0) assertEquals(4.0, res) } @Test fun testMultipleCalls() { - val e = RealField.mstInExtendedField { sin(symbol("x")).pow(4) - 6 * symbol("x") / tanh(symbol("x")) }.compile() + val e = RealField.mstInExtendedField { sin(bindSymbol("x")).pow(4) - 6 * bindSymbol("x") / tanh(bindSymbol("x")) }.compile() val r = Random(0) var s = 0.0 repeat(1000000) { s += e("x" to r.nextDouble()) } diff --git a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeSpecialization.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt similarity index 68% rename from kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeSpecialization.kt rename to kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt index 9d0d17e58..c5e43241a 100644 --- a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeSpecialization.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt @@ -1,52 +1,52 @@ -package kscience.kmath.estree +package space.kscience.kmath.estree -import kscience.kmath.ast.mstInField -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.RealField +import space.kscience.kmath.ast.mstInField +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.RealField import kotlin.test.Test import kotlin.test.assertEquals internal class TestESTreeSpecialization { @Test fun testUnaryPlus() { - val expr = RealField.mstInField { unaryOperationFunction("+")(symbol("x")) }.compile() + val expr = RealField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile() assertEquals(2.0, expr("x" to 2.0)) } @Test fun testUnaryMinus() { - val expr = RealField.mstInField { unaryOperationFunction("-")(symbol("x")) }.compile() + val expr = RealField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile() assertEquals(-2.0, expr("x" to 2.0)) } @Test fun testAdd() { - val expr = RealField.mstInField { binaryOperationFunction("+")(symbol("x"), symbol("x")) }.compile() + val expr = RealField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(4.0, expr("x" to 2.0)) } @Test fun testSine() { - val expr = RealField.mstInField { unaryOperationFunction("sin")(symbol("x")) }.compile() + val expr = RealField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile() assertEquals(0.0, expr("x" to 0.0)) } @Test fun testMinus() { - val expr = RealField.mstInField { binaryOperationFunction("-")(symbol("x"), symbol("x")) }.compile() + val expr = RealField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(0.0, expr("x" to 2.0)) } @Test fun testDivide() { - val expr = RealField.mstInField { binaryOperationFunction("/")(symbol("x"), symbol("x")) }.compile() + val expr = RealField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(1.0, expr("x" to 2.0)) } @Test fun testPower() { val expr = RealField - .mstInField { binaryOperationFunction("pow")(symbol("x"), number(2)) } + .mstInField { binaryOperationFunction("pow")(bindSymbol("x"), number(2)) } .compile() assertEquals(4.0, expr("x" to 2.0)) diff --git a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeVariables.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeVariables.kt similarity index 52% rename from kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeVariables.kt rename to kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeVariables.kt index 846120ee2..ee8f4c6f5 100644 --- a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeVariables.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeVariables.kt @@ -1,8 +1,8 @@ -package kscience.kmath.estree +package space.kscience.kmath.estree -import kscience.kmath.ast.mstInRing -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.ByteRing +import space.kscience.kmath.ast.mstInRing +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.ByteRing import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -10,13 +10,13 @@ import kotlin.test.assertFailsWith internal class TestESTreeVariables { @Test fun testVariable() { - val expr = ByteRing.mstInRing { symbol("x") }.compile() + val expr = ByteRing.mstInRing { bindSymbol("x") }.compile() assertEquals(1.toByte(), expr("x" to 1.toByte())) } @Test fun testUndefinedVariableFails() { - val expr = ByteRing.mstInRing { symbol("x") }.compile() + val expr = ByteRing.mstInRing { bindSymbol("x") }.compile() assertFailsWith { expr() } } } diff --git a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/asm.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt similarity index 84% rename from kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/asm.kt rename to kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt index 55cdec243..8875bd715 100644 --- a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/asm.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt @@ -1,13 +1,13 @@ -package kscience.kmath.asm +package space.kscience.kmath.asm -import kscience.kmath.asm.internal.AsmBuilder -import kscience.kmath.asm.internal.buildName -import kscience.kmath.ast.MST -import kscience.kmath.ast.MST.* -import kscience.kmath.ast.MstExpression -import kscience.kmath.expressions.Expression -import kscience.kmath.operations.Algebra -import kscience.kmath.operations.NumericAlgebra +import space.kscience.kmath.asm.internal.AsmBuilder +import space.kscience.kmath.asm.internal.buildName +import space.kscience.kmath.ast.MST +import space.kscience.kmath.ast.MST.* +import space.kscience.kmath.ast.MstExpression +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.operations.Algebra +import space.kscience.kmath.operations.NumericAlgebra /** * Compiles given MST to an Expression using AST compiler. @@ -22,7 +22,7 @@ internal fun MST.compileWith(type: Class, algebra: Algebra): Exp fun AsmBuilder.visit(node: MST): Unit = when (node) { is Symbolic -> { val symbol = try { - algebra.symbol(node.value) + algebra.bindSymbol(node.value) } catch (ignored: IllegalStateException) { null } diff --git a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/AsmBuilder.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt similarity index 94% rename from kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/AsmBuilder.kt rename to kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt index 93d8d1143..a03af5bf9 100644 --- a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/AsmBuilder.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt @@ -1,15 +1,14 @@ -package kscience.kmath.asm.internal +package space.kscience.kmath.asm.internal -import kscience.kmath.asm.internal.AsmBuilder.ClassLoader -import kscience.kmath.ast.MST -import kscience.kmath.expressions.Expression import org.objectweb.asm.* import org.objectweb.asm.Opcodes.* import org.objectweb.asm.Type.* import org.objectweb.asm.commons.InstructionAdapter +import space.kscience.kmath.asm.internal.AsmBuilder.ClassLoader +import space.kscience.kmath.ast.MST +import space.kscience.kmath.expressions.Expression import java.lang.invoke.MethodHandles import java.lang.invoke.MethodType -import java.lang.reflect.Modifier import java.util.stream.Collectors.toMap import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -83,7 +82,7 @@ internal class AsmBuilder( ACC_PUBLIC or ACC_FINAL, "invoke", getMethodDescriptor(tType, MAP_TYPE), - "(L${MAP_TYPE.internalName}<${SYMBOL_TYPE.descriptor}${if (Modifier.isFinal(classOfT.modifiers)) "" else "+"}${tType.descriptor}>;)${tType.descriptor}", + "(L${MAP_TYPE.internalName}<${SYMBOL_TYPE.descriptor}+${tType.descriptor}>;)${tType.descriptor}", null, ).instructionAdapter { invokeMethodVisitor = this @@ -310,7 +309,7 @@ internal class AsmBuilder( /** * ASM type for [Expression]. */ - val EXPRESSION_TYPE: Type by lazy { getObjectType("kscience/kmath/expressions/Expression") } + val EXPRESSION_TYPE: Type by lazy { getObjectType("space/kscience/kmath/expressions/Expression") } /** * ASM type for [java.util.Map]. @@ -335,11 +334,11 @@ internal class AsmBuilder( /** * ASM type for MapIntrinsics. */ - val MAP_INTRINSICS_TYPE: Type by lazy { getObjectType("kscience/kmath/asm/internal/MapIntrinsics") } + val MAP_INTRINSICS_TYPE: Type by lazy { getObjectType("space/kscience/kmath/asm/internal/MapIntrinsics") } /** * ASM Type for [kscience.kmath.expressions.Symbol]. */ - val SYMBOL_TYPE: Type by lazy { getObjectType("kscience/kmath/expressions/Symbol") } + val SYMBOL_TYPE: Type by lazy { getObjectType("space/kscience/kmath/expressions/Symbol") } } } diff --git a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/codegenUtils.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt similarity index 95% rename from kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/codegenUtils.kt rename to kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt index 6d5d19d42..1124a860f 100644 --- a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/codegenUtils.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt @@ -1,9 +1,9 @@ -package kscience.kmath.asm.internal +package space.kscience.kmath.asm.internal -import kscience.kmath.ast.MST -import kscience.kmath.expressions.Expression import org.objectweb.asm.* import org.objectweb.asm.commons.InstructionAdapter +import space.kscience.kmath.ast.MST +import space.kscience.kmath.expressions.Expression import kotlin.contracts.InvocationKind import kotlin.contracts.contract diff --git a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/mapIntrinsics.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt similarity index 64% rename from kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/mapIntrinsics.kt rename to kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt index 588b9611a..f54bc070c 100644 --- a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/mapIntrinsics.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt @@ -1,9 +1,9 @@ @file:JvmName("MapIntrinsics") -package kscience.kmath.asm.internal +package space.kscience.kmath.asm.internal -import kscience.kmath.expressions.StringSymbol -import kscience.kmath.expressions.Symbol +import space.kscience.kmath.expressions.StringSymbol +import space.kscience.kmath.expressions.Symbol /** * Gets value with given [key] or throws [NoSuchElementException] whenever it is not present. diff --git a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/ast/parser.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt similarity index 93% rename from kmath-ast/src/jvmMain/kotlin/kscience/kmath/ast/parser.kt rename to kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt index 0b66e2c31..4d8204383 100644 --- a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/ast/parser.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt @@ -1,6 +1,6 @@ // TODO move to common when https://github.com/h0tk3y/better-parse/pull/33 is merged -package kscience.kmath.ast +package space.kscience.kmath.ast import com.github.h0tk3y.betterParse.combinators.* import com.github.h0tk3y.betterParse.grammar.Grammar @@ -13,10 +13,10 @@ import com.github.h0tk3y.betterParse.lexer.literalToken import com.github.h0tk3y.betterParse.lexer.regexToken import com.github.h0tk3y.betterParse.parser.ParseResult import com.github.h0tk3y.betterParse.parser.Parser -import kscience.kmath.operations.FieldOperations -import kscience.kmath.operations.PowerOperations -import kscience.kmath.operations.RingOperations -import kscience.kmath.operations.SpaceOperations +import space.kscience.kmath.operations.FieldOperations +import space.kscience.kmath.operations.PowerOperations +import space.kscience.kmath.operations.RingOperations +import space.kscience.kmath.operations.SpaceOperations /** * better-parse implementation of grammar defined in the ArithmeticsEvaluator.g4. diff --git a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt similarity index 76% rename from kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt rename to kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt index ae180bf3f..0f2328db6 100644 --- a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt @@ -1,11 +1,11 @@ -package kscience.kmath.asm +package space.kscience.kmath.asm -import kscience.kmath.ast.* -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.ByteRing -import kscience.kmath.operations.ComplexField -import kscience.kmath.operations.RealField -import kscience.kmath.operations.toComplex +import space.kscience.kmath.ast.* +import space.kscience.kmath.complex.ComplexField +import space.kscience.kmath.complex.toComplex +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.ByteRing +import space.kscience.kmath.operations.RealField import kotlin.test.Test import kotlin.test.assertEquals @@ -22,7 +22,7 @@ internal class TestAsmConsistencyWithInterpreter { ), number(1) - ) + symbol("x") + zero + ) + bindSymbol("x") + zero }("x" to MST.Numeric(2)) val res2 = MstSpace.mstInSpace { @@ -35,7 +35,7 @@ internal class TestAsmConsistencyWithInterpreter { ), number(1) - ) + symbol("x") + zero + ) + bindSymbol("x") + zero }.compile()("x" to MST.Numeric(2)) assertEquals(res1, res2) @@ -46,7 +46,7 @@ internal class TestAsmConsistencyWithInterpreter { val res1 = ByteRing.mstInRing { binaryOperationFunction("+")( unaryOperationFunction("+")( - (symbol("x") - (2.toByte() + (multiply( + (bindSymbol("x") - (2.toByte() + (multiply( add(number(1), number(1)), 2 ) + 1.toByte()))) * 3.0 - 1.toByte() @@ -59,7 +59,7 @@ internal class TestAsmConsistencyWithInterpreter { val res2 = ByteRing.mstInRing { binaryOperationFunction("+")( unaryOperationFunction("+")( - (symbol("x") - (2.toByte() + (multiply( + (bindSymbol("x") - (2.toByte() + (multiply( add(number(1), number(1)), 2 ) + 1.toByte()))) * 3.0 - 1.toByte() @@ -75,7 +75,7 @@ internal class TestAsmConsistencyWithInterpreter { fun realField() { val res1 = RealField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( - (3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero @@ -83,7 +83,7 @@ internal class TestAsmConsistencyWithInterpreter { val res2 = RealField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( - (3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero @@ -96,7 +96,7 @@ internal class TestAsmConsistencyWithInterpreter { fun complexField() { val res1 = ComplexField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( - (3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero @@ -104,7 +104,7 @@ internal class TestAsmConsistencyWithInterpreter { val res2 = ComplexField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( - (3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero diff --git a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmOperationsSupport.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt similarity index 50% rename from kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmOperationsSupport.kt rename to kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt index 2ce52aa87..e3adc4629 100644 --- a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmOperationsSupport.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt @@ -1,10 +1,10 @@ -package kscience.kmath.asm +package space.kscience.kmath.asm -import kscience.kmath.ast.mstInExtendedField -import kscience.kmath.ast.mstInField -import kscience.kmath.ast.mstInSpace -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.RealField +import space.kscience.kmath.ast.mstInExtendedField +import space.kscience.kmath.ast.mstInField +import space.kscience.kmath.ast.mstInSpace +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.RealField import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals @@ -12,27 +12,27 @@ import kotlin.test.assertEquals internal class TestAsmOperationsSupport { @Test fun testUnaryOperationInvocation() { - val expression = RealField.mstInSpace { -symbol("x") }.compile() + val expression = RealField.mstInSpace { -bindSymbol("x") }.compile() val res = expression("x" to 2.0) assertEquals(-2.0, res) } @Test fun testBinaryOperationInvocation() { - val expression = RealField.mstInSpace { -symbol("x") + number(1.0) }.compile() + val expression = RealField.mstInSpace { -bindSymbol("x") + number(1.0) }.compile() val res = expression("x" to 2.0) assertEquals(-1.0, res) } @Test fun testConstProductInvocation() { - val res = RealField.mstInField { symbol("x") * 2 }("x" to 2.0) + val res = RealField.mstInField { bindSymbol("x") * 2 }("x" to 2.0) assertEquals(4.0, res) } @Test fun testMultipleCalls() { - val e = RealField.mstInExtendedField { sin(symbol("x")).pow(4) - 6 * symbol("x") / tanh(symbol("x")) }.compile() + val e = RealField.mstInExtendedField { sin(bindSymbol("x")).pow(4) - 6 * bindSymbol("x") / tanh(bindSymbol("x")) }.compile() val r = Random(0) var s = 0.0 repeat(1000000) { s += e("x" to r.nextDouble()) } diff --git a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmSpecialization.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt similarity index 68% rename from kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmSpecialization.kt rename to kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt index 602c54651..a214ca4ad 100644 --- a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmSpecialization.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt @@ -1,52 +1,52 @@ -package kscience.kmath.asm +package space.kscience.kmath.asm -import kscience.kmath.ast.mstInField -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.RealField +import space.kscience.kmath.ast.mstInField +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.RealField import kotlin.test.Test import kotlin.test.assertEquals internal class TestAsmSpecialization { @Test fun testUnaryPlus() { - val expr = RealField.mstInField { unaryOperationFunction("+")(symbol("x")) }.compile() + val expr = RealField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile() assertEquals(2.0, expr("x" to 2.0)) } @Test fun testUnaryMinus() { - val expr = RealField.mstInField { unaryOperationFunction("-")(symbol("x")) }.compile() + val expr = RealField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile() assertEquals(-2.0, expr("x" to 2.0)) } @Test fun testAdd() { - val expr = RealField.mstInField { binaryOperationFunction("+")(symbol("x"), symbol("x")) }.compile() + val expr = RealField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(4.0, expr("x" to 2.0)) } @Test fun testSine() { - val expr = RealField.mstInField { unaryOperationFunction("sin")(symbol("x")) }.compile() + val expr = RealField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile() assertEquals(0.0, expr("x" to 0.0)) } @Test fun testMinus() { - val expr = RealField.mstInField { binaryOperationFunction("-")(symbol("x"), symbol("x")) }.compile() + val expr = RealField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(0.0, expr("x" to 2.0)) } @Test fun testDivide() { - val expr = RealField.mstInField { binaryOperationFunction("/")(symbol("x"), symbol("x")) }.compile() + val expr = RealField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(1.0, expr("x" to 2.0)) } @Test fun testPower() { val expr = RealField - .mstInField { binaryOperationFunction("pow")(symbol("x"), number(2)) } + .mstInField { binaryOperationFunction("pow")(bindSymbol("x"), number(2)) } .compile() assertEquals(4.0, expr("x" to 2.0)) diff --git a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmVariables.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmVariables.kt similarity index 52% rename from kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmVariables.kt rename to kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmVariables.kt index c91568dbf..d1aaefffe 100644 --- a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmVariables.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmVariables.kt @@ -1,8 +1,8 @@ -package kscience.kmath.asm +package space.kscience.kmath.asm -import kscience.kmath.ast.mstInRing -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.ByteRing +import space.kscience.kmath.ast.mstInRing +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.ByteRing import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -10,13 +10,13 @@ import kotlin.test.assertFailsWith internal class TestAsmVariables { @Test fun testVariable() { - val expr = ByteRing.mstInRing { symbol("x") }.compile() + val expr = ByteRing.mstInRing { bindSymbol("x") }.compile() assertEquals(1.toByte(), expr("x" to 1.toByte())) } @Test fun testUndefinedVariableFails() { - val expr = ByteRing.mstInRing { symbol("x") }.compile() + val expr = ByteRing.mstInRing { bindSymbol("x") }.compile() assertFailsWith { expr() } } } diff --git a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/ast/ParserPrecedenceTest.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt similarity index 86% rename from kmath-ast/src/jvmTest/kotlin/kscience/kmath/ast/ParserPrecedenceTest.kt rename to kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt index 561fe51bd..7153f4bfc 100644 --- a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/ast/ParserPrecedenceTest.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt @@ -1,7 +1,7 @@ -package kscience.kmath.ast +package space.kscience.kmath.ast -import kscience.kmath.operations.Field -import kscience.kmath.operations.RealField +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.RealField import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/ast/ParserTest.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt similarity index 81% rename from kmath-ast/src/jvmTest/kotlin/kscience/kmath/ast/ParserTest.kt rename to kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt index 3aa5392c8..6807d5c5d 100644 --- a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/ast/ParserTest.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt @@ -1,10 +1,10 @@ -package kscience.kmath.ast +package space.kscience.kmath.ast -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.Algebra -import kscience.kmath.operations.Complex -import kscience.kmath.operations.ComplexField -import kscience.kmath.operations.RealField +import space.kscience.kmath.complex.Complex +import space.kscience.kmath.complex.ComplexField +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.Algebra +import space.kscience.kmath.operations.RealField import kotlin.test.Test import kotlin.test.assertEquals @@ -40,7 +40,7 @@ internal class ParserTest { @Test fun `evaluate MST with binary function`() { val magicalAlgebra = object : Algebra { - override fun symbol(value: String): String = value + override fun bindSymbol(value: String): String = value override fun unaryOperationFunction(operation: String): (arg: String) -> String { throw NotImplementedError() diff --git a/kmath-commons/build.gradle.kts b/kmath-commons/build.gradle.kts index 6a44c92f2..4fe16605a 100644 --- a/kmath-commons/build.gradle.kts +++ b/kmath-commons/build.gradle.kts @@ -1,12 +1,17 @@ plugins { - id("ru.mipt.npm.jvm") + id("ru.mipt.npm.gradle.jvm") } description = "Commons math binding for kmath" dependencies { api(project(":kmath-core")) + api(project(":kmath-complex")) api(project(":kmath-coroutines")) api(project(":kmath-stat")) api(project(":kmath-functions")) api("org.apache.commons:commons-math3:3.6.1") } + +readme{ + maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL +} \ No newline at end of file diff --git a/kmath-commons/src/main/kotlin/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt similarity index 92% rename from kmath-commons/src/main/kotlin/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt rename to kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt index 2912ddc4c..8342a8071 100644 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt @@ -1,10 +1,10 @@ -package kscience.kmath.commons.expressions +package space.kscience.kmath.commons.expressions -import kscience.kmath.expressions.* -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.ExtendedField -import kscience.kmath.operations.RingWithNumbers import org.apache.commons.math3.analysis.differentiation.DerivativeStructure +import space.kscience.kmath.expressions.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.RingWithNumbers /** * A field over commons-math [DerivativeStructure]. @@ -48,11 +48,11 @@ public class DerivativeStructureField( override fun const(value: Double): DerivativeStructure = DerivativeStructure(numberOfVariables, order, value) - public override fun bindOrNull(symbol: Symbol): DerivativeStructureSymbol? = variables[symbol.identity] + public override fun bindSymbolOrNull(symbol: Symbol): DerivativeStructureSymbol? = variables[symbol.identity] public fun bind(symbol: Symbol): DerivativeStructureSymbol = variables.getValue(symbol.identity) - override fun symbol(value: String): DerivativeStructureSymbol = bind(StringSymbol(value)) + override fun bindSymbol(value: String): DerivativeStructureSymbol = bind(StringSymbol(value)) public fun DerivativeStructure.derivative(symbols: List): Double { require(symbols.size <= order) { "The order of derivative ${symbols.size} exceeds computed order $order" } diff --git a/kmath-commons/src/main/kotlin/kscience/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt similarity index 63% rename from kmath-commons/src/main/kotlin/kscience/kmath/commons/linear/CMMatrix.kt rename to kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt index 850446afa..3638b9808 100644 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/linear/CMMatrix.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt @@ -1,12 +1,9 @@ -package kscience.kmath.commons.linear +package space.kscience.kmath.commons.linear -import kscience.kmath.linear.DiagonalFeature -import kscience.kmath.linear.MatrixContext -import kscience.kmath.linear.Point -import kscience.kmath.linear.origin -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.structures.Matrix import org.apache.commons.math3.linear.* +import space.kscience.kmath.linear.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.structures.RealBuffer import kotlin.reflect.KClass import kotlin.reflect.cast @@ -17,8 +14,40 @@ public inline class CMMatrix(public val origin: RealMatrix) : Matrix { @UnstableKMathAPI override fun getFeature(type: KClass): T? = when (type) { DiagonalFeature::class -> if (origin is DiagonalMatrix) DiagonalFeature else null + + DeterminantFeature::class, LupDecompositionFeature::class -> object : + DeterminantFeature, + LupDecompositionFeature { + private val lup by lazy { LUDecomposition(origin) } + override val determinant: Double by lazy { lup.determinant } + override val l: Matrix by lazy { CMMatrix(lup.l) + LFeature } + override val u: Matrix by lazy { CMMatrix(lup.u) + UFeature } + override val p: Matrix by lazy { CMMatrix(lup.p) } + } + + CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { + override val l: Matrix by lazy { + val cholesky = CholeskyDecomposition(origin) + CMMatrix(cholesky.l) + LFeature + } + } + + QRDecompositionFeature::class -> object : QRDecompositionFeature { + private val qr by lazy { QRDecomposition(origin) } + override val q: Matrix by lazy { CMMatrix(qr.q) + OrthogonalFeature } + override val r: Matrix by lazy { CMMatrix(qr.r) + UFeature } + } + + SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature { + private val sv by lazy { SingularValueDecomposition(origin) } + override val u: Matrix by lazy { CMMatrix(sv.u) } + override val s: Matrix by lazy { CMMatrix(sv.s) } + override val v: Matrix by lazy { CMMatrix(sv.v) } + override val singularValues: Point by lazy { RealBuffer(sv.singularValues) } + } + else -> null - }?.let { type.cast(it) } + }?.let(type::cast) public override operator fun get(i: Int, j: Int): Double = origin.getEntry(i, j) } diff --git a/kmath-commons/src/main/kotlin/kscience/kmath/commons/linear/CMSolver.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt similarity index 90% rename from kmath-commons/src/main/kotlin/kscience/kmath/commons/linear/CMSolver.kt rename to kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt index 210014e1a..3ce7ca9e6 100644 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/linear/CMSolver.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt @@ -1,8 +1,8 @@ -package kscience.kmath.commons.linear +package space.kscience.kmath.commons.linear -import kscience.kmath.linear.Point -import kscience.kmath.structures.Matrix import org.apache.commons.math3.linear.* +import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.linear.Point public enum class CMDecomposition { LUP, diff --git a/kmath-commons/src/main/kotlin/kscience/kmath/commons/optimization/CMOptimizationProblem.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimizationProblem.kt similarity index 93% rename from kmath-commons/src/main/kotlin/kscience/kmath/commons/optimization/CMOptimizationProblem.kt rename to kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimizationProblem.kt index d6f79529a..d655b4f61 100644 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/optimization/CMOptimizationProblem.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimizationProblem.kt @@ -1,10 +1,5 @@ -package kscience.kmath.commons.optimization +package space.kscience.kmath.commons.optimization -import kscience.kmath.expressions.* -import kscience.kmath.stat.OptimizationFeature -import kscience.kmath.stat.OptimizationProblem -import kscience.kmath.stat.OptimizationProblemFactory -import kscience.kmath.stat.OptimizationResult import org.apache.commons.math3.optim.* import org.apache.commons.math3.optim.nonlinear.scalar.GoalType import org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer @@ -14,6 +9,11 @@ import org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjuga import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.AbstractSimplex import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer +import space.kscience.kmath.expressions.* +import space.kscience.kmath.stat.OptimizationFeature +import space.kscience.kmath.stat.OptimizationProblem +import space.kscience.kmath.stat.OptimizationProblemFactory +import space.kscience.kmath.stat.OptimizationResult import kotlin.reflect.KClass public operator fun PointValuePair.component1(): DoubleArray = point diff --git a/kmath-commons/src/main/kotlin/kscience/kmath/commons/optimization/cmFit.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/cmFit.kt similarity index 80% rename from kmath-commons/src/main/kotlin/kscience/kmath/commons/optimization/cmFit.kt rename to kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/cmFit.kt index b8e8bfd4b..5ecd5b756 100644 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/optimization/cmFit.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/cmFit.kt @@ -1,16 +1,16 @@ -package kscience.kmath.commons.optimization +package space.kscience.kmath.commons.optimization -import kscience.kmath.commons.expressions.DerivativeStructureField -import kscience.kmath.expressions.DifferentiableExpression -import kscience.kmath.expressions.Expression -import kscience.kmath.expressions.Symbol -import kscience.kmath.stat.Fitting -import kscience.kmath.stat.OptimizationResult -import kscience.kmath.stat.optimizeWith -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.asBuffer import org.apache.commons.math3.analysis.differentiation.DerivativeStructure import org.apache.commons.math3.optim.nonlinear.scalar.GoalType +import space.kscience.kmath.commons.expressions.DerivativeStructureField +import space.kscience.kmath.expressions.DifferentiableExpression +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.stat.Fitting +import space.kscience.kmath.stat.OptimizationResult +import space.kscience.kmath.stat.optimizeWith +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asBuffer /** * Generate a chi squared expression from given x-y-sigma data and inline model. Provides automatic differentiation diff --git a/kmath-commons/src/main/kotlin/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt similarity index 91% rename from kmath-commons/src/main/kotlin/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt rename to kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt index 1eab5f2bd..3fd98d097 100644 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt @@ -1,6 +1,6 @@ -package kscience.kmath.commons.random +package space.kscience.kmath.commons.random -import kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.RandomGenerator public class CMRandomGeneratorWrapper( public val factory: (IntArray) -> RandomGenerator, diff --git a/kmath-commons/src/main/kotlin/kscience/kmath/commons/transform/Transformations.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/transform/Transformations.kt similarity index 93% rename from kmath-commons/src/main/kotlin/kscience/kmath/commons/transform/Transformations.kt rename to kmath-commons/src/main/kotlin/space/kscience/kmath/commons/transform/Transformations.kt index cd2896be6..e174a237f 100644 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/transform/Transformations.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/transform/Transformations.kt @@ -1,13 +1,13 @@ -package kscience.kmath.commons.transform +package space.kscience.kmath.commons.transform import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map -import kscience.kmath.operations.Complex -import kscience.kmath.streaming.chunked -import kscience.kmath.streaming.spread -import kscience.kmath.structures.* import org.apache.commons.math3.transform.* +import space.kscience.kmath.complex.Complex +import space.kscience.kmath.streaming.chunked +import space.kscience.kmath.streaming.spread +import space.kscience.kmath.structures.* /** diff --git a/kmath-commons/src/test/kotlin/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt similarity index 91% rename from kmath-commons/src/test/kotlin/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt rename to kmath-commons/src/test/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt index 7511a38ed..19b6e28da 100644 --- a/kmath-commons/src/test/kotlin/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt +++ b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt @@ -1,6 +1,6 @@ -package kscience.kmath.commons.expressions +package space.kscience.kmath.commons.expressions -import kscience.kmath.expressions.* +import space.kscience.kmath.expressions.* import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.test.Test @@ -24,7 +24,7 @@ internal class AutoDiffTest { fun derivativeStructureFieldTest() { diff(2, x to 1.0, y to 1.0) { val x = bind(x)//by binding() - val y = symbol("y") + val y = bindSymbol("y") val z = x * (-sin(x * y) + y) + 2.0 println(z.derivative(x)) println(z.derivative(y,x)) diff --git a/kmath-commons/src/test/kotlin/kscience/kmath/commons/optimization/OptimizeTest.kt b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt similarity index 79% rename from kmath-commons/src/test/kotlin/kscience/kmath/commons/optimization/OptimizeTest.kt rename to kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt index 3290c8f32..d29934a4d 100644 --- a/kmath-commons/src/test/kotlin/kscience/kmath/commons/optimization/OptimizeTest.kt +++ b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt @@ -1,12 +1,12 @@ -package kscience.kmath.commons.optimization +package space.kscience.kmath.commons.optimization -import kscience.kmath.commons.expressions.DerivativeStructureExpression -import kscience.kmath.expressions.symbol -import kscience.kmath.stat.Distribution -import kscience.kmath.stat.Fitting -import kscience.kmath.stat.RandomGenerator -import kscience.kmath.stat.normal import org.junit.jupiter.api.Test +import space.kscience.kmath.commons.expressions.DerivativeStructureExpression +import space.kscience.kmath.expressions.symbol +import space.kscience.kmath.stat.Distribution +import space.kscience.kmath.stat.Fitting +import space.kscience.kmath.stat.RandomGenerator +import space.kscience.kmath.stat.normal import kotlin.math.pow internal class OptimizeTest { @@ -56,7 +56,7 @@ internal class OptimizeTest { val yErr = List(x.size) { sigma } val chi2 = Fitting.chiSquared(x, y, yErr) { x1 -> - val cWithDefault = bindOrNull(c) ?: one + val cWithDefault = bindSymbolOrNull(c) ?: one bind(a) * x1.pow(2) + bind(b) * x1 + cWithDefault } diff --git a/kmath-complex/README.md b/kmath-complex/README.md new file mode 100644 index 000000000..71a75bd3e --- /dev/null +++ b/kmath-complex/README.md @@ -0,0 +1,48 @@ +# The Core Module (`kmath-core`) + +Complex and hypercomplex number systems in KMath: + + - [complex](src/commonMain/kotlin/kscience/kmath/complex/Complex.kt) : Complex Numbers + - [quaternion](src/commonMain/kotlin/kscience/kmath/complex/Quaternion.kt) : Quaternions + + +> #### Artifact: +> +> This module artifact: `space.kscience:kmath-complex:0.2.0`. +> +> Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-complex/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-complex/_latestVersion) +> +> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-complex/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-complex/_latestVersion) +> +> **Gradle:** +> +> ```gradle +> repositories { +> maven { url 'https://repo.kotlin.link' } +> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } +> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } // include for builds based on kotlin-eap +>// Uncomment if repo.kotlin.link is unavailable +>// maven { url 'https://dl.bintray.com/mipt-npm/kscience' } +>// maven { url 'https://dl.bintray.com/mipt-npm/dev' } +> } +> +> dependencies { +> implementation 'space.kscience:kmath-complex:0.2.0' +> } +> ``` +> **Gradle Kotlin DSL:** +> +> ```kotlin +> repositories { +> maven("https://repo.kotlin.link") +> maven("https://dl.bintray.com/kotlin/kotlin-eap") // include for builds based on kotlin-eap +> maven("https://dl.bintray.com/hotkeytlt/maven") // required for a +>// Uncomment if repo.kotlin.link is unavailable +>// maven("https://dl.bintray.com/mipt-npm/kscience") +>// maven("https://dl.bintray.com/mipt-npm/dev") +> } +> +> dependencies { +> implementation("space.kscience:kmath-complex:0.2.0") +> } +> ``` diff --git a/kmath-complex/build.gradle.kts b/kmath-complex/build.gradle.kts new file mode 100644 index 000000000..4cd43c70c --- /dev/null +++ b/kmath-complex/build.gradle.kts @@ -0,0 +1,36 @@ +import ru.mipt.npm.gradle.Maturity + +plugins { + id("ru.mipt.npm.gradle.mpp") + id("ru.mipt.npm.gradle.native") +} + +kotlin.sourceSets { + all { + languageSettings.useExperimentalAnnotation("kscience.kmath.misc.UnstableKMathAPI") + } + + commonMain { + dependencies { + api(project(":kmath-core")) + } + } +} + +readme { + description = "Complex numbers and quaternions." + maturity = Maturity.PROTOTYPE + propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) + + feature( + id = "complex", + description = "Complex Numbers", + ref = "src/commonMain/kotlin/kscience/kmath/complex/Complex.kt" + ) + + feature( + id = "quaternion", + description = "Quaternions", + ref = "src/commonMain/kotlin/kscience/kmath/complex/Quaternion.kt" + ) +} diff --git a/kmath-complex/docs/README-TEMPLATE.md b/kmath-complex/docs/README-TEMPLATE.md new file mode 100644 index 000000000..462fd617e --- /dev/null +++ b/kmath-complex/docs/README-TEMPLATE.md @@ -0,0 +1,7 @@ +# The Core Module (`kmath-core`) + +Complex and hypercomplex number systems in KMath: + +${features} + +${artifact} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Complex.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt similarity index 57% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Complex.kt rename to kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt index c6409c015..deadfda5b 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Complex.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt @@ -1,13 +1,17 @@ -package kscience.kmath.operations +package space.kscience.kmath.complex -import kscience.kmath.memory.MemoryReader -import kscience.kmath.memory.MemorySpec -import kscience.kmath.memory.MemoryWriter -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.MemoryBuffer -import kscience.kmath.structures.MutableBuffer -import kscience.kmath.structures.MutableMemoryBuffer +import space.kscience.kmath.memory.MemoryReader +import space.kscience.kmath.memory.MemorySpec +import space.kscience.kmath.memory.MemoryWriter +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.FieldElement +import space.kscience.kmath.operations.Norm +import space.kscience.kmath.operations.RingWithNumbers +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.MemoryBuffer +import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.MutableMemoryBuffer import kotlin.math.* /** @@ -44,72 +48,69 @@ private val PI_DIV_2 = Complex(PI / 2, 0) */ @OptIn(UnstableKMathAPI::class) public object ComplexField : ExtendedField, Norm, RingWithNumbers { - override val zero: Complex = 0.0.toComplex() - override val one: Complex = 1.0.toComplex() + public override val zero: Complex = 0.0.toComplex() + public override val one: Complex = 1.0.toComplex() /** * The imaginary unit. */ - public val i: Complex = Complex(0.0, 1.0) + public val i: Complex by lazy { Complex(0.0, 1.0) } - override fun add(a: Complex, b: Complex): Complex = Complex(a.re + b.re, a.im + b.im) + public override fun add(a: Complex, b: Complex): Complex = Complex(a.re + b.re, a.im + b.im) + public override fun multiply(a: Complex, k: Number): Complex = Complex(a.re * k.toDouble(), a.im * k.toDouble()) - override fun multiply(a: Complex, k: Number): Complex = Complex(a.re * k.toDouble(), a.im * k.toDouble()) - - override fun multiply(a: Complex, b: Complex): Complex = + public override fun multiply(a: Complex, b: Complex): Complex = Complex(a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re) - override fun divide(a: Complex, b: Complex): Complex = when { - b.re.isNaN() || b.im.isNaN() -> Complex(Double.NaN, Double.NaN) - - (if (b.im < 0) -b.im else +b.im) < (if (b.re < 0) -b.re else +b.re) -> { + public override fun divide(a: Complex, b: Complex): Complex = when { + abs(b.im) < abs(b.re) -> { val wr = b.im / b.re val wd = b.re + wr * b.im if (wd.isNaN() || wd == 0.0) - Complex(Double.NaN, Double.NaN) + throw ArithmeticException("Division by zero or infinity") else Complex((a.re + a.im * wr) / wd, (a.im - a.re * wr) / wd) } - b.im == 0.0 -> Complex(Double.NaN, Double.NaN) + b.im == 0.0 -> throw ArithmeticException("Division by zero") else -> { val wr = b.re / b.im val wd = b.im + wr * b.re if (wd.isNaN() || wd == 0.0) - Complex(Double.NaN, Double.NaN) + throw ArithmeticException("Division by zero or infinity") else Complex((a.re * wr + a.im) / wd, (a.im * wr - a.re) / wd) } } - override fun sin(arg: Complex): Complex = i * (exp(-i * arg) - exp(i * arg)) / 2 - override fun cos(arg: Complex): Complex = (exp(-i * arg) + exp(i * arg)) / 2 + public override fun sin(arg: Complex): Complex = i * (exp(-i * arg) - exp(i * arg)) / 2 + public override fun cos(arg: Complex): Complex = (exp(-i * arg) + exp(i * arg)) / 2 - override fun tan(arg: Complex): Complex { + public override fun tan(arg: Complex): Complex { val e1 = exp(-i * arg) val e2 = exp(i * arg) return i * (e1 - e2) / (e1 + e2) } - override fun asin(arg: Complex): Complex = -i * ln(sqrt(1 - (arg * arg)) + i * arg) - override fun acos(arg: Complex): Complex = PI_DIV_2 + i * ln(sqrt(1 - (arg * arg)) + i * arg) + public override fun asin(arg: Complex): Complex = -i * ln(sqrt(1 - (arg * arg)) + i * arg) + public override fun acos(arg: Complex): Complex = PI_DIV_2 + i * ln(sqrt(1 - (arg * arg)) + i * arg) - override fun atan(arg: Complex): Complex { + public override fun atan(arg: Complex): Complex { val iArg = i * arg return i * (ln(1 - iArg) - ln(1 + iArg)) / 2 } - override fun power(arg: Complex, pow: Number): Complex = if (arg.im == 0.0) + public override fun power(arg: Complex, pow: Number): Complex = if (arg.im == 0.0) arg.re.pow(pow.toDouble()).toComplex() else exp(pow * ln(arg)) - override fun exp(arg: Complex): Complex = exp(arg.re) * (cos(arg.im) + i * sin(arg.im)) + public override fun exp(arg: Complex): Complex = exp(arg.re) * (cos(arg.im) + i * sin(arg.im)) - override fun ln(arg: Complex): Complex = ln(arg.r) + i * atan2(arg.im, arg.re) + public override fun ln(arg: Complex): Complex = ln(arg.r) + i * atan2(arg.im, arg.re) /** * Adds complex number to real one. @@ -156,9 +157,9 @@ public object ComplexField : ExtendedField, Norm, Rin */ public operator fun Double.times(c: Complex): Complex = Complex(c.re * this, c.im * this) - override fun norm(arg: Complex): Complex = sqrt(arg.conjugate * arg) + public override fun norm(arg: Complex): Complex = sqrt(arg.conjugate * arg) - override fun symbol(value: String): Complex = if (value == "i") i else super.symbol(value) + public override fun bindSymbol(value: String): Complex = if (value == "i") i else super.bindSymbol(value) } /** @@ -167,30 +168,22 @@ public object ComplexField : ExtendedField, Norm, Rin * @property re The real part. * @property im The imaginary part. */ -public data class Complex(val re: Double, val im: Double) : FieldElement, - Comparable { +@OptIn(UnstableKMathAPI::class) +public data class Complex(val re: Double, val im: Double) : FieldElement { public constructor(re: Number, im: Number) : this(re.toDouble(), im.toDouble()) + public constructor(re: Number) : this(re.toDouble(), 0.0) - override val context: ComplexField get() = ComplexField - - override fun unwrap(): Complex = this - - override fun Complex.wrap(): Complex = this - - override fun compareTo(other: Complex): Int = r.compareTo(other.r) - - override fun toString(): String { - return "($re + i*$im)" - } + public override val context: ComplexField get() = ComplexField + public override fun toString(): String = "($re + i*$im)" public companion object : MemorySpec { - override val objectSize: Int + public override val objectSize: Int get() = 16 - override fun MemoryReader.read(offset: Int): Complex = Complex(readDouble(offset), readDouble(offset + 8)) + public override fun MemoryReader.read(offset: Int): Complex = Complex(readDouble(offset), readDouble(offset + 8)) - override fun MemoryWriter.write(offset: Int, value: Complex) { + public override fun MemoryWriter.write(offset: Int, value: Complex) { writeDouble(offset, value.re) writeDouble(offset + 8, value.im) } @@ -204,7 +197,7 @@ public data class Complex(val re: Double, val im: Double) : FieldElement(shape, ComplexField, Buffer.Companion::complex), + RingWithNumbers>, + ExtendedField> { + + override val zero: NDBuffer by lazy { produce { zero } } + override val one: NDBuffer by lazy { produce { one } } + + override fun number(value: Number): NDBuffer { + val d = value.toComplex() // minimize conversions + return produce { d } + } +// +// @Suppress("OVERRIDE_BY_INLINE") +// override inline fun map( +// arg: AbstractNDBuffer, +// transform: RealField.(Double) -> Double, +// ): RealNDElement { +// check(arg) +// val array = RealBuffer(arg.strides.linearSize) { offset -> RealField.transform(arg.buffer[offset]) } +// return BufferedNDFieldElement(this, array) +// } +// +// @Suppress("OVERRIDE_BY_INLINE") +// override inline fun produce(initializer: RealField.(IntArray) -> Double): RealNDElement { +// val array = RealBuffer(strides.linearSize) { offset -> elementContext.initializer(strides.index(offset)) } +// return BufferedNDFieldElement(this, array) +// } +// +// @Suppress("OVERRIDE_BY_INLINE") +// override inline fun mapIndexed( +// arg: AbstractNDBuffer, +// transform: RealField.(index: IntArray, Double) -> Double, +// ): RealNDElement { +// check(arg) +// return BufferedNDFieldElement( +// this, +// RealBuffer(arg.strides.linearSize) { offset -> +// elementContext.transform( +// arg.strides.index(offset), +// arg.buffer[offset] +// ) +// }) +// } +// +// @Suppress("OVERRIDE_BY_INLINE") +// override inline fun combine( +// a: AbstractNDBuffer, +// b: AbstractNDBuffer, +// transform: RealField.(Double, Double) -> Double, +// ): RealNDElement { +// check(a, b) +// val buffer = RealBuffer(strides.linearSize) { offset -> +// elementContext.transform(a.buffer[offset], b.buffer[offset]) +// } +// return BufferedNDFieldElement(this, buffer) +// } + + override fun power(arg: NDStructure, pow: Number): NDBuffer = arg.map() { power(it, pow) } + + override fun exp(arg: NDStructure): NDBuffer = arg.map() { exp(it) } + + override fun ln(arg: NDStructure): NDBuffer = arg.map() { ln(it) } + + override fun sin(arg: NDStructure): NDBuffer = arg.map() { sin(it) } + override fun cos(arg: NDStructure): NDBuffer = arg.map() { cos(it) } + override fun tan(arg: NDStructure): NDBuffer = arg.map() { tan(it) } + override fun asin(arg: NDStructure): NDBuffer = arg.map() { asin(it) } + override fun acos(arg: NDStructure): NDBuffer = arg.map() { acos(it) } + override fun atan(arg: NDStructure): NDBuffer = arg.map() { atan(it) } + + override fun sinh(arg: NDStructure): NDBuffer = arg.map() { sinh(it) } + override fun cosh(arg: NDStructure): NDBuffer = arg.map() { cosh(it) } + override fun tanh(arg: NDStructure): NDBuffer = arg.map() { tanh(it) } + override fun asinh(arg: NDStructure): NDBuffer = arg.map() { asinh(it) } + override fun acosh(arg: NDStructure): NDBuffer = arg.map() { acosh(it) } + override fun atanh(arg: NDStructure): NDBuffer = arg.map() { atanh(it) } +} + + +/** + * Fast element production using function inlining + */ +public inline fun BufferedNDField.produceInline(initializer: ComplexField.(Int) -> Complex): NDBuffer { + contract { callsInPlace(initializer, InvocationKind.EXACTLY_ONCE) } + val buffer = Buffer.complex(strides.linearSize) { offset -> ComplexField.initializer(offset) } + return NDBuffer(strides, buffer) +} + + +public fun NDAlgebra.Companion.complex(vararg shape: Int): ComplexNDField = ComplexNDField(shape) + +/** + * Produce a context for n-dimensional operations inside this real field + */ +public inline fun ComplexField.nd(vararg shape: Int, action: ComplexNDField.() -> R): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return ComplexNDField(shape).action() +} diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt new file mode 100644 index 000000000..4a15e7423 --- /dev/null +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt @@ -0,0 +1,263 @@ +package space.kscience.kmath.complex + +import space.kscience.kmath.memory.MemoryReader +import space.kscience.kmath.memory.MemorySpec +import space.kscience.kmath.memory.MemoryWriter +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.MemoryBuffer +import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.MutableMemoryBuffer +import kotlin.math.* + +/** + * This quaternion's conjugate. + */ +public val Quaternion.conjugate: Quaternion + get() = QuaternionField { z - x * i - y * j - z * k } + +/** + * This quaternion's reciprocal. + */ +public val Quaternion.reciprocal: Quaternion + get() { + val n = QuaternionField { norm(this@reciprocal) } + return conjugate / (n * n) + } + +/** + * Absolute value of the quaternion. + */ +public val Quaternion.r: Double + get() = sqrt(w * w + x * x + y * y + z * z) + +/** + * A field of [Quaternion]. + */ +@OptIn(UnstableKMathAPI::class) +public object QuaternionField : Field, Norm, PowerOperations, + ExponentialOperations, RingWithNumbers { + override val zero: Quaternion = 0.toQuaternion() + override val one: Quaternion = 1.toQuaternion() + + /** + * The `i` quaternion unit. + */ + public val i: Quaternion = Quaternion(0, 1) + + /** + * The `j` quaternion unit. + */ + public val j: Quaternion = Quaternion(0, 0, 1) + + /** + * The `k` quaternion unit. + */ + public val k: Quaternion = Quaternion(0, 0, 0, 1) + + public override fun add(a: Quaternion, b: Quaternion): Quaternion = + Quaternion(a.w + b.w, a.x + b.x, a.y + b.y, a.z + b.z) + + public override fun multiply(a: Quaternion, k: Number): Quaternion { + val d = k.toDouble() + return Quaternion(a.w * d, a.x * d, a.y * d, a.z * d) + } + + public override fun multiply(a: Quaternion, b: Quaternion): Quaternion = Quaternion( + a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z, + a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y, + a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x, + a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w, + ) + + public override fun divide(a: Quaternion, b: Quaternion): Quaternion { + val s = b.w * b.w + b.x * b.x + b.y * b.y + b.z * b.z + + return Quaternion( + (b.w * a.w + b.x * a.x + b.y * a.y + b.z * a.z) / s, + (b.w * a.x - b.x * a.w - b.y * a.z + b.z * a.y) / s, + (b.w * a.y + b.x * a.z - b.y * a.w - b.z * a.x) / s, + (b.w * a.z - b.x * a.y + b.y * a.x - b.z * a.w) / s, + ) + } + + public override fun power(arg: Quaternion, pow: Number): Quaternion { + if (pow is Int) return pwr(arg, pow) + if (floor(pow.toDouble()) == pow.toDouble()) return pwr(arg, pow.toInt()) + return exp(pow * ln(arg)) + } + + private fun pwr(x: Quaternion, a: Int): Quaternion = when { + a < 0 -> -(pwr(x, -a)) + a == 0 -> one + a == 1 -> x + a == 2 -> pwr2(x) + a == 3 -> pwr3(x) + a == 4 -> pwr4(x) + + else -> { + val x4 = pwr4(x) + var y = x4 + repeat((1 until a / 4).count()) { y *= x4 } + if (a % 4 == 3) y *= pwr3(x) + if (a % 4 == 2) y *= pwr2(x) + if (a % 4 == 1) y *= x + y + } + } + + private fun pwr2(x: Quaternion): Quaternion { + val aa = 2 * x.w + return Quaternion(x.w * x.w - (x.x * x.x + x.y * x.y + x.z * x.z), aa * x.x, aa * x.y, aa * x.z) + } + + private fun pwr3(x: Quaternion): Quaternion { + val a2 = x.w * x.w + val n1 = x.x * x.x + x.y * x.y + x.z * x.z + val n2 = 3.0 * a2 - n1 + return Quaternion(x.w * (a2 - 3 * n1), x.x * n2, x.y * n2, x.z * n2) + } + + private fun pwr4(x: Quaternion): Quaternion { + val a2 = x.w * x.w + val n1 = x.x * x.x + x.y * x.y + x.z * x.z + val n2 = 4 * x.w * (a2 - n1) + return Quaternion(a2 * a2 - 6 * a2 * n1 + n1 * n1, x.x * n2, x.y * n2, x.z * n2) + } + + public override fun exp(arg: Quaternion): Quaternion { + val un = arg.x * arg.x + arg.y * arg.y + arg.z * arg.z + if (un == 0.0) return exp(arg.w).toQuaternion() + val n1 = sqrt(un) + val ea = exp(arg.w) + val n2 = ea * sin(n1) / n1 + return Quaternion(ea * cos(n1), n2 * arg.x, n2 * arg.y, n2 * arg.z) + } + + public override fun ln(arg: Quaternion): Quaternion { + val nu2 = arg.x * arg.x + arg.y * arg.y + arg.z * arg.z + + if (nu2 == 0.0) + return if (arg.w > 0) + Quaternion(ln(arg.w), 0, 0, 0) + else { + val l = ComplexField { ComplexField.ln(arg.w.toComplex()) } + Quaternion(l.re, l.im, 0, 0) + } + + val a = arg.w + check(nu2 > 0) + val n = sqrt(a * a + nu2) + val th = acos(a / n) / sqrt(nu2) + return Quaternion(ln(n), th * arg.x, th * arg.y, th * arg.z) + } + + public override operator fun Number.plus(b: Quaternion): Quaternion = Quaternion(toDouble() + b.w, b.x, b.y, b.z) + + public override operator fun Number.minus(b: Quaternion): Quaternion = + Quaternion(toDouble() - b.w, -b.x, -b.y, -b.z) + + public override operator fun Quaternion.plus(b: Number): Quaternion = Quaternion(w + b.toDouble(), x, y, z) + public override operator fun Quaternion.minus(b: Number): Quaternion = Quaternion(w - b.toDouble(), x, y, z) + + public override operator fun Number.times(b: Quaternion): Quaternion = + Quaternion(toDouble() * b.w, toDouble() * b.x, toDouble() * b.y, toDouble() * b.z) + + public override fun Quaternion.unaryMinus(): Quaternion = Quaternion(-w, -x, -y, -z) + public override fun norm(arg: Quaternion): Quaternion = sqrt(arg.conjugate * arg) + + public override fun bindSymbol(value: String): Quaternion = when (value) { + "i" -> i + "j" -> j + "k" -> k + else -> super.bindSymbol(value) + } +} + +/** + * Represents `double`-based quaternion. + * + * @property w The first component. + * @property x The second component. + * @property y The third component. + * @property z The fourth component. + */ +@OptIn(UnstableKMathAPI::class) +public data class Quaternion( + val w: Double, val x: Double, val y: Double, val z: Double, +) : FieldElement { + public constructor(w: Number, x: Number, y: Number, z: Number) : this( + w.toDouble(), + x.toDouble(), + y.toDouble(), + z.toDouble(), + ) + + public constructor(w: Number, x: Number, y: Number) : this(w.toDouble(), x.toDouble(), y.toDouble(), 0.0) + public constructor(w: Number, x: Number) : this(w.toDouble(), x.toDouble(), 0.0, 0.0) + public constructor(w: Number) : this(w.toDouble(), 0.0, 0.0, 0.0) + public constructor(wx: Complex, yz: Complex) : this(wx.re, wx.im, yz.re, yz.im) + public constructor(wx: Complex) : this(wx.re, wx.im, 0, 0) + + init { + require(!w.isNaN()) { "w-component of quaternion is not-a-number" } + require(!x.isNaN()) { "x-component of quaternion is not-a-number" } + require(!y.isNaN()) { "x-component of quaternion is not-a-number" } + require(!z.isNaN()) { "x-component of quaternion is not-a-number" } + } + + public override val context: QuaternionField + get() = QuaternionField + + /** + * Returns a string representation of this quaternion. + */ + public override fun toString(): String = "($w + $x * i + $y * j + $z * k)" + + public companion object : MemorySpec { + public override val objectSize: Int + get() = 32 + + public override fun MemoryReader.read(offset: Int): Quaternion = + Quaternion(readDouble(offset), readDouble(offset + 8), readDouble(offset + 16), readDouble(offset + 24)) + + public override fun MemoryWriter.write(offset: Int, value: Quaternion) { + writeDouble(offset, value.w) + writeDouble(offset + 8, value.x) + writeDouble(offset + 16, value.y) + writeDouble(offset + 24, value.z) + } + } +} + +/** + * Creates a quaternion with real part equal to this real. + * + * @receiver the real part. + * @return a new quaternion. + */ +public fun Number.toQuaternion(): Quaternion = Quaternion(this) + +/** + * Creates a quaternion with `w`-component equal to `re`-component of given complex and `x`-component equal to + * `im`-component of given complex. + * + * @receiver the complex number. + * @return a new quaternion. + */ +public fun Complex.toQuaternion(): Quaternion = Quaternion(this) + +/** + * Creates a new buffer of quaternions with the specified [size], where each element is calculated by calling the + * specified [init] function. + */ +public inline fun Buffer.Companion.quaternion(size: Int, init: (Int) -> Quaternion): Buffer = + MemoryBuffer.create(Quaternion, size, init) + +/** + * Creates a new buffer of quaternions with the specified [size], where each element is calculated by calling the + * specified [init] function. + */ +public inline fun MutableBuffer.Companion.quaternion(size: Int, init: (Int) -> Quaternion): MutableBuffer = + MutableMemoryBuffer.create(Quaternion, size, init) diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/ComplexBufferSpecTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt similarity index 69% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/structures/ComplexBufferSpecTest.kt rename to kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt index 4837236db..e265e5896 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/ComplexBufferSpecTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt @@ -1,7 +1,6 @@ -package kscience.kmath.structures +package space.kscience.kmath.complex -import kscience.kmath.operations.Complex -import kscience.kmath.operations.complex +import space.kscience.kmath.structures.Buffer import kotlin.test.Test import kotlin.test.assertEquals @@ -11,4 +10,4 @@ class ComplexBufferSpecTest { val buffer = Buffer.complex(20) { Complex(it.toDouble(), -it.toDouble()) } assertEquals(Complex(5.0, -5.0), buffer[5]) } -} +} \ No newline at end of file diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexFieldTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt similarity index 84% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexFieldTest.kt rename to kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt index c0b4853f4..e00b92077 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexFieldTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt @@ -1,6 +1,6 @@ -package kscience.kmath.operations +package space.kscience.kmath.complex -import kscience.kmath.operations.internal.FieldVerifier +import space.kscience.kmath.operations.invoke import kotlin.math.PI import kotlin.math.abs import kotlin.test.Test @@ -8,8 +8,9 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue internal class ComplexFieldTest { - @Test - fun verify() = ComplexField { FieldVerifier(this, 42.0 * i, 66.0 + 28 * i, 2.0 + 0 * i, 5).verify() } + // TODO make verifier classes available in this source set + // @Test + // fun verify() = ComplexField { FieldVerifier(this, 42.0 * i, 66.0 + 28 * i, 2.0 + 0 * i, 5).verify() } @Test fun testAddition() { @@ -37,8 +38,6 @@ internal class ComplexFieldTest { assertEquals(Complex(42, 42), ComplexField { Complex(0, 168) / Complex(2, 2) }) assertEquals(Complex(42, 56), ComplexField { Complex(86, 56) - 44 }) assertEquals(Complex(42, 56), ComplexField { 86 - Complex(44, -56) }) - assertEquals(Complex(Double.NaN, Double.NaN), ComplexField { Complex(1, 1) / Complex(Double.NaN, Double.NaN) }) - assertEquals(Complex(Double.NaN, Double.NaN), ComplexField { Complex(1, 1) / Complex(0, 0) }) } @Test diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt new file mode 100644 index 000000000..e272f502f --- /dev/null +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt @@ -0,0 +1,31 @@ +package space.kscience.kmath.complex + +import space.kscience.kmath.operations.invoke +import kotlin.math.sqrt +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +internal class ComplexTest { + @Test + fun conjugate() = ComplexField { assertEquals(Complex(0, 42), Complex(0, -42).conjugate) } + + @Test + fun reciprocal() = ComplexField { assertTrue((Complex(0.5, -0.0) - 2.toComplex().reciprocal).r < 1e-10) } + + @Test + fun r() = ComplexField { assertEquals(sqrt(2.0), (i + 1.0.toComplex()).r) } + + @Test + fun theta() = assertEquals(0.0, 1.toComplex().theta) + + @Test + fun toComplex() { + assertEquals(Complex(42), 42.toComplex()) + assertEquals(Complex(42.0), 42.0.toComplex()) + assertEquals(Complex(42f), 42f.toComplex()) + assertEquals(Complex(42.0), 42.0.toComplex()) + assertEquals(Complex(42.toByte()), 42.toByte().toComplex()) + assertEquals(Complex(42.toShort()), 42.toShort().toComplex()) + } +} diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ExpressionFieldForComplexTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ExpressionFieldForComplexTest.kt new file mode 100644 index 000000000..43560b35a --- /dev/null +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ExpressionFieldForComplexTest.kt @@ -0,0 +1,26 @@ +package space.kscience.kmath.complex + +import space.kscience.kmath.expressions.FunctionalExpressionField +import space.kscience.kmath.expressions.bindSymbol +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.expressions.symbol +import space.kscience.kmath.operations.invoke +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class ExpressionFieldForComplexTest { + val x by symbol + + @Test + fun testComplex() { + val context = FunctionalExpressionField(ComplexField) + + val expression = context { + val x = bindSymbol(x) + x * x + 2 * x + one + } + + assertEquals(expression(x to Complex(1.0, 0.0)), Complex(4.0, 0.0)) + //assertEquals(expression(), Complex(9.0, 0.0)) + } +} diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionFieldTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionFieldTest.kt new file mode 100644 index 000000000..5ce81a251 --- /dev/null +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionFieldTest.kt @@ -0,0 +1,45 @@ +package space.kscience.kmath.complex + +import space.kscience.kmath.operations.invoke +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class QuaternionFieldTest { + @Test + fun testAddition() { + assertEquals(Quaternion(42, 42), QuaternionField { Quaternion(16, 16) + Quaternion(26, 26) }) + assertEquals(Quaternion(42, 16), QuaternionField { Quaternion(16, 16) + 26 }) + assertEquals(Quaternion(42, 16), QuaternionField { 26 + Quaternion(16, 16) }) + } + +// @Test +// fun testSubtraction() { +// assertEquals(Quaternion(42, 42), QuaternionField { Quaternion(86, 55) - Quaternion(44, 13) }) +// assertEquals(Quaternion(42, 56), QuaternionField { Quaternion(86, 56) - 44 }) +// assertEquals(Quaternion(42, 56), QuaternionField { 86 - Quaternion(44, -56) }) +// } + + @Test + fun testMultiplication() { + assertEquals(Quaternion(42, 42), QuaternionField { Quaternion(4.2, 0) * Quaternion(10, 10) }) + assertEquals(Quaternion(42, 21), QuaternionField { Quaternion(4.2, 2.1) * 10 }) + assertEquals(Quaternion(42, 21), QuaternionField { 10 * Quaternion(4.2, 2.1) }) + } + +// @Test +// fun testDivision() { +// assertEquals(Quaternion(42, 42), QuaternionField { Quaternion(0, 168) / Quaternion(2, 2) }) +// assertEquals(Quaternion(42, 56), QuaternionField { Quaternion(86, 56) - 44 }) +// assertEquals(Quaternion(42, 56) , QuaternionField { 86 - Quaternion(44, -56) }) +// } + + @Test + fun testPower() { + assertEquals(QuaternionField.zero, QuaternionField { zero pow 2 }) + assertEquals(QuaternionField.zero, QuaternionField { zero pow 2 }) + + assertEquals( + QuaternionField { i * 8 }.let { it.x.toInt() to it.w.toInt() }, + QuaternionField { Quaternion(2, 2) pow 2 }.let { it.x.toInt() to it.w.toInt() }) + } +} diff --git a/kmath-core/README.md b/kmath-core/README.md index 1ee19107b..54380670d 100644 --- a/kmath-core/README.md +++ b/kmath-core/README.md @@ -2,17 +2,20 @@ 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 + - [algebras](src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Algebraic structures like rings, spaces and fields. + - [nd](src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Many-dimensional structures and operations on them. + - [linear](src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : Basic linear algebra operations (sums, products, etc.), backed by the `Space` API. Advanced linear algebra operations like matrix inversion and LU decomposition. - [buffers](src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : One-dimensional structure - - [expressions](src/commonMain/kotlin/kscience/kmath/expressions) : Functional Expressions + - [expressions](src/commonMain/kotlin/kscience/kmath/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. - [domains](src/commonMain/kotlin/kscience/kmath/domains) : Domains - [autodif](src/commonMain/kotlin/kscience/kmath/expressions/SimpleAutoDiff.kt) : Automatic differentiation > #### Artifact: > -> This module artifact: `kscience.kmath:kmath-core:0.2.0-dev-5`. +> This module artifact: `space.kscience:kmath-core:0.2.0`. > > 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) > @@ -22,28 +25,31 @@ The core features of KMath: > > ```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://repo.kotlin.link' } > maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> +> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } // include for builds based on kotlin-eap +>// Uncomment if repo.kotlin.link is unavailable +>// maven { url 'https://dl.bintray.com/mipt-npm/kscience' } +>// maven { url 'https://dl.bintray.com/mipt-npm/dev' } > } > > dependencies { -> implementation 'kscience.kmath:kmath-core:0.2.0-dev-5' +> implementation 'space.kscience:kmath-core:0.2.0' > } > ``` > **Gradle Kotlin DSL:** > > ```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") +> maven("https://repo.kotlin.link") +> maven("https://dl.bintray.com/kotlin/kotlin-eap") // include for builds based on kotlin-eap +> maven("https://dl.bintray.com/hotkeytlt/maven") // required for a +>// Uncomment if repo.kotlin.link is unavailable +>// maven("https://dl.bintray.com/mipt-npm/kscience") +>// maven("https://dl.bintray.com/mipt-npm/dev") > } > > dependencies { -> implementation("kscience.kmath:kmath-core:0.2.0-dev-5") +> implementation("space.kscience:kmath-core:0.2.0") > } > ``` diff --git a/kmath-core/api/kmath-core.api b/kmath-core/api/kmath-core.api new file mode 100644 index 000000000..4a21a3d7e --- /dev/null +++ b/kmath-core/api/kmath-core.api @@ -0,0 +1,2974 @@ +public abstract interface class space/kscience/kmath/domains/Domain { + public abstract fun contains (Lspace/kscience/kmath/structures/Buffer;)Z + public abstract fun getDimension ()I +} + +public final class space/kscience/kmath/domains/HyperSquareDomain : space/kscience/kmath/domains/RealDomain { + public fun (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)V + public fun contains (Lspace/kscience/kmath/structures/Buffer;)Z + public fun getDimension ()I + public fun getLowerBound (I)Ljava/lang/Double; + public fun getLowerBound (ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public fun getUpperBound (I)Ljava/lang/Double; + public fun getUpperBound (ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public fun nearestInDomain (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun volume ()D +} + +public abstract interface class space/kscience/kmath/domains/RealDomain : space/kscience/kmath/domains/Domain { + public abstract fun getLowerBound (I)Ljava/lang/Double; + public abstract fun getLowerBound (ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public abstract fun getUpperBound (I)Ljava/lang/Double; + public abstract fun getUpperBound (ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public abstract fun nearestInDomain (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun volume ()D +} + +public final class space/kscience/kmath/domains/UnconstrainedDomain : space/kscience/kmath/domains/RealDomain { + public fun (I)V + public fun contains (Lspace/kscience/kmath/structures/Buffer;)Z + public fun getDimension ()I + public fun getLowerBound (I)Ljava/lang/Double; + public fun getLowerBound (ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public fun getUpperBound (I)Ljava/lang/Double; + public fun getUpperBound (ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public fun nearestInDomain (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun volume ()D +} + +public final class space/kscience/kmath/domains/UnivariateDomain : space/kscience/kmath/domains/RealDomain { + public static final synthetic fun box-impl (Lkotlin/ranges/ClosedFloatingPointRange;)Lspace/kscience/kmath/domains/UnivariateDomain; + public static fun constructor-impl (Lkotlin/ranges/ClosedFloatingPointRange;)Lkotlin/ranges/ClosedFloatingPointRange; + public fun contains (Lspace/kscience/kmath/structures/Buffer;)Z + public static final fun contains-impl (Lkotlin/ranges/ClosedFloatingPointRange;D)Z + public static fun contains-impl (Lkotlin/ranges/ClosedFloatingPointRange;Lspace/kscience/kmath/structures/Buffer;)Z + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Lkotlin/ranges/ClosedFloatingPointRange;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Lkotlin/ranges/ClosedFloatingPointRange;Lkotlin/ranges/ClosedFloatingPointRange;)Z + public fun getDimension ()I + public static fun getDimension-impl (Lkotlin/ranges/ClosedFloatingPointRange;)I + public fun getLowerBound (I)Ljava/lang/Double; + public fun getLowerBound (ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public static fun getLowerBound-impl (Lkotlin/ranges/ClosedFloatingPointRange;I)Ljava/lang/Double; + public static fun getLowerBound-impl (Lkotlin/ranges/ClosedFloatingPointRange;ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public final fun getRange ()Lkotlin/ranges/ClosedFloatingPointRange; + public fun getUpperBound (I)Ljava/lang/Double; + public fun getUpperBound (ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public static fun getUpperBound-impl (Lkotlin/ranges/ClosedFloatingPointRange;I)Ljava/lang/Double; + public static fun getUpperBound-impl (Lkotlin/ranges/ClosedFloatingPointRange;ILspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public fun hashCode ()I + public static fun hashCode-impl (Lkotlin/ranges/ClosedFloatingPointRange;)I + public fun nearestInDomain (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun nearestInDomain-impl (Lkotlin/ranges/ClosedFloatingPointRange;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Lkotlin/ranges/ClosedFloatingPointRange;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Lkotlin/ranges/ClosedFloatingPointRange; + public fun volume ()D + public static fun volume-impl (Lkotlin/ranges/ClosedFloatingPointRange;)D +} + +public abstract interface class space/kscience/kmath/expressions/AutoDiffProcessor { + public abstract fun process (Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/DifferentiableExpression; +} + +public class space/kscience/kmath/expressions/AutoDiffValue { + public fun (Ljava/lang/Object;)V + public final fun getValue ()Ljava/lang/Object; +} + +public final class space/kscience/kmath/expressions/DerivationResult { + public fun (Ljava/lang/Object;Ljava/util/Map;Lspace/kscience/kmath/operations/Field;)V + public final fun derivative (Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public final fun div ()Ljava/lang/Object; + public final fun getContext ()Lspace/kscience/kmath/operations/Field; + public final fun getValue ()Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/expressions/DifferentiableExpression : space/kscience/kmath/expressions/Expression { + public abstract fun derivativeOrNull (Ljava/util/List;)Lspace/kscience/kmath/expressions/Expression; +} + +public final class space/kscience/kmath/expressions/DifferentiableExpressionKt { + public static final fun derivative (Lspace/kscience/kmath/expressions/DifferentiableExpression;Ljava/lang/String;)Lspace/kscience/kmath/expressions/Expression; + public static final fun derivative (Lspace/kscience/kmath/expressions/DifferentiableExpression;Ljava/util/List;)Lspace/kscience/kmath/expressions/Expression; + public static final fun derivative (Lspace/kscience/kmath/expressions/DifferentiableExpression;[Lspace/kscience/kmath/expressions/Symbol;)Lspace/kscience/kmath/expressions/Expression; +} + +public abstract interface class space/kscience/kmath/expressions/Expression { + public abstract fun invoke (Ljava/util/Map;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/expressions/ExpressionAlgebra : space/kscience/kmath/operations/Algebra { + public abstract fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public abstract fun bindSymbolOrNull (Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public abstract fun const (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/expressions/ExpressionAlgebra$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/expressions/ExpressionBuildersKt { + public static final fun extendedFieldExpression (Lspace/kscience/kmath/operations/ExtendedField;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; + public static final fun fieldExpression (Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; + public static final fun ringExpression (Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; + public static final fun spaceExpression (Lspace/kscience/kmath/operations/Space;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; +} + +public final class space/kscience/kmath/expressions/ExpressionKt { + public static final fun bindSymbol (Lspace/kscience/kmath/expressions/ExpressionAlgebra;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static final fun binding (Lspace/kscience/kmath/expressions/ExpressionAlgebra;)Lkotlin/properties/ReadOnlyProperty; + public static final fun callByString (Lspace/kscience/kmath/expressions/Expression;[Lkotlin/Pair;)Ljava/lang/Object; + public static final fun callBySymbol (Lspace/kscience/kmath/expressions/Expression;[Lkotlin/Pair;)Ljava/lang/Object; + public static final fun getSymbol ()Lkotlin/properties/ReadOnlyProperty; + public static final fun invoke (Lspace/kscience/kmath/expressions/Expression;)Ljava/lang/Object; +} + +public abstract class space/kscience/kmath/expressions/FirstDerivativeExpression : space/kscience/kmath/expressions/DifferentiableExpression { + public fun ()V + public final fun derivativeOrNull (Ljava/util/List;)Lspace/kscience/kmath/expressions/Expression; + public abstract fun derivativeOrNull (Lspace/kscience/kmath/expressions/Symbol;)Lspace/kscience/kmath/expressions/Expression; +} + +public abstract class space/kscience/kmath/expressions/FunctionalExpressionAlgebra : space/kscience/kmath/expressions/ExpressionAlgebra { + public fun (Lspace/kscience/kmath/operations/Algebra;)V + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/Expression;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun bindSymbolOrNull (Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public fun bindSymbolOrNull (Lspace/kscience/kmath/expressions/Symbol;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun const (Ljava/lang/Object;)Ljava/lang/Object; + public fun const (Ljava/lang/Object;)Lspace/kscience/kmath/expressions/Expression; + public final fun getAlgebra ()Lspace/kscience/kmath/operations/Algebra; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/expressions/FunctionalExpressionAlgebraKt { + public static final fun expressionInExtendedField (Lspace/kscience/kmath/operations/ExtendedField;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; + public static final fun expressionInField (Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; + public static final fun expressionInRing (Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; + public static final fun expressionInSpace (Lspace/kscience/kmath/operations/Space;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; +} + +public class space/kscience/kmath/expressions/FunctionalExpressionExtendedField : space/kscience/kmath/expressions/FunctionalExpressionField, space/kscience/kmath/operations/ExtendedField { + public fun (Lspace/kscience/kmath/operations/ExtendedField;)V + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/Expression; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public class space/kscience/kmath/expressions/FunctionalExpressionField : space/kscience/kmath/expressions/FunctionalExpressionRing, space/kscience/kmath/operations/Field { + public fun (Lspace/kscience/kmath/operations/Field;)V + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/lang/Number;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public final fun div (Ljava/lang/Object;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public final fun div (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Object;)Lspace/kscience/kmath/expressions/Expression; + public fun div (Lspace/kscience/kmath/expressions/Expression;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Lspace/kscience/kmath/expressions/Expression;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public class space/kscience/kmath/expressions/FunctionalExpressionRing : space/kscience/kmath/expressions/FunctionalExpressionSpace, space/kscience/kmath/operations/Ring { + public fun (Lspace/kscience/kmath/operations/Ring;)V + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/expressions/Expression; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/expressions/Expression;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public final fun times (Ljava/lang/Object;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public final fun times (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Object;)Lspace/kscience/kmath/expressions/Expression; + public fun times (Lspace/kscience/kmath/expressions/Expression;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public class space/kscience/kmath/expressions/FunctionalExpressionSpace : space/kscience/kmath/expressions/FunctionalExpressionAlgebra, space/kscience/kmath/operations/Space { + public fun (Lspace/kscience/kmath/operations/Space;)V + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/expressions/Expression;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/expressions/Expression; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public final fun minus (Ljava/lang/Object;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public final fun minus (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Object;)Lspace/kscience/kmath/expressions/Expression; + public fun minus (Lspace/kscience/kmath/expressions/Expression;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public final fun plus (Ljava/lang/Object;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public final fun plus (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Object;)Lspace/kscience/kmath/expressions/Expression; + public fun plus (Lspace/kscience/kmath/expressions/Expression;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/Expression; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; +} + +public final class space/kscience/kmath/expressions/SimpleAutoDiffExpression : space/kscience/kmath/expressions/FirstDerivativeExpression { + public fun (Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)V + public fun derivativeOrNull (Lspace/kscience/kmath/expressions/Symbol;)Lspace/kscience/kmath/expressions/Expression; + public final fun getField ()Lspace/kscience/kmath/operations/Field; + public final fun getFunction ()Lkotlin/jvm/functions/Function1; + public fun invoke (Ljava/util/Map;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/expressions/SimpleAutoDiffExtendedField : space/kscience/kmath/expressions/SimpleAutoDiffField, space/kscience/kmath/operations/ExtendedField { + public fun (Lspace/kscience/kmath/operations/ExtendedField;Ljava/util/Map;)V + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public final fun pow (Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (Lspace/kscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public final fun sqr (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public class space/kscience/kmath/expressions/SimpleAutoDiffField : space/kscience/kmath/expressions/ExpressionAlgebra, space/kscience/kmath/operations/Field, space/kscience/kmath/operations/RingWithNumbers { + public fun (Lspace/kscience/kmath/operations/Field;Ljava/util/Map;)V + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun bindSymbolOrNull (Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public fun bindSymbolOrNull (Lspace/kscience/kmath/expressions/Symbol;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun const (Ljava/lang/Object;)Ljava/lang/Object; + public fun const (Ljava/lang/Object;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public final fun const (Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public final fun derive (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/lang/Number;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun div (Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public final fun getContext ()Lspace/kscience/kmath/operations/Field; + public final fun getD (Lspace/kscience/kmath/expressions/AutoDiffValue;)Ljava/lang/Object; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun minus (Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun multiply (Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun plus (Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public final fun setD (Lspace/kscience/kmath/expressions/AutoDiffValue;Ljava/lang/Object;)V + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun times (Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; +} + +public final class space/kscience/kmath/expressions/SimpleAutoDiffKt { + public static final fun acos (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun acosh (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun asin (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun asinh (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun atan (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun atanh (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun cos (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun cosh (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun exp (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun grad (Lspace/kscience/kmath/expressions/DerivationResult;[Lspace/kscience/kmath/expressions/Symbol;)Lspace/kscience/kmath/structures/Buffer; + public static final fun ln (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun pow (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;D)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun pow (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;I)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun pow (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun simpleAutoDiff (Lspace/kscience/kmath/operations/Field;)Lspace/kscience/kmath/expressions/AutoDiffProcessor; + public static final fun simpleAutoDiff (Lspace/kscience/kmath/operations/Field;Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/DerivationResult; + public static final fun simpleAutoDiff (Lspace/kscience/kmath/operations/Field;[Lkotlin/Pair;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/DerivationResult; + public static final fun sin (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun sinh (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun sqr (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun sqrt (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun tan (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; + public static final fun tanh (Lspace/kscience/kmath/expressions/SimpleAutoDiffField;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; +} + +public final class space/kscience/kmath/expressions/SimpleSymbolIndexer : space/kscience/kmath/expressions/SymbolIndexer { + public static final synthetic fun box-impl (Ljava/util/List;)Lspace/kscience/kmath/expressions/SimpleSymbolIndexer; + public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z + public fun get (Ljava/util/List;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public fun get (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/Symbol;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public fun get (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public fun get ([DLspace/kscience/kmath/expressions/Symbol;)D + public fun get ([Ljava/lang/Object;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static fun get-impl (Ljava/util/List;Ljava/util/List;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static fun get-impl (Ljava/util/List;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/Symbol;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static fun get-impl (Ljava/util/List;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static fun get-impl (Ljava/util/List;[DLspace/kscience/kmath/expressions/Symbol;)D + public static fun get-impl (Ljava/util/List;[Ljava/lang/Object;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public fun getSymbols ()Ljava/util/List; + public fun hashCode ()I + public static fun hashCode-impl (Ljava/util/List;)I + public fun indexOf (Lspace/kscience/kmath/expressions/Symbol;)I + public static fun indexOf-impl (Ljava/util/List;Lspace/kscience/kmath/expressions/Symbol;)I + public fun toDoubleArray (Ljava/util/Map;)[D + public static fun toDoubleArray-impl (Ljava/util/List;Ljava/util/Map;)[D + public fun toList (Ljava/util/Map;)Ljava/util/List; + public static fun toList-impl (Ljava/util/List;Ljava/util/Map;)Ljava/util/List; + public fun toMap ([D)Ljava/util/Map; + public static fun toMap-impl (Ljava/util/List;[D)Ljava/util/Map; + public fun toPoint (Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; + public static fun toPoint-impl (Ljava/util/List;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/List; +} + +public final class space/kscience/kmath/expressions/StringSymbol : space/kscience/kmath/expressions/Symbol { + public static final synthetic fun box-impl (Ljava/lang/String;)Lspace/kscience/kmath/expressions/StringSymbol; + public static fun constructor-impl (Ljava/lang/String;)Ljava/lang/String; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Ljava/lang/String;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/lang/String;Ljava/lang/String;)Z + public fun getIdentity ()Ljava/lang/String; + public fun hashCode ()I + public static fun hashCode-impl (Ljava/lang/String;)I + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Ljava/lang/String;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/lang/String; +} + +public abstract interface class space/kscience/kmath/expressions/Symbol { + public abstract fun getIdentity ()Ljava/lang/String; +} + +public abstract interface class space/kscience/kmath/expressions/SymbolIndexer { + public abstract fun get (Ljava/util/List;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public abstract fun get (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/Symbol;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public abstract fun get (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public abstract fun get ([DLspace/kscience/kmath/expressions/Symbol;)D + public abstract fun get ([Ljava/lang/Object;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public abstract fun getSymbols ()Ljava/util/List; + public abstract fun indexOf (Lspace/kscience/kmath/expressions/Symbol;)I + public abstract fun toDoubleArray (Ljava/util/Map;)[D + public abstract fun toList (Ljava/util/Map;)Ljava/util/List; + public abstract fun toMap ([D)Ljava/util/Map; + public abstract fun toPoint (Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/expressions/SymbolIndexer$DefaultImpls { + public static fun get (Lspace/kscience/kmath/expressions/SymbolIndexer;Ljava/util/List;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static fun get (Lspace/kscience/kmath/expressions/SymbolIndexer;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/Symbol;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static fun get (Lspace/kscience/kmath/expressions/SymbolIndexer;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static fun get (Lspace/kscience/kmath/expressions/SymbolIndexer;[DLspace/kscience/kmath/expressions/Symbol;)D + public static fun get (Lspace/kscience/kmath/expressions/SymbolIndexer;[Ljava/lang/Object;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static fun indexOf (Lspace/kscience/kmath/expressions/SymbolIndexer;Lspace/kscience/kmath/expressions/Symbol;)I + public static fun toDoubleArray (Lspace/kscience/kmath/expressions/SymbolIndexer;Ljava/util/Map;)[D + public static fun toList (Lspace/kscience/kmath/expressions/SymbolIndexer;Ljava/util/Map;)Ljava/util/List; + public static fun toMap (Lspace/kscience/kmath/expressions/SymbolIndexer;[D)Ljava/util/Map; + public static fun toPoint (Lspace/kscience/kmath/expressions/SymbolIndexer;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/expressions/SymbolIndexerKt { + public static final fun withSymbols (Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun withSymbols ([Lspace/kscience/kmath/expressions/Symbol;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/linear/BufferMatrix : space/kscience/kmath/nd/Structure2D { + public fun (IILspace/kscience/kmath/structures/Buffer;)V + public fun elements ()Lkotlin/sequences/Sequence; + public fun equals (Ljava/lang/Object;)Z + public fun get (II)Ljava/lang/Object; + public fun get ([I)Ljava/lang/Object; + public final fun getBuffer ()Lspace/kscience/kmath/structures/Buffer; + public fun getColNum ()I + public fun getColumns ()Lspace/kscience/kmath/structures/Buffer; + public fun getDimension ()I + public fun getRowNum ()I + public fun getRows ()Lspace/kscience/kmath/structures/Buffer; + public fun getShape ()[I + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class space/kscience/kmath/linear/BufferMatrixContext : space/kscience/kmath/linear/GenericMatrixContext { + public static final field Companion Lspace/kscience/kmath/linear/BufferMatrixContext$Companion; + public fun (Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;)V + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun add (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun getElementContext ()Lspace/kscience/kmath/operations/Ring; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun minus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun multiply (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public final fun one (II)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun point (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public fun produce (IILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun produce (IILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun unaryMinus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/BufferMatrixContext$Companion { +} + +public final class space/kscience/kmath/linear/BufferVectorSpace : space/kscience/kmath/linear/VectorSpace { + public fun (ILspace/kscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;)V + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public final fun getBufferFactory ()Lkotlin/jvm/functions/Function2; + public fun getSize ()I + public fun getSpace ()Lspace/kscience/kmath/operations/Space; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/structures/Buffer; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public abstract interface class space/kscience/kmath/linear/CholeskyDecompositionFeature : space/kscience/kmath/linear/MatrixFeature { + public abstract fun getL ()Lspace/kscience/kmath/nd/Structure2D; +} + +public abstract interface class space/kscience/kmath/linear/DeterminantFeature : space/kscience/kmath/linear/MatrixFeature { + public abstract fun getDeterminant ()Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/linear/DiagonalFeature : space/kscience/kmath/linear/MatrixFeature { + public static final field Companion Lspace/kscience/kmath/linear/DiagonalFeature$Companion; +} + +public final class space/kscience/kmath/linear/DiagonalFeature$Companion : space/kscience/kmath/linear/DiagonalFeature { +} + +public abstract interface class space/kscience/kmath/linear/GenericMatrixContext : space/kscience/kmath/linear/MatrixContext { + public abstract fun add (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun getElementContext ()Lspace/kscience/kmath/operations/Ring; + public abstract fun minus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun multiply (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun unaryMinus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/GenericMatrixContext$DefaultImpls { + public static fun add (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun binaryOperation (Lspace/kscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun binaryOperationFunction (Lspace/kscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;)Lspace/kscience/kmath/nd/Structure2D; + public static fun div (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public static fun dot (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun dot (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun minus (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun multiply (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public static fun plus (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun point (Lspace/kscience/kmath/linear/GenericMatrixContext;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public static fun times (Lspace/kscience/kmath/linear/GenericMatrixContext;Ljava/lang/Number;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun times (Lspace/kscience/kmath/linear/GenericMatrixContext;Ljava/lang/Object;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun times (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public static fun times (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public static fun unaryMinus (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun unaryOperation (Lspace/kscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun unaryOperationFunction (Lspace/kscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/linear/GenericMatrixContext;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; +} + +public abstract interface class space/kscience/kmath/linear/InverseMatrixFeature : space/kscience/kmath/linear/MatrixFeature { + public abstract fun getInverse ()Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/LFeature : space/kscience/kmath/linear/MatrixFeature { + public static final field INSTANCE Lspace/kscience/kmath/linear/LFeature; +} + +public final class space/kscience/kmath/linear/LinearAlgebraKt { + public static final fun asMatrix (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/linear/VirtualMatrix; + public static final fun asPoint (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/structures/Buffer; +} + +public abstract interface class space/kscience/kmath/linear/LinearSolver { + public abstract fun inverse (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun solve (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun solve (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/linear/LinearSolver$DefaultImpls { + public static fun solve (Lspace/kscience/kmath/linear/LinearSolver;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/linear/LupDecomposition : space/kscience/kmath/linear/DeterminantFeature, space/kscience/kmath/linear/LupDecompositionFeature { + public fun (Lspace/kscience/kmath/linear/MatrixContext;Lspace/kscience/kmath/operations/Field;Lspace/kscience/kmath/nd/Structure2D;[IZ)V + public final fun getContext ()Lspace/kscience/kmath/linear/MatrixContext; + public fun getDeterminant ()Ljava/lang/Object; + public final fun getElementContext ()Lspace/kscience/kmath/operations/Field; + public fun getL ()Lspace/kscience/kmath/nd/Structure2D; + public final fun getLu ()Lspace/kscience/kmath/nd/Structure2D; + public fun getP ()Lspace/kscience/kmath/nd/Structure2D; + public final fun getPivot ()[I + public fun getU ()Lspace/kscience/kmath/nd/Structure2D; +} + +public abstract interface class space/kscience/kmath/linear/LupDecompositionFeature : space/kscience/kmath/linear/MatrixFeature { + public abstract fun getL ()Lspace/kscience/kmath/nd/Structure2D; + public abstract fun getP ()Lspace/kscience/kmath/nd/Structure2D; + public abstract fun getU ()Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/LupDecompositionKt { + public static final fun abs (Lspace/kscience/kmath/linear/GenericMatrixContext;Ljava/lang/Comparable;)Ljava/lang/Comparable; + public static final fun inverseWithLup (Lspace/kscience/kmath/linear/RealMatrixContext;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun lup (Lspace/kscience/kmath/linear/MatrixContext;Lkotlin/jvm/functions/Function2;Lspace/kscience/kmath/operations/Field;Lspace/kscience/kmath/nd/Structure2D;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/linear/LupDecomposition; + public static final fun lup (Lspace/kscience/kmath/linear/MatrixContext;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/LupDecomposition; + public static final fun solveWithLup (Lspace/kscience/kmath/linear/LupDecomposition;Lkotlin/jvm/functions/Function2;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun solveWithLup (Lspace/kscience/kmath/linear/RealMatrixContext;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/MatrixBuilder { + public fun (II)V + public final fun getColumns ()I + public final fun getRows ()I + public final fun invoke ([Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/MatrixBuilderKt { + public static final fun build (Lspace/kscience/kmath/nd/Structure2D$Companion;II)Lspace/kscience/kmath/linear/MatrixBuilder; + public static final fun column (Lspace/kscience/kmath/nd/Structure2D$Companion;[Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun row (Lspace/kscience/kmath/nd/Structure2D$Companion;[Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; +} + +public abstract interface class space/kscience/kmath/linear/MatrixContext : space/kscience/kmath/operations/SpaceOperations { + public static final field Companion Lspace/kscience/kmath/linear/MatrixContext$Companion; + public abstract fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public abstract fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun point (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun produce (IILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/MatrixContext$Companion { + public final fun buffered (Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/linear/GenericMatrixContext; + public static synthetic fun buffered$default (Lspace/kscience/kmath/linear/MatrixContext$Companion;Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lspace/kscience/kmath/linear/GenericMatrixContext; +} + +public final class space/kscience/kmath/linear/MatrixContext$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/linear/MatrixContext;Ljava/lang/String;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun binaryOperationFunction (Lspace/kscience/kmath/linear/MatrixContext;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/linear/MatrixContext;Ljava/lang/String;)Lspace/kscience/kmath/nd/Structure2D; + public static fun div (Lspace/kscience/kmath/linear/MatrixContext;Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public static fun minus (Lspace/kscience/kmath/linear/MatrixContext;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun plus (Lspace/kscience/kmath/linear/MatrixContext;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun point (Lspace/kscience/kmath/linear/MatrixContext;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public static fun times (Lspace/kscience/kmath/linear/MatrixContext;Ljava/lang/Number;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun times (Lspace/kscience/kmath/linear/MatrixContext;Ljava/lang/Object;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun times (Lspace/kscience/kmath/linear/MatrixContext;Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public static fun unaryMinus (Lspace/kscience/kmath/linear/MatrixContext;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun unaryOperation (Lspace/kscience/kmath/linear/MatrixContext;Ljava/lang/String;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun unaryOperationFunction (Lspace/kscience/kmath/linear/MatrixContext;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/linear/MatrixContext;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; +} + +public abstract interface class space/kscience/kmath/linear/MatrixFeature { +} + +public final class space/kscience/kmath/linear/MatrixFeaturesKt { + public static final fun DeterminantFeature (Ljava/lang/Object;)Lspace/kscience/kmath/linear/DeterminantFeature; +} + +public final class space/kscience/kmath/linear/MatrixWrapper : space/kscience/kmath/nd/Structure2D { + public fun elements ()Lkotlin/sequences/Sequence; + public fun equals (Ljava/lang/Object;)Z + public fun get (II)Ljava/lang/Object; + public fun get ([I)Ljava/lang/Object; + public fun getColNum ()I + public fun getColumns ()Lspace/kscience/kmath/structures/Buffer; + public fun getDimension ()I + public final fun getFeatures ()Ljava/util/Set; + public final fun getOrigin ()Lspace/kscience/kmath/nd/Structure2D; + public fun getRowNum ()I + public fun getRows ()Lspace/kscience/kmath/structures/Buffer; + public fun getShape ()[I + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class space/kscience/kmath/linear/MatrixWrapperKt { + public static final fun getOrigin (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun one (Lspace/kscience/kmath/linear/GenericMatrixContext;II)Lspace/kscience/kmath/nd/Structure2D; + public static final fun plus (Lspace/kscience/kmath/nd/Structure2D;Ljava/util/Collection;)Lspace/kscience/kmath/linear/MatrixWrapper; + public static final fun plus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/linear/MatrixFeature;)Lspace/kscience/kmath/linear/MatrixWrapper; + public static final fun square (Lspace/kscience/kmath/nd/Structure2D$Companion;[Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun transpose (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun zero (Lspace/kscience/kmath/linear/GenericMatrixContext;II)Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/OrthogonalFeature : space/kscience/kmath/linear/MatrixFeature { + public static final field INSTANCE Lspace/kscience/kmath/linear/OrthogonalFeature; +} + +public abstract interface class space/kscience/kmath/linear/QRDecompositionFeature : space/kscience/kmath/linear/MatrixFeature { + public abstract fun getQ ()Lspace/kscience/kmath/nd/Structure2D; + public abstract fun getR ()Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/RealMatrixContext : space/kscience/kmath/linear/MatrixContext { + public static final field INSTANCE Lspace/kscience/kmath/linear/RealMatrixContext; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/linear/BufferMatrix; + public final fun one (II)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun point (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public fun produce (IILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun produce (IILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/Structure2D; + public fun times (DLspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun times (Lspace/kscience/kmath/nd/Structure2D;D)Lspace/kscience/kmath/linear/BufferMatrix; + public fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public final fun toBufferMatrix (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/BufferMatrix; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/RealMatrixContextKt { + public static final fun getReal (Lspace/kscience/kmath/linear/MatrixContext$Companion;)Lspace/kscience/kmath/linear/RealMatrixContext; +} + +public abstract interface class space/kscience/kmath/linear/SingularValueDecompositionFeature : space/kscience/kmath/linear/MatrixFeature { + public abstract fun getS ()Lspace/kscience/kmath/nd/Structure2D; + public abstract fun getSingularValues ()Lspace/kscience/kmath/structures/Buffer; + public abstract fun getU ()Lspace/kscience/kmath/nd/Structure2D; + public abstract fun getV ()Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/TransposedFeature : space/kscience/kmath/linear/MatrixFeature { + public fun (Lspace/kscience/kmath/nd/Structure2D;)V + public final fun getOriginal ()Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/UFeature : space/kscience/kmath/linear/MatrixFeature { + public static final field INSTANCE Lspace/kscience/kmath/linear/UFeature; +} + +public final class space/kscience/kmath/linear/UnitFeature : space/kscience/kmath/linear/DiagonalFeature { + public static final field INSTANCE Lspace/kscience/kmath/linear/UnitFeature; +} + +public abstract interface class space/kscience/kmath/linear/VectorSpace : space/kscience/kmath/operations/Space { + public static final field Companion Lspace/kscience/kmath/linear/VectorSpace$Companion; + public abstract fun add (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun getSize ()I + public abstract fun getSpace ()Lspace/kscience/kmath/operations/Space; + public abstract fun getZero ()Lspace/kscience/kmath/structures/Buffer; + public abstract fun multiply (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/linear/VectorSpace$Companion { + public final fun buffered (ILspace/kscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/linear/BufferVectorSpace; + public static synthetic fun buffered$default (Lspace/kscience/kmath/linear/VectorSpace$Companion;ILspace/kscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lspace/kscience/kmath/linear/BufferVectorSpace; + public final fun real (I)Lspace/kscience/kmath/linear/BufferVectorSpace; +} + +public final class space/kscience/kmath/linear/VectorSpace$DefaultImpls { + public static fun add (Lspace/kscience/kmath/linear/VectorSpace;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun binaryOperation (Lspace/kscience/kmath/linear/VectorSpace;Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun binaryOperationFunction (Lspace/kscience/kmath/linear/VectorSpace;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/linear/VectorSpace;Ljava/lang/String;)Lspace/kscience/kmath/structures/Buffer; + public static fun div (Lspace/kscience/kmath/linear/VectorSpace;Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public static fun getZero (Lspace/kscience/kmath/linear/VectorSpace;)Lspace/kscience/kmath/structures/Buffer; + public static fun minus (Lspace/kscience/kmath/linear/VectorSpace;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun multiply (Lspace/kscience/kmath/linear/VectorSpace;Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public static fun plus (Lspace/kscience/kmath/linear/VectorSpace;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun times (Lspace/kscience/kmath/linear/VectorSpace;Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun times (Lspace/kscience/kmath/linear/VectorSpace;Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public static fun unaryMinus (Lspace/kscience/kmath/linear/VectorSpace;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun unaryOperation (Lspace/kscience/kmath/linear/VectorSpace;Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun unaryOperationFunction (Lspace/kscience/kmath/linear/VectorSpace;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/linear/VectorSpace;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/linear/VirtualMatrix : space/kscience/kmath/nd/Structure2D { + public fun (IILkotlin/jvm/functions/Function2;)V + public fun elements ()Lkotlin/sequences/Sequence; + public fun equals (Ljava/lang/Object;)Z + public fun get (II)Ljava/lang/Object; + public fun get ([I)Ljava/lang/Object; + public fun getColNum ()I + public fun getColumns ()Lspace/kscience/kmath/structures/Buffer; + public fun getDimension ()I + public final fun getGenerator ()Lkotlin/jvm/functions/Function2; + public fun getRowNum ()I + public fun getRows ()Lspace/kscience/kmath/structures/Buffer; + public fun getShape ()[I + public fun hashCode ()I +} + +public final class space/kscience/kmath/linear/ZeroFeature : space/kscience/kmath/linear/DiagonalFeature { + public static final field INSTANCE Lspace/kscience/kmath/linear/ZeroFeature; +} + +public final class space/kscience/kmath/misc/CumulativeKt { + public static final fun cumulative (Ljava/lang/Iterable;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Iterable; + public static final fun cumulative (Ljava/util/Iterator;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/util/Iterator; + public static final fun cumulative (Ljava/util/List;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun cumulative (Lkotlin/sequences/Sequence;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence; + public static final fun cumulativeSum (Ljava/lang/Iterable;Lspace/kscience/kmath/operations/Space;)Ljava/lang/Iterable; + public static final fun cumulativeSum (Ljava/util/List;Lspace/kscience/kmath/operations/Space;)Ljava/util/List; + public static final fun cumulativeSum (Lkotlin/sequences/Sequence;Lspace/kscience/kmath/operations/Space;)Lkotlin/sequences/Sequence; + public static final fun cumulativeSumOfDouble (Ljava/lang/Iterable;)Ljava/lang/Iterable; + public static final fun cumulativeSumOfDouble (Ljava/util/List;)Ljava/util/List; + public static final fun cumulativeSumOfDouble (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; + public static final fun cumulativeSumOfInt (Ljava/lang/Iterable;)Ljava/lang/Iterable; + public static final fun cumulativeSumOfInt (Ljava/util/List;)Ljava/util/List; + public static final fun cumulativeSumOfInt (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; + public static final fun cumulativeSumOfLong (Ljava/lang/Iterable;)Ljava/lang/Iterable; + public static final fun cumulativeSumOfLong (Ljava/util/List;)Ljava/util/List; + public static final fun cumulativeSumOfLong (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; +} + +public abstract interface annotation class space/kscience/kmath/misc/UnstableKMathAPI : java/lang/annotation/Annotation { +} + +public abstract interface class space/kscience/kmath/nd/BufferNDAlgebra : space/kscience/kmath/nd/NDAlgebra { + public abstract fun combine (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public abstract fun getBuffer (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun getBufferFactory ()Lkotlin/jvm/functions/Function2; + public abstract fun getStrides ()Lspace/kscience/kmath/nd/Strides; + public abstract fun map (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; + public abstract fun mapIndexed (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public abstract fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; +} + +public final class space/kscience/kmath/nd/BufferNDAlgebra$DefaultImpls { + public static fun combine (Lspace/kscience/kmath/nd/BufferNDAlgebra;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public static fun getBuffer (Lspace/kscience/kmath/nd/BufferNDAlgebra;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/structures/Buffer; + public static fun invoke (Lspace/kscience/kmath/nd/BufferNDAlgebra;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun map (Lspace/kscience/kmath/nd/BufferNDAlgebra;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; + public static fun mapIndexed (Lspace/kscience/kmath/nd/BufferNDAlgebra;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public static fun produce (Lspace/kscience/kmath/nd/BufferNDAlgebra;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; +} + +public final class space/kscience/kmath/nd/BufferNDAlgebraKt { + public static final fun field (Lspace/kscience/kmath/nd/NDAlgebra$Companion;Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function2;[I)Lspace/kscience/kmath/nd/BufferedNDField; + public static final fun ndField (Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function2;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun ndRing (Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun ndSpace (Lspace/kscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun ring (Lspace/kscience/kmath/nd/NDAlgebra$Companion;Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;[I)Lspace/kscience/kmath/nd/BufferedNDRing; + public static final fun space (Lspace/kscience/kmath/nd/NDAlgebra$Companion;Lspace/kscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;[I)Lspace/kscience/kmath/nd/BufferedNDSpace; +} + +public class space/kscience/kmath/nd/BufferedNDField : space/kscience/kmath/nd/BufferedNDRing, space/kscience/kmath/nd/NDField { + public fun ([ILspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function2;)V + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun div (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public fun div (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; +} + +public class space/kscience/kmath/nd/BufferedNDRing : space/kscience/kmath/nd/BufferedNDSpace, space/kscience/kmath/nd/NDRing { + public fun ([ILspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;)V + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun times (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public fun times (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; +} + +public class space/kscience/kmath/nd/BufferedNDSpace : space/kscience/kmath/nd/BufferNDAlgebra, space/kscience/kmath/nd/NDSpace { + public fun ([ILspace/kscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;)V + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/nd/NDStructure; + public fun combine (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun combine (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public fun getBuffer (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/structures/Buffer; + public final fun getBufferFactory ()Lkotlin/jvm/functions/Function2; + public synthetic fun getElementContext ()Ljava/lang/Object; + public final fun getElementContext ()Lspace/kscience/kmath/operations/Space; + public final fun getShape ()[I + public fun getStrides ()Lspace/kscience/kmath/nd/Strides; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/nd/NDBuffer; + public fun invoke (Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun map (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun map (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDStructure; + public fun mapIndexed (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun minus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public fun minus (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun plus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public fun plus (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; +} + +public final class space/kscience/kmath/nd/DefaultStrides : space/kscience/kmath/nd/Strides { + public static final field Companion Lspace/kscience/kmath/nd/DefaultStrides$Companion; + public synthetic fun ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun equals (Ljava/lang/Object;)Z + public fun getLinearSize ()I + public fun getShape ()[I + public fun getStrides ()Ljava/util/List; + public fun hashCode ()I + public fun index (I)[I + public fun indices ()Lkotlin/sequences/Sequence; + public fun offset ([I)I +} + +public final class space/kscience/kmath/nd/DefaultStrides$Companion { + public final fun invoke ([I)Lspace/kscience/kmath/nd/Strides; +} + +public final class space/kscience/kmath/nd/MutableNDBuffer : space/kscience/kmath/nd/NDBuffer, space/kscience/kmath/nd/MutableNDStructure { + public fun (Lspace/kscience/kmath/nd/Strides;Lspace/kscience/kmath/structures/MutableBuffer;)V + public synthetic fun getBuffer ()Lspace/kscience/kmath/structures/Buffer; + public fun getBuffer ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun set ([ILjava/lang/Object;)V +} + +public abstract interface class space/kscience/kmath/nd/MutableNDStructure : space/kscience/kmath/nd/NDStructure { + public abstract fun set ([ILjava/lang/Object;)V +} + +public final class space/kscience/kmath/nd/MutableNDStructure$DefaultImpls { + public static fun getDimension (Lspace/kscience/kmath/nd/MutableNDStructure;)I +} + +public abstract interface class space/kscience/kmath/nd/NDAlgebra { + public static final field Companion Lspace/kscience/kmath/nd/NDAlgebra$Companion; + public abstract fun combine (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun getElementContext ()Ljava/lang/Object; + public abstract fun getShape ()[I + public abstract fun invoke (Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun map (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun mapIndexed (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDStructure; +} + +public final class space/kscience/kmath/nd/NDAlgebra$Companion { +} + +public final class space/kscience/kmath/nd/NDAlgebra$DefaultImpls { + public static fun invoke (Lspace/kscience/kmath/nd/NDAlgebra;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; +} + +public class space/kscience/kmath/nd/NDBuffer : space/kscience/kmath/nd/NDStructure { + public fun (Lspace/kscience/kmath/nd/Strides;Lspace/kscience/kmath/structures/Buffer;)V + public fun elements ()Lkotlin/sequences/Sequence; + public fun equals (Ljava/lang/Object;)Z + public fun get ([I)Ljava/lang/Object; + public fun getBuffer ()Lspace/kscience/kmath/structures/Buffer; + public fun getDimension ()I + public fun getShape ()[I + public final fun getStrides ()Lspace/kscience/kmath/nd/Strides; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public abstract interface class space/kscience/kmath/nd/NDField : space/kscience/kmath/nd/NDRing, space/kscience/kmath/operations/Field { + public abstract fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun div (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun divide (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; +} + +public final class space/kscience/kmath/nd/NDField$DefaultImpls { + public static fun add (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun binaryOperation (Lspace/kscience/kmath/nd/NDField;Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun binaryOperationFunction (Lspace/kscience/kmath/nd/NDField;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/nd/NDField;Ljava/lang/String;)Lspace/kscience/kmath/nd/NDStructure; + public static fun div (Lspace/kscience/kmath/nd/NDField;Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun div (Lspace/kscience/kmath/nd/NDField;Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun div (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public static fun div (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public static fun div (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun divide (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun invoke (Lspace/kscience/kmath/nd/NDField;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun minus (Lspace/kscience/kmath/nd/NDField;Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun minus (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public static fun minus (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun multiply (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public static fun multiply (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun plus (Lspace/kscience/kmath/nd/NDField;Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun plus (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public static fun plus (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDField;Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDField;Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun unaryMinus (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun unaryOperation (Lspace/kscience/kmath/nd/NDField;Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun unaryOperationFunction (Lspace/kscience/kmath/nd/NDField;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/nd/NDField;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; +} + +public abstract interface class space/kscience/kmath/nd/NDRing : space/kscience/kmath/nd/NDSpace, space/kscience/kmath/operations/Ring { + public static final field Companion Lspace/kscience/kmath/nd/NDRing$Companion; + public abstract fun multiply (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun times (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; +} + +public final class space/kscience/kmath/nd/NDRing$Companion { +} + +public final class space/kscience/kmath/nd/NDRing$DefaultImpls { + public static fun add (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun binaryOperation (Lspace/kscience/kmath/nd/NDRing;Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun binaryOperationFunction (Lspace/kscience/kmath/nd/NDRing;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/nd/NDRing;Ljava/lang/String;)Lspace/kscience/kmath/nd/NDStructure; + public static fun div (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public static fun invoke (Lspace/kscience/kmath/nd/NDRing;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun minus (Lspace/kscience/kmath/nd/NDRing;Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun minus (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public static fun minus (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun multiply (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public static fun multiply (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun plus (Lspace/kscience/kmath/nd/NDRing;Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun plus (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public static fun plus (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDRing;Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDRing;Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun unaryMinus (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun unaryOperation (Lspace/kscience/kmath/nd/NDRing;Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun unaryOperationFunction (Lspace/kscience/kmath/nd/NDRing;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/nd/NDRing;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; +} + +public abstract interface class space/kscience/kmath/nd/NDSpace : space/kscience/kmath/nd/NDAlgebra, space/kscience/kmath/operations/Space { + public static final field Companion Lspace/kscience/kmath/nd/NDSpace$Companion; + public abstract fun add (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun minus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun multiply (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public abstract fun plus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; +} + +public final class space/kscience/kmath/nd/NDSpace$Companion { +} + +public final class space/kscience/kmath/nd/NDSpace$DefaultImpls { + public static fun add (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun binaryOperation (Lspace/kscience/kmath/nd/NDSpace;Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun binaryOperationFunction (Lspace/kscience/kmath/nd/NDSpace;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/nd/NDSpace;Ljava/lang/String;)Lspace/kscience/kmath/nd/NDStructure; + public static fun div (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public static fun invoke (Lspace/kscience/kmath/nd/NDSpace;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun minus (Lspace/kscience/kmath/nd/NDSpace;Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun minus (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public static fun minus (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun multiply (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public static fun plus (Lspace/kscience/kmath/nd/NDSpace;Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun plus (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public static fun plus (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDSpace;Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun times (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public static fun unaryMinus (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun unaryOperation (Lspace/kscience/kmath/nd/NDSpace;Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public static fun unaryOperationFunction (Lspace/kscience/kmath/nd/NDSpace;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/nd/NDSpace;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; +} + +public abstract interface class space/kscience/kmath/nd/NDStructure { + public static final field Companion Lspace/kscience/kmath/nd/NDStructure$Companion; + public abstract fun elements ()Lkotlin/sequences/Sequence; + public abstract fun equals (Ljava/lang/Object;)Z + public abstract fun get ([I)Ljava/lang/Object; + public abstract fun getDimension ()I + public abstract fun getShape ()[I + public abstract fun hashCode ()I +} + +public final class space/kscience/kmath/nd/NDStructure$Companion { + public final fun auto (Lkotlin/reflect/KClass;Lspace/kscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/NDBuffer; + public final fun auto (Lkotlin/reflect/KClass;[ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/NDBuffer; + public final fun build (Lspace/kscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/NDBuffer; + public final fun build ([ILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/NDBuffer; + public static synthetic fun build$default (Lspace/kscience/kmath/nd/NDStructure$Companion;Lspace/kscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/NDBuffer; + public static synthetic fun build$default (Lspace/kscience/kmath/nd/NDStructure$Companion;[ILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/NDBuffer; + public final fun contentEquals (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Z +} + +public final class space/kscience/kmath/nd/NDStructure$DefaultImpls { + public static fun getDimension (Lspace/kscience/kmath/nd/NDStructure;)I +} + +public final class space/kscience/kmath/nd/NDStructureKt { + public static final fun get (Lspace/kscience/kmath/nd/NDStructure;[I)Ljava/lang/Object; + public static final fun mapInPlace (Lspace/kscience/kmath/nd/MutableNDStructure;Lkotlin/jvm/functions/Function2;)V +} + +public final class space/kscience/kmath/nd/RealNDField : space/kscience/kmath/nd/BufferedNDField, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/RingWithNumbers { + public fun ([I)V + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public fun combine (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun combine (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun getBuffer (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/structures/Buffer; + public fun getBuffer-LGjt3BI (Lspace/kscience/kmath/nd/NDStructure;)[D + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public fun map (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun map (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDStructure; + public fun mapIndexed (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDBuffer; + public fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDBuffer; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/nd/RealNDFieldKt { + public static final fun nd (Lspace/kscience/kmath/operations/RealField;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun real (Lspace/kscience/kmath/nd/NDAlgebra$Companion;[I)Lspace/kscience/kmath/nd/RealNDField; +} + +public final class space/kscience/kmath/nd/ShapeMismatchException : java/lang/RuntimeException { + public fun ([I[I)V + public final fun getActual ()[I + public final fun getExpected ()[I +} + +public final class space/kscience/kmath/nd/ShortNDRing : space/kscience/kmath/nd/BufferedNDRing, space/kscience/kmath/operations/RingWithNumbers { + public fun ([I)V + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; +} + +public final class space/kscience/kmath/nd/ShortNDRingKt { + public static final fun nd (Lspace/kscience/kmath/operations/ShortRing;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun produceInline (Lspace/kscience/kmath/nd/BufferedNDRing;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; +} + +public abstract interface class space/kscience/kmath/nd/Strides { + public abstract fun getLinearSize ()I + public abstract fun getShape ()[I + public abstract fun getStrides ()Ljava/util/List; + public abstract fun index (I)[I + public abstract fun indices ()Lkotlin/sequences/Sequence; + public abstract fun offset ([I)I +} + +public final class space/kscience/kmath/nd/Strides$DefaultImpls { + public static fun indices (Lspace/kscience/kmath/nd/Strides;)Lkotlin/sequences/Sequence; +} + +public abstract interface class space/kscience/kmath/nd/Structure1D : space/kscience/kmath/nd/NDStructure, space/kscience/kmath/structures/Buffer { + public abstract fun get ([I)Ljava/lang/Object; + public abstract fun getDimension ()I + public abstract fun iterator ()Ljava/util/Iterator; +} + +public final class space/kscience/kmath/nd/Structure1D$DefaultImpls { + public static fun contentEquals (Lspace/kscience/kmath/nd/Structure1D;Lspace/kscience/kmath/structures/Buffer;)Z + public static fun get (Lspace/kscience/kmath/nd/Structure1D;[I)Ljava/lang/Object; + public static fun getDimension (Lspace/kscience/kmath/nd/Structure1D;)I + public static fun iterator (Lspace/kscience/kmath/nd/Structure1D;)Ljava/util/Iterator; +} + +public final class space/kscience/kmath/nd/Structure1DKt { + public static final fun as1D (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/Structure1D; + public static final fun asND (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/nd/Structure1D; +} + +public abstract interface class space/kscience/kmath/nd/Structure2D : space/kscience/kmath/nd/NDStructure { + public static final field Companion Lspace/kscience/kmath/nd/Structure2D$Companion; + public abstract fun elements ()Lkotlin/sequences/Sequence; + public abstract fun get (II)Ljava/lang/Object; + public abstract fun get ([I)Ljava/lang/Object; + public abstract fun getColNum ()I + public abstract fun getColumns ()Lspace/kscience/kmath/structures/Buffer; + public abstract fun getRowNum ()I + public abstract fun getRows ()Lspace/kscience/kmath/structures/Buffer; + public abstract fun getShape ()[I +} + +public final class space/kscience/kmath/nd/Structure2D$Companion { + public final fun real (IILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/linear/BufferMatrix; +} + +public final class space/kscience/kmath/nd/Structure2D$DefaultImpls { + public static fun elements (Lspace/kscience/kmath/nd/Structure2D;)Lkotlin/sequences/Sequence; + public static fun get (Lspace/kscience/kmath/nd/Structure2D;[I)Ljava/lang/Object; + public static fun getColumns (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/structures/Buffer; + public static fun getDimension (Lspace/kscience/kmath/nd/Structure2D;)I + public static fun getRows (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/structures/Buffer; + public static fun getShape (Lspace/kscience/kmath/nd/Structure2D;)[I +} + +public final class space/kscience/kmath/nd/Structure2DKt { + public static final fun as2D (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/Structure2D; +} + +public abstract interface class space/kscience/kmath/operations/Algebra { + public abstract fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public abstract fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public abstract fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/operations/Algebra$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/Algebra;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/Algebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/Algebra;Ljava/lang/String;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/Algebra;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/Algebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public abstract interface class space/kscience/kmath/operations/AlgebraElement { + public abstract fun getContext ()Lspace/kscience/kmath/operations/Algebra; +} + +public final class space/kscience/kmath/operations/AlgebraElementsKt { + public static final fun div (Lspace/kscience/kmath/operations/AlgebraElement;Ljava/lang/Number;)Lspace/kscience/kmath/operations/AlgebraElement; + public static final fun div (Lspace/kscience/kmath/operations/AlgebraElement;Lspace/kscience/kmath/operations/AlgebraElement;)Lspace/kscience/kmath/operations/AlgebraElement; + public static final fun minus (Lspace/kscience/kmath/operations/AlgebraElement;Lspace/kscience/kmath/operations/AlgebraElement;)Lspace/kscience/kmath/operations/AlgebraElement; + public static final fun plus (Lspace/kscience/kmath/operations/AlgebraElement;Lspace/kscience/kmath/operations/AlgebraElement;)Lspace/kscience/kmath/operations/AlgebraElement; + public static final fun times (Ljava/lang/Number;Lspace/kscience/kmath/operations/AlgebraElement;)Lspace/kscience/kmath/operations/AlgebraElement; + public static final fun times (Lspace/kscience/kmath/operations/AlgebraElement;Ljava/lang/Number;)Lspace/kscience/kmath/operations/AlgebraElement; + public static final fun times (Lspace/kscience/kmath/operations/AlgebraElement;Lspace/kscience/kmath/operations/AlgebraElement;)Lspace/kscience/kmath/operations/AlgebraElement; +} + +public final class space/kscience/kmath/operations/AlgebraExtensionsKt { + public static final fun abs (Lspace/kscience/kmath/operations/Space;Ljava/lang/Comparable;)Ljava/lang/Comparable; + public static final fun average (Lspace/kscience/kmath/operations/Space;Ljava/lang/Iterable;)Ljava/lang/Object; + public static final fun average (Lspace/kscience/kmath/operations/Space;Lkotlin/sequences/Sequence;)Ljava/lang/Object; + public static final fun averageWith (Ljava/lang/Iterable;Lspace/kscience/kmath/operations/Space;)Ljava/lang/Object; + public static final fun averageWith (Lkotlin/sequences/Sequence;Lspace/kscience/kmath/operations/Space;)Ljava/lang/Object; + public static final fun power (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;I)Ljava/lang/Object; + public static final fun power (Lspace/kscience/kmath/operations/Ring;Ljava/lang/Object;I)Ljava/lang/Object; + public static final fun sum (Lspace/kscience/kmath/operations/Space;Ljava/lang/Iterable;)Ljava/lang/Object; + public static final fun sum (Lspace/kscience/kmath/operations/Space;Lkotlin/sequences/Sequence;)Ljava/lang/Object; + public static final fun sumWith (Ljava/lang/Iterable;Lspace/kscience/kmath/operations/Space;)Ljava/lang/Object; + public static final fun sumWith (Lkotlin/sequences/Sequence;Lspace/kscience/kmath/operations/Space;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/AlgebraKt { + public static final fun bindSymbol (Lspace/kscience/kmath/operations/Algebra;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; + public static final fun invoke (Lspace/kscience/kmath/operations/Algebra;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/BigInt : java/lang/Comparable { + public static final field BASE J + public static final field BASE_SIZE I + public static final field Companion Lspace/kscience/kmath/operations/BigInt$Companion; + public final fun abs ()Lspace/kscience/kmath/operations/BigInt; + public final fun and (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun compareTo (Ljava/lang/Object;)I + public fun compareTo (Lspace/kscience/kmath/operations/BigInt;)I + public final fun div (I)Lspace/kscience/kmath/operations/BigInt; + public final fun div (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public final fun div-WZ4Q5Ns (I)Lspace/kscience/kmath/operations/BigInt; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I + public final fun minus (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public final fun modPow (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public final fun or (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public final fun plus (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public final fun rem (I)I + public final fun rem (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public final fun shl (I)Lspace/kscience/kmath/operations/BigInt; + public final fun shr (I)Lspace/kscience/kmath/operations/BigInt; + public final fun times (I)Lspace/kscience/kmath/operations/BigInt; + public final fun times (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public final fun times-WZ4Q5Ns (I)Lspace/kscience/kmath/operations/BigInt; + public fun toString ()Ljava/lang/String; + public final fun unaryMinus ()Lspace/kscience/kmath/operations/BigInt; +} + +public final class space/kscience/kmath/operations/BigInt$Companion { + public final fun getONE ()Lspace/kscience/kmath/operations/BigInt; + public final fun getZERO ()Lspace/kscience/kmath/operations/BigInt; +} + +public final class space/kscience/kmath/operations/BigIntField : space/kscience/kmath/operations/Field, space/kscience/kmath/operations/RingWithNumbers { + public static final field INSTANCE Lspace/kscience/kmath/operations/BigIntField; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/lang/Number;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/operations/BigInt;Ljava/lang/Number;)Lspace/kscience/kmath/operations/BigInt; + public fun div (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/operations/BigInt; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/operations/BigInt; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/operations/BigInt;Ljava/lang/Number;)Lspace/kscience/kmath/operations/BigInt; + public fun minus (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/operations/BigInt;Ljava/lang/Number;)Lspace/kscience/kmath/operations/BigInt; + public fun multiply (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/operations/BigInt;Ljava/lang/Number;)Lspace/kscience/kmath/operations/BigInt; + public fun plus (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/operations/BigInt;Ljava/lang/Number;)Lspace/kscience/kmath/operations/BigInt; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/operations/BigInt;Ljava/lang/Number;)Lspace/kscience/kmath/operations/BigInt; + public fun times (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public final fun unaryMinus (Ljava/lang/String;)Lspace/kscience/kmath/operations/BigInt; + public fun unaryMinus (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public final fun unaryPlus (Ljava/lang/String;)Lspace/kscience/kmath/operations/BigInt; + public fun unaryPlus (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; +} + +public final class space/kscience/kmath/operations/BigIntKt { + public static final fun abs (Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public static final fun bigInt (Lspace/kscience/kmath/nd/NDAlgebra$Companion;[I)Lspace/kscience/kmath/nd/BufferedNDRing; + public static final fun bigInt (Lspace/kscience/kmath/structures/Buffer$Companion;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public static final fun bigInt (Lspace/kscience/kmath/structures/MutableBuffer$Companion;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; + public static final fun parseBigInteger (Ljava/lang/String;)Lspace/kscience/kmath/operations/BigInt; + public static final fun toBigInt (I)Lspace/kscience/kmath/operations/BigInt; + public static final fun toBigInt (J)Lspace/kscience/kmath/operations/BigInt; + public static final fun toBigInt-LpG4sQ0 ([IB)Lspace/kscience/kmath/operations/BigInt; + public static final fun toBigInt-VKZWuLQ (J)Lspace/kscience/kmath/operations/BigInt; + public static final fun toBigInt-WZ4Q5Ns (I)Lspace/kscience/kmath/operations/BigInt; +} + +public final class space/kscience/kmath/operations/ByteRing : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { + public static final field INSTANCE Lspace/kscience/kmath/operations/ByteRing; + public fun add (BB)Ljava/lang/Byte; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;BB)Ljava/lang/Byte; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Byte; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun div (BLjava/lang/Number;)Ljava/lang/Byte; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun getOne ()Ljava/lang/Byte; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Byte; + public synthetic fun getZero ()Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;B)Ljava/lang/Byte; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun minus (BB)Ljava/lang/Byte; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (BB)Ljava/lang/Byte; + public fun multiply (BLjava/lang/Number;)Ljava/lang/Byte; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (B)Ljava/lang/Byte; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Byte; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (BB)Ljava/lang/Byte; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;BLjava/lang/Number;)Ljava/lang/Byte; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun times (BB)Ljava/lang/Byte; + public fun times (BLjava/lang/Number;)Ljava/lang/Byte; + public fun times (Ljava/lang/Number;B)Ljava/lang/Byte; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (B)Ljava/lang/Byte; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;B)Ljava/lang/Byte; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public fun unaryPlus (B)Ljava/lang/Byte; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/ExponentialOperations : space/kscience/kmath/operations/Algebra { + public static final field Companion Lspace/kscience/kmath/operations/ExponentialOperations$Companion; + public static final field EXP_OPERATION Ljava/lang/String; + public static final field LN_OPERATION Ljava/lang/String; + public abstract fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun ln (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/ExponentialOperations$Companion { + public static final field EXP_OPERATION Ljava/lang/String; + public static final field LN_OPERATION Ljava/lang/String; +} + +public final class space/kscience/kmath/operations/ExponentialOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/ExponentialOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/ExponentialOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/ExponentialOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/ExponentialOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/ExponentialOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public abstract interface class space/kscience/kmath/operations/ExtendedField : space/kscience/kmath/operations/ExtendedFieldOperations, space/kscience/kmath/operations/Field, space/kscience/kmath/operations/NumericAlgebra { + public abstract fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public abstract fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun tanh (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/ExtendedField$DefaultImpls { + public static fun acosh (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; + public static fun asinh (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; + public static fun atanh (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperation (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/String;)Ljava/lang/Object; + public static fun cosh (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun leftSideNumberOperation (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun leftSideNumberOperationFunction (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun minus (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun pow (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun rightSideNumberOperation (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun rightSideNumberOperationFunction (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun sinh (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; + public static fun sqrt (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; + public static fun tan (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; + public static fun tanh (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryMinus (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/ExtendedFieldOperations : space/kscience/kmath/operations/ExponentialOperations, space/kscience/kmath/operations/FieldOperations, space/kscience/kmath/operations/HyperbolicOperations, space/kscience/kmath/operations/PowerOperations, space/kscience/kmath/operations/TrigonometricOperations { + public abstract fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/operations/ExtendedFieldOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun pow (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun sqrt (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; + public static fun tan (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; + public static fun tanh (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryMinus (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/Field : space/kscience/kmath/operations/FieldOperations, space/kscience/kmath/operations/Ring { + public abstract fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/Field$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/Field;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/Field;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/Field;Ljava/lang/String;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/Field;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/Field;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryMinus (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/Field;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/Field;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/FieldOperations : space/kscience/kmath/operations/RingOperations { + public static final field Companion Lspace/kscience/kmath/operations/FieldOperations$Companion; + public static final field DIV_OPERATION Ljava/lang/String; + public abstract fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public abstract fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/FieldOperations$Companion { + public static final field DIV_OPERATION Ljava/lang/String; +} + +public final class space/kscience/kmath/operations/FieldOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryMinus (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/FieldOperations;Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/FloatField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm { + public static final field INSTANCE Lspace/kscience/kmath/operations/FloatField; + public fun acos (F)Ljava/lang/Float; + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (F)Ljava/lang/Float; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun add (FF)Ljava/lang/Float; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (F)Ljava/lang/Float; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (F)Ljava/lang/Float; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (F)Ljava/lang/Float; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (F)Ljava/lang/Float; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;FF)Ljava/lang/Float; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Float; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun cos (F)Ljava/lang/Float; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (F)Ljava/lang/Float; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun div (FF)Ljava/lang/Float; + public fun div (FLjava/lang/Number;)Ljava/lang/Float; + public fun div (Ljava/lang/Number;F)Ljava/lang/Float; + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (FF)Ljava/lang/Float; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (F)Ljava/lang/Float; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun getOne ()Ljava/lang/Float; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Float; + public synthetic fun getZero ()Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;F)Ljava/lang/Float; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun ln (F)Ljava/lang/Float; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (FF)Ljava/lang/Float; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (FF)Ljava/lang/Float; + public fun multiply (FLjava/lang/Number;)Ljava/lang/Float; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (F)Ljava/lang/Float; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Float; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (FF)Ljava/lang/Float; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun pow (FLjava/lang/Number;)Ljava/lang/Float; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (FLjava/lang/Number;)Ljava/lang/Float; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;FLjava/lang/Number;)Ljava/lang/Float; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun sin (F)Ljava/lang/Float; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (F)Ljava/lang/Float; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (F)Ljava/lang/Float; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (F)Ljava/lang/Float; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (F)Ljava/lang/Float; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun times (FF)Ljava/lang/Float; + public fun times (FLjava/lang/Number;)Ljava/lang/Float; + public fun times (Ljava/lang/Number;F)Ljava/lang/Float; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (F)Ljava/lang/Float; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;F)Ljava/lang/Float; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public fun unaryPlus (F)Ljava/lang/Float; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/HyperbolicOperations : space/kscience/kmath/operations/Algebra { + public static final field ACOSH_OPERATION Ljava/lang/String; + public static final field ASINH_OPERATION Ljava/lang/String; + public static final field ATANH_OPERATION Ljava/lang/String; + public static final field COSH_OPERATION Ljava/lang/String; + public static final field Companion Lspace/kscience/kmath/operations/HyperbolicOperations$Companion; + public static final field SINH_OPERATION Ljava/lang/String; + public static final field TANH_OPERATION Ljava/lang/String; + public abstract fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun tanh (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/HyperbolicOperations$Companion { + public static final field ACOSH_OPERATION Ljava/lang/String; + public static final field ASINH_OPERATION Ljava/lang/String; + public static final field ATANH_OPERATION Ljava/lang/String; + public static final field COSH_OPERATION Ljava/lang/String; + public static final field SINH_OPERATION Ljava/lang/String; + public static final field TANH_OPERATION Ljava/lang/String; +} + +public final class space/kscience/kmath/operations/HyperbolicOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/operations/IntRing : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { + public static final field INSTANCE Lspace/kscience/kmath/operations/IntRing; + public fun add (II)Ljava/lang/Integer; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;II)Ljava/lang/Integer; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Integer; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun div (ILjava/lang/Number;)Ljava/lang/Integer; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun getOne ()Ljava/lang/Integer; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Integer; + public synthetic fun getZero ()Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;I)Ljava/lang/Integer; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun minus (II)Ljava/lang/Integer; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (II)Ljava/lang/Integer; + public fun multiply (ILjava/lang/Number;)Ljava/lang/Integer; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (I)Ljava/lang/Integer; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Integer; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (II)Ljava/lang/Integer; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;ILjava/lang/Number;)Ljava/lang/Integer; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun times (II)Ljava/lang/Integer; + public fun times (ILjava/lang/Number;)Ljava/lang/Integer; + public fun times (Ljava/lang/Number;I)Ljava/lang/Integer; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (I)Ljava/lang/Integer; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;I)Ljava/lang/Integer; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public fun unaryPlus (I)Ljava/lang/Integer; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/JBigDecimalField : space/kscience/kmath/operations/JBigDecimalFieldBase { + public static final field Companion Lspace/kscience/kmath/operations/JBigDecimalField$Companion; + public fun ()V + public fun (Ljava/math/MathContext;)V + public synthetic fun (Ljava/math/MathContext;ILkotlin/jvm/internal/DefaultConstructorMarker;)V +} + +public final class space/kscience/kmath/operations/JBigDecimalField$Companion : space/kscience/kmath/operations/JBigDecimalFieldBase { +} + +public abstract class space/kscience/kmath/operations/JBigDecimalFieldBase : space/kscience/kmath/operations/Field, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/PowerOperations { + public fun ()V + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Ljava/math/BigDecimal; + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/lang/Number;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/math/BigDecimal;Ljava/lang/Number;)Ljava/math/BigDecimal; + public fun div (Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Ljava/math/BigDecimal; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Ljava/math/BigDecimal; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Ljava/math/BigDecimal;Ljava/lang/Number;)Ljava/math/BigDecimal; + public fun multiply (Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/math/BigDecimal; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Ljava/math/BigDecimal;Ljava/lang/Number;)Ljava/math/BigDecimal; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (Ljava/math/BigDecimal;Ljava/lang/Number;)Ljava/math/BigDecimal; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Ljava/math/BigDecimal;Ljava/lang/Number;)Ljava/math/BigDecimal; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/math/BigDecimal;Ljava/lang/Number;)Ljava/math/BigDecimal; + public fun times (Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Ljava/math/BigDecimal;)Ljava/math/BigDecimal; +} + +public final class space/kscience/kmath/operations/JBigIntegerField : space/kscience/kmath/operations/Field, space/kscience/kmath/operations/NumericAlgebra { + public static final field INSTANCE Lspace/kscience/kmath/operations/JBigIntegerField; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Ljava/math/BigInteger; + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/lang/Number;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/math/BigInteger;Ljava/lang/Number;)Ljava/math/BigInteger; + public fun div (Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Ljava/math/BigInteger; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Ljava/math/BigInteger; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Ljava/math/BigInteger;Ljava/lang/Number;)Ljava/math/BigInteger; + public fun multiply (Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/math/BigInteger; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Ljava/math/BigInteger;Ljava/lang/Number;)Ljava/math/BigInteger; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/math/BigInteger;Ljava/lang/Number;)Ljava/math/BigInteger; + public fun times (Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Ljava/math/BigInteger;)Ljava/math/BigInteger; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Ljava/math/BigInteger;)Ljava/math/BigInteger; +} + +public abstract interface annotation class space/kscience/kmath/operations/KMathContext : java/lang/annotation/Annotation { +} + +public final class space/kscience/kmath/operations/LongRing : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { + public static final field INSTANCE Lspace/kscience/kmath/operations/LongRing; + public fun add (JJ)Ljava/lang/Long; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;JJ)Ljava/lang/Long; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Long; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun div (JLjava/lang/Number;)Ljava/lang/Long; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun getOne ()Ljava/lang/Long; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Long; + public synthetic fun getZero ()Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;J)Ljava/lang/Long; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun minus (JJ)Ljava/lang/Long; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (JJ)Ljava/lang/Long; + public fun multiply (JLjava/lang/Number;)Ljava/lang/Long; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (J)Ljava/lang/Long; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Long; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (JJ)Ljava/lang/Long; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;JLjava/lang/Number;)Ljava/lang/Long; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun times (JJ)Ljava/lang/Long; + public fun times (JLjava/lang/Number;)Ljava/lang/Long; + public fun times (Ljava/lang/Number;J)Ljava/lang/Long; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (J)Ljava/lang/Long; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;J)Ljava/lang/Long; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public fun unaryPlus (J)Ljava/lang/Long; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/Norm { + public abstract fun norm (Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/NumericAlgebra : space/kscience/kmath/operations/Algebra { + public abstract fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public abstract fun number (Ljava/lang/Number;)Ljava/lang/Object; + public abstract fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public abstract fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; +} + +public final class space/kscience/kmath/operations/NumericAlgebra$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/NumericAlgebra;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Ljava/lang/Object; + public static fun leftSideNumberOperation (Lspace/kscience/kmath/operations/NumericAlgebra;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun leftSideNumberOperationFunction (Lspace/kscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun rightSideNumberOperation (Lspace/kscience/kmath/operations/NumericAlgebra;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun rightSideNumberOperationFunction (Lspace/kscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun unaryOperation (Lspace/kscience/kmath/operations/NumericAlgebra;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/operations/OptionalOperationsKt { +} + +public abstract interface class space/kscience/kmath/operations/PowerOperations : space/kscience/kmath/operations/Algebra { + public static final field Companion Lspace/kscience/kmath/operations/PowerOperations$Companion; + public static final field POW_OPERATION Ljava/lang/String; + public static final field SQRT_OPERATION Ljava/lang/String; + public abstract fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public abstract fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public abstract fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/PowerOperations$Companion { + public static final field POW_OPERATION Ljava/lang/String; + public static final field SQRT_OPERATION Ljava/lang/String; +} + +public final class space/kscience/kmath/operations/PowerOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/PowerOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/PowerOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/PowerOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun pow (Lspace/kscience/kmath/operations/PowerOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun sqrt (Lspace/kscience/kmath/operations/PowerOperations;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/PowerOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/PowerOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/operations/RealField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm { + public static final field INSTANCE Lspace/kscience/kmath/operations/RealField; + public fun acos (D)Ljava/lang/Double; + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (D)Ljava/lang/Double; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun add (DD)Ljava/lang/Double; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (D)Ljava/lang/Double; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (D)Ljava/lang/Double; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (D)Ljava/lang/Double; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (D)Ljava/lang/Double; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;DD)Ljava/lang/Double; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Double; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun cos (D)Ljava/lang/Double; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (D)Ljava/lang/Double; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun div (DD)Ljava/lang/Double; + public fun div (DLjava/lang/Number;)Ljava/lang/Double; + public fun div (Ljava/lang/Number;D)Ljava/lang/Double; + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (DD)Ljava/lang/Double; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (D)Ljava/lang/Double; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun getOne ()Ljava/lang/Double; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Double; + public synthetic fun getZero ()Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;D)Ljava/lang/Double; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun ln (D)Ljava/lang/Double; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (DD)Ljava/lang/Double; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (DD)Ljava/lang/Double; + public fun multiply (DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (D)Ljava/lang/Double; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Double; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (DD)Ljava/lang/Double; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun pow (DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun sin (D)Ljava/lang/Double; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (D)Ljava/lang/Double; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (D)Ljava/lang/Double; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (D)Ljava/lang/Double; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (D)Ljava/lang/Double; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun times (DD)Ljava/lang/Double; + public fun times (DLjava/lang/Number;)Ljava/lang/Double; + public fun times (Ljava/lang/Number;D)Ljava/lang/Double; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (D)Ljava/lang/Double; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;D)Ljava/lang/Double; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public fun unaryPlus (D)Ljava/lang/Double; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/Ring : space/kscience/kmath/operations/RingOperations, space/kscience/kmath/operations/Space { + public abstract fun getOne ()Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/Ring$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/Ring;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/Ring;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/Ring;Ljava/lang/String;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/Ring;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryMinus (Lspace/kscience/kmath/operations/Ring;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/Ring;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/Ring;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/Ring;Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/RingOperations : space/kscience/kmath/operations/SpaceOperations { + public static final field Companion Lspace/kscience/kmath/operations/RingOperations$Companion; + public static final field TIMES_OPERATION Ljava/lang/String; + public abstract fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public abstract fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/RingOperations$Companion { + public static final field TIMES_OPERATION Ljava/lang/String; +} + +public final class space/kscience/kmath/operations/RingOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryMinus (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/RingOperations;Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/RingWithNumbers$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun leftSideNumberOperation (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun leftSideNumberOperationFunction (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun minus (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun number (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Number;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun rightSideNumberOperation (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun rightSideNumberOperationFunction (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun times (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryMinus (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/ShortRing : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { + public static final field INSTANCE Lspace/kscience/kmath/operations/ShortRing; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (SS)Ljava/lang/Short; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;SS)Ljava/lang/Short; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Short; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun div (SLjava/lang/Number;)Ljava/lang/Short; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Ljava/lang/Short; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Short; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;S)Ljava/lang/Short; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (SS)Ljava/lang/Short; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (SLjava/lang/Number;)Ljava/lang/Short; + public fun multiply (SS)Ljava/lang/Short; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (S)Ljava/lang/Short; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Short; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (SS)Ljava/lang/Short; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;SLjava/lang/Number;)Ljava/lang/Short; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;S)Ljava/lang/Short; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (SLjava/lang/Number;)Ljava/lang/Short; + public fun times (SS)Ljava/lang/Short; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (S)Ljava/lang/Short; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;S)Ljava/lang/Short; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (S)Ljava/lang/Short; +} + +public abstract interface class space/kscience/kmath/operations/Space : space/kscience/kmath/operations/SpaceOperations { + public abstract fun getZero ()Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/Space$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/Space;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/Space;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/Space;Ljava/lang/String;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/Space;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/Space;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/Space;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/Space;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/Space;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun unaryMinus (Lspace/kscience/kmath/operations/Space;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/Space;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/Space;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/Space;Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/SpaceOperations : space/kscience/kmath/operations/Algebra { + public static final field Companion Lspace/kscience/kmath/operations/SpaceOperations$Companion; + public static final field MINUS_OPERATION Ljava/lang/String; + public static final field PLUS_OPERATION Ljava/lang/String; + public abstract fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public abstract fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public abstract fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public abstract fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public abstract fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public abstract fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/SpaceOperations$Companion { + public static final field MINUS_OPERATION Ljava/lang/String; + public static final field PLUS_OPERATION Ljava/lang/String; +} + +public final class space/kscience/kmath/operations/SpaceOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun unaryMinus (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/SpaceOperations;Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/TrigonometricOperations : space/kscience/kmath/operations/Algebra { + public static final field ACOS_OPERATION Ljava/lang/String; + public static final field ASIN_OPERATION Ljava/lang/String; + public static final field ATAN_OPERATION Ljava/lang/String; + public static final field COS_OPERATION Ljava/lang/String; + public static final field Companion Lspace/kscience/kmath/operations/TrigonometricOperations$Companion; + public static final field SIN_OPERATION Ljava/lang/String; + public static final field TAN_OPERATION Ljava/lang/String; + public abstract fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun tan (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/TrigonometricOperations$Companion { + public static final field ACOS_OPERATION Ljava/lang/String; + public static final field ASIN_OPERATION Ljava/lang/String; + public static final field ATAN_OPERATION Ljava/lang/String; + public static final field COS_OPERATION Ljava/lang/String; + public static final field SIN_OPERATION Ljava/lang/String; + public static final field TAN_OPERATION Ljava/lang/String; +} + +public final class space/kscience/kmath/operations/TrigonometricOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/structures/ArrayBuffer : space/kscience/kmath/structures/MutableBuffer { + public fun ([Ljava/lang/Object;)V + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun get (I)Ljava/lang/Object; + public fun getSize ()I + public fun iterator ()Ljava/util/Iterator; + public fun set (ILjava/lang/Object;)V +} + +public abstract interface class space/kscience/kmath/structures/Buffer { + public static final field Companion Lspace/kscience/kmath/structures/Buffer$Companion; + public abstract fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public abstract fun get (I)Ljava/lang/Object; + public abstract fun getSize ()I + public abstract fun iterator ()Ljava/util/Iterator; +} + +public final class space/kscience/kmath/structures/Buffer$Companion { + public final fun auto (Lkotlin/reflect/KClass;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public final fun boxing (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public final fun real-8hrHhI4 (ILkotlin/jvm/functions/Function1;)[D +} + +public final class space/kscience/kmath/structures/Buffer$DefaultImpls { + public static fun contentEquals (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Z +} + +public final class space/kscience/kmath/structures/BufferKt { + public static final fun ListBuffer (ILkotlin/jvm/functions/Function1;)Ljava/util/List; + public static final fun asBuffer (Ljava/util/List;)Ljava/util/List; + public static final fun asBuffer ([Ljava/lang/Object;)Lspace/kscience/kmath/structures/ArrayBuffer; + public static final fun asIterable (Lspace/kscience/kmath/structures/Buffer;)Ljava/lang/Iterable; + public static final fun asReadOnly (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static final fun asSequence (Lspace/kscience/kmath/structures/Buffer;)Lkotlin/sequences/Sequence; + public static final fun getIndices (Lspace/kscience/kmath/structures/Buffer;)Lkotlin/ranges/IntRange; + public static final fun toList (Lspace/kscience/kmath/structures/Buffer;)Ljava/util/List; +} + +public abstract interface class space/kscience/kmath/structures/FlaggedBuffer : space/kscience/kmath/structures/Buffer { + public abstract fun getFlag (I)B +} + +public final class space/kscience/kmath/structures/FlaggedBuffer$DefaultImpls { + public static fun contentEquals (Lspace/kscience/kmath/structures/FlaggedBuffer;Lspace/kscience/kmath/structures/Buffer;)Z +} + +public final class space/kscience/kmath/structures/FlaggedBufferKt { + public static final fun forEachValid (Lspace/kscience/kmath/structures/FlaggedRealBuffer;Lkotlin/jvm/functions/Function1;)V + public static final fun hasFlag (Lspace/kscience/kmath/structures/FlaggedBuffer;ILspace/kscience/kmath/structures/ValueFlag;)Z + public static final fun isMissing (Lspace/kscience/kmath/structures/FlaggedBuffer;I)Z + public static final fun isValid (Lspace/kscience/kmath/structures/FlaggedBuffer;I)Z +} + +public final class space/kscience/kmath/structures/FlaggedRealBuffer : space/kscience/kmath/structures/Buffer, space/kscience/kmath/structures/FlaggedBuffer { + public fun ([D[B)V + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public fun get (I)Ljava/lang/Double; + public synthetic fun get (I)Ljava/lang/Object; + public fun getFlag (I)B + public final fun getFlags ()[B + public fun getSize ()I + public final fun getValues ()[D + public fun iterator ()Ljava/util/Iterator; +} + +public final class space/kscience/kmath/structures/FloatBuffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl ([F)Lspace/kscience/kmath/structures/FloatBuffer; + public static fun constructor-impl ([F)[F + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl ([FLspace/kscience/kmath/structures/Buffer;)Z + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static fun copy-impl ([F)Lspace/kscience/kmath/structures/MutableBuffer; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([FLjava/lang/Object;)Z + public static final fun equals-impl0 ([F[F)Z + public fun get (I)Ljava/lang/Float; + public synthetic fun get (I)Ljava/lang/Object; + public static fun get-impl ([FI)Ljava/lang/Float; + public final fun getArray ()[F + public fun getSize ()I + public static fun getSize-impl ([F)I + public fun hashCode ()I + public static fun hashCode-impl ([F)I + public synthetic fun iterator ()Ljava/util/Iterator; + public fun iterator ()Lkotlin/collections/FloatIterator; + public static fun iterator-impl ([F)Lkotlin/collections/FloatIterator; + public fun set (IF)V + public synthetic fun set (ILjava/lang/Object;)V + public static fun set-impl ([FIF)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl ([F)Ljava/lang/String; + public final synthetic fun unbox-impl ()[F +} + +public final class space/kscience/kmath/structures/FloatBufferKt { + public static final fun FloatBuffer (ILkotlin/jvm/functions/Function1;)[F + public static final fun FloatBuffer ([F)[F + public static final fun asBuffer ([F)[F + public static final fun getArray (Lspace/kscience/kmath/structures/MutableBuffer;)[F +} + +public final class space/kscience/kmath/structures/IntBuffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl ([I)Lspace/kscience/kmath/structures/IntBuffer; + public static fun constructor-impl ([I)[I + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl ([ILspace/kscience/kmath/structures/Buffer;)Z + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static fun copy-impl ([I)Lspace/kscience/kmath/structures/MutableBuffer; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([ILjava/lang/Object;)Z + public static final fun equals-impl0 ([I[I)Z + public fun get (I)Ljava/lang/Integer; + public synthetic fun get (I)Ljava/lang/Object; + public static fun get-impl ([II)Ljava/lang/Integer; + public final fun getArray ()[I + public fun getSize ()I + public static fun getSize-impl ([I)I + public fun hashCode ()I + public static fun hashCode-impl ([I)I + public synthetic fun iterator ()Ljava/util/Iterator; + public fun iterator ()Lkotlin/collections/IntIterator; + public static fun iterator-impl ([I)Lkotlin/collections/IntIterator; + public fun set (II)V + public synthetic fun set (ILjava/lang/Object;)V + public static fun set-impl ([III)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl ([I)Ljava/lang/String; + public final synthetic fun unbox-impl ()[I +} + +public final class space/kscience/kmath/structures/IntBufferKt { + public static final fun IntBuffer (ILkotlin/jvm/functions/Function1;)[I + public static final fun IntBuffer ([I)[I + public static final fun asBuffer ([I)[I + public static final fun getArray (Lspace/kscience/kmath/structures/MutableBuffer;)[I +} + +public final class space/kscience/kmath/structures/ListBuffer : space/kscience/kmath/structures/Buffer { + public static final synthetic fun box-impl (Ljava/util/List;)Lspace/kscience/kmath/structures/ListBuffer; + public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl (Ljava/util/List;Lspace/kscience/kmath/structures/Buffer;)Z + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z + public fun get (I)Ljava/lang/Object; + public static fun get-impl (Ljava/util/List;I)Ljava/lang/Object; + public final fun getList ()Ljava/util/List; + public fun getSize ()I + public static fun getSize-impl (Ljava/util/List;)I + public fun hashCode ()I + public static fun hashCode-impl (Ljava/util/List;)I + public fun iterator ()Ljava/util/Iterator; + public static fun iterator-impl (Ljava/util/List;)Ljava/util/Iterator; + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/List; +} + +public final class space/kscience/kmath/structures/LongBuffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl ([J)Lspace/kscience/kmath/structures/LongBuffer; + public static fun constructor-impl ([J)[J + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl ([JLspace/kscience/kmath/structures/Buffer;)Z + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static fun copy-impl ([J)Lspace/kscience/kmath/structures/MutableBuffer; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([JLjava/lang/Object;)Z + public static final fun equals-impl0 ([J[J)Z + public fun get (I)Ljava/lang/Long; + public synthetic fun get (I)Ljava/lang/Object; + public static fun get-impl ([JI)Ljava/lang/Long; + public final fun getArray ()[J + public fun getSize ()I + public static fun getSize-impl ([J)I + public fun hashCode ()I + public static fun hashCode-impl ([J)I + public synthetic fun iterator ()Ljava/util/Iterator; + public fun iterator ()Lkotlin/collections/LongIterator; + public static fun iterator-impl ([J)Lkotlin/collections/LongIterator; + public fun set (IJ)V + public synthetic fun set (ILjava/lang/Object;)V + public static fun set-impl ([JIJ)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl ([J)Ljava/lang/String; + public final synthetic fun unbox-impl ()[J +} + +public final class space/kscience/kmath/structures/LongBufferKt { + public static final fun LongBuffer (ILkotlin/jvm/functions/Function1;)[J + public static final fun LongBuffer ([J)[J + public static final fun asBuffer ([J)[J + public static final fun getArray (Lspace/kscience/kmath/structures/MutableBuffer;)[J +} + +public class space/kscience/kmath/structures/MemoryBuffer : space/kscience/kmath/structures/Buffer { + public static final field Companion Lspace/kscience/kmath/structures/MemoryBuffer$Companion; + public fun (Lspace/kscience/kmath/memory/Memory;Lspace/kscience/kmath/memory/MemorySpec;)V + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public fun get (I)Ljava/lang/Object; + protected final fun getMemory ()Lspace/kscience/kmath/memory/Memory; + public fun getSize ()I + protected final fun getSpec ()Lspace/kscience/kmath/memory/MemorySpec; + public fun iterator ()Ljava/util/Iterator; +} + +public final class space/kscience/kmath/structures/MemoryBuffer$Companion { + public final fun create (Lspace/kscience/kmath/memory/MemorySpec;I)Lspace/kscience/kmath/structures/MemoryBuffer; + public final fun create (Lspace/kscience/kmath/memory/MemorySpec;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MemoryBuffer; +} + +public abstract interface class space/kscience/kmath/structures/MutableBuffer : space/kscience/kmath/structures/Buffer { + public static final field Companion Lspace/kscience/kmath/structures/MutableBuffer$Companion; + public abstract fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public abstract fun set (ILjava/lang/Object;)V +} + +public final class space/kscience/kmath/structures/MutableBuffer$Companion { + public final fun auto (Lkotlin/reflect/KClass;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; + public final fun boxing (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; + public final fun real-8hrHhI4 (ILkotlin/jvm/functions/Function1;)[D +} + +public final class space/kscience/kmath/structures/MutableBuffer$DefaultImpls { + public static fun contentEquals (Lspace/kscience/kmath/structures/MutableBuffer;Lspace/kscience/kmath/structures/Buffer;)Z +} + +public final class space/kscience/kmath/structures/MutableListBuffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl (Ljava/util/List;)Lspace/kscience/kmath/structures/MutableListBuffer; + public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl (Ljava/util/List;Lspace/kscience/kmath/structures/Buffer;)Z + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static fun copy-impl (Ljava/util/List;)Lspace/kscience/kmath/structures/MutableBuffer; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z + public fun get (I)Ljava/lang/Object; + public static fun get-impl (Ljava/util/List;I)Ljava/lang/Object; + public final fun getList ()Ljava/util/List; + public fun getSize ()I + public static fun getSize-impl (Ljava/util/List;)I + public fun hashCode ()I + public static fun hashCode-impl (Ljava/util/List;)I + public fun iterator ()Ljava/util/Iterator; + public static fun iterator-impl (Ljava/util/List;)Ljava/util/Iterator; + public fun set (ILjava/lang/Object;)V + public static fun set-impl (Ljava/util/List;ILjava/lang/Object;)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/List; +} + +public final class space/kscience/kmath/structures/MutableMemoryBuffer : space/kscience/kmath/structures/MemoryBuffer, space/kscience/kmath/structures/MutableBuffer { + public static final field Companion Lspace/kscience/kmath/structures/MutableMemoryBuffer$Companion; + public fun (Lspace/kscience/kmath/memory/Memory;Lspace/kscience/kmath/memory/MemorySpec;)V + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun set (ILjava/lang/Object;)V +} + +public final class space/kscience/kmath/structures/MutableMemoryBuffer$Companion { + public final fun create (Lspace/kscience/kmath/memory/MemorySpec;I)Lspace/kscience/kmath/structures/MutableMemoryBuffer; + public final fun create (Lspace/kscience/kmath/memory/MemorySpec;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableMemoryBuffer; +} + +public final class space/kscience/kmath/structures/ReadOnlyBuffer : space/kscience/kmath/structures/Buffer { + public static final synthetic fun box-impl (Lspace/kscience/kmath/structures/MutableBuffer;)Lspace/kscience/kmath/structures/ReadOnlyBuffer; + public static fun constructor-impl (Lspace/kscience/kmath/structures/MutableBuffer;)Lspace/kscience/kmath/structures/MutableBuffer; + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl (Lspace/kscience/kmath/structures/MutableBuffer;Lspace/kscience/kmath/structures/Buffer;)Z + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Lspace/kscience/kmath/structures/MutableBuffer;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Lspace/kscience/kmath/structures/MutableBuffer;Lspace/kscience/kmath/structures/MutableBuffer;)Z + public fun get (I)Ljava/lang/Object; + public static fun get-impl (Lspace/kscience/kmath/structures/MutableBuffer;I)Ljava/lang/Object; + public final fun getBuffer ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun getSize ()I + public static fun getSize-impl (Lspace/kscience/kmath/structures/MutableBuffer;)I + public fun hashCode ()I + public static fun hashCode-impl (Lspace/kscience/kmath/structures/MutableBuffer;)I + public fun iterator ()Ljava/util/Iterator; + public static fun iterator-impl (Lspace/kscience/kmath/structures/MutableBuffer;)Ljava/util/Iterator; + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Lspace/kscience/kmath/structures/MutableBuffer;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Lspace/kscience/kmath/structures/MutableBuffer; +} + +public final class space/kscience/kmath/structures/RealBuffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl ([D)Lspace/kscience/kmath/structures/RealBuffer; + public static fun constructor-impl ([D)[D + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl ([DLspace/kscience/kmath/structures/Buffer;)Z + public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun copy-88GwAag ()[D + public static fun copy-88GwAag ([D)[D + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([DLjava/lang/Object;)Z + public static final fun equals-impl0 ([D[D)Z + public fun get (I)Ljava/lang/Double; + public synthetic fun get (I)Ljava/lang/Object; + public static fun get-impl ([DI)Ljava/lang/Double; + public final fun getArray ()[D + public fun getSize ()I + public static fun getSize-impl ([D)I + public fun hashCode ()I + public static fun hashCode-impl ([D)I + public synthetic fun iterator ()Ljava/util/Iterator; + public fun iterator ()Lkotlin/collections/DoubleIterator; + public static fun iterator-impl ([D)Lkotlin/collections/DoubleIterator; + public fun set (ID)V + public synthetic fun set (ILjava/lang/Object;)V + public static fun set-impl ([DID)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl ([D)Ljava/lang/String; + public final synthetic fun unbox-impl ()[D +} + +public final class space/kscience/kmath/structures/RealBufferField : space/kscience/kmath/operations/ExtendedField { + public fun (I)V + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public fun div (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/structures/Buffer; + public final fun getSize ()I + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/structures/Buffer; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D + public fun multiply-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public fun times (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/structures/RealBufferFieldOperations : space/kscience/kmath/operations/ExtendedFieldOperations { + public static final field INSTANCE Lspace/kscience/kmath/structures/RealBufferFieldOperations; + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public fun div (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D + public fun multiply-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public fun times (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/structures/RealBufferKt { + public static final fun RealBuffer (ILkotlin/jvm/functions/Function1;)[D + public static final fun RealBuffer ([D)[D + public static final fun asBuffer ([D)[D + public static final fun contentEquals-2uVC2J0 ([D[D)Z + public static final fun getArray (Lspace/kscience/kmath/structures/MutableBuffer;)[D +} + +public final class space/kscience/kmath/structures/ShortBuffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl ([S)Lspace/kscience/kmath/structures/ShortBuffer; + public static fun constructor-impl ([S)[S + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl ([SLspace/kscience/kmath/structures/Buffer;)Z + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static fun copy-impl ([S)Lspace/kscience/kmath/structures/MutableBuffer; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([SLjava/lang/Object;)Z + public static final fun equals-impl0 ([S[S)Z + public synthetic fun get (I)Ljava/lang/Object; + public fun get (I)Ljava/lang/Short; + public static fun get-impl ([SI)Ljava/lang/Short; + public final fun getArray ()[S + public fun getSize ()I + public static fun getSize-impl ([S)I + public fun hashCode ()I + public static fun hashCode-impl ([S)I + public synthetic fun iterator ()Ljava/util/Iterator; + public fun iterator ()Lkotlin/collections/ShortIterator; + public static fun iterator-impl ([S)Lkotlin/collections/ShortIterator; + public synthetic fun set (ILjava/lang/Object;)V + public fun set (IS)V + public static fun set-impl ([SIS)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl ([S)Ljava/lang/String; + public final synthetic fun unbox-impl ()[S +} + +public final class space/kscience/kmath/structures/ShortBufferKt { + public static final fun ShortBuffer (ILkotlin/jvm/functions/Function1;)[S + public static final fun ShortBuffer ([S)[S + public static final fun asBuffer ([S)[S + public static final fun getArray (Lspace/kscience/kmath/structures/MutableBuffer;)[S +} + +public final class space/kscience/kmath/structures/ValueFlag : java/lang/Enum { + public static final field MISSING Lspace/kscience/kmath/structures/ValueFlag; + public static final field NAN Lspace/kscience/kmath/structures/ValueFlag; + public static final field NEGATIVE_INFINITY Lspace/kscience/kmath/structures/ValueFlag; + public static final field POSITIVE_INFINITY Lspace/kscience/kmath/structures/ValueFlag; + public final fun getMask ()B + public static fun valueOf (Ljava/lang/String;)Lspace/kscience/kmath/structures/ValueFlag; + public static fun values ()[Lspace/kscience/kmath/structures/ValueFlag; +} + +public final class space/kscience/kmath/structures/VirtualBuffer : space/kscience/kmath/structures/Buffer { + public fun (ILkotlin/jvm/functions/Function1;)V + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public fun get (I)Ljava/lang/Object; + public fun getSize ()I + public fun iterator ()Ljava/util/Iterator; +} + diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 9ed7e690b..8d30f1d6e 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -1,31 +1,45 @@ +import ru.mipt.npm.gradle.Maturity + plugins { - id("ru.mipt.npm.mpp") - id("ru.mipt.npm.native") + id("ru.mipt.npm.gradle.mpp") + id("ru.mipt.npm.gradle.native") } -kotlin.sourceSets.commonMain { - dependencies { - api(project(":kmath-memory")) +kotlin.sourceSets { + commonMain { + dependencies { + api(project(":kmath-memory")) + } } } readme { description = "Core classes, algebra definitions, basic linear algebra" - maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT + maturity = Maturity.DEVELOPMENT propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature( id = "algebras", - description = "Algebraic structures: contexts and elements", + description = """ + Algebraic structures like rings, spaces and fields. + """.trimIndent(), ref = "src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt" ) feature( id = "nd", - description = "Many-dimensional structures", + description = "Many-dimensional structures and operations on them.", ref = "src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt" ) + feature( + id = "linear", + description = """ + Basic linear algebra operations (sums, products, etc.), backed by the `Space` API. Advanced linear algebra operations like matrix inversion and LU decomposition. + """.trimIndent(), + ref = "src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt" + ) + feature( id = "buffers", description = "One-dimensional structure", @@ -34,7 +48,11 @@ readme { feature( id = "expressions", - description = "Functional Expressions", + description = """ + 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. + """.trimIndent(), ref = "src/commonMain/kotlin/kscience/kmath/expressions" ) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/BufferMatrix.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/BufferMatrix.kt deleted file mode 100644 index a74d948fc..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/BufferMatrix.kt +++ /dev/null @@ -1,68 +0,0 @@ -package kscience.kmath.linear - -import kscience.kmath.operations.Ring -import kscience.kmath.structures.* - -/** - * Basic implementation of Matrix space based on [NDStructure] - */ -public class BufferMatrixContext>( - public override val elementContext: R, - private val bufferFactory: BufferFactory, -) : GenericMatrixContext> { - public override fun produce(rows: Int, columns: Int, initializer: (i: Int, j: Int) -> T): BufferMatrix { - val buffer = bufferFactory(rows * columns) { offset -> initializer(offset / columns, offset % columns) } - return BufferMatrix(rows, columns, buffer) - } - - public override fun point(size: Int, initializer: (Int) -> T): Point = bufferFactory(size, initializer) - - public companion object -} - -public class BufferMatrix( - public override val rowNum: Int, - public override val colNum: Int, - public val buffer: Buffer, -) : Matrix { - - init { - require(buffer.size == rowNum * colNum) { "Dimension mismatch for matrix structure" } - } - - override val shape: IntArray get() = intArrayOf(rowNum, colNum) - - public override operator fun get(index: IntArray): T = get(index[0], index[1]) - public override operator fun get(i: Int, j: Int): T = buffer[i * colNum + j] - - public override fun elements(): Sequence> = sequence { - for (i in 0 until rowNum) for (j in 0 until colNum) yield(intArrayOf(i, j) to get(i, j)) - } - - public override fun equals(other: Any?): Boolean { - if (this === other) return true - - return when (other) { - is NDStructure<*> -> NDStructure.contentEquals(this, other) - else -> false - } - } - - override fun hashCode(): Int { - var result = rowNum - result = 31 * result + colNum - result = 31 * result + buffer.hashCode() - return result - } - - public override fun toString(): String { - return if (rowNum <= 5 && colNum <= 5) - "Matrix(rowsNum = $rowNum, colNum = $colNum)\n" + - rows.asSequence().joinToString(prefix = "(", postfix = ")", separator = "\n ") { buffer -> - buffer.asSequence().joinToString(separator = "\t") { it.toString() } - } - else "Matrix(rowsNum = $rowNum, colNum = $colNum)" - } - - -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/AlgebraElements.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/AlgebraElements.kt deleted file mode 100644 index aa572d894..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/AlgebraElements.kt +++ /dev/null @@ -1,108 +0,0 @@ -package kscience.kmath.operations - -/** - * The generic mathematics elements which is able to store its context - * - * @param C the type of mathematical context for this element. - */ -public interface MathElement { - /** - * The context this element belongs to. - */ - public val context: C -} - -/** - * Represents element that can be wrapped to its "primitive" value. - * - * @param T the type wrapped by this wrapper. - * @param I the type of this wrapper. - */ -public interface MathWrapper { - /** - * Unwraps [I] to [T]. - */ - public fun unwrap(): T - - /** - * Wraps [T] to [I]. - */ - public fun T.wrap(): I -} - -/** - * The element of [Space]. - * - * @param T the type of space operation results. - * @param I self type of the element. Needed for static type checking. - * @param S the type of space. - */ -public interface SpaceElement, S : Space> : MathElement, MathWrapper { - /** - * Adds element to this one. - * - * @param b the augend. - * @return the sum. - */ - public operator fun plus(b: T): I = context.add(unwrap(), b).wrap() - - /** - * Subtracts element from this one. - * - * @param b the subtrahend. - * @return the difference. - */ - public operator fun minus(b: T): I = context.add(unwrap(), context.multiply(b, -1.0)).wrap() - - /** - * Multiplies this element by number. - * - * @param k the multiplicand. - * @return the product. - */ - public operator fun times(k: Number): I = context.multiply(unwrap(), k.toDouble()).wrap() - - /** - * Divides this element by number. - * - * @param k the divisor. - * @return the quotient. - */ - public operator fun div(k: Number): I = context.multiply(unwrap(), 1.0 / k.toDouble()).wrap() -} - -/** - * The element of [Ring]. - * - * @param T the type of ring operation results. - * @param I self type of the element. Needed for static type checking. - * @param R the type of ring. - */ -public interface RingElement, R : Ring> : SpaceElement { - /** - * Multiplies this element by another one. - * - * @param b the multiplicand. - * @return the product. - */ - public operator fun times(b: T): I = context.multiply(unwrap(), b).wrap() -} - -/** - * The element of [Field]. - * - * @param T the type of field operation results. - * @param I self type of the element. Needed for static type checking. - * @param F the type of field. - */ -public interface FieldElement, F : Field> : RingElement { - override val context: F - - /** - * Divides this element by another one. - * - * @param b the divisor. - * @return the quotient. - */ - public operator fun div(b: T): I = context.divide(unwrap(), b).wrap() -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BoxingNDField.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BoxingNDField.kt deleted file mode 100644 index dc65b12c4..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BoxingNDField.kt +++ /dev/null @@ -1,81 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.Field -import kscience.kmath.operations.FieldElement - -public class BoxingNDField>( - public override val shape: IntArray, - public override val elementContext: F, - public val bufferFactory: BufferFactory -) : BufferedNDField { - public override val zero: BufferedNDFieldElement by lazy { produce { zero } } - public override val one: BufferedNDFieldElement by lazy { produce { one } } - public override val strides: Strides = DefaultStrides(shape) - - public fun buildBuffer(size: Int, initializer: (Int) -> T): Buffer = - bufferFactory(size, initializer) - - public override fun check(vararg elements: NDBuffer): Array> { - require(elements.all { it.strides == strides }) { "Element strides are not the same as context strides" } - return elements - } - - public override fun produce(initializer: F.(IntArray) -> T): BufferedNDFieldElement = - BufferedNDFieldElement( - this, - buildBuffer(strides.linearSize) { offset -> elementContext.initializer(strides.index(offset)) }) - - public override fun map(arg: NDBuffer, transform: F.(T) -> T): BufferedNDFieldElement { - check(arg) - - return BufferedNDFieldElement( - this, - buildBuffer(arg.strides.linearSize) { offset -> elementContext.transform(arg.buffer[offset]) }) - -// val buffer = arg.buffer.transform { _, value -> elementContext.transform(value) } -// return BufferedNDFieldElement(this, buffer) - - } - - public override fun mapIndexed( - arg: NDBuffer, - transform: F.(index: IntArray, T) -> T - ): BufferedNDFieldElement { - check(arg) - return BufferedNDFieldElement( - this, - buildBuffer(arg.strides.linearSize) { offset -> - elementContext.transform( - arg.strides.index(offset), - arg.buffer[offset] - ) - }) - -// val buffer = -// arg.buffer.transform { offset, value -> elementContext.transform(arg.strides.index(offset), value) } -// return BufferedNDFieldElement(this, buffer) - } - - public override fun combine( - a: NDBuffer, - b: NDBuffer, - transform: F.(T, T) -> T - ): BufferedNDFieldElement { - check(a, b) - return BufferedNDFieldElement( - this, - buildBuffer(strides.linearSize) { offset -> elementContext.transform(a.buffer[offset], b.buffer[offset]) }) - } - - public override fun NDBuffer.toElement(): FieldElement, *, out BufferedNDField> = - BufferedNDFieldElement(this@BoxingNDField, buffer) -} - -public inline fun , R> F.nd( - noinline bufferFactory: BufferFactory, - vararg shape: Int, - action: NDField.() -> R -): R { - val ndfield = NDField.boxing(this, *shape, bufferFactory = bufferFactory) - return ndfield.action() -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BoxingNDRing.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BoxingNDRing.kt deleted file mode 100644 index b6794984c..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BoxingNDRing.kt +++ /dev/null @@ -1,71 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.Ring -import kscience.kmath.operations.RingElement - -public class BoxingNDRing>( - override val shape: IntArray, - override val elementContext: R, - public val bufferFactory: BufferFactory -) : BufferedNDRing { - override val strides: Strides = DefaultStrides(shape) - override val zero: BufferedNDRingElement by lazy { produce { zero } } - override val one: BufferedNDRingElement by lazy { produce { one } } - - public fun buildBuffer(size: Int, initializer: (Int) -> T): Buffer = bufferFactory(size, initializer) - - override fun check(vararg elements: NDBuffer): Array> { - if (!elements.all { it.strides == this.strides }) error("Element strides are not the same as context strides") - return elements - } - - override fun produce(initializer: R.(IntArray) -> T): BufferedNDRingElement = - BufferedNDRingElement( - this, - buildBuffer(strides.linearSize) { offset -> elementContext.initializer(strides.index(offset)) }) - - override fun map(arg: NDBuffer, transform: R.(T) -> T): BufferedNDRingElement { - check(arg) - return BufferedNDRingElement( - this, - buildBuffer(arg.strides.linearSize) { offset -> elementContext.transform(arg.buffer[offset]) }) - -// val buffer = arg.buffer.transform { _, value -> elementContext.transform(value) } -// return BufferedNDFieldElement(this, buffer) - - } - - override fun mapIndexed( - arg: NDBuffer, - transform: R.(index: IntArray, T) -> T - ): BufferedNDRingElement { - check(arg) - return BufferedNDRingElement( - this, - buildBuffer(arg.strides.linearSize) { offset -> - elementContext.transform( - arg.strides.index(offset), - arg.buffer[offset] - ) - }) - -// val buffer = -// arg.buffer.transform { offset, value -> elementContext.transform(arg.strides.index(offset), value) } -// return BufferedNDFieldElement(this, buffer) - } - - override fun combine( - a: NDBuffer, - b: NDBuffer, - transform: R.(T, T) -> T - ): BufferedNDRingElement { - check(a, b) - - return BufferedNDRingElement( - this, - buildBuffer(strides.linearSize) { offset -> elementContext.transform(a.buffer[offset], b.buffer[offset]) }) - } - - override fun NDBuffer.toElement(): RingElement, *, out BufferedNDRing> = - BufferedNDRingElement(this@BoxingNDRing, buffer) -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BufferedNDAlgebra.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BufferedNDAlgebra.kt deleted file mode 100644 index 3dcd0322c..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BufferedNDAlgebra.kt +++ /dev/null @@ -1,43 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.* - -public interface BufferedNDAlgebra : NDAlgebra> { - public val strides: Strides - - public override fun check(vararg elements: NDBuffer): Array> { - require(elements.all { it.strides == strides }) { "Strides mismatch" } - return elements - } - - /** - * Convert any [NDStructure] to buffered structure using strides from this context. - * If the structure is already [NDBuffer], conversion is free. If not, it could be expensive because iteration over - * indices. - * - * If the argument is [NDBuffer] with different strides structure, the new element will be produced. - */ - public fun NDStructure.toBuffer(): NDBuffer = - if (this is NDBuffer && this.strides == this@BufferedNDAlgebra.strides) - this - else - produce { index -> this@toBuffer[index] } - - /** - * Convert a buffer to element of this algebra - */ - public fun NDBuffer.toElement(): MathElement> -} - - -public interface BufferedNDSpace> : NDSpace>, BufferedNDAlgebra { - public override fun NDBuffer.toElement(): SpaceElement, *, out BufferedNDSpace> -} - -public interface BufferedNDRing> : NDRing>, BufferedNDSpace { - override fun NDBuffer.toElement(): RingElement, *, out BufferedNDRing> -} - -public interface BufferedNDField> : NDField>, BufferedNDRing { - override fun NDBuffer.toElement(): FieldElement, *, out BufferedNDField> -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BufferedNDElement.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BufferedNDElement.kt deleted file mode 100644 index d53702566..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BufferedNDElement.kt +++ /dev/null @@ -1,86 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.* - -/** - * Base class for an element with context, containing strides - */ -public abstract class BufferedNDElement : NDBuffer(), NDElement> { - abstract override val context: BufferedNDAlgebra - - override val strides: Strides get() = context.strides - - override val shape: IntArray get() = context.shape -} - -public class BufferedNDSpaceElement>( - override val context: BufferedNDSpace, - override val buffer: Buffer -) : BufferedNDElement(), SpaceElement, BufferedNDSpaceElement, BufferedNDSpace> { - - override fun unwrap(): NDBuffer = this - - override fun NDBuffer.wrap(): BufferedNDSpaceElement { - context.check(this) - return BufferedNDSpaceElement(context, buffer) - } -} - -public class BufferedNDRingElement>( - override val context: BufferedNDRing, - override val buffer: Buffer -) : BufferedNDElement(), RingElement, BufferedNDRingElement, BufferedNDRing> { - override fun unwrap(): NDBuffer = this - - override fun NDBuffer.wrap(): BufferedNDRingElement { - context.check(this) - return BufferedNDRingElement(context, buffer) - } -} - -public class BufferedNDFieldElement>( - override val context: BufferedNDField, - override val buffer: Buffer -) : BufferedNDElement(), FieldElement, BufferedNDFieldElement, BufferedNDField> { - override fun unwrap(): NDBuffer = this - - override fun NDBuffer.wrap(): BufferedNDFieldElement { - context.check(this) - return BufferedNDFieldElement(context, buffer) - } -} - - -/** - * Element by element application of any operation on elements to the whole array. Just like in numpy. - */ -public operator fun > Function1.invoke(ndElement: BufferedNDElement): MathElement> = - ndElement.context.run { map(ndElement) { invoke(it) }.toElement() } - -/* plus and minus */ - -/** - * Summation operation for [BufferedNDElement] and single element - */ -public operator fun > BufferedNDElement.plus(arg: T): NDElement> = - context.map(this) { it + arg }.wrap() - -/** - * Subtraction operation between [BufferedNDElement] and single element - */ -public operator fun > BufferedNDElement.minus(arg: T): NDElement> = - context.map(this) { it - arg }.wrap() - -/* prod and div */ - -/** - * Product operation for [BufferedNDElement] and single element - */ -public operator fun > BufferedNDElement.times(arg: T): NDElement> = - context.map(this) { it * arg }.wrap() - -/** - * Division operation between [BufferedNDElement] and single element - */ -public operator fun > BufferedNDElement.div(arg: T): NDElement> = - context.map(this) { it / arg }.wrap() diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ComplexNDField.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ComplexNDField.kt deleted file mode 100644 index 6de69cabe..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ComplexNDField.kt +++ /dev/null @@ -1,158 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.* -import kotlin.contracts.InvocationKind -import kotlin.contracts.contract - -public typealias ComplexNDElement = BufferedNDFieldElement - -/** - * An optimized nd-field for complex numbers - */ -@OptIn(UnstableKMathAPI::class) -public class ComplexNDField(override val shape: IntArray) : - BufferedNDField, - ExtendedNDField>, - RingWithNumbers>{ - - override val strides: Strides = DefaultStrides(shape) - override val elementContext: ComplexField get() = ComplexField - override val zero: ComplexNDElement by lazy { produce { zero } } - override val one: ComplexNDElement by lazy { produce { one } } - - override fun number(value: Number): NDBuffer { - val c = value.toComplex() - return produce { c } - } - - public inline fun buildBuffer(size: Int, crossinline initializer: (Int) -> Complex): Buffer = - Buffer.complex(size) { initializer(it) } - - /** - * Inline transform an NDStructure to another structure - */ - override fun map( - arg: NDBuffer, - transform: ComplexField.(Complex) -> Complex, - ): ComplexNDElement { - check(arg) - val array = buildBuffer(arg.strides.linearSize) { offset -> ComplexField.transform(arg.buffer[offset]) } - return BufferedNDFieldElement(this, array) - } - - override fun produce(initializer: ComplexField.(IntArray) -> Complex): ComplexNDElement { - val array = buildBuffer(strides.linearSize) { offset -> elementContext.initializer(strides.index(offset)) } - return BufferedNDFieldElement(this, array) - } - - override fun mapIndexed( - arg: NDBuffer, - transform: ComplexField.(index: IntArray, Complex) -> Complex, - ): ComplexNDElement { - check(arg) - - return BufferedNDFieldElement( - this, - buildBuffer(arg.strides.linearSize) { offset -> - elementContext.transform( - arg.strides.index(offset), - arg.buffer[offset] - ) - }) - } - - override fun combine( - a: NDBuffer, - b: NDBuffer, - transform: ComplexField.(Complex, Complex) -> Complex, - ): ComplexNDElement { - check(a, b) - - return BufferedNDFieldElement( - this, - buildBuffer(strides.linearSize) { offset -> elementContext.transform(a.buffer[offset], b.buffer[offset]) }) - } - - override fun NDBuffer.toElement(): FieldElement, *, out BufferedNDField> = - BufferedNDFieldElement(this@ComplexNDField, buffer) - - override fun power(arg: NDBuffer, pow: Number): ComplexNDElement = - map(arg) { power(it, pow) } - - override fun exp(arg: NDBuffer): ComplexNDElement = map(arg) { exp(it) } - override fun ln(arg: NDBuffer): ComplexNDElement = map(arg) { ln(it) } - - override fun sin(arg: NDBuffer): ComplexNDElement = map(arg) { sin(it) } - override fun cos(arg: NDBuffer): ComplexNDElement = map(arg) { cos(it) } - override fun tan(arg: NDBuffer): ComplexNDElement = map(arg) { tan(it) } - override fun asin(arg: NDBuffer): ComplexNDElement = map(arg) { asin(it) } - override fun acos(arg: NDBuffer): ComplexNDElement = map(arg) { acos(it) } - override fun atan(arg: NDBuffer): ComplexNDElement = map(arg) { atan(it) } - - override fun sinh(arg: NDBuffer): ComplexNDElement = map(arg) { sinh(it) } - override fun cosh(arg: NDBuffer): ComplexNDElement = map(arg) { cosh(it) } - override fun tanh(arg: NDBuffer): ComplexNDElement = map(arg) { tanh(it) } - override fun asinh(arg: NDBuffer): ComplexNDElement = map(arg) { asinh(it) } - override fun acosh(arg: NDBuffer): ComplexNDElement = map(arg) { acosh(it) } - override fun atanh(arg: NDBuffer): ComplexNDElement = map(arg) { atanh(it) } -} - - -/** - * Fast element production using function inlining - */ -public inline fun BufferedNDField.produceInline(initializer: ComplexField.(Int) -> Complex): ComplexNDElement { - val buffer = Buffer.complex(strides.linearSize) { offset -> ComplexField.initializer(offset) } - return BufferedNDFieldElement(this, buffer) -} - -/** - * Map one [ComplexNDElement] using function with indices. - */ -public inline fun ComplexNDElement.mapIndexed(transform: ComplexField.(index: IntArray, Complex) -> Complex): ComplexNDElement = - context.produceInline { offset -> transform(strides.index(offset), buffer[offset]) } - -/** - * Map one [ComplexNDElement] using function without indices. - */ -public inline fun ComplexNDElement.map(transform: ComplexField.(Complex) -> Complex): ComplexNDElement { - val buffer = Buffer.complex(strides.linearSize) { offset -> ComplexField.transform(buffer[offset]) } - return BufferedNDFieldElement(context, buffer) -} - -/** - * Element by element application of any operation on elements to the whole array. Just like in numpy - */ -public operator fun Function1.invoke(ndElement: ComplexNDElement): ComplexNDElement = - ndElement.map { this@invoke(it) } - -/* plus and minus */ - -/** - * Summation operation for [BufferedNDElement] and single element - */ -public operator fun ComplexNDElement.plus(arg: Complex): ComplexNDElement = map { it + arg } - -/** - * Subtraction operation between [BufferedNDElement] and single element - */ -public operator fun ComplexNDElement.minus(arg: Complex): ComplexNDElement = map { it - arg } - -public operator fun ComplexNDElement.plus(arg: Double): ComplexNDElement = map { it + arg } -public operator fun ComplexNDElement.minus(arg: Double): ComplexNDElement = map { it - arg } - -public fun NDField.Companion.complex(vararg shape: Int): ComplexNDField = ComplexNDField(shape) - -public fun NDElement.Companion.complex( - vararg shape: Int, - initializer: ComplexField.(IntArray) -> Complex, -): ComplexNDElement = NDField.complex(*shape).produce(initializer) - -/** - * Produce a context for n-dimensional operations inside this real field - */ -public inline fun ComplexField.nd(vararg shape: Int, action: ComplexNDField.() -> R): R { - contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } - return NDField.complex(*shape).action() -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ExtendedNDField.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ExtendedNDField.kt deleted file mode 100644 index a9fa2763b..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ExtendedNDField.kt +++ /dev/null @@ -1,44 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.ExtendedField - -/** - * [ExtendedField] over [NDStructure]. - * - * @param T the type of the element contained in ND structure. - * @param N the type of ND structure. - * @param F the extended field of structure elements. - */ -public interface ExtendedNDField, N : NDStructure> : NDField, ExtendedField - -///** -// * NDField that supports [ExtendedField] operations on its elements -// */ -//class ExtendedNDFieldWrapper, N : NDStructure>(private val ndField: NDField) : -// ExtendedNDField, NDField by ndField { -// -// override val shape: IntArray get() = ndField.shape -// override val elementContext: F get() = ndField.elementContext -// -// override fun produce(initializer: F.(IntArray) -> T) = ndField.produce(initializer) -// -// override fun power(arg: N, pow: Double): N { -// return produce { with(elementContext) { power(arg[it], pow) } } -// } -// -// override fun exp(arg: N): N { -// return produce { with(elementContext) { exp(arg[it]) } } -// } -// -// override fun ln(arg: N): N { -// return produce { with(elementContext) { ln(arg[it]) } } -// } -// -// override fun sin(arg: N): N { -// return produce { with(elementContext) { sin(arg[it]) } } -// } -// -// override fun cos(arg: N): N { -// return produce { with(elementContext) { cos(arg[it]) } } -// } -//} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt deleted file mode 100644 index d7b019c65..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt +++ /dev/null @@ -1,259 +0,0 @@ -package kscience.kmath.structures - -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. - * - * @property expected the expected shape. - * @property actual the actual shape. - */ -public class ShapeMismatchException(public val expected: IntArray, public val actual: IntArray) : - RuntimeException("Shape ${actual.contentToString()} doesn't fit in expected shape ${expected.contentToString()}.") - -/** - * The base interface for all ND-algebra implementations. - * - * @param T the type of ND-structure element. - * @param C the type of the element context. - * @param N the type of the structure. - */ -public interface NDAlgebra> { - /** - * The shape of ND-structures this algebra operates on. - */ - public val shape: IntArray - - /** - * The algebra over elements of ND structure. - */ - public val elementContext: C - - /** - * Produces a new [N] structure using given initializer function. - */ - public fun produce(initializer: C.(IntArray) -> T): N - - /** - * Maps elements from one structure to another one by applying [transform] to them. - */ - public fun map(arg: N, transform: C.(T) -> T): N - - /** - * Maps elements from one structure to another one by applying [transform] to them alongside with their indices. - */ - public fun mapIndexed(arg: N, transform: C.(index: IntArray, T) -> T): N - - /** - * Combines two structures into one. - */ - public fun combine(a: N, b: N, transform: C.(T, T) -> T): N - - /** - * Checks if given element is consistent with this context. - * - * @param element the structure to check. - * @return the valid structure. - */ - public fun check(element: N): N { - if (!element.shape.contentEquals(shape)) throw ShapeMismatchException(shape, element.shape) - return element - } - - /** - * Checks if given elements are consistent with this context. - * - * @param elements the structures to check. - * @return the array of valid structures. - */ - public fun check(vararg elements: N): Array = elements - .map(NDStructure::shape) - .singleOrNull { !shape.contentEquals(it) } - ?.let> { throw ShapeMismatchException(shape, it) } - ?: elements - - /** - * Element-wise invocation of function working on [T] on a [NDStructure]. - */ - public operator fun Function1.invoke(structure: N): N = map(structure) { value -> this@invoke(value) } - - public companion object -} - -/** - * Space of [NDStructure]. - * - * @param T the type of the element contained in ND structure. - * @param N the type of ND structure. - * @param S the type of space of structure elements. - */ -public interface NDSpace, N : NDStructure> : Space, NDAlgebra { - /** - * Element-wise addition. - * - * @param a the addend. - * @param b the augend. - * @return the sum. - */ - public override fun add(a: N, b: N): N = combine(a, b) { aValue, bValue -> add(aValue, bValue) } - - /** - * Element-wise multiplication by scalar. - * - * @param a the multiplicand. - * @param k the multiplier. - * @return the product. - */ - public override fun multiply(a: N, k: Number): N = map(a) { multiply(it, k) } - - // TODO move to extensions after KEEP-176 - - /** - * Adds an ND structure to an element of it. - * - * @receiver the addend. - * @param arg the augend. - * @return the sum. - */ - public operator fun N.plus(arg: T): N = map(this) { value -> add(arg, value) } - - /** - * Subtracts an element from ND structure of it. - * - * @receiver the dividend. - * @param arg the divisor. - * @return the quotient. - */ - public operator fun N.minus(arg: T): N = map(this) { value -> add(arg, -value) } - - /** - * Adds an element to ND structure of it. - * - * @receiver the addend. - * @param arg the augend. - * @return the sum. - */ - public operator fun T.plus(arg: N): N = map(arg) { value -> add(this@plus, value) } - - /** - * Subtracts an ND structure from an element of it. - * - * @receiver the dividend. - * @param arg the divisor. - * @return the quotient. - */ - public operator fun T.minus(arg: N): N = map(arg) { value -> add(-this@minus, value) } - - public companion object -} - -/** - * Ring of [NDStructure]. - * - * @param T the type of the element contained in ND structure. - * @param N the type of ND structure. - * @param R the type of ring of structure elements. - */ -public interface NDRing, N : NDStructure> : Ring, NDSpace { - /** - * Element-wise multiplication. - * - * @param a the multiplicand. - * @param b the multiplier. - * @return the product. - */ - public override fun multiply(a: N, b: N): N = combine(a, b) { aValue, bValue -> multiply(aValue, bValue) } - - //TODO move to extensions after KEEP-176 - - /** - * Multiplies an ND structure by an element of it. - * - * @receiver the multiplicand. - * @param arg the multiplier. - * @return the product. - */ - public operator fun N.times(arg: T): N = map(this) { value -> multiply(arg, value) } - - /** - * Multiplies an element by a ND structure of it. - * - * @receiver the multiplicand. - * @param arg the multiplier. - * @return the product. - */ - public operator fun T.times(arg: N): N = map(arg) { value -> multiply(this@times, value) } - - public companion object -} - -/** - * Field of [NDStructure]. - * - * @param T the type of the element contained in ND structure. - * @param N the type of ND structure. - * @param F the type field of structure elements. - */ -public interface NDField, N : NDStructure> : Field, NDRing { - /** - * Element-wise division. - * - * @param a the dividend. - * @param b the divisor. - * @return the quotient. - */ - public override fun divide(a: N, b: N): N = combine(a, b) { aValue, bValue -> divide(aValue, bValue) } - - //TODO move to extensions after KEEP-176 - /** - * Divides an ND structure by an element of it. - * - * @receiver the dividend. - * @param arg the divisor. - * @return the quotient. - */ - public operator fun N.div(arg: T): N = map(this) { value -> divide(arg, value) } - - /** - * Divides an element by an ND structure of it. - * - * @receiver the dividend. - * @param arg the divisor. - * @return the quotient. - */ - public operator fun T.div(arg: N): N = map(arg) { divide(it, this@div) } - - @ThreadLocal - public companion object { - private val realNDFieldCache: MutableMap = hashMapOf() - - /** - * Create a nd-field for [Double] values or pull it from cache if it was created previously. - */ - public fun real(vararg shape: Int): RealNDField = realNDFieldCache.getOrPut(shape) { RealNDField(shape) } - - /** - * Create an ND field with boxing generic buffer. - */ - public fun > boxing( - field: F, - vararg shape: Int, - bufferFactory: BufferFactory = Buffer.Companion::boxing - ): BoxingNDField = BoxingNDField(shape, field, bufferFactory) - - /** - * Create a most suitable implementation for nd-field using reified class. - */ - @Suppress("UNCHECKED_CAST") - public inline fun > auto(field: F, vararg shape: Int): BufferedNDField = - when { - T::class == Double::class -> real(*shape) as BufferedNDField - T::class == Complex::class -> complex(*shape) as BufferedNDField - else -> BoxingNDField(shape, field, Buffer.Companion::auto) - } - } -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDElement.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDElement.kt deleted file mode 100644 index f2f565064..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDElement.kt +++ /dev/null @@ -1,134 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.Field -import kscience.kmath.operations.RealField -import kscience.kmath.operations.Ring -import kscience.kmath.operations.Space - -/** - * The root for all [NDStructure] based algebra elements. Does not implement algebra element root because of problems with recursive self-types - * @param T the type of the element of the structure - * @param C the type of the context for the element - * @param N the type of the underlying [NDStructure] - */ -public interface NDElement> : NDStructure { - public val context: NDAlgebra - - public fun unwrap(): N - - public fun N.wrap(): NDElement - - public companion object { - /** - * Create a optimized NDArray of doubles - */ - public fun real(shape: IntArray, initializer: RealField.(IntArray) -> Double = { 0.0 }): RealNDElement = - NDField.real(*shape).produce(initializer) - - public inline fun real1D(dim: Int, crossinline initializer: (Int) -> Double = { _ -> 0.0 }): RealNDElement = - real(intArrayOf(dim)) { initializer(it[0]) } - - public inline fun real2D( - dim1: Int, - dim2: Int, - crossinline initializer: (Int, Int) -> Double = { _, _ -> 0.0 } - ): RealNDElement = real(intArrayOf(dim1, dim2)) { initializer(it[0], it[1]) } - - public inline fun real3D( - dim1: Int, - dim2: Int, - dim3: Int, - crossinline initializer: (Int, Int, Int) -> Double = { _, _, _ -> 0.0 } - ): RealNDElement = real(intArrayOf(dim1, dim2, dim3)) { initializer(it[0], it[1], it[2]) } - - - /** - * Simple boxing NDArray - */ - public fun > boxing( - shape: IntArray, - field: F, - initializer: F.(IntArray) -> T - ): BufferedNDElement { - val ndField = BoxingNDField(shape, field, Buffer.Companion::boxing) - return ndField.produce(initializer) - } - - public inline fun > auto( - shape: IntArray, - field: F, - noinline initializer: F.(IntArray) -> T - ): BufferedNDFieldElement { - val ndField = NDField.auto(field, *shape) - return BufferedNDFieldElement(ndField, ndField.produce(initializer).buffer) - } - } -} - -public fun > NDElement.mapIndexed(transform: C.(index: IntArray, T) -> T): NDElement = - context.mapIndexed(unwrap(), transform).wrap() - -public fun > NDElement.map(transform: C.(T) -> T): NDElement = - context.map(unwrap(), transform).wrap() - -/** - * Element by element application of any operation on elements to the whole [NDElement] - */ -public operator fun > Function1.invoke(ndElement: NDElement): NDElement = - ndElement.map { value -> this@invoke(value) } - -/* plus and minus */ - -/** - * Summation operation for [NDElement] and single element - */ -public operator fun , N : NDStructure> NDElement.plus(arg: T): NDElement = - map { value -> arg + value } - -/** - * Subtraction operation between [NDElement] and single element - */ -public operator fun , N : NDStructure> NDElement.minus(arg: T): NDElement = - map { value -> arg - value } - -/* prod and div */ - -/** - * Product operation for [NDElement] and single element - */ -public operator fun , N : NDStructure> NDElement.times(arg: T): NDElement = - map { value -> arg * value } - -/** - * Division operation between [NDElement] and single element - */ -public operator fun , N : NDStructure> NDElement.div(arg: T): NDElement = - map { value -> arg / value } - -// /** -// * Reverse sum operation -// */ -// operator fun T.plus(arg: NDStructure): NDElement = produce { index -> -// field.run { this@plus + arg[index] } -// } -// -// /** -// * Reverse minus operation -// */ -// operator fun T.minus(arg: NDStructure): NDElement = produce { index -> -// field.run { this@minus - arg[index] } -// } -// -// /** -// * Reverse product operation -// */ -// operator fun T.times(arg: NDStructure): NDElement = produce { index -> -// field.run { this@times * arg[index] } -// } -// -// /** -// * Reverse division operation -// */ -// operator fun T.div(arg: NDStructure): NDElement = produce { index -> -// field.run { this@div / arg[index] } -// } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealNDField.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealNDField.kt deleted file mode 100644 index 60e6de440..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealNDField.kt +++ /dev/null @@ -1,140 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.FieldElement -import kscience.kmath.operations.RealField -import kscience.kmath.operations.RingWithNumbers - -public typealias RealNDElement = BufferedNDFieldElement - -@OptIn(UnstableKMathAPI::class) -public class RealNDField(override val shape: IntArray) : - BufferedNDField, - ExtendedNDField>, - RingWithNumbers> { - - override val strides: Strides = DefaultStrides(shape) - - override val elementContext: RealField get() = RealField - override val zero: RealNDElement by lazy { produce { zero } } - override val one: RealNDElement by lazy { produce { one } } - - override fun number(value: Number): NDBuffer { - val d = value.toDouble() - return produce { d } - } - - @Suppress("OVERRIDE_BY_INLINE") - override inline fun map( - arg: NDBuffer, - transform: RealField.(Double) -> Double, - ): RealNDElement { - check(arg) - val array = RealBuffer(arg.strides.linearSize) { offset -> RealField.transform(arg.buffer[offset]) } - return BufferedNDFieldElement(this, array) - } - - @Suppress("OVERRIDE_BY_INLINE") - override inline fun produce(initializer: RealField.(IntArray) -> Double): RealNDElement { - val array = RealBuffer(strides.linearSize) { offset -> elementContext.initializer(strides.index(offset)) } - return BufferedNDFieldElement(this, array) - } - - @Suppress("OVERRIDE_BY_INLINE") - override inline fun mapIndexed( - arg: NDBuffer, - transform: RealField.(index: IntArray, Double) -> Double, - ): RealNDElement { - check(arg) - return BufferedNDFieldElement( - this, - RealBuffer(arg.strides.linearSize) { offset -> - elementContext.transform( - arg.strides.index(offset), - arg.buffer[offset] - ) - }) - } - - @Suppress("OVERRIDE_BY_INLINE") - override inline fun combine( - a: NDBuffer, - b: NDBuffer, - transform: RealField.(Double, Double) -> Double, - ): RealNDElement { - check(a, b) - val buffer = RealBuffer(strides.linearSize) { offset -> - elementContext.transform(a.buffer[offset], b.buffer[offset]) - } - return BufferedNDFieldElement(this, buffer) - } - - override fun NDBuffer.toElement(): FieldElement, *, out BufferedNDField> = - BufferedNDFieldElement(this@RealNDField, buffer) - - override fun power(arg: NDBuffer, pow: Number): RealNDElement = map(arg) { power(it, pow) } - - override fun exp(arg: NDBuffer): RealNDElement = map(arg) { exp(it) } - - override fun ln(arg: NDBuffer): RealNDElement = map(arg) { ln(it) } - - override fun sin(arg: NDBuffer): RealNDElement = map(arg) { sin(it) } - override fun cos(arg: NDBuffer): RealNDElement = map(arg) { cos(it) } - override fun tan(arg: NDBuffer): RealNDElement = map(arg) { tan(it) } - override fun asin(arg: NDBuffer): RealNDElement = map(arg) { asin(it) } - override fun acos(arg: NDBuffer): RealNDElement = map(arg) { acos(it) } - override fun atan(arg: NDBuffer): RealNDElement = map(arg) { atan(it) } - - override fun sinh(arg: NDBuffer): RealNDElement = map(arg) { sinh(it) } - override fun cosh(arg: NDBuffer): RealNDElement = map(arg) { cosh(it) } - override fun tanh(arg: NDBuffer): RealNDElement = map(arg) { tanh(it) } - override fun asinh(arg: NDBuffer): RealNDElement = map(arg) { asinh(it) } - override fun acosh(arg: NDBuffer): RealNDElement = map(arg) { acosh(it) } - override fun atanh(arg: NDBuffer): RealNDElement = map(arg) { atanh(it) } -} - - -/** - * Fast element production using function inlining - */ -public inline fun BufferedNDField.produceInline(crossinline initializer: RealField.(Int) -> Double): RealNDElement { - val array = DoubleArray(strides.linearSize) { offset -> RealField.initializer(offset) } - return BufferedNDFieldElement(this, RealBuffer(array)) -} - -/** - * Map one [RealNDElement] using function with indices. - */ -public inline fun RealNDElement.mapIndexed(crossinline transform: RealField.(index: IntArray, Double) -> Double): RealNDElement = - context.produceInline { offset -> transform(strides.index(offset), buffer[offset]) } - -/** - * Map one [RealNDElement] using function without indices. - */ -public inline fun RealNDElement.map(crossinline transform: RealField.(Double) -> Double): RealNDElement { - val array = DoubleArray(strides.linearSize) { offset -> RealField.transform(buffer[offset]) } - return BufferedNDFieldElement(context, RealBuffer(array)) -} - -/** - * Element by element application of any operation on elements to the whole array. Just like in numpy. - */ -public operator fun Function1.invoke(ndElement: RealNDElement): RealNDElement = - ndElement.map { this@invoke(it) } - -/* plus and minus */ - -/** - * Summation operation for [BufferedNDElement] and single element - */ -public operator fun RealNDElement.plus(arg: Double): RealNDElement = map { it + arg } - -/** - * Subtraction operation between [BufferedNDElement] and single element - */ -public operator fun RealNDElement.minus(arg: Double): RealNDElement = map { it - arg } - -/** - * Produce a context for n-dimensional operations inside this real field - */ -public inline fun RealField.nd(vararg shape: Int, action: RealNDField.() -> R): R = NDField.real(*shape).run(action) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ShortNDRing.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ShortNDRing.kt deleted file mode 100644 index 3b506a26a..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ShortNDRing.kt +++ /dev/null @@ -1,93 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.RingElement -import kscience.kmath.operations.ShortRing - -public typealias ShortNDElement = BufferedNDRingElement - -public class ShortNDRing(override val shape: IntArray) : - BufferedNDRing { - - override val strides: Strides = DefaultStrides(shape) - override val elementContext: ShortRing get() = ShortRing - override val zero: ShortNDElement by lazy { produce { zero } } - override val one: ShortNDElement by lazy { produce { one } } - - public inline fun buildBuffer(size: Int, crossinline initializer: (Int) -> Short): Buffer = - ShortBuffer(ShortArray(size) { initializer(it) }) - - /** - * Inline transform an NDStructure to - */ - override fun map( - arg: NDBuffer, - transform: ShortRing.(Short) -> Short - ): ShortNDElement { - check(arg) - val array = buildBuffer(arg.strides.linearSize) { offset -> ShortRing.transform(arg.buffer[offset]) } - return BufferedNDRingElement(this, array) - } - - override fun produce(initializer: ShortRing.(IntArray) -> Short): ShortNDElement { - val array = buildBuffer(strides.linearSize) { offset -> elementContext.initializer(strides.index(offset)) } - return BufferedNDRingElement(this, array) - } - - override fun mapIndexed( - arg: NDBuffer, - transform: ShortRing.(index: IntArray, Short) -> Short - ): ShortNDElement { - check(arg) - - return BufferedNDRingElement( - this, - buildBuffer(arg.strides.linearSize) { offset -> - elementContext.transform( - arg.strides.index(offset), - arg.buffer[offset] - ) - }) - } - - override fun combine( - a: NDBuffer, - b: NDBuffer, - transform: ShortRing.(Short, Short) -> Short - ): ShortNDElement { - check(a, b) - return BufferedNDRingElement( - this, - buildBuffer(strides.linearSize) { offset -> elementContext.transform(a.buffer[offset], b.buffer[offset]) }) - } - - override fun NDBuffer.toElement(): RingElement, *, out BufferedNDRing> = - BufferedNDRingElement(this@ShortNDRing, buffer) -} - - -/** - * Fast element production using function inlining. - */ -public inline fun BufferedNDRing.produceInline(crossinline initializer: ShortRing.(Int) -> Short): ShortNDElement = - BufferedNDRingElement(this, ShortBuffer(ShortArray(strides.linearSize) { offset -> ShortRing.initializer(offset) })) - -/** - * Element by element application of any operation on elements to the whole array. - */ -public operator fun Function1.invoke(ndElement: ShortNDElement): ShortNDElement = - ndElement.context.produceInline { i -> invoke(ndElement.buffer[i]) } - - -/* plus and minus */ - -/** - * Summation operation for [ShortNDElement] and single element. - */ -public operator fun ShortNDElement.plus(arg: Short): ShortNDElement = - context.produceInline { i -> (buffer[i] + arg).toShort() } - -/** - * Subtraction operation between [ShortNDElement] and single element. - */ -public operator fun ShortNDElement.minus(arg: Short): ShortNDElement = - context.produceInline { i -> (buffer[i] - arg).toShort() } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/Domain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain.kt similarity index 82% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/domains/Domain.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain.kt index 5c3cff2c5..edf19de55 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/Domain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain.kt @@ -1,6 +1,6 @@ -package kscience.kmath.domains +package space.kscience.kmath.domains -import kscience.kmath.linear.Point +import space.kscience.kmath.linear.Point /** * A simple geometric domain. diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/HyperSquareDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/HyperSquareDomain.kt similarity index 75% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/domains/HyperSquareDomain.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/HyperSquareDomain.kt index b45cf6bf5..3d0c6d3b8 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/HyperSquareDomain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/HyperSquareDomain.kt @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package kscience.kmath.domains +package space.kscience.kmath.domains -import kscience.kmath.linear.Point -import kscience.kmath.structures.RealBuffer -import kscience.kmath.structures.indices +import space.kscience.kmath.linear.Point +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.indices /** * @@ -25,20 +26,20 @@ import kscience.kmath.structures.indices * * @author Alexander Nozik */ -public class HyperSquareDomain(private val lower: RealBuffer, private val upper: RealBuffer) : RealDomain { +public class HyperSquareDomain(private val lower: Buffer, private val upper: Buffer) : RealDomain { public override val dimension: Int get() = lower.size public override operator fun contains(point: Point): Boolean = point.indices.all { i -> point[i] in lower[i]..upper[i] } - public override fun getLowerBound(num: Int, point: Point): Double? = lower[num] + public override fun getLowerBound(num: Int, point: Point): Double = lower[num] - public override fun getLowerBound(num: Int): Double? = lower[num] + public override fun getLowerBound(num: Int): Double = lower[num] - public override fun getUpperBound(num: Int, point: Point): Double? = upper[num] + public override fun getUpperBound(num: Int, point: Point): Double = upper[num] - public override fun getUpperBound(num: Int): Double? = upper[num] + public override fun getUpperBound(num: Int): Double = upper[num] public override fun nearestInDomain(point: Point): Point { val res = DoubleArray(point.size) { i -> diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/RealDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/RealDomain.kt similarity index 95% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/domains/RealDomain.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/RealDomain.kt index 369b093bb..13555dad9 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/RealDomain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/RealDomain.kt @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package kscience.kmath.domains +package space.kscience.kmath.domains -import kscience.kmath.linear.Point +import space.kscience.kmath.linear.Point /** * n-dimensional volume diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/UnconstrainedDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnconstrainedDomain.kt similarity index 94% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/domains/UnconstrainedDomain.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnconstrainedDomain.kt index e2efb51ab..f1bcc50ad 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/UnconstrainedDomain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnconstrainedDomain.kt @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package kscience.kmath.domains +package space.kscience.kmath.domains -import kscience.kmath.linear.Point +import space.kscience.kmath.linear.Point public class UnconstrainedDomain(public override val dimension: Int) : RealDomain { public override operator fun contains(point: Point): Boolean = true diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/UnivariateDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt similarity index 91% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/domains/UnivariateDomain.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt index bf090f2e5..36cd4afa7 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/UnivariateDomain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt @@ -1,7 +1,7 @@ -package kscience.kmath.domains +package space.kscience.kmath.domains -import kscience.kmath.linear.Point -import kscience.kmath.structures.asBuffer +import space.kscience.kmath.linear.Point +import space.kscience.kmath.structures.asBuffer public inline class UnivariateDomain(public val range: ClosedFloatingPointRange) : RealDomain { public override val dimension: Int diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/DifferentiableExpression.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DifferentiableExpression.kt similarity index 97% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/DifferentiableExpression.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DifferentiableExpression.kt index abce9c4ec..508a62aca 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/DifferentiableExpression.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DifferentiableExpression.kt @@ -1,4 +1,4 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions /** * Represents expression which structure can be differentiated. diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt similarity index 72% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt index 63bbc9312..231bbdab1 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt @@ -1,9 +1,8 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.operations.Algebra +import space.kscience.kmath.operations.Algebra import kotlin.jvm.JvmName import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty /** * A marker interface for a symbol. A symbol mus have an identity @@ -13,13 +12,6 @@ public interface Symbol { * Identity object for the symbol. Two symbols with the same identity are considered to be the same symbol. */ public val identity: String - - public companion object : ReadOnlyProperty { - //TODO deprecate and replace by top level function after fix of https://youtrack.jetbrains.com/issue/KT-40121 - override fun getValue(thisRef: Any?, property: KProperty<*>): Symbol { - return StringSymbol(property.name) - } - } } /** @@ -81,12 +73,12 @@ public interface ExpressionAlgebra : Algebra { /** * Bind a given [Symbol] to this context variable and produce context-specific object. Return null if symbol could not be bound in current context. */ - public fun bindOrNull(symbol: Symbol): E? + public fun bindSymbolOrNull(symbol: Symbol): E? /** * Bind a string to a context using [StringSymbol] */ - override fun symbol(value: String): E = bind(StringSymbol(value)) + override fun bindSymbol(value: String): E = bindSymbol(StringSymbol(value)) /** * A constant expression which does not depend on arguments @@ -97,19 +89,19 @@ public interface ExpressionAlgebra : Algebra { /** * Bind a given [Symbol] to this context variable and produce context-specific object. */ -public fun ExpressionAlgebra.bind(symbol: Symbol): E = - bindOrNull(symbol) ?: error("Symbol $symbol could not be bound to $this") +public fun ExpressionAlgebra.bindSymbol(symbol: Symbol): E = + bindSymbolOrNull(symbol) ?: error("Symbol $symbol could not be bound to $this") /** * A delegate to create a symbol with a string identity in this scope */ -public val symbol: ReadOnlyProperty get() = Symbol -//TODO does not work directly on native due to https://youtrack.jetbrains.com/issue/KT-40121 - +public val symbol: ReadOnlyProperty = ReadOnlyProperty { _, property -> + StringSymbol(property.name) +} /** * Bind a symbol by name inside the [ExpressionAlgebra] */ public fun ExpressionAlgebra.binding(): ReadOnlyProperty = ReadOnlyProperty { _, property -> - bind(StringSymbol(property.name)) ?: error("A variable with name ${property.name} does not exist") + bindSymbol(StringSymbol(property.name)) ?: error("A variable with name ${property.name} does not exist") } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt similarity index 97% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt index 1a3668855..5177bc868 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt @@ -1,6 +1,6 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.operations.* +import space.kscience.kmath.operations.* /** * A context class for [Expression] construction. @@ -18,7 +18,7 @@ public abstract class FunctionalExpressionAlgebra>( /** * Builds an Expression to access a variable. */ - public override fun bindOrNull(symbol: Symbol): Expression? = Expression { arguments -> + public override fun bindSymbolOrNull(symbol: Symbol): Expression? = Expression { arguments -> arguments[symbol] ?: error("Argument not found: $symbol") } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/SimpleAutoDiff.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt similarity index 97% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/SimpleAutoDiff.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt index 0621e82bd..c710ba679 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/SimpleAutoDiff.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt @@ -1,9 +1,9 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.linear.Point -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.* -import kscience.kmath.structures.asBuffer +import space.kscience.kmath.linear.Point +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.asBuffer import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -117,7 +117,7 @@ public open class SimpleAutoDiffField>( override fun hashCode(): Int = identity.hashCode() } - public override fun bindOrNull(symbol: Symbol): AutoDiffValue? = bindings[symbol.identity] + public override fun bindSymbolOrNull(symbol: Symbol): AutoDiffValue? = bindings[symbol.identity] private fun getDerivative(variable: AutoDiffValue): T = (variable as? AutoDiffVariableWithDerivative)?.d ?: derivatives[variable] ?: context.zero diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/SymbolIndexer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt similarity index 89% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/SymbolIndexer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt index 6c61c7c7d..580acaafb 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/SymbolIndexer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt @@ -1,12 +1,12 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.linear.Point -import kscience.kmath.structures.BufferFactory -import kscience.kmath.structures.Structure2D +import space.kscience.kmath.linear.Point +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.structures.BufferFactory /** * An environment to easy transform indexed variables to symbols and back. - * TODO requires multi-receivers to be beutiful + * TODO requires multi-receivers to be beautiful */ public interface SymbolIndexer { public val symbols: List diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/expressionBuilders.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/expressionBuilders.kt similarity index 85% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/expressionBuilders.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/expressionBuilders.kt index 1603bc21d..0ef6803d6 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/expressionBuilders.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/expressionBuilders.kt @@ -1,9 +1,9 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.operations.ExtendedField -import kscience.kmath.operations.Field -import kscience.kmath.operations.Ring -import kscience.kmath.operations.Space +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.Space import kotlin.contracts.InvocationKind import kotlin.contracts.contract diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferMatrix.kt new file mode 100644 index 000000000..f8f7f5a05 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferMatrix.kt @@ -0,0 +1,136 @@ +package space.kscience.kmath.linear + +import space.kscience.kmath.nd.NDStructure +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.asSequence + +/** + * Alias for [Structure2D] with more familiar name. + * + * @param T the type of items. + */ +public typealias Matrix = Structure2D + +/** + * Basic implementation of Matrix space based on [NDStructure] + */ +public class BufferMatrixContext>( + public override val elementContext: R, + private val bufferFactory: BufferFactory, +) : GenericMatrixContext> { + public override fun produce(rows: Int, columns: Int, initializer: (i: Int, j: Int) -> T): BufferMatrix { + val buffer = bufferFactory(rows * columns) { offset -> initializer(offset / columns, offset % columns) } + return BufferMatrix(rows, columns, buffer) + } + + public override fun point(size: Int, initializer: (Int) -> T): Point = bufferFactory(size, initializer) + + private fun Matrix.toBufferMatrix(): BufferMatrix = if (this is BufferMatrix) this else { + produce(rowNum, colNum) { i, j -> get(i, j) } + } + + public fun one(rows: Int, columns: Int): Matrix = VirtualMatrix(rows, columns) { i, j -> + if (i == j) 1.0 else 0.0 + } + DiagonalFeature + + public override infix fun Matrix.dot(other: Matrix): BufferMatrix { + require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } + val bufferMatrix = toBufferMatrix() + val otherBufferMatrix = other.toBufferMatrix() + return elementContext { + produce(rowNum, other.colNum) { i, j -> + var res = one + for (l in 0 until colNum) { + res += bufferMatrix[i, l] * otherBufferMatrix[l, j] + } + res + } + } + } + + public override infix fun Matrix.dot(vector: Point): Point { + require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } + val bufferMatrix = toBufferMatrix() + return elementContext { + bufferFactory(rowNum) { i -> + var res = one + for (j in 0 until colNum) { + res += bufferMatrix[i, j] * vector[j] + } + res + } + } + } + + override fun add(a: Matrix, b: Matrix): BufferMatrix { + require(a.rowNum == b.rowNum) { "Row number mismatch in matrix addition. Left side: ${a.rowNum}, right side: ${b.rowNum}" } + require(a.colNum == b.colNum) { "Column number mismatch in matrix addition. Left side: ${a.colNum}, right side: ${b.colNum}" } + val aBufferMatrix = a.toBufferMatrix() + val bBufferMatrix = b.toBufferMatrix() + return elementContext { + produce(a.rowNum, a.colNum) { i, j -> + aBufferMatrix[i, j] + bBufferMatrix[i, j] + } + } + } + + override fun multiply(a: Matrix, k: Number): BufferMatrix { + val aBufferMatrix = a.toBufferMatrix() + return elementContext { + produce(a.rowNum, a.colNum) { i, j -> aBufferMatrix[i, j] * k.toDouble() } + } + } + + public companion object +} + +public class BufferMatrix( + public override val rowNum: Int, + public override val colNum: Int, + public val buffer: Buffer, +) : Matrix { + + init { + require(buffer.size == rowNum * colNum) { "Dimension mismatch for matrix structure" } + } + + override val shape: IntArray get() = intArrayOf(rowNum, colNum) + + public override operator fun get(index: IntArray): T = get(index[0], index[1]) + public override operator fun get(i: Int, j: Int): T = buffer[i * colNum + j] + + public override fun elements(): Sequence> = sequence { + for (i in 0 until rowNum) for (j in 0 until colNum) yield(intArrayOf(i, j) to get(i, j)) + } + + public override fun equals(other: Any?): Boolean { + if (this === other) return true + + return when (other) { + is NDStructure<*> -> NDStructure.contentEquals(this, other) + else -> false + } + } + + override fun hashCode(): Int { + var result = rowNum + result = 31 * result + colNum + result = 31 * result + buffer.hashCode() + return result + } + + public override fun toString(): String { + return if (rowNum <= 5 && colNum <= 5) + "Matrix(rowsNum = $rowNum, colNum = $colNum)\n" + + rows.asSequence().joinToString(prefix = "(", postfix = ")", separator = "\n ") { buffer -> + buffer.asSequence().joinToString(separator = "\t") { it.toString() } + } + else "Matrix(rowsNum = $rowNum, colNum = $colNum)" + } + + +} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/LinearAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearAlgebra.kt similarity index 82% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/linear/LinearAlgebra.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearAlgebra.kt index 034decc2f..ea871ccba 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/LinearAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearAlgebra.kt @@ -1,8 +1,7 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.VirtualBuffer +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.VirtualBuffer public typealias Point = Buffer diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/LupDecomposition.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt similarity index 87% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/linear/LupDecomposition.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt index 5cf7c8f70..a3d4cbc47 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/LupDecomposition.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt @@ -1,8 +1,12 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.* -import kscience.kmath.structures.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.getFeature +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferAccessor2D +import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.MutableBufferFactory /** * Common implementation of [LupDecompositionFeature]. @@ -151,7 +155,7 @@ public inline fun , F : Field> GenericMatrixContext public fun MatrixContext>.lup(matrix: Matrix): LupDecomposition = lup(Buffer.Companion::real, RealField, matrix) { it < 1e-11 } -public fun LupDecomposition.solveWithLUP( +public fun LupDecomposition.solveWithLup( factory: MutableBufferFactory, matrix: Matrix, ): Matrix { @@ -199,14 +203,14 @@ public fun LupDecomposition.solveWithLUP( } } -public inline fun LupDecomposition.solveWithLUP(matrix: Matrix): Matrix = - solveWithLUP(MutableBuffer.Companion::auto, matrix) +public inline fun LupDecomposition.solveWithLup(matrix: Matrix): Matrix = + solveWithLup(MutableBuffer.Companion::auto, matrix) /** - * Solve a linear equation **a*x = b** using LUP decomposition + * Solves a system of linear equations *ax = b** using LUP decomposition. */ @OptIn(UnstableKMathAPI::class) -public inline fun , F : Field> GenericMatrixContext>.solveWithLUP( +public inline fun , F : Field> GenericMatrixContext>.solveWithLup( a: Matrix, b: Matrix, noinline bufferFactory: MutableBufferFactory = MutableBuffer.Companion::auto, @@ -214,26 +218,26 @@ public inline fun , F : Field> GenericMatrixContext ): Matrix { // Use existing decomposition if it is provided by matrix val decomposition = a.getFeature() ?: lup(bufferFactory, elementContext, a, checkSingular) - return decomposition.solveWithLUP(bufferFactory, b) + return decomposition.solveWithLup(bufferFactory, b) } -public inline fun , F : Field> GenericMatrixContext>.inverseWithLUP( +public inline fun , F : Field> GenericMatrixContext>.inverseWithLup( matrix: Matrix, noinline bufferFactory: MutableBufferFactory = MutableBuffer.Companion::auto, noinline checkSingular: (T) -> Boolean, -): Matrix = solveWithLUP(matrix, one(matrix.rowNum, matrix.colNum), bufferFactory, checkSingular) +): Matrix = solveWithLup(matrix, one(matrix.rowNum, matrix.colNum), bufferFactory, checkSingular) @OptIn(UnstableKMathAPI::class) -public fun RealMatrixContext.solveWithLUP(a: Matrix, b: Matrix): Matrix { +public fun RealMatrixContext.solveWithLup(a: Matrix, b: Matrix): Matrix { // Use existing decomposition if it is provided by matrix val bufferFactory: MutableBufferFactory = MutableBuffer.Companion::real val decomposition: LupDecomposition = a.getFeature() ?: lup(bufferFactory, RealField, a) { it < 1e-11 } - return decomposition.solveWithLUP(bufferFactory, b) + return decomposition.solveWithLup(bufferFactory, b) } /** * Inverses a square matrix using LUP decomposition. Non square matrix will throw a error. */ -public fun RealMatrixContext.inverseWithLUP(matrix: Matrix): Matrix = - solveWithLUP(matrix, one(matrix.rowNum, matrix.colNum)) \ No newline at end of file +public fun RealMatrixContext.inverseWithLup(matrix: Matrix): Matrix = + solveWithLup(matrix, one(matrix.rowNum, matrix.colNum)) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixBuilder.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt similarity index 82% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixBuilder.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt index c0c209248..c96834360 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixBuilder.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt @@ -1,6 +1,9 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.structures.* +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.asBuffer public class MatrixBuilder(public val rows: Int, public val columns: Int) { public operator fun invoke(vararg elements: T): Matrix { @@ -22,7 +25,7 @@ public fun Structure2D.Companion.row(vararg values: T): Matrix { public inline fun Structure2D.Companion.row( size: Int, factory: BufferFactory = Buffer.Companion::auto, - noinline builder: (Int) -> T + noinline builder: (Int) -> T, ): Matrix { val buffer = factory(size, builder) return BufferMatrix(1, size, buffer) @@ -36,7 +39,7 @@ public fun Structure2D.Companion.column(vararg values: T): Matrix { public inline fun Structure2D.Companion.column( size: Int, factory: BufferFactory = Buffer.Companion::auto, - noinline builder: (Int) -> T + noinline builder: (Int) -> T, ): Matrix { val buffer = factory(size, builder) return BufferMatrix(size, 1, buffer) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixContext.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixContext.kt similarity index 67% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixContext.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixContext.kt index 59a41f840..c999a170c 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixContext.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixContext.kt @@ -1,25 +1,29 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.operations.Ring -import kscience.kmath.operations.SpaceOperations -import kscience.kmath.operations.invoke -import kscience.kmath.operations.sum -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.BufferFactory -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.asSequence +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.SpaceOperations +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.operations.sum +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.asSequence +import kotlin.reflect.KClass /** - * Basic operations on matrices. Operates on [Matrix] + * Basic operations on matrices. Operates on [Matrix]. + * + * @param T the type of items in the matrices. + * @param M the type of operated matrices. */ public interface MatrixContext> : SpaceOperations> { /** - * Produce a matrix with this context and given dimensions + * Produces a matrix with this context and given dimensions. */ public fun produce(rows: Int, columns: Int, initializer: (i: Int, j: Int) -> T): M /** - * Produce a point compatible with matrix space (and possibly optimized for it) + * Produces a point compatible with matrix space (and possibly optimized for it). */ public fun point(size: Int, initializer: (Int) -> T): Point = Buffer.boxing(size, initializer) @@ -61,11 +65,23 @@ public interface MatrixContext> : SpaceOperations): M = m * this + /** + * Gets a feature from the matrix. This function may return some additional features to + * [kscience.kmath.nd.NDStructure.getFeature]. + * + * @param F the type of feature. + * @param m the matrix. + * @param type the [KClass] instance of [F]. + * @return a feature object or `null` if it isn't present. + */ + @UnstableKMathAPI + public fun getFeature(m: Matrix, type: KClass): F? = m.getFeature(type) + public companion object { /** @@ -84,9 +100,31 @@ public interface MatrixContext> : SpaceOperations MatrixContext.getFeature(m: Matrix): F? = + getFeature(m, F::class) + +/** + * Partial implementation of [MatrixContext] for matrices of [Ring]. + * + * @param T the type of items in the matrices. + * @param R the type of ring of matrix elements. + * @param M the type of operated matrices. + */ public interface GenericMatrixContext, out M : Matrix> : MatrixContext { /** - * The ring context for matrix elements + * The ring over matrix elements. */ public val elementContext: R diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixFeatures.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt similarity index 96% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixFeatures.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt index e61feec6c..6b97e89ef 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixFeatures.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt @@ -1,6 +1,4 @@ -package kscience.kmath.linear - -import kscience.kmath.structures.Matrix +package space.kscience.kmath.linear /** * A marker interface representing some properties of matrices or additional transformations of them. Features are used @@ -11,8 +9,8 @@ public interface MatrixFeature /** * Matrices with this feature are considered to have only diagonal non-null elements. */ -public interface DiagonalFeature : MatrixFeature{ - public companion object: DiagonalFeature +public interface DiagonalFeature : MatrixFeature { + public companion object : DiagonalFeature } /** @@ -39,6 +37,8 @@ public interface InverseMatrixFeature : MatrixFeature { /** * Matrices with this feature can compute their determinant. + * + * @param T the type of matrices' items. */ public interface DeterminantFeature : MatrixFeature { /** diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt similarity index 83% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixWrapper.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index 362db1fe7..86ec0de88 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -1,11 +1,10 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.Ring -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.Structure2D -import kscience.kmath.structures.asBuffer -import kscience.kmath.structures.getFeature +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.nd.getFeature +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.structures.asBuffer import kotlin.math.sqrt import kotlin.reflect.KClass import kotlin.reflect.safeCast @@ -39,7 +38,8 @@ public class MatrixWrapper internal constructor( * Origin does not necessary store all features. */ @UnstableKMathAPI -public val Matrix.origin: Matrix get() = (this as? MatrixWrapper)?.origin ?: this +public val Matrix.origin: Matrix + get() = (this as? MatrixWrapper)?.origin ?: this /** * Add a single feature to a [Matrix] @@ -60,12 +60,6 @@ public operator fun Matrix.plus(newFeatures: Collection Double, -): BufferMatrix = MatrixContext.real.produce(rows, columns, initializer) - /** * Build a square matrix from given elements. */ diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/RealMatrixContext.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/RealMatrixContext.kt similarity index 68% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/linear/RealMatrixContext.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/RealMatrixContext.kt index 8e197672f..5f28e6f4c 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/RealMatrixContext.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/RealMatrixContext.kt @@ -1,12 +1,10 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.RealBuffer -@Suppress("OVERRIDE_BY_INLINE") public object RealMatrixContext : MatrixContext> { - public override inline fun produce( + public override fun produce( rows: Int, columns: Int, initializer: (i: Int, j: Int) -> Double, @@ -15,7 +13,7 @@ public object RealMatrixContext : MatrixContext> { return BufferMatrix(rows, columns, buffer) } - private fun Matrix.wrap(): BufferMatrix = if (this is BufferMatrix) this else { + public fun Matrix.toBufferMatrix(): BufferMatrix = if (this is BufferMatrix) this else { produce(rowNum, colNum) { i, j -> get(i, j) } } @@ -25,10 +23,12 @@ public object RealMatrixContext : MatrixContext> { public override infix fun Matrix.dot(other: Matrix): BufferMatrix { require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } + val bufferMatrix = toBufferMatrix() + val otherBufferMatrix = other.toBufferMatrix() return produce(rowNum, other.colNum) { i, j -> var res = 0.0 for (l in 0 until colNum) { - res += get(i, l) * other.get(l, j) + res += bufferMatrix[i, l] * otherBufferMatrix[l, j] } res } @@ -36,10 +36,11 @@ public object RealMatrixContext : MatrixContext> { public override infix fun Matrix.dot(vector: Point): Point { require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } + val bufferMatrix = toBufferMatrix() return RealBuffer(rowNum) { i -> var res = 0.0 for (j in 0 until colNum) { - res += get(i, j) * vector[j] + res += bufferMatrix[i, j] * vector[j] } res } @@ -48,17 +49,23 @@ public object RealMatrixContext : MatrixContext> { override fun add(a: Matrix, b: Matrix): BufferMatrix { require(a.rowNum == b.rowNum) { "Row number mismatch in matrix addition. Left side: ${a.rowNum}, right side: ${b.rowNum}" } require(a.colNum == b.colNum) { "Column number mismatch in matrix addition. Left side: ${a.colNum}, right side: ${b.colNum}" } + val aBufferMatrix = a.toBufferMatrix() + val bBufferMatrix = b.toBufferMatrix() return produce(a.rowNum, a.colNum) { i, j -> - a[i, j] + b[i, j] + aBufferMatrix[i, j] + bBufferMatrix[i, j] } } - override fun Matrix.times(value: Double): BufferMatrix = - produce(rowNum, colNum) { i, j -> get(i, j) * value } + override fun Matrix.times(value: Double): BufferMatrix { + val bufferMatrix = toBufferMatrix() + return produce(rowNum, colNum) { i, j -> bufferMatrix[i, j] * value } + } - override fun multiply(a: Matrix, k: Number): BufferMatrix = - produce(a.rowNum, a.colNum) { i, j -> a[i, j] * k.toDouble() } + override fun multiply(a: Matrix, k: Number): BufferMatrix { + val aBufferMatrix = a.toBufferMatrix() + return produce(a.rowNum, a.colNum) { i, j -> aBufferMatrix[i, j] * k.toDouble() } + } } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VectorSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VectorSpace.kt similarity index 88% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VectorSpace.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VectorSpace.kt index 2a3b8f5d1..310c1350c 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VectorSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VectorSpace.kt @@ -1,10 +1,10 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.operations.RealField -import kscience.kmath.operations.Space -import kscience.kmath.operations.invoke -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.BufferFactory +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.Space +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory /** * A linear space for vectors. diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VirtualMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt similarity index 81% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VirtualMatrix.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt index 0269a64d1..26b1899a1 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VirtualMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt @@ -1,7 +1,10 @@ -package kscience.kmath.linear - -import kscience.kmath.structures.Matrix +package space.kscience.kmath.linear +/** + * The matrix where each element is evaluated each time when is being accessed. + * + * @property generator the function that provides elements. + */ public class VirtualMatrix( override val rowNum: Int, override val colNum: Int, diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/misc/annotations.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/annotations.kt similarity index 56% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/misc/annotations.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/annotations.kt index d70ac7b39..7fd7b433d 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/misc/annotations.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/annotations.kt @@ -1,4 +1,4 @@ -package kscience.kmath.misc +package space.kscience.kmath.misc @RequiresOptIn("This API is unstable and could change in future", RequiresOptIn.Level.WARNING) -public annotation class UnstableKMathAPI \ No newline at end of file +public annotation class UnstableKMathAPI diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/misc/cumulative.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/cumulative.kt similarity index 95% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/misc/cumulative.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/cumulative.kt index 72d2f2388..380723095 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/misc/cumulative.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/cumulative.kt @@ -1,7 +1,7 @@ -package kscience.kmath.misc +package space.kscience.kmath.misc -import kscience.kmath.operations.Space -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.Space +import space.kscience.kmath.operations.invoke import kotlin.jvm.JvmName /** diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferNDAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferNDAlgebra.kt new file mode 100644 index 000000000..71c7d444c --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferNDAlgebra.kt @@ -0,0 +1,136 @@ +package space.kscience.kmath.nd + +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.Space +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + +public interface BufferNDAlgebra : NDAlgebra { + public val strides: Strides + public val bufferFactory: BufferFactory + + override fun produce(initializer: C.(IntArray) -> T): NDBuffer = NDBuffer( + strides, + bufferFactory(strides.linearSize) { offset -> + elementContext.initializer(strides.index(offset)) + } + ) + + public val NDStructure.buffer: Buffer + get() = when { + !shape.contentEquals(this@BufferNDAlgebra.shape) -> throw ShapeMismatchException( + this@BufferNDAlgebra.shape, + shape + ) + this is NDBuffer && this.strides == this@BufferNDAlgebra.strides -> this.buffer + else -> bufferFactory(strides.linearSize) { offset -> get(strides.index(offset)) } + } + + override fun NDStructure.map(transform: C.(T) -> T): NDBuffer { + val buffer = bufferFactory(strides.linearSize) { offset -> + elementContext.transform(buffer[offset]) + } + return NDBuffer(strides, buffer) + } + + override fun NDStructure.mapIndexed(transform: C.(index: IntArray, T) -> T): NDBuffer { + val buffer = bufferFactory(strides.linearSize) { offset -> + elementContext.transform( + strides.index(offset), + buffer[offset] + ) + } + return NDBuffer(strides, buffer) + } + + override fun combine(a: NDStructure, b: NDStructure, transform: C.(T, T) -> T): NDBuffer { + val buffer = bufferFactory(strides.linearSize) { offset -> + elementContext.transform(a.buffer[offset], b.buffer[offset]) + } + return NDBuffer(strides, buffer) + } +} + +public open class BufferedNDSpace>( + final override val shape: IntArray, + final override val elementContext: R, + final override val bufferFactory: BufferFactory, +) : NDSpace, BufferNDAlgebra { + override val strides: Strides = DefaultStrides(shape) + override val zero: NDBuffer by lazy { produce { zero } } +} + +public open class BufferedNDRing>( + shape: IntArray, + elementContext: R, + bufferFactory: BufferFactory, +) : BufferedNDSpace(shape, elementContext, bufferFactory), NDRing { + override val one: NDBuffer by lazy { produce { one } } +} + +public open class BufferedNDField>( + shape: IntArray, + elementContext: R, + bufferFactory: BufferFactory, +) : BufferedNDRing(shape, elementContext, bufferFactory), NDField + +// space factories +public fun > NDAlgebra.Companion.space( + space: A, + bufferFactory: BufferFactory, + vararg shape: Int, +): BufferedNDSpace = BufferedNDSpace(shape, space, bufferFactory) + +public inline fun , R> A.ndSpace( + noinline bufferFactory: BufferFactory, + vararg shape: Int, + action: BufferedNDSpace.() -> R, +): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return NDAlgebra.space(this, bufferFactory, *shape).run(action) +} + +//ring factories +public fun > NDAlgebra.Companion.ring( + ring: A, + bufferFactory: BufferFactory, + vararg shape: Int, +): BufferedNDRing = BufferedNDRing(shape, ring, bufferFactory) + +public inline fun , R> A.ndRing( + noinline bufferFactory: BufferFactory, + vararg shape: Int, + action: BufferedNDRing.() -> R, +): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return NDAlgebra.ring(this, bufferFactory, *shape).run(action) +} + +//field factories +public fun > NDAlgebra.Companion.field( + field: A, + bufferFactory: BufferFactory, + vararg shape: Int, +): BufferedNDField = BufferedNDField(shape, field, bufferFactory) + +@Suppress("UNCHECKED_CAST") +public inline fun > NDAlgebra.Companion.auto( + field: A, + vararg shape: Int, +): NDField = when (field) { + RealField -> RealNDField(shape) as NDField + else -> BufferedNDField(shape, field, Buffer.Companion::auto) +} + +public inline fun , R> A.ndField( + noinline bufferFactory: BufferFactory, + vararg shape: Int, + action: BufferedNDField.() -> R, +): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return NDAlgebra.field(this, bufferFactory, *shape).run(action) +} \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/NDAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/NDAlgebra.kt new file mode 100644 index 000000000..af154d3cd --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/NDAlgebra.kt @@ -0,0 +1,262 @@ +package space.kscience.kmath.nd + +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.Space +import space.kscience.kmath.structures.* + +/** + * An exception is thrown when the expected ans actual shape of NDArray differs. + * + * @property expected the expected shape. + * @property actual the actual shape. + */ +public class ShapeMismatchException(public val expected: IntArray, public val actual: IntArray) : + RuntimeException("Shape ${actual.contentToString()} doesn't fit in expected shape ${expected.contentToString()}.") + +/** + * The base interface for all ND-algebra implementations. + * + * @param T the type of ND-structure element. + * @param C the type of the element context. + * @param N the type of the structure. + */ +public interface NDAlgebra { + /** + * The shape of ND-structures this algebra operates on. + */ + public val shape: IntArray + + /** + * The algebra over elements of ND structure. + */ + public val elementContext: C + + /** + * Produces a new [N] structure using given initializer function. + */ + public fun produce(initializer: C.(IntArray) -> T): NDStructure + + /** + * Maps elements from one structure to another one by applying [transform] to them. + */ + public fun NDStructure.map(transform: C.(T) -> T): NDStructure + + /** + * Maps elements from one structure to another one by applying [transform] to them alongside with their indices. + */ + public fun NDStructure.mapIndexed(transform: C.(index: IntArray, T) -> T): NDStructure + + /** + * Combines two structures into one. + */ + public fun combine(a: NDStructure, b: NDStructure, transform: C.(T, T) -> T): NDStructure + + /** + * Element-wise invocation of function working on [T] on a [NDStructure]. + */ + public operator fun Function1.invoke(structure: NDStructure): NDStructure = + structure.map() { value -> this@invoke(value) } + + public companion object +} + +/** + * Checks if given elements are consistent with this context. + * + * @param structures the structures to check. + * @return the array of valid structures. + */ +internal fun NDAlgebra.checkShape(vararg structures: NDStructure): Array> = structures + .map(NDStructure::shape) + .singleOrNull { !shape.contentEquals(it) } + ?.let>> { throw ShapeMismatchException(shape, it) } + ?: structures + +/** + * Checks if given element is consistent with this context. + * + * @param element the structure to check. + * @return the valid structure. + */ +internal fun NDAlgebra.checkShape(element: NDStructure): NDStructure { + if (!element.shape.contentEquals(shape)) throw ShapeMismatchException(shape, element.shape) + return element +} + +/** + * Space of [NDStructure]. + * + * @param T the type of the element contained in ND structure. + * @param N the type of ND structure. + * @param S the type of space of structure elements. + */ +public interface NDSpace> : Space>, NDAlgebra { + /** + * Element-wise addition. + * + * @param a the addend. + * @param b the augend. + * @return the sum. + */ + public override fun add(a: NDStructure, b: NDStructure): NDStructure = + combine(a, b) { aValue, bValue -> add(aValue, bValue) } + + /** + * Element-wise multiplication by scalar. + * + * @param a the multiplicand. + * @param k the multiplier. + * @return the product. + */ + public override fun multiply(a: NDStructure, k: Number): NDStructure = a.map() { multiply(it, k) } + + // TODO move to extensions after KEEP-176 + + /** + * Adds an ND structure to an element of it. + * + * @receiver the addend. + * @param arg the augend. + * @return the sum. + */ + public operator fun NDStructure.plus(arg: T): NDStructure = this.map() { value -> add(arg, value) } + + /** + * Subtracts an element from ND structure of it. + * + * @receiver the dividend. + * @param arg the divisor. + * @return the quotient. + */ + public operator fun NDStructure.minus(arg: T): NDStructure = this.map() { value -> add(arg, -value) } + + /** + * Adds an element to ND structure of it. + * + * @receiver the addend. + * @param arg the augend. + * @return the sum. + */ + public operator fun T.plus(arg: NDStructure): NDStructure = arg.map() { value -> add(this@plus, value) } + + /** + * Subtracts an ND structure from an element of it. + * + * @receiver the dividend. + * @param arg the divisor. + * @return the quotient. + */ + public operator fun T.minus(arg: NDStructure): NDStructure = arg.map() { value -> add(-this@minus, value) } + + public companion object +} + +/** + * Ring of [NDStructure]. + * + * @param T the type of the element contained in ND structure. + * @param N the type of ND structure. + * @param R the type of ring of structure elements. + */ +public interface NDRing> : Ring>, NDSpace { + /** + * Element-wise multiplication. + * + * @param a the multiplicand. + * @param b the multiplier. + * @return the product. + */ + public override fun multiply(a: NDStructure, b: NDStructure): NDStructure = + combine(a, b) { aValue, bValue -> multiply(aValue, bValue) } + + //TODO move to extensions after KEEP-176 + + /** + * Multiplies an ND structure by an element of it. + * + * @receiver the multiplicand. + * @param arg the multiplier. + * @return the product. + */ + public operator fun NDStructure.times(arg: T): NDStructure = this.map() { value -> multiply(arg, value) } + + /** + * Multiplies an element by a ND structure of it. + * + * @receiver the multiplicand. + * @param arg the multiplier. + * @return the product. + */ + public operator fun T.times(arg: NDStructure): NDStructure = arg.map() { value -> multiply(this@times, value) } + + public companion object +} + +/** + * Field of [NDStructure]. + * + * @param T the type of the element contained in ND structure. + * @param N the type of ND structure. + * @param F the type field of structure elements. + */ +public interface NDField> : Field>, NDRing { + /** + * Element-wise division. + * + * @param a the dividend. + * @param b the divisor. + * @return the quotient. + */ + public override fun divide(a: NDStructure, b: NDStructure): NDStructure = + combine(a, b) { aValue, bValue -> divide(aValue, bValue) } + + //TODO move to extensions after KEEP-176 + /** + * Divides an ND structure by an element of it. + * + * @receiver the dividend. + * @param arg the divisor. + * @return the quotient. + */ + public operator fun NDStructure.div(arg: T): NDStructure = this.map() { value -> divide(arg, value) } + + /** + * Divides an element by an ND structure of it. + * + * @receiver the dividend. + * @param arg the divisor. + * @return the quotient. + */ + public operator fun T.div(arg: NDStructure): NDStructure = arg.map() { divide(it, this@div) } + +// @ThreadLocal +// public companion object { +// private val realNDFieldCache: MutableMap = hashMapOf() +// +// /** +// * Create a nd-field for [Double] values or pull it from cache if it was created previously. +// */ +// public fun real(vararg shape: Int): RealNDField = realNDFieldCache.getOrPut(shape) { RealNDField(shape) } +// +// /** +// * Create an ND field with boxing generic buffer. +// */ +// public fun > boxing( +// field: F, +// vararg shape: Int, +// bufferFactory: BufferFactory = Buffer.Companion::boxing, +// ): BufferedNDField = BufferedNDField(shape, field, bufferFactory) +// +// /** +// * Create a most suitable implementation for nd-field using reified class. +// */ +// @Suppress("UNCHECKED_CAST") +// public inline fun > auto(field: F, vararg shape: Int): NDField = +// when { +// T::class == Double::class -> real(*shape) as NDField +// T::class == Complex::class -> complex(*shape) as BufferedNDField +// else -> BoxingNDField(shape, field, Buffer.Companion::auto) +// } +// } +} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/NDStructure.kt similarity index 82% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/NDStructure.kt index e7d89ca7e..137772632 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/NDStructure.kt @@ -1,6 +1,10 @@ -package kscience.kmath.structures +package space.kscience.kmath.nd -import kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.asSequence import kotlin.jvm.JvmName import kotlin.native.concurrent.ThreadLocal import kotlin.reflect.KClass @@ -74,8 +78,7 @@ public interface NDStructure { strides: Strides, bufferFactory: BufferFactory = Buffer.Companion::boxing, initializer: (IntArray) -> T, - ): BufferNDStructure = - BufferNDStructure(strides, bufferFactory(strides.linearSize) { i -> initializer(strides.index(i)) }) + ): NDBuffer = NDBuffer(strides, bufferFactory(strides.linearSize) { i -> initializer(strides.index(i)) }) /** * Inline create NDStructure with non-boxing buffer implementation if it is possible @@ -83,41 +86,37 @@ public interface NDStructure { public inline fun auto( strides: Strides, crossinline initializer: (IntArray) -> T, - ): BufferNDStructure = - BufferNDStructure(strides, Buffer.auto(strides.linearSize) { i -> initializer(strides.index(i)) }) + ): NDBuffer = NDBuffer(strides, Buffer.auto(strides.linearSize) { i -> initializer(strides.index(i)) }) public inline fun auto( type: KClass, strides: Strides, crossinline initializer: (IntArray) -> T, - ): BufferNDStructure = - BufferNDStructure(strides, Buffer.auto(type, strides.linearSize) { i -> initializer(strides.index(i)) }) + ): NDBuffer = NDBuffer(strides, Buffer.auto(type, strides.linearSize) { i -> initializer(strides.index(i)) }) public fun build( shape: IntArray, bufferFactory: BufferFactory = Buffer.Companion::boxing, initializer: (IntArray) -> T, - ): BufferNDStructure = build(DefaultStrides(shape), bufferFactory, initializer) + ): NDBuffer = build(DefaultStrides(shape), bufferFactory, initializer) public inline fun auto( shape: IntArray, crossinline initializer: (IntArray) -> T, - ): BufferNDStructure = - auto(DefaultStrides(shape), initializer) + ): NDBuffer = auto(DefaultStrides(shape), initializer) @JvmName("autoVarArg") public inline fun auto( vararg shape: Int, crossinline initializer: (IntArray) -> T, - ): BufferNDStructure = + ): NDBuffer = auto(DefaultStrides(shape), initializer) public inline fun auto( type: KClass, vararg shape: Int, crossinline initializer: (IntArray) -> T, - ): BufferNDStructure = - auto(type, DefaultStrides(shape), initializer) + ): NDBuffer = auto(type, DefaultStrides(shape), initializer) } } @@ -156,7 +155,7 @@ public inline fun MutableNDStructure.mapInPlace(action: (IntArray, T) -> */ public interface Strides { /** - * Shape of NDstructure + * Shape of NDStructure */ public val shape: IntArray @@ -185,7 +184,9 @@ public interface Strides { /** * Iterate over ND indices in a natural order */ - public fun indices(): Sequence = (0 until linearSize).asSequence().map { index(it) } + public fun indices(): Sequence = (0 until linearSize).asSequence().map { + index(it) + } } /** @@ -211,9 +212,7 @@ public class DefaultStrides private constructor(override val shape: IntArray) : } override fun offset(index: IntArray): Int = index.mapIndexed { i, value -> - if (value < 0 || value >= this.shape[i]) - throw IndexOutOfBoundsException("Index $value out of shape bounds: (0,${this.shape[i]})") - + if (value < 0 || value >= shape[i]) throw IndexOutOfBoundsException("Index $value out of shape bounds: (0,${this.shape[i]})") value * strides[i] }.sum() @@ -256,23 +255,29 @@ public class DefaultStrides private constructor(override val shape: IntArray) : * Represents [NDStructure] over [Buffer]. * * @param T the type of items. + * @param strides The strides to access elements of [Buffer] by linear indices. + * @param buffer The underlying buffer. */ -public abstract class NDBuffer : NDStructure { - /** - * The underlying buffer. - */ - public abstract val buffer: Buffer +public open class NDBuffer( + public val strides: Strides, + buffer: Buffer, +) : NDStructure { - /** - * The strides to access elements of [Buffer] by linear indices. - */ - public abstract val strides: Strides + init { + if (strides.linearSize != buffer.size) { + error("Expected buffer side of ${strides.linearSize}, but found ${buffer.size}") + } + } + + public open val buffer: Buffer = buffer override operator fun get(index: IntArray): T = buffer[strides.offset(index)] override val shape: IntArray get() = strides.shape - override fun elements(): Sequence> = strides.indices().map { it to this[it] } + override fun elements(): Sequence> = strides.indices().map { + it to this[it] + } override fun equals(other: Any?): Boolean { return NDStructure.contentEquals(this, other as? NDStructure<*> ?: return false) @@ -297,46 +302,30 @@ public abstract class NDBuffer : NDStructure { } return "NDBuffer(shape=${shape.contentToString()}, buffer=$bufferRepr)" } - - } /** - * Boxing generic [NDStructure] - */ -public class BufferNDStructure( - override val strides: Strides, - override val buffer: Buffer, -) : NDBuffer() { - init { - if (strides.linearSize != buffer.size) { - error("Expected buffer side of ${strides.linearSize}, but found ${buffer.size}") - } - } -} - -/** - * Transform structure to a new structure using provided [BufferFactory] and optimizing if argument is [BufferNDStructure] + * Transform structure to a new structure using provided [BufferFactory] and optimizing if argument is [NDBuffer] */ public inline fun NDStructure.mapToBuffer( factory: BufferFactory = Buffer.Companion::auto, crossinline transform: (T) -> R, -): BufferNDStructure { - return if (this is BufferNDStructure) - BufferNDStructure(this.strides, factory.invoke(strides.linearSize) { transform(buffer[it]) }) +): NDBuffer { + return if (this is NDBuffer) + NDBuffer(this.strides, factory.invoke(strides.linearSize) { transform(buffer[it]) }) else { val strides = DefaultStrides(shape) - BufferNDStructure(strides, factory.invoke(strides.linearSize) { transform(get(strides.index(it))) }) + NDBuffer(strides, factory.invoke(strides.linearSize) { transform(get(strides.index(it))) }) } } /** * Mutable ND buffer based on linear [MutableBuffer]. */ -public class MutableBufferNDStructure( - override val strides: Strides, - override val buffer: MutableBuffer, -) : NDBuffer(), MutableNDStructure { +public class MutableNDBuffer( + strides: Strides, + buffer: MutableBuffer, +) : NDBuffer(strides, buffer), MutableNDStructure { init { require(strides.linearSize == buffer.size) { @@ -344,6 +333,8 @@ public class MutableBufferNDStructure( } } + override val buffer: MutableBuffer = super.buffer as MutableBuffer + override operator fun set(index: IntArray, value: T): Unit = buffer.set(strides.offset(index), value) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/RealNDField.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/RealNDField.kt new file mode 100644 index 000000000..73ba337ae --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/RealNDField.kt @@ -0,0 +1,107 @@ +package space.kscience.kmath.nd + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.RingWithNumbers +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.RealBuffer +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + +@OptIn(UnstableKMathAPI::class) +public class RealNDField( + shape: IntArray, +) : BufferedNDField(shape, RealField, Buffer.Companion::real), + RingWithNumbers>, + ExtendedField> { + + override val zero: NDBuffer by lazy { produce { zero } } + override val one: NDBuffer by lazy { produce { one } } + + override fun number(value: Number): NDBuffer { + val d = value.toDouble() // minimize conversions + return produce { d } + } + + override val NDStructure.buffer: RealBuffer + get() = when { + !shape.contentEquals(this@RealNDField.shape) -> throw ShapeMismatchException( + this@RealNDField.shape, + shape + ) + this is NDBuffer && this.strides == this@RealNDField.strides -> this.buffer as RealBuffer + else -> RealBuffer(strides.linearSize) { offset -> get(strides.index(offset)) } + } + + @Suppress("OVERRIDE_BY_INLINE") + override inline fun NDStructure.map( + transform: RealField.(Double) -> Double, + ): NDBuffer { + val buffer = RealBuffer(strides.linearSize) { offset -> RealField.transform(buffer.array[offset]) } + return NDBuffer(strides, buffer) + } + + @Suppress("OVERRIDE_BY_INLINE") + override inline fun produce(initializer: RealField.(IntArray) -> Double): NDBuffer { + val array = DoubleArray(strides.linearSize) { offset -> + val index = strides.index(offset) + RealField.initializer(index) + } + return NDBuffer(strides, RealBuffer(array)) + } + + @Suppress("OVERRIDE_BY_INLINE") + override inline fun NDStructure.mapIndexed( + transform: RealField.(index: IntArray, Double) -> Double, + ): NDBuffer = NDBuffer( + strides, + buffer = RealBuffer(strides.linearSize) { offset -> + RealField.transform( + strides.index(offset), + buffer.array[offset] + ) + }) + + @Suppress("OVERRIDE_BY_INLINE") + override inline fun combine( + a: NDStructure, + b: NDStructure, + transform: RealField.(Double, Double) -> Double, + ): NDBuffer { + val buffer = RealBuffer(strides.linearSize) { offset -> + RealField.transform(a.buffer.array[offset], b.buffer.array[offset]) + } + return NDBuffer(strides, buffer) + } + + override fun power(arg: NDStructure, pow: Number): NDBuffer = arg.map { power(it, pow) } + + override fun exp(arg: NDStructure): NDBuffer = arg.map { exp(it) } + + override fun ln(arg: NDStructure): NDBuffer = arg.map { ln(it) } + + override fun sin(arg: NDStructure): NDBuffer = arg.map { sin(it) } + override fun cos(arg: NDStructure): NDBuffer = arg.map { cos(it) } + override fun tan(arg: NDStructure): NDBuffer = arg.map { tan(it) } + override fun asin(arg: NDStructure): NDBuffer = arg.map { asin(it) } + override fun acos(arg: NDStructure): NDBuffer = arg.map { acos(it) } + override fun atan(arg: NDStructure): NDBuffer = arg.map { atan(it) } + + override fun sinh(arg: NDStructure): NDBuffer = arg.map { sinh(it) } + override fun cosh(arg: NDStructure): NDBuffer = arg.map { cosh(it) } + override fun tanh(arg: NDStructure): NDBuffer = arg.map { tanh(it) } + override fun asinh(arg: NDStructure): NDBuffer = arg.map { asinh(it) } + override fun acosh(arg: NDStructure): NDBuffer = arg.map { acosh(it) } + override fun atanh(arg: NDStructure): NDBuffer = arg.map { atanh(it) } +} + +public fun NDAlgebra.Companion.real(vararg shape: Int): RealNDField = RealNDField(shape) + +/** + * Produce a context for n-dimensional operations inside this real field + */ +public inline fun RealField.nd(vararg shape: Int, action: RealNDField.() -> R): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return RealNDField(shape).run(action) +} diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortNDRing.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortNDRing.kt new file mode 100644 index 000000000..30960a090 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortNDRing.kt @@ -0,0 +1,36 @@ +package space.kscience.kmath.nd + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.RingWithNumbers +import space.kscience.kmath.operations.ShortRing +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.ShortBuffer +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + +@OptIn(UnstableKMathAPI::class) +public class ShortNDRing( + shape: IntArray, +) : BufferedNDRing(shape, ShortRing, Buffer.Companion::auto), + RingWithNumbers> { + + override val zero: NDBuffer by lazy { produce { zero } } + override val one: NDBuffer by lazy { produce { one } } + + override fun number(value: Number): NDBuffer { + val d = value.toShort() // minimize conversions + return produce { d } + } +} + +/** + * Fast element production using function inlining. + */ +public inline fun BufferedNDRing.produceInline(crossinline initializer: ShortRing.(Int) -> Short): NDBuffer { + return NDBuffer(strides, ShortBuffer(ShortArray(strides.linearSize) { offset -> ShortRing.initializer(offset) })) +} + +public inline fun ShortRing.nd(vararg shape: Int, action: ShortNDRing.() -> R): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return ShortNDRing(shape).run(action) +} \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Structure1D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt similarity index 88% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Structure1D.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt index 95422ac60..e83485ff0 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Structure1D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt @@ -1,4 +1,7 @@ -package kscience.kmath.structures +package space.kscience.kmath.nd + +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asSequence /** * A structure that is guaranteed to be one-dimensional @@ -34,7 +37,7 @@ private inline class Buffer1DWrapper(val buffer: Buffer) : Structure1D override val size: Int get() = buffer.size override fun elements(): Sequence> = - asSequence().mapIndexed { index, value -> intArrayOf(index) to value } + buffer.asSequence().mapIndexed { index, value -> intArrayOf(index) to value } override operator fun get(index: Int): T = buffer[index] } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Structure2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt similarity index 80% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Structure2D.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt index d20e9e53b..fcc8c0d7e 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt @@ -1,4 +1,9 @@ -package kscience.kmath.structures +package space.kscience.kmath.nd + +import space.kscience.kmath.linear.BufferMatrix +import space.kscience.kmath.linear.RealMatrixContext +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.VirtualBuffer /** * A structure that is guaranteed to be two-dimensional. @@ -49,7 +54,15 @@ public interface Structure2D : NDStructure { for (j in 0 until colNum) yield(intArrayOf(i, j) to get(i, j)) } - public companion object + public companion object { + public inline fun real( + rows: Int, + columns: Int, + crossinline init: (i: Int, j: Int) -> Double, + ): BufferMatrix = RealMatrixContext.produce(rows,columns) { i, j -> + init(i, j) + } + } } /** @@ -77,6 +90,6 @@ else /** * Alias for [Structure2D] with more familiar name. * - * @param T the type of items. + * @param T the type of items in the matrix. */ public typealias Matrix = Structure2D diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt similarity index 89% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt index e7eb2770d..201e39314 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt @@ -1,4 +1,6 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations + +import space.kscience.kmath.expressions.Symbol /** * Stub for DSL the [Algebra] is. @@ -24,7 +26,7 @@ public interface Algebra { * @param value the raw string. * @return an object. */ - public fun symbol(value: String): T = error("Wrapping of '$value' is not supported in $this") + public fun bindSymbol(value: String): T = error("Wrapping of '$value' is not supported in $this") /** * Dynamically dispatches an unary operation with the certain name. @@ -88,6 +90,8 @@ public interface Algebra { public fun binaryOperation(operation: String, left: T, right: T): T = binaryOperationFunction(operation)(left, right) } +public fun Algebra.bindSymbol(symbol: Symbol): T = bindSymbol(symbol.identity) + /** * Call a block with an [Algebra] as receiver. */ @@ -95,8 +99,8 @@ public interface Algebra { public inline operator fun , R> A.invoke(block: A.() -> R): R = run(block) /** - * Represents "semispace", i.e. algebraic structure with associative binary operation called "addition" as well as - * multiplication by scalars. + * Represents linear space without neutral element, i.e. algebraic structure with associative, binary operation [add] + * and scalar multiplication [multiply]. * * @param T the type of element of this semispace. */ @@ -162,7 +166,7 @@ public interface SpaceOperations : Algebra { * @param k the multiplicand. * @return the product. */ - public operator fun T.times(k: Number): T = multiply(this, k.toDouble()) + public operator fun T.times(k: Number): T = multiply(this, k) /** * Division of this element by scalar. @@ -208,10 +212,10 @@ public interface SpaceOperations : Algebra { } /** - * Represents linear space, i.e. algebraic structure with associative binary operation called "addition" and its neutral - * element as well as multiplication by scalars. + * Represents linear space with neutral element, i.e. algebraic structure with associative, binary operation [add] and + * scalar multiplication [multiply]. * - * @param T the type of element of this group. + * @param T the type of element of this semispace. */ public interface Space : SpaceOperations { /** @@ -221,8 +225,8 @@ public interface Space : SpaceOperations { } /** - * Represents semiring, i.e. algebraic structure with two associative binary operations called "addition" and - * "multiplication". + * Represents rng, i.e. algebraic structure with associative, binary, commutative operation [add] and associative, + * operation [multiply] distributive over [add]. * * @param T the type of element of this semiring. */ @@ -270,8 +274,8 @@ public interface Ring : Space, RingOperations { } /** - * Represents semifield, i.e. algebraic structure with three operations: associative "addition" and "multiplication", - * and "division". + * Represents field without identity elements, i.e. algebraic structure with associative, binary, commutative operations + * [add] and [multiply]; binary operation [divide] as multiplication of left operand by reciprocal of right one. * * @param T the type of element of this semifield. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/AlgebraElements.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/AlgebraElements.kt new file mode 100644 index 000000000..629c4de1b --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/AlgebraElements.kt @@ -0,0 +1,109 @@ +package space.kscience.kmath.operations + +import space.kscience.kmath.misc.UnstableKMathAPI + +/** + * The generic mathematics elements which is able to store its context + * + * @param C the type of mathematical context for this element. + * @param T the type wrapped by this wrapper. + */ +public interface AlgebraElement> { + /** + * The context this element belongs to. + */ + public val context: C +} + +/** + * Divides this element by number. + * + * @param k the divisor. + * @return the quotient. + */ +public operator fun , S : Space> T.div(k: Number): T = + context.multiply(this, 1.0 / k.toDouble()) + +/** + * Multiplies this element by number. + * + * @param k the multiplicand. + * @return the product. + */ +public operator fun , S : Space> T.times(k: Number): T = + context.multiply(this, k.toDouble()) + +/** + * Subtracts element from this one. + * + * @param b the subtrahend. + * @return the difference. + */ +public operator fun , S : Space> T.minus(b: T): T = + context.add(this, context.multiply(b, -1.0)) + +/** + * Adds element to this one. + * + * @param b the augend. + * @return the sum. + */ +public operator fun , S : Space> T.plus(b: T): T = + context.add(this, b) + +/** + * Number times element + */ +public operator fun , S : Space> Number.times(element: T): T = + element.times(this) + + +/** + * Multiplies this element by another one. + * + * @param b the multiplicand. + * @return the product. + */ +public operator fun , R : Ring> T.times(b: T): T = + context.multiply(this, b) + + +/** + * Divides this element by another one. + * + * @param b the divisor. + * @return the quotient. + */ +public operator fun , F : Field> T.div(b: T): T = + context.divide(this, b) + + +/** + * The element of [Space]. + * + * @param T the type of space operation results. + * @param I self type of the element. Needed for static type checking. + * @param S the type of space. + */ +@UnstableKMathAPI +public interface SpaceElement, S : Space> : AlgebraElement + +/** + * The element of [Ring]. + * + * @param T the type of ring operation results. + * @param I self type of the element. Needed for static type checking. + * @param R the type of ring. + */ +@UnstableKMathAPI +public interface RingElement, R : Ring> : SpaceElement + +/** + * The element of [Field]. + * + * @param T the type of field operation results. + * @param I self type of the element. Needed for static type checking. + * @param F the type of field. + */ +@UnstableKMathAPI +public interface FieldElement, F : Field> : RingElement \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/BigInt.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt similarity index 96% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/operations/BigInt.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt index 0be72e80c..c21260b82 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/BigInt.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt @@ -1,9 +1,12 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.BigInt.Companion.BASE -import kscience.kmath.operations.BigInt.Companion.BASE_SIZE -import kscience.kmath.structures.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.BufferedNDRing +import space.kscience.kmath.nd.NDAlgebra +import space.kscience.kmath.operations.BigInt.Companion.BASE +import space.kscience.kmath.operations.BigInt.Companion.BASE_SIZE +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.MutableBuffer import kotlin.math.log2 import kotlin.math.max import kotlin.math.min @@ -40,7 +43,7 @@ public object BigIntField : Field, RingWithNumbers { public class BigInt internal constructor( private val sign: Byte, private val magnitude: Magnitude -) : Comparable { + ) : Comparable { public override fun compareTo(other: BigInt): Int = when { (sign == 0.toByte()) and (other.sign == 0.toByte()) -> 0 sign < other.sign -> -1 @@ -462,10 +465,5 @@ public inline fun Buffer.Companion.bigInt(size: Int, initializer: (Int) -> BigIn public inline fun MutableBuffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInt): MutableBuffer = boxing(size, initializer) -public fun NDAlgebra.Companion.bigInt(vararg shape: Int): BoxingNDRing = - BoxingNDRing(shape, BigIntField, Buffer.Companion::bigInt) - -public fun NDElement.Companion.bigInt( - vararg shape: Int, - initializer: BigIntField.(IntArray) -> BigInt -): BufferedNDRingElement = NDAlgebra.bigInt(*shape).produce(initializer) +public fun NDAlgebra.Companion.bigInt(vararg shape: Int): BufferedNDRing = + BufferedNDRing(shape, BigIntField, Buffer.Companion::bigInt) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/NumericAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/NumericAlgebra.kt similarity index 98% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/operations/NumericAlgebra.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/NumericAlgebra.kt index 26f93fae8..81f4c1fdf 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/NumericAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/NumericAlgebra.kt @@ -1,6 +1,6 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations -import kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.misc.UnstableKMathAPI /** * An algebraic structure where elements can have numeric representation. diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/OptionalOperations.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt similarity index 72% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/operations/OptionalOperations.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt index f31d61ae1..6cb329695 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/OptionalOperations.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt @@ -1,4 +1,6 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations + +import space.kscience.kmath.misc.UnstableKMathAPI /** * A container for trigonometric operations for specific type. @@ -72,32 +74,38 @@ public interface TrigonometricOperations : Algebra { /** * Computes the sine of [arg]. */ -public fun >> sin(arg: T): T = arg.context.sin(arg) +@UnstableKMathAPI +public fun >> sin(arg: T): T = arg.context.sin(arg) /** * Computes the cosine of [arg]. */ -public fun >> cos(arg: T): T = arg.context.cos(arg) +@UnstableKMathAPI +public fun >> cos(arg: T): T = arg.context.cos(arg) /** * Computes the tangent of [arg]. */ -public fun >> tan(arg: T): T = arg.context.tan(arg) +@UnstableKMathAPI +public fun >> tan(arg: T): T = arg.context.tan(arg) /** * Computes the inverse sine of [arg]. */ -public fun >> asin(arg: T): T = arg.context.asin(arg) +@UnstableKMathAPI +public fun >> asin(arg: T): T = arg.context.asin(arg) /** * Computes the inverse cosine of [arg]. */ -public fun >> acos(arg: T): T = arg.context.acos(arg) +@UnstableKMathAPI +public fun >> acos(arg: T): T = arg.context.acos(arg) /** * Computes the inverse tangent of [arg]. */ -public fun >> atan(arg: T): T = arg.context.atan(arg) +@UnstableKMathAPI +public fun >> atan(arg: T): T = arg.context.atan(arg) /** * A container for hyperbolic trigonometric operations for specific type. @@ -171,32 +179,38 @@ public interface HyperbolicOperations : Algebra { /** * Computes the hyperbolic sine of [arg]. */ -public fun >> sinh(arg: T): T = arg.context.sinh(arg) +@UnstableKMathAPI +public fun >> sinh(arg: T): T = arg.context.sinh(arg) /** * Computes the hyperbolic cosine of [arg]. */ -public fun >> cosh(arg: T): T = arg.context.cosh(arg) +@UnstableKMathAPI +public fun >> cosh(arg: T): T = arg.context.cosh(arg) /** * Computes the hyperbolic tangent of [arg]. */ -public fun >> tanh(arg: T): T = arg.context.tanh(arg) +@UnstableKMathAPI +public fun >> tanh(arg: T): T = arg.context.tanh(arg) /** * Computes the inverse hyperbolic sine of [arg]. */ -public fun >> asinh(arg: T): T = arg.context.asinh(arg) +@UnstableKMathAPI +public fun >> asinh(arg: T): T = arg.context.asinh(arg) /** * Computes the inverse hyperbolic cosine of [arg]. */ -public fun >> acosh(arg: T): T = arg.context.acosh(arg) +@UnstableKMathAPI +public fun >> acosh(arg: T): T = arg.context.acosh(arg) /** * Computes the inverse hyperbolic tangent of [arg]. */ -public fun >> atanh(arg: T): T = arg.context.atanh(arg) +@UnstableKMathAPI +public fun >> atanh(arg: T): T = arg.context.atanh(arg) /** * A context extension to include power operations based on exponentiation. @@ -239,17 +253,20 @@ public interface PowerOperations : Algebra { * @param power the exponent. * @return the base raised to the power. */ -public infix fun >> T.pow(power: Double): T = context.power(this, power) +@UnstableKMathAPI +public infix fun >> T.pow(power: Double): T = context.power(this, power) /** * Computes the square root of the value [arg]. */ -public fun >> sqrt(arg: T): T = arg pow 0.5 +@UnstableKMathAPI +public fun >> sqrt(arg: T): T = arg pow 0.5 /** * Computes the square of the value [arg]. */ -public fun >> sqr(arg: T): T = arg pow 2.0 +@UnstableKMathAPI +public fun >> sqr(arg: T): T = arg pow 2.0 /** * A container for operations related to `exp` and `ln` functions. @@ -283,12 +300,14 @@ public interface ExponentialOperations : Algebra { /** * The identifier of exponential function. */ -public fun >> exp(arg: T): T = arg.context.exp(arg) +@UnstableKMathAPI +public fun >> exp(arg: T): T = arg.context.exp(arg) /** * The identifier of natural logarithm. */ -public fun >> ln(arg: T): T = arg.context.ln(arg) +@UnstableKMathAPI +public fun >> ln(arg: T): T = arg.context.ln(arg) /** * A container for norm functional on element. @@ -306,4 +325,5 @@ public interface Norm { /** * Computes the norm of [arg] (i.e. absolute value or vector length). */ -public fun >, R> norm(arg: T): R = arg.context.norm(arg) +@UnstableKMathAPI +public fun >, R> norm(arg: T): R = arg.context.norm(arg) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/AlgebraExtensions.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt similarity index 98% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/operations/AlgebraExtensions.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt index 4527a2a42..ae1267d2b 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/AlgebraExtensions.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt @@ -1,4 +1,4 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations /** * Returns the sum of all elements in the iterable in this [Space]. diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/numbers.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/numbers.kt similarity index 95% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/operations/numbers.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/numbers.kt index 0440d74e8..aa62715d1 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/numbers.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/numbers.kt @@ -1,4 +1,4 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations import kotlin.math.pow as kpow @@ -52,23 +52,6 @@ public interface ExtendedField : ExtendedFieldOperations, Field, Numeri } } -/** - * Real field element wrapping double. - * - * @property value the [Double] value wrapped by this [Real]. - * - * TODO inline does not work due to compiler bug. Waiting for fix for KT-27586 - */ -public inline class Real(public val value: Double) : FieldElement { - public override val context: RealField - get() = RealField - - public override fun unwrap(): Double = value - public override fun Double.wrap(): Real = Real(value) - - public companion object -} - /** * A field for [Double] without boxing. Does not produce appropriate field element. */ diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt similarity index 95% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt index bfec6f871..2fccd2eeb 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt @@ -1,7 +1,5 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures -import kscience.kmath.operations.Complex -import kscience.kmath.operations.complex import kotlin.reflect.KClass /** @@ -23,7 +21,7 @@ public typealias MutableBufferFactory = (Int, (Int) -> T) -> MutableBuffer * * @param T the type of elements contained in the buffer. */ -public interface Buffer { +public interface Buffer { /** * The size of this buffer. */ @@ -76,7 +74,6 @@ public interface Buffer { Int::class -> IntBuffer(size) { initializer(it) as Int } as Buffer Long::class -> LongBuffer(size) { initializer(it) as Long } as Buffer Float::class -> FloatBuffer(size) { initializer(it) as Float } as Buffer - Complex::class -> complex(size) { initializer(it) as Complex } as Buffer else -> boxing(size, initializer) } @@ -149,7 +146,6 @@ public interface MutableBuffer : Buffer { Int::class -> IntBuffer(size) { initializer(it) as Int } as MutableBuffer Float::class -> FloatBuffer(size) { initializer(it) as Float } as MutableBuffer Long::class -> LongBuffer(size) { initializer(it) as Long } as MutableBuffer - Complex::class -> complex(size) { initializer(it) as Complex } as MutableBuffer else -> boxing(size, initializer) } @@ -241,11 +237,22 @@ public class ArrayBuffer(private val array: Array) : MutableBuffer { override fun copy(): MutableBuffer = ArrayBuffer(array.copyOf()) } + /** * Returns an [ArrayBuffer] that wraps the original array. */ public fun Array.asBuffer(): ArrayBuffer = ArrayBuffer(this) +/** + * Creates a new [ArrayBuffer] with the specified [size], where each element is calculated by calling the specified + * [init] function. + * + * The function [init] is called for each array element sequentially starting from the first one. + * It should return the value for an array element given its index. + */ +public inline fun ArrayBuffer(size: Int, init: (Int) -> T): ArrayBuffer = + Array(size) { i -> init(i) }.asBuffer() + /** * Immutable wrapper for [MutableBuffer]. * diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BufferAccessor2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt similarity index 88% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BufferAccessor2D.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt index 5d7ba611f..fd440a344 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/BufferAccessor2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt @@ -1,4 +1,9 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures + +import space.kscience.kmath.nd.DefaultStrides +import space.kscience.kmath.nd.NDStructure +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.nd.as2D /** * A context that allows to operate on a [MutableBuffer] as on 2d array diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/FlaggedBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt similarity index 98% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/FlaggedBuffer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt index 4965e37cf..3326c1491 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/FlaggedBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt @@ -1,4 +1,4 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures import kotlin.experimental.and diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/FloatBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FloatBuffer.kt similarity index 97% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/FloatBuffer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FloatBuffer.kt index e96c45572..3839be8e1 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/FloatBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FloatBuffer.kt @@ -1,4 +1,4 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures /** * Specialized [MutableBuffer] implementation over [FloatArray]. diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/IntBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/IntBuffer.kt similarity index 97% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/IntBuffer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/IntBuffer.kt index 0fe68803b..df3289a3e 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/IntBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/IntBuffer.kt @@ -1,4 +1,4 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures /** * Specialized [MutableBuffer] implementation over [IntArray]. diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/LongBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/LongBuffer.kt similarity index 97% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/LongBuffer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/LongBuffer.kt index 87853c251..d07d44799 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/LongBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/LongBuffer.kt @@ -1,4 +1,4 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures /** * Specialized [MutableBuffer] implementation over [LongArray]. diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/MemoryBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt similarity index 88% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/MemoryBuffer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt index 66c9212cf..418adb537 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/MemoryBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt @@ -1,6 +1,6 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures -import kscience.kmath.memory.* +import space.kscience.kmath.memory.* /** * A non-boxing buffer over [Memory] object. @@ -43,8 +43,8 @@ public class MutableMemoryBuffer(memory: Memory, spec: MemorySpec) : private val writer: MemoryWriter = memory.writer() - override operator fun set(index: Int, value: T): Unit = writer.write(spec, spec.objectSize * index, value) - override fun copy(): MutableBuffer = MutableMemoryBuffer(memory.copy(), spec) + public override operator fun set(index: Int, value: T): Unit = writer.write(spec, spec.objectSize * index, value) + public override fun copy(): MutableBuffer = MutableMemoryBuffer(memory.copy(), spec) public companion object { public fun create(spec: MemorySpec, size: Int): MutableMemoryBuffer = diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt similarity index 90% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBuffer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt index 769c445d6..e53ed85c7 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt @@ -1,4 +1,4 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures /** * Specialized [MutableBuffer] implementation over [DoubleArray]. @@ -9,9 +9,9 @@ package kscience.kmath.structures public inline class RealBuffer(public val array: DoubleArray) : MutableBuffer { override val size: Int get() = array.size - override inline operator fun get(index: Int): Double = array[index] + override operator fun get(index: Int): Double = array[index] - override inline operator fun set(index: Int, value: Double) { + override operator fun set(index: Int, value: Double) { array[index] = value } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBufferField.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBufferField.kt similarity index 98% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBufferField.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBufferField.kt index 3f4d15c4d..7351881ee 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBufferField.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBufferField.kt @@ -1,7 +1,7 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures -import kscience.kmath.operations.ExtendedField -import kscience.kmath.operations.ExtendedFieldOperations +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.ExtendedFieldOperations import kotlin.math.* /** diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ShortBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ShortBuffer.kt similarity index 97% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ShortBuffer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ShortBuffer.kt index 0d9222320..afc472b72 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/ShortBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ShortBuffer.kt @@ -1,4 +1,4 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures /** * Specialized [MutableBuffer] implementation over [ShortArray]. diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt b/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt deleted file mode 100644 index 456e41467..000000000 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -package kscience.kmath.operations - -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -internal class ComplexTest { - @Test - fun conjugate() { - assertEquals( - Complex(0, -42), (ComplexField.i * 42).conjugate - ) - } - - @Test - fun reciprocal() { - assertTrue { (Complex(0.5, -0.0) - 2.toComplex().reciprocal).r < 1e-10} - } - - @Test - fun r() { - assertEquals(kotlin.math.sqrt(2.0), (ComplexField.i + 1.0.toComplex()).r) - } - - @Test - fun theta() { - assertEquals(0.0, 1.toComplex().theta) - } - - @Test - fun toComplex() { - assertEquals(Complex(42, 0), 42.toComplex()) - assertEquals(Complex(42.0, 0), 42.0.toComplex()) - assertEquals(Complex(42f, 0), 42f.toComplex()) - assertEquals(Complex(42.0, 0), 42.0.toComplex()) - assertEquals(Complex(42.toByte(), 0), 42.toByte().toComplex()) - assertEquals(Complex(42.toShort(), 0), 42.toShort().toComplex()) - } -} diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/NDFieldTest.kt b/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/NDFieldTest.kt deleted file mode 100644 index 1129a8a36..000000000 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/NDFieldTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.internal.FieldVerifier -import kotlin.test.Test -import kotlin.test.assertEquals - -internal class NDFieldTest { - @Test - fun verify() { - NDField.real(12, 32).run { FieldVerifier(this, one + 3, one - 23, one * 12, 6.66) } - } - - @Test - fun testStrides() { - val ndArray = NDElement.real(intArrayOf(10, 10)) { (it[0] + it[1]).toDouble() } - assertEquals(ndArray[5, 5], 10.0) - } -} diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/NumberNDFieldTest.kt b/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/NumberNDFieldTest.kt deleted file mode 100644 index 22a0d3629..000000000 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/NumberNDFieldTest.kt +++ /dev/null @@ -1,69 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.Norm -import kscience.kmath.operations.invoke -import kscience.kmath.structures.NDElement.Companion.real2D -import kotlin.math.abs -import kotlin.math.pow -import kotlin.test.Test -import kotlin.test.assertEquals - -@Suppress("UNUSED_VARIABLE") -class NumberNDFieldTest { - val array1: RealNDElement = real2D(3, 3) { i, j -> (i + j).toDouble() } - val array2: RealNDElement = real2D(3, 3) { i, j -> (i - j).toDouble() } - - @Test - fun testSum() { - val sum = array1 + array2 - assertEquals(4.0, sum[2, 2]) - } - - @Test - fun testProduct() { - val product = array1 * array2 - assertEquals(0.0, product[2, 2]) - } - - @Test - fun testGeneration() { - - val array = real2D(3, 3) { i, j -> (i * 10 + j).toDouble() } - - for (i in 0..2) { - for (j in 0..2) { - val expected = (i * 10 + j).toDouble() - assertEquals(expected, array[i, j], "Error at index [$i, $j]") - } - } - } - - @Test - fun testExternalFunction() { - val function: (Double) -> Double = { x -> x.pow(2) + 2 * x + 1 } - val result = function(array1) + 1.0 - assertEquals(10.0, result[1, 1]) - } - - @Test - fun testLibraryFunction() { - val abs: (Double) -> Double = ::abs - val result = abs(array2) - assertEquals(2.0, result[0, 2]) - } - - @Test - fun combineTest() { - val division = array1.combine(array2, Double::div) - } - - object L2Norm : Norm, Double> { - override fun norm(arg: NDStructure): Double = - kotlin.math.sqrt(arg.elements().sumByDouble { it.second.toDouble() }) - } - - @Test - fun testInternalContext() { - (NDField.real(*array1.shape)) { with(L2Norm) { 1 + norm(array1) + exp(array2) } } - } -} diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/expressions/ExpressionFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/ExpressionFieldTest.kt similarity index 64% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/expressions/ExpressionFieldTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/ExpressionFieldTest.kt index 484993eef..c13850193 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/expressions/ExpressionFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/ExpressionFieldTest.kt @@ -1,15 +1,14 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.operations.Complex -import kscience.kmath.operations.ComplexField -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.invoke import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFails class ExpressionFieldTest { val x by symbol + @Test fun testExpression() { val context = FunctionalExpressionField(RealField) @@ -20,20 +19,7 @@ class ExpressionFieldTest { } assertEquals(expression(x to 1.0), 4.0) - assertFails { expression()} - } - - @Test - fun testComplex() { - val context = FunctionalExpressionField(ComplexField) - - val expression = context { - val x = bind(x) - x * x + 2 * x + one - } - - assertEquals(expression(x to Complex(1.0, 0.0)), Complex(4.0, 0.0)) - //assertEquals(expression(), Complex(9.0, 0.0)) + assertFails { expression() } } @Test diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/expressions/SimpleAutoDiffTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/SimpleAutoDiffTest.kt similarity index 95% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/expressions/SimpleAutoDiffTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/SimpleAutoDiffTest.kt index 510ed23a9..ee7fffa4c 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/expressions/SimpleAutoDiffTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/SimpleAutoDiffTest.kt @@ -1,7 +1,7 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.operations.RealField -import kscience.kmath.structures.asBuffer +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.structures.asBuffer import kotlin.math.E import kotlin.math.PI import kotlin.math.pow @@ -15,14 +15,14 @@ class SimpleAutoDiffTest { fun dx( xBinding: Pair, body: SimpleAutoDiffField.(x: AutoDiffValue) -> AutoDiffValue, - ): DerivationResult = RealField.simpleAutoDiff(xBinding) { body(bind(xBinding.first)) } + ): DerivationResult = RealField.simpleAutoDiff(xBinding) { body(bindSymbol(xBinding.first)) } fun dxy( xBinding: Pair, yBinding: Pair, body: SimpleAutoDiffField.(x: AutoDiffValue, y: AutoDiffValue) -> AutoDiffValue, ): DerivationResult = RealField.simpleAutoDiff(xBinding, yBinding) { - body(bind(xBinding.first), bind(yBinding.first)) + body(bindSymbol(xBinding.first), bindSymbol(yBinding.first)) } fun diff(block: SimpleAutoDiffField.() -> AutoDiffValue): SimpleAutoDiffExpression { @@ -37,7 +37,7 @@ class SimpleAutoDiffTest { fun testPlusX2() { val y = RealField.simpleAutoDiff(x to 3.0) { // diff w.r.t this x at 3 - val x = bind(x) + val x = bindSymbol(x) x + x } assertEquals(6.0, y.value) // y = x + x = 6 @@ -47,7 +47,7 @@ class SimpleAutoDiffTest { @Test fun testPlusX2Expr() { val expr = diff { - val x = bind(x) + val x = bindSymbol(x) x + x } assertEquals(6.0, expr(x to 3.0)) // y = x + x = 6 @@ -59,8 +59,8 @@ class SimpleAutoDiffTest { fun testPlus() { // two variables val z = RealField.simpleAutoDiff(x to 2.0, y to 3.0) { - val x = bind(x) - val y = bind(y) + val x = bindSymbol(x) + val y = bindSymbol(y) x + y } assertEquals(5.0, z.value) // z = x + y = 5 @@ -72,8 +72,8 @@ class SimpleAutoDiffTest { fun testMinus() { // two variables val z = RealField.simpleAutoDiff(x to 7.0, y to 3.0) { - val x = bind(x) - val y = bind(y) + val x = bindSymbol(x) + val y = bindSymbol(y) x - y } diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/linear/MatrixTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt similarity index 90% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/linear/MatrixTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt index d7755dcb5..75967f024 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/linear/MatrixTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt @@ -1,9 +1,8 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.operations.invoke -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.NDStructure -import kscience.kmath.structures.as2D +import space.kscience.kmath.nd.NDStructure +import space.kscience.kmath.nd.as2D +import space.kscience.kmath.operations.invoke import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/linear/RealLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/RealLUSolverTest.kt similarity index 81% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/linear/RealLUSolverTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/RealLUSolverTest.kt index 28dfe46ec..f1289801a 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/linear/RealLUSolverTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/RealLUSolverTest.kt @@ -1,6 +1,5 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.structures.Matrix import kotlin.test.Test import kotlin.test.assertEquals @@ -9,7 +8,7 @@ class RealLUSolverTest { @Test fun testInvertOne() { val matrix = MatrixContext.real.one(2, 2) - val inverted = MatrixContext.real.inverseWithLUP(matrix) + val inverted = MatrixContext.real.inverseWithLup(matrix) assertEquals(matrix, inverted) } @@ -37,7 +36,7 @@ class RealLUSolverTest { 1.0, 3.0 ) - val inverted = MatrixContext.real.inverseWithLUP(matrix) + val inverted = MatrixContext.real.inverseWithLup(matrix) val expected = Matrix.square( 0.375, -0.125, diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/linear/VectorSpaceTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/VectorSpaceTest.kt similarity index 100% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/linear/VectorSpaceTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/VectorSpaceTest.kt diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/misc/CumulativeKtTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/CumulativeKtTest.kt similarity index 89% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/misc/CumulativeKtTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/CumulativeKtTest.kt index 1e6d2fd5d..dfdd3e18e 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/misc/CumulativeKtTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/CumulativeKtTest.kt @@ -1,4 +1,4 @@ -package kscience.kmath.misc +package space.kscience.kmath.misc import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntAlgebraTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt similarity index 94% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntAlgebraTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt index 78611e5d2..93237c7eb 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntAlgebraTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt @@ -1,6 +1,6 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations -import kscience.kmath.operations.internal.RingVerifier +import space.kscience.kmath.testutils.RingVerifier import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntConstructorTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConstructorTest.kt similarity index 93% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntConstructorTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConstructorTest.kt index ba2582bbf..59fd7e383 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntConstructorTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConstructorTest.kt @@ -1,4 +1,4 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntConversionsTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConversionsTest.kt similarity index 96% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntConversionsTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConversionsTest.kt index 0b433c436..ce599e1d1 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntConversionsTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConversionsTest.kt @@ -1,4 +1,4 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntOperationsTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntOperationsTest.kt similarity index 99% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntOperationsTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntOperationsTest.kt index a3ed85c7b..26e0c1d98 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/BigIntOperationsTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntOperationsTest.kt @@ -1,4 +1,4 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/RealFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/RealFieldTest.kt similarity index 76% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/RealFieldTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/RealFieldTest.kt index 5705733cf..bba612d12 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/RealFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/RealFieldTest.kt @@ -1,6 +1,6 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations -import kscience.kmath.operations.internal.FieldVerifier +import space.kscience.kmath.testutils.FieldVerifier import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt new file mode 100644 index 000000000..3c84d7b4b --- /dev/null +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt @@ -0,0 +1,22 @@ +package space.kscience.kmath.structures + +import space.kscience.kmath.nd.NDAlgebra +import space.kscience.kmath.nd.get +import space.kscience.kmath.nd.real +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.testutils.FieldVerifier +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class NDFieldTest { + @Test + fun verify() { + (NDAlgebra.real(12, 32)) { FieldVerifier(this, one + 3, one - 23, one * 12, 6.66) } + } + + @Test + fun testStrides() { + val ndArray = NDAlgebra.real(10, 10).produce { (it[0] + it[1]).toDouble() } + assertEquals(ndArray[5, 5], 10.0) + } +} diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt new file mode 100644 index 000000000..23b0e7348 --- /dev/null +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt @@ -0,0 +1,80 @@ +package space.kscience.kmath.structures + +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.Norm +import space.kscience.kmath.operations.invoke +import kotlin.math.abs +import kotlin.math.pow +import kotlin.test.Test +import kotlin.test.assertEquals + +@Suppress("UNUSED_VARIABLE") +class NumberNDFieldTest { + val algebra = NDAlgebra.real(3,3) + val array1 = algebra.produce { (i, j) -> (i + j).toDouble() } + val array2 = algebra.produce { (i, j) -> (i - j).toDouble() } + + @Test + fun testSum() { + algebra { + val sum = array1 + array2 + assertEquals(4.0, sum[2, 2]) + } + } + + @Test + fun testProduct() { + algebra { + val product = array1 * array2 + assertEquals(0.0, product[2, 2]) + } + } + + @Test + fun testGeneration() { + + val array = Structure2D.real(3, 3) { i, j -> (i * 10 + j).toDouble() } + + for (i in 0..2) { + for (j in 0..2) { + val expected = (i * 10 + j).toDouble() + assertEquals(expected, array[i, j], "Error at index [$i, $j]") + } + } + } + + @Test + fun testExternalFunction() { + algebra { + val function: (Double) -> Double = { x -> x.pow(2) + 2 * x + 1 } + val result = function(array1) + 1.0 + assertEquals(10.0, result[1, 1]) + } + } + + @Test + fun testLibraryFunction() { + algebra { + val abs: (Double) -> Double = ::abs + val result = abs(array2) + assertEquals(2.0, result[0, 2]) + } + } + + @Test + fun combineTest() { + val division = array1.combine(array2, Double::div) + } + + object L2Norm : Norm, Double> { + override fun norm(arg: NDStructure): Double = + kotlin.math.sqrt(arg.elements().sumByDouble { it.second.toDouble() }) + } + + @Test + fun testInternalContext() { + algebra { + (NDAlgebra.real(*array1.shape)) { with(L2Norm) { 1 + norm(array1) + exp(array2) } } + } + } +} diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/AlgebraicVerifier.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/AlgebraicVerifier.kt similarity index 56% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/AlgebraicVerifier.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/AlgebraicVerifier.kt index 7334c13a3..7474aae8f 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/AlgebraicVerifier.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/AlgebraicVerifier.kt @@ -1,6 +1,6 @@ -package kscience.kmath.operations.internal +package space.kscience.kmath.testutils -import kscience.kmath.operations.Algebra +import space.kscience.kmath.operations.Algebra internal interface AlgebraicVerifier where A : Algebra { val algebra: A diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/FieldVerifier.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/FieldVerifier.kt similarity index 89% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/FieldVerifier.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/FieldVerifier.kt index 89f31c75b..2aef6b27f 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/FieldVerifier.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/FieldVerifier.kt @@ -1,7 +1,7 @@ -package kscience.kmath.operations.internal +package space.kscience.kmath.testutils -import kscience.kmath.operations.Field -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.invoke import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/RingVerifier.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/RingVerifier.kt similarity index 92% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/RingVerifier.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/RingVerifier.kt index 359ba1701..dd8841806 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/RingVerifier.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/RingVerifier.kt @@ -1,7 +1,7 @@ -package kscience.kmath.operations.internal +package space.kscience.kmath.testutils -import kscience.kmath.operations.Ring -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.invoke import kotlin.test.assertEquals internal open class RingVerifier(override val algebra: Ring, a: T, b: T, c: T, x: Number) : diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/SpaceVerifier.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/SpaceVerifier.kt similarity index 91% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/SpaceVerifier.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/SpaceVerifier.kt index 045abb71f..f7a25b593 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/internal/SpaceVerifier.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/SpaceVerifier.kt @@ -1,7 +1,7 @@ -package kscience.kmath.operations.internal +package space.kscience.kmath.testutils -import kscience.kmath.operations.Space -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.Space +import space.kscience.kmath.operations.invoke import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/kmath-core/src/jvmMain/kotlin/kscience/kmath/operations/BigNumbers.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt similarity index 98% rename from kmath-core/src/jvmMain/kotlin/kscience/kmath/operations/BigNumbers.kt rename to kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt index 9bd6a9fc4..8f8b31ed9 100644 --- a/kmath-core/src/jvmMain/kotlin/kscience/kmath/operations/BigNumbers.kt +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt @@ -1,4 +1,4 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations import java.math.BigDecimal import java.math.BigInteger diff --git a/kmath-coroutines/build.gradle.kts b/kmath-coroutines/build.gradle.kts index e108c2755..4a9ca5244 100644 --- a/kmath-coroutines/build.gradle.kts +++ b/kmath-coroutines/build.gradle.kts @@ -1,4 +1,4 @@ -plugins { id("ru.mipt.npm.mpp") } +plugins { id("ru.mipt.npm.gradle.mpp") } kotlin.sourceSets { all { @@ -12,7 +12,12 @@ kotlin.sourceSets { commonMain { dependencies { api(project(":kmath-core")) + api(project(":kmath-complex")) api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${ru.mipt.npm.gradle.KScienceVersions.coroutinesVersion}") } } } + +readme{ + maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL +} \ No newline at end of file diff --git a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingIntChain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingIntChain.kt similarity index 88% rename from kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingIntChain.kt rename to kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingIntChain.kt index 6088267a2..11da7e503 100644 --- a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingIntChain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingIntChain.kt @@ -1,4 +1,4 @@ -package kscience.kmath.chains +package space.kscience.kmath.chains /** * Performance optimized chain for integer values diff --git a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingRealChain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingRealChain.kt similarity index 89% rename from kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingRealChain.kt rename to kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingRealChain.kt index 718b3a18b..ac6b117dc 100644 --- a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/BlockingRealChain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingRealChain.kt @@ -1,4 +1,4 @@ -package kscience.kmath.chains +package space.kscience.kmath.chains /** * Performance optimized chain for real values diff --git a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/Chain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt similarity index 99% rename from kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/Chain.kt rename to kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt index 7ff7b7aae..5375113fe 100644 --- a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/Chain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package kscience.kmath.chains +package space.kscience.kmath.chains import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.FlowCollector diff --git a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/flowExtra.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/flowExtra.kt similarity index 79% rename from kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/flowExtra.kt rename to kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/flowExtra.kt index 6b14057fe..489cca8c1 100644 --- a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/chains/flowExtra.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/flowExtra.kt @@ -1,13 +1,13 @@ -package kscience.kmath.chains +package space.kscience.kmath.chains import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.runningReduce import kotlinx.coroutines.flow.scan -import kscience.kmath.operations.Space -import kscience.kmath.operations.SpaceOperations -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.Space +import space.kscience.kmath.operations.SpaceOperations +import space.kscience.kmath.operations.invoke @ExperimentalCoroutinesApi public fun Flow.cumulativeSum(space: SpaceOperations): Flow = diff --git a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/coroutines/coroutinesExtra.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/coroutines/coroutinesExtra.kt similarity index 98% rename from kmath-coroutines/src/commonMain/kotlin/kscience/kmath/coroutines/coroutinesExtra.kt rename to kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/coroutines/coroutinesExtra.kt index 7dcdc0d62..6578af0e9 100644 --- a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/coroutines/coroutinesExtra.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/coroutines/coroutinesExtra.kt @@ -1,4 +1,4 @@ -package kscience.kmath.coroutines +package space.kscience.kmath.coroutines import kotlinx.coroutines.* import kotlinx.coroutines.channels.produce diff --git a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/streaming/BufferFlow.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt similarity index 85% rename from kmath-coroutines/src/commonMain/kotlin/kscience/kmath/streaming/BufferFlow.kt rename to kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt index 328a7807c..4df22c2ad 100644 --- a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/streaming/BufferFlow.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt @@ -1,12 +1,12 @@ -package kscience.kmath.streaming +package space.kscience.kmath.streaming import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.* -import kscience.kmath.chains.BlockingRealChain -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.BufferFactory -import kscience.kmath.structures.RealBuffer -import kscience.kmath.structures.asBuffer +import space.kscience.kmath.chains.BlockingRealChain +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.asBuffer /** * Create a [Flow] from buffer @@ -17,7 +17,7 @@ public fun Buffer.asFlow(): Flow = iterator().asFlow() * Flat map a [Flow] of [Buffer] into continuous [Flow] of elements */ @FlowPreview -public fun Flow>.spread(): Flow = flatMapConcat { it.asFlow() } +public fun Flow>.spread(): Flow = flatMapConcat { it.asFlow() } /** * Collect incoming flow into fixed size chunks diff --git a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/streaming/RingBuffer.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt similarity index 92% rename from kmath-coroutines/src/commonMain/kotlin/kscience/kmath/streaming/RingBuffer.kt rename to kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt index 385bbaae2..efed41112 100644 --- a/kmath-coroutines/src/commonMain/kotlin/kscience/kmath/streaming/RingBuffer.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt @@ -1,10 +1,10 @@ -package kscience.kmath.streaming +package space.kscience.kmath.streaming import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.MutableBuffer -import kscience.kmath.structures.VirtualBuffer +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.VirtualBuffer /** * Thread-safe ring buffer diff --git a/kmath-coroutines/src/jvmMain/kotlin/kscience/kmath/chains/ChainExt.kt b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/chains/ChainExt.kt similarity index 92% rename from kmath-coroutines/src/jvmMain/kotlin/kscience/kmath/chains/ChainExt.kt rename to kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/chains/ChainExt.kt index 3dfeddbac..c62785060 100644 --- a/kmath-coroutines/src/jvmMain/kotlin/kscience/kmath/chains/ChainExt.kt +++ b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/chains/ChainExt.kt @@ -1,4 +1,4 @@ -package kscience.kmath.chains +package space.kscience.kmath.chains import kotlinx.coroutines.runBlocking diff --git a/kmath-coroutines/src/jvmMain/kotlin/kscience/kmath/structures/LazyNDStructure.kt b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyNDStructure.kt similarity index 92% rename from kmath-coroutines/src/jvmMain/kotlin/kscience/kmath/structures/LazyNDStructure.kt rename to kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyNDStructure.kt index 7aa746797..51a79f44a 100644 --- a/kmath-coroutines/src/jvmMain/kotlin/kscience/kmath/structures/LazyNDStructure.kt +++ b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyNDStructure.kt @@ -1,7 +1,9 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures import kotlinx.coroutines.* -import kscience.kmath.coroutines.Math +import space.kscience.kmath.coroutines.Math +import space.kscience.kmath.nd.DefaultStrides +import space.kscience.kmath.nd.NDStructure public class LazyNDStructure( public val scope: CoroutineScope, diff --git a/kmath-coroutines/src/jvmTest/kotlin/kscience/kmath/streaming/BufferFlowTest.kt b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/BufferFlowTest.kt similarity index 87% rename from kmath-coroutines/src/jvmTest/kotlin/kscience/kmath/streaming/BufferFlowTest.kt rename to kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/BufferFlowTest.kt index a9bf38c12..589456843 100644 --- a/kmath-coroutines/src/jvmTest/kotlin/kscience/kmath/streaming/BufferFlowTest.kt +++ b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/BufferFlowTest.kt @@ -1,12 +1,12 @@ -package kscience.kmath.streaming +package space.kscience.kmath.streaming import kotlinx.coroutines.* import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.flow.collect -import kscience.kmath.coroutines.async -import kscience.kmath.coroutines.collect -import kscience.kmath.coroutines.mapParallel import org.junit.jupiter.api.Timeout +import space.kscience.kmath.coroutines.async +import space.kscience.kmath.coroutines.collect +import space.kscience.kmath.coroutines.mapParallel import java.util.concurrent.Executors import kotlin.test.Test diff --git a/kmath-coroutines/src/jvmTest/kotlin/kscience/kmath/streaming/RingBufferTest.kt b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt similarity index 83% rename from kmath-coroutines/src/jvmTest/kotlin/kscience/kmath/streaming/RingBufferTest.kt rename to kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt index 5bb0c1d40..4a7109310 100644 --- a/kmath-coroutines/src/jvmTest/kotlin/kscience/kmath/streaming/RingBufferTest.kt +++ b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt @@ -1,8 +1,8 @@ -package kscience.kmath.streaming +package space.kscience.kmath.streaming import kotlinx.coroutines.flow.* import kotlinx.coroutines.runBlocking -import kscience.kmath.structures.asSequence +import space.kscience.kmath.structures.asSequence import kotlin.test.Test import kotlin.test.assertEquals @@ -28,7 +28,7 @@ internal class RingBufferTest { val windowed = flow.windowed(10) runBlocking { - val first = windowed.take(1).single() + @Suppress("UNUSED_VARIABLE") val first = windowed.take(1).single() val res = windowed.take(15).map { it.asSequence().average() }.toList() assertEquals(0.0, res[0]) assertEquals(4.5, res[9]) diff --git a/kmath-dimensions/build.gradle.kts b/kmath-dimensions/build.gradle.kts index 9bf89fc43..3355eda42 100644 --- a/kmath-dimensions/build.gradle.kts +++ b/kmath-dimensions/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("ru.mipt.npm.mpp") - id("ru.mipt.npm.native") + id("ru.mipt.npm.gradle.mpp") + id("ru.mipt.npm.gradle.native") } description = "A proof of concept module for adding type-safe dimensions to structures" diff --git a/kmath-dimensions/src/commonMain/kotlin/kscience/kmath/dimensions/Dimensions.kt b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimensions.kt similarity index 96% rename from kmath-dimensions/src/commonMain/kotlin/kscience/kmath/dimensions/Dimensions.kt rename to kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimensions.kt index 9450f9174..9f0d868f2 100644 --- a/kmath-dimensions/src/commonMain/kotlin/kscience/kmath/dimensions/Dimensions.kt +++ b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimensions.kt @@ -1,4 +1,4 @@ -package kscience.kmath.dimensions +package space.kscience.kmath.dimensions import kotlin.reflect.KClass diff --git a/kmath-dimensions/src/commonMain/kotlin/kscience/kmath/dimensions/Wrappers.kt b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt similarity index 96% rename from kmath-dimensions/src/commonMain/kotlin/kscience/kmath/dimensions/Wrappers.kt rename to kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt index 0244eae7f..237824a39 100644 --- a/kmath-dimensions/src/commonMain/kotlin/kscience/kmath/dimensions/Wrappers.kt +++ b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt @@ -1,9 +1,8 @@ -package kscience.kmath.dimensions +package space.kscience.kmath.dimensions -import kscience.kmath.linear.* -import kscience.kmath.operations.invoke -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.Structure2D +import space.kscience.kmath.linear.* +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.operations.invoke /** * A matrix with compile-time controlled dimension diff --git a/kmath-dimensions/src/commonTest/kotlin/kscience/dimensions/DMatrixContextTest.kt b/kmath-dimensions/src/commonTest/kotlin/kscience/dimensions/DMatrixContextTest.kt index b9193d4dd..e2a9628ac 100644 --- a/kmath-dimensions/src/commonTest/kotlin/kscience/dimensions/DMatrixContextTest.kt +++ b/kmath-dimensions/src/commonTest/kotlin/kscience/dimensions/DMatrixContextTest.kt @@ -1,9 +1,9 @@ package kscience.dimensions -import kscience.kmath.dimensions.D2 -import kscience.kmath.dimensions.D3 -import kscience.kmath.dimensions.DMatrixContext -import kscience.kmath.dimensions.one +import space.kscience.kmath.dimensions.D2 +import space.kscience.kmath.dimensions.D3 +import space.kscience.kmath.dimensions.DMatrixContext +import space.kscience.kmath.dimensions.one import kotlin.test.Test @Suppress("UNUSED_VARIABLE") diff --git a/kmath-dimensions/src/jsMain/kotlin/kscience/kmath/dimensions/dimJs.kt b/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/dimJs.kt similarity index 93% rename from kmath-dimensions/src/jsMain/kotlin/kscience/kmath/dimensions/dimJs.kt rename to kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/dimJs.kt index 4230da156..40c1148cb 100644 --- a/kmath-dimensions/src/jsMain/kotlin/kscience/kmath/dimensions/dimJs.kt +++ b/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/dimJs.kt @@ -1,4 +1,4 @@ -package kscience.kmath.dimensions +package space.kscience.kmath.dimensions import kotlin.reflect.KClass diff --git a/kmath-dimensions/src/jvmMain/kotlin/kscience/kmath/dimensions/dimJvm.kt b/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/dimJvm.kt similarity index 90% rename from kmath-dimensions/src/jvmMain/kotlin/kscience/kmath/dimensions/dimJvm.kt rename to kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/dimJvm.kt index dec3979ef..87df1c097 100644 --- a/kmath-dimensions/src/jvmMain/kotlin/kscience/kmath/dimensions/dimJvm.kt +++ b/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/dimJvm.kt @@ -1,4 +1,4 @@ -package kscience.kmath.dimensions +package space.kscience.kmath.dimensions import kotlin.reflect.KClass diff --git a/kmath-dimensions/src/nativeMain/kotlin/kscience/kmath/dimensions/dimNative.kt b/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/dimNative.kt similarity index 94% rename from kmath-dimensions/src/nativeMain/kotlin/kscience/kmath/dimensions/dimNative.kt rename to kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/dimNative.kt index aeaeaf759..3b9728328 100644 --- a/kmath-dimensions/src/nativeMain/kotlin/kscience/kmath/dimensions/dimNative.kt +++ b/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/dimNative.kt @@ -1,4 +1,4 @@ -package kscience.kmath.dimensions +package space.kscience.kmath.dimensions import kotlin.native.concurrent.ThreadLocal import kotlin.reflect.KClass diff --git a/kmath-ejml/build.gradle.kts b/kmath-ejml/build.gradle.kts index fa4aa3e39..07f95b13f 100644 --- a/kmath-ejml/build.gradle.kts +++ b/kmath-ejml/build.gradle.kts @@ -1,8 +1,12 @@ plugins { - id("ru.mipt.npm.jvm") + id("ru.mipt.npm.gradle.jvm") } dependencies { implementation("org.ejml:ejml-simple:0.39") implementation(project(":kmath-core")) } + +readme{ + maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE +} \ No newline at end of file diff --git a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrix.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt similarity index 84% rename from kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrix.kt rename to kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt index 82a5399fd..d23e613e4 100644 --- a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrix.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt @@ -1,12 +1,11 @@ -package kscience.kmath.ejml +package space.kscience.kmath.ejml -import kscience.kmath.linear.* -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.NDStructure -import kscience.kmath.structures.RealBuffer import org.ejml.dense.row.factory.DecompositionFactory_DDRM import org.ejml.simple.SimpleMatrix +import space.kscience.kmath.linear.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.NDStructure +import space.kscience.kmath.structures.RealBuffer import kotlin.reflect.KClass import kotlin.reflect.cast @@ -16,21 +15,20 @@ import kotlin.reflect.cast * @property origin the underlying [SimpleMatrix]. * @author Iaroslav Postovalov */ -public class EjmlMatrix( - public val origin: SimpleMatrix, -) : Matrix { +public class EjmlMatrix(public val origin: SimpleMatrix) : Matrix { public override val rowNum: Int get() = origin.numRows() - public override val colNum: Int get() = origin.numCols() @UnstableKMathAPI - override fun getFeature(type: KClass): T? = when (type) { + public override fun getFeature(type: KClass): T? = when (type) { InverseMatrixFeature::class -> object : InverseMatrixFeature { override val inverse: Matrix by lazy { EjmlMatrix(origin.invert()) } } + DeterminantFeature::class -> object : DeterminantFeature { override val determinant: Double by lazy(origin::determinant) } + SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature { private val svd by lazy { DecompositionFactory_DDRM.svd(origin.numRows(), origin.numCols(), true, true, false) @@ -42,14 +40,19 @@ public class EjmlMatrix( override val v: Matrix by lazy { EjmlMatrix(SimpleMatrix(svd.getV(null, false))) } override val singularValues: Point by lazy { RealBuffer(svd.singularValues) } } + QRDecompositionFeature::class -> object : QRDecompositionFeature { private val qr by lazy { DecompositionFactory_DDRM.qr().apply { decompose(origin.ddrm.copy()) } } - override val q: Matrix by lazy { EjmlMatrix(SimpleMatrix(qr.getQ(null, false))) } - override val r: Matrix by lazy { EjmlMatrix(SimpleMatrix(qr.getR(null, false))) } + override val q: Matrix by lazy { + EjmlMatrix(SimpleMatrix(qr.getQ(null, false))) + OrthogonalFeature + } + + override val r: Matrix by lazy { EjmlMatrix(SimpleMatrix(qr.getR(null, false))) + UFeature } } + CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { override val l: Matrix by lazy { val cholesky = @@ -58,6 +61,7 @@ public class EjmlMatrix( EjmlMatrix(SimpleMatrix(cholesky.getT(null))) + LFeature } } + LupDecompositionFeature::class -> object : LupDecompositionFeature { private val lup by lazy { DecompositionFactory_DDRM.lu(origin.numRows(), origin.numCols()).apply { decompose(origin.ddrm.copy()) } @@ -73,8 +77,9 @@ public class EjmlMatrix( override val p: Matrix by lazy { EjmlMatrix(SimpleMatrix(lup.getRowPivot(null))) } } + else -> null - }?.let { type.cast(it) } + }?.let(type::cast) public override operator fun get(i: Int, j: Int): Double = origin[i, j] diff --git a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrixContext.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrixContext.kt similarity index 85% rename from kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrixContext.kt rename to kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrixContext.kt index 8184d0110..d67f80409 100644 --- a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrixContext.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrixContext.kt @@ -1,13 +1,9 @@ -package kscience.kmath.ejml +package space.kscience.kmath.ejml -import kscience.kmath.linear.InverseMatrixFeature -import kscience.kmath.linear.MatrixContext -import kscience.kmath.linear.Point -import kscience.kmath.linear.origin -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.getFeature import org.ejml.simple.SimpleMatrix +import space.kscience.kmath.linear.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.getFeature /** * Represents context of basic operations operating with [EjmlMatrix]. @@ -35,8 +31,8 @@ public object EjmlMatrixContext : MatrixContext { override fun produce(rows: Int, columns: Int, initializer: (i: Int, j: Int) -> Double): EjmlMatrix = EjmlMatrix(SimpleMatrix(rows, columns).also { - (0 until it.numRows()).forEach { row -> - (0 until it.numCols()).forEach { col -> it[row, col] = initializer(row, col) } + (0 until rows).forEach { row -> + (0 until columns).forEach { col -> it[row, col] = initializer(row, col) } } }) diff --git a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlVector.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt similarity index 90% rename from kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlVector.kt rename to kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt index f7cd1b66d..efa1f6128 100644 --- a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlVector.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt @@ -1,8 +1,8 @@ -package kscience.kmath.ejml +package space.kscience.kmath.ejml import org.ejml.simple.SimpleMatrix -import kscience.kmath.linear.Point -import kscience.kmath.structures.Buffer +import space.kscience.kmath.linear.Point +import space.kscience.kmath.structures.Buffer /** * Represents point over EJML [SimpleMatrix]. diff --git a/kmath-ejml/src/test/kotlin/kscience/kmath/ejml/EjmlMatrixTest.kt b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt similarity index 86% rename from kmath-ejml/src/test/kotlin/kscience/kmath/ejml/EjmlMatrixTest.kt rename to kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt index 455b52d9d..7f31d2f93 100644 --- a/kmath-ejml/src/test/kotlin/kscience/kmath/ejml/EjmlMatrixTest.kt +++ b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt @@ -1,13 +1,13 @@ -package kscience.kmath.ejml +package space.kscience.kmath.ejml -import kscience.kmath.linear.DeterminantFeature -import kscience.kmath.linear.LupDecompositionFeature -import kscience.kmath.linear.MatrixFeature -import kscience.kmath.linear.plus -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.structures.getFeature import org.ejml.dense.row.factory.DecompositionFactory_DDRM import org.ejml.simple.SimpleMatrix +import space.kscience.kmath.linear.DeterminantFeature +import space.kscience.kmath.linear.LupDecompositionFeature +import space.kscience.kmath.linear.MatrixFeature +import space.kscience.kmath.linear.plus +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.getFeature import kotlin.random.Random import kotlin.random.asJavaRandom import kotlin.test.* diff --git a/kmath-ejml/src/test/kotlin/kscience/kmath/ejml/EjmlVectorTest.kt b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt similarity index 96% rename from kmath-ejml/src/test/kotlin/kscience/kmath/ejml/EjmlVectorTest.kt rename to kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt index e27f977d2..1924696fb 100644 --- a/kmath-ejml/src/test/kotlin/kscience/kmath/ejml/EjmlVectorTest.kt +++ b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt @@ -1,4 +1,4 @@ -package kscience.kmath.ejml +package space.kscience.kmath.ejml import org.ejml.simple.SimpleMatrix import kotlin.random.Random diff --git a/kmath-for-real/README.md b/kmath-for-real/README.md index 70308f1d5..94b9eb59a 100644 --- a/kmath-for-real/README.md +++ b/kmath-for-real/README.md @@ -7,7 +7,7 @@ > #### Artifact: > -> This module artifact: `kscience.kmath:kmath-for-real:0.2.0-dev-5`. +> This module artifact: `space.kscience:kmath-for-real:0.2.0`. > > Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-for-real/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-for-real/_latestVersion) > @@ -17,28 +17,31 @@ > > ```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://repo.kotlin.link' } > maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> +> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } // include for builds based on kotlin-eap +>// Uncomment if repo.kotlin.link is unavailable +>// maven { url 'https://dl.bintray.com/mipt-npm/kscience' } +>// maven { url 'https://dl.bintray.com/mipt-npm/dev' } > } > > dependencies { -> implementation 'kscience.kmath:kmath-for-real:0.2.0-dev-5' +> implementation 'space.kscience:kmath-for-real:0.2.0' > } > ``` > **Gradle Kotlin DSL:** > > ```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") +> maven("https://repo.kotlin.link") +> maven("https://dl.bintray.com/kotlin/kotlin-eap") // include for builds based on kotlin-eap +> maven("https://dl.bintray.com/hotkeytlt/maven") // required for a +>// Uncomment if repo.kotlin.link is unavailable +>// maven("https://dl.bintray.com/mipt-npm/kscience") +>// maven("https://dl.bintray.com/mipt-npm/dev") > } > > dependencies { -> implementation("kscience.kmath:kmath-for-real:0.2.0-dev-5") +> implementation("space.kscience:kmath-for-real:0.2.0") > } > ``` diff --git a/kmath-for-real/build.gradle.kts b/kmath-for-real/build.gradle.kts index f26f98c2c..d095cac04 100644 --- a/kmath-for-real/build.gradle.kts +++ b/kmath-for-real/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("ru.mipt.npm.mpp") + id("ru.mipt.npm.gradle.mpp") } kotlin.sourceSets.commonMain { diff --git a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealMatrix.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt similarity index 90% rename from kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealMatrix.kt rename to kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt index 274030aff..30d002498 100644 --- a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealMatrix.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt @@ -1,14 +1,10 @@ -package kscience.kmath.real +package space.kscience.kmath.real -import kscience.kmath.linear.MatrixContext -import kscience.kmath.linear.VirtualMatrix -import kscience.kmath.linear.inverseWithLUP -import kscience.kmath.linear.real -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.RealBuffer -import kscience.kmath.structures.asIterable +import space.kscience.kmath.linear.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.asIterable import kotlin.math.pow /* @@ -144,7 +140,7 @@ public fun RealMatrix.min(): Double? = elements().map { (_, value) -> value }.mi public fun RealMatrix.max(): Double? = elements().map { (_, value) -> value }.maxOrNull() public fun RealMatrix.average(): Double = elements().map { (_, value) -> value }.average() -public inline fun RealMatrix.map(transform: (Double) -> Double): RealMatrix = +public inline fun RealMatrix.map(crossinline transform: (Double) -> Double): RealMatrix = MatrixContext.real.produce(rowNum, colNum) { i, j -> transform(get(i, j)) } @@ -152,7 +148,7 @@ public inline fun RealMatrix.map(transform: (Double) -> Double): RealMatrix = /** * Inverse a square real matrix using LUP decomposition */ -public fun RealMatrix.inverseWithLUP(): RealMatrix = MatrixContext.real.inverseWithLUP(this) +public fun RealMatrix.inverseWithLup(): RealMatrix = MatrixContext.real.inverseWithLup(this) //extended operations diff --git a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealVector.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt similarity index 75% rename from kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealVector.kt rename to kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt index 596692782..ca892fa7e 100644 --- a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealVector.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt @@ -1,10 +1,10 @@ -package kscience.kmath.real +package space.kscience.kmath.real -import kscience.kmath.linear.Point -import kscience.kmath.operations.Norm -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.asBuffer -import kscience.kmath.structures.asIterable +import space.kscience.kmath.linear.Point +import space.kscience.kmath.operations.Norm +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asBuffer +import space.kscience.kmath.structures.asIterable import kotlin.math.pow import kotlin.math.sqrt @@ -29,8 +29,10 @@ public inline fun RealVector.map(transform: (Double) -> Double): RealVector = public inline fun RealVector.mapIndexed(transform: (index: Int, value: Double) -> Double): RealVector = Buffer.real(size) { transform(it, get(it)) } -public operator fun RealVector.plus(other: RealVector): RealVector = - mapIndexed { index, value -> value + other[index] } +public operator fun RealVector.plus(other: RealVector): RealVector { + require(size == other.size){"Vector size $size expected but ${other.size} found"} + return mapIndexed { index, value -> value + other[index] } +} public operator fun RealVector.plus(number: Number): RealVector = map { it + number.toDouble() } @@ -38,22 +40,28 @@ public operator fun Number.plus(vector: RealVector): RealVector = vector + this public operator fun RealVector.unaryMinus(): Buffer = map { -it } -public operator fun RealVector.minus(other: RealVector): RealVector = - mapIndexed { index, value -> value - other[index] } +public operator fun RealVector.minus(other: RealVector): RealVector { + require(size == other.size){"Vector size $size expected but ${other.size} found"} + return mapIndexed { index, value -> value - other[index] } +} public operator fun RealVector.minus(number: Number): RealVector = map { it - number.toDouble() } public operator fun Number.minus(vector: RealVector): RealVector = vector.map { toDouble() - it } -public operator fun RealVector.times(other: RealVector): RealVector = - mapIndexed { index, value -> value * other[index] } +public operator fun RealVector.times(other: RealVector): RealVector { + require(size == other.size){"Vector size $size expected but ${other.size} found"} + return mapIndexed { index, value -> value * other[index] } +} public operator fun RealVector.times(number: Number): RealVector = map { it * number.toDouble() } public operator fun Number.times(vector: RealVector): RealVector = vector * this -public operator fun RealVector.div(other: RealVector): RealVector = - mapIndexed { index, value -> value / other[index] } +public operator fun RealVector.div(other: RealVector): RealVector { + require(size == other.size){"Vector size $size expected but ${other.size} found"} + return mapIndexed { index, value -> value / other[index] } +} public operator fun RealVector.div(number: Number): RealVector = map { it / number.toDouble() } diff --git a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/dot.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt similarity index 78% rename from kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/dot.kt rename to kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt index 9beffe6bb..cbfb364c1 100644 --- a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/dot.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt @@ -1,8 +1,8 @@ -package kscience.kmath.real +package space.kscience.kmath.real -import kscience.kmath.linear.BufferMatrix -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.RealBuffer +import space.kscience.kmath.linear.BufferMatrix +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.RealBuffer /** @@ -13,7 +13,7 @@ public infix fun BufferMatrix.dot(other: BufferMatrix): BufferMa val resultArray = DoubleArray(this.rowNum * other.colNum) //convert to array to insure there is no memory indirection - fun Buffer.unsafeArray() = if (this is RealBuffer) + fun Buffer.unsafeArray() = if (this is RealBuffer) this.array else DoubleArray(size) { get(it) } diff --git a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/grids.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt similarity index 94% rename from kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/grids.kt rename to kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt index 69a149fb8..8b4f1cd96 100644 --- a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/grids.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt @@ -1,6 +1,6 @@ -package kscience.kmath.real +package space.kscience.kmath.real -import kscience.kmath.structures.asBuffer +import space.kscience.kmath.structures.asBuffer import kotlin.math.abs /** diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/realND.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/realND.kt new file mode 100644 index 000000000..492e40922 --- /dev/null +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/realND.kt @@ -0,0 +1,31 @@ +package space.kscience.kmath.real + +import space.kscience.kmath.nd.NDBuffer +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.structures.RealBuffer + +/** + * Map one [NDBuffer] using function without indices. + */ +public inline fun NDBuffer.mapInline(crossinline transform: RealField.(Double) -> Double): NDBuffer { + val array = DoubleArray(strides.linearSize) { offset -> RealField.transform(buffer[offset]) } + return NDBuffer(strides, RealBuffer(array)) +} + +/** + * Element by element application of any operation on elements to the whole array. Just like in numpy. + */ +public operator fun Function1.invoke(ndElement: NDBuffer): NDBuffer = + ndElement.mapInline { this@invoke(it) } + +/* plus and minus */ + +/** + * Summation operation for [NDBuffer] and single element + */ +public operator fun NDBuffer.plus(arg: Double): NDBuffer = mapInline { it + arg } + +/** + * Subtraction operation between [NDBuffer] and single element + */ +public operator fun NDBuffer.minus(arg: Double): NDBuffer = mapInline { it - arg } \ No newline at end of file diff --git a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/GridTest.kt b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/GridTest.kt index 5f19e94b7..c538a2d99 100644 --- a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/GridTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/GridTest.kt @@ -1,6 +1,6 @@ package kaceince.kmath.real -import kscience.kmath.real.step +import space.kscience.kmath.real.step import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt index a89f99b3c..9e2778be9 100644 --- a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt @@ -1,9 +1,10 @@ package kaceince.kmath.real -import kscience.kmath.linear.build -import kscience.kmath.real.* -import kscience.kmath.structures.Matrix -import kscience.kmath.structures.contentEquals +import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.linear.build +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.real.* +import space.kscience.kmath.structures.contentEquals import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -91,6 +92,7 @@ internal class RealMatrixTest { assertEquals(matrix1.pow(3), matrix3) } + @OptIn(UnstableKMathAPI::class) @Test fun testTwoMatrixOperations() { val matrix1 = Matrix.build(2, 3)( diff --git a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealVectorTest.kt b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealVectorTest.kt index 6215ba5e8..463c68681 100644 --- a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealVectorTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealVectorTest.kt @@ -1,10 +1,12 @@ package kaceince.kmath.real -import kscience.kmath.linear.* -import kscience.kmath.operations.invoke -import kscience.kmath.real.RealVector -import kscience.kmath.real.plus -import kscience.kmath.structures.Buffer +import space.kscience.kmath.linear.MatrixContext +import space.kscience.kmath.linear.asMatrix +import space.kscience.kmath.linear.real +import space.kscience.kmath.linear.transpose +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.real.plus +import space.kscience.kmath.structures.Buffer import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-functions/README.md b/kmath-functions/README.md new file mode 100644 index 000000000..0eae4e3c0 --- /dev/null +++ b/kmath-functions/README.md @@ -0,0 +1,50 @@ +# Functions (`kmath-functions`) + +Functions and interpolations: + + - [piecewise](Piecewise functions.) : src/commonMain/kotlin/kscience/kmath/functions/Piecewise.kt + - [polynomials](Polynomial functions.) : src/commonMain/kotlin/kscience/kmath/functions/Polynomial.kt + - [linear interpolation](Linear XY interpolator.) : src/commonMain/kotlin/kscience/kmath/interpolation/LinearInterpolator.kt + - [spline interpolation](Cubic spline XY interpolator.) : src/commonMain/kotlin/kscience/kmath/interpolation/SplineInterpolator.kt + + +> #### Artifact: +> +> This module artifact: `space.kscience:kmath-functions:0.2.0`. +> +> Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-functions/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-functions/_latestVersion) +> +> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-functions/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-functions/_latestVersion) +> +> **Gradle:** +> +> ```gradle +> repositories { +> maven { url 'https://repo.kotlin.link' } +> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } +> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } // include for builds based on kotlin-eap +>// Uncomment if repo.kotlin.link is unavailable +>// maven { url 'https://dl.bintray.com/mipt-npm/kscience' } +>// maven { url 'https://dl.bintray.com/mipt-npm/dev' } +> } +> +> dependencies { +> implementation 'space.kscience:kmath-functions:0.2.0' +> } +> ``` +> **Gradle Kotlin DSL:** +> +> ```kotlin +> repositories { +> maven("https://repo.kotlin.link") +> maven("https://dl.bintray.com/kotlin/kotlin-eap") // include for builds based on kotlin-eap +> maven("https://dl.bintray.com/hotkeytlt/maven") // required for a +>// Uncomment if repo.kotlin.link is unavailable +>// maven("https://dl.bintray.com/mipt-npm/kscience") +>// maven("https://dl.bintray.com/mipt-npm/dev") +> } +> +> dependencies { +> implementation("space.kscience:kmath-functions:0.2.0") +> } +> ``` diff --git a/kmath-functions/build.gradle.kts b/kmath-functions/build.gradle.kts index 2a4539c10..fc52c4981 100644 --- a/kmath-functions/build.gradle.kts +++ b/kmath-functions/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("ru.mipt.npm.mpp") + id("ru.mipt.npm.gradle.mpp") } kotlin.sourceSets.commonMain { @@ -7,3 +7,14 @@ kotlin.sourceSets.commonMain { api(project(":kmath-core")) } } + +readme { + description = "Functions and interpolation" + maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE + propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) + + feature("piecewise", "src/commonMain/kotlin/kscience/kmath/functions/Piecewise.kt", "Piecewise functions.") + feature("polynomials", "src/commonMain/kotlin/kscience/kmath/functions/Polynomial.kt", "Polynomial functions.") + feature("linear interpolation", "src/commonMain/kotlin/kscience/kmath/interpolation/LinearInterpolator.kt", "Linear XY interpolator.") + feature("spline interpolation", "src/commonMain/kotlin/kscience/kmath/interpolation/SplineInterpolator.kt", "Cubic spline XY interpolator.") +} \ No newline at end of file diff --git a/kmath-functions/docs/README-TEMPLATE.md b/kmath-functions/docs/README-TEMPLATE.md new file mode 100644 index 000000000..8a34a7cc4 --- /dev/null +++ b/kmath-functions/docs/README-TEMPLATE.md @@ -0,0 +1,7 @@ +# Functions (`kmath-functions`) + +Functions and interpolations: + +${features} + +${artifact} diff --git a/kmath-functions/src/commonMain/kotlin/kscience/kmath/functions/Piecewise.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt similarity index 88% rename from kmath-functions/src/commonMain/kotlin/kscience/kmath/functions/Piecewise.kt rename to kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt index a8c020c05..d2470a4b4 100644 --- a/kmath-functions/src/commonMain/kotlin/kscience/kmath/functions/Piecewise.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt @@ -1,13 +1,12 @@ -package kscience.kmath.functions +package space.kscience.kmath.functions -import kscience.kmath.operations.Ring +import space.kscience.kmath.operations.Ring public fun interface Piecewise { public fun findPiece(arg: T): R? } -public fun interface PiecewisePolynomial : - Piecewise> +public fun interface PiecewisePolynomial : Piecewise> /** * Ordered list of pieces in piecewise function diff --git a/kmath-functions/src/commonMain/kotlin/kscience/kmath/functions/Polynomial.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt similarity index 92% rename from kmath-functions/src/commonMain/kotlin/kscience/kmath/functions/Polynomial.kt rename to kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt index 820076c4c..b1e47f34c 100644 --- a/kmath-functions/src/commonMain/kotlin/kscience/kmath/functions/Polynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt @@ -1,8 +1,8 @@ -package kscience.kmath.functions +package space.kscience.kmath.functions -import kscience.kmath.operations.Ring -import kscience.kmath.operations.Space -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.Space +import space.kscience.kmath.operations.invoke import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.math.max diff --git a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/Interpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt similarity index 82% rename from kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/Interpolator.kt rename to kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt index 0620b4aa8..dc5227f8b 100644 --- a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/Interpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt @@ -1,10 +1,10 @@ -package kscience.kmath.interpolation +package space.kscience.kmath.interpolation -import kscience.kmath.functions.PiecewisePolynomial -import kscience.kmath.functions.value -import kscience.kmath.operations.Ring -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.asBuffer +import space.kscience.kmath.functions.PiecewisePolynomial +import space.kscience.kmath.functions.value +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asBuffer public fun interface Interpolator { public fun interpolate(points: XYPointSet): (X) -> Y diff --git a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/LinearInterpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt similarity index 74% rename from kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/LinearInterpolator.kt rename to kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt index 377aa1fbe..c939384e3 100644 --- a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/LinearInterpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt @@ -1,10 +1,10 @@ -package kscience.kmath.interpolation +package space.kscience.kmath.interpolation -import kscience.kmath.functions.OrderedPiecewisePolynomial -import kscience.kmath.functions.PiecewisePolynomial -import kscience.kmath.functions.Polynomial -import kscience.kmath.operations.Field -import kscience.kmath.operations.invoke +import space.kscience.kmath.functions.OrderedPiecewisePolynomial +import space.kscience.kmath.functions.PiecewisePolynomial +import space.kscience.kmath.functions.Polynomial +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.invoke /** * Reference JVM implementation: https://github.com/apache/commons-math/blob/master/src/main/java/org/apache/commons/math4/analysis/interpolation/LinearInterpolator.java diff --git a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/LoessInterpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LoessInterpolator.kt similarity index 98% rename from kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/LoessInterpolator.kt rename to kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LoessInterpolator.kt index 6931857b1..26e7a4072 100644 --- a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/LoessInterpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LoessInterpolator.kt @@ -1,8 +1,8 @@ -package kscience.kmath.interpolation +package space.kscience.kmath.interpolation // -//import kscience.kmath.functions.PiecewisePolynomial -//import kscience.kmath.operations.Ring -//import kscience.kmath.structures.Buffer +//import space.kscience.kmath.functions.PiecewisePolynomial +//import space.kscience.kmath.operations.Ring +//import space.kscience.kmath.structures.Buffer //import kotlin.math.abs //import kotlin.math.sqrt // diff --git a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/SplineInterpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt similarity index 85% rename from kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/SplineInterpolator.kt rename to kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt index 6cda45f72..34fd25ad4 100644 --- a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/SplineInterpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt @@ -1,11 +1,11 @@ -package kscience.kmath.interpolation +package space.kscience.kmath.interpolation -import kscience.kmath.functions.OrderedPiecewisePolynomial -import kscience.kmath.functions.PiecewisePolynomial -import kscience.kmath.functions.Polynomial -import kscience.kmath.operations.Field -import kscience.kmath.operations.invoke -import kscience.kmath.structures.MutableBufferFactory +import space.kscience.kmath.functions.OrderedPiecewisePolynomial +import space.kscience.kmath.functions.PiecewisePolynomial +import space.kscience.kmath.functions.Polynomial +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.MutableBufferFactory /** * Generic spline interpolator. Not recommended for performance critical places, use platform-specific and type specific ones. diff --git a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/XYPointSet.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/XYPointSet.kt similarity index 92% rename from kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/XYPointSet.kt rename to kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/XYPointSet.kt index 2abb7742c..c3bcad846 100644 --- a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/XYPointSet.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/XYPointSet.kt @@ -1,7 +1,7 @@ -package kscience.kmath.interpolation +package space.kscience.kmath.interpolation -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.Structure2D +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.structures.Buffer public interface XYPointSet { public val size: Int diff --git a/kmath-functions/src/commonTest/kotlin/kscience/kmath/interpolation/LinearInterpolatorTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/LinearInterpolatorTest.kt similarity index 75% rename from kmath-functions/src/commonTest/kotlin/kscience/kmath/interpolation/LinearInterpolatorTest.kt rename to kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/LinearInterpolatorTest.kt index 303615676..0b7b62147 100644 --- a/kmath-functions/src/commonTest/kotlin/kscience/kmath/interpolation/LinearInterpolatorTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/LinearInterpolatorTest.kt @@ -1,8 +1,8 @@ -package kscience.kmath.interpolation +package space.kscience.kmath.interpolation -import kscience.kmath.functions.PiecewisePolynomial -import kscience.kmath.functions.asFunction -import kscience.kmath.operations.RealField +import space.kscience.kmath.functions.PiecewisePolynomial +import space.kscience.kmath.functions.asFunction +import space.kscience.kmath.operations.RealField import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-geometry/build.gradle.kts b/kmath-geometry/build.gradle.kts index 00abcb934..e99eee38b 100644 --- a/kmath-geometry/build.gradle.kts +++ b/kmath-geometry/build.gradle.kts @@ -1,7 +1,11 @@ -plugins { id("ru.mipt.npm.mpp") } +plugins { id("ru.mipt.npm.gradle.mpp") } kotlin.sourceSets.commonMain { dependencies { api(project(":kmath-core")) } } + +readme{ + maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE +} diff --git a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/ReferenceFrame.kt b/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/ReferenceFrame.kt deleted file mode 100644 index f9de7b51f..000000000 --- a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/ReferenceFrame.kt +++ /dev/null @@ -1,3 +0,0 @@ -package kscience.kmath.geometry - -public interface ReferenceFrame diff --git a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/Euclidean2DSpace.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean2DSpace.kt similarity index 82% rename from kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/Euclidean2DSpace.kt rename to kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean2DSpace.kt index c2a883a64..609274d7d 100644 --- a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/Euclidean2DSpace.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean2DSpace.kt @@ -1,11 +1,13 @@ -package kscience.kmath.geometry +package space.kscience.kmath.geometry -import kscience.kmath.linear.Point -import kscience.kmath.operations.SpaceElement -import kscience.kmath.operations.invoke +import space.kscience.kmath.linear.Point +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.SpaceElement +import space.kscience.kmath.operations.invoke import kotlin.math.sqrt -public interface Vector2D : Point, Vector, SpaceElement { +@OptIn(UnstableKMathAPI::class) +public interface Vector2D : Point, Vector, SpaceElement { public val x: Double public val y: Double public override val context: Euclidean2DSpace get() = Euclidean2DSpace @@ -18,8 +20,6 @@ public interface Vector2D : Point, Vector, SpaceElement = listOf(x, y).iterator() - public override fun unwrap(): Vector2D = this - public override fun Vector2D.wrap(): Vector2D = this } public val Vector2D.r: Double diff --git a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/Euclidean3DSpace.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean3DSpace.kt similarity index 83% rename from kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/Euclidean3DSpace.kt rename to kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean3DSpace.kt index e0052d791..906f5df03 100644 --- a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/Euclidean3DSpace.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean3DSpace.kt @@ -1,11 +1,13 @@ -package kscience.kmath.geometry +package space.kscience.kmath.geometry -import kscience.kmath.linear.Point -import kscience.kmath.operations.SpaceElement -import kscience.kmath.operations.invoke +import space.kscience.kmath.linear.Point +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.SpaceElement +import space.kscience.kmath.operations.invoke import kotlin.math.sqrt -public interface Vector3D : Point, Vector, SpaceElement { +@OptIn(UnstableKMathAPI::class) +public interface Vector3D : Point, Vector, SpaceElement { public val x: Double public val y: Double public val z: Double @@ -20,8 +22,6 @@ public interface Vector3D : Point, Vector, SpaceElement = listOf(x, y, z).iterator() - public override fun unwrap(): Vector3D = this - public override fun Vector3D.wrap(): Vector3D = this } @Suppress("FunctionName") diff --git a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/GeometrySpace.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt similarity index 74% rename from kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/GeometrySpace.kt rename to kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt index 54d2510cf..392156e9f 100644 --- a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/GeometrySpace.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt @@ -1,6 +1,6 @@ -package kscience.kmath.geometry +package space.kscience.kmath.geometry -import kscience.kmath.operations.Space +import space.kscience.kmath.operations.Space public interface Vector diff --git a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/Line.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt similarity index 79% rename from kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/Line.kt rename to kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt index ec2ce31ca..89cc46958 100644 --- a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/Line.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt @@ -1,4 +1,4 @@ -package kscience.kmath.geometry +package space.kscience.kmath.geometry public data class Line(val base: V, val direction: V) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/ReferenceFrame.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/ReferenceFrame.kt new file mode 100644 index 000000000..9197cfed7 --- /dev/null +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/ReferenceFrame.kt @@ -0,0 +1,3 @@ +package space.kscience.kmath.geometry + +public interface ReferenceFrame diff --git a/kmath-histograms/build.gradle.kts b/kmath-histograms/build.gradle.kts index 7de21ad89..1337e40aa 100644 --- a/kmath-histograms/build.gradle.kts +++ b/kmath-histograms/build.gradle.kts @@ -1,8 +1,24 @@ -plugins { id("ru.mipt.npm.mpp") } +plugins { + id("ru.mipt.npm.gradle.mpp") +} -kotlin.sourceSets.commonMain { - dependencies { - api(project(":kmath-core")) - api(project(":kmath-for-real")) +kscience { + useAtomic() +} + +kotlin.sourceSets { + commonMain { + dependencies { + api(project(":kmath-core")) + } + } + commonTest { + dependencies { + implementation(project(":kmath-for-real")) + } } } + +readme { + this.maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE +} diff --git a/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/Counters.kt b/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/Counters.kt deleted file mode 100644 index 7a263a9fc..000000000 --- a/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/Counters.kt +++ /dev/null @@ -1,20 +0,0 @@ -package kscience.kmath.histogram - -/* - * Common representation for atomic counters - * TODO replace with atomics - */ - -public expect class LongCounter() { - public fun decrement() - public fun increment() - public fun reset() - public fun sum(): Long - public fun add(l: Long) -} - -public expect class DoubleCounter() { - public fun reset() - public fun sum(): Double - public fun add(d: Double) -} diff --git a/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/Histogram.kt b/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/Histogram.kt deleted file mode 100644 index 370a01215..000000000 --- a/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/Histogram.kt +++ /dev/null @@ -1,54 +0,0 @@ -package kscience.kmath.histogram - -import kscience.kmath.domains.Domain -import kscience.kmath.linear.Point -import kscience.kmath.structures.ArrayBuffer -import kscience.kmath.structures.RealBuffer - -/** - * The bin in the histogram. The histogram is by definition always done in the real space - */ -public interface Bin : Domain { - /** - * The value of this bin. - */ - public val value: Number - - public val center: Point -} - -public interface Histogram> : Iterable { - /** - * Find existing bin, corresponding to given coordinates - */ - public operator fun get(point: Point): B? - - /** - * Dimension of the histogram - */ - public val dimension: Int -} - -public interface MutableHistogram> : Histogram { - - /** - * Increment appropriate bin - */ - public fun putWithWeight(point: Point, weight: Double) - - public fun put(point: Point): Unit = putWithWeight(point, 1.0) -} - -public fun MutableHistogram.put(vararg point: T): Unit = put(ArrayBuffer(point)) - -public fun MutableHistogram.put(vararg point: Number): Unit = - put(RealBuffer(point.map { it.toDouble() }.toDoubleArray())) - -public fun MutableHistogram.put(vararg point: Double): Unit = put(RealBuffer(point)) -public fun MutableHistogram.fill(sequence: Iterable>): Unit = sequence.forEach { put(it) } - -/** - * Pass a sequence builder into histogram - */ -public fun MutableHistogram.fill(block: suspend SequenceScope>.() -> Unit): Unit = - fill(sequence(block).asIterable()) diff --git a/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/RealHistogram.kt b/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/RealHistogram.kt deleted file mode 100644 index f95264ee1..000000000 --- a/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/RealHistogram.kt +++ /dev/null @@ -1,155 +0,0 @@ -package kscience.kmath.histogram - -import kscience.kmath.linear.Point -import kscience.kmath.operations.SpaceOperations -import kscience.kmath.operations.invoke -import kscience.kmath.structures.* -import kotlin.math.floor - -public data class BinDef>( - public val space: SpaceOperations>, - public val center: Point, - public val sizes: Point -) { - public fun contains(vector: Point): Boolean { - require(vector.size == center.size) { "Dimension mismatch for input vector. Expected ${center.size}, but found ${vector.size}" } - val upper = space { center + sizes / 2.0 } - val lower = space { center - sizes / 2.0 } - return vector.asSequence().mapIndexed { i, value -> value in lower[i]..upper[i] }.all { it } - } -} - - -public class MultivariateBin>(public val def: BinDef, public override val value: Number) : Bin { - public override val dimension: Int - get() = def.center.size - - public override val center: Point - get() = def.center - - public override operator fun contains(point: Point): Boolean = def.contains(point) -} - -/** - * Uniform multivariate histogram with fixed borders. Based on NDStructure implementation with complexity of m for bin search, where m is the number of dimensions. - */ -public class RealHistogram( - private val lower: Buffer, - private val upper: Buffer, - private val binNums: IntArray = IntArray(lower.size) { 20 } -) : MutableHistogram> { - private val strides = DefaultStrides(IntArray(binNums.size) { binNums[it] + 2 }) - private val values: NDStructure = NDStructure.auto(strides) { LongCounter() } - private val weights: NDStructure = NDStructure.auto(strides) { DoubleCounter() } - public override val dimension: Int get() = lower.size - private val binSize = RealBuffer(dimension) { (upper[it] - lower[it]) / binNums[it] } - - init { - // argument checks - require(lower.size == upper.size) { "Dimension mismatch in histogram lower and upper limits." } - require(lower.size == binNums.size) { "Dimension mismatch in bin count." } - require(!(0 until dimension).any { upper[it] - lower[it] < 0 }) { "Range for one of axis is not strictly positive" } - } - - - /** - * Get internal [NDStructure] bin index for given axis - */ - private fun getIndex(axis: Int, value: Double): Int = when { - value >= upper[axis] -> binNums[axis] + 1 // overflow - value < lower[axis] -> 0 // underflow - else -> floor((value - lower[axis]) / binSize[axis]).toInt() + 1 - } - - private fun getIndex(point: Buffer): IntArray = IntArray(dimension) { getIndex(it, point[it]) } - - private fun getValue(index: IntArray): Long = values[index].sum() - - public fun getValue(point: Buffer): Long = getValue(getIndex(point)) - - private fun getDef(index: IntArray): BinDef { - val center = index.mapIndexed { axis, i -> - when (i) { - 0 -> Double.NEGATIVE_INFINITY - strides.shape[axis] - 1 -> Double.POSITIVE_INFINITY - else -> lower[axis] + (i.toDouble() - 0.5) * binSize[axis] - } - }.asBuffer() - - return BinDef(RealBufferFieldOperations, center, binSize) - } - - public fun getDef(point: Buffer): BinDef = getDef(getIndex(point)) - - public override operator fun get(point: Buffer): MultivariateBin? { - val index = getIndex(point) - return MultivariateBin(getDef(index), getValue(index)) - } - -// fun put(point: Point){ -// val index = getIndex(point) -// values[index].increment() -// } - - public override fun putWithWeight(point: Buffer, weight: Double) { - val index = getIndex(point) - values[index].increment() - weights[index].add(weight) - } - - public override operator fun iterator(): Iterator> = - weights.elements().map { (index, value) -> MultivariateBin(getDef(index), value.sum()) } - .iterator() - - /** - * Convert this histogram into NDStructure containing bin values but not bin descriptions - */ - public fun values(): NDStructure = NDStructure.auto(values.shape) { values[it].sum() } - - /** - * Sum of weights - */ - public fun weights(): NDStructure = NDStructure.auto(weights.shape) { weights[it].sum() } - - public companion object { - /** - * Use it like - * ``` - *FastHistogram.fromRanges( - * (-1.0..1.0), - * (-1.0..1.0) - *) - *``` - */ - public fun fromRanges(vararg ranges: ClosedFloatingPointRange): RealHistogram = RealHistogram( - ranges.map(ClosedFloatingPointRange::start).asBuffer(), - ranges.map(ClosedFloatingPointRange::endInclusive).asBuffer() - ) - - /** - * Use it like - * ``` - *FastHistogram.fromRanges( - * (-1.0..1.0) to 50, - * (-1.0..1.0) to 32 - *) - *``` - */ - public fun fromRanges(vararg ranges: Pair, Int>): RealHistogram = - RealHistogram( - ListBuffer( - ranges - .map(Pair, Int>::first) - .map(ClosedFloatingPointRange::start) - ), - - ListBuffer( - ranges - .map(Pair, Int>::first) - .map(ClosedFloatingPointRange::endInclusive) - ), - - ranges.map(Pair, Int>::second).toIntArray() - ) - } -} diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt new file mode 100644 index 000000000..55e8c0631 --- /dev/null +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt @@ -0,0 +1,49 @@ +package space.kscience.kmath.histogram + +import kotlinx.atomicfu.atomic +import kotlinx.atomicfu.getAndUpdate +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.Space + +/** + * Common representation for atomic counters + */ +public interface Counter { + public fun add(delta: T) + public val value: T + public companion object{ + public fun real(): ObjectCounter = ObjectCounter(RealField) + } +} + +public class IntCounter : Counter { + private val innerValue = atomic(0) + + override fun add(delta: Int) { + innerValue += delta + } + + override val value: Int get() = innerValue.value +} + +public class LongCounter : Counter { + private val innerValue = atomic(0L) + + override fun add(delta: Long) { + innerValue += delta + } + + override val value: Long get() = innerValue.value +} + +public class ObjectCounter(public val space: Space) : Counter { + private val innerValue = atomic(space.zero) + + override fun add(delta: T) { + innerValue.getAndUpdate { space.run { it + delta } } + } + + override val value: T get() = innerValue.value +} + + diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt new file mode 100644 index 000000000..73b34783c --- /dev/null +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt @@ -0,0 +1,55 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.Domain +import space.kscience.kmath.linear.Point +import space.kscience.kmath.structures.ArrayBuffer +import space.kscience.kmath.structures.RealBuffer + +/** + * The binned data element. Could be a histogram bin with a number of counts or an artificial construct + */ +public interface Bin : Domain { + /** + * The value of this bin. + */ + public val value: Number +} + +public interface Histogram> { + /** + * Find existing bin, corresponding to given coordinates + */ + public operator fun get(point: Point): B? + + /** + * Dimension of the histogram + */ + public val dimension: Int + + public val bins: Iterable +} + +public fun interface HistogramBuilder { + + /** + * Increment appropriate bin + */ + public fun putValue(point: Point, value: Number) + +} + +public fun > HistogramBuilder.put(point: Point): Unit = putValue(point, 1.0) + +public fun HistogramBuilder.put(vararg point: T): Unit = put(ArrayBuffer(point)) + +public fun HistogramBuilder.put(vararg point: Number): Unit = + put(RealBuffer(point.map { it.toDouble() }.toDoubleArray())) + +public fun HistogramBuilder.put(vararg point: Double): Unit = put(RealBuffer(point)) +public fun HistogramBuilder.fill(sequence: Iterable>): Unit = sequence.forEach { put(it) } + +/** + * Pass a sequence builder into histogram + */ +public fun HistogramBuilder.fill(block: suspend SequenceScope>.() -> Unit): Unit = + fill(sequence(block).asIterable()) diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/IndexedHistogramSpace.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/IndexedHistogramSpace.kt new file mode 100644 index 000000000..85262abeb --- /dev/null +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/IndexedHistogramSpace.kt @@ -0,0 +1,76 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.Domain +import space.kscience.kmath.linear.Point +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.NDSpace +import space.kscience.kmath.nd.NDStructure +import space.kscience.kmath.nd.Strides +import space.kscience.kmath.operations.Space +import space.kscience.kmath.operations.SpaceElement +import space.kscience.kmath.operations.invoke + +/** + * A simple histogram bin based on domain + */ +public data class DomainBin>( + public val domain: Domain, + public override val value: Number, +) : Bin, Domain by domain + +@OptIn(UnstableKMathAPI::class) +public class IndexedHistogram, V : Any>( + override val context: IndexedHistogramSpace, + public val values: NDStructure, +) : Histogram>, SpaceElement, IndexedHistogramSpace> { + + override fun get(point: Point): Bin? { + val index = context.getIndex(point) ?: return null + return context.produceBin(index, values[index]) + } + + override val dimension: Int get() = context.strides.shape.size + + override val bins: Iterable> + get() = context.strides.indices().map { + context.produceBin(it, values[it]) + }.asIterable() + +} + +/** + * A space for producing histograms with values in a NDStructure + */ +public interface IndexedHistogramSpace, V : Any> : Space> { + //public val valueSpace: Space + public val strides: Strides + public val histogramValueSpace: NDSpace //= NDAlgebra.space(valueSpace, Buffer.Companion::boxing, *shape), + + /** + * Resolve index of the bin including given [point] + */ + public fun getIndex(point: Point): IntArray? + + /** + * Get a bin domain represented by given index + */ + public fun getDomain(index: IntArray): Domain? + + public fun produceBin(index: IntArray, value: V): Bin + + public fun produce(builder: HistogramBuilder.() -> Unit): IndexedHistogram + + override fun add(a: IndexedHistogram, b: IndexedHistogram): IndexedHistogram { + require(a.context == this) { "Can't operate on a histogram produced by external space" } + require(b.context == this) { "Can't operate on a histogram produced by external space" } + return IndexedHistogram(this, histogramValueSpace.invoke { a.values + b.values }) + } + + override fun multiply(a: IndexedHistogram, k: Number): IndexedHistogram { + require(a.context == this) { "Can't operate on a histogram produced by external space" } + return IndexedHistogram(this, histogramValueSpace.invoke { a.values * k }) + } + + override val zero: IndexedHistogram get() = produce { } +} + diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt new file mode 100644 index 000000000..26efdf1fe --- /dev/null +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt @@ -0,0 +1,121 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.Domain +import space.kscience.kmath.domains.HyperSquareDomain +import space.kscience.kmath.nd.* +import space.kscience.kmath.structures.* +import kotlin.math.floor + +public class RealHistogramSpace( + private val lower: Buffer, + private val upper: Buffer, + private val binNums: IntArray = IntArray(lower.size) { 20 }, +) : IndexedHistogramSpace { + + init { + // argument checks + require(lower.size == upper.size) { "Dimension mismatch in histogram lower and upper limits." } + require(lower.size == binNums.size) { "Dimension mismatch in bin count." } + require(!lower.indices.any { upper[it] - lower[it] < 0 }) { "Range for one of axis is not strictly positive" } + } + + public val dimension: Int get() = lower.size + + private val shape = IntArray(binNums.size) { binNums[it] + 2 } + override val histogramValueSpace: RealNDField = NDAlgebra.real(*shape) + + override val strides: Strides get() = histogramValueSpace.strides + private val binSize = RealBuffer(dimension) { (upper[it] - lower[it]) / binNums[it] } + + /** + * Get internal [NDStructure] bin index for given axis + */ + private fun getIndex(axis: Int, value: Double): Int = when { + value >= upper[axis] -> binNums[axis] + 1 // overflow + value < lower[axis] -> 0 // underflow + else -> floor((value - lower[axis]) / binSize[axis]).toInt() + } + + override fun getIndex(point: Buffer): IntArray = IntArray(dimension) { + getIndex(it, point[it]) + } + + override fun getDomain(index: IntArray): Domain { + val lowerBoundary = index.mapIndexed { axis, i -> + when (i) { + 0 -> Double.NEGATIVE_INFINITY + strides.shape[axis] - 1 -> upper[axis] + else -> lower[axis] + (i.toDouble()) * binSize[axis] + } + }.asBuffer() + + val upperBoundary = index.mapIndexed { axis, i -> + when (i) { + 0 -> lower[axis] + strides.shape[axis] - 1 -> Double.POSITIVE_INFINITY + else -> lower[axis] + (i.toDouble() + 1) * binSize[axis] + } + }.asBuffer() + + return HyperSquareDomain(lowerBoundary, upperBoundary) + } + + + override fun produceBin(index: IntArray, value: Double): Bin { + val domain = getDomain(index) + return DomainBin(domain, value) + } + + override fun produce(builder: HistogramBuilder.() -> Unit): IndexedHistogram { + val ndCounter = NDStructure.auto(strides) { Counter.real() } + val hBuilder = HistogramBuilder { point, value -> + val index = getIndex(point) + ndCounter[index].add(value.toDouble()) + } + hBuilder.apply(builder) + val values: NDBuffer = ndCounter.mapToBuffer { it.value } + return IndexedHistogram(this, values) + } + + public companion object { + /** + * Use it like + * ``` + *FastHistogram.fromRanges( + * (-1.0..1.0), + * (-1.0..1.0) + *) + *``` + */ + public fun fromRanges(vararg ranges: ClosedFloatingPointRange): RealHistogramSpace = RealHistogramSpace( + ranges.map(ClosedFloatingPointRange::start).asBuffer(), + ranges.map(ClosedFloatingPointRange::endInclusive).asBuffer() + ) + + /** + * Use it like + * ``` + *FastHistogram.fromRanges( + * (-1.0..1.0) to 50, + * (-1.0..1.0) to 32 + *) + *``` + */ + public fun fromRanges(vararg ranges: Pair, Int>): RealHistogramSpace = + RealHistogramSpace( + ListBuffer( + ranges + .map(Pair, Int>::first) + .map(ClosedFloatingPointRange::start) + ), + + ListBuffer( + ranges + .map(Pair, Int>::first) + .map(ClosedFloatingPointRange::endInclusive) + ), + + ranges.map(Pair, Int>::second).toIntArray() + ) + } +} \ No newline at end of file diff --git a/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt b/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt deleted file mode 100644 index af22afc6b..000000000 --- a/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt +++ /dev/null @@ -1,46 +0,0 @@ -package scietifik.kmath.histogram - -import kscience.kmath.histogram.RealHistogram -import kscience.kmath.histogram.fill -import kscience.kmath.histogram.put -import kscience.kmath.real.RealVector -import kscience.kmath.real.invoke -import kscience.kmath.structures.Buffer -import kotlin.random.Random -import kotlin.test.* - -internal class MultivariateHistogramTest { - @Test - fun testSinglePutHistogram() { - val histogram = RealHistogram.fromRanges( - (-1.0..1.0), - (-1.0..1.0) - ) - histogram.put(0.55, 0.55) - val bin = histogram.find { it.value.toInt() > 0 } ?: fail() - assertTrue { bin.contains(RealVector(0.55, 0.55)) } - assertTrue { bin.contains(RealVector(0.6, 0.5)) } - assertFalse { bin.contains(RealVector(-0.55, 0.55)) } - } - - @Test - fun testSequentialPut() { - val histogram = RealHistogram.fromRanges( - (-1.0..1.0), - (-1.0..1.0), - (-1.0..1.0) - ) - val random = Random(1234) - - fun nextDouble() = random.nextDouble(-1.0, 1.0) - - val n = 10000 - - histogram.fill { - repeat(n) { - yield(RealVector(nextDouble(), nextDouble(), nextDouble())) - } - } - assertEquals(n, histogram.sumBy { it.value.toInt() }) - } -} \ No newline at end of file diff --git a/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt b/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt new file mode 100644 index 000000000..e83f42b4b --- /dev/null +++ b/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt @@ -0,0 +1,78 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.real.RealVector +import space.kscience.kmath.real.invoke +import kotlin.random.Random +import kotlin.test.* + +internal class MultivariateHistogramTest { + @Test + fun testSinglePutHistogram() { + val hSpace = RealHistogramSpace.fromRanges( + (-1.0..1.0), + (-1.0..1.0) + ) + val histogram = hSpace.produce { + put(0.55, 0.55) + } + val bin = histogram.bins.find { it.value.toInt() > 0 } ?: fail() + assertTrue { bin.contains(RealVector(0.55, 0.55)) } + assertTrue { bin.contains(RealVector(0.6, 0.5)) } + assertFalse { bin.contains(RealVector(-0.55, 0.55)) } + } + + @Test + fun testSequentialPut() { + val hSpace = RealHistogramSpace.fromRanges( + (-1.0..1.0), + (-1.0..1.0), + (-1.0..1.0) + ) + val random = Random(1234) + + fun nextDouble() = random.nextDouble(-1.0, 1.0) + + val n = 10000 + val histogram = hSpace.produce { + repeat(n) { + put(nextDouble(), nextDouble(), nextDouble()) + } + } + assertEquals(n, histogram.bins.sumBy { it.value.toInt() }) + } + + @Test + fun testHistogramAlgebra() { + RealHistogramSpace.fromRanges( + (-1.0..1.0), + (-1.0..1.0), + (-1.0..1.0) + ).invoke { + val random = Random(1234) + + fun nextDouble() = random.nextDouble(-1.0, 1.0) + val n = 10000 + val histogram1 = produce { + repeat(n) { + put(nextDouble(), nextDouble(), nextDouble()) + } + } + val histogram2 = produce { + repeat(n) { + put(nextDouble(), nextDouble(), nextDouble()) + } + } + val res = histogram1 - histogram2 + assertTrue { + strides.indices().all { index -> + res.values[index] <= histogram1.values[index] + } + } + assertTrue { + res.bins.count() >= histogram1.bins.count() + } + assertEquals(0.0, res.bins.sumByDouble { it.value.toDouble() }) + } + } +} \ No newline at end of file diff --git a/kmath-histograms/src/jsMain/kotlin/kscience/kmath/histogram/Counters.kt b/kmath-histograms/src/jsMain/kotlin/kscience/kmath/histogram/Counters.kt deleted file mode 100644 index d0fa1f4c2..000000000 --- a/kmath-histograms/src/jsMain/kotlin/kscience/kmath/histogram/Counters.kt +++ /dev/null @@ -1,37 +0,0 @@ -package kscience.kmath.histogram - -public actual class LongCounter { - private var sum: Long = 0L - - public actual fun decrement() { - sum-- - } - - public actual fun increment() { - sum++ - } - - public actual fun reset() { - sum = 0 - } - - public actual fun sum(): Long = sum - - public actual fun add(l: Long) { - sum += l - } -} - -public actual class DoubleCounter { - private var sum: Double = 0.0 - - public actual fun reset() { - sum = 0.0 - } - - public actual fun sum(): Double = sum - - public actual fun add(d: Double) { - sum += d - } -} diff --git a/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/Counters.kt b/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/Counters.kt deleted file mode 100644 index efbd185ef..000000000 --- a/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/Counters.kt +++ /dev/null @@ -1,7 +0,0 @@ -package kscience.kmath.histogram - -import java.util.concurrent.atomic.DoubleAdder -import java.util.concurrent.atomic.LongAdder - -public actual typealias LongCounter = LongAdder -public actual typealias DoubleCounter = DoubleAdder diff --git a/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/UnivariateHistogram.kt b/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/UnivariateHistogram.kt deleted file mode 100644 index 2f3855892..000000000 --- a/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/UnivariateHistogram.kt +++ /dev/null @@ -1,101 +0,0 @@ -package kscience.kmath.histogram - -import kscience.kmath.real.RealVector -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.asBuffer -import java.util.* -import kotlin.math.floor - -//TODO move to common - -public class UnivariateBin( - public val position: Double, - public val size: Double, - public val counter: LongCounter = LongCounter() -) : Bin { - //TODO add weighting - public override val value: Number get() = counter.sum() - - public override val center: RealVector get() = doubleArrayOf(position).asBuffer() - public override val dimension: Int get() = 1 - - public operator fun contains(value: Double): Boolean = value in (position - size / 2)..(position + size / 2) - public override fun contains(point: Buffer): Boolean = contains(point[0]) - internal operator fun inc(): UnivariateBin = this.also { counter.increment() } -} - -/** - * Univariate histogram with log(n) bin search speed - */ -public class UnivariateHistogram private constructor(private val factory: (Double) -> UnivariateBin) : - MutableHistogram { - - private val bins: TreeMap = TreeMap() - - private operator fun get(value: Double): UnivariateBin? { - // check ceiling entry and return it if it is what needed - val ceil = bins.ceilingEntry(value)?.value - if (ceil != null && value in ceil) return ceil - //check floor entry - val floor = bins.floorEntry(value)?.value - if (floor != null && value in floor) return floor - //neither is valid, not found - return null - } - - private fun createBin(value: Double): UnivariateBin = factory(value).also { - synchronized(this) { bins[it.position] = it } - } - - public override operator fun get(point: Buffer): UnivariateBin? = get(point[0]) - - public override val dimension: Int get() = 1 - - public override operator fun iterator(): Iterator = bins.values.iterator() - - /** - * Thread safe put operation - */ - public fun put(value: Double) { - (get(value) ?: createBin(value)).inc() - } - - override fun putWithWeight(point: Buffer, weight: Double) { - if (weight != 1.0) TODO("Implement weighting") - put(point[0]) - } - - public companion object { - public fun uniform(binSize: Double, start: Double = 0.0): UnivariateHistogram = UnivariateHistogram { value -> - val center = start + binSize * floor((value - start) / binSize + 0.5) - UnivariateBin(center, binSize) - } - - public fun custom(borders: DoubleArray): UnivariateHistogram { - val sorted = borders.sortedArray() - - return UnivariateHistogram { value -> - when { - value < sorted.first() -> UnivariateBin( - Double.NEGATIVE_INFINITY, - Double.MAX_VALUE - ) - - value > sorted.last() -> UnivariateBin( - Double.POSITIVE_INFINITY, - Double.MAX_VALUE - ) - - else -> { - val index = sorted.indices.first { value > sorted[it] } - val left = sorted[index] - val right = sorted[index + 1] - UnivariateBin((left + right) / 2, (right - left)) - } - } - } - } - } -} - -public fun UnivariateHistogram.fill(sequence: Iterable): Unit = sequence.forEach(::put) diff --git a/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramSpace.kt b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramSpace.kt new file mode 100644 index 000000000..ddecc4332 --- /dev/null +++ b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramSpace.kt @@ -0,0 +1,156 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.UnivariateDomain +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.Space +import space.kscience.kmath.structures.Buffer +import java.util.* +import kotlin.math.abs +import kotlin.math.floor +import kotlin.math.sqrt + +private fun > TreeMap.getBin(value: Double): B? { + // check ceiling entry and return it if it is what needed + val ceil = ceilingEntry(value)?.value + if (ceil != null && value in ceil) return ceil + //check floor entry + val floor = floorEntry(value)?.value + if (floor != null && value in floor) return floor + //neither is valid, not found + return null +} + +@UnstableKMathAPI +public class TreeHistogram( + override val context: TreeHistogramSpace, + private val binMap: TreeMap, +) : UnivariateHistogram { + override fun get(value: Double): UnivariateBin? = binMap.getBin(value) + override val dimension: Int get() = 1 + override val bins: Collection get() = binMap.values +} + +/** + * A space for univariate histograms with variable bin borders based on a tree map + */ +@UnstableKMathAPI +public class TreeHistogramSpace( + public val binFactory: (Double) -> UnivariateDomain, +) : Space { + + private class BinCounter(val domain: UnivariateDomain, val counter: Counter = Counter.real()) : + ClosedFloatingPointRange by domain.range + + public fun produce(builder: UnivariateHistogramBuilder.() -> Unit): UnivariateHistogram { + val bins: TreeMap = TreeMap() + val hBuilder = object : UnivariateHistogramBuilder { + + fun get(value: Double): BinCounter? = bins.getBin(value) + + fun createBin(value: Double): BinCounter { + val binDefinition = binFactory(value) + val newBin = BinCounter(binDefinition) + synchronized(this) { bins[binDefinition.center] = newBin } + return newBin + } + + /** + * Thread safe put operation + */ + override fun putValue(at: Double, value: Double) { + (get(at) ?: createBin(at)).apply { + counter.add(value) + } + } + + override fun putValue(point: Buffer, value: Number) { + put(point[0], value.toDouble()) + } + } + hBuilder.apply(builder) + val resBins = TreeMap() + bins.forEach { (key, binCounter) -> + val count = binCounter.counter.value + resBins[key] = UnivariateBin(binCounter.domain, count, sqrt(count)) + } + return TreeHistogram(this, resBins) + } + + override fun add( + a: UnivariateHistogram, + b: UnivariateHistogram, + ): UnivariateHistogram { + require(a.context == this) { "Histogram $a does not belong to this context" } + require(b.context == this) { "Histogram $b does not belong to this context" } + val bins = TreeMap().apply { + (a.bins.map { it.domain } union b.bins.map { it.domain }).forEach { def -> + put(def.center, + UnivariateBin( + def, + value = (a[def.center]?.value ?: 0.0) + (b[def.center]?.value ?: 0.0), + standardDeviation = (a[def.center]?.standardDeviation + ?: 0.0) + (b[def.center]?.standardDeviation ?: 0.0) + ) + ) + } + } + return TreeHistogram(this, bins) + } + + override fun multiply(a: UnivariateHistogram, k: Number): UnivariateHistogram { + val bins = TreeMap().apply { + a.bins.forEach { bin -> + put(bin.domain.center, + UnivariateBin( + bin.domain, + value = bin.value * k.toDouble(), + standardDeviation = abs(bin.standardDeviation * k.toDouble()) + ) + ) + } + } + + return TreeHistogram(this, bins) + } + + override val zero: UnivariateHistogram = produce { } + + public companion object { + /** + * Build and fill a [UnivariateHistogram]. Returns a read-only histogram. + */ + public fun uniform( + binSize: Double, + start: Double = 0.0, + ): TreeHistogramSpace = TreeHistogramSpace { value -> + val center = start + binSize * floor((value - start) / binSize + 0.5) + UnivariateDomain((center - binSize / 2)..(center + binSize / 2)) + } + + /** + * Create a histogram with custom cell borders + */ + public fun custom(borders: DoubleArray): TreeHistogramSpace { + val sorted = borders.sortedArray() + + return TreeHistogramSpace { value -> + when { + value < sorted.first() -> UnivariateDomain( + Double.NEGATIVE_INFINITY..sorted.first() + ) + + value > sorted.last() -> UnivariateDomain( + sorted.last()..Double.POSITIVE_INFINITY + ) + + else -> { + val index = sorted.indices.first { value > sorted[it] } + val left = sorted[index] + val right = sorted[index + 1] + UnivariateDomain(left..right) + } + } + } + } + } +} \ No newline at end of file diff --git a/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/UnivariateHistogram.kt b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/UnivariateHistogram.kt new file mode 100644 index 000000000..8c4f9e434 --- /dev/null +++ b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/UnivariateHistogram.kt @@ -0,0 +1,73 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.UnivariateDomain +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.Space +import space.kscience.kmath.operations.SpaceElement +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asSequence + + +public val UnivariateDomain.center: Double get() = (range.endInclusive - range.start) / 2 + +/** + * A univariate bin based an a range + * @param value The value of histogram including weighting + * @param standardDeviation Standard deviation of the bin value. Zero or negative if not applicable + */ +public class UnivariateBin( + public val domain: UnivariateDomain, + override val value: Double, + public val standardDeviation: Double, +) : Bin, ClosedFloatingPointRange by domain.range { + + public override val dimension: Int get() = 1 + + public override fun contains(point: Buffer): Boolean = point.size == 1 && contains(point[0]) +} + +@OptIn(UnstableKMathAPI::class) +public interface UnivariateHistogram : Histogram, + SpaceElement> { + public operator fun get(value: Double): UnivariateBin? + public override operator fun get(point: Buffer): UnivariateBin? = get(point[0]) + + public companion object { + /** + * Build and fill a [UnivariateHistogram]. Returns a read-only histogram. + */ + public fun uniform( + binSize: Double, + start: Double = 0.0, + builder: UnivariateHistogramBuilder.() -> Unit, + ): UnivariateHistogram = TreeHistogramSpace.uniform(binSize, start).produce(builder) + + /** + * Build and fill a histogram with custom borders. Returns a read-only histogram. + */ + public fun custom( + borders: DoubleArray, + builder: UnivariateHistogramBuilder.() -> Unit, + ): UnivariateHistogram = TreeHistogramSpace.custom(borders).produce(builder) + + } +} + +@UnstableKMathAPI +public interface UnivariateHistogramBuilder : HistogramBuilder { + /** + * Thread safe put operation + */ + public fun putValue(at: Double, value: Double = 1.0) + + override fun putValue(point: Buffer, value: Number) +} + +@UnstableKMathAPI +public fun UnivariateHistogramBuilder.fill(items: Iterable): Unit = items.forEach(this::putValue) + +@UnstableKMathAPI +public fun UnivariateHistogramBuilder.fill(array: DoubleArray): Unit = array.forEach(this::putValue) + +@UnstableKMathAPI +public fun UnivariateHistogramBuilder.fill(buffer: Buffer): Unit = buffer.asSequence().forEach(this::putValue) \ No newline at end of file diff --git a/kmath-kotlingrad/build.gradle.kts b/kmath-kotlingrad/build.gradle.kts index 3925a744c..51292cbfb 100644 --- a/kmath-kotlingrad/build.gradle.kts +++ b/kmath-kotlingrad/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("ru.mipt.npm.jvm") + id("ru.mipt.npm.gradle.jvm") } dependencies { @@ -7,3 +7,7 @@ dependencies { implementation("com.github.breandan:kotlingrad:0.4.0") api(project(":kmath-ast")) } + +readme{ + maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE +} \ No newline at end of file diff --git a/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt similarity index 80% rename from kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt rename to kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt index abde9e54d..39a7248b4 100644 --- a/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt +++ b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt @@ -1,12 +1,12 @@ -package kscience.kmath.kotlingrad +package space.kscience.kmath.kotlingrad import edu.umontreal.kotlingrad.api.SFun -import kscience.kmath.ast.MST -import kscience.kmath.ast.MstAlgebra -import kscience.kmath.ast.MstExpression -import kscience.kmath.expressions.DifferentiableExpression -import kscience.kmath.expressions.Symbol -import kscience.kmath.operations.NumericAlgebra +import space.kscience.kmath.ast.MST +import space.kscience.kmath.ast.MstAlgebra +import space.kscience.kmath.ast.MstExpression +import space.kscience.kmath.expressions.DifferentiableExpression +import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.operations.NumericAlgebra /** * Represents wrapper of [MstExpression] implementing [DifferentiableExpression]. @@ -39,7 +39,7 @@ public inline class DifferentiableMstExpression(public val expr: MstExpres public override fun derivativeOrNull(symbols: List): MstExpression = MstExpression( algebra, symbols.map(Symbol::identity) - .map(MstAlgebra::symbol) + .map(MstAlgebra::bindSymbol) .map { it.toSVar>() } .fold(mst.toSFun(), SFun>::d) .toMst(), diff --git a/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/KMathNumber.kt b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KMathNumber.kt similarity index 86% rename from kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/KMathNumber.kt rename to kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KMathNumber.kt index 2a4db4258..d2edb4376 100644 --- a/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/KMathNumber.kt +++ b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KMathNumber.kt @@ -1,8 +1,8 @@ -package kscience.kmath.kotlingrad +package space.kscience.kmath.kotlingrad import edu.umontreal.kotlingrad.api.RealNumber import edu.umontreal.kotlingrad.api.SConst -import kscience.kmath.operations.NumericAlgebra +import space.kscience.kmath.operations.NumericAlgebra /** * Implements [RealNumber] by delegating its functionality to [NumericAlgebra]. diff --git a/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/ScalarsAdapters.kt b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/ScalarsAdapters.kt similarity index 92% rename from kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/ScalarsAdapters.kt rename to kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/ScalarsAdapters.kt index 8dc1d3958..6ca6bc113 100644 --- a/kmath-kotlingrad/src/main/kotlin/kscience/kmath/kotlingrad/ScalarsAdapters.kt +++ b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/ScalarsAdapters.kt @@ -1,11 +1,11 @@ -package kscience.kmath.kotlingrad +package space.kscience.kmath.kotlingrad import edu.umontreal.kotlingrad.api.* -import kscience.kmath.ast.MST -import kscience.kmath.ast.MstAlgebra -import kscience.kmath.ast.MstExtendedField -import kscience.kmath.ast.MstExtendedField.unaryMinus -import kscience.kmath.operations.* +import space.kscience.kmath.ast.MST +import space.kscience.kmath.ast.MstAlgebra +import space.kscience.kmath.ast.MstExtendedField +import space.kscience.kmath.ast.MstExtendedField.unaryMinus +import space.kscience.kmath.operations.* /** * Maps [SVar] to [MST.Symbolic] directly. @@ -13,7 +13,7 @@ import kscience.kmath.operations.* * @receiver the variable. * @return a node. */ -public fun > SVar.toMst(): MST.Symbolic = MstAlgebra.symbol(name) +public fun > SVar.toMst(): MST.Symbolic = MstAlgebra.bindSymbol(name) /** * Maps [SVar] to [MST.Numeric] directly. @@ -29,7 +29,7 @@ public fun > SConst.toMst(): MST.Numeric = MstAlgebra.number(doub * * Detailed mapping is: * - * - [SVar] -> [MstExtendedField.symbol]; + * - [SVar] -> [MstExtendedField.bindSymbol]; * - [SConst] -> [MstExtendedField.number]; * - [Sum] -> [MstExtendedField.add]; * - [Prod] -> [MstExtendedField.multiply]; diff --git a/kmath-kotlingrad/src/test/kotlin/kscience/kmath/kotlingrad/AdaptingTests.kt b/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt similarity index 79% rename from kmath-kotlingrad/src/test/kotlin/kscience/kmath/kotlingrad/AdaptingTests.kt rename to kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt index aa4ddd703..ffdabaffb 100644 --- a/kmath-kotlingrad/src/test/kotlin/kscience/kmath/kotlingrad/AdaptingTests.kt +++ b/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt @@ -1,12 +1,12 @@ -package kscience.kmath.kotlingrad +package space.kscience.kmath.kotlingrad import edu.umontreal.kotlingrad.api.* -import kscience.kmath.asm.compile -import kscience.kmath.ast.MstAlgebra -import kscience.kmath.ast.MstExpression -import kscience.kmath.ast.parseMath -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.RealField +import space.kscience.kmath.asm.compile +import space.kscience.kmath.ast.MstAlgebra +import space.kscience.kmath.ast.MstExpression +import space.kscience.kmath.ast.parseMath +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.RealField import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -15,7 +15,7 @@ import kotlin.test.fail internal class AdaptingTests { @Test fun symbol() { - val c1 = MstAlgebra.symbol("x") + val c1 = MstAlgebra.bindSymbol("x") assertTrue(c1.toSVar>().name == "x") val c2 = "kitten".parseMath().toSFun>() if (c2 is SVar) assertTrue(c2.name == "kitten") else fail() @@ -41,7 +41,7 @@ internal class AdaptingTests { @Test fun simpleFunctionDerivative() { - val x = MstAlgebra.symbol("x").toSVar>() + val x = MstAlgebra.bindSymbol("x").toSVar>() val quadratic = "x^2-4*x-44".parseMath().toSFun>() val actualDerivative = MstExpression(RealField, quadratic.d(x).toMst()).compile() val expectedDerivative = MstExpression(RealField, "2*x-4".parseMath()).compile() @@ -50,7 +50,7 @@ internal class AdaptingTests { @Test fun moreComplexDerivative() { - val x = MstAlgebra.symbol("x").toSVar>() + val x = MstAlgebra.bindSymbol("x").toSVar>() val composition = "-sqrt(sin(x^2)-cos(x)^2-16*x)".parseMath().toSFun>() val actualDerivative = MstExpression(RealField, composition.d(x).toMst()).compile() diff --git a/kmath-memory/api/kmath-memory.api b/kmath-memory/api/kmath-memory.api new file mode 100644 index 000000000..9c9641461 --- /dev/null +++ b/kmath-memory/api/kmath-memory.api @@ -0,0 +1,72 @@ +public final class space/kscience/kmath/memory/ByteBufferMemory : space/kscience/kmath/memory/Memory { + public fun (Ljava/nio/ByteBuffer;II)V + public synthetic fun (Ljava/nio/ByteBuffer;IIILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun copy ()Lspace/kscience/kmath/memory/Memory; + public final fun getBuffer ()Ljava/nio/ByteBuffer; + public fun getSize ()I + public final fun getStartOffset ()I + public fun reader ()Lspace/kscience/kmath/memory/MemoryReader; + public fun view (II)Lspace/kscience/kmath/memory/Memory; + public fun writer ()Lspace/kscience/kmath/memory/MemoryWriter; +} + +public final class space/kscience/kmath/memory/ByteBufferMemoryKt { + public static final fun allocate (Lspace/kscience/kmath/memory/Memory$Companion;I)Lspace/kscience/kmath/memory/Memory; + public static final fun asMemory (Ljava/nio/ByteBuffer;II)Lspace/kscience/kmath/memory/Memory; + public static synthetic fun asMemory$default (Ljava/nio/ByteBuffer;IIILjava/lang/Object;)Lspace/kscience/kmath/memory/Memory; + public static final fun readAsMemory (Ljava/nio/file/Path;JJLkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static synthetic fun readAsMemory$default (Ljava/nio/file/Path;JJLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun wrap (Lspace/kscience/kmath/memory/Memory$Companion;[B)Lspace/kscience/kmath/memory/Memory; +} + +public abstract interface class space/kscience/kmath/memory/Memory { + public static final field Companion Lspace/kscience/kmath/memory/Memory$Companion; + public abstract fun copy ()Lspace/kscience/kmath/memory/Memory; + public abstract fun getSize ()I + public abstract fun reader ()Lspace/kscience/kmath/memory/MemoryReader; + public abstract fun view (II)Lspace/kscience/kmath/memory/Memory; + public abstract fun writer ()Lspace/kscience/kmath/memory/MemoryWriter; +} + +public final class space/kscience/kmath/memory/Memory$Companion { +} + +public final class space/kscience/kmath/memory/MemoryKt { + public static final fun read (Lspace/kscience/kmath/memory/Memory;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun write (Lspace/kscience/kmath/memory/Memory;Lkotlin/jvm/functions/Function1;)V +} + +public abstract interface class space/kscience/kmath/memory/MemoryReader { + public abstract fun getMemory ()Lspace/kscience/kmath/memory/Memory; + public abstract fun readByte (I)B + public abstract fun readDouble (I)D + public abstract fun readFloat (I)F + public abstract fun readInt (I)I + public abstract fun readLong (I)J + public abstract fun readShort (I)S + public abstract fun release ()V +} + +public abstract interface class space/kscience/kmath/memory/MemorySpec { + public abstract fun getObjectSize ()I + public abstract fun read (Lspace/kscience/kmath/memory/MemoryReader;I)Ljava/lang/Object; + public abstract fun write (Lspace/kscience/kmath/memory/MemoryWriter;ILjava/lang/Object;)V +} + +public final class space/kscience/kmath/memory/MemorySpecKt { + public static final fun read (Lspace/kscience/kmath/memory/MemoryReader;Lspace/kscience/kmath/memory/MemorySpec;I)Ljava/lang/Object; + public static final fun write (Lspace/kscience/kmath/memory/MemoryWriter;Lspace/kscience/kmath/memory/MemorySpec;ILjava/lang/Object;)V + public static final fun writeArray (Lspace/kscience/kmath/memory/MemoryWriter;Lspace/kscience/kmath/memory/MemorySpec;I[Ljava/lang/Object;)V +} + +public abstract interface class space/kscience/kmath/memory/MemoryWriter { + public abstract fun getMemory ()Lspace/kscience/kmath/memory/Memory; + public abstract fun release ()V + public abstract fun writeByte (IB)V + public abstract fun writeDouble (ID)V + public abstract fun writeFloat (IF)V + public abstract fun writeInt (II)V + public abstract fun writeLong (IJ)V + public abstract fun writeShort (IS)V +} + diff --git a/kmath-memory/build.gradle.kts b/kmath-memory/build.gradle.kts index 9f92cca92..dbd68b042 100644 --- a/kmath-memory/build.gradle.kts +++ b/kmath-memory/build.gradle.kts @@ -1,4 +1,11 @@ plugins { - id("ru.mipt.npm.mpp") - id("ru.mipt.npm.native") + id("ru.mipt.npm.gradle.mpp") + id("ru.mipt.npm.gradle.native") } + +readme{ + description = """ + An API and basic implementation for arranging objects in a continous memory block. + """.trimIndent() + maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT +} \ No newline at end of file diff --git a/kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/Memory.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt similarity index 98% rename from kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/Memory.kt rename to kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt index 344a1f1d3..a18d25f7b 100644 --- a/kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/Memory.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt @@ -1,4 +1,4 @@ -package kscience.kmath.memory +package space.kscience.kmath.memory import kotlin.contracts.InvocationKind import kotlin.contracts.contract diff --git a/kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/MemorySpec.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt similarity index 97% rename from kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/MemorySpec.kt rename to kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt index 572dab0fa..7c68e3abb 100644 --- a/kmath-memory/src/commonMain/kotlin/kscience/kmath/memory/MemorySpec.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt @@ -1,4 +1,4 @@ -package kscience.kmath.memory +package space.kscience.kmath.memory /** * A specification to read or write custom objects with fixed size in bytes. diff --git a/kmath-memory/src/jsMain/kotlin/kscience/kmath/memory/DataViewMemory.kt b/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt similarity index 98% rename from kmath-memory/src/jsMain/kotlin/kscience/kmath/memory/DataViewMemory.kt rename to kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt index 2146cd4e1..38ea8a62e 100644 --- a/kmath-memory/src/jsMain/kotlin/kscience/kmath/memory/DataViewMemory.kt +++ b/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt @@ -1,4 +1,4 @@ -package kscience.kmath.memory +package space.kscience.kmath.memory import org.khronos.webgl.ArrayBuffer import org.khronos.webgl.DataView diff --git a/kmath-memory/src/jvmMain/kotlin/kscience/kmath/memory/ByteBufferMemory.kt b/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt similarity index 99% rename from kmath-memory/src/jvmMain/kotlin/kscience/kmath/memory/ByteBufferMemory.kt rename to kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt index 7a75b423e..5145b1ed4 100644 --- a/kmath-memory/src/jvmMain/kotlin/kscience/kmath/memory/ByteBufferMemory.kt +++ b/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt @@ -1,4 +1,4 @@ -package kscience.kmath.memory +package space.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/space/kscience/kmath/memory/NativeMemory.kt similarity index 98% rename from kmath-memory/src/nativeMain/kotlin/kscience/kmath/memory/NativeMemory.kt rename to kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt index 0e007a8ab..3afb6c7a2 100644 --- a/kmath-memory/src/nativeMain/kotlin/kscience/kmath/memory/NativeMemory.kt +++ b/kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt @@ -1,4 +1,4 @@ -package kscience.kmath.memory +package space.kscience.kmath.memory @PublishedApi internal class NativeMemory( diff --git a/kmath-nd4j/README.md b/kmath-nd4j/README.md index 0176c69dd..046c8127f 100644 --- a/kmath-nd4j/README.md +++ b/kmath-nd4j/README.md @@ -9,7 +9,7 @@ This subproject implements the following features: > #### Artifact: > -> This module artifact: `kscience.kmath:kmath-nd4j:0.2.0-dev-5`. +> This module artifact: `space.kscience:kmath-nd4j:0.2.0`. > > Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-nd4j/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-nd4j/_latestVersion) > @@ -19,29 +19,32 @@ This subproject implements the following features: > > ```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://repo.kotlin.link' } > maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> +> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } // include for builds based on kotlin-eap +>// Uncomment if repo.kotlin.link is unavailable +>// maven { url 'https://dl.bintray.com/mipt-npm/kscience' } +>// maven { url 'https://dl.bintray.com/mipt-npm/dev' } > } > > dependencies { -> implementation 'kscience.kmath:kmath-nd4j:0.2.0-dev-5' +> implementation 'space.kscience:kmath-nd4j:0.2.0' > } > ``` > **Gradle Kotlin DSL:** > > ```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") +> maven("https://repo.kotlin.link") +> maven("https://dl.bintray.com/kotlin/kotlin-eap") // include for builds based on kotlin-eap +> maven("https://dl.bintray.com/hotkeytlt/maven") // required for a +>// Uncomment if repo.kotlin.link is unavailable +>// maven("https://dl.bintray.com/mipt-npm/kscience") +>// maven("https://dl.bintray.com/mipt-npm/dev") > } > > dependencies { -> implementation("kscience.kmath:kmath-nd4j:0.2.0-dev-5") +> implementation("space.kscience:kmath-nd4j:0.2.0") > } > ``` diff --git a/kmath-nd4j/build.gradle.kts b/kmath-nd4j/build.gradle.kts index 391727c45..c801f8e51 100644 --- a/kmath-nd4j/build.gradle.kts +++ b/kmath-nd4j/build.gradle.kts @@ -1,7 +1,7 @@ import ru.mipt.npm.gradle.Maturity plugins { - id("ru.mipt.npm.jvm") + id("ru.mipt.npm.gradle.jvm") } dependencies { diff --git a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayAlgebra.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebra.kt similarity index 61% rename from kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayAlgebra.kt rename to kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebra.kt index db2a44861..1e9818a4a 100644 --- a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayAlgebra.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebra.kt @@ -1,13 +1,18 @@ -package kscience.kmath.nd4j +package space.kscience.kmath.nd4j -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.* -import kscience.kmath.structures.NDAlgebra -import kscience.kmath.structures.NDField -import kscience.kmath.structures.NDRing -import kscience.kmath.structures.NDSpace import org.nd4j.linalg.api.ndarray.INDArray import org.nd4j.linalg.factory.Nd4j +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.* + +internal fun NDAlgebra<*, *>.checkShape(array: INDArray): INDArray { + val arrayShape = array.shape().toIntArray() + if (!shape.contentEquals(arrayShape)) throw ShapeMismatchException(shape, arrayShape) + return array +} + /** * Represents [NDAlgebra] over [Nd4jArrayAlgebra]. @@ -15,41 +20,49 @@ import org.nd4j.linalg.factory.Nd4j * @param T the type of ND-structure element. * @param C the type of the element context. */ -public interface Nd4jArrayAlgebra : NDAlgebra> { +public interface Nd4jArrayAlgebra : NDAlgebra { /** * Wraps [INDArray] to [N]. */ public fun INDArray.wrap(): Nd4jArrayStructure + public val NDStructure.ndArray: INDArray + get() = when { + !shape.contentEquals(this@Nd4jArrayAlgebra.shape) -> throw ShapeMismatchException( + this@Nd4jArrayAlgebra.shape, + shape + ) + this is Nd4jArrayStructure -> ndArray //TODO check strides + else -> { + TODO() + } + } + public override fun produce(initializer: C.(IntArray) -> T): Nd4jArrayStructure { val struct = Nd4j.create(*shape)!!.wrap() struct.indicesIterator().forEach { struct[it] = elementContext.initializer(it) } return struct } - public override fun map(arg: Nd4jArrayStructure, transform: C.(T) -> T): Nd4jArrayStructure { - check(arg) - val newStruct = arg.ndArray.dup().wrap() + public override fun NDStructure.map(transform: C.(T) -> T): Nd4jArrayStructure { + val newStruct = ndArray.dup().wrap() newStruct.elements().forEach { (idx, value) -> newStruct[idx] = elementContext.transform(value) } return newStruct } - public override fun mapIndexed( - arg: Nd4jArrayStructure, + public override fun NDStructure.mapIndexed( transform: C.(index: IntArray, T) -> T, ): Nd4jArrayStructure { - check(arg) - val new = Nd4j.create(*shape).wrap() - new.indicesIterator().forEach { idx -> new[idx] = elementContext.transform(idx, arg[idx]) } + val new = Nd4j.create(*this@Nd4jArrayAlgebra.shape).wrap() + new.indicesIterator().forEach { idx -> new[idx] = elementContext.transform(idx, this[idx]) } return new } public override fun combine( - a: Nd4jArrayStructure, - b: Nd4jArrayStructure, + a: NDStructure, + b: NDStructure, transform: C.(T, T) -> T, ): Nd4jArrayStructure { - check(a, b) val new = Nd4j.create(*shape).wrap() new.indicesIterator().forEach { idx -> new[idx] = elementContext.transform(a[idx], b[idx]) } return new @@ -62,38 +75,32 @@ public interface Nd4jArrayAlgebra : NDAlgebra> * @param T the type of the element contained in ND structure. * @param S the type of space of structure elements. */ -public interface Nd4jArraySpace> : NDSpace>, Nd4jArrayAlgebra { +public interface Nd4jArraySpace> : NDSpace, Nd4jArrayAlgebra { public override val zero: Nd4jArrayStructure get() = Nd4j.zeros(*shape).wrap() - public override fun add(a: Nd4jArrayStructure, b: Nd4jArrayStructure): Nd4jArrayStructure { - check(a, b) + public override fun add(a: NDStructure, b: NDStructure): Nd4jArrayStructure { return a.ndArray.add(b.ndArray).wrap() } - public override operator fun Nd4jArrayStructure.minus(b: Nd4jArrayStructure): Nd4jArrayStructure { - check(this, b) + public override operator fun NDStructure.minus(b: NDStructure): Nd4jArrayStructure { return ndArray.sub(b.ndArray).wrap() } - public override operator fun Nd4jArrayStructure.unaryMinus(): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.unaryMinus(): Nd4jArrayStructure { return ndArray.neg().wrap() } - public override fun multiply(a: Nd4jArrayStructure, k: Number): Nd4jArrayStructure { - check(a) + public override fun multiply(a: NDStructure, k: Number): Nd4jArrayStructure { return a.ndArray.mul(k).wrap() } - public override operator fun Nd4jArrayStructure.div(k: Number): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.div(k: Number): Nd4jArrayStructure { return ndArray.div(k).wrap() } - public override operator fun Nd4jArrayStructure.times(k: Number): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.times(k: Number): Nd4jArrayStructure { return ndArray.mul(k).wrap() } } @@ -105,13 +112,12 @@ public interface Nd4jArraySpace> : NDSpace> : NDRing>, Nd4jArraySpace { +public interface Nd4jArrayRing> : NDRing, Nd4jArraySpace { public override val one: Nd4jArrayStructure get() = Nd4j.ones(*shape).wrap() - public override fun multiply(a: Nd4jArrayStructure, b: Nd4jArrayStructure): Nd4jArrayStructure { - check(a, b) + public override fun multiply(a: NDStructure, b: NDStructure): Nd4jArrayStructure { return a.ndArray.mul(b.ndArray).wrap() } // @@ -168,17 +174,12 @@ public interface Nd4jArrayRing> : NDRing> : NDField>, Nd4jArrayRing { +public interface Nd4jArrayField> : NDField, Nd4jArrayRing { - public override fun divide(a: Nd4jArrayStructure, b: Nd4jArrayStructure): Nd4jArrayStructure { - check(a, b) - return a.ndArray.div(b.ndArray).wrap() - } + public override fun divide(a: NDStructure, b: NDStructure): Nd4jArrayStructure = + a.ndArray.div(b.ndArray).wrap() - public override operator fun Number.div(b: Nd4jArrayStructure): Nd4jArrayStructure { - check(b) - return b.ndArray.rdiv(this).wrap() - } + public override operator fun Number.div(b: NDStructure): Nd4jArrayStructure = b.ndArray.rdiv(this).wrap() public companion object { @@ -219,35 +220,29 @@ public class RealNd4jArrayField(public override val shape: IntArray) : Nd4jArray public override val elementContext: RealField get() = RealField - public override fun INDArray.wrap(): Nd4jArrayStructure = check(asRealStructure()) + public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asRealStructure() - public override operator fun Nd4jArrayStructure.div(arg: Double): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.div(arg: Double): Nd4jArrayStructure { return ndArray.div(arg).wrap() } - public override operator fun Nd4jArrayStructure.plus(arg: Double): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.plus(arg: Double): Nd4jArrayStructure { return ndArray.add(arg).wrap() } - public override operator fun Nd4jArrayStructure.minus(arg: Double): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.minus(arg: Double): Nd4jArrayStructure { return ndArray.sub(arg).wrap() } - public override operator fun Nd4jArrayStructure.times(arg: Double): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.times(arg: Double): Nd4jArrayStructure { return ndArray.mul(arg).wrap() } - public override operator fun Double.div(arg: Nd4jArrayStructure): Nd4jArrayStructure { - check(arg) + public override operator fun Double.div(arg: NDStructure): Nd4jArrayStructure { return arg.ndArray.rdiv(this).wrap() } - public override operator fun Double.minus(arg: Nd4jArrayStructure): Nd4jArrayStructure { - check(arg) + public override operator fun Double.minus(arg: NDStructure): Nd4jArrayStructure { return arg.ndArray.rsub(this).wrap() } } @@ -259,35 +254,29 @@ public class FloatNd4jArrayField(public override val shape: IntArray) : Nd4jArra public override val elementContext: FloatField get() = FloatField - public override fun INDArray.wrap(): Nd4jArrayStructure = check(asFloatStructure()) + public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asFloatStructure() - public override operator fun Nd4jArrayStructure.div(arg: Float): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.div(arg: Float): Nd4jArrayStructure { return ndArray.div(arg).wrap() } - public override operator fun Nd4jArrayStructure.plus(arg: Float): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.plus(arg: Float): Nd4jArrayStructure { return ndArray.add(arg).wrap() } - public override operator fun Nd4jArrayStructure.minus(arg: Float): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.minus(arg: Float): Nd4jArrayStructure { return ndArray.sub(arg).wrap() } - public override operator fun Nd4jArrayStructure.times(arg: Float): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.times(arg: Float): Nd4jArrayStructure { return ndArray.mul(arg).wrap() } - public override operator fun Float.div(arg: Nd4jArrayStructure): Nd4jArrayStructure { - check(arg) + public override operator fun Float.div(arg: NDStructure): Nd4jArrayStructure { return arg.ndArray.rdiv(this).wrap() } - public override operator fun Float.minus(arg: Nd4jArrayStructure): Nd4jArrayStructure { - check(arg) + public override operator fun Float.minus(arg: NDStructure): Nd4jArrayStructure { return arg.ndArray.rsub(this).wrap() } } @@ -299,25 +288,21 @@ public class IntNd4jArrayRing(public override val shape: IntArray) : Nd4jArrayRi public override val elementContext: IntRing get() = IntRing - public override fun INDArray.wrap(): Nd4jArrayStructure = check(asIntStructure()) + public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asIntStructure() - public override operator fun Nd4jArrayStructure.plus(arg: Int): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.plus(arg: Int): Nd4jArrayStructure { return ndArray.add(arg).wrap() } - public override operator fun Nd4jArrayStructure.minus(arg: Int): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.minus(arg: Int): Nd4jArrayStructure { return ndArray.sub(arg).wrap() } - public override operator fun Nd4jArrayStructure.times(arg: Int): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.times(arg: Int): Nd4jArrayStructure { return ndArray.mul(arg).wrap() } - public override operator fun Int.minus(arg: Nd4jArrayStructure): Nd4jArrayStructure { - check(arg) + public override operator fun Int.minus(arg: NDStructure): Nd4jArrayStructure { return arg.ndArray.rsub(this).wrap() } } @@ -329,25 +314,21 @@ public class LongNd4jArrayRing(public override val shape: IntArray) : Nd4jArrayR public override val elementContext: LongRing get() = LongRing - public override fun INDArray.wrap(): Nd4jArrayStructure = check(asLongStructure()) + public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asLongStructure() - public override operator fun Nd4jArrayStructure.plus(arg: Long): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.plus(arg: Long): Nd4jArrayStructure { return ndArray.add(arg).wrap() } - public override operator fun Nd4jArrayStructure.minus(arg: Long): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.minus(arg: Long): Nd4jArrayStructure { return ndArray.sub(arg).wrap() } - public override operator fun Nd4jArrayStructure.times(arg: Long): Nd4jArrayStructure { - check(this) + public override operator fun NDStructure.times(arg: Long): Nd4jArrayStructure { return ndArray.mul(arg).wrap() } - public override operator fun Long.minus(arg: Nd4jArrayStructure): Nd4jArrayStructure { - check(arg) + public override operator fun Long.minus(arg: NDStructure): Nd4jArrayStructure { return arg.ndArray.rsub(this).wrap() } } diff --git a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayIterator.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayIterator.kt similarity index 98% rename from kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayIterator.kt rename to kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayIterator.kt index 1463a92fe..521c8cab3 100644 --- a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayIterator.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayIterator.kt @@ -1,4 +1,4 @@ -package kscience.kmath.nd4j +package space.kscience.kmath.nd4j import org.nd4j.linalg.api.ndarray.INDArray import org.nd4j.linalg.api.shape.Shape diff --git a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayStructure.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt similarity index 95% rename from kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayStructure.kt rename to kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt index d47a293c3..415c908a8 100644 --- a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayStructure.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt @@ -1,8 +1,8 @@ -package kscience.kmath.nd4j +package space.kscience.kmath.nd4j -import kscience.kmath.structures.MutableNDStructure -import kscience.kmath.structures.NDStructure import org.nd4j.linalg.api.ndarray.INDArray +import space.kscience.kmath.nd.MutableNDStructure +import space.kscience.kmath.nd.NDStructure /** * Represents a [NDStructure] wrapping an [INDArray] object. diff --git a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/arrays.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt similarity index 83% rename from kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/arrays.kt rename to kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt index 798f81c35..519c660e8 100644 --- a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/arrays.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt @@ -1,4 +1,4 @@ -package kscience.kmath.nd4j +package space.kscience.kmath.nd4j internal fun IntArray.toLongArray(): LongArray = LongArray(size) { this[it].toLong() } internal fun LongArray.toIntArray(): IntArray = IntArray(size) { this[it].toInt() } diff --git a/kmath-nd4j/src/test/kotlin/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt b/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt similarity index 77% rename from kmath-nd4j/src/test/kotlin/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt rename to kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt index 650d5670c..9a067aa29 100644 --- a/kmath-nd4j/src/test/kotlin/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt +++ b/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt @@ -1,7 +1,6 @@ -package kscience.kmath.nd4j +package space.kscience.kmath.nd4j import org.nd4j.linalg.factory.Nd4j -import kscience.kmath.operations.invoke import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.fail @@ -9,7 +8,7 @@ import kotlin.test.fail internal class Nd4jArrayAlgebraTest { @Test fun testProduce() { - val res = (RealNd4jArrayField(intArrayOf(2, 2))) { produce { it.sum().toDouble() } } + val res = with(RealNd4jArrayField(intArrayOf(2, 2))){ produce { it.sum().toDouble() } } val expected = (Nd4j.create(2, 2) ?: fail()).asRealStructure() expected[intArrayOf(0, 0)] = 0.0 expected[intArrayOf(0, 1)] = 1.0 @@ -20,7 +19,7 @@ internal class Nd4jArrayAlgebraTest { @Test fun testMap() { - val res = (IntNd4jArrayRing(intArrayOf(2, 2))) { map(one) { it + it * 2 } } + val res = with(IntNd4jArrayRing(intArrayOf(2, 2))) { one.map() { it + it * 2 } } val expected = (Nd4j.create(2, 2) ?: fail()).asIntStructure() expected[intArrayOf(0, 0)] = 3 expected[intArrayOf(0, 1)] = 3 @@ -31,7 +30,7 @@ internal class Nd4jArrayAlgebraTest { @Test fun testAdd() { - val res = (IntNd4jArrayRing(intArrayOf(2, 2))) { one + 25 } + val res = with(IntNd4jArrayRing(intArrayOf(2, 2))) { one + 25 } val expected = (Nd4j.create(2, 2) ?: fail()).asIntStructure() expected[intArrayOf(0, 0)] = 26 expected[intArrayOf(0, 1)] = 26 diff --git a/kmath-nd4j/src/test/kotlin/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt b/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt similarity index 96% rename from kmath-nd4j/src/test/kotlin/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt rename to kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt index 7e46211c1..03369127d 100644 --- a/kmath-nd4j/src/test/kotlin/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt +++ b/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt @@ -1,7 +1,7 @@ -package kscience.kmath.nd4j +package space.kscience.kmath.nd4j -import kscience.kmath.structures.get import org.nd4j.linalg.factory.Nd4j +import space.kscience.kmath.nd.get import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/kmath-stat/build.gradle.kts b/kmath-stat/build.gradle.kts index 186aff944..67a96937c 100644 --- a/kmath-stat/build.gradle.kts +++ b/kmath-stat/build.gradle.kts @@ -1,8 +1,16 @@ plugins { - id("ru.mipt.npm.mpp") + id("ru.mipt.npm.gradle.mpp") } kotlin.sourceSets { + all { + languageSettings.apply { + useExperimentalAnnotation("kotlinx.coroutines.FlowPreview") + useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi") + useExperimentalAnnotation("kotlinx.coroutines.ObsoleteCoroutinesApi") + } + } + commonMain { dependencies { api(project(":kmath-coroutines")) @@ -16,3 +24,7 @@ kotlin.sourceSets { } } } + +readme{ + maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL +} \ No newline at end of file diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Distribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt similarity index 90% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Distribution.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt index c4ceb29eb..fa38dd9e4 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Distribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat -import kscience.kmath.chains.Chain -import kscience.kmath.chains.collect -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.BufferFactory +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.chains.collect +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory public interface Sampler { public fun sample(generator: RandomGenerator): Chain diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/FactorizedDistribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/FactorizedDistribution.kt similarity index 92% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/FactorizedDistribution.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/FactorizedDistribution.kt index 1ed9deba9..ff7a13652 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/FactorizedDistribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/FactorizedDistribution.kt @@ -1,7 +1,7 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat -import kscience.kmath.chains.Chain -import kscience.kmath.chains.SimpleChain +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.chains.SimpleChain /** * A multivariate distribution which takes a map of parameters diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Fitting.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Fitting.kt similarity index 89% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Fitting.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Fitting.kt index 9d4655df2..b006c8ba2 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Fitting.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Fitting.kt @@ -1,9 +1,9 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat -import kscience.kmath.expressions.* -import kscience.kmath.operations.ExtendedField -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.indices +import space.kscience.kmath.expressions.* +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.indices import kotlin.math.pow public object Fitting { diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/MCScope.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/MCScope.kt similarity index 98% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/MCScope.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/MCScope.kt index 5dc567db8..d89d74914 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/MCScope.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/MCScope.kt @@ -1,4 +1,4 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/OptimizationProblem.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/OptimizationProblem.kt similarity index 93% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/OptimizationProblem.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/OptimizationProblem.kt index 0f3cd9dd9..71f3096de 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/OptimizationProblem.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/OptimizationProblem.kt @@ -1,8 +1,8 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat -import kscience.kmath.expressions.DifferentiableExpression -import kscience.kmath.expressions.Expression -import kscience.kmath.expressions.Symbol +import space.kscience.kmath.expressions.DifferentiableExpression +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.Symbol public interface OptimizationFeature diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/RandomChain.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomChain.kt similarity index 85% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/RandomChain.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomChain.kt index 0f10851b9..881eabdac 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/RandomChain.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomChain.kt @@ -1,6 +1,6 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat -import kscience.kmath.chains.Chain +import space.kscience.kmath.chains.Chain /** * A possibly stateful chain producing random values. diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/RandomGenerator.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomGenerator.kt similarity index 96% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/RandomGenerator.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomGenerator.kt index 4486ae016..1a4f3b75d 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/RandomGenerator.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomGenerator.kt @@ -1,4 +1,4 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlin.random.Random @@ -83,7 +83,7 @@ public interface RandomGenerator { /** * Implements [RandomGenerator] by delegating all operations to [Random]. */ -public inline class DefaultGenerator(public val random: Random = Random) : RandomGenerator { +public class DefaultGenerator(public val random: Random = Random) : RandomGenerator { public override fun nextBoolean(): Boolean = random.nextBoolean() public override fun nextDouble(): Double = random.nextDouble() public override fun nextInt(): Int = random.nextInt() diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/SamplerAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt similarity index 77% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/SamplerAlgebra.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt index f416028a5..9fed91e1f 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/SamplerAlgebra.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt @@ -1,11 +1,11 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat -import kscience.kmath.chains.Chain -import kscience.kmath.chains.ConstantChain -import kscience.kmath.chains.map -import kscience.kmath.chains.zip -import kscience.kmath.operations.Space -import kscience.kmath.operations.invoke +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.chains.ConstantChain +import space.kscience.kmath.chains.map +import space.kscience.kmath.chains.zip +import space.kscience.kmath.operations.Space +import space.kscience.kmath.operations.invoke public class BasicSampler(public val chainBuilder: (RandomGenerator) -> Chain) : Sampler { public override fun sample(generator: RandomGenerator): Chain = chainBuilder(generator) diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Statistic.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt similarity index 92% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Statistic.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt index a4624fc21..29ded2b88 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Statistic.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt @@ -1,4 +1,4 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers @@ -7,11 +7,11 @@ import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.runningReduce -import kscience.kmath.coroutines.mapParallel -import kscience.kmath.operations.* -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.asIterable -import kscience.kmath.structures.asSequence +import space.kscience.kmath.coroutines.mapParallel +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asIterable +import space.kscience.kmath.structures.asSequence /** * A function, that transforms a buffer of random quantities to some resulting value diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/UniformDistribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/UniformDistribution.kt similarity index 85% rename from kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/UniformDistribution.kt rename to kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/UniformDistribution.kt index 1ba5c96f1..4fc0905b8 100644 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/UniformDistribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/UniformDistribution.kt @@ -1,7 +1,7 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat -import kscience.kmath.chains.Chain -import kscience.kmath.chains.SimpleChain +import space.kscience.kmath.chains.Chain +import space.kscience.kmath.chains.SimpleChain public class UniformDistribution(public val range: ClosedFloatingPointRange) : UnivariateDistribution { private val length: Double = range.endInclusive - range.start diff --git a/kmath-stat/src/jvmMain/kotlin/kscience/kmath/stat/RandomSourceGenerator.kt b/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/RandomSourceGenerator.kt similarity index 98% rename from kmath-stat/src/jvmMain/kotlin/kscience/kmath/stat/RandomSourceGenerator.kt rename to kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/RandomSourceGenerator.kt index 5cba28a95..9e752d571 100644 --- a/kmath-stat/src/jvmMain/kotlin/kscience/kmath/stat/RandomSourceGenerator.kt +++ b/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/RandomSourceGenerator.kt @@ -1,4 +1,4 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import org.apache.commons.rng.UniformRandomProvider import org.apache.commons.rng.simple.RandomSource diff --git a/kmath-stat/src/jvmMain/kotlin/kscience/kmath/stat/distributions.kt b/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/distributions.kt similarity index 95% rename from kmath-stat/src/jvmMain/kotlin/kscience/kmath/stat/distributions.kt rename to kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/distributions.kt index 6cc18a37c..d33b54818 100644 --- a/kmath-stat/src/jvmMain/kotlin/kscience/kmath/stat/distributions.kt +++ b/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/distributions.kt @@ -1,10 +1,10 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat -import kscience.kmath.chains.BlockingIntChain -import kscience.kmath.chains.BlockingRealChain -import kscience.kmath.chains.Chain import org.apache.commons.rng.UniformRandomProvider import org.apache.commons.rng.sampling.distribution.* +import space.kscience.kmath.chains.BlockingIntChain +import space.kscience.kmath.chains.BlockingRealChain +import space.kscience.kmath.chains.Chain import kotlin.math.PI import kotlin.math.exp import kotlin.math.pow diff --git a/kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/CommonsDistributionsTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt similarity index 96% rename from kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/CommonsDistributionsTest.kt rename to kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt index fe58fac08..70708a5c8 100644 --- a/kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/CommonsDistributionsTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt @@ -1,4 +1,4 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList diff --git a/kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/MCScopeTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt similarity index 97% rename from kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/MCScopeTest.kt rename to kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt index 4e29e6105..9eada43f9 100644 --- a/kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/MCScopeTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt @@ -1,8 +1,7 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.* import java.util.* -import kotlin.collections.HashSet import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/SamplerTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/SamplerTest.kt similarity index 91% rename from kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/SamplerTest.kt rename to kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/SamplerTest.kt index afed4c5d0..244b5107f 100644 --- a/kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/SamplerTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/SamplerTest.kt @@ -1,4 +1,4 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.runBlocking import kotlin.test.Test diff --git a/kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/StatisticTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt similarity index 90% rename from kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/StatisticTest.kt rename to kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt index 5cee4d172..156e618f9 100644 --- a/kmath-stat/src/jvmTest/kotlin/kscience/kmath/stat/StatisticTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt @@ -1,10 +1,10 @@ -package kscience.kmath.stat +package space.kscience.kmath.stat import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking -import kscience.kmath.streaming.chunked +import space.kscience.kmath.streaming.chunked import kotlin.test.Test internal class StatisticTest { diff --git a/kmath-viktor/api/kmath-viktor.api b/kmath-viktor/api/kmath-viktor.api new file mode 100644 index 000000000..462e065bf --- /dev/null +++ b/kmath-viktor/api/kmath-viktor.api @@ -0,0 +1,184 @@ +public final class space/kscience/kmath/viktor/ViktorBuffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lspace/kscience/kmath/viktor/ViktorBuffer; + public static fun constructor-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lorg/jetbrains/bio/viktor/F64FlatArray; + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;Lspace/kscience/kmath/structures/Buffer;)Z + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static fun copy-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lspace/kscience/kmath/structures/MutableBuffer; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Lorg/jetbrains/bio/viktor/F64FlatArray;Lorg/jetbrains/bio/viktor/F64FlatArray;)Z + public fun get (I)Ljava/lang/Double; + public synthetic fun get (I)Ljava/lang/Object; + public static fun get-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;I)Ljava/lang/Double; + public final fun getFlatArray ()Lorg/jetbrains/bio/viktor/F64FlatArray; + public fun getSize ()I + public static fun getSize-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)I + public fun hashCode ()I + public static fun hashCode-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)I + public fun iterator ()Ljava/util/Iterator; + public static fun iterator-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Ljava/util/Iterator; + public fun set (ID)V + public synthetic fun set (ILjava/lang/Object;)V + public static fun set-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;ID)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Lorg/jetbrains/bio/viktor/F64FlatArray; +} + +public final class space/kscience/kmath/viktor/ViktorNDField : space/kscience/kmath/nd/NDField, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/RingWithNumbers { + public fun ([I)V + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos-Q7Xurp0 (Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun add (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun add-s8yP2C4 (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin-Q7Xurp0 (Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan-Q7Xurp0 (Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun combine (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDStructure; + public fun combine-ZQYDhZg (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos-Q7Xurp0 (Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun div (DLspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun div (Lspace/kscience/kmath/nd/NDStructure;D)Lspace/kscience/kmath/nd/NDStructure; + public fun div (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun div (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public fun div (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp-Q7Xurp0 (Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun getElementContext ()Ljava/lang/Object; + public fun getElementContext ()Lspace/kscience/kmath/operations/RealField; + public final fun getF64Buffer (Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne-MSOxzaI ()Lorg/jetbrains/bio/viktor/F64Array; + public fun getShape ()[I + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero-MSOxzaI ()Lorg/jetbrains/bio/viktor/F64Array; + public fun invoke (Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln-Q7Xurp0 (Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun map (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDStructure; + public fun map-s8yP2C4 (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDStructure; + public fun mapIndexed-s8yP2C4 (Lspace/kscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lorg/jetbrains/bio/viktor/F64Array; + public fun minus (DLspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun minus (Lspace/kscience/kmath/nd/NDStructure;D)Lspace/kscience/kmath/nd/NDStructure; + public fun minus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun minus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public fun minus-s8yP2C4 (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun multiply (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public fun multiply (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun multiply-s8yP2C4 (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number-Q7Xurp0 (Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; + public fun plus (DLspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun plus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun plus (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public fun plus-s8yP2C4 (Lspace/kscience/kmath/nd/NDStructure;D)Lorg/jetbrains/bio/viktor/F64Array; + public fun plus-s8yP2C4 (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power-s8yP2C4 (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDStructure; + public fun produce-Q7Xurp0 (Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDStructure; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin-Q7Xurp0 (Lspace/kscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun times (DLspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun times (Lspace/kscience/kmath/nd/NDStructure;D)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun times (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lspace/kscience/kmath/nd/NDStructure; + public fun times (Lspace/kscience/kmath/nd/NDStructure;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun times-s8yP2C4 (Lspace/kscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/nd/NDStructure;)Lspace/kscience/kmath/nd/NDStructure; +} + +public final class space/kscience/kmath/viktor/ViktorNDStructure : space/kscience/kmath/nd/MutableNDStructure { + public static final synthetic fun box-impl (Lorg/jetbrains/bio/viktor/F64Array;)Lspace/kscience/kmath/viktor/ViktorNDStructure; + public static fun constructor-impl (Lorg/jetbrains/bio/viktor/F64Array;)Lorg/jetbrains/bio/viktor/F64Array; + public fun elements ()Lkotlin/sequences/Sequence; + public static fun elements-impl (Lorg/jetbrains/bio/viktor/F64Array;)Lkotlin/sequences/Sequence; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Lorg/jetbrains/bio/viktor/F64Array;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Lorg/jetbrains/bio/viktor/F64Array;Lorg/jetbrains/bio/viktor/F64Array;)Z + public fun get ([I)Ljava/lang/Double; + public synthetic fun get ([I)Ljava/lang/Object; + public static fun get-impl (Lorg/jetbrains/bio/viktor/F64Array;[I)Ljava/lang/Double; + public fun getDimension ()I + public static fun getDimension-impl (Lorg/jetbrains/bio/viktor/F64Array;)I + public final fun getF64Buffer ()Lorg/jetbrains/bio/viktor/F64Array; + public fun getShape ()[I + public static fun getShape-impl (Lorg/jetbrains/bio/viktor/F64Array;)[I + public fun hashCode ()I + public static fun hashCode-impl (Lorg/jetbrains/bio/viktor/F64Array;)I + public fun set ([ID)V + public synthetic fun set ([ILjava/lang/Object;)V + public static fun set-impl (Lorg/jetbrains/bio/viktor/F64Array;[ID)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Lorg/jetbrains/bio/viktor/F64Array;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Lorg/jetbrains/bio/viktor/F64Array; +} + +public final class space/kscience/kmath/viktor/ViktorNDStructureKt { + public static final fun ViktorNDField ([I)Lspace/kscience/kmath/viktor/ViktorNDField; + public static final fun asStructure (Lorg/jetbrains/bio/viktor/F64Array;)Lorg/jetbrains/bio/viktor/F64Array; +} + diff --git a/kmath-viktor/build.gradle.kts b/kmath-viktor/build.gradle.kts index 3e5c5912c..b79a25ea1 100644 --- a/kmath-viktor/build.gradle.kts +++ b/kmath-viktor/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("ru.mipt.npm.jvm") + id("ru.mipt.npm.gradle.jvm") } description = "Binding for https://github.com/JetBrains-Research/viktor" @@ -8,3 +8,7 @@ dependencies { api(project(":kmath-core")) api("org.jetbrains.bio:viktor:1.0.1") } + +readme{ + maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT +} \ No newline at end of file diff --git a/kmath-viktor/src/main/kotlin/kscience/kmath/viktor/ViktorNDStructure.kt b/kmath-viktor/src/main/kotlin/kscience/kmath/viktor/ViktorNDStructure.kt deleted file mode 100644 index 2471362cb..000000000 --- a/kmath-viktor/src/main/kotlin/kscience/kmath/viktor/ViktorNDStructure.kt +++ /dev/null @@ -1,88 +0,0 @@ -package kscience.kmath.viktor - -import kscience.kmath.operations.RealField -import kscience.kmath.structures.DefaultStrides -import kscience.kmath.structures.MutableNDStructure -import kscience.kmath.structures.NDField -import kscience.kmath.structures.Strides -import org.jetbrains.bio.viktor.F64Array - -@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") -public inline class ViktorNDStructure(public val f64Buffer: F64Array) : MutableNDStructure { - public override val shape: IntArray get() = f64Buffer.shape - - public override inline fun get(index: IntArray): Double = f64Buffer.get(*index) - - public override inline fun set(index: IntArray, value: Double) { - f64Buffer.set(*index, value = value) - } - - public override fun elements(): Sequence> = - DefaultStrides(shape).indices().map { it to get(it) } -} - -public fun F64Array.asStructure(): ViktorNDStructure = ViktorNDStructure(this) - -@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") -public class ViktorNDField(public override val shape: IntArray) : NDField { - public override val zero: ViktorNDStructure - get() = F64Array.full(init = 0.0, shape = shape).asStructure() - - public override val one: ViktorNDStructure - get() = F64Array.full(init = 1.0, shape = shape).asStructure() - - public val strides: Strides = DefaultStrides(shape) - - public override val elementContext: RealField get() = RealField - - public override fun produce(initializer: RealField.(IntArray) -> Double): ViktorNDStructure = - F64Array(*shape).apply { - this@ViktorNDField.strides.indices().forEach { index -> - set(value = RealField.initializer(index), indices = index) - } - }.asStructure() - - public override fun map(arg: ViktorNDStructure, transform: RealField.(Double) -> Double): ViktorNDStructure = - F64Array(*shape).apply { - this@ViktorNDField.strides.indices().forEach { index -> - set(value = RealField.transform(arg[index]), indices = index) - } - }.asStructure() - - public override fun mapIndexed( - arg: ViktorNDStructure, - transform: RealField.(index: IntArray, Double) -> Double - ): ViktorNDStructure = F64Array(*shape).apply { - this@ViktorNDField.strides.indices().forEach { index -> - set(value = RealField.transform(index, arg[index]), indices = index) - } - }.asStructure() - - public override fun combine( - a: ViktorNDStructure, - b: ViktorNDStructure, - transform: RealField.(Double, Double) -> Double - ): ViktorNDStructure = F64Array(*shape).apply { - this@ViktorNDField.strides.indices().forEach { index -> - set(value = RealField.transform(a[index], b[index]), indices = index) - } - }.asStructure() - - public override fun add(a: ViktorNDStructure, b: ViktorNDStructure): ViktorNDStructure = - (a.f64Buffer + b.f64Buffer).asStructure() - - public override fun multiply(a: ViktorNDStructure, k: Number): ViktorNDStructure = - (a.f64Buffer * k.toDouble()).asStructure() - - public override inline fun ViktorNDStructure.plus(b: ViktorNDStructure): ViktorNDStructure = - (f64Buffer + b.f64Buffer).asStructure() - - public override inline fun ViktorNDStructure.minus(b: ViktorNDStructure): ViktorNDStructure = - (f64Buffer - b.f64Buffer).asStructure() - - public override inline fun ViktorNDStructure.times(k: Number): ViktorNDStructure = - (f64Buffer * k.toDouble()).asStructure() - - public override inline fun ViktorNDStructure.plus(arg: Double): ViktorNDStructure = - (f64Buffer.plus(arg)).asStructure() -} \ No newline at end of file diff --git a/kmath-viktor/src/main/kotlin/kscience/kmath/viktor/ViktorBuffer.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt similarity index 87% rename from kmath-viktor/src/main/kotlin/kscience/kmath/viktor/ViktorBuffer.kt rename to kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt index 5c9611758..1592763db 100644 --- a/kmath-viktor/src/main/kotlin/kscience/kmath/viktor/ViktorBuffer.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt @@ -1,7 +1,7 @@ -package kscience.kmath.viktor +package space.kscience.kmath.viktor -import kscience.kmath.structures.MutableBuffer import org.jetbrains.bio.viktor.F64FlatArray +import space.kscience.kmath.structures.MutableBuffer @Suppress("NOTHING_TO_INLINE", "OVERRIDE_BY_INLINE") public inline class ViktorBuffer(public val flatArray: F64FlatArray) : MutableBuffer { diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorNDStructure.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorNDStructure.kt new file mode 100644 index 000000000..8deda2544 --- /dev/null +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorNDStructure.kt @@ -0,0 +1,121 @@ +package space.kscience.kmath.viktor + +import org.jetbrains.bio.viktor.F64Array +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.RingWithNumbers + +@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") +public inline class ViktorNDStructure(public val f64Buffer: F64Array) : MutableNDStructure { + public override val shape: IntArray get() = f64Buffer.shape + + public override inline fun get(index: IntArray): Double = f64Buffer.get(*index) + + public override inline fun set(index: IntArray, value: Double) { + f64Buffer.set(*index, value = value) + } + + public override fun elements(): Sequence> = + DefaultStrides(shape).indices().map { it to get(it) } +} + +public fun F64Array.asStructure(): ViktorNDStructure = ViktorNDStructure(this) + +@OptIn(UnstableKMathAPI::class) +@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") +public class ViktorNDField(public override val shape: IntArray) : NDField, + RingWithNumbers>, ExtendedField> { + + public val NDStructure.f64Buffer: F64Array + get() = when { + !shape.contentEquals(this@ViktorNDField.shape) -> throw ShapeMismatchException( + this@ViktorNDField.shape, + shape + ) + this is ViktorNDStructure && this.f64Buffer.shape.contentEquals(this@ViktorNDField.shape) -> this.f64Buffer + else -> produce { this@f64Buffer[it] }.f64Buffer + } + + public override val zero: ViktorNDStructure + get() = F64Array.full(init = 0.0, shape = shape).asStructure() + + public override val one: ViktorNDStructure + get() = F64Array.full(init = 1.0, shape = shape).asStructure() + + private val strides: Strides = DefaultStrides(shape) + + public override val elementContext: RealField get() = RealField + + public override fun produce(initializer: RealField.(IntArray) -> Double): ViktorNDStructure = + F64Array(*shape).apply { + this@ViktorNDField.strides.indices().forEach { index -> + set(value = RealField.initializer(index), indices = index) + } + }.asStructure() + + public override fun NDStructure.map(transform: RealField.(Double) -> Double): ViktorNDStructure = + F64Array(*this@ViktorNDField.shape).apply { + this@ViktorNDField.strides.indices().forEach { index -> + set(value = RealField.transform(this@map[index]), indices = index) + } + }.asStructure() + + public override fun NDStructure.mapIndexed( + transform: RealField.(index: IntArray, Double) -> Double, + ): ViktorNDStructure = F64Array(*this@ViktorNDField.shape).apply { + this@ViktorNDField.strides.indices().forEach { index -> + set(value = RealField.transform(index, this@mapIndexed[index]), indices = index) + } + }.asStructure() + + public override fun combine( + a: NDStructure, + b: NDStructure, + transform: RealField.(Double, Double) -> Double, + ): ViktorNDStructure = F64Array(*shape).apply { + this@ViktorNDField.strides.indices().forEach { index -> + set(value = RealField.transform(a[index], b[index]), indices = index) + } + }.asStructure() + + public override fun add(a: NDStructure, b: NDStructure): ViktorNDStructure = + (a.f64Buffer + b.f64Buffer).asStructure() + + public override fun multiply(a: NDStructure, k: Number): ViktorNDStructure = + (a.f64Buffer * k.toDouble()).asStructure() + + public override inline fun NDStructure.plus(b: NDStructure): ViktorNDStructure = + (f64Buffer + b.f64Buffer).asStructure() + + public override inline fun NDStructure.minus(b: NDStructure): ViktorNDStructure = + (f64Buffer - b.f64Buffer).asStructure() + + public override inline fun NDStructure.times(k: Number): ViktorNDStructure = + (f64Buffer * k.toDouble()).asStructure() + + public override inline fun NDStructure.plus(arg: Double): ViktorNDStructure = + (f64Buffer.plus(arg)).asStructure() + + override fun number(value: Number): ViktorNDStructure = + F64Array.full(init = value.toDouble(), shape = shape).asStructure() + + override fun sin(arg: NDStructure): ViktorNDStructure = arg.map { sin(it) } + + override fun cos(arg: NDStructure): ViktorNDStructure = arg.map { cos(it) } + + override fun asin(arg: NDStructure): ViktorNDStructure = arg.map { asin(it) } + + override fun acos(arg: NDStructure): ViktorNDStructure = arg.map { acos(it) } + + override fun atan(arg: NDStructure): ViktorNDStructure = arg.map { atan(it) } + + override fun power(arg: NDStructure, pow: Number): ViktorNDStructure = arg.map { it.pow(pow) } + + override fun exp(arg: NDStructure): ViktorNDStructure = arg.f64Buffer.exp().asStructure() + + override fun ln(arg: NDStructure): ViktorNDStructure = arg.f64Buffer.log().asStructure() +} + +public fun ViktorNDField(vararg shape: Int): ViktorNDField = ViktorNDField(shape) \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index a1ea40148..ce6eb339a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,21 +2,20 @@ pluginManagement { repositories { gradlePluginPortal() jcenter() + maven("https://repo.kotlin.link") 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/kotlin/kotlinx") } - val toolsVersion = "0.7.3-1.4.30-RC" - val kotlinVersion = "1.4.30-RC" + val toolsVersion = "0.8.0" + val kotlinVersion = "1.4.30" 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 + id("ru.mipt.npm.gradle.project") version toolsVersion + id("ru.mipt.npm.gradle.mpp") version toolsVersion + id("ru.mipt.npm.gradle.jvm") version toolsVersion + id("ru.mipt.npm.gradle.publish") version toolsVersion kotlin("jvm") version kotlinVersion kotlin("plugin.allopen") version kotlinVersion } @@ -26,9 +25,10 @@ rootProject.name = "kmath" include( ":kmath-memory", + ":kmath-complex", ":kmath-core", - ":kmath-functions", ":kmath-coroutines", + ":kmath-functions", ":kmath-histograms", ":kmath-commons", ":kmath-viktor",