diff --git a/CHANGELOG.md b/CHANGELOG.md index fdace591c..c7fe7eed2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - DataSets are moved from functions to core - Redesign advanced Chain API - Redesign MST. Remove MSTExpression. +- Move MST to core ### Deprecated diff --git a/README.md b/README.md index 7b78d4531..bacf77bd5 100644 --- a/README.md +++ b/README.md @@ -87,9 +87,9 @@ KMath is a modular library. Different modules provide different features with di > > **Features:** > - [expression-language](kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt) : Expression language and its parser -> - [mst](kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt) : MST (Mathematical Syntax Tree) as expression language's syntax intermediate representation -> - [mst-building](kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt) : MST building algebraic structure -> - [mst-interpreter](kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt) : MST interpreter +> - [mst](kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt) : MST (Mathematical Syntax Tree) as expression language's syntax intermediate representation +> - [mst-building](kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt) : MST building algebraic structure +> - [mst-interpreter](kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt) : MST interpreter > - [mst-jvm-codegen](kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt) : Dynamic MST to JVM bytecode compiler > - [mst-js-codegen](kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt) : Dynamic MST to JS compiler diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 5968f118c..3fc2ec7f0 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") kotlin("plugin.allopen") - id("kotlinx.benchmark") + id("org.jetbrains.kotlinx.benchmark") } allOpen.annotation("org.openjdk.jmh.annotations.State") @@ -56,7 +56,7 @@ dependencies { implementation("org.nd4j:nd4j-native-platform:1.0.0-beta7") implementation("org.jetbrains.kotlinx:kotlinx-io:0.2.0-npm-dev-11") - implementation("org.jetbrains.kotlinx:kotlinx.benchmark.runtime:0.2.0-dev-20") + implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.3.0") implementation("org.slf4j:slf4j-simple:1.7.30") // plotting diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt index ad2a57597..a9c192e55 100644 --- a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt @@ -5,11 +5,7 @@ import kotlinx.benchmark.Blackhole import kotlinx.benchmark.Scope import kotlinx.benchmark.State import space.kscience.kmath.asm.compileToExpression -import space.kscience.kmath.ast.MstField -import space.kscience.kmath.ast.toExpression -import space.kscience.kmath.expressions.Expression -import space.kscience.kmath.expressions.expressionInField -import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.expressions.* import space.kscience.kmath.misc.symbol import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.bindSymbol diff --git a/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt b/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt index a4b8b7ca4..c6308c567 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt @@ -1,5 +1,7 @@ package space.kscience.kmath.ast +import space.kscience.kmath.expressions.MstField +import space.kscience.kmath.expressions.interpret import space.kscience.kmath.misc.Symbol.Companion.x import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.bindSymbol diff --git a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt index 5cf96adaa..41c3c64d7 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt @@ -3,12 +3,12 @@ package space.kscience.kmath.stat import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking +import org.apache.commons.rng.sampling.distribution.BoxMullerNormalizedGaussianSampler import org.apache.commons.rng.simple.RandomSource import space.kscience.kmath.samplers.GaussianSampler import java.time.Duration import java.time.Instant import org.apache.commons.rng.sampling.distribution.GaussianSampler as CMGaussianSampler -import org.apache.commons.rng.sampling.distribution.ZigguratNormalizedGaussianSampler as CMZigguratNormalizedGaussianSampler private suspend fun runKMathChained(): Duration { val generator = RandomGenerator.fromSource(RandomSource.MT, 123L) @@ -34,7 +34,7 @@ private fun runApacheDirect(): Duration { val rng = RandomSource.create(RandomSource.MT, 123L) val sampler = CMGaussianSampler.of( - CMZigguratNormalizedGaussianSampler.of(rng), + BoxMullerNormalizedGaussianSampler.of(rng), 7.0, 2.0 ) @@ -59,8 +59,8 @@ private fun runApacheDirect(): Duration { * Comparing chain sampling performance with direct sampling performance */ fun main(): Unit = runBlocking(Dispatchers.Default) { - val chainJob = async { runKMathChained() } val directJob = async { runApacheDirect() } + val chainJob = async { runKMathChained() } println("KMath Chained: ${chainJob.await()}") println("Apache Direct: ${directJob.await()}") } diff --git a/gradle.properties b/gradle.properties index 50123b16c..725d380f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,5 +4,5 @@ kotlin.mpp.stability.nowarn=true kotlin.native.enableDependencyPropagation=false kotlin.parallel.tasks.in.project=true org.gradle.configureondemand=true -org.gradle.jvmargs=-XX:MaxMetaspaceSize=9G +org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G org.gradle.parallel=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 442d9132e..f371643ee 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/kmath-ast/README.md b/kmath-ast/README.md index 44faa5cd5..547775efc 100644 --- a/kmath-ast/README.md +++ b/kmath-ast/README.md @@ -3,9 +3,9 @@ Abstract syntax tree expression representation and related optimizations. - [expression-language](src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt) : Expression language and its parser - - [mst](src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt) : MST (Mathematical Syntax Tree) as expression language's syntax intermediate representation - - [mst-building](src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt) : MST building algebraic structure - - [mst-interpreter](src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt) : MST interpreter + - [mst](../kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt) : MST (Mathematical Syntax Tree) as expression language's syntax intermediate representation + - [mst-building](../kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt) : MST building algebraic structure + - [mst-interpreter](../kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt) : MST interpreter - [mst-jvm-codegen](src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt) : Dynamic MST to JVM bytecode compiler - [mst-js-codegen](src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt) : Dynamic MST to JS compiler diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index e3a7faf0a..28abc06f2 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -1,7 +1,6 @@ -import ru.mipt.npm.gradle.Maturity - plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") } kotlin.js { @@ -52,7 +51,7 @@ tasks.dokkaHtml { } readme { - maturity = Maturity.PROTOTYPE + maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature( diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt index 14e14404c..b056496a8 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt @@ -1,6 +1,6 @@ package space.kscience.kmath.ast.rendering -import space.kscience.kmath.ast.MST +import space.kscience.kmath.expressions.MST /** * Renders [MST] to [MathSyntax]. diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt index 95108ba45..8cbc4e614 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt @@ -1,7 +1,7 @@ package space.kscience.kmath.ast.rendering -import space.kscience.kmath.ast.MST import space.kscience.kmath.ast.rendering.FeaturedMathRenderer.RenderFeature +import space.kscience.kmath.expressions.MST import space.kscience.kmath.operations.* import kotlin.reflect.KClass diff --git a/kmath-ast/src/commonTest/kotlin/space/kscisnce/kmath/ast/InterpretTest.kt b/kmath-ast/src/commonTest/kotlin/space/kscisnce/kmath/ast/InterpretTest.kt index 1b8ec1490..be7a5df9d 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscisnce/kmath/ast/InterpretTest.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscisnce/kmath/ast/InterpretTest.kt @@ -1,8 +1,8 @@ package space.kscisnce.kmath.ast -import space.kscience.kmath.ast.MstField -import space.kscience.kmath.ast.toExpression +import space.kscience.kmath.expressions.MstField import space.kscience.kmath.expressions.invoke +import space.kscience.kmath.expressions.toExpression import space.kscience.kmath.misc.Symbol.Companion.x import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.bindSymbol diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt index 796ffce1e..1d04a72db 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt @@ -1,10 +1,10 @@ package space.kscience.kmath.estree -import space.kscience.kmath.ast.MST -import space.kscience.kmath.ast.MST.* import space.kscience.kmath.estree.internal.ESTreeBuilder import space.kscience.kmath.estree.internal.estree.BaseExpression import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.MST +import space.kscience.kmath.expressions.MST.* import space.kscience.kmath.expressions.invoke import space.kscience.kmath.misc.Symbol import space.kscience.kmath.operations.Algebra @@ -26,16 +26,17 @@ internal fun MST.compileWith(algebra: Algebra): Expression { is Unary -> when { algebra is NumericAlgebra && node.value is Numeric -> constant( - algebra.unaryOperationFunction(node.operation)(algebra.number(node.value.value))) + algebra.unaryOperationFunction(node.operation)(algebra.number((node.value as Numeric).value))) else -> call(algebra.unaryOperationFunction(node.operation), visit(node.value)) } is Binary -> when { algebra is NumericAlgebra && node.left is Numeric && node.right is Numeric -> constant( - algebra - .binaryOperationFunction(node.operation) - .invoke(algebra.number(node.left.value), algebra.number(node.right.value)) + algebra.binaryOperationFunction(node.operation).invoke( + algebra.number((node.left as Numeric).value), + algebra.number((node.right as Numeric).value) + ) ) algebra is NumericAlgebra && node.left is Numeric -> call( @@ -70,12 +71,12 @@ public fun MST.compileToExpression(algebra: Algebra): Expression /** * Compile given MST to expression and evaluate it against [arguments] */ -public inline fun MST.compile(algebra: Algebra, arguments: Map): T = +public inline fun MST.compile(algebra: Algebra, arguments: Map): T = compileToExpression(algebra).invoke(arguments) /** * Compile given MST to expression and evaluate it against [arguments] */ -public inline fun MST.compile(algebra: Algebra, vararg arguments: Pair): T = +public inline fun MST.compile(algebra: Algebra, vararg arguments: Pair): T = compileToExpression(algebra).invoke(*arguments) diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt index fb8d73c0c..4944e2fc3 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt @@ -1,8 +1,8 @@ package space.kscience.kmath.estree -import space.kscience.kmath.ast.* import space.kscience.kmath.complex.ComplexField import space.kscience.kmath.complex.toComplex +import space.kscience.kmath.expressions.* import space.kscience.kmath.misc.Symbol import space.kscience.kmath.operations.ByteRing import space.kscience.kmath.operations.DoubleField diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt index 24c003e3e..0217ffcec 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt @@ -1,6 +1,6 @@ package space.kscience.kmath.estree -import space.kscience.kmath.ast.MstExtendedField +import space.kscience.kmath.expressions.MstExtendedField import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt index c83fbc391..939c82270 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt @@ -1,6 +1,6 @@ package space.kscience.kmath.estree -import space.kscience.kmath.ast.MstExtendedField +import space.kscience.kmath.expressions.MstExtendedField import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeVariables.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeVariables.kt index 0b1c1c33e..49fa31b9f 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeVariables.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeVariables.kt @@ -1,6 +1,6 @@ package space.kscience.kmath.estree -import space.kscience.kmath.ast.MstRing +import space.kscience.kmath.expressions.MstRing import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.ByteRing import space.kscience.kmath.operations.invoke diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt index ee2b6fb54..a8716a64e 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt @@ -2,9 +2,9 @@ package space.kscience.kmath.asm import space.kscience.kmath.asm.internal.AsmBuilder import space.kscience.kmath.asm.internal.buildName -import space.kscience.kmath.ast.MST -import space.kscience.kmath.ast.MST.* import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.MST +import space.kscience.kmath.expressions.MST.* import space.kscience.kmath.expressions.invoke import space.kscience.kmath.misc.Symbol import space.kscience.kmath.operations.Algebra @@ -34,15 +34,17 @@ internal fun MST.compileWith(type: Class, algebra: Algebra): Exp is Unary -> when { algebra is NumericAlgebra && node.value is Numeric -> loadObjectConstant( - algebra.unaryOperationFunction(node.operation)(algebra.number(node.value.value))) + algebra.unaryOperationFunction(node.operation)(algebra.number((node.value as Numeric).value))) else -> buildCall(algebra.unaryOperationFunction(node.operation)) { visit(node.value) } } is Binary -> when { algebra is NumericAlgebra && node.left is Numeric && node.right is Numeric -> loadObjectConstant( - algebra.binaryOperationFunction(node.operation) - .invoke(algebra.number(node.left.value), algebra.number(node.right.value)) + algebra.binaryOperationFunction(node.operation).invoke( + algebra.number((node.left as Numeric).value), + algebra.number((node.right as Numeric).value) + ) ) algebra is NumericAlgebra && node.left is Numeric -> buildCall( @@ -71,18 +73,18 @@ internal fun MST.compileWith(type: Class, algebra: Algebra): Exp /** * Create a compiled expression with given [MST] and given [algebra]. */ -public inline fun MST.compileToExpression(algebra: Algebra): Expression = +public inline fun MST.compileToExpression(algebra: Algebra): Expression = compileWith(T::class.java, algebra) /** * Compile given MST to expression and evaluate it against [arguments] */ -public inline fun MST.compile(algebra: Algebra, arguments: Map): T = +public inline fun MST.compile(algebra: Algebra, arguments: Map): T = compileToExpression(algebra).invoke(arguments) /** * Compile given MST to expression and evaluate it against [arguments] */ -public inline fun MST.compile(algebra: Algebra, vararg arguments: Pair): T = +public inline fun MST.compile(algebra: Algebra, vararg arguments: Pair): T = compileToExpression(algebra).invoke(*arguments) diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt index a03af5bf9..43704c815 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt @@ -5,8 +5,8 @@ import org.objectweb.asm.Opcodes.* import org.objectweb.asm.Type.* import org.objectweb.asm.commons.InstructionAdapter import space.kscience.kmath.asm.internal.AsmBuilder.ClassLoader -import space.kscience.kmath.ast.MST import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.MST import java.lang.invoke.MethodHandles import java.lang.invoke.MethodType import java.util.stream.Collectors.toMap diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt index 4522c966f..646879c02 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt @@ -2,8 +2,8 @@ package space.kscience.kmath.asm.internal import org.objectweb.asm.* import org.objectweb.asm.commons.InstructionAdapter -import space.kscience.kmath.ast.MST import space.kscience.kmath.expressions.Expression +import space.kscience.kmath.expressions.MST import kotlin.contracts.InvocationKind import kotlin.contracts.contract diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt index 8ecb0adda..2991dd68a 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/parser.kt @@ -13,6 +13,7 @@ import com.github.h0tk3y.betterParse.lexer.literalToken import com.github.h0tk3y.betterParse.lexer.regexToken import com.github.h0tk3y.betterParse.parser.ParseResult import com.github.h0tk3y.betterParse.parser.Parser +import space.kscience.kmath.expressions.MST import space.kscience.kmath.operations.FieldOperations import space.kscience.kmath.operations.GroupOperations import space.kscience.kmath.operations.PowerOperations diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt index 096bf4447..aefe15fe9 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt @@ -1,8 +1,8 @@ package space.kscience.kmath.asm -import space.kscience.kmath.ast.* import space.kscience.kmath.complex.ComplexField import space.kscience.kmath.complex.toComplex +import space.kscience.kmath.expressions.* import space.kscience.kmath.misc.Symbol.Companion.x import space.kscience.kmath.operations.ByteRing import space.kscience.kmath.operations.DoubleField diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt index d1a216ede..4ab953b26 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt @@ -1,8 +1,8 @@ package space.kscience.kmath.asm -import space.kscience.kmath.ast.MstExtendedField -import space.kscience.kmath.ast.MstField -import space.kscience.kmath.ast.MstGroup +import space.kscience.kmath.expressions.MstExtendedField +import space.kscience.kmath.expressions.MstField +import space.kscience.kmath.expressions.MstGroup import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt index 75a3ffaee..6c988cbe2 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt @@ -1,6 +1,6 @@ package space.kscience.kmath.asm -import space.kscience.kmath.ast.MstExtendedField +import space.kscience.kmath.expressions.MstExtendedField import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmVariables.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmVariables.kt index 144d63eea..14868ee01 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmVariables.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmVariables.kt @@ -1,6 +1,6 @@ package space.kscience.kmath.asm -import space.kscience.kmath.ast.MstRing +import space.kscience.kmath.expressions.MstRing import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.ByteRing import space.kscience.kmath.operations.invoke diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt index 1450cab84..e4eef757d 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt @@ -1,5 +1,6 @@ package space.kscience.kmath.ast +import space.kscience.kmath.expressions.evaluate import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.Field import kotlin.test.Test diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt index 2b83e566e..584737633 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt @@ -2,6 +2,9 @@ package space.kscience.kmath.ast import space.kscience.kmath.complex.Complex import space.kscience.kmath.complex.ComplexField +import space.kscience.kmath.expressions.MstField +import space.kscience.kmath.expressions.evaluate +import space.kscience.kmath.expressions.interpret import space.kscience.kmath.operations.Algebra import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt index 5850ea23d..9d335dbf9 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt @@ -1,7 +1,7 @@ package space.kscience.kmath.ast.rendering -import space.kscience.kmath.ast.MST.Numeric import space.kscience.kmath.ast.rendering.TestUtils.testLatex +import space.kscience.kmath.expressions.MST.Numeric import kotlin.test.Test internal class TestFeatures { diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt index 599bee436..8902a63e3 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt @@ -1,7 +1,7 @@ package space.kscience.kmath.ast.rendering -import space.kscience.kmath.ast.MST import space.kscience.kmath.ast.rendering.TestUtils.testLatex +import space.kscience.kmath.expressions.MST import space.kscience.kmath.operations.GroupOperations import kotlin.test.Test diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt index 6fadef6cd..c1c4468aa 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt @@ -1,7 +1,7 @@ package space.kscience.kmath.ast.rendering -import space.kscience.kmath.ast.MST import space.kscience.kmath.ast.rendering.TestUtils.testMathML +import space.kscience.kmath.expressions.MST import space.kscience.kmath.operations.GroupOperations import kotlin.test.Test diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt index e6359bcc9..5a0d4f8e4 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt @@ -1,7 +1,7 @@ package space.kscience.kmath.ast.rendering -import space.kscience.kmath.ast.MST import space.kscience.kmath.ast.parseMath +import space.kscience.kmath.expressions.MST import kotlin.test.assertEquals internal object TestUtils { diff --git a/kmath-commons/build.gradle.kts b/kmath-commons/build.gradle.kts index 56dcef29a..2f9a83df2 100644 --- a/kmath-commons/build.gradle.kts +++ b/kmath-commons/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - id("ru.mipt.npm.gradle.jvm") + kotlin("jvm") + id("ru.mipt.npm.gradle.common") } description = "Commons math binding for kmath" diff --git a/kmath-complex/build.gradle.kts b/kmath-complex/build.gradle.kts index 5b9dc3ba0..5244a03f0 100644 --- a/kmath-complex/build.gradle.kts +++ b/kmath-complex/build.gradle.kts @@ -1,7 +1,6 @@ -import ru.mipt.npm.gradle.Maturity - plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") id("ru.mipt.npm.gradle.native") } @@ -19,7 +18,7 @@ kotlin.sourceSets { readme { description = "Complex numbers and quaternions." - maturity = Maturity.PROTOTYPE + maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature( diff --git a/kmath-core/api/kmath-core.api b/kmath-core/api/kmath-core.api index f76372a3d..08aa1bbe4 100644 --- a/kmath-core/api/kmath-core.api +++ b/kmath-core/api/kmath-core.api @@ -217,6 +217,332 @@ public class space/kscience/kmath/expressions/FunctionalExpressionRing : space/k public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; } +public abstract class space/kscience/kmath/expressions/MST { +} + +public final class space/kscience/kmath/expressions/MST$Binary : space/kscience/kmath/expressions/MST { + public fun (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Lspace/kscience/kmath/expressions/MST; + public final fun component3 ()Lspace/kscience/kmath/expressions/MST; + public final fun copy (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public static synthetic fun copy$default (Lspace/kscience/kmath/expressions/MST$Binary;Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;ILjava/lang/Object;)Lspace/kscience/kmath/expressions/MST$Binary; + public fun equals (Ljava/lang/Object;)Z + public final fun getLeft ()Lspace/kscience/kmath/expressions/MST; + public final fun getOperation ()Ljava/lang/String; + public final fun getRight ()Lspace/kscience/kmath/expressions/MST; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class space/kscience/kmath/expressions/MST$Numeric : space/kscience/kmath/expressions/MST { + public fun (Ljava/lang/Number;)V + public final fun component1 ()Ljava/lang/Number; + public final fun copy (Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST$Numeric; + public static synthetic fun copy$default (Lspace/kscience/kmath/expressions/MST$Numeric;Ljava/lang/Number;ILjava/lang/Object;)Lspace/kscience/kmath/expressions/MST$Numeric; + public fun equals (Ljava/lang/Object;)Z + public final fun getValue ()Ljava/lang/Number; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class space/kscience/kmath/expressions/MST$Symbolic : space/kscience/kmath/expressions/MST { + public fun (Ljava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST$Symbolic; + public static synthetic fun copy$default (Lspace/kscience/kmath/expressions/MST$Symbolic;Ljava/lang/String;ILjava/lang/Object;)Lspace/kscience/kmath/expressions/MST$Symbolic; + public fun equals (Ljava/lang/Object;)Z + public final fun getValue ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class space/kscience/kmath/expressions/MST$Unary : space/kscience/kmath/expressions/MST { + public fun (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Lspace/kscience/kmath/expressions/MST; + public final fun copy (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public static synthetic fun copy$default (Lspace/kscience/kmath/expressions/MST$Unary;Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;ILjava/lang/Object;)Lspace/kscience/kmath/expressions/MST$Unary; + public fun equals (Ljava/lang/Object;)Z + public final fun getOperation ()Ljava/lang/String; + public final fun getValue ()Lspace/kscience/kmath/expressions/MST; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class space/kscience/kmath/expressions/MSTKt { + public static final fun evaluate (Lspace/kscience/kmath/operations/Algebra;Lspace/kscience/kmath/expressions/MST;)Ljava/lang/Object; + public static final fun interpret (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/operations/Algebra;Ljava/util/Map;)Ljava/lang/Object; + public static final fun interpret (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/operations/Algebra;[Lkotlin/Pair;)Ljava/lang/Object; + public static final fun toExpression (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/operations/Algebra;)Lspace/kscience/kmath/expressions/Expression; +} + +public final class space/kscience/kmath/expressions/MstAlgebra : space/kscience/kmath/operations/NumericAlgebra { + public static final field INSTANCE Lspace/kscience/kmath/expressions/MstAlgebra; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST$Symbolic; + public synthetic fun bindSymbolOrNull (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbolOrNull (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST$Symbolic; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/expressions/MstExtendedField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/NumericAlgebra { + public static final field INSTANCE Lspace/kscience/kmath/expressions/MstExtendedField; + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun bindSymbolOrNull (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbolOrNull (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST$Symbolic; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun div (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/expressions/MST;D)Lspace/kscience/kmath/expressions/MST; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun times (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; +} + +public final class space/kscience/kmath/expressions/MstField : space/kscience/kmath/operations/Field, space/kscience/kmath/operations/NumbersAddOperations, space/kscience/kmath/operations/ScaleOperations { + public static final field INSTANCE Lspace/kscience/kmath/expressions/MstField; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun bindSymbolOrNull (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbolOrNull (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST$Symbolic; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun div (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun minus (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun plus (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/expressions/MST;D)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun times (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; +} + +public final class space/kscience/kmath/expressions/MstGroup : space/kscience/kmath/operations/Group, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/ScaleOperations { + public static final field INSTANCE Lspace/kscience/kmath/expressions/MstGroup; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun bindSymbolOrNull (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbolOrNull (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST$Symbolic; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/expressions/MST;D)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; +} + +public final class space/kscience/kmath/expressions/MstRing : space/kscience/kmath/operations/NumbersAddOperations, space/kscience/kmath/operations/Ring, space/kscience/kmath/operations/ScaleOperations { + public static final field INSTANCE Lspace/kscience/kmath/expressions/MstRing; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun bindSymbolOrNull (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbolOrNull (Ljava/lang/String;)Lspace/kscience/kmath/expressions/MST$Symbolic; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun minus (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST$Numeric; + public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun plus (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/expressions/MST;D)Lspace/kscience/kmath/expressions/MST$Binary; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/expressions/MST;Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST; + public fun times (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; +} + public final class space/kscience/kmath/expressions/SimpleAutoDiffExpression : space/kscience/kmath/expressions/FirstDerivativeExpression { public fun (Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)V public fun derivativeOrNull (Lspace/kscience/kmath/misc/Symbol;)Lspace/kscience/kmath/expressions/Expression; diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 2fed3eb2f..92a5f419d 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -1,7 +1,6 @@ -import ru.mipt.npm.gradle.Maturity - plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") id("ru.mipt.npm.gradle.native") } @@ -15,7 +14,7 @@ kotlin.sourceSets { readme { description = "Core classes, algebra definitions, basic linear algebra" - maturity = Maturity.DEVELOPMENT + maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature( diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt similarity index 98% rename from kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt index 538db0caa..d05e3a389 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt @@ -1,6 +1,5 @@ -package space.kscience.kmath.ast +package space.kscience.kmath.expressions -import space.kscience.kmath.expressions.Expression import space.kscience.kmath.misc.StringSymbol import space.kscience.kmath.misc.Symbol import space.kscience.kmath.operations.Algebra diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt similarity index 99% rename from kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt index 33fca7521..3151ebaa0 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt @@ -1,4 +1,4 @@ -package space.kscience.kmath.ast +package space.kscience.kmath.expressions import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.operations.* diff --git a/kmath-coroutines/build.gradle.kts b/kmath-coroutines/build.gradle.kts index b68dd2e8d..d3f6711a6 100644 --- a/kmath-coroutines/build.gradle.kts +++ b/kmath-coroutines/build.gradle.kts @@ -1,4 +1,6 @@ -plugins { id("ru.mipt.npm.gradle.mpp") } +plugins { + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common")} kotlin.sourceSets { all { diff --git a/kmath-dimensions/build.gradle.kts b/kmath-dimensions/build.gradle.kts index 3c73f34e6..885f3c227 100644 --- a/kmath-dimensions/build.gradle.kts +++ b/kmath-dimensions/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") id("ru.mipt.npm.gradle.native") } diff --git a/kmath-ejml/build.gradle.kts b/kmath-ejml/build.gradle.kts index 5091139ac..d3a49aeb0 100644 --- a/kmath-ejml/build.gradle.kts +++ b/kmath-ejml/build.gradle.kts @@ -1,7 +1,6 @@ -import ru.mipt.npm.gradle.Maturity - plugins { - id("ru.mipt.npm.gradle.jvm") + kotlin("jvm") + id("ru.mipt.npm.gradle.common") } dependencies { @@ -10,7 +9,7 @@ dependencies { } readme { - maturity = Maturity.PROTOTYPE + maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature( diff --git a/kmath-for-real/build.gradle.kts b/kmath-for-real/build.gradle.kts index 0dcaf330a..f6d12decd 100644 --- a/kmath-for-real/build.gradle.kts +++ b/kmath-for-real/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") } kotlin.sourceSets.commonMain { diff --git a/kmath-functions/build.gradle.kts b/kmath-functions/build.gradle.kts index 51fc75501..a690170db 100644 --- a/kmath-functions/build.gradle.kts +++ b/kmath-functions/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") } kotlin.sourceSets.commonMain { diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt index ca4bbf6b8..637761497 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt @@ -1,6 +1,7 @@ package space.kscience.kmath.integration import space.kscience.kmath.misc.UnstableKMathAPI +import kotlin.jvm.JvmInline import kotlin.reflect.KClass public class UnivariateIntegrand internal constructor( @@ -26,7 +27,8 @@ public fun UnivariateIntegrand( public typealias UnivariateIntegrator = Integrator> -public inline class IntegrationRange>(public val range: ClosedRange) : IntegrandFeature +@JvmInline +public value class IntegrationRange>(public val range: ClosedRange) : IntegrandFeature public val UnivariateIntegrand.value: T? get() = getFeature>()?.value diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LoessInterpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LoessInterpolator.kt deleted file mode 100644 index 26e7a4072..000000000 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LoessInterpolator.kt +++ /dev/null @@ -1,296 +0,0 @@ -package space.kscience.kmath.interpolation -// -//import space.kscience.kmath.functions.PiecewisePolynomial -//import space.kscience.kmath.operations.Ring -//import space.kscience.kmath.structures.Buffer -//import kotlin.math.abs -//import kotlin.math.sqrt -// -// -///** -// * Original code: https://github.com/apache/commons-math/blob/eb57d6d457002a0bb5336d789a3381a24599affe/src/main/java/org/apache/commons/math4/analysis/interpolation/LoessInterpolator.java -// */ -//class LoessInterpolator>(override val algebra: Ring) : PolynomialInterpolator { -// /** -// * The bandwidth parameter: when computing the loess fit at -// * a particular point, this fraction of source points closest -// * to the current point is taken into account for computing -// * a least-squares regression. -// * -// * -// * A sensible value is usually 0.25 to 0.5. -// */ -// private var bandwidth = 0.0 -// -// /** -// * The number of robustness iterations parameter: this many -// * robustness iterations are done. -// * -// * -// * A sensible value is usually 0 (just the initial fit without any -// * robustness iterations) to 4. -// */ -// private var robustnessIters = 0 -// -// /** -// * If the median residual at a certain robustness iteration -// * is less than this amount, no more iterations are done. -// */ -// private var accuracy = 0.0 -// -// /** -// * Constructs a new [LoessInterpolator] -// * with a bandwidth of [.DEFAULT_BANDWIDTH], -// * [.DEFAULT_ROBUSTNESS_ITERS] robustness iterations -// * and an accuracy of {#link #DEFAULT_ACCURACY}. -// * See [.LoessInterpolator] for an explanation of -// * the parameters. -// */ -// fun LoessInterpolator() { -// bandwidth = DEFAULT_BANDWIDTH -// robustnessIters = DEFAULT_ROBUSTNESS_ITERS -// accuracy = DEFAULT_ACCURACY -// } -// -// fun LoessInterpolator(bandwidth: Double, robustnessIters: Int) { -// this(bandwidth, robustnessIters, DEFAULT_ACCURACY) -// } -// -// fun LoessInterpolator(bandwidth: Double, robustnessIters: Int, accuracy: Double) { -// if (bandwidth < 0 || -// bandwidth > 1 -// ) { -// throw OutOfRangeException(LocalizedFormats.BANDWIDTH, bandwidth, 0, 1) -// } -// this.bandwidth = bandwidth -// if (robustnessIters < 0) { -// throw NotPositiveException(LocalizedFormats.ROBUSTNESS_ITERATIONS, robustnessIters) -// } -// this.robustnessIters = robustnessIters -// this.accuracy = accuracy -// } -// -// fun interpolate( -// xval: DoubleArray, -// yval: DoubleArray -// ): PolynomialSplineFunction { -// return SplineInterpolator().interpolate(xval, smooth(xval, yval)) -// } -// -// fun XYZPointSet.smooth(): XYPointSet { -// checkAllFiniteReal(x) -// checkAllFiniteReal(y) -// checkAllFiniteReal(z) -// MathArrays.checkOrder(xval) -// if (size == 1) { -// return doubleArrayOf(y[0]) -// } -// if (size == 2) { -// return doubleArrayOf(y[0], y[1]) -// } -// val bandwidthInPoints = (bandwidth * size).toInt() -// if (bandwidthInPoints < 2) { -// throw NumberIsTooSmallException( -// LocalizedFormats.BANDWIDTH, -// bandwidthInPoints, 2, true -// ) -// } -// val res = DoubleArray(size) -// val residuals = DoubleArray(size) -// val sortedResiduals = DoubleArray(size) -// val robustnessWeights = DoubleArray(size) -// // Do an initial fit and 'robustnessIters' robustness iterations. -// // This is equivalent to doing 'robustnessIters+1' robustness iterations -// // starting with all robustness weights set to 1. -// Arrays.fill(robustnessWeights, 1.0) -// for (iter in 0..robustnessIters) { -// val bandwidthInterval = intArrayOf(0, bandwidthInPoints - 1) -// // At each x, compute a local weighted linear regression -// for (i in 0 until size) { -//// val x = x[i] -// // Find out the interval of source points on which -// // a regression is to be made. -// if (i > 0) { -// updateBandwidthInterval(x, z, i, bandwidthInterval) -// } -// val ileft = bandwidthInterval[0] -// val iright = bandwidthInterval[1] -// // Compute the point of the bandwidth interval that is -// // farthest from x -// val edge: Int -// edge = if (x[i] - x[ileft] > x[iright] - x[i]) { -// ileft -// } else { -// iright -// } -// // Compute a least-squares linear fit weighted by -// // the product of robustness weights and the tricube -// // weight function. -// // See http://en.wikipedia.org/wiki/Linear_regression -// // (section "Univariate linear case") -// // and http://en.wikipedia.org/wiki/Weighted_least_squares -// // (section "Weighted least squares") -// var sumWeights = 0.0 -// var sumX = 0.0 -// var sumXSquared = 0.0 -// var sumY = 0.0 -// var sumXY = 0.0 -// val denom: Double = abs(1.0 / (x[edge] - x[i])) -// for (k in ileft..iright) { -// val xk = x[k] -// val yk = y[k] -// val dist = if (k < i) x - xk else xk - x[i] -// val w = tricube(dist * denom) * robustnessWeights[k] * z[k] -// val xkw = xk * w -// sumWeights += w -// sumX += xkw -// sumXSquared += xk * xkw -// sumY += yk * w -// sumXY += yk * xkw -// } -// val meanX = sumX / sumWeights -// val meanY = sumY / sumWeights -// val meanXY = sumXY / sumWeights -// val meanXSquared = sumXSquared / sumWeights -// val beta: Double -// beta = if (sqrt(abs(meanXSquared - meanX * meanX)) < accuracy) { -// 0.0 -// } else { -// (meanXY - meanX * meanY) / (meanXSquared - meanX * meanX) -// } -// val alpha = meanY - beta * meanX -// res[i] = beta * x[i] + alpha -// residuals[i] = abs(y[i] - res[i]) -// } -// // No need to recompute the robustness weights at the last -// // iteration, they won't be needed anymore -// if (iter == robustnessIters) { -// break -// } -// // Recompute the robustness weights. -// // Find the median residual. -// // An arraycopy and a sort are completely tractable here, -// // because the preceding loop is a lot more expensive -// java.lang.System.arraycopy(residuals, 0, sortedResiduals, 0, size) -// Arrays.sort(sortedResiduals) -// val medianResidual = sortedResiduals[size / 2] -// if (abs(medianResidual) < accuracy) { -// break -// } -// for (i in 0 until size) { -// val arg = residuals[i] / (6 * medianResidual) -// if (arg >= 1) { -// robustnessWeights[i] = 0.0 -// } else { -// val w = 1 - arg * arg -// robustnessWeights[i] = w * w -// } -// } -// } -// return res -// } -// -// fun smooth(xval: DoubleArray, yval: DoubleArray): DoubleArray { -// if (xval.size != yval.size) { -// throw DimensionMismatchException(xval.size, yval.size) -// } -// val unitWeights = DoubleArray(xval.size) -// Arrays.fill(unitWeights, 1.0) -// return smooth(xval, yval, unitWeights) -// } -// -// /** -// * Given an index interval into xval that embraces a certain number of -// * points closest to `xval[i-1]`, update the interval so that it -// * embraces the same number of points closest to `xval[i]`, -// * ignoring zero weights. -// * -// * @param xval Arguments array. -// * @param weights Weights array. -// * @param i Index around which the new interval should be computed. -// * @param bandwidthInterval a two-element array {left, right} such that: -// * `(left==0 or xval[i] - xval[left-1] > xval[right] - xval[i])` -// * and -// * `(right==xval.length-1 or xval[right+1] - xval[i] > xval[i] - xval[left])`. -// * The array will be updated. -// */ -// private fun updateBandwidthInterval( -// xval: Buffer, weights: Buffer, -// i: Int, -// bandwidthInterval: IntArray -// ) { -// val left = bandwidthInterval[0] -// val right = bandwidthInterval[1] -// // The right edge should be adjusted if the next point to the right -// // is closer to xval[i] than the leftmost point of the current interval -// val nextRight = nextNonzero(weights, right) -// if (nextRight < xval.size && xval[nextRight] - xval[i] < xval[i] - xval[left]) { -// val nextLeft = nextNonzero(weights, bandwidthInterval[0]) -// bandwidthInterval[0] = nextLeft -// bandwidthInterval[1] = nextRight -// } -// } -// -// /** -// * Return the smallest index `j` such that -// * `j > i && (j == weights.length || weights[j] != 0)`. -// * -// * @param weights Weights array. -// * @param i Index from which to start search. -// * @return the smallest compliant index. -// */ -// private fun nextNonzero(weights: Buffer, i: Int): Int { -// var j = i + 1 -// while (j < weights.size && weights[j] == 0.0) { -// ++j -// } -// return j -// } -// -// /** -// * Compute the -// * [tricube](http://en.wikipedia.org/wiki/Local_regression#Weight_function) -// * weight function -// * -// * @param x Argument. -// * @return `(1 - |x|3)3` for |x| < 1, 0 otherwise. -// */ -// private fun tricube(x: Double): Double { -// val absX: Double = FastMath.abs(x) -// if (absX >= 1.0) { -// return 0.0 -// } -// val tmp = 1 - absX * absX * absX -// return tmp * tmp * tmp -// } -// -// /** -// * Check that all elements of an array are finite real numbers. -// * -// * @param values Values array. -// * @throws org.apache.commons.math4.exception.NotFiniteNumberException -// * if one of the values is not a finite real number. -// */ -// private fun checkAllFiniteReal(values: DoubleArray) { -// for (i in values.indices) { -// MathUtils.checkFinite(values[i]) -// } -// } -// -// override fun interpolatePolynomials(points: Collection>): PiecewisePolynomial { -// TODO("not implemented") //To change body of created functions use File | Settings | File Templates. -// } -// -// companion object { -// /** Default value of the bandwidth parameter. */ -// const val DEFAULT_BANDWIDTH = 0.3 -// -// /** Default value of the number of robustness iterations. */ -// const val DEFAULT_ROBUSTNESS_ITERS = 2 -// -// /** -// * Default value for accuracy. -// */ -// const val DEFAULT_ACCURACY = 1e-12 -// } -//} \ No newline at end of file diff --git a/kmath-geometry/build.gradle.kts b/kmath-geometry/build.gradle.kts index 9d1b2d4d6..90068a4bf 100644 --- a/kmath-geometry/build.gradle.kts +++ b/kmath-geometry/build.gradle.kts @@ -1,4 +1,6 @@ -plugins { id("ru.mipt.npm.gradle.mpp") } +plugins { + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common")} kotlin.sourceSets.commonMain { dependencies { diff --git a/kmath-histograms/build.gradle.kts b/kmath-histograms/build.gradle.kts index 1337e40aa..980c46d13 100644 --- a/kmath-histograms/build.gradle.kts +++ b/kmath-histograms/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") } kscience { diff --git a/kmath-kotlingrad/build.gradle.kts b/kmath-kotlingrad/build.gradle.kts index a7c0c7e01..dfc0904e0 100644 --- a/kmath-kotlingrad/build.gradle.kts +++ b/kmath-kotlingrad/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - id("ru.mipt.npm.gradle.jvm") + kotlin("jvm") + id("ru.mipt.npm.gradle.common") } dependencies { diff --git a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt index ab3547cda..fe73a63d6 100644 --- a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt +++ b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt @@ -1,10 +1,10 @@ package space.kscience.kmath.kotlingrad import edu.umontreal.kotlingrad.api.SFun -import space.kscience.kmath.ast.MST -import space.kscience.kmath.ast.MstAlgebra -import space.kscience.kmath.ast.interpret import space.kscience.kmath.expressions.DifferentiableExpression +import space.kscience.kmath.expressions.MST +import space.kscience.kmath.expressions.MstAlgebra +import space.kscience.kmath.expressions.interpret import space.kscience.kmath.misc.Symbol import space.kscience.kmath.operations.NumericAlgebra diff --git a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/ScalarsAdapters.kt b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/ScalarsAdapters.kt index 82b801f91..a3ab5cec5 100644 --- a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/ScalarsAdapters.kt +++ b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/ScalarsAdapters.kt @@ -1,10 +1,10 @@ package space.kscience.kmath.kotlingrad import edu.umontreal.kotlingrad.api.* -import space.kscience.kmath.ast.MST -import space.kscience.kmath.ast.MstAlgebra -import space.kscience.kmath.ast.MstExtendedField -import space.kscience.kmath.ast.MstExtendedField.unaryMinus +import space.kscience.kmath.expressions.MST +import space.kscience.kmath.expressions.MstAlgebra +import space.kscience.kmath.expressions.MstExtendedField +import space.kscience.kmath.expressions.MstExtendedField.unaryMinus import space.kscience.kmath.operations.* /** diff --git a/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt b/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt index c4c25d789..1f3a0185f 100644 --- a/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt +++ b/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt @@ -2,8 +2,8 @@ package space.kscience.kmath.kotlingrad import edu.umontreal.kotlingrad.api.* import space.kscience.kmath.asm.compileToExpression -import space.kscience.kmath.ast.MstAlgebra import space.kscience.kmath.ast.parseMath +import space.kscience.kmath.expressions.MstAlgebra import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.DoubleField import kotlin.test.Test diff --git a/kmath-memory/build.gradle.kts b/kmath-memory/build.gradle.kts index 1ccd1bed8..d6107dfd0 100644 --- a/kmath-memory/build.gradle.kts +++ b/kmath-memory/build.gradle.kts @@ -1,11 +1,12 @@ plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") id("ru.mipt.npm.gradle.native") } readme { + maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT description = """ An API and basic implementation for arranging objects in a continous memory block. """.trimIndent() - maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT } \ No newline at end of file diff --git a/kmath-nd4j/build.gradle.kts b/kmath-nd4j/build.gradle.kts index 2954a1e65..6c4f5ad74 100644 --- a/kmath-nd4j/build.gradle.kts +++ b/kmath-nd4j/build.gradle.kts @@ -1,7 +1,6 @@ -import ru.mipt.npm.gradle.Maturity - plugins { - id("ru.mipt.npm.gradle.jvm") + kotlin("jvm") + id("ru.mipt.npm.gradle.common") } dependencies { @@ -14,7 +13,7 @@ dependencies { readme { description = "ND4J NDStructure implementation and according NDAlgebra classes" - maturity = Maturity.EXPERIMENTAL + maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature( diff --git a/kmath-stat/build.gradle.kts b/kmath-stat/build.gradle.kts index c2ebb7ea1..e8f629f7a 100644 --- a/kmath-stat/build.gradle.kts +++ b/kmath-stat/build.gradle.kts @@ -1,8 +1,9 @@ plugins { - id("ru.mipt.npm.gradle.mpp") + kotlin("multiplatform") + id("ru.mipt.npm.gradle.common") } -kscience{ +kscience { useAtomic() } diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Mean.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Mean.kt new file mode 100644 index 000000000..e13d5ff69 --- /dev/null +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Mean.kt @@ -0,0 +1,45 @@ +package space.kscience.kmath.stat + +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.indices + +/** + * Arithmetic mean + */ +public class Mean( + private val group: Group, + private val division: (sum: T, count: Int) -> T, +) : ComposableStatistic, T>, BlockingStatistic { + + override fun evaluateBlocking(data: Buffer): T = group { + var res = zero + for (i in data.indices) { + res += data[i] + } + division(res, data.size) + } + + override suspend fun evaluate(data: Buffer): T = super.evaluate(data) + + public override suspend fun computeIntermediate(data: Buffer): Pair = + evaluateBlocking(data) to data.size + + public override suspend fun composeIntermediate(first: Pair, second: Pair): Pair = + group { first.first + second.first } to (first.second + second.second) + + public override suspend fun toResult(intermediate: Pair): T = group { + division(intermediate.first, intermediate.second) + } + + public companion object { + //TODO replace with optimized version which respects overflow + public val double: Mean = Mean(DoubleField) { sum, count -> sum / count } + public val int: Mean = Mean(IntRing) { sum, count -> sum / count } + public val long: Mean = Mean(LongRing) { sum, count -> sum / count } + + public fun evaluate(buffer: Buffer): Double = double.evaluateBlocking(buffer) + public fun evaluate(buffer: Buffer): Int = int.evaluateBlocking(buffer) + public fun evaluate(buffer: Buffer): Long = long.evaluateBlocking(buffer) + } +} \ No newline at end of file diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Median.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Median.kt new file mode 100644 index 000000000..a34e5e9a9 --- /dev/null +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Median.kt @@ -0,0 +1,16 @@ +package space.kscience.kmath.stat + +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.asSequence + +/** + * Non-composable median + */ +public class Median(private val comparator: Comparator) : BlockingStatistic { + public override fun evaluateBlocking(data: Buffer): T = + data.asSequence().sortedWith(comparator).toList()[data.size / 2] //TODO check if this is correct + + public companion object { + public val real: Median = Median { a: Double, b: Double -> a.compareTo(b) } + } +} \ No newline at end of file diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt index 67f55aea6..5e6da8f5a 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt @@ -8,16 +8,19 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.runningReduce import space.kscience.kmath.coroutines.mapParallel -import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.asIterable -import space.kscience.kmath.structures.asSequence /** * A function, that transforms a buffer of random quantities to some resulting value */ public interface Statistic { - public suspend operator fun invoke(data: Buffer): R + public suspend fun evaluate(data: Buffer): R +} + +public interface BlockingStatistic: Statistic{ + public fun evaluateBlocking(data: Buffer): R + + override suspend fun evaluate(data: Buffer): R = evaluateBlocking(data) } /** @@ -36,7 +39,7 @@ public interface ComposableStatistic : Statistic { //Transform block to result public suspend fun toResult(intermediate: I): R - public override suspend fun invoke(data: Buffer): R = toResult(computeIntermediate(data)) + public override suspend fun evaluate(data: Buffer): R = toResult(computeIntermediate(data)) } @FlowPreview @@ -55,46 +58,9 @@ private fun ComposableStatistic.flowIntermediate( * * The resulting flow contains values that include the whole previous statistics, not only the last chunk. */ -@FlowPreview -@ExperimentalCoroutinesApi +@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) public fun ComposableStatistic.flow( flow: Flow>, dispatcher: CoroutineDispatcher = Dispatchers.Default, ): Flow = flowIntermediate(flow, dispatcher).map(::toResult) -/** - * Arithmetic mean - */ -public class Mean( - private val group: Group, - private val division: (sum: T, count: Int) -> T, -) : ComposableStatistic, T> { - public override suspend fun computeIntermediate(data: Buffer): Pair = - group { sum(data.asIterable()) } to data.size - - public override suspend fun composeIntermediate(first: Pair, second: Pair): Pair = - group { first.first + second.first } to (first.second + second.second) - - public override suspend fun toResult(intermediate: Pair): T = group { - division(intermediate.first, intermediate.second) - } - - public companion object { - //TODO replace with optimized version which respects overflow - public val double: Mean = Mean(DoubleField) { sum, count -> sum / count } - public val int: Mean = Mean(IntRing) { sum, count -> sum / count } - public val long: Mean = Mean(LongRing) { sum, count -> sum / count } - } -} - -/** - * Non-composable median - */ -public class Median(private val comparator: Comparator) : Statistic { - public override suspend fun invoke(data: Buffer): T = - data.asSequence().sortedWith(comparator).toList()[data.size / 2] //TODO check if this is correct - - public companion object { - public val real: Median = Median { a: Double, b: Double -> a.compareTo(b) } - } -} diff --git a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt index e175c76ee..868208180 100644 --- a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt @@ -1,17 +1,18 @@ package space.kscience.kmath.stat -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import space.kscience.kmath.samplers.GaussianSampler internal class CommonsDistributionsTest { @Test - fun testNormalDistributionSuspend() = runBlocking { + fun testNormalDistributionSuspend() = GlobalScope.launch { val distribution = GaussianSampler(7.0, 2.0) val generator = RandomGenerator.default(1) val sample = distribution.sample(generator).nextBuffer(1000) - Assertions.assertEquals(7.0, Mean.double(sample), 0.2) + Assertions.assertEquals(7.0, Mean.evaluate(sample), 0.2) } @Test @@ -19,8 +20,6 @@ internal class CommonsDistributionsTest { val distribution = GaussianSampler(7.0, 2.0) val generator = RandomGenerator.default(1) val sample = distribution.sample(generator).nextBufferBlocking(1000) - runBlocking { - Assertions.assertEquals(7.0, Mean.double(sample), 0.2) - } + Assertions.assertEquals(7.0, Mean.evaluate(sample), 0.2) } } diff --git a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt index 908c5775b..e1891fb68 100644 --- a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt @@ -17,14 +17,12 @@ internal class StatisticTest { val chunked = data.chunked(1000) @Test - fun testParallelMean() { - runBlocking { - val average = Mean.double - .flow(chunked) //create a flow with results - .drop(99) // Skip first 99 values and use one with total data - .first() //get 1e5 data samples average + fun testParallelMean() = runBlocking { + val average = Mean.double + .flow(chunked) //create a flow with results + .drop(99) // Skip first 99 values and use one with total data + .first() //get 1e5 data samples average - println(average) - } + println(average) } } diff --git a/kmath-viktor/build.gradle.kts b/kmath-viktor/build.gradle.kts index 94744f528..232bd1388 100644 --- a/kmath-viktor/build.gradle.kts +++ b/kmath-viktor/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - id("ru.mipt.npm.gradle.jvm") + kotlin("jvm") + id("ru.mipt.npm.gradle.common") } description = "Binding for https://github.com/JetBrains-Research/viktor" diff --git a/settings.gradle.kts b/settings.gradle.kts index 38a4d86ff..ef9000fbb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,18 +7,17 @@ pluginManagement { maven("https://dl.bintray.com/kotlin/kotlinx") } - val toolsVersion = "0.9.4" + val toolsVersion = "0.9.5-dev" val kotlinVersion = "1.5.0-M2" plugins { - id("kotlinx.benchmark") version "0.2.0-dev-20" + kotlin("multiplatform") version kotlinVersion + kotlin("jvm") version kotlinVersion + kotlin("plugin.allopen") version kotlinVersion + id("org.jetbrains.kotlinx.benchmark") version "0.3.0" id("ru.mipt.npm.gradle.project") version toolsVersion id("ru.mipt.npm.gradle.mpp") version toolsVersion id("ru.mipt.npm.gradle.jvm") version toolsVersion - id("ru.mipt.npm.gradle.publish") version toolsVersion - kotlin("jvm") version kotlinVersion - kotlin("multiplatform") version kotlinVersion - kotlin("plugin.allopen") version kotlinVersion } }