Add Jupyter integration with kmath-ast #265

Closed
CommanderTvis wants to merge 1 commits from commandertvis/jupyter into dev
5 changed files with 53 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import java.net.URL
plugins { plugins {
id("ru.mipt.npm.gradle.project") id("ru.mipt.npm.gradle.project")
kotlin("jupyter.api") apply false
} }
allprojects { allprojects {
@ -14,6 +15,7 @@ allprojects {
maven("https://dl.bintray.com/hotkeytlt/maven") maven("https://dl.bintray.com/hotkeytlt/maven")
maven("https://jitpack.io") maven("https://jitpack.io")
maven("http://logicrunch.research.it.uu.se/maven/") maven("http://logicrunch.research.it.uu.se/maven/")
maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
mavenCentral() mavenCentral()
} }

View File

@ -127,6 +127,7 @@ public object MstExtendedField : ExtendedField<MST>, NumericAlgebra<MST> {
public override fun acosh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.ACOSH_OPERATION)(arg) public override fun acosh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.ACOSH_OPERATION)(arg)
public override fun atanh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.ATANH_OPERATION)(arg) public override fun atanh(arg: MST): MST.Unary = unaryOperationFunction(ExponentialOperations.ATANH_OPERATION)(arg)
public override fun add(a: MST, b: MST): MST.Binary = MstField.add(a, b) public override fun add(a: MST, b: MST): MST.Binary = MstField.add(a, b)
public override fun sqrt(arg: MST): MST = unaryOperationFunction(PowerOperations.SQRT_OPERATION)(arg)
public override fun scale(a: MST, value: Double): MST = public override fun scale(a: MST, value: Double): MST =
binaryOperation(GroupOperations.PLUS_OPERATION, a, number(value)) binaryOperation(GroupOperations.PLUS_OPERATION, a, number(value))

View File

@ -0,0 +1,15 @@
import ru.mipt.npm.gradle.Maturity
plugins {
id("ru.mipt.npm.gradle.jvm")
kotlin("jupyter.api")
}
dependencies {
api(project(":kmath-ast"))
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.3")
}
readme {
maturity = Maturity.PROTOTYPE
}

View File

@ -0,0 +1,33 @@
package space.kscience.kmath.jupyter
import kotlinx.html.div
import kotlinx.html.stream.createHTML
import kotlinx.html.unsafe
import org.jetbrains.kotlinx.jupyter.api.HTML
import org.jetbrains.kotlinx.jupyter.api.annotations.JupyterLibrary
import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
import space.kscience.kmath.ast.MST
import space.kscience.kmath.ast.rendering.FeaturedMathRendererWithPostProcess
import space.kscience.kmath.ast.rendering.MathMLSyntaxRenderer
import space.kscience.kmath.ast.rendering.renderWithStringBuilder
@JupyterLibrary
internal class KMathJupyter : JupyterIntegration() {
override fun Builder.onLoaded() {
import(
"space.kscience.kmath.ast.*",
"space.kscience.kmath.ast.rendering.*",
"space.kscience.kmath.operations.*",
"space.kscience.kmath.expressions.*",
"space.kscience.kmath.misc.*",
)
render<MST> { mst ->
HTML(createHTML().div {
unsafe {
+MathMLSyntaxRenderer.renderWithStringBuilder(FeaturedMathRendererWithPostProcess.Default.render(mst))
}
})
}
}
}

View File

@ -16,6 +16,7 @@ pluginManagement {
id("ru.mipt.npm.gradle.mpp") version toolsVersion id("ru.mipt.npm.gradle.mpp") version toolsVersion
id("ru.mipt.npm.gradle.jvm") version toolsVersion id("ru.mipt.npm.gradle.jvm") version toolsVersion
id("ru.mipt.npm.gradle.publish") version toolsVersion id("ru.mipt.npm.gradle.publish") version toolsVersion
kotlin("jupyter.api") version "0.8.3.279"
kotlin("jvm") version kotlinVersion kotlin("jvm") version kotlinVersion
kotlin("plugin.allopen") version kotlinVersion kotlin("plugin.allopen") version kotlinVersion
} }
@ -40,5 +41,6 @@ include(
":kmath-ast", ":kmath-ast",
":kmath-ejml", ":kmath-ejml",
":kmath-kotlingrad", ":kmath-kotlingrad",
":kmath-jupyter",
":examples" ":examples"
) )