Change package name to space.kscience

This commit is contained in:
Alexander Nozik 2021-02-18 11:17:28 +03:00
parent f201210fa0
commit 8485d28872
229 changed files with 2446 additions and 2405 deletions

View File

@ -21,11 +21,11 @@
- Basic Quaternion vector support in `kmath-complex`. - Basic Quaternion vector support in `kmath-complex`.
### Changed ### Changed
- Package changed from `scientifik` to `kscience.kmath` - Package changed from `scientifik` to `space.kscience`
- Gradle version: 6.6 -> 6.8 - Gradle version: 6.6 -> 6.8.2
- Minor exceptions refactor (throwing `IllegalArgumentException` by argument checks instead of `IllegalStateException`) - Minor exceptions refactor (throwing `IllegalArgumentException` by argument checks instead of `IllegalStateException`)
- `Polynomial` secondary constructor made function - `Polynomial` secondary constructor made function
- Kotlin version: 1.3.72 -> 1.4.21 - Kotlin version: 1.3.72 -> 1.4.30
- `kmath-ast` doesn't depend on heavy `kotlin-reflect` library - `kmath-ast` doesn't depend on heavy `kotlin-reflect` library
- Full autodiff refactoring based on `Symbol` - Full autodiff refactoring based on `Symbol`
- `kmath-prob` renamed to `kmath-stat` - `kmath-prob` renamed to `kmath-stat`
@ -41,6 +41,7 @@
- Refactor histograms. They are marked as prototype - Refactor histograms. They are marked as prototype
- `Complex` and related features moved to a separate module `kmath-complex` - `Complex` and related features moved to a separate module `kmath-complex`
- Refactor AlgebraElement - Refactor AlgebraElement
- `symbol` method in `Algebra` renamed to `bindSymbol` to avoid ambiguity
### Deprecated ### Deprecated

View File

