diff --git a/benchmarks/build.gradle b/benchmarks/build.gradle index 98a4a64c5..78d902459 100644 --- a/benchmarks/build.gradle +++ b/benchmarks/build.gradle @@ -4,11 +4,18 @@ plugins { id 'org.jetbrains.kotlin.jvm' } +repositories { + maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } + maven{ url "http://dl.bintray.com/kyonifer/maven"} + mavenCentral() +} + dependencies { implementation project(":kmath-core") implementation project(":kmath-coroutines") implementation project(":kmath-commons") implementation project(":kmath-koma") + compile group: "com.kyonifer", name:"koma-core-ejml", version: "0.12" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" //jmh project(':kmath-core') } @@ -18,10 +25,6 @@ jmh{ } jmhClasses.dependsOn(compileKotlin) -repositories { - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } - mavenCentral() -} compileKotlin { kotlinOptions { diff --git a/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt b/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt index 16ffc4639..d1bc92d8c 100644 --- a/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt +++ b/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt @@ -1,5 +1,6 @@ package scientifik.kmath.linear +import koma.matrix.ejml.EJMLMatrixFactory import kotlin.random.Random import kotlin.system.measureTimeMillis @@ -40,4 +41,19 @@ fun main() { println("[commons-math] Inversion of $n matrices $dim x $dim finished in $commonsTime millis") + + //koma-ejml + + val komaContext = KomaMatrixContext(EJMLMatrixFactory()) + + val komaTime = measureTimeMillis { + komaContext.run { + val km = matrix.toKoma() //avoid overhead on conversion + repeat(n) { + val res = cmSolver.inverse(km) + } + } + } + + println("[koma-ejml] Inversion of $n matrices $dim x $dim finished in $komaTime millis") } \ No newline at end of file diff --git a/kmath-core/build.gradle b/kmath-core/build.gradle index a8d0d2b22..b1a6cccb5 100644 --- a/kmath-core/build.gradle +++ b/kmath-core/build.gradle @@ -5,6 +5,7 @@ plugins { kotlin { jvm { compilations["main"].kotlinOptions.jvmTarget = "1.8" + compilations["test"].kotlinOptions.jvmTarget = "1.8" } js() diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/linear/LUPDecomposition.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/linear/LUPDecomposition.kt index d2de7609d..b2161baf2 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/linear/LUPDecomposition.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/linear/LUPDecomposition.kt @@ -68,7 +68,7 @@ class LUSolver, F : Field>( val context: GenericMatrixContext, val bufferFactory: MutableBufferFactory = ::boxing, val singularityCheck: (T) -> Boolean -) : LinearSolver { +) : LinearSolver { private fun abs(value: T) = @@ -201,6 +201,6 @@ class LUSolver, F : Field>( override fun inverse(a: Matrix): Matrix = solve(a, context.one(a.rowNum, a.colNum)) companion object { - val real = LUSolver(GenericMatrixContext.real, MutableBuffer.Companion::auto) { it < 1e-11 } + val real = LUSolver(MatrixContext.real, MutableBuffer.Companion::auto) { it < 1e-11 } } } \ No newline at end of file diff --git a/kmath-core/src/commonTest/kotlin/scientifik/kmath/linear/MatrixTest.kt b/kmath-core/src/commonTest/kotlin/scientifik/kmath/linear/MatrixTest.kt index eaf00c59b..2a00b84cd 100644 --- a/kmath-core/src/commonTest/kotlin/scientifik/kmath/linear/MatrixTest.kt +++ b/kmath-core/src/commonTest/kotlin/scientifik/kmath/linear/MatrixTest.kt @@ -22,9 +22,8 @@ class MatrixTest { @Test fun testTranspose() { - val matrix = GenericMatrixContext.real.one(3, 3) + val matrix = MatrixContext.real.one(3, 3) val transposed = matrix.transpose() - assertEquals((matrix as BufferMatrix).buffer, (transposed as BufferMatrix).buffer) assertEquals(matrix, transposed) } @@ -36,7 +35,7 @@ class MatrixTest { val matrix1 = vector1.toMatrix() val matrix2 = vector2.toMatrix().transpose() - val product = GenericMatrixContext.real.run { matrix1 dot matrix2 } + val product = MatrixContext.real.run { matrix1 dot matrix2 } assertEquals(5.0, product[1, 0]) diff --git a/kmath-core/src/commonTest/kotlin/scientifik/kmath/linear/RealLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/scientifik/kmath/linear/RealLUSolverTest.kt index 32b07eb86..ea104355c 100644 --- a/kmath-core/src/commonTest/kotlin/scientifik/kmath/linear/RealLUSolverTest.kt +++ b/kmath-core/src/commonTest/kotlin/scientifik/kmath/linear/RealLUSolverTest.kt @@ -6,7 +6,7 @@ import kotlin.test.assertEquals class RealLUSolverTest { @Test fun testInvertOne() { - val matrix = GenericMatrixContext.real.one(2, 2) + val matrix = MatrixContext.real.one(2, 2) val inverted = LUSolver.real.inverse(matrix) assertEquals(matrix, inverted) } @@ -25,7 +25,7 @@ class RealLUSolverTest { assertEquals(8.0, decomposition.determinant) //Check decomposition - with(GenericMatrixContext.real) { + with(MatrixContext.real) { assertEquals(decomposition.p dot matrix, decomposition.l dot decomposition.u) } diff --git a/kmath-koma/build.gradle.kts b/kmath-koma/build.gradle.kts index 623c7f3ba..20ad02fbe 100644 --- a/kmath-koma/build.gradle.kts +++ b/kmath-koma/build.gradle.kts @@ -9,6 +9,7 @@ repositories { kotlin { jvm { compilations["main"].kotlinOptions.jvmTarget = "1.8" + compilations["test"].kotlinOptions.jvmTarget = "1.8" } js() @@ -17,8 +18,7 @@ kotlin { val commonMain by getting { dependencies { api(project(":kmath-core")) - implementation("com.kyonifer:koma-core-api-common:0.12") - implementation("org.jetbrains.kotlin:kotlin-stdlib-common") + api("com.kyonifer:koma-core-api-common:0.12") } } val commonTest by getting { @@ -29,7 +29,7 @@ kotlin { } val jvmMain by getting { dependencies { - implementation(kotlin("stdlib-jdk8")) + api("com.kyonifer:koma-core-api-jvm:0.12") } } val jvmTest by getting { @@ -41,7 +41,7 @@ kotlin { } val jsMain by getting { dependencies { - implementation(kotlin("stdlib-js")) + api("com.kyonifer:koma-core-api-js:0.12") } } val jsTest by getting {