Fix failing test
This commit is contained in:
parent
c34af4d8bd
commit
ff930532e0
13
kmath-gsl/src/nativeTest/kotlin/GslMatrixTest.kt
Normal file
13
kmath-gsl/src/nativeTest/kotlin/GslMatrixTest.kt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package kscience.kmath.gsl
|
||||||
|
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
internal class GslMatrixTest {
|
||||||
|
@Test
|
||||||
|
fun dimensions() = GslRealMatrixContext {
|
||||||
|
val mat = produce(42, 24) { _, _ -> 0.0 }
|
||||||
|
assertEquals(42, mat.rowNum)
|
||||||
|
assertEquals(24, mat.colNum)
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,11 @@ package kscience.kmath.gsl
|
|||||||
|
|
||||||
import kscience.kmath.linear.RealMatrixContext
|
import kscience.kmath.linear.RealMatrixContext
|
||||||
import kscience.kmath.operations.invoke
|
import kscience.kmath.operations.invoke
|
||||||
import kscience.kmath.structures.*
|
import kscience.kmath.structures.Matrix
|
||||||
|
import kscience.kmath.structures.NDStructure
|
||||||
|
import kscience.kmath.structures.RealBuffer
|
||||||
|
import kscience.kmath.structures.asSequence
|
||||||
|
import kotlin.random.Random
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
@ -33,39 +37,23 @@ internal class RealTest {
|
|||||||
val mb = produce(2, 2) { _, _ -> 100.0 }
|
val mb = produce(2, 2) { _, _ -> 100.0 }
|
||||||
val res1: Matrix<Double> = ma dot mb
|
val res1: Matrix<Double> = ma dot mb
|
||||||
val res2: Matrix<Double> = RealMatrixContext { ma dot mb }
|
val res2: Matrix<Double> = RealMatrixContext { ma dot mb }
|
||||||
println(res1.rows.asIterable().map { it.asSequence() }.flatMap(Sequence<*>::toList))
|
|
||||||
println(res2.rows.asIterable().map { it.asSequence() }.flatMap(Sequence<*>::toList))
|
|
||||||
assertEquals(res1, res2)
|
assertEquals(res1, res2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testManyCalls() {
|
fun testManyCalls() = GslRealMatrixContext {
|
||||||
val r1 = GslRealMatrixContext {
|
val expected = RealMatrixContext {
|
||||||
var prod = produce(20, 20) { _, _ -> 100.0 }
|
val rng = Random(0)
|
||||||
val mult = produce(20, 20) { _, _ -> 3.0 }
|
var prod = produce(20, 20) { _, _ -> rng.nextDouble() }
|
||||||
|
val mult = produce(20, 20) { _, _ -> rng.nextDouble() }
|
||||||
measureTime {
|
measureTime { repeat(100) { prod = prod dot mult } }.also(::println)
|
||||||
repeat(100) {
|
|
||||||
prod = prod dot mult
|
|
||||||
}
|
|
||||||
}.also(::println)
|
|
||||||
|
|
||||||
prod
|
prod
|
||||||
}
|
}
|
||||||
|
|
||||||
val r2 = RealMatrixContext {
|
val rng = Random(0)
|
||||||
var prod = produce(20, 20) { _, _ -> 100.0 }
|
var prod = produce(20, 20) { _, _ -> rng.nextDouble() }
|
||||||
val mult = produce(20, 20) { _, _ -> 3.0 }
|
val mult = produce(20, 20) { _, _ -> rng.nextDouble() }
|
||||||
|
measureTime { repeat(100) { prod = prod dot mult } }.also(::println)
|
||||||
measureTime {
|
assertTrue(NDStructure.equals(expected, prod))
|
||||||
repeat(100) {
|
|
||||||
prod = prod dot mult
|
|
||||||
}
|
|
||||||
}.also(::println)
|
|
||||||
|
|
||||||
prod
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(NDStructure.equals(r1, r2))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user