diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 626062abf..25f2cfd0d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,105 +3,34 @@ name: Gradle build on: [ push ] jobs: - build-ubuntu: - runs-on: ubuntu-20.04 - + build: + strategy: + matrix: + os: [ macOS-latest, windows-latest ] + runs-on: ${{matrix.os}} steps: - - uses: actions/checkout@v2 + - name: Checkout the repo + 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 - - 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 - - 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 + if: matrix.os == 'windows-latest' 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 - + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} + 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 + path: ~/.konan + key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Build + run: ./gradlew build --no-daemon --stacktrace diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 000000000..82b0fb303 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,40 @@ +name: Dokka publication + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - name: Checkout the repo + uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache gradle + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ubuntu-20.04-gradle-${{ hashFiles('*.gradle.kts') }} + restore-keys: | + ubuntu-20.04-gradle- + - name: Cache konan + uses: actions/cache@v2 + with: + path: ~/.konan + key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Build + run: | + ./gradlew dokkaHtmlMultiModule --no-daemon --no-parallel --stacktrace + mv build/dokka/htmlMultiModule/-modules.html build/dokka/htmlMultiModule/index.html + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@4.1.0 + with: + branch: gh-pages + folder: build/dokka/htmlMultiModule diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 40b172908..ca374574e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,117 +1,59 @@ -name: Bintray Publish +name: Gradle publish on: + workflow_dispatch: release: types: - created jobs: - build-ubuntu: - runs-on: ubuntu-20.04 - + publish: + environment: + name: publish + strategy: + matrix: + os: [ macOS-latest, windows-latest ] + runs-on: ${{matrix.os}} steps: - - uses: actions/checkout@v2 + - name: Checkout the repo + 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 + if: matrix.os == 'windows-latest' 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 - + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} + 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 }} - + path: ~/.konan + key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Publish Windows Artifacts + if: matrix.os == 'windows-latest' + run: > + ./gradlew release --no-daemon + -Ppublishing.enabled=true + -Ppublishing.github.user=${{ secrets.PUBLISHING_GITHUB_USER }} + -Ppublishing.github.token=${{ secrets.PUBLISHING_GITHUB_TOKEN }} + -Ppublishing.space.user=${{ secrets.PUBLISHING_SPACE_USER }} + -Ppublishing.space.token=${{ secrets.PUBLISHING_SPACE_TOKEN }} + - name: Publish Mac Artifacts + if: matrix.os == 'macOS-latest' + run: > + ./gradlew release --no-daemon + -Ppublishing.enabled=true + -Ppublishing.platform=macosX64 + -Ppublishing.github.user=${{ secrets.PUBLISHING_GITHUB_USER }} + -Ppublishing.github.token=${{ secrets.PUBLISHING_GITHUB_TOKEN }} + -Ppublishing.space.user=${{ secrets.PUBLISHING_SPACE_USER }} + -Ppublishing.space.token=${{ secrets.PUBLISHING_SPACE_TOKEN }} diff --git a/.gitignore b/.gitignore index bade7f08c..07589aa00 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,14 @@ build/ out/ .idea/ +.vscode/ # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar # Cache of project .gradletasknamecache + +# Generated by javac -h and runtime +*.class +*.log diff --git a/CHANGELOG.md b/CHANGELOG.md index 2396c6b27..4ade9cd9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,32 @@ ## [Unreleased] ### Added +- ScaleOperations interface +- Field extends ScaleOperations +- Basic integration API + +### Changed +- Exponential operations merged with hyperbolic functions +- Space is replaced by Group. Space is reserved for vector spaces. +- VectorSpace is now a vector space +- Buffer factories for primitives moved to MutableBuffer.Companion +- NDStructure and NDAlgebra to StructureND and AlgebraND respectively +- Real -> Double +- DataSets are moved from functions to core + +### Deprecated + +### Removed +- Nearest in Domain. To be implemented in geometry package. +- Number multiplication and division in main Algebra chain +- `contentEquals` from Buffer. It moved to the companion. + +### 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) @@ -21,11 +47,11 @@ - 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` @@ -41,6 +67,8 @@ - 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 @@ -50,6 +78,7 @@ - `toGrid` method. - Public visibility of `BufferAccessor2D` - `Real` class +- StructureND identity and equals ### Fixed - `symbol` method in `MstExtendedField` (https://github.com/mipt-npm/kmath/pull/140) diff --git a/README.md b/README.md index 586d2185f..7080c757e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,8 @@ [![JetBrains Research](https://jb.gg/badges/research.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) [![DOI](https://zenodo.org/badge/129486382.svg)](https://zenodo.org/badge/latestdoi/129486382) - ![Gradle build](https://github.com/mipt-npm/kmath/workflows/Gradle%20build/badge.svg) - -Bintray: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-core/_latestVersion) - -Bintray-dev: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-core/_latestVersion) +[![Maven Central](https://img.shields.io/maven-central/v/space.kscience/kmath-core.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22space.kscience%22) +[![Space](https://img.shields.io/maven-metadata/v?label=Space&metadataUrl=https%3A%2F%2Fmaven.pkg.jetbrains.space%2Fmipt-npm%2Fp%2Fsci%2Fmaven%2Fkscience%2Fkmath%2Fkmath-core%2Fmaven-metadata.xml)](https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven/space/kscience/) # KMath @@ -89,12 +86,12 @@ KMath is a modular library. Different modules provide different features with di > **Maturity**: PROTOTYPE > > **Features:** -> - [expression-language](kmath-ast/src/jvmMain/kotlin/kscience/kmath/ast/parser.kt) : Expression language and its parser -> - [mst](kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MST.kt) : MST (Mathematical Syntax Tree) as expression language's syntax intermediate representation -> - [mst-building](kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MstAlgebra.kt) : MST building algebraic structure -> - [mst-interpreter](kmath-ast/src/commonMain/kotlin/kscience/kmath/ast/MST.kt) : MST interpreter -> - [mst-jvm-codegen](kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/asm.kt) : Dynamic MST to JVM bytecode compiler -> - [mst-js-codegen](kmath-ast/src/jsMain/kotlin/kscience/kmath/estree/estree.kt) : Dynamic MST to JS compiler +> - [expression-language](kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt) : Expression language and its parser +> - [mst](kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt) : MST (Mathematical Syntax Tree) as expression language's syntax intermediate representation +> - [mst-building](kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt) : MST building algebraic structure +> - [mst-interpreter](kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt) : MST interpreter +> - [mst-jvm-codegen](kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt) : Dynamic MST to JVM bytecode compiler +> - [mst-js-codegen](kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt) : Dynamic MST to JS compiler
@@ -110,8 +107,8 @@ KMath is a modular library. Different modules provide different features with di > **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 +> - [complex](kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt) : Complex Numbers +> - [quaternion](kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt) : Quaternions
@@ -121,15 +118,15 @@ KMath is a modular library. Different modules provide different features with di > **Maturity**: DEVELOPMENT > > **Features:** -> - [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) : By writing a single mathematical expression once, users will be able to apply different types of +> - [algebras](kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt) : Algebraic structures like rings, spaces and fields. +> - [nd](kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/StructureND.kt) : Many-dimensional structures and operations on them. +> - [linear](kmath-core/src/commonMain/kotlin/space/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/space/kscience/kmath/structures/Buffers.kt) : One-dimensional structure +> - [expressions](kmath-core/src/commonMain/kotlin/space/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 +> - [domains](kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains) : Domains +> - [autodif](kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt) : Automatic differentiation
@@ -149,6 +146,12 @@ performance calculations to code generation. > > > **Maturity**: PROTOTYPE +> +> **Features:** +> - [ejml-vector](kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt) : The Point implementation using SimpleMatrix. +> - [ejml-matrix](kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt) : The Matrix implementation using SimpleMatrix. +> - [ejml-linear-space](kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt) : The LinearSpace implementation using SimpleMatrix. +
* ### [kmath-for-real](kmath-for-real) @@ -159,9 +162,9 @@ One can still use generic algebras though. > **Maturity**: EXPERIMENTAL > > **Features:** -> - [RealVector](kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealVector.kt) : Numpy-like operations for Buffers/Points -> - [RealMatrix](kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealMatrix.kt) : Numpy-like operations for 2d real structures -> - [grids](kmath-for-real/src/commonMain/kotlin/kscience/kmath/structures/grids.kt) : Uniform grid generators +> - [DoubleVector](kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt) : Numpy-like operations for Buffers/Points +> - [DoubleMatrix](kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleMatrix.kt) : Numpy-like operations for 2d real structures +> - [grids](kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/structures/grids.kt) : Uniform grid generators
@@ -171,10 +174,10 @@ One can still use generic algebras though. > **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 +> - [piecewise](kmath-functions/Piecewise functions.) : src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt +> - [polynomials](kmath-functions/Polynomial functions.) : src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt +> - [linear interpolation](kmath-functions/Linear XY interpolator.) : src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt +> - [spline interpolation](kmath-functions/Cubic spline XY interpolator.) : src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt
@@ -208,9 +211,9 @@ One can still use generic algebras though. > **Maturity**: EXPERIMENTAL > > **Features:** -> - [nd4jarraystructure](kmath-nd4j/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : NDStructure wrapper for INDArray -> - [nd4jarrayrings](kmath-nd4j/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Rings over Nd4jArrayStructure of Int and Long -> - [nd4jarrayfields](kmath-nd4j/src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : Fields over Nd4jArrayStructure of Float and Double +> - [nd4jarraystructure](kmath-nd4j/#) : NDStructure wrapper for INDArray +> - [nd4jarrayrings](kmath-nd4j/#) : Rings over Nd4jArrayStructure of Int and Long +> - [nd4jarrayfields](kmath-nd4j/#) : Fields over Nd4jArrayStructure of Float and Double
@@ -247,33 +250,22 @@ better than SciPy. ### Repositories -Release artifacts are accessible from bintray with following configuration (see documentation of -[Kotlin Multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html) for more details): +Release and development artifacts are accessible from mipt-npm [Space](https://www.jetbrains.com/space/) repository `https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven` (see documentation of +[Kotlin Multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html) for more details). The repository could be reached through [repo.kotlin.link](https://repo.kotlin.link) proxy: ```kotlin repositories { - maven("https://dl.bintray.com/mipt-npm/kscience") - // maven("https://dl.bintray.com/mipt-npm/dev") for dev versions + maven("https://repo.kotlin.link") } dependencies { - api("kscience.kmath:kmath-core:0.2.0-dev-7") - // api("kscience.kmath:kmath-core-jvm:0.2.0-dev-7") for jvm-specific version + api("space.kscience:kmath-core:0.3.0-dev-3") + // api("kscience.kmath:kmath-core-jvm:0.3.0-dev-3") for jvm-specific version } ``` Gradle `6.0+` is required for multiplatform artifacts. -#### Development - -Development builds are uploaded to the separate repository: - -```kotlin -repositories { - maven("https://dl.bintray.com/mipt-npm/dev") -} -``` - ## Contributing The project requires a lot of additional work. The most important thing we need is a feedback about what features are diff --git a/build.gradle.kts b/build.gradle.kts index 7fe132315..cc863a957 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,34 +1,49 @@ -import ru.mipt.npm.gradle.KSciencePublishPlugin +import org.jetbrains.dokka.gradle.DokkaTask +import ru.mipt.npm.gradle.KSciencePublishingPlugin +import java.net.URL plugins { - id("ru.mipt.npm.project") + id("ru.mipt.npm.gradle.project") } -internal val kmathVersion: String by extra("0.2.0-dev-7") -internal val bintrayRepo: String by extra("kscience") -internal val githubProject: String by extra("kmath") - allprojects { repositories { jcenter() maven("https://clojars.org/repo") maven("https://dl.bintray.com/egor-bogomolov/astminer/") maven("https://dl.bintray.com/hotkeytlt/maven") - maven("https://dl.bintray.com/kotlin/kotlin-eap") - maven("https://dl.bintray.com/kotlin/kotlinx") - maven("https://dl.bintray.com/mipt-npm/dev") - maven("https://dl.bintray.com/mipt-npm/kscience") maven("https://jitpack.io") maven("http://logicrunch.research.it.uu.se/maven/") mavenCentral() } - group = "kscience.kmath" - version = kmathVersion + group = "space.kscience" + version = "0.3.0-dev-4" } subprojects { - if (name.startsWith("kmath")) apply() + if (name.startsWith("kmath")) apply() + + afterEvaluate { + tasks.withType { + dokkaSourceSets.all { + val readmeFile = File(this@subprojects.projectDir, "./README.md") + if (readmeFile.exists()) + includes.setFrom(includes + readmeFile.absolutePath) + + arrayOf( + "http://ejml.org/javadoc/", + "https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/", + "https://deeplearning4j.org/api/latest/" + ).map { URL("${it}package-list") to URL(it) }.forEach { (a, b) -> + externalDocumentationLink { + packageListUrl.set(a) + url.set(b) + } + } + } + } + } } readme { @@ -36,5 +51,11 @@ readme { } ksciencePublish { - spaceRepo = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven" -} \ No newline at end of file + github("kmath") + space() + sonatype() +} + +apiValidation { + nonPublicMarkers.add("space.kscience.kmath.misc.UnstableKMathAPI") +} diff --git a/docs/algebra.md b/docs/algebra.md index c3227517f..84693bb81 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 = ... @@ -31,7 +31,7 @@ multiplication; - [Ring](http://mathworld.wolfram.com/Ring.html) adds multiplication and its neutral element (i.e. 1); - [Field](http://mathworld.wolfram.com/Field.html) adds division operation. -A typical implementation of `Field` is the `RealField` which works on doubles, and `VectorSpace` for `Space`. +A typical implementation of `Field` is the `DoubleField` which works on doubles, and `VectorSpace` for `Space`. In some cases algebra context can hold additional operations like `exp` or `sin`, and then it inherits appropriate interface. Also, contexts may have operations, which produce elements outside of the context. For example, `Matrix.dot` @@ -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/images/KM.svg b/docs/images/KM.svg index 50126cbc5..83af21f35 100644 --- a/docs/images/KM.svg +++ b/docs/images/KM.svg @@ -13,27 +13,30 @@ version="1.1">image/svg+xml + + + image/svg+xml + + image/svg+xml + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + #### Artifact: -> -> This module artifact: `${group}:${name}:${version}`. -> -> Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/${name}/images/download.svg) ](https://bintray.com/mipt-npm/kscience/${name}/_latestVersion) -> -> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/${name}/images/download.svg) ](https://bintray.com/mipt-npm/dev/${name}/_latestVersion) -> -> **Gradle:** -> -> ```gradle -> repositories { -> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } -> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } -> maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> -> } -> -> dependencies { -> implementation '${group}:${name}:${version}' -> } -> ``` -> **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") -> } -> -> dependencies { -> implementation("${group}:${name}:${version}") -> } -> ``` \ No newline at end of file +## Artifact: + +The Maven coordinates of this project are `${group}:${name}:${version}`. + +**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 +} + +dependencies { + implementation '${group}:${name}:${version}' +} +``` +**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 +} + +dependencies { + implementation("${group}:${name}:${version}") +} +``` \ No newline at end of file diff --git a/docs/templates/README-TEMPLATE.md b/docs/templates/README-TEMPLATE.md index ec65c2db0..3502cdccd 100644 --- a/docs/templates/README-TEMPLATE.md +++ b/docs/templates/README-TEMPLATE.md @@ -1,11 +1,8 @@ [![JetBrains Research](https://jb.gg/badges/research.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) [![DOI](https://zenodo.org/badge/129486382.svg)](https://zenodo.org/badge/latestdoi/129486382) - ![Gradle build](https://github.com/mipt-npm/kmath/workflows/Gradle%20build/badge.svg) - -Bintray: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-core/_latestVersion) - -Bintray-dev: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-core/_latestVersion) +[![Maven Central](https://img.shields.io/maven-central/v/space.kscience/kmath-core.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22space.kscience%22) +[![Space](https://img.shields.io/maven-metadata/v?label=Space&metadataUrl=https%3A%2F%2Fmaven.pkg.jetbrains.space%2Fmipt-npm%2Fp%2Fsci%2Fmaven%2Fkscience%2Fkmath%2Fkmath-core%2Fmaven-metadata.xml)](https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven/space/kscience/) # KMath @@ -97,33 +94,22 @@ better than SciPy. ### Repositories -Release artifacts are accessible from bintray with following configuration (see documentation of -[Kotlin Multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html) for more details): +Release and development artifacts are accessible from mipt-npm [Space](https://www.jetbrains.com/space/) repository `https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven` (see documentation of +[Kotlin Multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html) for more details). The repository could be reached through [repo.kotlin.link](https://repo.kotlin.link) proxy: ```kotlin repositories { - maven("https://dl.bintray.com/mipt-npm/kscience") - // maven("https://dl.bintray.com/mipt-npm/dev") for dev versions + maven("https://repo.kotlin.link") } dependencies { - api("kscience.kmath:kmath-core:$version") + api("${group}:kmath-core:$version") // api("kscience.kmath:kmath-core-jvm:$version") for jvm-specific version } ``` Gradle `6.0+` is required for multiplatform artifacts. -#### Development - -Development builds are uploaded to the separate repository: - -```kotlin -repositories { - maven("https://dl.bintray.com/mipt-npm/dev") -} -``` - ## Contributing The project requires a lot of additional work. The most important thing we need is a feedback about what features are diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 054945eb7..5dd40b609 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") @@ -69,6 +69,14 @@ benchmark { targets.register("benchmarks") // This one matches sourceSet name above + 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 @@ -76,6 +84,22 @@ benchmark { 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") + } + + configurations.register("matrixInverse") { + 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("MatrixInverseBenchmark") + } } kotlin.sourceSets.all { @@ -89,6 +113,6 @@ tasks.withType { kotlinOptions.jvmTarget = "11" } -readme{ +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/BufferBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/BufferBenchmark.kt deleted file mode 100644 index e14b393e2..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/BufferBenchmark.kt +++ /dev/null @@ -1,34 +0,0 @@ -package kscience.kmath.benchmarks - -import kscience.kmath.complex.Complex -import kscience.kmath.complex.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 - -@State(Scope.Benchmark) -internal class BufferBenchmark { - @Benchmark - fun genericRealBufferReadWrite() { - val buffer = RealBuffer(size) { it.toDouble() } - - (0 until size).forEach { - buffer[it] - } - } - - @Benchmark - fun complexBufferReadWrite() { - val buffer = MutableBuffer.complex(size / 2) { Complex(it.toDouble(), -it.toDouble()) } - - (0 until size / 2).forEach { - buffer[it] - } - } - - companion object { - const val size: Int = 100 - } -} diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/DotBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/DotBenchmark.kt deleted file mode 100644 index 48be30cef..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/DotBenchmark.kt +++ /dev/null @@ -1,67 +0,0 @@ -package 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.Matrix -import kscience.kmath.linear.RealMatrixContext -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke -import kscience.kmath.structures.Buffer -import org.openjdk.jmh.annotations.Scope -import org.openjdk.jmh.annotations.State -import kotlin.random.Random - -@State(Scope.Benchmark) -internal class DotBenchmark { - companion object { - val random = Random(12224) - val dim = 1000 - - //creating invertible matrix - val matrix1 = Matrix.real(dim, dim) { i, j -> if (i <= j) random.nextDouble() else 0.0 } - val matrix2 = Matrix.real(dim, dim) { i, j -> if (i <= j) random.nextDouble() else 0.0 } - - val cmMatrix1 = CMMatrixContext { matrix1.toCM() } - val cmMatrix2 = CMMatrixContext { matrix2.toCM() } - - val ejmlMatrix1 = EjmlMatrixContext { matrix1.toEjml() } - val ejmlMatrix2 = EjmlMatrixContext { matrix2.toEjml() } - } - - @Benchmark - fun cmDot() { - CMMatrixContext { - cmMatrix1 dot cmMatrix2 - } - } - - @Benchmark - fun ejmlDot() { - EjmlMatrixContext { - ejmlMatrix1 dot ejmlMatrix2 - } - } - - @Benchmark - fun ejmlDotWithConversion() { - EjmlMatrixContext { - matrix1 dot matrix2 - } - } - - @Benchmark - fun bufferedDot() { - BufferMatrixContext(RealField, Buffer.Companion::real).invoke { - matrix1 dot matrix2 - } - } - - @Benchmark - fun realDot() { - RealMatrixContext { - matrix1 dot matrix2 - } - } -} diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt deleted file mode 100644 index 9607dd499..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt +++ /dev/null @@ -1,65 +0,0 @@ -package kscience.kmath.benchmarks - -import kscience.kmath.asm.compile -import kscience.kmath.ast.MstField -import kscience.kmath.ast.mstInField -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 kotlin.random.Random - -@State(Scope.Benchmark) -internal class ExpressionsInterpretersBenchmark { - private val algebra: Field = RealField - - @Benchmark - fun functionalExpression() { - val expr = algebra.expressionInField { - symbol("x") * const(2.0) + const(2.0) / symbol("x") - const(16.0) - } - - invokeAndSum(expr) - } - - @Benchmark - fun mstExpression() { - val expr = algebra.mstInField { - symbol("x") * 2.0 + 2.0 / symbol("x") - 16.0 - } - - invokeAndSum(expr) - } - - @Benchmark - fun asmExpression() { - val expr = algebra.mstInField { - MstField.symbol("x") * 2.0 + 2.0 / MstField.symbol("x") - 16.0 - }.compile() - - invokeAndSum(expr) - } - - @Benchmark - fun rawExpression() { - val x by symbol - val expr = Expression { args -> args.getValue(x) * 2.0 + 2.0 / args.getValue(x) - 16.0 } - invokeAndSum(expr) - } - - private fun invokeAndSum(expr: Expression) { - val random = Random(0) - var sum = 0.0 - - repeat(1000000) { - 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/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt deleted file mode 100644 index b54cff926..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt +++ /dev/null @@ -1,48 +0,0 @@ -package 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.linear.Matrix -import kscience.kmath.linear.MatrixContext -import kscience.kmath.linear.inverseWithLup -import kscience.kmath.linear.real -import kscience.kmath.operations.invoke -import org.openjdk.jmh.annotations.Scope -import org.openjdk.jmh.annotations.State -import kotlin.random.Random - -@State(Scope.Benchmark) -internal class LinearAlgebraBenchmark { - companion object { - val random = Random(1224) - val dim = 100 - - //creating invertible matrix - val u = Matrix.real(dim, dim) { i, j -> if (i <= j) random.nextDouble() else 0.0 } - val l = Matrix.real(dim, dim) { i, j -> if (i >= j) random.nextDouble() else 0.0 } - val matrix = l dot u - } - - @Benchmark - fun kmathLupInversion() { - MatrixContext.real.inverseWithLup(matrix) - } - - @Benchmark - fun cmLUPInversion() { - CMMatrixContext { - inverse(matrix) - } - } - - @Benchmark - fun ejmlInverse() { - EjmlMatrixContext { - inverse(matrix) - } - } -} 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 5f7559d02..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/NDFieldBenchmark.kt +++ /dev/null @@ -1,45 +0,0 @@ -package kscience.kmath.benchmarks - -import kscience.kmath.nd.* -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke -import kscience.kmath.structures.Buffer -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() { - autoField { - var res: NDStructure = one - repeat(n) { res += one } - } - } - - @Benchmark - fun specializedFieldAdd() { - specializedField { - var res: NDStructure = one - repeat(n) { res += 1.0 } - } - } - - - @Benchmark - fun boxingFieldAdd() { - 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/kscience/kmath/benchmarks/ViktorBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt deleted file mode 100644 index 5cf6c2ab8..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt +++ /dev/null @@ -1,52 +0,0 @@ -package kscience.kmath.benchmarks - -import kscience.kmath.nd.* -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke -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: NDField = NDAlgebra.auto(RealField, dim, dim) - final val realField: RealNDField = NDAlgebra.real(dim, dim) - final val viktorField: ViktorNDField = ViktorNDField(dim, dim) - - @Benchmark - fun automaticFieldAddition() { - autoField { - var res: NDStructure = one - repeat(n) { res += 1.0 } - } - } - - @Benchmark - fun realFieldAddition() { - realField { - var res: NDStructure = one - repeat(n) { res += 1.0 } - } - } - - @Benchmark - fun viktorFieldAddition() { - 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/kscience/kmath/benchmarks/ViktorLogBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorLogBenchmark.kt deleted file mode 100644 index 914584b8e..000000000 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorLogBenchmark.kt +++ /dev/null @@ -1,49 +0,0 @@ -package kscience.kmath.benchmarks - -import kscience.kmath.nd.* -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke -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 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() { - realField { - val fortyTwo = produce { 42.0 } - var res = one - repeat(n) { res = ln(fortyTwo) } - } - } - - @Benchmark - fun viktorFieldLog() { - 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/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..43b698c03 --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt @@ -0,0 +1,38 @@ +package space.kscience.kmath.benchmarks + +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import java.nio.IntBuffer + +@State(Scope.Benchmark) +internal class ArrayBenchmark { + @Benchmark + fun benchmarkArrayRead(blackhole: Blackhole) { + var res = 0 + for (i in 1..size) res += array[size - i] + blackhole.consume(res) + } + + @Benchmark + fun benchmarkBufferRead(blackhole: Blackhole) { + var res = 0 + for (i in 1..size) res += arrayBuffer[size - i] + blackhole.consume(res) + } + + @Benchmark + fun nativeBufferRead(blackhole: Blackhole) { + var res = 0 + for (i in 1..size) res += nativeBuffer[size - i] + blackhole.consume(res) + } + + private companion object { + private const val size = 1000 + private val array = IntArray(size) { it } + private val arrayBuffer = IntBuffer.wrap(array) + private val nativeBuffer = IntBuffer.allocate(size).also { for (i in 0 until size) it.put(i, i) } + } +} diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt new file mode 100644 index 000000000..1db1d77dc --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt @@ -0,0 +1,34 @@ +package space.kscience.kmath.benchmarks + +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import space.kscience.kmath.complex.Complex +import space.kscience.kmath.complex.complex +import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.MutableBuffer + +@State(Scope.Benchmark) +internal class BufferBenchmark { + @Benchmark + fun genericDoubleBufferReadWrite() { + val buffer = DoubleBuffer(size) { it.toDouble() } + + (0 until size).forEach { + buffer[it] + } + } + + @Benchmark + fun complexBufferReadWrite() { + val buffer = MutableBuffer.complex(size / 2) { Complex(it.toDouble(), -it.toDouble()) } + + (0 until size / 2).forEach { + buffer[it] + } + } + + private companion object { + private const val size = 100 + } +} diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt new file mode 100644 index 000000000..6a2126dc1 --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt @@ -0,0 +1,65 @@ +package space.kscience.kmath.benchmarks + +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import space.kscience.kmath.commons.linear.CMLinearSpace +import space.kscience.kmath.ejml.EjmlLinearSpace +import space.kscience.kmath.linear.LinearSpace +import space.kscience.kmath.linear.invoke +import space.kscience.kmath.operations.DoubleField +import kotlin.random.Random + +@State(Scope.Benchmark) +internal class DotBenchmark { + companion object { + val random = Random(12224) + const val dim = 1000 + + //creating invertible matrix + val matrix1 = LinearSpace.real.buildMatrix(dim, dim) { i, j -> if (i <= j) random.nextDouble() else 0.0 } + val matrix2 = LinearSpace.real.buildMatrix(dim, dim) { i, j -> if (i <= j) random.nextDouble() else 0.0 } + + val cmMatrix1 = CMLinearSpace { matrix1.toCM() } + val cmMatrix2 = CMLinearSpace { matrix2.toCM() } + + val ejmlMatrix1 = EjmlLinearSpace { matrix1.toEjml() } + val ejmlMatrix2 = EjmlLinearSpace { matrix2.toEjml() } + } + + @Benchmark + fun cmDot(blackhole: Blackhole) { + CMLinearSpace.run { + blackhole.consume(cmMatrix1 dot cmMatrix2) + } + } + + @Benchmark + fun ejmlDot(blackhole: Blackhole) { + EjmlLinearSpace { + blackhole.consume(ejmlMatrix1 dot ejmlMatrix2) + } + } + + @Benchmark + fun ejmlDotWithConversion(blackhole: Blackhole) { + EjmlLinearSpace { + blackhole.consume(matrix1 dot matrix2) + } + } + + @Benchmark + fun bufferedDot(blackhole: Blackhole) { + LinearSpace.auto(DoubleField).invoke { + blackhole.consume(matrix1 dot matrix2) + } + } + + @Benchmark + fun realDot(blackhole: Blackhole) { + LinearSpace.real { + blackhole.consume(matrix1 dot matrix2) + } + } +} diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt new file mode 100644 index 000000000..2438e3979 --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt @@ -0,0 +1,74 @@ +package space.kscience.kmath.benchmarks + +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.Scope +import kotlinx.benchmark.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.misc.symbol +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.bindSymbol +import kotlin.random.Random + +@State(Scope.Benchmark) +internal class ExpressionsInterpretersBenchmark { + @Benchmark + fun functionalExpression(blackhole: Blackhole) { + val expr = algebra.expressionInField { + val x = bindSymbol(x) + x * const(2.0) + const(2.0) / x - const(16.0) + } + + invokeAndSum(expr, blackhole) + } + + @Benchmark + fun mstExpression(blackhole: Blackhole) { + val expr = algebra.mstInField { + val x = bindSymbol(x) + x * 2.0 + number(2.0) / x - 16.0 + } + + invokeAndSum(expr, blackhole) + } + + @Benchmark + fun asmExpression(blackhole: Blackhole) { + val expr = algebra.mstInField { + val x = bindSymbol(x) + x * 2.0 + number(2.0) / x - 16.0 + }.compile() + + invokeAndSum(expr, blackhole) + } + + @Benchmark + fun rawExpression(blackhole: Blackhole) { + val expr = Expression { args -> + val x = args.getValue(x) + x * 2.0 + 2.0 / x - 16.0 + } + + invokeAndSum(expr, blackhole) + } + + private fun invokeAndSum(expr: Expression, blackhole: Blackhole) { + val random = Random(0) + var sum = 0.0 + + repeat(1000000) { + sum += expr(x to random.nextDouble()) + } + + blackhole.consume(sum) + } + + private companion object { + private val algebra = DoubleField + private val x by symbol + } +} diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt new file mode 100644 index 000000000..7aa8ac975 --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt @@ -0,0 +1,48 @@ +package space.kscience.kmath.benchmarks + +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import space.kscience.kmath.commons.linear.CMLinearSpace +import space.kscience.kmath.commons.linear.inverse +import space.kscience.kmath.ejml.EjmlLinearSpace +import space.kscience.kmath.ejml.inverse +import space.kscience.kmath.linear.LinearSpace +import space.kscience.kmath.linear.inverseWithLup +import space.kscience.kmath.linear.invoke +import kotlin.random.Random + +@State(Scope.Benchmark) +internal class MatrixInverseBenchmark { + companion object { + val random = Random(1224) + const val dim = 100 + + private val space = LinearSpace.real + + //creating invertible matrix + val u = space.buildMatrix(dim, dim) { i, j -> if (i <= j) random.nextDouble() else 0.0 } + val l = space.buildMatrix(dim, dim) { i, j -> if (i >= j) random.nextDouble() else 0.0 } + val matrix = space { l dot u } + } + + @Benchmark + fun kmathLupInversion(blackhole: Blackhole) { + blackhole.consume(LinearSpace.real.inverseWithLup(matrix)) + } + + @Benchmark + fun cmLUPInversion(blackhole: Blackhole) { + with(CMLinearSpace) { + blackhole.consume(inverse(matrix)) + } + } + + @Benchmark + fun ejmlInverse(blackhole: Blackhole) { + with(EjmlLinearSpace) { + blackhole.consume(inverse(matrix)) + } + } +} 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..09c415d9a --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt @@ -0,0 +1,48 @@ +package space.kscience.kmath.benchmarks + +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.structures.Buffer + +@State(Scope.Benchmark) +internal class NDFieldBenchmark { + @Benchmark + fun autoFieldAdd(blackhole: Blackhole) { + with(autoField) { + var res: StructureND = one + repeat(n) { res += one } + blackhole.consume(res) + } + } + + @Benchmark + fun specializedFieldAdd(blackhole: Blackhole) { + with(specializedField) { + var res: StructureND = one + repeat(n) { res += 1.0 } + blackhole.consume(res) + } + } + + + @Benchmark + fun boxingFieldAdd(blackhole: Blackhole) { + with(genericField) { + var res: StructureND = one + repeat(n) { res += 1.0 } + blackhole.consume(res) + } + } + + private companion object { + private const val dim = 1000 + private const val n = 100 + private val autoField = AlgebraND.auto(DoubleField, dim, dim) + private val specializedField = AlgebraND.real(dim, dim) + private val genericField = AlgebraND.field(DoubleField, 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..fd0188bd6 --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt @@ -0,0 +1,61 @@ +package space.kscience.kmath.benchmarks + +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import org.jetbrains.bio.viktor.F64Array +import space.kscience.kmath.nd.AlgebraND +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.nd.auto +import space.kscience.kmath.nd.real +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.viktor.ViktorNDField + +@State(Scope.Benchmark) +internal class ViktorBenchmark { + @Benchmark + fun automaticFieldAddition(blackhole: Blackhole) { + with(autoField) { + var res: StructureND = one + repeat(n) { res += 1.0 } + blackhole.consume(res) + } + } + + @Benchmark + fun realFieldAddition(blackhole: Blackhole) { + with(realField) { + var res: StructureND = one + repeat(n) { res += 1.0 } + blackhole.consume(res) + } + } + + @Benchmark + fun viktorFieldAddition(blackhole: Blackhole) { + with(viktorField) { + var res = one + repeat(n) { res += 1.0 } + blackhole.consume(res) + } + } + + @Benchmark + fun rawViktor(blackhole: Blackhole) { + val one = F64Array.full(init = 1.0, shape = intArrayOf(dim, dim)) + var res = one + repeat(n) { res = res + one } + blackhole.consume(res) + } + + private companion object { + private const val dim = 1000 + private const val n = 100 + + // automatically build context most suited for given type. + private val autoField = AlgebraND.auto(DoubleField, dim, dim) + private val realField = AlgebraND.real(dim, dim) + private val viktorField = ViktorNDField(dim, dim) + } +} 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..b6bd036ba --- /dev/null +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt @@ -0,0 +1,53 @@ +package space.kscience.kmath.benchmarks + +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import org.jetbrains.bio.viktor.F64Array +import space.kscience.kmath.nd.AlgebraND +import space.kscience.kmath.nd.auto +import space.kscience.kmath.nd.real +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.viktor.ViktorFieldND + +@State(Scope.Benchmark) +internal class ViktorLogBenchmark { + @Benchmark + fun realFieldLog(blackhole: Blackhole) { + with(realNdField) { + val fortyTwo = produce { 42.0 } + var res = one + repeat(n) { res = ln(fortyTwo) } + blackhole.consume(res) + } + } + + @Benchmark + fun viktorFieldLog(blackhole: Blackhole) { + with(viktorField) { + val fortyTwo = produce { 42.0 } + var res = one + repeat(n) { res = ln(fortyTwo) } + blackhole.consume(res) + } + } + + @Benchmark + fun rawViktorLog(blackhole: Blackhole) { + val fortyTwo = F64Array.full(dim, dim, init = 42.0) + lateinit var res: F64Array + repeat(n) { res = fortyTwo.log() } + blackhole.consume(res) + } + + private companion object { + private const val dim = 1000 + private const val n = 100 + + // automatically build context most suited for given type. + private val autoField = AlgebraND.auto(DoubleField, dim, dim) + private val realNdField = AlgebraND.real(dim, dim) + private val viktorField = ViktorFieldND(intArrayOf(dim, dim)) + } +} diff --git a/examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt b/examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt deleted file mode 100644 index b3c827503..000000000 --- a/examples/src/main/kotlin/kscience/kmath/ast/KotlingradSupport.kt +++ /dev/null @@ -1,24 +0,0 @@ -package 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 - -/** - * In this example, x^2-4*x-44 function is differentiated with Kotlin∇, and the autodiff result is compared with - * valid derivative. - */ -fun main() { - val x by symbol - - val actualDerivative = MstExpression(RealField, "x^2-4*x-44".parseMath()) - .differentiable() - .derivative(x) - .compile() - - val expectedDerivative = MstExpression(RealField, "2*x-4".parseMath()).compile() - assert(actualDerivative("x" to 123.0) == expectedDerivative("x" to 123.0)) -} diff --git a/examples/src/main/kotlin/kscience/kmath/structures/ParallelRealNDField.kt b/examples/src/main/kotlin/kscience/kmath/structures/ParallelRealNDField.kt deleted file mode 100644 index 48286c140..000000000 --- a/examples/src/main/kotlin/kscience/kmath/structures/ParallelRealNDField.kt +++ /dev/null @@ -1,103 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.nd.* -import kscience.kmath.operations.ExtendedField -import kscience.kmath.operations.RealField -import 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/space/kscience/kmath/ast/expressions.kt b/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt new file mode 100644 index 000000000..17c85eea5 --- /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.DoubleField + +fun main() { + val expr = DoubleField.mstInField { + val x = bindSymbol("x") + x * 2.0 + number(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/space/kscience/kmath/ast/kotlingradSupport.kt b/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt new file mode 100644 index 000000000..138b3e708 --- /dev/null +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt @@ -0,0 +1,24 @@ +package space.kscience.kmath.ast + +import space.kscience.kmath.asm.compile +import space.kscience.kmath.expressions.derivative +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.kotlingrad.differentiable +import space.kscience.kmath.misc.symbol +import space.kscience.kmath.operations.DoubleField + +/** + * In this example, x^2-4*x-44 function is differentiated with Kotlin∇, and the autodiff result is compared with + * valid derivative. + */ +fun main() { + val x by symbol + + val actualDerivative = MstExpression(DoubleField, "x^2-4*x-44".parseMath()) + .differentiable() + .derivative(x) + .compile() + + val expectedDerivative = MstExpression(DoubleField, "2*x-4".parseMath()).compile() + assert(actualDerivative("x" to 123.0) == expectedDerivative("x" to 123.0)) +} 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 100% 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 diff --git a/examples/src/main/kotlin/space/kscience/kmath/linear/gradient.kt b/examples/src/main/kotlin/space/kscience/kmath/linear/gradient.kt new file mode 100644 index 000000000..8940aeac9 --- /dev/null +++ b/examples/src/main/kotlin/space/kscience/kmath/linear/gradient.kt @@ -0,0 +1,28 @@ +package space.kscience.kmath.linear + +import space.kscience.kmath.real.* +import space.kscience.kmath.structures.DoubleBuffer + +fun main() { + val x0 = DoubleVector(0.0, 0.0, 0.0) + val sigma = DoubleVector(1.0, 1.0, 1.0) + + val gaussian: (Point) -> Double = { x -> + require(x.size == x0.size) + kotlin.math.exp(-((x - x0) / sigma).square().sum()) + } + + fun ((Point) -> Double).grad(x: Point): Point { + require(x.size == x0.size) + return DoubleBuffer(x.size) { i -> + val h = sigma[i] / 5 + val dVector = DoubleBuffer(x.size) { if (it == i) h else 0.0 } + val f1 = invoke(x + dVector / 2) + val f0 = invoke(x - dVector / 2) + (f1 - f0) / h + } + } + + println(gaussian.grad(x0)) + +} \ No newline at end of file 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 54% rename from examples/src/main/kotlin/kscience/kmath/operations/ComplexDemo.kt rename to examples/src/main/kotlin/space/kscience/kmath/operations/ComplexDemo.kt index 6641aad85..105fb108e 100644 --- a/examples/src/main/kotlin/kscience/kmath/operations/ComplexDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/operations/ComplexDemo.kt @@ -1,18 +1,18 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations -import kscience.kmath.complex.Complex -import kscience.kmath.complex.complex -import kscience.kmath.nd.NDAlgebra +import space.kscience.kmath.complex.Complex +import space.kscience.kmath.complex.complex +import space.kscience.kmath.nd.AlgebraND fun main() { // 2d element - val element = NDAlgebra.complex(2, 2).produce { (i, j) -> + val element = AlgebraND.complex(2, 2).produce { (i, j) -> Complex(i.toDouble() - j.toDouble(), i.toDouble() + j.toDouble()) } println(element) // 1d element operation - val result = with(NDAlgebra.complex(8)) { + val result = with(AlgebraND.complex(8)) { val a = produce { (it) -> i * it - it.toDouble() } val b = 3 val c = Complex(1.0, 1.0) 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 100% rename from examples/src/main/kotlin/kscience/kmath/stat/DistributionBenchmark.kt rename to examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt 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 100% rename from examples/src/main/kotlin/kscience/kmath/stat/DistributionDemo.kt rename to examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt 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 68% rename from examples/src/main/kotlin/kscience/kmath/structures/ComplexND.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt index 2c0254139..68af2560b 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/ComplexND.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt @@ -1,26 +1,26 @@ @file:Suppress("unused") -package kscience.kmath.structures +package space.kscience.kmath.structures -import kscience.kmath.complex.* -import kscience.kmath.linear.transpose -import kscience.kmath.nd.NDAlgebra -import kscience.kmath.nd.NDStructure -import kscience.kmath.nd.as2D -import kscience.kmath.nd.real -import kscience.kmath.operations.invoke +import space.kscience.kmath.complex.* +import space.kscience.kmath.linear.transpose +import space.kscience.kmath.nd.AlgebraND +import space.kscience.kmath.nd.StructureND +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 = NDAlgebra.real(dim, dim) - val complexField: ComplexNDField = NDAlgebra.complex(dim, dim) + val realField = AlgebraND.real(dim, dim) + val complexField: ComplexFieldND = AlgebraND.complex(dim, dim) val realTime = measureTimeMillis { realField { - var res: NDStructure = one + var res: StructureND = one repeat(n) { res += 1.0 } @@ -31,7 +31,7 @@ fun main() { val complexTime = measureTimeMillis { complexField { - var res: NDStructure = one + var res: StructureND = 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 68% rename from examples/src/main/kotlin/kscience/kmath/structures/NDField.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt index 1e7a19cf8..f7dc3280a 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/NDField.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt @@ -1,12 +1,12 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures import kotlinx.coroutines.GlobalScope -import kscience.kmath.nd.* -import kscience.kmath.nd4j.Nd4jArrayField -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke -import kscience.kmath.viktor.ViktorNDField import org.nd4j.linalg.factory.Nd4j +import space.kscience.kmath.nd.* +import space.kscience.kmath.nd4j.Nd4jArrayField +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.viktor.ViktorNDField import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.system.measureTimeMillis @@ -24,56 +24,56 @@ fun main() { val n = 1000 // automatically build context most suited for given type. - val autoField = NDAlgebra.auto(RealField, dim, dim) + val autoField = AlgebraND.auto(DoubleField, dim, dim) // specialized nd-field for Double. It works as generic Double field as well - val realField = NDAlgebra.real(dim, dim) + val realField = AlgebraND.real(dim, dim) //A generic boxing field. It should be used for objects, not primitives. - val boxingField = NDAlgebra.field(RealField, Buffer.Companion::boxing, dim, dim) + val boxingField = AlgebraND.field(DoubleField, Buffer.Companion::boxing, dim, dim) // Nd4j specialized field. val nd4jField = Nd4jArrayField.real(dim, dim) //viktor field - val viktorField = ViktorNDField(dim,dim) + val viktorField = ViktorNDField(dim, dim) //parallel processing based on Java Streams - val parallelField = NDAlgebra.realWithStream(dim,dim) + val parallelField = AlgebraND.realWithStream(dim, dim) measureAndPrint("Boxing addition") { boxingField { - var res: NDStructure = one + var res: StructureND = one repeat(n) { res += 1.0 } } } measureAndPrint("Specialized addition") { realField { - var res: NDStructure = one + var res: StructureND = one repeat(n) { res += 1.0 } } } measureAndPrint("Nd4j specialized addition") { nd4jField { - var res: NDStructure = one + var res: StructureND = one repeat(n) { res += 1.0 } } } measureAndPrint("Viktor addition") { viktorField { - var res: NDStructure = one + var res: StructureND = one repeat(n) { res += 1.0 } } } measureAndPrint("Parallel stream addition") { parallelField { - var res: NDStructure = one + var res: StructureND = one repeat(n) { res += 1.0 } } } measureAndPrint("Automatic field addition") { autoField { - var res: NDStructure = one + var res: StructureND = one repeat(n) { res += 1.0 } } } diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt new file mode 100644 index 000000000..6741209fc --- /dev/null +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt @@ -0,0 +1,107 @@ +package space.kscience.kmath.structures + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.NumbersAddOperations +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 StreamDoubleFieldND( + override val shape: IntArray, +) : FieldND, + NumbersAddOperations>, + ExtendedField> { + + private val strides = DefaultStrides(shape) + override val elementContext: DoubleField get() = DoubleField + override val zero: BufferND by lazy { produce { zero } } + override val one: BufferND by lazy { produce { one } } + + override fun number(value: Number): BufferND { + val d = value.toDouble() // minimize conversions + return produce { d } + } + + private val StructureND.buffer: DoubleBuffer + get() = when { + !shape.contentEquals(this@StreamDoubleFieldND.shape) -> throw ShapeMismatchException( + this@StreamDoubleFieldND.shape, + shape + ) + this is BufferND && this.strides == this@StreamDoubleFieldND.strides -> this.buffer as DoubleBuffer + else -> DoubleBuffer(strides.linearSize) { offset -> get(strides.index(offset)) } + } + + + override fun produce(initializer: DoubleField.(IntArray) -> Double): BufferND { + val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> + val index = strides.index(offset) + DoubleField.initializer(index) + }.toArray() + + return BufferND(strides, array.asBuffer()) + } + + override fun StructureND.map( + transform: DoubleField.(Double) -> Double, + ): BufferND { + val array = Arrays.stream(buffer.array).parallel().map { DoubleField.transform(it) }.toArray() + return BufferND(strides, array.asBuffer()) + } + + override fun StructureND.mapIndexed( + transform: DoubleField.(index: IntArray, Double) -> Double, + ): BufferND { + val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> + DoubleField.transform( + strides.index(offset), + buffer.array[offset] + ) + }.toArray() + + return BufferND(strides, array.asBuffer()) + } + + override fun combine( + a: StructureND, + b: StructureND, + transform: DoubleField.(Double, Double) -> Double, + ): BufferND { + val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> + DoubleField.transform(a.buffer.array[offset], b.buffer.array[offset]) + }.toArray() + return BufferND(strides, array.asBuffer()) + } + + override fun StructureND.unaryMinus(): StructureND = map { -it } + + override fun scale(a: StructureND, value: Double): StructureND = a.map { it * value } + + override fun power(arg: StructureND, pow: Number): BufferND = arg.map { power(it, pow) } + + override fun exp(arg: StructureND): BufferND = arg.map { exp(it) } + + override fun ln(arg: StructureND): BufferND = arg.map { ln(it) } + + override fun sin(arg: StructureND): BufferND = arg.map { sin(it) } + override fun cos(arg: StructureND): BufferND = arg.map { cos(it) } + override fun tan(arg: StructureND): BufferND = arg.map { tan(it) } + override fun asin(arg: StructureND): BufferND = arg.map { asin(it) } + override fun acos(arg: StructureND): BufferND = arg.map { acos(it) } + override fun atan(arg: StructureND): BufferND = arg.map { atan(it) } + + override fun sinh(arg: StructureND): BufferND = arg.map { sinh(it) } + override fun cosh(arg: StructureND): BufferND = arg.map { cosh(it) } + override fun tanh(arg: StructureND): BufferND = arg.map { tanh(it) } + override fun asinh(arg: StructureND): BufferND = arg.map { asinh(it) } + override fun acosh(arg: StructureND): BufferND = arg.map { acosh(it) } + override fun atanh(arg: StructureND): BufferND = arg.map { atanh(it) } +} + +fun AlgebraND.Companion.realWithStream(vararg shape: Int): StreamDoubleFieldND = StreamDoubleFieldND(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 76% rename from examples/src/main/kotlin/kscience/kmath/structures/StructureReadBenchmark.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt index 40db51908..8b0a2ed0e 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/StructureReadBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt @@ -1,15 +1,16 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures -import kscience.kmath.nd.DefaultStrides -import kscience.kmath.nd.NDBuffer +import space.kscience.kmath.nd.BufferND +import space.kscience.kmath.nd.DefaultStrides 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 buffer = DoubleBuffer(array) val strides = DefaultStrides(intArrayOf(n, n)) - val structure = NDBuffer(strides, buffer) + val structure = BufferND(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 67% rename from examples/src/main/kotlin/kscience/kmath/structures/StructureWriteBenchmark.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt index 307b068df..27741be61 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/StructureWriteBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt @@ -1,12 +1,13 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures -import kscience.kmath.nd.NDStructure -import kscience.kmath.nd.mapToBuffer +import space.kscience.kmath.nd.StructureND +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 } + val structure = StructureND.buffered(intArrayOf(n, n), Buffer.Companion::auto) { 1.0 } structure.mapToBuffer { it + 1 } // warm-up val time1 = measureTimeMillis { val res = structure.mapToBuffer { it + 1 } } println("Structure mapping finished in $time1 millis") @@ -19,10 +20,10 @@ fun main() { println("Array mapping finished in $time2 millis") - val buffer = RealBuffer(DoubleArray(n * n) { 1.0 }) + val buffer = DoubleBuffer(DoubleArray(n * n) { 1.0 }) val time3 = measureTimeMillis { - val target = RealBuffer(DoubleArray(n * n)) + val target = DoubleBuffer(DoubleArray(n * n)) val res = array.forEachIndexed { index, value -> target[index] = value + 1 } 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 61% 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..d2d130ab4 100644 --- a/examples/src/main/kotlin/kscience/kmath/structures/typeSafeDimensions.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt @@ -1,11 +1,11 @@ -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() { +private fun DMatrixContext.simple() { val m1 = produce { i, j -> (i + j).toDouble() } val m2 = produce { i, j -> (i + j).toDouble() } @@ -17,7 +17,7 @@ private object D5 : Dimension { override val dim: UInt = 5u } -private fun DMatrixContext.custom() { +private fun DMatrixContext.custom() { val m1 = produce { i, j -> (i + j).toDouble() } val m2 = produce { i, j -> (i - j).toDouble() } val m3 = produce { i, j -> (i - j).toDouble() } diff --git a/gradle.properties b/gradle.properties index 88b90f27b..50123b16c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,6 @@ kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.mpp.stability.nowarn=true kotlin.native.enableDependencyPropagation=false kotlin.parallel.tasks.in.project=true -org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m +org.gradle.configureondemand=true +org.gradle.jvmargs=-XX:MaxMetaspaceSize=9G org.gradle.parallel=true -systemProp.org.gradle.internal.publish.checksums.insecure=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 28ff446a2..442d9132e 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.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/kmath-ast/README.md b/kmath-ast/README.md index c54c4afb1..ff954b914 100644 --- a/kmath-ast/README.md +++ b/kmath-ast/README.md @@ -1,52 +1,43 @@ -# Abstract Syntax Tree Expression Representation and Operations (`kmath-ast`) +# Module kmath-ast -This subproject implements the following features: +Abstract syntax tree expression representation and related optimizations. - - [expression-language](src/jvmMain/kotlin/kscience/kmath/ast/parser.kt) : Expression language and its parser - - [mst](src/commonMain/kotlin/kscience/kmath/ast/MST.kt) : MST (Mathematical Syntax Tree) as expression language's syntax intermediate representation - - [mst-building](src/commonMain/kotlin/kscience/kmath/ast/MstAlgebra.kt) : MST building algebraic structure - - [mst-interpreter](src/commonMain/kotlin/kscience/kmath/ast/MST.kt) : MST interpreter - - [mst-jvm-codegen](src/jvmMain/kotlin/kscience/kmath/asm/asm.kt) : Dynamic MST to JVM bytecode compiler - - [mst-js-codegen](src/jsMain/kotlin/kscience/kmath/estree/estree.kt) : Dynamic MST to JS compiler + - [expression-language](src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt) : Expression language and its parser + - [mst](src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt) : MST (Mathematical Syntax Tree) as expression language's syntax intermediate representation + - [mst-building](src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt) : MST building algebraic structure + - [mst-interpreter](src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt) : MST interpreter + - [mst-jvm-codegen](src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt) : Dynamic MST to JVM bytecode compiler + - [mst-js-codegen](src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt) : Dynamic MST to JS compiler -> #### Artifact: -> -> This module artifact: `kscience.kmath:kmath-ast:0.2.0-dev-7`. -> -> 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) -> -> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-ast/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-ast/_latestVersion) -> -> **Gradle:** -> -> ```gradle -> repositories { -> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } -> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } -> maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> -> } -> -> dependencies { -> implementation 'kscience.kmath:kmath-ast:0.2.0-dev-7' -> } -> ``` -> **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") -> } -> -> dependencies { -> implementation("kscience.kmath:kmath-ast:0.2.0-dev-7") -> } -> ``` +## Artifact: + +The Maven coordinates of this project are `space.kscience:kmath-ast:0.3.0-dev-3`. + +**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 +} + +dependencies { + implementation 'space.kscience:kmath-ast:0.3.0-dev-3' +} +``` +**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 +} + +dependencies { + implementation("space.kscience:kmath-ast:0.3.0-dev-3") +} +``` ## Dynamic expression code generation @@ -58,19 +49,19 @@ a special implementation of `Expression` with implemented `invoke` function. For example, the following builder: ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() +DoubleField.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; @@ -91,8 +82,8 @@ public final class AsmCompiledExpression_45045_0 implements Expression { This API extends MST and MstExpression, so you may optimize as both of them: ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() -RealField.expression("x+2".parseMath()) +DoubleField.mstInField { symbol("x") + 2 }.compile() +DoubleField.expression("x+2".parseMath()) ``` #### Known issues @@ -106,7 +97,7 @@ RealField.expression("x+2".parseMath()) A similar feature is also available on JS. ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() +DoubleField.mstInField { symbol("x") + 2 }.compile() ``` The code above returns expression implemented with such a JS function: diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index ed06b396b..e3a7faf0a 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 { @@ -33,19 +33,24 @@ kotlin.sourceSets { jsMain { dependencies { - implementation(npm("astring", "1.4.3")) + implementation(npm("astring", "1.7.0")) } } jvmMain { dependencies { - api("com.github.h0tk3y.betterParse:better-parse:0.4.0") - implementation("org.ow2.asm:asm:9.0") - implementation("org.ow2.asm:asm-commons:9.0") + api("com.github.h0tk3y.betterParse:better-parse:0.4.1") + implementation("org.ow2.asm:asm:9.1") + implementation("org.ow2.asm:asm-commons:9.1") } } } +//Workaround for https://github.com/Kotlin/dokka/issues/1455 +tasks.dokkaHtml { + dependsOn(tasks.build) +} + readme { maturity = Maturity.PROTOTYPE propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) @@ -53,36 +58,36 @@ readme { feature( id = "expression-language", description = "Expression language and its parser", - ref = "src/jvmMain/kotlin/kscience/kmath/ast/parser.kt" + ref = "src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt" ) feature( id = "mst", description = "MST (Mathematical Syntax Tree) as expression language's syntax intermediate representation", - ref = "src/commonMain/kotlin/kscience/kmath/ast/MST.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt" ) feature( id = "mst-building", description = "MST building algebraic structure", - ref = "src/commonMain/kotlin/kscience/kmath/ast/MstAlgebra.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt" ) feature( id = "mst-interpreter", description = "MST interpreter", - ref = "src/commonMain/kotlin/kscience/kmath/ast/MST.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt" ) feature( id = "mst-jvm-codegen", description = "Dynamic MST to JVM bytecode compiler", - ref = "src/jvmMain/kotlin/kscience/kmath/asm/asm.kt" + ref = "src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt" ) feature( id = "mst-js-codegen", description = "Dynamic MST to JS compiler", - ref = "src/jsMain/kotlin/kscience/kmath/estree/estree.kt" + ref = "src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt" ) } diff --git a/kmath-ast/docs/README-TEMPLATE.md b/kmath-ast/docs/README-TEMPLATE.md index ebaa6246a..db071adb4 100644 --- a/kmath-ast/docs/README-TEMPLATE.md +++ b/kmath-ast/docs/README-TEMPLATE.md @@ -1,6 +1,6 @@ -# Abstract Syntax Tree Expression Representation and Operations (`kmath-ast`) +# Module kmath-ast -This subproject implements the following features: +Abstract syntax tree expression representation and related optimizations. ${features} @@ -16,19 +16,19 @@ a special implementation of `Expression` with implemented `invoke` function. For example, the following builder: ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() +DoubleField.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; @@ -49,8 +49,8 @@ public final class AsmCompiledExpression_45045_0 implements Expression { This API extends MST and MstExpression, so you may optimize as both of them: ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() -RealField.expression("x+2".parseMath()) +DoubleField.mstInField { symbol("x") + 2 }.compile() +DoubleField.expression("x+2".parseMath()) ``` #### Known issues @@ -64,7 +64,7 @@ RealField.expression("x+2".parseMath()) A similar feature is also available on JS. ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() +DoubleField.mstInField { symbol("x") + 2 }.compile() ``` The code above returns expression implemented with such a JS function: 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 67% 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..c1aeae90e 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) } @@ -18,25 +18,25 @@ public object MstAlgebra : NumericAlgebra { } /** - * [Space] over [MST] nodes. + * [Group] over [MST] nodes. */ -public object MstSpace : Space, NumericAlgebra { - public override val zero: MST.Numeric by lazy { number(0.0) } +public object MstGroup : Group, NumericAlgebra, ScaleOperations { + public override val zero: MST.Numeric = 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 add(a: MST, b: MST): MST.Binary = binaryOperationFunction(SpaceOperations.PLUS_OPERATION)(a, b) + public override fun bindSymbol(value: String): MST.Symbolic = MstAlgebra.bindSymbol(value) + public override fun add(a: MST, b: MST): MST.Binary = binaryOperationFunction(GroupOperations.PLUS_OPERATION)(a, b) public override operator fun MST.unaryPlus(): MST.Unary = - unaryOperationFunction(SpaceOperations.PLUS_OPERATION)(this) + unaryOperationFunction(GroupOperations.PLUS_OPERATION)(this) public override operator fun MST.unaryMinus(): MST.Unary = - unaryOperationFunction(SpaceOperations.MINUS_OPERATION)(this) + unaryOperationFunction(GroupOperations.MINUS_OPERATION)(this) public override operator fun MST.minus(b: MST): MST.Binary = - binaryOperationFunction(SpaceOperations.MINUS_OPERATION)(this, b) + binaryOperationFunction(GroupOperations.MINUS_OPERATION)(this, b) - public override fun multiply(a: MST, k: Number): MST.Binary = - binaryOperationFunction(RingOperations.TIMES_OPERATION)(a, number(k)) + public override fun scale(a: MST, value: Double): MST.Binary = + binaryOperationFunction(RingOperations.TIMES_OPERATION)(a, number(value)) public override fun binaryOperationFunction(operation: String): (left: MST, right: MST) -> MST.Binary = MstAlgebra.binaryOperationFunction(operation) @@ -49,25 +49,26 @@ public object MstSpace : Space, NumericAlgebra { * [Ring] over [MST] nodes. */ @OptIn(UnstableKMathAPI::class) -public object MstRing : Ring, RingWithNumbers { - public override val zero: MST.Numeric - get() = MstSpace.zero +public object MstRing : Ring, NumbersAddOperations, ScaleOperations { + public override val zero: MST.Numeric get() = MstGroup.zero + public override val one: MST.Numeric = number(1.0) - public override val one: MST.Numeric by lazy { number(1.0) } + public override fun number(value: Number): MST.Numeric = MstGroup.number(value) + public override fun bindSymbol(value: String): MST.Symbolic = MstAlgebra.bindSymbol(value) + public override fun add(a: MST, b: MST): MST.Binary = MstGroup.add(a, b) + + public override fun scale(a: MST, value: Double): MST.Binary = + MstGroup.binaryOperationFunction(RingOperations.TIMES_OPERATION)(a, MstGroup.number(value)) - 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 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 = binaryOperationFunction(RingOperations.TIMES_OPERATION)(a, b) - public override operator fun MST.unaryPlus(): MST.Unary = MstSpace { +this@unaryPlus } - public override operator fun MST.unaryMinus(): MST.Unary = MstSpace { -this@unaryMinus } - public override operator fun MST.minus(b: MST): MST.Binary = MstSpace { this@minus - b } + public override operator fun MST.unaryPlus(): MST.Unary = MstGroup { +this@unaryPlus } + public override operator fun MST.unaryMinus(): MST.Unary = MstGroup { -this@unaryMinus } + public override operator fun MST.minus(b: MST): MST.Binary = MstGroup { this@minus - b } public override fun binaryOperationFunction(operation: String): (left: MST, right: MST) -> MST.Binary = - MstSpace.binaryOperationFunction(operation) + MstGroup.binaryOperationFunction(operation) public override fun unaryOperationFunction(operation: String): (arg: MST) -> MST.Unary = MstAlgebra.unaryOperationFunction(operation) @@ -77,17 +78,18 @@ public object MstRing : Ring, RingWithNumbers { * [Field] over [MST] nodes. */ @OptIn(UnstableKMathAPI::class) -public object MstField : Field, RingWithNumbers { - public override val zero: MST.Numeric - get() = MstRing.zero +public object MstField : Field, NumbersAddOperations, ScaleOperations { + public override val zero: MST.Numeric get() = MstRing.zero - public override val one: MST.Numeric - get() = MstRing.one + 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 = MstAlgebra.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) + + public override fun scale(a: MST, value: Double): MST.Binary = + MstGroup.binaryOperationFunction(RingOperations.TIMES_OPERATION)(a, MstGroup.number(value)) + public override fun multiply(a: MST, b: MST): MST.Binary = MstRing.multiply(a, b) public override fun divide(a: MST, b: MST): MST.Binary = binaryOperationFunction(FieldOperations.DIV_OPERATION)(a, b) @@ -107,13 +109,10 @@ public object MstField : Field, RingWithNumbers { * [ExtendedField] over [MST] nodes. */ public object MstExtendedField : ExtendedField, NumericAlgebra { - public override val zero: MST.Numeric - get() = MstField.zero + public override val zero: MST.Numeric get() = MstField.zero + public override val one: MST.Numeric get() = MstField.one - 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 = MstAlgebra.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) @@ -121,14 +120,17 @@ public object MstExtendedField : ExtendedField, NumericAlgebra { public override fun asin(arg: MST): MST.Unary = unaryOperationFunction(TrigonometricOperations.ASIN_OPERATION)(arg) public override fun acos(arg: MST): MST.Unary = unaryOperationFunction(TrigonometricOperations.ACOS_OPERATION)(arg) public override fun atan(arg: MST): MST.Unary = unaryOperationFunction(TrigonometricOperations.ATAN_OPERATION)(arg) - public override fun sinh(arg: MST): MST.Unary = unaryOperationFunction(HyperbolicOperations.SINH_OPERATION)(arg) - public override fun cosh(arg: MST): MST.Unary = unaryOperationFunction(HyperbolicOperations.COSH_OPERATION)(arg) - public override fun tanh(arg: MST): MST.Unary = unaryOperationFunction(HyperbolicOperations.TANH_OPERATION)(arg) - public override fun asinh(arg: MST): MST.Unary = unaryOperationFunction(HyperbolicOperations.ASINH_OPERATION)(arg) - public override fun acosh(arg: MST): MST.Unary = unaryOperationFunction(HyperbolicOperations.ACOSH_OPERATION)(arg) - public override fun atanh(arg: MST): MST.Unary = unaryOperationFunction(HyperbolicOperations.ATANH_OPERATION)(arg) + public override fun sinh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.SINH_OPERATION)(arg) + public override fun cosh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.COSH_OPERATION)(arg) + public override fun tanh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.TANH_OPERATION)(arg) + public override fun asinh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.ASINH_OPERATION)(arg) + public override fun acosh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.ACOSH_OPERATION)(arg) + public override fun atanh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.ATANH_OPERATION)(arg) public override fun add(a: MST, b: MST): MST.Binary = MstField.add(a, b) - public override fun multiply(a: MST, k: Number): MST.Binary = MstField.multiply(a, k) + + public override fun scale(a: MST, value: Double): MST = + binaryOperation(GroupOperations.PLUS_OPERATION, a, number(value)) + public override fun multiply(a: MST, b: MST): MST.Binary = MstField.multiply(a, b) public override fun divide(a: MST, b: MST): MST.Binary = MstField.divide(a, b) public override operator fun MST.unaryPlus(): MST.Unary = MstField { +this@unaryPlus } 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 76% 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..5c43df068 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,9 @@ -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.misc.StringSymbol +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.operations.* import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -15,14 +17,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<*>) @@ -45,13 +56,13 @@ public inline fun , E : Algebra> A.mst( ): MstExpression = MstExpression(this, mstAlgebra.block()) /** - * Builds [MstExpression] over [Space]. + * Builds [MstExpression] over [Group]. * * @author Alexander Nozik */ -public inline fun > A.mstInSpace(block: MstSpace.() -> MST): MstExpression { +public inline fun > A.mstInGroup(block: MstGroup.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return MstExpression(this, MstSpace.block()) + return MstExpression(this, MstGroup.block()) } /** @@ -85,13 +96,13 @@ public inline fun > A.mstInExtendedField(b } /** - * Builds [MstExpression] over [FunctionalExpressionSpace]. + * Builds [MstExpression] over [FunctionalExpressionGroup]. * * @author Alexander Nozik */ -public inline fun > FunctionalExpressionSpace.mstInSpace(block: MstSpace.() -> MST): MstExpression { +public inline fun > FunctionalExpressionGroup.mstInGroup(block: MstGroup.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return algebra.mstInSpace(block) + return algebra.mstInGroup(block) } /** 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 91% 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..1e966d986 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.misc.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/TestESTreeOperationsSupport.kt b/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeOperationsSupport.kt deleted file mode 100644 index 72a4669d9..000000000 --- a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeOperationsSupport.kt +++ /dev/null @@ -1,41 +0,0 @@ -package 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 kotlin.random.Random -import kotlin.test.Test -import kotlin.test.assertEquals - -internal class TestESTreeOperationsSupport { - @Test - fun testUnaryOperationInvocation() { - val expression = RealField.mstInSpace { -symbol("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 res = expression("x" to 2.0) - assertEquals(-1.0, res) - } - - @Test - fun testConstProductInvocation() { - val res = RealField.mstInField { symbol("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 r = Random(0) - var s = 0.0 - repeat(1000000) { s += e("x" to r.nextDouble()) } - println(s) - } -} diff --git a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeSpecialization.kt b/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeSpecialization.kt deleted file mode 100644 index 9d0d17e58..000000000 --- a/kmath-ast/src/jsTest/kotlin/kscience/kmath/estree/TestESTreeSpecialization.kt +++ /dev/null @@ -1,54 +0,0 @@ -package kscience.kmath.estree - -import kscience.kmath.ast.mstInField -import kscience.kmath.expressions.invoke -import 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() - assertEquals(2.0, expr("x" to 2.0)) - } - - @Test - fun testUnaryMinus() { - val expr = RealField.mstInField { unaryOperationFunction("-")(symbol("x")) }.compile() - assertEquals(-2.0, expr("x" to 2.0)) - } - - @Test - fun testAdd() { - val expr = RealField.mstInField { binaryOperationFunction("+")(symbol("x"), symbol("x")) }.compile() - assertEquals(4.0, expr("x" to 2.0)) - } - - @Test - fun testSine() { - val expr = RealField.mstInField { unaryOperationFunction("sin")(symbol("x")) }.compile() - assertEquals(0.0, expr("x" to 0.0)) - } - - @Test - fun testMinus() { - val expr = RealField.mstInField { binaryOperationFunction("-")(symbol("x"), symbol("x")) }.compile() - assertEquals(0.0, expr("x" to 2.0)) - } - - @Test - fun testDivide() { - val expr = RealField.mstInField { binaryOperationFunction("/")(symbol("x"), symbol("x")) }.compile() - assertEquals(1.0, expr("x" to 2.0)) - } - - @Test - fun testPower() { - val expr = RealField - .mstInField { binaryOperationFunction("pow")(symbol("x"), number(2)) } - .compile() - - assertEquals(4.0, expr("x" to 2.0)) - } -} 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 69% 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 ff10c8a43..683c0337c 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,41 +1,41 @@ -package kscience.kmath.estree +package space.kscience.kmath.estree -import kscience.kmath.ast.* -import kscience.kmath.complex.ComplexField -import kscience.kmath.complex.toComplex -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.ByteRing -import kscience.kmath.operations.RealField +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.DoubleField import kotlin.test.Test import kotlin.test.assertEquals internal class TestESTreeConsistencyWithInterpreter { @Test fun mstSpace() { - val res1 = MstSpace.mstInSpace { + val res1 = MstGroup.mstInGroup { binaryOperationFunction("+")( unaryOperationFunction("+")( - number(3.toByte()) - (number(2.toByte()) + (multiply( + number(3.toByte()) - (number(2.toByte()) + (scale( add(number(1), number(1)), - 2 + 2.0 ) + number(1.toByte()) * 3.toByte() - number(1.toByte()))) ), number(1) - ) + symbol("x") + zero + ) + bindSymbol("x") + zero }("x" to MST.Numeric(2)) - val res2 = MstSpace.mstInSpace { + val res2 = MstGroup.mstInGroup { binaryOperationFunction("+")( unaryOperationFunction("+")( - number(3.toByte()) - (number(2.toByte()) + (multiply( + number(3.toByte()) - (number(2.toByte()) + (scale( add(number(1), number(1)), - 2 + 2.0 ) + number(1.toByte()) * 3.toByte() - number(1.toByte()))) ), number(1) - ) + symbol("x") + zero + ) + bindSymbol("x") + zero }.compile()("x" to MST.Numeric(2)) assertEquals(res1, res2) @@ -46,9 +46,9 @@ internal class TestESTreeConsistencyWithInterpreter { val res1 = ByteRing.mstInRing { binaryOperationFunction("+")( unaryOperationFunction("+")( - (symbol("x") - (2.toByte() + (multiply( + (bindSymbol("x") - (2.toByte() + (scale( add(number(1), number(1)), - 2 + 2.0 ) + 1.toByte()))) * 3.0 - 1.toByte() ), @@ -59,9 +59,9 @@ internal class TestESTreeConsistencyWithInterpreter { val res2 = ByteRing.mstInRing { binaryOperationFunction("+")( unaryOperationFunction("+")( - (symbol("x") - (2.toByte() + (multiply( + (bindSymbol("x") - (2.toByte() + (scale( add(number(1), number(1)), - 2 + 2.0 ) + 1.toByte()))) * 3.0 - 1.toByte() ), number(1) @@ -73,17 +73,17 @@ internal class TestESTreeConsistencyWithInterpreter { @Test fun realField() { - val res1 = RealField.mstInField { + val res1 = DoubleField.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") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero }("x" to 2.0) - val res2 = RealField.mstInField { + val res2 = DoubleField.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") + (scale(add(number(1.0), number(1.0)), 2.0) + 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") + (scale(add(number(1.0), number(1.0)), 2.0) + 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") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt new file mode 100644 index 000000000..d59c048b6 --- /dev/null +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt @@ -0,0 +1,43 @@ +package space.kscience.kmath.estree + +import space.kscience.kmath.ast.mstInExtendedField +import space.kscience.kmath.ast.mstInField +import space.kscience.kmath.ast.mstInGroup +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.DoubleField +import kotlin.random.Random +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class TestESTreeOperationsSupport { + @Test + fun testUnaryOperationInvocation() { + val expression = DoubleField.mstInGroup { -bindSymbol("x") }.compile() + val res = expression("x" to 2.0) + assertEquals(-2.0, res) + } + + @Test + fun testBinaryOperationInvocation() { + val expression = DoubleField.mstInGroup { -bindSymbol("x") + number(1.0) }.compile() + val res = expression("x" to 2.0) + assertEquals(-1.0, res) + } + + @Test + fun testConstProductInvocation() { + val res = DoubleField.mstInField { bindSymbol("x") * 2 }("x" to 2.0) + assertEquals(4.0, res) + } + + @Test + fun testMultipleCalls() { + val e = + DoubleField.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()) } + println(s) + } +} diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt new file mode 100644 index 000000000..6be963175 --- /dev/null +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt @@ -0,0 +1,54 @@ +package space.kscience.kmath.estree + +import space.kscience.kmath.ast.mstInField +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.DoubleField +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class TestESTreeSpecialization { + @Test + fun testUnaryPlus() { + val expr = DoubleField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile() + assertEquals(2.0, expr("x" to 2.0)) + } + + @Test + fun testUnaryMinus() { + val expr = DoubleField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile() + assertEquals(-2.0, expr("x" to 2.0)) + } + + @Test + fun testAdd() { + val expr = DoubleField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile() + assertEquals(4.0, expr("x" to 2.0)) + } + + @Test + fun testSine() { + val expr = DoubleField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile() + assertEquals(0.0, expr("x" to 0.0)) + } + + @Test + fun testMinus() { + val expr = DoubleField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile() + assertEquals(0.0, expr("x" to 2.0)) + } + + @Test + fun testDivide() { + val expr = DoubleField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile() + assertEquals(1.0, expr("x" to 2.0)) + } + + @Test + fun testPower() { + val expr = DoubleField + .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 95% 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 cd1236b70..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 @@ -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 94% 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..4522c966f 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 @@ -86,7 +86,7 @@ internal inline fun ClassWriter.visitField( descriptor: String, signature: String?, value: Any?, - block: FieldVisitor.() -> Unit + block: FieldVisitor.() -> Unit, ): FieldVisitor { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return visitField(access, name, descriptor, signature, value).apply(block) 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 66% 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..0a0c21d8a 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.misc.StringSymbol +import space.kscience.kmath.misc.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 86% 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..9a38ce81a 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 +// TODO move to common when https://github.com/h0tk3y/better-parse/pull/37 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.GroupOperations +import space.kscience.kmath.operations.PowerOperations +import space.kscience.kmath.operations.RingOperations /** * better-parse implementation of grammar defined in the ArithmeticsEvaluator.g4. @@ -25,8 +25,8 @@ import kscience.kmath.operations.SpaceOperations */ public object ArithmeticsEvaluator : Grammar() { // TODO replace with "...".toRegex() when better-parse 0.4.1 is released - private val num: Token by regexToken("[\\d.]+(?:[eE][-+]?\\d+)?") - private val id: Token by regexToken("[a-z_A-Z][\\da-z_A-Z]*") + private val num: Token by regexToken("[\\d.]+(?:[eE][-+]?\\d+)?".toRegex()) + private val id: Token by regexToken("[a-z_A-Z][\\da-z_A-Z]*".toRegex()) private val lpar: Token by literalToken("(") private val rpar: Token by literalToken(")") private val comma: Token by literalToken(",") @@ -35,7 +35,7 @@ public object ArithmeticsEvaluator : Grammar() { private val div: Token by literalToken("/") private val minus: Token by literalToken("-") private val plus: Token by literalToken("+") - private val ws: Token by regexToken("\\s+", ignore = true) + private val ws: Token by regexToken("\\s+".toRegex(), ignore = true) private val number: Parser by num use { MST.Numeric(text.toDouble()) } private val singular: Parser by id use { MST.Symbolic(text) } @@ -55,7 +55,7 @@ public object ArithmeticsEvaluator : Grammar() { .or(binaryFunction) .or(unaryFunction) .or(singular) - .or(-minus and parser(ArithmeticsEvaluator::term) map { MST.Unary(SpaceOperations.MINUS_OPERATION, it) }) + .or(-minus and parser(ArithmeticsEvaluator::term) map { MST.Unary(GroupOperations.MINUS_OPERATION, it) }) .or(-lpar and parser(ArithmeticsEvaluator::subSumChain) and -rpar) private val powChain: Parser by leftAssociative(term = term, operator = pow) { a, _, b -> @@ -77,9 +77,9 @@ public object ArithmeticsEvaluator : Grammar() { operator = plus or minus use TokenMatch::type ) { a, op, b -> if (op == plus) - MST.Binary(SpaceOperations.PLUS_OPERATION, a, b) + MST.Binary(GroupOperations.PLUS_OPERATION, a, b) else - MST.Binary(SpaceOperations.MINUS_OPERATION, a, b) + MST.Binary(GroupOperations.MINUS_OPERATION, a, b) } override val rootParser: Parser by subSumChain diff --git a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmOperationsSupport.kt b/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmOperationsSupport.kt deleted file mode 100644 index 2ce52aa87..000000000 --- a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmOperationsSupport.kt +++ /dev/null @@ -1,41 +0,0 @@ -package 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 kotlin.random.Random -import kotlin.test.Test -import kotlin.test.assertEquals - -internal class TestAsmOperationsSupport { - @Test - fun testUnaryOperationInvocation() { - val expression = RealField.mstInSpace { -symbol("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 res = expression("x" to 2.0) - assertEquals(-1.0, res) - } - - @Test - fun testConstProductInvocation() { - val res = RealField.mstInField { symbol("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 r = Random(0) - var s = 0.0 - repeat(1000000) { s += e("x" to r.nextDouble()) } - println(s) - } -} diff --git a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmSpecialization.kt b/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmSpecialization.kt deleted file mode 100644 index 602c54651..000000000 --- a/kmath-ast/src/jvmTest/kotlin/kscience/kmath/asm/TestAsmSpecialization.kt +++ /dev/null @@ -1,54 +0,0 @@ -package kscience.kmath.asm - -import kscience.kmath.ast.mstInField -import kscience.kmath.expressions.invoke -import 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() - assertEquals(2.0, expr("x" to 2.0)) - } - - @Test - fun testUnaryMinus() { - val expr = RealField.mstInField { unaryOperationFunction("-")(symbol("x")) }.compile() - assertEquals(-2.0, expr("x" to 2.0)) - } - - @Test - fun testAdd() { - val expr = RealField.mstInField { binaryOperationFunction("+")(symbol("x"), symbol("x")) }.compile() - assertEquals(4.0, expr("x" to 2.0)) - } - - @Test - fun testSine() { - val expr = RealField.mstInField { unaryOperationFunction("sin")(symbol("x")) }.compile() - assertEquals(0.0, expr("x" to 0.0)) - } - - @Test - fun testMinus() { - val expr = RealField.mstInField { binaryOperationFunction("-")(symbol("x"), symbol("x")) }.compile() - assertEquals(0.0, expr("x" to 2.0)) - } - - @Test - fun testDivide() { - val expr = RealField.mstInField { binaryOperationFunction("/")(symbol("x"), symbol("x")) }.compile() - assertEquals(1.0, expr("x" to 2.0)) - } - - @Test - fun testPower() { - val expr = RealField - .mstInField { binaryOperationFunction("pow")(symbol("x"), number(2)) } - .compile() - - assertEquals(4.0, expr("x" to 2.0)) - } -} 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 69% 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 4091aa8ed..abc320360 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,40 +1,41 @@ -package kscience.kmath.asm +package space.kscience.kmath.asm -import kscience.kmath.ast.* -import kscience.kmath.complex.* -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.ByteRing -import kscience.kmath.operations.RealField +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.DoubleField import kotlin.test.Test import kotlin.test.assertEquals internal class TestAsmConsistencyWithInterpreter { @Test fun mstSpace() { - val res1 = MstSpace.mstInSpace { + val res1 = MstGroup.mstInGroup { binaryOperationFunction("+")( unaryOperationFunction("+")( - number(3.toByte()) - (number(2.toByte()) + (multiply( + number(3.toByte()) - (number(2.toByte()) + (scale( add(number(1), number(1)), - 2 + 2.0 ) + number(1.toByte()) * 3.toByte() - number(1.toByte()))) ), number(1) - ) + symbol("x") + zero + ) + bindSymbol("x") + zero }("x" to MST.Numeric(2)) - val res2 = MstSpace.mstInSpace { + val res2 = MstGroup.mstInGroup { binaryOperationFunction("+")( unaryOperationFunction("+")( - number(3.toByte()) - (number(2.toByte()) + (multiply( + number(3.toByte()) - (number(2.toByte()) + (scale( add(number(1), number(1)), - 2 + 2.0 ) + number(1.toByte()) * 3.toByte() - number(1.toByte()))) ), number(1) - ) + symbol("x") + zero + ) + bindSymbol("x") + zero }.compile()("x" to MST.Numeric(2)) assertEquals(res1, res2) @@ -45,9 +46,9 @@ internal class TestAsmConsistencyWithInterpreter { val res1 = ByteRing.mstInRing { binaryOperationFunction("+")( unaryOperationFunction("+")( - (symbol("x") - (2.toByte() + (multiply( + (bindSymbol("x") - (2.toByte() + (scale( add(number(1), number(1)), - 2 + 2.0 ) + 1.toByte()))) * 3.0 - 1.toByte() ), @@ -58,9 +59,9 @@ internal class TestAsmConsistencyWithInterpreter { val res2 = ByteRing.mstInRing { binaryOperationFunction("+")( unaryOperationFunction("+")( - (symbol("x") - (2.toByte() + (multiply( + (bindSymbol("x") - (2.toByte() + (scale( add(number(1), number(1)), - 2 + 2.0 ) + 1.toByte()))) * 3.0 - 1.toByte() ), number(1) @@ -72,17 +73,17 @@ internal class TestAsmConsistencyWithInterpreter { @Test fun realField() { - val res1 = RealField.mstInField { + val res1 = DoubleField.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") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero }("x" to 2.0) - val res2 = RealField.mstInField { + val res2 = DoubleField.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") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero @@ -95,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") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero @@ -103,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") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), number(1) / 2 + number(2.0) * one ) + zero diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt new file mode 100644 index 000000000..5d70cb76b --- /dev/null +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt @@ -0,0 +1,43 @@ +package space.kscience.kmath.asm + +import space.kscience.kmath.ast.mstInExtendedField +import space.kscience.kmath.ast.mstInField +import space.kscience.kmath.ast.mstInGroup +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.DoubleField +import kotlin.random.Random +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class TestAsmOperationsSupport { + @Test + fun testUnaryOperationInvocation() { + val expression = DoubleField.mstInGroup { -bindSymbol("x") }.compile() + val res = expression("x" to 2.0) + assertEquals(-2.0, res) + } + + @Test + fun testBinaryOperationInvocation() { + val expression = DoubleField.mstInGroup { -bindSymbol("x") + number(1.0) }.compile() + val res = expression("x" to 2.0) + assertEquals(-1.0, res) + } + + @Test + fun testConstProductInvocation() { + val res = DoubleField.mstInField { bindSymbol("x") * 2 }("x" to 2.0) + assertEquals(4.0, res) + } + + @Test + fun testMultipleCalls() { + val e = + DoubleField.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()) } + println(s) + } +} diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt new file mode 100644 index 000000000..f485260c9 --- /dev/null +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt @@ -0,0 +1,54 @@ +package space.kscience.kmath.asm + +import space.kscience.kmath.ast.mstInField +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.operations.DoubleField +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class TestAsmSpecialization { + @Test + fun testUnaryPlus() { + val expr = DoubleField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile() + assertEquals(2.0, expr("x" to 2.0)) + } + + @Test + fun testUnaryMinus() { + val expr = DoubleField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile() + assertEquals(-2.0, expr("x" to 2.0)) + } + + @Test + fun testAdd() { + val expr = DoubleField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile() + assertEquals(4.0, expr("x" to 2.0)) + } + + @Test + fun testSine() { + val expr = DoubleField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile() + assertEquals(0.0, expr("x" to 0.0)) + } + + @Test + fun testMinus() { + val expr = DoubleField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile() + assertEquals(0.0, expr("x" to 2.0)) + } + + @Test + fun testDivide() { + val expr = DoubleField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile() + assertEquals(1.0, expr("x" to 2.0)) + } + + @Test + fun testPower() { + val expr = DoubleField + .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 81% 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..1450cab84 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,12 +1,12 @@ -package kscience.kmath.ast +package space.kscience.kmath.ast -import kscience.kmath.operations.Field -import kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.Field import kotlin.test.Test import kotlin.test.assertEquals internal class ParserPrecedenceTest { - private val f: Field = RealField + private val f: Field = DoubleField @Test fun test1(): Unit = assertEquals(6.0, f.evaluate("2*2+2".parseMath())) 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 79% 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 ffc4732ff..3d5449043 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.complex.Complex -import kscience.kmath.complex.ComplexField -import kscience.kmath.expressions.invoke -import kscience.kmath.operations.Algebra -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.DoubleField import kotlin.test.Test import kotlin.test.assertEquals @@ -33,14 +33,14 @@ internal class ParserTest { @Test fun `evaluate MST with unary function`() { val mst = "sin(0)".parseMath() - val res = RealField.evaluate(mst) + val res = DoubleField.evaluate(mst) assertEquals(0.0, res) } @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 08b472295..56dcef29a 100644 --- a/kmath-commons/build.gradle.kts +++ b/kmath-commons/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("ru.mipt.npm.jvm") + id("ru.mipt.npm.gradle.jvm") } description = "Commons math binding for kmath" @@ -12,6 +12,6 @@ dependencies { api("org.apache.commons:commons-math3:3.6.1") } -readme{ +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/linear/CMMatrix.kt b/kmath-commons/src/main/kotlin/kscience/kmath/commons/linear/CMMatrix.kt deleted file mode 100644 index 811c0c2d5..000000000 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/linear/CMMatrix.kt +++ /dev/null @@ -1,118 +0,0 @@ -package kscience.kmath.commons.linear - -import kscience.kmath.linear.* -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.structures.RealBuffer -import org.apache.commons.math3.linear.* -import kotlin.reflect.KClass -import kotlin.reflect.cast - -public inline class CMMatrix(public val origin: RealMatrix) : Matrix { - public override val rowNum: Int get() = origin.rowDimension - public override val colNum: Int get() = origin.columnDimension - - @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) - - public override operator fun get(i: Int, j: Int): Double = origin.getEntry(i, j) -} - - -public fun RealMatrix.asMatrix(): CMMatrix = CMMatrix(this) - -public class CMVector(public val origin: RealVector) : Point { - public override val size: Int get() = origin.dimension - - public override operator fun get(index: Int): Double = origin.getEntry(index) - - public override operator fun iterator(): Iterator = origin.toArray().iterator() -} - -public fun Point.toCM(): CMVector = if (this is CMVector) this else { - val array = DoubleArray(size) { this[it] } - CMVector(ArrayRealVector(array)) -} - -public fun RealVector.toPoint(): CMVector = CMVector(this) - -public object CMMatrixContext : MatrixContext { - public override fun produce(rows: Int, columns: Int, initializer: (i: Int, j: Int) -> Double): CMMatrix { - val array = Array(rows) { i -> DoubleArray(columns) { j -> initializer(i, j) } } - return CMMatrix(Array2DRowRealMatrix(array)) - } - - @OptIn(UnstableKMathAPI::class) - public fun Matrix.toCM(): CMMatrix = when (val matrix = origin) { - is CMMatrix -> matrix - else -> { - //TODO add feature analysis - val array = Array(rowNum) { i -> DoubleArray(colNum) { j -> get(i, j) } } - CMMatrix(Array2DRowRealMatrix(array)) - } - } - - public override fun Matrix.dot(other: Matrix): CMMatrix = - CMMatrix(toCM().origin.multiply(other.toCM().origin)) - - public override fun Matrix.dot(vector: Point): CMVector = - CMVector(toCM().origin.preMultiply(vector.toCM().origin)) - - public override operator fun Matrix.unaryMinus(): CMMatrix = - produce(rowNum, colNum) { i, j -> -get(i, j) } - - public override fun add(a: Matrix, b: Matrix): CMMatrix = - CMMatrix(a.toCM().origin.multiply(b.toCM().origin)) - - public override operator fun Matrix.minus(b: Matrix): CMMatrix = - CMMatrix(toCM().origin.subtract(b.toCM().origin)) - - public override fun multiply(a: Matrix, k: Number): CMMatrix = - CMMatrix(a.toCM().origin.scalarMultiply(k.toDouble())) - - public override operator fun Matrix.times(value: Double): CMMatrix = - produce(rowNum, colNum) { i, j -> get(i, j) * value } -} - -public operator fun CMMatrix.plus(other: CMMatrix): CMMatrix = - CMMatrix(origin.add(other.origin)) - -public operator fun CMMatrix.minus(other: CMMatrix): CMMatrix = - CMMatrix(origin.subtract(other.origin)) - -public infix fun CMMatrix.dot(other: CMMatrix): CMMatrix = - CMMatrix(origin.multiply(other.origin)) 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 87% 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..58e9687e5 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,12 @@ -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.StringSymbol +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.NumbersAddOperations /** * A field over commons-math [DerivativeStructure]. @@ -16,7 +18,8 @@ import org.apache.commons.math3.analysis.differentiation.DerivativeStructure public class DerivativeStructureField( public val order: Int, bindings: Map, -) : ExtendedField, ExpressionAlgebra, RingWithNumbers { +) : ExtendedField, ExpressionAlgebra, + NumbersAddOperations { public val numberOfVariables: Int = bindings.size public override val zero: DerivativeStructure by lazy { DerivativeStructure(numberOfVariables, order) } @@ -48,11 +51,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" } @@ -62,13 +65,11 @@ public class DerivativeStructureField( public fun DerivativeStructure.derivative(vararg symbols: Symbol): Double = derivative(symbols.toList()) + override fun DerivativeStructure.unaryMinus(): DerivativeStructure = negate() + public override fun add(a: DerivativeStructure, b: DerivativeStructure): DerivativeStructure = a.add(b) - public override fun multiply(a: DerivativeStructure, k: Number): DerivativeStructure = when (k) { - is Double -> a.multiply(k) - is Int -> a.multiply(k) - else -> a.multiply(k.toDouble()) - } + public override fun scale(a: DerivativeStructure, value: Double): DerivativeStructure = a.multiply(value) public override fun multiply(a: DerivativeStructure, b: DerivativeStructure): DerivativeStructure = a.multiply(b) public override fun divide(a: DerivativeStructure, b: DerivativeStructure): DerivativeStructure = a.divide(b) diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt new file mode 100644 index 000000000..e1ba7d777 --- /dev/null +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt @@ -0,0 +1,92 @@ +package space.kscience.kmath.commons.integration + +import org.apache.commons.math3.analysis.integration.IterativeLegendreGaussIntegrator +import org.apache.commons.math3.analysis.integration.SimpsonIntegrator +import space.kscience.kmath.integration.* +import space.kscience.kmath.misc.UnstableKMathAPI + +/** + * Integration wrapper for Common-maths UnivariateIntegrator + */ +public class CMIntegrator( + private val defaultMaxCalls: Int = 200, + public val integratorBuilder: (Integrand) -> org.apache.commons.math3.analysis.integration.UnivariateIntegrator, +) : UnivariateIntegrator { + + public class TargetRelativeAccuracy(public val value: Double) : IntegrandFeature + public class TargetAbsoluteAccuracy(public val value: Double) : IntegrandFeature + + public class MinIterations(public val value: Int) : IntegrandFeature + public class MaxIterations(public val value: Int) : IntegrandFeature + + override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand { + val integrator = integratorBuilder(integrand) + val maxCalls = integrand.getFeature()?.maxCalls ?: defaultMaxCalls + val remainingCalls = maxCalls - integrand.calls + val range = integrand.getFeature>()?.range + ?: error("Integration range is not provided") + val res = integrator.integrate(remainingCalls, integrand.function, range.start, range.endInclusive) + + return integrand + + IntegrandValue(res) + + IntegrandAbsoluteAccuracy(integrator.absoluteAccuracy) + + IntegrandRelativeAccuracy(integrator.relativeAccuracy) + + IntegrandCalls(integrator.evaluations + integrand.calls) + } + + + public companion object { + /** + * Create a Simpson integrator based on [SimpsonIntegrator] + */ + public fun simpson(defaultMaxCalls: Int = 200): CMIntegrator = CMIntegrator(defaultMaxCalls) { integrand -> + val absoluteAccuracy = integrand.getFeature()?.value + ?: SimpsonIntegrator.DEFAULT_ABSOLUTE_ACCURACY + val relativeAccuracy = integrand.getFeature()?.value + ?: SimpsonIntegrator.DEFAULT_ABSOLUTE_ACCURACY + val minIterations = integrand.getFeature()?.value + ?: SimpsonIntegrator.DEFAULT_MIN_ITERATIONS_COUNT + val maxIterations = integrand.getFeature()?.value + ?: SimpsonIntegrator.SIMPSON_MAX_ITERATIONS_COUNT + + SimpsonIntegrator(relativeAccuracy, absoluteAccuracy, minIterations, maxIterations) + } + + /** + * Create a Gauss-Legandre integrator based on [IterativeLegendreGaussIntegrator] + */ + public fun legandre(numPoints: Int, defaultMaxCalls: Int = numPoints * 5): CMIntegrator = + CMIntegrator(defaultMaxCalls) { integrand -> + val absoluteAccuracy = integrand.getFeature()?.value + ?: IterativeLegendreGaussIntegrator.DEFAULT_ABSOLUTE_ACCURACY + val relativeAccuracy = integrand.getFeature()?.value + ?: IterativeLegendreGaussIntegrator.DEFAULT_ABSOLUTE_ACCURACY + val minIterations = integrand.getFeature()?.value + ?: IterativeLegendreGaussIntegrator.DEFAULT_MIN_ITERATIONS_COUNT + val maxIterations = integrand.getFeature()?.value + ?: IterativeLegendreGaussIntegrator.DEFAULT_MAX_ITERATIONS_COUNT + + IterativeLegendreGaussIntegrator( + numPoints, + relativeAccuracy, + absoluteAccuracy, + minIterations, + maxIterations + ) + } + } +} + +@UnstableKMathAPI +public var MutableList.targetAbsoluteAccuracy: Double? + get() = filterIsInstance().lastOrNull()?.value + set(value) { + value?.let { add(CMIntegrator.TargetAbsoluteAccuracy(value)) } + } + +@UnstableKMathAPI +public var MutableList.targetRelativeAccuracy: Double? + get() = filterIsInstance().lastOrNull()?.value + set(value) { + value?.let { add(CMIntegrator.TargetRelativeAccuracy(value)) } + } \ No newline at end of file diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/GaussRuleIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/GaussRuleIntegrator.kt new file mode 100644 index 000000000..5a18756ac --- /dev/null +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/GaussRuleIntegrator.kt @@ -0,0 +1,94 @@ +/* + * Copyright 2015 Alexander Nozik. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package space.kscience.kmath.commons.integration + +import org.apache.commons.math3.analysis.integration.gauss.GaussIntegrator +import org.apache.commons.math3.analysis.integration.gauss.GaussIntegratorFactory +import space.kscience.kmath.integration.* + +/** + * A simple one-pass integrator based on Gauss rule + */ +public class GaussRuleIntegrator( + private val numpoints: Int, + private var type: GaussRule = GaussRule.LEGANDRE, +) : UnivariateIntegrator { + + override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand { + val range = integrand.getFeature>()?.range + ?: error("Integration range is not provided") + val integrator: GaussIntegrator = getIntegrator(range) + //TODO check performance + val res: Double = integrator.integrate(integrand.function) + return integrand + IntegrandValue(res) + IntegrandCalls(integrand.calls + numpoints) + } + + private fun getIntegrator(range: ClosedRange): GaussIntegrator { + return when (type) { + GaussRule.LEGANDRE -> factory.legendre( + numpoints, + range.start, + range.endInclusive + ) + GaussRule.LEGANDREHP -> factory.legendreHighPrecision( + numpoints, + range.start, + range.endInclusive + ) + GaussRule.UNIFORM -> GaussIntegrator( + getUniformRule( + range.start, + range.endInclusive, + numpoints + ) + ) + } + } + + private fun getUniformRule( + min: Double, + max: Double, + numPoints: Int, + ): org.apache.commons.math3.util.Pair { + assert(numPoints > 2) + val points = DoubleArray(numPoints) + val weights = DoubleArray(numPoints) + val step = (max - min) / (numPoints - 1) + points[0] = min + for (i in 1 until numPoints) { + points[i] = points[i - 1] + step + weights[i] = step + } + return org.apache.commons.math3.util.Pair(points, weights) + } + + public enum class GaussRule { + UNIFORM, LEGANDRE, LEGANDREHP + } + + public companion object { + private val factory: GaussIntegratorFactory = GaussIntegratorFactory() + + public fun integrate( + range: ClosedRange, + numPoints: Int = 100, + type: GaussRule = GaussRule.LEGANDRE, + function: (Double) -> Double, + ): Double = GaussRuleIntegrator(numPoints, type).integrate( + UnivariateIntegrand(function, IntegrationRange(range)) + ).value!! + } +} \ No newline at end of file diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt new file mode 100644 index 000000000..80929e6b9 --- /dev/null +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt @@ -0,0 +1,141 @@ +package space.kscience.kmath.commons.linear + +import org.apache.commons.math3.linear.* +import space.kscience.kmath.linear.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.StructureFeature +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.structures.DoubleBuffer +import kotlin.reflect.KClass +import kotlin.reflect.cast + +public inline class CMMatrix(public val origin: RealMatrix) : Matrix { + public override val rowNum: Int get() = origin.rowDimension + public override val colNum: Int get() = origin.columnDimension + + public override operator fun get(i: Int, j: Int): Double = origin.getEntry(i, j) +} + +public inline class CMVector(public val origin: RealVector) : Point { + public override val size: Int get() = origin.dimension + + public override operator fun get(index: Int): Double = origin.getEntry(index) + + public override operator fun iterator(): Iterator = origin.toArray().iterator() +} + +public fun RealVector.toPoint(): CMVector = CMVector(this) + +public object CMLinearSpace : LinearSpace { + override val elementAlgebra: DoubleField get() = DoubleField + + public override fun buildMatrix( + rows: Int, + columns: Int, + initializer: DoubleField.(i: Int, j: Int) -> Double, + ): CMMatrix { + val array = Array(rows) { i -> DoubleArray(columns) { j -> DoubleField.initializer(i, j) } } + return CMMatrix(Array2DRowRealMatrix(array)) + } + + @OptIn(UnstableKMathAPI::class) + public fun Matrix.toCM(): CMMatrix = when (val matrix = origin) { + is CMMatrix -> matrix + else -> { + //TODO add feature analysis + val array = Array(rowNum) { i -> DoubleArray(colNum) { j -> get(i, j) } } + Array2DRowRealMatrix(array).wrap() + } + } + + public fun Point.toCM(): CMVector = if (this is CMVector) this else { + val array = DoubleArray(size) { this[it] } + ArrayRealVector(array).wrap() + } + + internal fun RealMatrix.wrap(): CMMatrix = CMMatrix(this) + internal fun RealVector.wrap(): CMVector = CMVector(this) + + override fun buildVector(size: Int, initializer: DoubleField.(Int) -> Double): Point = + ArrayRealVector(DoubleArray(size) { DoubleField.initializer(it) }).wrap() + + override fun Matrix.plus(other: Matrix): CMMatrix = + toCM().origin.add(other.toCM().origin).wrap() + + override fun Point.plus(other: Point): CMVector = + toCM().origin.add(other.toCM().origin).wrap() + + override fun Point.minus(other: Point): CMVector = + toCM().origin.subtract(other.toCM().origin).wrap() + + public override fun Matrix.dot(other: Matrix): CMMatrix = + toCM().origin.multiply(other.toCM().origin).wrap() + + public override fun Matrix.dot(vector: Point): CMVector = + toCM().origin.preMultiply(vector.toCM().origin).wrap() + + public override operator fun Matrix.minus(other: Matrix): CMMatrix = + toCM().origin.subtract(other.toCM().origin).wrap() + + public override operator fun Matrix.times(value: Double): CMMatrix = + toCM().origin.scalarMultiply(value).wrap() + + override fun Double.times(m: Matrix): CMMatrix = + m * this + + override fun Point.times(value: Double): CMVector = + toCM().origin.mapMultiply(value).wrap() + + override fun Double.times(v: Point): CMVector = + v * this + + @UnstableKMathAPI + override fun getFeature(structure: Matrix, type: KClass): F? { + //Return the feature if it is intrinsic to the structure + structure.getFeature(type)?.let { return it } + + val origin = structure.toCM().origin + + return 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 { DoubleBuffer(sv.singularValues) } + } + else -> null + }?.let(type::cast) + } +} + +public operator fun CMMatrix.plus(other: CMMatrix): CMMatrix = CMMatrix(origin.add(other.origin)) + +public operator fun CMMatrix.minus(other: CMMatrix): CMMatrix = CMMatrix(origin.subtract(other.origin)) + +public infix fun CMMatrix.dot(other: CMMatrix): CMMatrix = CMMatrix(origin.multiply(other.origin)) 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 54% 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 1c0896597..b4706473a 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.Matrix -import kscience.kmath.linear.Point import org.apache.commons.math3.linear.* +import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.linear.Point public enum class CMDecomposition { LUP, @@ -12,9 +12,9 @@ public enum class CMDecomposition { CHOLESKY } -public fun CMMatrixContext.solver( +public fun CMLinearSpace.solver( a: Matrix, - decomposition: CMDecomposition = CMDecomposition.LUP + decomposition: CMDecomposition = CMDecomposition.LUP, ): DecompositionSolver = when (decomposition) { CMDecomposition.LUP -> LUDecomposition(a.toCM().origin).solver CMDecomposition.RRQR -> RRQRDecomposition(a.toCM().origin).solver @@ -23,19 +23,19 @@ public fun CMMatrixContext.solver( CMDecomposition.CHOLESKY -> CholeskyDecomposition(a.toCM().origin).solver } -public fun CMMatrixContext.solve( +public fun CMLinearSpace.solve( a: Matrix, b: Matrix, - decomposition: CMDecomposition = CMDecomposition.LUP -): CMMatrix = solver(a, decomposition).solve(b.toCM().origin).asMatrix() + decomposition: CMDecomposition = CMDecomposition.LUP, +): CMMatrix = solver(a, decomposition).solve(b.toCM().origin).wrap() -public fun CMMatrixContext.solve( +public fun CMLinearSpace.solve( a: Matrix, b: Point, - decomposition: CMDecomposition = CMDecomposition.LUP + decomposition: CMDecomposition = CMDecomposition.LUP, ): CMVector = solver(a, decomposition).solve(b.toCM().origin).toPoint() -public fun CMMatrixContext.inverse( +public fun CMLinearSpace.inverse( a: Matrix, - decomposition: CMDecomposition = CMDecomposition.LUP -): CMMatrix = solver(a, decomposition).inverse.asMatrix() + decomposition: CMDecomposition = CMDecomposition.LUP, +): CMMatrix = solver(a, decomposition).inverse.wrap() 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/CMOptimization.kt similarity index 63% 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/CMOptimization.kt index d6f79529a..444c505c9 100644 --- a/kmath-commons/src/main/kotlin/kscience/kmath/commons/optimization/CMOptimizationProblem.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimization.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,17 +9,36 @@ 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.DifferentiableExpression +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.SymbolIndexer +import space.kscience.kmath.expressions.derivative +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.optimization.* import kotlin.reflect.KClass public operator fun PointValuePair.component1(): DoubleArray = point public operator fun PointValuePair.component2(): Double = value -public class CMOptimizationProblem(override val symbols: List, ) : - OptimizationProblem, SymbolIndexer, OptimizationFeature { +@OptIn(UnstableKMathAPI::class) +public class CMOptimization( + override val symbols: List, +) : FunctionOptimization, NoDerivFunctionOptimization, SymbolIndexer, OptimizationFeature { + private val optimizationData: HashMap, OptimizationData> = HashMap() - private var optimizatorBuilder: (() -> MultivariateOptimizer)? = null - public var convergenceChecker: ConvergenceChecker = SimpleValueChecker(DEFAULT_RELATIVE_TOLERANCE, - DEFAULT_ABSOLUTE_TOLERANCE, DEFAULT_MAX_ITER) + private var optimizerBuilder: (() -> MultivariateOptimizer)? = null + public var convergenceChecker: ConvergenceChecker = SimpleValueChecker( + DEFAULT_RELATIVE_TOLERANCE, + DEFAULT_ABSOLUTE_TOLERANCE, + DEFAULT_MAX_ITER + ) + + override var maximize: Boolean + get() = optimizationData[GoalType::class] == GoalType.MAXIMIZE + set(value) { + optimizationData[GoalType::class] = if (value) GoalType.MAXIMIZE else GoalType.MINIMIZE + } public fun addOptimizationData(data: OptimizationData) { optimizationData[data::class] = data @@ -40,7 +54,7 @@ public class CMOptimizationProblem(override val symbols: List, ) : addOptimizationData(InitialGuess(map.toDoubleArray())) } - public override fun expression(expression: Expression): Unit { + public override fun function(expression: Expression): Unit { val objectiveFunction = ObjectiveFunction { val args = it.toMap() expression(args) @@ -48,8 +62,8 @@ public class CMOptimizationProblem(override val symbols: List, ) : addOptimizationData(objectiveFunction) } - public override fun diffExpression(expression: DifferentiableExpression>) { - expression(expression) + public override fun diffFunction(expression: DifferentiableExpression>) { + function(expression) val gradientFunction = ObjectiveFunctionGradient { val args = it.toMap() DoubleArray(symbols.size) { index -> @@ -57,8 +71,8 @@ public class CMOptimizationProblem(override val symbols: List, ) : } } addOptimizationData(gradientFunction) - if (optimizatorBuilder == null) { - optimizatorBuilder = { + if (optimizerBuilder == null) { + optimizerBuilder = { NonLinearConjugateGradientOptimizer( NonLinearConjugateGradientOptimizer.Formula.FLETCHER_REEVES, convergenceChecker @@ -70,8 +84,8 @@ public class CMOptimizationProblem(override val symbols: List, ) : public fun simplex(simplex: AbstractSimplex) { addOptimizationData(simplex) //Set optimization builder to simplex if it is not present - if (optimizatorBuilder == null) { - optimizatorBuilder = { SimplexOptimizer(convergenceChecker) } + if (optimizerBuilder == null) { + optimizerBuilder = { SimplexOptimizer(convergenceChecker) } } } @@ -84,7 +98,7 @@ public class CMOptimizationProblem(override val symbols: List, ) : } public fun optimizer(block: () -> MultivariateOptimizer) { - optimizatorBuilder = block + optimizerBuilder = block } override fun update(result: OptimizationResult) { @@ -92,19 +106,19 @@ public class CMOptimizationProblem(override val symbols: List, ) : } override fun optimize(): OptimizationResult { - val optimizer = optimizatorBuilder?.invoke() ?: error("Optimizer not defined") + val optimizer = optimizerBuilder?.invoke() ?: error("Optimizer not defined") val (point, value) = optimizer.optimize(*optimizationData.values.toTypedArray()) return OptimizationResult(point.toMap(), value, setOf(this)) } - public companion object : OptimizationProblemFactory { + public companion object : OptimizationProblemFactory { public const val DEFAULT_RELATIVE_TOLERANCE: Double = 1e-4 public const val DEFAULT_ABSOLUTE_TOLERANCE: Double = 1e-4 public const val DEFAULT_MAX_ITER: Int = 1000 - override fun build(symbols: List): CMOptimizationProblem = CMOptimizationProblem(symbols) + override fun build(symbols: List): CMOptimization = CMOptimization(symbols) } } -public fun CMOptimizationProblem.initialGuess(vararg pairs: Pair): Unit = initialGuess(pairs.toMap()) -public fun CMOptimizationProblem.simplexSteps(vararg pairs: Pair): Unit = simplexSteps(pairs.toMap()) +public fun CMOptimization.initialGuess(vararg pairs: Pair): Unit = initialGuess(pairs.toMap()) +public fun CMOptimization.simplexSteps(vararg pairs: Pair): Unit = simplexSteps(pairs.toMap()) 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 51% 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..f84dae693 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,21 +1,21 @@ -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.misc.Symbol +import space.kscience.kmath.optimization.FunctionOptimization +import space.kscience.kmath.optimization.OptimizationResult +import space.kscience.kmath.optimization.noDerivOptimizeWith +import space.kscience.kmath.optimization.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 */ -public fun Fitting.chiSquared( +public fun FunctionOptimization.Companion.chiSquared( x: Buffer, y: Buffer, yErr: Buffer, @@ -25,7 +25,7 @@ public fun Fitting.chiSquared( /** * Generate a chi squared expression from given x-y-sigma data and inline model. Provides automatic differentiation */ -public fun Fitting.chiSquared( +public fun FunctionOptimization.Companion.chiSquared( x: Iterable, y: Iterable, yErr: Iterable, @@ -43,25 +43,26 @@ public fun Fitting.chiSquared( */ public fun Expression.optimize( vararg symbols: Symbol, - configuration: CMOptimizationProblem.() -> Unit, -): OptimizationResult = optimizeWith(CMOptimizationProblem, symbols = symbols, configuration) + configuration: CMOptimization.() -> Unit, +): OptimizationResult = noDerivOptimizeWith(CMOptimization, symbols = symbols, configuration) /** * Optimize differentiable expression */ public fun DifferentiableExpression>.optimize( vararg symbols: Symbol, - configuration: CMOptimizationProblem.() -> Unit, -): OptimizationResult = optimizeWith(CMOptimizationProblem, symbols = symbols, configuration) + configuration: CMOptimization.() -> Unit, +): OptimizationResult = optimizeWith(CMOptimization, symbols = symbols, configuration) public fun DifferentiableExpression>.minimize( vararg startPoint: Pair, - configuration: CMOptimizationProblem.() -> Unit = {}, + configuration: CMOptimization.() -> Unit = {}, ): OptimizationResult { - require(startPoint.isNotEmpty()) { "Must provide a list of symbols for optimization" } - val problem = CMOptimizationProblem(startPoint.map { it.first }).apply(configuration) - problem.diffExpression(this) - problem.initialGuess(startPoint.toMap()) - problem.goal(GoalType.MINIMIZE) - return problem.optimize() + val symbols = startPoint.map { it.first }.toTypedArray() + return optimize(*symbols){ + maximize = false + initialGuess(startPoint.toMap()) + diffFunction(this@minimize) + configuration() + } } \ No newline at end of file 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 79% 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 4c83eb99f..010ea7e9f 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,14 @@ -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.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.* + /** @@ -17,7 +18,7 @@ public object Transformations { private fun Buffer.toArray(): Array = Array(size) { org.apache.commons.math3.complex.Complex(get(it).re, get(it).im) } - private fun Buffer.asArray() = if (this is RealBuffer) { + private fun Buffer.asArray() = if (this is DoubleBuffer) { array } else { DoubleArray(size) { i -> get(i) } @@ -33,34 +34,34 @@ public object Transformations { public fun fourier( normalization: DftNormalization = DftNormalization.STANDARD, - direction: TransformType = TransformType.FORWARD + direction: TransformType = TransformType.FORWARD, ): SuspendBufferTransform = { FastFourierTransformer(normalization).transform(it.toArray(), direction).asBuffer() } public fun realFourier( normalization: DftNormalization = DftNormalization.STANDARD, - direction: TransformType = TransformType.FORWARD + direction: TransformType = TransformType.FORWARD, ): SuspendBufferTransform = { FastFourierTransformer(normalization).transform(it.asArray(), direction).asBuffer() } public fun sine( normalization: DstNormalization = DstNormalization.STANDARD_DST_I, - direction: TransformType = TransformType.FORWARD + direction: TransformType = TransformType.FORWARD, ): SuspendBufferTransform = { FastSineTransformer(normalization).transform(it.asArray(), direction).asBuffer() } public fun cosine( normalization: DctNormalization = DctNormalization.STANDARD_DCT_I, - direction: TransformType = TransformType.FORWARD + direction: TransformType = TransformType.FORWARD, ): SuspendBufferTransform = { FastCosineTransformer(normalization).transform(it.asArray(), direction).asBuffer() } public fun hadamard( - direction: TransformType = TransformType.FORWARD + direction: TransformType = TransformType.FORWARD, ): SuspendBufferTransform = { FastHadamardTransformer().transform(it.asArray(), direction).asBuffer() } @@ -72,7 +73,7 @@ public object Transformations { @FlowPreview public fun Flow>.FFT( normalization: DftNormalization = DftNormalization.STANDARD, - direction: TransformType = TransformType.FORWARD + direction: TransformType = TransformType.FORWARD, ): Flow> { val transform = Transformations.fourier(normalization, direction) return map { transform(it) } @@ -82,7 +83,7 @@ public fun Flow>.FFT( @JvmName("realFFT") public fun Flow>.FFT( normalization: DftNormalization = DftNormalization.STANDARD, - direction: TransformType = TransformType.FORWARD + direction: TransformType = TransformType.FORWARD, ): Flow> { val transform = Transformations.realFourier(normalization, direction) return map(transform) @@ -96,7 +97,7 @@ public fun Flow>.FFT( public fun Flow.FFT( bufferSize: Int = Int.MAX_VALUE, normalization: DftNormalization = DftNormalization.STANDARD, - direction: TransformType = TransformType.FORWARD + direction: TransformType = TransformType.FORWARD, ): Flow = chunked(bufferSize).FFT(normalization, direction).spread() /** 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 76% 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..b19eb5950 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,10 @@ -package kscience.kmath.commons.expressions +package space.kscience.kmath.commons.expressions -import kscience.kmath.expressions.* +import space.kscience.kmath.expressions.binding +import space.kscience.kmath.expressions.derivative +import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.misc.symbol import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.test.Test @@ -24,13 +28,13 @@ 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)) + println(z.derivative(y, x)) assertEquals(z.derivative(x, y), z.derivative(y, x)) //check that improper order cause failure - assertFails { z.derivative(x,x,y) } + assertFails { z.derivative(x, x, y) } } } diff --git a/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt new file mode 100644 index 000000000..d163203f7 --- /dev/null +++ b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt @@ -0,0 +1,30 @@ +package space.kscience.kmath.commons.integration + +import org.junit.jupiter.api.Test +import space.kscience.kmath.integration.integrate +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.DoubleField.sin +import kotlin.math.PI +import kotlin.math.abs +import kotlin.test.assertTrue + +@UnstableKMathAPI +internal class IntegrationTest { + private val function: (Double) -> Double = { sin(it) } + + @Test + fun simpson() { + val res = CMIntegrator.simpson().integrate(0.0..2 * PI, function) + assertTrue { abs(res) < 1e-3 } + } + + @Test + fun customSimpson() { + val res = CMIntegrator.simpson().integrate(0.0..PI, function) { + targetRelativeAccuracy = 1e-4 + targetAbsoluteAccuracy = 1e-4 + } + assertTrue { abs(res - 2) < 1e-3 } + assertTrue { abs(res - 2) > 1e-12 } + } +} \ No newline at end of file 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 100% 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 diff --git a/kmath-complex/README.md b/kmath-complex/README.md index 8e5320225..d7b2937fd 100644 --- a/kmath-complex/README.md +++ b/kmath-complex/README.md @@ -1,45 +1,36 @@ -# The Core Module (`kmath-core`) +# Module kmath-complex -Complex and hypercomplex number systems in KMath: +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 + - [complex](src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt) : Complex Numbers + - [quaternion](src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt) : Quaternions -> #### Artifact: -> -> This module artifact: `kscience.kmath:kmath-complex:0.2.0-dev-7`. -> -> 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://dl.bintray.com/kotlin/kotlin-eap" } -> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } -> maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> -> } -> -> dependencies { -> implementation 'kscience.kmath:kmath-complex:0.2.0-dev-7' -> } -> ``` -> **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") -> } -> -> dependencies { -> implementation("kscience.kmath:kmath-complex:0.2.0-dev-7") -> } -> ``` +## Artifact: + +The Maven coordinates of this project are `space.kscience:kmath-complex:0.3.0-dev-3`. + +**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 +} + +dependencies { + implementation 'space.kscience:kmath-complex:0.3.0-dev-3' +} +``` +**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 +} + +dependencies { + implementation("space.kscience:kmath-complex:0.3.0-dev-3") +} +``` diff --git a/kmath-complex/build.gradle.kts b/kmath-complex/build.gradle.kts index 8e1ae5cb3..5b9dc3ba0 100644 --- a/kmath-complex/build.gradle.kts +++ b/kmath-complex/build.gradle.kts @@ -1,8 +1,8 @@ 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 { @@ -25,12 +25,12 @@ readme { feature( id = "complex", description = "Complex Numbers", - ref = "src/commonMain/kotlin/kscience/kmath/complex/Complex.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt" ) feature( id = "quaternion", description = "Quaternions", - ref = "src/commonMain/kotlin/kscience/kmath/complex/Quaternion.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt" ) } diff --git a/kmath-complex/docs/README-TEMPLATE.md b/kmath-complex/docs/README-TEMPLATE.md index 462fd617e..106d4aff1 100644 --- a/kmath-complex/docs/README-TEMPLATE.md +++ b/kmath-complex/docs/README-TEMPLATE.md @@ -1,6 +1,6 @@ -# The Core Module (`kmath-core`) +# Module kmath-complex -Complex and hypercomplex number systems in KMath: +Complex and hypercomplex number systems in KMath. ${features} diff --git a/kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/ComplexNDField.kt b/kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/ComplexNDField.kt deleted file mode 100644 index 5648ccee1..000000000 --- a/kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/ComplexNDField.kt +++ /dev/null @@ -1,117 +0,0 @@ -package kscience.kmath.complex - -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.nd.BufferedNDField -import kscience.kmath.nd.NDAlgebra -import kscience.kmath.nd.NDBuffer -import kscience.kmath.nd.NDStructure -import kscience.kmath.operations.* -import kscience.kmath.structures.Buffer -import kotlin.contracts.InvocationKind -import kotlin.contracts.contract - - -/** - * An optimized nd-field for complex numbers - */ -@OptIn(UnstableKMathAPI::class) -public class ComplexNDField( - shape: IntArray, -) : BufferedNDField(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/kscience/kmath/complex/Complex.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt similarity index 81% rename from kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/Complex.kt rename to kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt index f6914d3a0..a73fb0201 100644 --- a/kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/Complex.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt @@ -1,16 +1,14 @@ -package kscience.kmath.complex +package space.kscience.kmath.complex -import kscience.kmath.memory.MemoryReader -import kscience.kmath.memory.MemorySpec -import kscience.kmath.memory.MemoryWriter -import kscience.kmath.operations.ExtendedField -import kscience.kmath.operations.FieldElement -import kscience.kmath.operations.Norm -import kscience.kmath.operations.RingWithNumbers -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.* +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.* /** @@ -45,7 +43,9 @@ private val PI_DIV_2 = Complex(PI / 2, 0) /** * A field of [Complex]. */ -public object ComplexField : ExtendedField, Norm, RingWithNumbers { +@OptIn(UnstableKMathAPI::class) +public object ComplexField : ExtendedField, Norm, NumbersAddOperations, + ScaleOperations { public override val zero: Complex = 0.0.toComplex() public override val one: Complex = 1.0.toComplex() @@ -54,8 +54,14 @@ public object ComplexField : ExtendedField, Norm, Rin */ public val i: Complex by lazy { Complex(0.0, 1.0) } + override fun Complex.unaryMinus(): Complex = Complex(-re, -im) + + override fun number(value: Number): Complex = Complex(value.toDouble(), 0.0) + + override fun scale(a: Complex, value: Double): Complex = Complex(a.re * value, a.im * value) + 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()) +// public override fun multiply(a: Complex, k: Number): Complex = Complex(a.re * k.toDouble(), a.im * k.toDouble()) 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) @@ -84,8 +90,10 @@ public object ComplexField : ExtendedField, Norm, Rin } } - 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 operator fun Complex.div(k: Number): Complex = Complex(re / k.toDouble(), im / k.toDouble()) + + public override fun sin(arg: Complex): Complex = i * (exp(-i * arg) - exp(i * arg)) / 2.0 + public override fun cos(arg: Complex): Complex = (exp(-i * arg) + exp(i * arg)) / 2.0 public override fun tan(arg: Complex): Complex { val e1 = exp(-i * arg) @@ -157,7 +165,8 @@ public object ComplexField : ExtendedField, Norm, Rin public override fun norm(arg: Complex): Complex = sqrt(arg.conjugate * arg) - public 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) } /** @@ -166,6 +175,7 @@ public object ComplexField : ExtendedField, Norm, Rin * @property re The real part. * @property im The imaginary part. */ +@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) @@ -178,7 +188,8 @@ public data class Complex(val re: Double, val im: Double) : FieldElement(shape, ComplexField, Buffer.Companion::complex), + NumbersAddOperations>, + ExtendedField> { + + override val zero: BufferND by lazy { produce { zero } } + override val one: BufferND by lazy { produce { one } } + + override fun number(value: Number): BufferND { + val d = value.toComplex() // minimize conversions + return produce { d } + } + +// +// @Suppress("OVERRIDE_BY_INLINE") +// override inline fun map( +// arg: AbstractNDBuffer, +// transform: DoubleField.(Double) -> Double, +// ): RealNDElement { +// check(arg) +// val array = RealBuffer(arg.strides.linearSize) { offset -> DoubleField.transform(arg.buffer[offset]) } +// return BufferedNDFieldElement(this, array) +// } +// +// @Suppress("OVERRIDE_BY_INLINE") +// override inline fun produce(initializer: DoubleField.(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: DoubleField.(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: DoubleField.(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: StructureND, pow: Number): BufferND = arg.map { power(it, pow) } + + override fun exp(arg: StructureND): BufferND = arg.map { exp(it) } + + override fun ln(arg: StructureND): BufferND = arg.map { ln(it) } + + override fun sin(arg: StructureND): BufferND = arg.map { sin(it) } + override fun cos(arg: StructureND): BufferND = arg.map { cos(it) } + override fun tan(arg: StructureND): BufferND = arg.map { tan(it) } + override fun asin(arg: StructureND): BufferND = arg.map { asin(it) } + override fun acos(arg: StructureND): BufferND = arg.map { acos(it) } + override fun atan(arg: StructureND): BufferND = arg.map { atan(it) } + + override fun sinh(arg: StructureND): BufferND = arg.map { sinh(it) } + override fun cosh(arg: StructureND): BufferND = arg.map { cosh(it) } + override fun tanh(arg: StructureND): BufferND = arg.map { tanh(it) } + override fun asinh(arg: StructureND): BufferND = arg.map { asinh(it) } + override fun acosh(arg: StructureND): BufferND = arg.map { acosh(it) } + override fun atanh(arg: StructureND): BufferND = arg.map { atanh(it) } +} + + +/** + * Fast element production using function inlining + */ +public inline fun BufferedFieldND.produceInline(initializer: ComplexField.(Int) -> Complex): BufferND { + contract { callsInPlace(initializer, InvocationKind.EXACTLY_ONCE) } + val buffer = Buffer.complex(strides.linearSize) { offset -> ComplexField.initializer(offset) } + return BufferND(strides, buffer) +} + + +public fun AlgebraND.Companion.complex(vararg shape: Int): ComplexFieldND = ComplexFieldND(shape) + +/** + * Produce a context for n-dimensional operations inside this real field + */ +public inline fun ComplexField.nd(vararg shape: Int, action: ComplexFieldND.() -> R): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return ComplexFieldND(shape).action() +} diff --git a/kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/Quaternion.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt similarity index 81% rename from kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/Quaternion.kt rename to kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt index a0ad47b90..9a0346ca7 100644 --- a/kmath-complex/src/commonMain/kotlin/kscience/kmath/complex/Quaternion.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt @@ -1,13 +1,14 @@ -package kscience.kmath.complex +package space.kscience.kmath.complex -import kscience.kmath.memory.MemoryReader -import kscience.kmath.memory.MemorySpec -import kscience.kmath.memory.MemoryWriter -import kscience.kmath.operations.* -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.* +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.* /** @@ -34,8 +35,9 @@ public val Quaternion.r: Double /** * A field of [Quaternion]. */ +@OptIn(UnstableKMathAPI::class) public object QuaternionField : Field, Norm, PowerOperations, - ExponentialOperations, RingWithNumbers { + ExponentialOperations, NumbersAddOperations, ScaleOperations { override val zero: Quaternion = 0.toQuaternion() override val one: Quaternion = 1.toQuaternion() @@ -57,10 +59,8 @@ public object QuaternionField : Field, Norm, 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 scale(a: Quaternion, value: Double): Quaternion = + Quaternion(a.w * value, a.x * value, a.y * value, a.z * value) 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, @@ -165,12 +165,21 @@ public object QuaternionField : Field, Norm, 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 symbol(value: String): Quaternion = when (value) { + public override fun bindSymbol(value: String): Quaternion = when (value) { "i" -> i "j" -> j "k" -> k - else -> super.symbol(value) + else -> super.bindSymbol(value) } + + override fun number(value: Number): Quaternion = value.toQuaternion() + + public override fun sinh(arg: Quaternion): Quaternion = (exp(arg) - exp(-arg)) / 2.0 + public override fun cosh(arg: Quaternion): Quaternion = (exp(arg) + exp(-arg)) / 2.0 + public override fun tanh(arg: Quaternion): Quaternion = (exp(arg) - exp(-arg)) / (exp(-arg) + exp(arg)) + public override fun asinh(arg: Quaternion): Quaternion = ln(sqrt(arg * arg + one) + arg) + public override fun acosh(arg: Quaternion): Quaternion = ln(arg + sqrt((arg - one) * (arg + one))) + public override fun atanh(arg: Quaternion): Quaternion = (ln(arg + one) - ln(one - arg)) / 2.0 } /** @@ -181,8 +190,10 @@ public object QuaternionField : Field, Norm, * @property y The third component. * @property z The fourth component. */ -public data class Quaternion(val w: Double, val x: Double, val y: Double, val z: Double) : - FieldElement { +@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(), @@ -203,8 +214,7 @@ public data class Quaternion(val w: Double, val x: Double, val y: Double, val z: require(!z.isNaN()) { "x-component of quaternion is not-a-number" } } - public override val context: QuaternionField - get() = QuaternionField + public override val context: QuaternionField get() = QuaternionField /** * Returns a string representation of this quaternion. diff --git a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ExpressionFieldForComplexTest.kt b/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ExpressionFieldForComplexTest.kt deleted file mode 100644 index 1a3a55047..000000000 --- a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ExpressionFieldForComplexTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package kscience.kmath.complex - -import kscience.kmath.expressions.FunctionalExpressionField -import kscience.kmath.expressions.bind -import kscience.kmath.expressions.invoke -import kscience.kmath.expressions.symbol -import 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 = 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)) - } -} diff --git a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ComplexBufferSpecTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt similarity index 76% rename from kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ComplexBufferSpecTest.kt rename to kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt index a19ce8b95..e265e5896 100644 --- a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ComplexBufferSpecTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt @@ -1,6 +1,6 @@ -package kscience.kmath.complex +package space.kscience.kmath.complex -import kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.Buffer import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ComplexFieldTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt similarity index 96% rename from kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ComplexFieldTest.kt rename to kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt index aa25f6b4b..e00b92077 100644 --- a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ComplexFieldTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt @@ -1,6 +1,6 @@ -package kscience.kmath.complex +package space.kscience.kmath.complex -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.invoke import kotlin.math.PI import kotlin.math.abs import kotlin.test.Test diff --git a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ComplexTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt similarity index 91% rename from kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ComplexTest.kt rename to kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt index 6b7364c59..e272f502f 100644 --- a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/ComplexTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt @@ -1,6 +1,6 @@ -package kscience.kmath.complex +package space.kscience.kmath.complex -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.invoke import kotlin.math.sqrt import kotlin.test.Test import kotlin.test.assertEquals 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..3837b0d40 --- /dev/null +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ExpressionFieldForComplexTest.kt @@ -0,0 +1,22 @@ +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.misc.symbol +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class ExpressionFieldForComplexTest { + val x by symbol + + @Test + fun testComplex() { + val expression = FunctionalExpressionField(ComplexField).run { + val x = bindSymbol(x) + x * x + 2 * x + one + } + + assertEquals(expression(x to Complex(1.0, 0.0)), Complex(4.0, 0.0)) + } +} diff --git a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/QuaternionFieldTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionFieldTest.kt similarity index 95% rename from kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/QuaternionFieldTest.kt rename to kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionFieldTest.kt index df690cfc4..5ce81a251 100644 --- a/kmath-complex/src/commonTest/kotlin/kscience/kmath/complex/QuaternionFieldTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionFieldTest.kt @@ -1,6 +1,6 @@ -package kscience.kmath.complex +package space.kscience.kmath.complex -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.invoke import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-core/README.md b/kmath-core/README.md index a38b3acaa..096c7d833 100644 --- a/kmath-core/README.md +++ b/kmath-core/README.md @@ -1,52 +1,43 @@ -# The Core Module (`kmath-core`) +# Module kmath-core -The core features of KMath: +The core interfaces of KMath. - - [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) : By writing a single mathematical expression once, users will be able to apply different types of + - [algebras](src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt) : Algebraic structures like rings, spaces and fields. + - [nd](src/commonMain/kotlin/space/kscience/kmath/structures/StructureND.kt) : Many-dimensional structures and operations on them. + - [linear](src/commonMain/kotlin/space/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/space/kscience/kmath/structures/Buffers.kt) : One-dimensional structure + - [expressions](src/commonMain/kotlin/space/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 + - [domains](src/commonMain/kotlin/space/kscience/kmath/domains) : Domains + - [autodif](src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt) : Automatic differentiation -> #### Artifact: -> -> This module artifact: `kscience.kmath:kmath-core:0.2.0-dev-7`. -> -> Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-core/_latestVersion) -> -> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-core/_latestVersion) -> -> **Gradle:** -> -> ```gradle -> repositories { -> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } -> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } -> maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> -> } -> -> dependencies { -> implementation 'kscience.kmath:kmath-core:0.2.0-dev-7' -> } -> ``` -> **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") -> } -> -> dependencies { -> implementation("kscience.kmath:kmath-core:0.2.0-dev-7") -> } -> ``` +## Artifact: + +The Maven coordinates of this project are `space.kscience:kmath-core:0.3.0-dev-3`. + +**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 +} + +dependencies { + implementation 'space.kscience:kmath-core:0.3.0-dev-3' +} +``` +**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 +} + +dependencies { + implementation("space.kscience:kmath-core:0.3.0-dev-3") +} +``` diff --git a/kmath-core/api/kmath-core.api b/kmath-core/api/kmath-core.api index e58e5d45d..e6f4697aa 100644 --- a/kmath-core/api/kmath-core.api +++ b/kmath-core/api/kmath-core.api @@ -1,450 +1,625 @@ -public abstract interface class kscience/kmath/domains/Domain { - public abstract fun contains (Lkscience/kmath/structures/Buffer;)Z +public final class space/kscience/kmath/data/ColumnarDataKt { +} + +public final class space/kscience/kmath/data/XYColumnarData$DefaultImpls { + public static fun get (Lspace/kscience/kmath/data/XYColumnarData;Lspace/kscience/kmath/misc/Symbol;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/data/XYColumnarDataKt { + public static synthetic fun asXYData$default (Lspace/kscience/kmath/nd/Structure2D;IIILjava/lang/Object;)Lspace/kscience/kmath/data/XYColumnarData; +} + +public final class space/kscience/kmath/data/XYZColumnarData$DefaultImpls { + public static fun get (Lspace/kscience/kmath/data/XYZColumnarData;Lspace/kscience/kmath/misc/Symbol;)Lspace/kscience/kmath/structures/Buffer; +} + +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 kscience/kmath/domains/HyperSquareDomain : kscience/kmath/domains/RealDomain { - public synthetic fun ([D[DLkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun contains (Lkscience/kmath/structures/Buffer;)Z - public fun getDimension ()I - public fun getLowerBound (I)Ljava/lang/Double; - public fun getLowerBound (ILkscience/kmath/structures/Buffer;)Ljava/lang/Double; - public fun getUpperBound (I)Ljava/lang/Double; - public fun getUpperBound (ILkscience/kmath/structures/Buffer;)Ljava/lang/Double; - public fun nearestInDomain (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public fun volume ()D +public abstract interface class space/kscience/kmath/expressions/AutoDiffProcessor { + public abstract fun process (Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/DifferentiableExpression; } -public abstract interface class kscience/kmath/domains/RealDomain : kscience/kmath/domains/Domain { - public abstract fun getLowerBound (I)Ljava/lang/Double; - public abstract fun getLowerBound (ILkscience/kmath/structures/Buffer;)Ljava/lang/Double; - public abstract fun getUpperBound (I)Ljava/lang/Double; - public abstract fun getUpperBound (ILkscience/kmath/structures/Buffer;)Ljava/lang/Double; - public abstract fun nearestInDomain (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public abstract fun volume ()D -} - -public final class kscience/kmath/domains/UnconstrainedDomain : kscience/kmath/domains/RealDomain { - public fun (I)V - public fun contains (Lkscience/kmath/structures/Buffer;)Z - public fun getDimension ()I - public fun getLowerBound (I)Ljava/lang/Double; - public fun getLowerBound (ILkscience/kmath/structures/Buffer;)Ljava/lang/Double; - public fun getUpperBound (I)Ljava/lang/Double; - public fun getUpperBound (ILkscience/kmath/structures/Buffer;)Ljava/lang/Double; - public fun nearestInDomain (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public fun volume ()D -} - -public final class kscience/kmath/domains/UnivariateDomain : kscience/kmath/domains/RealDomain { - public static final synthetic fun box-impl (Lkotlin/ranges/ClosedFloatingPointRange;)Lkscience/kmath/domains/UnivariateDomain; - public static fun constructor-impl (Lkotlin/ranges/ClosedFloatingPointRange;)Lkotlin/ranges/ClosedFloatingPointRange; - public fun contains (Lkscience/kmath/structures/Buffer;)Z - public static final fun contains-impl (Lkotlin/ranges/ClosedFloatingPointRange;D)Z - public static fun contains-impl (Lkotlin/ranges/ClosedFloatingPointRange;Lkscience/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 (ILkscience/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;ILkscience/kmath/structures/Buffer;)Ljava/lang/Double; - public final fun getRange ()Lkotlin/ranges/ClosedFloatingPointRange; - public fun getUpperBound (I)Ljava/lang/Double; - public fun getUpperBound (ILkscience/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;ILkscience/kmath/structures/Buffer;)Ljava/lang/Double; - public fun hashCode ()I - public static fun hashCode-impl (Lkotlin/ranges/ClosedFloatingPointRange;)I - public fun nearestInDomain (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static fun nearestInDomain-impl (Lkotlin/ranges/ClosedFloatingPointRange;Lkscience/kmath/structures/Buffer;)Lkscience/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 kscience/kmath/expressions/AutoDiffProcessor { - public abstract fun process (Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/DifferentiableExpression; -} - -public class kscience/kmath/expressions/AutoDiffValue { +public class space/kscience/kmath/expressions/AutoDiffValue { public fun (Ljava/lang/Object;)V public final fun getValue ()Ljava/lang/Object; } -public final class kscience/kmath/expressions/DerivationResult { - public fun (Ljava/lang/Object;Ljava/util/Map;Lkscience/kmath/operations/Field;)V - public final fun derivative (Lkscience/kmath/expressions/Symbol;)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/misc/Symbol;)Ljava/lang/Object; public final fun div ()Ljava/lang/Object; - public final fun getContext ()Lkscience/kmath/operations/Field; + public final fun getContext ()Lspace/kscience/kmath/operations/Field; public final fun getValue ()Ljava/lang/Object; } -public abstract interface class kscience/kmath/expressions/DifferentiableExpression : kscience/kmath/expressions/Expression { - public abstract fun derivativeOrNull (Ljava/util/List;)Lkscience/kmath/expressions/Expression; +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 kscience/kmath/expressions/DifferentiableExpressionKt { - public static final fun derivative (Lkscience/kmath/expressions/DifferentiableExpression;Ljava/lang/String;)Lkscience/kmath/expressions/Expression; - public static final fun derivative (Lkscience/kmath/expressions/DifferentiableExpression;Ljava/util/List;)Lkscience/kmath/expressions/Expression; - public static final fun derivative (Lkscience/kmath/expressions/DifferentiableExpression;[Lkscience/kmath/expressions/Symbol;)Lkscience/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/misc/Symbol;)Lspace/kscience/kmath/expressions/Expression; } -public abstract interface class 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 kscience/kmath/expressions/ExpressionAlgebra : kscience/kmath/operations/Algebra { - public abstract fun bindOrNull (Lkscience/kmath/expressions/Symbol;)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/misc/Symbol;)Ljava/lang/Object; public abstract fun const (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun symbol (Ljava/lang/String;)Ljava/lang/Object; } -public final class kscience/kmath/expressions/ExpressionAlgebra$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun symbol (Lkscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/expressions/ExpressionAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +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 kscience/kmath/expressions/ExpressionBuildersKt { - public static final fun extendedFieldExpression (Lkscience/kmath/operations/ExtendedField;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/Expression; - public static final fun fieldExpression (Lkscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/Expression; - public static final fun ringExpression (Lkscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/Expression; - public static final fun spaceExpression (Lkscience/kmath/operations/Space;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/Expression; +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/Group;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; } -public final class kscience/kmath/expressions/ExpressionKt { - public static final fun bind (Lkscience/kmath/expressions/ExpressionAlgebra;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public static final fun binding (Lkscience/kmath/expressions/ExpressionAlgebra;)Lkotlin/properties/ReadOnlyProperty; - public static final fun callByString (Lkscience/kmath/expressions/Expression;[Lkotlin/Pair;)Ljava/lang/Object; - public static final fun callBySymbol (Lkscience/kmath/expressions/Expression;[Lkotlin/Pair;)Ljava/lang/Object; - public static final fun getSymbol ()Lkotlin/properties/ReadOnlyProperty; - public static final fun invoke (Lkscience/kmath/expressions/Expression;)Ljava/lang/Object; +public final class space/kscience/kmath/expressions/ExpressionKt { + public static final fun bindSymbol (Lspace/kscience/kmath/expressions/ExpressionAlgebra;Lspace/kscience/kmath/misc/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 invoke (Lspace/kscience/kmath/expressions/Expression;)Ljava/lang/Object; } -public abstract class kscience/kmath/expressions/FirstDerivativeExpression : kscience/kmath/expressions/DifferentiableExpression { +public abstract class space/kscience/kmath/expressions/FirstDerivativeExpression : space/kscience/kmath/expressions/DifferentiableExpression { public fun ()V - public final fun derivativeOrNull (Ljava/util/List;)Lkscience/kmath/expressions/Expression; - public abstract fun derivativeOrNull (Lkscience/kmath/expressions/Symbol;)Lkscience/kmath/expressions/Expression; + public final fun derivativeOrNull (Ljava/util/List;)Lspace/kscience/kmath/expressions/Expression; + public abstract fun derivativeOrNull (Lspace/kscience/kmath/misc/Symbol;)Lspace/kscience/kmath/expressions/Expression; } -public abstract class kscience/kmath/expressions/FunctionalExpressionAlgebra : kscience/kmath/expressions/ExpressionAlgebra { - public fun (Lkscience/kmath/operations/Algebra;)V +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;Lkscience/kmath/expressions/Expression;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 bindOrNull (Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public fun bindOrNull (Lkscience/kmath/expressions/Symbol;)Lkscience/kmath/expressions/Expression; + 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/misc/Symbol;)Ljava/lang/Object; + public fun bindSymbolOrNull (Lspace/kscience/kmath/misc/Symbol;)Lspace/kscience/kmath/expressions/Expression; public synthetic fun const (Ljava/lang/Object;)Ljava/lang/Object; - public fun const (Ljava/lang/Object;)Lkscience/kmath/expressions/Expression; - public final fun getAlgebra ()Lkscience/kmath/operations/Algebra; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/expressions/Expression; + 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;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 kscience/kmath/expressions/FunctionalExpressionAlgebraKt { - public static final fun expressionInExtendedField (Lkscience/kmath/operations/ExtendedField;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/Expression; - public static final fun expressionInField (Lkscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/Expression; - public static final fun expressionInRing (Lkscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/Expression; - public static final fun expressionInSpace (Lkscience/kmath/operations/Space;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/Expression; +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/Group;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; } -public class kscience/kmath/expressions/FunctionalExpressionExtendedField : kscience/kmath/expressions/FunctionalExpressionField, kscience/kmath/operations/ExtendedField { - public fun (Lkscience/kmath/operations/ExtendedField;)V +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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/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;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun exp (Lspace/kscience/kmath/expressions/Expression;)Lspace/kscience/kmath/expressions/Expression; public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun ln (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;Ljava/lang/Number;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;Ljava/lang/Number;)Lkscience/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;Lkscience/kmath/expressions/Expression;Ljava/lang/Number;)Lkscience/kmath/expressions/Expression; + public fun power (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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 kscience/kmath/expressions/FunctionalExpressionField : kscience/kmath/expressions/FunctionalExpressionRing, kscience/kmath/operations/Field { - public fun (Lkscience/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;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public final fun div (Ljava/lang/Object;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public final fun div (Lkscience/kmath/expressions/Expression;Ljava/lang/Object;)Lkscience/kmath/expressions/Expression; - public fun div (Lkscience/kmath/expressions/Expression;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun divide (Lkscience/kmath/expressions/Expression;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; -} - -public class kscience/kmath/expressions/FunctionalExpressionRing : kscience/kmath/expressions/FunctionalExpressionSpace, kscience/kmath/operations/Ring { - public fun (Lkscience/kmath/operations/Ring;)V - public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public synthetic fun getOne ()Ljava/lang/Object; - public fun getOne ()Lkscience/kmath/expressions/Expression; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply (Lkscience/kmath/expressions/Expression;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public final fun times (Ljava/lang/Object;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public final fun times (Lkscience/kmath/expressions/Expression;Ljava/lang/Object;)Lkscience/kmath/expressions/Expression; - public fun times (Lkscience/kmath/expressions/Expression;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; -} - -public class kscience/kmath/expressions/FunctionalExpressionSpace : kscience/kmath/expressions/FunctionalExpressionAlgebra, kscience/kmath/operations/Space { - public fun (Lkscience/kmath/operations/Space;)V - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add (Lkscience/kmath/expressions/Expression;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; +public class space/kscience/kmath/expressions/FunctionalExpressionField : space/kscience/kmath/expressions/FunctionalExpressionRing, space/kscience/kmath/operations/Field, space/kscience/kmath/operations/ScaleOperations { + public fun (Lspace/kscience/kmath/operations/Field;)V 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 (Lkscience/kmath/expressions/Expression;Ljava/lang/Number;)Lkscience/kmath/expressions/Expression; - public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lkscience/kmath/expressions/Expression; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public final fun minus (Ljava/lang/Object;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public final fun minus (Lkscience/kmath/expressions/Expression;Ljava/lang/Object;)Lkscience/kmath/expressions/Expression; - public fun minus (Lkscience/kmath/expressions/Expression;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun multiply (Lkscience/kmath/expressions/Expression;Ljava/lang/Number;)Lkscience/kmath/expressions/Expression; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public final fun plus (Ljava/lang/Object;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; - public final fun plus (Lkscience/kmath/expressions/Expression;Ljava/lang/Object;)Lkscience/kmath/expressions/Expression; - public fun plus (Lkscience/kmath/expressions/Expression;Lkscience/kmath/expressions/Expression;)Lkscience/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 fun div (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Number;)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 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 number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (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 scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/expressions/Expression;D)Lspace/kscience/kmath/expressions/Expression; public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + 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 (Lkscience/kmath/expressions/Expression;Ljava/lang/Number;)Lkscience/kmath/expressions/Expression; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; + public fun times (Lspace/kscience/kmath/expressions/Expression;Ljava/lang/Number;)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 (Lkscience/kmath/expressions/Expression;)Lkscience/kmath/expressions/Expression; } -public final class kscience/kmath/expressions/SimpleAutoDiffExpression : kscience/kmath/expressions/FirstDerivativeExpression { - public fun (Lkscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)V - public fun derivativeOrNull (Lkscience/kmath/expressions/Symbol;)Lkscience/kmath/expressions/Expression; - public final fun getField ()Lkscience/kmath/operations/Field; +public class space/kscience/kmath/expressions/FunctionalExpressionGroup : space/kscience/kmath/expressions/FunctionalExpressionAlgebra, space/kscience/kmath/operations/Group { + public fun (Lspace/kscience/kmath/operations/Group;)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 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 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 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 class space/kscience/kmath/expressions/FunctionalExpressionRing : space/kscience/kmath/expressions/FunctionalExpressionGroup, 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 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/misc/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 kscience/kmath/expressions/SimpleAutoDiffExtendedField : kscience/kmath/expressions/SimpleAutoDiffField, kscience/kmath/operations/ExtendedField { - public fun (Lkscience/kmath/operations/ExtendedField;Ljava/util/Map;)V +public final class space/kscience/kmath/expressions/SimpleAutoDiffExtendedField : space/kscience/kmath/expressions/SimpleAutoDiffField, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/ScaleOperations { + public fun (Lspace/kscience/kmath/operations/ExtendedField;Ljava/util/Map;)V public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acos (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + public fun ln (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 pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun pow (Lkscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lkscience/kmath/expressions/AutoDiffValue; - public final fun pow (Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lkscience/kmath/expressions/AutoDiffValue; + 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 scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/expressions/AutoDiffValue;D)Lspace/kscience/kmath/expressions/AutoDiffValue; public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sin (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public final fun sqr (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 kscience/kmath/expressions/SimpleAutoDiffField : kscience/kmath/expressions/ExpressionAlgebra, kscience/kmath/operations/Field, kscience/kmath/operations/RingWithNumbers { - public fun (Lkscience/kmath/operations/Field;Ljava/util/Map;)V +public class space/kscience/kmath/expressions/SimpleAutoDiffField : space/kscience/kmath/expressions/ExpressionAlgebra, space/kscience/kmath/operations/Field, space/kscience/kmath/operations/NumbersAddOperations { + 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 (Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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;Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 bindOrNull (Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public fun bindOrNull (Lkscience/kmath/expressions/Symbol;)Lkscience/kmath/expressions/AutoDiffValue; + 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/misc/Symbol;)Ljava/lang/Object; + public fun bindSymbolOrNull (Lspace/kscience/kmath/misc/Symbol;)Lspace/kscience/kmath/expressions/AutoDiffValue; public synthetic fun const (Ljava/lang/Object;)Ljava/lang/Object; - public fun const (Ljava/lang/Object;)Lkscience/kmath/expressions/AutoDiffValue; - public final fun const (Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/AutoDiffValue; + 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;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/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 (Lkscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lkscience/kmath/expressions/AutoDiffValue; - public fun div (Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public final fun getContext ()Lkscience/kmath/operations/Field; - public final fun getD (Lkscience/kmath/expressions/AutoDiffValue;)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 ()Lkscience/kmath/expressions/AutoDiffValue; + public fun getOne ()Lspace/kscience/kmath/expressions/AutoDiffValue; public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lkscience/kmath/expressions/AutoDiffValue; + 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;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lkscience/kmath/expressions/AutoDiffValue; - public fun minus (Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)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/Object;)Ljava/lang/Object; - public fun multiply (Lkscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lkscience/kmath/expressions/AutoDiffValue; - public fun multiply (Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/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;)Lkscience/kmath/expressions/AutoDiffValue; + 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;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lkscience/kmath/expressions/AutoDiffValue; - public fun plus (Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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;Lkscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;Ljava/lang/Object;)V - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/expressions/AutoDiffValue; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/expressions/AutoDiffValue;D)Lspace/kscience/kmath/expressions/AutoDiffValue; + 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;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;Ljava/lang/Number;)Lkscience/kmath/expressions/AutoDiffValue; - public fun times (Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + 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 (Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; + public fun unaryPlus (Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; } -public final class kscience/kmath/expressions/SimpleAutoDiffKt { - public static final fun acos (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun acosh (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun asin (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun asinh (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun atan (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun atanh (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun cos (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun cosh (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun exp (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun grad (Lkscience/kmath/expressions/DerivationResult;[Lkscience/kmath/expressions/Symbol;)Lkscience/kmath/structures/Buffer; - public static final fun ln (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun pow (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;D)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun pow (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;I)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun pow (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun simpleAutoDiff (Lkscience/kmath/operations/Field;)Lkscience/kmath/expressions/AutoDiffProcessor; - public static final fun simpleAutoDiff (Lkscience/kmath/operations/Field;Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/DerivationResult; - public static final fun simpleAutoDiff (Lkscience/kmath/operations/Field;[Lkotlin/Pair;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/expressions/DerivationResult; - public static final fun sin (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun sinh (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun sqr (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun sqrt (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun tan (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/kmath/expressions/AutoDiffValue; - public static final fun tanh (Lkscience/kmath/expressions/SimpleAutoDiffField;Lkscience/kmath/expressions/AutoDiffValue;)Lkscience/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/misc/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 kscience/kmath/expressions/SimpleSymbolIndexer : kscience/kmath/expressions/SymbolIndexer { - public static final synthetic fun box-impl (Ljava/util/List;)Lkscience/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;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public fun get (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/expressions/Symbol;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public fun get (Lkscience/kmath/structures/Buffer;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public fun get ([DLkscience/kmath/expressions/Symbol;)D - public fun get ([Ljava/lang/Object;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public static fun get-impl (Ljava/util/List;Ljava/util/List;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public static fun get-impl (Ljava/util/List;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/expressions/Symbol;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public static fun get-impl (Ljava/util/List;Lkscience/kmath/structures/Buffer;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public static fun get-impl (Ljava/util/List;[DLkscience/kmath/expressions/Symbol;)D - public static fun get-impl (Ljava/util/List;[Ljava/lang/Object;Lkscience/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 (Lkscience/kmath/expressions/Symbol;)I - public static fun indexOf-impl (Ljava/util/List;Lkscience/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;)Lkscience/kmath/structures/Buffer; - public static fun toPoint-impl (Ljava/util/List;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Lkscience/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/misc/Symbol;)Ljava/lang/Object; + public static fun get (Lspace/kscience/kmath/expressions/SymbolIndexer;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/misc/Symbol;Lspace/kscience/kmath/misc/Symbol;)Ljava/lang/Object; + public static fun get (Lspace/kscience/kmath/expressions/SymbolIndexer;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/misc/Symbol;)Ljava/lang/Object; + public static fun get (Lspace/kscience/kmath/expressions/SymbolIndexer;[DLspace/kscience/kmath/misc/Symbol;)D + public static fun get (Lspace/kscience/kmath/expressions/SymbolIndexer;[Ljava/lang/Object;Lspace/kscience/kmath/misc/Symbol;)Ljava/lang/Object; + public static fun indexOf (Lspace/kscience/kmath/expressions/SymbolIndexer;Lspace/kscience/kmath/misc/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 final class space/kscience/kmath/linear/BufferedLinearSpace : space/kscience/kmath/linear/LinearSpace { + public fun (Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;)V + public fun buildMatrix (IILkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/Structure2D; + public fun buildVector (ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; + public 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 getElementAlgebra ()Lspace/kscience/kmath/operations/Ring; + public fun minus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun plus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun times (Ljava/lang/Object;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public fun times (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Object;)Lspace/kscience/kmath/structures/Buffer; + public fun unaryMinus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public fun unaryMinus (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/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 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/LinearSolverKt { + public static final fun asMatrix (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/linear/VirtualMatrix; + public static final fun asVector (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/structures/Buffer; +} + +public abstract interface class space/kscience/kmath/linear/LinearSpace { + public static final field Companion Lspace/kscience/kmath/linear/LinearSpace$Companion; + public abstract fun buildMatrix (IILkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun buildVector (ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; + 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 getElementAlgebra ()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 minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun plus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun times (Ljava/lang/Object;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun times (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Object;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun unaryMinus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public abstract fun unaryMinus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/linear/LinearSpace$Companion { + public final fun buffered (Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/linear/LinearSpace; + public static synthetic fun buffered$default (Lspace/kscience/kmath/linear/LinearSpace$Companion;Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lspace/kscience/kmath/linear/LinearSpace; + public final fun getReal ()Lspace/kscience/kmath/linear/LinearSpace; +} + +public final class space/kscience/kmath/linear/LinearSpace$DefaultImpls { + public static fun dot (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun dot (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun minus (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun minus (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun plus (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun plus (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun times (Lspace/kscience/kmath/linear/LinearSpace;Ljava/lang/Object;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun times (Lspace/kscience/kmath/linear/LinearSpace;Ljava/lang/Object;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static fun times (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public static fun times (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Object;)Lspace/kscience/kmath/structures/Buffer; + public static fun unaryMinus (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static fun unaryMinus (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/linear/LinearSpaceKt { + public static final fun invoke (Lspace/kscience/kmath/linear/LinearSpace;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/linear/LupDecomposition : space/kscience/kmath/linear/DeterminantFeature, space/kscience/kmath/linear/LupDecompositionFeature { + public fun (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/operations/Field;Lspace/kscience/kmath/nd/Structure2D;[IZ)V + public final fun getContext ()Lspace/kscience/kmath/linear/LinearSpace; + 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/LinearSpace;Ljava/lang/Comparable;)Ljava/lang/Comparable; + public static final fun inverseWithLup (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun lup (Lspace/kscience/kmath/linear/LinearSpace;Lkotlin/jvm/functions/Function2;Lspace/kscience/kmath/nd/Structure2D;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/linear/LupDecomposition; + public static final fun lup (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/LupDecomposition; + public static final fun solveWithLup (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + 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 final class space/kscience/kmath/linear/MatrixBuilder { + public fun (Lspace/kscience/kmath/linear/LinearSpace;II)V + public final fun getColumns ()I + public final fun getLinearSpace ()Lspace/kscience/kmath/linear/LinearSpace; + 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 column (Lspace/kscience/kmath/linear/LinearSpace;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun column (Lspace/kscience/kmath/linear/LinearSpace;[Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun row (Lspace/kscience/kmath/linear/LinearSpace;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun row (Lspace/kscience/kmath/linear/LinearSpace;[Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; +} + +public abstract interface class space/kscience/kmath/linear/MatrixFeature : space/kscience/kmath/nd/StructureFeature { +} + +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 get (II)Ljava/lang/Object; + public fun get ([I)Ljava/lang/Object; + public fun getColNum ()I + public fun getColumns ()Ljava/util/List; + 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 ()Ljava/util/List; + public fun getShape ()[I 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 kscience/kmath/expressions/StringSymbol : kscience/kmath/expressions/Symbol { - public static final synthetic fun box-impl (Ljava/lang/String;)Lkscience/kmath/expressions/StringSymbol; +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/LinearSpace;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 transpose (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public static final fun zero (Lspace/kscience/kmath/linear/LinearSpace;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 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 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 get (II)Ljava/lang/Object; + public fun get ([I)Ljava/lang/Object; + public fun getColNum ()I + public fun getColumns ()Ljava/util/List; + public fun getDimension ()I + public final fun getGenerator ()Lkotlin/jvm/functions/Function2; + public fun getRowNum ()I + public fun getRows ()Ljava/util/List; + public fun getShape ()[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/Group;)Ljava/lang/Iterable; + public static final fun cumulativeSum (Ljava/util/List;Lspace/kscience/kmath/operations/Group;)Ljava/util/List; + public static final fun cumulativeSum (Lkotlin/sequences/Sequence;Lspace/kscience/kmath/operations/Group;)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 final class space/kscience/kmath/misc/StringSymbol : space/kscience/kmath/misc/Symbol { + public static final synthetic fun box-impl (Ljava/lang/String;)Lspace/kscience/kmath/misc/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 @@ -457,584 +632,166 @@ public final class kscience/kmath/expressions/StringSymbol : kscience/kmath/expr public final synthetic fun unbox-impl ()Ljava/lang/String; } -public abstract interface class kscience/kmath/expressions/Symbol { +public abstract interface class space/kscience/kmath/misc/Symbol { + public static final field Companion Lspace/kscience/kmath/misc/Symbol$Companion; public abstract fun getIdentity ()Ljava/lang/String; } -public abstract interface class kscience/kmath/expressions/SymbolIndexer { - public abstract fun get (Ljava/util/List;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public abstract fun get (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/expressions/Symbol;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public abstract fun get (Lkscience/kmath/structures/Buffer;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public abstract fun get ([DLkscience/kmath/expressions/Symbol;)D - public abstract fun get ([Ljava/lang/Object;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public abstract fun getSymbols ()Ljava/util/List; - public abstract fun indexOf (Lkscience/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;)Lkscience/kmath/structures/Buffer; +public final class space/kscience/kmath/misc/Symbol$Companion { + public final fun getX-tWtZOCg ()Ljava/lang/String; + public final fun getY-tWtZOCg ()Ljava/lang/String; + public final fun getZ-tWtZOCg ()Ljava/lang/String; } -public final class kscience/kmath/expressions/SymbolIndexer$DefaultImpls { - public static fun get (Lkscience/kmath/expressions/SymbolIndexer;Ljava/util/List;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public static fun get (Lkscience/kmath/expressions/SymbolIndexer;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/expressions/Symbol;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public static fun get (Lkscience/kmath/expressions/SymbolIndexer;Lkscience/kmath/structures/Buffer;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public static fun get (Lkscience/kmath/expressions/SymbolIndexer;[DLkscience/kmath/expressions/Symbol;)D - public static fun get (Lkscience/kmath/expressions/SymbolIndexer;[Ljava/lang/Object;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object; - public static fun indexOf (Lkscience/kmath/expressions/SymbolIndexer;Lkscience/kmath/expressions/Symbol;)I - public static fun toDoubleArray (Lkscience/kmath/expressions/SymbolIndexer;Ljava/util/Map;)[D - public static fun toList (Lkscience/kmath/expressions/SymbolIndexer;Ljava/util/Map;)Ljava/util/List; - public static fun toMap (Lkscience/kmath/expressions/SymbolIndexer;[D)Ljava/util/Map; - public static fun toPoint (Lkscience/kmath/expressions/SymbolIndexer;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/structures/Buffer; +public final class space/kscience/kmath/misc/SymbolKt { + public static final fun getSymbol ()Lkotlin/properties/ReadOnlyProperty; } -public final class kscience/kmath/expressions/SymbolIndexerKt { - public static final fun withSymbols (Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun withSymbols ([Lkscience/kmath/expressions/Symbol;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; +public abstract interface annotation class space/kscience/kmath/misc/UnstableKMathAPI : java/lang/annotation/Annotation { } -public final class kscience/kmath/linear/BufferMatrix : kscience/kmath/nd/Structure2D { - public fun (IILkscience/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 ()Lkscience/kmath/structures/Buffer; - public fun getColNum ()I - public fun getColumns ()Lkscience/kmath/structures/Buffer; - public fun getDimension ()I - public fun getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public fun getRowNum ()I - public fun getRows ()Lkscience/kmath/structures/Buffer; - public fun getShape ()[I - public fun hashCode ()I - public fun toString ()Ljava/lang/String; +public abstract interface class space/kscience/kmath/nd/AlgebraND { + public static final field Companion Lspace/kscience/kmath/nd/AlgebraND$Companion; + public abstract fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun getElementContext ()Lspace/kscience/kmath/operations/Algebra; + public abstract fun getShape ()[I + public abstract fun invoke (Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; } -public final class kscience/kmath/linear/BufferMatrixContext : kscience/kmath/linear/GenericMatrixContext { - public static final field Companion Lkscience/kmath/linear/BufferMatrixContext$Companion; - public fun (Lkscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;)V - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun add (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/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;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - 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 (Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public fun getElementContext ()Lkscience/kmath/operations/Ring; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun minus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun multiply (Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun multiply (Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public final fun one (II)Lkscience/kmath/nd/Structure2D; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public fun point (ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer; - public fun produce (IILkotlin/jvm/functions/Function2;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun produce (IILkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/Structure2D; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/nd/Structure2D; - public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun times (Ljava/lang/Object;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun times (Ljava/lang/Object;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public fun times (Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public fun times (Lkscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun times (Lkscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lkscience/kmath/nd/Structure2D; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun unaryMinus (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperation (Ljava/lang/String;Lkscience/kmath/nd/Structure2D;)Lkscience/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 (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; +public final class space/kscience/kmath/nd/AlgebraND$Companion { } -public final class kscience/kmath/linear/BufferMatrixContext$Companion { +public final class space/kscience/kmath/nd/AlgebraND$DefaultImpls { + public static fun invoke (Lspace/kscience/kmath/nd/AlgebraND;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; } -public final class kscience/kmath/linear/BufferVectorSpace : kscience/kmath/linear/VectorSpace { - public fun (ILkscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;)V - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/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;Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - 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 (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public final fun getBufferFactory ()Lkotlin/jvm/functions/Function2; - public fun getSize ()I - public fun getSpace ()Lkscience/kmath/operations/Space; - public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lkscience/kmath/structures/Buffer; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun multiply (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public fun produce (Lkotlin/jvm/functions/Function2;)Lkscience/kmath/structures/Buffer; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/structures/Buffer; - public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun times (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperation (Ljava/lang/String;Lkscience/kmath/structures/Buffer;)Lkscience/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 (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; -} - -public abstract interface class kscience/kmath/linear/CholeskyDecompositionFeature : kscience/kmath/linear/MatrixFeature { - public abstract fun getL ()Lkscience/kmath/nd/Structure2D; -} - -public abstract interface class kscience/kmath/linear/DeterminantFeature : kscience/kmath/linear/MatrixFeature { - public abstract fun getDeterminant ()Ljava/lang/Object; -} - -public abstract interface class kscience/kmath/linear/DiagonalFeature : kscience/kmath/linear/MatrixFeature { - public static final field Companion Lkscience/kmath/linear/DiagonalFeature$Companion; -} - -public final class kscience/kmath/linear/DiagonalFeature$Companion : kscience/kmath/linear/DiagonalFeature { -} - -public abstract interface class kscience/kmath/linear/GenericMatrixContext : kscience/kmath/linear/MatrixContext { - public abstract fun add (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public abstract fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public abstract fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public abstract fun getElementContext ()Lkscience/kmath/operations/Ring; - public abstract fun minus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public abstract fun multiply (Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public abstract fun times (Lkscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lkscience/kmath/nd/Structure2D; - public abstract fun unaryMinus (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/GenericMatrixContext$DefaultImpls { - public static fun add (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun binaryOperation (Lkscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun binaryOperationFunction (Lkscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public static fun dot (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun dot (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static fun minus (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun multiply (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public static fun plus (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun point (Lkscience/kmath/linear/GenericMatrixContext;ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer; - public static fun symbol (Lkscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;)Lkscience/kmath/nd/Structure2D; - public static fun times (Lkscience/kmath/linear/GenericMatrixContext;Ljava/lang/Number;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun times (Lkscience/kmath/linear/GenericMatrixContext;Ljava/lang/Object;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun times (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public static fun times (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lkscience/kmath/nd/Structure2D; - public static fun unaryMinus (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun unaryOperation (Lkscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun unaryOperationFunction (Lkscience/kmath/linear/GenericMatrixContext;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; -} - -public abstract interface class kscience/kmath/linear/InverseMatrixFeature : kscience/kmath/linear/MatrixFeature { - public abstract fun getInverse ()Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/LFeature : kscience/kmath/linear/MatrixFeature { - public static final field INSTANCE Lkscience/kmath/linear/LFeature; -} - -public final class kscience/kmath/linear/LinearAlgebraKt { - public static final fun asMatrix (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/linear/VirtualMatrix; - public static final fun asPoint (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/structures/Buffer; -} - -public abstract interface class kscience/kmath/linear/LinearSolver { - public abstract fun inverse (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public abstract fun solve (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public abstract fun solve (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; -} - -public final class kscience/kmath/linear/LinearSolver$DefaultImpls { - public static fun solve (Lkscience/kmath/linear/LinearSolver;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; -} - -public final class kscience/kmath/linear/LupDecomposition : kscience/kmath/linear/DeterminantFeature, kscience/kmath/linear/LupDecompositionFeature { - public fun (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/operations/Field;Lkscience/kmath/nd/Structure2D;[IZ)V - public final fun getContext ()Lkscience/kmath/linear/MatrixContext; - public fun getDeterminant ()Ljava/lang/Object; - public final fun getElementContext ()Lkscience/kmath/operations/Field; - public fun getL ()Lkscience/kmath/nd/Structure2D; - public final fun getLu ()Lkscience/kmath/nd/Structure2D; - public fun getP ()Lkscience/kmath/nd/Structure2D; - public final fun getPivot ()[I - public fun getU ()Lkscience/kmath/nd/Structure2D; -} - -public abstract interface class kscience/kmath/linear/LupDecompositionFeature : kscience/kmath/linear/MatrixFeature { - public abstract fun getL ()Lkscience/kmath/nd/Structure2D; - public abstract fun getP ()Lkscience/kmath/nd/Structure2D; - public abstract fun getU ()Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/LupDecompositionKt { - public static final fun abs (Lkscience/kmath/linear/GenericMatrixContext;Ljava/lang/Comparable;)Ljava/lang/Comparable; - public static final fun inverseWithLup (Lkscience/kmath/linear/RealMatrixContext;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static final fun lup (Lkscience/kmath/linear/MatrixContext;Lkotlin/jvm/functions/Function2;Lkscience/kmath/operations/Field;Lkscience/kmath/nd/Structure2D;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/linear/LupDecomposition; - public static final fun lup (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/LupDecomposition; - public static final fun solveWithLup (Lkscience/kmath/linear/LupDecomposition;Lkotlin/jvm/functions/Function2;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static final fun solveWithLup (Lkscience/kmath/linear/RealMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; -} - -public final class 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;)Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/MatrixBuilderKt { - public static final fun build (Lkscience/kmath/nd/Structure2D$Companion;II)Lkscience/kmath/linear/MatrixBuilder; - public static final fun column (Lkscience/kmath/nd/Structure2D$Companion;[Ljava/lang/Object;)Lkscience/kmath/nd/Structure2D; - public static final fun row (Lkscience/kmath/nd/Structure2D$Companion;[Ljava/lang/Object;)Lkscience/kmath/nd/Structure2D; -} - -public abstract interface class kscience/kmath/linear/MatrixContext : kscience/kmath/operations/SpaceOperations { - public static final field Companion Lkscience/kmath/linear/MatrixContext$Companion; - public abstract fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public abstract fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public abstract fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public abstract fun point (ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer; - public abstract fun produce (IILkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/Structure2D; - public abstract fun times (Ljava/lang/Object;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public abstract fun times (Lkscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/MatrixContext$Companion { - public final fun buffered (Lkscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/linear/GenericMatrixContext; - public static synthetic fun buffered$default (Lkscience/kmath/linear/MatrixContext$Companion;Lkscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkscience/kmath/linear/GenericMatrixContext; -} - -public final class kscience/kmath/linear/MatrixContext$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/linear/MatrixContext;Ljava/lang/String;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun binaryOperationFunction (Lkscience/kmath/linear/MatrixContext;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public static fun minus (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun plus (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun point (Lkscience/kmath/linear/MatrixContext;ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer; - public static fun symbol (Lkscience/kmath/linear/MatrixContext;Ljava/lang/String;)Lkscience/kmath/nd/Structure2D; - public static fun times (Lkscience/kmath/linear/MatrixContext;Ljava/lang/Number;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun times (Lkscience/kmath/linear/MatrixContext;Ljava/lang/Object;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun times (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public static fun unaryMinus (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun unaryOperation (Lkscience/kmath/linear/MatrixContext;Ljava/lang/String;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static fun unaryOperationFunction (Lkscience/kmath/linear/MatrixContext;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; -} - -public abstract interface class kscience/kmath/linear/MatrixFeature { -} - -public final class kscience/kmath/linear/MatrixFeaturesKt { - public static final fun DeterminantFeature (Ljava/lang/Object;)Lkscience/kmath/linear/DeterminantFeature; -} - -public final class kscience/kmath/linear/MatrixWrapper : 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 ()Lkscience/kmath/structures/Buffer; - public fun getDimension ()I - public fun getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public final fun getFeatures ()Ljava/util/Set; - public final fun getOrigin ()Lkscience/kmath/nd/Structure2D; - public fun getRowNum ()I - public fun getRows ()Lkscience/kmath/structures/Buffer; - public fun getShape ()[I - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class kscience/kmath/linear/MatrixWrapperKt { - public static final fun getOrigin (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static final fun one (Lkscience/kmath/linear/GenericMatrixContext;II)Lkscience/kmath/nd/Structure2D; - public static final fun plus (Lkscience/kmath/nd/Structure2D;Ljava/util/Collection;)Lkscience/kmath/linear/MatrixWrapper; - public static final fun plus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/linear/MatrixFeature;)Lkscience/kmath/linear/MatrixWrapper; - public static final fun square (Lkscience/kmath/nd/Structure2D$Companion;[Ljava/lang/Object;)Lkscience/kmath/nd/Structure2D; - public static final fun transpose (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public static final fun zero (Lkscience/kmath/linear/GenericMatrixContext;II)Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/OrthogonalFeature : kscience/kmath/linear/MatrixFeature { - public static final field INSTANCE Lkscience/kmath/linear/OrthogonalFeature; -} - -public abstract interface class kscience/kmath/linear/QRDecompositionFeature : kscience/kmath/linear/MatrixFeature { - public abstract fun getQ ()Lkscience/kmath/nd/Structure2D; - public abstract fun getR ()Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/RealMatrixContext : kscience/kmath/linear/MatrixContext { - public static final field INSTANCE Lkscience/kmath/linear/RealMatrixContext; - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/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;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - 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 (Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun multiply (Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/linear/BufferMatrix; - public final fun one (II)Lkscience/kmath/nd/Structure2D; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public fun point (ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer; - public fun produce (IILkotlin/jvm/functions/Function2;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun produce (IILkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/Structure2D; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/nd/Structure2D; - public fun times (DLkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public synthetic fun times (Ljava/lang/Object;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public fun times (Lkscience/kmath/nd/Structure2D;D)Lkscience/kmath/linear/BufferMatrix; - public fun times (Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D; - public synthetic fun times (Lkscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lkscience/kmath/nd/Structure2D; - public final fun toBufferMatrix (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; - public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperation (Ljava/lang/String;Lkscience/kmath/nd/Structure2D;)Lkscience/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 (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/RealMatrixContextKt { - public static final fun getReal (Lkscience/kmath/linear/MatrixContext$Companion;)Lkscience/kmath/linear/RealMatrixContext; -} - -public abstract interface class kscience/kmath/linear/SingularValueDecompositionFeature : kscience/kmath/linear/MatrixFeature { - public abstract fun getS ()Lkscience/kmath/nd/Structure2D; - public abstract fun getSingularValues ()Lkscience/kmath/structures/Buffer; - public abstract fun getU ()Lkscience/kmath/nd/Structure2D; - public abstract fun getV ()Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/TransposedFeature : kscience/kmath/linear/MatrixFeature { - public fun (Lkscience/kmath/nd/Structure2D;)V - public final fun getOriginal ()Lkscience/kmath/nd/Structure2D; -} - -public final class kscience/kmath/linear/UFeature : kscience/kmath/linear/MatrixFeature { - public static final field INSTANCE Lkscience/kmath/linear/UFeature; -} - -public final class kscience/kmath/linear/UnitFeature : kscience/kmath/linear/DiagonalFeature { - public static final field INSTANCE Lkscience/kmath/linear/UnitFeature; -} - -public abstract interface class kscience/kmath/linear/VectorSpace : kscience/kmath/operations/Space { - public static final field Companion Lkscience/kmath/linear/VectorSpace$Companion; - public abstract fun add (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public abstract fun getSize ()I - public abstract fun getSpace ()Lkscience/kmath/operations/Space; - public abstract fun getZero ()Lkscience/kmath/structures/Buffer; - public abstract fun multiply (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public abstract fun produce (Lkotlin/jvm/functions/Function2;)Lkscience/kmath/structures/Buffer; -} - -public final class kscience/kmath/linear/VectorSpace$Companion { - public final fun buffered (ILkscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/linear/BufferVectorSpace; - public static synthetic fun buffered$default (Lkscience/kmath/linear/VectorSpace$Companion;ILkscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkscience/kmath/linear/BufferVectorSpace; - public final fun real (I)Lkscience/kmath/linear/BufferVectorSpace; -} - -public final class kscience/kmath/linear/VectorSpace$DefaultImpls { - public static fun add (Lkscience/kmath/linear/VectorSpace;Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static fun binaryOperation (Lkscience/kmath/linear/VectorSpace;Ljava/lang/String;Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static fun binaryOperationFunction (Lkscience/kmath/linear/VectorSpace;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/linear/VectorSpace;Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public static fun getZero (Lkscience/kmath/linear/VectorSpace;)Lkscience/kmath/structures/Buffer; - public static fun minus (Lkscience/kmath/linear/VectorSpace;Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static fun multiply (Lkscience/kmath/linear/VectorSpace;Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public static fun plus (Lkscience/kmath/linear/VectorSpace;Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static fun symbol (Lkscience/kmath/linear/VectorSpace;Ljava/lang/String;)Lkscience/kmath/structures/Buffer; - public static fun times (Lkscience/kmath/linear/VectorSpace;Ljava/lang/Number;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static fun times (Lkscience/kmath/linear/VectorSpace;Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public static fun unaryMinus (Lkscience/kmath/linear/VectorSpace;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static fun unaryOperation (Lkscience/kmath/linear/VectorSpace;Ljava/lang/String;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static fun unaryOperationFunction (Lkscience/kmath/linear/VectorSpace;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/linear/VectorSpace;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; -} - -public final class kscience/kmath/linear/VirtualMatrix : 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 ()Lkscience/kmath/structures/Buffer; - public fun getDimension ()I - public fun getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public final fun getGenerator ()Lkotlin/jvm/functions/Function2; - public fun getRowNum ()I - public fun getRows ()Lkscience/kmath/structures/Buffer; - public fun getShape ()[I - public fun hashCode ()I -} - -public final class kscience/kmath/linear/ZeroFeature : kscience/kmath/linear/DiagonalFeature { - public static final field INSTANCE Lkscience/kmath/linear/ZeroFeature; -} - -public final class 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;Lkscience/kmath/operations/Space;)Ljava/lang/Iterable; - public static final fun cumulativeSum (Ljava/util/List;Lkscience/kmath/operations/Space;)Ljava/util/List; - public static final fun cumulativeSum (Lkotlin/sequences/Sequence;Lkscience/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 kscience/kmath/misc/UnstableKMathAPI : java/lang/annotation/Annotation { -} - -public abstract interface class kscience/kmath/nd/BufferNDAlgebra : kscience/kmath/nd/NDAlgebra { - public abstract fun combine (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDBuffer; - public abstract fun getBuffer (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/structures/Buffer; +public abstract interface class space/kscience/kmath/nd/BufferAlgebraND : space/kscience/kmath/nd/AlgebraND { + public abstract fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; + public abstract fun getBuffer (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/structures/Buffer; public abstract fun getBufferFactory ()Lkotlin/jvm/functions/Function2; - public abstract fun getStrides ()Lkscience/kmath/nd/Strides; - public abstract fun map (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDBuffer; - public abstract fun mapIndexed (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDBuffer; - public abstract fun produce (Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDBuffer; + public abstract fun getStrides ()Lspace/kscience/kmath/nd/Strides; + public abstract fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; + public abstract fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; + public abstract fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; } -public final class kscience/kmath/nd/BufferNDAlgebra$DefaultImpls { - public static fun combine (Lkscience/kmath/nd/BufferNDAlgebra;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDBuffer; - public static fun getBuffer (Lkscience/kmath/nd/BufferNDAlgebra;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/structures/Buffer; - public static fun invoke (Lkscience/kmath/nd/BufferNDAlgebra;Lkotlin/jvm/functions/Function1;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun map (Lkscience/kmath/nd/BufferNDAlgebra;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDBuffer; - public static fun mapIndexed (Lkscience/kmath/nd/BufferNDAlgebra;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDBuffer; - public static fun produce (Lkscience/kmath/nd/BufferNDAlgebra;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDBuffer; +public final class space/kscience/kmath/nd/BufferAlgebraND$DefaultImpls { + public static fun combine (Lspace/kscience/kmath/nd/BufferAlgebraND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; + public static fun getBuffer (Lspace/kscience/kmath/nd/BufferAlgebraND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/structures/Buffer; + public static fun invoke (Lspace/kscience/kmath/nd/BufferAlgebraND;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun map (Lspace/kscience/kmath/nd/BufferAlgebraND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; + public static fun mapIndexed (Lspace/kscience/kmath/nd/BufferAlgebraND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; + public static fun produce (Lspace/kscience/kmath/nd/BufferAlgebraND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; } -public final class kscience/kmath/nd/BufferNDAlgebraKt { - public static final fun field (Lkscience/kmath/nd/NDAlgebra$Companion;Lkscience/kmath/operations/Field;Lkotlin/jvm/functions/Function2;[I)Lkscience/kmath/nd/BufferedNDField; - public static final fun ndField (Lkscience/kmath/operations/Field;Lkotlin/jvm/functions/Function2;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun ndRing (Lkscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun ndSpace (Lkscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun ring (Lkscience/kmath/nd/NDAlgebra$Companion;Lkscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;[I)Lkscience/kmath/nd/BufferedNDRing; - public static final fun space (Lkscience/kmath/nd/NDAlgebra$Companion;Lkscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;[I)Lkscience/kmath/nd/BufferedNDSpace; +public final class space/kscience/kmath/nd/BufferAlgebraNDKt { + public static final fun field (Lspace/kscience/kmath/nd/AlgebraND$Companion;Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function2;[I)Lspace/kscience/kmath/nd/BufferedFieldND; + public static final fun group (Lspace/kscience/kmath/nd/AlgebraND$Companion;Lspace/kscience/kmath/operations/Group;Lkotlin/jvm/functions/Function2;[I)Lspace/kscience/kmath/nd/BufferedGroupND; + 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 ndGroup (Lspace/kscience/kmath/operations/Group;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 ring (Lspace/kscience/kmath/nd/AlgebraND$Companion;Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;[I)Lspace/kscience/kmath/nd/BufferedRingND; } -public class kscience/kmath/nd/BufferedNDField : kscience/kmath/nd/BufferedNDRing, kscience/kmath/nd/NDField { - public fun ([ILkscience/kmath/operations/Field;Lkotlin/jvm/functions/Function2;)V +public final class space/kscience/kmath/nd/BufferND : space/kscience/kmath/nd/StructureND { + public fun (Lspace/kscience/kmath/nd/Strides;Lspace/kscience/kmath/structures/Buffer;)V + public fun elements ()Lkotlin/sequences/Sequence; + public fun get ([I)Ljava/lang/Object; + public final 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 toString ()Ljava/lang/String; +} + +public class space/kscience/kmath/nd/BufferedFieldND : space/kscience/kmath/nd/BufferedRingND, space/kscience/kmath/nd/FieldND { + 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;Lkscience/kmath/nd/NDStructure;)Lkscience/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 fun div (Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun div (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public fun div (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun divide (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun divide (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + 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/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + 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/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; } -public class kscience/kmath/nd/BufferedNDRing : kscience/kmath/nd/BufferedNDSpace, kscience/kmath/nd/NDRing { - public fun ([ILkscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function2;)V +public class space/kscience/kmath/nd/BufferedGroupND : space/kscience/kmath/nd/BufferAlgebraND, space/kscience/kmath/nd/GroupND { + public fun ([ILspace/kscience/kmath/operations/Group;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/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + 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/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + 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/StructureND; + public fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public fun getBuffer (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/structures/Buffer; + public final fun getBufferFactory ()Lkotlin/jvm/functions/Function2; + public synthetic fun getElementContext ()Lspace/kscience/kmath/operations/Algebra; + public final fun getElementContext ()Lspace/kscience/kmath/operations/Group; + 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/BufferND; + public fun invoke (Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + 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/StructureND;)Lspace/kscience/kmath/nd/StructureND; +} + +public class space/kscience/kmath/nd/BufferedRingND : space/kscience/kmath/nd/BufferedGroupND, space/kscience/kmath/nd/RingND { + 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 ()Lkscience/kmath/nd/NDBuffer; + public fun getOne ()Lspace/kscience/kmath/nd/BufferND; public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun times (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public fun times (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun times (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; } -public class kscience/kmath/nd/BufferedNDSpace : kscience/kmath/nd/BufferNDAlgebra, kscience/kmath/nd/NDSpace { - public fun ([ILkscience/kmath/operations/Space;Lkotlin/jvm/functions/Function2;)V - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/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;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public fun combine (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDBuffer; - public synthetic fun combine (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDStructure; - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun div (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public fun getBuffer (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/structures/Buffer; - public final fun getBufferFactory ()Lkotlin/jvm/functions/Function2; - public synthetic fun getElementContext ()Ljava/lang/Object; - public final fun getElementContext ()Lkscience/kmath/operations/Space; - public final fun getShape ()[I - public fun getStrides ()Lkscience/kmath/nd/Strides; - public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lkscience/kmath/nd/NDBuffer; - public fun invoke (Lkotlin/jvm/functions/Function1;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun map (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDBuffer; - public synthetic fun map (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDStructure; - public fun mapIndexed (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDBuffer; - public synthetic fun mapIndexed (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDStructure; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun minus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public fun minus (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun multiply (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun plus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public fun plus (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun produce (Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDBuffer; - public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDStructure; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/nd/NDStructure; - public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun times (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperation (Ljava/lang/String;Lkscience/kmath/nd/NDStructure;)Lkscience/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 (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; -} - -public final class kscience/kmath/nd/DefaultStrides : kscience/kmath/nd/Strides { - public static final field Companion Lkscience/kmath/nd/DefaultStrides$Companion; +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 @@ -1046,307 +803,225 @@ public final class kscience/kmath/nd/DefaultStrides : kscience/kmath/nd/Strides public fun offset ([I)I } -public final class kscience/kmath/nd/DefaultStrides$Companion { - public final fun invoke ([I)Lkscience/kmath/nd/Strides; +public final class space/kscience/kmath/nd/DefaultStrides$Companion { + public final fun invoke ([I)Lspace/kscience/kmath/nd/Strides; } -public final class kscience/kmath/nd/MutableNDBuffer : kscience/kmath/nd/NDBuffer, kscience/kmath/nd/MutableNDStructure { - public fun (Lkscience/kmath/nd/Strides;Lkscience/kmath/structures/MutableBuffer;)V - public synthetic fun getBuffer ()Lkscience/kmath/structures/Buffer; - public fun getBuffer ()Lkscience/kmath/structures/MutableBuffer; - public fun set ([ILjava/lang/Object;)V -} - -public abstract interface class kscience/kmath/nd/MutableNDStructure : kscience/kmath/nd/NDStructure { - public abstract fun set ([ILjava/lang/Object;)V -} - -public final class kscience/kmath/nd/MutableNDStructure$DefaultImpls { - public static fun getDimension (Lkscience/kmath/nd/MutableNDStructure;)I - public static fun getFeature (Lkscience/kmath/nd/MutableNDStructure;Lkotlin/reflect/KClass;)Ljava/lang/Object; -} - -public abstract interface class kscience/kmath/nd/NDAlgebra { - public static final field Companion Lkscience/kmath/nd/NDAlgebra$Companion; - public abstract fun combine (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDStructure; - public abstract fun getElementContext ()Ljava/lang/Object; - public abstract fun getShape ()[I - public abstract fun invoke (Lkotlin/jvm/functions/Function1;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public abstract fun map (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDStructure; - public abstract fun mapIndexed (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDStructure; - public abstract fun produce (Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDStructure; -} - -public final class kscience/kmath/nd/NDAlgebra$Companion { -} - -public final class kscience/kmath/nd/NDAlgebra$DefaultImpls { - public static fun invoke (Lkscience/kmath/nd/NDAlgebra;Lkotlin/jvm/functions/Function1;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; -} - -public class kscience/kmath/nd/NDBuffer : kscience/kmath/nd/NDStructure { - public fun (Lkscience/kmath/nd/Strides;Lkscience/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 ()Lkscience/kmath/structures/Buffer; - public fun getDimension ()I - public fun getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public fun getShape ()[I - public final fun getStrides ()Lkscience/kmath/nd/Strides; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public abstract interface class kscience/kmath/nd/NDField : kscience/kmath/nd/NDRing, kscience/kmath/operations/Field { - public abstract fun div (Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public abstract fun div (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public abstract fun divide (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; -} - -public final class kscience/kmath/nd/NDField$DefaultImpls { - public static fun add (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun binaryOperation (Lkscience/kmath/nd/NDField;Ljava/lang/String;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun binaryOperationFunction (Lkscience/kmath/nd/NDField;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/nd/NDField;Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun div (Lkscience/kmath/nd/NDField;Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun div (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public static fun div (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public static fun div (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun divide (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun invoke (Lkscience/kmath/nd/NDField;Lkotlin/jvm/functions/Function1;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun minus (Lkscience/kmath/nd/NDField;Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun minus (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public static fun minus (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun multiply (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public static fun multiply (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun plus (Lkscience/kmath/nd/NDField;Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun plus (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public static fun plus (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun symbol (Lkscience/kmath/nd/NDField;Ljava/lang/String;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDField;Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDField;Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun unaryMinus (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun unaryOperation (Lkscience/kmath/nd/NDField;Ljava/lang/String;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun unaryOperationFunction (Lkscience/kmath/nd/NDField;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/nd/NDField;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; -} - -public abstract interface class kscience/kmath/nd/NDRing : kscience/kmath/nd/NDSpace, kscience/kmath/operations/Ring { - public static final field Companion Lkscience/kmath/nd/NDRing$Companion; - public abstract fun multiply (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public abstract fun times (Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public abstract fun times (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; -} - -public final class kscience/kmath/nd/NDRing$Companion { -} - -public final class kscience/kmath/nd/NDRing$DefaultImpls { - public static fun add (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun binaryOperation (Lkscience/kmath/nd/NDRing;Ljava/lang/String;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun binaryOperationFunction (Lkscience/kmath/nd/NDRing;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public static fun invoke (Lkscience/kmath/nd/NDRing;Lkotlin/jvm/functions/Function1;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun minus (Lkscience/kmath/nd/NDRing;Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun minus (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public static fun minus (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun multiply (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public static fun multiply (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun plus (Lkscience/kmath/nd/NDRing;Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun plus (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public static fun plus (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun symbol (Lkscience/kmath/nd/NDRing;Ljava/lang/String;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDRing;Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDRing;Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun unaryMinus (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun unaryOperation (Lkscience/kmath/nd/NDRing;Ljava/lang/String;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun unaryOperationFunction (Lkscience/kmath/nd/NDRing;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/nd/NDRing;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; -} - -public abstract interface class kscience/kmath/nd/NDSpace : kscience/kmath/nd/NDAlgebra, kscience/kmath/operations/Space { - public static final field Companion Lkscience/kmath/nd/NDSpace$Companion; - public abstract fun add (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public abstract fun minus (Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public abstract fun minus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public abstract fun multiply (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public abstract fun plus (Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public abstract fun plus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; -} - -public final class kscience/kmath/nd/NDSpace$Companion { -} - -public final class kscience/kmath/nd/NDSpace$DefaultImpls { - public static fun add (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun binaryOperation (Lkscience/kmath/nd/NDSpace;Ljava/lang/String;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun binaryOperationFunction (Lkscience/kmath/nd/NDSpace;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public static fun invoke (Lkscience/kmath/nd/NDSpace;Lkotlin/jvm/functions/Function1;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun minus (Lkscience/kmath/nd/NDSpace;Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun minus (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public static fun minus (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun multiply (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public static fun plus (Lkscience/kmath/nd/NDSpace;Ljava/lang/Object;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun plus (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public static fun plus (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun symbol (Lkscience/kmath/nd/NDSpace;Ljava/lang/String;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDSpace;Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun times (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public static fun unaryMinus (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun unaryOperation (Lkscience/kmath/nd/NDSpace;Ljava/lang/String;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public static fun unaryOperationFunction (Lkscience/kmath/nd/NDSpace;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/nd/NDSpace;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; -} - -public abstract interface class kscience/kmath/nd/NDStructure { - public static final field Companion Lkscience/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 getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public abstract fun getShape ()[I - public abstract fun hashCode ()I -} - -public final class kscience/kmath/nd/NDStructure$Companion { - public final fun auto (Lkotlin/reflect/KClass;Lkscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/nd/NDBuffer; - public final fun auto (Lkotlin/reflect/KClass;[ILkotlin/jvm/functions/Function1;)Lkscience/kmath/nd/NDBuffer; - public final fun build (Lkscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/nd/NDBuffer; - public final fun build ([ILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lkscience/kmath/nd/NDBuffer; - public static synthetic fun build$default (Lkscience/kmath/nd/NDStructure$Companion;Lkscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkscience/kmath/nd/NDBuffer; - public static synthetic fun build$default (Lkscience/kmath/nd/NDStructure$Companion;[ILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkscience/kmath/nd/NDBuffer; - public final fun contentEquals (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Z -} - -public final class kscience/kmath/nd/NDStructure$DefaultImpls { - public static fun getDimension (Lkscience/kmath/nd/NDStructure;)I - public static fun getFeature (Lkscience/kmath/nd/NDStructure;Lkotlin/reflect/KClass;)Ljava/lang/Object; -} - -public final class kscience/kmath/nd/NDStructureKt { - public static final fun get (Lkscience/kmath/nd/NDStructure;[I)Ljava/lang/Object; - public static final fun mapInPlace (Lkscience/kmath/nd/MutableNDStructure;Lkotlin/jvm/functions/Function2;)V -} - -public final class kscience/kmath/nd/RealNDField : kscience/kmath/nd/BufferedNDField, kscience/kmath/operations/ExtendedField, kscience/kmath/operations/RingWithNumbers { +public final class space/kscience/kmath/nd/DoubleFieldND : space/kscience/kmath/nd/BufferedFieldND, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/NumbersAddOperations, space/kscience/kmath/operations/ScaleOperations { public fun ([I)V public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acos (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun acos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asin (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun asin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun atan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; - public fun combine (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDBuffer; - public synthetic fun combine (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDStructure; + public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; + public fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; - public fun cos (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun cos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun exp (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; - public synthetic fun getBuffer (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/structures/Buffer; - public fun getBuffer-JVEF3vg (Lkscience/kmath/nd/NDStructure;)[D + public fun exp (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun getBuffer (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/structures/Buffer; + public fun getBuffer-Udx-57Q (Lspace/kscience/kmath/nd/StructureND;)[D public synthetic fun getOne ()Ljava/lang/Object; - public fun getOne ()Lkscience/kmath/nd/NDBuffer; + public fun getOne ()Lspace/kscience/kmath/nd/BufferND; public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lkscience/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;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun getZero ()Lspace/kscience/kmath/nd/BufferND; public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun ln (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; - public fun map (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDBuffer; - public synthetic fun map (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDStructure; - public fun mapIndexed (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDBuffer; - public synthetic fun mapIndexed (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDStructure; + public fun ln (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; + public fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun minus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Lkscience/kmath/nd/NDBuffer; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun plus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; + public fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun pow (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; + public fun pow (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun power (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDBuffer; - public fun produce (Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDBuffer; - public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lkscience/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;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; + public fun power (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/BufferND; + public fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sin (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun sin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun sqrt (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; - public fun tan (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun tan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDBuffer; + public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; } -public final class kscience/kmath/nd/RealNDFieldKt { - public static final fun nd (Lkscience/kmath/operations/RealField;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun real (Lkscience/kmath/nd/NDAlgebra$Companion;[I)Lkscience/kmath/nd/RealNDField; +public final class space/kscience/kmath/nd/DoubleFieldNDKt { + public static final fun nd (Lspace/kscience/kmath/operations/DoubleField;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun real (Lspace/kscience/kmath/nd/AlgebraND$Companion;[I)Lspace/kscience/kmath/nd/DoubleFieldND; } -public final class kscience/kmath/nd/ShapeMismatchException : java/lang/RuntimeException { +public abstract interface class space/kscience/kmath/nd/FieldND : space/kscience/kmath/nd/RingND, space/kscience/kmath/operations/Field, space/kscience/kmath/operations/ScaleOperations { + public abstract fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun divide (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; +} + +public final class space/kscience/kmath/nd/FieldND$DefaultImpls { + public static fun add (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun binaryOperation (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun binaryOperationFunction (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/String;)Lspace/kscience/kmath/nd/StructureND; + public static fun div (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun div (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public static fun div (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public static fun div (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun divide (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun invoke (Lspace/kscience/kmath/nd/FieldND;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun leftSideNumberOperation (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun leftSideNumberOperationFunction (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun minus (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun minus (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public static fun minus (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun multiply (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun number (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public static fun plus (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun plus (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public static fun plus (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun rightSideNumberOperation (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public static fun rightSideNumberOperationFunction (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun times (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun times (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun times (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public static fun times (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public static fun times (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun unaryOperation (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun unaryOperationFunction (Lspace/kscience/kmath/nd/FieldND;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/nd/FieldND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; +} + +public abstract interface class space/kscience/kmath/nd/GroupND : space/kscience/kmath/nd/AlgebraND, space/kscience/kmath/operations/Group { + public static final field Companion Lspace/kscience/kmath/nd/GroupND$Companion; + public abstract fun add (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; +} + +public final class space/kscience/kmath/nd/GroupND$Companion { +} + +public final class space/kscience/kmath/nd/GroupND$DefaultImpls { + public static fun add (Lspace/kscience/kmath/nd/GroupND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun binaryOperation (Lspace/kscience/kmath/nd/GroupND;Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun binaryOperationFunction (Lspace/kscience/kmath/nd/GroupND;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/nd/GroupND;Ljava/lang/String;)Lspace/kscience/kmath/nd/StructureND; + public static fun invoke (Lspace/kscience/kmath/nd/GroupND;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun minus (Lspace/kscience/kmath/nd/GroupND;Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun minus (Lspace/kscience/kmath/nd/GroupND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public static fun minus (Lspace/kscience/kmath/nd/GroupND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun plus (Lspace/kscience/kmath/nd/GroupND;Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun plus (Lspace/kscience/kmath/nd/GroupND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public static fun plus (Lspace/kscience/kmath/nd/GroupND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun unaryOperation (Lspace/kscience/kmath/nd/GroupND;Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun unaryOperationFunction (Lspace/kscience/kmath/nd/GroupND;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/nd/GroupND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; +} + +public abstract interface class space/kscience/kmath/nd/MutableStructureND : space/kscience/kmath/nd/StructureND { + public abstract fun set ([ILjava/lang/Object;)V +} + +public final class space/kscience/kmath/nd/MutableStructureND$DefaultImpls { + public static fun getDimension (Lspace/kscience/kmath/nd/MutableStructureND;)I +} + +public abstract interface class space/kscience/kmath/nd/RingND : space/kscience/kmath/nd/GroupND, space/kscience/kmath/operations/Ring { + public static final field Companion Lspace/kscience/kmath/nd/RingND$Companion; + public abstract fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; +} + +public final class space/kscience/kmath/nd/RingND$Companion { +} + +public final class space/kscience/kmath/nd/RingND$DefaultImpls { + public static fun add (Lspace/kscience/kmath/nd/RingND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun binaryOperation (Lspace/kscience/kmath/nd/RingND;Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun binaryOperationFunction (Lspace/kscience/kmath/nd/RingND;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/nd/RingND;Ljava/lang/String;)Lspace/kscience/kmath/nd/StructureND; + public static fun invoke (Lspace/kscience/kmath/nd/RingND;Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun minus (Lspace/kscience/kmath/nd/RingND;Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun minus (Lspace/kscience/kmath/nd/RingND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public static fun minus (Lspace/kscience/kmath/nd/RingND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun multiply (Lspace/kscience/kmath/nd/RingND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun plus (Lspace/kscience/kmath/nd/RingND;Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun plus (Lspace/kscience/kmath/nd/RingND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public static fun plus (Lspace/kscience/kmath/nd/RingND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun times (Lspace/kscience/kmath/nd/RingND;Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun times (Lspace/kscience/kmath/nd/RingND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public static fun times (Lspace/kscience/kmath/nd/RingND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun unaryOperation (Lspace/kscience/kmath/nd/RingND;Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public static fun unaryOperationFunction (Lspace/kscience/kmath/nd/RingND;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/nd/RingND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; +} + +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 kscience/kmath/nd/ShortNDRing : kscience/kmath/nd/BufferedNDRing, kscience/kmath/operations/RingWithNumbers { +public final class space/kscience/kmath/nd/ShortRingND : space/kscience/kmath/nd/BufferedRingND, space/kscience/kmath/operations/NumbersAddOperations { public fun ([I)V public synthetic fun getOne ()Ljava/lang/Object; - public fun getOne ()Lkscience/kmath/nd/NDBuffer; + public fun getOne ()Lspace/kscience/kmath/nd/BufferND; public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lkscience/kmath/nd/NDBuffer; + public fun getZero ()Lspace/kscience/kmath/nd/BufferND; 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;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; 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;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun minus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Lkscience/kmath/nd/NDBuffer; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun plus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; + public fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun rightSideNumberOperation (Ljava/lang/String;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; } -public final class kscience/kmath/nd/ShortNDRingKt { - public static final fun nd (Lkscience/kmath/operations/ShortRing;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun produceInline (Lkscience/kmath/nd/BufferedNDRing;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDBuffer; +public final class space/kscience/kmath/nd/ShortRingNDKt { + 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/BufferedRingND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; } -public abstract interface class kscience/kmath/nd/Strides { +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; @@ -1355,224 +1030,250 @@ public abstract interface class kscience/kmath/nd/Strides { public abstract fun offset ([I)I } -public final class kscience/kmath/nd/Strides$DefaultImpls { - public static fun indices (Lkscience/kmath/nd/Strides;)Lkotlin/sequences/Sequence; +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 kscience/kmath/nd/Structure1D : kscience/kmath/nd/NDStructure, kscience/kmath/structures/Buffer { +public abstract interface class space/kscience/kmath/nd/Structure1D : space/kscience/kmath/nd/StructureND, space/kscience/kmath/structures/Buffer { + public static final field Companion Lspace/kscience/kmath/nd/Structure1D$Companion; public abstract fun get ([I)Ljava/lang/Object; public abstract fun getDimension ()I public abstract fun iterator ()Ljava/util/Iterator; } -public final class kscience/kmath/nd/Structure1D$DefaultImpls { - public static fun contentEquals (Lkscience/kmath/nd/Structure1D;Lkscience/kmath/structures/Buffer;)Z - public static fun get (Lkscience/kmath/nd/Structure1D;[I)Ljava/lang/Object; - public static fun getDimension (Lkscience/kmath/nd/Structure1D;)I - public static fun getFeature (Lkscience/kmath/nd/Structure1D;Lkotlin/reflect/KClass;)Ljava/lang/Object; - public static fun iterator (Lkscience/kmath/nd/Structure1D;)Ljava/util/Iterator; +public final class space/kscience/kmath/nd/Structure1D$Companion { } -public final class kscience/kmath/nd/Structure1DKt { - public static final fun as1D (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/Structure1D; - public static final fun asND (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/nd/Structure1D; +public final class space/kscience/kmath/nd/Structure1D$DefaultImpls { + 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 abstract interface class kscience/kmath/nd/Structure2D : kscience/kmath/nd/NDStructure { - public static final field Companion Lkscience/kmath/nd/Structure2D$Companion; +public final class space/kscience/kmath/nd/Structure1DKt { + public static final fun as1D (Lspace/kscience/kmath/nd/StructureND;)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/StructureND { + 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 ()Lkscience/kmath/structures/Buffer; + public abstract fun getColumns ()Ljava/util/List; public abstract fun getRowNum ()I - public abstract fun getRows ()Lkscience/kmath/structures/Buffer; + public abstract fun getRows ()Ljava/util/List; public abstract fun getShape ()[I } -public final class kscience/kmath/nd/Structure2D$Companion { - public final fun real (IILkotlin/jvm/functions/Function2;)Lkscience/kmath/linear/BufferMatrix; +public final class space/kscience/kmath/nd/Structure2D$Companion { } -public final class kscience/kmath/nd/Structure2D$DefaultImpls { - public static fun elements (Lkscience/kmath/nd/Structure2D;)Lkotlin/sequences/Sequence; - public static fun get (Lkscience/kmath/nd/Structure2D;[I)Ljava/lang/Object; - public static fun getColumns (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/structures/Buffer; - public static fun getDimension (Lkscience/kmath/nd/Structure2D;)I - public static fun getFeature (Lkscience/kmath/nd/Structure2D;Lkotlin/reflect/KClass;)Ljava/lang/Object; - public static fun getRows (Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/structures/Buffer; - public static fun getShape (Lkscience/kmath/nd/Structure2D;)[I +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;)Ljava/util/List; + public static fun getDimension (Lspace/kscience/kmath/nd/Structure2D;)I + public static fun getRows (Lspace/kscience/kmath/nd/Structure2D;)Ljava/util/List; + public static fun getShape (Lspace/kscience/kmath/nd/Structure2D;)[I } -public final class kscience/kmath/nd/Structure2DKt { - public static final fun as2D (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/Structure2D; +public final class space/kscience/kmath/nd/Structure2DKt { + public static final fun as2D (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Structure2D; } -public abstract interface class kscience/kmath/operations/Algebra { +public abstract interface class space/kscience/kmath/nd/StructureFeature { +} + +public abstract interface class space/kscience/kmath/nd/StructureND { + public static final field Companion Lspace/kscience/kmath/nd/StructureND$Companion; + public abstract fun elements ()Lkotlin/sequences/Sequence; + public abstract fun get ([I)Ljava/lang/Object; + public abstract fun getDimension ()I + public abstract fun getShape ()[I +} + +public final class space/kscience/kmath/nd/StructureND$Companion { + public final fun auto (Lkotlin/reflect/KClass;Lspace/kscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; + public final fun auto (Lkotlin/reflect/KClass;[ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; + public final fun buffered (Lspace/kscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; + public final fun buffered ([ILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; + public static synthetic fun buffered$default (Lspace/kscience/kmath/nd/StructureND$Companion;Lspace/kscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/BufferND; + public static synthetic fun buffered$default (Lspace/kscience/kmath/nd/StructureND$Companion;[ILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/BufferND; + public final fun contentEquals (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Z + public final fun toString (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/String; +} + +public final class space/kscience/kmath/nd/StructureND$DefaultImpls { + public static fun getDimension (Lspace/kscience/kmath/nd/StructureND;)I +} + +public final class space/kscience/kmath/nd/StructureNDKt { + public static final fun get (Lspace/kscience/kmath/nd/StructureND;[I)Ljava/lang/Object; + public static final fun mapInPlace (Lspace/kscience/kmath/nd/MutableStructureND;Lkotlin/jvm/functions/Function2;)V +} + +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 symbol (Ljava/lang/String;)Ljava/lang/Object; + 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 kscience/kmath/operations/Algebra$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/Algebra;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/Algebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun symbol (Lkscience/kmath/operations/Algebra;Ljava/lang/String;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/Algebra;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/Algebra;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 kscience/kmath/operations/AlgebraElement { - public abstract fun getContext ()Lkscience/kmath/operations/Algebra; +public abstract interface class space/kscience/kmath/operations/AlgebraElement { + public abstract fun getContext ()Lspace/kscience/kmath/operations/Algebra; } -public final class kscience/kmath/operations/AlgebraElementsKt { - public static final fun div (Lkscience/kmath/operations/AlgebraElement;Ljava/lang/Number;)Lkscience/kmath/operations/AlgebraElement; - public static final fun div (Lkscience/kmath/operations/AlgebraElement;Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun minus (Lkscience/kmath/operations/AlgebraElement;Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun plus (Lkscience/kmath/operations/AlgebraElement;Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun times (Ljava/lang/Number;Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun times (Lkscience/kmath/operations/AlgebraElement;Ljava/lang/Number;)Lkscience/kmath/operations/AlgebraElement; - public static final fun times (Lkscience/kmath/operations/AlgebraElement;Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; +public final class space/kscience/kmath/operations/AlgebraElementsKt { + public static final fun div (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 (Lspace/kscience/kmath/operations/AlgebraElement;Lspace/kscience/kmath/operations/AlgebraElement;)Lspace/kscience/kmath/operations/AlgebraElement; } -public final class kscience/kmath/operations/AlgebraExtensionsKt { - public static final fun abs (Lkscience/kmath/operations/Space;Ljava/lang/Comparable;)Ljava/lang/Comparable; - public static final fun average (Lkscience/kmath/operations/Space;Ljava/lang/Iterable;)Ljava/lang/Object; - public static final fun average (Lkscience/kmath/operations/Space;Lkotlin/sequences/Sequence;)Ljava/lang/Object; - public static final fun averageWith (Ljava/lang/Iterable;Lkscience/kmath/operations/Space;)Ljava/lang/Object; - public static final fun averageWith (Lkotlin/sequences/Sequence;Lkscience/kmath/operations/Space;)Ljava/lang/Object; - public static final fun power (Lkscience/kmath/operations/Field;Ljava/lang/Object;I)Ljava/lang/Object; - public static final fun power (Lkscience/kmath/operations/Ring;Ljava/lang/Object;I)Ljava/lang/Object; - public static final fun sum (Lkscience/kmath/operations/Space;Ljava/lang/Iterable;)Ljava/lang/Object; - public static final fun sum (Lkscience/kmath/operations/Space;Lkotlin/sequences/Sequence;)Ljava/lang/Object; - public static final fun sumWith (Ljava/lang/Iterable;Lkscience/kmath/operations/Space;)Ljava/lang/Object; - public static final fun sumWith (Lkotlin/sequences/Sequence;Lkscience/kmath/operations/Space;)Ljava/lang/Object; +public final class space/kscience/kmath/operations/AlgebraExtensionsKt { + public static final fun abs (Lspace/kscience/kmath/operations/Group;Ljava/lang/Comparable;)Ljava/lang/Comparable; + public static final fun average (Lspace/kscience/kmath/operations/Group;Ljava/lang/Iterable;)Ljava/lang/Object; + public static final fun average (Lspace/kscience/kmath/operations/Group;Lkotlin/sequences/Sequence;)Ljava/lang/Object; + public static final fun averageWith (Ljava/lang/Iterable;Lspace/kscience/kmath/operations/Group;)Ljava/lang/Object; + public static final fun averageWith (Lkotlin/sequences/Sequence;Lspace/kscience/kmath/operations/Group;)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/Group;Ljava/lang/Iterable;)Ljava/lang/Object; + public static final fun sum (Lspace/kscience/kmath/operations/Group;Lkotlin/sequences/Sequence;)Ljava/lang/Object; + public static final fun sumWith (Ljava/lang/Iterable;Lspace/kscience/kmath/operations/Group;)Ljava/lang/Object; + public static final fun sumWith (Lkotlin/sequences/Sequence;Lspace/kscience/kmath/operations/Group;)Ljava/lang/Object; } -public final class kscience/kmath/operations/AlgebraKt { - public static final fun invoke (Lkscience/kmath/operations/Algebra;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; +public final class space/kscience/kmath/operations/AlgebraKt { + public static final fun bindSymbol (Lspace/kscience/kmath/operations/Algebra;Lspace/kscience/kmath/misc/Symbol;)Ljava/lang/Object; + public static final fun invoke (Lspace/kscience/kmath/operations/Algebra;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } -public final class kscience/kmath/operations/BigInt : java/lang/Comparable { +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 Lkscience/kmath/operations/BigInt$Companion; - public final fun abs ()Lkscience/kmath/operations/BigInt; - public final fun and (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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 (Lkscience/kmath/operations/BigInt;)I - public final fun div (I)Lkscience/kmath/operations/BigInt; - public final fun div (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; - public final fun div-WZ4Q5Ns (I)Lkscience/kmath/operations/BigInt; + 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 (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; - public final fun modPow (Lkscience/kmath/operations/BigInt;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; - public final fun or (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; - public final fun plus (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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 (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; - public final fun shl (I)Lkscience/kmath/operations/BigInt; - public final fun shr (I)Lkscience/kmath/operations/BigInt; - public final fun times (I)Lkscience/kmath/operations/BigInt; - public final fun times (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; - public final fun times-WZ4Q5Ns (I)Lkscience/kmath/operations/BigInt; + 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 ()Lkscience/kmath/operations/BigInt; + public final fun unaryMinus ()Lspace/kscience/kmath/operations/BigInt; } -public final class kscience/kmath/operations/BigInt$Companion { - public final fun getONE ()Lkscience/kmath/operations/BigInt; - public final fun getZERO ()Lkscience/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 kscience/kmath/operations/BigIntField : kscience/kmath/operations/Field, kscience/kmath/operations/RingWithNumbers { - public static final field INSTANCE Lkscience/kmath/operations/BigIntField; +public final class space/kscience/kmath/operations/BigIntField : space/kscience/kmath/operations/Field, space/kscience/kmath/operations/NumbersAddOperations, space/kscience/kmath/operations/ScaleOperations { + 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 (Lkscience/kmath/operations/BigInt;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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;Lkscience/kmath/operations/BigInt;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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 div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun div (Ljava/lang/Number;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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/Object;Ljava/lang/Number;)Ljava/lang/Object; public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun div (Lkscience/kmath/operations/BigInt;Ljava/lang/Number;)Lkscience/kmath/operations/BigInt; - public fun div (Lkscience/kmath/operations/BigInt;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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 (Lkscience/kmath/operations/BigInt;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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 ()Lkscience/kmath/operations/BigInt; + public fun getOne ()Lspace/kscience/kmath/operations/BigInt; public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lkscience/kmath/operations/BigInt; + 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;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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 (Lkscience/kmath/operations/BigInt;Ljava/lang/Number;)Lkscience/kmath/operations/BigInt; - public fun minus (Lkscience/kmath/operations/BigInt;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)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/Object;)Ljava/lang/Object; - public fun multiply (Lkscience/kmath/operations/BigInt;Ljava/lang/Number;)Lkscience/kmath/operations/BigInt; - public fun multiply (Lkscience/kmath/operations/BigInt;Lkscience/kmath/operations/BigInt;)Lkscience/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;)Lkscience/kmath/operations/BigInt; + 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;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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 (Lkscience/kmath/operations/BigInt;Ljava/lang/Number;)Lkscience/kmath/operations/BigInt; - public fun plus (Lkscience/kmath/operations/BigInt;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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;Lkscience/kmath/operations/BigInt;Ljava/lang/Number;)Lkscience/kmath/operations/BigInt; + 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 symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/operations/BigInt; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/operations/BigInt;D)Lspace/kscience/kmath/operations/BigInt; public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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 (Lkscience/kmath/operations/BigInt;Ljava/lang/Number;)Lkscience/kmath/operations/BigInt; - public fun times (Lkscience/kmath/operations/BigInt;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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;)Lkscience/kmath/operations/BigInt; - public fun unaryMinus (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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;Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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;)Lkscience/kmath/operations/BigInt; - public fun unaryPlus (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; + 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 kscience/kmath/operations/BigIntKt { - public static final fun abs (Lkscience/kmath/operations/BigInt;)Lkscience/kmath/operations/BigInt; - public static final fun bigInt (Lkscience/kmath/nd/NDAlgebra$Companion;[I)Lkscience/kmath/nd/BufferedNDRing; - public static final fun bigInt (Lkscience/kmath/structures/Buffer$Companion;ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer; - public static final fun bigInt (Lkscience/kmath/structures/MutableBuffer$Companion;ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/MutableBuffer; - public static final fun parseBigInteger (Ljava/lang/String;)Lkscience/kmath/operations/BigInt; - public static final fun toBigInt (I)Lkscience/kmath/operations/BigInt; - public static final fun toBigInt (J)Lkscience/kmath/operations/BigInt; - public static final fun toBigInt-LpG4sQ0 ([IB)Lkscience/kmath/operations/BigInt; - public static final fun toBigInt-VKZWuLQ (J)Lkscience/kmath/operations/BigInt; - public static final fun toBigInt-WZ4Q5Ns (I)Lkscience/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/AlgebraND$Companion;[I)Lspace/kscience/kmath/nd/BufferedRingND; + 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 kscience/kmath/operations/ByteRing : kscience/kmath/operations/Norm, kscience/kmath/operations/NumericAlgebra, kscience/kmath/operations/Ring { - public static final field INSTANCE Lkscience/kmath/operations/ByteRing; +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 div (BLjava/lang/Number;)Ljava/lang/Byte; - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Byte; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; public fun getOne ()Ljava/lang/Byte; public synthetic fun getOne ()Ljava/lang/Object; public fun getZero ()Ljava/lang/Byte; @@ -1583,8 +1284,6 @@ public final class kscience/kmath/operations/ByteRing : kscience/kmath/operation 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; @@ -1595,13 +1294,7 @@ public final class kscience/kmath/operations/ByteRing : kscience/kmath/operation 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 symbol (Ljava/lang/String;)Ljava/lang/Byte; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; 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; @@ -1612,560 +1305,8 @@ public final class kscience/kmath/operations/ByteRing : kscience/kmath/operation public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; } -public abstract interface class kscience/kmath/operations/ExponentialOperations : kscience/kmath/operations/Algebra { - public static final field Companion Lkscience/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 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 kscience/kmath/operations/ExponentialOperations$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/ExponentialOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/ExponentialOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun symbol (Lkscience/kmath/operations/ExponentialOperations;Ljava/lang/String;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/ExponentialOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/ExponentialOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; -} - -public abstract interface class kscience/kmath/operations/ExtendedField : kscience/kmath/operations/ExtendedFieldOperations, kscience/kmath/operations/Field, 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 kscience/kmath/operations/ExtendedField$DefaultImpls { - public static fun acosh (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; - public static fun asinh (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; - public static fun atanh (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperation (Lkscience/kmath/operations/ExtendedField;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/ExtendedField;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun cosh (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; - public static fun div (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun div (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun div (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun leftSideNumberOperation (Lkscience/kmath/operations/ExtendedField;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun leftSideNumberOperationFunction (Lkscience/kmath/operations/ExtendedField;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun minus (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun pow (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun rightSideNumberOperation (Lkscience/kmath/operations/ExtendedField;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun rightSideNumberOperationFunction (Lkscience/kmath/operations/ExtendedField;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun sinh (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; - public static fun sqrt (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; - public static fun symbol (Lkscience/kmath/operations/ExtendedField;Ljava/lang/String;)Ljava/lang/Object; - public static fun tan (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; - public static fun tanh (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryMinus (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/ExtendedField;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/ExtendedField;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/operations/ExtendedField;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class kscience/kmath/operations/ExtendedFieldOperations : kscience/kmath/operations/ExponentialOperations, kscience/kmath/operations/FieldOperations, kscience/kmath/operations/HyperbolicOperations, kscience/kmath/operations/PowerOperations, 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 kscience/kmath/operations/ExtendedFieldOperations$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun div (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun minus (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun pow (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun sqrt (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; - public static fun symbol (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;)Ljava/lang/Object; - public static fun tan (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; - public static fun tanh (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryMinus (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/operations/ExtendedFieldOperations;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class kscience/kmath/operations/Field : kscience/kmath/operations/FieldOperations, kscience/kmath/operations/Ring { - public abstract fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class kscience/kmath/operations/Field$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/Field;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/Field;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/operations/Field;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun div (Lkscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun div (Lkscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun minus (Lkscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun symbol (Lkscience/kmath/operations/Field;Ljava/lang/String;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/Field;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryMinus (Lkscience/kmath/operations/Field;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/Field;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/Field;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/operations/Field;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class kscience/kmath/operations/FieldElement : kscience/kmath/operations/RingElement { -} - -public abstract interface class kscience/kmath/operations/FieldOperations : kscience/kmath/operations/RingOperations { - public static final field Companion Lkscience/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 kscience/kmath/operations/FieldOperations$Companion { - public static final field DIV_OPERATION Ljava/lang/String; -} - -public final class kscience/kmath/operations/FieldOperations$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/FieldOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/FieldOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun div (Lkscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun minus (Lkscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun symbol (Lkscience/kmath/operations/FieldOperations;Ljava/lang/String;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/FieldOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/FieldOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryMinus (Lkscience/kmath/operations/FieldOperations;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/FieldOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/FieldOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/operations/FieldOperations;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class kscience/kmath/operations/FloatField : kscience/kmath/operations/ExtendedField, kscience/kmath/operations/Norm { - public static final field INSTANCE Lkscience/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 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 symbol (Ljava/lang/String;)Ljava/lang/Float; - public synthetic fun symbol (Ljava/lang/String;)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 kscience/kmath/operations/HyperbolicOperations : 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 Lkscience/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 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 kscience/kmath/operations/HyperbolicOperations$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun symbol (Lkscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/HyperbolicOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; -} - -public final class kscience/kmath/operations/IntRing : kscience/kmath/operations/Norm, kscience/kmath/operations/NumericAlgebra, kscience/kmath/operations/Ring { - public static final field INSTANCE Lkscience/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 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 symbol (Ljava/lang/String;)Ljava/lang/Integer; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - 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 kscience/kmath/operations/JBigDecimalField : kscience/kmath/operations/JBigDecimalFieldBase { - public static final field Companion Lkscience/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 kscience/kmath/operations/JBigDecimalField$Companion : kscience/kmath/operations/JBigDecimalFieldBase { -} - -public abstract class kscience/kmath/operations/JBigDecimalFieldBase : kscience/kmath/operations/Field, kscience/kmath/operations/NumericAlgebra, 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 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 symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)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 kscience/kmath/operations/JBigIntegerField : kscience/kmath/operations/Field, kscience/kmath/operations/NumericAlgebra { - public static final field INSTANCE Lkscience/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 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 symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Ljava/math/BigInteger; - 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 kscience/kmath/operations/KMathContext : java/lang/annotation/Annotation { -} - -public final class kscience/kmath/operations/LongRing : kscience/kmath/operations/Norm, kscience/kmath/operations/NumericAlgebra, kscience/kmath/operations/Ring { - public static final field INSTANCE Lkscience/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 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 symbol (Ljava/lang/String;)Ljava/lang/Long; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - 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 kscience/kmath/operations/Norm { - public abstract fun norm (Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class kscience/kmath/operations/NumericAlgebra : 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 kscience/kmath/operations/NumericAlgebra$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/NumericAlgebra;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun leftSideNumberOperation (Lkscience/kmath/operations/NumericAlgebra;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun leftSideNumberOperationFunction (Lkscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun rightSideNumberOperation (Lkscience/kmath/operations/NumericAlgebra;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun rightSideNumberOperationFunction (Lkscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun symbol (Lkscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/NumericAlgebra;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/NumericAlgebra;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; -} - -public final class kscience/kmath/operations/OptionalOperationsKt { - public static final fun acos (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun acosh (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun asin (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun asinh (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun atan (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun atanh (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun cos (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun cosh (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun exp (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun ln (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun norm (Lkscience/kmath/operations/AlgebraElement;)Ljava/lang/Object; - public static final fun pow (Lkscience/kmath/operations/AlgebraElement;D)Lkscience/kmath/operations/AlgebraElement; - public static final fun sin (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun sinh (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun sqr (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun sqrt (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun tan (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; - public static final fun tanh (Lkscience/kmath/operations/AlgebraElement;)Lkscience/kmath/operations/AlgebraElement; -} - -public abstract interface class kscience/kmath/operations/PowerOperations : kscience/kmath/operations/Algebra { - public static final field Companion Lkscience/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 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 kscience/kmath/operations/PowerOperations$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/PowerOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/PowerOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun pow (Lkscience/kmath/operations/PowerOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun sqrt (Lkscience/kmath/operations/PowerOperations;Ljava/lang/Object;)Ljava/lang/Object; - public static fun symbol (Lkscience/kmath/operations/PowerOperations;Ljava/lang/String;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/PowerOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/PowerOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; -} - -public final class kscience/kmath/operations/RealField : kscience/kmath/operations/ExtendedField, kscience/kmath/operations/Norm { - public static final field INSTANCE Lkscience/kmath/operations/RealField; +public final class space/kscience/kmath/operations/DoubleField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/ScaleOperations { + public static final field INSTANCE Lspace/kscience/kmath/operations/DoubleField; public fun acos (D)Ljava/lang/Double; public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; public fun acosh (D)Ljava/lang/Double; @@ -2183,14 +1324,14 @@ public final class kscience/kmath/operations/RealField : kscience/kmath/operatio 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; @@ -2209,8 +1350,6 @@ public final class kscience/kmath/operations/RealField : kscience/kmath/operatio 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; @@ -2225,14 +1364,14 @@ public final class kscience/kmath/operations/RealField : kscience/kmath/operatio 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 scale (DD)Ljava/lang/Double; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; 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 symbol (Ljava/lang/String;)Ljava/lang/Double; - public synthetic fun symbol (Ljava/lang/String;)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; @@ -2252,99 +1391,612 @@ public final class kscience/kmath/operations/RealField : kscience/kmath/operatio public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; } -public abstract interface class kscience/kmath/operations/Ring : kscience/kmath/operations/RingOperations, kscience/kmath/operations/Space { +public abstract interface class space/kscience/kmath/operations/ExponentialOperations : 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/ExponentialOperations$Companion; + public static final field EXP_OPERATION Ljava/lang/String; + public static final field LN_OPERATION Ljava/lang/String; + 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 exp (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun ln (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/ExponentialOperations$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 EXP_OPERATION Ljava/lang/String; + public static final field LN_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/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, space/kscience/kmath/operations/ScaleOperations { + 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/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 number (Lspace/kscience/kmath/operations/ExtendedField;Ljava/lang/Number;)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 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/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/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/Object;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/NumericAlgebra, space/kscience/kmath/operations/Ring, space/kscience/kmath/operations/ScaleOperations { + public abstract fun number (Ljava/lang/Number;)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/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 leftSideNumberOperation (Lspace/kscience/kmath/operations/Field;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun leftSideNumberOperationFunction (Lspace/kscience/kmath/operations/Field;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun minus (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun number (Lspace/kscience/kmath/operations/Field;Ljava/lang/Number;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/Field;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun rightSideNumberOperation (Lspace/kscience/kmath/operations/Field;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun rightSideNumberOperationFunction (Lspace/kscience/kmath/operations/Field;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + 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 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/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/Object;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 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 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 scale (FD)Ljava/lang/Float; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + 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/Group : space/kscience/kmath/operations/GroupOperations { + public abstract fun getZero ()Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/Group$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/Group;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/Group;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/Group;Ljava/lang/String;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/Group;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/Group;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/Group;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/Group;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/Group;Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class space/kscience/kmath/operations/GroupOperations : space/kscience/kmath/operations/Algebra { + public static final field Companion Lspace/kscience/kmath/operations/GroupOperations$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 minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun plus (Ljava/lang/Object;Ljava/lang/Object;)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/GroupOperations$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/GroupOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/GroupOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/GroupOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/GroupOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/GroupOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/GroupOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/GroupOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/GroupOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/GroupOperations;Ljava/lang/Object;)Ljava/lang/Object; +} + +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 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 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 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, space/kscience/kmath/operations/ScaleOperations { + 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/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/Object;)Ljava/lang/Object; + 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 scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Ljava/math/BigDecimal;D)Ljava/math/BigDecimal; + 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/NumericAlgebra, space/kscience/kmath/operations/Ring { + 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 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/Object;)Ljava/lang/Object; + 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/Object;Ljava/lang/Object;)Ljava/lang/Object; + 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 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 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 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 final class space/kscience/kmath/operations/NumbersAddOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun leftSideNumberOperation (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun leftSideNumberOperationFunction (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun minus (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun minus (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun plus (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun rightSideNumberOperation (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun rightSideNumberOperationFunction (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun unaryOperation (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/NumbersAddOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public static fun unaryPlus (Lspace/kscience/kmath/operations/NumbersAddOperations;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 abstract interface class space/kscience/kmath/operations/Ring : space/kscience/kmath/operations/Group, space/kscience/kmath/operations/RingOperations { public abstract fun getOne ()Ljava/lang/Object; } -public final class kscience/kmath/operations/Ring$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/Ring;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/Ring;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun minus (Lkscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun symbol (Lkscience/kmath/operations/Ring;Ljava/lang/String;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/Ring;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/Ring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryMinus (Lkscience/kmath/operations/Ring;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/Ring;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/Ring;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/operations/Ring;Ljava/lang/Object;)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 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/Object;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 kscience/kmath/operations/RingElement : kscience/kmath/operations/SpaceElement { -} - -public abstract interface class kscience/kmath/operations/RingOperations : kscience/kmath/operations/SpaceOperations { - public static final field Companion Lkscience/kmath/operations/RingOperations$Companion; +public abstract interface class space/kscience/kmath/operations/RingOperations : space/kscience/kmath/operations/GroupOperations { + 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 kscience/kmath/operations/RingOperations$Companion { +public final class space/kscience/kmath/operations/RingOperations$Companion { public static final field TIMES_OPERATION Ljava/lang/String; } -public final class kscience/kmath/operations/RingOperations$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/RingOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/RingOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun minus (Lkscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun symbol (Lkscience/kmath/operations/RingOperations;Ljava/lang/String;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/RingOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/RingOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryMinus (Lkscience/kmath/operations/RingOperations;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/RingOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/RingOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/operations/RingOperations;Ljava/lang/Object;)Ljava/lang/Object; +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 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/Object;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 abstract interface class kscience/kmath/operations/RingWithNumbers : kscience/kmath/operations/NumericAlgebra, kscience/kmath/operations/Ring { - public abstract fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public abstract fun number (Ljava/lang/Number;)Ljava/lang/Object; - public abstract fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; +public abstract interface class space/kscience/kmath/operations/ScaleOperations : space/kscience/kmath/operations/Algebra { + public abstract fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public abstract fun scale (Ljava/lang/Object;D)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 final class kscience/kmath/operations/RingWithNumbers$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun leftSideNumberOperation (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun leftSideNumberOperationFunction (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun minus (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun minus (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun minus (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun number (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Number;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun rightSideNumberOperation (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun rightSideNumberOperationFunction (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun symbol (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryMinus (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/operations/RingWithNumbers;Ljava/lang/Object;)Ljava/lang/Object; +public final class space/kscience/kmath/operations/ScaleOperations$DefaultImpls { + public static fun binaryOperation (Lspace/kscience/kmath/operations/ScaleOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun binaryOperationFunction (Lspace/kscience/kmath/operations/ScaleOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public static fun bindSymbol (Lspace/kscience/kmath/operations/ScaleOperations;Ljava/lang/String;)Ljava/lang/Object; + public static fun div (Lspace/kscience/kmath/operations/ScaleOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/ScaleOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public static fun times (Lspace/kscience/kmath/operations/ScaleOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public static fun unaryOperation (Lspace/kscience/kmath/operations/ScaleOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/ScaleOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; } -public final class kscience/kmath/operations/ShortRing : kscience/kmath/operations/Norm, kscience/kmath/operations/NumericAlgebra, kscience/kmath/operations/Ring { - public static final field INSTANCE Lkscience/kmath/operations/ShortRing; +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 div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun div (SLjava/lang/Number;)Ljava/lang/Short; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Short; public synthetic fun getOne ()Ljava/lang/Object; public fun getOne ()Ljava/lang/Short; public synthetic fun getZero ()Ljava/lang/Object; @@ -2354,9 +2006,7 @@ public final class kscience/kmath/operations/ShortRing : kscience/kmath/operatio 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; @@ -2367,13 +2017,7 @@ public final class kscience/kmath/operations/ShortRing : kscience/kmath/operatio 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 symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Ljava/lang/Short; - 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; @@ -2384,71 +2028,12 @@ public final class kscience/kmath/operations/ShortRing : kscience/kmath/operatio public fun unaryPlus (S)Ljava/lang/Short; } -public abstract interface class kscience/kmath/operations/Space : kscience/kmath/operations/SpaceOperations { - public abstract fun getZero ()Ljava/lang/Object; -} - -public final class kscience/kmath/operations/Space$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/Space;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/Space;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/operations/Space;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun minus (Lkscience/kmath/operations/Space;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/Space;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun symbol (Lkscience/kmath/operations/Space;Ljava/lang/String;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/Space;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/Space;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun unaryMinus (Lkscience/kmath/operations/Space;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/Space;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/Space;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/operations/Space;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class kscience/kmath/operations/SpaceElement : kscience/kmath/operations/AlgebraElement { -} - -public abstract interface class kscience/kmath/operations/SpaceOperations : kscience/kmath/operations/Algebra { - public static final field Companion Lkscience/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 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 kscience/kmath/operations/SpaceOperations$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun div (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun minus (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun symbol (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/String;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public static fun unaryMinus (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public static fun unaryPlus (Lkscience/kmath/operations/SpaceOperations;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class kscience/kmath/operations/TrigonometricOperations : kscience/kmath/operations/Algebra { +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 Lkscience/kmath/operations/TrigonometricOperations$Companion; + 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; @@ -2459,7 +2044,7 @@ public abstract interface class kscience/kmath/operations/TrigonometricOperation public abstract fun tan (Ljava/lang/Object;)Ljava/lang/Object; } -public final class kscience/kmath/operations/TrigonometricOperations$Companion { +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; @@ -2468,310 +2053,57 @@ public final class kscience/kmath/operations/TrigonometricOperations$Companion { public static final field TAN_OPERATION Ljava/lang/String; } -public final class kscience/kmath/operations/TrigonometricOperations$DefaultImpls { - public static fun binaryOperation (Lkscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun binaryOperationFunction (Lkscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public static fun symbol (Lkscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;)Ljava/lang/Object; - public static fun unaryOperation (Lkscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public static fun unaryOperationFunction (Lkscience/kmath/operations/TrigonometricOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +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 kscience/kmath/structures/ArrayBuffer : kscience/kmath/structures/MutableBuffer { +public final class space/kscience/kmath/structures/ArrayBuffer : space/kscience/kmath/structures/MutableBuffer { public fun ([Ljava/lang/Object;)V - public fun contentEquals (Lkscience/kmath/structures/Buffer;)Z - public fun copy ()Lkscience/kmath/structures/MutableBuffer; + 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 kscience/kmath/structures/Buffer { - public static final field Companion Lkscience/kmath/structures/Buffer$Companion; - public abstract fun contentEquals (Lkscience/kmath/structures/Buffer;)Z +public abstract interface class space/kscience/kmath/structures/Buffer { + public static final field Companion Lspace/kscience/kmath/structures/Buffer$Companion; public abstract fun get (I)Ljava/lang/Object; public abstract fun getSize ()I public abstract fun iterator ()Ljava/util/Iterator; } -public final class kscience/kmath/structures/Buffer$Companion { - public final fun auto (Lkotlin/reflect/KClass;ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer; - public final fun boxing (ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer; - public final fun real-4n5bU9U (ILkotlin/jvm/functions/Function1;)[D +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 contentEquals (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Z } -public final class kscience/kmath/structures/Buffer$DefaultImpls { - public static fun contentEquals (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Z -} - -public final class kscience/kmath/structures/BufferKt { - public static final fun ListBuffer (ILkotlin/jvm/functions/Function1;)Ljava/util/List; +public final class space/kscience/kmath/structures/BufferKt { public static final fun asBuffer (Ljava/util/List;)Ljava/util/List; - public static final fun asBuffer ([Ljava/lang/Object;)Lkscience/kmath/structures/ArrayBuffer; - public static final fun asIterable (Lkscience/kmath/structures/Buffer;)Ljava/lang/Iterable; - public static final fun asReadOnly (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public static final fun asSequence (Lkscience/kmath/structures/Buffer;)Lkotlin/sequences/Sequence; - public static final fun getIndices (Lkscience/kmath/structures/Buffer;)Lkotlin/ranges/IntRange; - public static final fun toList (Lkscience/kmath/structures/Buffer;)Ljava/util/List; + public static final fun asBuffer ([Ljava/lang/Object;)Lspace/kscience/kmath/structures/ArrayBuffer; + public static final fun asMutableBuffer (Ljava/util/List;)Ljava/util/List; + public static final fun asReadOnly (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static final fun getIndices (Lspace/kscience/kmath/structures/Buffer;)Lkotlin/ranges/IntRange; } -public abstract interface class kscience/kmath/structures/FlaggedBuffer : kscience/kmath/structures/Buffer { - public abstract fun getFlag (I)B +public final class space/kscience/kmath/structures/BufferOperationKt { + public static final fun asIterable (Lspace/kscience/kmath/structures/Buffer;)Ljava/lang/Iterable; + public static final fun asSequence (Lspace/kscience/kmath/structures/Buffer;)Lkotlin/sequences/Sequence; + public static final fun fold (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static final fun toList (Lspace/kscience/kmath/structures/Buffer;)Ljava/util/List; } -public final class kscience/kmath/structures/FlaggedBuffer$DefaultImpls { - public static fun contentEquals (Lkscience/kmath/structures/FlaggedBuffer;Lkscience/kmath/structures/Buffer;)Z -} - -public final class kscience/kmath/structures/FlaggedBufferKt { - public static final fun forEachValid (Lkscience/kmath/structures/FlaggedRealBuffer;Lkotlin/jvm/functions/Function1;)V - public static final fun hasFlag (Lkscience/kmath/structures/FlaggedBuffer;ILkscience/kmath/structures/ValueFlag;)Z - public static final fun isMissing (Lkscience/kmath/structures/FlaggedBuffer;I)Z - public static final fun isValid (Lkscience/kmath/structures/FlaggedBuffer;I)Z -} - -public final class kscience/kmath/structures/FlaggedRealBuffer : kscience/kmath/structures/Buffer, kscience/kmath/structures/FlaggedBuffer { - public fun ([D[B)V - public fun contentEquals (Lkscience/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 kscience/kmath/structures/FloatBuffer : kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl ([F)Lkscience/kmath/structures/FloatBuffer; - public static fun constructor-impl ([F)[F - public fun contentEquals (Lkscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl ([FLkscience/kmath/structures/Buffer;)Z - public fun copy ()Lkscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([F)Lkscience/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 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 (Lkscience/kmath/structures/MutableBuffer;)[F -} - -public final class kscience/kmath/structures/IntBuffer : kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl ([I)Lkscience/kmath/structures/IntBuffer; - public static fun constructor-impl ([I)[I - public fun contentEquals (Lkscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl ([ILkscience/kmath/structures/Buffer;)Z - public fun copy ()Lkscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([I)Lkscience/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 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 (Lkscience/kmath/structures/MutableBuffer;)[I -} - -public final class kscience/kmath/structures/ListBuffer : kscience/kmath/structures/Buffer { - public static final synthetic fun box-impl (Ljava/util/List;)Lkscience/kmath/structures/ListBuffer; - public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; - public fun contentEquals (Lkscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl (Ljava/util/List;Lkscience/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 kscience/kmath/structures/LongBuffer : kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl ([J)Lkscience/kmath/structures/LongBuffer; - public static fun constructor-impl ([J)[J - public fun contentEquals (Lkscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl ([JLkscience/kmath/structures/Buffer;)Z - public fun copy ()Lkscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([J)Lkscience/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 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 (Lkscience/kmath/structures/MutableBuffer;)[J -} - -public class kscience/kmath/structures/MemoryBuffer : kscience/kmath/structures/Buffer { - public static final field Companion Lkscience/kmath/structures/MemoryBuffer$Companion; - public fun (Lkscience/kmath/memory/Memory;Lkscience/kmath/memory/MemorySpec;)V - public fun contentEquals (Lkscience/kmath/structures/Buffer;)Z - public fun get (I)Ljava/lang/Object; - protected final fun getMemory ()Lkscience/kmath/memory/Memory; - public fun getSize ()I - protected final fun getSpec ()Lkscience/kmath/memory/MemorySpec; - public fun iterator ()Ljava/util/Iterator; -} - -public final class kscience/kmath/structures/MemoryBuffer$Companion { - public final fun create (Lkscience/kmath/memory/MemorySpec;I)Lkscience/kmath/structures/MemoryBuffer; - public final fun create (Lkscience/kmath/memory/MemorySpec;ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/MemoryBuffer; -} - -public abstract interface class kscience/kmath/structures/MutableBuffer : kscience/kmath/structures/Buffer { - public static final field Companion Lkscience/kmath/structures/MutableBuffer$Companion; - public abstract fun copy ()Lkscience/kmath/structures/MutableBuffer; - public abstract fun set (ILjava/lang/Object;)V -} - -public final class kscience/kmath/structures/MutableBuffer$Companion { - public final fun auto (Lkotlin/reflect/KClass;ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/MutableBuffer; - public final fun boxing (ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/MutableBuffer; - public final fun real-4n5bU9U (ILkotlin/jvm/functions/Function1;)[D -} - -public final class kscience/kmath/structures/MutableBuffer$DefaultImpls { - public static fun contentEquals (Lkscience/kmath/structures/MutableBuffer;Lkscience/kmath/structures/Buffer;)Z -} - -public final class kscience/kmath/structures/MutableListBuffer : kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl (Ljava/util/List;)Lkscience/kmath/structures/MutableListBuffer; - public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; - public fun contentEquals (Lkscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl (Ljava/util/List;Lkscience/kmath/structures/Buffer;)Z - public fun copy ()Lkscience/kmath/structures/MutableBuffer; - public static fun copy-impl (Ljava/util/List;)Lkscience/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 kscience/kmath/structures/MutableMemoryBuffer : kscience/kmath/structures/MemoryBuffer, kscience/kmath/structures/MutableBuffer { - public static final field Companion Lkscience/kmath/structures/MutableMemoryBuffer$Companion; - public fun (Lkscience/kmath/memory/Memory;Lkscience/kmath/memory/MemorySpec;)V - public fun copy ()Lkscience/kmath/structures/MutableBuffer; - public fun set (ILjava/lang/Object;)V -} - -public final class kscience/kmath/structures/MutableMemoryBuffer$Companion { - public final fun create (Lkscience/kmath/memory/MemorySpec;I)Lkscience/kmath/structures/MutableMemoryBuffer; - public final fun create (Lkscience/kmath/memory/MemorySpec;ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/MutableMemoryBuffer; -} - -public final class kscience/kmath/structures/ReadOnlyBuffer : kscience/kmath/structures/Buffer { - public static final synthetic fun box-impl (Lkscience/kmath/structures/MutableBuffer;)Lkscience/kmath/structures/ReadOnlyBuffer; - public static fun constructor-impl (Lkscience/kmath/structures/MutableBuffer;)Lkscience/kmath/structures/MutableBuffer; - public fun contentEquals (Lkscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl (Lkscience/kmath/structures/MutableBuffer;Lkscience/kmath/structures/Buffer;)Z - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Lkscience/kmath/structures/MutableBuffer;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Lkscience/kmath/structures/MutableBuffer;Lkscience/kmath/structures/MutableBuffer;)Z - public fun get (I)Ljava/lang/Object; - public static fun get-impl (Lkscience/kmath/structures/MutableBuffer;I)Ljava/lang/Object; - public final fun getBuffer ()Lkscience/kmath/structures/MutableBuffer; - public fun getSize ()I - public static fun getSize-impl (Lkscience/kmath/structures/MutableBuffer;)I - public fun hashCode ()I - public static fun hashCode-impl (Lkscience/kmath/structures/MutableBuffer;)I - public fun iterator ()Ljava/util/Iterator; - public static fun iterator-impl (Lkscience/kmath/structures/MutableBuffer;)Ljava/util/Iterator; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Lkscience/kmath/structures/MutableBuffer;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Lkscience/kmath/structures/MutableBuffer; -} - -public final class kscience/kmath/structures/RealBuffer : kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl ([D)Lkscience/kmath/structures/RealBuffer; +public final class space/kscience/kmath/structures/DoubleBuffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl ([D)Lspace/kscience/kmath/structures/DoubleBuffer; public static fun constructor-impl ([D)[D - public fun contentEquals (Lkscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl ([DLkscience/kmath/structures/Buffer;)Z - public synthetic fun copy ()Lkscience/kmath/structures/MutableBuffer; - public fun copy-H8_hoUg ()[D - public static fun copy-H8_hoUg ([D)[D + public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun copy-Dv3HvWU ()[D + public static fun copy-Dv3HvWU ([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 @@ -2794,180 +2126,399 @@ public final class kscience/kmath/structures/RealBuffer : kscience/kmath/structu public final synthetic fun unbox-impl ()[D } -public final class kscience/kmath/structures/RealBufferField : kscience/kmath/operations/ExtendedField { +public final class space/kscience/kmath/structures/DoubleBufferField : space/kscience/kmath/operations/ExtendedField { public fun (I)V public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acos-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun acos-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun acosh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add-4n5bU9U (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)[D + public fun add-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asin-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun asin-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun asinh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun atan-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun atanh-Udx-57Q (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;Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun cos-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D - public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun div (Ljava/lang/Number;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + public fun cosh-Udx-57Q (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 (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public fun div (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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-4n5bU9U (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)[D + public fun divide-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun exp-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun exp-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun getOne ()Ljava/lang/Object; - public fun getOne ()Lkscience/kmath/structures/Buffer; + public fun getOne ()Lspace/kscience/kmath/structures/Buffer; public final fun getSize ()I public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lkscience/kmath/structures/Buffer; + 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;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun ln-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)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/Object;)Ljava/lang/Object; - public fun multiply-4n5bU9U (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)[D - public fun multiply-4n5bU9U (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)[D + public fun multiply-CZ9oacQ (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;)Lkscience/kmath/structures/Buffer; + 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 (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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 (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; + 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-4n5bU9U (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)[D + public fun power-CZ9oacQ (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;Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; + 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 scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;D)[D public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sin-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun sin-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun sinh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/structures/Buffer; + 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-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun tan-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun tanh-Udx-57Q (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;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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 (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public fun times (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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 (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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 (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + public fun unaryPlus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; } -public final class kscience/kmath/structures/RealBufferFieldOperations : kscience/kmath/operations/ExtendedFieldOperations { - public static final field INSTANCE Lkscience/kmath/structures/RealBufferFieldOperations; +public final class space/kscience/kmath/structures/DoubleBufferFieldOperations : space/kscience/kmath/operations/ExtendedFieldOperations { + public static final field INSTANCE Lspace/kscience/kmath/structures/DoubleBufferFieldOperations; public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acos-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun acos-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun acosh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add-4n5bU9U (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)[D + public fun add-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asin-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun asin-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun asinh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun atan-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun atanh-Udx-57Q (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;Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun cos-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun cosh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun div (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public fun div (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/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-4n5bU9U (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)[D + public fun divide-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun exp-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun exp-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun ln-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun ln-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)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/Object;)Ljava/lang/Object; - public fun multiply-4n5bU9U (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)[D - public fun multiply-4n5bU9U (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)[D + public fun multiply-CZ9oacQ (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 (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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 (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; + 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-4n5bU9U (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)[D + public fun power-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sin-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun sin-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun sinh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/structures/Buffer; + 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-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D + public fun tan-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh-JVEF3vg (Lkscience/kmath/structures/Buffer;)[D - public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun tanh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Lkscience/kmath/structures/Buffer;Ljava/lang/Number;)Lkscience/kmath/structures/Buffer; - public fun times (Lkscience/kmath/structures/Buffer;Lkscience/kmath/structures/Buffer;)Lkscience/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 (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + public fun unaryMinus-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperation (Ljava/lang/String;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + 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 (Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer; + public fun unaryPlus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; } -public final class kscience/kmath/structures/RealBufferKt { - public static final fun RealBuffer (ILkotlin/jvm/functions/Function1;)[D - public static final fun RealBuffer ([D)[D +public final class space/kscience/kmath/structures/DoubleBufferKt { + public static final fun DoubleBuffer (ILkotlin/jvm/functions/Function1;)[D + public static final fun DoubleBuffer ([D)[D public static final fun asBuffer ([D)[D - public static final fun contentEquals-KRld2r8 ([D[D)Z - public static final fun getArray (Lkscience/kmath/structures/MutableBuffer;)[D + public static final fun contentEquals-2c9zdjM ([D[D)Z + public static final fun toDoubleArray (Lspace/kscience/kmath/structures/Buffer;)[D } -public final class kscience/kmath/structures/ShortBuffer : kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl ([S)Lkscience/kmath/structures/ShortBuffer; +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/FlaggedBufferKt { + public static final fun forEachValid (Lspace/kscience/kmath/structures/FlaggedDoubleBuffer;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/FlaggedDoubleBuffer : space/kscience/kmath/structures/Buffer, space/kscience/kmath/structures/FlaggedBuffer { + public fun ([D[B)V + 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 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 toFloatArray (Lspace/kscience/kmath/structures/Buffer;)[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 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 toIntArray (Lspace/kscience/kmath/structures/Buffer;)[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 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 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 toLongArray (Lspace/kscience/kmath/structures/Buffer;)[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 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 double-CZ9oacQ (ILkotlin/jvm/functions/Function1;)[D + public final fun float-YxruXGw (ILkotlin/jvm/functions/Function1;)[F + public final fun int-Ye6GY2U (ILkotlin/jvm/functions/Function1;)[I + public final fun long-BuQOeTY (ILkotlin/jvm/functions/Function1;)[J + public final fun short-1yRgbGw (ILkotlin/jvm/functions/Function1;)[S +} + +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 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 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/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 (Lkscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl ([SLkscience/kmath/structures/Buffer;)Z - public fun copy ()Lkscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([S)Lkscience/kmath/structures/MutableBuffer; + 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 @@ -2990,26 +2541,25 @@ public final class kscience/kmath/structures/ShortBuffer : kscience/kmath/struct public final synthetic fun unbox-impl ()[S } -public final class kscience/kmath/structures/ShortBufferKt { +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 (Lkscience/kmath/structures/MutableBuffer;)[S + public static final fun toShortArray (Lspace/kscience/kmath/structures/Buffer;)[S } -public final class kscience/kmath/structures/ValueFlag : java/lang/Enum { - public static final field MISSING Lkscience/kmath/structures/ValueFlag; - public static final field NAN Lkscience/kmath/structures/ValueFlag; - public static final field NEGATIVE_INFINITY Lkscience/kmath/structures/ValueFlag; - public static final field POSITIVE_INFINITY Lkscience/kmath/structures/ValueFlag; +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;)Lkscience/kmath/structures/ValueFlag; - public static fun values ()[Lkscience/kmath/structures/ValueFlag; + public static fun valueOf (Ljava/lang/String;)Lspace/kscience/kmath/structures/ValueFlag; + public static fun values ()[Lspace/kscience/kmath/structures/ValueFlag; } -public final class kscience/kmath/structures/VirtualBuffer : kscience/kmath/structures/Buffer { +public final class space/kscience/kmath/structures/VirtualBuffer : space/kscience/kmath/structures/Buffer { public fun (ILkotlin/jvm/functions/Function1;)V - public fun contentEquals (Lkscience/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 cfb996894..2fed3eb2f 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -1,8 +1,8 @@ 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 { @@ -23,13 +23,13 @@ readme { description = """ Algebraic structures like rings, spaces and fields. """.trimIndent(), - ref = "src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt" ) feature( id = "nd", description = "Many-dimensional structures and operations on them.", - ref = "src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/structures/StructureND.kt" ) feature( @@ -37,13 +37,13 @@ readme { 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" + ref = "src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt" ) feature( id = "buffers", description = "One-dimensional structure", - ref = "src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/structures/Buffers.kt" ) feature( @@ -53,18 +53,18 @@ readme { 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" + ref = "src/commonMain/kotlin/space/kscience/kmath/expressions" ) feature( id = "domains", description = "Domains", - ref = "src/commonMain/kotlin/kscience/kmath/domains" + ref = "src/commonMain/kotlin/space/kscience/kmath/domains" ) feature( id = "autodif", description = "Automatic differentiation", - ref = "src/commonMain/kotlin/kscience/kmath/expressions/SimpleAutoDiff.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt" ) } diff --git a/kmath-core/docs/README-TEMPLATE.md b/kmath-core/docs/README-TEMPLATE.md index 83d1ebdce..41cfe1ccb 100644 --- a/kmath-core/docs/README-TEMPLATE.md +++ b/kmath-core/docs/README-TEMPLATE.md @@ -1,6 +1,6 @@ -# The Core Module (`kmath-core`) +# Module kmath-core -The core features of KMath: +The core interfaces of KMath. ${features} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/UnivariateDomain.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/UnivariateDomain.kt deleted file mode 100644 index bf090f2e5..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/UnivariateDomain.kt +++ /dev/null @@ -1,49 +0,0 @@ -package kscience.kmath.domains - -import kscience.kmath.linear.Point -import kscience.kmath.structures.asBuffer - -public inline class UnivariateDomain(public val range: ClosedFloatingPointRange) : RealDomain { - public override val dimension: Int - get() = 1 - - public operator fun contains(d: Double): Boolean = range.contains(d) - - public override operator fun contains(point: Point): Boolean { - require(point.size == 0) - return contains(point[0]) - } - - public override fun nearestInDomain(point: Point): Point { - require(point.size == 1) - val value = point[0] - - return when { - value in range -> point - value >= range.endInclusive -> doubleArrayOf(range.endInclusive).asBuffer() - else -> doubleArrayOf(range.start).asBuffer() - } - } - - public override fun getLowerBound(num: Int, point: Point): Double? { - require(num == 0) - return range.start - } - - public override fun getUpperBound(num: Int, point: Point): Double? { - require(num == 0) - return range.endInclusive - } - - public override fun getLowerBound(num: Int): Double? { - require(num == 0) - return range.start - } - - public override fun getUpperBound(num: Int): Double? { - require(num == 0) - return range.endInclusive - } - - public override fun volume(): Double = range.endInclusive - range.start -} 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 6a66e91c8..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/BufferMatrix.kt +++ /dev/null @@ -1,136 +0,0 @@ -package kscience.kmath.linear - -import kscience.kmath.nd.NDStructure -import kscience.kmath.nd.Structure2D -import kscience.kmath.operations.Ring -import kscience.kmath.operations.invoke -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.BufferFactory -import 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/kscience/kmath/linear/LinearAlgebra.kt deleted file mode 100644 index d9201d0f1..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/LinearAlgebra.kt +++ /dev/null @@ -1,26 +0,0 @@ -package kscience.kmath.linear - -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.VirtualBuffer - -public typealias Point = Buffer - -/** - * A group of methods to resolve equation A dot X = B, where A and B are matrices or vectors - */ -public interface LinearSolver { - public fun solve(a: Matrix, b: Matrix): Matrix - public fun solve(a: Matrix, b: Point): Point = solve(a, b.asMatrix()).asPoint() - public fun inverse(a: Matrix): Matrix -} - -/** - * Convert matrix to vector if it is possible - */ -public fun Matrix.asPoint(): Point = - if (this.colNum == 1) - VirtualBuffer(rowNum) { get(it, 0) } - else - error("Can't convert matrix with more than one column to vector") - -public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(size, 1) { i, _ -> get(i) } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixBuilder.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixBuilder.kt deleted file mode 100644 index cb01939cc..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixBuilder.kt +++ /dev/null @@ -1,46 +0,0 @@ -package kscience.kmath.linear - -import kscience.kmath.nd.Structure2D -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.BufferFactory -import kscience.kmath.structures.asBuffer - -public class MatrixBuilder(public val rows: Int, public val columns: Int) { - public operator fun invoke(vararg elements: T): Matrix { - require(rows * columns == elements.size) { "The number of elements ${elements.size} is not equal $rows * $columns" } - val buffer = elements.asBuffer() - return BufferMatrix(rows, columns, buffer) - } - - //TODO add specific matrix builder functions like diagonal, etc -} - -public fun Structure2D.Companion.build(rows: Int, columns: Int): MatrixBuilder = MatrixBuilder(rows, columns) - -public fun Structure2D.Companion.row(vararg values: T): Matrix { - val buffer = values.asBuffer() - return BufferMatrix(1, values.size, buffer) -} - -public inline fun Structure2D.Companion.row( - size: Int, - factory: BufferFactory = Buffer.Companion::auto, - noinline builder: (Int) -> T, -): Matrix { - val buffer = factory(size, builder) - return BufferMatrix(1, size, buffer) -} - -public fun Structure2D.Companion.column(vararg values: T): Matrix { - val buffer = values.asBuffer() - return BufferMatrix(values.size, 1, buffer) -} - -public inline fun Structure2D.Companion.column( - size: Int, - factory: BufferFactory = Buffer.Companion::auto, - 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/kscience/kmath/linear/MatrixContext.kt deleted file mode 100644 index 234435b29..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/MatrixContext.kt +++ /dev/null @@ -1,147 +0,0 @@ -package 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.asSequence - -/** - * 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 - */ - 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) - */ - public fun point(size: Int, initializer: (Int) -> T): Point = Buffer.boxing(size, initializer) - - @Suppress("UNCHECKED_CAST") - public override fun binaryOperationFunction(operation: String): (left: Matrix, right: Matrix) -> M = - when (operation) { - "dot" -> { left, right -> left dot right } - else -> super.binaryOperationFunction(operation) as (Matrix, Matrix) -> M - } - - /** - * Computes the dot product of this matrix and another one. - * - * @receiver the multiplicand. - * @param other the multiplier. - * @return the dot product. - */ - public infix fun Matrix.dot(other: Matrix): M - - /** - * Computes the dot product of this matrix and a vector. - * - * @receiver the multiplicand. - * @param vector the multiplier. - * @return the dot product. - */ - public infix fun Matrix.dot(vector: Point): Point - - /** - * Multiplies a matrix by its element. - * - * @receiver the multiplicand. - * @param value the multiplier. - * @receiver the product. - */ - public operator fun Matrix.times(value: T): M - - /** - * Multiplies an element by a matrix of it. - * - * @receiver the multiplicand. - * @param value the multiplier. - * @receiver the product. - */ - public operator fun T.times(m: Matrix): M = m * this - - public companion object { - - /** - * A structured matrix with custom buffer - */ - public fun > buffered( - ring: R, - bufferFactory: BufferFactory = Buffer.Companion::boxing, - ): GenericMatrixContext> = BufferMatrixContext(ring, bufferFactory) - - /** - * Automatic buffered matrix, unboxed if it is possible - */ - public inline fun > auto(ring: R): GenericMatrixContext> = - buffered(ring, Buffer.Companion::auto) - } -} - -/** - * 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 over matrix elements. - */ - public val elementContext: R - - public override infix fun Matrix.dot(other: Matrix): M { - //TODO add typed error - require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } - - return produce(rowNum, other.colNum) { i, j -> - val row = rows[i] - val column = other.columns[j] - elementContext { sum(row.asSequence().zip(column.asSequence(), ::multiply)) } - } - } - - public override infix fun Matrix.dot(vector: Point): Point { - //TODO add typed error - require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } - - return point(rowNum) { i -> - val row = rows[i] - elementContext { sum(row.asSequence().zip(vector.asSequence(), ::multiply)) } - } - } - - public override operator fun Matrix.unaryMinus(): M = - produce(rowNum, colNum) { i, j -> elementContext { -get(i, j) } } - - public override fun add(a: Matrix, b: Matrix): M { - require(a.rowNum == b.rowNum && a.colNum == b.colNum) { - "Matrix operation dimension mismatch. [${a.rowNum},${a.colNum}] + [${b.rowNum},${b.colNum}]" - } - - return produce(a.rowNum, a.colNum) { i, j -> elementContext { a[i, j] + b[i, j] } } - } - - public override operator fun Matrix.minus(b: Matrix): M { - require(rowNum == b.rowNum && colNum == b.colNum) { - "Matrix operation dimension mismatch. [$rowNum,$colNum] - [${b.rowNum},${b.colNum}]" - } - - return produce(rowNum, colNum) { i, j -> elementContext { get(i, j) + b[i, j] } } - } - - public override fun multiply(a: Matrix, k: Number): M = - produce(a.rowNum, a.colNum) { i, j -> elementContext { a[i, j] * k } } - - public override operator fun Matrix.times(value: T): M = - produce(rowNum, colNum) { i, j -> elementContext { get(i, j) * value } } -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/RealMatrixContext.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/RealMatrixContext.kt deleted file mode 100644 index da795f56b..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/RealMatrixContext.kt +++ /dev/null @@ -1,75 +0,0 @@ -package kscience.kmath.linear - -import kscience.kmath.structures.RealBuffer - -public object RealMatrixContext : MatrixContext> { - - public override fun produce( - rows: Int, - columns: Int, - initializer: (i: Int, j: Int) -> Double, - ): BufferMatrix { - val buffer = RealBuffer(rows * columns) { offset -> initializer(offset / columns, offset % columns) } - return BufferMatrix(rows, columns, buffer) - } - - public 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 produce(rowNum, other.colNum) { i, j -> - var res = 0.0 - 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 RealBuffer(rowNum) { i -> - var res = 0.0 - 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 produce(a.rowNum, a.colNum) { i, j -> - aBufferMatrix[i, j] + bBufferMatrix[i, j] - } - } - - 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 { - val aBufferMatrix = a.toBufferMatrix() - return produce(a.rowNum, a.colNum) { i, j -> aBufferMatrix[i, j] * k.toDouble() } - } -} - - -/** - * Partially optimized real-valued matrix - */ -public val MatrixContext.Companion.real: RealMatrixContext get() = RealMatrixContext diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VectorSpace.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VectorSpace.kt deleted file mode 100644 index 2a3b8f5d1..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VectorSpace.kt +++ /dev/null @@ -1,70 +0,0 @@ -package 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 - -/** - * A linear space for vectors. - * Could be used on any point-like structure - */ -public interface VectorSpace> : Space> { - public val size: Int - public val space: S - override val zero: Point get() = produce { space.zero } - - public fun produce(initializer: S.(Int) -> T): Point - - /** - * Produce a space-element of this vector space for expressions - */ - //fun produceElement(initializer: (Int) -> T): Vector - - override fun add(a: Point, b: Point): Point = produce { space { a[it] + b[it] } } - - override fun multiply(a: Point, k: Number): Point = produce { space { a[it] * k } } - - //TODO add basis - - public companion object { - private val realSpaceCache: MutableMap> = hashMapOf() - - /** - * Non-boxing double vector space - */ - public fun real(size: Int): BufferVectorSpace = realSpaceCache.getOrPut(size) { - BufferVectorSpace( - size, - RealField, - Buffer.Companion::auto - ) - } - - /** - * A structured vector space with custom buffer - */ - public fun > buffered( - size: Int, - space: S, - bufferFactory: BufferFactory = Buffer.Companion::boxing, - ): BufferVectorSpace = BufferVectorSpace(size, space, bufferFactory) - - /** - * Automatic buffered vector, unboxed if it is possible - */ - public inline fun > auto(size: Int, space: S): VectorSpace = - buffered(size, space, Buffer.Companion::auto) - } -} - - -public class BufferVectorSpace>( - override val size: Int, - override val space: S, - public val bufferFactory: BufferFactory, -) : VectorSpace { - override fun produce(initializer: S.(Int) -> T): Buffer = bufferFactory(size) { space.initializer(it) } - //override fun produceElement(initializer: (Int) -> T): Vector = BufferVector(this, produce(initializer)) -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VirtualMatrix.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VirtualMatrix.kt deleted file mode 100644 index c96e55be6..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/linear/VirtualMatrix.kt +++ /dev/null @@ -1,36 +0,0 @@ -package 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, - public val generator: (i: Int, j: Int) -> T -) : Matrix { - - override val shape: IntArray get() = intArrayOf(rowNum, colNum) - - override operator fun get(i: Int, j: Int): T = generator(i, j) - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is Matrix<*>) return false - - if (rowNum != other.rowNum) return false - if (colNum != other.colNum) return false - - return elements().all { (index, value) -> value == other[index] } - } - - override fun hashCode(): Int { - var result = rowNum - result = 31 * result + colNum - result = 31 * result + generator.hashCode() - return result - } - - -} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/BufferNDAlgebra.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/BufferNDAlgebra.kt deleted file mode 100644 index 2d72162a6..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/BufferNDAlgebra.kt +++ /dev/null @@ -1,134 +0,0 @@ -package kscience.kmath.nd - -import kscience.kmath.nd.* -import kscience.kmath.operations.* -import kscience.kmath.structures.Buffer -import 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/kscience/kmath/nd/RealNDField.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/RealNDField.kt deleted file mode 100644 index 8e0f9e171..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/RealNDField.kt +++ /dev/null @@ -1,107 +0,0 @@ -package kscience.kmath.nd - -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.ExtendedField -import kscience.kmath.operations.RealField -import kscience.kmath.operations.RingWithNumbers -import kscience.kmath.structures.Buffer -import 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/kscience/kmath/nd/ShortNDRing.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/ShortNDRing.kt deleted file mode 100644 index 7ffe688cb..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/ShortNDRing.kt +++ /dev/null @@ -1,36 +0,0 @@ -package kscience.kmath.nd - -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.RingWithNumbers -import kscience.kmath.operations.ShortRing -import kscience.kmath.structures.Buffer -import 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/RealBuffer.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBuffer.kt deleted file mode 100644 index 769c445d6..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBuffer.kt +++ /dev/null @@ -1,54 +0,0 @@ -package kscience.kmath.structures - -/** - * Specialized [MutableBuffer] implementation over [DoubleArray]. - * - * @property array the underlying array. - */ -@Suppress("OVERRIDE_BY_INLINE") -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 inline operator fun set(index: Int, value: Double) { - array[index] = value - } - - override operator fun iterator(): DoubleIterator = array.iterator() - - override fun copy(): RealBuffer = RealBuffer(array.copyOf()) -} - -/** - * Creates a new [RealBuffer] 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 buffer element given its index. - */ -public inline fun RealBuffer(size: Int, init: (Int) -> Double): RealBuffer = RealBuffer(DoubleArray(size) { init(it) }) - -/** - * Returns a new [RealBuffer] of given elements. - */ -public fun RealBuffer(vararg doubles: Double): RealBuffer = RealBuffer(doubles) - -/** - * Simplified [RealBuffer] to array comparison - */ -public fun RealBuffer.contentEquals(vararg doubles: Double): Boolean = array.contentEquals(doubles) - -/** - * Returns a [DoubleArray] containing all of the elements of this [MutableBuffer]. - */ -public val MutableBuffer.array: DoubleArray - get() = (if (this is RealBuffer) array else DoubleArray(size) { get(it) }) - -/** - * Returns [RealBuffer] over this array. - * - * @receiver the array. - * @return the new buffer. - */ -public fun DoubleArray.asBuffer(): RealBuffer = RealBuffer(this) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBufferField.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBufferField.kt deleted file mode 100644 index 3f4d15c4d..000000000 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/RealBufferField.kt +++ /dev/null @@ -1,249 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.operations.ExtendedField -import kscience.kmath.operations.ExtendedFieldOperations -import kotlin.math.* - -/** - * [ExtendedFieldOperations] over [RealBuffer]. - */ -public object RealBufferFieldOperations : ExtendedFieldOperations> { - public override fun add(a: Buffer, b: Buffer): RealBuffer { - require(b.size == a.size) { - "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " - } - - return if (a is RealBuffer && b is RealBuffer) { - val aArray = a.array - val bArray = b.array - RealBuffer(DoubleArray(a.size) { aArray[it] + bArray[it] }) - } else RealBuffer(DoubleArray(a.size) { a[it] + b[it] }) - } - - public override fun multiply(a: Buffer, k: Number): RealBuffer { - val kValue = k.toDouble() - - return if (a is RealBuffer) { - val aArray = a.array - RealBuffer(DoubleArray(a.size) { aArray[it] * kValue }) - } else RealBuffer(DoubleArray(a.size) { a[it] * kValue }) - } - - public override fun multiply(a: Buffer, b: Buffer): RealBuffer { - require(b.size == a.size) { - "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " - } - - return if (a is RealBuffer && b is RealBuffer) { - val aArray = a.array - val bArray = b.array - RealBuffer(DoubleArray(a.size) { aArray[it] * bArray[it] }) - } else - RealBuffer(DoubleArray(a.size) { a[it] * b[it] }) - } - - public override fun divide(a: Buffer, b: Buffer): RealBuffer { - require(b.size == a.size) { - "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " - } - - return if (a is RealBuffer && b is RealBuffer) { - val aArray = a.array - val bArray = b.array - RealBuffer(DoubleArray(a.size) { aArray[it] / bArray[it] }) - } else RealBuffer(DoubleArray(a.size) { a[it] / b[it] }) - } - - public override fun sin(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { sin(array[it]) }) - } else RealBuffer(DoubleArray(arg.size) { sin(arg[it]) }) - - public override fun cos(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { cos(array[it]) }) - } else RealBuffer(DoubleArray(arg.size) { cos(arg[it]) }) - - public override fun tan(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { tan(array[it]) }) - } else RealBuffer(DoubleArray(arg.size) { tan(arg[it]) }) - - public override fun asin(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { asin(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { asin(arg[it]) }) - - public override fun acos(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { acos(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { acos(arg[it]) }) - - public override fun atan(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { atan(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { atan(arg[it]) }) - - public override fun sinh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { sinh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { sinh(arg[it]) }) - - public override fun cosh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { cosh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { cosh(arg[it]) }) - - public override fun tanh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { tanh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { tanh(arg[it]) }) - - public override fun asinh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { asinh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { asinh(arg[it]) }) - - public override fun acosh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { acosh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { acosh(arg[it]) }) - - public override fun atanh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { atanh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { atanh(arg[it]) }) - - public override fun power(arg: Buffer, pow: Number): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { array[it].pow(pow.toDouble()) }) - } else - RealBuffer(DoubleArray(arg.size) { arg[it].pow(pow.toDouble()) }) - - public override fun exp(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { exp(array[it]) }) - } else RealBuffer(DoubleArray(arg.size) { exp(arg[it]) }) - - public override fun ln(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { ln(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { ln(arg[it]) }) -} - -/** - * [ExtendedField] over [RealBuffer]. - * - * @property size the size of buffers to operate on. - */ -public class RealBufferField(public val size: Int) : ExtendedField> { - public override val zero: Buffer by lazy { RealBuffer(size) { 0.0 } } - public override val one: Buffer by lazy { RealBuffer(size) { 1.0 } } - - override fun number(value: Number): Buffer = RealBuffer(size) { value.toDouble() } - - public override fun add(a: Buffer, b: Buffer): RealBuffer { - require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return RealBufferFieldOperations.add(a, b) - } - - public override fun multiply(a: Buffer, k: Number): RealBuffer { - require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return RealBufferFieldOperations.multiply(a, k) - } - - public override fun multiply(a: Buffer, b: Buffer): RealBuffer { - require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return RealBufferFieldOperations.multiply(a, b) - } - - public override fun divide(a: Buffer, b: Buffer): RealBuffer { - require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return RealBufferFieldOperations.divide(a, b) - } - - public override fun sin(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.sin(arg) - } - - public override fun cos(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.cos(arg) - } - - public override fun tan(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.tan(arg) - } - - public override fun asin(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.asin(arg) - } - - public override fun acos(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.acos(arg) - } - - public override fun atan(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.atan(arg) - } - - public override fun sinh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.sinh(arg) - } - - public override fun cosh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.cosh(arg) - } - - public override fun tanh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.tanh(arg) - } - - public override fun asinh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.asinh(arg) - } - - public override fun acosh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.acosh(arg) - } - - public override fun atanh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.atanh(arg) - } - - public override fun power(arg: Buffer, pow: Number): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.power(arg, pow) - } - - public override fun exp(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.exp(arg) - } - - public override fun ln(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.ln(arg) - } -} diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/ColumnarData.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/ColumnarData.kt new file mode 100644 index 000000000..761255158 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/ColumnarData.kt @@ -0,0 +1,34 @@ +package space.kscience.kmath.data + +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.structures.Buffer + +/** + * A column-based data set with all columns of the same size (not necessary fixed in time). + * The column could be retrieved by a [get] operation. + */ +@UnstableKMathAPI +public interface ColumnarData { + public val size: Int + + public operator fun get(symbol: Symbol): Buffer +} + +/** + * A zero-copy method to represent a [Structure2D] as a two-column x-y data. + * There could more than two columns in the structure. + */ +@UnstableKMathAPI +public fun Structure2D.asColumnarData(mapping: Map): ColumnarData { + require(shape[1] >= mapping.maxOf { it.value }) { "Column index out of bounds" } + return object : ColumnarData { + override val size: Int get() = shape[0] + override fun get(symbol: Symbol): Buffer { + val index = mapping[symbol] ?: error("No column mapping for symbol $symbol") + return columns[index] + } + } +} + diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt new file mode 100644 index 000000000..15239bca1 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt @@ -0,0 +1,55 @@ +package space.kscience.kmath.data + +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.structures.Buffer +import kotlin.math.max + +/** + * The buffer of X values. + */ +@UnstableKMathAPI +public interface XYColumnarData : ColumnarData { + /** + * The buffer of X values + */ + public val x: Buffer + + /** + * The buffer of Y values. + */ + public val y: Buffer + + override fun get(symbol: Symbol): Buffer = when (symbol) { + Symbol.x -> x + Symbol.y -> y + else -> error("A column for symbol $symbol not found") + } +} + +@Suppress("FunctionName") +@UnstableKMathAPI +public fun XYColumnarData(x: Buffer, y: Buffer): XYColumnarData { + require(x.size == y.size) { "Buffer size mismatch. x buffer size is ${x.size}, y buffer size is ${y.size}" } + return object : XYColumnarData { + override val size: Int = x.size + override val x: Buffer = x + override val y: Buffer = y + } +} + + +/** + * A zero-copy method to represent a [Structure2D] as a two-column x-y data. + * There could more than two columns in the structure. + */ +@UnstableKMathAPI +public fun Structure2D.asXYData(xIndex: Int = 0, yIndex: Int = 1): XYColumnarData { + require(shape[1] >= max(xIndex, yIndex)) { "Column index out of bounds" } + return object : XYColumnarData { + override val size: Int get() = this@asXYData.shape[0] + override val x: Buffer get() = columns[xIndex] + override val y: Buffer get() = columns[yIndex] + } +} diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYZColumnarData.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYZColumnarData.kt new file mode 100644 index 000000000..f74c6e2d6 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYZColumnarData.kt @@ -0,0 +1,21 @@ +package space.kscience.kmath.data + +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.structures.Buffer + +/** + * A [XYColumnarData] with guaranteed [x], [y] and [z] columns designated by corresponding symbols. + * Inherits [XYColumnarData]. + */ +@UnstableKMathAPI +public interface XYZColumnarData : XYColumnarData { + public val z: Buffer + + override fun get(symbol: Symbol): Buffer = when (symbol) { + Symbol.x -> x + Symbol.y -> y + Symbol.z -> z + else -> error("A column for symbol $symbol not found") + } +} \ No newline at end of file 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/RealDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/DoubleDomain.kt similarity index 53% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/domains/RealDomain.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/DoubleDomain.kt index 369b093bb..154763159 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/domains/RealDomain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/DoubleDomain.kt @@ -13,47 +13,28 @@ * 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.misc.UnstableKMathAPI /** * n-dimensional volume * * @author Alexander Nozik */ -public interface RealDomain : Domain { - public fun nearestInDomain(point: Point): Point - - /** - * The lower edge for the domain going down from point - * @param num - * @param point - * @return - */ - public fun getLowerBound(num: Int, point: Point): Double? - - /** - * The upper edge of the domain going up from point - * @param num - * @param point - * @return - */ - public fun getUpperBound(num: Int, point: Point): Double? - +@UnstableKMathAPI +public interface DoubleDomain : Domain { /** * Global lower edge - * @param num - * @return + * @param num axis number */ - public fun getLowerBound(num: Int): Double? + public fun getLowerBound(num: Int): Double /** * Global upper edge - * @param num - * @return + * @param num axis number */ - public fun getUpperBound(num: Int): Double? + public fun getUpperBound(num: Int): Double /** * Hyper volume 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 56% 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..a15d04b4c 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.misc.UnstableKMathAPI +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.indices /** * @@ -25,32 +26,17 @@ import kscience.kmath.structures.indices * * @author Alexander Nozik */ -public class HyperSquareDomain(private val lower: RealBuffer, private val upper: RealBuffer) : RealDomain { +@UnstableKMathAPI +public class HyperSquareDomain(private val lower: Buffer, private val upper: Buffer) : DoubleDomain { 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): 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): Double? = upper[num] - - public override fun nearestInDomain(point: Point): Point { - val res = DoubleArray(point.size) { i -> - when { - point[i] < lower[i] -> lower[i] - point[i] > upper[i] -> upper[i] - else -> point[i] - } - } - - return RealBuffer(*res) - } + public override fun getUpperBound(num: Int): Double = upper[num] public override fun volume(): Double { var res = 1.0 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 59% 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..79f33fe05 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,22 +13,18 @@ * 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 +import space.kscience.kmath.misc.UnstableKMathAPI -public class UnconstrainedDomain(public override val dimension: Int) : RealDomain { +@UnstableKMathAPI +public class UnconstrainedDomain(public override val dimension: Int) : DoubleDomain { public override operator fun contains(point: Point): Boolean = true - public override fun getLowerBound(num: Int, point: Point): Double? = Double.NEGATIVE_INFINITY + public override fun getLowerBound(num: Int): Double = Double.NEGATIVE_INFINITY - public override fun getLowerBound(num: Int): Double? = Double.NEGATIVE_INFINITY - - public override fun getUpperBound(num: Int, point: Point): Double? = Double.POSITIVE_INFINITY - - public override fun getUpperBound(num: Int): Double? = Double.POSITIVE_INFINITY - - public override fun nearestInDomain(point: Point): Point = point + public override fun getUpperBound(num: Int): Double = Double.POSITIVE_INFINITY public override fun volume(): Double = Double.POSITIVE_INFINITY } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt new file mode 100644 index 000000000..6f737bd38 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt @@ -0,0 +1,28 @@ +package space.kscience.kmath.domains + +import space.kscience.kmath.linear.Point +import space.kscience.kmath.misc.UnstableKMathAPI + +@UnstableKMathAPI +public inline class UnivariateDomain(public val range: ClosedFloatingPointRange) : DoubleDomain { + public override val dimension: Int get() = 1 + + public operator fun contains(d: Double): Boolean = range.contains(d) + + public override operator fun contains(point: Point): Boolean { + require(point.size == 0) + return contains(point[0]) + } + + public override fun getLowerBound(num: Int): Double { + require(num == 0) + return range.start + } + + public override fun getUpperBound(num: Int): Double { + require(num == 0) + return range.endInclusive + } + + public override fun volume(): Double = range.endInclusive - range.start +} 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 91% 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..1f0ceaec3 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,7 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions + +import space.kscience.kmath.misc.StringSymbol +import space.kscience.kmath.misc.Symbol /** * Represents expression which structure can be differentiated. @@ -28,7 +31,7 @@ public fun > DifferentiableExpression.derivative(name /** * A [DifferentiableExpression] that defines only first derivatives */ -public abstract class FirstDerivativeExpression> : DifferentiableExpression { +public abstract class FirstDerivativeExpression> : DifferentiableExpression { /** * Returns first derivative of this expression by given [symbol]. */ 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 65% 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 19f4eeffd..7918f199e 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,26 +1,11 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.operations.Algebra +import space.kscience.kmath.misc.StringSymbol +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.operations.Algebra import kotlin.jvm.JvmName import kotlin.properties.ReadOnlyProperty -/** - * A marker interface for a symbol. A symbol mus have an identity - */ -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 -} - -/** - * A [Symbol] with a [String] identity - */ -public inline class StringSymbol(override val identity: String) : Symbol { - override fun toString(): String = identity -} - /** * An elementary function that could be invoked on a map of arguments. * @@ -73,12 +58,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 @@ -89,19 +74,12 @@ 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") - -/** - * A delegate to create a symbol with a string identity in this scope - */ -public val symbol: ReadOnlyProperty = ReadOnlyProperty { _, property -> - StringSymbol(property.name) -} +public fun ExpressionAlgebra.bindSymbol(symbol: Symbol): E = + bindSymbolOrNull(symbol) ?: error("Symbol $symbol could not be bound to $this") /** * 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 79% 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..ebd9e7f22 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,7 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.operations.* +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.operations.* /** * A context class for [Expression] construction. @@ -18,7 +19,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") } @@ -41,25 +42,28 @@ public abstract class FunctionalExpressionAlgebra>( } /** - * A context class for [Expression] construction for [Space] algebras. + * A context class for [Expression] construction for [Group] algebras. */ -public open class FunctionalExpressionSpace>( +public open class FunctionalExpressionGroup>( algebra: A, -) : FunctionalExpressionAlgebra(algebra), Space> { +) : FunctionalExpressionAlgebra(algebra), Group> { public override val zero: Expression get() = const(algebra.zero) + override fun Expression.unaryMinus(): Expression = + unaryOperation(GroupOperations.MINUS_OPERATION, this) + /** * Builds an Expression of addition of two another expressions. */ public override fun add(a: Expression, b: Expression): Expression = - binaryOperationFunction(SpaceOperations.PLUS_OPERATION)(a, b) + binaryOperation(GroupOperations.PLUS_OPERATION, a, b) - /** - * Builds an Expression of multiplication of expression by number. - */ - public override fun multiply(a: Expression, k: Number): Expression = Expression { arguments -> - algebra.multiply(a.invoke(arguments), k) - } +// /** +// * Builds an Expression of multiplication of expression by number. +// */ +// public override fun multiply(a: Expression, k: Number): Expression = Expression { arguments -> +// algebra.multiply(a.invoke(arguments), k) +// } public operator fun Expression.plus(arg: T): Expression = this + const(arg) public operator fun Expression.minus(arg: T): Expression = this - const(arg) @@ -71,13 +75,13 @@ public open class FunctionalExpressionSpace>( public override fun binaryOperationFunction(operation: String): (left: Expression, right: Expression) -> Expression = super.binaryOperationFunction(operation) + } public open class FunctionalExpressionRing>( algebra: A, -) : FunctionalExpressionSpace(algebra), Ring> { - public override val one: Expression - get() = const(algebra.one) +) : FunctionalExpressionGroup(algebra), Ring> { + public override val one: Expression get() = const(algebra.one) /** * Builds an Expression of multiplication of two expressions. @@ -89,15 +93,16 @@ public open class FunctionalExpressionRing>( public operator fun T.times(arg: Expression): Expression = arg * this public override fun unaryOperationFunction(operation: String): (arg: Expression) -> Expression = - super.unaryOperationFunction(operation) + super.unaryOperationFunction(operation) public override fun binaryOperationFunction(operation: String): (left: Expression, right: Expression) -> Expression = - super.binaryOperationFunction(operation) + super.binaryOperationFunction(operation) } public open class FunctionalExpressionField>( algebra: A, -) : FunctionalExpressionRing(algebra), Field> { +) : FunctionalExpressionRing(algebra), Field>, + ScaleOperations> { /** * Builds an Expression of division an expression by another one. */ @@ -112,6 +117,10 @@ public open class FunctionalExpressionField>( public override fun binaryOperationFunction(operation: String): (left: Expression, right: Expression) -> Expression = super.binaryOperationFunction(operation) + + override fun scale(a: Expression, value: Double): Expression = algebra { + Expression { args -> a(args) * value } + } } public open class FunctionalExpressionExtendedField>( @@ -151,8 +160,8 @@ public open class FunctionalExpressionExtendedField>( super.binaryOperationFunction(operation) } -public inline fun > A.expressionInSpace(block: FunctionalExpressionSpace.() -> Expression): Expression = - FunctionalExpressionSpace(this).block() +public inline fun > A.expressionInSpace(block: FunctionalExpressionGroup.() -> Expression): Expression = + FunctionalExpressionGroup(this).block() public inline fun > A.expressionInRing(block: FunctionalExpressionRing.() -> Expression): Expression = FunctionalExpressionRing(this).block() @@ -160,5 +169,6 @@ public inline fun > A.expressionInRing(block: FunctionalExpressio public inline fun > A.expressionInField(block: FunctionalExpressionField.() -> Expression): Expression = FunctionalExpressionField(this).block() -public inline fun > A.expressionInExtendedField(block: FunctionalExpressionExtendedField.() -> Expression): Expression = - FunctionalExpressionExtendedField(this).block() +public inline fun > A.expressionInExtendedField( + block: FunctionalExpressionExtendedField.() -> Expression, +): Expression = FunctionalExpressionExtendedField(this).block() 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 85% 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..d9be4a92e 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,10 @@ -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.Symbol +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 @@ -47,36 +48,6 @@ public fun DerivationResult.grad(vararg variables: Symbol): Point> F.simpleAutoDiff( - bindings: Map, - body: SimpleAutoDiffField.() -> AutoDiffValue, -): DerivationResult { - contract { callsInPlace(body, InvocationKind.EXACTLY_ONCE) } - - return SimpleAutoDiffField(this, bindings).differentiate(body) -} - -public fun > F.simpleAutoDiff( - vararg bindings: Pair, - body: SimpleAutoDiffField.() -> AutoDiffValue, -): DerivationResult = simpleAutoDiff(bindings.toMap(), body) - /** * Represents field in context of which functions can be derived. */ @@ -84,12 +55,9 @@ public fun > F.simpleAutoDiff( public open class SimpleAutoDiffField>( public val context: F, bindings: Map, -) : Field>, ExpressionAlgebra>, RingWithNumbers> { - public override val zero: AutoDiffValue - get() = const(context.zero) - - public override val one: AutoDiffValue - get() = const(context.one) +) : Field>, ExpressionAlgebra>, NumbersAddOperations> { + public override val zero: AutoDiffValue get() = const(context.zero) + public override val one: AutoDiffValue get() = const(context.one) // this stack contains pairs of blocks and values to apply them to private var stack: Array = arrayOfNulls(8) @@ -117,7 +85,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 @@ -137,6 +105,8 @@ public open class SimpleAutoDiffField>( override fun const(value: T): AutoDiffValue = AutoDiffValue(value) + override fun number(value: Number): AutoDiffValue = const { one * value } + /** * A variable accessing inner state of derivatives. * Use this value in inner builders to avoid creating additional derivative bindings. @@ -175,21 +145,24 @@ public open class SimpleAutoDiffField>( return DerivationResult(result.value, bindings.mapValues { it.value.d }, context) } - // Overloads for Double constants +// // Overloads for Double constants +// +// public override operator fun Number.plus(b: AutoDiffValue): AutoDiffValue = +// derive(const { this@plus.toDouble() * one + b.value }) { z -> +// b.d += z.d +// } +// +// public override operator fun AutoDiffValue.plus(b: Number): AutoDiffValue = b.plus(this) +// +// public override operator fun Number.minus(b: AutoDiffValue): AutoDiffValue = +// derive(const { this@minus.toDouble() * one - b.value }) { z -> b.d -= z.d } +// +// public override operator fun AutoDiffValue.minus(b: Number): AutoDiffValue = +// derive(const { this@minus.value - one * b.toDouble() }) { z -> d += z.d } - public override operator fun Number.plus(b: AutoDiffValue): AutoDiffValue = - derive(const { this@plus.toDouble() * one + b.value }) { z -> - b.d += z.d - } - - public override operator fun AutoDiffValue.plus(b: Number): AutoDiffValue = b.plus(this) - - public override operator fun Number.minus(b: AutoDiffValue): AutoDiffValue = - derive(const { this@minus.toDouble() * one - b.value }) { z -> b.d -= z.d } - - public override operator fun AutoDiffValue.minus(b: Number): AutoDiffValue = - derive(const { this@minus.value - one * b.toDouble() }) { z -> this@minus.d += z.d } + override fun AutoDiffValue.unaryMinus(): AutoDiffValue = + derive(const { -value }) { z -> d -= z.d } // Basic math (+, -, *, /) @@ -211,12 +184,44 @@ public open class SimpleAutoDiffField>( b.d -= z.d * a.value / (b.value * b.value) } - public override fun multiply(a: AutoDiffValue, k: Number): AutoDiffValue = - derive(const { k.toDouble() * a.value }) { z -> - a.d += z.d * k.toDouble() + public override fun scale(a: AutoDiffValue, value: Double): AutoDiffValue = + derive(const { value * a.value }) { z -> + a.d += z.d * value } } + +/** + * Runs differentiation and establishes [SimpleAutoDiffField] context inside the block of code. + * + * The partial derivatives are placed in argument `d` variable + * + * Example: + * ``` + * val x by symbol // define variable(s) and their values + * val y = DoubleField.withAutoDiff() { sqr(x) + 5 * x + 3 } // write formulate in deriv context + * assertEquals(17.0, y.x) // the value of result (y) + * assertEquals(9.0, x.d) // dy/dx + * ``` + * + * @param body the action in [SimpleAutoDiffField] context returning [AutoDiffVariable] to differentiate with respect to. + * @return the result of differentiation. + */ +public fun > F.simpleAutoDiff( + bindings: Map, + body: SimpleAutoDiffField.() -> AutoDiffValue, +): DerivationResult { + contract { callsInPlace(body, InvocationKind.EXACTLY_ONCE) } + + return SimpleAutoDiffField(this, bindings).differentiate(body) +} + +public fun > F.simpleAutoDiff( + vararg bindings: Pair, + body: SimpleAutoDiffField.() -> AutoDiffValue, +): DerivationResult = simpleAutoDiff(bindings.toMap(), body) + + /** * A constructs that creates a derivative structure with required order on-demand */ @@ -247,19 +252,20 @@ public fun > simpleAutoDiff(field: F): AutoDiffProcessor> SimpleAutoDiffField.sqr(x: AutoDiffValue): AutoDiffValue = - derive(const { x.value * x.value }) { z -> x.d += z.d * 2 * x.value } +public fun > SimpleAutoDiffField.sqr(x: AutoDiffValue): AutoDiffValue = + derive(const { x.value * x.value }) { z -> x.d += z.d * 2.0 * x.value } // x ^ 1/2 public fun > SimpleAutoDiffField.sqrt(x: AutoDiffValue): AutoDiffValue = - derive(const { sqrt(x.value) }) { z -> x.d += z.d * 0.5 / z.value } + derive(const { sqrt(x.value) }) { z -> x.d += z.d / 2.0 / z.value } // x ^ y (const) public fun > SimpleAutoDiffField.pow( x: AutoDiffValue, y: Double, -): AutoDiffValue = - derive(const { power(x.value, y) }) { z -> x.d += z.d * y * power(x.value, y - 1) } +): AutoDiffValue = derive(const { power(x.value, y) }) { z -> + x.d += z.d * y * power(x.value, y - 1) +} public fun > SimpleAutoDiffField.pow( x: AutoDiffValue, @@ -328,7 +334,13 @@ public fun > SimpleAutoDiffField.atanh(x: Au public class SimpleAutoDiffExtendedField>( context: F, bindings: Map, -) : ExtendedField>, SimpleAutoDiffField(context, bindings) { +) : ExtendedField>, ScaleOperations>, + SimpleAutoDiffField(context, bindings) { + + override fun number(value: Number): AutoDiffValue = const { number(value) } + + override fun scale(a: AutoDiffValue, value: Double): AutoDiffValue = a * number(value) + // x ^ 2 public fun sqr(x: AutoDiffValue): AutoDiffValue = (this as SimpleAutoDiffField).sqr(x) 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 84% 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 fd0661080..4db4b5828 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,13 +1,16 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.linear.Point -import kscience.kmath.nd.Structure2D -import kscience.kmath.structures.BufferFactory +import space.kscience.kmath.linear.Point +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.misc.UnstableKMathAPI +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 */ +@UnstableKMathAPI public interface SymbolIndexer { public val symbols: List public fun indexOf(symbol: Symbol): Int = symbols.indexOf(symbol) @@ -49,13 +52,16 @@ public interface SymbolIndexer { public fun Map.toDoubleArray(): DoubleArray = DoubleArray(symbols.size) { getValue(symbols[it]) } } +@UnstableKMathAPI public inline class SimpleSymbolIndexer(override val symbols: List) : SymbolIndexer /** * Execute the block with symbol indexer based on given symbol order */ +@UnstableKMathAPI public inline fun withSymbols(vararg symbols: Symbol, block: SymbolIndexer.() -> R): R = with(SimpleSymbolIndexer(symbols.toList()), block) +@UnstableKMathAPI public inline fun withSymbols(symbols: Collection, block: SymbolIndexer.() -> R): R = with(SimpleSymbolIndexer(symbols.toList()), block) \ No newline at end of file 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 71% 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..fbf080032 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,19 +1,19 @@ -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.Group +import space.kscience.kmath.operations.Ring import kotlin.contracts.InvocationKind import kotlin.contracts.contract /** - * Creates a functional expression with this [Space]. + * Creates a functional expression with this [Group]. */ -public inline fun Space.spaceExpression(block: FunctionalExpressionSpace>.() -> Expression): Expression { +public inline fun Group.spaceExpression(block: FunctionalExpressionGroup>.() -> Expression): Expression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return FunctionalExpressionSpace(this).block() + return FunctionalExpressionGroup(this).block() } /** diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt new file mode 100644 index 000000000..662cd6409 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt @@ -0,0 +1,83 @@ +package space.kscience.kmath.linear + +import space.kscience.kmath.nd.* +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.VirtualBuffer +import space.kscience.kmath.structures.indices + + +public class BufferedLinearSpace>( + override val elementAlgebra: A, + private val bufferFactory: BufferFactory, +) : LinearSpace { + + private fun ndRing( + rows: Int, + cols: Int, + ): BufferedRingND = AlgebraND.ring(elementAlgebra, bufferFactory, rows, cols) + + override fun buildMatrix(rows: Int, columns: Int, initializer: A.(i: Int, j: Int) -> T): Matrix = + ndRing(rows, columns).produce { (i, j) -> elementAlgebra.initializer(i, j) }.as2D() + + override fun buildVector(size: Int, initializer: A.(Int) -> T): Point = + bufferFactory(size) { elementAlgebra.initializer(it) } + + override fun Matrix.unaryMinus(): Matrix = ndRing(rowNum, colNum).run { + unwrap().map { -it }.as2D() + } + + override fun Matrix.plus(other: Matrix): Matrix = ndRing(rowNum, colNum).run { + require(shape.contentEquals(other.shape)) { "Shape mismatch on Matrix::plus. Expected $shape but found ${other.shape}" } + unwrap().plus(other.unwrap()).as2D() + } + + override fun Matrix.minus(other: Matrix): Matrix = ndRing(rowNum, colNum).run { + require(shape.contentEquals(other.shape)) { "Shape mismatch on Matrix::minus. Expected $shape but found ${other.shape}" } + unwrap().minus(other.unwrap()).as2D() + } + + private fun Buffer.linearize() = if (this is VirtualBuffer) { + buildVector(size) { get(it) } + } else { + this + } + + override fun Matrix.dot(other: Matrix): Matrix { + require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } + return elementAlgebra { + val rows = this@dot.rows.map { it.linearize() } + val columns = other.columns.map { it.linearize() } + buildMatrix(rowNum, other.colNum) { i, j -> + val r = rows[i] + val c = columns[j] + var res = zero + for (l in r.indices) { + res += r[l] * c[l] + } + res + } + } + } + + override fun Matrix.dot(vector: Point): Point { + require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } + return elementAlgebra { + val rows = this@dot.rows.map { it.linearize() } + buildVector(rowNum) { i -> + val r = rows[i] + var res = zero + for (j in r.indices) { + res += r[j] * vector[j] + } + res + } + } + } + + override fun Matrix.times(value: T): Matrix = ndRing(rowNum, colNum).run { + unwrap().map { it * value }.as2D() + } +} \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt new file mode 100644 index 000000000..3e2dbee3f --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt @@ -0,0 +1,44 @@ +package space.kscience.kmath.linear + +import space.kscience.kmath.nd.as1D + +/** + * A group of methods to solve for *X* in equation *X = A -1 · B*, where *A* and *B* are matrices or + * vectors. + * + * @param T the type of items. + */ +public interface LinearSolver { + /** + * Solve a dot x = b matrix equation and return x + */ + public fun solve(a: Matrix, b: Matrix): Matrix + + /** + * Solve a dot x = b vector equation and return b + */ + public fun solve(a: Matrix, b: Point): Point = solve(a, b.asMatrix()).asVector() + + /** + * Get inverse of a matrix + */ + public fun inverse(matrix: Matrix): Matrix +} + +/** + * Convert matrix to vector if it is possible. + */ +public fun Matrix.asVector(): Point = + if (this.colNum == 1) + as1D() + else + error("Can't convert matrix with more than one column to vector") + +/** + * Creates an n × 1 [VirtualMatrix], where n is the size of the given buffer. + * + * @param T the type of elements contained in the buffer. + * @receiver a buffer. + * @return the new matrix. + */ +public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(size, 1) { i, _ -> get(i) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt new file mode 100644 index 000000000..7522978ec --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt @@ -0,0 +1,204 @@ +package space.kscience.kmath.linear + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.DoubleBuffer +import kotlin.reflect.KClass + +/** + * Alias for [Structure2D] with more familiar name. + * + * @param T the type of items. + */ +public typealias Matrix = Structure2D + +/** + * Alias or using [Buffer] as a point/vector in a many-dimensional space. + * + * @param T the type of elements contained in the buffer. + */ +public typealias Point = Buffer + +/** + * Basic operations on matrices and vectors. Operates on [Matrix]. + * + * @param T the type of items in the matrices. + * @param M the type of operated matrices. + */ +public interface LinearSpace> { + public val elementAlgebra: A + + /** + * Produces a matrix with this context and given dimensions. + */ + public fun buildMatrix(rows: Int, columns: Int, initializer: A.(i: Int, j: Int) -> T): Matrix + + /** + * Produces a point compatible with matrix space (and possibly optimized for it). + */ + public fun buildVector(size: Int, initializer: A.(Int) -> T): Point + + public operator fun Matrix.unaryMinus(): Matrix = buildMatrix(rowNum, colNum) { i, j -> + -get(i, j) + } + + public operator fun Point.unaryMinus(): Point = buildVector(size) { + -get(it) + } + + /** + * Matrix sum + */ + public operator fun Matrix.plus(other: Matrix): Matrix = buildMatrix(rowNum, colNum) { i, j -> + get(i, j) + other[i, j] + } + + + /** + * Vector sum + */ + public operator fun Point.plus(other: Point): Point = buildVector(size) { + get(it) + other[it] + } + + /** + * Matrix subtraction + */ + public operator fun Matrix.minus(other: Matrix): Matrix = buildMatrix(rowNum, colNum) { i, j -> + get(i, j) - other[i, j] + } + + /** + * Vector subtraction + */ + public operator fun Point.minus(other: Point): Point = buildVector(size) { + get(it) - other[it] + } + + + /** + * Computes the dot product of this matrix and another one. + * + * @receiver the multiplicand. + * @param other the multiplier. + * @return the dot product. + */ + public infix fun Matrix.dot(other: Matrix): Matrix { + require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } + return elementAlgebra { + buildMatrix(rowNum, other.colNum) { i, j -> + var res = zero + for (l in 0 until colNum) { + res += this@dot[i, l] * other[l, j] + } + res + } + } + } + + /** + * Computes the dot product of this matrix and a vector. + * + * @receiver the multiplicand. + * @param vector the multiplier. + * @return the dot product. + */ + public infix fun Matrix.dot(vector: Point): Point { + require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } + return elementAlgebra { + buildVector(rowNum) { i -> + var res = one + for (j in 0 until colNum) { + res += this@dot[i, j] * vector[j] + } + res + } + } + } + + /** + * Multiplies a matrix by its element. + * + * @receiver the multiplicand. + * @param value the multiplier. + * @receiver the product. + */ + public operator fun Matrix.times(value: T): Matrix = + buildMatrix(rowNum, colNum) { i, j -> get(i, j) * value } + + /** + * Multiplies an element by a matrix of it. + * + * @receiver the multiplicand. + * @param m the multiplier. + * @receiver the product. + */ + public operator fun T.times(m: Matrix): Matrix = m * this + + /** + * Multiplies a vector by its element. + * + * @receiver the multiplicand. + * @param value the multiplier. + * @receiver the product. + */ + public operator fun Point.times(value: T): Point = + buildVector(size) { i -> get(i) * value } + + /** + * Multiplies an element by a vector of it. + * + * @receiver the multiplicand. + * @param v the multiplier. + * @receiver the product. + */ + public operator fun T.times(v: Point): Point = v * this + + /** + * Get a feature of the structure in this scope. Structure features take precedence other context features + * + * @param F the type of feature. + * @param structure the structure. + * @param type the [KClass] instance of [F]. + * @return a feature object or `null` if it isn't present. + */ + @UnstableKMathAPI + public fun getFeature(structure: Matrix, type: KClass): F? = structure.getFeature(type) + + public companion object { + + /** + * A structured matrix with custom buffer + */ + public fun > buffered( + algebra: A, + bufferFactory: BufferFactory = Buffer.Companion::boxing, + ): LinearSpace = BufferedLinearSpace(algebra, bufferFactory) + + public val real: LinearSpace = buffered(DoubleField, ::DoubleBuffer) + + /** + * Automatic buffered matrix, unboxed if it is possible + */ + public inline fun > auto(ring: A): LinearSpace = + buffered(ring, Buffer.Companion::auto) + } +} + +/** + * Get a feature of the structure in this scope. Structure features take precedence other context features + * + * @param T the type of items in the matrices. + * @param F the type of feature. + * @return a feature object or `null` if it isn't present. + */ +@UnstableKMathAPI +public inline fun LinearSpace.getFeature(structure: Matrix): F? = + getFeature(structure, F::class) + + +public operator fun , R> LS.invoke(block: LS.() -> R): R = run(block) + 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 79% 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 7c7422c94..7a6495638 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,15 +1,18 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.nd.getFeature -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.BufferAccessor2D +import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.MutableBufferFactory /** * Common implementation of [LupDecompositionFeature]. */ public class LupDecomposition( - public val context: MatrixContext>, + public val context: LinearSpace, public val elementContext: Field, public val lu: Matrix, public val pivot: IntArray, @@ -59,15 +62,14 @@ public class LupDecomposition( } @PublishedApi -internal fun , F : Field> GenericMatrixContext.abs(value: T): T = - if (value > elementContext.zero) value else elementContext { -value } +internal fun > LinearSpace>.abs(value: T): T = + if (value > elementAlgebra.zero) value else elementAlgebra { -value } /** * Create a lup decomposition of generic matrix. */ -public fun > MatrixContext>.lup( +public fun > LinearSpace>.lup( factory: MutableBufferFactory, - elementContext: Field, matrix: Matrix, checkSingular: (T) -> Boolean, ): LupDecomposition { @@ -77,7 +79,7 @@ public fun > MatrixContext>.lup( //TODO just waits for KEEP-176 BufferAccessor2D(matrix.rowNum, matrix.colNum, factory).run { - elementContext { + elementAlgebra { val lu = create(matrix) // Initialize permutation array and parity @@ -139,18 +141,18 @@ public fun > MatrixContext>.lup( for (row in col + 1 until m) lu[row, col] /= luDiag } - return LupDecomposition(this@lup, elementContext, lu.collect(), pivot, even) + return LupDecomposition(this@lup, elementAlgebra, lu.collect(), pivot, even) } } } -public inline fun , F : Field> GenericMatrixContext>.lup( +public inline fun > LinearSpace>.lup( matrix: Matrix, noinline checkSingular: (T) -> Boolean, -): LupDecomposition = lup(MutableBuffer.Companion::auto, elementContext, matrix, checkSingular) +): LupDecomposition = lup(MutableBuffer.Companion::auto, matrix, checkSingular) -public fun MatrixContext>.lup(matrix: Matrix): LupDecomposition = - lup(Buffer.Companion::real, RealField, matrix) { it < 1e-11 } +public fun LinearSpace.lup(matrix: Matrix): LupDecomposition = + lup(::DoubleBuffer, matrix) { it < 1e-11 } public fun LupDecomposition.solveWithLup( factory: MutableBufferFactory, @@ -195,7 +197,7 @@ public fun LupDecomposition.solveWithLup( } } - return context.produce(pivot.size, matrix.colNum) { i, j -> bp[i, j] } + return context.buildMatrix(pivot.size, matrix.colNum) { i, j -> bp[i, j] } } } } @@ -207,18 +209,18 @@ public inline fun LupDecomposition.solveWithLup(matrix: Mat * Solves a system of linear equations *ax = b** using LUP decomposition. */ @OptIn(UnstableKMathAPI::class) -public inline fun , F : Field> GenericMatrixContext>.solveWithLup( +public inline fun > LinearSpace>.solveWithLup( a: Matrix, b: Matrix, noinline bufferFactory: MutableBufferFactory = MutableBuffer.Companion::auto, noinline checkSingular: (T) -> Boolean, ): Matrix { // Use existing decomposition if it is provided by matrix - val decomposition = a.getFeature() ?: lup(bufferFactory, elementContext, a, checkSingular) + val decomposition = a.getFeature() ?: lup(bufferFactory, a, checkSingular) return decomposition.solveWithLup(bufferFactory, b) } -public inline fun , F : Field> GenericMatrixContext>.inverseWithLup( +public inline fun > LinearSpace>.inverseWithLup( matrix: Matrix, noinline bufferFactory: MutableBufferFactory = MutableBuffer.Companion::auto, noinline checkSingular: (T) -> Boolean, @@ -226,15 +228,15 @@ public inline fun , F : Field> GenericMatrixContext @OptIn(UnstableKMathAPI::class) -public fun RealMatrixContext.solveWithLup(a: Matrix, b: Matrix): Matrix { +public fun LinearSpace.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 } + val bufferFactory: MutableBufferFactory = ::DoubleBuffer + val decomposition: LupDecomposition = a.getFeature() ?: lup(bufferFactory, a) { it < 1e-11 } 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 = +public fun LinearSpace.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/space/kscience/kmath/linear/MatrixBuilder.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt new file mode 100644 index 000000000..b30d621fe --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt @@ -0,0 +1,43 @@ +package space.kscience.kmath.linear + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.Ring + +public class MatrixBuilder>( + public val linearSpace: LinearSpace, + public val rows: Int, + public val columns: Int, +) { + public operator fun invoke(vararg elements: T): Matrix { + require(rows * columns == elements.size) { "The number of elements ${elements.size} is not equal $rows * $columns" } + return linearSpace.buildMatrix(rows, columns) { i, j -> elements[i * columns + j] } + } + + //TODO add specific matrix builder functions like diagonal, etc +} + +/** + * Create a matrix builder with given number of rows and columns + */ +@UnstableKMathAPI +public fun > LinearSpace.matrix(rows: Int, columns: Int): MatrixBuilder = + MatrixBuilder(this, rows, columns) + +@UnstableKMathAPI +public fun LinearSpace>.vector(vararg elements: T): Point { + return buildVector(elements.size) { elements[it] } +} + +public inline fun LinearSpace>.row( + size: Int, + crossinline builder: (Int) -> T, +): Matrix = buildMatrix(1, size) { _, j -> builder(j) } + +public fun LinearSpace>.row(vararg values: T): Matrix = row(values.size, values::get) + +public inline fun LinearSpace>.column( + size: Int, + crossinline builder: (Int) -> T, +): Matrix = buildMatrix(size, 1) { i, _ -> builder(i) } + +public fun LinearSpace>.column(vararg values: T): Matrix = column(values.size, values::get) \ No newline at end of file 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 97% 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 196c46623..30e3daa7a 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,10 +1,12 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear + +import space.kscience.kmath.nd.StructureFeature /** * A marker interface representing some properties of matrices or additional transformations of them. Features are used * to optimize matrix operations performance in some cases or retrieve the APIs. */ -public interface MatrixFeature +public interface MatrixFeature: StructureFeature /** * Matrices with this feature are considered to have only diagonal non-null elements. 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 52% 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 df967e3c1..def3b87f7 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,20 +1,17 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.nd.Structure2D -import kscience.kmath.nd.getFeature -import kscience.kmath.operations.Ring -import kscience.kmath.structures.asBuffer -import kotlin.math.sqrt +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.StructureFeature +import space.kscience.kmath.nd.getFeature +import space.kscience.kmath.operations.Ring import kotlin.reflect.KClass -import kotlin.reflect.safeCast /** * A [Matrix] that holds [MatrixFeature] objects. * * @param T the type of items. */ -public class MatrixWrapper internal constructor( +public class MatrixWrapper internal constructor( public val origin: Matrix, public val features: Set, ) : Matrix by origin { @@ -23,11 +20,10 @@ public class MatrixWrapper internal constructor( * Get the first feature matching given class. Does not guarantee that matrix has only one feature matching the criteria */ @UnstableKMathAPI - override fun getFeature(type: KClass): T? = type.safeCast(features.find { type.isInstance(it) }) + @Suppress("UNCHECKED_CAST") + override fun getFeature(type: KClass): F? = features.singleOrNull { type.isInstance(it) } as? F ?: origin.getFeature(type) - override fun equals(other: Any?): Boolean = origin == other - override fun hashCode(): Int = origin.hashCode() override fun toString(): String { return "MatrixWrapper(matrix=$origin, features=$features)" } @@ -60,30 +56,26 @@ public operator fun Matrix.plus(newFeatures: Collection Structure2D.Companion.square(vararg elements: T): Matrix { - val size: Int = sqrt(elements.size.toDouble()).toInt() - require(size * size == elements.size) { "The number of elements ${elements.size} is not a full square" } - val buffer = elements.asBuffer() - return BufferMatrix(size, size, buffer) -} - /** * Diagonal matrix of ones. The matrix is virtual no actual matrix is created */ -public fun > GenericMatrixContext.one(rows: Int, columns: Int): Matrix = - VirtualMatrix(rows, columns) { i, j -> - if (i == j) elementContext.one else elementContext.zero - } + UnitFeature +public fun LinearSpace>.one( + rows: Int, + columns: Int, +): Matrix = VirtualMatrix(rows, columns) { i, j -> + if (i == j) elementAlgebra.one else elementAlgebra.zero +} + UnitFeature /** * A virtual matrix of zeroes */ -public fun > GenericMatrixContext.zero(rows: Int, columns: Int): Matrix = - VirtualMatrix(rows, columns) { _, _ -> elementContext.zero } + ZeroFeature +public fun LinearSpace>.zero( + rows: Int, + columns: Int, +): Matrix = VirtualMatrix(rows, columns) { _, _ -> + elementAlgebra.zero +} + ZeroFeature public class TransposedFeature(public val original: Matrix) : MatrixFeature @@ -91,9 +83,7 @@ public class TransposedFeature(public val original: Matrix) : Matrix * Create a virtual transposed matrix without copying anything. `A.transpose().transpose() === A` */ @OptIn(UnstableKMathAPI::class) -public fun Matrix.transpose(): Matrix { - return getFeature>()?.original ?: VirtualMatrix( - colNum, - rowNum, - ) { i, j -> get(j, i) } + TransposedFeature(this) -} \ No newline at end of file +public fun Matrix.transpose(): Matrix = getFeature>()?.original ?: VirtualMatrix( + colNum, + rowNum, +) { i, j -> get(j, i) } + TransposedFeature(this) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt new file mode 100644 index 000000000..e80ee5ebd --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt @@ -0,0 +1,17 @@ +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, + public val generator: (i: Int, j: Int) -> T, +) : Matrix { + + override val shape: IntArray get() = intArrayOf(rowNum, colNum) + + override operator fun get(i: Int, j: Int): T = generator(i, j) +} diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Symbol.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Symbol.kt new file mode 100644 index 000000000..2c9774b6a --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Symbol.kt @@ -0,0 +1,34 @@ +package space.kscience.kmath.misc + +import kotlin.properties.ReadOnlyProperty + +/** + * A marker interface for a symbol. A symbol mus have an identity + */ +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{ + public val x: StringSymbol = StringSymbol("x") + public val y: StringSymbol = StringSymbol("y") + public val z: StringSymbol = StringSymbol("z") + } +} + +/** + * A [Symbol] with a [String] identity + */ +public inline class StringSymbol(override val identity: String) : Symbol { + override fun toString(): String = identity +} + + +/** + * A delegate to create a symbol with a string identity in this scope + */ +public val symbol: ReadOnlyProperty = ReadOnlyProperty { _, property -> + StringSymbol(property.name) +} 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 80% 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 06248a166..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 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 82% 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..6466695a6 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.Group +import space.kscience.kmath.operations.invoke import kotlin.jvm.JvmName /** @@ -37,8 +37,8 @@ public fun List.cumulative(initial: R, operation: (R, T) -> R): List Iterable.cumulativeSum(space: Space): Iterable = - space { cumulative(zero) { element: T, sum: T -> sum + element } } +public fun Iterable.cumulativeSum(group: Group): Iterable = + group { cumulative(zero) { element: T, sum: T -> sum + element } } @JvmName("cumulativeSumOfDouble") public fun Iterable.cumulativeSum(): Iterable = cumulative(0.0) { element, sum -> sum + element } @@ -49,8 +49,8 @@ public fun Iterable.cumulativeSum(): Iterable = cumulative(0) { elemen @JvmName("cumulativeSumOfLong") public fun Iterable.cumulativeSum(): Iterable = cumulative(0L) { element, sum -> sum + element } -public fun Sequence.cumulativeSum(space: Space): Sequence = - space { cumulative(zero) { element: T, sum: T -> sum + element } } +public fun Sequence.cumulativeSum(group: Group): Sequence = + group { cumulative(zero) { element: T, sum: T -> sum + element } } @JvmName("cumulativeSumOfDouble") public fun Sequence.cumulativeSum(): Sequence = cumulative(0.0) { element, sum -> sum + element } @@ -61,8 +61,8 @@ public fun Sequence.cumulativeSum(): Sequence = cumulative(0) { elemen @JvmName("cumulativeSumOfLong") public fun Sequence.cumulativeSum(): Sequence = cumulative(0L) { element, sum -> sum + element } -public fun List.cumulativeSum(space: Space): List = - space { cumulative(zero) { element: T, sum: T -> sum + element } } +public fun List.cumulativeSum(group: Group): List = + group { cumulative(zero) { element: T, sum: T -> sum + element } } @JvmName("cumulativeSumOfDouble") public fun List.cumulativeSum(): List = cumulative(0.0) { element, sum -> sum + element } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt similarity index 58% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDAlgebra.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt index 749fb1a13..2821a6648 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt @@ -1,9 +1,9 @@ -package kscience.kmath.nd +package space.kscience.kmath.nd -import kscience.kmath.operations.Field -import kscience.kmath.operations.Ring -import kscience.kmath.operations.Space -import kscience.kmath.structures.* +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.* +import kotlin.reflect.KClass /** * An exception is thrown when the expected ans actual shape of NDArray differs. @@ -21,7 +21,7 @@ public class ShapeMismatchException(public val expected: IntArray, public val ac * @param C the type of the element context. * @param N the type of the structure. */ -public interface NDAlgebra { +public interface AlgebraND> { /** * The shape of ND-structures this algebra operates on. */ @@ -33,45 +33,70 @@ public interface NDAlgebra { public val elementContext: C /** - * Produces a new [N] structure using given initializer function. + * Produces a new NDStructure using given initializer function. */ - public fun produce(initializer: C.(IntArray) -> T): NDStructure + public fun produce(initializer: C.(IntArray) -> T): StructureND /** * Maps elements from one structure to another one by applying [transform] to them. */ - public fun NDStructure.map(transform: C.(T) -> T): NDStructure + public fun StructureND.map(transform: C.(T) -> T): StructureND /** * 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 + public fun StructureND.mapIndexed(transform: C.(index: IntArray, T) -> T): StructureND /** * Combines two structures into one. */ - public fun combine(a: NDStructure, b: NDStructure, transform: C.(T, T) -> T): NDStructure + public fun combine(a: StructureND, b: StructureND, transform: C.(T, T) -> T): StructureND /** - * Element-wise invocation of function working on [T] on a [NDStructure]. + * Element-wise invocation of function working on [T] on a [StructureND]. */ - public operator fun Function1.invoke(structure: NDStructure): NDStructure = - structure.map() { value -> this@invoke(value) } + public operator fun Function1.invoke(structure: StructureND): StructureND = + structure.map { value -> this@invoke(value) } + + /** + * Get a feature of the structure in this scope. Structure features take precedence other context features + * + * @param F the type of feature. + * @param structure the structure. + * @param type the [KClass] instance of [F]. + * @return a feature object or `null` if it isn't present. + */ + @UnstableKMathAPI + public fun getFeature(structure: StructureND, type: KClass): F? = + structure.getFeature(type) public companion object } + +/** + * Get a feature of the structure in this scope. Structure features take precedence other context features + * + * @param T the type of items in the matrices. + * @param F the type of feature. + * @return a feature object or `null` if it isn't present. + */ +@UnstableKMathAPI +public inline fun AlgebraND.getFeature(structure: StructureND): F? = + getFeature(structure, F::class) + /** * 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 +internal fun > AlgebraND.checkShape(vararg structures: StructureND): Array> = + structures + .map(StructureND::shape) + .singleOrNull { !shape.contentEquals(it) } + ?.let>> { throw ShapeMismatchException(shape, it) } + ?: structures /** * Checks if given element is consistent with this context. @@ -79,19 +104,19 @@ internal fun NDAlgebra.checkShape(vararg structures: NDStructure * @param element the structure to check. * @return the valid structure. */ -internal fun NDAlgebra.checkShape(element: NDStructure): NDStructure { +internal fun > AlgebraND.checkShape(element: StructureND): StructureND { if (!element.shape.contentEquals(shape)) throw ShapeMismatchException(shape, element.shape) return element } /** - * Space of [NDStructure]. + * Space of [StructureND]. * * @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 { +public interface GroupND> : Group>, AlgebraND { /** * Element-wise addition. * @@ -99,17 +124,17 @@ public interface NDSpace> : Space>, NDAlgebra, b: NDStructure): NDStructure = + public override fun add(a: StructureND, b: StructureND): StructureND = 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) } +// /** +// * 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 @@ -120,7 +145,7 @@ public interface NDSpace> : Space>, NDAlgebra.plus(arg: T): NDStructure = this.map() { value -> add(arg, value) } + public operator fun StructureND.plus(arg: T): StructureND = this.map { value -> add(arg, value) } /** * Subtracts an element from ND structure of it. @@ -129,7 +154,7 @@ public interface NDSpace> : Space>, NDAlgebra.minus(arg: T): NDStructure = this.map() { value -> add(arg, -value) } + public operator fun StructureND.minus(arg: T): StructureND = this.map { value -> add(arg, -value) } /** * Adds an element to ND structure of it. @@ -138,7 +163,7 @@ public interface NDSpace> : Space>, NDAlgebra): NDStructure = arg.map() { value -> add(this@plus, value) } + public operator fun T.plus(arg: StructureND): StructureND = arg.map { value -> add(this@plus, value) } /** * Subtracts an ND structure from an element of it. @@ -147,19 +172,19 @@ public interface NDSpace> : Space>, NDAlgebra): NDStructure = arg.map() { value -> add(-this@minus, value) } + public operator fun T.minus(arg: StructureND): StructureND = arg.map { value -> add(-this@minus, value) } public companion object } /** - * Ring of [NDStructure]. + * Ring of [StructureND]. * * @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 { +public interface RingND> : Ring>, GroupND { /** * Element-wise multiplication. * @@ -167,7 +192,7 @@ public interface NDRing> : Ring>, NDSpace { * @param b the multiplier. * @return the product. */ - public override fun multiply(a: NDStructure, b: NDStructure): NDStructure = + public override fun multiply(a: StructureND, b: StructureND): StructureND = combine(a, b) { aValue, bValue -> multiply(aValue, bValue) } //TODO move to extensions after KEEP-176 @@ -179,7 +204,7 @@ public interface NDRing> : Ring>, NDSpace { * @param arg the multiplier. * @return the product. */ - public operator fun NDStructure.times(arg: T): NDStructure = this.map() { value -> multiply(arg, value) } + public operator fun StructureND.times(arg: T): StructureND = this.map { value -> multiply(arg, value) } /** * Multiplies an element by a ND structure of it. @@ -188,19 +213,19 @@ public interface NDRing> : Ring>, NDSpace { * @param arg the multiplier. * @return the product. */ - public operator fun T.times(arg: NDStructure): NDStructure = arg.map() { value -> multiply(this@times, value) } + public operator fun T.times(arg: StructureND): StructureND = arg.map { value -> multiply(this@times, value) } public companion object } /** - * Field of [NDStructure]. + * Field of [StructureND]. * * @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 { +public interface FieldND> : Field>, RingND, ScaleOperations> { /** * Element-wise division. * @@ -208,7 +233,7 @@ public interface NDField> : Field>, NDRing * @param b the divisor. * @return the quotient. */ - public override fun divide(a: NDStructure, b: NDStructure): NDStructure = + public override fun divide(a: StructureND, b: StructureND): StructureND = combine(a, b) { aValue, bValue -> divide(aValue, bValue) } //TODO move to extensions after KEEP-176 @@ -219,7 +244,7 @@ public interface NDField> : Field>, NDRing * @param arg the divisor. * @return the quotient. */ - public operator fun NDStructure.div(arg: T): NDStructure = this.map() { value -> divide(arg, value) } + public operator fun StructureND.div(arg: T): StructureND = this.map { value -> divide(arg, value) } /** * Divides an element by an ND structure of it. @@ -228,7 +253,7 @@ public interface NDField> : Field>, NDRing * @param arg the divisor. * @return the quotient. */ - public operator fun T.div(arg: NDStructure): NDStructure = arg.map() { divide(it, this@div) } + public operator fun T.div(arg: StructureND): StructureND = arg.map { divide(it, this@div) } // @ThreadLocal // public companion object { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt new file mode 100644 index 000000000..67e94df74 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt @@ -0,0 +1,137 @@ +package space.kscience.kmath.nd + +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + +public interface BufferAlgebraND> : AlgebraND { + public val strides: Strides + public val bufferFactory: BufferFactory + + override fun produce(initializer: A.(IntArray) -> T): BufferND = BufferND( + strides, + bufferFactory(strides.linearSize) { offset -> + elementContext.initializer(strides.index(offset)) + } + ) + + public val StructureND.buffer: Buffer + get() = when { + !shape.contentEquals(this@BufferAlgebraND.shape) -> throw ShapeMismatchException( + this@BufferAlgebraND.shape, + shape + ) + this is BufferND && this.strides == this@BufferAlgebraND.strides -> this.buffer + else -> bufferFactory(strides.linearSize) { offset -> get(strides.index(offset)) } + } + + override fun StructureND.map(transform: A.(T) -> T): BufferND { + val buffer = bufferFactory(strides.linearSize) { offset -> + elementContext.transform(buffer[offset]) + } + return BufferND(strides, buffer) + } + + override fun StructureND.mapIndexed(transform: A.(index: IntArray, T) -> T): BufferND { + val buffer = bufferFactory(strides.linearSize) { offset -> + elementContext.transform( + strides.index(offset), + buffer[offset] + ) + } + return BufferND(strides, buffer) + } + + override fun combine(a: StructureND, b: StructureND, transform: A.(T, T) -> T): BufferND { + val buffer = bufferFactory(strides.linearSize) { offset -> + elementContext.transform(a.buffer[offset], b.buffer[offset]) + } + return BufferND(strides, buffer) + } +} + +public open class BufferedGroupND>( + final override val shape: IntArray, + final override val elementContext: A, + final override val bufferFactory: BufferFactory, +) : GroupND, BufferAlgebraND { + override val strides: Strides = DefaultStrides(shape) + override val zero: BufferND by lazy { produce { zero } } + override fun StructureND.unaryMinus(): StructureND = produce { -get(it) } +} + +public open class BufferedRingND>( + shape: IntArray, + elementContext: R, + bufferFactory: BufferFactory, +) : BufferedGroupND(shape, elementContext, bufferFactory), RingND { + override val one: BufferND by lazy { produce { one } } +} + +public open class BufferedFieldND>( + shape: IntArray, + elementContext: R, + bufferFactory: BufferFactory, +) : BufferedRingND(shape, elementContext, bufferFactory), FieldND { + + override fun scale(a: StructureND, value: Double): StructureND = a.map { it * value } +} + +// group factories +public fun > AlgebraND.Companion.group( + space: A, + bufferFactory: BufferFactory, + vararg shape: Int, +): BufferedGroupND = BufferedGroupND(shape, space, bufferFactory) + +public inline fun , R> A.ndGroup( + noinline bufferFactory: BufferFactory, + vararg shape: Int, + action: BufferedGroupND.() -> R, +): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return AlgebraND.group(this, bufferFactory, *shape).run(action) +} + +//ring factories +public fun > AlgebraND.Companion.ring( + ring: A, + bufferFactory: BufferFactory, + vararg shape: Int, +): BufferedRingND = BufferedRingND(shape, ring, bufferFactory) + +public inline fun , R> A.ndRing( + noinline bufferFactory: BufferFactory, + vararg shape: Int, + action: BufferedRingND.() -> R, +): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return AlgebraND.ring(this, bufferFactory, *shape).run(action) +} + +//field factories +public fun > AlgebraND.Companion.field( + field: A, + bufferFactory: BufferFactory, + vararg shape: Int, +): BufferedFieldND = BufferedFieldND(shape, field, bufferFactory) + +@Suppress("UNCHECKED_CAST") +public inline fun > AlgebraND.Companion.auto( + field: A, + vararg shape: Int, +): FieldND = when (field) { + DoubleField -> DoubleFieldND(shape) as FieldND + else -> BufferedFieldND(shape, field, Buffer.Companion::auto) +} + +public inline fun , R> A.ndField( + noinline bufferFactory: BufferFactory, + vararg shape: Int, + action: BufferedFieldND.() -> R, +): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return AlgebraND.field(this, bufferFactory, *shape).run(action) +} \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt new file mode 100644 index 000000000..c7f8d222d --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt @@ -0,0 +1,48 @@ +package space.kscience.kmath.nd + +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory + +/** + * Represents [StructureND] 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 class BufferND( + public val strides: Strides, + public val buffer: Buffer, +) : StructureND { + + init { + if (strides.linearSize != buffer.size) { + error("Expected buffer side of ${strides.linearSize}, but found ${buffer.size}") + } + } + + 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 toString(): String = StructureND.toString(this) +} + +/** + * Transform structure to a new structure using provided [BufferFactory] and optimizing if argument is [BufferND] + */ +public inline fun StructureND.mapToBuffer( + factory: BufferFactory = Buffer.Companion::auto, + crossinline transform: (T) -> R, +): BufferND { + return if (this is BufferND) + BufferND(this.strides, factory.invoke(strides.linearSize) { transform(buffer[it]) }) + else { + val strides = DefaultStrides(shape) + BufferND(strides, factory.invoke(strides.linearSize) { transform(get(strides.index(it))) }) + } +} \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt new file mode 100644 index 000000000..d38ed02da --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt @@ -0,0 +1,110 @@ +package space.kscience.kmath.nd + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.NumbersAddOperations +import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.structures.DoubleBuffer +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + +@OptIn(UnstableKMathAPI::class) +public class DoubleFieldND( + shape: IntArray, +) : BufferedFieldND(shape, DoubleField, ::DoubleBuffer), + NumbersAddOperations>, + ScaleOperations>, + ExtendedField> { + + override val zero: BufferND by lazy { produce { zero } } + override val one: BufferND by lazy { produce { one } } + + override fun number(value: Number): BufferND { + val d = value.toDouble() // minimize conversions + return produce { d } + } + + override val StructureND.buffer: DoubleBuffer + get() = when { + !shape.contentEquals(this@DoubleFieldND.shape) -> throw ShapeMismatchException( + this@DoubleFieldND.shape, + shape + ) + this is BufferND && this.strides == this@DoubleFieldND.strides -> this.buffer as DoubleBuffer + else -> DoubleBuffer(strides.linearSize) { offset -> get(strides.index(offset)) } + } + + @Suppress("OVERRIDE_BY_INLINE") + override inline fun StructureND.map( + transform: DoubleField.(Double) -> Double, + ): BufferND { + val buffer = DoubleBuffer(strides.linearSize) { offset -> DoubleField.transform(buffer.array[offset]) } + return BufferND(strides, buffer) + } + + @Suppress("OVERRIDE_BY_INLINE") + override inline fun produce(initializer: DoubleField.(IntArray) -> Double): BufferND { + val array = DoubleArray(strides.linearSize) { offset -> + val index = strides.index(offset) + DoubleField.initializer(index) + } + return BufferND(strides, DoubleBuffer(array)) + } + + @Suppress("OVERRIDE_BY_INLINE") + override inline fun StructureND.mapIndexed( + transform: DoubleField.(index: IntArray, Double) -> Double, + ): BufferND = BufferND( + strides, + buffer = DoubleBuffer(strides.linearSize) { offset -> + DoubleField.transform( + strides.index(offset), + buffer.array[offset] + ) + }) + + @Suppress("OVERRIDE_BY_INLINE") + override inline fun combine( + a: StructureND, + b: StructureND, + transform: DoubleField.(Double, Double) -> Double, + ): BufferND { + val buffer = DoubleBuffer(strides.linearSize) { offset -> + DoubleField.transform(a.buffer.array[offset], b.buffer.array[offset]) + } + return BufferND(strides, buffer) + } + + override fun scale(a: StructureND, value: Double): StructureND = a.map { it * value } + + override fun power(arg: StructureND, pow: Number): BufferND = arg.map { power(it, pow) } + + override fun exp(arg: StructureND): BufferND = arg.map { exp(it) } + + override fun ln(arg: StructureND): BufferND = arg.map { ln(it) } + + override fun sin(arg: StructureND): BufferND = arg.map { sin(it) } + override fun cos(arg: StructureND): BufferND = arg.map { cos(it) } + override fun tan(arg: StructureND): BufferND = arg.map { tan(it) } + override fun asin(arg: StructureND): BufferND = arg.map { asin(it) } + override fun acos(arg: StructureND): BufferND = arg.map { acos(it) } + override fun atan(arg: StructureND): BufferND = arg.map { atan(it) } + + override fun sinh(arg: StructureND): BufferND = arg.map { sinh(it) } + override fun cosh(arg: StructureND): BufferND = arg.map { cosh(it) } + override fun tanh(arg: StructureND): BufferND = arg.map { tanh(it) } + override fun asinh(arg: StructureND): BufferND = arg.map { asinh(it) } + override fun acosh(arg: StructureND): BufferND = arg.map { acosh(it) } + override fun atanh(arg: StructureND): BufferND = arg.map { atanh(it) } +} + +public fun AlgebraND.Companion.real(vararg shape: Int): DoubleFieldND = DoubleFieldND(shape) + +/** + * Produce a context for n-dimensional operations inside this real field + */ +public inline fun DoubleField.nd(vararg shape: Int, action: DoubleFieldND.() -> R): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return DoubleFieldND(shape).run(action) +} diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortRingND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortRingND.kt new file mode 100644 index 000000000..f1056d0ff --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortRingND.kt @@ -0,0 +1,36 @@ +package space.kscience.kmath.nd + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.NumbersAddOperations +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 ShortRingND( + shape: IntArray, +) : BufferedRingND(shape, ShortRing, Buffer.Companion::auto), + NumbersAddOperations> { + + override val zero: BufferND by lazy { produce { zero } } + override val one: BufferND by lazy { produce { one } } + + override fun number(value: Number): BufferND { + val d = value.toShort() // minimize conversions + return produce { d } + } +} + +/** + * Fast element production using function inlining. + */ +public inline fun BufferedRingND.produceInline(crossinline initializer: ShortRing.(Int) -> Short): BufferND { + return BufferND(strides, ShortBuffer(ShortArray(strides.linearSize) { offset -> ShortRing.initializer(offset) })) +} + +public inline fun ShortRing.nd(vararg shape: Int, action: ShortRingND.() -> R): R { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + return ShortRingND(shape).run(action) +} \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/Structure1D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt similarity index 58% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/nd/Structure1D.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt index d69c23fb4..5483ed28f 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/Structure1D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt @@ -1,12 +1,12 @@ -package kscience.kmath.nd +package space.kscience.kmath.nd -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.asSequence +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asSequence /** * A structure that is guaranteed to be one-dimensional */ -public interface Structure1D : NDStructure, Buffer { +public interface Structure1D : StructureND, Buffer { public override val dimension: Int get() = 1 public override operator fun get(index: IntArray): T { @@ -15,12 +15,14 @@ public interface Structure1D : NDStructure, Buffer { } public override operator fun iterator(): Iterator = (0 until size).asSequence().map(::get).iterator() + + public companion object } /** * A 1D wrapper for nd-structure */ -private inline class Structure1DWrapper(val structure: NDStructure) : Structure1D { +private inline class Structure1DWrapper(val structure: StructureND) : Structure1D { override val shape: IntArray get() = structure.shape override val size: Int get() = structure.shape[0] @@ -43,14 +45,25 @@ private inline class Buffer1DWrapper(val buffer: Buffer) : Structure1D } /** - * Represent a [NDStructure] as [Structure1D]. Throw error in case of dimension mismatch + * Represent a [StructureND] as [Structure1D]. Throw error in case of dimension mismatch */ -public fun NDStructure.as1D(): Structure1D = if (shape.size == 1) { - if (this is NDBuffer) Buffer1DWrapper(this.buffer) else Structure1DWrapper(this) -} else - error("Can't create 1d-structure from ${shape.size}d-structure") +public fun StructureND.as1D(): Structure1D = this as? Structure1D ?: if (shape.size == 1) { + when (this) { + is BufferND -> Buffer1DWrapper(this.buffer) + else -> Structure1DWrapper(this) + } +} else error("Can't create 1d-structure from ${shape.size}d-structure") /** * Represent this buffer as 1D structure */ public fun Buffer.asND(): Structure1D = Buffer1DWrapper(this) + +/** + * Expose inner buffer of this [Structure1D] if possible + */ +internal fun Structure1D.unwrap(): Buffer = when { + this is Buffer1DWrapper -> buffer + this is Structure1DWrapper && structure is BufferND -> structure.buffer + else -> this +} diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/Structure2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt similarity index 55% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/nd/Structure2D.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt index e2694309a..5dfdd028a 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt @@ -1,16 +1,16 @@ -package kscience.kmath.nd +package space.kscience.kmath.nd -import kscience.kmath.linear.BufferMatrix -import kscience.kmath.linear.RealMatrixContext -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.VirtualBuffer +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.VirtualBuffer +import kotlin.reflect.KClass /** * A structure that is guaranteed to be two-dimensional. * * @param T the type of items. */ -public interface Structure2D : NDStructure { +public interface Structure2D : StructureND { /** * The number of rows in this structure. */ @@ -26,14 +26,14 @@ public interface Structure2D : NDStructure { /** * The buffer of rows of this structure. It gets elements from the structure dynamically. */ - public val rows: Buffer> - get() = VirtualBuffer(rowNum) { i -> VirtualBuffer(colNum) { j -> get(i, j) } } + public val rows: List> + get() = List(rowNum) { i -> VirtualBuffer(colNum) { j -> get(i, j) } } /** * The buffer of columns of this structure. It gets elements from the structure dynamically. */ - public val columns: Buffer> - get() = VirtualBuffer(colNum) { j -> VirtualBuffer(rowNum) { i -> get(i, j) } } + public val columns: List> + get() = List(colNum) { j -> VirtualBuffer(rowNum) { i -> get(i, j) } } /** * Retrieves an element from the structure by two indices. @@ -54,21 +54,13 @@ public interface Structure2D : NDStructure { for (j in 0 until colNum) yield(intArrayOf(i, j) to get(i, j)) } - 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) - } - } + public companion object } /** * A 2D wrapper for nd-structure */ -private inline class Structure2DWrapper(val structure: NDStructure) : Structure2D { +private inline class Structure2DWrapper(val structure: StructureND) : Structure2D { override val shape: IntArray get() = structure.shape override val rowNum: Int get() = shape[0] @@ -76,20 +68,23 @@ private inline class Structure2DWrapper(val structure: NDStructure) : Stru override operator fun get(i: Int, j: Int): T = structure[i, j] + @UnstableKMathAPI + override fun getFeature(type: KClass): F? = structure.getFeature(type) + override fun elements(): Sequence> = structure.elements() } /** - * Represent a [NDStructure] as [Structure1D]. Throw error in case of dimension mismatch + * Represent a [StructureND] as [Structure1D]. Throw error in case of dimension mismatch */ -public fun NDStructure.as2D(): Structure2D = if (shape.size == 2) - Structure2DWrapper(this) -else - error("Can't create 2d-structure from ${shape.size}d-structure") +public fun StructureND.as2D(): Structure2D = this as? Structure2D ?: when (shape.size) { + 2 -> Structure2DWrapper(this) + else -> error("Can't create 2d-structure from ${shape.size}d-structure") +} /** - * Alias for [Structure2D] with more familiar name. - * - * @param T the type of items in the matrix. + * Expose inner [StructureND] if possible */ -public typealias Matrix = Structure2D +internal fun Structure2D.unwrap(): StructureND = + if (this is Structure2DWrapper) structure + else this \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDStructure.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt similarity index 55% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDStructure.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index 4aa1c7d52..a1aa5e554 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDStructure.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -1,22 +1,24 @@ -package kscience.kmath.nd +package space.kscience.kmath.nd -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.BufferFactory -import kscience.kmath.structures.MutableBuffer -import kscience.kmath.structures.asSequence +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory import kotlin.jvm.JvmName import kotlin.native.concurrent.ThreadLocal import kotlin.reflect.KClass +public interface StructureFeature + /** * Represents n-dimensional structure, i.e. multidimensional container of items of the same type and size. The number * of dimensions and items in an array is defined by its shape, which is a sequence of non-negative integers that * specify the sizes of each dimension. * + * StructureND is in general identity-free. [StructureND.contentEquals] should be used in tests to compare contents. + * * @param T the type of items. */ -public interface NDStructure { +public interface StructureND { /** * The shape of structure, i.e. non-empty sequence of non-negative integers that specify sizes of dimensions of * this structure. @@ -43,43 +45,57 @@ public interface NDStructure { */ public fun elements(): Sequence> - //force override equality and hash code - public override fun equals(other: Any?): Boolean - public override fun hashCode(): Int - /** - * Feature is additional property or hint that does not directly affect the structure, but could in some cases help - * optimize operations and performance. If the feature is not present, null is defined. + * Feature is some additional strucure information which allows to access it special properties or hints. + * If the feature is not present, null is returned. */ @UnstableKMathAPI - public fun getFeature(type: KClass): T? = null + public fun getFeature(type: KClass): F? = null public companion object { /** - * Indicates whether some [NDStructure] is equal to another one. + * Indicates whether some [StructureND] is equal to another one. */ - public fun contentEquals(st1: NDStructure<*>, st2: NDStructure<*>): Boolean { + public fun contentEquals(st1: StructureND, st2: StructureND): Boolean { if (st1 === st2) return true // fast comparison of buffers if possible - if (st1 is NDBuffer && st2 is NDBuffer && st1.strides == st2.strides) - return st1.buffer.contentEquals(st2.buffer) + if (st1 is BufferND && st2 is BufferND && st1.strides == st2.strides) + return Buffer.contentEquals(st1.buffer, st2.buffer) //element by element comparison if it could not be avoided return st1.elements().all { (index, value) -> value == st2[index] } } + /** + * Debug output to string + */ + public fun toString(structure: StructureND<*>): String { + val bufferRepr: String = when (structure.shape.size) { + 1 -> (0 until structure.shape[0]).map { structure[it] } + .joinToString(prefix = "[", postfix = "]", separator = ", ") + 2 -> (0 until structure.shape[0]).joinToString(prefix = "[", postfix = "]", separator = ", ") { i -> + (0 until structure.shape[1]).joinToString(prefix = "[", postfix = "]", separator = ", ") { j -> + structure[i, j].toString() + } + } + else -> "..." + } + val className = structure::class.simpleName ?: "StructureND" + + return "$className(shape=${structure.shape.contentToString()}, buffer=$bufferRepr)" + } + /** * Creates a NDStructure with explicit buffer factory. * * Strides should be reused if possible. */ - public fun build( + public fun buffered( strides: Strides, bufferFactory: BufferFactory = Buffer.Companion::boxing, initializer: (IntArray) -> T, - ): NDBuffer = - NDBuffer(strides, bufferFactory(strides.linearSize) { i -> initializer(strides.index(i)) }) + ): BufferND = BufferND(strides, bufferFactory(strides.linearSize) { i -> initializer(strides.index(i)) }) /** * Inline create NDStructure with non-boxing buffer implementation if it is possible @@ -87,41 +103,37 @@ public interface NDStructure { public inline fun auto( strides: Strides, crossinline initializer: (IntArray) -> T, - ): NDBuffer = - NDBuffer(strides, Buffer.auto(strides.linearSize) { i -> initializer(strides.index(i)) }) + ): BufferND = BufferND(strides, Buffer.auto(strides.linearSize) { i -> initializer(strides.index(i)) }) public inline fun auto( type: KClass, strides: Strides, crossinline initializer: (IntArray) -> T, - ): NDBuffer = - NDBuffer(strides, Buffer.auto(type, strides.linearSize) { i -> initializer(strides.index(i)) }) + ): BufferND = BufferND(strides, Buffer.auto(type, strides.linearSize) { i -> initializer(strides.index(i)) }) - public fun build( + public fun buffered( shape: IntArray, bufferFactory: BufferFactory = Buffer.Companion::boxing, initializer: (IntArray) -> T, - ): NDBuffer = build(DefaultStrides(shape), bufferFactory, initializer) + ): BufferND = buffered(DefaultStrides(shape), bufferFactory, initializer) public inline fun auto( shape: IntArray, crossinline initializer: (IntArray) -> T, - ): NDBuffer = - auto(DefaultStrides(shape), initializer) + ): BufferND = auto(DefaultStrides(shape), initializer) @JvmName("autoVarArg") public inline fun auto( vararg shape: Int, crossinline initializer: (IntArray) -> T, - ): NDBuffer = + ): BufferND = auto(DefaultStrides(shape), initializer) public inline fun auto( type: KClass, vararg shape: Int, crossinline initializer: (IntArray) -> T, - ): NDBuffer = - auto(type, DefaultStrides(shape), initializer) + ): BufferND = auto(type, DefaultStrides(shape), initializer) } } @@ -131,15 +143,15 @@ public interface NDStructure { * @param index the indices. * @return the value. */ -public operator fun NDStructure.get(vararg index: Int): T = get(index) +public operator fun StructureND.get(vararg index: Int): T = get(index) @UnstableKMathAPI -public inline fun NDStructure<*>.getFeature(): T? = getFeature(T::class) +public inline fun StructureND<*>.getFeature(): T? = getFeature(T::class) /** - * Represents mutable [NDStructure]. + * Represents mutable [StructureND]. */ -public interface MutableNDStructure : NDStructure { +public interface MutableStructureND : StructureND { /** * Inserts an item at the specified indices. * @@ -152,7 +164,7 @@ public interface MutableNDStructure : NDStructure { /** * Transform a structure element-by element in place. */ -public inline fun MutableNDStructure.mapInPlace(action: (IntArray, T) -> T): Unit = +public inline fun MutableStructureND.mapInPlace(action: (IntArray, T) -> T): Unit = elements().forEach { (index, oldValue) -> this[index] = action(index, oldValue) } /** @@ -256,97 +268,10 @@ 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 open class NDBuffer( - public val strides: Strides, - buffer: Buffer, -) : NDStructure { - - 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 equals(other: Any?): Boolean { - return NDStructure.contentEquals(this, other as? NDStructure<*> ?: return false) - } - - override fun hashCode(): Int { - var result = strides.hashCode() - result = 31 * result + buffer.hashCode() - return result - } - - override fun toString(): String { - val bufferRepr: String = when (shape.size) { - 1 -> buffer.asSequence().joinToString(prefix = "[", postfix = "]", separator = ", ") - 2 -> (0 until shape[0]).joinToString(prefix = "[", postfix = "]", separator = ", ") { i -> - (0 until shape[1]).joinToString(prefix = "[", postfix = "]", separator = ", ") { j -> - val offset = strides.offset(intArrayOf(i, j)) - buffer[offset].toString() - } - } - else -> "..." - } - return "NDBuffer(shape=${shape.contentToString()}, buffer=$bufferRepr)" - } -} - -/** - * 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, -): NDBuffer { - return if (this is NDBuffer) - NDBuffer(this.strides, factory.invoke(strides.linearSize) { transform(buffer[it]) }) - else { - val strides = DefaultStrides(shape) - NDBuffer(strides, factory.invoke(strides.linearSize) { transform(get(strides.index(it))) }) - } -} - -/** - * Mutable ND buffer based on linear [MutableBuffer]. - */ -public class MutableNDBuffer( - strides: Strides, - buffer: MutableBuffer, -) : NDBuffer(strides, buffer), MutableNDStructure { - - init { - require(strides.linearSize == buffer.size) { - "Expected buffer side of ${strides.linearSize}, but found ${buffer.size}" - } - } - - override val buffer: MutableBuffer = super.buffer as MutableBuffer - - override operator fun set(index: IntArray, value: T): Unit = buffer.set(strides.offset(index), value) -} - -public inline fun NDStructure.combine( - struct: NDStructure, +public inline fun StructureND.combine( + struct: StructureND, crossinline block: (T, T) -> T, -): NDStructure { +): StructureND { require(shape.contentEquals(struct.shape)) { "Shape mismatch in structure combination" } - return NDStructure.auto(shape) { block(this[it], struct[it]) } + return StructureND.auto(shape) { block(this[it], struct[it]) } } 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 75% 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 f3a87d644..492ec8e88 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.misc.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. @@ -85,9 +87,12 @@ public interface Algebra { * @param right the second argument of operation. * @return a result of operation. */ - public fun binaryOperation(operation: String, left: T, right: T): T = binaryOperationFunction(operation)(left, right) + 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,12 +100,12 @@ 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 group without neutral element (also known as inverse semigroup), i.e. algebraic structure with + * associative, binary operation [add]. * * @param T the type of element of this semispace. */ -public interface SpaceOperations : Algebra { +public interface GroupOperations : Algebra { /** * Addition of two elements. * @@ -110,15 +115,6 @@ public interface SpaceOperations : Algebra { */ public fun add(a: T, b: T): T - /** - * Multiplication of element by scalar. - * - * @param a the multiplier. - * @param k the multiplicand. - * @return the produce. - */ - public fun multiply(a: T, k: Number): T - // Operations to be performed in this context. Could be moved to extensions in case of KEEP-176 /** @@ -127,7 +123,7 @@ public interface SpaceOperations : Algebra { * @receiver this value. * @return the additive inverse of this value. */ - public operator fun T.unaryMinus(): T = multiply(this, -1.0) + public operator fun T.unaryMinus(): T /** * Returns this value. @@ -155,35 +151,8 @@ public interface SpaceOperations : Algebra { */ public operator fun T.minus(b: T): T = add(this, -b) - /** - * Multiplication of this element by a scalar. - * - * @receiver the multiplier. - * @param k the multiplicand. - * @return the product. - */ - public operator fun T.times(k: Number): T = multiply(this, k) - - /** - * Division of this element by scalar. - * - * @receiver the dividend. - * @param k the divisor. - * @return the quotient. - */ - public operator fun T.div(k: Number): T = multiply(this, 1.0 / k.toDouble()) - - /** - * Multiplication of this number by element. - * - * @receiver the multiplier. - * @param b the multiplicand. - * @return the product. - */ - public operator fun Number.times(b: T): T = b * this - public override fun unaryOperationFunction(operation: String): (arg: T) -> T = when (operation) { - PLUS_OPERATION -> { arg -> arg } + PLUS_OPERATION -> { arg -> +arg } MINUS_OPERATION -> { arg -> -arg } else -> super.unaryOperationFunction(operation) } @@ -208,12 +177,11 @@ 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 group, i.e. algebraic structure with associative, binary operation [add]. * - * @param T the type of element of this group. + * @param T the type of element of this semispace. */ -public interface Space : SpaceOperations { +public interface Group : GroupOperations { /** * The neutral element of addition. */ @@ -221,12 +189,12 @@ public interface Space : SpaceOperations { } /** - * Represents semiring, i.e. algebraic structure with two associative binary operations called "addition" and - * "multiplication". + * Represents ring without multiplicative and additive identities, 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. */ -public interface RingOperations : SpaceOperations { +public interface RingOperations : GroupOperations { /** * Multiplies two elements. * @@ -262,7 +230,7 @@ public interface RingOperations : SpaceOperations { * * @param T the type of element of this ring. */ -public interface Ring : Space, RingOperations { +public interface Ring : Group, RingOperations { /** * neutral operation for multiplication */ @@ -270,8 +238,8 @@ public interface Ring : Space, RingOperations { } /** - * Represents semifield, i.e. algebraic structure with three operations: associative "addition" and "multiplication", - * and "division". + * Represents field without without multiplicative and additive identities, 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. */ @@ -308,18 +276,12 @@ public interface FieldOperations : RingOperations { } /** - * Represents field, i.e. algebraic structure with three operations: associative "addition" and "multiplication", - * and "division" and their neutral elements. + * Represents field, i.e. algebraic structure with three operations: associative, commutative addition and + * multiplication, and division. **This interface differs from the eponymous mathematical definition: fields in KMath + * also support associative multiplication by scalar.** * - * @param T the type of element of this semifield. + * @param T the type of element of this field. */ -public interface Field : Ring, FieldOperations { - /** - * Division of element by scalar. - * - * @receiver the dividend. - * @param b the divisor. - * @return the quotient. - */ - public operator fun Number.div(b: T): T = this * divide(one, b) -} +public interface Field : Ring, FieldOperations, ScaleOperations, NumericAlgebra { + override fun number(value: Number): T = scale(one, value.toDouble()) +} \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/AlgebraElements.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/AlgebraElements.kt similarity index 62% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/operations/AlgebraElements.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/AlgebraElements.kt index eb55678b9..b2b5911df 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/operations/AlgebraElements.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/AlgebraElements.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 /** * The generic mathematics elements which is able to store its context @@ -14,24 +14,24 @@ public interface AlgebraElement> { */ 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()) +// +///** +// * 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. @@ -39,8 +39,9 @@ public operator fun , S : Space> T.times(k: Number): * @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)) +@UnstableKMathAPI +public operator fun , S : NumbersAddOperations> T.minus(b: T): T = + context.add(this, context.run { -b }) /** * Adds element to this one. @@ -48,14 +49,14 @@ public operator fun , S : Space> T.minus(b: T): T = * @param b the augend. * @return the sum. */ -public operator fun , S : Space> T.plus(b: T): T = +public operator fun , S : Group> 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) +///** +// * Number times element +// */ +//public operator fun , S : Space> Number.times(element: T): T = +// element.times(this) /** @@ -79,14 +80,14 @@ public operator fun , F : Field> T.div(b: T): T = /** - * The element of [Space]. + * The element of [Group]. * * @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 +public interface SpaceElement, S : Group> : AlgebraElement /** * The element of [Ring]. 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 93% 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 b72be94ff..18fbf0fdd 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,19 +1,19 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.nd.BufferedNDRing -import kscience.kmath.nd.NDAlgebra -import kscience.kmath.operations.BigInt.Companion.BASE -import kscience.kmath.operations.BigInt.Companion.BASE_SIZE -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.AlgebraND +import space.kscience.kmath.nd.BufferedRingND +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 import kotlin.math.sign -public typealias Magnitude = UIntArray -public typealias TBase = ULong +private typealias Magnitude = UIntArray +private typealias TBase = ULong /** * Kotlin Multiplatform implementation of Big Integer numbers (KBigInteger). @@ -21,28 +21,27 @@ public typealias TBase = ULong * @author Robert Drynkin (https://github.com/robdrynkin) and Peter Klimai (https://github.com/pklimai) */ @OptIn(UnstableKMathAPI::class) -public object BigIntField : Field, RingWithNumbers { +public object BigIntField : Field, NumbersAddOperations, ScaleOperations { override val zero: BigInt = BigInt.ZERO override val one: BigInt = BigInt.ONE - override fun add(a: BigInt, b: BigInt): BigInt = a.plus(b) override fun number(value: Number): BigInt = value.toLong().toBigInt() - override fun multiply(a: BigInt, k: Number): BigInt = a.times(number(k)) - + @Suppress("EXTENSION_SHADOWED_BY_MEMBER") + override fun BigInt.unaryMinus(): BigInt = -this + override fun add(a: BigInt, b: BigInt): BigInt = a.plus(b) + override fun scale(a: BigInt, value: Double): BigInt = a.times(number(value)) override fun multiply(a: BigInt, b: BigInt): BigInt = a.times(b) + override fun divide(a: BigInt, b: BigInt): BigInt = a.div(b) public operator fun String.unaryPlus(): BigInt = this.parseBigInteger() ?: error("Can't parse $this as big integer") - public operator fun String.unaryMinus(): BigInt = -(this.parseBigInteger() ?: error("Can't parse $this as big integer")) - - override fun divide(a: BigInt, b: BigInt): BigInt = a.div(b) } public class BigInt internal constructor( private val sign: Byte, - private val magnitude: Magnitude + private val magnitude: Magnitude, ) : Comparable { public override fun compareTo(other: BigInt): Int = when { (sign == 0.toByte()) and (other.sign == 0.toByte()) -> 0 @@ -360,6 +359,9 @@ private fun stripLeadingZeros(mag: Magnitude): Magnitude { return mag.sliceArray(IntRange(0, resSize)) } +/** + * Returns the absolute value of the given value [x]. + */ public fun abs(x: BigInt): BigInt = x.abs() /** @@ -466,5 +468,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): BufferedNDRing = - BufferedNDRing(shape, BigIntField, Buffer.Companion::bigInt) +public fun AlgebraND.Companion.bigInt(vararg shape: Int): BufferedRingND = + BufferedRingND(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 79% 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..bd5f5951f 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. @@ -81,14 +81,53 @@ public interface NumericAlgebra : Algebra { rightSideNumberOperationFunction(operation)(left, right) } +/** + * Scale by scalar operations + */ +public interface ScaleOperations : Algebra { + /** + * Scaling an element by a scalar. + * + * @param a the multiplier. + * @param value the multiplicand. + * @return the produce. + */ + public fun scale(a: T, value: Double): T + + /** + * Multiplication of this element by a scalar. + * + * @receiver the multiplier. + * @param k the multiplicand. + * @return the product. + */ + public operator fun T.times(k: Number): T = scale(this, k.toDouble()) + + /** + * Division of this element by scalar. + * + * @receiver the dividend. + * @param k the divisor. + * @return the quotient. + */ + public operator fun T.div(k: Number): T = scale(this, 1.0 / k.toDouble()) + + /** + * Multiplication of this number by element. + * + * @receiver the multiplier. + * @param b the multiplicand. + * @return the product. + */ + public operator fun Number.times(b: T): T = b * this +} + /** * A combination of [NumericAlgebra] and [Ring] that adds intrinsic simple operations on numbers like `T+1` * TODO to be removed and replaced by extensions after multiple receivers are there */ @UnstableKMathAPI -public interface RingWithNumbers: Ring, NumericAlgebra{ - public override fun number(value: Number): T = one * value - +public interface NumbersAddOperations : Group, NumericAlgebra { /** * Addition of element and scalar. * 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 88% 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 3d809e6a5..6e6249dfe 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,6 +1,6 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations -import kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.misc.UnstableKMathAPI /** * A container for trigonometric operations for specific type. @@ -107,111 +107,6 @@ public fun >> acos(arg: T): @UnstableKMathAPI public fun >> atan(arg: T): T = arg.context.atan(arg) -/** - * A container for hyperbolic trigonometric operations for specific type. - * - * @param T the type of element of this structure. - */ -public interface HyperbolicOperations : Algebra { - /** - * Computes the hyperbolic sine of [arg]. - */ - public fun sinh(arg: T): T - - /** - * Computes the hyperbolic cosine of [arg]. - */ - public fun cosh(arg: T): T - - /** - * Computes the hyperbolic tangent of [arg]. - */ - public fun tanh(arg: T): T - - /** - * Computes the inverse hyperbolic sine of [arg]. - */ - public fun asinh(arg: T): T - - /** - * Computes the inverse hyperbolic cosine of [arg]. - */ - public fun acosh(arg: T): T - - /** - * Computes the inverse hyperbolic tangent of [arg]. - */ - public fun atanh(arg: T): T - - public companion object { - /** - * The identifier of hyperbolic sine. - */ - public const val SINH_OPERATION: String = "sinh" - - /** - * The identifier of hyperbolic cosine. - */ - public const val COSH_OPERATION: String = "cosh" - - /** - * The identifier of hyperbolic tangent. - */ - public const val TANH_OPERATION: String = "tanh" - - /** - * The identifier of inverse hyperbolic sine. - */ - public const val ASINH_OPERATION: String = "asinh" - - /** - * The identifier of inverse hyperbolic cosine. - */ - public const val ACOSH_OPERATION: String = "acosh" - - /** - * The identifier of inverse hyperbolic tangent. - */ - public const val ATANH_OPERATION: String = "atanh" - } -} - -/** - * Computes the hyperbolic sine of [arg]. - */ -@UnstableKMathAPI -public fun >> sinh(arg: T): T = arg.context.sinh(arg) - -/** - * Computes the hyperbolic cosine of [arg]. - */ -@UnstableKMathAPI -public fun >> cosh(arg: T): T = arg.context.cosh(arg) - -/** - * Computes the hyperbolic tangent of [arg]. - */ -@UnstableKMathAPI -public fun >> tanh(arg: T): T = arg.context.tanh(arg) - -/** - * Computes the inverse hyperbolic sine of [arg]. - */ -@UnstableKMathAPI -public fun >> asinh(arg: T): T = arg.context.asinh(arg) - -/** - * Computes the inverse hyperbolic cosine of [arg]. - */ -@UnstableKMathAPI -public fun >> acosh(arg: T): T = arg.context.acosh(arg) - -/** - * Computes the inverse hyperbolic tangent of [arg]. - */ -@UnstableKMathAPI -public fun >> atanh(arg: T): T = arg.context.atanh(arg) - /** * A context extension to include power operations based on exponentiation. * @@ -284,6 +179,36 @@ public interface ExponentialOperations : Algebra { */ public fun ln(arg: T): T + /** + * Computes the hyperbolic sine of [arg]. + */ + public fun sinh(arg: T): T + + /** + * Computes the hyperbolic cosine of [arg]. + */ + public fun cosh(arg: T): T + + /** + * Computes the hyperbolic tangent of [arg]. + */ + public fun tanh(arg: T): T + + /** + * Computes the inverse hyperbolic sine of [arg]. + */ + public fun asinh(arg: T): T + + /** + * Computes the inverse hyperbolic cosine of [arg]. + */ + public fun acosh(arg: T): T + + /** + * Computes the inverse hyperbolic tangent of [arg]. + */ + public fun atanh(arg: T): T + public companion object { /** * The identifier of exponential function. @@ -294,6 +219,36 @@ public interface ExponentialOperations : Algebra { * The identifier of natural logarithm. */ public const val LN_OPERATION: String = "ln" + + /** + * The identifier of hyperbolic sine. + */ + public const val SINH_OPERATION: String = "sinh" + + /** + * The identifier of hyperbolic cosine. + */ + public const val COSH_OPERATION: String = "cosh" + + /** + * The identifier of hyperbolic tangent. + */ + public const val TANH_OPERATION: String = "tanh" + + /** + * The identifier of inverse hyperbolic sine. + */ + public const val ASINH_OPERATION: String = "asinh" + + /** + * The identifier of inverse hyperbolic cosine. + */ + public const val ACOSH_OPERATION: String = "acosh" + + /** + * The identifier of inverse hyperbolic tangent. + */ + public const val ATANH_OPERATION: String = "atanh" } } @@ -309,6 +264,43 @@ public fun >> exp(arg: T): T @UnstableKMathAPI public fun >> ln(arg: T): T = arg.context.ln(arg) + +/** + * Computes the hyperbolic sine of [arg]. + */ +@UnstableKMathAPI +public fun >> sinh(arg: T): T = arg.context.sinh(arg) + +/** + * Computes the hyperbolic cosine of [arg]. + */ +@UnstableKMathAPI +public fun >> cosh(arg: T): T = arg.context.cosh(arg) + +/** + * Computes the hyperbolic tangent of [arg]. + */ +@UnstableKMathAPI +public fun >> tanh(arg: T): T = arg.context.tanh(arg) + +/** + * Computes the inverse hyperbolic sine of [arg]. + */ +@UnstableKMathAPI +public fun >> asinh(arg: T): T = arg.context.asinh(arg) + +/** + * Computes the inverse hyperbolic cosine of [arg]. + */ +@UnstableKMathAPI +public fun >> acosh(arg: T): T = arg.context.acosh(arg) + +/** + * Computes the inverse hyperbolic tangent of [arg]. + */ +@UnstableKMathAPI +public fun >> atanh(arg: T): T = arg.context.atanh(arg) + /** * A container for norm functional on element. * 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 70% 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..b927655e3 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,85 +1,89 @@ -package kscience.kmath.operations +package space.kscience.kmath.operations /** - * Returns the sum of all elements in the iterable in this [Space]. + * Returns the sum of all elements in the iterable in this [Group]. * * @receiver the algebra that provides addition. * @param data the iterable to sum up. * @return the sum. */ -public fun Space.sum(data: Iterable): T = data.fold(zero) { left, right -> add(left, right) } +public fun Group.sum(data: Iterable): T = data.fold(zero) { left, right -> add(left, right) } /** - * Returns the sum of all elements in the sequence in this [Space]. + * Returns the sum of all elements in the sequence in this [Group]. * * @receiver the algebra that provides addition. * @param data the sequence to sum up. * @return the sum. */ -public fun Space.sum(data: Sequence): T = data.fold(zero) { left, right -> add(left, right) } +public fun Group.sum(data: Sequence): T = data.fold(zero) { left, right -> add(left, right) } /** - * Returns an average value of elements in the iterable in this [Space]. + * Returns an average value of elements in the iterable in this [Group]. * * @receiver the algebra that provides addition and division. * @param data the iterable to find average. * @return the average value. * @author Iaroslav Postovalov */ -public fun Space.average(data: Iterable): T = sum(data) / data.count() +public fun S.average(data: Iterable): T where S : Group, S : ScaleOperations = + sum(data) / data.count() /** - * Returns an average value of elements in the sequence in this [Space]. + * Returns an average value of elements in the sequence in this [Group]. * * @receiver the algebra that provides addition and division. * @param data the sequence to find average. * @return the average value. * @author Iaroslav Postovalov */ -public fun Space.average(data: Sequence): T = sum(data) / data.count() +public fun S.average(data: Sequence): T where S : Group, S : ScaleOperations = + sum(data) / data.count() /** * Absolute of the comparable [value] */ -public fun > Space.abs(value: T): T = if (value > zero) value else -value +public fun > Group.abs(value: T): T = if (value > zero) value else -value /** * Returns the sum of all elements in the iterable in provided space. * * @receiver the collection to sum up. - * @param space the algebra that provides addition. + * @param group the algebra that provides addition. * @return the sum. */ -public fun Iterable.sumWith(space: Space): T = space.sum(this) +public fun Iterable.sumWith(group: Group): T = group.sum(this) /** * Returns the sum of all elements in the sequence in provided space. * * @receiver the collection to sum up. - * @param space the algebra that provides addition. + * @param group the algebra that provides addition. * @return the sum. */ -public fun Sequence.sumWith(space: Space): T = space.sum(this) +public fun Sequence.sumWith(group: Group): T = group.sum(this) /** - * Returns an average value of elements in the iterable in this [Space]. + * Returns an average value of elements in the iterable in this [Group]. * * @receiver the iterable to find average. * @param space the algebra that provides addition and division. * @return the average value. * @author Iaroslav Postovalov */ -public fun Iterable.averageWith(space: Space): T = space.average(this) +public fun Iterable.averageWith(space: S): T where S : Group, S : ScaleOperations = + space.average(this) /** - * Returns an average value of elements in the sequence in this [Space]. + * Returns an average value of elements in the sequence in this [Group]. * * @receiver the sequence to find average. * @param space the algebra that provides addition and division. * @return the average value. * @author Iaroslav Postovalov */ -public fun Sequence.averageWith(space: Space): T = space.average(this) +public fun Sequence.averageWith(space: S): T where S : Group, S : ScaleOperations = + space.average(this) //TODO optimized power operation 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 87% 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 a5c4cfff9..0101b058a 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 @@ -8,7 +8,6 @@ import kotlin.math.pow as kpow public interface ExtendedFieldOperations : FieldOperations, TrigonometricOperations, - HyperbolicOperations, PowerOperations, ExponentialOperations { public override fun tan(arg: T): T = sin(arg) / cos(arg) @@ -21,15 +20,15 @@ public interface ExtendedFieldOperations : TrigonometricOperations.ACOS_OPERATION -> ::acos TrigonometricOperations.ASIN_OPERATION -> ::asin TrigonometricOperations.ATAN_OPERATION -> ::atan - HyperbolicOperations.COSH_OPERATION -> ::cosh - HyperbolicOperations.SINH_OPERATION -> ::sinh - HyperbolicOperations.TANH_OPERATION -> ::tanh - HyperbolicOperations.ACOSH_OPERATION -> ::acosh - HyperbolicOperations.ASINH_OPERATION -> ::asinh - HyperbolicOperations.ATANH_OPERATION -> ::atanh PowerOperations.SQRT_OPERATION -> ::sqrt ExponentialOperations.EXP_OPERATION -> ::exp ExponentialOperations.LN_OPERATION -> ::ln + ExponentialOperations.COSH_OPERATION -> ::cosh + ExponentialOperations.SINH_OPERATION -> ::sinh + ExponentialOperations.TANH_OPERATION -> ::tanh + ExponentialOperations.ACOSH_OPERATION -> ::acosh + ExponentialOperations.ASINH_OPERATION -> ::asinh + ExponentialOperations.ATANH_OPERATION -> ::atanh else -> super.unaryOperationFunction(operation) } } @@ -37,18 +36,18 @@ public interface ExtendedFieldOperations : /** * Advanced Number-like field that implements basic operations. */ -public interface ExtendedField : ExtendedFieldOperations, Field, NumericAlgebra { - public override fun sinh(arg: T): T = (exp(arg) - exp(-arg)) / 2 - public override fun cosh(arg: T): T = (exp(arg) + exp(-arg)) / 2 +public interface ExtendedField : ExtendedFieldOperations, Field, NumericAlgebra, ScaleOperations { + public override fun sinh(arg: T): T = (exp(arg) - exp(-arg)) / 2.0 + public override fun cosh(arg: T): T = (exp(arg) + exp(-arg)) / 2.0 public override fun tanh(arg: T): T = (exp(arg) - exp(-arg)) / (exp(-arg) + exp(arg)) public override fun asinh(arg: T): T = ln(sqrt(arg * arg + one) + arg) public override fun acosh(arg: T): T = ln(arg + sqrt((arg - one) * (arg + one))) - public override fun atanh(arg: T): T = (ln(arg + one) - ln(one - arg)) / 2 + public override fun atanh(arg: T): T = (ln(arg + one) - ln(one - arg)) / 2.0 public override fun rightSideNumberOperationFunction(operation: String): (left: T, right: Number) -> T = when (operation) { PowerOperations.POW_OPERATION -> ::power - else -> super.rightSideNumberOperationFunction(operation) + else -> super.rightSideNumberOperationFunction(operation) } } @@ -56,28 +55,27 @@ public interface ExtendedField : ExtendedFieldOperations, Field, Numeri * A field for [Double] without boxing. Does not produce appropriate field element. */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER", "OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") -public object RealField : ExtendedField, Norm { - public override val zero: Double - get() = 0.0 - - public override val one: Double - get() = 1.0 +public object DoubleField : ExtendedField, Norm, ScaleOperations { + public override val zero: Double = 0.0 + public override val one: Double = 1.0 override fun number(value: Number): Double = value.toDouble() public override fun binaryOperationFunction(operation: String): (left: Double, right: Double) -> Double = when (operation) { PowerOperations.POW_OPERATION -> ::power - else -> super.binaryOperationFunction(operation) + else -> super.binaryOperationFunction(operation) } public override inline fun add(a: Double, b: Double): Double = a + b - public override inline fun multiply(a: Double, k: Number): Double = a * k.toDouble() +// public override inline fun multiply(a: Double, k: Number): Double = a * k.toDouble() +// override fun divide(a: Double, k: Number): Double = a / k.toDouble() public override inline fun multiply(a: Double, b: Double): Double = a * b - public override inline fun divide(a: Double, b: Double): Double = a / b + override fun scale(a: Double, value: Double): Double = a * value + public override inline fun sin(arg: Double): Double = kotlin.math.sin(arg) public override inline fun cos(arg: Double): Double = kotlin.math.cos(arg) public override inline fun tan(arg: Double): Double = kotlin.math.tan(arg) @@ -110,11 +108,8 @@ public object RealField : ExtendedField, Norm { */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER", "OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") public object FloatField : ExtendedField, Norm { - public override val zero: Float - get() = 0.0f - - public override val one: Float - get() = 1.0f + public override val zero: Float = 0.0f + public override val one: Float = 1.0f override fun number(value: Number): Float = value.toFloat() @@ -125,7 +120,7 @@ public object FloatField : ExtendedField, Norm { } public override inline fun add(a: Float, b: Float): Float = a + b - public override inline fun multiply(a: Float, k: Number): Float = a * k.toFloat() + override fun scale(a: Float, value: Double): Float = a * value.toFloat() public override inline fun multiply(a: Float, b: Float): Float = a * b @@ -170,12 +165,8 @@ public object IntRing : Ring, Norm, NumericAlgebra { get() = 1 override fun number(value: Number): Int = value.toInt() - public override inline fun add(a: Int, b: Int): Int = a + b - public override inline fun multiply(a: Int, k: Number): Int = k.toInt() * a - public override inline fun multiply(a: Int, b: Int): Int = a * b - public override inline fun norm(arg: Int): Int = abs(arg) public override inline fun Int.unaryMinus(): Int = -this @@ -196,12 +187,8 @@ public object ShortRing : Ring, Norm, NumericAlgebra get() = 1 override fun number(value: Number): Short = value.toShort() - public override inline fun add(a: Short, b: Short): Short = (a + b).toShort() - public override inline fun multiply(a: Short, k: Number): Short = (a * k.toShort()).toShort() - public override inline fun multiply(a: Short, b: Short): Short = (a * b).toShort() - public override fun norm(arg: Short): Short = if (arg > 0) arg else (-arg).toShort() public override inline fun Short.unaryMinus(): Short = (-this).toShort() @@ -222,12 +209,8 @@ public object ByteRing : Ring, Norm, NumericAlgebra { get() = 1 override fun number(value: Number): Byte = value.toByte() - public override inline fun add(a: Byte, b: Byte): Byte = (a + b).toByte() - public override inline fun multiply(a: Byte, k: Number): Byte = (a * k.toByte()).toByte() - public override inline fun multiply(a: Byte, b: Byte): Byte = (a * b).toByte() - public override fun norm(arg: Byte): Byte = if (arg > 0) arg else (-arg).toByte() public override inline fun Byte.unaryMinus(): Byte = (-this).toByte() @@ -248,12 +231,8 @@ public object LongRing : Ring, Norm, NumericAlgebra { get() = 1L override fun number(value: Number): Long = value.toLong() - public override inline fun add(a: Long, b: Long): Long = a + b - public override inline fun multiply(a: Long, k: Number): Long = a * k.toLong() - public override inline fun multiply(a: Long, b: Long): Long = a * b - public override fun norm(arg: Long): Long = abs(arg) public override inline fun Long.unaryMinus(): Long = (-this) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt similarity index 100% rename from kmath-core/src/commonMain/kotlin/kscience/kmath/structures/Buffer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt 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 80% 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 3c53d6c51..6666c88b4 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,9 +1,9 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures -import kscience.kmath.nd.DefaultStrides -import kscience.kmath.nd.NDStructure -import kscience.kmath.nd.Structure2D -import kscience.kmath.nd.as2D +import space.kscience.kmath.nd.DefaultStrides +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.nd.as2D /** * A context that allows to operate on a [MutableBuffer] as on 2d array @@ -13,10 +13,10 @@ internal class BufferAccessor2D( public val colNum: Int, val factory: MutableBufferFactory, ) { - public operator fun Buffer.get(i: Int, j: Int): T = get(i + colNum * j) + public operator fun Buffer.get(i: Int, j: Int): T = get(i * colNum + j) public operator fun MutableBuffer.set(i: Int, j: Int, value: T) { - set(i + colNum * j, value) + set(i * colNum + j, value) } public inline fun create(crossinline init: (i: Int, j: Int) -> T): MutableBuffer = @@ -25,7 +25,7 @@ internal class BufferAccessor2D( public fun create(mat: Structure2D): MutableBuffer = create { i, j -> mat[i, j] } //TODO optimize wrapper - public fun MutableBuffer.collect(): Structure2D = NDStructure.build( + public fun MutableBuffer.collect(): Structure2D = StructureND.buffered( DefaultStrides(intArrayOf(rowNum, colNum)), factory ) { (i, j) -> diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBuffer.kt new file mode 100644 index 000000000..0a23d31fe --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBuffer.kt @@ -0,0 +1,56 @@ +package space.kscience.kmath.structures + +/** + * Specialized [MutableBuffer] implementation over [DoubleArray]. + * + * @property array the underlying array. + */ +@Suppress("OVERRIDE_BY_INLINE") +public inline class DoubleBuffer(public val array: DoubleArray) : MutableBuffer { + override val size: Int get() = array.size + + override operator fun get(index: Int): Double = array[index] + + override operator fun set(index: Int, value: Double) { + array[index] = value + } + + override operator fun iterator(): DoubleIterator = array.iterator() + + override fun copy(): DoubleBuffer = DoubleBuffer(array.copyOf()) +} + +/** + * Creates a new [DoubleBuffer] 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 buffer element given its index. + */ +public inline fun DoubleBuffer(size: Int, init: (Int) -> Double): DoubleBuffer = DoubleBuffer(DoubleArray(size) { init(it) }) + +/** + * Returns a new [DoubleBuffer] of given elements. + */ +public fun DoubleBuffer(vararg doubles: Double): DoubleBuffer = DoubleBuffer(doubles) + +/** + * Simplified [DoubleBuffer] to array comparison + */ +public fun DoubleBuffer.contentEquals(vararg doubles: Double): Boolean = array.contentEquals(doubles) + +/** + * Returns a new [DoubleArray] containing all of the elements of this [Buffer]. + */ +public fun Buffer.toDoubleArray(): DoubleArray = when (this) { + is DoubleBuffer -> array.copyOf() + else -> DoubleArray(size, ::get) +} + +/** + * Returns [DoubleBuffer] over this array. + * + * @receiver the array. + * @return the new buffer. + */ +public fun DoubleArray.asBuffer(): DoubleBuffer = DoubleBuffer(this) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt new file mode 100644 index 000000000..4a85219ac --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt @@ -0,0 +1,272 @@ +package space.kscience.kmath.structures + +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.ExtendedFieldOperations +import kotlin.math.* + +/** + * [ExtendedFieldOperations] over [DoubleBuffer]. + */ +public object DoubleBufferFieldOperations : ExtendedFieldOperations> { + override fun Buffer.unaryMinus(): DoubleBuffer = if (this is DoubleBuffer) { + DoubleBuffer(size) { -array[it] } + } else { + DoubleBuffer(size) { -get(it) } + } + + public override fun add(a: Buffer, b: Buffer): DoubleBuffer { + require(b.size == a.size) { + "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " + } + + return if (a is DoubleBuffer && b is DoubleBuffer) { + val aArray = a.array + val bArray = b.array + DoubleBuffer(DoubleArray(a.size) { aArray[it] + bArray[it] }) + } else DoubleBuffer(DoubleArray(a.size) { a[it] + b[it] }) + } +// +// public override fun multiply(a: Buffer, k: Number): RealBuffer { +// val kValue = k.toDouble() +// +// return if (a is RealBuffer) { +// val aArray = a.array +// RealBuffer(DoubleArray(a.size) { aArray[it] * kValue }) +// } else RealBuffer(DoubleArray(a.size) { a[it] * kValue }) +// } +// +// public override fun divide(a: Buffer, k: Number): RealBuffer { +// val kValue = k.toDouble() +// +// return if (a is RealBuffer) { +// val aArray = a.array +// RealBuffer(DoubleArray(a.size) { aArray[it] / kValue }) +// } else RealBuffer(DoubleArray(a.size) { a[it] / kValue }) +// } + + public override fun multiply(a: Buffer, b: Buffer): DoubleBuffer { + require(b.size == a.size) { + "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " + } + + return if (a is DoubleBuffer && b is DoubleBuffer) { + val aArray = a.array + val bArray = b.array + DoubleBuffer(DoubleArray(a.size) { aArray[it] * bArray[it] }) + } else + DoubleBuffer(DoubleArray(a.size) { a[it] * b[it] }) + } + + public override fun divide(a: Buffer, b: Buffer): DoubleBuffer { + require(b.size == a.size) { + "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " + } + + return if (a is DoubleBuffer && b is DoubleBuffer) { + val aArray = a.array + val bArray = b.array + DoubleBuffer(DoubleArray(a.size) { aArray[it] / bArray[it] }) + } else DoubleBuffer(DoubleArray(a.size) { a[it] / b[it] }) + } + + public override fun sin(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { sin(array[it]) }) + } else DoubleBuffer(DoubleArray(arg.size) { sin(arg[it]) }) + + public override fun cos(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { cos(array[it]) }) + } else DoubleBuffer(DoubleArray(arg.size) { cos(arg[it]) }) + + public override fun tan(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { tan(array[it]) }) + } else DoubleBuffer(DoubleArray(arg.size) { tan(arg[it]) }) + + public override fun asin(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { asin(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { asin(arg[it]) }) + + public override fun acos(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { acos(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { acos(arg[it]) }) + + public override fun atan(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { atan(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { atan(arg[it]) }) + + public override fun sinh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { sinh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { sinh(arg[it]) }) + + public override fun cosh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { cosh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { cosh(arg[it]) }) + + public override fun tanh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { tanh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { tanh(arg[it]) }) + + public override fun asinh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { asinh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { asinh(arg[it]) }) + + public override fun acosh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { acosh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { acosh(arg[it]) }) + + public override fun atanh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { atanh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { atanh(arg[it]) }) + + public override fun power(arg: Buffer, pow: Number): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { array[it].pow(pow.toDouble()) }) + } else + DoubleBuffer(DoubleArray(arg.size) { arg[it].pow(pow.toDouble()) }) + + public override fun exp(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { exp(array[it]) }) + } else DoubleBuffer(DoubleArray(arg.size) { exp(arg[it]) }) + + public override fun ln(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { ln(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { ln(arg[it]) }) +} + +/** + * [ExtendedField] over [DoubleBuffer]. + * + * @property size the size of buffers to operate on. + */ +public class DoubleBufferField(public val size: Int) : ExtendedField> { + public override val zero: Buffer by lazy { DoubleBuffer(size) { 0.0 } } + public override val one: Buffer by lazy { DoubleBuffer(size) { 1.0 } } + + override fun number(value: Number): Buffer = DoubleBuffer(size) { value.toDouble() } + + override fun Buffer.unaryMinus(): Buffer = DoubleBufferFieldOperations.run { + -this@unaryMinus + } + + public override fun add(a: Buffer, b: Buffer): DoubleBuffer { + require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } + return DoubleBufferFieldOperations.add(a, b) + } + + public override fun scale(a: Buffer, value: Double): DoubleBuffer { + require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } + + return if (a is DoubleBuffer) { + val aArray = a.array + DoubleBuffer(DoubleArray(a.size) { aArray[it] * value }) + } else DoubleBuffer(DoubleArray(a.size) { a[it] * value }) + } + + public override fun multiply(a: Buffer, b: Buffer): DoubleBuffer { + require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } + return DoubleBufferFieldOperations.multiply(a, b) + } + + public override fun divide(a: Buffer, b: Buffer): DoubleBuffer { + require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } + return DoubleBufferFieldOperations.divide(a, b) + } + + public override fun sin(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.sin(arg) + } + + public override fun cos(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.cos(arg) + } + + public override fun tan(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.tan(arg) + } + + public override fun asin(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.asin(arg) + } + + public override fun acos(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.acos(arg) + } + + public override fun atan(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.atan(arg) + } + + public override fun sinh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.sinh(arg) + } + + public override fun cosh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.cosh(arg) + } + + public override fun tanh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.tanh(arg) + } + + public override fun asinh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.asinh(arg) + } + + public override fun acosh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.acosh(arg) + } + + public override fun atanh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.atanh(arg) + } + + public override fun power(arg: Buffer, pow: Number): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.power(arg, pow) + } + + public override fun exp(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.exp(arg) + } + + public override fun ln(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.ln(arg) + } +} 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 88% 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..670a0c175 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 @@ -48,7 +48,7 @@ public fun FlaggedBuffer<*>.isMissing(index: Int): Boolean = hasFlag(index, Valu /** * A real buffer which supports flags for each value like NaN or Missing */ -public class FlaggedRealBuffer(public val values: DoubleArray, public val flags: ByteArray) : FlaggedBuffer, +public class FlaggedDoubleBuffer(public val values: DoubleArray, public val flags: ByteArray) : FlaggedBuffer, Buffer { init { require(values.size == flags.size) { "Values and flags must have the same dimensions" } @@ -65,7 +65,7 @@ public class FlaggedRealBuffer(public val values: DoubleArray, public val flags: }.iterator() } -public inline fun FlaggedRealBuffer.forEachValid(block: (Double) -> Unit) { +public inline fun FlaggedDoubleBuffer.forEachValid(block: (Double) -> Unit) { indices .asSequence() .filter(::isValid) 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 83% 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..5c4ec3b05 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]. @@ -36,10 +36,12 @@ public inline fun FloatBuffer(size: Int, init: (Int) -> Float): FloatBuffer = Fl public fun FloatBuffer(vararg floats: Float): FloatBuffer = FloatBuffer(floats) /** - * Returns a [FloatArray] containing all of the elements of this [MutableBuffer]. + * Returns a new [FloatArray] containing all of the elements of this [Buffer]. */ -public val MutableBuffer.array: FloatArray - get() = (if (this is FloatBuffer) array else FloatArray(size) { get(it) }) +public fun Buffer.toFloatArray(): FloatArray = when (this) { + is FloatBuffer -> array.copyOf() + else -> FloatArray(size, ::get) +} /** * Returns [FloatBuffer] over this array. 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 83% 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..32dfcf9aa 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]. @@ -35,10 +35,12 @@ public inline fun IntBuffer(size: Int, init: (Int) -> Int): IntBuffer = IntBuffe public fun IntBuffer(vararg ints: Int): IntBuffer = IntBuffer(ints) /** - * Returns a [IntArray] containing all of the elements of this [MutableBuffer]. + * Returns a new [IntArray] containing all of the elements of this [Buffer]. */ -public val MutableBuffer.array: IntArray - get() = (if (this is IntBuffer) array else IntArray(size) { get(it) }) +public fun Buffer.toIntArray(): IntArray = when (this) { + is IntBuffer -> array.copyOf() + else -> IntArray(size, ::get) +} /** * Returns [IntBuffer] over this array. 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 83% 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..48b1d7a7b 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]. @@ -35,10 +35,12 @@ public inline fun LongBuffer(size: Int, init: (Int) -> Long): LongBuffer = LongB public fun LongBuffer(vararg longs: Long): LongBuffer = LongBuffer(longs) /** - * Returns a [IntArray] containing all of the elements of this [MutableBuffer]. + * Returns a new [LongArray] containing all of the elements of this [Buffer]. */ -public val MutableBuffer.array: LongArray - get() = (if (this is LongBuffer) array else LongArray(size) { get(it) }) +public fun Buffer.toLongArray(): LongArray = when (this) { + is LongBuffer -> array.copyOf() + else -> LongArray(size, ::get) +} /** * Returns [LongBuffer] over this array. 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 93% 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 3a98ce941..50a2db590 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. @@ -24,7 +24,7 @@ public open class MemoryBuffer(protected val memory: Memory, protected public inline fun create( spec: MemorySpec, size: Int, - initializer: (Int) -> T + initializer: (Int) -> T, ): MemoryBuffer = MutableMemoryBuffer(Memory.allocate(size * spec.objectSize), spec).also { buffer -> (0 until size).forEach { buffer[it] = initializer(it) } } @@ -53,7 +53,7 @@ public class MutableMemoryBuffer(memory: Memory, spec: MemorySpec) : public inline fun create( spec: MemorySpec, size: Int, - initializer: (Int) -> T + initializer: (Int) -> T, ): MutableMemoryBuffer = MutableMemoryBuffer(Memory.allocate(size * spec.objectSize), spec).also { buffer -> (0 until size).forEach { buffer[it] = initializer(it) } } 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 83% 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..7832bb863 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]. @@ -33,10 +33,12 @@ public inline fun ShortBuffer(size: Int, init: (Int) -> Short): ShortBuffer = Sh public fun ShortBuffer(vararg shorts: Short): ShortBuffer = ShortBuffer(shorts) /** - * Returns a [ShortArray] containing all of the elements of this [MutableBuffer]. + * Returns a new [ShortArray] containing all of the elements of this [Buffer]. */ -public val MutableBuffer.array: ShortArray - get() = (if (this is ShortBuffer) array else ShortArray(size) { get(it) }) +public fun Buffer.toShortArray(): ShortArray = when (this) { + is ShortBuffer -> array.copyOf() + else -> ShortArray(size, ::get) +} /** * Returns [ShortBuffer] over this array. diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferOperation.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferOperation.kt new file mode 100644 index 000000000..5f8bbe21f --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferOperation.kt @@ -0,0 +1,93 @@ +package space.kscience.kmath.structures + +import space.kscience.kmath.misc.UnstableKMathAPI + +/** + * Typealias for buffer transformations. + */ +public typealias BufferTransform = (Buffer) -> Buffer + +/** + * Typealias for buffer transformations with suspend function. + */ +public typealias SuspendBufferTransform = suspend (Buffer) -> Buffer + + +/** + * Creates a sequence that returns all elements from this [Buffer]. + */ +public fun Buffer.asSequence(): Sequence = Sequence(::iterator) + +/** + * Creates an iterable that returns all elements from this [Buffer]. + */ +public fun Buffer.asIterable(): Iterable = Iterable(::iterator) + +/** + * Returns a new [List] containing all elements of this buffer. + */ +public fun Buffer.toList(): List = when (this) { + is ArrayBuffer -> array.toList() + is ListBuffer -> list.toList() + is MutableListBuffer -> list.toList() + else -> asSequence().toList() +} + +/** + * Returns a new [MutableList] filled with all elements of this buffer. + * **NOTE:** this method uses a protective copy, so it should not be used in performance-critical code. + */ +@UnstableKMathAPI +public fun Buffer.toMutableList(): MutableList = when (this) { + is ArrayBuffer -> array.toMutableList() + is ListBuffer -> list.toMutableList() + is MutableListBuffer -> list.toMutableList() + else -> MutableList(size, ::get) +} + +/** + * Returns a new [Array] containing all elements of this buffer. + * **NOTE:** this method uses a protective copy, so it should not be used in performance-critical code. + */ +@UnstableKMathAPI +public inline fun Buffer.toTypedArray(): Array = Array(size, ::get) + +/** + * Create a new buffer from this one with the given mapping function. + * Provided [BufferFactory] is used to construct the new buffer. + */ +public inline fun Buffer.map( + bufferFactory: BufferFactory = Buffer.Companion::auto, + crossinline block: (T) -> R, +): Buffer = bufferFactory(size) { block(get(it)) } + +/** + * Create a new buffer from this one with the given indexed mapping function. + * Provided [BufferFactory] is used to construct the new buffer. + */ +public inline fun Buffer.mapIndexed( + bufferFactory: BufferFactory = Buffer.Companion::auto, + crossinline block: (index: Int, value: T) -> R, +): Buffer = bufferFactory(size) { block(it, get(it)) } + +/** + * Fold given buffer according to [operation] + */ +public inline fun Buffer.fold(initial: R, operation: (acc: R, T) -> R): R { + var accumulator = initial + for (index in this.indices) accumulator = operation(accumulator, get(index)) + return accumulator +} + +/** + * Zip two buffers using given [transform]. + */ +@UnstableKMathAPI +public inline fun Buffer.zip( + other: Buffer, + bufferFactory: BufferFactory = Buffer.Companion::auto, + crossinline transform: (T1, T2) -> R, +): Buffer { + require(size == other.size) { "Buffer size mismatch in zip: expected $size but found ${other.size}" } + return bufferFactory(size) { transform(get(it), other[it]) } +} \ No newline at end of file diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/linear/RealLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/kscience/kmath/linear/RealLUSolverTest.kt deleted file mode 100644 index b22da96dd..000000000 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/linear/RealLUSolverTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package kscience.kmath.linear - -import kotlin.test.Test -import kotlin.test.assertEquals - -class RealLUSolverTest { - - @Test - fun testInvertOne() { - val matrix = MatrixContext.real.one(2, 2) - val inverted = MatrixContext.real.inverseWithLup(matrix) - assertEquals(matrix, inverted) - } - - @Test - fun testDecomposition() { - val matrix = Matrix.square( - 3.0, 1.0, - 1.0, 3.0 - ) - - MatrixContext.real.run { - val lup = lup(matrix) - - //Check determinant - assertEquals(8.0, lup.determinant) - - assertEquals(lup.p dot matrix, lup.l dot lup.u) - } - } - - @Test - fun testInvert() { - val matrix = Matrix.square( - 3.0, 1.0, - 1.0, 3.0 - ) - - val inverted = MatrixContext.real.inverseWithLup(matrix) - - val expected = Matrix.square( - 0.375, -0.125, - -0.125, 0.375 - ) - - assertEquals(expected, inverted) - } -} diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/RealFieldTest.kt b/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/RealFieldTest.kt deleted file mode 100644 index 93f72413e..000000000 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/RealFieldTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package kscience.kmath.operations - -import kscience.kmath.testutils.FieldVerifier -import kotlin.test.Test -import kotlin.test.assertEquals - -internal class RealFieldTest { - @Test - fun verify() = FieldVerifier(RealField, 42.0, 66.0, 2.0, 5).verify() - - @Test - fun testSqrt() { - val sqrt = RealField { sqrt(25 * one) } - assertEquals(5.0, sqrt) - } -} 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 1c0d5a555..000000000 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/NDFieldTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package kscience.kmath.structures - -import kscience.kmath.nd.NDAlgebra -import kscience.kmath.nd.get -import kscience.kmath.nd.real -import kscience.kmath.testutils.FieldVerifier -import kotlin.test.Test -import kotlin.test.assertEquals -import kscience.kmath.operations.invoke - -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/kscience/kmath/expressions/ExpressionFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/ExpressionFieldTest.kt similarity index 67% 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 0d31c8691..61b1d03f0 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,7 +1,8 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke +import space.kscience.kmath.misc.symbol +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.invoke import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFails @@ -11,9 +12,7 @@ class ExpressionFieldTest { @Test fun testExpression() { - val context = FunctionalExpressionField(RealField) - - val expression = context { + val expression = FunctionalExpressionField(DoubleField).invoke { val x by binding() x * x + 2 * x + one } @@ -29,7 +28,7 @@ class ExpressionFieldTest { return x * x + 2 * x + one } - val expression = FunctionalExpressionField(RealField).expression() + val expression = FunctionalExpressionField(DoubleField).expression() assertEquals(expression(x to 1.0), 4.0) } @@ -40,7 +39,7 @@ class ExpressionFieldTest { x * x + 2 * x + one } - val expression = FunctionalExpressionField(RealField).expressionBuilder() + val expression = FunctionalExpressionField(DoubleField).expressionBuilder() assertEquals(expression(x to 1.0), 4.0) } } 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 84% 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..666db13d8 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,10 @@ -package kscience.kmath.expressions +package space.kscience.kmath.expressions -import kscience.kmath.operations.RealField -import kscience.kmath.structures.asBuffer +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.misc.symbol +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asBuffer import kotlin.math.E import kotlin.math.PI import kotlin.math.pow @@ -14,19 +17,19 @@ class SimpleAutoDiffTest { fun dx( xBinding: Pair, - body: SimpleAutoDiffField.(x: AutoDiffValue) -> AutoDiffValue, - ): DerivationResult = RealField.simpleAutoDiff(xBinding) { body(bind(xBinding.first)) } + body: SimpleAutoDiffField.(x: AutoDiffValue) -> AutoDiffValue, + ): DerivationResult = DoubleField.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: SimpleAutoDiffField.(x: AutoDiffValue, y: AutoDiffValue) -> AutoDiffValue, + ): DerivationResult = DoubleField.simpleAutoDiff(xBinding, yBinding) { + body(bindSymbol(xBinding.first), bindSymbol(yBinding.first)) } - fun diff(block: SimpleAutoDiffField.() -> AutoDiffValue): SimpleAutoDiffExpression { - return SimpleAutoDiffExpression(RealField, block) + fun diff(block: SimpleAutoDiffField.() -> AutoDiffValue): SimpleAutoDiffExpression { + return SimpleAutoDiffExpression(DoubleField, block) } val x by symbol @@ -35,9 +38,9 @@ class SimpleAutoDiffTest { @Test fun testPlusX2() { - val y = RealField.simpleAutoDiff(x to 3.0) { + val y = DoubleField.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 +50,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 @@ -58,9 +61,9 @@ class SimpleAutoDiffTest { @Test 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 z = DoubleField.simpleAutoDiff(x to 2.0, y to 3.0) { + val x = bindSymbol(x) + val y = bindSymbol(y) x + y } assertEquals(5.0, z.value) // z = x + y = 5 @@ -71,9 +74,9 @@ class SimpleAutoDiffTest { @Test 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 z = DoubleField.simpleAutoDiff(x to 7.0, y to 3.0) { + val x = bindSymbol(x) + val y = bindSymbol(y) x - y } @@ -276,7 +279,7 @@ class SimpleAutoDiffTest { fun testDivGrad() { val res = dxy(x to 1.0, y to 2.0) { x, y -> x * x + y * y } assertEquals(6.0, res.div()) - assertTrue(res.grad(x, y).contentEquals(doubleArrayOf(2.0, 4.0).asBuffer())) + assertTrue(Buffer.contentEquals(res.grad(x, y), doubleArrayOf(2.0, 4.0).asBuffer())) } private fun assertApprox(a: Double, b: Double) { diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt new file mode 100644 index 000000000..445aadd97 --- /dev/null +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt @@ -0,0 +1,56 @@ +package space.kscience.kmath.linear + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.StructureND +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +fun assertMatrixEquals(expected: StructureND, actual: StructureND) { + assertTrue { StructureND.contentEquals(expected, actual) } +} + +@UnstableKMathAPI +class DoubleLUSolverTest { + + @Test + fun testInvertOne() { + val matrix = LinearSpace.real.one(2, 2) + val inverted = LinearSpace.real.inverseWithLup(matrix) + assertMatrixEquals(matrix, inverted) + } + + @Test + fun testDecomposition() { + LinearSpace.real.run { + val matrix = matrix(2, 2)( + 3.0, 1.0, + 2.0, 3.0 + ) + + val lup = lup(matrix) + + //Check determinant + assertEquals(7.0, lup.determinant) + + assertMatrixEquals(lup.p dot matrix, lup.l dot lup.u) + } + } + + @Test + fun testInvert() { + val matrix = LinearSpace.real.matrix(2, 2)( + 3.0, 1.0, + 1.0, 3.0 + ) + + val inverted = LinearSpace.real.inverseWithLup(matrix) + + val expected = LinearSpace.real.matrix(2, 2)( + 0.375, -0.125, + -0.125, 0.375 + ) + + assertMatrixEquals(expected, inverted) + } +} 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 69% 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 a0ac92172..fd6fb320b 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,23 +1,25 @@ -package kscience.kmath.linear +package space.kscience.kmath.linear -import kscience.kmath.nd.NDStructure -import kscience.kmath.nd.as2D -import kscience.kmath.operations.invoke +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.nd.as2D import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue +@UnstableKMathAPI @Suppress("UNUSED_VARIABLE") class MatrixTest { @Test fun testTranspose() { - val matrix = MatrixContext.real.one(3, 3) + val matrix = LinearSpace.real.one(3, 3) val transposed = matrix.transpose() - assertEquals(matrix, transposed) + assertTrue { StructureND.contentEquals(matrix, transposed) } } @Test fun testBuilder() { - val matrix = Matrix.build(2, 3)( + val matrix = LinearSpace.real.matrix(2, 3)( 1.0, 0.0, 0.0, 0.0, 1.0, 2.0 ) @@ -39,7 +41,7 @@ class MatrixTest { infix fun Matrix.pow(power: Int): Matrix { var res = this repeat(power - 1) { - res = RealMatrixContext.invoke { res dot this@pow } + res = LinearSpace.real.run { res dot this@pow } } return res } @@ -49,10 +51,10 @@ class MatrixTest { @Test fun test2DDot() { - val firstMatrix = NDStructure.auto(2, 3) { (i, j) -> (i + j).toDouble() }.as2D() - val secondMatrix = NDStructure.auto(3, 2) { (i, j) -> (i + j).toDouble() }.as2D() + val firstMatrix = StructureND.auto(2, 3) { (i, j) -> (i + j).toDouble() }.as2D() + val secondMatrix = StructureND.auto(3, 2) { (i, j) -> (i + j).toDouble() }.as2D() - MatrixContext.real.run { + LinearSpace.real.run { // val firstMatrix = produce(2, 3) { i, j -> (i + j).toDouble() } // val secondMatrix = produce(3, 2) { i, j -> (i + j).toDouble() } val result = firstMatrix dot secondMatrix 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 f81bd7e67..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.testutils.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/space/kscience/kmath/operations/DoubleFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/DoubleFieldTest.kt new file mode 100644 index 000000000..fde4f4a9e --- /dev/null +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/DoubleFieldTest.kt @@ -0,0 +1,16 @@ +package space.kscience.kmath.operations + +import space.kscience.kmath.testutils.FieldVerifier +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class DoubleFieldTest { + @Test + fun verify() = FieldVerifier(DoubleField, 42.0, 66.0, 2.0, 5).verify() + + @Test + fun testSqrt() { + val sqrt = DoubleField { sqrt(25 * one) } + assertEquals(5.0, sqrt) + } +} 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..b282ee9f5 --- /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.AlgebraND +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() { + (AlgebraND.real(12, 32)) { FieldVerifier(this, one + 3, one - 23, one * 12, 6.66) } + } + + @Test + fun testStrides() { + val ndArray = AlgebraND.real(10, 10).produce { (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/space/kscience/kmath/structures/NumberNDFieldTest.kt similarity index 74% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/structures/NumberNDFieldTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt index 4a533f38c..376415a56 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/structures/NumberNDFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt @@ -1,8 +1,9 @@ -package kscience.kmath.structures +package space.kscience.kmath.structures -import kscience.kmath.nd.* -import kscience.kmath.operations.Norm -import kscience.kmath.operations.invoke +import space.kscience.kmath.linear.LinearSpace +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 @@ -10,7 +11,7 @@ import kotlin.test.assertEquals @Suppress("UNUSED_VARIABLE") class NumberNDFieldTest { - val algebra = NDAlgebra.real(3,3) + val algebra = AlgebraND.real(3, 3) val array1 = algebra.produce { (i, j) -> (i + j).toDouble() } val array2 = algebra.produce { (i, j) -> (i - j).toDouble() } @@ -33,7 +34,9 @@ class NumberNDFieldTest { @Test fun testGeneration() { - val array = Structure2D.real(3, 3) { i, j -> (i * 10 + j).toDouble() } + val array = LinearSpace.real.buildMatrix(3, 3) { i, j -> + (i * 10 + j).toDouble() + } for (i in 0..2) for (j in 0..2) { @@ -65,15 +68,15 @@ class NumberNDFieldTest { val division = array1.combine(array2, Double::div) } - object L2Norm : Norm, Double> { - override fun norm(arg: NDStructure): Double = + object L2Norm : Norm, Double> { + override fun norm(arg: StructureND): 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) } } + (AlgebraND.real(*array1.shape)) { with(L2Norm) { 1 + norm(array1) + exp(array2) } } } } } diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/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/testutils/AlgebraicVerifier.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/AlgebraicVerifier.kt index dea4697e7..7474aae8f 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/AlgebraicVerifier.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/AlgebraicVerifier.kt @@ -1,6 +1,6 @@ -package kscience.kmath.testutils +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/testutils/FieldVerifier.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/FieldVerifier.kt similarity index 79% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/FieldVerifier.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/FieldVerifier.kt index 4fe134fe5..cdb0a7c5d 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/FieldVerifier.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/FieldVerifier.kt @@ -1,12 +1,13 @@ -package kscience.kmath.testutils +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 -internal class FieldVerifier(override val algebra: Field, a: T, b: T, c: T, x: Number) : - RingVerifier(algebra, a, b, c, x) { +internal class FieldVerifier>( + algebra: A, a: T, b: T, c: T, x: Number, +) : RingVerifier(algebra, a, b, c, x) { override fun verify() { super.verify() diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/RingVerifier.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/RingVerifier.kt similarity index 80% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/RingVerifier.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/RingVerifier.kt index 2149c6ec0..6970c8ac7 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/RingVerifier.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/RingVerifier.kt @@ -1,11 +1,13 @@ -package kscience.kmath.testutils +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.ScaleOperations +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) : - SpaceVerifier(algebra, a, b, c, x) { +internal open class RingVerifier(algebra: A, a: T, b: T, c: T, x: Number) : + SpaceVerifier(algebra, a, b, c, x) where A : Ring, A : ScaleOperations { + override fun verify() { super.verify() diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/SpaceVerifier.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/SpaceVerifier.kt similarity index 79% rename from kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/SpaceVerifier.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/SpaceVerifier.kt index 4282dad2f..a9cd4454c 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/testutils/SpaceVerifier.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/testutils/SpaceVerifier.kt @@ -1,18 +1,18 @@ -package kscience.kmath.testutils +package space.kscience.kmath.testutils -import kscience.kmath.operations.Space -import kscience.kmath.operations.invoke +import space.kscience.kmath.operations.Group +import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.operations.invoke import kotlin.test.assertEquals import kotlin.test.assertNotEquals -internal open class SpaceVerifier( - override val algebra: Space, +internal open class SpaceVerifier( + override val algebra: S, val a: T, val b: T, val c: T, - val x: Number -) : - AlgebraicVerifier> { + val x: Number, +) : AlgebraicVerifier> where S : Group, S : ScaleOperations { override fun verify() { algebra { assertEquals(a + b + c, a + (b + c), "Addition in $algebra is not associative.") 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 76% 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..0ac0ba1c5 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 @@ -7,19 +7,16 @@ import java.math.MathContext /** * A field over [BigInteger]. */ -public object JBigIntegerField : Field, NumericAlgebra { - public override val zero: BigInteger - get() = BigInteger.ZERO +public object JBigIntegerField : Ring, NumericAlgebra { + public override val zero: BigInteger get() = BigInteger.ZERO - public override val one: BigInteger - get() = BigInteger.ONE + public override val one: BigInteger get() = BigInteger.ONE public override fun number(value: Number): BigInteger = BigInteger.valueOf(value.toLong()) - public override fun divide(a: BigInteger, b: BigInteger): BigInteger = a.div(b) public override fun add(a: BigInteger, b: BigInteger): BigInteger = a.add(b) public override operator fun BigInteger.minus(b: BigInteger): BigInteger = subtract(b) - public override fun multiply(a: BigInteger, k: Number): BigInteger = a.multiply(k.toInt().toBigInteger()) public override fun multiply(a: BigInteger, b: BigInteger): BigInteger = a.multiply(b) + public override operator fun BigInteger.unaryMinus(): BigInteger = negate() } @@ -30,7 +27,7 @@ public object JBigIntegerField : Field, NumericAlgebra { */ public abstract class JBigDecimalFieldBase internal constructor( private val mathContext: MathContext = MathContext.DECIMAL64, -) : Field, PowerOperations, NumericAlgebra { +) : Field, PowerOperations, NumericAlgebra, ScaleOperations { public override val zero: BigDecimal get() = BigDecimal.ZERO @@ -41,8 +38,8 @@ public abstract class JBigDecimalFieldBase internal constructor( public override operator fun BigDecimal.minus(b: BigDecimal): BigDecimal = subtract(b) public override fun number(value: Number): BigDecimal = BigDecimal.valueOf(value.toDouble()) - public override fun multiply(a: BigDecimal, k: Number): BigDecimal = - a.multiply(k.toDouble().toBigDecimal(mathContext), mathContext) + public override fun scale(a: BigDecimal, value: Double): BigDecimal = + a.multiply(value.toBigDecimal(mathContext), mathContext) public override fun multiply(a: BigDecimal, b: BigDecimal): BigDecimal = a.multiply(b, mathContext) public override fun divide(a: BigDecimal, b: BigDecimal): BigDecimal = a.divide(b, mathContext) diff --git a/kmath-coroutines/build.gradle.kts b/kmath-coroutines/build.gradle.kts index 1f436a54b..b68dd2e8d 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 { @@ -18,6 +18,6 @@ kotlin.sourceSets { } } -readme{ +readme { maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL } \ No newline at end of file diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt new file mode 100644 index 000000000..ba6adf35b --- /dev/null +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt @@ -0,0 +1,12 @@ +package space.kscience.kmath.chains + +/** + * Performance optimized chain for real values + */ +public abstract class BlockingDoubleChain : Chain { + public abstract fun nextDouble(): Double + + override suspend fun next(): Double = nextDouble() + + public open fun nextBlock(size: Int): DoubleArray = DoubleArray(size) { nextDouble() } +} 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 86% 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 766311fc3..fb2e453ad 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/Chain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt similarity index 97% 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 703274e3c..a961f2e09 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 @@ -81,7 +81,7 @@ public class StatefulChain( private val state: S, private val seed: S.() -> R, private val forkState: ((S) -> S), - private val gen: suspend S.(R) -> R + private val gen: suspend S.(R) -> R, ) : Chain { private val mutex: Mutex = Mutex() private var value: R? = null @@ -141,7 +141,7 @@ public fun Chain.collect(mapper: suspend (Chain) -> R): Chain = public fun Chain.collectWithState( state: S, stateFork: (S) -> S, - mapper: suspend S.(Chain) -> R + mapper: suspend S.(Chain) -> R, ): Chain = object : Chain { override suspend fun next(): R = state.mapper(this@collectWithState) 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 50% 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..7d4914a01 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,20 +1,20 @@ -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.Group +import space.kscience.kmath.operations.GroupOperations +import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.operations.invoke + +public fun Flow.cumulativeSum(group: GroupOperations): Flow = + group { runningReduce { sum, element -> sum + element } } @ExperimentalCoroutinesApi -public fun Flow.cumulativeSum(space: SpaceOperations): Flow = - space { runningReduce { sum, element -> sum + element } } - -@ExperimentalCoroutinesApi -public fun Flow.mean(space: Space): Flow = space { +public fun Flow.mean(space: S): Flow where S : Group, S : ScaleOperations = space { data class Accumulator(var sum: T, var num: Int) scan(Accumulator(zero, 0)) { sum, element -> 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 93% 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..7a3a52657 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 @@ -27,7 +27,7 @@ public class AsyncFlow internal constructor(internal val deferredFlow: Flow Flow.async( dispatcher: CoroutineDispatcher = Dispatchers.Default, - block: suspend CoroutineScope.(T) -> R + block: suspend CoroutineScope.(T) -> R, ): AsyncFlow { val flow = map { LazyDeferred(dispatcher) { block(it) } } return AsyncFlow(flow) @@ -72,12 +72,12 @@ public suspend fun AsyncFlow.collect(concurrency: Int, collector: FlowCol public suspend inline fun AsyncFlow.collect( concurrency: Int, - crossinline action: suspend (value: T) -> Unit + crossinline action: suspend (value: T) -> Unit, ): Unit = collect(concurrency, object : FlowCollector { override suspend fun emit(value: T): Unit = action(value) }) public inline fun Flow.mapParallel( dispatcher: CoroutineDispatcher = Dispatchers.Default, - crossinline transform: suspend (T) -> R + crossinline transform: suspend (T) -> R, ): Flow = flatMapMerge { value -> flow { emit(transform(value)) } }.flowOn(dispatcher) 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 75% 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 7be86b6e7..dc1dd4757 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.BlockingDoubleChain +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.DoubleBuffer +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 @@ -45,10 +45,10 @@ public fun Flow.chunked(bufferSize: Int, bufferFactory: BufferFactory) /** * Specialized flow chunker for real buffer */ -public fun Flow.chunked(bufferSize: Int): Flow = flow { +public fun Flow.chunked(bufferSize: Int): Flow = flow { require(bufferSize > 0) { "Resulting chunk size must be more than zero" } - if (this@chunked is BlockingRealChain) { + if (this@chunked is BlockingDoubleChain) { // performance optimization for blocking primitive chain while (true) emit(nextBlock(bufferSize).asBuffer()) } else { @@ -60,13 +60,13 @@ public fun Flow.chunked(bufferSize: Int): Flow = flow { counter++ if (counter == bufferSize) { - val buffer = RealBuffer(array) + val buffer = DoubleBuffer(array) emit(buffer) counter = 0 } } - if (counter > 0) emit(RealBuffer(counter) { array[it] }) + if (counter > 0) emit(DoubleBuffer(counter) { array[it] }) } } 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 91% 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 a59979238..e844b765d 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 @@ -13,7 +13,7 @@ import kscience.kmath.structures.VirtualBuffer public class RingBuffer( private val buffer: MutableBuffer, private var startIndex: Int = 0, - size: Int = 0 + size: Int = 0, ) : Buffer { private val mutex: Mutex = Mutex() diff --git a/kmath-coroutines/src/jvmMain/kotlin/kscience/kmath/structures/LazyNDStructure.kt b/kmath-coroutines/src/jvmMain/kotlin/kscience/kmath/structures/LazyNDStructure.kt deleted file mode 100644 index 3933ef28b..000000000 --- a/kmath-coroutines/src/jvmMain/kotlin/kscience/kmath/structures/LazyNDStructure.kt +++ /dev/null @@ -1,58 +0,0 @@ -package kscience.kmath.structures - -import kotlinx.coroutines.* -import kscience.kmath.coroutines.Math -import kscience.kmath.nd.DefaultStrides -import kscience.kmath.nd.NDStructure - -public class LazyNDStructure( - public val scope: CoroutineScope, - public override val shape: IntArray, - public val function: suspend (IntArray) -> T -) : NDStructure { - private val cache: MutableMap> = hashMapOf() - - public fun deferred(index: IntArray): Deferred = cache.getOrPut(index) { - scope.async(context = Dispatchers.Math) { function(index) } - } - - public suspend fun await(index: IntArray): T = deferred(index).await() - public override operator fun get(index: IntArray): T = runBlocking { deferred(index).await() } - - public override fun elements(): Sequence> { - val strides = DefaultStrides(shape) - val res = runBlocking { strides.indices().toList().map { index -> index to await(index) } } - return res.asSequence() - } - - public override fun equals(other: Any?): Boolean { - return NDStructure.contentEquals(this, other as? NDStructure<*> ?: return false) - } - - public override fun hashCode(): Int { - var result = scope.hashCode() - result = 31 * result + shape.contentHashCode() - result = 31 * result + function.hashCode() - result = 31 * result + cache.hashCode() - return result - } -} - -public fun NDStructure.deferred(index: IntArray): Deferred = - if (this is LazyNDStructure) deferred(index) else CompletableDeferred(get(index)) - -public suspend fun NDStructure.await(index: IntArray): T = - if (this is LazyNDStructure) await(index) else get(index) - -/** - * PENDING would benefit from KEEP-176 - */ -public inline fun NDStructure.mapAsyncIndexed( - scope: CoroutineScope, - crossinline function: suspend (T, index: IntArray) -> R -): LazyNDStructure = LazyNDStructure(scope, shape) { index -> function(get(index), index) } - -public inline fun NDStructure.mapAsync( - scope: CoroutineScope, - crossinline function: suspend (T) -> R -): LazyNDStructure = LazyNDStructure(scope, shape) { index -> function(get(index)) } 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/space/kscience/kmath/structures/LazyStructureND.kt b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt new file mode 100644 index 000000000..6b0938c54 --- /dev/null +++ b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt @@ -0,0 +1,46 @@ +package space.kscience.kmath.structures + +import kotlinx.coroutines.* +import space.kscience.kmath.coroutines.Math +import space.kscience.kmath.nd.DefaultStrides +import space.kscience.kmath.nd.StructureND + +public class LazyStructureND( + public val scope: CoroutineScope, + public override val shape: IntArray, + public val function: suspend (IntArray) -> T, +) : StructureND { + private val cache: MutableMap> = HashMap() + + public fun deferred(index: IntArray): Deferred = cache.getOrPut(index) { + scope.async(context = Dispatchers.Math) { function(index) } + } + + public suspend fun await(index: IntArray): T = deferred(index).await() + public override operator fun get(index: IntArray): T = runBlocking { deferred(index).await() } + + public override fun elements(): Sequence> { + val strides = DefaultStrides(shape) + val res = runBlocking { strides.indices().toList().map { index -> index to await(index) } } + return res.asSequence() + } +} + +public fun StructureND.deferred(index: IntArray): Deferred = + if (this is LazyStructureND) deferred(index) else CompletableDeferred(get(index)) + +public suspend fun StructureND.await(index: IntArray): T = + if (this is LazyStructureND) await(index) else get(index) + +/** + * PENDING would benefit from KEEP-176 + */ +public inline fun StructureND.mapAsyncIndexed( + scope: CoroutineScope, + crossinline function: suspend (T, index: IntArray) -> R, +): LazyStructureND = LazyStructureND(scope, shape) { index -> function(get(index), index) } + +public inline fun StructureND.mapAsync( + scope: CoroutineScope, + crossinline function: suspend (T) -> R, +): LazyStructureND = LazyStructureND(scope, shape) { index -> function(get(index)) } 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..3c73f34e6 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" @@ -19,6 +19,6 @@ kotlin.sourceSets { } } -readme{ +readme { maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE } 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 75% 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 52443da0e..dd85a97cb 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,8 +1,12 @@ -package kscience.kmath.dimensions +package space.kscience.kmath.dimensions -import kscience.kmath.linear.* -import kscience.kmath.nd.Structure2D -import kscience.kmath.operations.invoke +import space.kscience.kmath.linear.LinearSpace +import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.linear.Point +import space.kscience.kmath.linear.transpose +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.Ring /** * A matrix with compile-time controlled dimension @@ -77,7 +81,7 @@ public inline class DPointWrapper(public val point: Point) /** * Basic operations on dimension-safe matrices. Operates on [Matrix] */ -public inline class DMatrixContext(public val context: MatrixContext>) { +public inline class DMatrixContext>(public val context: LinearSpace) { public inline fun Matrix.coerce(): DMatrix { require(rowNum == Dimension.dim().toInt()) { "Row number mismatch: expected ${Dimension.dim()} but found $rowNum" @@ -93,17 +97,19 @@ public inline class DMatrixContext(public val context: MatrixContext produce(noinline initializer: (i: Int, j: Int) -> T): DMatrix { + public inline fun produce( + noinline initializer: A.(i: Int, j: Int) -> T, + ): DMatrix { val rows = Dimension.dim() val cols = Dimension.dim() - return context.produce(rows.toInt(), cols.toInt(), initializer).coerce() + return context.buildMatrix(rows.toInt(), cols.toInt(), initializer).coerce() } - public inline fun point(noinline initializer: (Int) -> T): DPoint { + public inline fun point(noinline initializer: A.(Int) -> T): DPoint { val size = Dimension.dim() return DPoint.coerceUnsafe( - context.point( + context.buildVector( size.toInt(), initializer ) @@ -112,31 +118,31 @@ public inline class DMatrixContext(public val context: MatrixContext DMatrix.dot( other: DMatrix, - ): DMatrix = context { this@dot dot other }.coerce() + ): DMatrix = context.run { this@dot dot other }.coerce() public inline infix fun DMatrix.dot(vector: DPoint): DPoint = - DPoint.coerceUnsafe(context { this@dot dot vector }) + DPoint.coerceUnsafe(context.run { this@dot dot vector }) public inline operator fun DMatrix.times(value: T): DMatrix = - context { this@times.times(value) }.coerce() + context.run { this@times.times(value) }.coerce() public inline operator fun T.times(m: DMatrix): DMatrix = m * this public inline operator fun DMatrix.plus(other: DMatrix): DMatrix = - context { this@plus + other }.coerce() + context.run { this@plus + other }.coerce() public inline operator fun DMatrix.minus(other: DMatrix): DMatrix = - context { this@minus + other }.coerce() + context.run { this@minus + other }.coerce() public inline operator fun DMatrix.unaryMinus(): DMatrix = - context { this@unaryMinus.unaryMinus() }.coerce() + context.run { this@unaryMinus.unaryMinus() }.coerce() public inline fun DMatrix.transpose(): DMatrix = - context { (this@transpose as Matrix).transpose() }.coerce() + context.run { (this@transpose as Matrix).transpose() }.coerce() public companion object { - public val real: DMatrixContext = DMatrixContext(MatrixContext.real) + public val real: DMatrixContext = DMatrixContext(LinearSpace.real) } } @@ -144,11 +150,12 @@ public inline class DMatrixContext(public val context: MatrixContext DMatrixContext.one(): DMatrix = produce { i, j -> - if (i == j) 1.0 else 0.0 -} +public inline fun DMatrixContext.one(): DMatrix = + produce { i, j -> + if (i == j) 1.0 else 0.0 + } -public inline fun DMatrixContext.zero(): DMatrix = +public inline fun DMatrixContext.zero(): DMatrix = produce { _, _ -> 0.0 } \ No newline at end of file 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/README.md b/kmath-ejml/README.md new file mode 100644 index 000000000..2551703a4 --- /dev/null +++ b/kmath-ejml/README.md @@ -0,0 +1,37 @@ +# Module kmath-ejml + +EJML based linear algebra implementation. + + - [ejml-vector](src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt) : The Point implementation using SimpleMatrix. + - [ejml-matrix](src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt) : The Matrix implementation using SimpleMatrix. + - [ejml-linear-space](src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt) : The LinearSpace implementation using SimpleMatrix. + + +## Artifact: + +The Maven coordinates of this project are `space.kscience:kmath-ejml:0.3.0-dev-3`. + +**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 +} + +dependencies { + implementation 'space.kscience:kmath-ejml:0.3.0-dev-3' +} +``` +**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 +} + +dependencies { + implementation("space.kscience:kmath-ejml:0.3.0-dev-3") +} +``` diff --git a/kmath-ejml/build.gradle.kts b/kmath-ejml/build.gradle.kts index ecf76a022..5091139ac 100644 --- a/kmath-ejml/build.gradle.kts +++ b/kmath-ejml/build.gradle.kts @@ -1,12 +1,33 @@ +import ru.mipt.npm.gradle.Maturity + plugins { - id("ru.mipt.npm.jvm") + id("ru.mipt.npm.gradle.jvm") } dependencies { - implementation("org.ejml:ejml-simple:0.39") - implementation(project(":kmath-core")) + api("org.ejml:ejml-simple:0.40") + api(project(":kmath-core")) } -readme{ - maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE -} \ No newline at end of file +readme { + maturity = Maturity.PROTOTYPE + propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) + + feature( + id = "ejml-vector", + description = "The Point implementation using SimpleMatrix.", + ref = "src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt" + ) + + feature( + id = "ejml-matrix", + description = "The Matrix implementation using SimpleMatrix.", + ref = "src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt" + ) + + feature( + id = "ejml-linear-space", + description = "The LinearSpace implementation using SimpleMatrix.", + ref = "src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt" + ) +} diff --git a/kmath-ejml/docs/README-TEMPLATE.md b/kmath-ejml/docs/README-TEMPLATE.md new file mode 100644 index 000000000..27fcedd65 --- /dev/null +++ b/kmath-ejml/docs/README-TEMPLATE.md @@ -0,0 +1,7 @@ +# Module kmath-ejml + +EJML based linear algebra implementation. + +${features} + +${artifact} diff --git a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrix.kt b/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrix.kt deleted file mode 100644 index 3587823a7..000000000 --- a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrix.kt +++ /dev/null @@ -1,95 +0,0 @@ -package kscience.kmath.ejml - -import kscience.kmath.linear.* -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.nd.NDStructure -import kscience.kmath.structures.RealBuffer -import org.ejml.dense.row.factory.DecompositionFactory_DDRM -import org.ejml.simple.SimpleMatrix -import kotlin.reflect.KClass -import kotlin.reflect.cast - -/** - * Represents featured matrix over EJML [SimpleMatrix]. - * - * @property origin the underlying [SimpleMatrix]. - * @author Iaroslav Postovalov - */ -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 - 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) - .apply { decompose(origin.ddrm.copy()) } - } - - override val u: Matrix by lazy { EjmlMatrix(SimpleMatrix(svd.getU(null, false))) } - override val s: Matrix by lazy { EjmlMatrix(SimpleMatrix(svd.getW(null))) } - 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))) + 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 = - DecompositionFactory_DDRM.chol(rowNum, true).apply { decompose(origin.ddrm.copy()) } - - 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()) } - } - - override val l: Matrix by lazy { - EjmlMatrix(SimpleMatrix(lup.getLower(null))) + LFeature - } - - override val u: Matrix by lazy { - EjmlMatrix(SimpleMatrix(lup.getUpper(null))) + UFeature - } - - override val p: Matrix by lazy { EjmlMatrix(SimpleMatrix(lup.getRowPivot(null))) } - } - - else -> null - }?.let(type::cast) - - public override operator fun get(i: Int, j: Int): Double = origin[i, j] - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is Matrix<*>) return false - return NDStructure.contentEquals(this, other) - } - - override fun hashCode(): Int = origin.hashCode() - - -} diff --git a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrixContext.kt b/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrixContext.kt deleted file mode 100644 index eb126e00a..000000000 --- a/kmath-ejml/src/main/kotlin/kscience/kmath/ejml/EjmlMatrixContext.kt +++ /dev/null @@ -1,88 +0,0 @@ -package kscience.kmath.ejml - -import kscience.kmath.linear.* -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.nd.getFeature -import org.ejml.simple.SimpleMatrix - -/** - * Represents context of basic operations operating with [EjmlMatrix]. - * - * @author Iaroslav Postovalov - */ -public object EjmlMatrixContext : MatrixContext { - - /** - * Converts this matrix to EJML one. - */ - @OptIn(UnstableKMathAPI::class) - public fun Matrix.toEjml(): EjmlMatrix = when (val matrix = origin) { - is EjmlMatrix -> matrix - else -> produce(rowNum, colNum) { i, j -> get(i, j) } - } - - /** - * Converts this vector to EJML one. - */ - public fun Point.toEjml(): EjmlVector = - if (this is EjmlVector) this else EjmlVector(SimpleMatrix(size, 1).also { - (0 until it.numRows()).forEach { row -> it[row, 0] = get(row) } - }) - - 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) } - } - }) - - override fun point(size: Int, initializer: (Int) -> Double): Point = - EjmlVector(SimpleMatrix(size, 1).also { - (0 until it.numRows()).forEach { row -> it[row, 0] = initializer(row) } - }) - - public override fun Matrix.dot(other: Matrix): EjmlMatrix = - EjmlMatrix(toEjml().origin.mult(other.toEjml().origin)) - - public override fun Matrix.dot(vector: Point): EjmlVector = - EjmlVector(toEjml().origin.mult(vector.toEjml().origin)) - - public override fun add(a: Matrix, b: Matrix): EjmlMatrix = - EjmlMatrix(a.toEjml().origin + b.toEjml().origin) - - public override operator fun Matrix.minus(b: Matrix): EjmlMatrix = - EjmlMatrix(toEjml().origin - b.toEjml().origin) - - public override fun multiply(a: Matrix, k: Number): EjmlMatrix = - produce(a.rowNum, a.colNum) { i, j -> a[i, j] * k.toDouble() } - - public override operator fun Matrix.times(value: Double): EjmlMatrix = - EjmlMatrix(toEjml().origin.scale(value)) -} - -/** - * Solves for X in the following equation: x = a^-1*b, where 'a' is base matrix and 'b' is an n by p matrix. - * - * @param a the base matrix. - * @param b n by p matrix. - * @return the solution for 'x' that is n by p. - * @author Iaroslav Postovalov - */ -public fun EjmlMatrixContext.solve(a: Matrix, b: Matrix): EjmlMatrix = - EjmlMatrix(a.toEjml().origin.solve(b.toEjml().origin)) - -/** - * Solves for X in the following equation: x = a^(-1)*b, where 'a' is base matrix and 'b' is an n by p matrix. - * - * @param a the base matrix. - * @param b n by p vector. - * @return the solution for 'x' that is n by p. - * @author Iaroslav Postovalov - */ -public fun EjmlMatrixContext.solve(a: Matrix, b: Point): EjmlVector = - EjmlVector(a.toEjml().origin.solve(b.toEjml().origin)) - -@OptIn(UnstableKMathAPI::class) -public fun EjmlMatrix.inverted(): EjmlMatrix = getFeature>()!!.inverse as EjmlMatrix - -public fun EjmlMatrixContext.inverse(matrix: Matrix): Matrix = matrix.toEjml().inverted() \ No newline at end of file diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt new file mode 100644 index 000000000..94429e7b3 --- /dev/null +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt @@ -0,0 +1,204 @@ +package space.kscience.kmath.ejml + +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.StructureFeature +import space.kscience.kmath.nd.getFeature +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.structures.DoubleBuffer +import kotlin.reflect.KClass +import kotlin.reflect.cast + +/** + * Represents context of basic operations operating with [EjmlMatrix]. + * + * @author Iaroslav Postovalov + * @author Alexander Nozik + */ +public object EjmlLinearSpace : LinearSpace { + /** + * The [DoubleField] reference. + */ + public override val elementAlgebra: DoubleField get() = DoubleField + + /** + * Converts this matrix to EJML one. + */ + @OptIn(UnstableKMathAPI::class) + public fun Matrix.toEjml(): EjmlMatrix = when (val matrix = origin) { + is EjmlMatrix -> matrix + else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } + } + + /** + * Converts this vector to EJML one. + */ + public fun Point.toEjml(): EjmlVector = when (this) { + is EjmlVector -> this + else -> EjmlVector(SimpleMatrix(size, 1).also { + (0 until it.numRows()).forEach { row -> it[row, 0] = get(row) } + }) + } + + public override fun buildMatrix( + rows: Int, + columns: Int, + initializer: DoubleField.(i: Int, j: Int) -> Double, + ): EjmlMatrix = EjmlMatrix(SimpleMatrix(rows, columns).also { + (0 until rows).forEach { row -> + (0 until columns).forEach { col -> it[row, col] = DoubleField.initializer(row, col) } + } + }) + + public override fun buildVector(size: Int, initializer: DoubleField.(Int) -> Double): Point = + EjmlVector(SimpleMatrix(size, 1).also { + (0 until it.numRows()).forEach { row -> it[row, 0] = DoubleField.initializer(row) } + }) + + private fun SimpleMatrix.wrapMatrix() = EjmlMatrix(this) + private fun SimpleMatrix.wrapVector() = EjmlVector(this) + + public override fun Matrix.unaryMinus(): Matrix = this * (-1.0) + + public override fun Matrix.dot(other: Matrix): EjmlMatrix = + EjmlMatrix(toEjml().origin.mult(other.toEjml().origin)) + + public override fun Matrix.dot(vector: Point): EjmlVector = + EjmlVector(toEjml().origin.mult(vector.toEjml().origin)) + + public override operator fun Matrix.minus(other: Matrix): EjmlMatrix = + (toEjml().origin - other.toEjml().origin).wrapMatrix() + + public override operator fun Matrix.times(value: Double): EjmlMatrix = + toEjml().origin.scale(value).wrapMatrix() + + public override fun Point.unaryMinus(): EjmlVector = + toEjml().origin.negative().wrapVector() + + public override fun Matrix.plus(other: Matrix): EjmlMatrix = + (toEjml().origin + other.toEjml().origin).wrapMatrix() + + public override fun Point.plus(other: Point): EjmlVector = + (toEjml().origin + other.toEjml().origin).wrapVector() + + public override fun Point.minus(other: Point): EjmlVector = + (toEjml().origin - other.toEjml().origin).wrapVector() + + public override fun Double.times(m: Matrix): EjmlMatrix = + m.toEjml().origin.scale(this).wrapMatrix() + + public override fun Point.times(value: Double): EjmlVector = + toEjml().origin.scale(value).wrapVector() + + public override fun Double.times(v: Point): EjmlVector = + v.toEjml().origin.scale(this).wrapVector() + + @UnstableKMathAPI + public override fun getFeature(structure: Matrix, type: KClass): F? { + //Return the feature if it is intrinsic to the structure + structure.getFeature(type)?.let { return it } + + val origin = structure.toEjml().origin + + return 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) + .apply { decompose(origin.ddrm.copy()) } + } + + override val u: Matrix by lazy { EjmlMatrix(SimpleMatrix(svd.getU(null, false))) } + override val s: Matrix by lazy { EjmlMatrix(SimpleMatrix(svd.getW(null))) } + override val v: Matrix by lazy { EjmlMatrix(SimpleMatrix(svd.getV(null, false))) } + override val singularValues: Point by lazy { DoubleBuffer(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))) + 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 = + DecompositionFactory_DDRM.chol(structure.rowNum, true).apply { decompose(origin.ddrm.copy()) } + + 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()) } + } + + override val l: Matrix by lazy { + EjmlMatrix(SimpleMatrix(lup.getLower(null))) + LFeature + } + + override val u: Matrix by lazy { + EjmlMatrix(SimpleMatrix(lup.getUpper(null))) + UFeature + } + + override val p: Matrix by lazy { EjmlMatrix(SimpleMatrix(lup.getRowPivot(null))) } + } + + else -> null + }?.let(type::cast) + } +} + +/** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p matrix. + * @return the solution for 'x' that is n by p. + * @author Iaroslav Postovalov + */ +public fun EjmlLinearSpace.solve(a: Matrix, b: Matrix): EjmlMatrix = + EjmlMatrix(a.toEjml().origin.solve(b.toEjml().origin)) + +/** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p vector. + * @return the solution for 'x' that is n by p. + * @author Iaroslav Postovalov + */ +public fun EjmlLinearSpace.solve(a: Matrix, b: Point): EjmlVector = + EjmlVector(a.toEjml().origin.solve(b.toEjml().origin)) + +/** + * Inverts this matrix. + * + * @author Alexander Nozik + */ +@OptIn(UnstableKMathAPI::class) +public fun EjmlMatrix.inverted(): EjmlMatrix = getFeature>()!!.inverse as EjmlMatrix + +/** + * Inverts the given matrix. + * + * @author Alexander Nozik + */ +public fun EjmlLinearSpace.inverse(matrix: Matrix): Matrix = matrix.toEjml().inverted() \ No newline at end of file diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt new file mode 100644 index 000000000..10afd6ec2 --- /dev/null +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt @@ -0,0 +1,17 @@ +package space.kscience.kmath.ejml + +import org.ejml.simple.SimpleMatrix +import space.kscience.kmath.linear.Matrix + +/** + * The matrix implementation over EJML [SimpleMatrix]. + * + * @property origin the underlying [SimpleMatrix]. + * @author Iaroslav Postovalov + */ +public inline class EjmlMatrix(public val origin: SimpleMatrix) : Matrix { + public override val rowNum: Int get() = origin.numRows() + public override val colNum: Int get() = origin.numCols() + + public override operator fun get(i: Int, j: Int): Double = origin[i, j] +} 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 67% 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..2c8d2edd4 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,7 @@ -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 /** * Represents point over EJML [SimpleMatrix]. @@ -10,7 +9,7 @@ import kscience.kmath.structures.Buffer * @property origin the underlying [SimpleMatrix]. * @author Iaroslav Postovalov */ -public class EjmlVector internal constructor(public val origin: SimpleMatrix) : Point { +public inline class EjmlVector internal constructor(public val origin: SimpleMatrix) : Point { public override val size: Int get() = origin.numRows() @@ -31,10 +30,5 @@ public class EjmlVector internal constructor(public val origin: SimpleMatrix) : override fun hasNext(): Boolean = cursor < origin.numCols() * origin.numRows() } - public override fun contentEquals(other: Buffer<*>): Boolean { - if (other is EjmlVector) return origin.isIdentical(other.origin, 0.0) - return super.contentEquals(other) - } - public override fun toString(): String = "EjmlVector(origin=$origin)" } 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 66% 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 6af70b6f5..5fb526f40 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,17 +1,19 @@ -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.nd.getFeature 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.StructureND +import space.kscience.kmath.nd.getFeature import kotlin.random.Random import kotlin.random.asJavaRandom import kotlin.test.* +fun assertMatrixEquals(expected: StructureND, actual: StructureND) { + assertTrue { StructureND.contentEquals(expected, actual) } +} + internal class EjmlMatrixTest { private val random = Random(0) @@ -45,16 +47,16 @@ internal class EjmlMatrixTest { fun features() { val m = randomMatrix val w = EjmlMatrix(m) - val det = w.getFeature>() ?: fail() + val det: DeterminantFeature = EjmlLinearSpace.getFeature(w) ?: fail() assertEquals(m.determinant(), det.determinant) - val lup = w.getFeature>() ?: fail() + val lup: LupDecompositionFeature = EjmlLinearSpace.getFeature(w) ?: fail() val ludecompositionF64 = DecompositionFactory_DDRM.lu(m.numRows(), m.numCols()) .also { it.decompose(m.ddrm.copy()) } - assertEquals(EjmlMatrix(SimpleMatrix(ludecompositionF64.getLower(null))), lup.l) - assertEquals(EjmlMatrix(SimpleMatrix(ludecompositionF64.getUpper(null))), lup.u) - assertEquals(EjmlMatrix(SimpleMatrix(ludecompositionF64.getRowPivot(null))), lup.p) + assertMatrixEquals(EjmlMatrix(SimpleMatrix(ludecompositionF64.getLower(null))), lup.l) + assertMatrixEquals(EjmlMatrix(SimpleMatrix(ludecompositionF64.getUpper(null))), lup.u) + assertMatrixEquals(EjmlMatrix(SimpleMatrix(ludecompositionF64.getRowPivot(null))), lup.p) } private object SomeFeature : MatrixFeature {} 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 c291be3a1..ad3d33062 100644 --- a/kmath-for-real/README.md +++ b/kmath-for-real/README.md @@ -1,44 +1,37 @@ -# Real number specialization module (`kmath-for-real`) +# Module kmath-for-real - - [RealVector](src/commonMain/kotlin/kscience/kmath/real/RealVector.kt) : Numpy-like operations for Buffers/Points - - [RealMatrix](src/commonMain/kotlin/kscience/kmath/real/RealMatrix.kt) : Numpy-like operations for 2d real structures - - [grids](src/commonMain/kotlin/kscience/kmath/structures/grids.kt) : Uniform grid generators +Specialization of KMath APIs for Double numbers. + + - [DoubleVector](src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt) : Numpy-like operations for Buffers/Points + - [DoubleMatrix](src/commonMain/kotlin/space/kscience/kmath/real/DoubleMatrix.kt) : Numpy-like operations for 2d real structures + - [grids](src/commonMain/kotlin/space/kscience/kmath/structures/grids.kt) : Uniform grid generators -> #### Artifact: -> -> This module artifact: `kscience.kmath:kmath-for-real:0.2.0-dev-7`. -> -> 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) -> -> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-for-real/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-for-real/_latestVersion) -> -> **Gradle:** -> -> ```gradle -> repositories { -> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } -> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } -> maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> -> } -> -> dependencies { -> implementation 'kscience.kmath:kmath-for-real:0.2.0-dev-7' -> } -> ``` -> **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") -> } -> -> dependencies { -> implementation("kscience.kmath:kmath-for-real:0.2.0-dev-7") -> } -> ``` +## Artifact: + +The Maven coordinates of this project are `space.kscience:kmath-for-real:0.3.0-dev-3`. + +**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 +} + +dependencies { + implementation 'space.kscience:kmath-for-real:0.3.0-dev-3' +} +``` +**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 +} + +dependencies { + implementation("space.kscience:kmath-for-real:0.3.0-dev-3") +} +``` diff --git a/kmath-for-real/build.gradle.kts b/kmath-for-real/build.gradle.kts index f26f98c2c..0dcaf330a 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 { @@ -18,20 +18,20 @@ readme { propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature( - id = "RealVector", + id = "DoubleVector", description = "Numpy-like operations for Buffers/Points", - ref = "src/commonMain/kotlin/kscience/kmath/real/RealVector.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt" ) feature( - id = "RealMatrix", + id = "DoubleMatrix", description = "Numpy-like operations for 2d real structures", - ref = "src/commonMain/kotlin/kscience/kmath/real/RealMatrix.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/real/DoubleMatrix.kt" ) feature( id = "grids", description = "Uniform grid generators", - ref = "src/commonMain/kotlin/kscience/kmath/structures/grids.kt" + ref = "src/commonMain/kotlin/space/kscience/kmath/structures/grids.kt" ) } diff --git a/kmath-for-real/docs/README-TEMPLATE.md b/kmath-for-real/docs/README-TEMPLATE.md index 670844bd0..c2ef25aa7 100644 --- a/kmath-for-real/docs/README-TEMPLATE.md +++ b/kmath-for-real/docs/README-TEMPLATE.md @@ -1,4 +1,6 @@ -# Real number specialization module (`kmath-for-real`) +# Module kmath-for-real + +Specialization of KMath APIs for Double numbers. ${features} diff --git a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealVector.kt b/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealVector.kt deleted file mode 100644 index ee2a960a1..000000000 --- a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/RealVector.kt +++ /dev/null @@ -1,90 +0,0 @@ -package 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 kotlin.math.pow -import kotlin.math.sqrt - -public typealias RealVector = Point - -public object VectorL2Norm : Norm, Double> { - override fun norm(arg: Point): Double = sqrt(arg.asIterable().sumByDouble(Number::toDouble)) -} - -public operator fun Buffer.Companion.invoke(vararg doubles: Double): RealVector = doubles.asBuffer() - -/** - * Fill the vector of given [size] with given [value] - */ -public fun Buffer.Companion.same(size: Int, value: Number): RealVector = real(size) { value.toDouble() } - -// Transformation methods - -public inline fun RealVector.map(transform: (Double) -> Double): RealVector = - Buffer.real(size) { transform(get(it)) } - -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 { - 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() } - -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 { - 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 { - 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 { - 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() } - -public operator fun Number.div(vector: RealVector): RealVector = vector.map { toDouble() / it } - -//extended operations - -public fun RealVector.pow(p: Double): RealVector = map { it.pow(p) } - -public fun RealVector.pow(p: Int): RealVector = map { it.pow(p) } - -public fun exp(vector: RealVector): RealVector = vector.map { kotlin.math.exp(it) } - -public fun sqrt(vector: RealVector): RealVector = vector.map { kotlin.math.sqrt(it) } - -public fun RealVector.square(): RealVector = map { it.pow(2) } - -public fun sin(vector: RealVector): RealVector = vector.map { kotlin.math.sin(it) } - -public fun cos(vector: RealVector): RealVector = vector.map { kotlin.math.cos(it) } - -public fun tan(vector: RealVector): RealVector = vector.map { kotlin.math.tan(it) } - -public fun ln(vector: RealVector): RealVector = vector.map { kotlin.math.ln(it) } - -public fun log10(vector: RealVector): RealVector = vector.map { kotlin.math.log10(it) } diff --git a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/dot.kt b/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/dot.kt deleted file mode 100644 index 9beffe6bb..000000000 --- a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/dot.kt +++ /dev/null @@ -1,31 +0,0 @@ -package kscience.kmath.real - -import kscience.kmath.linear.BufferMatrix -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.RealBuffer - - -/** - * Optimized dot product for real matrices - */ -public infix fun BufferMatrix.dot(other: BufferMatrix): BufferMatrix { - require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } - val resultArray = DoubleArray(this.rowNum * other.colNum) - - //convert to array to insure there is no memory indirection - fun Buffer.unsafeArray() = if (this is RealBuffer) - this.array - else - DoubleArray(size) { get(it) } - - val a = this.buffer.unsafeArray() - val b = other.buffer.unsafeArray() - - for (i in (0 until rowNum)) - for (j in (0 until other.colNum)) - for (k in (0 until colNum)) - resultArray[i * other.colNum + j] += a[i * colNum + k] * b[k * other.colNum + j] - - val buffer = RealBuffer(resultArray) - return BufferMatrix(rowNum, other.colNum, buffer) -} \ No newline at end of file diff --git a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/grids.kt b/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/grids.kt deleted file mode 100644 index 69a149fb8..000000000 --- a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/grids.kt +++ /dev/null @@ -1,45 +0,0 @@ -package kscience.kmath.real - -import kscience.kmath.structures.asBuffer -import kotlin.math.abs - -/** - * Convert double range to sequence. - * - * If the step is positive, than the sequence starts with the lower boundary and increments by [step] until current value is lower than upper boundary. - * The boundary itself is not necessary included. - * - * If step is negative, the same goes from upper boundary downwards - */ -public fun ClosedFloatingPointRange.toSequenceWithStep(step: Double): Sequence = when { - step == 0.0 -> error("Zero step in double progression") - - step > 0 -> sequence { - var current = start - - while (current <= endInclusive) { - yield(current) - current += step - } - } - - else -> sequence { - var current = endInclusive - - while (current >= start) { - yield(current) - current += step - } - } -} - -public infix fun ClosedFloatingPointRange.step(step: Double): RealVector = - toSequenceWithStep(step).toList().asBuffer() - -/** - * Convert double range to sequence with the fixed number of points - */ -public fun ClosedFloatingPointRange.toSequenceWithPoints(numPoints: Int): Sequence { - require(numPoints > 1) { "The number of points should be more than 2" } - return toSequenceWithStep(abs(endInclusive - start) / (numPoints - 1)) -} diff --git a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/realND.kt b/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/realND.kt deleted file mode 100644 index f8757b132..000000000 --- a/kmath-for-real/src/commonMain/kotlin/kscience/kmath/real/realND.kt +++ /dev/null @@ -1,31 +0,0 @@ -package kscience.kmath.real - -import kscience.kmath.nd.NDBuffer -import kscience.kmath.operations.RealField -import 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/commonMain/kotlin/kscience/kmath/real/RealMatrix.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt similarity index 60% 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 d0e4a7325..a16d64234 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,10 +1,11 @@ -package kscience.kmath.real +package space.kscience.kmath.real -import kscience.kmath.linear.* -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.structures.Buffer -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.operations.DoubleField +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.asIterable import kotlin.math.pow /* @@ -21,15 +22,19 @@ import kotlin.math.pow public typealias RealMatrix = Matrix -public fun realMatrix(rowNum: Int, colNum: Int, initializer: (i: Int, j: Int) -> Double): RealMatrix = - MatrixContext.real.produce(rowNum, colNum, initializer) +public fun realMatrix(rowNum: Int, colNum: Int, initializer: DoubleField.(i: Int, j: Int) -> Double): RealMatrix = + LinearSpace.real.buildMatrix(rowNum, colNum, initializer) + +@OptIn(UnstableKMathAPI::class) +public fun realMatrix(rowNum: Int, colNum: Int): MatrixBuilder = + LinearSpace.real.matrix(rowNum, colNum) public fun Array.toMatrix(): RealMatrix { - return MatrixContext.real.produce(size, this[0].size) { row, col -> this[row][col] } + return LinearSpace.real.buildMatrix(size, this[0].size) { row, col -> this@toMatrix[row][col] } } public fun Sequence.toMatrix(): RealMatrix = toList().let { - MatrixContext.real.produce(it.size, it[0].size) { row, col -> it[row][col] } + LinearSpace.real.buildMatrix(it.size, it[0].size) { row, col -> it[row][col] } } public fun RealMatrix.repeatStackVertical(n: Int): RealMatrix = @@ -42,38 +47,38 @@ public fun RealMatrix.repeatStackVertical(n: Int): RealMatrix = */ public operator fun RealMatrix.times(double: Double): RealMatrix = - MatrixContext.real.produce(rowNum, colNum) { row, col -> - this[row, col] * double + LinearSpace.real.buildMatrix(rowNum, colNum) { row, col -> + get(row, col) * double } public operator fun RealMatrix.plus(double: Double): RealMatrix = - MatrixContext.real.produce(rowNum, colNum) { row, col -> - this[row, col] + double + LinearSpace.real.buildMatrix(rowNum, colNum) { row, col -> + get(row, col) + double } public operator fun RealMatrix.minus(double: Double): RealMatrix = - MatrixContext.real.produce(rowNum, colNum) { row, col -> - this[row, col] - double + LinearSpace.real.buildMatrix(rowNum, colNum) { row, col -> + get(row, col) - double } public operator fun RealMatrix.div(double: Double): RealMatrix = - MatrixContext.real.produce(rowNum, colNum) { row, col -> - this[row, col] / double + LinearSpace.real.buildMatrix(rowNum, colNum) { row, col -> + get(row, col) / double } public operator fun Double.times(matrix: RealMatrix): RealMatrix = - MatrixContext.real.produce(matrix.rowNum, matrix.colNum) { row, col -> - this * matrix[row, col] + LinearSpace.real.buildMatrix(matrix.rowNum, matrix.colNum) { row, col -> + this@times * matrix[row, col] } public operator fun Double.plus(matrix: RealMatrix): RealMatrix = - MatrixContext.real.produce(matrix.rowNum, matrix.colNum) { row, col -> - this + matrix[row, col] + LinearSpace.real.buildMatrix(matrix.rowNum, matrix.colNum) { row, col -> + this@plus + matrix[row, col] } public operator fun Double.minus(matrix: RealMatrix): RealMatrix = - MatrixContext.real.produce(matrix.rowNum, matrix.colNum) { row, col -> - this - matrix[row, col] + LinearSpace.real.buildMatrix(matrix.rowNum, matrix.colNum) { row, col -> + this@minus - matrix[row, col] } // TODO: does this operation make sense? Should it be 'this/matrix[row, col]'? @@ -87,47 +92,47 @@ public operator fun Double.minus(matrix: RealMatrix): RealMatrix = @UnstableKMathAPI public operator fun RealMatrix.times(other: RealMatrix): RealMatrix = - MatrixContext.real.produce(rowNum, colNum) { row, col -> this[row, col] * other[row, col] } + LinearSpace.real.buildMatrix(rowNum, colNum) { row, col -> this@times[row, col] * other[row, col] } public operator fun RealMatrix.plus(other: RealMatrix): RealMatrix = - MatrixContext.real.add(this, other) + LinearSpace.real.run { this@plus + other } public operator fun RealMatrix.minus(other: RealMatrix): RealMatrix = - MatrixContext.real.produce(rowNum, colNum) { row, col -> this[row, col] - other[row, col] } + LinearSpace.real.buildMatrix(rowNum, colNum) { row, col -> this@minus[row, col] - other[row, col] } /* * Operations on columns */ public inline fun RealMatrix.appendColumn(crossinline mapper: (Buffer) -> Double): RealMatrix = - MatrixContext.real.produce(rowNum, colNum + 1) { row, col -> + LinearSpace.real.buildMatrix(rowNum, colNum + 1) { row, col -> if (col < colNum) - this[row, col] + get(row, col) else mapper(rows[row]) } public fun RealMatrix.extractColumns(columnRange: IntRange): RealMatrix = - MatrixContext.real.produce(rowNum, columnRange.count()) { row, col -> - this[row, columnRange.first + col] + LinearSpace.real.buildMatrix(rowNum, columnRange.count()) { row, col -> + this@extractColumns[row, columnRange.first + col] } public fun RealMatrix.extractColumn(columnIndex: Int): RealMatrix = extractColumns(columnIndex..columnIndex) -public fun RealMatrix.sumByColumn(): RealBuffer = RealBuffer(colNum) { j -> +public fun RealMatrix.sumByColumn(): DoubleBuffer = DoubleBuffer(colNum) { j -> columns[j].asIterable().sum() } -public fun RealMatrix.minByColumn(): RealBuffer = RealBuffer(colNum) { j -> +public fun RealMatrix.minByColumn(): DoubleBuffer = DoubleBuffer(colNum) { j -> columns[j].asIterable().minOrNull() ?: error("Cannot produce min on empty column") } -public fun RealMatrix.maxByColumn(): RealBuffer = RealBuffer(colNum) { j -> +public fun RealMatrix.maxByColumn(): DoubleBuffer = DoubleBuffer(colNum) { j -> columns[j].asIterable().maxOrNull() ?: error("Cannot produce min on empty column") } -public fun RealMatrix.averageByColumn(): RealBuffer = RealBuffer(colNum) { j -> +public fun RealMatrix.averageByColumn(): DoubleBuffer = DoubleBuffer(colNum) { j -> columns[j].asIterable().average() } @@ -141,14 +146,14 @@ public fun RealMatrix.max(): Double? = elements().map { (_, value) -> value }.ma public fun RealMatrix.average(): Double = elements().map { (_, value) -> value }.average() public inline fun RealMatrix.map(crossinline transform: (Double) -> Double): RealMatrix = - MatrixContext.real.produce(rowNum, colNum) { i, j -> + LinearSpace.real.buildMatrix(rowNum, colNum) { i, j -> transform(get(i, j)) } /** * Inverse a square real matrix using LUP decomposition */ -public fun RealMatrix.inverseWithLup(): RealMatrix = MatrixContext.real.inverseWithLup(this) +public fun RealMatrix.inverseWithLup(): RealMatrix = LinearSpace.real.inverseWithLup(this) //extended operations diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt new file mode 100644 index 000000000..6b059ef56 --- /dev/null +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt @@ -0,0 +1,107 @@ +package space.kscience.kmath.real + +import space.kscience.kmath.linear.Point +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.Norm +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.MutableBuffer.Companion.double +import space.kscience.kmath.structures.asBuffer +import space.kscience.kmath.structures.fold +import space.kscience.kmath.structures.indices +import kotlin.math.pow +import kotlin.math.sqrt + +public typealias DoubleVector = Point + +@Suppress("FunctionName") +public fun DoubleVector(vararg doubles: Double): DoubleVector = doubles.asBuffer() + +/** + * Fill the vector of given [size] with given [value] + */ +@UnstableKMathAPI +public fun Buffer.Companion.same(size: Int, value: Number): DoubleVector = double(size) { value.toDouble() } + +// Transformation methods + +public inline fun DoubleVector.map(transform: (Double) -> Double): DoubleVector = + double(size) { transform(get(it)) } + +public inline fun DoubleVector.mapIndexed(transform: (index: Int, value: Double) -> Double): DoubleVector = + double(size) { transform(it, get(it)) } + +public operator fun DoubleVector.plus(other: DoubleVector): DoubleVector { + require(size == other.size) { "Vector size $size expected but ${other.size} found" } + return mapIndexed { index, value -> value + other[index] } +} + +public operator fun DoubleVector.plus(number: Number): DoubleVector = map { it + number.toDouble() } + +public operator fun Number.plus(vector: DoubleVector): DoubleVector = vector + this + +public operator fun DoubleVector.unaryMinus(): Buffer = map { -it } + +public operator fun DoubleVector.minus(other: DoubleVector): DoubleVector { + require(size == other.size) { "Vector size $size expected but ${other.size} found" } + return mapIndexed { index, value -> value - other[index] } +} + +public operator fun DoubleVector.minus(number: Number): DoubleVector = map { it - number.toDouble() } + +public operator fun Number.minus(vector: DoubleVector): DoubleVector = vector.map { toDouble() - it } + +public operator fun DoubleVector.times(other: DoubleVector): DoubleVector { + require(size == other.size) { "Vector size $size expected but ${other.size} found" } + return mapIndexed { index, value -> value * other[index] } +} + +public operator fun DoubleVector.times(number: Number): DoubleVector = map { it * number.toDouble() } + +public operator fun Number.times(vector: DoubleVector): DoubleVector = vector * this + +public operator fun DoubleVector.div(other: DoubleVector): DoubleVector { + require(size == other.size) { "Vector size $size expected but ${other.size} found" } + return mapIndexed { index, value -> value / other[index] } +} + +public operator fun DoubleVector.div(number: Number): DoubleVector = map { it / number.toDouble() } + +public operator fun Number.div(vector: DoubleVector): DoubleVector = vector.map { toDouble() / it } + +//extended operations + +public fun DoubleVector.pow(p: Double): DoubleVector = map { it.pow(p) } + +public fun DoubleVector.pow(p: Int): DoubleVector = map { it.pow(p) } + +public fun exp(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.exp(it) } + +public fun sqrt(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.sqrt(it) } + +public fun DoubleVector.square(): DoubleVector = map { it.pow(2) } + +public fun sin(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.sin(it) } + +public fun cos(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.cos(it) } + +public fun tan(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.tan(it) } + +public fun ln(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.ln(it) } + +public fun log10(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.log10(it) } + +// reductions methods + +public fun DoubleVector.sum(): Double { + var res = 0.0 + for (i in indices) { + res += get(i) + } + return res +} + +public object VectorL2Norm : Norm { + override fun norm(arg: DoubleVector): Double = sqrt(arg.fold(0.0) { acc: Double, d: Double -> acc + d.pow(2) }) +} + +public val DoubleVector.norm: Double get() = VectorL2Norm.norm(this) \ No newline at end of file diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt new file mode 100644 index 000000000..d5f093d63 --- /dev/null +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt @@ -0,0 +1,12 @@ +package space.kscience.kmath.real + +import space.kscience.kmath.linear.LinearSpace +import space.kscience.kmath.linear.Matrix + + +/** + * Optimized dot product for real matrices + */ +public infix fun Matrix.dot(other: Matrix): Matrix = LinearSpace.real.run { + this@dot dot other +} \ No newline at end of file diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt new file mode 100644 index 000000000..7f02c7db3 --- /dev/null +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt @@ -0,0 +1,49 @@ +package space.kscience.kmath.real + +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.DoubleBuffer +import kotlin.math.floor + +public val ClosedFloatingPointRange.length: Double get() = endInclusive - start + +/** + * Create a Buffer-based grid with equally distributed [numberOfPoints] points. The range could be increasing or decreasing. + * If range has a zero size, then the buffer consisting of [numberOfPoints] equal values is returned. + */ +public fun Buffer.Companion.fromRange(range: ClosedFloatingPointRange, numberOfPoints: Int): DoubleBuffer { + require(numberOfPoints >= 2) { "Number of points in grid must be more than 1" } + val normalizedRange = when { + range.endInclusive > range.start -> range + range.endInclusive < range.start -> range.endInclusive..range.start + else -> return DoubleBuffer(numberOfPoints) { range.start } + } + val step = normalizedRange.length / (numberOfPoints - 1) + return DoubleBuffer(numberOfPoints) { normalizedRange.start + step * it } +} + +/** + * Create a Buffer-based grid with equally distributed points with a fixed [step]. The range could be increasing or decreasing. + * If the step is larger than the range size, single point is returned. + */ +public fun Buffer.Companion.withFixedStep(range: ClosedFloatingPointRange, step: Double): DoubleBuffer { + require(step > 0) { "The grid step must be positive" } + val normalizedRange = when { + range.endInclusive > range.start -> range + range.endInclusive < range.start -> range.endInclusive..range.start + else -> return DoubleBuffer(range.start) + } + val numberOfPoints = floor(normalizedRange.length / step).toInt() + 1 + return DoubleBuffer(numberOfPoints) { normalizedRange.start + step * it } +} + +/** + * Convert double range to sequence. + * + * If the step is positive, than the sequence starts with the lower boundary and increments by [step] until current value is lower than upper boundary. + * The boundary itself is not necessary included. + * + * If step is negative, the same goes from upper boundary downwards + */ +@UnstableKMathAPI +public infix fun ClosedFloatingPointRange.step(step: Double): DoubleBuffer = Buffer.withFixedStep(this, step) \ No newline at end of file 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..95faec4b3 --- /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.BufferND +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.structures.DoubleBuffer + +/** + * Map one [BufferND] using function without indices. + */ +public inline fun BufferND.mapInline(crossinline transform: DoubleField.(Double) -> Double): BufferND { + val array = DoubleArray(strides.linearSize) { offset -> DoubleField.transform(buffer[offset]) } + return BufferND(strides, DoubleBuffer(array)) +} + +/** + * Element by element application of any operation on elements to the whole array. Just like in numpy. + */ +public operator fun Function1.invoke(elementND: BufferND): BufferND = + elementND.mapInline { this@invoke(it) } + +/* plus and minus */ + +/** + * Summation operation for [BufferND] and single element + */ +public operator fun BufferND.plus(arg: Double): BufferND = mapInline { it + arg } + +/** + * Subtraction operation between [BufferND] and single element + */ +public operator fun BufferND.minus(arg: Double): BufferND = mapInline { it - arg } \ No newline at end of file diff --git a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleMatrixTest.kt similarity index 67% rename from kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt rename to kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleMatrixTest.kt index 7c3540a2e..1c47d803a 100644 --- a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleMatrixTest.kt @@ -1,15 +1,21 @@ package kaceince.kmath.real -import kscience.kmath.linear.Matrix -import kscience.kmath.linear.build -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.real.* -import kscience.kmath.structures.contentEquals +import space.kscience.kmath.linear.LinearSpace +import space.kscience.kmath.linear.matrix +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.real.* +import space.kscience.kmath.structures.contentEquals import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue -internal class RealMatrixTest { +fun assertMatrixEquals(expected: StructureND, actual: StructureND) { + assertTrue { StructureND.contentEquals(expected, actual) } +} + +@UnstableKMathAPI +internal class DoubleMatrixTest { @Test fun testSum() { val m = realMatrix(10, 10) { i, j -> (i + j).toDouble() } @@ -30,11 +36,11 @@ internal class RealMatrixTest { @Test fun testRepeatStackVertical() { - val matrix1 = Matrix.build(2, 3)( + val matrix1 = realMatrix(2, 3)( 1.0, 0.0, 0.0, 0.0, 1.0, 2.0 ) - val matrix2 = Matrix.build(6, 3)( + val matrix2 = realMatrix(6, 3)( 1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 1.0, 0.0, 0.0, @@ -42,94 +48,94 @@ internal class RealMatrixTest { 1.0, 0.0, 0.0, 0.0, 1.0, 2.0 ) - assertEquals(matrix2, matrix1.repeatStackVertical(3)) + assertMatrixEquals(matrix2, matrix1.repeatStackVertical(3)) } @Test fun testMatrixAndDouble() { - val matrix1 = Matrix.build(2, 3)( + val matrix1 = realMatrix(2, 3)( 1.0, 0.0, 3.0, 4.0, 6.0, 2.0 ) val matrix2 = (matrix1 * 2.5 + 1.0 - 2.0) / 2.0 - val expectedResult = Matrix.build(2, 3)( + val expectedResult = LinearSpace.real.matrix(2, 3)( 0.75, -0.5, 3.25, 4.5, 7.0, 2.0 ) - assertEquals(matrix2, expectedResult) + assertMatrixEquals(matrix2, expectedResult) } @Test fun testDoubleAndMatrix() { - val matrix1 = Matrix.build(2, 3)( + val matrix1 = realMatrix(2, 3)( 1.0, 0.0, 3.0, 4.0, 6.0, 2.0 ) val matrix2 = 20.0 - (10.0 + (5.0 * matrix1)) //val matrix2 = 10.0 + (5.0 * matrix1) - val expectedResult = Matrix.build(2, 3)( + val expectedResult = realMatrix(2, 3)( 5.0, 10.0, -5.0, -10.0, -20.0, 0.0 ) - assertEquals(matrix2, expectedResult) + assertMatrixEquals(matrix2, expectedResult) } @Test fun testSquareAndPower() { - val matrix1 = Matrix.build(2, 3)( + val matrix1 = realMatrix(2, 3)( -1.0, 0.0, 3.0, 4.0, -6.0, -2.0 ) - val matrix2 = Matrix.build(2, 3)( + val matrix2 = realMatrix(2, 3)( 1.0, 0.0, 9.0, 16.0, 36.0, 4.0 ) - val matrix3 = Matrix.build(2, 3)( + val matrix3 = realMatrix(2, 3)( -1.0, 0.0, 27.0, 64.0, -216.0, -8.0 ) - assertEquals(matrix1.square(), matrix2) - assertEquals(matrix1.pow(3), matrix3) + assertMatrixEquals(matrix1.square(), matrix2) + assertMatrixEquals(matrix1.pow(3), matrix3) } @OptIn(UnstableKMathAPI::class) @Test fun testTwoMatrixOperations() { - val matrix1 = Matrix.build(2, 3)( + val matrix1 = realMatrix(2, 3)( -1.0, 0.0, 3.0, 4.0, -6.0, 7.0 ) - val matrix2 = Matrix.build(2, 3)( + val matrix2 = realMatrix(2, 3)( 1.0, 0.0, 3.0, 4.0, 6.0, -2.0 ) val result = matrix1 * matrix2 + matrix1 - matrix2 - val expectedResult = Matrix.build(2, 3)( + val expectedResult = realMatrix(2, 3)( -3.0, 0.0, 9.0, 16.0, -48.0, -5.0 ) - assertEquals(result, expectedResult) + assertMatrixEquals(result, expectedResult) } @Test fun testColumnOperations() { - val matrix1 = Matrix.build(2, 4)( + val matrix1 = realMatrix(2, 4)( -1.0, 0.0, 3.0, 15.0, 4.0, -6.0, 7.0, -11.0 ) - val matrix2 = Matrix.build(2, 5)( + val matrix2 = realMatrix(2, 5)( -1.0, 0.0, 3.0, 15.0, -1.0, 4.0, -6.0, 7.0, -11.0, 4.0 ) - val col1 = Matrix.build(2, 1)(0.0, -6.0) - val cols1to2 = Matrix.build(2, 2)( + val col1 = realMatrix(2, 1)(0.0, -6.0) + val cols1to2 = realMatrix(2, 2)( 0.0, 3.0, -6.0, 7.0 ) - assertEquals(matrix1.appendColumn { it[0] }, matrix2) - assertEquals(matrix1.extractColumn(1), col1) - assertEquals(matrix1.extractColumns(1..2), cols1to2) + assertMatrixEquals(matrix1.appendColumn { it[0] }, matrix2) + assertMatrixEquals(matrix1.extractColumn(1), col1) + assertMatrixEquals(matrix1.extractColumns(1..2), cols1to2) //equals should never be called on buffers assertTrue { matrix1.sumByColumn().contentEquals(3.0, -6.0, 10.0, 4.0) @@ -147,7 +153,7 @@ internal class RealMatrixTest { @Test fun testAllElementOperations() { - val matrix1 = Matrix.build(2, 4)( + val matrix1 = LinearSpace.real.matrix(2, 4)( -1.0, 0.0, 3.0, 15.0, 4.0, -6.0, 7.0, -11.0 ) diff --git a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleVectorTest.kt b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleVectorTest.kt new file mode 100644 index 000000000..669f88186 --- /dev/null +++ b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleVectorTest.kt @@ -0,0 +1,37 @@ +package kaceince.kmath.real + +import space.kscience.kmath.linear.LinearSpace +import space.kscience.kmath.linear.asMatrix +import space.kscience.kmath.linear.transpose +import space.kscience.kmath.real.plus +import space.kscience.kmath.structures.DoubleBuffer +import kotlin.test.Test +import kotlin.test.assertEquals + +internal class DoubleVectorTest { + @Test + fun testSum() { + val vector1 = DoubleBuffer(5) { it.toDouble() } + val vector2 = DoubleBuffer(5) { 5 - it.toDouble() } + val sum = vector1 + vector2 + assertEquals(5.0, sum[2]) + } + + @Test + fun testVectorToMatrix() { + val vector = DoubleBuffer(5) { it.toDouble() } + val matrix = vector.asMatrix() + assertEquals(4.0, matrix[4, 0]) + } + + @Test + fun testDot() { + val vector1 = DoubleBuffer(5) { it.toDouble() } + val vector2 = DoubleBuffer(5) { 5 - it.toDouble() } + val matrix1 = vector1.asMatrix() + val matrix2 = vector2.asMatrix().transpose() + val product = LinearSpace.real.run { matrix1 dot matrix2 } + assertEquals(5.0, product[1, 0]) + assertEquals(6.0, product[2, 2]) + } +} 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..91ee517ab 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,13 +1,18 @@ package kaceince.kmath.real -import kscience.kmath.real.step +import space.kscience.kmath.real.DoubleVector +import space.kscience.kmath.real.minus +import space.kscience.kmath.real.norm +import space.kscience.kmath.real.step import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue class GridTest { @Test - fun testStepGrid(){ + fun testStepGrid() { val grid = 0.0..1.0 step 0.2 assertEquals(6, grid.size) + assertTrue { (grid - DoubleVector(0.0, 0.2, 0.4, 0.6, 0.8, 1.0)).norm < 1e-4 } } } \ No newline at end of file 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 deleted file mode 100644 index 6215ba5e8..000000000 --- a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealVectorTest.kt +++ /dev/null @@ -1,37 +0,0 @@ -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 kotlin.test.Test -import kotlin.test.assertEquals - -internal class RealVectorTest { - @Test - fun testSum() { - val vector1 = Buffer.real(5) { it.toDouble() } - val vector2 = Buffer.real(5) { 5 - it.toDouble() } - val sum = vector1 + vector2 - assertEquals(5.0, sum[2]) - } - - @Test - fun testVectorToMatrix() { - val vector = Buffer.real(5) { it.toDouble() } - val matrix = vector.asMatrix() - assertEquals(4.0, matrix[4, 0]) - } - - @Test - fun testDot() { - val vector1 = Buffer.real(5) { it.toDouble() } - val vector2 = Buffer.real(5) { 5 - it.toDouble() } - val matrix1 = vector1.asMatrix() - val matrix2 = vector2.asMatrix().transpose() - val product = MatrixContext.real { matrix1 dot matrix2 } - assertEquals(5.0, product[1, 0]) - assertEquals(6.0, product[2, 2]) - } -} diff --git a/kmath-functions/README.md b/kmath-functions/README.md index f5462e09f..531e97a44 100644 --- a/kmath-functions/README.md +++ b/kmath-functions/README.md @@ -1,47 +1,38 @@ -# Functions (`kmath-functions`) +# Module kmath-functions -Functions and interpolations: +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 + - [piecewise](Piecewise functions.) : src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt + - [polynomials](Polynomial functions.) : src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt + - [linear interpolation](Linear XY interpolator.) : src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt + - [spline interpolation](Cubic spline XY interpolator.) : src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt -> #### Artifact: -> -> This module artifact: `kscience.kmath:kmath-functions:0.2.0-dev-7`. -> -> 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://dl.bintray.com/kotlin/kotlin-eap" } -> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } -> maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> -> } -> -> dependencies { -> implementation 'kscience.kmath:kmath-functions:0.2.0-dev-7' -> } -> ``` -> **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") -> } -> -> dependencies { -> implementation("kscience.kmath:kmath-functions:0.2.0-dev-7") -> } -> ``` +## Artifact: + +The Maven coordinates of this project are `space.kscience:kmath-functions:0.3.0-dev-3`. + +**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 +} + +dependencies { + implementation 'space.kscience:kmath-functions:0.3.0-dev-3' +} +``` +**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 +} + +dependencies { + implementation("space.kscience:kmath-functions:0.3.0-dev-3") +} +``` diff --git a/kmath-functions/build.gradle.kts b/kmath-functions/build.gradle.kts index 3af61a199..51fc75501 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 { @@ -13,8 +13,12 @@ readme { 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.") + feature("piecewise", "src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt", "Piecewise functions.") + feature("polynomials", "src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt", "Polynomial functions.") + feature("linear interpolation", + "src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt", + "Linear XY interpolator.") + feature("spline interpolation", + "src/commonMain/kotlin/space/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 index 8a34a7cc4..2e163eee5 100644 --- a/kmath-functions/docs/README-TEMPLATE.md +++ b/kmath-functions/docs/README-TEMPLATE.md @@ -1,6 +1,6 @@ -# Functions (`kmath-functions`) +# Module kmath-functions -Functions and interpolations: +Functions and interpolations. ${features} diff --git a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/Interpolator.kt b/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/Interpolator.kt deleted file mode 100644 index 0620b4aa8..000000000 --- a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/Interpolator.kt +++ /dev/null @@ -1,45 +0,0 @@ -package 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 - -public fun interface Interpolator { - public fun interpolate(points: XYPointSet): (X) -> Y -} - -public interface PolynomialInterpolator> : Interpolator { - public val algebra: Ring - - public fun getDefaultValue(): T = error("Out of bounds") - - public fun interpolatePolynomials(points: XYPointSet): PiecewisePolynomial - - override fun interpolate(points: XYPointSet): (T) -> T = { x -> - interpolatePolynomials(points).value(algebra, x) ?: getDefaultValue() - } -} - -public fun > PolynomialInterpolator.interpolatePolynomials( - x: Buffer, - y: Buffer -): PiecewisePolynomial { - val pointSet = BufferXYPointSet(x, y) - return interpolatePolynomials(pointSet) -} - -public fun > PolynomialInterpolator.interpolatePolynomials( - data: Map -): PiecewisePolynomial { - val pointSet = BufferXYPointSet(data.keys.toList().asBuffer(), data.values.toList().asBuffer()) - return interpolatePolynomials(pointSet) -} - -public fun > PolynomialInterpolator.interpolatePolynomials( - data: List> -): PiecewisePolynomial { - val pointSet = BufferXYPointSet(data.map { it.first }.asBuffer(), data.map { it.second }.asBuffer()) - return interpolatePolynomials(pointSet) -} diff --git a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/XYPointSet.kt b/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/XYPointSet.kt deleted file mode 100644 index bdece28e7..000000000 --- a/kmath-functions/src/commonMain/kotlin/kscience/kmath/interpolation/XYPointSet.kt +++ /dev/null @@ -1,53 +0,0 @@ -package kscience.kmath.interpolation - -import kscience.kmath.nd.Structure2D -import kscience.kmath.structures.Buffer - -public interface XYPointSet { - public val size: Int - public val x: Buffer - public val y: Buffer -} - -public interface XYZPointSet : XYPointSet { - public val z: Buffer -} - -internal fun > insureSorted(points: XYPointSet) { - for (i in 0 until points.size - 1) - require(points.x[i + 1] > points.x[i]) { "Input data is not sorted at index $i" } -} - -public class NDStructureColumn(public val structure: Structure2D, public val column: Int) : Buffer { - public override val size: Int - get() = structure.rowNum - - init { - require(column < structure.colNum) { "Column index is outside of structure column range" } - } - - public override operator fun get(index: Int): T = structure[index, column] - public override operator fun iterator(): Iterator = sequence { repeat(size) { yield(get(it)) } }.iterator() -} - -public class BufferXYPointSet( - public override val x: Buffer, - public override val y: Buffer -) : XYPointSet { - public override val size: Int - get() = x.size - - init { - require(x.size == y.size) { "Sizes of x and y buffers should be the same" } - } -} - -public fun Structure2D.asXYPointSet(): XYPointSet { - require(shape[1] == 2) { "Structure second dimension should be of size 2" } - - return object : XYPointSet { - override val size: Int get() = this@asXYPointSet.shape[0] - override val x: Buffer get() = NDStructureColumn(this@asXYPointSet, 0) - override val y: Buffer get() = NDStructureColumn(this@asXYPointSet, 1) - } -} 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 58% 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 95242c245..2477af618 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,15 +1,29 @@ -package kscience.kmath.functions +package space.kscience.kmath.functions -import kscience.kmath.operations.Ring +import space.kscience.kmath.operations.Ring +/** + * Represents piecewise-defined function. + * + * @param T the piece key type. + * @param R the sub-function type. + */ public fun interface Piecewise { + /** + * Returns the appropriate sub-function for given piece key. + */ public fun findPiece(arg: T): R? } +/** + * Represents piecewise-defined function where all the sub-functions are polynomials. + */ public fun interface PiecewisePolynomial : Piecewise> /** - * Ordered list of pieces in piecewise function + * Basic [Piecewise] implementation where all the pieces are ordered by the [Comparable] type instances. + * + * @param T the comparable piece key type. */ public class OrderedPiecewisePolynomial>(delimiter: T) : PiecewisePolynomial { @@ -17,8 +31,10 @@ public class OrderedPiecewisePolynomial>(delimiter: T) : private val pieces: MutableList> = arrayListOf() /** - * Dynamically add a piece to the "right" side (beyond maximum argument value of previous piece) - * @param right new rightmost position. If is less then current rightmost position, a error is thrown. + * Dynamically adds a piece to the right side (beyond maximum argument value of previous piece) + * + * @param right new rightmost position. If is less then current rightmost position, an error is thrown. + * @param piece the sub-function. */ public fun putRight(right: T, piece: Polynomial) { require(right > delimiters.last()) { "New delimiter should be to the right of old one" } @@ -26,13 +42,19 @@ public class OrderedPiecewisePolynomial>(delimiter: T) : pieces += piece } + /** + * Dynamically adds a piece to the left side (beyond maximum argument value of previous piece) + * + * @param left the new leftmost position. If is less then current rightmost position, an error is thrown. + * @param piece the sub-function. + */ public fun putLeft(left: T, piece: Polynomial) { require(left < delimiters.first()) { "New delimiter should be to the left of old one" } delimiters.add(0, left) pieces.add(0, piece) } - override fun findPiece(arg: T): Polynomial? { + public override fun findPiece(arg: T): Polynomial? { if (arg < delimiters.first() || arg >= delimiters.last()) return null else { @@ -46,7 +68,8 @@ public class OrderedPiecewisePolynomial>(delimiter: T) : } /** - * Return a value of polynomial function with given [ring] an given [arg] or null if argument is outside of piecewise definition. + * Return a value of polynomial function with given [ring] an given [arg] or null if argument is outside of piecewise + * definition. */ public fun , C : Ring> PiecewisePolynomial.value(ring: C, arg: T): T? = findPiece(arg)?.value(ring, arg) 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 52% 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..550785812 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,24 +1,35 @@ -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.Group +import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.operations.invoke import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.math.max import kotlin.math.pow /** - * Polynomial coefficients without fixation on specific context they are applied to - * @param coefficients constant is the leftmost coefficient + * Polynomial coefficients model without fixation on specific context they are applied to. + * + * @param coefficients constant is the leftmost coefficient. */ public inline class Polynomial(public val coefficients: List) +/** + * Returns a [Polynomial] instance with given [coefficients]. + */ @Suppress("FunctionName") public fun Polynomial(vararg coefficients: T): Polynomial = Polynomial(coefficients.toList()) +/** + * Evaluates the value of the given double polynomial for given double argument. + */ public fun Polynomial.value(): Double = coefficients.reduceIndexed { index, acc, d -> acc + d.pow(index) } +/** + * Evaluates the value of the given polynomial for given argument. + */ public fun > Polynomial.value(ring: C, arg: T): T = ring { if (coefficients.isEmpty()) return@ring zero var res = coefficients.first() @@ -34,16 +45,26 @@ public fun > Polynomial.value(ring: C, arg: T): T = ring } /** - * Represent the polynomial as a regular context-less function + * Represent the polynomial as a regular context-less function. */ public fun > Polynomial.asFunction(ring: C): (T) -> T = { value(ring, it) } /** - * An algebra for polynomials + * Space of polynomials. + * + * @param T the type of operated polynomials. + * @param C the intersection of [Ring] of [T] and [ScaleOperations] of [T]. + * @param ring the [C] instance. */ -public class PolynomialSpace>(private val ring: C) : Space> { +public class PolynomialSpace( + private val ring: C, +) : Group>, ScaleOperations> where C : Ring, C : ScaleOperations { public override val zero: Polynomial = Polynomial(emptyList()) + override fun Polynomial.unaryMinus(): Polynomial = ring { + Polynomial(coefficients.map { -it }) + } + public override fun add(a: Polynomial, b: Polynomial): Polynomial { val dim = max(a.coefficients.size, b.coefficients.size) @@ -54,13 +75,16 @@ public class PolynomialSpace>(private val ring: C) : Space< } } - public override fun multiply(a: Polynomial, k: Number): Polynomial = - ring { Polynomial(List(a.coefficients.size) { index -> a.coefficients[index] * k }) } + public override fun scale(a: Polynomial, value: Double): Polynomial = + ring { Polynomial(List(a.coefficients.size) { index -> a.coefficients[index] * value }) } + /** + * Evaluates the polynomial for the given value [arg]. + */ public operator fun Polynomial.invoke(arg: T): T = value(ring, arg) } -public inline fun , R> C.polynomial(block: PolynomialSpace.() -> R): R { +public inline fun C.polynomial(block: PolynomialSpace.() -> R): R where C : Ring, C : ScaleOperations { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return PolynomialSpace(this).block() } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt new file mode 100644 index 000000000..336a3ef3a --- /dev/null +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt @@ -0,0 +1,23 @@ +package space.kscience.kmath.integration + +import kotlin.reflect.KClass + +public interface IntegrandFeature + +public interface Integrand { + public fun getFeature(type: KClass): T? +} + +public inline fun Integrand.getFeature(): T? = getFeature(T::class) + +public class IntegrandValue(public val value: T) : IntegrandFeature + +public class IntegrandRelativeAccuracy(public val accuracy: Double) : IntegrandFeature + +public class IntegrandAbsoluteAccuracy(public val accuracy: Double) : IntegrandFeature + +public class IntegrandCalls(public val calls: Int) : IntegrandFeature + +public val Integrand.calls: Int get() = getFeature()?.calls ?: 0 + +public class IntegrandMaxCalls(public val maxCalls: Int) : IntegrandFeature diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt new file mode 100644 index 000000000..e421fb680 --- /dev/null +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt @@ -0,0 +1,11 @@ +package space.kscience.kmath.integration + +/** + * A general interface for all integrators. + */ +public interface Integrator { + /** + * Runs one integration pass and return a new [Integrand] with a new set of features. + */ + public fun integrate(integrand: I): I +} diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt new file mode 100644 index 000000000..4b3a6deb4 --- /dev/null +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt @@ -0,0 +1,27 @@ +package space.kscience.kmath.integration + +import space.kscience.kmath.linear.Point +import kotlin.reflect.KClass + +public class MultivariateIntegrand internal constructor( + private val features: Map, IntegrandFeature>, + public val function: (Point) -> T, +) : Integrand { + + @Suppress("UNCHECKED_CAST") + override fun getFeature(type: KClass): T? = features[type] as? T + + public operator fun plus(pair: Pair, F>): MultivariateIntegrand = + MultivariateIntegrand(features + pair, function) + + public operator fun plus(feature: F): MultivariateIntegrand = + plus(feature::class to feature) +} + +@Suppress("FunctionName") +public fun MultivariateIntegrand( + vararg features: IntegrandFeature, + function: (Point) -> T, +): MultivariateIntegrand = MultivariateIntegrand(features.associateBy { it::class }, function) + +public val MultivariateIntegrand.value: T? get() = getFeature>()?.value diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt new file mode 100644 index 000000000..ca4bbf6b8 --- /dev/null +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt @@ -0,0 +1,64 @@ +package space.kscience.kmath.integration + +import space.kscience.kmath.misc.UnstableKMathAPI +import kotlin.reflect.KClass + +public class UnivariateIntegrand internal constructor( + private val features: Map, IntegrandFeature>, + public val function: (T) -> T, +) : Integrand { + + @Suppress("UNCHECKED_CAST") + override fun getFeature(type: KClass): T? = features[type] as? T + + public operator fun plus(pair: Pair, F>): UnivariateIntegrand = + UnivariateIntegrand(features + pair, function) + + public operator fun plus(feature: F): UnivariateIntegrand = + plus(feature::class to feature) +} + +@Suppress("FunctionName") +public fun UnivariateIntegrand( + function: (T) -> T, + vararg features: IntegrandFeature, +): UnivariateIntegrand = UnivariateIntegrand(features.associateBy { it::class }, function) + +public typealias UnivariateIntegrator = Integrator> + +public inline class IntegrationRange>(public val range: ClosedRange) : IntegrandFeature + +public val UnivariateIntegrand.value: T? get() = getFeature>()?.value + +/** + * A shortcut method to integrate a [function] in [range] with additional [features]. + * The [function] is placed in the end position to allow passing a lambda. + */ +@UnstableKMathAPI +public fun UnivariateIntegrator.integrate( + range: ClosedRange, + vararg features: IntegrandFeature, + function: (Double) -> Double, +): Double = integrate( + UnivariateIntegrand(function, IntegrationRange(range), *features) +).value ?: error("Unexpected: no value after integration.") + +/** + * A shortcut method to integrate a [function] in [range] with additional [features]. + * The [function] is placed in the end position to allow passing a lambda. + */ +@UnstableKMathAPI +public fun UnivariateIntegrator.integrate( + range: ClosedRange, + function: (Double) -> Double, + featureBuilder: (MutableList.() -> Unit) = {}, +): Double { + //TODO use dedicated feature builder class instead or add extensions to MutableList + val features = buildList { + featureBuilder() + add(IntegrationRange(range)) + } + return integrate( + UnivariateIntegrand(function, *features.toTypedArray()) + ).value ?: error("Unexpected: no value after integration.") +} diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt new file mode 100644 index 000000000..9fad30abb --- /dev/null +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt @@ -0,0 +1,50 @@ +@file:OptIn(UnstableKMathAPI::class) + +package space.kscience.kmath.interpolation + +import space.kscience.kmath.data.XYColumnarData +import space.kscience.kmath.functions.PiecewisePolynomial +import space.kscience.kmath.functions.value +import space.kscience.kmath.misc.UnstableKMathAPI +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: XYColumnarData): (X) -> Y +} + +public interface PolynomialInterpolator> : Interpolator { + public val algebra: Ring + + public fun getDefaultValue(): T = error("Out of bounds") + + public fun interpolatePolynomials(points: XYColumnarData): PiecewisePolynomial + + override fun interpolate(points: XYColumnarData): (T) -> T = { x -> + interpolatePolynomials(points).value(algebra, x) ?: getDefaultValue() + } +} + + +public fun > PolynomialInterpolator.interpolatePolynomials( + x: Buffer, + y: Buffer, +): PiecewisePolynomial { + val pointSet = XYColumnarData(x, y) + return interpolatePolynomials(pointSet) +} + +public fun > PolynomialInterpolator.interpolatePolynomials( + data: Map, +): PiecewisePolynomial { + val pointSet = XYColumnarData(data.keys.toList().asBuffer(), data.values.toList().asBuffer()) + return interpolatePolynomials(pointSet) +} + +public fun > PolynomialInterpolator.interpolatePolynomials( + data: List>, +): PiecewisePolynomial { + val pointSet = XYColumnarData(data.map { it.first }.asBuffer(), data.map { it.second }.asBuffer()) + return interpolatePolynomials(pointSet) +} 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 50% 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..37d378ad0 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,16 +1,25 @@ -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.data.XYColumnarData +import space.kscience.kmath.functions.OrderedPiecewisePolynomial +import space.kscience.kmath.functions.PiecewisePolynomial +import space.kscience.kmath.functions.Polynomial +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.Field +import space.kscience.kmath.operations.invoke + +@OptIn(UnstableKMathAPI::class) +internal fun > insureSorted(points: XYColumnarData<*, T, *>) { + for (i in 0 until points.size - 1) + require(points.x[i + 1] > points.x[i]) { "Input data is not sorted at index $i" } +} /** * Reference JVM implementation: https://github.com/apache/commons-math/blob/master/src/main/java/org/apache/commons/math4/analysis/interpolation/LinearInterpolator.java */ public class LinearInterpolator>(public override val algebra: Field) : PolynomialInterpolator { - public override fun interpolatePolynomials(points: XYPointSet): PiecewisePolynomial = algebra { + @OptIn(UnstableKMathAPI::class) + public override fun interpolatePolynomials(points: XYColumnarData): PiecewisePolynomial = algebra { require(points.size > 0) { "Point array should not be empty" } insureSorted(points) 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 64% 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..3a3dfab59 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,23 +1,29 @@ -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.data.XYColumnarData +import space.kscience.kmath.functions.OrderedPiecewisePolynomial +import space.kscience.kmath.functions.PiecewisePolynomial +import space.kscience.kmath.functions.Polynomial +import space.kscience.kmath.misc.UnstableKMathAPI +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. - * Based on https://github.com/apache/commons-math/blob/eb57d6d457002a0bb5336d789a3381a24599affe/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java + * Generic spline interpolator. Not recommended for performance critical places, use platform-specific and type + * specific ones. + * + * Based on + * https://github.com/apache/commons-math/blob/eb57d6d457002a0bb5336d789a3381a24599affe/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java */ public class SplineInterpolator>( public override val algebra: Field, - public val bufferFactory: MutableBufferFactory + public val bufferFactory: MutableBufferFactory, ) : PolynomialInterpolator { //TODO possibly optimize zeroed buffers - public override fun interpolatePolynomials(points: XYPointSet): PiecewisePolynomial = algebra { + @OptIn(UnstableKMathAPI::class) + public override fun interpolatePolynomials(points: XYColumnarData): PiecewisePolynomial = algebra { require(points.size >= 3) { "Can't use spline interpolator with less than 3 points" } insureSorted(points) // Number of intervals. The number of data points is n + 1. 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 62% 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..476c035e9 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.DoubleField import kotlin.test.Test import kotlin.test.assertEquals @@ -16,8 +16,8 @@ internal class LinearInterpolatorTest { 3.0 to 4.0 ) - val polynomial: PiecewisePolynomial = LinearInterpolator(RealField).interpolatePolynomials(data) - val function = polynomial.asFunction(RealField) + val polynomial: PiecewisePolynomial = LinearInterpolator(DoubleField).interpolatePolynomials(data) + val function = polynomial.asFunction(DoubleField) assertEquals(null, function(-1.0)) assertEquals(0.5, function(0.5)) assertEquals(2.0, function(1.5)) diff --git a/kmath-geometry/build.gradle.kts b/kmath-geometry/build.gradle.kts index e27496a41..9d1b2d4d6 100644 --- a/kmath-geometry/build.gradle.kts +++ b/kmath-geometry/build.gradle.kts @@ -1,4 +1,4 @@ -plugins { id("ru.mipt.npm.mpp") } +plugins { id("ru.mipt.npm.gradle.mpp") } kotlin.sourceSets.commonMain { dependencies { @@ -6,6 +6,6 @@ kotlin.sourceSets.commonMain { } } -readme{ +readme { maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE } diff --git a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/GeometrySpace.kt b/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/GeometrySpace.kt deleted file mode 100644 index 54d2510cf..000000000 --- a/kmath-geometry/src/commonMain/kotlin/kscience/kmath/geometry/GeometrySpace.kt +++ /dev/null @@ -1,17 +0,0 @@ -package kscience.kmath.geometry - -import kscience.kmath.operations.Space - -public interface Vector - -public interface GeometrySpace : Space { - /** - * L2 distance - */ - public fun V.distanceTo(other: V): Double - - /** - * Scalar product - */ - public infix fun V.dot(other: V): Double -} \ No newline at end of file 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 69% 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 7714dc939..54a1e032c 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,9 +1,10 @@ -package kscience.kmath.geometry +package space.kscience.kmath.geometry -import kscience.kmath.linear.Point -import kscience.kmath.misc.UnstableKMathAPI -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.ScaleOperations +import space.kscience.kmath.operations.SpaceElement +import space.kscience.kmath.operations.invoke import kotlin.math.sqrt @OptIn(UnstableKMathAPI::class) @@ -30,18 +31,20 @@ public fun Vector2D(x: Double, y: Double): Vector2D = Vector2DImpl(x, y) private data class Vector2DImpl( override val x: Double, - override val y: Double + override val y: Double, ) : Vector2D /** * 2D Euclidean space */ -public object Euclidean2DSpace : GeometrySpace { +public object Euclidean2DSpace : GeometrySpace, ScaleOperations { public override val zero: Vector2D by lazy { Vector2D(0.0, 0.0) } public fun Vector2D.norm(): Double = sqrt(x * x + y * y) + override fun Vector2D.unaryMinus(): Vector2D = Vector2D(-x, -y) + public override fun Vector2D.distanceTo(other: Vector2D): Double = (this - other).norm() public override fun add(a: Vector2D, b: Vector2D): Vector2D = Vector2D(a.x + b.x, a.y + b.y) - public override fun multiply(a: Vector2D, k: Number): Vector2D = Vector2D(a.x * k.toDouble(), a.y * k.toDouble()) + public override fun scale(a: Vector2D, value: Double): Vector2D = Vector2D(a.x * value, a.y * value) public override fun Vector2D.dot(other: Vector2D): Double = x * other.x + y * other.y } 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 70% 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 00daa2d75..ed110e383 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,9 +1,10 @@ -package kscience.kmath.geometry +package space.kscience.kmath.geometry -import kscience.kmath.linear.Point -import kscience.kmath.misc.UnstableKMathAPI -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.ScaleOperations +import space.kscience.kmath.operations.SpaceElement +import space.kscience.kmath.operations.invoke import kotlin.math.sqrt @OptIn(UnstableKMathAPI::class) @@ -32,21 +33,22 @@ public val Vector3D.r: Double get() = Euclidean3DSpace { sqrt(norm()) } private data class Vector3DImpl( override val x: Double, override val y: Double, - override val z: Double + override val z: Double, ) : Vector3D -public object Euclidean3DSpace : GeometrySpace { +public object Euclidean3DSpace : GeometrySpace, ScaleOperations { public override val zero: Vector3D by lazy { Vector3D(0.0, 0.0, 0.0) } public fun Vector3D.norm(): Double = sqrt(x * x + y * y + z * z) + override fun Vector3D.unaryMinus(): Vector3D = Vector3D(-x, -y, -z) public override fun Vector3D.distanceTo(other: Vector3D): Double = (this - other).norm() public override fun add(a: Vector3D, b: Vector3D): Vector3D = Vector3D(a.x + b.x, a.y + b.y, a.z + b.z) - public override fun multiply(a: Vector3D, k: Number): Vector3D = - Vector3D(a.x * k.toDouble(), a.y * k.toDouble(), a.z * k.toDouble()) + public override fun scale(a: Vector3D, value: Double): Vector3D = + Vector3D(a.x * value, a.y * value, a.z * value) public override fun Vector3D.dot(other: Vector3D): Double = x * other.x + y * other.y + z * other.z diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt new file mode 100644 index 000000000..9552c1320 --- /dev/null +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt @@ -0,0 +1,18 @@ +package space.kscience.kmath.geometry + +import space.kscience.kmath.operations.Group +import space.kscience.kmath.operations.ScaleOperations + +public interface Vector + +public interface GeometrySpace : Group, ScaleOperations { + /** + * L2 distance + */ + public fun V.distanceTo(other: V): Double + + /** + * Scalar product + */ + public infix fun V.dot(other: V): Double +} \ No newline at end of file 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 40196416e..1337e40aa 100644 --- a/kmath-histograms/build.gradle.kts +++ b/kmath-histograms/build.gradle.kts @@ -1,4 +1,10 @@ -plugins { id("ru.mipt.npm.mpp") } +plugins { + id("ru.mipt.npm.gradle.mpp") +} + +kscience { + useAtomic() +} kotlin.sourceSets { commonMain { @@ -6,8 +12,8 @@ kotlin.sourceSets { api(project(":kmath-core")) } } - commonTest{ - dependencies{ + commonTest { + dependencies { implementation(project(":kmath-for-real")) } } 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 21d873806..000000000 --- a/kmath-histograms/src/commonMain/kotlin/kscience/kmath/histogram/RealHistogram.kt +++ /dev/null @@ -1,165 +0,0 @@ -package kscience.kmath.histogram - -import kscience.kmath.linear.Point -import kscience.kmath.nd.DefaultStrides -import kscience.kmath.nd.NDStructure -import kscience.kmath.operations.SpaceOperations -import kscience.kmath.operations.invoke -import kscience.kmath.structures.* -import kotlin.math.floor - -public data class MultivariateBinDefinition>( - 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 definition: MultivariateBinDefinition, - public val count: Long, - public override val value: Double, -) : Bin { - public override val dimension: Int - get() = definition.center.size - - public override val center: Point - get() = definition.center - - public override operator fun contains(point: Point): Boolean = definition.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 counts: NDStructure = NDStructure.auto(strides) { LongCounter() } - private val values: 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 getCount(index: IntArray): Long = counts[index].sum() - - public fun getCount(point: Buffer): Long = getCount(getIndex(point)) - - private fun getValue(index: IntArray): Double = values[index].sum() - - public fun getValue(point: Buffer): Double = getValue(getIndex(point)) - - private fun getBinDefinition(index: IntArray): MultivariateBinDefinition { - 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 MultivariateBinDefinition(RealBufferFieldOperations, center, binSize) - } - - public fun getBinDefinition(point: Buffer): MultivariateBinDefinition = getBinDefinition(getIndex(point)) - - public override operator fun get(point: Buffer): MultivariateBin? { - val index = getIndex(point) - return MultivariateBin(getBinDefinition(index), getCount(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) - counts[index].increment() - values[index].add(weight) - } - - public override operator fun iterator(): Iterator> = - strides.indices().map { index-> - MultivariateBin(getBinDefinition(index), counts[index].sum(), values[index].sum()) - }.iterator() - - /** - * NDStructure containing number of events in bins without weights - */ - public fun counts(): NDStructure = NDStructure.auto(counts.shape) { counts[it].sum() } - - /** - * NDStructure containing values of bins including weights - */ - public fun values(): NDStructure = NDStructure.auto(values.shape) { values[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..764ff116c --- /dev/null +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt @@ -0,0 +1,50 @@ +package space.kscience.kmath.histogram + +import kotlinx.atomicfu.atomic +import kotlinx.atomicfu.getAndUpdate +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.Group + +/** + * 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(DoubleField) + } +} + +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 group: Group) : Counter { + private val innerValue = atomic(group.zero) + + override fun add(delta: T) { + innerValue.getAndUpdate { group.run { it + delta } } + } + + override val value: T get() = innerValue.value +} + + diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt new file mode 100644 index 000000000..384ce6159 --- /dev/null +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt @@ -0,0 +1,125 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.Domain +import space.kscience.kmath.domains.HyperSquareDomain +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.nd.* +import space.kscience.kmath.structures.* +import kotlin.math.floor + +public class DoubleHistogramSpace( + 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: DoubleFieldND = AlgebraND.real(*shape) + + override val strides: Strides get() = histogramValueSpace.strides + private val binSize = DoubleBuffer(dimension) { (upper[it] - lower[it]) / binNums[it] } + + /** + * Get internal [StructureND] 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]) + } + + @OptIn(UnstableKMathAPI::class) + 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 = StructureND.auto(strides) { Counter.real() } + val hBuilder = HistogramBuilder { point, value -> + val index = getIndex(point) + ndCounter[index].add(value.toDouble()) + } + hBuilder.apply(builder) + val values: BufferND = ndCounter.mapToBuffer { it.value } + return IndexedHistogram(this, values) + } + + override fun IndexedHistogram.unaryMinus(): IndexedHistogram = this * (-1) + + public companion object { + /** + * Use it like + * ``` + *FastHistogram.fromRanges( + * (-1.0..1.0), + * (-1.0..1.0) + *) + *``` + */ + public fun fromRanges(vararg ranges: ClosedFloatingPointRange): DoubleHistogramSpace = DoubleHistogramSpace( + 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>): DoubleHistogramSpace = + DoubleHistogramSpace( + 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/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..d680a9ad0 --- /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.DoubleBuffer +import space.kscience.kmath.structures.asBuffer + +/** + * 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(point.asBuffer()) + +public fun HistogramBuilder.put(vararg point: Number): Unit = + put(DoubleBuffer(point.map { it.toDouble() }.toDoubleArray())) + +public fun HistogramBuilder.put(vararg point: Double): Unit = put(DoubleBuffer(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..f55080b09 --- /dev/null +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/IndexedHistogramSpace.kt @@ -0,0 +1,78 @@ +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.FieldND +import space.kscience.kmath.nd.Strides +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.operations.Group +import space.kscience.kmath.operations.ScaleOperations +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: StructureND, +) : 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> + : Group>, ScaleOperations> { + //public val valueSpace: Space + public val strides: Strides + public val histogramValueSpace: FieldND //= 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 { a.values + b.values }) + } + + override fun scale(a: IndexedHistogram, value: Double): IndexedHistogram { + require(a.context == this) { "Can't operate on a histogram produced by external space" } + return IndexedHistogram(this, histogramValueSpace { a.values * value }) + } + + override val zero: IndexedHistogram get() = produce { } +} + 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 87a2b3e68..000000000 --- a/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt +++ /dev/null @@ -1,45 +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 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..feb87a7a7 --- /dev/null +++ b/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt @@ -0,0 +1,77 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.real.DoubleVector +import kotlin.random.Random +import kotlin.test.* + +internal class MultivariateHistogramTest { + @Test + fun testSinglePutHistogram() { + val hSpace = DoubleHistogramSpace.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(DoubleVector(0.55, 0.55)) } + assertTrue { bin.contains(DoubleVector(0.6, 0.5)) } + assertFalse { bin.contains(DoubleVector(-0.55, 0.55)) } + } + + @Test + fun testSequentialPut() { + val hSpace = DoubleHistogramSpace.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() { + DoubleHistogramSpace.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 10aa9f8ca..000000000 --- a/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/UnivariateHistogram.kt +++ /dev/null @@ -1,161 +0,0 @@ -package kscience.kmath.histogram - -import kscience.kmath.linear.Point -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.operations.SpaceElement -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.asBuffer -import kscience.kmath.structures.asSequence -import java.util.* -import kotlin.math.floor - -//TODO move to common - -public class UnivariateBin( - public val position: Double, - public val size: Double, -) : Bin { - //internal mutation operations - internal val counter: LongCounter = LongCounter() - internal val weightCounter: DoubleCounter = DoubleCounter() - - /** - * The precise number of events ignoring weighting - */ - public val count: Long get() = counter.sum() - - /** - * The value of histogram including weighting - */ - public override val value: Double get() = weightCounter.sum() - - public override val center: Point 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]) -} - -/** - * Univariate histogram with log(n) bin search speed - */ -@OptIn(UnstableKMathAPI::class) -public abstract class UnivariateHistogram protected constructor( - protected val bins: TreeMap = TreeMap(), -) : Histogram, SpaceElement { - - public 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 - } - - 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() - - public companion object { - /** - * Build a histogram with a uniform binning with a start at [start] and a bin size of [binSize] - */ - public fun uniformBuilder(binSize: Double, start: Double = 0.0): UnivariateHistogramBuilder = - UnivariateHistogramSpace { value -> - val center = start + binSize * floor((value - start) / binSize + 0.5) - UnivariateBin(center, binSize) - }.builder() - - /** - * Build and fill a [UnivariateHistogram]. Returns a read-only histogram. - */ - public fun uniform( - binSize: Double, - start: Double = 0.0, - builder: UnivariateHistogramBuilder.() -> Unit, - ): UnivariateHistogram = uniformBuilder(binSize, start).apply(builder) - - /** - * Create a histogram with custom cell borders - */ - public fun customBuilder(borders: DoubleArray): UnivariateHistogramBuilder { - val sorted = borders.sortedArray() - - return UnivariateHistogramSpace { 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)) - } - } - }.builder() - } - - /** - * Build and fill a histogram with custom borders. Returns a read-only histogram. - */ - public fun custom( - borders: DoubleArray, - builder: UnivariateHistogramBuilder.() -> Unit, - ): UnivariateHistogram = customBuilder(borders).apply(builder) - } -} - -public class UnivariateHistogramBuilder internal constructor( - override val context: UnivariateHistogramSpace, -) : UnivariateHistogram(), MutableHistogram { - - private fun createBin(value: Double): UnivariateBin = context.binFactory(value).also { - synchronized(this) { bins[it.position] = it } - } - - /** - * Thread safe put operation - */ - public fun put(value: Double, weight: Double = 1.0) { - (get(value) ?: createBin(value)).apply { - counter.increment() - weightCounter.add(weight) - } - } - - override fun putWithWeight(point: Buffer, weight: Double) { - put(point[0], weight) - } - - /** - * Put several items into a single bin - */ - public fun putMany(value: Double, count: Int, weight: Double = count.toDouble()) { - (get(value) ?: createBin(value)).apply { - counter.add(count.toLong()) - weightCounter.add(weight) - } - } -} - -@UnstableKMathAPI -public fun UnivariateHistogramBuilder.fill(items: Iterable): Unit = items.forEach(::put) - -@UnstableKMathAPI -public fun UnivariateHistogramBuilder.fill(array: DoubleArray): Unit = array.forEach(::put) - -@UnstableKMathAPI -public fun UnivariateHistogramBuilder.fill(buffer: Buffer): Unit = buffer.asSequence().forEach(::put) \ No newline at end of file diff --git a/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/UnivariateHistogramSpace.kt b/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/UnivariateHistogramSpace.kt deleted file mode 100644 index 0deeb0a97..000000000 --- a/kmath-histograms/src/jvmMain/kotlin/kscience/kmath/histogram/UnivariateHistogramSpace.kt +++ /dev/null @@ -1,25 +0,0 @@ -package kscience.kmath.histogram - -import kscience.kmath.operations.Space - -public class UnivariateHistogramSpace(public val binFactory: (Double) -> UnivariateBin) : Space { - - public fun builder(): UnivariateHistogramBuilder = UnivariateHistogramBuilder(this) - - public fun produce(builder: UnivariateHistogramBuilder.() -> Unit): UnivariateHistogram = builder().apply(builder) - - 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"} - TODO() - } - - override fun multiply(a: UnivariateHistogram, k: Number): UnivariateHistogram { - TODO("Not yet implemented") - } - - override val zero: UnivariateHistogram = produce { } -} \ No newline at end of file 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..b2071fa02 --- /dev/null +++ b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramSpace.kt @@ -0,0 +1,159 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.UnivariateDomain +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.Group +import space.kscience.kmath.operations.ScaleOperations +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, +) : Group, ScaleOperations { + + 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 scale(a: UnivariateHistogram, value: Double): UnivariateHistogram { + val bins = TreeMap().apply { + a.bins.forEach { bin -> + put(bin.domain.center, + UnivariateBin( + bin.domain, + value = bin.value * value.toDouble(), + standardDeviation = abs(bin.standardDeviation * value.toDouble()) + ) + ) + } + } + + return TreeHistogram(this, bins) + } + + override fun UnivariateHistogram.unaryMinus(): UnivariateHistogram = this * (-1) + + 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..b1b2a10c2 --- /dev/null +++ b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/UnivariateHistogram.kt @@ -0,0 +1,76 @@ +package space.kscience.kmath.histogram + +import space.kscience.kmath.domains.UnivariateDomain +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.Group +import space.kscience.kmath.operations.SpaceElement +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asSequence + + +@UnstableKMathAPI +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 + */ +@UnstableKMathAPI +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 bb76f096b..a7c0c7e01 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 { @@ -8,6 +8,6 @@ dependencies { api(project(":kmath-ast")) } -readme{ +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 70% 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..1275b0c90 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.misc.Symbol +import space.kscience.kmath.operations.NumericAlgebra /** * Represents wrapper of [MstExpression] implementing [DifferentiableExpression]. @@ -18,8 +18,10 @@ import kscience.kmath.operations.NumericAlgebra * @param A the [NumericAlgebra] of [T]. * @property expr the underlying [MstExpression]. */ -public inline class DifferentiableMstExpression(public val expr: MstExpression) : - DifferentiableExpression> where A : NumericAlgebra, T : Number { +public inline class DifferentiableMstExpression( + public val expr: MstExpression, +) : DifferentiableExpression> where A : NumericAlgebra { + public constructor(algebra: A, mst: MST) : this(MstExpression(algebra, mst)) /** @@ -39,7 +41,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 87% 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..82b801f91 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]; @@ -102,8 +102,8 @@ public fun > MST.toSFun(): SFun = when (this) { is MST.Symbolic -> toSVar() is MST.Unary -> when (operation) { - SpaceOperations.PLUS_OPERATION -> +value.toSFun() - SpaceOperations.MINUS_OPERATION -> -value.toSFun() + GroupOperations.PLUS_OPERATION -> +value.toSFun() + GroupOperations.MINUS_OPERATION -> -value.toSFun() TrigonometricOperations.SIN_OPERATION -> sin(value.toSFun()) TrigonometricOperations.COS_OPERATION -> cos(value.toSFun()) TrigonometricOperations.TAN_OPERATION -> tan(value.toSFun()) @@ -114,8 +114,8 @@ public fun > MST.toSFun(): SFun = when (this) { } is MST.Binary -> when (operation) { - SpaceOperations.PLUS_OPERATION -> left.toSFun() + right.toSFun() - SpaceOperations.MINUS_OPERATION -> left.toSFun() - right.toSFun() + GroupOperations.PLUS_OPERATION -> left.toSFun() + right.toSFun() + GroupOperations.MINUS_OPERATION -> left.toSFun() - right.toSFun() RingOperations.TIMES_OPERATION -> left.toSFun() * right.toSFun() FieldOperations.DIV_OPERATION -> left.toSFun() / right.toSFun() PowerOperations.POW_OPERATION -> left.toSFun() pow (right as MST.Numeric).toSConst() 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 57% 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..7cd3276b8 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.DoubleField import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -15,9 +15,9 @@ import kotlin.test.fail internal class AdaptingTests { @Test fun symbol() { - val c1 = MstAlgebra.symbol("x") - assertTrue(c1.toSVar>().name == "x") - val c2 = "kitten".parseMath().toSFun>() + 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() } @@ -25,15 +25,15 @@ internal class AdaptingTests { fun number() { val c1 = MstAlgebra.number(12354324) assertTrue(c1.toSConst().doubleValue == 12354324.0) - val c2 = "0.234".parseMath().toSFun>() + val c2 = "0.234".parseMath().toSFun>() if (c2 is SConst) assertTrue(c2.doubleValue == 0.234) else fail() - val c3 = "1e-3".parseMath().toSFun>() + val c3 = "1e-3".parseMath().toSFun>() if (c3 is SConst) assertEquals(0.001, c3.value) else fail() } @Test fun simpleFunctionShape() { - val linear = "2*x+16".parseMath().toSFun>() + val linear = "2*x+16".parseMath().toSFun>() if (linear !is Sum) fail() if (linear.left !is Prod) fail() if (linear.right !is SConst) fail() @@ -41,21 +41,21 @@ internal class AdaptingTests { @Test fun simpleFunctionDerivative() { - val x = MstAlgebra.symbol("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() + val x = MstAlgebra.bindSymbol("x").toSVar>() + val quadratic = "x^2-4*x-44".parseMath().toSFun>() + val actualDerivative = MstExpression(DoubleField, quadratic.d(x).toMst()).compile() + val expectedDerivative = MstExpression(DoubleField, "2*x-4".parseMath()).compile() assertEquals(actualDerivative("x" to 123.0), expectedDerivative("x" to 123.0)) } @Test fun moreComplexDerivative() { - val x = MstAlgebra.symbol("x").toSVar>() - val composition = "-sqrt(sin(x^2)-cos(x)^2-16*x)".parseMath().toSFun>() - val actualDerivative = MstExpression(RealField, composition.d(x).toMst()).compile() + val x = MstAlgebra.bindSymbol("x").toSVar>() + val composition = "-sqrt(sin(x^2)-cos(x)^2-16*x)".parseMath().toSFun>() + val actualDerivative = MstExpression(DoubleField, composition.d(x).toMst()).compile() val expectedDerivative = MstExpression( - RealField, + DoubleField, "-(2*x*cos(x^2)+2*sin(x)*cos(x)-16)/(2*sqrt(sin(x^2)-16*x-cos(x)^2))".parseMath() ).compile() diff --git a/kmath-memory/api/kmath-memory.api b/kmath-memory/api/kmath-memory.api index 88b6be1d4..9c9641461 100644 --- a/kmath-memory/api/kmath-memory.api +++ b/kmath-memory/api/kmath-memory.api @@ -1,43 +1,43 @@ -public final class kscience/kmath/memory/ByteBufferMemory : kscience/kmath/memory/Memory { +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 ()Lkscience/kmath/memory/Memory; + 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 ()Lkscience/kmath/memory/MemoryReader; - public fun view (II)Lkscience/kmath/memory/Memory; - public fun writer ()Lkscience/kmath/memory/MemoryWriter; + 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 kscience/kmath/memory/ByteBufferMemoryKt { - public static final fun allocate (Lkscience/kmath/memory/Memory$Companion;I)Lkscience/kmath/memory/Memory; - public static final fun asMemory (Ljava/nio/ByteBuffer;II)Lkscience/kmath/memory/Memory; - public static synthetic fun asMemory$default (Ljava/nio/ByteBuffer;IIILjava/lang/Object;)Lkscience/kmath/memory/Memory; +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 (Lkscience/kmath/memory/Memory$Companion;[B)Lkscience/kmath/memory/Memory; + public static final fun wrap (Lspace/kscience/kmath/memory/Memory$Companion;[B)Lspace/kscience/kmath/memory/Memory; } -public abstract interface class kscience/kmath/memory/Memory { - public static final field Companion Lkscience/kmath/memory/Memory$Companion; - public abstract fun copy ()Lkscience/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 ()Lkscience/kmath/memory/MemoryReader; - public abstract fun view (II)Lkscience/kmath/memory/Memory; - public abstract fun writer ()Lkscience/kmath/memory/MemoryWriter; + 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 kscience/kmath/memory/Memory$Companion { +public final class space/kscience/kmath/memory/Memory$Companion { } -public final class kscience/kmath/memory/MemoryKt { - public static final fun read (Lkscience/kmath/memory/Memory;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun write (Lkscience/kmath/memory/Memory;Lkotlin/jvm/functions/Function1;)V +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 kscience/kmath/memory/MemoryReader { - public abstract fun getMemory ()Lkscience/kmath/memory/Memory; +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 @@ -47,20 +47,20 @@ public abstract interface class kscience/kmath/memory/MemoryReader { public abstract fun release ()V } -public abstract interface class kscience/kmath/memory/MemorySpec { +public abstract interface class space/kscience/kmath/memory/MemorySpec { public abstract fun getObjectSize ()I - public abstract fun read (Lkscience/kmath/memory/MemoryReader;I)Ljava/lang/Object; - public abstract fun write (Lkscience/kmath/memory/MemoryWriter;ILjava/lang/Object;)V + 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 kscience/kmath/memory/MemorySpecKt { - public static final fun read (Lkscience/kmath/memory/MemoryReader;Lkscience/kmath/memory/MemorySpec;I)Ljava/lang/Object; - public static final fun write (Lkscience/kmath/memory/MemoryWriter;Lkscience/kmath/memory/MemorySpec;ILjava/lang/Object;)V - public static final fun writeArray (Lkscience/kmath/memory/MemoryWriter;Lkscience/kmath/memory/MemorySpec;I[Ljava/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 kscience/kmath/memory/MemoryWriter { - public abstract fun getMemory ()Lkscience/kmath/memory/Memory; +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 diff --git a/kmath-memory/build.gradle.kts b/kmath-memory/build.gradle.kts index fe7b591de..1ccd1bed8 100644 --- a/kmath-memory/build.gradle.kts +++ b/kmath-memory/build.gradle.kts @@ -1,9 +1,9 @@ plugins { - id("ru.mipt.npm.mpp") - id("ru.mipt.npm.native") + id("ru.mipt.npm.gradle.mpp") + id("ru.mipt.npm.gradle.native") } -readme{ +readme { description = """ An API and basic implementation for arranging objects in a continous memory block. """.trimIndent() 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 93% 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..5ed3c3c9e 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. @@ -32,7 +32,8 @@ public fun MemoryReader.read(spec: MemorySpec, offset: Int): T = wi /** * Writes the object [value] with [spec] starting from [offset]. */ -public fun MemoryWriter.write(spec: MemorySpec, offset: Int, value: T): Unit = with(spec) { write(offset, value) } +public fun MemoryWriter.write(spec: MemorySpec, offset: Int, value: T): Unit = + with(spec) { write(offset, value) } /** * Reads array of [size] objects mapped by [spec] at certain [offset]. 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 96% 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..fe15cce49 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 @@ -13,7 +13,7 @@ import kotlin.contracts.contract internal class ByteBufferMemory( val buffer: ByteBuffer, val startOffset: Int = 0, - override val size: Int = buffer.limit() + override val size: Int = buffer.limit(), ) : Memory { @Suppress("NOTHING_TO_INLINE") private inline fun position(o: Int): Int = startOffset + o @@ -100,7 +100,8 @@ public actual fun Memory.Companion.allocate(length: Int): Memory = * Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied * and could be mutated independently from the resulting [Memory]. */ -public actual fun Memory.Companion.wrap(array: ByteArray): Memory = ByteBufferMemory(checkNotNull(ByteBuffer.wrap(array))) +public actual fun Memory.Companion.wrap(array: ByteArray): Memory = + ByteBufferMemory(checkNotNull(ByteBuffer.wrap(array))) /** * Wraps this [ByteBuffer] to [Memory] object. 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 97% 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..1274959ad 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,10 +1,10 @@ -package kscience.kmath.memory +package space.kscience.kmath.memory @PublishedApi internal class NativeMemory( val array: ByteArray, val startOffset: Int = 0, - override val size: Int = array.size + override val size: Int = array.size, ) : Memory { @Suppress("NOTHING_TO_INLINE") private inline fun position(o: Int): Int = startOffset + o diff --git a/kmath-nd4j/README.md b/kmath-nd4j/README.md index 9011ef3c5..938d05c33 100644 --- a/kmath-nd4j/README.md +++ b/kmath-nd4j/README.md @@ -1,49 +1,40 @@ -# ND4J NDStructure implementation (`kmath-nd4j`) +# Module kmath-nd4j -This subproject implements the following features: +ND4J based implementations of KMath abstractions. - - [nd4jarraystructure](src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : NDStructure wrapper for INDArray - - [nd4jarrayrings](src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Rings over Nd4jArrayStructure of Int and Long - - [nd4jarrayfields](src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : Fields over Nd4jArrayStructure of Float and Double + - [nd4jarraystructure](#) : NDStructure wrapper for INDArray + - [nd4jarrayrings](#) : Rings over Nd4jArrayStructure of Int and Long + - [nd4jarrayfields](#) : Fields over Nd4jArrayStructure of Float and Double -> #### Artifact: -> -> This module artifact: `kscience.kmath:kmath-nd4j:0.2.0-dev-7`. -> -> 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) -> -> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-nd4j/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-nd4j/_latestVersion) -> -> **Gradle:** -> -> ```gradle -> repositories { -> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } -> maven { url 'https://dl.bintray.com/mipt-npm/kscience' } -> maven { url 'https://dl.bintray.com/mipt-npm/dev' } -> maven { url 'https://dl.bintray.com/hotkeytlt/maven' } -> -> } -> -> dependencies { -> implementation 'kscience.kmath:kmath-nd4j:0.2.0-dev-7' -> } -> ``` -> **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") -> } -> -> dependencies { -> implementation("kscience.kmath:kmath-nd4j:0.2.0-dev-7") -> } -> ``` +## Artifact: + +The Maven coordinates of this project are `space.kscience:kmath-nd4j:0.3.0-dev-3`. + +**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 +} + +dependencies { + implementation 'space.kscience:kmath-nd4j:0.3.0-dev-3' +} +``` +**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 +} + +dependencies { + implementation("space.kscience:kmath-nd4j:0.3.0-dev-3") +} +``` ## Examples @@ -54,7 +45,7 @@ import org.nd4j.linalg.factory.* import scientifik.kmath.nd4j.* import scientifik.kmath.structures.* -val array = Nd4j.ones(2, 2).asRealStructure() +val array = Nd4j.ones(2, 2).asDoubleStructure() println(array[0, 0]) // 1.0 array[intArrayOf(0, 0)] = 24.0 println(array[0, 0]) // 24.0 @@ -67,8 +58,8 @@ import org.nd4j.linalg.factory.* import scientifik.kmath.nd4j.* import scientifik.kmath.operations.* -val field = RealNd4jArrayField(intArrayOf(2, 2)) -val array = Nd4j.rand(2, 2).asRealStructure() +val field = DoubleNd4jArrayField(intArrayOf(2, 2)) +val array = Nd4j.rand(2, 2).asDoubleStructure() val res = field { (25.0 / array + 20) * 4 diff --git a/kmath-nd4j/build.gradle.kts b/kmath-nd4j/build.gradle.kts index 391727c45..2954a1e65 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 { @@ -19,19 +19,16 @@ readme { feature( id = "nd4jarraystructure", - description = "NDStructure wrapper for INDArray", - ref = "src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt" + description = "NDStructure wrapper for INDArray" ) feature( id = "nd4jarrayrings", - description = "Rings over Nd4jArrayStructure of Int and Long", - ref = "src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt" + description = "Rings over Nd4jArrayStructure of Int and Long" ) feature( id = "nd4jarrayfields", - description = "Fields over Nd4jArrayStructure of Float and Double", - ref = "src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt" + description = "Fields over Nd4jArrayStructure of Float and Double" ) } diff --git a/kmath-nd4j/docs/README-TEMPLATE.md b/kmath-nd4j/docs/README-TEMPLATE.md index 76ce8c9a7..5f325cab5 100644 --- a/kmath-nd4j/docs/README-TEMPLATE.md +++ b/kmath-nd4j/docs/README-TEMPLATE.md @@ -1,6 +1,6 @@ -# ND4J NDStructure implementation (`kmath-nd4j`) +# Module kmath-nd4j -This subproject implements the following features: +ND4J based implementations of KMath abstractions. ${features} @@ -15,7 +15,7 @@ import org.nd4j.linalg.factory.* import scientifik.kmath.nd4j.* import scientifik.kmath.structures.* -val array = Nd4j.ones(2, 2).asRealStructure() +val array = Nd4j.ones(2, 2).asDoubleStructure() println(array[0, 0]) // 1.0 array[intArrayOf(0, 0)] = 24.0 println(array[0, 0]) // 24.0 @@ -28,8 +28,8 @@ import org.nd4j.linalg.factory.* import scientifik.kmath.nd4j.* import scientifik.kmath.operations.* -val field = RealNd4jArrayField(intArrayOf(2, 2)) -val array = Nd4j.rand(2, 2).asRealStructure() +val field = DoubleNd4jArrayField(intArrayOf(2, 2)) +val array = Nd4j.rand(2, 2).asDoubleStructure() val res = field { (25.0 / array + 20) * 4 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 56% 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 b9c95034e..8ea992bcb 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,13 @@ -package kscience.kmath.nd4j +package space.kscience.kmath.nd4j -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.nd.* -import kscience.kmath.operations.* -import kscience.kmath.structures.* 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 { +internal fun AlgebraND<*, *>.checkShape(array: INDArray): INDArray { val arrayShape = array.shape().toIntArray() if (!shape.contentEquals(arrayShape)) throw ShapeMismatchException(shape, arrayShape) return array @@ -15,18 +15,18 @@ internal fun NDAlgebra<*, *>.checkShape(array: INDArray): INDArray { /** - * Represents [NDAlgebra] over [Nd4jArrayAlgebra]. + * Represents [AlgebraND] over [Nd4jArrayAlgebra]. * * @param T the type of ND-structure element. * @param C the type of the element context. */ -public interface Nd4jArrayAlgebra : NDAlgebra { +public interface Nd4jArrayAlgebra> : AlgebraND { /** * Wraps [INDArray] to [N]. */ public fun INDArray.wrap(): Nd4jArrayStructure - public val NDStructure.ndArray: INDArray + public val StructureND.ndArray: INDArray get() = when { !shape.contentEquals(this@Nd4jArrayAlgebra.shape) -> throw ShapeMismatchException( this@Nd4jArrayAlgebra.shape, @@ -44,13 +44,13 @@ public interface Nd4jArrayAlgebra : NDAlgebra { return struct } - public override fun NDStructure.map(transform: C.(T) -> T): Nd4jArrayStructure { + public override fun StructureND.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 NDStructure.mapIndexed( + public override fun StructureND.mapIndexed( transform: C.(index: IntArray, T) -> T, ): Nd4jArrayStructure { val new = Nd4j.create(*this@Nd4jArrayAlgebra.shape).wrap() @@ -59,8 +59,8 @@ public interface Nd4jArrayAlgebra : NDAlgebra { } public override fun combine( - a: NDStructure, - b: NDStructure, + a: StructureND, + b: StructureND, transform: C.(T, T) -> T, ): Nd4jArrayStructure { val new = Nd4j.create(*shape).wrap() @@ -70,56 +70,43 @@ public interface Nd4jArrayAlgebra : NDAlgebra { } /** - * Represents [NDSpace] over [Nd4jArrayStructure]. + * Represents [GroupND] over [Nd4jArrayStructure]. * * @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 Nd4JArrayGroup> : GroupND, Nd4jArrayAlgebra { public override val zero: Nd4jArrayStructure get() = Nd4j.zeros(*shape).wrap() - public override fun add(a: NDStructure, b: NDStructure): Nd4jArrayStructure { - return a.ndArray.add(b.ndArray).wrap() - } + public override fun add(a: StructureND, b: StructureND): Nd4jArrayStructure = + a.ndArray.add(b.ndArray).wrap() - public override operator fun NDStructure.minus(b: NDStructure): Nd4jArrayStructure { - return ndArray.sub(b.ndArray).wrap() - } + public override operator fun StructureND.minus(b: StructureND): Nd4jArrayStructure = + ndArray.sub(b.ndArray).wrap() - public override operator fun NDStructure.unaryMinus(): Nd4jArrayStructure { - return ndArray.neg().wrap() - } + public override operator fun StructureND.unaryMinus(): Nd4jArrayStructure = + ndArray.neg().wrap() - public override fun multiply(a: NDStructure, k: Number): Nd4jArrayStructure { - return a.ndArray.mul(k).wrap() - } - - public override operator fun NDStructure.div(k: Number): Nd4jArrayStructure { - return ndArray.div(k).wrap() - } - - public override operator fun NDStructure.times(k: Number): Nd4jArrayStructure { - return ndArray.mul(k).wrap() - } + public fun multiply(a: StructureND, k: Number): Nd4jArrayStructure = + a.ndArray.mul(k).wrap() } /** - * Represents [NDRing] over [Nd4jArrayStructure]. + * Represents [RingND] over [Nd4jArrayStructure]. * * @param T the type of the element contained in ND structure. * @param R the type of ring of structure elements. */ @OptIn(UnstableKMathAPI::class) -public interface Nd4jArrayRing> : NDRing, Nd4jArraySpace { +public interface Nd4jArrayRing> : RingND, Nd4JArrayGroup { public override val one: Nd4jArrayStructure get() = Nd4j.ones(*shape).wrap() - public override fun multiply(a: NDStructure, b: NDStructure): Nd4jArrayStructure { - return a.ndArray.mul(b.ndArray).wrap() - } + public override fun multiply(a: StructureND, b: StructureND): Nd4jArrayStructure = + a.ndArray.mul(b.ndArray).wrap() // // public override operator fun Nd4jArrayStructure.minus(b: Number): Nd4jArrayStructure { // check(this) @@ -144,19 +131,19 @@ public interface Nd4jArrayRing> : NDRing, Nd4jArraySpace = intNd4jArrayRingCache.get().getOrPut(shape) { IntNd4jArrayRing(shape) } /** - * Creates an [NDRing] for [Long] values or pull it from cache if it was created previously. + * Creates an [RingND] for [Long] values or pull it from cache if it was created previously. */ public fun long(vararg shape: Int): Nd4jArrayRing = longNd4jArrayRingCache.get().getOrPut(shape) { LongNd4jArrayRing(shape) } /** - * Creates a most suitable implementation of [NDRing] using reified class. + * Creates a most suitable implementation of [RingND] using reified class. */ @Suppress("UNCHECKED_CAST") public inline fun auto(vararg shape: Int): Nd4jArrayRing> = when { @@ -168,41 +155,40 @@ public interface Nd4jArrayRing> : NDRing, Nd4jArraySpace> : NDField, Nd4jArrayRing { +public interface Nd4jArrayField> : FieldND, Nd4jArrayRing { - public override fun divide(a: NDStructure, b: NDStructure): Nd4jArrayStructure = + public override fun divide(a: StructureND, b: StructureND): Nd4jArrayStructure = a.ndArray.div(b.ndArray).wrap() - public override operator fun Number.div(b: NDStructure): Nd4jArrayStructure = b.ndArray.rdiv(this).wrap() - + public operator fun Number.div(b: StructureND): Nd4jArrayStructure = b.ndArray.rdiv(this).wrap() public companion object { private val floatNd4jArrayFieldCache: ThreadLocal> = ThreadLocal.withInitial { hashMapOf() } - private val realNd4jArrayFieldCache: ThreadLocal> = + private val doubleNd4JArrayFieldCache: ThreadLocal> = ThreadLocal.withInitial { hashMapOf() } /** - * Creates an [NDField] for [Float] values or pull it from cache if it was created previously. + * Creates an [FieldND] for [Float] values or pull it from cache if it was created previously. */ public fun float(vararg shape: Int): Nd4jArrayRing = floatNd4jArrayFieldCache.get().getOrPut(shape) { FloatNd4jArrayField(shape) } /** - * Creates an [NDField] for [Double] values or pull it from cache if it was created previously. + * Creates an [FieldND] for [Double] values or pull it from cache if it was created previously. */ - public fun real(vararg shape: Int): Nd4jArrayRing = - realNd4jArrayFieldCache.get().getOrPut(shape) { RealNd4jArrayField(shape) } + public fun real(vararg shape: Int): Nd4jArrayRing = + doubleNd4JArrayFieldCache.get().getOrPut(shape) { DoubleNd4jArrayField(shape) } /** - * Creates a most suitable implementation of [NDRing] using reified class. + * Creates a most suitable implementation of [RingND] using reified class. */ @Suppress("UNCHECKED_CAST") public inline fun auto(vararg shape: Int): Nd4jArrayField> = when { @@ -214,41 +200,44 @@ public interface Nd4jArrayField> : NDField, Nd4jArrayRing< } /** - * Represents [NDField] over [Nd4jArrayRealStructure]. + * Represents [FieldND] over [Nd4jArrayDoubleStructure]. */ -public class RealNd4jArrayField(public override val shape: IntArray) : Nd4jArrayField { - public override val elementContext: RealField - get() = RealField +public class DoubleNd4jArrayField(public override val shape: IntArray) : Nd4jArrayField { + public override val elementContext: DoubleField get() = DoubleField - public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asRealStructure() + public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asDoubleStructure() - public override operator fun NDStructure.div(arg: Double): Nd4jArrayStructure { + override fun scale(a: StructureND, value: Double): Nd4jArrayStructure { + return a.ndArray.mul(value).wrap() + } + + public override operator fun StructureND.div(arg: Double): Nd4jArrayStructure { return ndArray.div(arg).wrap() } - public override operator fun NDStructure.plus(arg: Double): Nd4jArrayStructure { + public override operator fun StructureND.plus(arg: Double): Nd4jArrayStructure { return ndArray.add(arg).wrap() } - public override operator fun NDStructure.minus(arg: Double): Nd4jArrayStructure { + public override operator fun StructureND.minus(arg: Double): Nd4jArrayStructure { return ndArray.sub(arg).wrap() } - public override operator fun NDStructure.times(arg: Double): Nd4jArrayStructure { + public override operator fun StructureND.times(arg: Double): Nd4jArrayStructure { return ndArray.mul(arg).wrap() } - public override operator fun Double.div(arg: NDStructure): Nd4jArrayStructure { + public override operator fun Double.div(arg: StructureND): Nd4jArrayStructure { return arg.ndArray.rdiv(this).wrap() } - public override operator fun Double.minus(arg: NDStructure): Nd4jArrayStructure { + public override operator fun Double.minus(arg: StructureND): Nd4jArrayStructure { return arg.ndArray.rsub(this).wrap() } } /** - * Represents [NDField] over [Nd4jArrayStructure] of [Float]. + * Represents [FieldND] over [Nd4jArrayStructure] of [Float]. */ public class FloatNd4jArrayField(public override val shape: IntArray) : Nd4jArrayField { public override val elementContext: FloatField @@ -256,33 +245,30 @@ public class FloatNd4jArrayField(public override val shape: IntArray) : Nd4jArra public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asFloatStructure() - public override operator fun NDStructure.div(arg: Float): Nd4jArrayStructure { - return ndArray.div(arg).wrap() - } + override fun scale(a: StructureND, value: Double): StructureND = + a.ndArray.mul(value).wrap() - public override operator fun NDStructure.plus(arg: Float): Nd4jArrayStructure { - return ndArray.add(arg).wrap() - } + public override operator fun StructureND.div(arg: Float): Nd4jArrayStructure = + ndArray.div(arg).wrap() - public override operator fun NDStructure.minus(arg: Float): Nd4jArrayStructure { - return ndArray.sub(arg).wrap() - } + public override operator fun StructureND.plus(arg: Float): Nd4jArrayStructure = + ndArray.add(arg).wrap() - public override operator fun NDStructure.times(arg: Float): Nd4jArrayStructure { - return ndArray.mul(arg).wrap() - } + public override operator fun StructureND.minus(arg: Float): Nd4jArrayStructure = + ndArray.sub(arg).wrap() - public override operator fun Float.div(arg: NDStructure): Nd4jArrayStructure { - return arg.ndArray.rdiv(this).wrap() - } + public override operator fun StructureND.times(arg: Float): Nd4jArrayStructure = + ndArray.mul(arg).wrap() - public override operator fun Float.minus(arg: NDStructure): Nd4jArrayStructure { - return arg.ndArray.rsub(this).wrap() - } + public override operator fun Float.div(arg: StructureND): Nd4jArrayStructure = + arg.ndArray.rdiv(this).wrap() + + public override operator fun Float.minus(arg: StructureND): Nd4jArrayStructure = + arg.ndArray.rsub(this).wrap() } /** - * Represents [NDRing] over [Nd4jArrayIntStructure]. + * Represents [RingND] over [Nd4jArrayIntStructure]. */ public class IntNd4jArrayRing(public override val shape: IntArray) : Nd4jArrayRing { public override val elementContext: IntRing @@ -290,25 +276,21 @@ public class IntNd4jArrayRing(public override val shape: IntArray) : Nd4jArrayRi public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asIntStructure() - public override operator fun NDStructure.plus(arg: Int): Nd4jArrayStructure { - return ndArray.add(arg).wrap() - } + public override operator fun StructureND.plus(arg: Int): Nd4jArrayStructure = + ndArray.add(arg).wrap() - public override operator fun NDStructure.minus(arg: Int): Nd4jArrayStructure { - return ndArray.sub(arg).wrap() - } + public override operator fun StructureND.minus(arg: Int): Nd4jArrayStructure = + ndArray.sub(arg).wrap() - public override operator fun NDStructure.times(arg: Int): Nd4jArrayStructure { - return ndArray.mul(arg).wrap() - } + public override operator fun StructureND.times(arg: Int): Nd4jArrayStructure = + ndArray.mul(arg).wrap() - public override operator fun Int.minus(arg: NDStructure): Nd4jArrayStructure { - return arg.ndArray.rsub(this).wrap() - } + public override operator fun Int.minus(arg: StructureND): Nd4jArrayStructure = + arg.ndArray.rsub(this).wrap() } /** - * Represents [NDRing] over [Nd4jArrayStructure] of [Long]. + * Represents [RingND] over [Nd4jArrayStructure] of [Long]. */ public class LongNd4jArrayRing(public override val shape: IntArray) : Nd4jArrayRing { public override val elementContext: LongRing @@ -316,19 +298,15 @@ public class LongNd4jArrayRing(public override val shape: IntArray) : Nd4jArrayR public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asLongStructure() - public override operator fun NDStructure.plus(arg: Long): Nd4jArrayStructure { - return ndArray.add(arg).wrap() - } + public override operator fun StructureND.plus(arg: Long): Nd4jArrayStructure = + ndArray.add(arg).wrap() - public override operator fun NDStructure.minus(arg: Long): Nd4jArrayStructure { - return ndArray.sub(arg).wrap() - } + public override operator fun StructureND.minus(arg: Long): Nd4jArrayStructure = + ndArray.sub(arg).wrap() - public override operator fun NDStructure.times(arg: Long): Nd4jArrayStructure { - return ndArray.mul(arg).wrap() - } + public override operator fun StructureND.times(arg: Long): Nd4jArrayStructure = + ndArray.mul(arg).wrap() - public override operator fun Long.minus(arg: NDStructure): Nd4jArrayStructure { - return arg.ndArray.rsub(this).wrap() - } + public override operator fun Long.minus(arg: StructureND): Nd4jArrayStructure = + 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 92% 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..cfb900277 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 @@ -37,11 +37,11 @@ private sealed class Nd4jArrayIteratorBase(protected val iterateOver: INDArra } } -private class Nd4jArrayRealIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) { +private class Nd4jArrayDoubleIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) { override fun getSingle(indices: LongArray): Double = iterateOver.getDouble(*indices) } -internal fun INDArray.realIterator(): Iterator> = Nd4jArrayRealIterator(this) +internal fun INDArray.realIterator(): Iterator> = Nd4jArrayDoubleIterator(this) private class Nd4jArrayLongIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) { override fun getSingle(indices: LongArray) = iterateOver.getLong(*indices) 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 84% 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 2a6b56602..6a3ae37a7 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,15 +1,15 @@ -package kscience.kmath.nd4j +package space.kscience.kmath.nd4j -import kscience.kmath.nd.MutableNDStructure -import kscience.kmath.nd.NDStructure import org.nd4j.linalg.api.ndarray.INDArray +import space.kscience.kmath.nd.MutableStructureND +import space.kscience.kmath.nd.StructureND /** - * Represents a [NDStructure] wrapping an [INDArray] object. + * Represents a [StructureND] wrapping an [INDArray] object. * * @param T the type of items. */ -public sealed class Nd4jArrayStructure : MutableNDStructure { +public sealed class Nd4jArrayStructure : MutableStructureND { /** * The wrapped [INDArray]. */ @@ -45,7 +45,7 @@ private data class Nd4jArrayLongStructure(override val ndArray: INDArray) : Nd4j */ public fun INDArray.asLongStructure(): Nd4jArrayStructure = Nd4jArrayLongStructure(this) -private data class Nd4jArrayRealStructure(override val ndArray: INDArray) : Nd4jArrayStructure() { +private data class Nd4jArrayDoubleStructure(override val ndArray: INDArray) : Nd4jArrayStructure() { override fun elementsIterator(): Iterator> = ndArray.realIterator() override fun get(index: IntArray): Double = ndArray.getDouble(*index) override fun set(index: IntArray, value: Double): Unit = run { ndArray.putScalar(index, value) } @@ -54,7 +54,7 @@ private data class Nd4jArrayRealStructure(override val ndArray: INDArray) : Nd4j /** * Wraps this [INDArray] to [Nd4jArrayStructure]. */ -public fun INDArray.asRealStructure(): Nd4jArrayStructure = Nd4jArrayRealStructure(this) +public fun INDArray.asDoubleStructure(): Nd4jArrayStructure = Nd4jArrayDoubleStructure(this) private data class Nd4jArrayFloatStructure(override val ndArray: INDArray) : Nd4jArrayStructure() { override fun elementsIterator(): Iterator> = ndArray.floatIterator() 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 72% 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 04959d290..e658275f5 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,6 +1,5 @@ -package kscience.kmath.nd4j +package space.kscience.kmath.nd4j -import kscience.kmath.operations.invoke import org.nd4j.linalg.factory.Nd4j import kotlin.test.Test import kotlin.test.assertEquals @@ -9,8 +8,8 @@ import kotlin.test.fail internal class Nd4jArrayAlgebraTest { @Test fun testProduce() { - val res = (RealNd4jArrayField(intArrayOf(2, 2))) { produce { it.sum().toDouble() } } - val expected = (Nd4j.create(2, 2) ?: fail()).asRealStructure() + val res = with(DoubleNd4jArrayField(intArrayOf(2, 2))) { produce { it.sum().toDouble() } } + val expected = (Nd4j.create(2, 2) ?: fail()).asDoubleStructure() expected[intArrayOf(0, 0)] = 0.0 expected[intArrayOf(0, 1)] = 1.0 expected[intArrayOf(1, 0)] = 1.0 @@ -20,7 +19,7 @@ internal class Nd4jArrayAlgebraTest { @Test fun testMap() { - val res = (IntNd4jArrayRing(intArrayOf(2, 2))) { one.map() { 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 74% 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 2f1606061..0c03270dd 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.nd.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 @@ -11,7 +11,7 @@ internal class Nd4jArrayStructureTest { @Test fun testElements() { val nd = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0))!! - val struct = nd.asRealStructure() + val struct = nd.asDoubleStructure() val res = struct.elements().map(Pair::second).toList() assertEquals(listOf(1.0, 2.0, 3.0), res) } @@ -19,32 +19,32 @@ internal class Nd4jArrayStructureTest { @Test fun testShape() { val nd = Nd4j.rand(10, 2, 3, 6) ?: fail() - val struct = nd.asRealStructure() + val struct = nd.asDoubleStructure() assertEquals(intArrayOf(10, 2, 3, 6).toList(), struct.shape.toList()) } @Test fun testEquals() { val nd1 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() - val struct1 = nd1.asRealStructure() + val struct1 = nd1.asDoubleStructure() assertEquals(struct1, struct1) assertNotEquals(struct1 as Any?, null) val nd2 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() - val struct2 = nd2.asRealStructure() + val struct2 = nd2.asDoubleStructure() assertEquals(struct1, struct2) assertEquals(struct2, struct1) val nd3 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() - val struct3 = nd3.asRealStructure() + val struct3 = nd3.asDoubleStructure() assertEquals(struct2, struct3) assertEquals(struct1, struct3) } @Test fun testHashCode() { - val nd1 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0))?:fail() - val struct1 = nd1.asRealStructure() - val nd2 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0))?:fail() - val struct2 = nd2.asRealStructure() + val nd1 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() + val struct1 = nd1.asDoubleStructure() + val nd2 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() + val struct2 = nd2.asDoubleStructure() assertEquals(struct1.hashCode(), struct2.hashCode()) } @@ -57,7 +57,7 @@ internal class Nd4jArrayStructureTest { @Test fun testGet() { - val nd = Nd4j.rand(10, 2, 3, 6)?:fail() + val nd = Nd4j.rand(10, 2, 3, 6) ?: fail() val struct = nd.asIntStructure() assertEquals(nd.getInt(0, 0, 0, 0), struct[0, 0, 0, 0]) } diff --git a/kmath-stat/build.gradle.kts b/kmath-stat/build.gradle.kts index adeaab360..bc3890b1e 100644 --- a/kmath-stat/build.gradle.kts +++ b/kmath-stat/build.gradle.kts @@ -1,15 +1,8 @@ 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") - } - } - commonMain { dependencies { api(project(":kmath-coroutines")) @@ -24,6 +17,6 @@ kotlin.sourceSets { } } -readme{ +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/Fitting.kt b/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Fitting.kt deleted file mode 100644 index 9d4655df2..000000000 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/Fitting.kt +++ /dev/null @@ -1,63 +0,0 @@ -package kscience.kmath.stat - -import kscience.kmath.expressions.* -import kscience.kmath.operations.ExtendedField -import kscience.kmath.structures.Buffer -import kscience.kmath.structures.indices -import kotlin.math.pow - -public object Fitting { - - /** - * Generate a chi squared expression from given x-y-sigma data and inline model. Provides automatic differentiation - */ - public fun chiSquared( - autoDiff: AutoDiffProcessor>, - x: Buffer, - y: Buffer, - yErr: Buffer, - model: A.(I) -> I, - ): DifferentiableExpression> where A : ExtendedField, A : ExpressionAlgebra { - require(x.size == y.size) { "X and y buffers should be of the same size" } - require(y.size == yErr.size) { "Y and yErr buffer should of the same size" } - - return autoDiff.process { - var sum = zero - - x.indices.forEach { - val xValue = const(x[it]) - val yValue = const(y[it]) - val yErrValue = const(yErr[it]) - val modelValue = model(xValue) - sum += ((yValue - modelValue) / yErrValue).pow(2) - } - - sum - } - } - - /** - * Generate a chi squared expression from given x-y-sigma model represented by an expression. Does not provide derivatives - */ - public fun chiSquared( - x: Buffer, - y: Buffer, - yErr: Buffer, - model: Expression, - xSymbol: Symbol = StringSymbol("x"), - ): Expression { - require(x.size == y.size) { "X and y buffers should be of the same size" } - require(y.size == yErr.size) { "Y and yErr buffer should of the same size" } - - return Expression { arguments -> - x.indices.sumByDouble { - val xValue = x[it] - val yValue = y[it] - val yErrValue = yErr[it] - val modifiedArgs = arguments + (xSymbol to xValue) - val modelValue = model(modifiedArgs) - ((yValue - modelValue) / yErrValue).pow(2) - } - } - } -} diff --git a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/OptimizationProblem.kt b/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/OptimizationProblem.kt deleted file mode 100644 index 0f3cd9dd9..000000000 --- a/kmath-stat/src/commonMain/kotlin/kscience/kmath/stat/OptimizationProblem.kt +++ /dev/null @@ -1,88 +0,0 @@ -package kscience.kmath.stat - -import kscience.kmath.expressions.DifferentiableExpression -import kscience.kmath.expressions.Expression -import kscience.kmath.expressions.Symbol - -public interface OptimizationFeature - -public class OptimizationResult( - public val point: Map, - public val value: T, - public val features: Set = emptySet(), -) { - override fun toString(): String { - return "OptimizationResult(point=$point, value=$value)" - } -} - -public operator fun OptimizationResult.plus( - feature: OptimizationFeature, -): OptimizationResult = OptimizationResult(point, value, features + feature) - -/** - * A configuration builder for optimization problem - */ -public interface OptimizationProblem { - /** - * Define the initial guess for the optimization problem - */ - public fun initialGuess(map: Map) - - /** - * Set an objective function expression - */ - public fun expression(expression: Expression) - - /** - * Set a differentiable expression as objective function as function and gradient provider - */ - public fun diffExpression(expression: DifferentiableExpression>) - - /** - * Update the problem from previous optimization run - */ - public fun update(result: OptimizationResult) - - /** - * Make an optimization run - */ - public fun optimize(): OptimizationResult -} - -public fun interface OptimizationProblemFactory> { - public fun build(symbols: List): P -} - -public operator fun > OptimizationProblemFactory.invoke( - symbols: List, - block: P.() -> Unit, -): P = build(symbols).apply(block) - -/** - * Optimize expression without derivatives using specific [OptimizationProblemFactory] - */ -public fun > Expression.optimizeWith( - factory: OptimizationProblemFactory, - vararg symbols: Symbol, - configuration: F.() -> Unit, -): OptimizationResult { - require(symbols.isNotEmpty()) { "Must provide a list of symbols for optimization" } - val problem = factory(symbols.toList(),configuration) - problem.expression(this) - return problem.optimize() -} - -/** - * Optimize differentiable expression using specific [OptimizationProblemFactory] - */ -public fun > DifferentiableExpression>.optimizeWith( - factory: OptimizationProblemFactory, - vararg symbols: Symbol, - configuration: F.() -> Unit, -): OptimizationResult { - require(symbols.isNotEmpty()) { "Must provide a list of symbols for optimization" } - val problem = factory(symbols.toList(), configuration) - problem.diffExpression(this) - return problem.optimize() -} diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt new file mode 100644 index 000000000..528a5744e --- /dev/null +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt @@ -0,0 +1,89 @@ +package space.kscience.kmath.optimization + +import space.kscience.kmath.expressions.AutoDiffProcessor +import space.kscience.kmath.expressions.DifferentiableExpression +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.ExpressionAlgebra +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.indices + +/** + * A likelihood function optimization problem with provided derivatives + */ +public interface FunctionOptimization : Optimization { + /** + * The optimization direction. If true search for function maximum, if false, search for the minimum + */ + public var maximize: Boolean + + /** + * Define the initial guess for the optimization problem + */ + public fun initialGuess(map: Map) + + /** + * Set a differentiable expression as objective function as function and gradient provider + */ + public fun diffFunction(expression: DifferentiableExpression>) + + public companion object { + /** + * Generate a chi squared expression from given x-y-sigma data and inline model. Provides automatic differentiation + */ + public fun chiSquared( + autoDiff: AutoDiffProcessor>, + x: Buffer, + y: Buffer, + yErr: Buffer, + model: A.(I) -> I, + ): DifferentiableExpression> where A : ExtendedField, A : ExpressionAlgebra { + require(x.size == y.size) { "X and y buffers should be of the same size" } + require(y.size == yErr.size) { "Y and yErr buffer should of the same size" } + + return autoDiff.process { + var sum = zero + + x.indices.forEach { + val xValue = const(x[it]) + val yValue = const(y[it]) + val yErrValue = const(yErr[it]) + val modelValue = model(xValue) + sum += ((yValue - modelValue) / yErrValue).pow(2) + } + + sum + } + } + } +} + +/** + * Define a chi-squared-based objective function + */ +public fun FunctionOptimization.chiSquared( + autoDiff: AutoDiffProcessor>, + x: Buffer, + y: Buffer, + yErr: Buffer, + model: A.(I) -> I, +) where A : ExtendedField, A : ExpressionAlgebra { + val chiSquared = FunctionOptimization.chiSquared(autoDiff, x, y, yErr, model) + diffFunction(chiSquared) + maximize = false +} + +/** + * Optimize differentiable expression using specific [OptimizationProblemFactory] + */ +public fun > DifferentiableExpression>.optimizeWith( + factory: OptimizationProblemFactory, + vararg symbols: Symbol, + configuration: F.() -> Unit, +): OptimizationResult { + require(symbols.isNotEmpty()) { "Must provide a list of symbols for optimization" } + val problem = factory(symbols.toList(), configuration) + problem.diffFunction(this) + return problem.optimize() +} diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/NoDerivFunctionOptimization.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/NoDerivFunctionOptimization.kt new file mode 100644 index 000000000..b8785dd8c --- /dev/null +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/NoDerivFunctionOptimization.kt @@ -0,0 +1,69 @@ +package space.kscience.kmath.optimization + +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.indices +import kotlin.math.pow + +/** + * A likelihood function optimization problem + */ +public interface NoDerivFunctionOptimization : Optimization { + /** + * The optimization direction. If true search for function maximum, if false, search for the minimum + */ + public var maximize: Boolean + + /** + * Define the initial guess for the optimization problem + */ + public fun initialGuess(map: Map) + + /** + * Set an objective function expression + */ + public fun function(expression: Expression) + + public companion object { + /** + * Generate a chi squared expression from given x-y-sigma model represented by an expression. Does not provide derivatives + */ + public fun chiSquared( + x: Buffer, + y: Buffer, + yErr: Buffer, + model: Expression, + xSymbol: Symbol = Symbol.x, + ): Expression { + require(x.size == y.size) { "X and y buffers should be of the same size" } + require(y.size == yErr.size) { "Y and yErr buffer should of the same size" } + + return Expression { arguments -> + x.indices.sumByDouble { + val xValue = x[it] + val yValue = y[it] + val yErrValue = yErr[it] + val modifiedArgs = arguments + (xSymbol to xValue) + val modelValue = model(modifiedArgs) + ((yValue - modelValue) / yErrValue).pow(2) + } + } + } + } +} + + +/** + * Optimize expression without derivatives using specific [OptimizationProblemFactory] + */ +public fun > Expression.noDerivOptimizeWith( + factory: OptimizationProblemFactory, + vararg symbols: Symbol, + configuration: F.() -> Unit, +): OptimizationResult { + require(symbols.isNotEmpty()) { "Must provide a list of symbols for optimization" } + val problem = factory(symbols.toList(), configuration) + problem.function(this) + return problem.optimize() +} diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/Optimization.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/Optimization.kt new file mode 100644 index 000000000..0b13e07ba --- /dev/null +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/Optimization.kt @@ -0,0 +1,44 @@ +package space.kscience.kmath.optimization + +import space.kscience.kmath.misc.Symbol + +public interface OptimizationFeature + +public class OptimizationResult( + public val point: Map, + public val value: T, + public val features: Set = emptySet(), +) { + override fun toString(): String { + return "OptimizationResult(point=$point, value=$value)" + } +} + +public operator fun OptimizationResult.plus( + feature: OptimizationFeature, +): OptimizationResult = OptimizationResult(point, value, features + feature) + +/** + * An optimization problem builder over [T] variables + */ +public interface Optimization { + + /** + * Update the problem from previous optimization run + */ + public fun update(result: OptimizationResult) + + /** + * Make an optimization run + */ + public fun optimize(): OptimizationResult +} + +public fun interface OptimizationProblemFactory> { + public fun build(symbols: List): P +} + +public operator fun > OptimizationProblemFactory.invoke( + symbols: List, + block: P.() -> Unit, +): P = build(symbols).apply(block) diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt new file mode 100644 index 000000000..c3106c819 --- /dev/null +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt @@ -0,0 +1,40 @@ +package space.kscience.kmath.optimization + +import space.kscience.kmath.data.ColumnarData +import space.kscience.kmath.expressions.AutoDiffProcessor +import space.kscience.kmath.expressions.DifferentiableExpression +import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.ExpressionAlgebra +import space.kscience.kmath.misc.Symbol +import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.Field + +@UnstableKMathAPI +public interface XYFit : Optimization { + + public val algebra: Field + + /** + * Set X-Y data for this fit optionally including x and y errors + */ + public fun data( + dataSet: ColumnarData, + xSymbol: Symbol, + ySymbol: Symbol, + xErrSymbol: Symbol? = null, + yErrSymbol: Symbol? = null, + ) + + public fun model(model: (T) -> DifferentiableExpression) + + /** + * Set the differentiable model for this fit + */ + public fun model( + autoDiff: AutoDiffProcessor>, + modelFunction: A.(I) -> I, + ): Unit where A : ExtendedField, A : ExpressionAlgebra = model { arg -> + autoDiff.process { modelFunction(const(arg)) } + } +} \ 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 100% 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 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 a95ef4c37..3dd506b67 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/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/RandomChain.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/RandomChain.kt similarity index 100% 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 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 99% 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 dd4db2aba..bad2334e9 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 diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt new file mode 100644 index 000000000..c5ec99dae --- /dev/null +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/SamplerAlgebra.kt @@ -0,0 +1,36 @@ +package space.kscience.kmath.stat + +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.Group +import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.operations.invoke + +public class BasicSampler(public val chainBuilder: (RandomGenerator) -> Chain) : Sampler { + public override fun sample(generator: RandomGenerator): Chain = chainBuilder(generator) +} + +public class ConstantSampler(public val value: T) : Sampler { + public override fun sample(generator: RandomGenerator): Chain = ConstantChain(value) +} + +/** + * A space for samplers. Allows to perform simple operations on distributions + */ +public class SamplerSpace(public val algebra: S) : Group>, + ScaleOperations> where S : Group, S : ScaleOperations { + + public override val zero: Sampler = ConstantSampler(algebra.zero) + + public override fun add(a: Sampler, b: Sampler): Sampler = BasicSampler { generator -> + a.sample(generator).zip(b.sample(generator)) { aValue, bValue -> algebra { aValue + bValue } } + } + + public override fun scale(a: Sampler, value: Double): Sampler = BasicSampler { generator -> + a.sample(generator).map { algebra { it * value } } + } + + override fun Sampler.unaryMinus(): Sampler = scale(this, -1.0) +} 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 72% 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..689182115 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 @@ -43,7 +43,7 @@ public interface ComposableStatistic : Statistic { @ExperimentalCoroutinesApi private fun ComposableStatistic.flowIntermediate( flow: Flow>, - dispatcher: CoroutineDispatcher = Dispatchers.Default + dispatcher: CoroutineDispatcher = Dispatchers.Default, ): Flow = flow .mapParallel(dispatcher) { computeIntermediate(it) } .runningReduce(::composeIntermediate) @@ -59,27 +59,31 @@ private fun ComposableStatistic.flowIntermediate( @ExperimentalCoroutinesApi public fun ComposableStatistic.flow( flow: Flow>, - dispatcher: CoroutineDispatcher = Dispatchers.Default + dispatcher: CoroutineDispatcher = Dispatchers.Default, ): Flow = flowIntermediate(flow, dispatcher).map(::toResult) /** * Arithmetic mean */ -public class Mean(public val space: Space) : ComposableStatistic, T> { +public class Mean( + private val group: Group, + private val division: (sum: T, count: Int) -> T, +) : ComposableStatistic, T> { public override suspend fun computeIntermediate(data: Buffer): Pair = - space { sum(data.asIterable()) } to data.size + group { sum(data.asIterable()) } to data.size public override suspend fun composeIntermediate(first: Pair, second: Pair): Pair = - space { first.first + second.first } to (first.second + second.second) + group { first.first + second.first } to (first.second + second.second) - public override suspend fun toResult(intermediate: Pair): T = - space { intermediate.first / intermediate.second } + public override suspend fun toResult(intermediate: Pair): T = group { + division(intermediate.first, intermediate.second) + } public companion object { //TODO replace with optimized version which respects overflow - public val real: Mean = Mean(RealField) - public val int: Mean = Mean(IntRing) - public val long: Mean = Mean(LongRing) + public val real: Mean = Mean(DoubleField) { sum, count -> sum / count } + public val int: Mean = Mean(IntRing) { sum, count -> sum / count } + public val long: Mean = Mean(LongRing) { sum, count -> sum / count } } } 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 99% 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 0b3ec01cb..f6a5d6605 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/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 8090f9b2b..59320e6b5 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 89% 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 82b7e0165..497a843c0 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 index cbfaeb8d5..0b9ea1b48 100644 --- a/kmath-viktor/api/kmath-viktor.api +++ b/kmath-viktor/api/kmath-viktor.api @@ -1,10 +1,8 @@ -public final class kscience/kmath/viktor/ViktorBuffer : kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lkscience/kmath/viktor/ViktorBuffer; +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 (Lkscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;Lkscience/kmath/structures/Buffer;)Z - public fun copy ()Lkscience/kmath/structures/MutableBuffer; - public static fun copy-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lkscience/kmath/structures/MutableBuffer; + 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 @@ -26,133 +24,130 @@ public final class kscience/kmath/viktor/ViktorBuffer : kscience/kmath/structure public final synthetic fun unbox-impl ()Lorg/jetbrains/bio/viktor/F64FlatArray; } -public final class kscience/kmath/viktor/ViktorNDField : kscience/kmath/nd/NDField, kscience/kmath/operations/ExtendedField, kscience/kmath/operations/RingWithNumbers { +public final class space/kscience/kmath/viktor/ViktorFieldND : space/kscience/kmath/nd/FieldND, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/NumbersAddOperations, space/kscience/kmath/operations/ScaleOperations { public fun ([I)V public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acos-02gLDOA (Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public fun acos-8UOKELU (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public synthetic fun add (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun add-frQ_39w (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun add (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun add-zrEAbyI (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asin-02gLDOA (Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public fun asin-8UOKELU (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan-02gLDOA (Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public fun atan-8UOKELU (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun binaryOperation (Ljava/lang/String;Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public synthetic fun combine (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDStructure; - public fun combine-C8Lp-Ak (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public fun combine-WKhNzhk (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; - public fun cos-02gLDOA (Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public fun cos-8UOKELU (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun div (DLkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public synthetic fun div (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun div (Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun div (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; 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;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun div (Lkscience/kmath/nd/NDStructure;D)Lkscience/kmath/nd/NDStructure; - public fun div (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public synthetic fun div (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public fun div (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public synthetic fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun divide (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun divide (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun exp-02gLDOA (Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; - public synthetic fun getElementContext ()Ljava/lang/Object; - public fun getElementContext ()Lkscience/kmath/operations/RealField; - public final fun getF64Buffer (Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public fun exp-8UOKELU (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun getElementContext ()Lspace/kscience/kmath/operations/Algebra; + public fun getElementContext ()Lspace/kscience/kmath/operations/DoubleField; + public final fun getF64Buffer (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun getOne ()Ljava/lang/Object; - public fun getOne-hHuhEO0 ()Lorg/jetbrains/bio/viktor/F64Array; + public fun getOne-6kW2wQc ()Lorg/jetbrains/bio/viktor/F64Array; public fun getShape ()[I public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero-hHuhEO0 ()Lorg/jetbrains/bio/viktor/F64Array; - public fun invoke (Lkotlin/jvm/functions/Function1;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun getZero-6kW2wQc ()Lorg/jetbrains/bio/viktor/F64Array; + public fun invoke (Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; 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;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun ln-02gLDOA (Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; - public synthetic fun map (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDStructure; - public fun map-frQ_39w (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/bio/viktor/F64Array; - public synthetic fun mapIndexed (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lkscience/kmath/nd/NDStructure; - public fun mapIndexed-frQ_39w (Lkscience/kmath/nd/NDStructure;Lkotlin/jvm/functions/Function3;)Lorg/jetbrains/bio/viktor/F64Array; - public fun minus (DLkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun ln-8UOKELU (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public fun map-zrEAbyI (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public fun mapIndexed-zrEAbyI (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lorg/jetbrains/bio/viktor/F64Array; + public fun minus (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; 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;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun minus (Lkscience/kmath/nd/NDStructure;D)Lkscience/kmath/nd/NDStructure; - public fun minus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public synthetic fun minus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public fun minus-frQ_39w (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun minus-zrEAbyI (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public synthetic fun multiply (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public fun multiply (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun multiply-frQ_39w (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; + public fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun number-02gLDOA (Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; - public fun plus (DLkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun number-8UOKELU (Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; + public fun plus (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; 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;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun plus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; - public synthetic fun plus (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public fun plus-frQ_39w (Lkscience/kmath/nd/NDStructure;D)Lorg/jetbrains/bio/viktor/F64Array; - public fun plus-frQ_39w (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun plus-zrEAbyI (Lspace/kscience/kmath/nd/StructureND;D)Lorg/jetbrains/bio/viktor/F64Array; + public fun plus-zrEAbyI (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun pow (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; + public fun pow (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun power-frQ_39w (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; - public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/NDStructure; - public fun produce-02gLDOA (Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/bio/viktor/F64Array; + public fun power-zrEAbyI (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public fun produce-8UOKELU (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;Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lkscience/kmath/nd/NDStructure; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale-zrEAbyI (Lspace/kscience/kmath/nd/StructureND;D)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sin-02gLDOA (Lkscience/kmath/nd/NDStructure;)Lorg/jetbrains/bio/viktor/F64Array; + public fun sin-8UOKELU (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public synthetic fun symbol (Ljava/lang/String;)Ljava/lang/Object; - public fun symbol (Ljava/lang/String;)Lkscience/kmath/nd/NDStructure; + public fun sqrt (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; - public fun tan (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun tan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun times (DLkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun times (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; 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;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun times (Lkscience/kmath/nd/NDStructure;D)Lkscience/kmath/nd/NDStructure; - public synthetic fun times (Lkscience/kmath/nd/NDStructure;Ljava/lang/Object;)Lkscience/kmath/nd/NDStructure; - public fun times (Lkscience/kmath/nd/NDStructure;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; - public fun times-frQ_39w (Lkscience/kmath/nd/NDStructure;Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; + public synthetic fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun times (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun times (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun times-zrEAbyI (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperation (Ljava/lang/String;Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryPlus (Lkscience/kmath/nd/NDStructure;)Lkscience/kmath/nd/NDStructure; + public fun unaryPlus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; } -public final class kscience/kmath/viktor/ViktorNDStructure : kscience/kmath/nd/MutableNDStructure { - public static final synthetic fun box-impl (Lorg/jetbrains/bio/viktor/F64Array;)Lkscience/kmath/viktor/ViktorNDStructure; +public final class space/kscience/kmath/viktor/ViktorStructureND : space/kscience/kmath/nd/MutableStructureND { + public static final synthetic fun box-impl (Lorg/jetbrains/bio/viktor/F64Array;)Lspace/kscience/kmath/viktor/ViktorStructureND; 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; @@ -165,8 +160,6 @@ public final class kscience/kmath/viktor/ViktorNDStructure : kscience/kmath/nd/M 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 getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public static fun getFeature-impl (Lorg/jetbrains/bio/viktor/F64Array;Lkotlin/reflect/KClass;)Ljava/lang/Object; public fun getShape ()[I public static fun getShape-impl (Lorg/jetbrains/bio/viktor/F64Array;)[I public fun hashCode ()I @@ -179,8 +172,8 @@ public final class kscience/kmath/viktor/ViktorNDStructure : kscience/kmath/nd/M public final synthetic fun unbox-impl ()Lorg/jetbrains/bio/viktor/F64Array; } -public final class kscience/kmath/viktor/ViktorNDStructureKt { - public static final fun ViktorNDField ([I)Lkscience/kmath/viktor/ViktorNDField; +public final class space/kscience/kmath/viktor/ViktorStructureNDKt { + public static final fun ViktorNDField ([I)Lspace/kscience/kmath/viktor/ViktorFieldND; 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 3c042174f..94744f528 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" @@ -9,6 +9,6 @@ dependencies { api("org.jetbrains.bio:viktor:1.0.1") } -readme{ +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 d3e4806b0..000000000 --- a/kmath-viktor/src/main/kotlin/kscience/kmath/viktor/ViktorNDStructure.kt +++ /dev/null @@ -1,121 +0,0 @@ -package kscience.kmath.viktor - -import kscience.kmath.misc.UnstableKMathAPI -import kscience.kmath.nd.* -import kscience.kmath.operations.ExtendedField -import kscience.kmath.operations.RealField -import kscience.kmath.operations.RingWithNumbers -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) - -@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/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/ViktorStructureND.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt new file mode 100644 index 000000000..420bcac90 --- /dev/null +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt @@ -0,0 +1,123 @@ +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.DoubleField +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.NumbersAddOperations +import space.kscience.kmath.operations.ScaleOperations + +@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") +public inline class ViktorStructureND(public val f64Buffer: F64Array) : MutableStructureND { + 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(): ViktorStructureND = ViktorStructureND(this) + +@OptIn(UnstableKMathAPI::class) +@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") +public class ViktorFieldND(public override val shape: IntArray) : FieldND, + NumbersAddOperations>, ExtendedField>, + ScaleOperations> { + + public val StructureND.f64Buffer: F64Array + get() = when { + !shape.contentEquals(this@ViktorFieldND.shape) -> throw ShapeMismatchException( + this@ViktorFieldND.shape, + shape + ) + this is ViktorStructureND && this.f64Buffer.shape.contentEquals(this@ViktorFieldND.shape) -> this.f64Buffer + else -> produce { this@f64Buffer[it] }.f64Buffer + } + + public override val zero: ViktorStructureND by lazy { F64Array.full(init = 0.0, shape = shape).asStructure() } + + public override val one: ViktorStructureND by lazy { F64Array.full(init = 1.0, shape = shape).asStructure() } + + private val strides: Strides = DefaultStrides(shape) + + public override val elementContext: DoubleField get() = DoubleField + + public override fun produce(initializer: DoubleField.(IntArray) -> Double): ViktorStructureND = + F64Array(*shape).apply { + this@ViktorFieldND.strides.indices().forEach { index -> + set(value = DoubleField.initializer(index), indices = index) + } + }.asStructure() + + override fun StructureND.unaryMinus(): StructureND = -1 * this + + public override fun StructureND.map(transform: DoubleField.(Double) -> Double): ViktorStructureND = + F64Array(*this@ViktorFieldND.shape).apply { + this@ViktorFieldND.strides.indices().forEach { index -> + set(value = DoubleField.transform(this@map[index]), indices = index) + } + }.asStructure() + + public override fun StructureND.mapIndexed( + transform: DoubleField.(index: IntArray, Double) -> Double, + ): ViktorStructureND = F64Array(*this@ViktorFieldND.shape).apply { + this@ViktorFieldND.strides.indices().forEach { index -> + set(value = DoubleField.transform(index, this@mapIndexed[index]), indices = index) + } + }.asStructure() + + public override fun combine( + a: StructureND, + b: StructureND, + transform: DoubleField.(Double, Double) -> Double, + ): ViktorStructureND = F64Array(*shape).apply { + this@ViktorFieldND.strides.indices().forEach { index -> + set(value = DoubleField.transform(a[index], b[index]), indices = index) + } + }.asStructure() + + public override fun add(a: StructureND, b: StructureND): ViktorStructureND = + (a.f64Buffer + b.f64Buffer).asStructure() + + public override fun scale(a: StructureND, value: Double): ViktorStructureND = + (a.f64Buffer * value.toDouble()).asStructure() + + public override inline fun StructureND.plus(b: StructureND): ViktorStructureND = + (f64Buffer + b.f64Buffer).asStructure() + + public override inline fun StructureND.minus(b: StructureND): ViktorStructureND = + (f64Buffer - b.f64Buffer).asStructure() + + public override inline fun StructureND.times(k: Number): ViktorStructureND = + (f64Buffer * k.toDouble()).asStructure() + + public override inline fun StructureND.plus(arg: Double): ViktorStructureND = + (f64Buffer.plus(arg)).asStructure() + + override fun number(value: Number): ViktorStructureND = + F64Array.full(init = value.toDouble(), shape = shape).asStructure() + + override fun sin(arg: StructureND): ViktorStructureND = arg.map { sin(it) } + + override fun cos(arg: StructureND): ViktorStructureND = arg.map { cos(it) } + + override fun asin(arg: StructureND): ViktorStructureND = arg.map { asin(it) } + + override fun acos(arg: StructureND): ViktorStructureND = arg.map { acos(it) } + + override fun atan(arg: StructureND): ViktorStructureND = arg.map { atan(it) } + + override fun power(arg: StructureND, pow: Number): ViktorStructureND = arg.map { it.pow(pow) } + + override fun exp(arg: StructureND): ViktorStructureND = arg.f64Buffer.exp().asStructure() + + override fun ln(arg: StructureND): ViktorStructureND = arg.f64Buffer.log().asStructure() +} + +public fun ViktorNDField(vararg shape: Int): ViktorFieldND = ViktorFieldND(shape) \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 806419bcd..4467d5ed6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,22 +1,21 @@ pluginManagement { repositories { + maven("https://repo.kotlin.link") + mavenLocal() gradlePluginPortal() jcenter() - 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.5" - val kotlinVersion = "1.4.30" + val toolsVersion = "0.9.3" + val kotlinVersion = "1.4.32" 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 }