Compare commits
86 Commits
beta/kotli
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 72b0d9edc9 | |||
| f8b23261e1 | |||
| d64a117a9f | |||
| 845aea0cd7 | |||
| 7267880126 | |||
| f3e9e338bf | |||
| 73a6ad28c3 | |||
|
|
7da0ace8f8 | ||
| 9c22b51fa5 | |||
| 26dfdf39df | |||
| 58a3f749a7 | |||
| 5abc90a4ba | |||
| 6e97e513fb | |||
| 7d08aed5eb | |||
| b9c1947b70 | |||
| b1446741db | |||
| 98dd43d404 | |||
| 577401bb08 | |||
| 896822ec77 | |||
| ff5fbfa8d8 | |||
| 6fe77607d8 | |||
| b6892e2e5c | |||
| 101eb612b1 | |||
|
|
785d3bd104 | ||
| f362c3e31f | |||
| 1fd5e3fba1 | |||
| 0cd9a329ce | |||
| d2a3fd4fa2 | |||
| 4afd350a4e | |||
| 202585d956 | |||
| f6f9984c8e | |||
| 3649d013cd | |||
| b10caebe2a | |||
| 752a849cd3 | |||
| 2535d4536e | |||
| 4464b72e45 | |||
| ce453129f0 | |||
| d43ce15b99 | |||
| 288ec467e6 | |||
| 59fbe5165f | |||
| 2d37a5255f | |||
| 61209e81b5 | |||
|
|
5bbff7e8ad | ||
| 7ac9794c0c | |||
| e41bbe711c | |||
| 57e4819430 | |||
| e213db67da | |||
| f2fef6cb5d | |||
| ef31e35603 | |||
| a756490d20 | |||
| 9d3d08e66b | |||
|
|
8deaf1470a | ||
| e11968f8d2 | |||
| 656d874a65 | |||
| 4277f480d8 | |||
| 2a3cf190b1 | |||
| 06271fb889 | |||
| bdc9d35512 | |||
| b230abefc8 | |||
| c47fa7bdba | |||
| c70a7c5128 | |||
|
|
720378f7fc | ||
|
|
f9f6b51772 | ||
| 676cf5ff3b | |||
| 5538102ad9 | |||
|
|
345f4f2acf | ||
|
|
8a73406d2c | ||
| ead9b95ae8 | |||
| c9d1de41b1 | |||
| b2b64f35d0 | |||
| 1ec3d1adb9 | |||
| d8af4e36ed | |||
| da9608128b | |||
| 5c8e50c3df | |||
| 117b253d4d | |||
| 6170f0376e | |||
| cd46773f43 | |||
|
|
b518969f02 | ||
| 3aa387c544 | |||
| 19139c0d4e | |||
| b4b8f30b2a | |||
| b9f413b5ce | |||
| 43e407e11a | |||
| a6fcfdebd1 | |||
| c475c43744 | |||
|
|
d1d1476cae |
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
@@ -10,15 +10,25 @@ jobs:
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3.5.1
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '11'
|
||||
java-version: '21'
|
||||
distribution: 'liberica'
|
||||
cache: 'gradle'
|
||||
- name: Gradle Wrapper Validation
|
||||
uses: gradle/wrapper-validation-action@v1.0.4
|
||||
- name: Gradle Build
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
uses: gradle/gradle-build-action@v3
|
||||
with:
|
||||
arguments: test jvmTest
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@v6
|
||||
if: ${{ !cancelled() }} # always run even if the previous step fails
|
||||
with:
|
||||
report_paths: '**/test-results/**/TEST-*.xml'
|
||||
annotate_only: true
|
||||
detailed_summary: true
|
||||
flaky_summary: true
|
||||
include_empty_in_summary: false
|
||||
skip_success_summary: true
|
||||
|
||||
25
.github/workflows/pages.yml
vendored
25
.github/workflows/pages.yml
vendored
@@ -7,25 +7,20 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 40
|
||||
steps:
|
||||
- uses: actions/checkout@v3.0.0
|
||||
- uses: actions/setup-java@v3.0.0
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: 11
|
||||
java-version: 21
|
||||
distribution: liberica
|
||||
- name: Cache konan
|
||||
uses: actions/cache@v3.0.1
|
||||
- name: Gradle Wrapper Validation
|
||||
uses: gradle/wrapper-validation-action@v1.0.4
|
||||
- uses: gradle/gradle-build-action@v3
|
||||
with:
|
||||
path: ~/.konan
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
- uses: gradle/gradle-build-action@v2.4.2
|
||||
with:
|
||||
arguments: dokkaHtmlMultiModule --no-parallel
|
||||
- uses: JamesIves/github-pages-deploy-action@v4.3.0
|
||||
arguments: dokkaGenerate --no-parallel
|
||||
- uses: JamesIves/github-pages-deploy-action@v4
|
||||
with:
|
||||
branch: gh-pages
|
||||
folder: build/dokka/htmlMultiModule
|
||||
folder: build/dokka/html
|
||||
|
||||
50
.github/workflows/publish.yml
vendored
50
.github/workflows/publish.yml
vendored
@@ -1,50 +0,0 @@
|
||||
name: Gradle publish
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [ created ]
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
environment:
|
||||
name: publish
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ macOS-latest, windows-latest ]
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
- uses: actions/checkout@v3.0.0
|
||||
- uses: actions/setup-java@v3.10.0
|
||||
with:
|
||||
java-version: 11
|
||||
distribution: liberica
|
||||
- name: Cache konan
|
||||
uses: actions/cache@v3.0.1
|
||||
with:
|
||||
path: ~/.konan
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
- name: Publish Windows Artifacts
|
||||
if: matrix.os == 'windows-latest'
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
with:
|
||||
arguments: |
|
||||
publishAllPublicationsToSpaceRepository
|
||||
-Ppublishing.targets=all
|
||||
-Ppublishing.space.user=${{ secrets.SPACE_APP_ID }}
|
||||
-Ppublishing.space.token=${{ secrets.SPACE_APP_SECRET }}
|
||||
- name: Publish Mac Artifacts
|
||||
if: matrix.os == 'macOS-latest'
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
with:
|
||||
arguments: |
|
||||
publishMacosX64PublicationToSpaceRepository
|
||||
publishMacosArm64PublicationToSpaceRepository
|
||||
publishIosX64PublicationToSpaceRepository
|
||||
publishIosArm64PublicationToSpaceRepository
|
||||
publishIosSimulatorArm64PublicationToSpaceRepository
|
||||
-Ppublishing.targets=all
|
||||
-Ppublishing.space.user=${{ secrets.SPACE_APP_ID }}
|
||||
-Ppublishing.space.token=${{ secrets.SPACE_APP_SECRET }}
|
||||
48
.space.kts
48
.space.kts
@@ -1,48 +0,0 @@
|
||||
import kotlin.io.path.readText
|
||||
|
||||
val projectName = "kmath"
|
||||
|
||||
job("Build") {
|
||||
//Perform only jvm tests
|
||||
gradlew("spc.registry.jetbrains.space/p/sci/containers/kotlin-ci:1.0.3", "test", "jvmTest")
|
||||
}
|
||||
|
||||
job("Publish") {
|
||||
startOn {
|
||||
gitPush { enabled = false }
|
||||
}
|
||||
container("spc.registry.jetbrains.space/p/sci/containers/kotlin-ci:1.0.3") {
|
||||
env["SPACE_USER"] = "{{ project:space_user }}"
|
||||
env["SPACE_TOKEN"] = "{{ project:space_token }}"
|
||||
kotlinScript { api ->
|
||||
|
||||
val spaceUser = System.getenv("SPACE_USER")
|
||||
val spaceToken = System.getenv("SPACE_TOKEN")
|
||||
|
||||
// write the version to the build directory
|
||||
api.gradlew("version")
|
||||
|
||||
//read the version from build file
|
||||
val version = java.nio.file.Path.of("build/project-version.txt").readText()
|
||||
|
||||
val revisionSuffix = if (version.endsWith("SNAPSHOT")) {
|
||||
"-" + api.gitRevision().take(7)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
api.space().projects.automation.deployments.start(
|
||||
project = api.projectIdentifier(),
|
||||
targetIdentifier = TargetIdentifier.Key(projectName),
|
||||
version = version + revisionSuffix,
|
||||
// automatically update deployment status based on the status of a job
|
||||
syncWithAutomationJob = true
|
||||
)
|
||||
api.gradlew(
|
||||
"publishAllPublicationsToSpaceRepository",
|
||||
"-Ppublishing.space.user=\"$spaceUser\"",
|
||||
"-Ppublishing.space.token=\"$spaceToken\"",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
48
CHANGELOG.md
48
CHANGELOG.md
@@ -3,7 +3,6 @@
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
- Metropolis-Hastings sampler
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -15,7 +14,52 @@
|
||||
|
||||
### Security
|
||||
|
||||
## 0.4.0-dev-3 - 2024-02-18
|
||||
## 0.5.0 - 2026-01-09
|
||||
|
||||
### Added
|
||||
|
||||
- More statistics functions by @qwazer
|
||||
- Fit accessors with Attribute
|
||||
|
||||
### Changed
|
||||
|
||||
- Flag attributes are replaced with boolean attributes to properly support missing values
|
||||
- Upgrade tensorflow version to 1.0.0
|
||||
|
||||
### Removed
|
||||
|
||||
- Support for ND4J
|
||||
|
||||
## 0.4.2 - 2025-01-27
|
||||
|
||||
### Added
|
||||
|
||||
- Convenient matrix builders for rows, columns, vstacks and hstacks
|
||||
- Sparse matrix builder
|
||||
|
||||
### Fixed
|
||||
|
||||
- Ojalgo conversion bug which made all converted matrices be zero.
|
||||
|
||||
## 0.4.1 - 2025-01-12
|
||||
|
||||
### Added
|
||||
|
||||
- Metropolis-Hastings sampler
|
||||
- Ojalgo `LinearSpace` implementation.
|
||||
|
||||
### Changed
|
||||
|
||||
- attributes-kt moved to a separate project, and the version used is 0.3.0
|
||||
- Kotlin 2.1. Now use cross-compilation to deploy macOS targets.
|
||||
- Changed `origin` to `cmMatrix` in kmath-commons to avoid property name clash. Expose bidirectional conversion in `CMLinearSpace`
|
||||
- (BREAKING CHANGE) Changed implementations in `kmath-ejml` to match CM and ojalgo style. Specifically, provide bidirectional conversion for library types.
|
||||
|
||||
### Fixed
|
||||
|
||||
- (BREAKING CHANGE) Fix EJML to properly treat vectors as columns
|
||||
|
||||
## 0.4.0 - 2024-02-18
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
89
README.md
89
README.md
@@ -2,14 +2,10 @@
|
||||
[](https://zenodo.org/badge/latestdoi/129486382)
|
||||

|
||||
[](https://search.maven.org/search?q=g:%22space.kscience%22)
|
||||
[](https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven/space/kscience/)
|
||||
|
||||
# KMath
|
||||
|
||||
Could be pronounced as `key-math`. The **K**otlin **Math**ematics library was initially intended as a Kotlin-based
|
||||
analog to Python's NumPy library. Later we found that kotlin is much more flexible language and allows superior
|
||||
architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like
|
||||
experience could be achieved with [kmath-for-real](/kmath-for-real) extension module.
|
||||
Could be pronounced as `key-math`. The **K**otlin **Math**ematics library was initially intended as a Kotlin-based analog to Python's NumPy library. Later we found that kotlin is a much more flexible language and allows superior architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could be achieved with [kmath-for-real](kmath-for-real) extension module.
|
||||
|
||||
[Documentation site](https://SciProgCentre.github.io/kmath/)
|
||||
|
||||
@@ -35,15 +31,17 @@ experience could be achieved with [kmath-for-real](/kmath-for-real) extension mo
|
||||
* Be like NumPy. It was the idea at the beginning, but we decided that we can do better in API.
|
||||
* Provide the best performance out of the box. We have specialized libraries for that. Need only API wrappers for them.
|
||||
* Cover all cases as immediately and in one bundle. We will modularize everything and add new features gradually.
|
||||
* Provide specialized behavior in the core. API is made generic on purpose, so one needs to specialize for types, like
|
||||
for `Double` in the core. For that we will have specialization modules like `kmath-for-real`, which will give better
|
||||
experience for those, who want to work with specific types.
|
||||
* Provide specialized behavior in the core. API is made generic on purpose, so one needs to specialize for types, like for `Float64` in the core. For that we will have specialization modules like [kmath-for-real](kmath-for-real), which will give a better experience for those who want to work with specific types.
|
||||
|
||||
## Contributing
|
||||
|
||||
The project requires a lot of additional work. The most important thing we need is feedback about what features are required the most. Feel free to create feature requests. We are also welcome to code contributions, especially in issues marked with [good first issue](https://github.com/SciProgCentre/kmath/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label.
|
||||
|
||||
Project roadmap will be available at [GitHub Projects](https://github.com/orgs/SciProgCentre/projects/3).
|
||||
|
||||
## Features and stability
|
||||
|
||||
KMath is a modular library. Different modules provide different features with different API stability guarantees. All
|
||||
core modules are released with the same version, but with different API change policy. The features are described in
|
||||
module definitions below. The module stability could have the following levels:
|
||||
KMath is a modular library. Different modules provide different features with different API stability guarantees. All core modules are released with the same version, but with different API change policy. The features are described in module definitions below. The module stability could have the following levels:
|
||||
|
||||
* **PROTOTYPE**. On this level there are no compatibility guarantees. All methods and classes form those modules could
|
||||
break any moment. You can still use it, but be sure to fix the specific version.
|
||||
@@ -51,25 +49,16 @@ module definitions below. The module stability could have the following levels:
|
||||
with `@UnstableKMathAPI` or other stability warning annotations.
|
||||
* **DEVELOPMENT**. API breaking generally follows semantic versioning ideology. There could be changes in minor
|
||||
versions, but not in patch versions. API is protected
|
||||
with [binary-compatibility-validator](https://github.com/Kotlin/binary-compatibility-validator) tool.
|
||||
with [binary-compatibility-validator](https://kotlinlang.org/docs/gradle-binary-compatibility-validation.html) tool.
|
||||
* **STABLE**. The API stabilized. Breaking changes are allowed only in major releases.
|
||||
|
||||
## Modules
|
||||
|
||||
|
||||
### [attributes-kt](attributes-kt)
|
||||
> An API and basic implementation for arranging objects in a continuous memory block.
|
||||
>
|
||||
> **Maturity**: DEVELOPMENT
|
||||
|
||||
### [benchmarks](benchmarks)
|
||||
>
|
||||
> **Maturity**: EXPERIMENTAL
|
||||
|
||||
### [examples](examples)
|
||||
>
|
||||
> **Maturity**: EXPERIMENTAL
|
||||
|
||||
### [kmath-ast](kmath-ast)
|
||||
>
|
||||
> **Maturity**: EXPERIMENTAL
|
||||
@@ -104,11 +93,9 @@ module definitions below. The module stability could have the following levels:
|
||||
> **Features:**
|
||||
> - [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.
|
||||
> - [linear](kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt) : Basic linear algebra operations (sums, products, etc.), backed by the `Space` API.
|
||||
> - [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.
|
||||
> - [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
|
||||
> - [domains](kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains) : Domains
|
||||
> - [autodiff](kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt) : Automatic differentiation
|
||||
> - [Parallel linear algebra](kmath-core/#) : Parallel implementation for `LinearAlgebra`
|
||||
@@ -167,15 +154,6 @@ One can still use generic algebras though.
|
||||
>
|
||||
> **Maturity**: PROTOTYPE
|
||||
|
||||
### [kmath-jafama](kmath-jafama)
|
||||
> Jafama integration module
|
||||
>
|
||||
> **Maturity**: DEPRECATED
|
||||
>
|
||||
> **Features:**
|
||||
> - [jafama-double](kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/) : Double ExtendedField implementations based on Jafama
|
||||
|
||||
|
||||
### [kmath-jupyter](kmath-jupyter)
|
||||
>
|
||||
> **Maturity**: PROTOTYPE
|
||||
@@ -200,16 +178,10 @@ One can still use generic algebras though.
|
||||
>
|
||||
> **Maturity**: PROTOTYPE
|
||||
|
||||
### [kmath-nd4j](kmath-nd4j)
|
||||
> ND4J NDStructure implementation and according NDAlgebra classes
|
||||
### [kmath-ojalgo](kmath-ojalgo)
|
||||
> Ojalgo bindings for kmath
|
||||
>
|
||||
> **Maturity**: DEPRECATED
|
||||
>
|
||||
> **Features:**
|
||||
> - [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
|
||||
|
||||
> **Maturity**: PROTOTYPE
|
||||
|
||||
### [kmath-optimization](kmath-optimization)
|
||||
>
|
||||
@@ -251,34 +223,21 @@ One can still use generic algebras though.
|
||||
|
||||
## Multi-platform support
|
||||
|
||||
KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the
|
||||
[common source sets](/kmath-core/src/commonMain) and implemented there wherever it is possible. In some cases, features
|
||||
are delegated to platform-specific implementations even if they could be provided in the common module for performance
|
||||
reasons. Currently, Kotlin/JVM is the primary platform, however, Kotlin/Native and Kotlin/JS contributions and
|
||||
feedback are also welcome.
|
||||
KMath is developed as a multi-platform library, which means that most of the interfaces are declared in common source sets like [common source sets](kmath-core/src/commonMain) and implemented there wherever it is possible. In some cases, features are delegated to platform-specific implementations even if they could be provided in the common module for performance reasons. Currently, Kotlin/JVM is the primary platform, however, Kotlin/Native, Kotlin/JS and Kotlin/Wasm contributions and feedback are also welcome.
|
||||
|
||||
## Performance
|
||||
|
||||
Calculation of performance is one of the major goals of KMath in the future, but in some cases it is impossible to
|
||||
achieve both
|
||||
performance and flexibility.
|
||||
Performance of mathematical operations is hard to achieve without a lot of effort. KMath focus is to provide a reasonable performance for common cases, out of the box and good interoperability with optimized libraries for edge cases. For example, one could prototype an algorithm using KMath core implementations and then use Multik or Ojalgo for performance-critical parts just by adding a dependency and algebra context switch.
|
||||
|
||||
We expect to focus on creating a convenient universal API first and then work on increasing performance for specific
|
||||
cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized
|
||||
native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be
|
||||
better than SciPy.
|
||||
As for core implementations, we expect to focus on creating a convenient universal API first and then work on increasing performance for specific cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be better than SciPy.
|
||||
|
||||
## Requirements
|
||||
|
||||
KMath currently relies on JDK 11 for compilation and execution of Kotlin-JVM part. We recommend using GraalVM-CE or
|
||||
Oracle GraalVM for execution to get better performance.
|
||||
KMath currently relies on JDK 21 for compilation and execution of Kotlin-JVM part.
|
||||
|
||||
### Repositories
|
||||
|
||||
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:
|
||||
Intermediate releases are published to [Kotlin.Link](https://repo.kotlin.link) repository.
|
||||
|
||||
```kotlin
|
||||
repositories {
|
||||
@@ -290,11 +249,3 @@ dependencies {
|
||||
// api("space.kscience:kmath-core-jvm:$version") for jvm-specific version
|
||||
}
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
The project requires a lot of additional work. The most important thing we need is feedback about what features are
|
||||
required the most. Feel free to create feature requests. We are also welcome to code contributions, especially in issues
|
||||
marked
|
||||
with [good first issue](hhttps://github.com/SciProgCentre/kmath/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
|
||||
label.
|
||||
@@ -1,21 +0,0 @@
|
||||
# Module attributes-kt
|
||||
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:attributes-kt:0.1.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
repositories {
|
||||
maven("https://repo.kotlin.link")
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:attributes-kt:0.1.0")
|
||||
}
|
||||
```
|
||||
@@ -1,104 +0,0 @@
|
||||
public abstract interface class space/kscience/attributes/Attribute {
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/attributes/AttributeContainer {
|
||||
public abstract fun getAttributes ()Lspace/kscience/attributes/Attributes;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/attributes/AttributeScope {
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/attributes/AttributeWithDefault : space/kscience/attributes/Attribute {
|
||||
public abstract fun getDefault ()Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/attributes/Attributes {
|
||||
public static final field Companion Lspace/kscience/attributes/Attributes$Companion;
|
||||
public abstract fun equals (Ljava/lang/Object;)Z
|
||||
public fun get (Lspace/kscience/attributes/Attribute;)Ljava/lang/Object;
|
||||
public abstract fun getContent ()Ljava/util/Map;
|
||||
public fun getKeys ()Ljava/util/Set;
|
||||
public abstract fun hashCode ()I
|
||||
public abstract fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class space/kscience/attributes/Attributes$Companion {
|
||||
public final fun equals (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attributes;)Z
|
||||
public final fun getEMPTY ()Lspace/kscience/attributes/Attributes;
|
||||
}
|
||||
|
||||
public final class space/kscience/attributes/AttributesBuilder : space/kscience/attributes/Attributes {
|
||||
public final fun add (Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)V
|
||||
public final fun build ()Lspace/kscience/attributes/Attributes;
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public fun getContent ()Ljava/util/Map;
|
||||
public fun hashCode ()I
|
||||
public final fun invoke (Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)V
|
||||
public final fun put (Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)V
|
||||
public final fun putAll (Lspace/kscience/attributes/Attributes;)V
|
||||
public final fun remove (Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)V
|
||||
public final fun set (Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)V
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class space/kscience/attributes/AttributesBuilderKt {
|
||||
public static final fun Attributes (Lkotlin/jvm/functions/Function1;)Lspace/kscience/attributes/Attributes;
|
||||
}
|
||||
|
||||
public final class space/kscience/attributes/AttributesKt {
|
||||
public static final fun Attributes (Lspace/kscience/attributes/Attribute;)Lspace/kscience/attributes/Attributes;
|
||||
public static final fun Attributes (Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)Lspace/kscience/attributes/Attributes;
|
||||
public static final fun getOrDefault (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/AttributeWithDefault;)Ljava/lang/Object;
|
||||
public static final fun isEmpty (Lspace/kscience/attributes/Attributes;)Z
|
||||
public static final fun modified (Lspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function1;)Lspace/kscience/attributes/Attributes;
|
||||
public static final fun plus (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attributes;)Lspace/kscience/attributes/Attributes;
|
||||
public static final fun withAttribute (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attribute;)Lspace/kscience/attributes/Attributes;
|
||||
public static final fun withAttribute (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)Lspace/kscience/attributes/Attributes;
|
||||
public static final fun withAttributeElement (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)Lspace/kscience/attributes/Attributes;
|
||||
public static final fun withoutAttribute (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attribute;)Lspace/kscience/attributes/Attributes;
|
||||
public static final fun withoutAttributeElement (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)Lspace/kscience/attributes/Attributes;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/attributes/FlagAttribute : space/kscience/attributes/Attribute {
|
||||
}
|
||||
|
||||
public abstract class space/kscience/attributes/PolymorphicAttribute : space/kscience/attributes/Attribute {
|
||||
public synthetic fun <init> (Lkotlin/reflect/KType;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public final fun getType-V0oMfBY ()Lkotlin/reflect/KType;
|
||||
public fun hashCode ()I
|
||||
}
|
||||
|
||||
public final class space/kscience/attributes/PolymorphicAttributeKt {
|
||||
public static final fun get (Lspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
|
||||
public static final fun set (Lspace/kscience/attributes/AttributesBuilder;Lkotlin/jvm/functions/Function0;Ljava/lang/Object;)V
|
||||
}
|
||||
|
||||
public final class space/kscience/attributes/SafeType {
|
||||
public static final synthetic fun box-impl (Lkotlin/reflect/KType;)Lspace/kscience/attributes/SafeType;
|
||||
public static fun constructor-impl (Lkotlin/reflect/KType;)Lkotlin/reflect/KType;
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public static fun equals-impl (Lkotlin/reflect/KType;Ljava/lang/Object;)Z
|
||||
public static final fun equals-impl0 (Lkotlin/reflect/KType;Lkotlin/reflect/KType;)Z
|
||||
public final fun getKType ()Lkotlin/reflect/KType;
|
||||
public fun hashCode ()I
|
||||
public static fun hashCode-impl (Lkotlin/reflect/KType;)I
|
||||
public fun toString ()Ljava/lang/String;
|
||||
public static fun toString-impl (Lkotlin/reflect/KType;)Ljava/lang/String;
|
||||
public final synthetic fun unbox-impl ()Lkotlin/reflect/KType;
|
||||
}
|
||||
|
||||
public final class space/kscience/attributes/SafeTypeKt {
|
||||
public static final fun getKClass-X0YbwmU (Lkotlin/reflect/KType;)Lkotlin/reflect/KClass;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/attributes/SetAttribute : space/kscience/attributes/Attribute {
|
||||
}
|
||||
|
||||
public abstract interface annotation class space/kscience/attributes/UnstableAttributesAPI : java/lang/annotation/Annotation {
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/attributes/WithType {
|
||||
public abstract fun getType-V0oMfBY ()Lkotlin/reflect/KType;
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
plugins {
|
||||
id("space.kscience.gradle.mpp")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
version = rootProject.extra.get("attributesVersion").toString()
|
||||
|
||||
kscience {
|
||||
jvm()
|
||||
js()
|
||||
native()
|
||||
wasm()
|
||||
}
|
||||
|
||||
readme {
|
||||
maturity = space.kscience.gradle.Maturity.DEVELOPMENT
|
||||
description = """
|
||||
An API and basic implementation for arranging objects in a continuous memory block.
|
||||
""".trimIndent()
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018-2023 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.attributes
|
||||
|
||||
/**
|
||||
* A marker interface for an attribute. Attributes are used as keys to access contents of type [T] in the container.
|
||||
*/
|
||||
public interface Attribute<T>
|
||||
|
||||
/**
|
||||
* An attribute that could be either present or absent
|
||||
*/
|
||||
public interface FlagAttribute : Attribute<Unit>
|
||||
|
||||
/**
|
||||
* An attribute with a default value
|
||||
*/
|
||||
public interface AttributeWithDefault<T> : Attribute<T> {
|
||||
public val default: T
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute containing a set of values
|
||||
*/
|
||||
public interface SetAttribute<V> : Attribute<Set<V>>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018-2023 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.attributes
|
||||
|
||||
/**
|
||||
* A container for [Attributes]
|
||||
*/
|
||||
public interface AttributeContainer {
|
||||
public val attributes: Attributes
|
||||
}
|
||||
|
||||
/**
|
||||
* A scope, where attribute keys could be resolved.
|
||||
* [O] is used only to resolve types in compile-time.
|
||||
*/
|
||||
public interface AttributeScope<O>
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018-2023 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.attributes
|
||||
|
||||
/**
|
||||
* A set of attributes. The implementation must guarantee that [content] keys correspond to their value types.
|
||||
*/
|
||||
public interface Attributes {
|
||||
/**
|
||||
* Raw content for this [Attributes]
|
||||
*/
|
||||
public val content: Map<out Attribute<*>, Any?>
|
||||
|
||||
/**
|
||||
* Attribute keys contained in this [Attributes]
|
||||
*/
|
||||
public val keys: Set<Attribute<*>> get() = content.keys
|
||||
|
||||
/**
|
||||
* Provide an attribute value. Return null if attribute is not present or if its value is null.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public operator fun <T> get(attribute: Attribute<T>): T? = content[attribute] as? T
|
||||
|
||||
override fun toString(): String
|
||||
override fun equals(other: Any?): Boolean
|
||||
override fun hashCode(): Int
|
||||
|
||||
public companion object {
|
||||
public val EMPTY: Attributes = object : Attributes {
|
||||
override val content: Map<out Attribute<*>, Any?> get() = emptyMap()
|
||||
|
||||
override fun toString(): String = "Attributes.EMPTY"
|
||||
|
||||
override fun equals(other: Any?): Boolean = (other as? Attributes)?.isEmpty() ?: false
|
||||
|
||||
override fun hashCode(): Int = Unit.hashCode()
|
||||
}
|
||||
|
||||
public fun equals(a1: Attributes, a2: Attributes): Boolean =
|
||||
a1.keys == a2.keys && a1.keys.all { a1[it] == a2[it] }
|
||||
}
|
||||
}
|
||||
|
||||
internal class MapAttributes(override val content: Map<out Attribute<*>, Any?>) : Attributes {
|
||||
override fun toString(): String = "Attributes(value=${content.entries})"
|
||||
override fun equals(other: Any?): Boolean = other is Attributes && Attributes.equals(this, other)
|
||||
override fun hashCode(): Int = content.hashCode()
|
||||
}
|
||||
|
||||
public fun Attributes.isEmpty(): Boolean = keys.isEmpty()
|
||||
|
||||
/**
|
||||
* Get attribute value or default
|
||||
*/
|
||||
public fun <T> Attributes.getOrDefault(attribute: AttributeWithDefault<T>): T = get(attribute) ?: attribute.default
|
||||
|
||||
/**
|
||||
* Check if there is an attribute that matches given key by type and adheres to [predicate].
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public inline fun <T, reified A : Attribute<T>> Attributes.hasAny(predicate: (value: T) -> Boolean): Boolean =
|
||||
content.any { (mapKey, mapValue) -> mapKey is A && predicate(mapValue as T) }
|
||||
|
||||
/**
|
||||
* Check if there is an attribute of given type (subtypes included)
|
||||
*/
|
||||
public inline fun <reified A : Attribute<*>> Attributes.hasAny(): Boolean =
|
||||
content.any { (mapKey, _) -> mapKey is A }
|
||||
|
||||
/**
|
||||
* Check if [Attributes] contains a flag. Multiple keys that are instances of a flag could be present
|
||||
*/
|
||||
public inline fun <reified A : FlagAttribute> Attributes.hasFlag(): Boolean =
|
||||
content.keys.any { it is A }
|
||||
|
||||
/**
|
||||
* Create [Attributes] with an added or replaced attribute key.
|
||||
*/
|
||||
public fun <T, A : Attribute<T>> Attributes.withAttribute(
|
||||
attribute: A,
|
||||
attrValue: T,
|
||||
): Attributes = MapAttributes(content + (attribute to attrValue))
|
||||
|
||||
public fun <A : Attribute<Unit>> Attributes.withAttribute(attribute: A): Attributes =
|
||||
withAttribute(attribute, Unit)
|
||||
|
||||
/**
|
||||
* Create a new [Attributes] by modifying the current one
|
||||
*/
|
||||
public fun <O> Attributes.modified(block: AttributesBuilder<O>.() -> Unit): Attributes = Attributes<O> {
|
||||
putAll(this@modified)
|
||||
block()
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new [Attributes] by removing [attribute] key
|
||||
*/
|
||||
public fun Attributes.withoutAttribute(attribute: Attribute<*>): Attributes = MapAttributes(content.minus(attribute))
|
||||
|
||||
/**
|
||||
* Add an element to a [SetAttribute]
|
||||
*/
|
||||
public fun <T, A : SetAttribute<T>> Attributes.withAttributeElement(
|
||||
attribute: A,
|
||||
attrValue: T,
|
||||
): Attributes {
|
||||
val currentSet: Set<T> = get(attribute) ?: emptySet()
|
||||
return MapAttributes(
|
||||
content + (attribute to (currentSet + attrValue))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an element from [SetAttribute]
|
||||
*/
|
||||
public fun <T, A : SetAttribute<T>> Attributes.withoutAttributeElement(
|
||||
attribute: A,
|
||||
attrValue: T,
|
||||
): Attributes {
|
||||
val currentSet: Set<T> = get(attribute) ?: emptySet()
|
||||
return MapAttributes(content + (attribute to (currentSet - attrValue)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Create [Attributes] with a single key
|
||||
*/
|
||||
public fun <T, A : Attribute<T>> Attributes(
|
||||
attribute: A,
|
||||
attrValue: T,
|
||||
): Attributes = MapAttributes(mapOf(attribute to attrValue))
|
||||
|
||||
/**
|
||||
* Create Attributes with a single [Unit] valued attribute
|
||||
*/
|
||||
public fun <A : Attribute<Unit>> Attributes(
|
||||
attribute: A,
|
||||
): Attributes = MapAttributes(mapOf(attribute to Unit))
|
||||
|
||||
/**
|
||||
* Create a new [Attributes] that overlays [other] on top of this set of attributes. New attributes are added.
|
||||
* Existing attribute keys are replaced.
|
||||
*/
|
||||
public operator fun Attributes.plus(other: Attributes): Attributes = when {
|
||||
isEmpty() -> other
|
||||
other.isEmpty() -> this
|
||||
else -> MapAttributes(content + other.content)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new [Attributes] with removed [key] (if it is present).
|
||||
*/
|
||||
public operator fun Attributes.minus(key: Attribute<*>): Attributes =
|
||||
if (content.contains(key)) MapAttributes(content.minus(key)) else this
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018-2023 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.attributes
|
||||
|
||||
/**
|
||||
* A builder for [Attributes].
|
||||
* The builder is not thread safe
|
||||
*
|
||||
* @param O type marker of an owner object, for which these attributes are made
|
||||
*/
|
||||
public class AttributesBuilder<out O> internal constructor() : Attributes {
|
||||
|
||||
private val map = mutableMapOf<Attribute<*>, Any?>()
|
||||
|
||||
override fun toString(): String = "Attributes(value=${map.entries})"
|
||||
override fun equals(other: Any?): Boolean = other is Attributes && Attributes.equals(this, other)
|
||||
override fun hashCode(): Int = map.hashCode()
|
||||
|
||||
override val content: Map<out Attribute<*>, Any?> get() = map
|
||||
|
||||
public operator fun <T> set(attribute: Attribute<T>, value: T?) {
|
||||
if (value == null) {
|
||||
map.remove(attribute)
|
||||
} else {
|
||||
map[attribute] = value
|
||||
}
|
||||
}
|
||||
|
||||
public operator fun <V> Attribute<V>.invoke(value: V?) {
|
||||
set(this, value)
|
||||
}
|
||||
|
||||
public infix fun <V> Attribute<V>.put(value: V?) {
|
||||
set(this, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Put all attributes for given [attributes]
|
||||
*/
|
||||
public fun putAll(attributes: Attributes) {
|
||||
map.putAll(attributes.content)
|
||||
}
|
||||
|
||||
public infix fun <V> SetAttribute<V>.add(attrValue: V) {
|
||||
val currentSet: Set<V> = get(this) ?: emptySet()
|
||||
map[this] = currentSet + attrValue
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an element from [SetAttribute]
|
||||
*/
|
||||
public infix fun <V> SetAttribute<V>.remove(attrValue: V) {
|
||||
val currentSet: Set<V> = get(this) ?: emptySet()
|
||||
map[this] = currentSet - attrValue
|
||||
}
|
||||
|
||||
public fun build(): Attributes = MapAttributes(map)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create [Attributes] with a given [builder]
|
||||
* @param O the type for which attributes are built. The type is used only during compilation phase for static extension dispatch
|
||||
*/
|
||||
public fun <O> Attributes(builder: AttributesBuilder<O>.() -> Unit): Attributes =
|
||||
AttributesBuilder<O>().apply(builder).build()
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018-2023 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.attributes
|
||||
|
||||
/**
|
||||
* An attribute that has a type parameter for value
|
||||
* @param type parameter-type
|
||||
*/
|
||||
public abstract class PolymorphicAttribute<T>(public val type: SafeType<T>) : Attribute<T> {
|
||||
override fun equals(other: Any?): Boolean = other != null &&
|
||||
(this::class == other::class) &&
|
||||
(other as? PolymorphicAttribute<*>)?.type == this.type
|
||||
|
||||
override fun hashCode(): Int = this::class.hashCode() + type.hashCode()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a polymorphic attribute using attribute factory
|
||||
*/
|
||||
@UnstableAttributesAPI
|
||||
public operator fun <T> Attributes.get(attributeKeyBuilder: () -> PolymorphicAttribute<T>): T? =
|
||||
get(attributeKeyBuilder())
|
||||
|
||||
/**
|
||||
* Set a polymorphic attribute using its factory
|
||||
*/
|
||||
@UnstableAttributesAPI
|
||||
public operator fun <O, T> AttributesBuilder<O>.set(attributeKeyBuilder: () -> PolymorphicAttribute<T>, value: T) {
|
||||
set(attributeKeyBuilder(), value)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018-2023 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.attributes
|
||||
|
||||
import kotlin.jvm.JvmInline
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
/**
|
||||
* Safe variant ok Kotlin [KType] that ensures that the type parameter is of the same type as [kType]
|
||||
*
|
||||
* @param kType raw [KType]
|
||||
*/
|
||||
@JvmInline
|
||||
public value class SafeType<out T> @PublishedApi internal constructor(public val kType: KType)
|
||||
|
||||
public inline fun <reified T> safeTypeOf(): SafeType<T> = SafeType(typeOf<T>())
|
||||
|
||||
/**
|
||||
* Derive Kotlin [KClass] from this type and fail if the type is not a class (should not happen)
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@UnstableAttributesAPI
|
||||
public val <T> SafeType<T>.kClass: KClass<T & Any> get() = kType.classifier as KClass<T & Any>
|
||||
|
||||
/**
|
||||
* An interface containing [type] for dynamic type checking.
|
||||
*/
|
||||
public interface WithType<out T> {
|
||||
public val type: SafeType<T>
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018-2023 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.attributes
|
||||
|
||||
/**
|
||||
* Marks declarations that are still experimental in the Attributes-kt APIs, which means that the design of the corresponding
|
||||
* declarations has open issues that may (or may not) lead to their changes in the future. Roughly speaking, there is
|
||||
* a chance of those declarations will be deprecated in the future or the semantics of their behavior may change
|
||||
* in some way that may break some code.
|
||||
*/
|
||||
@MustBeDocumented
|
||||
@Retention(value = AnnotationRetention.BINARY)
|
||||
@RequiresOptIn("This API is unstable and could change in future", RequiresOptIn.Level.WARNING)
|
||||
public annotation class UnstableAttributesAPI
|
||||
@@ -1,119 +1,122 @@
|
||||
# Module KMath-Benchmarks
|
||||
|
||||
# BenchmarksResult
|
||||
|
||||
## Report for benchmark configuration <code>main</code>
|
||||
|
||||
* Run on Java HotSpot(TM) 64-Bit Server VM (build 21.0.4+8-LTS-jvmci-23.1-b41) with Java process:
|
||||
* Run on OpenJDK 64-Bit Server VM (build 21.0.9+10-LTS) with Java process:
|
||||
|
||||
```
|
||||
C:\Users\altavir\scoop\apps\graalvm-oracle-21jdk\current\bin\java.exe -XX:ThreadPriorityPolicy=1 -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCIProduct -XX:-UnlockExperimentalVMOptions -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant
|
||||
C:\Users\altavir\.gradle\jdks\eclipse_adoptium-21-amd64-windows.2\bin\java.exe -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant
|
||||
```
|
||||
* JMH 1.21 was used in `thrpt` mode with 5 warmup iterations by 10 s and 5 measurement iterations by 10 s.
|
||||
* JMH 1.37 was used in `thrpt` mode with 5 warmup iterations by 10 s and 5 measurement iterations by 10 s.
|
||||
### [ArrayBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`benchmarkArrayRead`|1.9E+07 ± 2.3E+05 ops/s|
|
||||
|`benchmarkBufferRead`|1.4E+07 ± 8.7E+05 ops/s|
|
||||
|`nativeBufferRead`|1.4E+07 ± 1.3E+06 ops/s|
|
||||
|`benchmarkArrayRead`|3.9E+06 ± 1.1E+06 ops/s|
|
||||
|`benchmarkBufferRead`|4.0E+06 ± 2.2E+05 ops/s|
|
||||
|`nativeBufferRead`|4.0E+06 ± 1.7E+05 ops/s|
|
||||
### [BigIntBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BigIntBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`jvmAdd`|5.1E+07 ± 1.3E+06 ops/s|
|
||||
|`jvmAddLarge`|5.1E+04 ± 8.2E+02 ops/s|
|
||||
|`jvmMultiply`|8.5E+07 ± 9.7E+06 ops/s|
|
||||
|`jvmMultiplyLarge`|2.5E+02 ± 15 ops/s|
|
||||
|`jvmParsing10`|8.7E+06 ± 5.1E+05 ops/s|
|
||||
|`jvmParsing16`|6.4E+06 ± 1.8E+05 ops/s|
|
||||
|`jvmPower`|28 ± 0.79 ops/s|
|
||||
|`jvmSmallAdd`|7.0E+07 ± 4.3E+06 ops/s|
|
||||
|`kmAdd`|4.8E+07 ± 2.2E+06 ops/s|
|
||||
|`kmAddLarge`|3.5E+04 ± 3.7E+03 ops/s|
|
||||
|`kmMultiply`|6.7E+07 ± 1.5E+07 ops/s|
|
||||
|`kmMultiplyLarge`|54 ± 4.2 ops/s|
|
||||
|`kmParsing10`|4.5E+06 ± 8.3E+04 ops/s|
|
||||
|`kmParsing16`|4.9E+06 ± 1.1E+05 ops/s|
|
||||
|`kmPower`|10 ± 0.96 ops/s|
|
||||
|`kmSmallAdd`|4.1E+07 ± 5.9E+05 ops/s|
|
||||
|`jvmAdd`|2.9E+07 ± 2.8E+06 ops/s|
|
||||
|`jvmAddLarge`|3.8E+04 ± 6.4E+03 ops/s|
|
||||
|`jvmMultiply`|5.3E+07 ± 6.1E+06 ops/s|
|
||||
|`jvmMultiplyLarge`|2.2E+02 ± 1.9 ops/s|
|
||||
|`jvmParsing10`|3.9E+06 ± 4.7E+05 ops/s|
|
||||
|`jvmParsing16`|3.1E+06 ± 4.6E+05 ops/s|
|
||||
|`jvmPower`|24 ± 1.7 ops/s|
|
||||
|`jvmSmallAdd`|4.7E+07 ± 4.6E+06 ops/s|
|
||||
|`kmAdd`|2.3E+07 ± 5.1E+06 ops/s|
|
||||
|`kmAddLarge`|2.6E+04 ± 3.0E+02 ops/s|
|
||||
|`kmMultiply`|3.7E+07 ± 2.9E+06 ops/s|
|
||||
|`kmMultiplyLarge`|34 ± 2.8 ops/s|
|
||||
|`kmParsing10`|2.5E+06 ± 1.5E+05 ops/s|
|
||||
|`kmParsing16`|4.0E+06 ± 2.4E+05 ops/s|
|
||||
|`kmPower`|6.5 ± 0.69 ops/s|
|
||||
|`kmSmallAdd`|1.6E+07 ± 8.0E+05 ops/s|
|
||||
### [BufferBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`bufferViewReadWrite`|5.8E+06 ± 1.6E+05 ops/s|
|
||||
|`bufferViewReadWriteSpecialized`|5.6E+06 ± 2.6E+05 ops/s|
|
||||
|`complexBufferReadWrite`|6.6E+06 ± 2.7E+05 ops/s|
|
||||
|`doubleArrayReadWrite`|7.5E+06 ± 1.0E+06 ops/s|
|
||||
|`doubleBufferReadWrite`|8.0E+06 ± 6.7E+05 ops/s|
|
||||
|`bufferViewReadWrite`|5.4E+06 ± 3.8E+05 ops/s|
|
||||
|`bufferViewReadWriteSpecialized`|5.0E+06 ± 1.2E+06 ops/s|
|
||||
|`complexBufferReadWrite`|2.2E+06 ± 5.7E+04 ops/s|
|
||||
|`doubleArrayReadWrite`|6.9E+06 ± 1.2E+06 ops/s|
|
||||
|`doubleBufferReadWrite`|6.6E+06 ± 1.1E+06 ops/s|
|
||||
### [DotBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`bufferedDot`|1.3 ± 0.020 ops/s|
|
||||
|`cmDot`|0.47 ± 0.42 ops/s|
|
||||
|`cmDotWithConversion`|0.76 ± 0.13 ops/s|
|
||||
|`ejmlDot`|6.7 ± 0.091 ops/s|
|
||||
|`ejmlDotWithConversion`|6.4 ± 0.82 ops/s|
|
||||
|`multikDot`|40 ± 6.7 ops/s|
|
||||
|`parallelDot`|12 ± 1.8 ops/s|
|
||||
|`tensorDot`|1.2 ± 0.041 ops/s|
|
||||
|`tfDot`|5.9 ± 0.49 ops/s|
|
||||
|`bufferedDot`|1.2 ± 0.20 ops/s|
|
||||
|`cmDot`|0.36 ± 0.14 ops/s|
|
||||
|`cmDotWithConversion`|0.80 ± 0.092 ops/s|
|
||||
|`ejmlDot`|2.9 ± 0.61 ops/s|
|
||||
|`ejmlDotWithConversion`|2.7 ± 0.15 ops/s|
|
||||
|`multikDot`|23 ± 2.4 ops/s|
|
||||
|`ojalgoDot`|11 ± 0.79 ops/s|
|
||||
|`parallelDot`|9.4 ± 1.3 ops/s|
|
||||
|`tensorDot`|1.0 ± 0.15 ops/s|
|
||||
|`tfDot`|3.9 ± 0.90 ops/s|
|
||||
### [ExpressionsInterpretersBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`asmGenericExpression`|29 ± 1.2 ops/s|
|
||||
|`asmPrimitiveExpression`|43 ± 1.3 ops/s|
|
||||
|`asmPrimitiveExpressionArray`|71 ± 0.38 ops/s|
|
||||
|`functionalExpression`|5.6 ± 0.11 ops/s|
|
||||
|`justCalculate`|69 ± 9.0 ops/s|
|
||||
|`mstExpression`|7.1 ± 0.020 ops/s|
|
||||
|`rawExpression`|41 ± 1.5 ops/s|
|
||||
|`asmGenericExpression`|15 ± 1.8 ops/s|
|
||||
|`asmPrimitiveExpression`|27 ± 0.98 ops/s|
|
||||
|`asmPrimitiveExpressionArray`|78 ± 14 ops/s|
|
||||
|`functionalExpression`|4.4 ± 0.25 ops/s|
|
||||
|`justCalculate`|79 ± 5.4 ops/s|
|
||||
|`mstExpression`|4.2 ± 0.93 ops/s|
|
||||
|`rawExpression`|25 ± 5.0 ops/s|
|
||||
### [IntegrationBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/IntegrationBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`complexIntegration`|3.6E+03 ± 1.9E+02 ops/s|
|
||||
|`doubleIntegration`|3.7E+03 ± 12 ops/s|
|
||||
### [JafamaBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/JafamaBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`core`|38 ± 0.64 ops/s|
|
||||
|`jafama`|52 ± 0.36 ops/s|
|
||||
|`strictJafama`|52 ± 4.0 ops/s|
|
||||
|`complexIntegration`|2.2E+03 ± 3.0E+02 ops/s|
|
||||
|`doubleIntegration`|2.3E+03 ± 6.4E+02 ops/s|
|
||||
### [MatrixInverseBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`cmLUPInversion`|2.2E+03 ± 76 ops/s|
|
||||
|`ejmlInverse`|1.3E+03 ± 5.7 ops/s|
|
||||
|`kmathLupInversion`|9.5E+02 ± 1.8E+02 ops/s|
|
||||
|`kmathParallelLupInversion`|9.1E+02 ± 1.4E+02 ops/s|
|
||||
|`cmLUPInversion`|2.0E+03 ± 1.1E+02 ops/s|
|
||||
|`ejmlInverse`|1.2E+03 ± 29 ops/s|
|
||||
|`kmathLupInversion`|3.9E+02 ± 92 ops/s|
|
||||
|`kmathParallelLupInversion`|55 ± 5.0 ops/s|
|
||||
|`ojalgoInverse`|1.7E+03 ± 35 ops/s|
|
||||
### [MinStatisticBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MinStatisticBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`kotlinArrayMin`|1.6E+03 ± 3.0E+02 ops/s|
|
||||
|`minBlocking`|1.2E+03 ± 1.2E+02 ops/s|
|
||||
### [NDFieldBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`boxingFieldAdd`|7.7 ± 0.79 ops/s|
|
||||
|`multikAdd`|6.5 ± 0.33 ops/s|
|
||||
|`multikInPlaceAdd`|64 ± 0.79 ops/s|
|
||||
|`specializedFieldAdd`|8.0 ± 0.090 ops/s|
|
||||
|`tensorAdd`|9.2 ± 0.053 ops/s|
|
||||
|`tensorInPlaceAdd`|17 ± 10 ops/s|
|
||||
|`viktorAdd`|7.6 ± 1.2 ops/s|
|
||||
|`boxingFieldAdd`|1.9 ± 0.089 ops/s|
|
||||
|`multikAdd`|6.8 ± 1.0 ops/s|
|
||||
|`multikInPlaceAdd`|32 ± 4.7 ops/s|
|
||||
|`specializedFieldAdd`|6.7 ± 0.98 ops/s|
|
||||
|`tensorAdd`|7.9 ± 1.1 ops/s|
|
||||
|`tensorInPlaceAdd`|11 ± 3.4 ops/s|
|
||||
|`viktorAdd`|6.4 ± 0.41 ops/s|
|
||||
### [ViktorBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`doubleFieldAddition`|7.7 ± 0.34 ops/s|
|
||||
|`rawViktor`|5.9 ± 1.1 ops/s|
|
||||
|`viktorFieldAddition`|7.3 ± 1.1 ops/s|
|
||||
|`doubleFieldAddition`|7.3 ± 1.1 ops/s|
|
||||
|`rawViktor`|6.0 ± 0.88 ops/s|
|
||||
|`viktorFieldAddition`|6.7 ± 0.47 ops/s|
|
||||
### [ViktorLogBenchmark](src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt)
|
||||
|
||||
| Benchmark | Score |
|
||||
|:---------:|:-----:|
|
||||
|`rawViktorLog`|1.4 ± 0.076 ops/s|
|
||||
|`realFieldLog`|1.3 ± 0.069 ops/s|
|
||||
|`viktorFieldLog`|1.3 ± 0.032 ops/s|
|
||||
|`rawViktorLog`|1.3 ± 0.40 ops/s|
|
||||
|`realFieldLog`|1.2 ± 0.34 ops/s|
|
||||
|`viktorFieldLog`|1.3 ± 0.0073 ops/s|
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,38 +1,76 @@
|
||||
|
||||
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import kotlinx.benchmark.gradle.BenchmarksExtension
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.util.*
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
id("space.kscience.gradle.mpp")
|
||||
alias(spclibs.plugins.kotlin.plugin.allopen)
|
||||
alias(spclibs.plugins.kotlinx.benchmark)
|
||||
}
|
||||
|
||||
allOpen.annotation("org.openjdk.jmh.annotations.State")
|
||||
sourceSets.register("benchmarks")
|
||||
//sourceSets.register("benchmarks")
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
kscience {
|
||||
maturity = space.kscience.gradle.Maturity.EXPERIMENTAL
|
||||
|
||||
jvm()
|
||||
|
||||
js {
|
||||
nodejs()
|
||||
}
|
||||
|
||||
commonMain{
|
||||
implementation(project(":kmath-ast"))
|
||||
implementation(project(":kmath-core"))
|
||||
implementation(project(":kmath-coroutines"))
|
||||
implementation(project(":kmath-complex"))
|
||||
implementation(project(":kmath-stat"))
|
||||
implementation(project(":kmath-dimensions"))
|
||||
implementation(project(":kmath-for-real"))
|
||||
implementation(project(":kmath-tensors"))
|
||||
implementation(libs.multik.default)
|
||||
implementation(spclibs.kotlinx.benchmark.runtime)
|
||||
}
|
||||
|
||||
jvmMain {
|
||||
implementation(projects.kmathCommons)
|
||||
implementation(projects.kmathEjml)
|
||||
implementation(projects.kmathKotlingrad)
|
||||
implementation(projects.kmathViktor)
|
||||
implementation(projects.kmathOjalgo)
|
||||
implementation(projects.kmath.kmathTensorflow)
|
||||
implementation(projects.kmathMultik)
|
||||
implementation(libs.tensorflow.core.platform)
|
||||
// implementation(projects.kmathNd4j)
|
||||
|
||||
// implementation(libs.nd4j.native.platform)
|
||||
// uncomment if your system supports AVX2
|
||||
// val os = System.getProperty("os.name")
|
||||
//
|
||||
// if (System.getProperty("os.arch") in arrayOf("x86_64", "amd64")) when {
|
||||
// os.startsWith("Windows") -> implementation("org.nd4j:nd4j-native:1.0.0-beta7:windows-x86_64-avx2")
|
||||
// os == "Linux" -> implementation("org.nd4j:nd4j-native:1.0.0-beta7:linux-x86_64-avx2")
|
||||
// os == "Mac OS X" -> implementation("org.nd4j:nd4j-native:1.0.0-beta7:macosx-x86_64-avx2")
|
||||
// } else
|
||||
// implementation("org.nd4j:nd4j-native-platform:1.0.0-beta7")
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
optIn.addAll(
|
||||
"space.kscience.kmath.UnstableKMathAPI"
|
||||
)
|
||||
}
|
||||
|
||||
jvm()
|
||||
|
||||
js(IR) {
|
||||
nodejs()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
all {
|
||||
languageSettings {
|
||||
@@ -42,45 +80,6 @@ kotlin {
|
||||
optIn("space.kscience.kmath.UnstableKMathAPI")
|
||||
}
|
||||
}
|
||||
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(project(":kmath-ast"))
|
||||
implementation(project(":kmath-core"))
|
||||
implementation(project(":kmath-coroutines"))
|
||||
implementation(project(":kmath-complex"))
|
||||
implementation(project(":kmath-stat"))
|
||||
implementation(project(":kmath-dimensions"))
|
||||
implementation(project(":kmath-for-real"))
|
||||
implementation(project(":kmath-tensors"))
|
||||
implementation(project(":kmath-multik"))
|
||||
implementation(libs.multik.default)
|
||||
implementation(spclibs.kotlinx.benchmark.runtime)
|
||||
}
|
||||
}
|
||||
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
implementation(project(":kmath-commons"))
|
||||
implementation(project(":kmath-ejml"))
|
||||
implementation(project(":kmath-nd4j"))
|
||||
implementation(project(":kmath-kotlingrad"))
|
||||
implementation(project(":kmath-viktor"))
|
||||
// implementation(project(":kmath-jafama"))
|
||||
implementation(projects.kmath.kmathTensorflow)
|
||||
implementation("org.tensorflow:tensorflow-core-platform:0.4.0")
|
||||
implementation("org.nd4j:nd4j-native:1.0.0-M1")
|
||||
// uncomment if your system supports AVX2
|
||||
// val os = System.getProperty("os.name")
|
||||
//
|
||||
// if (System.getProperty("os.arch") in arrayOf("x86_64", "amd64")) when {
|
||||
// os.startsWith("Windows") -> implementation("org.nd4j:nd4j-native:1.0.0-beta7:windows-x86_64-avx2")
|
||||
// os == "Linux" -> implementation("org.nd4j:nd4j-native:1.0.0-beta7:linux-x86_64-avx2")
|
||||
// os == "Mac OS X" -> implementation("org.nd4j:nd4j-native:1.0.0-beta7:macosx-x86_64-avx2")
|
||||
// } else
|
||||
// implementation("org.nd4j:nd4j-native-platform:1.0.0-beta7")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +103,11 @@ benchmark {
|
||||
include("BufferBenchmark")
|
||||
}
|
||||
|
||||
configurations.register("minStatistic") {
|
||||
commonConfiguration()
|
||||
include("MinStatisticBenchmark")
|
||||
}
|
||||
|
||||
configurations.register("nd") {
|
||||
commonConfiguration()
|
||||
include("NDFieldBenchmark")
|
||||
@@ -211,7 +215,6 @@ private data class JmhReport(
|
||||
}
|
||||
|
||||
readme {
|
||||
maturity = space.kscience.gradle.Maturity.EXPERIMENTAL
|
||||
|
||||
val jsonMapper = jacksonObjectMapper()
|
||||
|
||||
@@ -228,7 +231,7 @@ readme {
|
||||
|
||||
property(propertyName) {
|
||||
val resDirectory = launches.listFiles()?.maxByOrNull {
|
||||
LocalDateTime.parse(it.name).atZone(ZoneId.systemDefault()).toInstant()
|
||||
it.nameWithoutExtension
|
||||
}
|
||||
|
||||
if (resDirectory == null || !(resDirectory.resolve("jvm.json")).exists()) {
|
||||
@@ -261,7 +264,7 @@ readme {
|
||||
)
|
||||
|
||||
reports.groupBy { it.benchmark.substringBeforeLast(".") }.forEach { (cl, compare) ->
|
||||
appendLine("### [${cl.substringAfterLast(".")}](src/jvmMain/kotlin/${cl.replace(".","/")}.kt)")
|
||||
appendLine("### [${cl.substringAfterLast(".")}](src/jvmMain/kotlin/${cl.replace(".", "/")}.kt)")
|
||||
appendLine()
|
||||
appendLine("| Benchmark | Score |")
|
||||
appendLine("|:---------:|:-----:|")
|
||||
@@ -277,4 +280,6 @@ readme {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin.explicitApi = org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Disabled
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# Module KMath-Benchmarks
|
||||
|
||||
# BenchmarksResult
|
||||
|
||||
${benchmarkMain}
|
||||
|
||||
@@ -35,13 +35,13 @@ class ExpressionsInterpretersBenchmark {
|
||||
fun mstExpression(blackhole: Blackhole) = invokeAndSum(mst, blackhole)
|
||||
|
||||
/**
|
||||
* Benchmark case for [Expression] created with [compileToExpression].
|
||||
* Benchmark case for [Expression] created with [space.kscience.kmath.estree.compileToExpression].
|
||||
*/
|
||||
@Benchmark
|
||||
fun wasmExpression(blackhole: Blackhole) = invokeAndSum(wasm, blackhole)
|
||||
|
||||
/**
|
||||
* Benchmark case for [Expression] created with [compileToExpression].
|
||||
* Benchmark case for [Expression] created with [space.kscience.kmath.estree.compileToExpression].
|
||||
*/
|
||||
@Benchmark
|
||||
fun estreeExpression(blackhole: Blackhole) = invokeAndSum(estree, blackhole)
|
||||
|
||||
@@ -14,6 +14,8 @@ import space.kscience.kmath.ejml.EjmlLinearSpaceDDRM
|
||||
import space.kscience.kmath.linear.Float64ParallelLinearSpace
|
||||
import space.kscience.kmath.linear.invoke
|
||||
import space.kscience.kmath.linear.linearSpace
|
||||
import space.kscience.kmath.ojalgo.Ojalgo
|
||||
import space.kscience.kmath.ojalgo.linearSpace
|
||||
import space.kscience.kmath.operations.Float64Field
|
||||
import space.kscience.kmath.tensorflow.produceWithTF
|
||||
import space.kscience.kmath.tensors.core.tensorAlgebra
|
||||
@@ -56,13 +58,13 @@ internal class DotBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun cmDot(blackhole: Blackhole) = CMLinearSpace {
|
||||
blackhole.consume(cmMatrix1 dot cmMatrix2)
|
||||
fun cmDot(blackhole: Blackhole): Unit = CMLinearSpace {
|
||||
blackhole.consume(cmMatrix1.asMatrix() dot cmMatrix2.asMatrix())
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun ejmlDot(blackhole: Blackhole) = EjmlLinearSpaceDDRM {
|
||||
blackhole.consume(ejmlMatrix1 dot ejmlMatrix2)
|
||||
fun ejmlDot(blackhole: Blackhole): Unit = EjmlLinearSpaceDDRM {
|
||||
blackhole.consume(ejmlMatrix1.asMatrix() dot ejmlMatrix2.asMatrix())
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@@ -70,6 +72,11 @@ internal class DotBenchmark {
|
||||
blackhole.consume(matrix1 dot matrix2)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun ojalgoDot(blackhole: Blackhole) = Ojalgo.R064.linearSpace {
|
||||
blackhole.consume(matrix1 dot matrix2)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun multikDot(blackhole: Blackhole) = with(multikAlgebra) {
|
||||
blackhole.consume(matrix1 dot matrix2)
|
||||
|
||||
@@ -12,10 +12,9 @@ import kotlinx.benchmark.State
|
||||
import space.kscience.kmath.commons.linear.CMLinearSpace
|
||||
import space.kscience.kmath.commons.linear.lupSolver
|
||||
import space.kscience.kmath.ejml.EjmlLinearSpaceDDRM
|
||||
import space.kscience.kmath.linear.invoke
|
||||
import space.kscience.kmath.linear.linearSpace
|
||||
import space.kscience.kmath.linear.lupSolver
|
||||
import space.kscience.kmath.linear.parallel
|
||||
import space.kscience.kmath.linear.*
|
||||
import space.kscience.kmath.ojalgo.Ojalgo
|
||||
import space.kscience.kmath.ojalgo.linearSpace
|
||||
import space.kscience.kmath.operations.algebra
|
||||
import kotlin.random.Random
|
||||
|
||||
@@ -48,10 +47,14 @@ internal class MatrixInverseBenchmark {
|
||||
blackhole.consume(lupSolver().inverse(matrix))
|
||||
}
|
||||
|
||||
|
||||
@Benchmark
|
||||
fun ejmlInverse(blackhole: Blackhole) = EjmlLinearSpaceDDRM {
|
||||
blackhole.consume(matrix.toEjml().inverted())
|
||||
blackhole.consume(matrix.inverted())
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun ojalgoInverse(blackhole: Blackhole) = Ojalgo.R064.linearSpace {
|
||||
blackhole.consume(matrix.getOrComputeAttribute(Inverted))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2018-2025 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.kmath.benchmarks
|
||||
|
||||
import kotlinx.benchmark.Benchmark
|
||||
import kotlinx.benchmark.Blackhole
|
||||
import kotlinx.benchmark.Scope
|
||||
import kotlinx.benchmark.State
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import space.kscience.kmath.operations.Float64Field
|
||||
import space.kscience.kmath.stat.min
|
||||
import space.kscience.kmath.structures.*
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
internal class MinStatisticBenchmark {
|
||||
|
||||
@Benchmark
|
||||
fun kotlinArrayMin(blackhole: Blackhole) {
|
||||
val array = DoubleArray(size) { it.toDouble() }
|
||||
var res = 0.0
|
||||
(0 until size).forEach {
|
||||
res += array.min()
|
||||
}
|
||||
blackhole.consume(res)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun minBlocking(blackhole: Blackhole) {
|
||||
val buffer = Float64Buffer(size) { it.toDouble() }
|
||||
var res = 0.0
|
||||
(0 until size).forEach {
|
||||
res += Float64Field.min.evaluateBlocking(buffer)
|
||||
}
|
||||
blackhole.consume(res)
|
||||
}
|
||||
|
||||
|
||||
private companion object {
|
||||
private const val size = 1000
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import org.jetbrains.kotlinx.multik.ndarray.data.DN
|
||||
import org.jetbrains.kotlinx.multik.ndarray.data.DataType
|
||||
import space.kscience.kmath.UnsafeKMathAPI
|
||||
import space.kscience.kmath.nd.*
|
||||
import space.kscience.kmath.nd4j.nd4j
|
||||
import space.kscience.kmath.operations.Float64Field
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.kmath.tensors.core.DoubleTensor
|
||||
@@ -32,7 +31,6 @@ internal class NDFieldBenchmark {
|
||||
private val shape = ShapeND(dim, dim)
|
||||
private val specializedField = Float64Field.ndAlgebra
|
||||
private val genericField = BufferedFieldOpsND(Float64Field)
|
||||
private val nd4jField = Float64Field.nd4j
|
||||
private val viktorField = Float64Field.viktorAlgebra
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import kotlinx.benchmark.Benchmark
|
||||
import kotlinx.benchmark.Blackhole
|
||||
import kotlinx.benchmark.Scope
|
||||
import kotlinx.benchmark.State
|
||||
import space.kscience.kmath.linear.MatrixBuilder
|
||||
import space.kscience.kmath.linear.linearSpace
|
||||
import space.kscience.kmath.linear.matrix
|
||||
import space.kscience.kmath.linear.symmetric
|
||||
import space.kscience.kmath.operations.Float64Field
|
||||
import space.kscience.kmath.tensors.core.symEigJacobi
|
||||
@@ -24,7 +24,7 @@ internal class TensorAlgebraBenchmark {
|
||||
private val random = Random(12224)
|
||||
private const val dim = 30
|
||||
|
||||
private val matrix = Float64Field.linearSpace.matrix(dim, dim).symmetric { _, _ -> random.nextDouble() }
|
||||
private val matrix = Float64Field.linearSpace.MatrixBuilder(dim, dim).symmetric { _, _ -> random.nextDouble() }
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation
|
||||
import space.kscience.gradle.useApache2Licence
|
||||
import space.kscience.gradle.useSPCTeam
|
||||
|
||||
@@ -6,8 +7,6 @@ plugins {
|
||||
alias(spclibs.plugins.kotlinx.kover)
|
||||
}
|
||||
|
||||
val attributesVersion by extra("0.2.0")
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
maven("https://repo.kotlin.link")
|
||||
@@ -16,36 +15,49 @@ allprojects {
|
||||
}
|
||||
|
||||
group = "space.kscience"
|
||||
version = "0.4.1-dev"
|
||||
version = "0.5.0"
|
||||
}
|
||||
|
||||
dependencies{
|
||||
dependencies {
|
||||
subprojects.forEach {
|
||||
dokka(it)
|
||||
}
|
||||
}
|
||||
|
||||
dokka {
|
||||
dokkaSourceSets.configureEach {
|
||||
val readmeFile = projectDir.resolve("README.md")
|
||||
if (readmeFile.exists()) includes.from(readmeFile)
|
||||
}
|
||||
}
|
||||
|
||||
subprojects {
|
||||
if (name.startsWith("kmath")) apply<MavenPublishPlugin>()
|
||||
|
||||
plugins.withId("org.jetbrains.dokka") {
|
||||
tasks.withType<org.jetbrains.dokka.gradle.DokkaTaskPartial> {
|
||||
dependsOn(tasks["assemble"])
|
||||
|
||||
dokkaSourceSets.all {
|
||||
val readmeFile = this@subprojects.projectDir.resolve("README.md")
|
||||
dokka {
|
||||
dokkaSourceSets.configureEach {
|
||||
val readmeFile = projectDir.resolve("README.md")
|
||||
if (readmeFile.exists()) includes.from(readmeFile)
|
||||
val kotlinDirPath = "src/$name/kotlin"
|
||||
val kotlinDir = file(kotlinDirPath)
|
||||
|
||||
if (kotlinDir.exists()) sourceLink {
|
||||
localDirectory.set(kotlinDir)
|
||||
|
||||
remoteUrl.set(
|
||||
uri("https://github.com/SciProgCentre/kmath/tree/master/${this@subprojects.name}/$kotlinDirPath").toURL()
|
||||
remoteUrl(
|
||||
"https://github.com/SciProgCentre/kmath/tree/master/${name}/$kotlinDirPath"
|
||||
)
|
||||
}
|
||||
|
||||
fun externalDocumentationLink(url: String, packageListUrl: String? = null) {
|
||||
externalDocumentationLinks.register(url) {
|
||||
url(url)
|
||||
packageListUrl?.let {
|
||||
packageListUrl(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
externalDocumentationLink("https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/")
|
||||
externalDocumentationLink("https://deeplearning4j.org/api/latest/")
|
||||
externalDocumentationLink("https://axelclk.bitbucket.io/symja/javadoc/")
|
||||
@@ -56,23 +68,35 @@ subprojects {
|
||||
)
|
||||
|
||||
externalDocumentationLink(
|
||||
"https://breandan.net/kotlingrad/kotlingrad/",
|
||||
"https://breandan.net/kotlingrad/kotlingrad/kotlingrad/package-list",
|
||||
"https://breandan.net/kotlingrad/kotlingrad",
|
||||
"https://breandan.net/kotlingrad/package-list",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
kscienceProject {
|
||||
readme.readmeTemplate = file("docs/templates/README-TEMPLATE.md")
|
||||
|
||||
|
||||
pom("https://github.com/SciProgCentre/kmath") {
|
||||
useApache2Licence()
|
||||
useSPCTeam()
|
||||
}
|
||||
publishTo("spc", "https://maven.sciprog.center/kscience")
|
||||
publishToCentral()
|
||||
|
||||
@OptIn(ExperimentalAbiValidation::class)
|
||||
abiValidation {
|
||||
filters {
|
||||
excluded {
|
||||
annotatedWith.add("space.kscience.kmath.UnstableKMathAPI")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readme.readmeTemplate = file("docs/templates/README-TEMPLATE.md")
|
||||
|
||||
ksciencePublish {
|
||||
pom("https://github.com/SciProgCentre/kmath") {
|
||||
useApache2Licence()
|
||||
useSPCTeam()
|
||||
}
|
||||
repository("spc", "https://maven.sciprog.center/kscience")
|
||||
sonatype("https://oss.sonatype.org")
|
||||
}
|
||||
|
||||
apiValidation.nonPublicMarkers.add("space.kscience.kmath.UnstableKMathAPI")
|
||||
|
||||
@@ -11,4 +11,6 @@
|
||||
|
||||
* [Expressions](expressions.md)
|
||||
|
||||
* [Statistics](statistics.md): statistical functions on data [Buffers](buffers.md)
|
||||
|
||||
* Commons math integration
|
||||
|
||||
34
docs/statistics.md
Normal file
34
docs/statistics.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Statistics
|
||||
|
||||
Mathematically speaking, a statistic is a measurable numerical function of sample data.
|
||||
In KMath, a statistic is a function that operates on a [Buffer](buffers.md) and is implemented as the `evaluate` method
|
||||
of the `Statistic` interface.
|
||||
There are two subinterfaces of the `Statistic` interface:
|
||||
|
||||
* `BlockingStatistic` – A statistic that is computed in a synchronous blocking mode
|
||||
* `ComposableStatistic` – A statistic tha could be computed separately on different blocks of data and then composed
|
||||
|
||||
|
||||
## Common statistics and Implementation Status
|
||||
|
||||
| Category | Statistic | Description | Implementation Status |
|
||||
|------------------|-------------------|------------------------------------|--------------------------------|
|
||||
| **Basic** | Min | Minimum value | ✅ `ComposableStatistic` |
|
||||
| | Max | Maximum value | ✅ `ComposableStatistic` |
|
||||
| | Mean | Arithmetic mean | ✅ `ComposableStatistic` |
|
||||
| | Sum | Sum of all values | 🚧 Not yet implemented |
|
||||
| | Product | Product of all values | 🚧 Not yet implemented |
|
||||
| **Distribution** | Median | Median (50th percentile) | ✅ `BlockingStatistic` |
|
||||
| | Quantile | Quantile and percentile | ✅ `BlockingStatistic` |
|
||||
| | Variance | Unbiased sample variance | ✅ `BlockingStatistic` |
|
||||
| | StandardDeviation | Population standard deviation (σ) | ✅ `BlockingStatistic` |
|
||||
| | Skewness | Measure of distribution asymmetry | 🚧 *(Requires `ThirdMoment`)* |
|
||||
| | Kurtosis | Measure of distribution tailedness | 🚧 *(Requires `FourthMoment`)* |
|
||||
| **Advanced** | GeometricMean | Nth root of product of values | ✅ `ComposableStatistic` |
|
||||
| | SumOfLogs | Sum of natural logarithms | Does not planned |
|
||||
| | SumOfSquares | Sum of squared values | 🚧 *(Blocks `Variance`)* |
|
||||
| **Moments** | FirstMoment | Mean (same as `Mean`) | ✅ *(Alias for `Mean`)* |
|
||||
| | SecondMoment | Variance (same as `Variance`) | ✅ *(Alias for `Variance`)* |
|
||||
| | ThirdMoment | Used in skewness calculation | 🚧 Not yet implemented |
|
||||
| | FourthMoment | Used in kurtosis calculation | 🚧 Not yet implemented |
|
||||
| **Risk Metrics** | SemiVariance | Downside variance | 🚧 *(Depends on `Variance`)* |
|
||||
53
docs/templates/README-TEMPLATE.md
vendored
53
docs/templates/README-TEMPLATE.md
vendored
@@ -2,14 +2,10 @@
|
||||
[](https://zenodo.org/badge/latestdoi/129486382)
|
||||

|
||||
[](https://search.maven.org/search?q=g:%22space.kscience%22)
|
||||
[](https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven/space/kscience/)
|
||||
|
||||
# KMath
|
||||
|
||||
Could be pronounced as `key-math`. The **K**otlin **Math**ematics library was initially intended as a Kotlin-based
|
||||
analog to Python's NumPy library. Later we found that kotlin is much more flexible language and allows superior
|
||||
architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like
|
||||
experience could be achieved with [kmath-for-real](/kmath-for-real) extension module.
|
||||
Could be pronounced as `key-math`. The **K**otlin **Math**ematics library was initially intended as a Kotlin-based analog to Python's NumPy library. Later we found that kotlin is a much more flexible language and allows superior architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could be achieved with [kmath-for-real](kmath-for-real) extension module.
|
||||
|
||||
[Documentation site](https://SciProgCentre.github.io/kmath/)
|
||||
|
||||
@@ -35,15 +31,17 @@ experience could be achieved with [kmath-for-real](/kmath-for-real) extension mo
|
||||
* Be like NumPy. It was the idea at the beginning, but we decided that we can do better in API.
|
||||
* Provide the best performance out of the box. We have specialized libraries for that. Need only API wrappers for them.
|
||||
* Cover all cases as immediately and in one bundle. We will modularize everything and add new features gradually.
|
||||
* Provide specialized behavior in the core. API is made generic on purpose, so one needs to specialize for types, like
|
||||
for `Double` in the core. For that we will have specialization modules like `kmath-for-real`, which will give better
|
||||
experience for those, who want to work with specific types.
|
||||
* Provide specialized behavior in the core. API is made generic on purpose, so one needs to specialize for types, like for `Float64` in the core. For that we will have specialization modules like [kmath-for-real](kmath-for-real), which will give a better experience for those who want to work with specific types.
|
||||
|
||||
## Contributing
|
||||
|
||||
The project requires a lot of additional work. The most important thing we need is feedback about what features are required the most. Feel free to create feature requests. We are also welcome to code contributions, especially in issues marked with [good first issue](https://github.com/SciProgCentre/kmath/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label.
|
||||
|
||||
Project roadmap will be available at [GitHub Projects](https://github.com/orgs/SciProgCentre/projects/3).
|
||||
|
||||
## Features and stability
|
||||
|
||||
KMath is a modular library. Different modules provide different features with different API stability guarantees. All
|
||||
core modules are released with the same version, but with different API change policy. The features are described in
|
||||
module definitions below. The module stability could have the following levels:
|
||||
KMath is a modular library. Different modules provide different features with different API stability guarantees. All core modules are released with the same version, but with different API change policy. The features are described in module definitions below. The module stability could have the following levels:
|
||||
|
||||
* **PROTOTYPE**. On this level there are no compatibility guarantees. All methods and classes form those modules could
|
||||
break any moment. You can still use it, but be sure to fix the specific version.
|
||||
@@ -51,7 +49,7 @@ module definitions below. The module stability could have the following levels:
|
||||
with `@UnstableKMathAPI` or other stability warning annotations.
|
||||
* **DEVELOPMENT**. API breaking generally follows semantic versioning ideology. There could be changes in minor
|
||||
versions, but not in patch versions. API is protected
|
||||
with [binary-compatibility-validator](https://github.com/Kotlin/binary-compatibility-validator) tool.
|
||||
with [binary-compatibility-validator](https://kotlinlang.org/docs/gradle-binary-compatibility-validation.html) tool.
|
||||
* **STABLE**. The API stabilized. Breaking changes are allowed only in major releases.
|
||||
|
||||
## Modules
|
||||
@@ -60,34 +58,21 @@ ${modules}
|
||||
|
||||
## Multi-platform support
|
||||
|
||||
KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the
|
||||
[common source sets](/kmath-core/src/commonMain) and implemented there wherever it is possible. In some cases, features
|
||||
are delegated to platform-specific implementations even if they could be provided in the common module for performance
|
||||
reasons. Currently, Kotlin/JVM is the primary platform, however, Kotlin/Native and Kotlin/JS contributions and
|
||||
feedback are also welcome.
|
||||
KMath is developed as a multi-platform library, which means that most of the interfaces are declared in common source sets like [common source sets](kmath-core/src/commonMain) and implemented there wherever it is possible. In some cases, features are delegated to platform-specific implementations even if they could be provided in the common module for performance reasons. Currently, Kotlin/JVM is the primary platform, however, Kotlin/Native, Kotlin/JS and Kotlin/Wasm contributions and feedback are also welcome.
|
||||
|
||||
## Performance
|
||||
|
||||
Calculation of performance is one of the major goals of KMath in the future, but in some cases it is impossible to
|
||||
achieve both
|
||||
performance and flexibility.
|
||||
Performance of mathematical operations is hard to achieve without a lot of effort. KMath focus is to provide a reasonable performance for common cases, out of the box and good interoperability with optimized libraries for edge cases. For example, one could prototype an algorithm using KMath core implementations and then use Multik or Ojalgo for performance-critical parts just by adding a dependency and algebra context switch.
|
||||
|
||||
We expect to focus on creating a convenient universal API first and then work on increasing performance for specific
|
||||
cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized
|
||||
native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be
|
||||
better than SciPy.
|
||||
As for core implementations, we expect to focus on creating a convenient universal API first and then work on increasing performance for specific cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be better than SciPy.
|
||||
|
||||
## Requirements
|
||||
|
||||
KMath currently relies on JDK 11 for compilation and execution of Kotlin-JVM part. We recommend using GraalVM-CE or
|
||||
Oracle GraalVM for execution to get better performance.
|
||||
KMath currently relies on JDK 21 for compilation and execution of Kotlin-JVM part.
|
||||
|
||||
### Repositories
|
||||
|
||||
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:
|
||||
Intermediate releases are published to [Kotlin.Link](https://repo.kotlin.link) repository.
|
||||
|
||||
```kotlin
|
||||
repositories {
|
||||
@@ -99,11 +84,3 @@ dependencies {
|
||||
// api("${group}:kmath-core-jvm:$version") for jvm-specific version
|
||||
}
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
The project requires a lot of additional work. The most important thing we need is feedback about what features are
|
||||
required the most. Feel free to create feature requests. We are also welcome to code contributions, especially in issues
|
||||
marked
|
||||
with [good first issue](hhttps://github.com/SciProgCentre/kmath/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
|
||||
label.
|
||||
@@ -23,7 +23,6 @@ dependencies {
|
||||
implementation(project(":kmath-viktor"))
|
||||
implementation(project(":kmath-dimensions"))
|
||||
implementation(project(":kmath-ejml"))
|
||||
implementation(project(":kmath-nd4j"))
|
||||
implementation(project(":kmath-tensors"))
|
||||
implementation(project(":kmath-symja"))
|
||||
implementation(project(":kmath-for-real"))
|
||||
@@ -32,9 +31,10 @@ dependencies {
|
||||
implementation(libs.multik.default)
|
||||
|
||||
//datetime
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
|
||||
implementation(spclibs.kotlinx.datetime)
|
||||
|
||||
implementation("org.nd4j:nd4j-native:1.0.0-beta7")
|
||||
// implementation(project(":kmath-nd4j"))
|
||||
// implementation("org.nd4j:nd4j-native:1.0.0-beta7")
|
||||
|
||||
// uncomment if your system supports AVX2
|
||||
// val os = System.getProperty("os.name")
|
||||
@@ -44,7 +44,7 @@ dependencies {
|
||||
// os == "Linux" -> implementation("org.nd4j:nd4j-native:1.0.0-beta7:linux-x86_64-avx2")
|
||||
// os == "Mac OS X" -> implementation("org.nd4j:nd4j-native:1.0.0-beta7:macosx-x86_64-avx2")
|
||||
// } else
|
||||
implementation("org.nd4j:nd4j-native-platform:1.0.0-beta7")
|
||||
// implementation("org.nd4j:nd4j-native-platform:1.0.0-beta7")
|
||||
|
||||
implementation("org.slf4j:slf4j-simple:1.7.32")
|
||||
// plotting
|
||||
@@ -52,7 +52,7 @@ dependencies {
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
jvmToolchain(21)
|
||||
sourceSets.all {
|
||||
languageSettings {
|
||||
optIn("kotlin.contracts.ExperimentalContracts")
|
||||
@@ -64,10 +64,6 @@ kotlin {
|
||||
|
||||
tasks.withType<KotlinJvmCompile> {
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll("-Xjvm-default=all", "-Xopt-in=kotlin.RequiresOptIn", "-Xlambdas=indy")
|
||||
freeCompilerArgs.addAll("-Xopt-in=kotlin.RequiresOptIn")
|
||||
}
|
||||
}
|
||||
|
||||
readme {
|
||||
maturity = space.kscience.gradle.Maturity.EXPERIMENTAL
|
||||
}
|
||||
}
|
||||
@@ -9,16 +9,21 @@ import kotlinx.html.br
|
||||
import kotlinx.html.h3
|
||||
import space.kscience.kmath.commons.optimization.CMOptimizer
|
||||
import space.kscience.kmath.distributions.NormalDistribution
|
||||
import space.kscience.kmath.expressions.DifferentiableExpression
|
||||
import space.kscience.kmath.expressions.autodiff
|
||||
import space.kscience.kmath.expressions.symbol
|
||||
import space.kscience.kmath.operations.asIterable
|
||||
import space.kscience.kmath.operations.toList
|
||||
import space.kscience.kmath.optimization.*
|
||||
import space.kscience.kmath.optimization.minimize
|
||||
import space.kscience.kmath.optimization.optimizeWith
|
||||
import space.kscience.kmath.optimization.result
|
||||
import space.kscience.kmath.optimization.resultValue
|
||||
import space.kscience.kmath.random.RandomGenerator
|
||||
import space.kscience.kmath.real.DoubleVector
|
||||
import space.kscience.kmath.real.map
|
||||
import space.kscience.kmath.real.step
|
||||
import space.kscience.kmath.stat.chiSquaredExpression
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.plotly.*
|
||||
import space.kscience.plotly.models.ScatterMode
|
||||
import space.kscience.plotly.models.TraceValues
|
||||
@@ -64,7 +69,7 @@ suspend fun main() {
|
||||
val yErr = y.map { sqrt(it) }//RealVector.same(x.size, sigma)
|
||||
|
||||
// compute differentiable chi^2 sum for given model ax^2 + bx + c
|
||||
val chi2 = Double.autodiff.chiSquaredExpression(x, y, yErr) { arg ->
|
||||
val chi2: DifferentiableExpression<Float64> = Double.autodiff.chiSquaredExpression(x, y, yErr) { arg ->
|
||||
//bind variables to autodiff context
|
||||
val a = bindSymbol(a)
|
||||
val b = bindSymbol(b)
|
||||
@@ -77,9 +82,10 @@ suspend fun main() {
|
||||
val result = chi2.optimizeWith(
|
||||
CMOptimizer,
|
||||
mapOf(a to 1.5, b to 0.9, c to 1.0),
|
||||
) {
|
||||
FunctionOptimizationTarget(OptimizationDirection.MINIMIZE)
|
||||
}
|
||||
attributesBuilder = {
|
||||
minimize()
|
||||
}
|
||||
)
|
||||
|
||||
//display a page with plot and numerical results
|
||||
val page = Plotly.page {
|
||||
|
||||
@@ -7,7 +7,6 @@ package space.kscience.kmath.fit
|
||||
|
||||
import kotlinx.html.br
|
||||
import kotlinx.html.h3
|
||||
import space.kscience.attributes.Attributes
|
||||
import space.kscience.kmath.data.XYErrorColumnarData
|
||||
import space.kscience.kmath.distributions.NormalDistribution
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
@@ -65,7 +64,9 @@ suspend fun main() {
|
||||
QowOptimizer,
|
||||
Double.autodiff,
|
||||
mapOf(a to 0.9, b to 1.2, c to 2.0, e to 1.0, d to 1.0, e to 0.0),
|
||||
attributes = Attributes(OptimizationParameters, listOf(a, b, c, d))
|
||||
attributesBuilder = {
|
||||
freeParameters(a, b, c, d)
|
||||
},
|
||||
) { arg ->
|
||||
//bind variables to autodiff context
|
||||
val a by binding
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package space.kscience.kmath.linear
|
||||
|
||||
import space.kscience.kmath.PerformancePitfall
|
||||
import space.kscience.kmath.commons.linear.CMLinearSpace
|
||||
import space.kscience.kmath.ejml.EjmlLinearSpaceDDRM
|
||||
import space.kscience.kmath.nd.StructureND
|
||||
@@ -12,6 +13,7 @@ import space.kscience.kmath.operations.algebra
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import kotlin.random.Random
|
||||
|
||||
@OptIn(PerformancePitfall::class)
|
||||
fun main() {
|
||||
val dim = 46
|
||||
|
||||
@@ -21,7 +23,7 @@ fun main() {
|
||||
|
||||
listOf(CMLinearSpace, EjmlLinearSpaceDDRM).forEach { algebra ->
|
||||
with(algebra) {
|
||||
//create a simmetric matrix
|
||||
//create a symmetric matrix
|
||||
val matrix = buildMatrix(dim, dim) { row, col ->
|
||||
if (row >= col) u[row, col] else u[col, row]
|
||||
}
|
||||
|
||||
@@ -6,22 +6,21 @@
|
||||
package space.kscience.kmath.operations
|
||||
|
||||
import space.kscience.kmath.commons.linear.CMLinearSpace
|
||||
import space.kscience.kmath.linear.matrix
|
||||
import space.kscience.kmath.linear.MatrixBuilder
|
||||
import space.kscience.kmath.linear.fill
|
||||
import space.kscience.kmath.nd.Float64BufferND
|
||||
import space.kscience.kmath.nd.Structure2D
|
||||
import space.kscience.kmath.nd.mutableStructureND
|
||||
import space.kscience.kmath.nd.ndAlgebra
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.kmath.viktor.viktorAlgebra
|
||||
import kotlin.collections.component1
|
||||
import kotlin.collections.component2
|
||||
|
||||
fun main() {
|
||||
val viktorStructure = Float64Field.viktorAlgebra.mutableStructureND(2, 2) { (i, j) ->
|
||||
if (i == j) 2.0 else 0.0
|
||||
}
|
||||
|
||||
val cmMatrix: Structure2D<Float64> = CMLinearSpace.matrix(2, 2)(0.0, 1.0, 0.0, 3.0)
|
||||
val cmMatrix: Structure2D<Float64> = CMLinearSpace.MatrixBuilder(2, 2).fill(0.0, 1.0, 0.0, 3.0)
|
||||
|
||||
val res: Float64BufferND = Float64Field.ndAlgebra {
|
||||
exp(viktorStructure) + 2.0 * cmMatrix
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
|
||||
package space.kscience.kmath.series
|
||||
|
||||
import kotlinx.datetime.Instant
|
||||
import space.kscience.kmath.operations.algebra
|
||||
import space.kscience.kmath.operations.bufferAlgebra
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.ExperimentalTime
|
||||
import kotlin.time.Instant
|
||||
|
||||
@OptIn(ExperimentalTime::class)
|
||||
fun SeriesAlgebra.Companion.time(zero: Instant, step: Duration) = MonotonicSeriesAlgebra(
|
||||
bufferAlgebra = Double.algebra.bufferAlgebra,
|
||||
offsetToLabel = { zero + step * it },
|
||||
|
||||
@@ -7,9 +7,7 @@ package space.kscience.kmath.structures
|
||||
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import org.nd4j.linalg.factory.Nd4j
|
||||
import space.kscience.kmath.nd.*
|
||||
import space.kscience.kmath.nd4j.nd4j
|
||||
import space.kscience.kmath.operations.Float64Field
|
||||
import space.kscience.kmath.operations.invoke
|
||||
import space.kscience.kmath.viktor.ViktorFieldND
|
||||
@@ -26,7 +24,6 @@ internal inline fun measureAndPrint(title: String, block: () -> Unit) {
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun main() {
|
||||
// initializing Nd4j
|
||||
Nd4j.zeros(0)
|
||||
val dim = 1000
|
||||
val n = 1000
|
||||
val shape = ShapeND(dim, dim)
|
||||
@@ -36,8 +33,6 @@ fun main() {
|
||||
val doubleField = Float64Field.ndAlgebra
|
||||
//A generic field. It should be used for objects, not primitives.
|
||||
val genericField = BufferedFieldOpsND(Float64Field)
|
||||
// Nd4j specialized field.
|
||||
val nd4jField = Float64Field.nd4j
|
||||
//viktor field
|
||||
val viktorField = ViktorFieldND(dim, dim)
|
||||
//parallel processing based on Java Streams
|
||||
@@ -57,13 +52,6 @@ fun main() {
|
||||
}
|
||||
}
|
||||
|
||||
measureAndPrint("Nd4j specialized addition") {
|
||||
nd4jField {
|
||||
var res: StructureND<Float64> = one(shape)
|
||||
repeat(n) { res += 1.0 }
|
||||
}
|
||||
}
|
||||
|
||||
measureAndPrint("Viktor addition") {
|
||||
viktorField {
|
||||
var res: StructureND<Float64> = one
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# Copyright 2018-2021 KMath contributors.
|
||||
# Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
#
|
||||
org.gradle.configureondemand=true
|
||||
org.gradle.jvmargs=-Xmx4096m
|
||||
org.gradle.parallel=true
|
||||
org.gradle.workers.max=4
|
||||
@@ -10,7 +9,7 @@ org.gradle.workers.max=4
|
||||
kotlin.code.style=official
|
||||
kotlin.mpp.stability.nowarn=true
|
||||
kotlin.native.ignoreDisabledTargets=true
|
||||
org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers
|
||||
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
|
||||
kotlin.native.enableKlibsCrossCompilation=true
|
||||
|
||||
toolsVersion=0.16.0-kotlin-2.1.20-Beta1
|
||||
toolsVersion=0.20.2-kotlin-2.3.0
|
||||
@@ -2,8 +2,13 @@
|
||||
|
||||
commons-rng = "1.6"
|
||||
multik = "0.2.3"
|
||||
nd4j = "1.0.0-M2.1"
|
||||
tensorflow = "1.1.0"
|
||||
|
||||
[libraries]
|
||||
attributes = "space.kscience:attributes-kt:0.4.0"
|
||||
|
||||
commons-math = "org.apache.commons:commons-math3:3.6.1"
|
||||
|
||||
commons-rng-simple = { module = "org.apache.commons:commons-rng-simple", version.ref = "commons-rng" }
|
||||
commons-rng-sampling = { module = "org.apache.commons:commons-rng-sampling", version.ref = "commons-rng" }
|
||||
@@ -11,4 +16,13 @@ commons-rng-sampling = { module = "org.apache.commons:commons-rng-sampling", ver
|
||||
multik-core = { module = "org.jetbrains.kotlinx:multik-core", version.ref = "multik" }
|
||||
multik-default = { module = "org.jetbrains.kotlinx:multik-default", version.ref = "multik" }
|
||||
|
||||
nd4j-api = { module = "org.nd4j:nd4j-api", version.ref = "nd4j" }
|
||||
nd4j-native-platform = { module = "org.nd4j:nd4j-native-platform", version.ref = "nd4j" }
|
||||
|
||||
ojalgo = "org.ojalgo:ojalgo:56.2.0"
|
||||
|
||||
|
||||
tensorflow-core-api = {module = "org.tensorflow:tensorflow-core-api", version.ref="tensorflow"}
|
||||
tensorflow-core-platform = {module = "org.tensorflow:tensorflow-core-platform", version.ref="tensorflow"}
|
||||
|
||||
[plugins]
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -10,7 +10,7 @@ Extensions to MST API: transformations, dynamic compilation and visualization.
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:kmath-ast:0.4.0`.
|
||||
The Maven coordinates of this project are `space.kscience:kmath-ast:0.5.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@@ -20,7 +20,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:kmath-ast:0.4.0")
|
||||
implementation("space.kscience:kmath-ast:0.5.0")
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ kscience {
|
||||
}
|
||||
|
||||
dependencies(jvmMain) {
|
||||
implementation("org.ow2.asm:asm-commons:9.2")
|
||||
implementation("org.ow2.asm:asm-commons:9.7.1")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,7 +54,7 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
if (System.getProperty("space.kscience.kmath.ast.dump.generated.classes") == "1") {
|
||||
if (project.properties["space.kscience.kmath.ast.dump.generated.classes"] == "1") {
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest> {
|
||||
jvmArgs("-Dspace.kscience.kmath.ast.dump.generated.classes=1")
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import space.kscience.kmath.wasm.compile as wasmCompile
|
||||
import space.kscience.kmath.wasm.compileToExpression as wasmCompileToExpression
|
||||
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
private object WasmCompilerTestContext : CompilerTestContext {
|
||||
internal object WasmCompilerTestContext : CompilerTestContext {
|
||||
override fun MST.compileToExpression(algebra: Int32Ring): Expression<Int> = wasmCompileToExpression(algebra)
|
||||
override fun MST.compile(algebra: Int32Ring, arguments: Map<Symbol, Int>): Int = wasmCompile(algebra, arguments)
|
||||
override fun MST.compileToExpression(algebra: Float64Field): Expression<Float64> = wasmCompileToExpression(algebra)
|
||||
@@ -31,7 +31,7 @@ private object WasmCompilerTestContext : CompilerTestContext {
|
||||
wasmCompile(algebra, arguments)
|
||||
}
|
||||
|
||||
private object ESTreeCompilerTestContext : CompilerTestContext {
|
||||
internal object ESTreeCompilerTestContext : CompilerTestContext {
|
||||
override fun MST.compileToExpression(algebra: Int32Ring): Expression<Int> = estreeCompileToExpression(algebra)
|
||||
override fun MST.compile(algebra: Int32Ring, arguments: Map<Symbol, Int>): Int = estreeCompile(algebra, arguments)
|
||||
override fun MST.compileToExpression(algebra: Float64Field): Expression<Float64> = estreeCompileToExpression(algebra)
|
||||
|
||||
@@ -19,7 +19,7 @@ internal abstract class AsmBuilder {
|
||||
|
||||
protected val classLoader = ByteArrayClassLoader(javaClass.classLoader)
|
||||
|
||||
protected companion object {
|
||||
companion object {
|
||||
/**
|
||||
* ASM type for [Expression].
|
||||
*/
|
||||
|
||||
@@ -5,11 +5,16 @@
|
||||
|
||||
package space.kscience.kmath.asm.internal
|
||||
|
||||
import org.objectweb.asm.*
|
||||
import org.objectweb.asm.ClassWriter
|
||||
import org.objectweb.asm.FieldVisitor
|
||||
import org.objectweb.asm.Opcodes.*
|
||||
import org.objectweb.asm.Type
|
||||
import org.objectweb.asm.Type.*
|
||||
import org.objectweb.asm.commons.InstructionAdapter
|
||||
import space.kscience.kmath.expressions.*
|
||||
import space.kscience.kmath.expressions.Expression
|
||||
import space.kscience.kmath.expressions.MST
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.expressions.invoke
|
||||
import java.lang.invoke.MethodHandles
|
||||
import java.lang.invoke.MethodType
|
||||
import java.nio.file.Paths
|
||||
@@ -24,6 +29,7 @@ import kotlin.io.path.writeBytes
|
||||
* @property expressionResultCallback the function to apply to this object when generating expression value.
|
||||
* @author Iaroslav Postovalov
|
||||
*/
|
||||
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
internal class GenericAsmBuilder<T>(
|
||||
classOfT: Class<*>,
|
||||
private val className: String,
|
||||
|
||||
@@ -75,7 +75,7 @@ internal sealed class PrimitiveAsmBuilder<T : Number, out E : Expression<T>>(
|
||||
val instance: E by lazy {
|
||||
val classWriter = ClassWriter(ClassWriter.COMPUTE_FRAMES) {
|
||||
visit(
|
||||
V1_8,
|
||||
V11,
|
||||
ACC_PUBLIC or ACC_FINAL or ACC_SUPER,
|
||||
classType.internalName,
|
||||
"${OBJECT_TYPE.descriptor}${expressionParentType.descriptor}",
|
||||
@@ -372,12 +372,12 @@ internal sealed class PrimitiveAsmBuilder<T : Number, out E : Expression<T>>(
|
||||
/**
|
||||
* ASM type for [java.lang.Number].
|
||||
*/
|
||||
val NUMBER_TYPE: Type = getObjectType("java/lang/Number")
|
||||
val NUMBER_TYPE: Type = getType(Number::class.java)
|
||||
|
||||
/**
|
||||
* ASM type for [SymbolIndexer].
|
||||
*/
|
||||
val SYMBOL_INDEXER_TYPE: Type = getObjectType("space/kscience/kmath/expressions/SymbolIndexer")
|
||||
val SYMBOL_INDEXER_TYPE: Type = getType(SymbolIndexer::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,6 @@ internal tailrec fun buildName(marker: String, collision: Int = 0): String {
|
||||
return buildName(marker, collision + 1)
|
||||
}
|
||||
|
||||
@Suppress("FunctionName")
|
||||
internal inline fun ClassWriter(flags: Int, block: ClassWriter.() -> Unit): ClassWriter {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return ClassWriter(flags).apply(block)
|
||||
|
||||
@@ -16,7 +16,7 @@ import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.kmath.asm.compile as asmCompile
|
||||
import space.kscience.kmath.asm.compileToExpression as asmCompileToExpression
|
||||
|
||||
private object GenericAsmCompilerTestContext : CompilerTestContext {
|
||||
internal object GenericAsmCompilerTestContext : CompilerTestContext {
|
||||
override fun MST.compileToExpression(algebra: Int32Ring): Expression<Int> =
|
||||
asmCompileToExpression(algebra as Algebra<Int>)
|
||||
|
||||
@@ -31,7 +31,7 @@ private object GenericAsmCompilerTestContext : CompilerTestContext {
|
||||
}
|
||||
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
private object PrimitiveAsmCompilerTestContext : CompilerTestContext {
|
||||
internal object PrimitiveAsmCompilerTestContext : CompilerTestContext {
|
||||
override fun MST.compileToExpression(algebra: Int32Ring): Expression<Int> = asmCompileToExpression(algebra)
|
||||
override fun MST.compile(algebra: Int32Ring, arguments: Map<Symbol, Int>): Int = asmCompile(algebra, arguments)
|
||||
override fun MST.compileToExpression(algebra: Float64Field): Expression<Float64> = asmCompileToExpression(algebra)
|
||||
|
||||
@@ -6,7 +6,7 @@ Commons math binding for kmath
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:kmath-commons:0.4.0`.
|
||||
The Maven coordinates of this project are `space.kscience:kmath-commons:0.5.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:kmath-commons:0.4.0")
|
||||
implementation("space.kscience:kmath-commons:0.5.0")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -13,7 +13,7 @@ kscience {
|
||||
api(projects.kmathOptimization)
|
||||
api(projects.kmathStat)
|
||||
api(projects.kmathFunctions)
|
||||
api("org.apache.commons:commons-math3:3.6.1")
|
||||
api(libs.commons.math)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
package space.kscience.kmath.commons.linear
|
||||
|
||||
import org.apache.commons.math3.linear.*
|
||||
import org.apache.commons.math3.linear.LUDecomposition
|
||||
import org.apache.commons.math3.linear.SingularValueDecomposition
|
||||
import space.kscience.attributes.SafeType
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.linear.*
|
||||
@@ -23,27 +21,26 @@ import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.kmath.structures.IntBuffer
|
||||
import space.kscience.kmath.structures.asBuffer
|
||||
|
||||
public class CMMatrix(public val origin: RealMatrix) : Matrix<Float64> {
|
||||
@JvmInline
|
||||
public value class CMMatrix(public val cmMatrix: RealMatrix) : Matrix<Float64> {
|
||||
|
||||
override val rowNum: Int get() = origin.rowDimension
|
||||
override val colNum: Int get() = origin.columnDimension
|
||||
override val rowNum: Int get() = cmMatrix.rowDimension
|
||||
override val colNum: Int get() = cmMatrix.columnDimension
|
||||
|
||||
override operator fun get(i: Int, j: Int): Double = origin.getEntry(i, j)
|
||||
override operator fun get(i: Int, j: Int): Double = cmMatrix.getEntry(i, j)
|
||||
}
|
||||
|
||||
@JvmInline
|
||||
public value class CMVector(public val origin: RealVector) : Point<Float64> {
|
||||
override val size: Int get() = origin.dimension
|
||||
public value class CMVector(public val cmVector: RealVector) : Point<Float64> {
|
||||
override val size: Int get() = cmVector.dimension
|
||||
|
||||
override operator fun get(index: Int): Double = origin.getEntry(index)
|
||||
override operator fun get(index: Int): Double = cmVector.getEntry(index)
|
||||
|
||||
override operator fun iterator(): Iterator<Float64> = origin.toArray().iterator()
|
||||
override operator fun iterator(): Iterator<Float64> = cmVector.toArray().iterator()
|
||||
|
||||
override fun toString(): String = Buffer.toString(this)
|
||||
}
|
||||
|
||||
public fun RealVector.toPoint(): CMVector = CMVector(this)
|
||||
|
||||
public object CMLinearSpace : LinearSpace<Double, Float64Field> {
|
||||
override val elementAlgebra: Float64Field get() = Float64Field
|
||||
|
||||
@@ -59,52 +56,52 @@ public object CMLinearSpace : LinearSpace<Double, Float64Field> {
|
||||
}
|
||||
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
public fun Matrix<Float64>.toCM(): CMMatrix = when (val matrix = origin) {
|
||||
is CMMatrix -> matrix
|
||||
public fun Matrix<Float64>.toCM(): RealMatrix = when (val matrix = origin) {
|
||||
is CMMatrix -> matrix.cmMatrix
|
||||
else -> {
|
||||
//TODO add feature analysis
|
||||
val array = Array(rowNum) { i -> DoubleArray(colNum) { j -> get(i, j) } }
|
||||
Array2DRowRealMatrix(array).wrap()
|
||||
Array2DRowRealMatrix(array)
|
||||
}
|
||||
}
|
||||
|
||||
public fun Point<Float64>.toCM(): CMVector = if (this is CMVector) this else {
|
||||
val array = DoubleArray(size) { this[it] }
|
||||
ArrayRealVector(array).wrap()
|
||||
public fun Point<Float64>.toCM(): RealVector = if (this is CMVector) cmVector else {
|
||||
val array = DoubleArray(size) { get(it) }
|
||||
ArrayRealVector(array)
|
||||
}
|
||||
|
||||
internal fun RealMatrix.wrap(): CMMatrix = CMMatrix(this)
|
||||
internal fun RealVector.wrap(): CMVector = CMVector(this)
|
||||
public fun RealMatrix.asMatrix(): CMMatrix = CMMatrix(this)
|
||||
public fun RealVector.asVector(): CMVector = CMVector(this)
|
||||
|
||||
override fun buildVector(size: Int, initializer: Float64Field.(Int) -> Double): Point<Float64> =
|
||||
ArrayRealVector(DoubleArray(size) { Float64Field.initializer(it) }).wrap()
|
||||
ArrayRealVector(DoubleArray(size) { Float64Field.initializer(it) }).asVector()
|
||||
|
||||
override fun Matrix<Float64>.plus(other: Matrix<Float64>): CMMatrix =
|
||||
toCM().origin.add(other.toCM().origin).wrap()
|
||||
toCM().add(other.toCM()).asMatrix()
|
||||
|
||||
override fun Point<Float64>.plus(other: Point<Float64>): CMVector =
|
||||
toCM().origin.add(other.toCM().origin).wrap()
|
||||
toCM().add(other.toCM()).asVector()
|
||||
|
||||
override fun Point<Float64>.minus(other: Point<Float64>): CMVector =
|
||||
toCM().origin.subtract(other.toCM().origin).wrap()
|
||||
toCM().subtract(other.toCM()).asVector()
|
||||
|
||||
override fun Matrix<Float64>.dot(other: Matrix<Float64>): CMMatrix =
|
||||
toCM().origin.multiply(other.toCM().origin).wrap()
|
||||
toCM().multiply(other.toCM()).asMatrix()
|
||||
|
||||
override fun Matrix<Float64>.dot(vector: Point<Float64>): CMVector =
|
||||
toCM().origin.preMultiply(vector.toCM().origin).wrap()
|
||||
toCM().preMultiply(vector.toCM()).asVector()
|
||||
|
||||
override operator fun Matrix<Float64>.minus(other: Matrix<Float64>): CMMatrix =
|
||||
toCM().origin.subtract(other.toCM().origin).wrap()
|
||||
toCM().subtract(other.toCM()).asMatrix()
|
||||
|
||||
override operator fun Matrix<Float64>.times(value: Double): CMMatrix =
|
||||
toCM().origin.scalarMultiply(value).wrap()
|
||||
toCM().scalarMultiply(value).asMatrix()
|
||||
|
||||
override fun Double.times(m: Matrix<Float64>): CMMatrix =
|
||||
m * this
|
||||
|
||||
override fun Point<Float64>.times(value: Double): CMVector =
|
||||
toCM().origin.mapMultiply(value).wrap()
|
||||
toCM().mapMultiply(value).asVector()
|
||||
|
||||
override fun Double.times(v: Point<Float64>): CMVector =
|
||||
v * this
|
||||
@@ -112,36 +109,38 @@ public object CMLinearSpace : LinearSpace<Double, Float64Field> {
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
override fun <V, A : StructureAttribute<V>> computeAttribute(structure: Structure2D<Float64>, attribute: A): V? {
|
||||
|
||||
val origin = structure.toCM().origin
|
||||
val origin = structure.toCM()
|
||||
|
||||
val raw: Any? = when (attribute) {
|
||||
IsDiagonal -> if (origin is DiagonalMatrix) Unit else null
|
||||
Determinant -> LUDecomposition(origin).determinant
|
||||
Determinant -> org.apache.commons.math3.linear.LUDecomposition(origin).determinant
|
||||
|
||||
Inverted -> org.apache.commons.math3.linear.LUDecomposition(origin).solver.inverse.asMatrix()
|
||||
|
||||
LUP -> object : LupDecomposition<Float64> {
|
||||
val lup by lazy { LUDecomposition(origin) }
|
||||
val lup by lazy { org.apache.commons.math3.linear.LUDecomposition(origin) }
|
||||
override val pivot: IntBuffer get() = lup.pivot.asBuffer()
|
||||
override val l: Matrix<Float64> get() = lup.l.wrap()
|
||||
override val u: Matrix<Float64> get() = lup.u.wrap()
|
||||
override val l: Matrix<Float64> get() = lup.l.asMatrix().withAttribute(LowerTriangular)
|
||||
override val u: Matrix<Float64> get() = lup.u.asMatrix().withAttribute(UpperTriangular)
|
||||
}
|
||||
|
||||
Cholesky -> object : CholeskyDecomposition<Float64> {
|
||||
val cmCholesky by lazy { org.apache.commons.math3.linear.CholeskyDecomposition(origin) }
|
||||
override val l: Matrix<Float64> get() = cmCholesky.l.wrap()
|
||||
override val l: Matrix<Float64> get() = cmCholesky.l.asMatrix()
|
||||
}
|
||||
|
||||
QR -> object : QRDecomposition<Float64> {
|
||||
val cmQr by lazy { org.apache.commons.math3.linear.QRDecomposition(origin) }
|
||||
override val q: Matrix<Float64> get() = cmQr.q.wrap().withAttribute(OrthogonalAttribute)
|
||||
override val r: Matrix<Float64> get() = cmQr.r.wrap().withAttribute(UpperTriangular)
|
||||
override val q: Matrix<Float64> get() = cmQr.q.asMatrix().withAttribute(OrthogonalAttribute)
|
||||
override val r: Matrix<Float64> get() = cmQr.r.asMatrix().withAttribute(UpperTriangular)
|
||||
}
|
||||
|
||||
SVD -> object : space.kscience.kmath.linear.SingularValueDecomposition<Float64> {
|
||||
val cmSvd by lazy { SingularValueDecomposition(origin) }
|
||||
val cmSvd by lazy { org.apache.commons.math3.linear.SingularValueDecomposition(origin) }
|
||||
|
||||
override val u: Matrix<Float64> get() = cmSvd.u.wrap()
|
||||
override val s: Matrix<Float64> get() = cmSvd.s.wrap()
|
||||
override val v: Matrix<Float64> get() = cmSvd.v.wrap()
|
||||
override val u: Matrix<Float64> get() = cmSvd.u.asMatrix()
|
||||
override val s: Matrix<Float64> get() = cmSvd.s.asMatrix()
|
||||
override val v: Matrix<Float64> get() = cmSvd.v.asMatrix()
|
||||
override val singularValues: Point<Float64> get() = cmSvd.singularValues.asBuffer()
|
||||
|
||||
}
|
||||
@@ -149,8 +148,8 @@ public object CMLinearSpace : LinearSpace<Double, Float64Field> {
|
||||
EIG -> object : EigenDecomposition<Float64> {
|
||||
val cmEigen by lazy { org.apache.commons.math3.linear.EigenDecomposition(origin) }
|
||||
|
||||
override val v: Matrix<Float64> get() = cmEigen.v.wrap()
|
||||
override val d: Matrix<Float64> get() = cmEigen.d.wrap()
|
||||
override val v: Matrix<Float64> get() = cmEigen.v.asMatrix()
|
||||
override val d: Matrix<Float64> get() = cmEigen.d.asMatrix()
|
||||
}
|
||||
|
||||
else -> null
|
||||
@@ -161,8 +160,8 @@ public object CMLinearSpace : LinearSpace<Double, Float64Field> {
|
||||
|
||||
}
|
||||
|
||||
public operator fun CMMatrix.plus(other: CMMatrix): CMMatrix = CMMatrix(origin.add(other.origin))
|
||||
public operator fun CMMatrix.plus(other: CMMatrix): CMMatrix = CMMatrix(cmMatrix.add(other.cmMatrix))
|
||||
|
||||
public operator fun CMMatrix.minus(other: CMMatrix): CMMatrix = CMMatrix(origin.subtract(other.origin))
|
||||
public operator fun CMMatrix.minus(other: CMMatrix): CMMatrix = CMMatrix(cmMatrix.subtract(other.cmMatrix))
|
||||
|
||||
public infix fun CMMatrix.dot(other: CMMatrix): CMMatrix = CMMatrix(origin.multiply(other.origin))
|
||||
public infix fun CMMatrix.dot(other: CMMatrix): CMMatrix = CMMatrix(cmMatrix.multiply(other.cmMatrix))
|
||||
@@ -19,43 +19,44 @@ public enum class CMDecomposition {
|
||||
CHOLESKY
|
||||
}
|
||||
|
||||
private fun CMLinearSpace.solver(
|
||||
private fun CMLinearSpace.cmSolver(
|
||||
a: Matrix<Float64>,
|
||||
decomposition: CMDecomposition = CMDecomposition.LUP,
|
||||
): DecompositionSolver = when (decomposition) {
|
||||
CMDecomposition.LUP -> LUDecomposition(a.toCM().origin).solver
|
||||
CMDecomposition.RRQR -> RRQRDecomposition(a.toCM().origin).solver
|
||||
CMDecomposition.QR -> QRDecomposition(a.toCM().origin).solver
|
||||
CMDecomposition.EIGEN -> EigenDecomposition(a.toCM().origin).solver
|
||||
CMDecomposition.CHOLESKY -> CholeskyDecomposition(a.toCM().origin).solver
|
||||
CMDecomposition.LUP -> LUDecomposition(a.toCM()).solver
|
||||
CMDecomposition.RRQR -> RRQRDecomposition(a.toCM()).solver
|
||||
CMDecomposition.QR -> QRDecomposition(a.toCM()).solver
|
||||
CMDecomposition.EIGEN -> EigenDecomposition(a.toCM()).solver
|
||||
CMDecomposition.CHOLESKY -> CholeskyDecomposition(a.toCM()).solver
|
||||
}
|
||||
|
||||
public fun CMLinearSpace.solve(
|
||||
a: Matrix<Float64>,
|
||||
b: Matrix<Float64>,
|
||||
decomposition: CMDecomposition = CMDecomposition.LUP,
|
||||
): CMMatrix = solver(a, decomposition).solve(b.toCM().origin).wrap()
|
||||
): CMMatrix = cmSolver(a, decomposition).solve(b.toCM()).asMatrix()
|
||||
|
||||
public fun CMLinearSpace.solve(
|
||||
a: Matrix<Float64>,
|
||||
b: Point<Float64>,
|
||||
decomposition: CMDecomposition = CMDecomposition.LUP,
|
||||
): CMVector = solver(a, decomposition).solve(b.toCM().origin).toPoint()
|
||||
): CMVector = cmSolver(a, decomposition).solve(b.toCM()).asVector()
|
||||
|
||||
public fun CMLinearSpace.inverse(
|
||||
a: Matrix<Float64>,
|
||||
decomposition: CMDecomposition = CMDecomposition.LUP,
|
||||
): CMMatrix = solver(a, decomposition).inverse.wrap()
|
||||
): CMMatrix = cmSolver(a, decomposition).inverse.asMatrix()
|
||||
|
||||
|
||||
public fun CMLinearSpace.solver(decomposition: CMDecomposition): LinearSolver<Float64> = object : LinearSolver<Float64> {
|
||||
override fun solve(a: Matrix<Float64>, b: Matrix<Float64>): Matrix<Float64> =
|
||||
solver(a, decomposition).solve(b.toCM().origin).wrap()
|
||||
public fun CMLinearSpace.solver(decomposition: CMDecomposition): LinearSolver<Float64> =
|
||||
object : LinearSolver<Float64> {
|
||||
override fun solve(a: Matrix<Float64>, b: Matrix<Float64>): Matrix<Float64> =
|
||||
cmSolver(a, decomposition).solve(b.toCM()).asMatrix()
|
||||
|
||||
override fun solve(a: Matrix<Float64>, b: Point<Float64>): Point<Float64> =
|
||||
solver(a, decomposition).solve(b.toCM().origin).toPoint()
|
||||
override fun solve(a: Matrix<Float64>, b: Point<Float64>): Point<Float64> =
|
||||
cmSolver(a, decomposition).solve(b.toCM()).asVector()
|
||||
|
||||
override fun inverse(matrix: Matrix<Float64>): Matrix<Float64> = solver(matrix, decomposition).inverse.wrap()
|
||||
}
|
||||
override fun inverse(matrix: Matrix<Float64>): Matrix<Float64> = cmSolver(matrix, decomposition).inverse.asMatrix()
|
||||
}
|
||||
|
||||
public fun CMLinearSpace.lupSolver(): LinearSolver<Float64> = solver((CMDecomposition.LUP))
|
||||
@@ -23,7 +23,6 @@ import space.kscience.kmath.expressions.derivative
|
||||
import space.kscience.kmath.expressions.withSymbols
|
||||
import space.kscience.kmath.optimization.*
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import kotlin.collections.set
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
public operator fun PointValuePair.component1(): DoubleArray = point
|
||||
@@ -35,7 +34,7 @@ public object CMOptimizerEngine : OptimizationAttribute<() -> MultivariateOptimi
|
||||
* Specify a Commons-maths optimization engine
|
||||
*/
|
||||
public fun AttributesBuilder<FunctionOptimization<Float64>>.cmEngine(optimizerBuilder: () -> MultivariateOptimizer) {
|
||||
set(CMOptimizerEngine, optimizerBuilder)
|
||||
CMOptimizerEngine(optimizerBuilder)
|
||||
}
|
||||
|
||||
public object CMOptimizerData : SetAttribute<SymbolIndexer.() -> OptimizationData>
|
||||
|
||||
@@ -8,7 +8,7 @@ Complex and hypercomplex number systems in KMath.
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:kmath-complex:0.4.0`.
|
||||
The Maven coordinates of this project are `space.kscience:kmath-complex:0.5.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@@ -18,6 +18,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:kmath-complex:0.4.0")
|
||||
implementation("space.kscience:kmath-complex:0.5.0")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -6,7 +6,7 @@ kscience {
|
||||
jvm()
|
||||
js()
|
||||
native()
|
||||
wasm()
|
||||
wasmJs()
|
||||
|
||||
dependencies {
|
||||
api(projects.kmathCore)
|
||||
|
||||
@@ -4,11 +4,9 @@ The core interfaces of KMath.
|
||||
|
||||
- [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.
|
||||
- [linear](src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt) : Basic linear algebra operations (sums, products, etc.), backed by the `Space` API.
|
||||
- [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.
|
||||
- [expressions](src/commonMain/kotlin/space/kscience/kmath/expressions) : By writing a single mathematical expression once, users will be able to apply different types of
|
||||
- [domains](src/commonMain/kotlin/space/kscience/kmath/domains) : Domains
|
||||
- [autodiff](src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt) : Automatic differentiation
|
||||
- [Parallel linear algebra](#) : Parallel implementation for `LinearAlgebra`
|
||||
@@ -16,7 +14,7 @@ performance calculations to code generation.
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:kmath-core:0.4.0`.
|
||||
The Maven coordinates of this project are `space.kscience:kmath-core:0.5.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@@ -26,6 +24,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:kmath-core:0.4.0")
|
||||
implementation("space.kscience:kmath-core:0.5.0")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -9,15 +9,9 @@ public abstract interface annotation class space/kscience/kmath/UnsafeKMathAPI :
|
||||
public abstract interface annotation class space/kscience/kmath/UnstableKMathAPI : java/lang/annotation/Annotation {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/data/ColumnarDataKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/data/XYColumnarData$Companion {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/data/XYColumnarDataKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/data/XYErrorColumnarData$Companion {
|
||||
public final fun of (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/data/XYErrorColumnarData;
|
||||
}
|
||||
@@ -27,9 +21,6 @@ public abstract interface class space/kscience/kmath/domains/Domain {
|
||||
public abstract fun getDimension ()I
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/domains/Domain1DKt {
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/kmath/expressions/AutoDiffProcessor {
|
||||
public abstract fun differentiate (Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/DifferentiableExpression;
|
||||
}
|
||||
@@ -39,9 +30,6 @@ public class space/kscience/kmath/expressions/AutoDiffValue {
|
||||
public final fun getValue ()Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/expressions/DSAlgebraKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/expressions/DSCompiler {
|
||||
public final fun getAlgebra ()Lspace/kscience/kmath/operations/Algebra;
|
||||
public final fun getFreeParameters ()I
|
||||
@@ -412,34 +400,6 @@ public final class space/kscience/kmath/expressions/MstRing : space/kscience/kma
|
||||
public fun unaryPlus (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/expressions/NamedMatrix : space/kscience/kmath/nd/Structure2D {
|
||||
public static final field Companion Lspace/kscience/kmath/expressions/NamedMatrix$Companion;
|
||||
public fun <init> (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/SymbolIndexer;)V
|
||||
public fun elements ()Lkotlin/sequences/Sequence;
|
||||
public fun get (II)Ljava/lang/Object;
|
||||
public final fun get (Lspace/kscience/kmath/expressions/Symbol;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object;
|
||||
public fun get ([I)Ljava/lang/Object;
|
||||
public fun getAttributes ()Lspace/kscience/attributes/Attributes;
|
||||
public fun getColNum ()I
|
||||
public fun getColumns ()Ljava/util/List;
|
||||
public fun getDimension ()I
|
||||
public final fun getIndexer ()Lspace/kscience/kmath/expressions/SymbolIndexer;
|
||||
public fun getIndices ()Lspace/kscience/kmath/nd/ShapeIndexer;
|
||||
public fun getRowNum ()I
|
||||
public fun getRows ()Ljava/util/List;
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public final fun getValues ()Lspace/kscience/kmath/nd/Structure2D;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/expressions/NamedMatrix$Companion {
|
||||
public final fun toStringWithSymbols (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/SymbolIndexer;)Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/expressions/NamedMatrixKt {
|
||||
public static final fun named (Lspace/kscience/kmath/nd/Structure2D;Ljava/util/List;)Lspace/kscience/kmath/expressions/NamedMatrix;
|
||||
public static final fun named (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/SymbolIndexer;)Lspace/kscience/kmath/expressions/NamedMatrix;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/expressions/SimpleAutoDiffExpression : space/kscience/kmath/expressions/FirstDerivativeExpression {
|
||||
public fun <init> (Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)V
|
||||
public fun derivativeOrNull (Lspace/kscience/kmath/expressions/Symbol;)Lspace/kscience/kmath/expressions/Expression;
|
||||
@@ -565,9 +525,6 @@ public final class space/kscience/kmath/expressions/Symbol$Companion {
|
||||
public final fun getZError ()Lspace/kscience/kmath/expressions/Symbol;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/expressions/SymbolIndexerKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/expressions/SymbolKt {
|
||||
public static final fun Symbol (Ljava/lang/String;)Lspace/kscience/kmath/expressions/Symbol;
|
||||
public static final fun get (Ljava/util/Map;Ljava/lang/String;)Ljava/lang/Object;
|
||||
@@ -679,7 +636,7 @@ public final class space/kscience/kmath/linear/Inverted : space/kscience/attribu
|
||||
public fun <init> ()V
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/kmath/linear/IsDiagonal : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute {
|
||||
public abstract interface class space/kscience/kmath/linear/IsDiagonal : space/kscience/kmath/linear/Symmetric {
|
||||
public static final field Companion Lspace/kscience/kmath/linear/IsDiagonal$Companion;
|
||||
}
|
||||
|
||||
@@ -786,24 +743,15 @@ public final class space/kscience/kmath/linear/MatrixAttributesKt {
|
||||
public static final fun getSVD (Lspace/kscience/kmath/linear/MatrixScope;)Lspace/kscience/kmath/linear/SVDAttribute;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/linear/MatrixBuilder : space/kscience/attributes/WithType {
|
||||
public fun <init> (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 fun getType-V0oMfBY ()Lkotlin/reflect/KType;
|
||||
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 final class space/kscience/kmath/linear/MatrixBuildersKt {
|
||||
public static final fun column (Lspace/kscience/kmath/linear/LinearSpace;ILkotlin/jvm/functions/Function2;)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;ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/Structure2D;
|
||||
public static final fun row (Lspace/kscience/kmath/linear/LinearSpace;[Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D;
|
||||
public static final fun symmetric (Lspace/kscience/kmath/linear/MatrixBuilder;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/Structure2D;
|
||||
public static final fun vector (Lspace/kscience/kmath/linear/LinearSpace;[Ljava/lang/Object;)Lspace/kscience/kmath/structures/Buffer;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/kmath/linear/MatrixScope : space/kscience/attributes/AttributeScope, space/kscience/attributes/WithType {
|
||||
public abstract interface class space/kscience/kmath/linear/MatrixScope : space/kscience/attributes/WithType {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/linear/MatrixWrapper : space/kscience/kmath/nd/Structure2D {
|
||||
@@ -818,7 +766,7 @@ public final class space/kscience/kmath/linear/MatrixWrapper : space/kscience/km
|
||||
public final fun getOrigin ()Lspace/kscience/kmath/nd/Structure2D;
|
||||
public fun getRowNum ()I
|
||||
public fun getRows ()Ljava/util/List;
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
@@ -854,8 +802,11 @@ public abstract interface class space/kscience/kmath/linear/SingularValueDecompo
|
||||
public abstract fun getV ()Lspace/kscience/kmath/nd/Structure2D;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/linear/Symmetric : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute {
|
||||
public static final field INSTANCE Lspace/kscience/kmath/linear/Symmetric;
|
||||
public abstract interface class space/kscience/kmath/linear/Symmetric : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute {
|
||||
public static final field Companion Lspace/kscience/kmath/linear/Symmetric$Companion;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/linear/Symmetric$Companion : space/kscience/kmath/linear/Symmetric {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/linear/TransposedKt {
|
||||
@@ -883,12 +834,6 @@ public final class space/kscience/kmath/linear/VirtualMatrix : space/kscience/km
|
||||
public fun getColNum ()I
|
||||
public final fun getGenerator ()Lkotlin/jvm/functions/Function2;
|
||||
public fun getRowNum ()I
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/linear/VirtualMatrixKt {
|
||||
public static final fun virtual (Lspace/kscience/kmath/linear/MatrixBuilder;Lspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/linear/VirtualMatrix;
|
||||
public static synthetic fun virtual$default (Lspace/kscience/kmath/linear/MatrixBuilder;Lspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lspace/kscience/kmath/linear/VirtualMatrix;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/misc/CollectionsKt {
|
||||
@@ -944,14 +889,66 @@ public final class space/kscience/kmath/misc/SortingKt {
|
||||
public static final fun sortedWith (Lspace/kscience/kmath/structures/Buffer;Ljava/util/Comparator;)Lspace/kscience/kmath/structures/Buffer;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/named/NamedBuffer : space/kscience/kmath/structures/Buffer {
|
||||
public fun <init> (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/expressions/SymbolIndexer;)V
|
||||
public fun get (I)Ljava/lang/Object;
|
||||
public final fun get (Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object;
|
||||
public final fun getIndexer ()Lspace/kscience/kmath/expressions/SymbolIndexer;
|
||||
public fun getSize ()I
|
||||
public final fun getValues ()Lspace/kscience/kmath/structures/Buffer;
|
||||
public fun iterator ()Ljava/util/Iterator;
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/named/NamedMatrix : space/kscience/kmath/nd/Structure2D {
|
||||
public static final field Companion Lspace/kscience/kmath/named/NamedMatrix$Companion;
|
||||
public fun <init> (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/SymbolIndexer;)V
|
||||
public fun elements ()Lkotlin/sequences/Sequence;
|
||||
public fun get (II)Ljava/lang/Object;
|
||||
public final fun get (Lspace/kscience/kmath/expressions/Symbol;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object;
|
||||
public fun get ([I)Ljava/lang/Object;
|
||||
public fun getAttributes ()Lspace/kscience/attributes/Attributes;
|
||||
public fun getColNum ()I
|
||||
public fun getColumns ()Ljava/util/List;
|
||||
public fun getDimension ()I
|
||||
public final fun getIndexer ()Lspace/kscience/kmath/expressions/SymbolIndexer;
|
||||
public fun getIndices ()Lspace/kscience/kmath/nd/ShapeIndexer;
|
||||
public fun getRowNum ()I
|
||||
public fun getRows ()Ljava/util/List;
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public final fun getValues ()Lspace/kscience/kmath/nd/Structure2D;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/named/NamedMatrix$Companion {
|
||||
public final fun toStringWithSymbols (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/SymbolIndexer;)Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/named/NamedMatrixKt {
|
||||
public static final fun named (Lspace/kscience/kmath/nd/Structure2D;Ljava/util/List;)Lspace/kscience/kmath/named/NamedMatrix;
|
||||
public static final fun named (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/expressions/SymbolIndexer;)Lspace/kscience/kmath/named/NamedMatrix;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/named/NamedMutableBuffer : space/kscience/kmath/structures/MutableBuffer {
|
||||
public fun <init> (Lspace/kscience/kmath/structures/MutableBuffer;Lspace/kscience/kmath/expressions/SymbolIndexer;)V
|
||||
public fun get (I)Ljava/lang/Object;
|
||||
public final fun get (Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object;
|
||||
public final fun getIndexer ()Lspace/kscience/kmath/expressions/SymbolIndexer;
|
||||
public fun getSize ()I
|
||||
public final fun getValues ()Lspace/kscience/kmath/structures/MutableBuffer;
|
||||
public fun iterator ()Ljava/util/Iterator;
|
||||
public fun set (ILjava/lang/Object;)V
|
||||
public final fun set (Lspace/kscience/kmath/expressions/Symbol;Ljava/lang/Object;)V
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/kmath/nd/AlgebraND : space/kscience/kmath/operations/Algebra {
|
||||
public static final field Companion Lspace/kscience/kmath/nd/AlgebraND$Companion;
|
||||
public abstract fun getElementAlgebra ()Lspace/kscience/kmath/operations/Algebra;
|
||||
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/StructureND;
|
||||
public fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public abstract fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND;
|
||||
public fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public abstract fun mutableStructureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND;
|
||||
public fun structureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND;
|
||||
}
|
||||
|
||||
@@ -960,10 +957,10 @@ public final class space/kscience/kmath/nd/AlgebraND$Companion {
|
||||
|
||||
public final class space/kscience/kmath/nd/AlgebraNDExtentionsKt {
|
||||
public static final fun mutableStructureND (Lspace/kscience/kmath/nd/AlgebraND;I[ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND;
|
||||
public static final fun one-waz_sdI (Lspace/kscience/kmath/nd/AlgebraND;[I)Lspace/kscience/kmath/nd/StructureND;
|
||||
public static final fun one (Lspace/kscience/kmath/nd/AlgebraND;Lspace/kscience/kmath/nd/ShapeND;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public static final fun oneVarArg (Lspace/kscience/kmath/nd/AlgebraND;I[I)Lspace/kscience/kmath/nd/StructureND;
|
||||
public static final fun structureND (Lspace/kscience/kmath/nd/AlgebraND;I[ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public static final fun zero-waz_sdI (Lspace/kscience/kmath/nd/AlgebraND;[I)Lspace/kscience/kmath/nd/StructureND;
|
||||
public static final fun zero (Lspace/kscience/kmath/nd/AlgebraND;Lspace/kscience/kmath/nd/ShapeND;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public static final fun zeroVarArg (Lspace/kscience/kmath/nd/AlgebraND;I[I)Lspace/kscience/kmath/nd/StructureND;
|
||||
}
|
||||
|
||||
@@ -976,10 +973,10 @@ public abstract interface class space/kscience/kmath/nd/BufferAlgebraND : space/
|
||||
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 fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableBufferND;
|
||||
public synthetic fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND;
|
||||
public fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public synthetic fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public fun mutableStructureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableBufferND;
|
||||
public synthetic fun mutableStructureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND;
|
||||
public fun structureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public synthetic fun structureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public fun toBufferND (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public synthetic fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND;
|
||||
@@ -1004,7 +1001,7 @@ public class space/kscience/kmath/nd/BufferND : space/kscience/kmath/nd/Structur
|
||||
public fun get ([I)Ljava/lang/Object;
|
||||
public fun getBuffer ()Lspace/kscience/kmath/structures/Buffer;
|
||||
public fun getIndices ()Lspace/kscience/kmath/nd/ShapeIndexer;
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
@@ -1034,10 +1031,10 @@ public class space/kscience/kmath/nd/BufferedRingOpsND : space/kscience/kmath/nd
|
||||
|
||||
public final class space/kscience/kmath/nd/ColumnStrides : space/kscience/kmath/nd/Strides {
|
||||
public static final field Companion Lspace/kscience/kmath/nd/ColumnStrides$Companion;
|
||||
public synthetic fun <init> ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (Lspace/kscience/kmath/nd/ShapeND;)V
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public fun getLinearSize ()I
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public fun hashCode ()I
|
||||
public fun index (I)[I
|
||||
}
|
||||
@@ -1107,9 +1104,9 @@ public abstract class space/kscience/kmath/nd/Floa64FieldOpsND : space/kscience/
|
||||
public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
|
||||
public fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND;
|
||||
public synthetic fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/Float64BufferND;
|
||||
public synthetic fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableBufferND;
|
||||
public synthetic fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND;
|
||||
public fun mutableStructureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/Float64BufferND;
|
||||
public synthetic fun mutableStructureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableBufferND;
|
||||
public synthetic fun mutableStructureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND;
|
||||
public fun plus (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
|
||||
public synthetic fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND;
|
||||
@@ -1159,7 +1156,7 @@ public final class space/kscience/kmath/nd/Float64BufferND : space/kscience/kmat
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/Float64FieldND : space/kscience/kmath/nd/Floa64FieldOpsND, space/kscience/kmath/nd/FieldND, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/NumbersAddOps {
|
||||
public synthetic fun <init> ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (Lspace/kscience/kmath/nd/ShapeND;)V
|
||||
public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object;
|
||||
public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND;
|
||||
public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object;
|
||||
@@ -1168,7 +1165,7 @@ public final class space/kscience/kmath/nd/Float64FieldND : space/kscience/kmath
|
||||
public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND;
|
||||
public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object;
|
||||
public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND;
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object;
|
||||
public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/Float64BufferND;
|
||||
public synthetic fun power (Ljava/lang/Object;I)Ljava/lang/Object;
|
||||
@@ -1186,8 +1183,8 @@ public final class space/kscience/kmath/nd/Float64FieldND : space/kscience/kmath
|
||||
|
||||
public final class space/kscience/kmath/nd/Float64FieldNDKt {
|
||||
public static final fun getNdAlgebra (Lspace/kscience/kmath/operations/Float64Field;)Lspace/kscience/kmath/nd/Floa64FieldOpsND;
|
||||
public static final fun ndAlgebra (Lspace/kscience/kmath/operations/Float64Field;Lspace/kscience/kmath/nd/ShapeND;)Lspace/kscience/kmath/nd/Float64FieldND;
|
||||
public static final fun ndAlgebra (Lspace/kscience/kmath/operations/Float64Field;[I)Lspace/kscience/kmath/nd/Float64FieldND;
|
||||
public static final fun ndAlgebra-waz_sdI (Lspace/kscience/kmath/operations/Float64Field;[I)Lspace/kscience/kmath/nd/Float64FieldND;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/kmath/nd/GroupND : space/kscience/kmath/nd/GroupOpsND, space/kscience/kmath/nd/WithShape, space/kscience/kmath/operations/Group {
|
||||
@@ -1210,14 +1207,14 @@ public final class space/kscience/kmath/nd/GroupOpsND$Companion {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/IndexOutOfShapeException : java/lang/RuntimeException {
|
||||
public synthetic fun <init> ([I[ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (Lspace/kscience/kmath/nd/ShapeND;[I)V
|
||||
public final fun getIndex ()[I
|
||||
public final fun getShape-IIYLAfE ()[I
|
||||
public final fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/Int16RingND : space/kscience/kmath/nd/Int16RingOpsND, space/kscience/kmath/nd/RingND, space/kscience/kmath/operations/NumbersAddOps {
|
||||
public synthetic fun <init> ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun <init> (Lspace/kscience/kmath/nd/ShapeND;)V
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object;
|
||||
public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/BufferND;
|
||||
}
|
||||
@@ -1241,8 +1238,8 @@ public final class space/kscience/kmath/nd/IntBufferND : space/kscience/kmath/nd
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/IntRingND : space/kscience/kmath/nd/IntRingOpsND, space/kscience/kmath/nd/RingND, space/kscience/kmath/operations/NumbersAddOps {
|
||||
public synthetic fun <init> ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun <init> (Lspace/kscience/kmath/nd/ShapeND;)V
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object;
|
||||
public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/BufferND;
|
||||
}
|
||||
@@ -1253,9 +1250,9 @@ public final class space/kscience/kmath/nd/IntRingNDKt {
|
||||
|
||||
public abstract class space/kscience/kmath/nd/IntRingOpsND : space/kscience/kmath/nd/BufferedRingOpsND {
|
||||
public static final field Companion Lspace/kscience/kmath/nd/IntRingOpsND$Companion;
|
||||
public synthetic fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/IntBufferND;
|
||||
public synthetic fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND;
|
||||
public synthetic fun structureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public fun structureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/IntBufferND;
|
||||
public synthetic fun structureND (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/IntRingOpsND$Companion : space/kscience/kmath/nd/IntRingOpsND {
|
||||
@@ -1302,12 +1299,12 @@ public final class space/kscience/kmath/nd/OperationsNDKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/PermutedMutableStructureND : space/kscience/kmath/nd/MutableStructureND {
|
||||
public synthetic fun <init> (Lspace/kscience/kmath/nd/MutableStructureND;[ILkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (Lspace/kscience/kmath/nd/MutableStructureND;[ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function1;)V
|
||||
public synthetic fun <init> (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun get ([I)Ljava/lang/Object;
|
||||
public final fun getOrigin ()Lspace/kscience/kmath/nd/MutableStructureND;
|
||||
public final fun getPermutation ()Lkotlin/jvm/functions/Function1;
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public fun set ([ILjava/lang/Object;)V
|
||||
}
|
||||
|
||||
@@ -1316,13 +1313,13 @@ public final class space/kscience/kmath/nd/PermutedStructureND : space/kscience/
|
||||
public fun get ([I)Ljava/lang/Object;
|
||||
public final fun getOrigin ()Lspace/kscience/kmath/nd/StructureND;
|
||||
public final fun getPermutation ()Lkotlin/jvm/functions/Function1;
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/PermutedStructureNDKt {
|
||||
public static final fun permute (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/PermutedMutableStructureND;
|
||||
public static final fun permute (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/PermutedStructureND;
|
||||
public static final fun permute-_A0By-k (Lspace/kscience/kmath/nd/MutableStructureND;[ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/PermutedMutableStructureND;
|
||||
public static synthetic fun permute-_A0By-k$default (Lspace/kscience/kmath/nd/MutableStructureND;[ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/PermutedMutableStructureND;
|
||||
public static synthetic fun permute$default (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/PermutedMutableStructureND;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/PrimitiveStructureNDKt {
|
||||
@@ -1349,10 +1346,10 @@ public final class space/kscience/kmath/nd/RingOpsND$Companion {
|
||||
|
||||
public final class space/kscience/kmath/nd/RowStrides : space/kscience/kmath/nd/Strides {
|
||||
public static final field Companion Lspace/kscience/kmath/nd/RowStrides$Companion;
|
||||
public synthetic fun <init> ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (Lspace/kscience/kmath/nd/ShapeND;)V
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public fun getLinearSize ()I
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public fun hashCode ()I
|
||||
public fun index (I)[I
|
||||
}
|
||||
@@ -1364,7 +1361,7 @@ public abstract interface class space/kscience/kmath/nd/ShapeIndexer : java/lang
|
||||
public abstract fun asSequence ()Lkotlin/sequences/Sequence;
|
||||
public abstract fun equals (Ljava/lang/Object;)Z
|
||||
public abstract fun getLinearSize ()I
|
||||
public abstract fun getShape-IIYLAfE ()[I
|
||||
public abstract fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public abstract fun hashCode ()I
|
||||
public abstract fun index (I)[I
|
||||
public fun iterator ()Ljava/util/Iterator;
|
||||
@@ -1372,54 +1369,49 @@ public abstract interface class space/kscience/kmath/nd/ShapeIndexer : java/lang
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/ShapeIndicesKt {
|
||||
public static final fun Strides-dNlrn20 ([I)Lspace/kscience/kmath/nd/Strides;
|
||||
public static final fun Strides (Lspace/kscience/kmath/nd/ShapeND;)Lspace/kscience/kmath/nd/Strides;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/ShapeMismatchException : java/lang/RuntimeException {
|
||||
public synthetic fun <init> ([I[ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public final fun getActual-IIYLAfE ()[I
|
||||
public final fun getExpected-IIYLAfE ()[I
|
||||
public fun <init> (Lspace/kscience/kmath/nd/ShapeND;Lspace/kscience/kmath/nd/ShapeND;)V
|
||||
public final fun getActual ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
public final fun getExpected ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/ShapeND {
|
||||
public static final synthetic fun box-impl ([I)Lspace/kscience/kmath/nd/ShapeND;
|
||||
public static fun constructor-impl ([I)[I
|
||||
public fun <init> ([I)V
|
||||
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 static final fun get-impl ([II)I
|
||||
public static final fun getSize-impl ([I)I
|
||||
public final fun get (I)I
|
||||
public final fun getArray ()[I
|
||||
public final fun getSize ()I
|
||||
public fun hashCode ()I
|
||||
public static fun hashCode-impl ([I)I
|
||||
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/nd/ShapeNDKt {
|
||||
public static final fun ShapeND (I[I)[I
|
||||
public static final fun asArray-dNlrn20 ([I)[I
|
||||
public static final fun asList-dNlrn20 ([I)Ljava/util/List;
|
||||
public static final fun component1-dNlrn20 ([I)I
|
||||
public static final fun component2-dNlrn20 ([I)I
|
||||
public static final fun component3-dNlrn20 ([I)I
|
||||
public static final fun contentEquals-9Nqdy04 ([I[I)Z
|
||||
public static final fun contentHashCode-dNlrn20 ([I)I
|
||||
public static final fun first-dNlrn20 ([I)I
|
||||
public static final fun first-qL90JFI ([II)[I
|
||||
public static final fun forEach-qL90JFI ([ILkotlin/jvm/functions/Function1;)V
|
||||
public static final fun forEachIndexed-qL90JFI ([ILkotlin/jvm/functions/Function2;)V
|
||||
public static final fun getIndices-dNlrn20 ([I)Lkotlin/ranges/IntRange;
|
||||
public static final fun getLinearSize-dNlrn20 ([I)I
|
||||
public static final fun isEmpty-dNlrn20 ([I)Z
|
||||
public static final fun isNotEmpty-dNlrn20 ([I)Z
|
||||
public static final fun last-dNlrn20 ([I)I
|
||||
public static final fun last-qL90JFI ([II)[I
|
||||
public static final fun plus-9Nqdy04 ([I[I)[I
|
||||
public static final fun plus-qL90JFI ([I[I)[I
|
||||
public static final fun slice-qL90JFI ([ILkotlin/ranges/IntRange;)[I
|
||||
public static final fun toArray-dNlrn20 ([I)[I
|
||||
public static final fun transposed-bYNkpeI ([III)[I
|
||||
public static final fun ShapeND (I[I)Lspace/kscience/kmath/nd/ShapeND;
|
||||
public static final fun asArray (Lspace/kscience/kmath/nd/ShapeND;)[I
|
||||
public static final fun asList (Lspace/kscience/kmath/nd/ShapeND;)Ljava/util/List;
|
||||
public static final fun component1 (Lspace/kscience/kmath/nd/ShapeND;)I
|
||||
public static final fun component2 (Lspace/kscience/kmath/nd/ShapeND;)I
|
||||
public static final fun component3 (Lspace/kscience/kmath/nd/ShapeND;)I
|
||||
public static final fun contentEquals (Lspace/kscience/kmath/nd/ShapeND;Lspace/kscience/kmath/nd/ShapeND;)Z
|
||||
public static final fun contentHashCode (Lspace/kscience/kmath/nd/ShapeND;)I
|
||||
public static final fun first (Lspace/kscience/kmath/nd/ShapeND;)I
|
||||
public static final fun first (Lspace/kscience/kmath/nd/ShapeND;I)Lspace/kscience/kmath/nd/ShapeND;
|
||||
public static final fun forEach (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function1;)V
|
||||
public static final fun forEachIndexed (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function2;)V
|
||||
public static final fun getIndices (Lspace/kscience/kmath/nd/ShapeND;)Lkotlin/ranges/IntRange;
|
||||
public static final fun getLinearSize (Lspace/kscience/kmath/nd/ShapeND;)I
|
||||
public static final fun isEmpty (Lspace/kscience/kmath/nd/ShapeND;)Z
|
||||
public static final fun isNotEmpty (Lspace/kscience/kmath/nd/ShapeND;)Z
|
||||
public static final fun last (Lspace/kscience/kmath/nd/ShapeND;)I
|
||||
public static final fun last (Lspace/kscience/kmath/nd/ShapeND;I)Lspace/kscience/kmath/nd/ShapeND;
|
||||
public static final fun plus (Lspace/kscience/kmath/nd/ShapeND;Lspace/kscience/kmath/nd/ShapeND;)Lspace/kscience/kmath/nd/ShapeND;
|
||||
public static final fun plus (Lspace/kscience/kmath/nd/ShapeND;[I)Lspace/kscience/kmath/nd/ShapeND;
|
||||
public static final fun slice (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/ranges/IntRange;)Lspace/kscience/kmath/nd/ShapeND;
|
||||
public static final fun toArray (Lspace/kscience/kmath/nd/ShapeND;)[I
|
||||
public static final fun transposed (Lspace/kscience/kmath/nd/ShapeND;II)Lspace/kscience/kmath/nd/ShapeND;
|
||||
}
|
||||
|
||||
public abstract class space/kscience/kmath/nd/Strides : space/kscience/kmath/nd/ShapeIndexer {
|
||||
@@ -1453,7 +1445,7 @@ public abstract interface class space/kscience/kmath/nd/Structure2D : space/ksci
|
||||
public fun getColumns ()Ljava/util/List;
|
||||
public abstract fun getRowNum ()I
|
||||
public fun getRows ()Ljava/util/List;
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/Structure2D$Companion {
|
||||
@@ -1473,7 +1465,7 @@ public abstract interface class space/kscience/kmath/nd/StructureND : space/ksci
|
||||
public abstract fun get ([I)Ljava/lang/Object;
|
||||
public fun getAttributes ()Lspace/kscience/attributes/Attributes;
|
||||
public fun getDimension ()I
|
||||
public abstract fun getShape-IIYLAfE ()[I
|
||||
public abstract fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/StructureND$Companion {
|
||||
@@ -1484,9 +1476,9 @@ public final class space/kscience/kmath/nd/StructureND$Companion {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/nd/StructureNDKt {
|
||||
public static final fun BufferND--rwW0uw (Lkotlin/reflect/KType;Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public static final fun BufferND--rwW0uw (Lkotlin/reflect/KType;Lspace/kscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public static final fun BufferND--rwW0uw (Lkotlin/reflect/KType;[ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public static final fun BufferND-vHyE91E (Lkotlin/reflect/KType;[ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND;
|
||||
public static final fun contentEquals (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Z
|
||||
public static final fun contentEquals (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Comparable;)Z
|
||||
public static final fun contentEquals (Lspace/kscience/kmath/nd/AlgebraND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Z
|
||||
@@ -1506,15 +1498,15 @@ public abstract interface class space/kscience/kmath/nd/StructureNDOfInt : space
|
||||
}
|
||||
|
||||
public class space/kscience/kmath/nd/VirtualStructureND : space/kscience/kmath/nd/StructureND {
|
||||
public synthetic fun <init> ([ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (Lspace/kscience/kmath/nd/ShapeND;Lkotlin/jvm/functions/Function1;)V
|
||||
public fun get ([I)Ljava/lang/Object;
|
||||
public final fun getProducer ()Lkotlin/jvm/functions/Function1;
|
||||
public fun getShape-IIYLAfE ()[I
|
||||
public fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/kmath/nd/WithShape {
|
||||
public fun getIndices ()Lspace/kscience/kmath/nd/ShapeIndexer;
|
||||
public abstract fun getShape-IIYLAfE ()[I
|
||||
public abstract fun getShape ()Lspace/kscience/kmath/nd/ShapeND;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/kmath/operations/Algebra : space/kscience/attributes/WithType {
|
||||
@@ -2429,9 +2421,6 @@ public final class space/kscience/kmath/structures/BufferListKt {
|
||||
public static final fun asList (Lspace/kscience/kmath/structures/Buffer;)Ljava/util/List;
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/structures/BufferPrimitiveAccessKt {
|
||||
}
|
||||
|
||||
public final class space/kscience/kmath/structures/BufferSlice : space/kscience/kmath/structures/BufferView {
|
||||
public fun <init> (Lspace/kscience/kmath/structures/Buffer;II)V
|
||||
public synthetic fun <init> (Lspace/kscience/kmath/structures/Buffer;IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
|
||||
@@ -6,10 +6,10 @@ kscience {
|
||||
jvm()
|
||||
js()
|
||||
native()
|
||||
wasm()
|
||||
wasmJs()
|
||||
|
||||
dependencies {
|
||||
api(projects.attributesKt)
|
||||
api(libs.attributes)
|
||||
}
|
||||
|
||||
testDependencies {
|
||||
@@ -44,7 +44,12 @@ readme {
|
||||
feature(
|
||||
id = "linear",
|
||||
ref = "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." }
|
||||
) {
|
||||
"""
|
||||
Basic linear algebra operations (sums, products, etc.), backed by the `Space` API.
|
||||
Advanced linear algebra operations like matrix inversion and LU decomposition.
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
feature(
|
||||
id = "buffers",
|
||||
@@ -56,7 +61,7 @@ readme {
|
||||
ref = "src/commonMain/kotlin/space/kscience/kmath/expressions"
|
||||
) {
|
||||
"""
|
||||
By writing a single mathematical expression once, users will be able to apply different types of
|
||||
By writing a single mathematical expression once, users will be able to apply different types of
|
||||
objects to the expression by providing a context. Expressions can be used for a wide variety of purposes from high
|
||||
performance calculations to code generation.
|
||||
""".trimIndent()
|
||||
|
||||
@@ -23,7 +23,7 @@ public abstract class Domain1D<T : Comparable<T>>(public val range: ClosedRange<
|
||||
|
||||
@UnstableKMathAPI
|
||||
public class DoubleDomain1D(
|
||||
@Suppress("CanBeParameter") public val doubleRange: ClosedFloatingPointRange<Float64>,
|
||||
public val doubleRange: ClosedFloatingPointRange<Float64>,
|
||||
) : Domain1D<Float64>(doubleRange), Float64Domain {
|
||||
override fun getLowerBound(num: Int): Double {
|
||||
require(num == 0)
|
||||
|
||||
@@ -126,7 +126,7 @@ public class DSCompiler<T, out A : Algebra<T>> internal constructor(
|
||||
* If all orders are set to 0, then the 0<sup>th</sup> order derivative is returned, which is the value of the
|
||||
* function.
|
||||
*
|
||||
* The indices of derivatives are between 0 and [size] − 1. Their specific order is fixed for a given compiler, but
|
||||
* The indices of derivatives are between 0 and [getSize] − 1. Their specific order is fixed for a given compiler, but
|
||||
* otherwise not publicly specified. There are however some simple cases which have guaranteed indices:
|
||||
*
|
||||
* * the index of 0<sup>th</sup> order derivative is always 0
|
||||
@@ -209,12 +209,12 @@ internal fun <T, A> DSCompiler<T, A>.pow(
|
||||
n: Int,
|
||||
result: MutableBuffer<T>,
|
||||
resultOffset: Int,
|
||||
) where A : Field<T>, A : PowerOperations<T> = algebra {
|
||||
): Unit where A : Field<T>, A : PowerOperations<T> = algebra {
|
||||
if (n == 0) {
|
||||
// special case, x^0 = 1 for all x
|
||||
result[resultOffset] = one
|
||||
result.fill(zero, resultOffset + 1, resultOffset + size)
|
||||
return
|
||||
return Unit
|
||||
}
|
||||
|
||||
// create the power function value and derivatives
|
||||
|
||||
@@ -69,6 +69,9 @@ public interface SymbolIndexer {
|
||||
public fun Map<Symbol, Double>.toDoubleArray(): DoubleArray = DoubleArray(symbols.size) { getValue(symbols[it]) }
|
||||
}
|
||||
|
||||
@UnstableKMathAPI
|
||||
public val SymbolIndexer.size: Int get() = symbols.size
|
||||
|
||||
@UnstableKMathAPI
|
||||
@JvmInline
|
||||
public value class SimpleSymbolIndexer(override val symbols: List<Symbol>) : SymbolIndexer
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
package space.kscience.kmath.linear
|
||||
|
||||
/**
|
||||
* A group of methods to solve for *X* in equation *X = A<sup>−1</sup> · B*, where *A* and *B* are
|
||||
* A group of methods to solve for $X$ in equation $X = A^{-1} \cdot B$, where $A$ and $B$ are
|
||||
* matrices or vectors.
|
||||
*
|
||||
* @param T the type of items.
|
||||
|
||||
@@ -5,13 +5,20 @@
|
||||
|
||||
package space.kscience.kmath.linear
|
||||
|
||||
import space.kscience.attributes.*
|
||||
import space.kscience.attributes.Attributes
|
||||
import space.kscience.attributes.SafeType
|
||||
import space.kscience.attributes.withAttribute
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.nd.*
|
||||
import space.kscience.kmath.nd.MutableStructure2D
|
||||
import space.kscience.kmath.nd.Structure2D
|
||||
import space.kscience.kmath.nd.StructureAttribute
|
||||
import space.kscience.kmath.nd.as1D
|
||||
import space.kscience.kmath.operations.BufferRingOps
|
||||
import space.kscience.kmath.operations.Ring
|
||||
import space.kscience.kmath.operations.invoke
|
||||
import space.kscience.kmath.structures.Buffer
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
|
||||
/**
|
||||
* Alias for [Structure2D] with more familiar name.
|
||||
@@ -179,7 +186,7 @@ public interface LinearSpace<T, out A : Ring<T>> : MatrixScope<T> {
|
||||
* If the structure holds given [attribute] return itself. Otherwise, return a new [Matrix] that contains a computed attribute.
|
||||
*
|
||||
* This method is used to compute and cache attribute inside the structure. If one needs an attribute only once,
|
||||
* better use [StructureND.getOrComputeAttribute].
|
||||
* better use [Structure2D.getOrComputeAttribute].
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public fun <V : Any, A : StructureAttribute<V>> Matrix<T>.withComputedAttribute(
|
||||
@@ -210,7 +217,12 @@ public interface LinearSpace<T, out A : Ring<T>> : MatrixScope<T> {
|
||||
}
|
||||
|
||||
|
||||
public inline operator fun <LS : LinearSpace<*, *>, R> LS.invoke(block: LS.() -> R): R = run(block)
|
||||
public inline operator fun <LS : LinearSpace<*, *>, R> LS.invoke(block: LS.() -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return this.block()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,9 @@ import space.kscience.kmath.PerformancePitfall
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.nd.*
|
||||
import space.kscience.kmath.operations.*
|
||||
import space.kscience.kmath.structures.*
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.kmath.structures.IntBuffer
|
||||
import space.kscience.kmath.structures.asBuffer
|
||||
|
||||
public interface LupDecomposition<T> {
|
||||
public val pivot: IntBuffer
|
||||
@@ -47,7 +49,7 @@ public class GenericLupDecomposition<T>(
|
||||
|
||||
|
||||
override val l: Matrix<T>
|
||||
get() = VirtualMatrix(lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular)) { i, j ->
|
||||
get() = VirtualMatrix(lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular, true)) { i, j ->
|
||||
when {
|
||||
j < i -> lu[i, j]
|
||||
j == i -> elementAlgebra.one
|
||||
@@ -56,7 +58,7 @@ public class GenericLupDecomposition<T>(
|
||||
}
|
||||
|
||||
override val u: Matrix<T>
|
||||
get() = VirtualMatrix(lu.rowNum, lu.colNum, attributes = Attributes(UpperTriangular)) { i, j ->
|
||||
get() = VirtualMatrix(lu.rowNum, lu.colNum, attributes = Attributes(UpperTriangular,true)) { i, j ->
|
||||
if (j >= i) lu[i, j] else elementAlgebra.zero
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package space.kscience.kmath.linear
|
||||
|
||||
import space.kscience.attributes.FlagAttribute
|
||||
import space.kscience.attributes.Attributes
|
||||
import space.kscience.attributes.SafeType
|
||||
import space.kscience.attributes.WithType
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
@@ -13,62 +13,51 @@ import space.kscience.kmath.operations.Ring
|
||||
import space.kscience.kmath.structures.BufferAccessor2D
|
||||
import space.kscience.kmath.structures.MutableBufferFactory
|
||||
|
||||
public class MatrixBuilder<T : Any, out A : Ring<T>>(
|
||||
/**
|
||||
* A builder for matrix with fixed size
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public class MatrixBuilder<T, out A : Ring<T>>(
|
||||
public val linearSpace: LinearSpace<T, A>,
|
||||
public val rows: Int,
|
||||
public val columns: Int,
|
||||
public val rowNum: Int,
|
||||
public val colNum: Int,
|
||||
) : WithType<T> {
|
||||
|
||||
override val type: SafeType<T> get() = linearSpace.type
|
||||
|
||||
public operator fun invoke(vararg elements: T): Matrix<T> {
|
||||
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
|
||||
@UnstableKMathAPI
|
||||
public fun <T, A : Ring<T>> MatrixBuilder<T, A>.sparse(): SparseMatrix<T> =
|
||||
SparseMatrix(rowNum, colNum, linearSpace.elementAlgebra.zero)
|
||||
|
||||
@UnstableKMathAPI
|
||||
public fun <T, A : Ring<T>> MatrixBuilder<T, A>.fill(vararg elements: T): Matrix<T> {
|
||||
require(rowNum * colNum == elements.size) { "The number of elements ${elements.size} is not equal $rowNum * $colNum" }
|
||||
return linearSpace.buildMatrix(rowNum, colNum) { i, j -> elements[i * colNum + j] }
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a matrix builder with given number of rows and columns
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public fun <T : Any, A : Ring<T>> LinearSpace<T, A>.matrix(rows: Int, columns: Int): MatrixBuilder<T, A> =
|
||||
public fun <T, A : Ring<T>> LinearSpace<T, A>.MatrixBuilder(rows: Int, columns: Int): MatrixBuilder<T, A> =
|
||||
MatrixBuilder(this, rows, columns)
|
||||
|
||||
@UnstableKMathAPI
|
||||
public fun <T : Any> LinearSpace<T, Ring<T>>.vector(vararg elements: T): Point<T> {
|
||||
return buildVector(elements.size) { elements[it] }
|
||||
}
|
||||
|
||||
public inline fun <T : Any> LinearSpace<T, Ring<T>>.row(
|
||||
size: Int,
|
||||
crossinline builder: (Int) -> T,
|
||||
): Matrix<T> = buildMatrix(1, size) { _, j -> builder(j) }
|
||||
|
||||
public fun <T : Any> LinearSpace<T, Ring<T>>.row(vararg values: T): Matrix<T> = row(values.size, values::get)
|
||||
|
||||
public inline fun <T : Any> LinearSpace<T, Ring<T>>.column(
|
||||
size: Int,
|
||||
crossinline builder: (Int) -> T,
|
||||
): Matrix<T> = buildMatrix(size, 1) { i, _ -> builder(i) }
|
||||
|
||||
public fun <T : Any> LinearSpace<T, Ring<T>>.column(vararg values: T): Matrix<T> = column(values.size, values::get)
|
||||
|
||||
public object Symmetric : MatrixAttribute<Unit>, FlagAttribute
|
||||
|
||||
/**
|
||||
* Naive implementation of a symmetric matrix builder, that adds a [Symmetric] tag. The resulting matrix contains
|
||||
* full `size^2` number of elements, but caches elements during calls to save [builder] calls. [builder] is always called in the
|
||||
* upper triangle region meaning that `i <= j`
|
||||
* Naive implementation of a symmetric matrix builder, that adds a [Symmetric] tag.
|
||||
* The resulting matrix contains full `size^2` number of elements,
|
||||
* but caches elements during calls to save [builder] calls.
|
||||
* Always called in the upper triangle region meaning that `i <= j`
|
||||
*/
|
||||
public fun <T : Any, A : Ring<T>> MatrixBuilder<T, A>.symmetric(
|
||||
builder: (i: Int, j: Int) -> T,
|
||||
@UnstableKMathAPI
|
||||
public fun <T, A : Ring<T>> MatrixBuilder<T, A>.symmetric(
|
||||
builder: A.(i: Int, j: Int) -> T,
|
||||
): Matrix<T> {
|
||||
require(columns == rows) { "In order to build symmetric matrix, number of rows $rows should be equal to number of columns $columns" }
|
||||
return with(BufferAccessor2D<T?>(rows, rows, MutableBufferFactory(type))) {
|
||||
require(colNum == rowNum) { "In order to build symmetric matrix, number of rows $rowNum should be equal to number of columns $colNum" }
|
||||
return with(BufferAccessor2D<T?>(rowNum, rowNum, MutableBufferFactory(type))) {
|
||||
val cache = HashMap<IntArray, T>()
|
||||
linearSpace.buildMatrix(rows, rows) { i, j ->
|
||||
linearSpace.buildMatrix(this@symmetric.rowNum, this@symmetric.rowNum) { i, j ->
|
||||
val index = intArrayOf(i, j)
|
||||
val cached = cache[index]
|
||||
if (cached == null) {
|
||||
@@ -81,4 +70,51 @@ public fun <T : Any, A : Ring<T>> MatrixBuilder<T, A>.symmetric(
|
||||
}
|
||||
}.withAttribute(Symmetric)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a diagonal matrix with given factory.
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public fun <T, A : Ring<T>> MatrixBuilder<T, A>.diagonal(
|
||||
builder: A.(Int) -> T
|
||||
): Matrix<T> = with(linearSpace.elementAlgebra) {
|
||||
require(colNum == rowNum) { "In order to build symmetric matrix, number of rows $rowNum should be equal to number of columns $colNum" }
|
||||
return VirtualMatrix(rowNum, colNum, attributes = Attributes(IsDiagonal, true)) { i, j ->
|
||||
check(i in 0 until rowNum) { "$i out of bounds: 0..<$rowNum" }
|
||||
check(j in 0 until colNum) { "$j out of bounds: 0..<$colNum" }
|
||||
if (i == j) {
|
||||
builder(i)
|
||||
} else {
|
||||
zero
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a diagonal matrix from elements
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public fun <T> MatrixBuilder<T, Ring<T>>.diagonal(vararg elements: T): Matrix<T> {
|
||||
require(colNum == rowNum) { "In order to build symmetric matrix, number of rows $rowNum should be equal to number of columns $colNum" }
|
||||
|
||||
return VirtualMatrix(rowNum, colNum, attributes = Attributes(IsDiagonal,true)) { i, j ->
|
||||
check(i in 0 until rowNum) { "$i out of bounds: 0..<$rowNum" }
|
||||
check(j in 0 until colNum) { "$j out of bounds: 0..<$colNum" }
|
||||
if (i == j) {
|
||||
elements[i]
|
||||
} else {
|
||||
linearSpace.elementAlgebra.zero
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a lazily evaluated virtual matrix with a given size
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public fun <T : Any> MatrixBuilder<T, *>.virtual(
|
||||
attributes: Attributes = Attributes.EMPTY,
|
||||
generator: (i: Int, j: Int) -> T,
|
||||
): VirtualMatrix<T> = VirtualMatrix(rowNum, colNum, attributes, generator)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package space.kscience.kmath.linear
|
||||
import space.kscience.attributes.Attribute
|
||||
import space.kscience.attributes.Attributes
|
||||
import space.kscience.attributes.withAttribute
|
||||
import space.kscience.attributes.withFlag
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.operations.Ring
|
||||
|
||||
@@ -35,8 +36,8 @@ public val <T : Any> Matrix<T>.origin: Matrix<T>
|
||||
/**
|
||||
* Add a single feature to a [Matrix]
|
||||
*/
|
||||
public fun <T, A : Attribute<T>> Matrix<T>.withAttribute(
|
||||
attribute: A,
|
||||
public fun <T> Matrix<T>.withAttribute(
|
||||
attribute: Attribute<T>,
|
||||
attrValue: T,
|
||||
): MatrixWrapper<T> = if (this is MatrixWrapper) {
|
||||
MatrixWrapper(origin, attributes.withAttribute(attribute, attrValue))
|
||||
@@ -44,14 +45,26 @@ public fun <T, A : Attribute<T>> Matrix<T>.withAttribute(
|
||||
MatrixWrapper(this, Attributes(attribute, attrValue))
|
||||
}
|
||||
|
||||
public fun <T, A : Attribute<Unit>> Matrix<T>.withAttribute(
|
||||
attribute: A,
|
||||
public fun <T> Matrix<T>.withAttribute(
|
||||
attribute: Attribute<Unit>,
|
||||
): MatrixWrapper<T> = if (this is MatrixWrapper) {
|
||||
MatrixWrapper(origin, attributes.withAttribute(attribute))
|
||||
MatrixWrapper(origin, attributes.withFlag(attribute))
|
||||
} else {
|
||||
MatrixWrapper(this, Attributes(attribute, Unit))
|
||||
}
|
||||
|
||||
/**
|
||||
* Add boolean attribute with default value `true`
|
||||
*/
|
||||
public fun <T> Matrix<T>.withAttribute(
|
||||
attribute: Attribute<Boolean>,
|
||||
value: Boolean = true
|
||||
): MatrixWrapper<T> = if (this is MatrixWrapper) {
|
||||
MatrixWrapper(origin, attributes.withAttribute(attribute, value))
|
||||
} else {
|
||||
MatrixWrapper(this, Attributes(attribute, value))
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify matrix attributes
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2018-2025 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.kmath.linear
|
||||
|
||||
import space.kscience.attributes.Attributes
|
||||
import space.kscience.kmath.PerformancePitfall
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.operations.Ring
|
||||
|
||||
/**
|
||||
* Mutable sparse matrix that stores values only for non-zero cells ([DOK format](https://en.wikipedia.org/wiki/Sparse_matrix#Dictionary_of_keys_(DOK))).
|
||||
*
|
||||
* [SparseMatrix] is ineffective, but does not depend on particular [LinearSpace]
|
||||
*
|
||||
* Using this class is almost always a [PerformancePitfall]. It should be used only for special cases like manual matrix building.
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public class SparseMatrix<T>(
|
||||
override val rowNum: Int,
|
||||
override val colNum: Int,
|
||||
private val zero: T,
|
||||
cells: Map<Pair<Int, Int>, T> = emptyMap(),
|
||||
override val attributes: Attributes = Attributes.EMPTY,
|
||||
) : MutableMatrix<T> {
|
||||
|
||||
private val cells = cells.toMutableMap()
|
||||
|
||||
override fun get(i: Int, j: Int): T {
|
||||
if (i !in 0 until rowNum) throw IndexOutOfBoundsException("Row index $i out of row range 0..$rowNum")
|
||||
if (j !in 0 until colNum) throw IndexOutOfBoundsException("Column index $j out of column range 0..$colNum")
|
||||
return cells[i to j] ?: zero
|
||||
}
|
||||
|
||||
override fun set(i: Int, j: Int, value: T) {
|
||||
require(i in 0 until rowNum) { "Row index $i is out of bounds: 0..<$rowNum" }
|
||||
require(j in 0 until colNum) { "Row index $j is out of bounds: 0..<$colNum" }
|
||||
val coordinates = i to j
|
||||
if (cells[coordinates] != null || value != zero) {
|
||||
cells[coordinates] = value
|
||||
}
|
||||
}
|
||||
|
||||
override fun set(index: IntArray, value: T) {
|
||||
require(index.size == 2) { "Index array must contain two elements." }
|
||||
set(index[0], index[1], value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and optionally fill DOK [SparseMatrix]. Those matrices must be converted to dense or effective sparse form
|
||||
* after creation for effective use.
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public fun <T> LinearSpace<T, Ring<T>>.sparse(
|
||||
rows: Int,
|
||||
columns: Int,
|
||||
attributes: Attributes = Attributes.EMPTY,
|
||||
builder: SparseMatrix<T>.() -> Unit = {}
|
||||
): SparseMatrix<T> = SparseMatrix(rows, columns, elementAlgebra.zero, attributes = attributes).apply(builder)
|
||||
@@ -6,7 +6,6 @@
|
||||
package space.kscience.kmath.linear
|
||||
|
||||
import space.kscience.attributes.Attributes
|
||||
import space.kscience.kmath.nd.ShapeND
|
||||
|
||||
|
||||
/**
|
||||
@@ -20,13 +19,5 @@ public class VirtualMatrix<out T>(
|
||||
override val attributes: Attributes = Attributes.EMPTY,
|
||||
public val generator: (i: Int, j: Int) -> T,
|
||||
) : Matrix<T> {
|
||||
|
||||
override val shape: ShapeND get() = ShapeND(rowNum, colNum)
|
||||
|
||||
override operator fun get(i: Int, j: Int): T = generator(i, j)
|
||||
}
|
||||
|
||||
public fun <T : Any> MatrixBuilder<T, *>.virtual(
|
||||
attributes: Attributes = Attributes.EMPTY,
|
||||
generator: (i: Int, j: Int) -> T,
|
||||
): VirtualMatrix<T> = VirtualMatrix(rows, columns, attributes, generator)
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import space.kscience.kmath.nd.StructureAttribute
|
||||
* A marker interface for algebras that operate on matrices
|
||||
* @param T type of matrix element
|
||||
*/
|
||||
public interface MatrixScope<T> : AttributeScope<Matrix<T>>, WithType<T>
|
||||
public interface MatrixScope<T> : WithType<T>
|
||||
|
||||
/**
|
||||
* A marker interface representing some properties of matrices or additional transformations of them. Features are used
|
||||
@@ -23,10 +23,20 @@ public interface MatrixScope<T> : AttributeScope<Matrix<T>>, WithType<T>
|
||||
*/
|
||||
public interface MatrixAttribute<T> : StructureAttribute<T>
|
||||
|
||||
public typealias BooleanAttribute = Attribute<Boolean>
|
||||
|
||||
|
||||
/**
|
||||
* Matrices with this feature are symmetric, meaning `matrix[i,j] == matrix[j,i]`
|
||||
*/
|
||||
public interface Symmetric : MatrixAttribute<Boolean> {
|
||||
public companion object : Symmetric
|
||||
}
|
||||
|
||||
/**
|
||||
* Matrices with this feature are considered to have only diagonal non-zero elements.
|
||||
*/
|
||||
public interface IsDiagonal : MatrixAttribute<Unit>, FlagAttribute {
|
||||
public interface IsDiagonal : Symmetric {
|
||||
public companion object : IsDiagonal
|
||||
}
|
||||
|
||||
@@ -65,12 +75,12 @@ public val <T> MatrixScope<T>.Determinant: Determinant<T> get() = Determinant(ty
|
||||
/**
|
||||
* Matrices with this feature are lower triangular ones.
|
||||
*/
|
||||
public object LowerTriangular : MatrixAttribute<Unit>, FlagAttribute
|
||||
public object LowerTriangular : MatrixAttribute<Boolean>
|
||||
|
||||
/**
|
||||
* Matrices with this feature are upper triangular ones.
|
||||
*/
|
||||
public object UpperTriangular : MatrixAttribute<Unit>, FlagAttribute
|
||||
public object UpperTriangular : MatrixAttribute<Boolean>
|
||||
|
||||
/**
|
||||
* Matrices with this feature support LU factorization: *a = [l] · [u]* where *a* is the owning matrix.
|
||||
@@ -95,7 +105,7 @@ public val <T> MatrixScope<T>.LU: LuDecompositionAttribute<T> get() = LuDecompos
|
||||
* Matrices with this feature are orthogonal ones: *a · a<sup>T</sup> = u* where *a* is the owning matrix, *u*
|
||||
* is the unit matrix ([IsUnit]).
|
||||
*/
|
||||
public object OrthogonalAttribute : MatrixAttribute<Unit>, FlagAttribute
|
||||
public object OrthogonalAttribute : MatrixAttribute<Boolean>
|
||||
|
||||
|
||||
public interface QRDecomposition<out T> {
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2018-2025 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.kmath.linear
|
||||
|
||||
import space.kscience.kmath.PerformancePitfall
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.operations.Ring
|
||||
|
||||
|
||||
/**
|
||||
* Create a vector from elements
|
||||
*/
|
||||
public fun <T> LinearSpace<T, Ring<T>>.vector(vararg elements: T): Point<T> =
|
||||
buildVector(elements.size) { elements[it] }
|
||||
|
||||
/**
|
||||
* Create a single row matrix
|
||||
*/
|
||||
public inline fun <T, A : Ring<T>> LinearSpace<T, A>.row(
|
||||
size: Int,
|
||||
crossinline builder: A.(Int) -> T,
|
||||
): Matrix<T> = buildMatrix(1, size) { _, j -> builder(j) }
|
||||
|
||||
/**
|
||||
* Create a single row matrix from elements
|
||||
*/
|
||||
public fun <T> LinearSpace<T, Ring<T>>.row(vararg elements: T): Matrix<T> = row(elements.size) { elements[it] }
|
||||
|
||||
/**
|
||||
* Create a single column matrix
|
||||
*/
|
||||
public inline fun <T, A : Ring<T>> LinearSpace<T, A>.column(
|
||||
size: Int,
|
||||
crossinline builder: A.(Int) -> T,
|
||||
): Matrix<T> = buildMatrix(size, 1) { i, _ -> builder(i) }
|
||||
|
||||
/**
|
||||
* Create a single column matrix from elements
|
||||
*/
|
||||
public fun <T> LinearSpace<T, Ring<T>>.column(vararg elements: T): Matrix<T> = column(elements.size) { elements[it] }
|
||||
|
||||
/**
|
||||
* Stack vertically several matrices with the same number of columns.
|
||||
*
|
||||
* Resulting matrix number of rows is the sum of rows in all [matrices]
|
||||
*/
|
||||
@PerformancePitfall
|
||||
@UnstableKMathAPI
|
||||
public fun <T> LinearSpace<T, Ring<T>>.vstack(vararg matrices: Matrix<T>): Matrix<T> {
|
||||
require(matrices.isNotEmpty()) { "No matrices" }
|
||||
val colNum = matrices.first().colNum
|
||||
require(matrices.all { it.colNum == colNum }) { "All matrices must have the same number of columns: $colNum" }
|
||||
|
||||
val rows = matrices.flatMap { it.rows }
|
||||
|
||||
return buildMatrix(matrices.sumOf { it.rowNum }, colNum) { row, column->
|
||||
rows[row][column]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stack horizontally several matrices with the same number of rows.
|
||||
*
|
||||
* Resulting matrix number of co is the sum of rows in all [matrices]
|
||||
*/
|
||||
@PerformancePitfall
|
||||
@UnstableKMathAPI
|
||||
public fun <T> LinearSpace<T, Ring<T>>.hstack(vararg matrices: Matrix<T>): Matrix<T> {
|
||||
require(matrices.isNotEmpty()) { "No matrices" }
|
||||
val rowNum = matrices.first().rowNum
|
||||
require(matrices.all { it.rowNum == rowNum }) { "All matrices must have the same number of rows: $rowNum" }
|
||||
|
||||
val columns = matrices.flatMap { it.columns }
|
||||
|
||||
return buildMatrix(rowNum, matrices.sumOf { it.colNum }) { row, column->
|
||||
columns[column][row]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fill the matrix with given elements. The number of elements must be the same as the number of elements in the matrix.
|
||||
*
|
||||
* This method is used for small matrices and test purposes.
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public fun <T> MutableMatrix<T>.fill(vararg elements: T): MutableMatrix<T> {
|
||||
require(rowNum * colNum == elements.size) { "The number of elements ${elements.size} is not equal $rowNum * $colNum" }
|
||||
for (i in 0 until rowNum) {
|
||||
for (j in 0 until colNum) {
|
||||
set(i, j, elements[i * rowNum + j])
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2018-2024 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:OptIn(UnstableKMathAPI::class)
|
||||
|
||||
package space.kscience.kmath.named
|
||||
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.expressions.SymbolIndexer
|
||||
import space.kscience.kmath.structures.Buffer
|
||||
import space.kscience.kmath.structures.MutableBuffer
|
||||
|
||||
public class NamedBuffer<T>(public val values: Buffer<T>, public val indexer: SymbolIndexer): Buffer<T> by values{
|
||||
public operator fun get(symbol: Symbol): T = values[indexer.indexOf(symbol)]
|
||||
}
|
||||
|
||||
public class NamedMutableBuffer<T>(public val values: MutableBuffer<T>, public val indexer: SymbolIndexer): MutableBuffer<T> by values{
|
||||
public operator fun get(symbol: Symbol): T = values[indexer.indexOf(symbol)]
|
||||
public operator fun set(symbol: Symbol, value: T) { values[indexer.indexOf(symbol)] = value }
|
||||
}
|
||||
@@ -5,14 +5,26 @@
|
||||
|
||||
@file:OptIn(UnstableKMathAPI::class)
|
||||
|
||||
package space.kscience.kmath.expressions
|
||||
package space.kscience.kmath.named
|
||||
|
||||
import space.kscience.kmath.PerformancePitfall
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.expressions.SimpleSymbolIndexer
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.expressions.SymbolIndexer
|
||||
import space.kscience.kmath.linear.Matrix
|
||||
import space.kscience.kmath.structures.getOrNull
|
||||
|
||||
/**
|
||||
* A square matrix that could be accessed via column and row names.
|
||||
*
|
||||
* Multiple symbols could in theory reference the same columns or rows. Some columns could be not references at all.
|
||||
*/
|
||||
public class NamedMatrix<T>(public val values: Matrix<T>, public val indexer: SymbolIndexer) : Matrix<T> by values {
|
||||
init {
|
||||
require(values.rowNum == values.colNum) { "Only square matrices could be named" }
|
||||
}
|
||||
|
||||
public operator fun get(i: Symbol, j: Symbol): T = get(indexer.indexOf(i), indexer.indexOf(j))
|
||||
|
||||
public companion object {
|
||||
@@ -117,12 +117,13 @@ internal class MutableBuffer1DWrapper<T>(val buffer: MutableBuffer<T>) : Mutable
|
||||
/**
|
||||
* Represent a [StructureND] as [Structure1D]. Throw error in case of dimension mismatch.
|
||||
*/
|
||||
public fun <T> StructureND<T>.as1D(): Structure1D<T> = this as? Structure1D<T> ?: 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")
|
||||
public fun <T> StructureND<T>.as1D(): Structure1D<T> =
|
||||
this as? Structure1D<T> ?: 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")
|
||||
|
||||
public fun <T> MutableStructureND<T>.as1D(): MutableStructure1D<T> =
|
||||
this as? MutableStructure1D<T> ?: if (shape.size == 1) {
|
||||
@@ -133,13 +134,3 @@ public fun <T> MutableStructureND<T>.as1D(): MutableStructure1D<T> =
|
||||
* Represent this buffer as 1D structure
|
||||
*/
|
||||
public fun <T> Buffer<T>.asND(): Structure1D<T> = Buffer1DWrapper(this)
|
||||
|
||||
/**
|
||||
* Expose inner buffer of this [Structure1D] if possible
|
||||
*/
|
||||
internal fun <T : Any> Structure1D<T>.asND(): Buffer<T> = when {
|
||||
this is Buffer1DWrapper<T> -> buffer
|
||||
this is Structure1DWrapper && structure is BufferND<T> -> structure.buffer
|
||||
else -> this
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +228,6 @@ public interface MutableStructureND<T> : StructureND<T> {
|
||||
* @param index the indices.
|
||||
* @param value the value.
|
||||
*/
|
||||
@PerformancePitfall
|
||||
public operator fun set(index: IntArray, value: T)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package space.kscience.kmath.nd
|
||||
import space.kscience.kmath.PerformancePitfall
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.kmath.structures.Int32
|
||||
|
||||
public open class VirtualStructureND<T>(
|
||||
override val shape: ShapeND,
|
||||
@@ -22,13 +23,13 @@ public open class VirtualStructureND<T>(
|
||||
}
|
||||
|
||||
@UnstableKMathAPI
|
||||
public class VirtualDoubleStructureND(
|
||||
public class VirtualFloat64StructureND(
|
||||
shape: ShapeND,
|
||||
producer: (IntArray) -> Double,
|
||||
producer: (IntArray) -> Float64,
|
||||
) : VirtualStructureND<Float64>(shape, producer)
|
||||
|
||||
@UnstableKMathAPI
|
||||
public class VirtualIntStructureND(
|
||||
public class VirtualInt32StructureND(
|
||||
shape: ShapeND,
|
||||
producer: (IntArray) -> Int,
|
||||
producer: (IntArray) -> Int32,
|
||||
) : VirtualStructureND<Int>(shape, producer)
|
||||
@@ -11,6 +11,8 @@ import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.operations.Ring.Companion.optimizedPower
|
||||
import space.kscience.kmath.structures.MutableBufferFactory
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
|
||||
/**
|
||||
* Represents an algebraic structure.
|
||||
@@ -122,8 +124,12 @@ public fun <T> Algebra<T>.bindSymbol(symbol: Symbol): T = bindSymbol(symbol.iden
|
||||
/**
|
||||
* Call a block with an [Algebra] as receiver.
|
||||
*/
|
||||
// TODO add contract when KT-32313 is fixed
|
||||
public inline operator fun <A : Algebra<*>, R> A.invoke(block: A.() -> R): R = run(block)
|
||||
public inline operator fun <A : Algebra<*>, R> A.invoke(block: A.() -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return this.block()
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents group without neutral element (also known as inverse semigroup) i.e., algebraic structure with
|
||||
|
||||
@@ -50,6 +50,7 @@ public class BigInt internal constructor(
|
||||
private val sign: Byte,
|
||||
private val magnitude: Magnitude,
|
||||
) : Comparable<BigInt> {
|
||||
|
||||
override fun compareTo(other: BigInt): Int = when {
|
||||
(sign == 0.toByte()) and (other.sign == 0.toByte()) -> 0
|
||||
sign < other.sign -> -1
|
||||
|
||||
@@ -10,7 +10,7 @@ import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.structures.MutableBufferFactory
|
||||
|
||||
/**
|
||||
* An algebra for generic boolean logic
|
||||
* Algebra for generic boolean logic
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public interface LogicAlgebra<T : Any> : Algebra<T> {
|
||||
|
||||
@@ -22,7 +22,7 @@ internal class BufferAccessor2D<T>(
|
||||
}
|
||||
|
||||
inline fun create(crossinline init: (i: Int, j: Int) -> T): MutableBuffer<T> =
|
||||
factory(rowNum * colNum) { offset -> init(offset / colNum, offset % colNum) }
|
||||
factory(this@BufferAccessor2D.rowNum * colNum) { offset -> init(offset / colNum, offset % colNum) }
|
||||
|
||||
fun create(mat: Structure2D<T>): MutableBuffer<T> = create { i, j -> mat[i, j] }
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class DoubleLUSolverTest {
|
||||
|
||||
@Test
|
||||
fun testDecomposition() = with(Double.algebra.linearSpace) {
|
||||
val matrix = matrix(2, 2)(
|
||||
val matrix = MatrixBuilder(2, 2).fill(
|
||||
3.0, 1.0,
|
||||
2.0, 3.0
|
||||
)
|
||||
@@ -44,14 +44,14 @@ class DoubleLUSolverTest {
|
||||
|
||||
@Test
|
||||
fun testInvert() = Double.algebra.linearSpace.run {
|
||||
val matrix = matrix(2, 2)(
|
||||
val matrix = MatrixBuilder(2, 2).fill(
|
||||
3.0, 1.0,
|
||||
1.0, 3.0
|
||||
)
|
||||
|
||||
val inverted = lupSolver().inverse(matrix)
|
||||
|
||||
val expected = matrix(2, 2)(
|
||||
val expected = MatrixBuilder(2, 2).fill(
|
||||
0.375, -0.125,
|
||||
-0.125, 0.375
|
||||
)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2018-2025 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.kmath.linear
|
||||
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.operations.algebra
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import kotlin.test.Test
|
||||
|
||||
@UnstableKMathAPI
|
||||
class MatrixBuilderTest {
|
||||
|
||||
@Test
|
||||
fun buildCompositeMatrix() = with(Float64.algebra.linearSpace) {
|
||||
|
||||
val matrix = vstack(
|
||||
sparse(1, 5) { set(0, 4, 1.0) },
|
||||
hstack(
|
||||
sparse(4, 4).fill(
|
||||
1.0, 1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0, 1.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
),
|
||||
sparse(4, 1)
|
||||
)
|
||||
)
|
||||
|
||||
val expected = sparse(5, 5).fill(
|
||||
0.0, 0.0, 0.0, 0.0, 1.0,
|
||||
1.0, 1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0, 0.0
|
||||
)
|
||||
|
||||
assertMatrixEquals(expected, matrix)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class MatrixTest {
|
||||
|
||||
@Test
|
||||
fun testBuilder() = Double.algebra.linearSpace.run {
|
||||
val matrix = matrix(2, 3)(
|
||||
val matrix = MatrixBuilder(2, 3).fill(
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 2.0
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ class ParallelMatrixTest {
|
||||
|
||||
@Test
|
||||
fun testBuilder() = Float64Field.linearSpace.parallel {
|
||||
val matrix = matrix(2, 3)(
|
||||
val matrix = MatrixBuilder(2, 3).fill(
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 2.0
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:kmath-coroutines:0.4.0`.
|
||||
The Maven coordinates of this project are `space.kscience:kmath-coroutines:0.5.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:kmath-coroutines:0.4.0")
|
||||
implementation("space.kscience:kmath-coroutines:0.5.0")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -6,7 +6,7 @@ kscience {
|
||||
jvm()
|
||||
js()
|
||||
native()
|
||||
wasm()
|
||||
wasmJs()
|
||||
|
||||
dependencies {
|
||||
api(projects.kmathCore)
|
||||
|
||||
@@ -5,27 +5,30 @@
|
||||
|
||||
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 kotlinx.coroutines.flow.transform
|
||||
import space.kscience.kmath.operations.GroupOps
|
||||
import space.kscience.kmath.operations.Ring
|
||||
import space.kscience.kmath.operations.ScaleOperations
|
||||
import space.kscience.kmath.operations.invoke
|
||||
|
||||
public fun <T> Flow<T>.cumulativeSum(group: GroupOps<T>): Flow<T> =
|
||||
group { runningReduce { sum, element -> sum + element } }
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
public fun <T, S> Flow<T>.mean(space: S): Flow<T> where S : Ring<T>, S : ScaleOperations<T> = space {
|
||||
data class Accumulator(var sum: T, var num: Int)
|
||||
|
||||
scan(Accumulator(zero, 0)) { sum, element ->
|
||||
sum.apply {
|
||||
this.sum += element
|
||||
this.num += 1
|
||||
}
|
||||
}.map { it.sum / it.num }
|
||||
/**
|
||||
* Return a [Flow] of a cumulative sum of elements in the flow. The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public fun <T> Flow<T>.cumulativeSum(group: GroupOps<T>): Flow<T> = with(group) {
|
||||
runningReduce { sum, element -> sum + element }
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a [Flow] of mean values of elements in the flow. The operation is _intermediate_ and _stateful_.
|
||||
*/
|
||||
public fun <T, S> Flow<T>.mean(space: S): Flow<T> where S : Ring<T>, S : ScaleOperations<T> = with(space) {
|
||||
var sum = zero
|
||||
var num = 0
|
||||
|
||||
transform {
|
||||
sum += it
|
||||
num++
|
||||
emit(sum / num)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ A proof of concept module for adding type-safe dimensions to structures
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:kmath-dimensions:0.4.0`.
|
||||
The Maven coordinates of this project are `space.kscience:kmath-dimensions:0.5.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@@ -16,6 +16,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:kmath-dimensions:0.4.0")
|
||||
implementation("space.kscience:kmath-dimensions:0.5.0")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -6,7 +6,7 @@ kscience {
|
||||
jvm()
|
||||
js()
|
||||
native()
|
||||
wasm()
|
||||
wasmJs()
|
||||
|
||||
dependencies {
|
||||
api(projects.kmathCore)
|
||||
|
||||
@@ -9,7 +9,7 @@ EJML based linear algebra implementation.
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:kmath-ejml:0.4.0`.
|
||||
The Maven coordinates of this project are `space.kscience:kmath-ejml:0.5.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@@ -19,6 +19,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:kmath-ejml:0.4.0")
|
||||
implementation("space.kscience:kmath-ejml:0.5.0")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -22,16 +22,16 @@ import space.kscience.kmath.structures.Float64
|
||||
* @param M the EJML matrix type.
|
||||
* @author Iaroslav Postovalov
|
||||
*/
|
||||
public abstract class EjmlLinearSpace<T : Any, out A : Ring<T>, out M : org.ejml.data.Matrix> : LinearSpace<T, A> {
|
||||
public interface EjmlLinearSpace<T : Any, out A : Ring<T>, M : org.ejml.data.Matrix> : LinearSpace<T, A> {
|
||||
/**
|
||||
* Converts this matrix to EJML one.
|
||||
*/
|
||||
public abstract fun Matrix<T>.toEjml(): EjmlMatrix<T, M>
|
||||
public fun Matrix<T>.toEjml(): M
|
||||
|
||||
/**
|
||||
* Converts this vector to EJML one.
|
||||
*/
|
||||
public abstract fun Point<T>.toEjml(): EjmlVector<T, M>
|
||||
public fun Point<T>.toEjml(): M
|
||||
|
||||
public abstract override fun buildMatrix(
|
||||
rows: Int,
|
||||
|
||||
@@ -13,10 +13,10 @@ import space.kscience.kmath.nd.Structure2D
|
||||
*
|
||||
* @param T the type of elements contained in the buffer.
|
||||
* @param M the type of EJML matrix.
|
||||
* @property origin The underlying EJML matrix.
|
||||
* @property ejmlMatrix The underlying EJML matrix.
|
||||
* @author Iaroslav Postovalov
|
||||
*/
|
||||
public abstract class EjmlMatrix<out T, out M : Matrix>(public open val origin: M) : Structure2D<T> {
|
||||
override val rowNum: Int get() = origin.numRows
|
||||
override val colNum: Int get() = origin.numCols
|
||||
public abstract class EjmlMatrix<out T, out M : Matrix>(public open val ejmlMatrix: M) : Structure2D<T> {
|
||||
override val rowNum: Int get() = ejmlMatrix.numRows
|
||||
override val colNum: Int get() = ejmlMatrix.numCols
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ import space.kscience.kmath.linear.Point
|
||||
*
|
||||
* @param T the type of elements contained in the buffer.
|
||||
* @param M the type of EJML matrix.
|
||||
* @property origin The underlying matrix, must have only one row.
|
||||
* @property ejmlVector The underlying matrix, must have only one row.
|
||||
* @author Iaroslav Postovalov
|
||||
*/
|
||||
public abstract class EjmlVector<out T, out M : Matrix>(public open val origin: M) : Point<T> {
|
||||
public abstract class EjmlVector<out T, out M : Matrix>(public open val ejmlVector: M) : Point<T> {
|
||||
override val size: Int
|
||||
get() = origin.numCols
|
||||
get() = ejmlVector.numRows
|
||||
|
||||
override operator fun iterator(): Iterator<T> = object : Iterator<T> {
|
||||
private var cursor: Int = 0
|
||||
@@ -28,8 +28,8 @@ public abstract class EjmlVector<out T, out M : Matrix>(public open val origin:
|
||||
return this@EjmlVector[cursor - 1]
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean = cursor < origin.numCols * origin.numRows
|
||||
override fun hasNext(): Boolean = cursor < ejmlVector.numCols * ejmlVector.numRows
|
||||
}
|
||||
|
||||
override fun toString(): String = "EjmlVector(origin=$origin)"
|
||||
override fun toString(): String = "EjmlVector(origin=$ejmlVector)"
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -86,7 +86,7 @@ internal class EjmlMatrixTest {
|
||||
@Test
|
||||
fun origin() {
|
||||
val m = randomMatrix
|
||||
assertSame(m, EjmlDoubleMatrix(m).origin)
|
||||
assertSame(m, EjmlDoubleMatrix(m).ejmlMatrix)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,7 +100,7 @@ internal class EjmlMatrixTest {
|
||||
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 }
|
||||
val inverted = matrix.toEjml().inverted()
|
||||
val inverted = matrix.inverted()
|
||||
|
||||
val res = matrix dot inverted
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ package space.kscience.kmath.ejml
|
||||
|
||||
import org.ejml.data.DMatrixRMaj
|
||||
import org.ejml.dense.row.RandomMatrices_DDRM
|
||||
import space.kscience.kmath.linear.invoke
|
||||
import space.kscience.kmath.structures.asBuffer
|
||||
import space.kscience.kmath.testutils.assertBufferEquals
|
||||
import kotlin.random.Random
|
||||
import kotlin.random.asJavaRandom
|
||||
import kotlin.test.Test
|
||||
@@ -18,7 +21,7 @@ internal class EjmlVectorTest {
|
||||
|
||||
private val randomMatrix: DMatrixRMaj
|
||||
get() {
|
||||
val d = DMatrixRMaj(1, random.nextInt(2, 100))
|
||||
val d = DMatrixRMaj(random.nextInt(2, 100), 1)
|
||||
RandomMatrices_DDRM.fillUniform(d, random.asJavaRandom())
|
||||
return d
|
||||
}
|
||||
@@ -27,7 +30,7 @@ internal class EjmlVectorTest {
|
||||
fun size() {
|
||||
val m = randomMatrix
|
||||
val w = EjmlDoubleVector(m)
|
||||
assertEquals(m.numCols, w.size)
|
||||
assertEquals(m.numRows, w.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +46,7 @@ internal class EjmlVectorTest {
|
||||
val w = EjmlDoubleVector(m)
|
||||
|
||||
assertEquals(
|
||||
m.iterator(true, 0, 0, 0, m.numCols - 1).asSequence().toList(),
|
||||
m.iterator(true, 0, 0, m.numRows - 1, 0).asSequence().toList(),
|
||||
w.iterator().asSequence().toList()
|
||||
)
|
||||
}
|
||||
@@ -52,6 +55,12 @@ internal class EjmlVectorTest {
|
||||
fun origin() {
|
||||
val m = randomMatrix
|
||||
val w = EjmlDoubleVector(m)
|
||||
assertSame(m, w.origin)
|
||||
assertSame(m, w.ejmlVector)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unaryMinus() = EjmlLinearSpaceDDRM {
|
||||
val mu = doubleArrayOf(1.0, 2.0, 3.0).asBuffer()
|
||||
assertBufferEquals(mu, -(-mu))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ Specialization of KMath APIs for Double numbers.
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:kmath-for-real:0.4.0`.
|
||||
The Maven coordinates of this project are `space.kscience:kmath-for-real:0.5.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@@ -19,6 +19,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:kmath-for-real:0.4.0")
|
||||
implementation("space.kscience:kmath-for-real:0.5.0")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -6,7 +6,7 @@ kscience {
|
||||
jvm()
|
||||
js()
|
||||
native()
|
||||
wasm()
|
||||
wasmJs()
|
||||
|
||||
dependencies {
|
||||
api(projects.kmathCore)
|
||||
|
||||
@@ -37,8 +37,8 @@ public fun realMatrix(rowNum: Int, colNum: Int, initializer: Float64Field.(i: In
|
||||
Double.algebra.linearSpace.buildMatrix(rowNum, colNum, initializer)
|
||||
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
public fun realMatrix(rowNum: Int, colNum: Int): MatrixBuilder<Double, Float64Field> =
|
||||
Double.algebra.linearSpace.matrix(rowNum, colNum)
|
||||
public fun MatrixBuilder(rowNum: Int, colNum: Int): MatrixBuilder<Double, Float64Field> =
|
||||
Double.algebra.linearSpace.MatrixBuilder(rowNum, colNum)
|
||||
|
||||
public fun Array<DoubleArray>.toMatrix(): RealMatrix {
|
||||
return Double.algebra.linearSpace.buildMatrix(size, this[0].size) { row, col -> this@toMatrix[row][col] }
|
||||
|
||||
@@ -7,8 +7,9 @@ package space.kscience.kmath.real
|
||||
|
||||
import space.kscience.kmath.PerformancePitfall
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.linear.MatrixBuilder
|
||||
import space.kscience.kmath.linear.fill
|
||||
import space.kscience.kmath.linear.linearSpace
|
||||
import space.kscience.kmath.linear.matrix
|
||||
import space.kscience.kmath.nd.StructureND
|
||||
import space.kscience.kmath.operations.algebra
|
||||
import space.kscience.kmath.testutils.contentEquals
|
||||
@@ -43,11 +44,11 @@ internal class DoubleMatrixTest {
|
||||
|
||||
@Test
|
||||
fun testRepeatStackVertical() {
|
||||
val matrix1 = realMatrix(2, 3)(
|
||||
val matrix1 = MatrixBuilder(2, 3).fill(
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 2.0
|
||||
)
|
||||
val matrix2 = realMatrix(6, 3)(
|
||||
val matrix2 = MatrixBuilder(6, 3).fill(
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 2.0,
|
||||
1.0, 0.0, 0.0,
|
||||
@@ -60,12 +61,12 @@ internal class DoubleMatrixTest {
|
||||
|
||||
@Test
|
||||
fun testMatrixAndDouble() = Double.algebra.linearSpace.run {
|
||||
val matrix1 = realMatrix(2, 3)(
|
||||
val matrix1 = space.kscience.kmath.real.MatrixBuilder(2, 3).fill(
|
||||
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(2, 3)(
|
||||
val expectedResult = this.MatrixBuilder(2, 3).fill(
|
||||
0.75, -0.5, 3.25,
|
||||
4.5, 7.0, 2.0
|
||||
)
|
||||
@@ -74,13 +75,13 @@ internal class DoubleMatrixTest {
|
||||
|
||||
@Test
|
||||
fun testDoubleAndMatrix() {
|
||||
val matrix1 = realMatrix(2, 3)(
|
||||
val matrix1 = MatrixBuilder(2, 3).fill(
|
||||
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 = realMatrix(2, 3)(
|
||||
val expectedResult = MatrixBuilder(2, 3).fill(
|
||||
5.0, 10.0, -5.0,
|
||||
-10.0, -20.0, 0.0
|
||||
)
|
||||
@@ -89,15 +90,15 @@ internal class DoubleMatrixTest {
|
||||
|
||||
@Test
|
||||
fun testSquareAndPower() {
|
||||
val matrix1 = realMatrix(2, 3)(
|
||||
val matrix1 = MatrixBuilder(2, 3).fill(
|
||||
-1.0, 0.0, 3.0,
|
||||
4.0, -6.0, -2.0
|
||||
)
|
||||
val matrix2 = realMatrix(2, 3)(
|
||||
val matrix2 = MatrixBuilder(2, 3).fill(
|
||||
1.0, 0.0, 9.0,
|
||||
16.0, 36.0, 4.0
|
||||
)
|
||||
val matrix3 = realMatrix(2, 3)(
|
||||
val matrix3 = MatrixBuilder(2, 3).fill(
|
||||
-1.0, 0.0, 27.0,
|
||||
64.0, -216.0, -8.0
|
||||
)
|
||||
@@ -108,16 +109,16 @@ internal class DoubleMatrixTest {
|
||||
@OptIn(UnstableKMathAPI::class)
|
||||
@Test
|
||||
fun testTwoMatrixOperations() {
|
||||
val matrix1 = realMatrix(2, 3)(
|
||||
val matrix1 = MatrixBuilder(2, 3).fill(
|
||||
-1.0, 0.0, 3.0,
|
||||
4.0, -6.0, 7.0
|
||||
)
|
||||
val matrix2 = realMatrix(2, 3)(
|
||||
val matrix2 = MatrixBuilder(2, 3).fill(
|
||||
1.0, 0.0, 3.0,
|
||||
4.0, 6.0, -2.0
|
||||
)
|
||||
val result = matrix1 * matrix2 + matrix1 - matrix2
|
||||
val expectedResult = realMatrix(2, 3)(
|
||||
val expectedResult = MatrixBuilder(2, 3).fill(
|
||||
-3.0, 0.0, 9.0,
|
||||
16.0, -48.0, -5.0
|
||||
)
|
||||
@@ -126,16 +127,16 @@ internal class DoubleMatrixTest {
|
||||
|
||||
@Test
|
||||
fun testColumnOperations() {
|
||||
val matrix1 = realMatrix(2, 4)(
|
||||
val matrix1 = MatrixBuilder(2, 4).fill(
|
||||
-1.0, 0.0, 3.0, 15.0,
|
||||
4.0, -6.0, 7.0, -11.0
|
||||
)
|
||||
val matrix2 = realMatrix(2, 5)(
|
||||
val matrix2 = MatrixBuilder(2, 5).fill(
|
||||
-1.0, 0.0, 3.0, 15.0, -1.0,
|
||||
4.0, -6.0, 7.0, -11.0, 4.0
|
||||
)
|
||||
val col1 = realMatrix(2, 1)(0.0, -6.0)
|
||||
val cols1to2 = realMatrix(2, 2)(
|
||||
val col1 = MatrixBuilder(2, 1).fill(0.0, -6.0)
|
||||
val cols1to2 = MatrixBuilder(2, 2).fill(
|
||||
0.0, 3.0,
|
||||
-6.0, 7.0
|
||||
)
|
||||
@@ -160,7 +161,7 @@ internal class DoubleMatrixTest {
|
||||
|
||||
@Test
|
||||
fun testAllElementOperations() = Double.algebra.linearSpace.run {
|
||||
val matrix1 = matrix(2, 4)(
|
||||
val matrix1 = this.MatrixBuilder(2, 4).fill(
|
||||
-1.0, 0.0, 3.0, 15.0,
|
||||
4.0, -6.0, 7.0, -11.0
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ Functions and interpolations.
|
||||
|
||||
## Artifact:
|
||||
|
||||
The Maven coordinates of this project are `space.kscience:kmath-functions:0.4.0`.
|
||||
The Maven coordinates of this project are `space.kscience:kmath-functions:0.5.0`.
|
||||
|
||||
**Gradle Kotlin DSL:**
|
||||
```kotlin
|
||||
@@ -21,6 +21,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("space.kscience:kmath-functions:0.4.0")
|
||||
implementation("space.kscience:kmath-functions:0.5.0")
|
||||
}
|
||||
```
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user