Add Jupyter integration with kmath-ast

This commit is contained in:
Iaroslav Postovalov 2021-03-31 19:39:34 +07:00
parent ae911fcc2f
commit 9b5c34311f
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
5 changed files with 53 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import java.net.URL
plugins {
id("ru.mipt.npm.gradle.project")
kotlin("jupyter.api") apply false
}
allprojects {
@ -14,6 +15,7 @@ allprojects {
maven("https://dl.bintray.com/hotkeytlt/maven")
maven("https://jitpack.io")
maven("http://logicrunch.research.it.uu.se/maven/")
maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
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 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 sqrt(arg: MST): MST = unaryOperationFunction(PowerOperations.SQRT_OPERATION)(arg)
public override fun scale(a: MST, value: Double): MST =
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.jvm") version toolsVersion
id("ru.mipt.npm.gradle.publish") version toolsVersion
kotlin("jupyter.api") version "0.8.3.279"
kotlin("jvm") version kotlinVersion
kotlin("plugin.allopen") version kotlinVersion
}
@ -40,5 +41,6 @@ include(
":kmath-ast",
":kmath-ejml",
":kmath-kotlingrad",
":kmath-jupyter",
":examples"
)