) {
private fun softMaxLoss(yPred: DoubleTensor, yTrue: DoubleTensor): DoubleTensor = BroadcastDoubleTensorAlgebra {
val onesForAnswers = yPred.zeroesLike()
- yTrue.toDoubleArray().forEachIndexed { index, labelDouble ->
+ yTrue.copyArray().forEachIndexed { index, labelDouble ->
val label = labelDouble.toInt()
onesForAnswers[intArrayOf(index, label)] = 1.0
}
@@ -186,7 +186,7 @@ fun main() = BroadcastDoubleTensorAlgebra {
x += fromArray(
intArrayOf(5),
- doubleArrayOf(0.0, -1.0, -2.5, -3.0, 5.5) // rows means
+ doubleArrayOf(0.0, -1.0, -2.5, -3.0, 5.5) // row means
)
diff --git a/gradle.properties b/gradle.properties
index 3aaade368..959511c68 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,10 +4,13 @@
#
kotlin.code.style=official
-kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.stability.nowarn=true
-kotlin.native.enableDependencyPropagation=false
-kotlin.parallel.tasks.in.project=true
+
+#kotlin.mpp.enableGranularSourceSetsMetadata=true
+#kotlin.native.enableDependencyPropagation=false
+
+kotlin.jupyter.add.scanner=false
+
org.gradle.configureondemand=true
org.gradle.jvmargs=-XX:MaxMetaspaceSize=2G
org.gradle.parallel=true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index e708b1c02..7454180f2 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index f371643ee..ffed3a254 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-7.0-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index 4f906e0c8..744e882ed 100755
--- a/gradlew
+++ b/gradlew
@@ -72,7 +72,7 @@ case "`uname`" in
Darwin* )
darwin=true
;;
- MINGW* )
+ MSYS* | MINGW* )
msys=true
;;
NONSTOP* )
diff --git a/kmath-ast/README.md b/kmath-ast/README.md
index 026c5a625..686506f6f 100644
--- a/kmath-ast/README.md
+++ b/kmath-ast/README.md
@@ -10,7 +10,7 @@ Performance and visualization extensions to MST API.
## Artifact:
-The Maven coordinates of this project are `space.kscience:kmath-ast:0.3.0-dev-13`.
+The Maven coordinates of this project are `space.kscience:kmath-ast:0.3.0-dev-14`.
**Gradle:**
```gradle
@@ -20,7 +20,7 @@ repositories {
}
dependencies {
- implementation 'space.kscience:kmath-ast:0.3.0-dev-13'
+ implementation 'space.kscience:kmath-ast:0.3.0-dev-14'
}
```
**Gradle Kotlin DSL:**
@@ -31,7 +31,7 @@ repositories {
}
dependencies {
- implementation("space.kscience:kmath-ast:0.3.0-dev-13")
+ implementation("space.kscience:kmath-ast:0.3.0-dev-14")
}
```
@@ -106,7 +106,7 @@ var executable = function (constants, arguments) {
};
```
-JS also supports very experimental expression optimization with [WebAssembly](https://webassembly.org/) IR generation.
+JS also supports experimental expression optimization with [WebAssembly](https://webassembly.org/) IR generation.
Currently, only expressions inside `DoubleField` and `IntRing` are supported.
```kotlin
@@ -161,7 +161,10 @@ public fun main() {
Result LaTeX:
+
+
![](https://latex.codecogs.com/gif.latex?%5Coperatorname{exp}%5C,%5Cleft(%5Csqrt{x}%5Cright)-%5Cfrac{%5Cfrac{%5Coperatorname{arcsin}%5C,%5Cleft(2%5C,x%5Cright)}{2%5Ctimes10^{10}%2Bx^{3}}}{12}+x^{2/3})
+
Result MathML (can be used with MathJax or other renderers):
diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts
index 8209a0dad..9de7e9980 100644
--- a/kmath-ast/build.gradle.kts
+++ b/kmath-ast/build.gradle.kts
@@ -45,8 +45,7 @@ kotlin.sourceSets {
jvmMain {
dependencies {
- implementation("org.ow2.asm:asm:9.1")
- implementation("org.ow2.asm:asm-commons:9.1")
+ implementation("org.ow2.asm:asm-commons:9.2")
}
}
}
diff --git a/kmath-ast/docs/README-TEMPLATE.md b/kmath-ast/docs/README-TEMPLATE.md
index b90f8ff08..9494af63a 100644
--- a/kmath-ast/docs/README-TEMPLATE.md
+++ b/kmath-ast/docs/README-TEMPLATE.md
@@ -77,7 +77,7 @@ var executable = function (constants, arguments) {
};
```
-JS also supports very experimental expression optimization with [WebAssembly](https://webassembly.org/) IR generation.
+JS also supports experimental expression optimization with [WebAssembly](https://webassembly.org/) IR generation.
Currently, only expressions inside `DoubleField` and `IntRing` are supported.
```kotlin
@@ -132,7 +132,10 @@ public fun main() {
Result LaTeX:
+
+
![](https://latex.codecogs.com/gif.latex?%5Coperatorname{exp}%5C,%5Cleft(%5Csqrt{x}%5Cright)-%5Cfrac{%5Cfrac{%5Coperatorname{arcsin}%5C,%5Cleft(2%5C,x%5Cright)}{2%5Ctimes10^{10}%2Bx^{3}}}{12}+x^{2/3})
+
Result MathML (can be used with MathJax or other renderers):
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt
index 5201fec38..7f2780548 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
@@ -17,11 +17,11 @@ 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.expressions.StringSymbol
-import space.kscience.kmath.operations.FieldOperations
-import space.kscience.kmath.operations.GroupOperations
+import space.kscience.kmath.expressions.Symbol
+import space.kscience.kmath.operations.FieldOps
+import space.kscience.kmath.operations.GroupOps
import space.kscience.kmath.operations.PowerOperations
-import space.kscience.kmath.operations.RingOperations
+import space.kscience.kmath.operations.RingOps
/**
* better-parse implementation of grammar defined in the ArithmeticsEvaluator.g4.
@@ -43,7 +43,7 @@ public object ArithmeticsEvaluator : Grammar() {
private val ws: Token by regexToken("\\s+".toRegex(), ignore = true)
private val number: Parser by num use { MST.Numeric(text.toDouble()) }
- private val singular: Parser by id use { StringSymbol(text) }
+ private val singular: Parser by id use { Symbol(text) }
private val unaryFunction: Parser by (id and -lpar and parser(ArithmeticsEvaluator::subSumChain) and -rpar)
.map { (id, term) -> MST.Unary(id.text, term) }
@@ -60,7 +60,7 @@ public object ArithmeticsEvaluator : Grammar() {
.or(binaryFunction)
.or(unaryFunction)
.or(singular)
- .or(-minus and parser(ArithmeticsEvaluator::term) map { MST.Unary(GroupOperations.MINUS_OPERATION, it) })
+ .or(-minus and parser(ArithmeticsEvaluator::term) map { MST.Unary(GroupOps.MINUS_OPERATION, it) })
.or(-lpar and parser(ArithmeticsEvaluator::subSumChain) and -rpar)
private val powChain: Parser by leftAssociative(term = term, operator = pow) { a, _, b ->
@@ -72,9 +72,9 @@ public object ArithmeticsEvaluator : Grammar() {
operator = div or mul use TokenMatch::type
) { a, op, b ->
if (op == div)
- MST.Binary(FieldOperations.DIV_OPERATION, a, b)
+ MST.Binary(FieldOps.DIV_OPERATION, a, b)
else
- MST.Binary(RingOperations.TIMES_OPERATION, a, b)
+ MST.Binary(RingOps.TIMES_OPERATION, a, b)
}
private val subSumChain: Parser by leftAssociative(
@@ -82,9 +82,9 @@ public object ArithmeticsEvaluator : Grammar() {
operator = plus or minus use TokenMatch::type
) { a, op, b ->
if (op == plus)
- MST.Binary(GroupOperations.PLUS_OPERATION, a, b)
+ MST.Binary(GroupOps.PLUS_OPERATION, a, b)
else
- MST.Binary(GroupOperations.MINUS_OPERATION, a, b)
+ MST.Binary(GroupOps.MINUS_OPERATION, a, b)
}
override val rootParser: Parser by subSumChain
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt
index 01717b0f9..bf5916fa5 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
@@ -27,7 +27,7 @@ import space.kscience.kmath.misc.UnstableKMathAPI
*/
@UnstableKMathAPI
public object LatexSyntaxRenderer : SyntaxRenderer {
- public override fun render(node: MathSyntax, output: Appendable): Unit = output.run {
+ override fun render(node: MathSyntax, output: Appendable): Unit = output.run {
fun render(syntax: MathSyntax) = render(syntax, output)
when (node) {
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt
index cda8e2322..5439c42fa 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
@@ -16,7 +16,7 @@ import space.kscience.kmath.misc.UnstableKMathAPI
*/
@UnstableKMathAPI
public object MathMLSyntaxRenderer : SyntaxRenderer {
- public override fun render(node: MathSyntax, output: Appendable) {
+ override fun render(node: MathSyntax, output: Appendable) {
output.append("")
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 68d829724..24bac425a 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 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
@@ -29,7 +29,7 @@ public fun interface MathRenderer {
*/
@UnstableKMathAPI
public open class FeaturedMathRenderer(public val features: List) : MathRenderer {
- public override fun render(mst: MST): MathSyntax {
+ override fun render(mst: MST): MathSyntax {
for (feature in features) feature.render(this, mst)?.let { return it }
throw UnsupportedOperationException("Renderer $this has no appropriate feature to render node $mst.")
}
@@ -56,7 +56,7 @@ public open class FeaturedMathRendererWithPostProcess(
features: List,
public val stages: List,
) : FeaturedMathRenderer(features) {
- public override fun render(mst: MST): MathSyntax {
+ override fun render(mst: MST): MathSyntax {
val res = super.render(mst)
for (stage in stages) stage.perform(res)
return res
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt
index a71985fbc..81b7d2afb 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
@@ -8,7 +8,7 @@ package space.kscience.kmath.ast.rendering
import space.kscience.kmath.misc.UnstableKMathAPI
/**
- * Mathematical typography syntax node.
+ * Syntax node for mathematical typography.
*
* @author Iaroslav Postovalov
*/
@@ -150,9 +150,9 @@ public data class OperandSyntax(
*/
@UnstableKMathAPI
public data class UnaryOperatorSyntax(
- public override val operation: String,
+ override val operation: String,
public var prefix: MathSyntax,
- public override val operand: OperandSyntax,
+ override val operand: OperandSyntax,
) : UnarySyntax() {
init {
operand.parent = this
@@ -166,8 +166,8 @@ public data class UnaryOperatorSyntax(
*/
@UnstableKMathAPI
public data class UnaryPlusSyntax(
- public override val operation: String,
- public override val operand: OperandSyntax,
+ override val operation: String,
+ override val operand: OperandSyntax,
) : UnarySyntax() {
init {
operand.parent = this
@@ -181,8 +181,8 @@ public data class UnaryPlusSyntax(
*/
@UnstableKMathAPI
public data class UnaryMinusSyntax(
- public override val operation: String,
- public override val operand: OperandSyntax,
+ override val operation: String,
+ override val operand: OperandSyntax,
) : UnarySyntax() {
init {
operand.parent = this
@@ -197,8 +197,8 @@ public data class UnaryMinusSyntax(
*/
@UnstableKMathAPI
public data class RadicalSyntax(
- public override val operation: String,
- public override val operand: MathSyntax,
+ override val operation: String,
+ override val operand: MathSyntax,
) : UnarySyntax() {
init {
operand.parent = this
@@ -215,8 +215,8 @@ public data class RadicalSyntax(
*/
@UnstableKMathAPI
public data class ExponentSyntax(
- public override val operation: String,
- public override val operand: OperandSyntax,
+ override val operation: String,
+ override val operand: OperandSyntax,
public var useOperatorForm: Boolean,
) : UnarySyntax() {
init {
@@ -233,9 +233,9 @@ public data class ExponentSyntax(
*/
@UnstableKMathAPI
public data class SuperscriptSyntax(
- public override val operation: String,
- public override val left: MathSyntax,
- public override val right: MathSyntax,
+ override val operation: String,
+ override val left: MathSyntax,
+ override val right: MathSyntax,
) : BinarySyntax() {
init {
left.parent = this
@@ -252,9 +252,9 @@ public data class SuperscriptSyntax(
*/
@UnstableKMathAPI
public data class SubscriptSyntax(
- public override val operation: String,
- public override val left: MathSyntax,
- public override val right: MathSyntax,
+ override val operation: String,
+ override val left: MathSyntax,
+ override val right: MathSyntax,
) : BinarySyntax() {
init {
left.parent = this
@@ -270,10 +270,10 @@ public data class SubscriptSyntax(
*/
@UnstableKMathAPI
public data class BinaryOperatorSyntax(
- public override val operation: String,
+ override val operation: String,
public var prefix: MathSyntax,
- public override val left: MathSyntax,
- public override val right: MathSyntax,
+ override val left: MathSyntax,
+ override val right: MathSyntax,
) : BinarySyntax() {
init {
left.parent = this
@@ -290,9 +290,9 @@ public data class BinaryOperatorSyntax(
*/
@UnstableKMathAPI
public data class BinaryPlusSyntax(
- public override val operation: String,
- public override val left: OperandSyntax,
- public override val right: OperandSyntax,
+ override val operation: String,
+ override val left: OperandSyntax,
+ override val right: OperandSyntax,
) : BinarySyntax() {
init {
left.parent = this
@@ -301,7 +301,7 @@ public data class BinaryPlusSyntax(
}
/**
- * Represents binary, infix subtraction (*42 - 42*).
+ * Represents binary, infix subtraction (*42 − 42*).
*
* @param left The minuend.
* @param right The subtrahend.
@@ -309,9 +309,9 @@ public data class BinaryPlusSyntax(
*/
@UnstableKMathAPI
public data class BinaryMinusSyntax(
- public override val operation: String,
- public override val left: OperandSyntax,
- public override val right: OperandSyntax,
+ override val operation: String,
+ override val left: OperandSyntax,
+ override val right: OperandSyntax,
) : BinarySyntax() {
init {
left.parent = this
@@ -329,9 +329,9 @@ public data class BinaryMinusSyntax(
*/
@UnstableKMathAPI
public data class FractionSyntax(
- public override val operation: String,
- public override val left: OperandSyntax,
- public override val right: OperandSyntax,
+ override val operation: String,
+ override val left: OperandSyntax,
+ override val right: OperandSyntax,
public var infix: Boolean,
) : BinarySyntax() {
init {
@@ -349,9 +349,9 @@ public data class FractionSyntax(
*/
@UnstableKMathAPI
public data class RadicalWithIndexSyntax(
- public override val operation: String,
- public override val left: MathSyntax,
- public override val right: MathSyntax,
+ override val operation: String,
+ override val left: MathSyntax,
+ override val right: MathSyntax,
) : BinarySyntax() {
init {
left.parent = this
@@ -369,9 +369,9 @@ public data class RadicalWithIndexSyntax(
*/
@UnstableKMathAPI
public data class MultiplicationSyntax(
- public override val operation: String,
- public override val left: OperandSyntax,
- public override val right: OperandSyntax,
+ override val operation: String,
+ override val left: OperandSyntax,
+ override val right: OperandSyntax,
public var times: Boolean,
) : BinarySyntax() {
init {
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt
index fb2b3b66f..2f285c600 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
@@ -9,7 +9,7 @@ import space.kscience.kmath.misc.UnstableKMathAPI
/**
* Abstraction of writing [MathSyntax] as a string of an actual markup language. Typical implementation should
- * involve traversal of MathSyntax with handling each its subtype.
+ * involve traversal of MathSyntax with handling each subtype.
*
* @author Iaroslav Postovalov
*/
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 a2f42d1bf..8b76b6f19 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,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
@@ -13,7 +13,7 @@ import space.kscience.kmath.operations.*
import kotlin.reflect.KClass
/**
- * Prints any [Symbol] as a [SymbolSyntax] containing the [Symbol.value] of it.
+ * Prints any [Symbol] as a [SymbolSyntax] containing the [Symbol.identity] of it.
*
* @author Iaroslav Postovalov
*/
@@ -39,7 +39,7 @@ public val PrintNumeric: RenderFeature = RenderFeature { _, node ->
@UnstableKMathAPI
private fun printSignedNumberString(s: String): MathSyntax = if (s.startsWith('-'))
UnaryMinusSyntax(
- operation = GroupOperations.MINUS_OPERATION,
+ operation = GroupOps.MINUS_OPERATION,
operand = OperandSyntax(
operand = NumberSyntax(string = s.removePrefix("-")),
parentheses = true,
@@ -49,7 +49,7 @@ else
NumberSyntax(string = s)
/**
- * Special printing for numeric types which are printed in form of
+ * Special printing for numeric types that are printed in form of
* *('-'? (DIGIT+ ('.' DIGIT+)? ('E' '-'? DIGIT+)? | 'Infinity')) | 'NaN'*.
*
* @property types The suitable types.
@@ -57,7 +57,7 @@ else
*/
@UnstableKMathAPI
public class PrettyPrintFloats(public val types: Set>) : RenderFeature {
- public override fun render(renderer: FeaturedMathRenderer, node: MST): MathSyntax? {
+ override fun render(renderer: FeaturedMathRenderer, node: MST): MathSyntax? {
if (node !is MST.Numeric || node.value::class !in types) return null
val toString = when (val v = node.value) {
@@ -72,7 +72,7 @@ public class PrettyPrintFloats(public val types: Set>) : Rend
val exponent = afterE.toDouble().toString().removeSuffix(".0")
return MultiplicationSyntax(
- operation = RingOperations.TIMES_OPERATION,
+ operation = RingOps.TIMES_OPERATION,
left = OperandSyntax(operand = NumberSyntax(significand), parentheses = true),
right = OperandSyntax(
operand = SuperscriptSyntax(
@@ -91,7 +91,7 @@ public class PrettyPrintFloats(public val types: Set>) : Rend
if (toString.startsWith('-'))
return UnaryMinusSyntax(
- operation = GroupOperations.MINUS_OPERATION,
+ operation = GroupOps.MINUS_OPERATION,
operand = OperandSyntax(operand = infty, parentheses = true),
)
@@ -110,14 +110,14 @@ public class PrettyPrintFloats(public val types: Set>) : Rend
}
/**
- * Special printing for numeric types which are printed in form of *'-'? DIGIT+*.
+ * Special printing for numeric types that are printed in form of *'-'? DIGIT+*.
*
* @property types The suitable types.
* @author Iaroslav Postovalov
*/
@UnstableKMathAPI
public class PrettyPrintIntegers(public val types: Set>) : RenderFeature {
- public override fun render(renderer: FeaturedMathRenderer, node: MST): MathSyntax? =
+ override fun render(renderer: FeaturedMathRenderer, node: MST): MathSyntax? =
if (node !is MST.Numeric || node.value::class !in types)
null
else
@@ -140,7 +140,7 @@ public class PrettyPrintIntegers(public val types: Set>) : Re
*/
@UnstableKMathAPI
public class PrettyPrintPi(public val symbols: Set) : RenderFeature {
- public override fun render(renderer: FeaturedMathRenderer, node: MST): MathSyntax? =
+ override fun render(renderer: FeaturedMathRenderer, node: MST): MathSyntax? =
if (node !is Symbol || node.identity !in symbols)
null
else
@@ -155,7 +155,7 @@ public class PrettyPrintPi(public val symbols: Set) : RenderFeature {
}
/**
- * Abstract printing of unary operations which discards [MST] if their operation is not in [operations] or its type is
+ * Abstract printing of unary operations that discards [MST] if their operation is not in [operations] or its type is
* not [MST.Unary].
*
* @param operations the allowed operations. If `null`, any operation is accepted.
@@ -176,7 +176,7 @@ public abstract class Unary(public val operations: Collection?) : Render
}
/**
- * Abstract printing of unary operations which discards [MST] if their operation is not in [operations] or its type is
+ * Abstract printing of unary operations that discards [MST] if their operation is not in [operations] or its type is
* not [MST.Binary].
*
* @property operations the allowed operations. If `null`, any operation is accepted.
@@ -202,7 +202,7 @@ public abstract class Binary(public val operations: Collection?) : Rende
*/
@UnstableKMathAPI
public class BinaryPlus(operations: Collection?) : Binary(operations) {
- public override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
+ override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
BinaryPlusSyntax(
operation = node.operation,
left = OperandSyntax(parent.render(node.left), true),
@@ -211,9 +211,9 @@ public class BinaryPlus(operations: Collection?) : Binary(operations) {
public companion object {
/**
- * The default instance configured with [GroupOperations.PLUS_OPERATION].
+ * The default instance configured with [GroupOps.PLUS_OPERATION].
*/
- public val Default: BinaryPlus = BinaryPlus(setOf(GroupOperations.PLUS_OPERATION))
+ public val Default: BinaryPlus = BinaryPlus(setOf(GroupOps.PLUS_OPERATION))
}
}
@@ -224,7 +224,7 @@ public class BinaryPlus(operations: Collection?) : Binary(operations) {
*/
@UnstableKMathAPI
public class BinaryMinus(operations: Collection?) : Binary(operations) {
- public override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
+ override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
BinaryMinusSyntax(
operation = node.operation,
left = OperandSyntax(operand = parent.render(node.left), parentheses = true),
@@ -233,9 +233,9 @@ public class BinaryMinus(operations: Collection?) : Binary(operations) {
public companion object {
/**
- * The default instance configured with [GroupOperations.MINUS_OPERATION].
+ * The default instance configured with [GroupOps.MINUS_OPERATION].
*/
- public val Default: BinaryMinus = BinaryMinus(setOf(GroupOperations.MINUS_OPERATION))
+ public val Default: BinaryMinus = BinaryMinus(setOf(GroupOps.MINUS_OPERATION))
}
}
@@ -246,16 +246,16 @@ public class BinaryMinus(operations: Collection?) : Binary(operations) {
*/
@UnstableKMathAPI
public class UnaryPlus(operations: Collection?) : Unary(operations) {
- public override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax = UnaryPlusSyntax(
+ override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax = UnaryPlusSyntax(
operation = node.operation,
operand = OperandSyntax(operand = parent.render(node.value), parentheses = true),
)
public companion object {
/**
- * The default instance configured with [GroupOperations.PLUS_OPERATION].
+ * The default instance configured with [GroupOps.PLUS_OPERATION].
*/
- public val Default: UnaryPlus = UnaryPlus(setOf(GroupOperations.PLUS_OPERATION))
+ public val Default: UnaryPlus = UnaryPlus(setOf(GroupOps.PLUS_OPERATION))
}
}
@@ -266,16 +266,16 @@ public class UnaryPlus(operations: Collection?) : Unary(operations) {
*/
@UnstableKMathAPI
public class UnaryMinus(operations: Collection?) : Unary(operations) {
- public override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax = UnaryMinusSyntax(
+ override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax = UnaryMinusSyntax(
operation = node.operation,
operand = OperandSyntax(operand = parent.render(node.value), parentheses = true),
)
public companion object {
/**
- * The default instance configured with [GroupOperations.MINUS_OPERATION].
+ * The default instance configured with [GroupOps.MINUS_OPERATION].
*/
- public val Default: UnaryMinus = UnaryMinus(setOf(GroupOperations.MINUS_OPERATION))
+ public val Default: UnaryMinus = UnaryMinus(setOf(GroupOps.MINUS_OPERATION))
}
}
@@ -286,7 +286,7 @@ public class UnaryMinus(operations: Collection?) : Unary(operations) {
*/
@UnstableKMathAPI
public class Fraction(operations: Collection?) : Binary(operations) {
- public override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax = FractionSyntax(
+ override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax = FractionSyntax(
operation = node.operation,
left = OperandSyntax(operand = parent.render(node.left), parentheses = true),
right = OperandSyntax(operand = parent.render(node.right), parentheses = true),
@@ -295,9 +295,9 @@ public class Fraction(operations: Collection?) : Binary(operations) {
public companion object {
/**
- * The default instance configured with [FieldOperations.DIV_OPERATION].
+ * The default instance configured with [FieldOps.DIV_OPERATION].
*/
- public val Default: Fraction = Fraction(setOf(FieldOperations.DIV_OPERATION))
+ public val Default: Fraction = Fraction(setOf(FieldOps.DIV_OPERATION))
}
}
@@ -308,7 +308,7 @@ public class Fraction(operations: Collection?) : Binary(operations) {
*/
@UnstableKMathAPI
public class BinaryOperator(operations: Collection?) : Binary(operations) {
- public override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
+ override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
BinaryOperatorSyntax(
operation = node.operation,
prefix = OperatorNameSyntax(name = node.operation),
@@ -331,7 +331,7 @@ public class BinaryOperator(operations: Collection?) : Binary(operations
*/
@UnstableKMathAPI
public class UnaryOperator(operations: Collection?) : Unary(operations) {
- public override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax =
+ override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax =
UnaryOperatorSyntax(
operation = node.operation,
prefix = OperatorNameSyntax(node.operation),
@@ -353,7 +353,7 @@ public class UnaryOperator(operations: Collection?) : Unary(operations)
*/
@UnstableKMathAPI
public class Power(operations: Collection?) : Binary(operations) {
- public override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
+ override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
SuperscriptSyntax(
operation = node.operation,
left = OperandSyntax(parent.render(node.left), true),
@@ -373,7 +373,7 @@ public class Power(operations: Collection?) : Binary(operations) {
*/
@UnstableKMathAPI
public class SquareRoot(operations: Collection?) : Unary(operations) {
- public override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax =
+ override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax =
RadicalSyntax(operation = node.operation, operand = parent.render(node.value))
public companion object {
@@ -391,7 +391,7 @@ public class SquareRoot(operations: Collection?) : Unary(operations) {
*/
@UnstableKMathAPI
public class Exponent(operations: Collection?) : Unary(operations) {
- public override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax = ExponentSyntax(
+ override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax = ExponentSyntax(
operation = node.operation,
operand = OperandSyntax(operand = parent.render(node.value), parentheses = true),
useOperatorForm = true,
@@ -412,7 +412,7 @@ public class Exponent(operations: Collection?) : Unary(operations) {
*/
@UnstableKMathAPI
public class Multiplication(operations: Collection?) : Binary(operations) {
- public override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
+ override fun renderBinary(parent: FeaturedMathRenderer, node: MST.Binary): MathSyntax =
MultiplicationSyntax(
operation = node.operation,
left = OperandSyntax(operand = parent.render(node.left), parentheses = true),
@@ -422,9 +422,9 @@ public class Multiplication(operations: Collection?) : Binary(operations
public companion object {
/**
- * The default instance configured with [RingOperations.TIMES_OPERATION].
+ * The default instance configured with [RingOps.TIMES_OPERATION].
*/
- public val Default: Multiplication = Multiplication(setOf(RingOperations.TIMES_OPERATION))
+ public val Default: Multiplication = Multiplication(setOf(RingOps.TIMES_OPERATION))
}
}
@@ -435,7 +435,7 @@ public class Multiplication(operations: Collection?) : Binary(operations
*/
@UnstableKMathAPI
public class InverseTrigonometricOperations(operations: Collection?) : Unary(operations) {
- public override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax =
+ override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax =
UnaryOperatorSyntax(
operation = node.operation,
prefix = OperatorNameSyntax(name = node.operation.replaceFirst("a", "arc")),
@@ -462,7 +462,7 @@ public class InverseTrigonometricOperations(operations: Collection?) : U
*/
@UnstableKMathAPI
public class InverseHyperbolicOperations(operations: Collection?) : Unary(operations) {
- public override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax =
+ override fun renderUnary(parent: FeaturedMathRenderer, node: MST.Unary): MathSyntax =
UnaryOperatorSyntax(
operation = node.operation,
prefix = OperatorNameSyntax(name = node.operation.replaceFirst("a", "ar")),
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
index 291399cee..3e33d6415 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt
index 6da4994a6..ecea2d104 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt
@@ -1,16 +1,16 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
import space.kscience.kmath.ast.rendering.FeaturedMathRendererWithPostProcess.PostProcessPhase
import space.kscience.kmath.misc.UnstableKMathAPI
-import space.kscience.kmath.operations.FieldOperations
-import space.kscience.kmath.operations.GroupOperations
+import space.kscience.kmath.operations.FieldOps
+import space.kscience.kmath.operations.GroupOps
import space.kscience.kmath.operations.PowerOperations
-import space.kscience.kmath.operations.RingOperations
+import space.kscience.kmath.operations.RingOps
/**
* Removes unnecessary times (×) symbols from [MultiplicationSyntax].
@@ -205,7 +205,7 @@ public val BetterExponent: PostProcessPhase = PostProcessPhase { node ->
@UnstableKMathAPI
public class SimplifyParentheses(public val precedenceFunction: (MathSyntax) -> Int) :
PostProcessPhase {
- public override fun perform(node: MathSyntax): Unit = when (node) {
+ override fun perform(node: MathSyntax): Unit = when (node) {
is NumberSyntax -> Unit
is SymbolSyntax -> Unit
is OperatorNameSyntax -> Unit
@@ -306,10 +306,10 @@ public class SimplifyParentheses(public val precedenceFunction: (MathSyntax) ->
is BinarySyntax -> when (it.operation) {
PowerOperations.POW_OPERATION -> 1
- RingOperations.TIMES_OPERATION -> 3
- FieldOperations.DIV_OPERATION -> 3
- GroupOperations.MINUS_OPERATION -> 4
- GroupOperations.PLUS_OPERATION -> 4
+ RingOps.TIMES_OPERATION -> 3
+ FieldOps.DIV_OPERATION -> 3
+ GroupOps.MINUS_OPERATION -> 4
+ GroupOps.PLUS_OPERATION -> 4
else -> 0
}
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt
index 3116466e6..802d4c10e 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
@@ -11,7 +11,6 @@ import space.kscience.kmath.expressions.Symbol.Companion.x
import space.kscience.kmath.expressions.interpret
import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.operations.IntRing
-import space.kscience.kmath.operations.bindSymbol
import space.kscience.kmath.operations.invoke
import kotlin.test.Test
import kotlin.test.assertEquals
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt
index 929d17775..f5b1e2842 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt
index bed5bc7fa..8d9a2301f 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
@@ -9,7 +9,6 @@ import space.kscience.kmath.expressions.MstRing
import space.kscience.kmath.expressions.Symbol.Companion.x
import space.kscience.kmath.expressions.invoke
import space.kscience.kmath.operations.IntRing
-import space.kscience.kmath.operations.bindSymbol
import space.kscience.kmath.operations.invoke
import kotlin.test.Test
import kotlin.test.assertEquals
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt
index b838245e1..4c834a9ca 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt
index bb6bb3ce1..9776da45c 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt
index a40c785b9..ae429d97e 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt
index 6322df25d..aba713c43 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt
@@ -1,13 +1,13 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
import space.kscience.kmath.ast.rendering.TestUtils.testLatex
import space.kscience.kmath.expressions.MST
-import space.kscience.kmath.operations.GroupOperations
+import space.kscience.kmath.operations.GroupOps
import kotlin.test.Test
internal class TestLatex {
@@ -36,7 +36,7 @@ internal class TestLatex {
fun unaryOperator() = testLatex("sin(1)", "\\operatorname{sin}\\,\\left(1\\right)")
@Test
- fun unaryPlus() = testLatex(MST.Unary(GroupOperations.PLUS_OPERATION, MST.Numeric(1)), "+1")
+ fun unaryPlus() = testLatex(MST.Unary(GroupOps.PLUS_OPERATION, MST.Numeric(1)), "+1")
@Test
fun unaryMinus() = testLatex("-x", "-x")
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt
index 2d7bfad19..658ecd47a 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt
@@ -1,13 +1,13 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
import space.kscience.kmath.ast.rendering.TestUtils.testMathML
import space.kscience.kmath.expressions.MST
-import space.kscience.kmath.operations.GroupOperations
+import space.kscience.kmath.operations.GroupOps
import kotlin.test.Test
internal class TestMathML {
@@ -47,7 +47,7 @@ internal class TestMathML {
@Test
fun unaryPlus() =
- testMathML(MST.Unary(GroupOperations.PLUS_OPERATION, MST.Numeric(1)), "+1")
+ testMathML(MST.Unary(GroupOps.PLUS_OPERATION, MST.Numeric(1)), "+1")
@Test
fun unaryMinus() = testMathML("-x", "-x")
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt
index 09ec127c7..4485605a6 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt
index bf87b6fd0..6b418821b 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt
index ec7436188..ef9f3145a 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
index 521907d2c..2e69a536f 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
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 0c15e994c..316fdeeff 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,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.estree
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt
index 4907d8225..850f20be7 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.estree.internal
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt
index eb5c1e3dd..c7faf73e0 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.estree.internal.astring
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt
index cca2d83af..c36860654 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
@file:JsModule("astring")
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt
index 93b4f6ce6..0a5b059ba 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.internal.astring
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt
index 86e0cede7..26186c453 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
@file:Suppress(
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt
index 42b6ac7d8..13e3a49e2 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
@file:Suppress(
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt
index 523b13b40..8e449627c 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
@file:Suppress("PackageDirectoryMismatch", "NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "KDocMissingDocumentation")
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt
index 1f7b09af8..d85857de8 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.internal.emitter
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt
index 3aa31f921..122a3a397 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.internal.estree
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt
index e5254013e..ad079dbd0 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt
@@ -1,8 +1,10 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
+@file:Suppress("ClassName")
+
package space.kscience.kmath.internal.estree
import kotlin.js.RegExp
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt
index 52be5530f..caab91731 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.internal.stream
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt
index 9c012e3a3..5c091e3a1 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.internal.tsstdlib
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt
index 0cd395f2c..bb7fd44ca 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
@file:Suppress("UNUSED_TYPEALIAS_PARAMETER", "DEPRECATION")
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt
index 3754c3eff..52dd64a5e 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
@file:JsQualifier("WebAssembly")
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt
index c5023c384..d59a52701 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
@file:Suppress(
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt
index c89ad83c4..b04c4d48f 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.wasm.internal
@@ -108,8 +108,8 @@ internal class DoubleWasmBuilder(target: MST) : WasmBuilder(f64, DoubleF
override fun visitNumeric(mst: Numeric): ExpressionRef = ctx.f64.const(mst.value)
override fun visitUnary(mst: Unary): ExpressionRef = when (mst.operation) {
- GroupOperations.MINUS_OPERATION -> ctx.f64.neg(visit(mst.value))
- GroupOperations.PLUS_OPERATION -> visit(mst.value)
+ GroupOps.MINUS_OPERATION -> ctx.f64.neg(visit(mst.value))
+ GroupOps.PLUS_OPERATION -> visit(mst.value)
PowerOperations.SQRT_OPERATION -> ctx.f64.sqrt(visit(mst.value))
TrigonometricOperations.SIN_OPERATION -> ctx.call("sin", arrayOf(visit(mst.value)), f64)
TrigonometricOperations.COS_OPERATION -> ctx.call("cos", arrayOf(visit(mst.value)), f64)
@@ -129,10 +129,10 @@ internal class DoubleWasmBuilder(target: MST) : WasmBuilder(f64, DoubleF
}
override fun visitBinary(mst: Binary): ExpressionRef = when (mst.operation) {
- GroupOperations.PLUS_OPERATION -> ctx.f64.add(visit(mst.left), visit(mst.right))
- GroupOperations.MINUS_OPERATION -> ctx.f64.sub(visit(mst.left), visit(mst.right))
- RingOperations.TIMES_OPERATION -> ctx.f64.mul(visit(mst.left), visit(mst.right))
- FieldOperations.DIV_OPERATION -> ctx.f64.div(visit(mst.left), visit(mst.right))
+ GroupOps.PLUS_OPERATION -> ctx.f64.add(visit(mst.left), visit(mst.right))
+ GroupOps.MINUS_OPERATION -> ctx.f64.sub(visit(mst.left), visit(mst.right))
+ RingOps.TIMES_OPERATION -> ctx.f64.mul(visit(mst.left), visit(mst.right))
+ FieldOps.DIV_OPERATION -> ctx.f64.div(visit(mst.left), visit(mst.right))
PowerOperations.POW_OPERATION -> ctx.call("pow", arrayOf(visit(mst.left), visit(mst.right)), f64)
else -> super.visitBinary(mst)
}
@@ -142,15 +142,15 @@ internal class IntWasmBuilder(target: MST) : WasmBuilder(i32, IntRing, targ
override fun visitNumeric(mst: Numeric): ExpressionRef = ctx.i32.const(mst.value)
override fun visitUnary(mst: Unary): ExpressionRef = when (mst.operation) {
- GroupOperations.MINUS_OPERATION -> ctx.i32.sub(ctx.i32.const(0), visit(mst.value))
- GroupOperations.PLUS_OPERATION -> visit(mst.value)
+ GroupOps.MINUS_OPERATION -> ctx.i32.sub(ctx.i32.const(0), visit(mst.value))
+ GroupOps.PLUS_OPERATION -> visit(mst.value)
else -> super.visitUnary(mst)
}
override fun visitBinary(mst: Binary): ExpressionRef = when (mst.operation) {
- GroupOperations.PLUS_OPERATION -> ctx.i32.add(visit(mst.left), visit(mst.right))
- GroupOperations.MINUS_OPERATION -> ctx.i32.sub(visit(mst.left), visit(mst.right))
- RingOperations.TIMES_OPERATION -> ctx.i32.mul(visit(mst.left), visit(mst.right))
+ GroupOps.PLUS_OPERATION -> ctx.i32.add(visit(mst.left), visit(mst.right))
+ GroupOps.MINUS_OPERATION -> ctx.i32.sub(visit(mst.left), visit(mst.right))
+ RingOps.TIMES_OPERATION -> ctx.i32.mul(visit(mst.left), visit(mst.right))
else -> super.visitBinary(mst)
}
}
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt
index 21a88b5d0..fe9c22c18 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.wasm.internal
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt
index 6ea8f26c1..5b28b8782 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.wasm
diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/TestExecutionTime.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/TestExecutionTime.kt
index d0e8128b4..f8c429d5a 100644
--- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/TestExecutionTime.kt
+++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/TestExecutionTime.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
@@ -11,19 +11,21 @@ import space.kscience.kmath.operations.bindSymbol
import space.kscience.kmath.operations.invoke
import kotlin.math.sin
import kotlin.random.Random
+import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.time.measureTime
import space.kscience.kmath.estree.compileToExpression as estreeCompileToExpression
import space.kscience.kmath.wasm.compileToExpression as wasmCompileToExpression
// TODO move to benchmarks when https://github.com/Kotlin/kotlinx-benchmark/pull/38 or similar feature is merged
+@Ignore
internal class TestExecutionTime {
private companion object {
private const val times = 1_000_000
private val x by symbol
private val algebra = DoubleField
- private val functional = DoubleField.expressionInExtendedField {
+ private val functional = algebra.expressionInExtendedField {
bindSymbol(x) * const(2.0) + const(2.0) / bindSymbol(x) - const(16.0) / sin(bindSymbol(x))
}
@@ -31,9 +33,9 @@ internal class TestExecutionTime {
x * number(2.0) + number(2.0) / x - number(16.0) / sin(x)
}
- private val mst = node.toExpression(DoubleField)
- private val wasm = node.wasmCompileToExpression(DoubleField)
- private val estree = node.estreeCompileToExpression(DoubleField)
+ private val mst = node.toExpression(algebra)
+ private val wasm = node.wasmCompileToExpression(algebra)
+ private val estree = node.estreeCompileToExpression(algebra)
// In JavaScript, the expression below is implemented like
// _no_name_provided__125.prototype.invoke_178 = function (args) {
@@ -44,7 +46,7 @@ internal class TestExecutionTime {
private val raw = Expression { args ->
val x = args[x]!!
- x * 2.0 + 2.0 / x - 16.0 / sin(x)
+ algebra { x * 2.0 + 2.0 / x - 16.0 / sin(x) }
}
private val justCalculate = { args: dynamic ->
diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt
index 93b7e9449..3c2a9bd13 100644
--- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt
+++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
@@ -10,6 +10,8 @@ import space.kscience.kmath.expressions.MST
import space.kscience.kmath.expressions.Symbol
import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.operations.IntRing
+import kotlin.contracts.InvocationKind
+import kotlin.contracts.contract
import space.kscience.kmath.estree.compile as estreeCompile
import space.kscience.kmath.estree.compileToExpression as estreeCompileToExpression
import space.kscience.kmath.wasm.compile as wasmCompile
@@ -34,6 +36,7 @@ private object ESTreeCompilerTestContext : CompilerTestContext {
}
internal actual inline fun runCompilerTest(action: CompilerTestContext.() -> Unit) {
+ contract { callsInPlace(action, InvocationKind.AT_LEAST_ONCE) }
action(WasmCompilerTestContext)
action(ESTreeCompilerTestContext)
}
diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt
index 45776c191..6c91df866 100644
--- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt
+++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.wasm
@@ -11,7 +11,6 @@ import space.kscience.kmath.expressions.invoke
import space.kscience.kmath.expressions.symbol
import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.operations.IntRing
-import space.kscience.kmath.operations.bindSymbol
import space.kscience.kmath.operations.invoke
import kotlin.test.Test
import kotlin.test.assertEquals
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 4147324ee..2426d6ee4 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
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.asm
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 a796ae2a5..418d6141b 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
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.asm.internal
@@ -14,9 +14,11 @@ import space.kscience.kmath.expressions.Expression
import space.kscience.kmath.expressions.MST
import java.lang.invoke.MethodHandles
import java.lang.invoke.MethodType
+import java.nio.file.Paths
import java.util.stream.Collectors.toMap
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
+import kotlin.io.path.writeBytes
/**
* ASM Builder is a structure that abstracts building a class designated to unwrap [MST] to plain Java expression.
@@ -194,15 +196,18 @@ internal class AsmBuilder(
visitEnd()
}
- val cls = classLoader.defineClass(className, classWriter.toByteArray())
- // java.io.File("dump.class").writeBytes(classWriter.toByteArray())
+ val binary = classWriter.toByteArray()
+ val cls = classLoader.defineClass(className, binary)
+
+ if (System.getProperty("space.kscience.communicator.prettyapi.dump.generated.classes") == "1")
+ Paths.get("$className.class").writeBytes(binary)
+
val l = MethodHandles.publicLookup()
- if (hasConstants)
- l.findConstructor(cls, MethodType.methodType(Void.TYPE, Array::class.java))
- .invoke(constants.toTypedArray()) as Expression
+ (if (hasConstants)
+ l.findConstructor(cls, MethodType.methodType(Void.TYPE, Array::class.java))(constants.toTypedArray())
else
- l.findConstructor(cls, MethodType.methodType(Void.TYPE)).invoke() as Expression
+ l.findConstructor(cls, MethodType.methodType(Void.TYPE))()) as Expression
}
/**
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 a84248f63..5e2e7d8c6 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
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.asm.internal
@@ -57,13 +57,13 @@ internal fun MethodVisitor.label(): Label = Label().also(::visitLabel)
/**
* Creates a class name for [Expression] subclassed to implement [mst] provided.
*
- * This methods helps to avoid collisions of class name to prevent loading several classes with the same name. If there
+ * These methods help to avoid collisions of class name to prevent loading several classes with the same name. If there
* is a colliding class, change [collision] parameter or leave it `0` to check existing classes recursively.
*
* @author Iaroslav Postovalov
*/
internal tailrec fun buildName(mst: MST, collision: Int = 0): String {
- val name = "space.kscience.kmath.asm.generated.AsmCompiledExpression_${mst.hashCode()}_$collision"
+ val name = "space.kscience.kmath.asm.generated.CompiledExpression_${mst.hashCode()}_$collision"
try {
Class.forName(name)
diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt
index 8f4daecf9..40d9d8fe6 100644
--- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt
+++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt
@@ -1,13 +1,12 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
@file:JvmName("MapIntrinsics")
package space.kscience.kmath.asm.internal
-import space.kscience.kmath.expressions.StringSymbol
import space.kscience.kmath.expressions.Symbol
/**
@@ -15,4 +14,4 @@ import space.kscience.kmath.expressions.Symbol
*
* @author Iaroslav Postovalov
*/
-internal fun Map.getOrFail(key: String): V = getValue(StringSymbol(key))
+internal fun Map.getOrFail(key: String): V = getValue(Symbol(key))
diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
index 556adbe7d..3e5253084 100644
--- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
+++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt
index d3b554efd..a0bdd68a0 100644
--- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt
+++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.ast
@@ -10,6 +10,8 @@ import space.kscience.kmath.expressions.MST
import space.kscience.kmath.expressions.Symbol
import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.operations.IntRing
+import kotlin.contracts.InvocationKind
+import kotlin.contracts.contract
import space.kscience.kmath.asm.compile as asmCompile
import space.kscience.kmath.asm.compileToExpression as asmCompileToExpression
@@ -22,4 +24,7 @@ private object AsmCompilerTestContext : CompilerTestContext {
asmCompile(algebra, arguments)
}
-internal actual inline fun runCompilerTest(action: CompilerTestContext.() -> Unit) = action(AsmCompilerTestContext)
+internal actual inline fun runCompilerTest(action: CompilerTestContext.() -> Unit) {
+ contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
+ action(AsmCompilerTestContext)
+}
diff --git a/kmath-commons/build.gradle.kts b/kmath-commons/build.gradle.kts
index a208c956c..96c17a215 100644
--- a/kmath-commons/build.gradle.kts
+++ b/kmath-commons/build.gradle.kts
@@ -9,6 +9,7 @@ dependencies {
api(project(":kmath-core"))
api(project(":kmath-complex"))
api(project(":kmath-coroutines"))
+ api(project(":kmath-optimization"))
api(project(":kmath-stat"))
api(project(":kmath-functions"))
api("org.apache.commons:commons-math3:3.6.1")
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt
index 361027968..4d2bd6237 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.commons.expressions
@@ -9,29 +9,29 @@ 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.NumbersAddOperations
+import space.kscience.kmath.operations.NumbersAddOps
/**
* A field over commons-math [DerivativeStructure].
*
* @property order The derivation order.
- * @property bindings The map of bindings values. All bindings are considered free parameters
+ * @param bindings The map of bindings values. All bindings are considered free parameters
*/
@OptIn(UnstableKMathAPI::class)
public class DerivativeStructureField(
public val order: Int,
bindings: Map,
) : ExtendedField, ExpressionAlgebra,
- NumbersAddOperations {
+ NumbersAddOps {
public val numberOfVariables: Int = bindings.size
- public override val zero: DerivativeStructure by lazy { DerivativeStructure(numberOfVariables, order) }
- public override val one: DerivativeStructure by lazy { DerivativeStructure(numberOfVariables, order, 1.0) }
+ override val zero: DerivativeStructure by lazy { DerivativeStructure(numberOfVariables, order) }
+ override val one: DerivativeStructure by lazy { DerivativeStructure(numberOfVariables, order, 1.0) }
- public override fun number(value: Number): DerivativeStructure = const(value.toDouble())
+ override fun number(value: Number): DerivativeStructure = const(value.toDouble())
/**
- * A class that implements both [DerivativeStructure] and a [Symbol]
+ * A class implementing both [DerivativeStructure] and [Symbol].
*/
public inner class DerivativeStructureSymbol(
size: Int,
@@ -39,10 +39,10 @@ public class DerivativeStructureField(
symbol: Symbol,
value: Double,
) : DerivativeStructure(size, order, index, value), Symbol {
- public override val identity: String = symbol.identity
- public override fun toString(): String = identity
- public override fun equals(other: Any?): Boolean = this.identity == (other as? Symbol)?.identity
- public override fun hashCode(): Int = identity.hashCode()
+ override val identity: String = symbol.identity
+ override fun toString(): String = identity
+ override fun equals(other: Any?): Boolean = this.identity == (other as? Symbol)?.identity
+ override fun hashCode(): Int = identity.hashCode()
}
/**
@@ -52,10 +52,10 @@ public class DerivativeStructureField(
key.identity to DerivativeStructureSymbol(numberOfVariables, index, key, value)
}.toMap()
- public override fun const(value: Double): DerivativeStructure = DerivativeStructure(numberOfVariables, order, value)
+ override fun const(value: Double): DerivativeStructure = DerivativeStructure(numberOfVariables, order, value)
- public override fun bindSymbolOrNull(value: String): DerivativeStructureSymbol? = variables[value]
- public override fun bindSymbol(value: String): DerivativeStructureSymbol = variables.getValue(value)
+ override fun bindSymbolOrNull(value: String): DerivativeStructureSymbol? = variables[value]
+ override fun bindSymbol(value: String): DerivativeStructureSymbol = variables.getValue(value)
public fun bindSymbolOrNull(symbol: Symbol): DerivativeStructureSymbol? = variables[symbol.identity]
public fun bindSymbol(symbol: Symbol): DerivativeStructureSymbol = variables.getValue(symbol.identity)
@@ -68,47 +68,50 @@ public class DerivativeStructureField(
public fun DerivativeStructure.derivative(vararg symbols: Symbol): Double = derivative(symbols.toList())
- public override fun DerivativeStructure.unaryMinus(): DerivativeStructure = negate()
+ override fun DerivativeStructure.unaryMinus(): DerivativeStructure = negate()
- public override fun add(a: DerivativeStructure, b: DerivativeStructure): DerivativeStructure = a.add(b)
+ override fun add(left: DerivativeStructure, right: DerivativeStructure): DerivativeStructure = left.add(right)
- public override fun scale(a: DerivativeStructure, value: Double): DerivativeStructure = a.multiply(value)
+ override fun scale(a: DerivativeStructure, value: Double): DerivativeStructure = a.multiply(value)
- public override fun multiply(a: DerivativeStructure, b: DerivativeStructure): DerivativeStructure = a.multiply(b)
- public override fun divide(a: DerivativeStructure, b: DerivativeStructure): DerivativeStructure = a.divide(b)
- public override fun sin(arg: DerivativeStructure): DerivativeStructure = arg.sin()
- public override fun cos(arg: DerivativeStructure): DerivativeStructure = arg.cos()
- public override fun tan(arg: DerivativeStructure): DerivativeStructure = arg.tan()
- public override fun asin(arg: DerivativeStructure): DerivativeStructure = arg.asin()
- public override fun acos(arg: DerivativeStructure): DerivativeStructure = arg.acos()
- public override fun atan(arg: DerivativeStructure): DerivativeStructure = arg.atan()
- public override fun sinh(arg: DerivativeStructure): DerivativeStructure = arg.sinh()
- public override fun cosh(arg: DerivativeStructure): DerivativeStructure = arg.cosh()
- public override fun tanh(arg: DerivativeStructure): DerivativeStructure = arg.tanh()
- public override fun asinh(arg: DerivativeStructure): DerivativeStructure = arg.asinh()
- public override fun acosh(arg: DerivativeStructure): DerivativeStructure = arg.acosh()
- public override fun atanh(arg: DerivativeStructure): DerivativeStructure = arg.atanh()
+ override fun multiply(left: DerivativeStructure, right: DerivativeStructure): DerivativeStructure = left.multiply(right)
+ override fun divide(left: DerivativeStructure, right: DerivativeStructure): DerivativeStructure = left.divide(right)
+ override fun sin(arg: DerivativeStructure): DerivativeStructure = arg.sin()
+ override fun cos(arg: DerivativeStructure): DerivativeStructure = arg.cos()
+ override fun tan(arg: DerivativeStructure): DerivativeStructure = arg.tan()
+ override fun asin(arg: DerivativeStructure): DerivativeStructure = arg.asin()
+ override fun acos(arg: DerivativeStructure): DerivativeStructure = arg.acos()
+ override fun atan(arg: DerivativeStructure): DerivativeStructure = arg.atan()
+ override fun sinh(arg: DerivativeStructure): DerivativeStructure = arg.sinh()
+ override fun cosh(arg: DerivativeStructure): DerivativeStructure = arg.cosh()
+ override fun tanh(arg: DerivativeStructure): DerivativeStructure = arg.tanh()
+ override fun asinh(arg: DerivativeStructure): DerivativeStructure = arg.asinh()
+ override fun acosh(arg: DerivativeStructure): DerivativeStructure = arg.acosh()
+ override fun atanh(arg: DerivativeStructure): DerivativeStructure = arg.atanh()
- public override fun power(arg: DerivativeStructure, pow: Number): DerivativeStructure = when (pow) {
+ override fun power(arg: DerivativeStructure, pow: Number): DerivativeStructure = when (pow) {
is Double -> arg.pow(pow)
is Int -> arg.pow(pow)
else -> arg.pow(pow.toDouble())
}
public fun power(arg: DerivativeStructure, pow: DerivativeStructure): DerivativeStructure = arg.pow(pow)
- public override fun exp(arg: DerivativeStructure): DerivativeStructure = arg.exp()
- public override fun ln(arg: DerivativeStructure): DerivativeStructure = arg.log()
+ override fun exp(arg: DerivativeStructure): DerivativeStructure = arg.exp()
+ override fun ln(arg: DerivativeStructure): DerivativeStructure = arg.log()
- public override operator fun DerivativeStructure.plus(b: Number): DerivativeStructure = add(b.toDouble())
- public override operator fun DerivativeStructure.minus(b: Number): DerivativeStructure = subtract(b.toDouble())
- public override operator fun Number.plus(b: DerivativeStructure): DerivativeStructure = b + this
- public override operator fun Number.minus(b: DerivativeStructure): DerivativeStructure = b - this
+ override operator fun DerivativeStructure.plus(other: Number): DerivativeStructure = add(other.toDouble())
+ override operator fun DerivativeStructure.minus(other: Number): DerivativeStructure = subtract(other.toDouble())
+ override operator fun Number.plus(other: DerivativeStructure): DerivativeStructure = other + this
+ override operator fun Number.minus(other: DerivativeStructure): DerivativeStructure = other - this
+}
- public companion object :
- AutoDiffProcessor> {
- public override fun process(function: DerivativeStructureField.() -> DerivativeStructure): DifferentiableExpression =
- DerivativeStructureExpression(function)
- }
+/**
+ * Auto-diff processor based on Commons-math [DerivativeStructure]
+ */
+public object DSProcessor : AutoDiffProcessor {
+ override fun differentiate(
+ function: DerivativeStructureField.() -> DerivativeStructure,
+ ): DerivativeStructureExpression = DerivativeStructureExpression(function)
}
/**
@@ -117,13 +120,13 @@ public class DerivativeStructureField(
public class DerivativeStructureExpression(
public val function: DerivativeStructureField.() -> DerivativeStructure,
) : DifferentiableExpression {
- public override operator fun invoke(arguments: Map): Double =
+ override operator fun invoke(arguments: Map): Double =
DerivativeStructureField(0, arguments).function().value
/**
* Get the derivative expression with given orders
*/
- public override fun derivativeOrNull(symbols: List): Expression = Expression { arguments ->
+ override fun derivativeOrNull(symbols: List): Expression = Expression { arguments ->
with(DerivativeStructureField(symbols.size, arguments)) { function().derivative(symbols) }
}
}
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt
index 4e174723d..5152b04f9 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.commons.integration
@@ -16,7 +16,7 @@ public class CMGaussRuleIntegrator(
private var type: GaussRule = GaussRule.LEGANDRE,
) : UnivariateIntegrator {
- override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand {
+ override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand {
val range = integrand.getFeature()?.range
?: error("Integration range is not provided")
val integrator: GaussIntegrator = getIntegrator(range)
@@ -76,8 +76,8 @@ public class CMGaussRuleIntegrator(
numPoints: Int = 100,
type: GaussRule = GaussRule.LEGANDRE,
function: (Double) -> Double,
- ): Double = CMGaussRuleIntegrator(numPoints, type).integrate(
+ ): Double = CMGaussRuleIntegrator(numPoints, type).process(
UnivariateIntegrand(function, IntegrationRange(range))
- ).valueOrNull!!
+ ).value
}
}
\ No newline at end of file
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt
index bcddccdc4..76a2f297c 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.commons.integration
@@ -18,7 +18,7 @@ public class CMIntegrator(
public val integratorBuilder: (Integrand) -> org.apache.commons.math3.analysis.integration.UnivariateIntegrator,
) : UnivariateIntegrator {
- override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand {
+ override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand {
val integrator = integratorBuilder(integrand)
val maxCalls = integrand.getFeature()?.maxCalls ?: defaultMaxCalls
val remainingCalls = maxCalls - integrand.calls
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt
index 11b097831..14e7fc365 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.commons.linear
@@ -10,23 +10,27 @@ import space.kscience.kmath.linear.*
import space.kscience.kmath.misc.UnstableKMathAPI
import space.kscience.kmath.nd.StructureFeature
import space.kscience.kmath.operations.DoubleField
+import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.DoubleBuffer
import kotlin.reflect.KClass
import kotlin.reflect.cast
public class CMMatrix(public val origin: RealMatrix) : Matrix {
- public override val rowNum: Int get() = origin.rowDimension
- public override val colNum: Int get() = origin.columnDimension
+ override val rowNum: Int get() = origin.rowDimension
+ override val colNum: Int get() = origin.columnDimension
- public override operator fun get(i: Int, j: Int): Double = origin.getEntry(i, j)
+ override operator fun get(i: Int, j: Int): Double = origin.getEntry(i, j)
}
-public class CMVector(public val origin: RealVector) : Point {
- public override val size: Int get() = origin.dimension
+@JvmInline
+public value class CMVector(public val origin: RealVector) : Point {
+ override val size: Int get() = origin.dimension
- public override operator fun get(index: Int): Double = origin.getEntry(index)
+ override operator fun get(index: Int): Double = origin.getEntry(index)
- public override operator fun iterator(): Iterator = origin.toArray().iterator()
+ override operator fun iterator(): Iterator = origin.toArray().iterator()
+
+ override fun toString(): String = Buffer.toString(this)
}
public fun RealVector.toPoint(): CMVector = CMVector(this)
@@ -34,7 +38,7 @@ public fun RealVector.toPoint(): CMVector = CMVector(this)
public object CMLinearSpace : LinearSpace {
override val elementAlgebra: DoubleField get() = DoubleField
- public override fun buildMatrix(
+ override fun buildMatrix(
rows: Int,
columns: Int,
initializer: DoubleField.(i: Int, j: Int) -> Double,
@@ -73,16 +77,16 @@ public object CMLinearSpace : LinearSpace {
override fun Point.minus(other: Point): CMVector =
toCM().origin.subtract(other.toCM().origin).wrap()
- public override fun Matrix.dot(other: Matrix): CMMatrix =
+ override fun Matrix.dot(other: Matrix): CMMatrix =
toCM().origin.multiply(other.toCM().origin).wrap()
- public override fun Matrix.dot(vector: Point): CMVector =
+ override fun Matrix.dot(vector: Point): CMVector =
toCM().origin.preMultiply(vector.toCM().origin).wrap()
- public override operator fun Matrix.minus(other: Matrix): CMMatrix =
+ override operator fun Matrix.minus(other: Matrix): CMMatrix =
toCM().origin.subtract(other.toCM().origin).wrap()
- public override operator fun Matrix.times(value: Double): CMMatrix =
+ override operator fun Matrix.times(value: Double): CMMatrix =
toCM().origin.scalarMultiply(value).wrap()
override fun Double.times(m: Matrix): CMMatrix =
@@ -95,7 +99,7 @@ public object CMLinearSpace : LinearSpace {
v * this
@UnstableKMathAPI
- override fun getFeature(structure: Matrix, type: KClass): F? {
+ override fun computeFeature(structure: Matrix, type: KClass): F? {
//Return the feature if it is intrinsic to the structure
structure.getFeature(type)?.let { return it }
@@ -109,22 +113,22 @@ public object CMLinearSpace : LinearSpace {
LupDecompositionFeature {
private val lup by lazy { LUDecomposition(origin) }
override val determinant: Double by lazy { lup.determinant }
- override val l: Matrix by lazy { CMMatrix(lup.l) + LFeature }
- override val u: Matrix by lazy { CMMatrix(lup.u) + UFeature }
+ override val l: Matrix by lazy> { CMMatrix(lup.l).withFeature(LFeature) }
+ override val u: Matrix by lazy> { CMMatrix(lup.u).withFeature(UFeature) }
override val p: Matrix by lazy { CMMatrix(lup.p) }
}
CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature {
- override val l: Matrix by lazy {
+ override val l: Matrix by lazy> {
val cholesky = CholeskyDecomposition(origin)
- CMMatrix(cholesky.l) + LFeature
+ CMMatrix(cholesky.l).withFeature(LFeature)
}
}
QRDecompositionFeature::class -> object : QRDecompositionFeature {
private val qr by lazy { QRDecomposition(origin) }
- override val q: Matrix by lazy { CMMatrix(qr.q) + OrthogonalFeature }
- override val r: Matrix by lazy { CMMatrix(qr.r) + UFeature }
+ override val q: Matrix by lazy> { CMMatrix(qr.q).withFeature(OrthogonalFeature) }
+ override val r: Matrix by lazy> { CMMatrix(qr.r).withFeature(UFeature) }
}
SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature {
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt
index ee602ca06..d1fb441b0 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt
@@ -1,11 +1,12 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package space.kscience.kmath.commons.linear
import org.apache.commons.math3.linear.*
+import space.kscience.kmath.linear.LinearSolver
import space.kscience.kmath.linear.Matrix
import space.kscience.kmath.linear.Point
@@ -17,7 +18,7 @@ public enum class CMDecomposition {
CHOLESKY
}
-public fun CMLinearSpace.solver(
+private fun CMLinearSpace.solver(
a: Matrix,
decomposition: CMDecomposition = CMDecomposition.LUP,
): DecompositionSolver = when (decomposition) {
@@ -44,3 +45,14 @@ public fun CMLinearSpace.inverse(
a: Matrix,
decomposition: CMDecomposition = CMDecomposition.LUP,
): CMMatrix = solver(a, decomposition).inverse.wrap()
+
+
+public fun CMLinearSpace.solver(decomposition: CMDecomposition): LinearSolver = object : LinearSolver {
+ override fun solve(a: Matrix, b: Matrix): Matrix = solver(a, decomposition).solve(b.toCM().origin).wrap()
+
+ override fun solve(a: Matrix, b: Point): Point = solver(a, decomposition).solve(b.toCM().origin).toPoint()
+
+ override fun inverse(matrix: Matrix): Matrix = solver(matrix, decomposition).inverse.wrap()
+}
+
+public fun CMLinearSpace.lupSolver(): LinearSolver = solver((CMDecomposition.LUP))
\ No newline at end of file
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimization.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimization.kt
deleted file mode 100644
index 400ee0310..000000000
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimization.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
- */
-
-package space.kscience.kmath.commons.optimization
-
-import org.apache.commons.math3.optim.*
-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.ObjectiveFunction
-import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunctionGradient
-import org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer
-import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.AbstractSimplex
-import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex
-import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer
-import space.kscience.kmath.expressions.*
-import space.kscience.kmath.misc.UnstableKMathAPI
-import space.kscience.kmath.optimization.*
-import kotlin.collections.set
-import kotlin.reflect.KClass
-
-public operator fun PointValuePair.component1(): DoubleArray = point
-public operator fun PointValuePair.component2(): Double = value
-
-@OptIn(UnstableKMathAPI::class)
-public class CMOptimization(
- override val symbols: List,
-) : FunctionOptimization, NoDerivFunctionOptimization, SymbolIndexer, OptimizationFeature {
-
- private val optimizationData: HashMap, OptimizationData> = HashMap()
- private var optimizerBuilder: (() -> MultivariateOptimizer)? = null
- public var convergenceChecker: ConvergenceChecker = SimpleValueChecker(
- DEFAULT_RELATIVE_TOLERANCE,
- DEFAULT_ABSOLUTE_TOLERANCE,
- DEFAULT_MAX_ITER
- )
-
- override var maximize: Boolean
- get() = optimizationData[GoalType::class] == GoalType.MAXIMIZE
- set(value) {
- optimizationData[GoalType::class] = if (value) GoalType.MAXIMIZE else GoalType.MINIMIZE
- }
-
- public fun addOptimizationData(data: OptimizationData) {
- optimizationData[data::class] = data
- }
-
- init {
- addOptimizationData(MaxEval.unlimited())
- }
-
- public fun exportOptimizationData(): List = optimizationData.values.toList()
-
- public override fun initialGuess(map: Map): Unit {
- addOptimizationData(InitialGuess(map.toDoubleArray()))
- }
-
- public override fun function(expression: Expression): Unit {
- val objectiveFunction = ObjectiveFunction {
- val args = it.toMap()
- expression(args)
- }
- addOptimizationData(objectiveFunction)
- }
-
- public override fun diffFunction(expression: DifferentiableExpression) {
- function(expression)
- val gradientFunction = ObjectiveFunctionGradient {
- val args = it.toMap()
- DoubleArray(symbols.size) { index ->
- expression.derivative(symbols[index])(args)
- }
- }
- addOptimizationData(gradientFunction)
- if (optimizerBuilder == null) {
- optimizerBuilder = {
- NonLinearConjugateGradientOptimizer(
- NonLinearConjugateGradientOptimizer.Formula.FLETCHER_REEVES,
- convergenceChecker
- )
- }
- }
- }
-
- public fun simplex(simplex: AbstractSimplex) {
- addOptimizationData(simplex)
- //Set optimization builder to simplex if it is not present
- if (optimizerBuilder == null) {
- optimizerBuilder = { SimplexOptimizer(convergenceChecker) }
- }
- }
-
- public fun simplexSteps(steps: Map) {
- simplex(NelderMeadSimplex(steps.toDoubleArray()))
- }
-
- public fun goal(goalType: GoalType) {
- addOptimizationData(goalType)
- }
-
- public fun optimizer(block: () -> MultivariateOptimizer) {
- optimizerBuilder = block
- }
-
- override fun update(result: OptimizationResult) {
- initialGuess(result.point)
- }
-
- override fun optimize(): OptimizationResult {
- val optimizer = optimizerBuilder?.invoke() ?: error("Optimizer not defined")
- val (point, value) = optimizer.optimize(*optimizationData.values.toTypedArray())
- return OptimizationResult(point.toMap(), value, setOf(this))
- }
-
- public companion object : OptimizationProblemFactory {
- public const val DEFAULT_RELATIVE_TOLERANCE: Double = 1e-4
- public const val DEFAULT_ABSOLUTE_TOLERANCE: Double = 1e-4
- public const val DEFAULT_MAX_ITER: Int = 1000
-
- override fun build(symbols: List): CMOptimization = CMOptimization(symbols)
- }
-}
-
-public fun CMOptimization.initialGuess(vararg pairs: Pair