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'
|
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 {
|
dependencies {
|
||||||
implementation project(":kmath-core")
|
implementation project(":kmath-core")
|
||||||
implementation project(":kmath-coroutines")
|
implementation project(":kmath-coroutines")
|
||||||
implementation project(":kmath-commons")
|
implementation project(":kmath-commons")
|
||||||
implementation project(":kmath-koma")
|
implementation project(":kmath-koma")
|
||||||
|
compile group: "com.kyonifer", name:"koma-core-ejml", version: "0.12"
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||||
//jmh project(':kmath-core')
|
//jmh project(':kmath-core')
|
||||||
}
|
}
|
||||||
@ -18,10 +25,6 @@ jmh{
|
|||||||
}
|
}
|
||||||
|
|
||||||
jmhClasses.dependsOn(compileKotlin)
|
jmhClasses.dependsOn(compileKotlin)
|
||||||
repositories {
|
|
||||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package scientifik.kmath.linear
|
package scientifik.kmath.linear
|
||||||
|
|
||||||
|
import koma.matrix.ejml.EJMLMatrixFactory
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
import kotlin.system.measureTimeMillis
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
@ -40,4 +41,19 @@ fun main() {
|
|||||||
|
|
||||||
|
|
||||||
println("[commons-math] Inversion of $n matrices $dim x $dim finished in $commonsTime millis")
|
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 {
|
kotlin {
|
||||||
jvm {
|
jvm {
|
||||||
compilations["main"].kotlinOptions.jvmTarget = "1.8"
|
compilations["main"].kotlinOptions.jvmTarget = "1.8"
|
||||||
|
compilations["test"].kotlinOptions.jvmTarget = "1.8"
|
||||||
}
|
}
|
||||||
js()
|
js()
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class LUSolver<T : Comparable<T>, F : Field<T>>(
|
|||||||
val context: GenericMatrixContext<T, F>,
|
val context: GenericMatrixContext<T, F>,
|
||||||
val bufferFactory: MutableBufferFactory<T> = ::boxing,
|
val bufferFactory: MutableBufferFactory<T> = ::boxing,
|
||||||
val singularityCheck: (T) -> Boolean
|
val singularityCheck: (T) -> Boolean
|
||||||
) : LinearSolver<T, F> {
|
) : LinearSolver<T> {
|
||||||
|
|
||||||
|
|
||||||
private fun abs(value: 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))
|
override fun inverse(a: Matrix<T>): Matrix<T> = solve(a, context.one(a.rowNum, a.colNum))
|
||||||
|
|
||||||
companion object {
|
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
|
@Test
|
||||||
fun testTranspose() {
|
fun testTranspose() {
|
||||||
val matrix = GenericMatrixContext.real.one(3, 3)
|
val matrix = MatrixContext.real.one(3, 3)
|
||||||
val transposed = matrix.transpose()
|
val transposed = matrix.transpose()
|
||||||
assertEquals((matrix as BufferMatrix).buffer, (transposed as BufferMatrix).buffer)
|
|
||||||
assertEquals(matrix, transposed)
|
assertEquals(matrix, transposed)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +35,7 @@ class MatrixTest {
|
|||||||
|
|
||||||
val matrix1 = vector1.toMatrix()
|
val matrix1 = vector1.toMatrix()
|
||||||
val matrix2 = vector2.toMatrix().transpose()
|
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])
|
assertEquals(5.0, product[1, 0])
|
||||||
|
@ -6,7 +6,7 @@ import kotlin.test.assertEquals
|
|||||||
class RealLUSolverTest {
|
class RealLUSolverTest {
|
||||||
@Test
|
@Test
|
||||||
fun testInvertOne() {
|
fun testInvertOne() {
|
||||||
val matrix = GenericMatrixContext.real.one(2, 2)
|
val matrix = MatrixContext.real.one(2, 2)
|
||||||
val inverted = LUSolver.real.inverse(matrix)
|
val inverted = LUSolver.real.inverse(matrix)
|
||||||
assertEquals(matrix, inverted)
|
assertEquals(matrix, inverted)
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ class RealLUSolverTest {
|
|||||||
assertEquals(8.0, decomposition.determinant)
|
assertEquals(8.0, decomposition.determinant)
|
||||||
|
|
||||||
//Check decomposition
|
//Check decomposition
|
||||||
with(GenericMatrixContext.real) {
|
with(MatrixContext.real) {
|
||||||
assertEquals(decomposition.p dot matrix, decomposition.l dot decomposition.u)
|
assertEquals(decomposition.p dot matrix, decomposition.l dot decomposition.u)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ repositories {
|
|||||||
kotlin {
|
kotlin {
|
||||||
jvm {
|
jvm {
|
||||||
compilations["main"].kotlinOptions.jvmTarget = "1.8"
|
compilations["main"].kotlinOptions.jvmTarget = "1.8"
|
||||||
|
compilations["test"].kotlinOptions.jvmTarget = "1.8"
|
||||||
}
|
}
|
||||||
js()
|
js()
|
||||||
|
|
||||||
@ -17,8 +18,7 @@ kotlin {
|
|||||||
val commonMain by getting {
|
val commonMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
api(project(":kmath-core"))
|
api(project(":kmath-core"))
|
||||||
implementation("com.kyonifer:koma-core-api-common:0.12")
|
api("com.kyonifer:koma-core-api-common:0.12")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val commonTest by getting {
|
val commonTest by getting {
|
||||||
@ -29,7 +29,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
val jvmMain by getting {
|
val jvmMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("stdlib-jdk8"))
|
api("com.kyonifer:koma-core-api-jvm:0.12")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jvmTest by getting {
|
val jvmTest by getting {
|
||||||
@ -41,7 +41,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
val jsMain by getting {
|
val jsMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("stdlib-js"))
|
api("com.kyonifer:koma-core-api-js:0.12")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jsTest by getting {
|
val jsTest by getting {
|
||||||
|
Loading…
Reference in New Issue
Block a user