Skip to content

Commit

Permalink
finish KMP migraiton, fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Dec 8, 2021
1 parent 34f8bf7 commit 1b712e6
Show file tree
Hide file tree
Showing 15 changed files with 498 additions and 498 deletions.
3 changes: 1 addition & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ kotlin {
dependencies {
implementation(kotlin("stdlib-common"))
implementation(kotlin("reflect"))
api("ai.hypergraph:kaliningraph:0.1.9")
}
}

Expand All @@ -123,8 +124,6 @@ kotlin {
implementation(kotlin("bom"))
implementation(kotlin("stdlib"))

api("ai.hypergraph:kaliningraph:0.1.9")

implementation("org.graalvm.js:js:21.3.0")
implementation("guru.nidi:graphviz-kotlin:0.18.1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ fun String.superscript() =
}.joinToString("").replace(" ", "")

fun <T> Iterable<T>.repeat(n: Int) =
sequence { repeat(n) { yieldAll(this@repeat) } }
sequence { repeat(n) { yieldAll(this@repeat) } }

var EAGER = false
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ data class Bindings<X: SFun<X>> constructor(val fMap: MapFxF<X>) {
operator fun minus(func: Fun<X>) = Bindings(fMap.filterNot { it.key == func })

// Scalar, vector, and matrix variables
val sVars: Set<SVar<X>> = sVarMap.keys.toSortedSet { v1, v2 -> v1.name.compareTo(v2.name) }
val vVars: Set<VVar<X, *>> = vVarMap.keys.toSortedSet { v1, v2 -> v1.name.compareTo(v2.name) }
val mVars: Set<MVar<X, *, *>> = mVarMap.keys.toSortedSet { v1, v2 -> v1.name.compareTo(v2.name) }
val allVars: Set<Variable<X>> = sVars + vVars + mVars
val sVars: List<SVar<X>> = sVarMap.keys.sortedBy { it.name }
val vVars: List<VVar<X, *>> = vVarMap.keys.sortedBy { it.name }
val mVars: List<MVar<X, *, *>> = mVarMap.keys.sortedBy { it.name }
val allVars: List<Variable<X>> = sVars + vVars + mVars
val allFreeVariables by lazy { allVarMap.filterValues { containsFreeVariable(it) } }
val allBoundVariables: Map<Variable<X>, Fun<X>> by lazy { allVarMap.filterValues { !containsFreeVariable(it) } }

Expand All @@ -95,7 +95,7 @@ data class Bindings<X: SFun<X>> constructor(val fMap: MapFxF<X>) {
val boundVars = allBoundVariables.keys
val unpropagated = (freeVars intersect boundVars).map { it to this[it] }
require(unpropagated.isEmpty()) {
before.show("input"); after.show("result")
//before.show("input"); after.show("result")
"Free vars: $freeVars\n" +
"Bindings were $this\n" +
"Result included unpropagated variables: $unpropagated"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ai.hypergraph.kaliningraph.circuits.Op
import ai.hypergraph.kaliningraph.circuits.Ops
import ai.hypergraph.kaliningraph.tensor.DoubleMatrix
import ai.hypergraph.kaliningraph.*
import ai.hypergraph.kotlingrad.EAGER
import ai.hypergraph.kotlingrad.api.VFun.Companion.KG_IT
import ai.hypergraph.kotlingrad.shapes.D1
import ai.hypergraph.kotlingrad.shapes.DN
Expand All @@ -30,7 +31,7 @@ open class MFun<X, R, C>(override vararg val inputs: Fun<X>): Fun<X>
try {
it as Mat<X, R, C>
} catch (e: ClassCastException) {
show("before"); it.show("after")
//show("before"); it.show("after")
throw NumberFormatException("Matrix function has unbound free variables: ${bindings.allFreeVariables.keys}")
}
}
Expand Down
Loading

0 comments on commit 1b712e6

Please sign in to comment.