From b9f413b5ceb43147984c04d8e26a98fb245d7771 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 24 Dec 2024 12:26:01 +0300 Subject: [PATCH] Revert SymbolIndexer package to make ASM builders work. --- gradle.properties | 2 +- kmath-ast/build.gradle.kts | 4 ++-- .../space/kscience/kmath/wasm/internal/WasmBuilder.kt | 7 ++----- .../src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt | 1 - .../src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt | 1 - .../kscience/kmath/asm/internal/PrimitiveAsmBuilder.kt | 4 +--- .../space/kscience/kmath/asm/internal/codegenUtils.kt | 1 - .../kscience/kmath/commons/optimization/CMOptimizer.kt | 5 ++--- .../kotlin/space/kscience/kmath/expressions/DSAlgebra.kt | 1 - .../kotlin/space/kscience/kmath/expressions/Expression.kt | 1 - .../kscience/kmath/{named => expressions}/SymbolIndexer.kt | 5 +++-- .../kotlin/space/kscience/kmath/named/NamedBuffer.kt | 1 + .../kotlin/space/kscience/kmath/named/NamedMatrix.kt | 4 +++- .../space/kscience/kmath/optimization/QowOptimizer.kt | 7 ++----- 14 files changed, 17 insertions(+), 27 deletions(-) rename kmath-core/src/commonMain/kotlin/space/kscience/kmath/{named => expressions}/SymbolIndexer.kt (97%) diff --git a/gradle.properties b/gradle.properties index 3c52aadac..0741d89af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,4 +13,4 @@ kotlin.native.ignoreDisabledTargets=true org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers kotlin.native.enableKlibsCrossCompilation=true -toolsVersion=0.16.0-kotlin-2.1.0 +toolsVersion=0.16.0-kotlin-2.1.0 \ No newline at end of file diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index f441c4a86..26286896c 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -40,7 +40,7 @@ kscience { } dependencies(jvmMain) { - implementation("org.ow2.asm:asm-commons:9.2") + implementation("org.ow2.asm:asm-commons:9.7.1") } } @@ -54,7 +54,7 @@ kotlin { } } -if (System.getProperty("space.kscience.kmath.ast.dump.generated.classes") == "1") { +if (project.properties["space.kscience.kmath.ast.dump.generated.classes"] == "1") { tasks.withType { jvmArgs("-Dspace.kscience.kmath.ast.dump.generated.classes=1") } diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt index c12a7c033..69e608c03 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt @@ -5,15 +5,12 @@ package space.kscience.kmath.wasm.internal +import ``.invoke import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.ast.TypedMst -import space.kscience.kmath.expressions.DoubleExpression -import space.kscience.kmath.expressions.Expression -import space.kscience.kmath.expressions.IntExpression -import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.expressions.* import space.kscience.kmath.internal.binaryen.* import space.kscience.kmath.internal.webassembly.Instance -import space.kscience.kmath.named.SimpleSymbolIndexer import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Float64 import space.kscience.kmath.internal.binaryen.Module as BinaryenModule diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt index a70638159..26e6a2486 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt @@ -11,7 +11,6 @@ import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.ast.TypedMst import space.kscience.kmath.ast.evaluateConstants import space.kscience.kmath.expressions.* -import space.kscience.kmath.named.SimpleSymbolIndexer import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.Int32Ring import space.kscience.kmath.structures.Float64 diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt index 9a417e1d8..ac35562d2 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt @@ -12,7 +12,6 @@ import space.kscience.kmath.asm.internal.* import space.kscience.kmath.ast.TypedMst import space.kscience.kmath.ast.evaluateConstants import space.kscience.kmath.expressions.* -import space.kscience.kmath.named.SimpleSymbolIndexer import space.kscience.kmath.operations.Algebra import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.Int32Ring diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/PrimitiveAsmBuilder.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/PrimitiveAsmBuilder.kt index 117e2b9cb..277251433 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/PrimitiveAsmBuilder.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/PrimitiveAsmBuilder.kt @@ -14,8 +14,6 @@ import org.objectweb.asm.commons.InstructionAdapter import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.ast.TypedMst import space.kscience.kmath.expressions.* -import space.kscience.kmath.named.SimpleSymbolIndexer -import space.kscience.kmath.named.SymbolIndexer import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Float64 import java.lang.invoke.MethodHandles @@ -77,7 +75,7 @@ internal sealed class PrimitiveAsmBuilder>( val instance: E by lazy { val classWriter = ClassWriter(ClassWriter.COMPUTE_FRAMES) { visit( - V1_8, + V11, ACC_PUBLIC or ACC_FINAL or ACC_SUPER, classType.internalName, "${OBJECT_TYPE.descriptor}${expressionParentType.descriptor}", diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt index e0d3a0ef4..c4fe121ec 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt @@ -73,7 +73,6 @@ internal tailrec fun buildName(marker: String, collision: Int = 0): String { return buildName(marker, collision + 1) } -@Suppress("FunctionName") internal inline fun ClassWriter(flags: Int, block: ClassWriter.() -> Unit): ClassWriter { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return ClassWriter(flags).apply(block) diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt index e0cca4ae5..f0c9b0fb0 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt @@ -18,12 +18,11 @@ import space.kscience.attributes.AttributesBuilder import space.kscience.attributes.SetAttribute import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.expressions.SymbolIndexer import space.kscience.kmath.expressions.derivative -import space.kscience.kmath.named.SymbolIndexer -import space.kscience.kmath.named.withSymbols +import space.kscience.kmath.expressions.withSymbols import space.kscience.kmath.optimization.* import space.kscience.kmath.structures.Float64 -import kotlin.collections.set import kotlin.reflect.KClass public operator fun PointValuePair.component1(): DoubleArray = point diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt index 5965fa3aa..a6e721d13 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt @@ -7,7 +7,6 @@ package space.kscience.kmath.expressions import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.named.SymbolIndexer import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt index 8661a7c20..1cc3b766b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt @@ -9,7 +9,6 @@ import space.kscience.attributes.SafeType import space.kscience.attributes.WithType import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.named.SymbolIndexer import space.kscience.kmath.operations.Algebra import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.IntRing diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/SymbolIndexer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt similarity index 97% rename from kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/SymbolIndexer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt index 0c3e27158..983a3435a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/SymbolIndexer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt @@ -3,10 +3,9 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package space.kscience.kmath.named +package space.kscience.kmath.expressions import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.linear.Point import space.kscience.kmath.nd.Structure2D import space.kscience.kmath.structures.BufferFactory @@ -15,6 +14,8 @@ import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.jvm.JvmInline +//DO NOT MOVE THIS CLASS if you do not want ASM module to break + /** * An environment to easy transform indexed variables to symbols and back. * TODO requires multi-receivers to be beautiful diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/NamedBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/NamedBuffer.kt index 5b9b8f0d0..d4daed001 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/NamedBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/NamedBuffer.kt @@ -9,6 +9,7 @@ package space.kscience.kmath.named import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.expressions.SymbolIndexer import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/NamedMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/NamedMatrix.kt index 395cbdc17..73de465b8 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/NamedMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/named/NamedMatrix.kt @@ -9,7 +9,9 @@ package space.kscience.kmath.named import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI +import space.kscience.kmath.expressions.SimpleSymbolIndexer import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.expressions.SymbolIndexer import space.kscience.kmath.linear.Matrix import space.kscience.kmath.structures.getOrNull @@ -20,7 +22,7 @@ import space.kscience.kmath.structures.getOrNull */ public class NamedMatrix(public val values: Matrix, public val indexer: SymbolIndexer) : Matrix by values { init { - require(values.rows.size == values.columns.size) { "Only square matrices could be named" } + require(values.rowNum == values.colNum) { "Only square matrices could be named" } } public operator fun get(i: Symbol, j: Symbol): T = get(indexer.indexOf(i), indexer.indexOf(j)) diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt index 4b115d7e1..337904923 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt @@ -6,18 +6,15 @@ package space.kscience.kmath.optimization import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.expressions.DifferentiableExpression -import space.kscience.kmath.expressions.Symbol -import space.kscience.kmath.expressions.derivative -import space.kscience.kmath.expressions.withDefaultArgs +import space.kscience.kmath.expressions.* import space.kscience.kmath.linear.* import space.kscience.kmath.misc.log import space.kscience.kmath.named.NamedMatrix -import space.kscience.kmath.named.SymbolIndexer import space.kscience.kmath.named.named import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.Float64L2Norm import space.kscience.kmath.operations.algebra +import space.kscience.kmath.optimization.QowOptimizer.distance import space.kscience.kmath.structures.Float64 import space.kscience.kmath.structures.Float64Buffer import kotlin.math.abs