Add adapters of scalar functions to MST and vice versa #150

Merged
CommanderTvis merged 23 commits from kotlingrad into dev 2020-11-01 21:09:45 +03:00
Showing only changes of commit 5de9d69237 - Show all commits

View File

@ -8,8 +8,8 @@ import kscience.kmath.operations.*
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
/**
* Maps [SFun] objects to [MST]. Some unsupported operations like [Derivative] are bound and converted then.
*
* @receiver a scalar function.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @return the [MST].
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @receiver the scalar function.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @return a node.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
*/
public fun <X : SFun<X>> SFun<X>.mst(): MST = MstExtendedField {
when (this@mst) {
@ -30,36 +30,52 @@ public fun <X : SFun<X>> SFun<X>.mst(): MST = MstExtendedField {
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
}
}
/**
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* Maps [MST.Numeric] to [SConst] directly.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
*
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @receiver the node.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @return a new constant.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
*/
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
public fun <X : SFun<X>> MST.Numeric.sconst(): SConst<X> = SConst(value)
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
/**
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* Maps [MST.Symbolic] to [SVar] directly.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
*
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @receiver the node.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @param proto the prototype instance.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @return a new variable.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
*/
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
public fun <X : SFun<X>> MST.Symbolic.svar(proto: X): SVar<X> = SVar(proto, value)
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
/**
* Maps [MST] objects to [SFun]. Unsupported operations throw [IllegalStateException].
*
* @receiver an [MST].
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @return the scalar function.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @receiver the node.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @param proto the prototype instance.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
* @return a scalar function.
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
*/
public fun <X : SFun<X>> MST.sfun(proto: X): SFun<X> {
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
return when (this) {
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
is MST.Numeric -> SConst(value)
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
is MST.Symbolic -> SVar(proto, value)
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
public fun <X : SFun<X>> MST.sfun(proto: X): SFun<X> = when (this) {
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
is MST.Numeric -> sconst()
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
is MST.Symbolic -> svar(proto)
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
is MST.Unary -> when (operation) {
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
SpaceOperations.PLUS_OPERATION -> value.sfun(proto)
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
SpaceOperations.MINUS_OPERATION -> Negative(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
TrigonometricOperations.SIN_OPERATION -> Sine(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
TrigonometricOperations.COS_OPERATION -> Cosine(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
TrigonometricOperations.TAN_OPERATION -> Tangent(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
PowerOperations.SQRT_OPERATION -> Power(value.sfun(proto), SConst(0.5))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
ExponentialOperations.EXP_OPERATION -> Power(value.sfun(proto), E())
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
ExponentialOperations.LN_OPERATION -> Log(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
else -> error("Unary operation $operation not defined in $this")
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
}
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
is MST.Unary -> when (operation) {
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
SpaceOperations.PLUS_OPERATION -> value.sfun(proto)
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
SpaceOperations.MINUS_OPERATION -> Negative(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
TrigonometricOperations.SIN_OPERATION -> Sine(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
TrigonometricOperations.COS_OPERATION -> Cosine(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
TrigonometricOperations.TAN_OPERATION -> Tangent(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
PowerOperations.SQRT_OPERATION -> Power(value.sfun(proto), SConst(0.5))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
ExponentialOperations.EXP_OPERATION -> Power(value.sfun(proto), E())
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
ExponentialOperations.LN_OPERATION -> Log(value.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
else -> error("Unary operation $operation not defined in $this")
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
}
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
is MST.Binary -> when (operation) {
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
SpaceOperations.PLUS_OPERATION -> Sum(left.sfun(proto), right.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
SpaceOperations.MINUS_OPERATION -> Sum(left.sfun(proto), Negative(right.sfun(proto)))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
RingOperations.TIMES_OPERATION -> Prod(left.sfun(proto), right.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
FieldOperations.DIV_OPERATION -> Prod(left.sfun(proto), Power(right.sfun(proto), Negative(One())))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
PowerOperations.POW_OPERATION -> Power(left.sfun(proto), SConst((right as MST.Numeric).value))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
else -> error("Binary operation $operation not defined in $this")
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
}
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
is MST.Binary -> when (operation) {
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
SpaceOperations.PLUS_OPERATION -> Sum(left.sfun(proto), right.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
SpaceOperations.MINUS_OPERATION -> Sum(left.sfun(proto), Negative(right.sfun(proto)))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
RingOperations.TIMES_OPERATION -> Prod(left.sfun(proto), right.sfun(proto))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
FieldOperations.DIV_OPERATION -> Prod(left.sfun(proto), Power(right.sfun(proto), Negative(One())))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
PowerOperations.POW_OPERATION -> Power(left.sfun(proto), SConst((right as MST.Numeric).value))
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
else -> error("Binary operation $operation not defined in $this")
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
}
}

altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()
altavir commented 2020-10-13 15:36:56 +03:00 (Migrated from github.com)
Review

change to toMst()

change to toMst()