Add adapters of scalar functions to MST and vice versa #150
@ -12,6 +12,7 @@ allprojects {
|
|||||||
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||||
maven("https://dl.bintray.com/kotlin/kotlinx")
|
maven("https://dl.bintray.com/kotlin/kotlinx")
|
||||||
maven("https://dl.bintray.com/hotkeytlt/maven")
|
maven("https://dl.bintray.com/hotkeytlt/maven")
|
||||||
|
maven("https://jitpack.io")
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "kscience.kmath"
|
group = "kscience.kmath"
|
||||||
|
8
kmath-ast-kotlingrad/build.gradle.kts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
plugins {
|
||||||
|
id("ru.mipt.npm.jvm")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api("com.github.breandan:kotlingrad:0.3.2")
|
||||||
|
api(project(":kmath-ast"))
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
|||||||
|
package kscience.kmath.ast.kotlingrad
|
||||||
change to toMst() change to toMst()
|
|||||||
|
|
||||||
change to toMst() change to toMst()
|
|||||||
|
import edu.umontreal.kotlingrad.experimental.*
|
||||||
change to toMst() change to toMst()
|
|||||||
|
import kscience.kmath.ast.MST
|
||||||
change to toMst() change to toMst()
|
|||||||
|
import kscience.kmath.ast.MstExtendedField
|
||||||
change to toMst() change to toMst()
|
|||||||
|
import kscience.kmath.operations.*
|
||||||
change to toMst() change to toMst()
|
|||||||
|
|
||||||
change to toMst() change to toMst()
|
|||||||
|
/**
|
||||||
change to toMst() change to toMst()
|
|||||||
|
* Maps [SFun] objects to [MST]. Some unsupported operations like [Derivative] are bound and converted then.
|
||||||
change to toMst() change to toMst()
|
|||||||
|
*
|
||||||
change to toMst() change to toMst()
|
|||||||
|
* @receiver a scalar function.
|
||||||
change to toMst() change to toMst()
|
|||||||
|
* @return the [MST].
|
||||||
change to toMst() change to toMst()
|
|||||||
|
*/
|
||||||
change to toMst() change to toMst()
|
|||||||
|
public fun <X : SFun<X>> SFun<X>.mst(): MST = MstExtendedField {
|
||||||
change to toMst() change to toMst()
|
|||||||
|
when (this@mst) {
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is SVar -> symbol(name)
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is SConst -> number(doubleValue)
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is Sum -> left.mst() + right.mst()
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is Prod -> left.mst() * right.mst()
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is Power -> power(left.mst(), (right() as SConst<*>).doubleValue)
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is Negative -> -input.mst()
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is Log -> ln(left.mst()) / ln(right.mst())
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is Sine -> sin(input.mst())
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is Cosine -> cos(input.mst())
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is Tangent -> tan(input.mst())
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is DProd -> this@mst().mst()
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is SComposition -> this@mst().mst()
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is VSumAll<X, *> -> this@mst().mst()
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is Derivative -> this@mst().mst()
|
||||||
change to toMst() change to toMst()
|
|||||||
|
}
|
||||||
change to toMst() change to toMst()
|
|||||||
|
}
|
||||||
change to toMst() change to toMst()
|
|||||||
|
|
||||||
change to toMst() change to toMst()
|
|||||||
|
/**
|
||||||
change to toMst() change to toMst()
|
|||||||
|
* Maps [MST] objects to [SFun]. Unsupported operations throw [IllegalStateException].
|
||||||
change to toMst() change to toMst()
|
|||||||
|
*
|
||||||
change to toMst() change to toMst()
|
|||||||
|
* @receiver an [MST].
|
||||||
change to toMst() change to toMst()
|
|||||||
|
* @return the scalar function.
|
||||||
change to toMst() change to toMst()
|
|||||||
|
*/
|
||||||
change to toMst() change to toMst()
|
|||||||
|
public fun <X : SFun<X>> MST.sfun(proto: X): SFun<X> {
|
||||||
change to toMst() change to toMst()
|
|||||||
|
return when (this) {
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is MST.Numeric -> SConst(value)
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is MST.Symbolic -> SVar(proto, value)
|
||||||
change to toMst() change to toMst()
|
|||||||
|
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is MST.Unary -> when (operation) {
|
||||||
change to toMst() change to toMst()
|
|||||||
|
SpaceOperations.PLUS_OPERATION -> value.sfun(proto)
|
||||||
change to toMst() change to toMst()
|
|||||||
|
SpaceOperations.MINUS_OPERATION -> Negative(value.sfun(proto))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
TrigonometricOperations.SIN_OPERATION -> Sine(value.sfun(proto))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
TrigonometricOperations.COS_OPERATION -> Cosine(value.sfun(proto))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
TrigonometricOperations.TAN_OPERATION -> Tangent(value.sfun(proto))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
PowerOperations.SQRT_OPERATION -> Power(value.sfun(proto), SConst(0.5))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
ExponentialOperations.EXP_OPERATION -> Power(value.sfun(proto), E())
|
||||||
change to toMst() change to toMst()
|
|||||||
|
ExponentialOperations.LN_OPERATION -> Log(value.sfun(proto))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
else -> error("Unary operation $operation not defined in $this")
|
||||||
change to toMst() change to toMst()
|
|||||||
|
}
|
||||||
change to toMst() change to toMst()
|
|||||||
|
|
||||||
change to toMst() change to toMst()
|
|||||||
|
is MST.Binary -> when (operation) {
|
||||||
change to toMst() change to toMst()
|
|||||||
|
SpaceOperations.PLUS_OPERATION -> Sum(left.sfun(proto), right.sfun(proto))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
SpaceOperations.MINUS_OPERATION -> Sum(left.sfun(proto), Negative(right.sfun(proto)))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
RingOperations.TIMES_OPERATION -> Prod(left.sfun(proto), right.sfun(proto))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
FieldOperations.DIV_OPERATION -> Prod(left.sfun(proto), Power(right.sfun(proto), Negative(One())))
|
||||||
change to toMst() change to toMst()
|
|||||||
|
else -> error("Binary operation $operation not defined in $this")
|
||||||
change to toMst() change to toMst()
|
|||||||
|
}
|
||||||
change to toMst() change to toMst()
|
|||||||
|
}
|
||||||
change to toMst() change to toMst()
|
|||||||
|
}
|
||||||
change to toMst() change to toMst()
|
@ -1,4 +1,6 @@
|
|||||||
plugins { id("ru.mipt.npm.mpp") }
|
plugins {
|
||||||
|
id("ru.mipt.npm.mpp")
|
||||||
|
}
|
||||||
|
|
||||||
kotlin.sourceSets {
|
kotlin.sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
plugins { id("ru.mipt.npm.jvm") }
|
plugins {
|
||||||
|
id("ru.mipt.npm.jvm")
|
||||||
|
}
|
||||||
|
|
||||||
description = "Binding for https://github.com/JetBrains-Research/viktor"
|
description = "Binding for https://github.com/JetBrains-Research/viktor"
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ pluginManagement {
|
|||||||
maven("https://dl.bintray.com/mipt-npm/kscience")
|
maven("https://dl.bintray.com/mipt-npm/kscience")
|
||||||
maven("https://dl.bintray.com/mipt-npm/dev")
|
maven("https://dl.bintray.com/mipt-npm/dev")
|
||||||
maven("https://dl.bintray.com/kotlin/kotlinx")
|
maven("https://dl.bintray.com/kotlin/kotlinx")
|
||||||
maven("https://dl.bintray.com/kotlin/kotlin-dev/")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val toolsVersion = "0.6.1-dev-1.4.20-M1"
|
val toolsVersion = "0.6.1-dev-1.4.20-M1"
|
||||||
@ -25,11 +24,11 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = "kmath"
|
rootProject.name = "kmath"
|
||||||
|
|
||||||
include(
|
include(
|
||||||
":kmath-memory",
|
":kmath-memory",
|
||||||
":kmath-core",
|
":kmath-core",
|
||||||
":kmath-functions",
|
":kmath-functions",
|
||||||
// ":kmath-io",
|
|
||||||
":kmath-coroutines",
|
":kmath-coroutines",
|
||||||
":kmath-histograms",
|
":kmath-histograms",
|
||||||
":kmath-commons",
|
":kmath-commons",
|
||||||
@ -40,5 +39,6 @@ include(
|
|||||||
":kmath-geometry",
|
":kmath-geometry",
|
||||||
":kmath-ast",
|
":kmath-ast",
|
||||||
":examples",
|
":examples",
|
||||||
":kmath-ejml"
|
":kmath-ejml",
|
||||||
|
":kmath-ast-kotlingrad"
|
||||||
)
|
)
|
||||||
|
change to toMst()
change to toMst()