@ -5,8 +5,6 @@ plugins {
} }
internal val kmathVersion: String by extra("0.2.0-dev-7") internal val kmathVersion: String by extra("0.2.0-dev-7")
internal val bintrayRepo: String by extra("kscience")
internal val githubProject: String by extra("kmath")
allprojects { allprojects {
repositories { repositories {
@ -23,7 +21,7 @@ allprojects {
mavenCentral() mavenCentral()
} }
group = "kscience.kmath" group = "space.kscience"
version = kmathVersion version = kmathVersion
} }
@ -37,4 +35,6 @@ readme {
ksciencePublish { ksciencePublish {
spaceRepo = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven" spaceRepo = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven"
bintrayRepo = "kscience"
githubProject = "kmath"
} }

View File

@ -5,7 +5,7 @@ operation, say `+`, one needs two objects of a type `T` and an algebra context,
say `Space<T>`. Next one needs to run the actual operation in the context: say `Space<T>`. Next one needs to run the actual operation in the context:
```kotlin ```kotlin
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
val a: T = ... val a: T = ...
val b: T = ... val b: T = ...
@ -47,7 +47,7 @@ but it also holds reference to the `ComplexField` singleton, which allows perfor
numbers without explicit involving the context like: numbers without explicit involving the context like:
```kotlin ```kotlin
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
// Using elements // Using elements
val c1 = Complex(1.0, 1.0) val c1 = Complex(1.0, 1.0)
@ -82,7 +82,7 @@ operations in all performance-critical places. The performance of element operat
KMath submits both contexts and elements for builtin algebraic structures: KMath submits both contexts and elements for builtin algebraic structures:
```kotlin ```kotlin
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
val c1 = Complex(1.0, 2.0) val c1 = Complex(1.0, 2.0)
val c2 = ComplexField.i val c2 = ComplexField.i
@ -95,7 +95,7 @@ val c3 = ComplexField { c1 + c2 }
Also, `ComplexField` features special operations to mix complex and real numbers, for example: Also, `ComplexField` features special operations to mix complex and real numbers, for example:
```kotlin ```kotlin
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
val c1 = Complex(1.0, 2.0) val c1 = Complex(1.0, 2.0)
val c2 = ComplexField { c1 - 1.0 } // Returns: Complex(re=0.0, im=2.0) val c2 = ComplexField { c1 - 1.0 } // Returns: Complex(re=0.0, im=2.0)

View File

@ -76,6 +76,14 @@ benchmark {
iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds
include("DotBenchmark") include("DotBenchmark")
} }
configurations.register("expressions") {
warmups = 1 // number of warmup iterations
iterations = 3 // number of iterations
iterationTime = 500 // time in seconds per iteration
iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds
include("ExpressionsInterpretersBenchmark")
}
} }
kotlin.sourceSets.all { kotlin.sourceSets.all {

View File

@ -1,34 +0,0 @@
package kscience.kmath.benchmarks
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import java.nio.IntBuffer
@State(Scope.Benchmark)
internal class ArrayBenchmark {
@Benchmark
fun benchmarkArrayRead() {
var res = 0
for (i in 1..size) res += array[size - i]
}
@Benchmark
fun benchmarkBufferRead() {
var res = 0
for (i in 1..size) res += arrayBuffer[size - i]
}
@Benchmark
fun nativeBufferRead() {
var res = 0
for (i in 1..size) res += nativeBuffer[size - i]
}
companion object {
const val size: Int = 1000
val array: IntArray = IntArray(size) { it }
val arrayBuffer: IntBuffer = IntBuffer.wrap(array)
val nativeBuffer: IntBuffer = IntBuffer.allocate(size).also { for (i in 0 until size) it.put(i, i) }
}
}

View File

@ -0,0 +1,34 @@
package space.kscience.kmath.benchmarks
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import java.nio.IntBuffer
@State(Scope.Benchmark)
internal class ArrayBenchmark {
@Benchmark
fun benchmarkArrayRead() {
var res = 0
for (i in 1..space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) res += space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.array[space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size - i]
}
@Benchmark
fun benchmarkBufferRead() {
var res = 0
for (i in 1..space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) res += space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.arrayBuffer[space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size - i]
}
@Benchmark
fun nativeBufferRead() {
var res = 0
for (i in 1..space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) res += space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.nativeBuffer[space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size - i]
}
companion object {
const val size: Int = 1000
val array: IntArray = IntArray(space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) { it }
val arrayBuffer: IntBuffer = IntBuffer.wrap(space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.array)
val nativeBuffer: IntBuffer = IntBuffer.allocate(space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size).also { for (i in 0 until space.kscience.kmath.benchmarks.ArrayBenchmark.Companion.size) it.put(i, i) }
}
}

View File

@ -1,12 +1,12 @@
package kscience.kmath.benchmarks package space.kscience.kmath.benchmarks
import kscience.kmath.complex.Complex
import kscience.kmath.complex.complex
import kscience.kmath.structures.MutableBuffer
import kscience.kmath.structures.RealBuffer
import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State import org.openjdk.jmh.annotations.State
import space.kscience.kmath.complex.Complex
import space.kscience.kmath.complex.complex
import space.kscience.kmath.structures.MutableBuffer
import space.kscience.kmath.structures.RealBuffer
@State(Scope.Benchmark) @State(Scope.Benchmark)
internal class BufferBenchmark { internal class BufferBenchmark {

View File

@ -1,16 +1,16 @@
package kscience.kmath.benchmarks package space.kscience.kmath.benchmarks
import kotlinx.benchmark.Benchmark import kotlinx.benchmark.Benchmark
import kscience.kmath.commons.linear.CMMatrixContext
import kscience.kmath.ejml.EjmlMatrixContext
import kscience.kmath.linear.BufferMatrixContext
import kscience.kmath.linear.Matrix
import kscience.kmath.linear.RealMatrixContext
import kscience.kmath.operations.RealField
import kscience.kmath.operations.invoke
import kscience.kmath.structures.Buffer
import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State import org.openjdk.jmh.annotations.State
import space.kscience.kmath.commons.linear.CMMatrixContext
import space.kscience.kmath.ejml.EjmlMatrixContext
import space.kscience.kmath.linear.BufferMatrixContext
import space.kscience.kmath.linear.Matrix
import space.kscience.kmath.linear.RealMatrixContext
import space.kscience.kmath.operations.RealField
import space.kscience.kmath.operations.invoke
import space.kscience.kmath.structures.Buffer
import kotlin.random.Random import kotlin.random.Random
@State(Scope.Benchmark) @State(Scope.Benchmark)

View File

@ -1,27 +1,29 @@
package kscience.kmath.benchmarks package space.kscience.kmath.benchmarks
import kscience.kmath.asm.compile
import kscience.kmath.ast.MstField
import kscience.kmath.ast.mstInField
import kscience.kmath.expressions.Expression
import kscience.kmath.expressions.expressionInField
import kscience.kmath.expressions.invoke
import kscience.kmath.expressions.symbol
import kscience.kmath.operations.Field
import kscience.kmath.operations.RealField
import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State import org.openjdk.jmh.annotations.State
import space.kscience.kmath.asm.compile
import space.kscience.kmath.ast.mstInField
import space.kscience.kmath.expressions.Expression
import space.kscience.kmath.expressions.expressionInField
import space.kscience.kmath.expressions.invoke
import space.kscience.kmath.expressions.symbol
import space.kscience.kmath.operations.Field
import space.kscience.kmath.operations.RealField
import space.kscience.kmath.operations.bindSymbol
import kotlin.random.Random import kotlin.random.Random
@State(Scope.Benchmark) @State(Scope.Benchmark)
internal class ExpressionsInterpretersBenchmark { internal class ExpressionsInterpretersBenchmark {
private val algebra: Field<Double> = RealField private val algebra: Field<Double> = RealField
val x by symbol
@Benchmark @Benchmark
fun functionalExpression() { fun functionalExpression() {
val expr = algebra.expressionInField { val expr = algebra.expressionInField {
symbol("x") * const(2.0) + const(2.0) / symbol("x") - const(16.0) val x = bindSymbol(x)
x * const(2.0) + const(2.0) / x - const(16.0)
} }
invokeAndSum(expr) invokeAndSum(expr)
@ -30,7 +32,8 @@ internal class ExpressionsInterpretersBenchmark {
@Benchmark @Benchmark
fun mstExpression() { fun mstExpression() {
val expr = algebra.mstInField { val expr = algebra.mstInField {
symbol("x") * 2.0 + 2.0 / symbol("x") - 16.0 val x = bindSymbol(x)
x * 2.0 + 2.0 / x - 16.0
} }
invokeAndSum(expr) invokeAndSum(expr)
@ -39,7 +42,8 @@ internal class ExpressionsInterpretersBenchmark {
@Benchmark @Benchmark
fun asmExpression() { fun asmExpression() {
val expr = algebra.mstInField { val expr = algebra.mstInField {
MstField.symbol("x") * 2.0 + 2.0 / MstField.symbol("x") - 16.0 val x = bindSymbol(x)
x * 2.0 + 2.0 / x - 16.0
}.compile() }.compile()
invokeAndSum(expr) invokeAndSum(expr)
@ -47,8 +51,10 @@ internal class ExpressionsInterpretersBenchmark {
@Benchmark @Benchmark
fun rawExpression() { fun rawExpression() {
val x by symbol val expr = Expression<Double> { args ->
val expr = Expression<Double> { args -> args.getValue(x) * 2.0 + 2.0 / args.getValue(x) - 16.0 } val x = args.getValue(x)
x * 2.0 + 2.0 / x - 16.0
}
invokeAndSum(expr) invokeAndSum(expr)
} }
@ -57,7 +63,7 @@ internal class ExpressionsInterpretersBenchmark {
var sum = 0.0 var sum = 0.0
repeat(1000000) { repeat(1000000) {
sum += expr("x" to random.nextDouble()) sum += expr(x to random.nextDouble())
} }
println(sum) println(sum)

View File

@ -1,17 +1,17 @@
package kscience.kmath.benchmarks package space.kscience.kmath.benchmarks
import kotlinx.benchmark.Benchmark import kotlinx.benchmark.Benchmark
import kscience.kmath.commons.linear.CMMatrixContext
import kscience.kmath.commons.linear.CMMatrixContext.dot
import kscience.kmath.commons.linear.inverse
import kscience.kmath.ejml.EjmlMatrixContext
import kscience.kmath.ejml.inverse
import kscience.kmath.linear.Matrix
import kscience.kmath.linear.MatrixContext
import kscience.kmath.linear.inverseWithLup
import kscience.kmath.linear.real
import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State import org.openjdk.jmh.annotations.State
import space.kscience.kmath.commons.linear.CMMatrixContext
import space.kscience.kmath.commons.linear.CMMatrixContext.dot
import space.kscience.kmath.commons.linear.inverse
import space.kscience.kmath.ejml.EjmlMatrixContext
import space.kscience.kmath.ejml.inverse
import space.kscience.kmath.linear.Matrix
import space.kscience.kmath.linear.MatrixContext
import space.kscience.kmath.linear.inverseWithLup
import space.kscience.kmath.linear.real
import kotlin.random.Random import kotlin.random.Random
@State(Scope.Benchmark) @State(Scope.Benchmark)

View File

@ -1,11 +1,11 @@
package kscience.kmath.benchmarks package space.kscience.kmath.benchmarks
import kscience.kmath.nd.*
import kscience.kmath.operations.RealField
import kscience.kmath.structures.Buffer
import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State import org.openjdk.jmh.annotations.State
import space.kscience.kmath.nd.*
import space.kscience.kmath.operations.RealField
import space.kscience.kmath.structures.Buffer
@State(Scope.Benchmark) @State(Scope.Benchmark)
internal class NDFieldBenchmark { internal class NDFieldBenchmark {

View File

@ -1,12 +1,12 @@
package kscience.kmath.benchmarks package space.kscience.kmath.benchmarks
import kscience.kmath.nd.*
import kscience.kmath.operations.RealField
import kscience.kmath.viktor.ViktorNDField
import org.jetbrains.bio.viktor.F64Array import org.jetbrains.bio.viktor.F64Array
import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State import org.openjdk.jmh.annotations.State
import space.kscience.kmath.nd.*
import space.kscience.kmath.operations.RealField
import space.kscience.kmath.viktor.ViktorNDField
@State(Scope.Benchmark) @State(Scope.Benchmark)
internal class ViktorBenchmark { internal class ViktorBenchmark {

View File

@ -1,12 +1,12 @@
package kscience.kmath.benchmarks package space.kscience.kmath.benchmarks
import kscience.kmath.nd.*
import kscience.kmath.operations.RealField
import kscience.kmath.viktor.ViktorNDField
import org.jetbrains.bio.viktor.F64Array import org.jetbrains.bio.viktor.F64Array
import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State import org.openjdk.jmh.annotations.State
import space.kscience.kmath.nd.*
import space.kscience.kmath.operations.RealField
import space.kscience.kmath.viktor.ViktorNDField
@State(Scope.Benchmark) @State(Scope.Benchmark)
internal class ViktorLogBenchmark { internal class ViktorLogBenchmark {

View File

@ -0,0 +1,15 @@
package space.kscience.kmath.ast
import space.kscience.kmath.expressions.invoke
import space.kscience.kmath.operations.RealField
fun main() {
val expr = RealField.mstInField {
val x = bindSymbol("x")
x * 2.0 + 2.0 / x - 16.0
}
repeat(10000000){
expr.invoke("x" to 1.0)
}
}

View File

@ -1,11 +1,11 @@
package kscience.kmath.ast package space.kscience.kmath.ast
import kscience.kmath.asm.compile import space.kscience.kmath.asm.compile
import kscience.kmath.expressions.derivative import space.kscience.kmath.expressions.derivative
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.expressions.symbol import space.kscience.kmath.expressions.symbol
import kscience.kmath.kotlingrad.differentiable import space.kscience.kmath.kotlingrad.differentiable
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
/** /**
* In this example, x^2-4*x-44 function is differentiated with Kotlin, and the autodiff result is compared with * In this example, x^2-4*x-44 function is differentiated with Kotlin, and the autodiff result is compared with

View File

@ -1,19 +1,19 @@
package kscience.kmath.commons.fit package space.kscience.kmath.commons.fit
import kotlinx.html.br import kotlinx.html.br
import kotlinx.html.h3 import kotlinx.html.h3
import kscience.kmath.commons.optimization.chiSquared
import kscience.kmath.commons.optimization.minimize
import kscience.kmath.expressions.symbol
import kscience.kmath.real.RealVector
import kscience.kmath.real.map
import kscience.kmath.real.step
import kscience.kmath.stat.*
import kscience.kmath.structures.asIterable
import kscience.kmath.structures.toList
import kscience.plotly.* import kscience.plotly.*
import kscience.plotly.models.ScatterMode import kscience.plotly.models.ScatterMode
import kscience.plotly.models.TraceValues import kscience.plotly.models.TraceValues
import space.kscience.kmath.commons.optimization.chiSquared
import space.kscience.kmath.commons.optimization.minimize
import space.kscience.kmath.expressions.symbol
import space.kscience.kmath.real.RealVector
import space.kscience.kmath.real.map
import space.kscience.kmath.real.step
import space.kscience.kmath.stat.*
import space.kscience.kmath.structures.asIterable
import space.kscience.kmath.structures.toList
import kotlin.math.pow import kotlin.math.pow
import kotlin.math.sqrt import kotlin.math.sqrt
@ -63,7 +63,7 @@ fun main() {
val a = bind(a) val a = bind(a)
val b = bind(b) val b = bind(b)
//Include default value for c if it is not provided as a parameter //Include default value for c if it is not provided as a parameter
val c = bindOrNull(c) ?: one val c = bindSymbolOrNull(c) ?: one
a * x1.pow(2) + b * x1 + c a * x1.pow(2) + b * x1 + c
} }

View File

@ -1,4 +1,4 @@
package kscience.kmath.operations package space.kscience.kmath.operations
fun main() { fun main() {
val res = BigIntField { number(1) * 2 } val res = BigIntField { number(1) * 2 }

View File

@ -1,8 +1,8 @@
package kscience.kmath.operations package space.kscience.kmath.operations
import kscience.kmath.complex.Complex import space.kscience.kmath.complex.Complex
import kscience.kmath.complex.complex import space.kscience.kmath.complex.complex
import kscience.kmath.nd.NDAlgebra import space.kscience.kmath.nd.NDAlgebra
fun main() { fun main() {
// 2d element // 2d element

View File

@ -3,9 +3,9 @@ package kscience.kmath.commons.prob
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import kscience.kmath.stat.*
import org.apache.commons.rng.sampling.distribution.ZigguratNormalizedGaussianSampler import org.apache.commons.rng.sampling.distribution.ZigguratNormalizedGaussianSampler
import org.apache.commons.rng.simple.RandomSource import org.apache.commons.rng.simple.RandomSource
import space.kscience.kmath.stat.*
import java.time.Duration import java.time.Duration
import java.time.Instant import java.time.Instant

View File

@ -1,8 +1,8 @@
package kscience.kmath.stat package space.kscience.kmath.stat
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import kscience.kmath.chains.Chain import space.kscience.kmath.chains.Chain
import kscience.kmath.chains.collectWithState import space.kscience.kmath.chains.collectWithState
/** /**
* The state of distribution averager * The state of distribution averager

View File

@ -1,14 +1,14 @@
@file:Suppress("unused") @file:Suppress("unused")
package kscience.kmath.structures package space.kscience.kmath.structures
import kscience.kmath.complex.* import space.kscience.kmath.complex.*
import kscience.kmath.linear.transpose import space.kscience.kmath.linear.transpose
import kscience.kmath.nd.NDAlgebra import space.kscience.kmath.nd.NDAlgebra
import kscience.kmath.nd.NDStructure import space.kscience.kmath.nd.NDStructure
import kscience.kmath.nd.as2D import space.kscience.kmath.nd.as2D
import kscience.kmath.nd.real import space.kscience.kmath.nd.real
import kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import kotlin.system.measureTimeMillis import kotlin.system.measureTimeMillis
fun main() { fun main() {

View File

@ -1,12 +1,12 @@
package kscience.kmath.structures package space.kscience.kmath.structures
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kscience.kmath.nd.*
import kscience.kmath.nd4j.Nd4jArrayField
import kscience.kmath.operations.RealField
import kscience.kmath.operations.invoke
import kscience.kmath.viktor.ViktorNDField
import org.nd4j.linalg.factory.Nd4j import org.nd4j.linalg.factory.Nd4j
import space.kscience.kmath.nd.*
import space.kscience.kmath.nd4j.Nd4jArrayField
import space.kscience.kmath.operations.RealField
import space.kscience.kmath.operations.invoke
import space.kscience.kmath.viktor.ViktorNDField
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract
import kotlin.system.measureTimeMillis import kotlin.system.measureTimeMillis

View File

@ -1,10 +1,10 @@
package kscience.kmath.structures package space.kscience.kmath.structures
import kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.misc.UnstableKMathAPI
import kscience.kmath.nd.* import space.kscience.kmath.nd.*
import kscience.kmath.operations.ExtendedField import space.kscience.kmath.operations.ExtendedField
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
import kscience.kmath.operations.RingWithNumbers import space.kscience.kmath.operations.RingWithNumbers
import java.util.* import java.util.*
import java.util.stream.IntStream import java.util.stream.IntStream

View File

@ -1,7 +1,7 @@
package kscience.kmath.structures package space.kscience.kmath.structures
import kscience.kmath.nd.DefaultStrides import space.kscience.kmath.nd.DefaultStrides
import kscience.kmath.nd.NDBuffer import space.kscience.kmath.nd.NDBuffer
import kotlin.system.measureTimeMillis import kotlin.system.measureTimeMillis
fun main() { fun main() {

View File

@ -1,7 +1,7 @@
package kscience.kmath.structures package space.kscience.kmath.structures
import kscience.kmath.nd.NDStructure import space.kscience.kmath.nd.NDStructure
import kscience.kmath.nd.mapToBuffer import space.kscience.kmath.nd.mapToBuffer
import kotlin.system.measureTimeMillis import kotlin.system.measureTimeMillis
fun main() { fun main() {

View File

@ -1,9 +1,9 @@
package kscience.kmath.structures package space.kscience.kmath.structures
import kscience.kmath.dimensions.D2 import space.kscience.kmath.dimensions.D2
import kscience.kmath.dimensions.D3 import space.kscience.kmath.dimensions.D3
import kscience.kmath.dimensions.DMatrixContext import space.kscience.kmath.dimensions.DMatrixContext
import kscience.kmath.dimensions.Dimension import space.kscience.kmath.dimensions.Dimension
private fun DMatrixContext<Double>.simple() { private fun DMatrixContext<Double>.simple() {
val m1 = produce<D2, D3> { i, j -> (i + j).toDouble() } val m1 = produce<D2, D3> { i, j -> (i + j).toDouble() }

View File

@ -68,9 +68,9 @@ package kscience.kmath.asm.generated;
import java.util.Map; import java.util.Map;
import kotlin.jvm.functions.Function2; import kotlin.jvm.functions.Function2;
import kscience.kmath.asm.internal.MapIntrinsics; import space.kscience.kmath.asm.internal.MapIntrinsics;
import kscience.kmath.expressions.Expression; import space.kscience.kmath.expressions.Expression;
import kscience.kmath.expressions.Symbol; import space.kscience.kmath.expressions.Symbol;
public final class AsmCompiledExpression_45045_0 implements Expression<Double> { public final class AsmCompiledExpression_45045_0 implements Expression<Double> {
private final Object[] constants; private final Object[] constants;

View File

@ -26,9 +26,9 @@ package kscience.kmath.asm.generated;
import java.util.Map; import java.util.Map;
import kotlin.jvm.functions.Function2; import kotlin.jvm.functions.Function2;
import kscience.kmath.asm.internal.MapIntrinsics; import space.kscience.kmath.asm.internal.MapIntrinsics;
import kscience.kmath.expressions.Expression; import space.kscience.kmath.expressions.Expression;
import kscience.kmath.expressions.Symbol; import space.kscience.kmath.expressions.Symbol;
public final class AsmCompiledExpression_45045_0 implements Expression<Double> { public final class AsmCompiledExpression_45045_0 implements Expression<Double> {
private final Object[] constants; private final Object[] constants;

View File

@ -1,7 +1,7 @@
package kscience.kmath.ast package space.kscience.kmath.ast
import kscience.kmath.operations.Algebra import space.kscience.kmath.operations.Algebra
import kscience.kmath.operations.NumericAlgebra import space.kscience.kmath.operations.NumericAlgebra
/** /**
* A Mathematical Syntax Tree (MST) node for mathematical expressions. * A Mathematical Syntax Tree (MST) node for mathematical expressions.
@ -55,7 +55,7 @@ public fun <T> Algebra<T>.evaluate(node: MST): T = when (node) {
is MST.Numeric -> (this as? NumericAlgebra<T>)?.number(node.value) is MST.Numeric -> (this as? NumericAlgebra<T>)?.number(node.value)
?: error("Numeric nodes are not supported by $this") ?: error("Numeric nodes are not supported by $this")
is MST.Symbolic -> symbol(node.value) is MST.Symbolic -> bindSymbol(node.value)
is MST.Unary -> when { is MST.Unary -> when {
this is NumericAlgebra && node.value is MST.Numeric -> unaryOperationFunction(node.operation)(number(node.value.value)) this is NumericAlgebra && node.value is MST.Numeric -> unaryOperationFunction(node.operation)(number(node.value.value))

View File

@ -1,14 +1,14 @@
package kscience.kmath.ast package space.kscience.kmath.ast
import kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.misc.UnstableKMathAPI
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
/** /**
* [Algebra] over [MST] nodes. * [Algebra] over [MST] nodes.
*/ */
public object MstAlgebra : NumericAlgebra<MST> { public object MstAlgebra : NumericAlgebra<MST> {
public override fun number(value: Number): MST.Numeric = MST.Numeric(value) public override fun number(value: Number): MST.Numeric = MST.Numeric(value)
public override fun symbol(value: String): MST.Symbolic = MST.Symbolic(value) public override fun bindSymbol(value: String): MST.Symbolic = MST.Symbolic(value)
public override fun unaryOperationFunction(operation: String): (arg: MST) -> MST.Unary = public override fun unaryOperationFunction(operation: String): (arg: MST) -> MST.Unary =
{ arg -> MST.Unary(operation, arg) } { arg -> MST.Unary(operation, arg) }
@ -24,7 +24,7 @@ public object MstSpace : Space<MST>, NumericAlgebra<MST> {
public override val zero: MST.Numeric by lazy { number(0.0) } public override val zero: MST.Numeric by lazy { number(0.0) }
public override fun number(value: Number): MST.Numeric = MstAlgebra.number(value) public override fun number(value: Number): MST.Numeric = MstAlgebra.number(value)
public override fun symbol(value: String): MST.Symbolic = MstAlgebra.symbol(value) public override fun bindSymbol(value: String): MST.Symbolic = MstAlgebra.bindSymbol(value)
public override fun add(a: MST, b: MST): MST.Binary = binaryOperationFunction(SpaceOperations.PLUS_OPERATION)(a, b) public override fun add(a: MST, b: MST): MST.Binary = binaryOperationFunction(SpaceOperations.PLUS_OPERATION)(a, b)
public override operator fun MST.unaryPlus(): MST.Unary = public override operator fun MST.unaryPlus(): MST.Unary =
unaryOperationFunction(SpaceOperations.PLUS_OPERATION)(this) unaryOperationFunction(SpaceOperations.PLUS_OPERATION)(this)
@ -56,7 +56,7 @@ public object MstRing : Ring<MST>, RingWithNumbers<MST> {
public override val one: MST.Numeric by lazy { number(1.0) } public override val one: MST.Numeric by lazy { number(1.0) }
public override fun number(value: Number): MST.Numeric = MstSpace.number(value) public override fun number(value: Number): MST.Numeric = MstSpace.number(value)
public override fun symbol(value: String): MST.Symbolic = MstSpace.symbol(value) public override fun bindSymbol(value: String): MST.Symbolic = MstSpace.bindSymbol(value)
public override fun add(a: MST, b: MST): MST.Binary = MstSpace.add(a, b) public override fun add(a: MST, b: MST): MST.Binary = MstSpace.add(a, b)
public override fun multiply(a: MST, k: Number): MST.Binary = MstSpace.multiply(a, k) public override fun multiply(a: MST, k: Number): MST.Binary = MstSpace.multiply(a, k)
public override fun multiply(a: MST, b: MST): MST.Binary = public override fun multiply(a: MST, b: MST): MST.Binary =
@ -84,7 +84,7 @@ public object MstField : Field<MST>, RingWithNumbers<MST> {
public override val one: MST.Numeric public override val one: MST.Numeric
get() = MstRing.one get() = MstRing.one
public override fun symbol(value: String): MST.Symbolic = MstRing.symbol(value) public override fun bindSymbol(value: String): MST.Symbolic = MstRing.bindSymbol(value)
public override fun number(value: Number): MST.Numeric = MstRing.number(value) public override fun number(value: Number): MST.Numeric = MstRing.number(value)
public override fun add(a: MST, b: MST): MST.Binary = MstRing.add(a, b) public override fun add(a: MST, b: MST): MST.Binary = MstRing.add(a, b)
public override fun multiply(a: MST, k: Number): MST.Binary = MstRing.multiply(a, k) public override fun multiply(a: MST, k: Number): MST.Binary = MstRing.multiply(a, k)
@ -113,7 +113,7 @@ public object MstExtendedField : ExtendedField<MST>, NumericAlgebra<MST> {
public override val one: MST.Numeric public override val one: MST.Numeric
get() = MstField.one get() = MstField.one
public override fun symbol(value: String): MST.Symbolic = MstField.symbol(value) public override fun bindSymbol(value: String): MST.Symbolic = MstField.bindSymbol(value)
public override fun number(value: Number): MST.Numeric = MstRing.number(value) public override fun number(value: Number): MST.Numeric = MstRing.number(value)
public override fun sin(arg: MST): MST.Unary = unaryOperationFunction(TrigonometricOperations.SIN_OPERATION)(arg) public override fun sin(arg: MST): MST.Unary = unaryOperationFunction(TrigonometricOperations.SIN_OPERATION)(arg)
public override fun cos(arg: MST): MST.Unary = unaryOperationFunction(TrigonometricOperations.COS_OPERATION)(arg) public override fun cos(arg: MST): MST.Unary = unaryOperationFunction(TrigonometricOperations.COS_OPERATION)(arg)

View File

@ -1,7 +1,7 @@
package kscience.kmath.ast package space.kscience.kmath.ast
import kscience.kmath.expressions.* import space.kscience.kmath.expressions.*
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract
@ -15,8 +15,8 @@ import kotlin.contracts.contract
*/ */
public class MstExpression<T, out A : Algebra<T>>(public val algebra: A, public val mst: MST) : Expression<T> { public class MstExpression<T, out A : Algebra<T>>(public val algebra: A, public val mst: MST) : Expression<T> {
private inner class InnerAlgebra(val arguments: Map<Symbol, T>) : NumericAlgebra<T> { private inner class InnerAlgebra(val arguments: Map<Symbol, T>) : NumericAlgebra<T> {
override fun symbol(value: String): T = try { override fun bindSymbol(value: String): T = try {
algebra.symbol(value) algebra.bindSymbol(value)
} catch (ignored: IllegalStateException) { } catch (ignored: IllegalStateException) {
null null
} ?: arguments.getValue(StringSymbol(value)) } ?: arguments.getValue(StringSymbol(value))

View File

@ -1,3 +0,0 @@
package kscience.kmath.estree.internal.astring
internal typealias Generator = Any

View File

@ -1,7 +0,0 @@
package kscience.kmath.estree.internal.stream
import kscience.kmath.estree.internal.emitter.Emitter
internal open external class Stream : Emitter {
open fun pipe(dest: Any, options: Any): Any
}

View File

@ -1,20 +1,20 @@
package kscience.kmath.estree package space.kscience.kmath.estree
import kscience.kmath.ast.MST import space.kscience.kmath.ast.MST
import kscience.kmath.ast.MST.* import space.kscience.kmath.ast.MST.*
import kscience.kmath.ast.MstExpression import space.kscience.kmath.ast.MstExpression
import kscience.kmath.estree.internal.ESTreeBuilder import space.kscience.kmath.estree.internal.ESTreeBuilder
import kscience.kmath.estree.internal.estree.BaseExpression import space.kscience.kmath.estree.internal.estree.BaseExpression
import kscience.kmath.expressions.Expression import space.kscience.kmath.expressions.Expression
import kscience.kmath.operations.Algebra import space.kscience.kmath.operations.Algebra
import kscience.kmath.operations.NumericAlgebra import space.kscience.kmath.operations.NumericAlgebra
@PublishedApi @PublishedApi
internal fun <T> MST.compileWith(algebra: Algebra<T>): Expression<T> { internal fun <T> MST.compileWith(algebra: Algebra<T>): Expression<T> {
fun ESTreeBuilder<T>.visit(node: MST): BaseExpression = when (node) { fun ESTreeBuilder<T>.visit(node: MST): BaseExpression = when (node) {
is Symbolic -> { is Symbolic -> {
val symbol = try { val symbol = try {
algebra.symbol(node.value) algebra.bindSymbol(node.value)
} catch (ignored: IllegalStateException) { } catch (ignored: IllegalStateException) {
null null
} }

View File

@ -1,9 +1,9 @@
package kscience.kmath.estree.internal package space.kscience.kmath.estree.internal
import kscience.kmath.estree.internal.astring.generate import space.kscience.kmath.estree.internal.astring.generate
import kscience.kmath.estree.internal.estree.* import space.kscience.kmath.estree.internal.estree.*
import kscience.kmath.expressions.Expression import space.kscience.kmath.expressions.Expression
import kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.Symbol
internal class ESTreeBuilder<T>(val bodyCallback: ESTreeBuilder<T>.() -> BaseExpression) { internal class ESTreeBuilder<T>(val bodyCallback: ESTreeBuilder<T>.() -> BaseExpression) {
private class GeneratedExpression<T>(val executable: dynamic, val constants: Array<dynamic>) : Expression<T> { private class GeneratedExpression<T>(val executable: dynamic, val constants: Array<dynamic>) : Expression<T> {

View File

@ -1,9 +1,9 @@
@file:JsModule("astring") @file:JsModule("astring")
@file:JsNonModule @file:JsNonModule
package kscience.kmath.estree.internal.astring package space.kscience.kmath.estree.internal.astring
import kscience.kmath.estree.internal.estree.BaseNode import space.kscience.kmath.estree.internal.estree.BaseNode
internal external interface Options { internal external interface Options {
var indent: String? var indent: String?

View File

@ -0,0 +1,3 @@
package space.kscience.kmath.estree.internal.astring
internal typealias Generator = Any

View File

@ -1,4 +1,4 @@
package kscience.kmath.estree.internal.emitter package space.kscience.kmath.estree.internal.emitter
internal open external class Emitter { internal open external class Emitter {
constructor(obj: Any) constructor(obj: Any)

View File

@ -1,4 +1,4 @@
package kscience.kmath.estree.internal.estree package space.kscience.kmath.estree.internal.estree
internal fun Program(sourceType: String, vararg body: dynamic) = object : Program { internal fun Program(sourceType: String, vararg body: dynamic) = object : Program {
override var type = "Program" override var type = "Program"

View File

@ -1,4 +1,4 @@
package kscience.kmath.estree.internal.estree package space.kscience.kmath.estree.internal.estree
import kotlin.js.RegExp import kotlin.js.RegExp

View File

@ -0,0 +1,7 @@
package space.kscience.kmath.estree.internal.stream
import space.kscience.kmath.estree.internal.emitter.Emitter
internal open external class Stream : Emitter {
open fun pipe(dest: Any, options: Any): Any
}

View File

@ -1,4 +1,4 @@
package kscience.kmath.estree.internal.tsstdlib package space.kscience.kmath.estree.internal.tsstdlib
internal external interface IteratorYieldResult<TYield> { internal external interface IteratorYieldResult<TYield> {
var done: Boolean? var done: Boolean?

View File

@ -1,6 +1,6 @@
@file:Suppress("UNUSED_TYPEALIAS_PARAMETER", "DEPRECATION") @file:Suppress("UNUSED_TYPEALIAS_PARAMETER", "DEPRECATION")
package kscience.kmath.estree.internal.tsstdlib package space.kscience.kmath.estree.internal.tsstdlib
import kotlin.js.RegExp import kotlin.js.RegExp

View File

@ -1,11 +1,11 @@
package kscience.kmath.estree package space.kscience.kmath.estree
import kscience.kmath.ast.* import space.kscience.kmath.ast.*
import kscience.kmath.complex.ComplexField import space.kscience.kmath.complex.ComplexField
import kscience.kmath.complex.toComplex import space.kscience.kmath.complex.toComplex
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.operations.ByteRing import space.kscience.kmath.operations.ByteRing
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -22,7 +22,7 @@ internal class TestESTreeConsistencyWithInterpreter {
), ),
number(1) number(1)
) + symbol("x") + zero ) + bindSymbol("x") + zero
}("x" to MST.Numeric(2)) }("x" to MST.Numeric(2))
val res2 = MstSpace.mstInSpace { val res2 = MstSpace.mstInSpace {
@ -35,7 +35,7 @@ internal class TestESTreeConsistencyWithInterpreter {
), ),
number(1) number(1)
) + symbol("x") + zero ) + bindSymbol("x") + zero
}.compile()("x" to MST.Numeric(2)) }.compile()("x" to MST.Numeric(2))
assertEquals(res1, res2) assertEquals(res1, res2)
@ -46,7 +46,7 @@ internal class TestESTreeConsistencyWithInterpreter {
val res1 = ByteRing.mstInRing { val res1 = ByteRing.mstInRing {
binaryOperationFunction("+")( binaryOperationFunction("+")(
unaryOperationFunction("+")( unaryOperationFunction("+")(
(symbol("x") - (2.toByte() + (multiply( (bindSymbol("x") - (2.toByte() + (multiply(
add(number(1), number(1)), add(number(1), number(1)),
2 2
) + 1.toByte()))) * 3.0 - 1.toByte() ) + 1.toByte()))) * 3.0 - 1.toByte()
@ -59,7 +59,7 @@ internal class TestESTreeConsistencyWithInterpreter {
val res2 = ByteRing.mstInRing { val res2 = ByteRing.mstInRing {
binaryOperationFunction("+")( binaryOperationFunction("+")(
unaryOperationFunction("+")( unaryOperationFunction("+")(
(symbol("x") - (2.toByte() + (multiply( (bindSymbol("x") - (2.toByte() + (multiply(
add(number(1), number(1)), add(number(1), number(1)),
2 2
) + 1.toByte()))) * 3.0 - 1.toByte() ) + 1.toByte()))) * 3.0 - 1.toByte()
@ -75,7 +75,7 @@ internal class TestESTreeConsistencyWithInterpreter {
fun realField() { fun realField() {
val res1 = RealField.mstInField { val res1 = RealField.mstInField {
+(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")(
(3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0
+ number(1), + number(1),
number(1) / 2 + number(2.0) * one number(1) / 2 + number(2.0) * one
) + zero ) + zero
@ -83,7 +83,7 @@ internal class TestESTreeConsistencyWithInterpreter {
val res2 = RealField.mstInField { val res2 = RealField.mstInField {
+(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")(
(3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0
+ number(1), + number(1),
number(1) / 2 + number(2.0) * one number(1) / 2 + number(2.0) * one
) + zero ) + zero
@ -96,7 +96,7 @@ internal class TestESTreeConsistencyWithInterpreter {
fun complexField() { fun complexField() {
val res1 = ComplexField.mstInField { val res1 = ComplexField.mstInField {
+(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")(
(3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0
+ number(1), + number(1),
number(1) / 2 + number(2.0) * one number(1) / 2 + number(2.0) * one
) + zero ) + zero
@ -104,7 +104,7 @@ internal class TestESTreeConsistencyWithInterpreter {
val res2 = ComplexField.mstInField { val res2 = ComplexField.mstInField {
+(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")(
(3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0
+ number(1), + number(1),
number(1) / 2 + number(2.0) * one number(1) / 2 + number(2.0) * one
) + zero ) + zero

View File

@ -1,10 +1,10 @@
package kscience.kmath.estree package space.kscience.kmath.estree
import kscience.kmath.ast.mstInExtendedField import space.kscience.kmath.ast.mstInExtendedField
import kscience.kmath.ast.mstInField import space.kscience.kmath.ast.mstInField
import kscience.kmath.ast.mstInSpace import space.kscience.kmath.ast.mstInSpace
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
import kotlin.random.Random import kotlin.random.Random
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -12,27 +12,27 @@ import kotlin.test.assertEquals
internal class TestESTreeOperationsSupport { internal class TestESTreeOperationsSupport {
@Test @Test
fun testUnaryOperationInvocation() { fun testUnaryOperationInvocation() {
val expression = RealField.mstInSpace { -symbol("x") }.compile() val expression = RealField.mstInSpace { -bindSymbol("x") }.compile()
val res = expression("x" to 2.0) val res = expression("x" to 2.0)
assertEquals(-2.0, res) assertEquals(-2.0, res)
} }
@Test @Test
fun testBinaryOperationInvocation() { fun testBinaryOperationInvocation() {
val expression = RealField.mstInSpace { -symbol("x") + number(1.0) }.compile() val expression = RealField.mstInSpace { -bindSymbol("x") + number(1.0) }.compile()
val res = expression("x" to 2.0) val res = expression("x" to 2.0)
assertEquals(-1.0, res) assertEquals(-1.0, res)
} }
@Test @Test
fun testConstProductInvocation() { fun testConstProductInvocation() {
val res = RealField.mstInField { symbol("x") * 2 }("x" to 2.0) val res = RealField.mstInField { bindSymbol("x") * 2 }("x" to 2.0)
assertEquals(4.0, res) assertEquals(4.0, res)
} }
@Test @Test
fun testMultipleCalls() { fun testMultipleCalls() {
val e = RealField.mstInExtendedField { sin(symbol("x")).pow(4) - 6 * symbol("x") / tanh(symbol("x")) }.compile() val e = RealField.mstInExtendedField { sin(bindSymbol("x")).pow(4) - 6 * bindSymbol("x") / tanh(bindSymbol("x")) }.compile()
val r = Random(0) val r = Random(0)
var s = 0.0 var s = 0.0
repeat(1000000) { s += e("x" to r.nextDouble()) } repeat(1000000) { s += e("x" to r.nextDouble()) }

View File

@ -1,52 +1,52 @@
package kscience.kmath.estree package space.kscience.kmath.estree
import kscience.kmath.ast.mstInField import space.kscience.kmath.ast.mstInField
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
internal class TestESTreeSpecialization { internal class TestESTreeSpecialization {
@Test @Test
fun testUnaryPlus() { fun testUnaryPlus() {
val expr = RealField.mstInField { unaryOperationFunction("+")(symbol("x")) }.compile() val expr = RealField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile()
assertEquals(2.0, expr("x" to 2.0)) assertEquals(2.0, expr("x" to 2.0))
} }
@Test @Test
fun testUnaryMinus() { fun testUnaryMinus() {
val expr = RealField.mstInField { unaryOperationFunction("-")(symbol("x")) }.compile() val expr = RealField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile()
assertEquals(-2.0, expr("x" to 2.0)) assertEquals(-2.0, expr("x" to 2.0))
} }
@Test @Test
fun testAdd() { fun testAdd() {
val expr = RealField.mstInField { binaryOperationFunction("+")(symbol("x"), symbol("x")) }.compile() val expr = RealField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile()
assertEquals(4.0, expr("x" to 2.0)) assertEquals(4.0, expr("x" to 2.0))
} }
@Test @Test
fun testSine() { fun testSine() {
val expr = RealField.mstInField { unaryOperationFunction("sin")(symbol("x")) }.compile() val expr = RealField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile()
assertEquals(0.0, expr("x" to 0.0)) assertEquals(0.0, expr("x" to 0.0))
} }
@Test @Test
fun testMinus() { fun testMinus() {
val expr = RealField.mstInField { binaryOperationFunction("-")(symbol("x"), symbol("x")) }.compile() val expr = RealField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile()
assertEquals(0.0, expr("x" to 2.0)) assertEquals(0.0, expr("x" to 2.0))
} }
@Test @Test
fun testDivide() { fun testDivide() {
val expr = RealField.mstInField { binaryOperationFunction("/")(symbol("x"), symbol("x")) }.compile() val expr = RealField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile()
assertEquals(1.0, expr("x" to 2.0)) assertEquals(1.0, expr("x" to 2.0))
} }
@Test @Test
fun testPower() { fun testPower() {
val expr = RealField val expr = RealField
.mstInField { binaryOperationFunction("pow")(symbol("x"), number(2)) } .mstInField { binaryOperationFunction("pow")(bindSymbol("x"), number(2)) }
.compile() .compile()
assertEquals(4.0, expr("x" to 2.0)) assertEquals(4.0, expr("x" to 2.0))

View File

@ -1,8 +1,8 @@
package kscience.kmath.estree package space.kscience.kmath.estree
import kscience.kmath.ast.mstInRing import space.kscience.kmath.ast.mstInRing
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.operations.ByteRing import space.kscience.kmath.operations.ByteRing
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
@ -10,13 +10,13 @@ import kotlin.test.assertFailsWith
internal class TestESTreeVariables { internal class TestESTreeVariables {
@Test @Test
fun testVariable() { fun testVariable() {
val expr = ByteRing.mstInRing { symbol("x") }.compile() val expr = ByteRing.mstInRing { bindSymbol("x") }.compile()
assertEquals(1.toByte(), expr("x" to 1.toByte())) assertEquals(1.toByte(), expr("x" to 1.toByte()))
} }
@Test @Test
fun testUndefinedVariableFails() { fun testUndefinedVariableFails() {
val expr = ByteRing.mstInRing { symbol("x") }.compile() val expr = ByteRing.mstInRing { bindSymbol("x") }.compile()
assertFailsWith<NoSuchElementException> { expr() } assertFailsWith<NoSuchElementException> { expr() }
} }
} }

View File

@ -1,13 +1,13 @@
package kscience.kmath.asm package space.kscience.kmath.asm
import kscience.kmath.asm.internal.AsmBuilder import space.kscience.kmath.asm.internal.AsmBuilder
import kscience.kmath.asm.internal.buildName import space.kscience.kmath.asm.internal.buildName
import kscience.kmath.ast.MST import space.kscience.kmath.ast.MST
import kscience.kmath.ast.MST.* import space.kscience.kmath.ast.MST.*
import kscience.kmath.ast.MstExpression import space.kscience.kmath.ast.MstExpression
import kscience.kmath.expressions.Expression import space.kscience.kmath.expressions.Expression
import kscience.kmath.operations.Algebra import space.kscience.kmath.operations.Algebra
import kscience.kmath.operations.NumericAlgebra import space.kscience.kmath.operations.NumericAlgebra
/** /**
* Compiles given MST to an Expression using AST compiler. * Compiles given MST to an Expression using AST compiler.
@ -22,7 +22,7 @@ internal fun <T : Any> MST.compileWith(type: Class<T>, algebra: Algebra<T>): Exp
fun AsmBuilder<T>.visit(node: MST): Unit = when (node) { fun AsmBuilder<T>.visit(node: MST): Unit = when (node) {
is Symbolic -> { is Symbolic -> {
val symbol = try { val symbol = try {
algebra.symbol(node.value) algebra.bindSymbol(node.value)
} catch (ignored: IllegalStateException) { } catch (ignored: IllegalStateException) {
null null
} }

View File

@ -1,15 +1,14 @@
package kscience.kmath.asm.internal package space.kscience.kmath.asm.internal
import kscience.kmath.asm.internal.AsmBuilder.ClassLoader
import kscience.kmath.ast.MST
import kscience.kmath.expressions.Expression
import org.objectweb.asm.* import org.objectweb.asm.*
import org.objectweb.asm.Opcodes.* import org.objectweb.asm.Opcodes.*
import org.objectweb.asm.Type.* import org.objectweb.asm.Type.*
import org.objectweb.asm.commons.InstructionAdapter import org.objectweb.asm.commons.InstructionAdapter
import space.kscience.kmath.asm.internal.AsmBuilder.ClassLoader
import space.kscience.kmath.ast.MST
import space.kscience.kmath.expressions.Expression
import java.lang.invoke.MethodHandles import java.lang.invoke.MethodHandles
import java.lang.invoke.MethodType import java.lang.invoke.MethodType
import java.lang.reflect.Modifier
import java.util.stream.Collectors.toMap import java.util.stream.Collectors.toMap
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract
@ -310,7 +309,7 @@ internal class AsmBuilder<T>(
/** /**
* ASM type for [Expression]. * ASM type for [Expression].
*/ */
val EXPRESSION_TYPE: Type by lazy { getObjectType("kscience/kmath/expressions/Expression") } val EXPRESSION_TYPE: Type by lazy { getObjectType("space/kscience/kmath/expressions/Expression") }
/** /**
* ASM type for [java.util.Map]. * ASM type for [java.util.Map].
@ -335,11 +334,11 @@ internal class AsmBuilder<T>(
/** /**
* ASM type for MapIntrinsics. * ASM type for MapIntrinsics.
*/ */
val MAP_INTRINSICS_TYPE: Type by lazy { getObjectType("kscience/kmath/asm/internal/MapIntrinsics") } val MAP_INTRINSICS_TYPE: Type by lazy { getObjectType("space/kscience/kmath/asm/internal/MapIntrinsics") }
/** /**
* ASM Type for [kscience.kmath.expressions.Symbol]. * ASM Type for [kscience.kmath.expressions.Symbol].
*/ */
val SYMBOL_TYPE: Type by lazy { getObjectType("kscience/kmath/expressions/Symbol") } val SYMBOL_TYPE: Type by lazy { getObjectType("space/kscience/kmath/expressions/Symbol") }
} }
} }

View File

@ -1,9 +1,9 @@
package kscience.kmath.asm.internal package space.kscience.kmath.asm.internal
import kscience.kmath.ast.MST
import kscience.kmath.expressions.Expression
import org.objectweb.asm.* import org.objectweb.asm.*
import org.objectweb.asm.commons.InstructionAdapter import org.objectweb.asm.commons.InstructionAdapter
import space.kscience.kmath.ast.MST
import space.kscience.kmath.expressions.Expression
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract

View File

@ -1,9 +1,9 @@
@file:JvmName("MapIntrinsics") @file:JvmName("MapIntrinsics")
package kscience.kmath.asm.internal package space.kscience.kmath.asm.internal
import kscience.kmath.expressions.StringSymbol import space.kscience.kmath.expressions.StringSymbol
import kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.Symbol
/** /**
* Gets value with given [key] or throws [NoSuchElementException] whenever it is not present. * Gets value with given [key] or throws [NoSuchElementException] whenever it is not present.

View File

@ -1,6 +1,6 @@
// TODO move to common when https://github.com/h0tk3y/better-parse/pull/33 is merged // TODO move to common when https://github.com/h0tk3y/better-parse/pull/33 is merged
package kscience.kmath.ast package space.kscience.kmath.ast
import com.github.h0tk3y.betterParse.combinators.* import com.github.h0tk3y.betterParse.combinators.*
import com.github.h0tk3y.betterParse.grammar.Grammar import com.github.h0tk3y.betterParse.grammar.Grammar
@ -13,10 +13,10 @@ import com.github.h0tk3y.betterParse.lexer.literalToken
import com.github.h0tk3y.betterParse.lexer.regexToken import com.github.h0tk3y.betterParse.lexer.regexToken
import com.github.h0tk3y.betterParse.parser.ParseResult import com.github.h0tk3y.betterParse.parser.ParseResult
import com.github.h0tk3y.betterParse.parser.Parser import com.github.h0tk3y.betterParse.parser.Parser
import kscience.kmath.operations.FieldOperations import space.kscience.kmath.operations.FieldOperations
import kscience.kmath.operations.PowerOperations import space.kscience.kmath.operations.PowerOperations
import kscience.kmath.operations.RingOperations import space.kscience.kmath.operations.RingOperations
import kscience.kmath.operations.SpaceOperations import space.kscience.kmath.operations.SpaceOperations
/** /**
* better-parse implementation of grammar defined in the ArithmeticsEvaluator.g4. * better-parse implementation of grammar defined in the ArithmeticsEvaluator.g4.

View File

@ -1,10 +1,11 @@
package kscience.kmath.asm package space.kscience.kmath.asm
import kscience.kmath.ast.* import space.kscience.kmath.ast.*
import kscience.kmath.complex.* import space.kscience.kmath.complex.ComplexField
import kscience.kmath.expressions.invoke import space.kscience.kmath.complex.toComplex
import kscience.kmath.operations.ByteRing import space.kscience.kmath.expressions.invoke
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.ByteRing
import space.kscience.kmath.operations.RealField
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -21,7 +22,7 @@ internal class TestAsmConsistencyWithInterpreter {
), ),
number(1) number(1)
) + symbol("x") + zero ) + bindSymbol("x") + zero
}("x" to MST.Numeric(2)) }("x" to MST.Numeric(2))
val res2 = MstSpace.mstInSpace { val res2 = MstSpace.mstInSpace {
@ -34,7 +35,7 @@ internal class TestAsmConsistencyWithInterpreter {
), ),
number(1) number(1)
) + symbol("x") + zero ) + bindSymbol("x") + zero
}.compile()("x" to MST.Numeric(2)) }.compile()("x" to MST.Numeric(2))
assertEquals(res1, res2) assertEquals(res1, res2)
@ -45,7 +46,7 @@ internal class TestAsmConsistencyWithInterpreter {
val res1 = ByteRing.mstInRing { val res1 = ByteRing.mstInRing {
binaryOperationFunction("+")( binaryOperationFunction("+")(
unaryOperationFunction("+")( unaryOperationFunction("+")(
(symbol("x") - (2.toByte() + (multiply( (bindSymbol("x") - (2.toByte() + (multiply(
add(number(1), number(1)), add(number(1), number(1)),
2 2
) + 1.toByte()))) * 3.0 - 1.toByte() ) + 1.toByte()))) * 3.0 - 1.toByte()
@ -58,7 +59,7 @@ internal class TestAsmConsistencyWithInterpreter {
val res2 = ByteRing.mstInRing { val res2 = ByteRing.mstInRing {
binaryOperationFunction("+")( binaryOperationFunction("+")(
unaryOperationFunction("+")( unaryOperationFunction("+")(
(symbol("x") - (2.toByte() + (multiply( (bindSymbol("x") - (2.toByte() + (multiply(
add(number(1), number(1)), add(number(1), number(1)),
2 2
) + 1.toByte()))) * 3.0 - 1.toByte() ) + 1.toByte()))) * 3.0 - 1.toByte()
@ -74,7 +75,7 @@ internal class TestAsmConsistencyWithInterpreter {
fun realField() { fun realField() {
val res1 = RealField.mstInField { val res1 = RealField.mstInField {
+(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")(
(3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0
+ number(1), + number(1),
number(1) / 2 + number(2.0) * one number(1) / 2 + number(2.0) * one
) + zero ) + zero
@ -82,7 +83,7 @@ internal class TestAsmConsistencyWithInterpreter {
val res2 = RealField.mstInField { val res2 = RealField.mstInField {
+(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")(
(3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0
+ number(1), + number(1),
number(1) / 2 + number(2.0) * one number(1) / 2 + number(2.0) * one
) + zero ) + zero
@ -95,7 +96,7 @@ internal class TestAsmConsistencyWithInterpreter {
fun complexField() { fun complexField() {
val res1 = ComplexField.mstInField { val res1 = ComplexField.mstInField {
+(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")(
(3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0
+ number(1), + number(1),
number(1) / 2 + number(2.0) * one number(1) / 2 + number(2.0) * one
) + zero ) + zero
@ -103,7 +104,7 @@ internal class TestAsmConsistencyWithInterpreter {
val res2 = ComplexField.mstInField { val res2 = ComplexField.mstInField {
+(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")(
(3.0 - (symbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0 (3.0 - (bindSymbol("x") + (multiply(add(number(1.0), number(1.0)), 2) + 1.0))) * 3 - 1.0
+ number(1), + number(1),
number(1) / 2 + number(2.0) * one number(1) / 2 + number(2.0) * one
) + zero ) + zero

View File

@ -1,10 +1,10 @@
package kscience.kmath.asm package space.kscience.kmath.asm
import kscience.kmath.ast.mstInExtendedField import space.kscience.kmath.ast.mstInExtendedField
import kscience.kmath.ast.mstInField import space.kscience.kmath.ast.mstInField
import kscience.kmath.ast.mstInSpace import space.kscience.kmath.ast.mstInSpace
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
import kotlin.random.Random import kotlin.random.Random
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -12,27 +12,27 @@ import kotlin.test.assertEquals
internal class TestAsmOperationsSupport { internal class TestAsmOperationsSupport {
@Test @Test
fun testUnaryOperationInvocation() { fun testUnaryOperationInvocation() {
val expression = RealField.mstInSpace { -symbol("x") }.compile() val expression = RealField.mstInSpace { -bindSymbol("x") }.compile()
val res = expression("x" to 2.0) val res = expression("x" to 2.0)
assertEquals(-2.0, res) assertEquals(-2.0, res)
} }
@Test @Test
fun testBinaryOperationInvocation() { fun testBinaryOperationInvocation() {
val expression = RealField.mstInSpace { -symbol("x") + number(1.0) }.compile() val expression = RealField.mstInSpace { -bindSymbol("x") + number(1.0) }.compile()
val res = expression("x" to 2.0) val res = expression("x" to 2.0)
assertEquals(-1.0, res) assertEquals(-1.0, res)
} }
@Test @Test
fun testConstProductInvocation() { fun testConstProductInvocation() {
val res = RealField.mstInField { symbol("x") * 2 }("x" to 2.0) val res = RealField.mstInField { bindSymbol("x") * 2 }("x" to 2.0)
assertEquals(4.0, res) assertEquals(4.0, res)
} }
@Test @Test
fun testMultipleCalls() { fun testMultipleCalls() {
val e = RealField.mstInExtendedField { sin(symbol("x")).pow(4) - 6 * symbol("x") / tanh(symbol("x")) }.compile() val e = RealField.mstInExtendedField { sin(bindSymbol("x")).pow(4) - 6 * bindSymbol("x") / tanh(bindSymbol("x")) }.compile()
val r = Random(0) val r = Random(0)
var s = 0.0 var s = 0.0
repeat(1000000) { s += e("x" to r.nextDouble()) } repeat(1000000) { s += e("x" to r.nextDouble()) }

View File

@ -1,52 +1,52 @@
package kscience.kmath.asm package space.kscience.kmath.asm
import kscience.kmath.ast.mstInField import space.kscience.kmath.ast.mstInField
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
internal class TestAsmSpecialization { internal class TestAsmSpecialization {
@Test @Test
fun testUnaryPlus() { fun testUnaryPlus() {
val expr = RealField.mstInField { unaryOperationFunction("+")(symbol("x")) }.compile() val expr = RealField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile()
assertEquals(2.0, expr("x" to 2.0)) assertEquals(2.0, expr("x" to 2.0))
} }
@Test @Test
fun testUnaryMinus() { fun testUnaryMinus() {
val expr = RealField.mstInField { unaryOperationFunction("-")(symbol("x")) }.compile() val expr = RealField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile()
assertEquals(-2.0, expr("x" to 2.0)) assertEquals(-2.0, expr("x" to 2.0))
} }
@Test @Test
fun testAdd() { fun testAdd() {
val expr = RealField.mstInField { binaryOperationFunction("+")(symbol("x"), symbol("x")) }.compile() val expr = RealField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile()
assertEquals(4.0, expr("x" to 2.0)) assertEquals(4.0, expr("x" to 2.0))
} }
@Test @Test
fun testSine() { fun testSine() {
val expr = RealField.mstInField { unaryOperationFunction("sin")(symbol("x")) }.compile() val expr = RealField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile()
assertEquals(0.0, expr("x" to 0.0)) assertEquals(0.0, expr("x" to 0.0))
} }
@Test @Test
fun testMinus() { fun testMinus() {
val expr = RealField.mstInField { binaryOperationFunction("-")(symbol("x"), symbol("x")) }.compile() val expr = RealField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile()
assertEquals(0.0, expr("x" to 2.0)) assertEquals(0.0, expr("x" to 2.0))
} }
@Test @Test
fun testDivide() { fun testDivide() {
val expr = RealField.mstInField { binaryOperationFunction("/")(symbol("x"), symbol("x")) }.compile() val expr = RealField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile()
assertEquals(1.0, expr("x" to 2.0)) assertEquals(1.0, expr("x" to 2.0))
} }
@Test @Test
fun testPower() { fun testPower() {
val expr = RealField val expr = RealField
.mstInField { binaryOperationFunction("pow")(symbol("x"), number(2)) } .mstInField { binaryOperationFunction("pow")(bindSymbol("x"), number(2)) }
.compile() .compile()
assertEquals(4.0, expr("x" to 2.0)) assertEquals(4.0, expr("x" to 2.0))

View File

@ -1,8 +1,8 @@
package kscience.kmath.asm package space.kscience.kmath.asm
import kscience.kmath.ast.mstInRing import space.kscience.kmath.ast.mstInRing
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.operations.ByteRing import space.kscience.kmath.operations.ByteRing
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
@ -10,13 +10,13 @@ import kotlin.test.assertFailsWith
internal class TestAsmVariables { internal class TestAsmVariables {
@Test @Test
fun testVariable() { fun testVariable() {
val expr = ByteRing.mstInRing { symbol("x") }.compile() val expr = ByteRing.mstInRing { bindSymbol("x") }.compile()
assertEquals(1.toByte(), expr("x" to 1.toByte())) assertEquals(1.toByte(), expr("x" to 1.toByte()))
} }
@Test @Test
fun testUndefinedVariableFails() { fun testUndefinedVariableFails() {
val expr = ByteRing.mstInRing { symbol("x") }.compile() val expr = ByteRing.mstInRing { bindSymbol("x") }.compile()
assertFailsWith<NoSuchElementException> { expr() } assertFailsWith<NoSuchElementException> { expr() }
} }
} }

View File

@ -1,7 +1,7 @@
package kscience.kmath.ast package space.kscience.kmath.ast
import kscience.kmath.operations.Field import space.kscience.kmath.operations.Field
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals

View File

@ -1,10 +1,10 @@
package kscience.kmath.ast package space.kscience.kmath.ast
import kscience.kmath.complex.Complex import space.kscience.kmath.complex.Complex
import kscience.kmath.complex.ComplexField import space.kscience.kmath.complex.ComplexField
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.operations.Algebra import space.kscience.kmath.operations.Algebra
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -40,7 +40,7 @@ internal class ParserTest {
@Test @Test
fun `evaluate MST with binary function`() { fun `evaluate MST with binary function`() {
val magicalAlgebra = object : Algebra<String> { val magicalAlgebra = object : Algebra<String> {
override fun symbol(value: String): String = value override fun bindSymbol(value: String): String = value
override fun unaryOperationFunction(operation: String): (arg: String) -> String { override fun unaryOperationFunction(operation: String): (arg: String) -> String {
throw NotImplementedError() throw NotImplementedError()

View File

@ -1,10 +1,10 @@
package kscience.kmath.commons.expressions package space.kscience.kmath.commons.expressions
import kscience.kmath.expressions.*
import kscience.kmath.misc.UnstableKMathAPI
import kscience.kmath.operations.ExtendedField
import kscience.kmath.operations.RingWithNumbers
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure import org.apache.commons.math3.analysis.differentiation.DerivativeStructure
import space.kscience.kmath.expressions.*
import space.kscience.kmath.misc.UnstableKMathAPI
import space.kscience.kmath.operations.ExtendedField
import space.kscience.kmath.operations.RingWithNumbers
/** /**
* A field over commons-math [DerivativeStructure]. * A field over commons-math [DerivativeStructure].
@ -48,11 +48,11 @@ public class DerivativeStructureField(
override fun const(value: Double): DerivativeStructure = DerivativeStructure(numberOfVariables, order, value) override fun const(value: Double): DerivativeStructure = DerivativeStructure(numberOfVariables, order, value)
public override fun bindOrNull(symbol: Symbol): DerivativeStructureSymbol? = variables[symbol.identity] public override fun bindSymbolOrNull(symbol: Symbol): DerivativeStructureSymbol? = variables[symbol.identity]
public fun bind(symbol: Symbol): DerivativeStructureSymbol = variables.getValue(symbol.identity) public fun bind(symbol: Symbol): DerivativeStructureSymbol = variables.getValue(symbol.identity)
override fun symbol(value: String): DerivativeStructureSymbol = bind(StringSymbol(value)) override fun bindSymbol(value: String): DerivativeStructureSymbol = bind(StringSymbol(value))
public fun DerivativeStructure.derivative(symbols: List<Symbol>): Double { public fun DerivativeStructure.derivative(symbols: List<Symbol>): Double {
require(symbols.size <= order) { "The order of derivative ${symbols.size} exceeds computed order $order" } require(symbols.size <= order) { "The order of derivative ${symbols.size} exceeds computed order $order" }

View File

@ -1,9 +1,9 @@
package kscience.kmath.commons.linear package space.kscience.kmath.commons.linear
import kscience.kmath.linear.*
import kscience.kmath.misc.UnstableKMathAPI
import kscience.kmath.structures.RealBuffer
import org.apache.commons.math3.linear.* import org.apache.commons.math3.linear.*
import space.kscience.kmath.linear.*
import space.kscience.kmath.misc.UnstableKMathAPI
import space.kscience.kmath.structures.RealBuffer
import kotlin.reflect.KClass import kotlin.reflect.KClass
import kotlin.reflect.cast import kotlin.reflect.cast

View File

@ -1,8 +1,8 @@
package kscience.kmath.commons.linear package space.kscience.kmath.commons.linear
import kscience.kmath.linear.Matrix
import kscience.kmath.linear.Point
import org.apache.commons.math3.linear.* import org.apache.commons.math3.linear.*
import space.kscience.kmath.linear.Matrix
import space.kscience.kmath.linear.Point
public enum class CMDecomposition { public enum class CMDecomposition {
LUP, LUP,

View File

@ -1,10 +1,5 @@
package kscience.kmath.commons.optimization package space.kscience.kmath.commons.optimization
import kscience.kmath.expressions.*
import kscience.kmath.stat.OptimizationFeature
import kscience.kmath.stat.OptimizationProblem
import kscience.kmath.stat.OptimizationProblemFactory
import kscience.kmath.stat.OptimizationResult
import org.apache.commons.math3.optim.* import org.apache.commons.math3.optim.*
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType import org.apache.commons.math3.optim.nonlinear.scalar.GoalType
import org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer import org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer
@ -14,6 +9,11 @@ import org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjuga
import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.AbstractSimplex import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.AbstractSimplex
import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex
import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer
import space.kscience.kmath.expressions.*
import space.kscience.kmath.stat.OptimizationFeature
import space.kscience.kmath.stat.OptimizationProblem
import space.kscience.kmath.stat.OptimizationProblemFactory
import space.kscience.kmath.stat.OptimizationResult
import kotlin.reflect.KClass import kotlin.reflect.KClass
public operator fun PointValuePair.component1(): DoubleArray = point public operator fun PointValuePair.component1(): DoubleArray = point

View File

@ -1,16 +1,16 @@
package kscience.kmath.commons.optimization package space.kscience.kmath.commons.optimization
import kscience.kmath.commons.expressions.DerivativeStructureField
import kscience.kmath.expressions.DifferentiableExpression
import kscience.kmath.expressions.Expression
import kscience.kmath.expressions.Symbol
import kscience.kmath.stat.Fitting
import kscience.kmath.stat.OptimizationResult
import kscience.kmath.stat.optimizeWith
import kscience.kmath.structures.Buffer
import kscience.kmath.structures.asBuffer
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure import org.apache.commons.math3.analysis.differentiation.DerivativeStructure
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType import org.apache.commons.math3.optim.nonlinear.scalar.GoalType
import space.kscience.kmath.commons.expressions.DerivativeStructureField
import space.kscience.kmath.expressions.DifferentiableExpression
import space.kscience.kmath.expressions.Expression
import space.kscience.kmath.expressions.Symbol
import space.kscience.kmath.stat.Fitting
import space.kscience.kmath.stat.OptimizationResult
import space.kscience.kmath.stat.optimizeWith
import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.asBuffer
/** /**
* Generate a chi squared expression from given x-y-sigma data and inline model. Provides automatic differentiation * Generate a chi squared expression from given x-y-sigma data and inline model. Provides automatic differentiation

View File

@ -1,6 +1,6 @@
package kscience.kmath.commons.random package space.kscience.kmath.commons.random
import kscience.kmath.stat.RandomGenerator import space.kscience.kmath.stat.RandomGenerator
public class CMRandomGeneratorWrapper( public class CMRandomGeneratorWrapper(
public val factory: (IntArray) -> RandomGenerator, public val factory: (IntArray) -> RandomGenerator,

View File

@ -1,13 +1,13 @@
package kscience.kmath.commons.transform package space.kscience.kmath.commons.transform
import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kscience.kmath.complex.*
import kscience.kmath.streaming.chunked
import kscience.kmath.streaming.spread
import kscience.kmath.structures.*
import org.apache.commons.math3.transform.* import org.apache.commons.math3.transform.*
import space.kscience.kmath.complex.Complex
import space.kscience.kmath.streaming.chunked
import space.kscience.kmath.streaming.spread
import space.kscience.kmath.structures.*
/** /**

View File

@ -1,6 +1,6 @@
package kscience.kmath.commons.expressions package space.kscience.kmath.commons.expressions
import kscience.kmath.expressions.* import space.kscience.kmath.expressions.*
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract
import kotlin.test.Test import kotlin.test.Test
@ -24,7 +24,7 @@ internal class AutoDiffTest {
fun derivativeStructureFieldTest() { fun derivativeStructureFieldTest() {
diff(2, x to 1.0, y to 1.0) { diff(2, x to 1.0, y to 1.0) {
val x = bind(x)//by binding() val x = bind(x)//by binding()
val y = symbol("y") val y = bindSymbol("y")
val z = x * (-sin(x * y) + y) + 2.0 val z = x * (-sin(x * y) + y) + 2.0
println(z.derivative(x)) println(z.derivative(x))
println(z.derivative(y,x)) println(z.derivative(y,x))

View File

@ -1,12 +1,12 @@
package kscience.kmath.commons.optimization package space.kscience.kmath.commons.optimization
import kscience.kmath.commons.expressions.DerivativeStructureExpression
import kscience.kmath.expressions.symbol
import kscience.kmath.stat.Distribution
import kscience.kmath.stat.Fitting
import kscience.kmath.stat.RandomGenerator
import kscience.kmath.stat.normal
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import space.kscience.kmath.commons.expressions.DerivativeStructureExpression
import space.kscience.kmath.expressions.symbol
import space.kscience.kmath.stat.Distribution
import space.kscience.kmath.stat.Fitting
import space.kscience.kmath.stat.RandomGenerator
import space.kscience.kmath.stat.normal
import kotlin.math.pow import kotlin.math.pow
internal class OptimizeTest { internal class OptimizeTest {
@ -56,7 +56,7 @@ internal class OptimizeTest {
val yErr = List(x.size) { sigma } val yErr = List(x.size) { sigma }
val chi2 = Fitting.chiSquared(x, y, yErr) { x1 -> val chi2 = Fitting.chiSquared(x, y, yErr) { x1 ->
val cWithDefault = bindOrNull(c) ?: one val cWithDefault = bindSymbolOrNull(c) ?: one
bind(a) * x1.pow(2) + bind(b) * x1 + cWithDefault bind(a) * x1.pow(2) + bind(b) * x1 + cWithDefault
} }

View File

@ -1,16 +1,16 @@
package kscience.kmath.complex package space.kscience.kmath.complex
import kscience.kmath.memory.MemoryReader import space.kscience.kmath.memory.MemoryReader
import kscience.kmath.memory.MemorySpec import space.kscience.kmath.memory.MemorySpec
import kscience.kmath.memory.MemoryWriter import space.kscience.kmath.memory.MemoryWriter
import kscience.kmath.operations.ExtendedField import space.kscience.kmath.operations.ExtendedField
import kscience.kmath.operations.FieldElement import space.kscience.kmath.operations.FieldElement
import kscience.kmath.operations.Norm import space.kscience.kmath.operations.Norm
import kscience.kmath.operations.RingWithNumbers import space.kscience.kmath.operations.RingWithNumbers
import kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Buffer
import kscience.kmath.structures.MemoryBuffer import space.kscience.kmath.structures.MemoryBuffer
import kscience.kmath.structures.MutableBuffer import space.kscience.kmath.structures.MutableBuffer
import kscience.kmath.structures.MutableMemoryBuffer import space.kscience.kmath.structures.MutableMemoryBuffer
import kotlin.math.* import kotlin.math.*
/** /**
@ -157,7 +157,7 @@ public object ComplexField : ExtendedField<Complex>, Norm<Complex, Complex>, Rin
public override fun norm(arg: Complex): Complex = sqrt(arg.conjugate * arg) public override fun norm(arg: Complex): Complex = sqrt(arg.conjugate * arg)
public override fun symbol(value: String): Complex = if (value == "i") i else super<ExtendedField>.symbol(value) public override fun bindSymbol(value: String): Complex = if (value == "i") i else super<ExtendedField>.bindSymbol(value)
} }
/** /**

View File

@ -1,12 +1,13 @@
package kscience.kmath.complex package space.kscience.kmath.complex
import kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.misc.UnstableKMathAPI
import kscience.kmath.nd.BufferedNDField import space.kscience.kmath.nd.BufferedNDField
import kscience.kmath.nd.NDAlgebra import space.kscience.kmath.nd.NDAlgebra
import kscience.kmath.nd.NDBuffer import space.kscience.kmath.nd.NDBuffer
import kscience.kmath.nd.NDStructure import space.kscience.kmath.nd.NDStructure
import kscience.kmath.operations.* import space.kscience.kmath.operations.ExtendedField
import kscience.kmath.structures.Buffer import space.kscience.kmath.operations.RingWithNumbers
import space.kscience.kmath.structures.Buffer
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract

View File

@ -1,13 +1,13 @@
package kscience.kmath.complex package space.kscience.kmath.complex
import kscience.kmath.memory.MemoryReader import space.kscience.kmath.memory.MemoryReader
import kscience.kmath.memory.MemorySpec import space.kscience.kmath.memory.MemorySpec
import kscience.kmath.memory.MemoryWriter import space.kscience.kmath.memory.MemoryWriter
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
import kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Buffer
import kscience.kmath.structures.MemoryBuffer import space.kscience.kmath.structures.MemoryBuffer
import kscience.kmath.structures.MutableBuffer import space.kscience.kmath.structures.MutableBuffer
import kscience.kmath.structures.MutableMemoryBuffer import space.kscience.kmath.structures.MutableMemoryBuffer
import kotlin.math.* import kotlin.math.*
/** /**
@ -165,11 +165,11 @@ public object QuaternionField : Field<Quaternion>, Norm<Quaternion, Quaternion>,
public override fun Quaternion.unaryMinus(): Quaternion = Quaternion(-w, -x, -y, -z) public override fun Quaternion.unaryMinus(): Quaternion = Quaternion(-w, -x, -y, -z)
public override fun norm(arg: Quaternion): Quaternion = sqrt(arg.conjugate * arg) public override fun norm(arg: Quaternion): Quaternion = sqrt(arg.conjugate * arg)
public override fun symbol(value: String): Quaternion = when (value) { public override fun bindSymbol(value: String): Quaternion = when (value) {
"i" -> i "i" -> i
"j" -> j "j" -> j
"k" -> k "k" -> k
else -> super<Field>.symbol(value) else -> super<Field>.bindSymbol(value)
} }
} }

View File

@ -1,6 +1,6 @@
package kscience.kmath.complex package space.kscience.kmath.complex
import kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Buffer
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals

View File

@ -1,6 +1,6 @@
package kscience.kmath.complex package space.kscience.kmath.complex
import kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import kotlin.math.PI import kotlin.math.PI
import kotlin.math.abs import kotlin.math.abs
import kotlin.test.Test import kotlin.test.Test

View File

@ -1,6 +1,6 @@
package kscience.kmath.complex package space.kscience.kmath.complex
import kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import kotlin.math.sqrt import kotlin.math.sqrt
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals

View File

@ -1,10 +1,10 @@
package kscience.kmath.complex package space.kscience.kmath.complex
import kscience.kmath.expressions.FunctionalExpressionField import space.kscience.kmath.expressions.FunctionalExpressionField
import kscience.kmath.expressions.bind import space.kscience.kmath.expressions.bindSymbol
import kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.invoke
import kscience.kmath.expressions.symbol import space.kscience.kmath.expressions.symbol
import kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -16,7 +16,7 @@ internal class ExpressionFieldForComplexTest {
val context = FunctionalExpressionField(ComplexField) val context = FunctionalExpressionField(ComplexField)
val expression = context { val expression = context {
val x = bind(x) val x = bindSymbol(x)
x * x + 2 * x + one x * x + 2 * x + one
} }

View File

@ -1,6 +1,6 @@
package kscience.kmath.complex package space.kscience.kmath.complex
import kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
package kscience.kmath.domains package space.kscience.kmath.domains
import kscience.kmath.linear.Point import space.kscience.kmath.linear.Point
/** /**
* A simple geometric domain. * A simple geometric domain.

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package kscience.kmath.domains package space.kscience.kmath.domains
import kscience.kmath.linear.Point import space.kscience.kmath.linear.Point
import kscience.kmath.structures.RealBuffer import space.kscience.kmath.structures.RealBuffer
import kscience.kmath.structures.indices import space.kscience.kmath.structures.indices
/** /**
* *

View File

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package kscience.kmath.domains package space.kscience.kmath.domains
import kscience.kmath.linear.Point import space.kscience.kmath.linear.Point
/** /**
* n-dimensional volume * n-dimensional volume

View File

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package kscience.kmath.domains package space.kscience.kmath.domains
import kscience.kmath.linear.Point import space.kscience.kmath.linear.Point
public class UnconstrainedDomain(public override val dimension: Int) : RealDomain { public class UnconstrainedDomain(public override val dimension: Int) : RealDomain {
public override operator fun contains(point: Point<Double>): Boolean = true public override operator fun contains(point: Point<Double>): Boolean = true

View File

@ -1,7 +1,7 @@
package kscience.kmath.domains package space.kscience.kmath.domains
import kscience.kmath.linear.Point import space.kscience.kmath.linear.Point
import kscience.kmath.structures.asBuffer import space.kscience.kmath.structures.asBuffer
public inline class UnivariateDomain(public val range: ClosedFloatingPointRange<Double>) : RealDomain { public inline class UnivariateDomain(public val range: ClosedFloatingPointRange<Double>) : RealDomain {
public override val dimension: Int public override val dimension: Int

View File

@ -1,4 +1,4 @@
package kscience.kmath.expressions package space.kscience.kmath.expressions
/** /**
* Represents expression which structure can be differentiated. * Represents expression which structure can be differentiated.

View File

@ -1,6 +1,6 @@
package kscience.kmath.expressions package space.kscience.kmath.expressions
import kscience.kmath.operations.Algebra import space.kscience.kmath.operations.Algebra
import kotlin.jvm.JvmName import kotlin.jvm.JvmName
import kotlin.properties.ReadOnlyProperty import kotlin.properties.ReadOnlyProperty
@ -73,12 +73,12 @@ public interface ExpressionAlgebra<in T, E> : Algebra<E> {
/** /**
* Bind a given [Symbol] to this context variable and produce context-specific object. Return null if symbol could not be bound in current context. * Bind a given [Symbol] to this context variable and produce context-specific object. Return null if symbol could not be bound in current context.
*/ */
public fun bindOrNull(symbol: Symbol): E? public fun bindSymbolOrNull(symbol: Symbol): E?
/** /**
* Bind a string to a context using [StringSymbol] * Bind a string to a context using [StringSymbol]
*/ */
override fun symbol(value: String): E = bind(StringSymbol(value)) override fun bindSymbol(value: String): E = bindSymbol(StringSymbol(value))
/** /**
* A constant expression which does not depend on arguments * A constant expression which does not depend on arguments
@ -89,8 +89,8 @@ public interface ExpressionAlgebra<in T, E> : Algebra<E> {
/** /**
* Bind a given [Symbol] to this context variable and produce context-specific object. * Bind a given [Symbol] to this context variable and produce context-specific object.
*/ */
public fun <T, E> ExpressionAlgebra<T, E>.bind(symbol: Symbol): E = public fun <T, E> ExpressionAlgebra<T, E>.bindSymbol(symbol: Symbol): E =
bindOrNull(symbol) ?: error("Symbol $symbol could not be bound to $this") bindSymbolOrNull(symbol) ?: error("Symbol $symbol could not be bound to $this")
/** /**
* A delegate to create a symbol with a string identity in this scope * A delegate to create a symbol with a string identity in this scope
@ -103,5 +103,5 @@ public val symbol: ReadOnlyProperty<Any?, Symbol> = ReadOnlyProperty { _, prope
* Bind a symbol by name inside the [ExpressionAlgebra] * Bind a symbol by name inside the [ExpressionAlgebra]
*/ */
public fun <T, E> ExpressionAlgebra<T, E>.binding(): ReadOnlyProperty<Any?, E> = ReadOnlyProperty { _, property -> public fun <T, E> ExpressionAlgebra<T, E>.binding(): ReadOnlyProperty<Any?, E> = ReadOnlyProperty { _, property ->
bind(StringSymbol(property.name)) ?: error("A variable with name ${property.name} does not exist") bindSymbol(StringSymbol(property.name)) ?: error("A variable with name ${property.name} does not exist")
} }

View File

@ -1,6 +1,6 @@
package kscience.kmath.expressions package space.kscience.kmath.expressions
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
/** /**
* A context class for [Expression] construction. * A context class for [Expression] construction.
@ -18,7 +18,7 @@ public abstract class FunctionalExpressionAlgebra<T, A : Algebra<T>>(
/** /**
* Builds an Expression to access a variable. * Builds an Expression to access a variable.
*/ */
public override fun bindOrNull(symbol: Symbol): Expression<T>? = Expression { arguments -> public override fun bindSymbolOrNull(symbol: Symbol): Expression<T>? = Expression { arguments ->
arguments[symbol] ?: error("Argument not found: $symbol") arguments[symbol] ?: error("Argument not found: $symbol")
} }

View File

@ -1,9 +1,9 @@
package kscience.kmath.expressions package space.kscience.kmath.expressions
import kscience.kmath.linear.Point import space.kscience.kmath.linear.Point
import kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.misc.UnstableKMathAPI
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
import kscience.kmath.structures.asBuffer import space.kscience.kmath.structures.asBuffer
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract
@ -117,7 +117,7 @@ public open class SimpleAutoDiffField<T : Any, F : Field<T>>(
override fun hashCode(): Int = identity.hashCode() override fun hashCode(): Int = identity.hashCode()
} }
public override fun bindOrNull(symbol: Symbol): AutoDiffValue<T>? = bindings[symbol.identity] public override fun bindSymbolOrNull(symbol: Symbol): AutoDiffValue<T>? = bindings[symbol.identity]
private fun getDerivative(variable: AutoDiffValue<T>): T = private fun getDerivative(variable: AutoDiffValue<T>): T =
(variable as? AutoDiffVariableWithDerivative)?.d ?: derivatives[variable] ?: context.zero (variable as? AutoDiffVariableWithDerivative)?.d ?: derivatives[variable] ?: context.zero

View File

@ -1,12 +1,12 @@
package kscience.kmath.expressions package space.kscience.kmath.expressions
import kscience.kmath.linear.Point import space.kscience.kmath.linear.Point
import kscience.kmath.nd.Structure2D import space.kscience.kmath.nd.Structure2D
import kscience.kmath.structures.BufferFactory import space.kscience.kmath.structures.BufferFactory
/** /**
* An environment to easy transform indexed variables to symbols and back. * An environment to easy transform indexed variables to symbols and back.
* TODO requires multi-receivers to be beutiful * TODO requires multi-receivers to be beautiful
*/ */
public interface SymbolIndexer { public interface SymbolIndexer {
public val symbols: List<Symbol> public val symbols: List<Symbol>

View File

@ -1,9 +1,9 @@
package kscience.kmath.expressions package space.kscience.kmath.expressions
import kscience.kmath.operations.ExtendedField import space.kscience.kmath.operations.ExtendedField
import kscience.kmath.operations.Field import space.kscience.kmath.operations.Field
import kscience.kmath.operations.Ring import space.kscience.kmath.operations.Ring
import kscience.kmath.operations.Space import space.kscience.kmath.operations.Space
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract

View File

@ -1,12 +1,12 @@
package kscience.kmath.linear package space.kscience.kmath.linear
import kscience.kmath.nd.NDStructure import space.kscience.kmath.nd.NDStructure
import kscience.kmath.nd.Structure2D import space.kscience.kmath.nd.Structure2D
import kscience.kmath.operations.Ring import space.kscience.kmath.operations.Ring
import kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Buffer
import kscience.kmath.structures.BufferFactory import space.kscience.kmath.structures.BufferFactory
import kscience.kmath.structures.asSequence import space.kscience.kmath.structures.asSequence
/** /**
* Alias for [Structure2D] with more familiar name. * Alias for [Structure2D] with more familiar name.

View File

@ -1,7 +1,7 @@
package kscience.kmath.linear package space.kscience.kmath.linear
import kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Buffer
import kscience.kmath.structures.VirtualBuffer import space.kscience.kmath.structures.VirtualBuffer
public typealias Point<T> = Buffer<T> public typealias Point<T> = Buffer<T>

View File

@ -1,9 +1,12 @@
package kscience.kmath.linear package space.kscience.kmath.linear
import kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.misc.UnstableKMathAPI
import kscience.kmath.nd.getFeature import space.kscience.kmath.nd.getFeature
import kscience.kmath.operations.* import space.kscience.kmath.operations.*
import kscience.kmath.structures.* import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.BufferAccessor2D
import space.kscience.kmath.structures.MutableBuffer
import space.kscience.kmath.structures.MutableBufferFactory
/** /**
* Common implementation of [LupDecompositionFeature]. * Common implementation of [LupDecompositionFeature].

View File

@ -1,9 +1,9 @@
package kscience.kmath.linear package space.kscience.kmath.linear
import kscience.kmath.nd.Structure2D import space.kscience.kmath.nd.Structure2D
import kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Buffer
import kscience.kmath.structures.BufferFactory import space.kscience.kmath.structures.BufferFactory
import kscience.kmath.structures.asBuffer import space.kscience.kmath.structures.asBuffer
public class MatrixBuilder(public val rows: Int, public val columns: Int) { public class MatrixBuilder(public val rows: Int, public val columns: Int) {
public operator fun <T : Any> invoke(vararg elements: T): Matrix<T> { public operator fun <T : Any> invoke(vararg elements: T): Matrix<T> {

View File

@ -1,12 +1,12 @@
package kscience.kmath.linear package space.kscience.kmath.linear
import kscience.kmath.operations.Ring import space.kscience.kmath.operations.Ring
import kscience.kmath.operations.SpaceOperations import space.kscience.kmath.operations.SpaceOperations
import kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import kscience.kmath.operations.sum import space.kscience.kmath.operations.sum
import kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Buffer
import kscience.kmath.structures.BufferFactory import space.kscience.kmath.structures.BufferFactory
import kscience.kmath.structures.asSequence import space.kscience.kmath.structures.asSequence
/** /**
* Basic operations on matrices. Operates on [Matrix]. * Basic operations on matrices. Operates on [Matrix].

View File

@ -1,4 +1,4 @@
package kscience.kmath.linear package space.kscience.kmath.linear
/** /**
* A marker interface representing some properties of matrices or additional transformations of them. Features are used * A marker interface representing some properties of matrices or additional transformations of them. Features are used

View File

@ -1,10 +1,10 @@
package kscience.kmath.linear package space.kscience.kmath.linear
import kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.misc.UnstableKMathAPI
import kscience.kmath.nd.Structure2D import space.kscience.kmath.nd.Structure2D
import kscience.kmath.nd.getFeature import space.kscience.kmath.nd.getFeature
import kscience.kmath.operations.Ring import space.kscience.kmath.operations.Ring
import kscience.kmath.structures.asBuffer import space.kscience.kmath.structures.asBuffer
import kotlin.math.sqrt import kotlin.math.sqrt
import kotlin.reflect.KClass import kotlin.reflect.KClass
import kotlin.reflect.safeCast import kotlin.reflect.safeCast

View File

@ -1,6 +1,6 @@
package kscience.kmath.linear package space.kscience.kmath.linear
import kscience.kmath.structures.RealBuffer import space.kscience.kmath.structures.RealBuffer
public object RealMatrixContext : MatrixContext<Double, BufferMatrix<Double>> { public object RealMatrixContext : MatrixContext<Double, BufferMatrix<Double>> {

View File

@ -1,10 +1,10 @@
package kscience.kmath.linear package space.kscience.kmath.linear
import kscience.kmath.operations.RealField import space.kscience.kmath.operations.RealField
import kscience.kmath.operations.Space import space.kscience.kmath.operations.Space
import kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Buffer
import kscience.kmath.structures.BufferFactory import space.kscience.kmath.structures.BufferFactory
/** /**
* A linear space for vectors. * A linear space for vectors.

View File

@ -1,4 +1,4 @@
package kscience.kmath.linear package space.kscience.kmath.linear
/** /**
* The matrix where each element is evaluated each time when is being accessed. * The matrix where each element is evaluated each time when is being accessed.

View File

@ -1,4 +1,4 @@
package kscience.kmath.misc package space.kscience.kmath.misc
@RequiresOptIn("This API is unstable and could change in future", RequiresOptIn.Level.WARNING) @RequiresOptIn("This API is unstable and could change in future", RequiresOptIn.Level.WARNING)
public annotation class UnstableKMathAPI public annotation class UnstableKMathAPI

View File

@ -1,7 +1,7 @@
package kscience.kmath.misc package space.kscience.kmath.misc
import kscience.kmath.operations.Space import space.kscience.kmath.operations.Space
import kscience.kmath.operations.invoke import space.kscience.kmath.operations.invoke
import kotlin.jvm.JvmName import kotlin.jvm.JvmName
/** /**

View File

@ -1,9 +1,11 @@
package kscience.kmath.nd package space.kscience.kmath.nd
import kscience.kmath.nd.* import space.kscience.kmath.operations.Field
import kscience.kmath.operations.* import space.kscience.kmath.operations.RealField
import kscience.kmath.structures.Buffer import space.kscience.kmath.operations.Ring
import kscience.kmath.structures.BufferFactory import space.kscience.kmath.operations.Space
import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.BufferFactory
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract

Some files were not shown because too many files have changed in this diff Show More