diff --git a/build.gradle.kts b/build.gradle.kts index 05e2d5979..0da2212a7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,6 +12,7 @@ allprojects { maven("https://dl.bintray.com/kotlin/kotlin-eap") maven("https://dl.bintray.com/kotlin/kotlinx") maven("https://dl.bintray.com/hotkeytlt/maven") + maven("https://jitpack.io") } group = "kscience.kmath" diff --git a/kmath-ast-kotlingrad/build.gradle.kts b/kmath-ast-kotlingrad/build.gradle.kts new file mode 100644 index 000000000..0fe6e6b93 --- /dev/null +++ b/kmath-ast-kotlingrad/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + id("ru.mipt.npm.jvm") +} + +dependencies { + api("com.github.breandan:kotlingrad:0.3.2") + api(project(":kmath-ast")) +} diff --git a/kmath-ast-kotlingrad/src/main/kotlin/kscience/kmath/ast/kotlingrad/ScalarsAdapters.kt b/kmath-ast-kotlingrad/src/main/kotlin/kscience/kmath/ast/kotlingrad/ScalarsAdapters.kt new file mode 100644 index 000000000..70c8c09f8 --- /dev/null +++ b/kmath-ast-kotlingrad/src/main/kotlin/kscience/kmath/ast/kotlingrad/ScalarsAdapters.kt @@ -0,0 +1,64 @@ +package kscience.kmath.ast.kotlingrad + +import edu.umontreal.kotlingrad.experimental.* +import kscience.kmath.ast.MST +import kscience.kmath.ast.MstExtendedField +import kscience.kmath.operations.* + +/** + * Maps [SFun] objects to [MST]. Some unsupported operations like [Derivative] are bound and converted then. + * + * @receiver a scalar function. + * @return the [MST]. + */ +public fun > SFun.mst(): MST = MstExtendedField { + when (this@mst) { + is SVar -> symbol(name) + is SConst -> number(doubleValue) + is Sum -> left.mst() + right.mst() + is Prod -> left.mst() * right.mst() + is Power -> power(left.mst(), (right() as SConst<*>).doubleValue) + is Negative -> -input.mst() + is Log -> ln(left.mst()) / ln(right.mst()) + is Sine -> sin(input.mst()) + is Cosine -> cos(input.mst()) + is Tangent -> tan(input.mst()) + is DProd -> this@mst().mst() + is SComposition -> this@mst().mst() + is VSumAll -> this@mst().mst() + is Derivative -> this@mst().mst() + } +} + +/** + * Maps [MST] objects to [SFun]. Unsupported operations throw [IllegalStateException]. + * + * @receiver an [MST]. + * @return the scalar function. + */ +public fun > MST.sfun(proto: X): SFun { + return when (this) { + is MST.Numeric -> SConst(value) + is MST.Symbolic -> SVar(proto, value) + + is MST.Unary -> when (operation) { + SpaceOperations.PLUS_OPERATION -> value.sfun(proto) + SpaceOperations.MINUS_OPERATION -> Negative(value.sfun(proto)) + TrigonometricOperations.SIN_OPERATION -> Sine(value.sfun(proto)) + TrigonometricOperations.COS_OPERATION -> Cosine(value.sfun(proto)) + TrigonometricOperations.TAN_OPERATION -> Tangent(value.sfun(proto)) + PowerOperations.SQRT_OPERATION -> Power(value.sfun(proto), SConst(0.5)) + ExponentialOperations.EXP_OPERATION -> Power(value.sfun(proto), E()) + ExponentialOperations.LN_OPERATION -> Log(value.sfun(proto)) + else -> error("Unary operation $operation not defined in $this") + } + + is MST.Binary -> when (operation) { + SpaceOperations.PLUS_OPERATION -> Sum(left.sfun(proto), right.sfun(proto)) + SpaceOperations.MINUS_OPERATION -> Sum(left.sfun(proto), Negative(right.sfun(proto))) + RingOperations.TIMES_OPERATION -> Prod(left.sfun(proto), right.sfun(proto)) + FieldOperations.DIV_OPERATION -> Prod(left.sfun(proto), Power(right.sfun(proto), Negative(One()))) + else -> error("Binary operation $operation not defined in $this") + } + } +} diff --git a/kmath-prob/build.gradle.kts b/kmath-prob/build.gradle.kts index 4c9663e5f..186aff944 100644 --- a/kmath-prob/build.gradle.kts +++ b/kmath-prob/build.gradle.kts @@ -1,4 +1,6 @@ -plugins { id("ru.mipt.npm.mpp") } +plugins { + id("ru.mipt.npm.mpp") +} kotlin.sourceSets { commonMain { diff --git a/kmath-viktor/build.gradle.kts b/kmath-viktor/build.gradle.kts index 6fe8ad878..3e5c5912c 100644 --- a/kmath-viktor/build.gradle.kts +++ b/kmath-viktor/build.gradle.kts @@ -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" diff --git a/settings.gradle.kts b/settings.gradle.kts index 7ece3f25c..5fd072e1a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,7 +7,6 @@ pluginManagement { maven("https://dl.bintray.com/mipt-npm/kscience") maven("https://dl.bintray.com/mipt-npm/dev") 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" @@ -25,11 +24,11 @@ pluginManagement { } rootProject.name = "kmath" + include( ":kmath-memory", ":kmath-core", ":kmath-functions", -// ":kmath-io", ":kmath-coroutines", ":kmath-histograms", ":kmath-commons", @@ -40,5 +39,6 @@ include( ":kmath-geometry", ":kmath-ast", ":examples", - ":kmath-ejml" + ":kmath-ejml", + ":kmath-ast-kotlingrad" )