forked from kscience/kmath
Special rendering of Quaternion #330
This commit is contained in:
parent
feb5743f58
commit
fcb9605338
@ -187,7 +187,7 @@ public data class Complex(val re: Double, val im: Double) {
|
|||||||
public constructor(re: Number, im: Number) : this(re.toDouble(), im.toDouble())
|
public constructor(re: Number, im: Number) : this(re.toDouble(), im.toDouble())
|
||||||
public constructor(re: Number) : this(re.toDouble(), 0.0)
|
public constructor(re: Number) : this(re.toDouble(), 0.0)
|
||||||
|
|
||||||
public override fun toString(): String = "($re + i*$im)"
|
public override fun toString(): String = "($re + i * $im)"
|
||||||
|
|
||||||
public companion object : MemorySpec<Complex> {
|
public companion object : MemorySpec<Complex> {
|
||||||
public override val objectSize: Int
|
public override val objectSize: Int
|
||||||
|
@ -12,18 +12,19 @@ import space.kscience.kmath.ast.rendering.FeaturedMathRendererWithPostProcess
|
|||||||
import space.kscience.kmath.ast.rendering.MathMLSyntaxRenderer
|
import space.kscience.kmath.ast.rendering.MathMLSyntaxRenderer
|
||||||
import space.kscience.kmath.ast.rendering.renderWithStringBuilder
|
import space.kscience.kmath.ast.rendering.renderWithStringBuilder
|
||||||
import space.kscience.kmath.complex.Complex
|
import space.kscience.kmath.complex.Complex
|
||||||
|
import space.kscience.kmath.complex.Quaternion
|
||||||
import space.kscience.kmath.expressions.MST
|
import space.kscience.kmath.expressions.MST
|
||||||
|
import space.kscience.kmath.expressions.MstRing
|
||||||
import space.kscience.kmath.misc.PerformancePitfall
|
import space.kscience.kmath.misc.PerformancePitfall
|
||||||
import space.kscience.kmath.nd.Structure2D
|
import space.kscience.kmath.nd.Structure2D
|
||||||
import space.kscience.kmath.operations.GroupOperations
|
import space.kscience.kmath.operations.invoke
|
||||||
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
|
* A function for conversion of number to MST for pretty print
|
||||||
*/
|
*/
|
||||||
public fun Number.toMst(): MST.Numeric = MST.Numeric(this)
|
public fun Number.toMst(): MST.Numeric = MST.Numeric(this)
|
||||||
|
|
||||||
@JupyterLibrary
|
@JupyterLibrary
|
||||||
internal class KMathJupyter : JupyterIntegration() {
|
internal class KMathJupyter : JupyterIntegration() {
|
||||||
@ -121,11 +122,18 @@ internal class KMathJupyter : JupyterIntegration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render<Complex> {
|
render<Complex> {
|
||||||
MST.Binary(
|
MstRing {
|
||||||
operation = GroupOperations.PLUS_OPERATION,
|
number(it.re) + number(it.im) * bindSymbol("i")
|
||||||
left = MST.Numeric(it.re),
|
}.toDisplayResult()
|
||||||
right = MST.Binary(RingOperations.TIMES_OPERATION, MST.Numeric(it.im), MST.Symbolic("i")),
|
}
|
||||||
).toDisplayResult()
|
|
||||||
|
render<Quaternion> {
|
||||||
|
MstRing {
|
||||||
|
number(it.w) +
|
||||||
|
number(it.x) * bindSymbol("i") +
|
||||||
|
number(it.x) * bindSymbol("j") +
|
||||||
|
number(it.x) * bindSymbol("k")
|
||||||
|
}.toDisplayResult()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user