Fix issues found after merge

This commit is contained in:
Iaroslav 2020-06-12 22:10:56 +07:00
parent 07b938e582
commit b902f3980a
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
6 changed files with 42 additions and 13 deletions

View File

@ -1,11 +1,11 @@
package scientifik.kmath.expressions.asm package scientifik.kmath.expressions.asm
import scientifik.kmath.expressions.ExpressionContext import scientifik.kmath.expressions.ExpressionAlgebra
import scientifik.kmath.operations.* import scientifik.kmath.operations.*
open class AsmExpressionAlgebra<T>(val algebra: Algebra<T>) : open class AsmExpressionAlgebra<T>(val algebra: Algebra<T>) :
Algebra<AsmExpression<T>>, Algebra<AsmExpression<T>>,
ExpressionContext<T, AsmExpression<T>> { ExpressionAlgebra<T, AsmExpression<T>> {
override fun unaryOperation(operation: String, arg: AsmExpression<T>): AsmExpression<T> = override fun unaryOperation(operation: String, arg: AsmExpression<T>): AsmExpression<T> =
AsmUnaryOperation(algebra, operation, arg) AsmUnaryOperation(algebra, operation, arg)

View File

@ -1,7 +1,7 @@
package scientifik.kmath.expressions.asm package scientifik.kmath.expressions.asm
import scientifik.kmath.expressions.Expression import scientifik.kmath.expressions.Expression
import scientifik.kmath.expressions.ExpressionContext import scientifik.kmath.expressions.ExpressionAlgebra
import scientifik.kmath.operations.* import scientifik.kmath.operations.*
@PublishedApi @PublishedApi
@ -18,7 +18,7 @@ internal fun buildName(expression: AsmExpression<*>, collision: Int = 0): String
} }
inline fun <reified T, E : ExpressionContext<T, AsmExpression<T>>> asm( inline fun <reified T, E : ExpressionAlgebra<T, AsmExpression<T>>> asm(
i: E, i: E,
algebra: Algebra<T>, algebra: Algebra<T>,
block: E.() -> AsmExpression<T> block: E.() -> AsmExpression<T>
@ -29,22 +29,22 @@ inline fun <reified T, E : ExpressionContext<T, AsmExpression<T>>> asm(
return ctx.generate() return ctx.generate()
} }
inline fun <reified T> asmAlgebra( inline fun <reified T> buildAsmAlgebra(
algebra: Algebra<T>, algebra: Algebra<T>,
block: AsmExpressionAlgebra<T>.() -> AsmExpression<T> block: AsmExpressionAlgebra<T>.() -> AsmExpression<T>
): Expression<T> = asm(AsmExpressionAlgebra(algebra), algebra, block) ): Expression<T> = asm(AsmExpressionAlgebra(algebra), algebra, block)
inline fun <reified T> asmSpace( inline fun <reified T> buildAsmSpace(
algebra: Space<T>, algebra: Space<T>,
block: AsmExpressionSpace<T>.() -> AsmExpression<T> block: AsmExpressionSpace<T>.() -> AsmExpression<T>
): Expression<T> = asm(AsmExpressionSpace(algebra), algebra, block) ): Expression<T> = asm(AsmExpressionSpace(algebra), algebra, block)
inline fun <reified T> asmRing( inline fun <reified T> buildAsmRing(
algebra: Ring<T>, algebra: Ring<T>,
block: AsmExpressionRing<T>.() -> AsmExpression<T> block: AsmExpressionRing<T>.() -> AsmExpression<T>
): Expression<T> = asm(AsmExpressionRing(algebra), algebra, block) ): Expression<T> = asm(AsmExpressionRing(algebra), algebra, block)
inline fun <reified T> asmField( inline fun <reified T> buildAsmField(
algebra: Field<T>, algebra: Field<T>,
block: AsmExpressionField<T>.() -> AsmExpression<T> block: AsmExpressionField<T>.() -> AsmExpression<T>
): Expression<T> = asm(AsmExpressionField(algebra), algebra, block) ): Expression<T> = asm(AsmExpressionField(algebra), algebra, block)

View File

@ -2,9 +2,7 @@ package scientifik.kmath.expressions
import scientifik.kmath.expressions.asm.AsmExpression import scientifik.kmath.expressions.asm.AsmExpression
import scientifik.kmath.expressions.asm.AsmExpressionField import scientifik.kmath.expressions.asm.AsmExpressionField
import scientifik.kmath.expressions.asm.asmField import scientifik.kmath.expressions.asm.buildAsmField
import scientifik.kmath.expressions.asm.asmRing
import scientifik.kmath.operations.IntRing
import scientifik.kmath.operations.RealField import scientifik.kmath.operations.RealField
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -14,7 +12,7 @@ class AsmTest {
expected: Double?, expected: Double?,
arguments: Map<String, Double> = emptyMap(), arguments: Map<String, Double> = emptyMap(),
block: AsmExpressionField<Double>.() -> AsmExpression<Double> block: AsmExpressionField<Double>.() -> AsmExpression<Double>
): Unit = assertEquals(expected = expected, actual = asmField(RealField, block)(arguments)) ): Unit = assertEquals(expected = expected, actual = buildAsmField(RealField, block)(arguments))
@Test @Test
fun testConstantsSum(): Unit = testDoubleExpression(16.0) { const(8.0) + 8.0 } fun testConstantsSum(): Unit = testDoubleExpression(16.0) { const(8.0) + 8.0 }

View File

@ -0,0 +1,30 @@
package scientifik.kmath.expressions
import scientifik.kmath.operations.Algebra
import scientifik.kmath.operations.Field
import scientifik.kmath.operations.Ring
import scientifik.kmath.operations.Space
/**
* Create a functional expression on this [Algebra]
*/
fun <T> Algebra<T>.buildExpression(block: FunctionalExpressionAlgebra<T>.() -> Expression<T>): Expression<T> =
FunctionalExpressionAlgebra(this).run(block)
/**
* Create a functional expression on this [Space]
*/
fun <T> Space<T>.buildExpression(block: FunctionalExpressionSpace<T>.() -> Expression<T>): Expression<T> =
FunctionalExpressionSpace(this).run(block)
/**
* Create a functional expression on this [Ring]
*/
fun <T> Ring<T>.buildExpression(block: FunctionalExpressionRing<T>.() -> Expression<T>): Expression<T> =
FunctionalExpressionRing(this).run(block)
/**
* Create a functional expression on this [Field]
*/
fun <T> Field<T>.buildExpression(block: FunctionalExpressionField<T>.() -> Expression<T>): Expression<T> =
FunctionalExpressionField(this).run(block)

View File

@ -33,7 +33,7 @@ internal class FunctionalConstProductExpression<T>(val context: Space<T>, val ex
open class FunctionalExpressionAlgebra<T>(val algebra: Algebra<T>) : open class FunctionalExpressionAlgebra<T>(val algebra: Algebra<T>) :
Algebra<Expression<T>>, Algebra<Expression<T>>,
ExpressionContext<T, Expression<T>> { ExpressionAlgebra<T, Expression<T>> {
override fun unaryOperation(operation: String, arg: Expression<T>): Expression<T> = override fun unaryOperation(operation: String, arg: Expression<T>): Expression<T> =
FunctionalUnaryOperation(algebra, operation, arg) FunctionalUnaryOperation(algebra, operation, arg)

View File

@ -45,5 +45,6 @@ include(
":kmath-for-real", ":kmath-for-real",
":kmath-geometry", ":kmath-geometry",
":kmath-ast", ":kmath-ast",
":kmath-asm",
":examples" ":examples"
) )