Koma integration + multiple fixes to Matrix API
This commit is contained in:
parent
baae18b223
commit
6154588534
@ -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 {
|
||||
|
@ -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")
|
||||
}
|
@ -5,6 +5,7 @@ plugins {
|
||||
kotlin {
|
||||
jvm {
|
||||
compilations["main"].kotlinOptions.jvmTarget = "1.8"
|
||||
compilations["test"].kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
js()
|
||||
|
||||
|
@ -68,7 +68,7 @@ class LUSolver<T : Comparable<T>, F : Field<T>>(
|
||||
val context: GenericMatrixContext<T, F>,
|
||||
val bufferFactory: MutableBufferFactory<T> = ::boxing,
|
||||
val singularityCheck: (T) -> Boolean
|
||||
) : LinearSolver<T, F> {
|
||||
) : LinearSolver<T> {
|
||||
|
||||
|
||||
private fun abs(value: T) =
|
||||
@ -201,6 +201,6 @@ class LUSolver<T : Comparable<T>, F : Field<T>>(
|
||||
override fun inverse(a: Matrix<T>): Matrix<T> = 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 }
|
||||
}
|
||||
}
|
@ -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])
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user