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