Move RealVector to kmath-for-real and use scientifik plugin

This commit is contained in:
Peter Klimai 2019-08-07 21:47:50 +03:00
parent 4f8c838c9a
commit c31c9a9532
5 changed files with 43 additions and 34 deletions

View File

@ -6,21 +6,6 @@ import kotlin.test.assertEquals
class MatrixTest {
@Test
fun testSum() {
val vector1 = RealVector(5) { it.toDouble() }
val vector2 = RealVector(5) { 5 - it.toDouble() }
val sum = vector1 + vector2
assertEquals(5.0, sum[2])
}
@Test
fun testVectorToMatrix() {
val vector = RealVector(5) { it.toDouble() }
val matrix = vector.asMatrix()
assertEquals(4.0, matrix[4, 0])
}
@Test
fun testTranspose() {
val matrix = MatrixContext.real.one(3, 3)
@ -28,21 +13,6 @@ class MatrixTest {
assertEquals(matrix, transposed)
}
@Test
fun testDot() {
val vector1 = RealVector(5) { it.toDouble() }
val vector2 = RealVector(5) { 5 - it.toDouble() }
val matrix1 = vector1.asMatrix()
val matrix2 = vector2.asMatrix().transpose()
val product = MatrixContext.real.run { matrix1 dot matrix2 }
assertEquals(5.0, product[1, 0])
assertEquals(6.0, product[2, 2])
}
@Test
fun testBuilder() {
val matrix = Matrix.build<Double>(2, 3)(

View File

@ -1,9 +1,11 @@
plugins {
`npm-multiplatform`
id("scientifik.mpp")
}
kotlin.sourceSets.commonMain {
dependencies {
api(project(":kmath-core"))
kotlin.sourceSets {
commonMain {
dependencies {
api(project(":kmath-core"))
}
}
}

View File

@ -0,0 +1,36 @@
package scientifik.kmath.linear
import kotlin.test.Test
import kotlin.test.assertEquals
class VectorTest {
@Test
fun testSum() {
val vector1 = RealVector(5) { it.toDouble() }
val vector2 = RealVector(5) { 5 - it.toDouble() }
val sum = vector1 + vector2
assertEquals(5.0, sum[2])
}
@Test
fun testVectorToMatrix() {
val vector = RealVector(5) { it.toDouble() }
val matrix = vector.asMatrix()
assertEquals(4.0, matrix[4, 0])
}
@Test
fun testDot() {
val vector1 = RealVector(5) { it.toDouble() }
val vector2 = RealVector(5) { 5 - it.toDouble() }
val matrix1 = vector1.asMatrix()
val matrix2 = vector2.asMatrix().transpose()
val product = MatrixContext.real.run { matrix1 dot matrix2 }
assertEquals(5.0, product[1, 0])
assertEquals(6.0, product[2, 2])
}
}

View File

@ -5,5 +5,6 @@ plugins {
kotlin.sourceSets.commonMain {
dependencies {
api(project(":kmath-core"))
api(project(":kmath-for-real"))
}
}