forked from kscience/kmath
Update jupyter integration
This commit is contained in:
parent
0622be2494
commit
e4e661a3bf
@ -5,6 +5,7 @@
|
||||
|
||||
package space.kscience.kmath.structures
|
||||
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import org.nd4j.linalg.factory.Nd4j
|
||||
import space.kscience.kmath.nd.*
|
||||
@ -22,6 +23,7 @@ internal inline fun measureAndPrint(title: String, block: () -> Unit) {
|
||||
println("$title completed in $time millis")
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun main() {
|
||||
// initializing Nd4j
|
||||
Nd4j.zeros(0)
|
||||
|
@ -7,7 +7,10 @@ dependencies {
|
||||
api(project(":kmath-ast"))
|
||||
api(project(":kmath-complex"))
|
||||
api(project(":kmath-for-real"))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.3")
|
||||
}
|
||||
|
||||
kscience{
|
||||
useHtml()
|
||||
}
|
||||
|
||||
readme {
|
||||
|
@ -19,31 +19,23 @@ import space.kscience.kmath.operations.RingOperations
|
||||
import space.kscience.kmath.structures.Buffer
|
||||
import space.kscience.kmath.structures.asSequence
|
||||
|
||||
/**
|
||||
* A function for conversion of number to MST for pretty print
|
||||
*/
|
||||
public fun Number.toMst(): MST.Numeric = MST.Numeric(this)
|
||||
|
||||
@JupyterLibrary
|
||||
internal class KMathJupyter : JupyterIntegration() {
|
||||
private val mathRender = FeaturedMathRendererWithPostProcess.Default
|
||||
private val syntaxRender = MathMLSyntaxRenderer
|
||||
|
||||
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.*",
|
||||
"space.kscience.kmath.real.*",
|
||||
)
|
||||
|
||||
fun MST.toDisplayResult(): DisplayResult = HTML(createHTML().div {
|
||||
private fun MST.toDisplayResult(): DisplayResult = HTML(createHTML().div {
|
||||
unsafe {
|
||||
+syntaxRender.renderWithStringBuilder(mathRender.render(this@toDisplayResult))
|
||||
}
|
||||
})
|
||||
|
||||
render<MST> { it.toDisplayResult() }
|
||||
render<Number> { MST.Numeric(it).toDisplayResult() }
|
||||
|
||||
fun Unsafe.appendCellValue(it: Any?) {
|
||||
private fun Unsafe.appendCellValue(it: Any?) {
|
||||
when (it) {
|
||||
is Number -> {
|
||||
val s = StringBuilder()
|
||||
@ -63,6 +55,23 @@ internal class KMathJupyter : JupyterIntegration() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun Builder.onLoaded() {
|
||||
import(
|
||||
"space.kscience.kmath.ast.*",
|
||||
"space.kscience.kmath.ast.rendering.*",
|
||||
"space.kscience.kmath.structures.*",
|
||||
"space.kscience.kmath.operations.*",
|
||||
"space.kscience.kmath.expressions.*",
|
||||
"space.kscience.kmath.nd.*",
|
||||
"space.kscience.kmath.misc.*",
|
||||
"space.kscience.kmath.real.*",
|
||||
)
|
||||
|
||||
import("space.kscience.kmath.jupyter.toMst")
|
||||
|
||||
render<MST> { it.toDisplayResult() }
|
||||
//render<Number> { MST.Numeric(it).toDisplayResult() }
|
||||
|
||||
render<Structure2D<*>> { structure ->
|
||||
HTML(createHTML().div {
|
||||
unsafe {
|
||||
|
@ -1,25 +1,23 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.kotlin.link")
|
||||
}
|
||||
|
||||
val toolsVersion = "0.9.5-dev-2"
|
||||
val kotlinVersion = "1.5.0-RC"
|
||||
val toolsVersion = "0.9.6"
|
||||
val kotlinVersion = "1.5.0"
|
||||
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.project") version toolsVersion
|
||||
id("ru.mipt.npm.gradle.mpp") version toolsVersion
|
||||
id("ru.mipt.npm.gradle.jvm") version toolsVersion
|
||||
kotlin("multiplatform") version kotlinVersion
|
||||
kotlin("jvm") version kotlinVersion
|
||||
kotlin("plugin.allopen") version kotlinVersion
|
||||
id("org.jetbrains.kotlinx.benchmark") version "0.3.0"
|
||||
id("ru.mipt.npm.gradle.project") version toolsVersion
|
||||
id("ru.mipt.npm.gradle.mpp") version toolsVersion
|
||||
id("ru.mipt.npm.gradle.jvm") version toolsVersion
|
||||
kotlin("jupyter.api") version "0.9.0.12"
|
||||
kotlin("jvm") version kotlinVersion
|
||||
kotlin("plugin.allopen") version kotlinVersion
|
||||
kotlin("jupyter.api") version "0.9.1-61"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user